def test_complex(self):
        with GMSHSession() as session:

            # initialize wrapper
            wrapper = cuba.Wrapper(session=session)

            # get file path of complex shape
            file_path = os.path.join(path, 'cone.stl')

            # create CUDS for complex shape
            comp = Complex(file_path,
                           values={
                               'inside_point': [0, 0, 5],
                               'filling_fraction': 0.5
                           },
                           units={'lengths': 'mm'},
                           session=session)
            wrapper.add(comp.get_model(), rel=emmo.hasPart)
            session.run()

            complex_extent = extent(min_extent=[-5.0, -5.0, 0.0],
                                    max_extent=[5.0, 5.0, 10.0])
            filling_extent = extent(min_extent=[-5.0, -5.0, 0.0],
                                    max_extent=[5.0, 5.0, 5.0])

            meta_data = cuds_to_meta_data(wrapper)
            for ax in complex_extent.keys():
                for direction in complex_extent[ax].keys():
                    self.assertEqual(meta_data[0][ax][direction],
                                     complex_extent[ax][direction])
                    self.assertEqual(meta_data[1][ax][direction],
                                     filling_extent[ax][direction])
            volume = 1 / 3 * (np.pi * 0.05**2 * 0.1) * 1e-3
            self.assertAlmostEqual(volume, meta_data[2], delta=1.5e-6)
            self.assertListEqual([0, 0, 5], meta_data[3])
Exemple #2
0
 def test_update_mesh_dimensions(self):
     blockmesh_extent = extent([0, 0, 0], [5, 10, 20])
     self.data_dict.update_mesh_dimensions(blockmesh_extent)
     for ax in blockmesh_extent.keys():
         for direction in blockmesh_extent[ax].keys():
             self.assertEqual(self.data_dict.data[ax + direction],
                              blockmesh_extent[ax][direction])
    def setUp(self):
        # Define rectangular mesh and its properties
        self.rectangular = RectangularMesh(length=20,
                                           width=10,
                                           height=150,
                                           resolution=4,
                                           filling_fraction=0.5,
                                           units="mm")
        self.rectangular_block_extent = extent(max_extent=[20, 10, 150])
        self.rectangular_filling_extent = [[0, 0, 0], [0.02, 0.01, 0.075]]
        self.rectangular_ncells = [80, 40, 600]
        self.rectangular_volume = 30000

        # Define cylindrical mesh and its properties
        self.cylinder = CylinderMesh(radius=5,
                                     height=20,
                                     resolution=7,
                                     filling_fraction=0.5,
                                     units="cm")
        self.cylinder_stl_extent = extent([-0.05, -0.05, 0], [0.05, 0.05, 0.2])
        self.cylinder_block_extent = extent([-5, -5, 0], [5, 5, 20])
        self.cylinder_filling_extent = [0.05, 0.1]
        self.cylinder_ncells = [70, 70, 140]
        self.cylinder_location = [0, 0, 0.1]
        self.cylinder_volume = 25 * 20 * np.pi

        # Define complex mesh and its properties
        self.complex_radius = 5
        self.complex_height = 10
        self.complex_resolution = 10
        self.complex = ComplexMesh(source_path=get("cone.stl"),
                                   inside_location=[0, 0, 5],
                                   resolution=10,
                                   filling_fraction=0.5,
                                   units="cm")
        self.complex_stl_extent = extent([-0.05, -0.05, 0], [0.05, 0.05, 0.1])
        self.complex_block_extent = extent([-5, -5, 0], [5, 5, 10])
        self.complex_filling_extent = [[-0.05, -0.05, 0], [0.05, 0.05, 0.05]]
        self.complex_ncells = [100, 100, 100]
        self.complex_location = [0, 0, 0.05]
        self.complex_cutoff = 0.5
        self.complex_volume = 1 / 3 * (np.pi * self.complex_radius**2 *
                                       self.complex_height)
        self.complex_volume_cutoff = 1 / 3 * (
            self.complex_radius *
            (1 - self.complex_cutoff))**2 * np.pi * (self.complex_height *
                                                     self.complex_cutoff)
