示例#1
0
    def test_get_nameless_cuds_component(self):
        c = CUDS()
        c.add([self.nameless_cuds_1])
        component = c.get(self.nameless_cuds_1.uid)

        self.assertEqual(component, self.nameless_cuds_1)
        self.assertRaises(TypeError, c.get_by_name, component.name)
示例#2
0
    def test_add_nameless_cuds_component(self):
        c = CUDS()
        c.add([self.nameless_cuds_1])

        self.assertEqual(c.get(self.nameless_cuds_1.uid),
                         self.nameless_cuds_1)
        self.assertRaises(TypeError, c.get_by_name, self.nameless_cuds_1.name)
示例#3
0
    def test_remove_named_component_by_uid(self):
        c = CUDS()
        c.add([self.named_cuds_1])
        c.remove([self.named_cuds_1.uid])

        self.assertRaises(KeyError, c.get_by_name,
                          self.named_cuds_1.name)
示例#4
0
    def test_get_named_cuds_component(self):
        c = CUDS()
        c.add([self.named_cuds_1])

        self.assertEqual(c.get_by_name(self.named_cuds_1.name),
                         self.named_cuds_1)
        self.assertEqual(c.get(self.named_cuds_1.uid), self.named_cuds_1)
示例#5
0
    def test_run(self):
        """ Test if cfd can run

        """

        path = os.path.join(os.path.dirname(__file__), "CFD_exampleFluid")

        cuds = CUDS(name='example_kratos_cfd_simulatiob')

        itime = api.IntegrationTime(name="cfd_integration_time")
        itime.time = 0.0001
        itime.step = 0.0025
        itime.final = 0.0075
        cuds.add([itime])

        cfd_utils = CFD_Utils()

        model_fluid = cfd_utils.read_modelpart(path)

        for model in [model_fluid]:
            cuds.add(list(model['datasets']))
            cuds.add(list(model['conditions']))
            cuds.add(list(model['materials']))
            cuds.add([model['pe']])

        # Create the simulation and run the problem
        sim = Simulation(cuds, "KRATOS_CFD", engine_interface=True)
        sim.run()
示例#6
0
    def test_remove_nameless_component_by_uid(self):
        c = CUDS()

        c.add([self.nameless_cuds_1])
        c.remove([self.nameless_cuds_1.uid])

        self.assertRaises(KeyError, c.get, self.nameless_cuds_1.uid)
示例#7
0
    def test_remove_dataset(self):
        ps = Particles('my particles')
        ps.add([Particle(), Particle()])
        c = CUDS()
        c.add([ps])
        c.remove([ps.uid])

        self.assertRaises(KeyError, c.get, ps.uid)
示例#8
0
    def test_add_named_dataset(self):
        ps = Particles('my particles')
        ps.add([Particle(), Particle()])
        c = CUDS()
        c.add([ps])

        self.assertEqual(c.get_by_name(ps.name), ps)
        self.assertRaises(ValueError, c.add, [ps])
示例#9
0
    def test_get_named_cuds_component(self):
        c = CUDS()
        c.add([self.named_cuds_1])

        self.assertEqual(c.get_by_name(self.named_cuds_1.name),
                         self.named_cuds_1)
        self.assertEqual(c.get(self.named_cuds_1.uid),
                         self.named_cuds_1)
示例#10
0
    def test_remove_dataset(self):
        ps = Particles('my particles')
        ps.add([Particle(), Particle()])
        c = CUDS()
        c.add([ps])
        c.remove([ps.uid])

        self.assertRaises(KeyError, c.get, ps.uid)
示例#11
0
    def test_add_named_dataset(self):
        ps = Particles('my particles')
        ps.add([Particle(), Particle()])
        c = CUDS()
        c.add([ps])

        self.assertEqual(c.get_by_name(ps.name), ps)
        self.assertRaises(ValueError, c.add, [ps])
示例#12
0
    def test_add_nameless_component_several_times(self):
        c = CUDS()
        c.add([self.nameless_cuds_1])
        c.add([self.nameless_cuds_1])
        component = c.get(self.nameless_cuds_1.uid)

        self.assertEqual(component,
                         self.nameless_cuds_1)
        self.assertRaises(TypeError, c.get_by_name, component.name)
