def get_dump_period(self): """Return the dump period and whether this is measured in timesteps.""" if libspud.have_option('/io/dump_period_in_timesteps'): opt_type = libspud.get_child_name('/io/dump_period_in_timesteps', 0) period = libspud.get_option('/io/dump_period_in_timesteps/'+opt_type) return period, True #otherwise opt_type = libspud.get_child_name('/io/dump_period', 0) period = libspud.get_option('/io/dump_period/'+opt_type) return period, False
def get_parameters_from_options(options_file=None, **kwargs): """Read particle data from Fluidity options file.""" if options_file: libspud.load_options(options_file) parameters = [] options_base = '/embedded_models/particle_model/particle_classes' def get_option(pclass, key, default=None): """Get option from key.""" result = default if libspud.have_option('/'.join((options_base, pclass, key))): result = libspud.get_option('/'.join((options_base, pclass, key))) return result for i in range(libspud.get_number_of_children(options_base)): key = libspud.get_child_name(options_base, i) name = get_option(key, 'name') diameter = get_option(key, 'diameter') distribution = get_option(key, 'distribution') density = get_option(key, 'density', default=2.5e3) parameters.append( PhysicalParticle(diameter=diameter, rho=density, distribution=distribution, material_name=name, **kwargs)) return parameters
def __init__(self, option_path): print option_path self.name = libspud.get_option(option_path + "/name") self.surface_ids = libspud.get_option(option_path + "/surface_ids") self.type = libspud.get_option(option_path + "/type/name") if (self.type == "dirichlet"): self.weak = libspud.have_option(option_path + "/type::%s/apply_weakly" % self.type) self.value = [] R = ["x", "y", "z"] for r in R: if (libspud.have_option( option_path + "/type::%s/align_bc_with_cartesian/%s_component" % (self.type, r))): c = libspud.get_child_name( option_path + "/type::%s/align_bc_with_cartesian/%s_component/" % (self.type), 1) self.value.append( libspud.get_option( option_path + "/type::%s/align_bc_with_cartesian/%s_component/%s" % (self.type, r, c))) else: self.value.append(None) print self.value else: self.weak = None self.value = [None, None, None]
def get_parameters_from_options(options_file=None,**kwargs): if options_file: libspud.load_options(options_file) parameters = [] options_base = '/embedded_models/particle_model/particle_classes' def get_option(pclass,key,default=None): result = default if libspud.have_option('/'.join((options_base,pclass,key))): result = libspud.get_option('/'.join((options_base,pclass,key))) return result for i in range(libspud.get_number_of_children(options_base)): key = libspud.get_child_name(options_base,i) name = get_option(key,'name') diameter = get_option(key,'diameter') distribution = get_option(key,'distribution') density = get_option(key,'density',default=2.5e3) parameters.append(PhysicalParticle(diameter=diameter, rho=density, distribution=distribution, material_name=name, **kwargs)) return parameters
def get_parameters_from_reader(reader, **kwargs): """Get particle parameter data from an option reader object.""" del reader options_base = '/embedded_models/particle_model/particle_classes' parameters = [] def get_option(pclass, key, default=None): """libspud wrapper.""" result = default if libspud.have_option('/'.join((options_base, pclass, key))): result = libspud.get_option('/'.join((options_base, pclass, key))) return result for i in range(libspud.get_number_of_children(options_base)): key = libspud.get_child_name(options_base, i) name = get_option(key, 'name') diameter = get_option(key, 'diameter') distribution = get_option(key, 'distribution') density = get_option(key, 'density', default=2.5e3) parameters.append( PhysicalParticle(diameter=diameter, rho=density, distribution=distribution, material_name=name, **kwargs)) return parameters
def __init__(self, option_path): print option_path self.name = libspud.get_option(option_path + "/name") self.surface_ids = libspud.get_option(option_path + "/surface_ids") self.type = libspud.get_option(option_path + "/type/name") if(self.type == "dirichlet"): c = libspud.get_child_name(option_path + "/type::%s/", 1) self.value.append(libspud.get_option(option_path + "/type::%s/align_bc_with_cartesian/%s_component/%s" % (self.type, c))) else: self.value = None
def __init__(self, option_path): print option_path self.name = libspud.get_option(option_path + "/name") self.surface_ids = libspud.get_option(option_path + "/surface_ids") self.type = libspud.get_option(option_path + "/type/name") if (self.type == "dirichlet"): c = libspud.get_child_name(option_path + "/type::%s/", 1) self.value.append( libspud.get_option( option_path + "/type::%s/align_bc_with_cartesian/%s_component/%s" % (self.type, c))) else: self.value = None
def __init__(self, option_path): print option_path self.name = libspud.get_option(option_path + "/name") self.surface_ids = libspud.get_option(option_path + "/surface_ids") self.type = libspud.get_option(option_path + "/type/name") if(self.type == "dirichlet"): self.weak = libspud.have_option(option_path + "/type::%s/apply_weakly" % self.type) self.value = [] R = ["x", "y", "z"] for r in R: if(libspud.have_option(option_path + "/type::%s/align_bc_with_cartesian/%s_component" % (self.type, r))): c = libspud.get_child_name(option_path + "/type::%s/align_bc_with_cartesian/%s_component/" % (self.type), 1) self.value.append(libspud.get_option(option_path + "/type::%s/align_bc_with_cartesian/%s_component/%s" % (self.type, r, c))) else: self.value.append(None) print self.value else: self.weak = None self.value = [None, None, None]
def __init__(self, path): self.path = path self.name = libspud.get_option(path+'/name') # Meshes read from file are alway P1 CG if libspud.have_option(path+'/from_file'): self.shape = 'CG' self.degree = 1 # For derived meshes, check if shape or degree are overridden elif libspud.have_option(path+'/from_mesh'): # Take the inherited options as default basemesh = Mesh('/geometry/'+libspud.get_child_name(path+'/from_mesh',0)) self.shape = basemesh.shape self.degree = basemesh.degree # Override continuity if set if libspud.have_option(path+'/from_mesh/mesh_continuity'): if libspud.get_option(path+'/from_mesh/mesh_continuity') == 'discontinuous': self.shape = 'DG' # Override polynomial degree if set if libspud.have_option(path+'/from_mesh/mesh_shape/polynomial_degree'): self.degree = libspud.get_option(path+'/from_mesh/mesh_shape/polynomial_degree')
import libspud print libspud.__file__ libspud.load_options('test.flml') libspud.print_options() print libspud.number_of_children('/geometry') print libspud.get_child_name('geometry', 0) print libspud.option_count('/problem_type') print libspud.have_option('/problem_type') print libspud.get_option_type('/geometry/dimension') print libspud.get_option_type('/problem_type') print libspud.get_option_rank('/geometry/dimension') print libspud.get_option_rank( '/physical_parameters/gravity/vector_field::GravityDirection/prescribed/value/constant' ) print libspud.get_option_shape('/geometry/dimension') print libspud.get_option_shape('/problem_type') print libspud.get_option('/problem_type') print libspud.get_option('/geometry/dimension') libspud.set_option('/geometry/dimension', 3) print libspud.get_option('/geometry/dimension') list_path = '/material_phase::Material1/scalar_field::MaterialVolumeFraction/prognostic/boundary_conditions::LetNoOneLeave/surface_ids' print libspud.get_option_shape(list_path)
def convert(fluidity_options_file_path, ff_options_file_path): # Read in Fluidity simulation options libspud.clear_options() libspud.load_options(fluidity_options_file_path) # Simulation name simulation_name = libspud.get_option("/simulation_name") # Geometry base = "/geometry" dimension = libspud.get_option(base + "/dimension") mesh_path = libspud.get_option(base + "/mesh::CoordinateMesh/from_file/file_name") + ".msh" # FIXME: Always assumes gmsh format. # Function spaces velocity_function_space = FunctionSpace("/geometry", 1) freesurface_function_space = FunctionSpace("/geometry", 2) # Timestepping base = "/timestepping" current_time = libspud.get_option(base + "/current_time") timestep = libspud.get_option(base + "/timestep") finish_time = libspud.get_option(base + "/finish_time") ## Steady-state if(libspud.have_option(base + "/steady_state")): if(libspud.have_option(base + "/steady_state/tolerance")): steady_state = libspud.get_option(base + "/steady_state/tolerance") else: steady_state = 1e-7 else: steady_state = None # I/O base = "/io" dump_format = libspud.get_option(base + "/dump_format") if(libspud.have_option(base + "/dump_period")): dump_period = libspud.get_option(base + "/dump_period/constant") elif(libspud.have_option(base + "/dump_period_in_timesteps")): dump_period = libspud.get_option(base + "/dump_period_in_timesteps/constant")*timestep else: print "Unable to obtain dump_period." sys.exit() # Gravity g_magnitude = libspud.get_option("/physical_parameters/gravity/magnitude") # Velocity field (momentum equation) base = "/material_phase[0]/vector_field::Velocity" ## Depth (free surface mean height) c = libspud.get_child_name(base + "/prognostic/equation::ShallowWater/scalar_field::BottomDepth/prescribed/value::WholeMesh/", 1) depth = libspud.get_option(base + "/prognostic/equation::ShallowWater/scalar_field::BottomDepth/prescribed/value::WholeMesh/%s" % c) ## Bottom drag coefficient if(libspud.have_option(base + "/prognostic/equation::ShallowWater/bottom_drag")): c = libspud.get_child_name(base + "/prognostic/equation::ShallowWater/bottom_drag/scalar_field::BottomDragCoefficient/prescribed/value::WholeMesh/", 1) bottom_drag = libspud.get_option(base + "/prognostic/equation::ShallowWater/bottom_drag/scalar_field::BottomDragCoefficient/prescribed/value::WholeMesh/%s" % c) else: bottom_drag = None ## Viscosity if(libspud.have_option(base + "/prognostic/tensor_field::Viscosity")): viscosity = libspud.get_option(base + "/prognostic/tensor_field::Viscosity/prescribed/value::WholeMesh/anisotropic_symmetric/constant")[0][0] else: viscosity = None ## Momentum source if(libspud.have_option(base + "/prognostic/vector_field::Source")): c = libspud.get_child_name(base + "/prognostic/vector_field::Source/prescribed/value::WholeMesh/", 1) momentum_source = libspud.get_option(base + "/prognostic/vector_field::Source/prescribed/value::WholeMesh/%s" % c) else: momentum_source = None ## Initial condition if(libspud.have_option(base + "/prognostic/initial_condition::WholeMesh")): c = libspud.get_child_name(base + "/prognostic/initial_condition::WholeMesh/", 1) velocity_initial_condition = libspud.get_option(base + "/prognostic/initial_condition::WholeMesh/%s" % c) else: velocity_initial_condition = 0.0 ## Boundary conditions number_of_bcs = libspud.option_count(base + "/prognostic/boundary_conditions") velocity_bcs = [] for i in range(number_of_bcs): velocity_bcs.append(VelocityBoundaryCondition(base + "/prognostic/boundary_conditions[%d]" % i)) # Pressure field (continuity equation) base = "/material_phase[0]/scalar_field::Pressure" integrate_by_parts = libspud.have_option(base + "/prognostic/spatial_discretisation/continuous_galerkin/integrate_continuity_by_parts") ## Initial condition if(libspud.have_option(base + "/prognostic/initial_condition::WholeMesh")): c = libspud.get_child_name(base + "/prognostic/initial_condition::WholeMesh/", 1) pressure_initial_condition = libspud.get_option(base + "/prognostic/initial_condition::WholeMesh/%s" % c) else: pressure_initial_condition = 0.0 ## Boundary conditions number_of_bcs = libspud.option_count(base + "/prognostic/boundary_conditions") pressure_bcs = [] for i in range(number_of_bcs): pressure_bcs.append(PressureBoundaryCondition(base + "/prognostic/boundary_conditions[%d]" % i)) ## Continuity source if(libspud.have_option(base + "/prognostic/scalar_field::Source")): c = libspud.get_child_name(base + "/prognostic/scalar_field::Source/prescribed/value::WholeMesh/", 1) continuity_source = libspud.get_option(base + "/prognostic/scalar_field::Source/prescribed/value::WholeMesh/%s" % c) else: continuity_source = None # Write out to a Firedrake-Fluids simulation configuration file libspud.clear_options() # Create a bare-bones .swml file to add to. f = open(ff_options_file_path, "w") f.write("<?xml version='1.0' encoding='utf-8'?>\n") f.write("<shallow_water_options>\n") f.write("</shallow_water_options>\n") f.close() libspud.load_options(ff_options_file_path) # Simulation name libspud.set_option("/simulation_name", simulation_name) # Geometry base = "/geometry" libspud.set_option(base + "/dimension", dimension) libspud.set_option(base + "/mesh/from_file/relative_path", mesh_path) # Function spaces base = "/function_spaces" libspud.set_option(base + "/function_space::VelocityFunctionSpace/degree", velocity_function_space.degree) libspud.set_option(base + "/function_space::VelocityFunctionSpace/family", velocity_function_space.family) libspud.set_option(base + "/function_space::FreeSurfaceFunctionSpace/degree", freesurface_function_space.degree) libspud.set_option(base + "/function_space::FreeSurfaceFunctionSpace/family", freesurface_function_space.family) # I/O base = "/io" libspud.set_option(base + "/dump_format", dump_format) libspud.set_option(base + "/dump_period", dump_period) # Timestepping base = "/timestepping" print timestep libspud.set_option(base + "/current_time", current_time) try: libspud.set_option(base + "/timestep", timestep) except: pass libspud.set_option(base + "/finish_time", finish_time) ## Steady-state if(steady_state): libspud.set_option(base + "/steady_state/tolerance", steady_state) # Gravity libspud.set_option("/physical_parameters/gravity/magnitude", g_magnitude) # System/Core Fields: Velocity base = "/system/core_fields/vector_field::Velocity" ## Initial condition if(isinstance(velocity_initial_condition, str)): libspud.set_option(base + "/initial_condition/python", velocity_initial_condition) else: libspud.set_option(base + "/initial_condition/constant", velocity_initial_condition) ## Boundary conditions try: for i in range(len(velocity_bcs)): libspud.set_option(base + "/boundary_condition::%s/surface_ids" % velocity_bcs[i].name, velocity_bcs[i].surface_ids) libspud.set_option_attribute(base + "/boundary_condition::%s/type/name" % velocity_bcs[i].name, velocity_bcs[i].type) if(velocity_bcs[i].type == "dirichlet"): if(isinstance(velocity_bcs[i].value, str)): libspud.set_option(base + "/boundary_condition::%s/type::dirichlet/value/python" % velocity_bcs[i].name, velocity_bcs[i].value) else: libspud.set_option(base + "/boundary_condition::%s/type::dirichlet/value/constant" % velocity_bcs[i].name, velocity_bcs[i].value) except: pass # System/Core Fields: FreeSurfacePerturbation base = "/system/core_fields/scalar_field::FreeSurfacePerturbation" #FIXME: Pressure initial and boundary conditions are multiplied by 'g' in Fluidity, but not in Firedrake-Fluids. ## Initial condition if(isinstance(pressure_initial_condition, str)): libspud.set_option(base + "/initial_condition/python", pressure_initial_condition) else: libspud.set_option(base + "/initial_condition/constant", pressure_initial_condition) ## Boundary conditions try: for i in range(len(pressure_bcs)): libspud.set_option(base + "/boundary_condition::%s/surface_ids" % pressure_bcs[i].name, pressure_bcs[i].surface_ids) libspud.set_option(base + "/boundary_condition::%s/type/name" % pressure_bcs[i].name, pressure_bcs[i].type) if(pressure_bcs[i].type == "dirichlet"): if(isinstance(pressure_bcs[i].value, str)): libspud.set_option(base + "/boundary_condition::%s/type::dirichlet/value/python" % pressure_bcs[i].name, pressure_bcs[i].value) else: libspud.set_option(base + "/boundary_condition::%s/type::dirichlet/value/constant" % pressure_bcs[i].name, pressure_bcs[i].value) except: pass # System/Core Fields: FreeSurfaceMean base = "/system/core_fields/scalar_field::FreeSurfaceMean" if(isinstance(depth, str)): libspud.set_option(base + "/value/python", depth) else: libspud.set_option(base + "/value/constant", depth) # Equations: Continuity equation base = "/system/equations/continuity_equation" libspud.set_option(base + "/integrate_by_parts", integrate_by_parts) ## Source term if(continuity_source is not None): if(isinstance(continuity_source, str)): libspud.set_option(base + "/source_term/scalar_field::Source/value/python", continuity_source) else: libspud.set_option(base + "/source_term/scalar_field::Source/value/constant", continuity_source) # Equations: Momentum equation base = "/system/equations/momentum_equation" ## Viscosity if(viscosity is not None): if(isinstance(viscosity, str)): libspud.set_option(base + "/stress_term/scalar_field::Viscosity/value/python", viscosity) else: libspud.set_option(base + "/stress_term/scalar_field::Viscosity/value/constant", viscosity) ## Bottom drag if(bottom_drag is not None): if(isinstance(bottom_drag, str)): libspud.set_option(base + "/drag_term/scalar_field::BottomDragCoefficient/value/python", bottom_drag) else: libspud.set_option(base + "/drag_term/scalar_field::BottomDragCoefficient/value/constant", bottom_drag) ## Source term if(momentum_source is not None): if(isinstance(momentum_source, str)): libspud.set_option(base + "/source_term/vector_field::Source/value/python", momentum_source) else: libspud.set_option(base + "/source_term/vector_field::Source/value/constant", momentum_source) # Write all the applied options to file. libspud.write_options(ff_options_file_path) return
import libspud print libspud.__file__ libspud.load_options('test.flml') libspud.print_options() print libspud.number_of_children('/geometry') print libspud.get_child_name('geometry', 0) print libspud.option_count('/problem_type') print libspud.have_option('/problem_type') print libspud.get_option_type('/geometry/dimension') print libspud.get_option_type('/problem_type') print libspud.get_option_rank('/geometry/dimension') print libspud.get_option_rank('/physical_parameters/gravity/vector_field::GravityDirection/prescribed/value/constant') print libspud.get_option_shape('/geometry/dimension') print libspud.get_option_shape('/problem_type') print libspud.get_option('/problem_type') print libspud.get_option('/geometry/dimension') libspud.set_option('/geometry/dimension', 3) print libspud.get_option('/geometry/dimension') list_path = '/material_phase::Material1/scalar_field::MaterialVolumeFraction/prognostic/boundary_conditions::LetNoOneLeave/surface_ids' print libspud.get_option_shape(list_path) print libspud.get_option_rank(list_path) print libspud.get_option(list_path)
def convert(fluidity_options_file_path, ff_options_file_path): # Read in Fluidity simulation options libspud.clear_options() libspud.load_options(fluidity_options_file_path) # Simulation name simulation_name = libspud.get_option("/simulation_name") # Geometry base = "/geometry" dimension = libspud.get_option(base + "/dimension") mesh_path = libspud.get_option( base + "/mesh::CoordinateMesh/from_file/file_name" ) + ".msh" # FIXME: Always assumes gmsh format. # Function spaces velocity_function_space = FunctionSpace("/geometry", 1) freesurface_function_space = FunctionSpace("/geometry", 2) # Timestepping base = "/timestepping" current_time = libspud.get_option(base + "/current_time") timestep = libspud.get_option(base + "/timestep") finish_time = libspud.get_option(base + "/finish_time") ## Steady-state if (libspud.have_option(base + "/steady_state")): if (libspud.have_option(base + "/steady_state/tolerance")): steady_state = libspud.get_option(base + "/steady_state/tolerance") else: steady_state = 1e-7 else: steady_state = None # I/O base = "/io" dump_format = libspud.get_option(base + "/dump_format") if (libspud.have_option(base + "/dump_period")): dump_period = libspud.get_option(base + "/dump_period/constant") elif (libspud.have_option(base + "/dump_period_in_timesteps")): dump_period = libspud.get_option( base + "/dump_period_in_timesteps/constant") * timestep else: print "Unable to obtain dump_period." sys.exit() # Gravity g_magnitude = libspud.get_option("/physical_parameters/gravity/magnitude") # Velocity field (momentum equation) base = "/material_phase[0]/vector_field::Velocity" ## Depth (free surface mean height) c = libspud.get_child_name( base + "/prognostic/equation::ShallowWater/scalar_field::BottomDepth/prescribed/value::WholeMesh/", 1) depth = libspud.get_option( base + "/prognostic/equation::ShallowWater/scalar_field::BottomDepth/prescribed/value::WholeMesh/%s" % c) ## Bottom drag coefficient if (libspud.have_option(base + "/prognostic/equation::ShallowWater/bottom_drag")): c = libspud.get_child_name( base + "/prognostic/equation::ShallowWater/bottom_drag/scalar_field::BottomDragCoefficient/prescribed/value::WholeMesh/", 1) bottom_drag = libspud.get_option( base + "/prognostic/equation::ShallowWater/bottom_drag/scalar_field::BottomDragCoefficient/prescribed/value::WholeMesh/%s" % c) else: bottom_drag = None ## Viscosity if (libspud.have_option(base + "/prognostic/tensor_field::Viscosity")): viscosity = libspud.get_option( base + "/prognostic/tensor_field::Viscosity/prescribed/value::WholeMesh/anisotropic_symmetric/constant" )[0][0] else: viscosity = None ## Momentum source if (libspud.have_option(base + "/prognostic/vector_field::Source")): c = libspud.get_child_name( base + "/prognostic/vector_field::Source/prescribed/value::WholeMesh/", 1) momentum_source = libspud.get_option( base + "/prognostic/vector_field::Source/prescribed/value::WholeMesh/%s" % c) else: momentum_source = None ## Initial condition if (libspud.have_option(base + "/prognostic/initial_condition::WholeMesh")): c = libspud.get_child_name( base + "/prognostic/initial_condition::WholeMesh/", 1) velocity_initial_condition = libspud.get_option( base + "/prognostic/initial_condition::WholeMesh/%s" % c) else: velocity_initial_condition = 0.0 ## Boundary conditions number_of_bcs = libspud.option_count(base + "/prognostic/boundary_conditions") velocity_bcs = [] for i in range(number_of_bcs): velocity_bcs.append( VelocityBoundaryCondition(base + "/prognostic/boundary_conditions[%d]" % i)) # Pressure field (continuity equation) base = "/material_phase[0]/scalar_field::Pressure" integrate_by_parts = libspud.have_option( base + "/prognostic/spatial_discretisation/continuous_galerkin/integrate_continuity_by_parts" ) ## Initial condition if (libspud.have_option(base + "/prognostic/initial_condition::WholeMesh")): c = libspud.get_child_name( base + "/prognostic/initial_condition::WholeMesh/", 1) pressure_initial_condition = libspud.get_option( base + "/prognostic/initial_condition::WholeMesh/%s" % c) else: pressure_initial_condition = 0.0 ## Boundary conditions number_of_bcs = libspud.option_count(base + "/prognostic/boundary_conditions") pressure_bcs = [] for i in range(number_of_bcs): pressure_bcs.append( PressureBoundaryCondition(base + "/prognostic/boundary_conditions[%d]" % i)) ## Continuity source if (libspud.have_option(base + "/prognostic/scalar_field::Source")): c = libspud.get_child_name( base + "/prognostic/scalar_field::Source/prescribed/value::WholeMesh/", 1) continuity_source = libspud.get_option( base + "/prognostic/scalar_field::Source/prescribed/value::WholeMesh/%s" % c) else: continuity_source = None # Write out to a Firedrake-Fluids simulation configuration file libspud.clear_options() # Create a bare-bones .swml file to add to. f = open(ff_options_file_path, "w") f.write("<?xml version='1.0' encoding='utf-8'?>\n") f.write("<shallow_water_options>\n") f.write("</shallow_water_options>\n") f.close() libspud.load_options(ff_options_file_path) # Simulation name libspud.set_option("/simulation_name", simulation_name) # Geometry base = "/geometry" libspud.set_option(base + "/dimension", dimension) libspud.set_option(base + "/mesh/from_file/relative_path", mesh_path) # Function spaces base = "/function_spaces" libspud.set_option(base + "/function_space::VelocityFunctionSpace/degree", velocity_function_space.degree) libspud.set_option(base + "/function_space::VelocityFunctionSpace/family", velocity_function_space.family) libspud.set_option( base + "/function_space::FreeSurfaceFunctionSpace/degree", freesurface_function_space.degree) libspud.set_option( base + "/function_space::FreeSurfaceFunctionSpace/family", freesurface_function_space.family) # I/O base = "/io" libspud.set_option(base + "/dump_format", dump_format) libspud.set_option(base + "/dump_period", dump_period) # Timestepping base = "/timestepping" print timestep libspud.set_option(base + "/current_time", current_time) try: libspud.set_option(base + "/timestep", timestep) except: pass libspud.set_option(base + "/finish_time", finish_time) ## Steady-state if (steady_state): libspud.set_option(base + "/steady_state/tolerance", steady_state) # Gravity libspud.set_option("/physical_parameters/gravity/magnitude", g_magnitude) # System/Core Fields: Velocity base = "/system/core_fields/vector_field::Velocity" ## Initial condition if (isinstance(velocity_initial_condition, str)): libspud.set_option(base + "/initial_condition/python", velocity_initial_condition) else: libspud.set_option(base + "/initial_condition/constant", velocity_initial_condition) ## Boundary conditions try: for i in range(len(velocity_bcs)): libspud.set_option( base + "/boundary_condition::%s/surface_ids" % velocity_bcs[i].name, velocity_bcs[i].surface_ids) libspud.set_option_attribute( base + "/boundary_condition::%s/type/name" % velocity_bcs[i].name, velocity_bcs[i].type) if (velocity_bcs[i].type == "dirichlet"): if (isinstance(velocity_bcs[i].value, str)): libspud.set_option( base + "/boundary_condition::%s/type::dirichlet/value/python" % velocity_bcs[i].name, velocity_bcs[i].value) else: libspud.set_option( base + "/boundary_condition::%s/type::dirichlet/value/constant" % velocity_bcs[i].name, velocity_bcs[i].value) except: pass # System/Core Fields: FreeSurfacePerturbation base = "/system/core_fields/scalar_field::FreeSurfacePerturbation" #FIXME: Pressure initial and boundary conditions are multiplied by 'g' in Fluidity, but not in Firedrake-Fluids. ## Initial condition if (isinstance(pressure_initial_condition, str)): libspud.set_option(base + "/initial_condition/python", pressure_initial_condition) else: libspud.set_option(base + "/initial_condition/constant", pressure_initial_condition) ## Boundary conditions try: for i in range(len(pressure_bcs)): libspud.set_option( base + "/boundary_condition::%s/surface_ids" % pressure_bcs[i].name, pressure_bcs[i].surface_ids) libspud.set_option( base + "/boundary_condition::%s/type/name" % pressure_bcs[i].name, pressure_bcs[i].type) if (pressure_bcs[i].type == "dirichlet"): if (isinstance(pressure_bcs[i].value, str)): libspud.set_option( base + "/boundary_condition::%s/type::dirichlet/value/python" % pressure_bcs[i].name, pressure_bcs[i].value) else: libspud.set_option( base + "/boundary_condition::%s/type::dirichlet/value/constant" % pressure_bcs[i].name, pressure_bcs[i].value) except: pass # System/Core Fields: FreeSurfaceMean base = "/system/core_fields/scalar_field::FreeSurfaceMean" if (isinstance(depth, str)): libspud.set_option(base + "/value/python", depth) else: libspud.set_option(base + "/value/constant", depth) # Equations: Continuity equation base = "/system/equations/continuity_equation" libspud.set_option(base + "/integrate_by_parts", integrate_by_parts) ## Source term if (continuity_source is not None): if (isinstance(continuity_source, str)): libspud.set_option( base + "/source_term/scalar_field::Source/value/python", continuity_source) else: libspud.set_option( base + "/source_term/scalar_field::Source/value/constant", continuity_source) # Equations: Momentum equation base = "/system/equations/momentum_equation" ## Viscosity if (viscosity is not None): if (isinstance(viscosity, str)): libspud.set_option( base + "/stress_term/scalar_field::Viscosity/value/python", viscosity) else: libspud.set_option( base + "/stress_term/scalar_field::Viscosity/value/constant", viscosity) ## Bottom drag if (bottom_drag is not None): if (isinstance(bottom_drag, str)): libspud.set_option( base + "/drag_term/scalar_field::BottomDragCoefficient/value/python", bottom_drag) else: libspud.set_option( base + "/drag_term/scalar_field::BottomDragCoefficient/value/constant", bottom_drag) ## Source term if (momentum_source is not None): if (isinstance(momentum_source, str)): libspud.set_option( base + "/source_term/vector_field::Source/value/python", momentum_source) else: libspud.set_option( base + "/source_term/vector_field::Source/value/constant", momentum_source) # Write all the applied options to file. libspud.write_options(ff_options_file_path) return
import libspud libspud.load_options('test.flml') #libspud.print_options() assert libspud.get_option('/timestepping/timestep') == 0.025 assert libspud.get_number_of_children('/geometry') == 5 assert libspud.get_child_name('geometry', 0) == "dimension" assert libspud.option_count('/problem_type') == 1 assert libspud.have_option('/problem_type') assert libspud.get_option_type('/geometry/dimension') is int assert libspud.get_option_type('/problem_type') is str assert libspud.get_option_rank('/geometry/dimension') == 0 assert libspud.get_option_rank( '/physical_parameters/gravity/vector_field::GravityDirection/prescribed/value/constant' ) == 1 assert libspud.get_option_shape('/geometry/dimension') == (-1, -1) assert libspud.get_option_shape('/problem_type')[0] > 1 assert libspud.get_option_shape('/problem_type')[1] == -1 assert libspud.get_option('/problem_type') == "multimaterial" assert libspud.get_option('/geometry/dimension') == 2 libspud.set_option('/geometry/dimension', 3) assert libspud.get_option('/geometry/dimension') == 3
def _children(self, path, test): for i in range(libspud.get_number_of_children(path)): child = libspud.get_child_name(path,i) if test(child): yield child
def post_init(model, xml_path): model.start_time = get_optional('time_options/start_time', default=0.0) if libspud.have_option('time_options/adaptive_timestep'): option_path = 'time_options/adaptive_timestep/' model.adapt_timestep = True model.adapt_cfl = project(Constant( libspud.get_option(option_path + 'cfl_criteria')), model.R, name='cfl') else: model.adapt_timestep = False model.adapt_cfl = project(Constant(0.2), model.R, name='cfl') # ts info options if libspud.have_option('output_options/ts_info'): model.ts_info = True else: model.ts_info = False # plotting options option_path = 'output_options/plotting/' if libspud.have_option('output_options/plotting'): model.plot = libspud.get_option(option_path + 'plotting_interval') if libspud.have_option(option_path + 'output::both'): model.show_plot = True model.save_plot = True elif libspud.have_option(option_path + 'output::live_plotting'): model.show_plot = True model.save_plot = False elif libspud.have_option(option_path + 'output::save_plots'): model.show_plot = False model.save_plot = True else: raise Exception('unrecognised plotting output in options file') option_path = option_path + 'dimensionalise_plots/' else: model.plot = None # dimenionalisation model.g = project(Constant( get_optional(option_path + 'g_prime', default=1.0)), model.R, name='g_prime') model.h_0 = project(Constant(get_optional(option_path + 'h_0', default=1.0)), model.R, name='h_0') model.phi_0 = project(Constant( get_optional(option_path + 'phi_0', default=1.0)), model.R, name='phi_0') # non dimensional numbers option_path = 'non_dimensional_numbers/' model.Fr = project(Constant(get_optional(option_path + 'Fr', default=1.19)), model.R, name="Fr") model.beta = project(Constant( get_optional(option_path + 'beta', default=5e-3)), model.R, name="beta") # initial conditions model.form_ic = ( { 'id': 'momentum', 'function': Function(model.V, name='ic_q'), 'test_function': TestFunction(model.V) }, { 'id': 'height', 'function': Function(model.V, name='ic_h'), 'test_function': TestFunction(model.V) }, { 'id': 'volume_fraction', 'function': Function(model.V, name='ic_phi'), 'test_function': TestFunction(model.V) }, { 'id': 'deposit_depth', 'function': Function(model.V, name='ic_phi_d'), 'test_function': TestFunction(model.V) }, { 'id': 'initial_length', 'function': Function(model.R, name='ic_X_n'), 'test_function': TestFunction(model.R) }, { 'id': 'front_velocity', 'function': Function(model.R, name='ic_u_N'), 'test_function': TestFunction(model.R) }, { 'id': 'timestep', 'function': Function(model.R, name='ic_k'), 'test_function': TestFunction(model.R) }, { 'id': 'phi_int', 'function': Function(model.R, name='ic_phi_int'), 'test_function': TestFunction(model.R) }, ) option_path = 'initial_conditions/' var_paths = 'momentum', 'height', 'volume_fraction', 'deposit_depth', \ 'initial_length', 'front_velocity', 'timestep' # form defines ic for i, var_path in enumerate(var_paths): path = option_path + var_path + '/form' if libspud.have_option(path): if libspud.have_option(path + '/additional_form_var'): for j in range( libspud.option_count(path + '/additional_form_var/var')): py_code = libspud.get_option( path + '/additional_form_var/var[%d]' % j) exec py_code py_code = "model.form_ic[%d]['form'] = %s" % ( i, libspud.get_option(path)) exec py_code # expression defined ic model.w_ic_var = '' if (libspud.have_option(option_path + 'variables') and libspud.option_count(option_path + 'variables/var') > 0): n_var = libspud.option_count(option_path + 'variables/var') for i_var in range(n_var): name = libspud.get_child_name(option_path + 'variables/', i_var) var = name.split(':')[-1] code = libspud.get_option('initial_conditions/variables/' + name + '/code') model.w_ic_var = model.w_ic_var + var + ' = ' + code + ', ' ic_exp = (read_ic(option_path + 'momentum', default='0.0'), read_ic(option_path + 'height', default='1.0'), read_ic(option_path + 'volume_fraction', default='1.0'), read_ic(option_path + 'deposit_depth', default='0.0'), read_ic(option_path + 'initial_length', default='1.0'), read_ic(option_path + 'front_velocity', default='1.19'), read_ic(option_path + 'timestep', default='1.0'), '0.0') exp_str = ('model.w_ic_e = Expression(ic_exp, model.W.ufl_element(), %s)' % model.w_ic_var) exec exp_str in globals(), locals()
import libspud libspud.load_options('test.flml') #libspud.print_options() assert libspud.get_option('/timestepping/timestep') == 0.025 assert libspud.get_number_of_children('/geometry') == 5 assert libspud.get_child_name('geometry', 0) == "dimension" assert libspud.option_count('/problem_type') == 1 assert libspud.have_option('/problem_type') assert libspud.get_option_type('/geometry/dimension') is int assert libspud.get_option_type('/problem_type') is str assert libspud.get_option_rank('/geometry/dimension') == 0 assert libspud.get_option_rank('/physical_parameters/gravity/vector_field::GravityDirection/prescribed/value/constant') == 1 assert libspud.get_option_shape('/geometry/dimension') == (-1, -1) assert libspud.get_option_shape('/problem_type')[0] > 1 assert libspud.get_option_shape('/problem_type')[1] == -1 assert libspud.get_option('/problem_type') == "multimaterial" assert libspud.get_option('/geometry/dimension') == 2 libspud.set_option('/geometry/dimension', 3) assert libspud.get_option('/geometry/dimension') == 3