Exemple #4
0
 def _syntactic_extent(self, entity):
     extent_data = extent()
     for axis in MAPPING.keys():
         for direction in MAPPING[axis].keys():
             extent_data[axis][direction] = self._to_meters(
                 entity.get(rel=MAPPING[axis][direction])[0]
             )
     return extent_data
    def test_cylinder(self):
        with GMSHSession() as session, TemporaryDirectory() as temp_dir:

            wrapper = cuba.Wrapper(session=session)

            cyl = Cylinder(temp_dir,
                           values={
                               'length': 20,
                               'radius': 5,
                               'filling_fraction': 0.5,
                               'resolution': 0.14
                           },
                           units={
                               'lengths': "cm",
                               'resolution': "cm"
                           },
                           session=session)

            wrapper.add(cyl.get_model(), rel=emmo.hasPart)
            wrapper.session.run()
            meta_data = cuds_to_meta_data(wrapper)

            stl_path = os.path.join(temp_dir, 'new_surface.stl')
            geo_path = os.path.join(temp_dir, 'new_surface.geo')
            stl_ref = os.path.join(path, 'cylinder_ref.stl')
            geo_ref = os.path.join(path, 'cylinder_ref.geo')

            self.assertTrue(os.path.exists(geo_path))
            self.assertTrue(os.path.exists(stl_path))
            self.compare_files(geo_path, geo_ref)
            self.compare_files(stl_path, stl_ref)

            cyl_extent = extent([-0.05, -0.05, 0], [0.05, 0.05, 0.2])
            filling_extent = extent([-0.05, -0.05, 0], [0.05, 0.05, 0.1])

            for ax in cyl_extent.keys():
                for direction in cyl_extent[ax].keys():
                    self.assertEqual(meta_data[0][ax][direction],
                                     cyl_extent[ax][direction])
                    self.assertEqual(meta_data[1][ax][direction],
                                     filling_extent[ax][direction])
            self.assertAlmostEqual(0.2 * 0.05**2 * np.pi,
                                   meta_data[2],
                                   delta=1.5e-6)
            self.assertListEqual([0, 0, 0.1], meta_data[3])
    def test_rectangle(self):
        with GMSHSession() as session, TemporaryDirectory() as temp_dir:

            wrapper = cuba.Wrapper(session=session)

            rec = Rectangle(temp_dir,
                            values={
                                'x': 20,
                                'y': 10,
                                'z': 150,
                                'filling_fraction': 0.5,
                                'resolution': 1
                            },
                            units={
                                'lengths': "mm",
                                'resolution': "mm"
                            },
                            session=session)

            wrapper.add(rec.get_model(), rel=emmo.hasPart)
            wrapper.session.run()
            meta_data = cuds_to_meta_data(wrapper)

            stl_path = os.path.join(temp_dir, 'new_surface.stl')
            geo_path = os.path.join(temp_dir, 'new_surface.geo')
            stl_ref = os.path.join(path, 'rectangle_ref.stl')
            geo_ref = os.path.join(path, 'rectangle_ref.geo')

            self.assertTrue(os.path.exists(geo_path))
            self.assertTrue(os.path.exists(stl_path))
            self.compare_files(geo_path, geo_ref)
            self.compare_files(stl_path, stl_ref)

            rec_extent = extent(max_extent=[0.02, 0.01, 0.15])
            filling_extent = extent(max_extent=[0.02, 0.01, 0.075])

            for ax in rec_extent.keys():
                for direction in rec_extent[ax].keys():
                    self.assertEqual(meta_data[0][ax][direction],
                                     rec_extent[ax][direction])
                    self.assertEqual(meta_data[1][ax][direction],
                                     filling_extent[ax][direction])
            self.assertEqual(3e-5, meta_data[2])
            self.assertListEqual([0.01, 0.005, 0.075], meta_data[3])
    def test_update_stl_data(self):
        stl_extent = extent([-1] * 3, [1] * 3)
        location = [100, 55, -3]

        surface_dict = self.data_dict.data['geometry']
        controls_dict = self.data_dict.data['castellatedMeshControls']

        self.data_dict.update_stl_data(stl_extent, location)
        surface_dict = self.data_dict.data['geometry']
        controls_dict = self.data_dict.data['castellatedMeshControls']
        self.assertListEqual([-1, -1, -1],
                             surface_dict["refinementBox"]["min"])
        self.assertListEqual([1, 1, 1], surface_dict["refinementBox"]["max"])
        self.assertListEqual(controls_dict['locationInMesh'], location)
 def __init__(self):
     super().__init__()
     self.add_data({
         "#includeEtc": library,
         "castellatedMesh": 'on',
         "snap": 'off',
         "addLayers": 'off',
         "geometry": get_geometry_data(extent()),
         'castellatedMeshControls': get_mesh_controls([0, 0, 0]),
         'snapControls': snap_controls.copy(),
         'addLayersControls': layers_controls.copy(),
         'meshQualityControls': {},
         'writeFlags': write_flags,
         'mergeTolerance': 1e-6
     })