示例#13
0
    def test_iter_datasets_types(self):
        dataset = Particles('M1')
        dataset.add([Particle(), Particle()])
        c = CUDS()
        c.add([dataset])

        for ps in c.iter(item_type=CUBA.PARTICLES):
            self.assertIsInstance(ps, Particles)
            self.assertIn(ps, [dataset])
示例#14
0
    def test_iter_datasets_types(self):
        dataset = Particles('M1')
        dataset.add([Particle(),
                     Particle()])
        c = CUDS()
        c.add([dataset])

        for ps in c.iter(item_type=CUBA.PARTICLES):
            self.assertIsInstance(ps, Particles)
            self.assertIn(ps, [dataset])
示例#15
0
    def test_cuds_update_invalid_component(self):
        component = api.Box(name='a box')

        c = CUDS()
        c.add([component])

        another_component = api.Box(name='another box')

        error = 'Component another box:[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12} does not exist'  # noqa
        with self.assertRaisesRegexp(ValueError, error):
            c.update([another_component])
示例#16
0
    def test_cuds_update(self):

        component = api.Box(name='a box')
        c = CUDS()
        c.add([component])

        component.name = 'updated box'
        c.update([component])
        updated_component = c.get(component.uid)

        self.assertEqual(updated_component.name, 'updated box')
示例#17
0
    def test_iter_with_uid(self):
        c = CUDS()

        c.add([self.named_cuds_1])
        c.add([self.named_cuds_2])

        component_list = []
        for component in c.iter(uids=[self.named_cuds_1.uid]):
            component_list.append(component)

        self.assertTrue(len(component_list), 1)
        self.assertEqual(component_list[0].uid, self.named_cuds_1.uid)
示例#18
0
    def test_iter_with_component(self):
        c = CUDS()

        c.add([self.named_cuds_1])
        c.add([self.named_cuds_2])

        component_list = []
        for component in c.iter(item_type=CUBA.BOX):
            component_list.append(component)

        self.assertTrue(len(component_list), 2)
        for cmp in component_list:
            self.assertIn(cmp, [self.named_cuds_1, self.named_cuds_2])
示例#19
0
    def test_iter_with_uid(self):
        c = CUDS()

        c.add([self.named_cuds_1])
        c.add([self.named_cuds_2])

        component_list = []
        for component in c.iter(uids=[self.named_cuds_1.uid]):
            component_list.append(component)

        self.assertTrue(len(component_list), 1)
        self.assertEqual(component_list[0].uid,
                         self.named_cuds_1.uid)
示例#20
0
    def test_iter_with_component(self):
        c = CUDS()

        c.add([self.named_cuds_1])
        c.add([self.named_cuds_2])

        component_list = []
        for component in c.iter(item_type=CUBA.BOX):
            component_list.append(component)

        self.assertTrue(len(component_list), 2)
        for cmp in component_list:
            self.assertIn(cmp, [self.named_cuds_1,
                                self.named_cuds_2])
示例#21
0
    def test_iter_datasets_dimention(self):
        ps1 = Particles('M1')
        ps2 = Particles('M2')
        ps1.add([Particle(), Particle()])
        ps2.add([Particle(), Particle()])

        c = CUDS()
        c.add([ps1])
        c.add([ps2])

        cuds_list = []
        for component in c.iter(item_type=CUBA.PARTICLES):
            cuds_list.append(component)

        self.assertTrue(len(cuds_list), 2)
示例#22
0
    def test_iter_datasets_dimention(self):
        ps1 = Particles('M1')
        ps2 = Particles('M2')
        ps1.add([Particle(), Particle()])
        ps2.add([Particle(), Particle()])

        c = CUDS()
        c.add([ps1])
        c.add([ps2])

        cuds_list = []
        for component in c.iter(item_type=CUBA.PARTICLES):
            cuds_list.append(component)

        self.assertTrue(len(cuds_list), 2)
示例#23
0
    def generate_cuds(self):
        pset1 = create_particles_with_id(restrict=[CUBA.VELOCITY])
        for p in pset1:
            p.data[CUBA.MATERIAL_TYPE] = 1

        pset2 = create_particles_with_id(restrict=[CUBA.VELOCITY])
        for p in pset2:
            p.data[CUBA.MATERIAL_TYPE] = 1

        ps1 = Particles('ps1')
        ps2 = Particles('ps2')

        ps1.add(pset1)
        ps2.add(pset2)

        c = CUDS()
        c.add([ps2])

        mat = api.Material()
        mat.data[CUBA.MASS] = 1.0
        c.add([mat])

        box = api.Box()
        c.add([box])

        return c
