Ejemplo n.º 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)
Ejemplo n.º 2
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)
Ejemplo n.º 3
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)
Ejemplo n.º 4
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()
Ejemplo n.º 5
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)
Ejemplo n.º 6
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])
Ejemplo n.º 7
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])
Ejemplo n.º 8
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])
Ejemplo n.º 9
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)
Ejemplo n.º 10
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])
Ejemplo n.º 11
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)
Ejemplo n.º 12
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)
Ejemplo n.º 13
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()
Ejemplo n.º 14
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])
Ejemplo n.º 15
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)
Ejemplo n.º 16
0
    def test_add_non_cuds_component(self):
        c = CUDS()

        self.assertRaises(TypeError, c.add, object())
Ejemplo n.º 17
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]))
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])
Ejemplo n.º 19
0
    def test_descriptioned_cuds_description(self):
        c = CUDS(description='test model')

        self.assertEqual(c.description, 'test model')
Ejemplo n.º 20
0
    def test_nameless_cuds_name(self):
        c = CUDS()

        self.assertIs(c.name, '')
Ejemplo n.º 21
0
    def test_named_cuds_name(self):
        c = CUDS(name='mycuds')

        self.assertEqual(c.name, 'mycuds')
Ejemplo n.º 22
0
    def test_cuds_uid(self):
        c = CUDS()

        self.assertIsNotNone(c.uid)
        self.assertIsInstance(c.uid, uuid.UUID)
Ejemplo n.º 23
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)
Ejemplo n.º 24
0
from simphony.api import CUDS, Simulation
from simphony.cuds.meta import api

from simkratos.DEM.kratos_DEM_utils import DEM_Utils


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


# Path for the Kratos' MDPA
pathParticles = abs_path("3ballsDEM")
pathSolid = abs_path("3ballsDEM_FEM_boundary")

cuds = CUDS(name='example_kratos_dem_somulation')

# Integration time:
itime = api.IntegrationTime(name="dem_integration_time")
itime.time = 0.0001
itime.step = 0.001
itime.final = 60 * itime.step
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.
utils = DEM_Utils()

# Reads Kratos mpda as a simphony data.
model_particles = utils.read_modelpart_as_particles(pathParticles)
Ejemplo n.º 25
0
    def test_descriptionless_cuds_description(self):
        c = CUDS()

        self.assertEqual(c.description, '')
Ejemplo n.º 26
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)
Ejemplo n.º 27
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.')
Ejemplo n.º 28
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")
Ejemplo n.º 29
0
    def test_add_nameless_dataset(self):
        ps = Particles(None)
        ps.add([Particle(), Particle()])
        c = CUDS()

        self.assertRaises(TypeError, c.add, [ps])