コード例 #1
0
ファイル: test_cuds.py プロジェクト: simphony/simphony-common
    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)
コード例 #2
0
ファイル: test_cuds.py プロジェクト: simphony/simphony-common
    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)
コード例 #3
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)
コード例 #4
0
ファイル: test_cuds.py プロジェクト: simphony/simphony-common
    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)
コード例 #5
0
ファイル: test_cuds.py プロジェクト: simphony/simphony-common
    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])
コード例 #6
0
ファイル: test_cuds.py プロジェクト: simphony/simphony-common
    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)
コード例 #7
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])
コード例 #8
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])
コード例 #9
0
ファイル: test_cuds.py プロジェクト: simphony/simphony-common
    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)
コード例 #10
0
    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])
コード例 #11
0
ファイル: test_cuds.py プロジェクト: simphony/simphony-common
    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])
コード例 #12
0
ファイル: test_cuds.py プロジェクト: simphony/simphony-common
    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])
コード例 #13
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)
コード例 #14
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])
コード例 #15
0
ファイル: test_cuds.py プロジェクト: simphony/simphony-common
    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)
コード例 #16
0
ファイル: test_cuds.py プロジェクト: simphony/simphony-common
    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])
コード例 #17
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)
コード例 #18
0
ファイル: test_cuds.py プロジェクト: simphony/simphony-common
    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)
コード例 #19
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
コード例 #20
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)
コード例 #21
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)
コード例 #22
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)
コード例 #23
0
ファイル: test_cuds.py プロジェクト: simphony/simphony-common
    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')
コード例 #24
0
    def test_run(self):
        get_engine_manager().register_extension(get_example_engine_extension())
        cuds = CUDS()
        engine_names = get_engine_manager().get_supported_engine_names()
        # There should be at least one dummy extension there
        self.assertGreater(len(engine_names), 0)
        engine_a_name = engine_names[0]
        engine_a = None
        for engine_ext in get_engine_manager().get_supported_engines():
            for engine in engine_ext.get_supported_engines():
                if engine.name == engine_a_name:
                    engine_a = engine

        self.assertIsNotNone(engine_a)
        self.assertGreater(len(engine_a.interfaces), 0)

        sim = Simulation(cuds, engine_a_name, engine_a.interfaces[0])
        sim.run()
        self.assertEqual(sim.get_cuds(), cuds)
コード例 #25
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)
コード例 #26
0
ファイル: dahl.py プロジェクト: simphony/simphony-openfoam
import foam_controlwrapper
from simphony.core.cuba import CUBA
from simphony.api import CUDS, Simulation
from simphony.cuds.meta import api
from simphony.engine import EngineInterface


from mayavi.scripts import mayavi2

import dahl_mesh
import tempfile

case_name = 'dahl'
mesh_name = 'dahl_mesh'

cuds = CUDS(name=case_name)

# 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)
コード例 #27
0
from simphony.core.cuba import CUBA

from mayavi.scripts import mayavi2

from simphony.api import CUDS, Simulation
from simphony.cuds.meta import api
from simphony.engine import EngineInterface

import tempfile
from foam_controlwrapper import create_quad_mesh

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
コード例 #28
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])
コード例 #29
0
    def test_add_non_cuds_component(self):
        c = CUDS()

        self.assertRaises(TypeError, c.add, object())
コード例 #30
0
    def test_cuds_data(self):
        c = CUDS()
        data = c.data

        self.assertEqual(c.data, data)
        self.assertIs(c.data, data, msg='data is a copy.')
コード例 #31
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
コード例 #32
0
from simphony.api import CUDS, Simulation
from simphony.cuds.meta import api
from simphony.engine import EngineInterface

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])
from simphony.api import CUDS, Simulation
from simphony.cuds.meta import api
from simphony.engine import EngineInterface

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])
コード例 #34
0
from simphony.api import CUDS, Simulation
from simphony.cuds.meta import api
from simphony.engine import EngineInterface

import tube_mesh

import tempfile