示例#24
0
    def test_run(self):
        """ Test if cfd can run

        """

        pathParticles = os.path.join(
            "/home/travis/build/simphony/simphony-kratos/simkratos/tests/dem",
            "3balls"
        )
        pathSolid = os.path.join(
            "/home/travis/build/simphony/simphony-kratos/simkratos/tests/dem",
            "3ballsDEM_FEM_boundary"
        )

        cuds = CUDS(name='example_kratos_dem_somulation')

        itime = api.IntegrationTime(name="dem_integration_time")
        itime.time = 0.0001
        itime.step = 0.001
        itime.final = 60 * itime.step
        cuds.add([itime])

        utils = DEM_Utils()

        print(pathParticles)

        model_particles = utils.read_modelpart_as_particles(pathParticles)
        model_solid = utils.read_modelpart_as_mesh(pathSolid)

        for model in [model_particles, model_solid]:
            cuds.add(list(model['datasets']))
            cuds.add(list(model['conditions']))
            cuds.add(list(model['materials']))
            cuds.add([model['pe']])

        sim = Simulation(cuds, "KRATOS_DEM", engine_interface=True)
        sim.run()
示例#25
0
    def test_add_named_component_several_times(self):
        c = CUDS()
        c.add([self.named_cuds_1])

        self.assertRaises(ValueError, c.add, [self.named_cuds_1])
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]
hb.relaxation_time = 0.0148 * foam.data[CUBA.DENSITY]
hb.linear_constant = 0.00268 * foam.data[CUBA.DENSITY]
hb.power_law_index = 0.5
hb.material = cuds.get_by_name('foam').uid

cfd.rheology_model = hb

cuds.add([cfd])


sol_par = api.SolverParameter(name='steady_state')
示例#27
0
    def test_add_cuds_component(self):
        c = CUDS()

        self.assertIsNone(c.add([self.named_cuds_1]))
        self.assertIsNone(c.add([self.nameless_cuds_1]))
示例#28
0
    def test_add_named_cuds_component(self):
        c = CUDS()

        self.assertIsNone(c.add([self.named_cuds_1]))
        self.assertEqual(c.get_by_name(self.named_cuds_1.name),
                         self.named_cuds_1)
