Exemple #1
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()
Exemple #2
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)
    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)
Exemple #4
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()
Exemple #5
0
simPRO = Simulation(cuds, "KRATOS_PRO", engine_interface=True)
simGID = Simulation(cuds, "KRATOS_GID", engine_interface=True)

for step in xrange(0, 10):

    # Set interval times
    CFDitime.final = 0.0125 * (step + 1)  # 5 Kratos Timesteps
    DEMitime.final = 0.0125 * (step + 1)  # 5 Kratos Timesteps

    # Make sure the timestep between wrappers are consistent
    COUiTime.time = 0.0125 * (step + 0)
    COUiTime.step = CFDitime.step
    COUiTime.final = CFDitime.final

    # Run the CFD
    simCFD.run()

for step in xrange(0, 100):
    # Projects the velocity from the fluid to the particles
    simPRO.run()

    # Coupling ( For both the particle and the fiber)
    simple_coupling(cuds, particles_dataset_name)
    simple_coupling(cuds, fibers_dataset_name)

    # Make sure the timestep between wrappers are consistent
    COUiTime.time = 0.0125 * (step + 0)
    COUiTime.step = DEMitime.step
    COUiTime.final = 0.0125 * (step + 0) + COUiTime.step * 10

    # Run the DEM
walls = api.Boundary(name='walls', condition=[vel_walls, pres_walls])
outlet = api.Boundary(name='outlet', condition=[vel_outlet, pres_outlet])

cuds.add([inlet, walls, outlet])

end = time.time()
print "Time spend in boundary settings: ", end - start

start = time.time()
sim = Simulation(cuds, 'OpenFOAM', engine_interface=EngineInterface.Internal)
end = time.time()
print "Time spend in Simulation initialization: ", end - start

start = time.time()

sim.run()
end = time.time()
print "Time spend in run: ", end - start

start = time.time()
mesh_in_engine = cuds.get_by_name(mesh_name)
print "Working directory ", mesh_in_engine.path
average_pressure = 0.0
for cell in mesh_in_engine.get_boundary_cells(inlet.name):
    average_pressure += cell.data[CUBA.PRESSURE]

average_pressure /= len(mesh_in_engine._boundaries[inlet.name])
end = time.time()
print "Time spend in post processing: ", end - start

print "Average pressure on inlet: ", average_pressure
walls = api.Boundary(name='walls', condition=[vel_walls, pres_walls])
outlet = api.Boundary(name='outlet', condition=[vel_outlet, pres_outlet])

cuds.add([inlet, walls, outlet])

end = time.time()
print "Time spend in boundary settings: ", end-start

start = time.time()
sim = Simulation(cuds, 'OpenFOAM', engine_interface=EngineInterface.Internal)
end = time.time()
print "Time spend in Simulation initialization: ", end-start

start = time.time()

sim.run()
end = time.time()
print "Time spend in run: ", end-start

start = time.time()
mesh_in_engine = cuds.get_by_name(mesh_name)
print "Working directory ", mesh_in_engine.path
average_pressure = 0.0
for cell in mesh_in_engine.get_boundary_cells(inlet.name):
    average_pressure += cell.data[CUBA.PRESSURE]

average_pressure /= len(mesh_in_engine._boundaries[inlet.name])
end = time.time()
print "Time spend in post processing: ", end-start