import time

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
コード例 #35
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)
コード例 #36
0
    def test_descriptioned_cuds_description(self):
        c = CUDS(description='test model')

        self.assertEqual(c.description, 'test model')
コード例 #37
0
    def test_descriptionless_cuds_description(self):
        c = CUDS()

        self.assertEqual(c.description, '')
コード例 #38
0
from simphony.core.cuba import CUBA

from mayavi.scripts import mayavi2

from simphony.api import CUDS, Simulation
from simphony.cuds.meta import api
from simphony.engine import EngineInterface

import tempfile
from foam_controlwrapper import create_quad_mesh

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
コード例 #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
ファイル: test_cuds.py プロジェクト: simphony/simphony-common
    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])
コード例 #41
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)
コード例 #42
0
ファイル: test_cuds.py プロジェクト: simphony/simphony-common
    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)
コード例 #43
0
    def test_cuds_uid(self):
        c = CUDS()

        self.assertIsNotNone(c.uid)
        self.assertIsInstance(c.uid, uuid.UUID)
コード例 #44
0
ファイル: test_cuds.py プロジェクト: simphony/simphony-common
    def test_add_cuds_component(self):
        c = CUDS()

        self.assertIsNone(c.add([self.named_cuds_1]))
        self.assertIsNone(c.add([self.nameless_cuds_1]))
コード例 #45
0
ファイル: dahl.py プロジェクト: simphony/simphony-openfoam
import foam_controlwrapper
from simphony.core.cuba import CUBA
from simphony.api import CUDS, Simulation
from simphony.cuds.meta import api
from simphony.engine import EngineInterface


from mayavi.scripts import mayavi2

import dahl_mesh
import tempfile

case_name = 'dahl'
mesh_name = 'dahl_mesh'

cuds = CUDS(name=case_name)

# 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)
コード例 #46
0
    def test_named_cuds_name(self):
        c = CUDS(name='mycuds')

        self.assertEqual(c.name, 'mycuds')
コード例 #47
0
""" This files provide a test example on how to use
Simphony along with the Kratos Multiphisics CFD wrapper

"""

import os

from simphony.api import CUDS, Simulation
from simphony.cuds.meta import api

from simkratos.CFD.kratos_CFD_utils import CFD_Utils

# Add the problem path to the script
path = os.path.join(os.path.dirname(__file__), "CFD_exampleFluid")

cuds = CUDS(name='example_fluid_name')

# Integration time:
itime = api.IntegrationTime(name="md_nve_integration_time")
itime.time = 0.0001
itime.step = 0.0025
itime.final = 0.0125  # 5 Kratos Timesteps
cuds.add([itime])

# 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 so its interpretable by simphony
model_fluid = cfd_utils.read_modelpart(path)
コード例 #48
0
    def test_nameless_cuds_name(self):
        c = CUDS()

        self.assertIs(c.name, '')
コード例 #49
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)))
コード例 #50
0
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)))
コード例 #51
0
from simphony.cuds.meta import api
from simphony.engine import EngineInterface

from foam_controlwrapper import create_block_mesh
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])
コード例 #52
0
    def test_add_nameless_dataset(self):
        ps = Particles(None)
        ps.add([Particle(), Particle()])
        c = CUDS()

        self.assertRaises(TypeError, c.add, [ps])
コード例 #53
0
        'datasets': smp_particles,
        'conditions': smp_conditions,
        'materials': smp_materials,
        'pe': smp_pe,
    }


def abs_path(relPath):
    return os.path.join(os.path.dirname(os.path.abspath(__file__)), relPath)


# Path for the Kratos' MDPA
pathFluid = abs_path("fluid_prism")
pathParticles = abs_path("fibers_and_ballsDEM")

cuds = CUDS(name='Coupling')

# 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")
コード例 #54
0
from simphony.core.cuba import CUBA
from simphony.api import CUDS, Simulation
from simphony.cuds.meta import api
from simphony.engine import EngineInterface

import vortex_shedding_mesh

import tempfile
import math

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