class WrapperTestCase(unittest.TestCase):
    """Test case for Wrapper class"""
    def setUp(self):
        register.OpenFOAMExtension()

        self.engine = EngineInterface.Internal

        self.mesh = TestMesh(name="mesh1")

        self.points = [
            Point(
                (0.0, 0.0, 0.0)),
            Point(
                (1.0, 0.0, 0.0)),
            Point(
                (1.0, 0.0, 1.0)),
            Point(
                (0.0, 0.0, 1.0)),
            Point(
                (0.0, 1.0, 0.0)),
            Point(
                (1.0, 1.0, 0.0)),
            Point(
                (1.0, 1.0, 1.0)),
            Point(
                (0.0, 1.0, 1.0))
        ]

        puids = self.mesh.add(self.points)

        self.faces = [
            Face([puids[0], puids[3], puids[7], puids[4]]),
            Face([puids[1], puids[2], puids[6], puids[5]]),
            Face([puids[0], puids[1], puids[5], puids[4]]),
            Face([puids[3], puids[2], puids[6], puids[7]]),
            Face([puids[0], puids[1], puids[2], puids[3]]),
            Face([puids[4], puids[5], puids[6], puids[7]])
        ]

        self.fuids = self.mesh.add(self.faces)

        self.cells = [
            Cell(puids,
                 data=DataContainer({CUBA.VELOCITY: [1, 0, 0],
                                     CUBA.PRESSURE: 4.0}))
        ]

        self.puids = puids

        self.mesh.add(self.cells)

        self.boundaries = {"boundary"+str(i): [self.fuids[i]]
                           for i in range(6)}
        self.mesh._boundaries = self.boundaries

        self.cuds = CUDS(name='cuds')
        cfd = Cfd(name='default cfd model')
        self.cuds.add([cfd, self.mesh])

    def test_add_dataset(self):
        """Test add_dataset method

        """

        sim = Simulation(self.cuds, 'OpenFOAM',
                         engine_interface=self.engine)
        wrapper = sim._wrapper

        self.assertEqual(sum(1 for _ in wrapper.iter_datasets()), 1)

    def test_remove_dataset(self):
        """Test remove_dataset method

        """

        sim = Simulation(self.cuds, 'OpenFOAM',
                         engine_interface=self.engine)
        wrapper = sim._wrapper
        wrapper.remove_dataset(self.mesh.name)
        with self.assertRaises(ValueError):
            wrapper.get_dataset(self.mesh.name)

    def test_get_dataset(self):
        """Test get_dataset method

        """

        sim = Simulation(self.cuds, 'OpenFOAM',
                         engine_interface=self.engine)
        wrapper = sim._wrapper
        mesh_inside_wrapper = wrapper.get_dataset(self.mesh.name)
        self.assertEqual(self.mesh.name, mesh_inside_wrapper.name)

        label = 0

        for point in self.mesh.iter(item_type=CUBA.POINT):
            puid = mesh_inside_wrapper._foamPointLabelToUuid[label]
            point_f = mesh_inside_wrapper.get(puid)

            self.assertEqual(point.coordinates, point_f.coordinates)
            label += 1

        label = 0

        for cell in self.mesh.iter(item_type=CUBA.CELL):
            cuid = mesh_inside_wrapper._foamCellLabelToUuid[label]
            cell_f = mesh_inside_wrapper.get(cuid)

            self.assertEqual(cell.data[CUBA.PRESSURE],
                             cell_f.data[CUBA.PRESSURE])
            self.assertEqual(cell.data[CUBA.VELOCITY],
                             cell_f.data[CUBA.VELOCITY])
            label += 1

    def test_get_dataset_names(self):
        """Test get_dataset_names method

        """

        sim = Simulation(self.cuds, 'OpenFOAM',
                         engine_interface=self.engine)
        wrapper = sim._wrapper
        name1 = self.mesh.name
        mesh2 = self.mesh
        name2 = "mesh2"
        mesh2.name = name2
        wrapper.add_dataset(mesh2)

        self.assertEqual(list(wrapper.get_dataset_names())[0], name1)
        self.assertEqual(list(wrapper.get_dataset_names())[1], name2)

    def test_iter_datasets(self):
        """Test iter_datasets method

        """

        sim = Simulation(self.cuds, 'OpenFOAM',
                         engine_interface=self.engine)
        wrapper = sim._wrapper
        mesh2 = self.mesh
        mesh2.name = "mesh2"
        wrapper.add_dataset(mesh2)

        self.assertEqual(sum(1 for _ in wrapper.iter_datasets()), 2)

    def test_multiple_meshes(self):
        """Test multiple meshes inside wrapper

        """

        sim = Simulation(self.cuds, 'OpenFOAM',
                         engine_interface=self.engine)
        wrapper = sim._wrapper
        mesh2 = self.mesh
        mesh2.name = "mesh2"
        wrapper.add_dataset(mesh2)
        mesh_inside_wrapper1 = wrapper.get_dataset(self.mesh.name)
        mesh_inside_wrapper2 = wrapper.get_dataset(mesh2.name)

        self.assertEqual(
            sum(1 for _ in mesh_inside_wrapper1.iter(item_type=CUBA.POINT)),
            sum(1 for _ in mesh_inside_wrapper2.iter(item_type=CUBA.POINT)))