print "Average pressure on inlet: ", average_pressure
class WrapperRunTestCase(unittest.TestCase):
    def setUp(self):

        case_name = "simplemeshIO"
        mesh_name = "simplemeshIO_mesh"

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

        self.sim_time = api.IntegrationTime(name='simulation_time',
                                            current=0.0,
                                            final=1.0,
                                            size=0.5)
        cuds.add([self.sim_time])

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

        vel_inlet = api.Dirichlet(mat, name='vel_inlet')
        vel_inlet._data[CUBA.VARIABLE] = CUBA.VELOCITY
        vel_inlet._data[CUBA.VELOCITY] = (0.1, 0, 0)
        pres_inlet = api.Neumann(mat, name='pres_inlet')
        pres_inlet._data[CUBA.VARIABLE] = CUBA.PRESSURE

        vel_outlet = api.Neumann(mat, name='vel_outlet')
        vel_outlet._data[CUBA.VARIABLE] = CUBA.VELOCITY
        pres_outlet = api.Dirichlet(mat, name='pres_outlet')
        pres_outlet._data[CUBA.VARIABLE] = CUBA.PRESSURE
        pres_outlet._data[CUBA.PRESSURE] = 0.0

        vel_walls = api.Dirichlet(mat, name='vel_walls')
        vel_walls._data[CUBA.VARIABLE] = CUBA.VELOCITY
        vel_walls._data[CUBA.VELOCITY] = (0, 0, 0)
        pres_walls = api.Neumann(mat, name='pres_walls')
        pres_walls._data[CUBA.VARIABLE] = CUBA.PRESSURE

        vel_frontAndBack = api.EmptyCondition(name='vel_frontAndBack')
        vel_frontAndBack._data[CUBA.VARIABLE] = CUBA.VELOCITY
        pres_frontAndBack = api.EmptyCondition(name='pres_frontAndBack')
        pres_frontAndBack._data[CUBA.VARIABLE] = CUBA.PRESSURE

        inlet = api.Boundary(name='inlet', condition=[vel_inlet, pres_inlet])
        walls = api.Boundary(name='walls', condition=[vel_walls, pres_walls])
        outlet = api.Boundary(name='outlet',
                              condition=[vel_outlet, pres_outlet])
        frontAndBack = api.Boundary(
            name='frontAndBack',
            condition=[vel_frontAndBack, pres_frontAndBack])

        cuds.add([inlet, walls, outlet, frontAndBack])

        corner_points = [(0.0, 0.0, 0.0), (5.0, 0.0, 0.0), (5.0, 5.0, 0.0),
                         (0.0, 5.0, 0.0), (0.0, 0.0, 1.0), (5.0, 0.0, 1.0),
                         (5.0, 5.0, 1.0), (0.0, 5.0, 1.0)]
        self.mesh_path = tempfile.mkdtemp()
        mesh = create_quad_mesh(self.mesh_path, mesh_name, corner_points, 5, 5,
                                5)
        cuds.add([mesh])
        self.cuds = cuds
        self.sim = Simulation(cuds,
                              'OpenFOAM',
                              engine_interface=EngineInterface.FileIO)
        self.mesh_in_cuds = self.cuds.get_by_name(mesh_name)

    def tearDown(self):
        if os.path.exists(self.mesh_in_cuds.path):
            shutil.rmtree(self.mesh_in_cuds.path)
        if os.path.exists(self.mesh_path):
            shutil.rmtree(self.mesh_path)

    def test_run_time(self):
        """Test that field variable value is changed after
        consecutive calls of run method

        """

        self.sim.run()

        for cell in self.mesh_in_cuds.iter(item_type=CUBA.CELL):
            old_vel = cell.data[CUBA.VELOCITY]
            old_pres = cell.data[CUBA.PRESSURE]
            cell_uid = cell.uid

        self.sim.run()

        cell = self.mesh_in_cuds.get(cell_uid)
        new_vel = cell.data[CUBA.VELOCITY]
        new_pres = cell.data[CUBA.PRESSURE]

        self.assertNotEqual(old_vel, new_vel)
        self.assertNotEqual(old_pres, new_pres)
class WrapperRunTestCase(unittest.TestCase):
    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)

    def tearDown(self):
        if os.path.exists(self.mesh_in_cuds.path):
            shutil.rmtree(self.mesh_in_cuds.path)
        if os.path.exists(self.mesh_path):
            shutil.rmtree(self.mesh_path)

    def test_parallel_run(self):
        """Test parallel running of OpenFoam

        """

        self.sim.run()

        self.assertEqual(self.sp._data[CUBA.NUMBER_OF_CORES],
                         len([d for d in
                              os.listdir(self.mesh_in_cuds.path)
                              if re.match(r'processor*', d)]))
