def read_modelpart_as_mesh(self, filename): """ Reads a Kratos formated modelpart from DEM """ model_part = KRTS.ModelPart("Fluid") model_part.AddNodalSolutionStepVariable(KRTS.RADIUS) model_part.AddNodalSolutionStepVariable(KRTSDEM.PARTICLE_DENSITY) model_part.AddNodalSolutionStepVariable(KRTS.VELOCITY) model_part_io_fluid = KRTS.ModelPartIO(filename) model_part_io_fluid.ReadModelPart(model_part) smp_meshes = [] smp_conditions = [] smp_materials = [] dem_fem_pe = api.Cfd() dem_fem_pe.data[CUBA.DATA_SET] = [] for i in xrange(1, model_part.NumberOfMeshes()): mesh_name = 'solid_' + str(i) mesh = SMesh(name=mesh_name) # Export mesh data to Simphony self.exportKratosNodes(model_part, mesh, i) self.exportKratosElements(model_part, mesh, i) self.exportKratosConditions(model_part, mesh, i) properties = model_part.GetProperties(0)[i] # Fill the boundary condition for the mesh condition = self.convertBc(properties, mesh_name) # Fill the material for the mesh material = self.convertMaterial(properties, mesh_name) # Save the relations meshData = mesh.data meshData[CUBA.CONDITION] = condition.name meshData[CUBA.MATERIAL] = material.name mesh.data = meshData # Pack the return objects smp_meshes.append(mesh) smp_conditions.append(condition) smp_materials.append(material) # Add to the pe? dem_fem_pe.data[CUBA.DATA_SET].append(mesh.name) return { 'datasets': smp_meshes, 'conditions': smp_conditions, 'materials': smp_materials, 'pe': dem_fem_pe, }
def test_Cfd(self): ''' Test for Cfd ''' gravity_model = meta_class.GravityModel() meta_obj = meta_class.Cfd(gravity_model=gravity_model) # Test setting the attribute on init self.assertEqual(meta_obj.gravity_model, gravity_model) self.assertEqual( meta_obj.definition, 'Computational fluid dynamics general (set of ) equations for momentum, mass and energy' ) # noqa # Test the default values self.assertIsInstance(meta_obj.compressibility_model, meta_class.IncompressibleFluidModel) self.assertIsInstance(meta_obj.thermal_model, meta_class.IsothermalModel) self.assertIsInstance(meta_obj.turbulence_model, meta_class.LaminarFlowModel) self.assertIsInstance(meta_obj.multiphase_model, meta_class.SinglePhaseModel) self.assertIsInstance(meta_obj.rheology_model, meta_class.NewtonianFluidModel) self.assertIsInstance(meta_obj.electrostatic_model, meta_class.ConstantElectrostaticFieldModel) self.check_cuds_item(meta_obj) self.check_cuds_component(meta_obj) self.check_model_equation(meta_obj)
from mayavi.scripts import mayavi2 import pipe_mesh import tempfile import time start = time.time() case_name = 'aqueous_foam' mesh_name = 'aqueous_foam_mesh' cuds = CUDS(name=case_name) # physics model cfd = api.Cfd(name='default model') # these are already bt default set in CFD cfd.thermal_model = api.IsothermalModel(name='isothermal') cfd.turbulence_model = api.LaminarFlowModel(name='laminar') cfd.compressibility_model = api.IncompressibleFluidModel(name='incompressible') # material foam = api.Material(name='foam') foam.data[CUBA.DENSITY] = 250.0 foam.data[CUBA.DYNAMIC_VISCOSITY] = 4.37 cuds.add([foam]) # use Herschel Bulkley viscosity model for aqueous foam hb = api.HerschelBulkleyModel(name='foam_rheology') hb.initial_viscosity = 0.01748
def setUp(self): case_name = "simplemeshIO" mesh_name = "simplemeshIO_mesh" cuds = CUDS(name=case_name) # physics model cfd = api.Cfd(name='default model') cuds.add([cfd]) self.sim_time = api.IntegrationTime(name='simulation_time', current=0.0, final=1.0, size=0.5) cuds.add([self.sim_time]) mat = api.Material(name='a_material') mat._data[CUBA.DENSITY] = 1.0 mat._data[CUBA.DYNAMIC_VISCOSITY] = 1.0 cuds.add([mat]) vel_inlet = api.Dirichlet(mat, name='vel_inlet') vel_inlet._data[CUBA.VARIABLE] = CUBA.VELOCITY vel_inlet._data[CUBA.VELOCITY] = (0.1, 0, 0) pres_inlet = api.Neumann(mat, name='pres_inlet') pres_inlet._data[CUBA.VARIABLE] = CUBA.PRESSURE vel_outlet = api.Neumann(mat, name='vel_outlet') vel_outlet._data[CUBA.VARIABLE] = CUBA.VELOCITY pres_outlet = api.Dirichlet(mat, name='pres_outlet') pres_outlet._data[CUBA.VARIABLE] = CUBA.PRESSURE pres_outlet._data[CUBA.PRESSURE] = 0.0 vel_walls = api.Dirichlet(mat, name='vel_walls') vel_walls._data[CUBA.VARIABLE] = CUBA.VELOCITY vel_walls._data[CUBA.VELOCITY] = (0, 0, 0) pres_walls = api.Neumann(mat, name='pres_walls') pres_walls._data[CUBA.VARIABLE] = CUBA.PRESSURE vel_frontAndBack = api.EmptyCondition(name='vel_frontAndBack') vel_frontAndBack._data[CUBA.VARIABLE] = CUBA.VELOCITY pres_frontAndBack = api.EmptyCondition(name='pres_frontAndBack') pres_frontAndBack._data[CUBA.VARIABLE] = CUBA.PRESSURE inlet = api.Boundary(name='inlet', condition=[vel_inlet, pres_inlet]) walls = api.Boundary(name='walls', condition=[vel_walls, pres_walls]) outlet = api.Boundary(name='outlet', condition=[vel_outlet, pres_outlet]) frontAndBack = api.Boundary( name='frontAndBack', condition=[vel_frontAndBack, pres_frontAndBack]) cuds.add([inlet, walls, outlet, frontAndBack]) corner_points = [(0.0, 0.0, 0.0), (5.0, 0.0, 0.0), (5.0, 5.0, 0.0), (0.0, 5.0, 0.0), (0.0, 0.0, 1.0), (5.0, 0.0, 1.0), (5.0, 5.0, 1.0), (0.0, 5.0, 1.0)] self.mesh_path = tempfile.mkdtemp() mesh = create_quad_mesh(self.mesh_path, mesh_name, corner_points, 5, 5, 5) cuds.add([mesh]) self.cuds = cuds self.sim = Simulation(cuds, 'OpenFOAM', engine_interface=EngineInterface.FileIO) self.mesh_in_cuds = self.cuds.get_by_name(mesh_name)
def read_modelpart(self, filename): """ Reads a Kratos formated modelpart for KratosCFD wrapper This functions translates each of the modelpart meshes to one simphony mesh. Properties in the modelpart related to boundary conditions are stored in simphony conditions and referenced in CUBA.CONDITION inside the mesh. Properties in the modelpart not relared to boundary conditions are stored in simphony as materials and referenced in CUBA.MATERIAL inside the mesh. """ model_part = KRTS.ModelPart("FluidPart") self.addNodalVariablesToModelpart(model_part) model_part_io_fluid = KRTS.ModelPartIO(filename) model_part_io_fluid.ReadModelPart(model_part) smp_meshes = [] smp_conditions = [] smp_materials = [] cfd_pe = api.Cfd() cfd_pe.data[CUBA.DATA_SET] = [] for i in xrange(1, model_part.NumberOfMeshes()): mesh_name = 'fluid_' + str(i) mesh = SMesh(name=mesh_name) # Export mesh data to Simphony self.exportKratosNodes(model_part, mesh, i) self.exportKratosElements(model_part, mesh, i) self.exportKratosConditions(model_part, mesh, i) properties = model_part.GetProperties(0)[i] # Fill the boundary condition for the mesh condition = self._convertBc(properties, mesh_name) # Fill the material for the mesh material = self._convertMaterial(properties, mesh_name) # Save the relations meshData = mesh.data meshData[CUBA.CONDITION] = condition.name meshData[CUBA.MATERIAL] = material.name mesh.data = meshData # Pack the return objects smp_meshes.append(mesh) smp_conditions.append(condition) smp_materials.append(material) # Add to the pe? cfd_pe.data[CUBA.DATA_SET].append(mesh.name) return { 'datasets': smp_meshes, 'conditions': smp_conditions, 'materials': smp_materials, 'pe': cfd_pe, }
from mayavi.scripts import mayavi2 import slit_mesh import tempfile import time start = time.time() case_name = 'aqueous_foam' mesh_name = 'aqueous_foam_mesh' cuds = CUDS(name=case_name) # physics model cfd = api.Cfd(name='cfd model') # these are already bt default set in CFD cfd.thermal_model = api.IsothermalModel(name='isothermal') cfd.turbulence_model = api.LaminarFlowModel(name='laminar') cfd.compressibility_model = api.IncompressibleFluidModel(name='incompressible') # material foam = api.Material(name='foam') foam.data[CUBA.DENSITY] = 250.0 foam.data[CUBA.DYNAMIC_VISCOSITY] = 4.37 # initial_viscosity of HB model cuds.add([foam]) # use Herschel Bulkley viscosity model for aqueous foam hb = api.HerschelBulkleyModel(name='foam_rheology') hb.initial_viscosity = 0.01748 * foam.data[CUBA.DENSITY]