示例#30
0
def read_data_file(filename, atom_style=None, name=None):
    """ Reads LAMMPS data file and create CUDS objects

    Reads LAMMPS data file and create a Particles and CUDS. The CUDS
    will contain a material for each atom type (e.g. CUBA.MATERIAL_TYPE).

    The attributes for each particle are based upon what atom-style
    the file contains (i.e. "sphere" means that particles in addition to having
    CUBA.VELOCITY will also have a CUBA.RADIUS and CUBA.MASS). See
    'atom_style' for more details.

    Parameters
    ----------
    filename : str
        filename of lammps data file
    atom_style : AtomStyle, optional
        type of atoms in the file.  If None, then an attempt of
        interpreting the atom-style in the file is performed.
    name : str, optional
        name to be given to returned Particles.  If None, then filename is
        used.

    Returns
    -------
    particles : Particles
        particles
    SD : CUDS
        SD containing materials

    """
    handler = LammpsSimpleDataHandler()
    parser = LammpsDataFileParser(handler=handler)

    parser.parse(filename)

    if atom_style is None:
        atom_style = (
            get_atom_style(handler.get_atom_type())
            if handler.get_atom_type()
            else AtomStyle.ATOMIC)

    types = (atom_t for atom_t in
             range(1, handler.get_number_atom_types() + 1))
    atoms = handler.get_atoms()
    velocities = handler.get_velocities()
    masses = handler.get_masses()

    box_origin = handler.get_box_origin()
    box_vectors = handler.get_box_vectors()

    type_to_material_map = {}

    statedata = CUDS()

    # set up a Material for each different type
    for atom_type in types:
        material = Material()
        description = "Material for lammps atom type (originally '{}')".format(
            atom_type
        )
        material.description = description
        type_to_material_map[atom_type] = material.uid
        statedata.add([material])

    # add masses to materials
    for atom_type, mass in masses.iteritems():
        material = statedata.get(type_to_material_map[atom_type])
        material.data[CUBA.MASS] = mass
        statedata.update([material])

    def convert_atom_type_to_material(atom_type):
        return type_to_material_map[atom_type]

    interpreter = LammpsDataLineInterpreter(atom_style,
                                            convert_atom_type_to_material)

    # create particles
    particles = Particles(name=name if name else filename)
    data = particles.data
    data.update({CUBA.ORIGIN: box_origin,
                 CUBA.VECTOR: box_vectors})
    particles.data = data

    # add each particle
    for lammps_id, values in atoms.iteritems():
        coordinates, data = interpreter.convert_atom_values(values)
        data.update(interpreter.convert_velocity_values(velocities[lammps_id]))

        p = Particle(coordinates=coordinates, data=data)
        particles.add([p])

    return particles, statedata
示例#31
0
    def test_add_named_component_several_times(self):
        c = CUDS()
        c.add([self.named_cuds_1])

        self.assertRaises(ValueError, c.add, [self.named_cuds_1])
示例#32
0
    def test_add_named_cuds_component(self):
        c = CUDS()

        self.assertIsNone(c.add([self.named_cuds_1]))
        self.assertEqual(c.get_by_name(self.named_cuds_1.name),
                         self.named_cuds_1)
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]
hb.relaxation_time = 0.0148 * foam.data[CUBA.DENSITY]
hb.linear_constant = 0.00268 * foam.data[CUBA.DENSITY]
hb.power_law_index = 0.5
hb.material = cuds.get_by_name('foam').uid

cfd.rheology_model = hb

cuds.add([cfd])


sol_par = api.SolverParameter(name='steady_state')
示例#34
0
# physics model
cfd = api.Cfd(name='default model')

# these are already by 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')


# time setting
sim_time = api.IntegrationTime(name='simulation_time',
                               current=0.0,
                               final=640.0,
                               size=0.1)
cuds.add([sim_time])


# create computational mesh
mesh = foam_controlwrapper.create_block_mesh(tempfile.mkdtemp(), mesh_name,
                                             dahl_mesh.blockMeshDict)
cuds.add([mesh])


# materials
sludge = api.Material(name='sludge')
sludge.data[CUBA.DENSITY] = 1900.0
sludge.data[CUBA.DYNAMIC_VISCOSITY] = 0.01
cuds.add([sludge])

water = api.Material(name='water')
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
hb.relaxation_time = 0.0148
hb.linear_constant = 0.00268
hb.power_law_index = 0.5
hb.material = cuds.get_by_name('foam').uid
cfd.rheology_model = hb

cuds.add([cfd])