Exemple #9
0
    def setUp(self):
        # Define rectangular mesh and its properties
        self.rectangular = RectangularMesh(
            x_length=0.02,
            y_length=0.01,
            z_length=0.15,
            resolution=0.001,
            filling_fraction=0.5,
            units="m"
        )
        self.rectangular_max_extent = extent(
            max_extent=[0.02, 0.01, 0.15]
        )
        self.rectangular_filling_extent = extent(
            max_extent=[0.02, 0.01, 0.075]
        )
        self.rectangular_inside_location = [0.01, 0.005, 0.075]
        self.rectangular_volume = 3e-5
        self.rectangular_stl_ref = os.path.join(
            path, 'rectangle_ref.stl'
        )
        self.rectangular_geo_ref = os.path.join(
            path, 'rectangle_ref.geo'
        )
        # Define cylindrical mesh and its properties
        self.cylinder = CylinderMesh(
            xy_radius=0.05,
            z_length=0.2,
            resolution=0.0014,
            filling_fraction=0.5,
            units="m"
        )
        self.cylinder_max_extent = extent(
            [-0.05, -0.05, 0], [0.05, 0.05, 0.2]
        )
        self.cylinder_filling_extent = extent(
            [-0.05, -0.05, 0], [0.05, 0.05, 0.1]
        )
        self.cylinder_inside_location = [0, 0, 0.1]
        self.cylinder_volume = 0.025**2*0.2*np.pi
        self.cylinder_stl_ref = os.path.join(
            path, 'cylinder_ref.stl'
        )
        self.cylinder_geo_ref = os.path.join(
            path, 'cylinder_ref.geo'
        )

        # Define complex mesh and its properties
        self.complex_xy_radius = 5
        self.complex_z_length = 10
        self.complex_cutoff = 0.5
        self.complex = ComplexMesh(
            source_path=os.path.join(path, "cone.stl"),
            inside_location=[0.0, 0.0, 5.0],
            filling_fraction=0.5,
            units="mm"
        )
        self.complex_max_extent = extent(
            [-5.0, -5.0, 0.0], [5.0, 5.0, 10.0]
        )
        self.complex_filling_extent = extent(
            [-5.0, -5.0, 0.0], [5.0, 5.0, 5.0]
        )
        self.complex_inside_location = [0.0, 0.0, 5.0]
        self.complex_volume = 1/3*(np.pi*5**2*10)
        self.complex_volume_cutoff = \
            1/3*(5/10*10*0.5)**2*np.pi*(10*0.5)
Exemple #10
0
import os
from decimal import Decimal
import numpy as np
from osp.core.session import WrapperSession
from osp.core.namespaces import emmo
from osp.wrappers.gmsh_wrapper.gmsh_engine import (
    RectangularMesh, CylinderMesh, ComplexMesh, CONVERSIONS, extent
)


MAPPING = extent(
    min_extent=[
        emmo.hasMinimumXCoordinate,
        emmo.hasMinimumYCoordinate,
        emmo.hasMinimumZCoordinate
    ],
    max_extent=[
        emmo.hasMaximumXCoordinate,
        emmo.hasMaximumYCoordinate,
        emmo.hasMaximumZCoordinate
    ]
)


class GMSHSession(WrapperSession):

    """
    Session class for GMSH.
    """

    def __init__(self, **kwargs):
        super().__init__(engine=None, **kwargs)