class WrapperRunTestCase(unittest.TestCase):
    def setUp(self):

        case_name = "simplemeshIO"
        mesh_name = "simplemeshIO_mesh"

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

        self.sim_time = api.IntegrationTime(name='simulation_time',
                                            current=0.0,
                                            final=1.0,
                                            size=0.5)
        cuds.add([self.sim_time])

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

        vel_inlet = api.Dirichlet(mat, name='vel_inlet')
        vel_inlet._data[CUBA.VARIABLE] = CUBA.VELOCITY
        vel_inlet._data[CUBA.VELOCITY] = (0.1, 0, 0)
        pres_inlet = api.Neumann(mat, name='pres_inlet')
        pres_inlet._data[CUBA.VARIABLE] = CUBA.PRESSURE

        vel_outlet = api.Neumann(mat, name='vel_outlet')
        vel_outlet._data[CUBA.VARIABLE] = CUBA.VELOCITY
        pres_outlet = api.Dirichlet(mat, name='pres_outlet')
        pres_outlet._data[CUBA.VARIABLE] = CUBA.PRESSURE
        pres_outlet._data[CUBA.PRESSURE] = 0.0

        vel_walls = api.Dirichlet(mat, name='vel_walls')
        vel_walls._data[CUBA.VARIABLE] = CUBA.VELOCITY
        vel_walls._data[CUBA.VELOCITY] = (0, 0, 0)
        pres_walls = api.Neumann(mat, name='pres_walls')
        pres_walls._data[CUBA.VARIABLE] = CUBA.PRESSURE

        vel_frontAndBack = api.EmptyCondition(name='vel_frontAndBack')
        vel_frontAndBack._data[CUBA.VARIABLE] = CUBA.VELOCITY
        pres_frontAndBack = api.EmptyCondition(name='pres_frontAndBack')
        pres_frontAndBack._data[CUBA.VARIABLE] = CUBA.PRESSURE

        inlet = api.Boundary(name='inlet', condition=[vel_inlet, pres_inlet])
        walls = api.Boundary(name='walls', condition=[vel_walls, pres_walls])
        outlet = api.Boundary(name='outlet', condition=[vel_outlet,
                                                        pres_outlet])
        frontAndBack = api.Boundary(name='frontAndBack',
                                    condition=[vel_frontAndBack,
                                               pres_frontAndBack])

        cuds.add([inlet, walls, outlet, frontAndBack])

        corner_points = [(0.0, 0.0, 0.0), (5.0, 0.0, 0.0),
                         (5.0, 5.0, 0.0), (0.0, 5.0, 0.0),
                         (0.0, 0.0, 1.0), (5.0, 0.0, 1.0),
                         (5.0, 5.0, 1.0), (0.0, 5.0, 1.0)]
        self.mesh_path = tempfile.mkdtemp()
        mesh = create_quad_mesh(self.mesh_path, mesh_name,
                                corner_points, 5, 5, 5)
        cuds.add([mesh])
        self.cuds = cuds
        self.sim = Simulation(cuds, 'OpenFOAM',
                              engine_interface=EngineInterface.FileIO)
        self.mesh_in_cuds = self.cuds.get_by_name(mesh_name)

    def tearDown(self):
        if os.path.exists(self.mesh_in_cuds.path):
            shutil.rmtree(self.mesh_in_cuds.path)
        if os.path.exists(self.mesh_path):
            shutil.rmtree(self.mesh_path)

    def test_run_time(self):
        """Test that field variable value is changed after
        consecutive calls of run method

        """

        self.sim.run()

        for cell in self.mesh_in_cuds.iter(item_type=CUBA.CELL):
            old_vel = cell.data[CUBA.VELOCITY]
            old_pres = cell.data[CUBA.PRESSURE]
            cell_uid = cell.uid

        self.sim.run()

        cell = self.mesh_in_cuds.get(cell_uid)
        new_vel = cell.data[CUBA.VELOCITY]
        new_pres = cell.data[CUBA.PRESSURE]

        self.assertNotEqual(old_vel, new_vel)
        self.assertNotEqual(old_pres, new_pres)