# time setting
sim_time = api.IntegrationTime(name='simulation_time',
                               current=0.0,
case_name = 'capillary_rise'
mesh_name = 'capillary_rise_mesh'

# create cuds
cuds = CUDS(name=case_name)
# physics model
cfd = api.Cfd(name='default model')

# these are already by default set in CFD
cfd.rheology_model = api.NewtonianFluidModel(name='newtonian')
cfd.thermal_model = api.IsothermalModel(name='isothermal')
cfd.turbulence_model = api.LaminarFlowModel(name='laminar')
cfd.compressibility_model = api.IncompressibleFluidModel(name='incompressible')
# add to cuds
cuds.add([cfd])

# materials
water = api.Material(name='water')
water.data[CUBA.DENSITY] = 1000.0
water.data[CUBA.DYNAMIC_VISCOSITY] = 0.001
cuds.add([water])

air = api.Material(name='air')
air.data[CUBA.DENSITY] = 1.0
air.data[CUBA.DYNAMIC_VISCOSITY] = 1.0e-5
cuds.add([air])

# surface tension

st = api.SurfaceTensionRelation(material=[water, air],
示例#37
0
    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)
示例#38
0
# physics model
cfd = api.Cfd(name='default model')

# these are already by 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')


# time setting
sim_time = api.IntegrationTime(name='simulation_time',
                               current=0.0,
                               final=640.0,
                               size=0.1)
cuds.add([sim_time])


# create computational mesh
mesh = foam_controlwrapper.create_block_mesh(tempfile.mkdtemp(), mesh_name,
                                             dahl_mesh.blockMeshDict)
cuds.add([mesh])


# materials
sludge = api.Material(name='sludge')
sludge.data[CUBA.DENSITY] = 1900.0
sludge.data[CUBA.DYNAMIC_VISCOSITY] = 0.01
cuds.add([sludge])

water = api.Material(name='water')
示例#39
0
    def test_add_cuds_component(self):
        c = CUDS()

        self.assertIsNone(c.add([self.named_cuds_1]))
        self.assertIsNone(c.add([self.nameless_cuds_1]))
示例#40
0
case_name = 'poiseuille'
mesh_name = 'poiseuille_mesh'

# create cuds
cuds = CUDS(name=case_name)

# physics model
cfd = api.Cfd(name='default model')

# these are already by default set in CFD
cfd.rheology_model = api.NewtonianFluidModel(name='newtonian')
cfd.thermal_model = api.IsothermalModel(name='isothermal')
cfd.turbulence_model = api.LaminarFlowModel(name='laminar')
cfd.compressibility_model = api.IncompressibleFluidModel(name='incompressible')
# add to cuds
cuds.add([cfd])

# material
mat = api.Material(name='a_material')
mat.data[CUBA.DENSITY] = 1.0
mat.data[CUBA.DYNAMIC_VISCOSITY] = 1.0
cuds.add([mat])

# time setting
sim_time = api.IntegrationTime(name='simulation_time',
                               current=0.0,
                               final=1.0,
                               size=0.01)
cuds.add([sim_time])

# solver parameter to write data
mesh_name = 'vortex_shedding_mesh'


# create cuds
cuds = CUDS(name=case_name)

# physics model
cfd = api.Cfd(name='default model')

# these are already by default set in CFD
cfd.rheology_model = api.NewtonianFluidModel(name='newtonian')
cfd.thermal_model = api.IsothermalModel(name='isothermal')
cfd.turbulence_model = api.LaminarFlowModel(name='laminar')
cfd.compressibility_model = api.IncompressibleFluidModel(name='incompressible')
# add to cuds
cuds.add([cfd])

# material
mat = api.Material(name='a_material')
mat.data[CUBA.DENSITY] = 1.0
mat.data[CUBA.DYNAMIC_VISCOSITY] = 2.0e-2
cuds.add([mat])

# time setting
sim_time = api.IntegrationTime(name='simulation_time',
                               current=0.0,
                               final=150.0,
                               size=0.025)
cuds.add([sim_time])

# create mesh
示例#42
0
class WrapperTestCase(unittest.TestCase):
    """Test case for Wrapper class"""
    def setUp(self):
        register.OpenFOAMExtension()

        self.engine = EngineInterface.FileIO

        self.mesh = TestMesh(name="mesh1")

        self.points = [
            Point((0.0, 0.0, 0.0)),
            Point((1.0, 0.0, 0.0)),
            Point((1.0, 0.0, 1.0)),
            Point((0.0, 0.0, 1.0)),
            Point((0.0, 1.0, 0.0)),
            Point((1.0, 1.0, 0.0)),
            Point((1.0, 1.0, 1.0)),
            Point((0.0, 1.0, 1.0))
        ]

        puids = self.mesh.add(self.points)

        self.faces = [
            Face([puids[0], puids[3], puids[7], puids[4]]),
            Face([puids[1], puids[2], puids[6], puids[5]]),
            Face([puids[0], puids[1], puids[5], puids[4]]),
            Face([puids[3], puids[2], puids[6], puids[7]]),
            Face([puids[0], puids[1], puids[2], puids[3]]),
            Face([puids[4], puids[5], puids[6], puids[7]])
        ]

        self.fuids = self.mesh.add(self.faces)

        self.cells = [
            Cell(puids,
                 data=DataContainer({
                     CUBA.VELOCITY: [1, 0, 0],
                     CUBA.PRESSURE: 4.0
                 }))
        ]

        self.puids = puids

        self.mesh.add(self.cells)

        self.boundaries = {
            "boundary" + str(i): [self.fuids[i]]
            for i in range(6)
        }
        self.mesh._boundaries = self.boundaries

        self.cuds = CUDS(name='cuds')
        self.cuds.add([Cfd(name='default cfd model'), self.mesh])

    def test_add_dataset(self):
        """Test add_dataset method

        """

        sim = Simulation(self.cuds, 'OpenFOAM', engine_interface=self.engine)
        wrapper = sim._wrapper

        self.assertEqual(sum(1 for _ in wrapper.iter_datasets()), 1)

    def test_remove_dataset(self):
        """Test remove_dataset method

        """

        sim = Simulation(self.cuds, 'OpenFOAM', engine_interface=self.engine)
        wrapper = sim._wrapper
        wrapper.remove_dataset(self.mesh.name)
        with self.assertRaises(ValueError):
            wrapper.get_dataset(self.mesh.name)

    def test_get_dataset(self):
        """Test get_dataset method

        """

        sim = Simulation(self.cuds, 'OpenFOAM', engine_interface=self.engine)
        wrapper = sim._wrapper
        mesh_inside_wrapper = wrapper.get_dataset(self.mesh.name)
        self.assertEqual(self.mesh.name, mesh_inside_wrapper.name)

        label = 0
        for point in self.mesh.iter(item_type=CUBA.POINT):
            puid = mesh_inside_wrapper._foamPointLabelToUuid[label]
            point_f = mesh_inside_wrapper.get(puid)
            self.assertEqual(point.coordinates, point_f.coordinates)
            label += 1

        label = 0

        for cell in self.mesh.iter(item_type=CUBA.CELL):
            cuid = mesh_inside_wrapper._foamCellLabelToUuid[label]
            cell_f = mesh_inside_wrapper.get(cuid)
            self.assertEqual(cell.data[CUBA.PRESSURE],
                             cell_f.data[CUBA.PRESSURE])
            self.assertEqual(cell.data[CUBA.VELOCITY],
                             cell_f.data[CUBA.VELOCITY])
            label += 1

    def test_get_dataset_names(self):
        """Test get_dataset_names method

        """

        sim = Simulation(self.cuds, 'OpenFOAM', engine_interface=self.engine)
        wrapper = sim._wrapper
        name1 = self.mesh.name
        mesh2 = self.mesh
        name2 = "mesh2"
        mesh2.name = name2
        wrapper.add_dataset(mesh2)

        self.assertEqual(list(wrapper.get_dataset_names())[0], name1)
        self.assertEqual(list(wrapper.get_dataset_names())[1], name2)

    def test_iter_datasets(self):
        """Test iter_datasets method

        """

        sim = Simulation(self.cuds, 'OpenFOAM', engine_interface=self.engine)
        wrapper = sim._wrapper
        mesh2 = self.mesh
        mesh2.name = "mesh2"
        wrapper.add_dataset(mesh2)

        self.assertEqual(sum(1 for _ in wrapper.iter_datasets()), 2)

    def test_multiple_meshes(self):
        """Test multiple meshes inside wrapper

        """

        sim = Simulation(self.cuds, 'OpenFOAM', engine_interface=self.engine)
        wrapper = sim._wrapper
        mesh2 = self.mesh
        mesh2.name = "mesh2"
        wrapper.add_dataset(mesh2)
        mesh_inside_wrapper1 = wrapper.get_dataset(self.mesh.name)
        mesh_inside_wrapper2 = wrapper.get_dataset(mesh2.name)

        self.assertEqual(
            sum(1 for _ in mesh_inside_wrapper1.iter(item_type=CUBA.POINT)),
            sum(1 for _ in mesh_inside_wrapper2.iter(item_type=CUBA.POINT)))
示例#43
0
case_name = 'poiseuille'
mesh_name = 'poiseuille_mesh'

# create cuds
cuds = CUDS(name=case_name)

# physics model
cfd = api.Cfd(name='default model')

# these are already by default set in CFD
cfd.rheology_model = api.NewtonianFluidModel(name='newtonian')
cfd.thermal_model = api.IsothermalModel(name='isothermal')
cfd.turbulence_model = api.LaminarFlowModel(name='laminar')
cfd.compressibility_model = api.IncompressibleFluidModel(name='incompressible')
# add to cuds
cuds.add([cfd])

# material
mat = api.Material(name='a_material')
mat.data[CUBA.DENSITY] = 1.0
mat.data[CUBA.DYNAMIC_VISCOSITY] = 1.0
cuds.add([mat])

# time setting
sim_time = api.IntegrationTime(name='simulation_time',
                               current=0.0,
                               final=1.0,
                               size=0.01)
cuds.add([sim_time])

# solver parameter to write data
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 * foam.data[CUBA.DENSITY]
hb.relaxation_time = 0.0148 * foam.data[CUBA.DENSITY]
hb.linear_constant = 0.00268 * foam.data[CUBA.DENSITY]
hb.power_law_index = 0.5
hb.material = cuds.get_by_name('foam').uid
cfd.rheology_model = hb

cuds.add([cfd])

# time setting
sim_time = api.IntegrationTime(name='simulation_time',
                               current=0.0,
    def setUp(self):

        case_name = "simplemesh_parallel"
        mesh_name = "simplemesh_parallel_mesh"
        cuds = CUDS(name=case_name)
        # physics model
        cfd = api.Cfd(name='default model')
        cuds.add([cfd])

        self.sp = api.SolverParameter(name='solver_parameters')
        self.sp._data[CUBA.NUMBER_OF_CORES] = 4

        cuds.add([self.sp])

        sim_time = api.IntegrationTime(name='simulation_time',
                                       current=0.0,
                                       final=1.0,
                                       size=1.0)
        cuds.add([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)
示例#46
0
# Integration time for the fluid solver:
CFDitime = api.IntegrationTime(name="CFD_Integration_time")
CFDitime.time = 0.0001
CFDitime.step = 0.005
CFDitime.final = 0.0125  # 1 Kratos Timesteps

# Integration time for the particle solver
DEMitime = api.IntegrationTime(name="DEM_Integration_time")
DEMitime.time = 0.0001
DEMitime.step = 5e-5
DEMitime.final = 0.0125  # 5 Kratos Timesteps

COUiTime = api.IntegrationTime(name="COU_Inetegration_time")

cuds.add([COUiTime])

# Utils are used to read an existing Kratos model as raw data so we can
# initialize the correct simphony datasets. We can also use manualy written
# datasets.
cfd_utils = CFD_Utils()

# Reads kratos data as simphony datasets
model_fluid = cfd_utils.read_modelpart(pathFluid)

# Dem is generated on the script
smp_particles = []
smp_conditions = []
smp_materials = []

dem_pe = api.GranularDynamics()
case_name = 'vortex_shedding'
mesh_name = 'vortex_shedding_mesh'

# create cuds
cuds = CUDS(name=case_name)

# physics model
cfd = api.Cfd(name='default model')

# these are already by default set in CFD
cfd.rheology_model = api.NewtonianFluidModel(name='newtonian')
cfd.thermal_model = api.IsothermalModel(name='isothermal')
cfd.turbulence_model = api.LaminarFlowModel(name='laminar')
cfd.compressibility_model = api.IncompressibleFluidModel(name='incompressible')
# add to cuds
cuds.add([cfd])

# material
mat = api.Material(name='a_material')
mat.data[CUBA.DENSITY] = 1.0
mat.data[CUBA.DYNAMIC_VISCOSITY] = 2.0e-2
cuds.add([mat])

# time setting
sim_time = api.IntegrationTime(name='simulation_time',
                               current=0.0,
                               final=150.0,
                               size=0.025)
cuds.add([sim_time])

# create mesh