def setUp(self):
     self.factory = TimeSeriesProfilerFactory(plugin={
         'id': '0',
         'name': 'test'
     })
     self.data_source = self.factory.create_data_source()
     self.model = self.factory.create_model()
     self.height_profile = np.load(get('test_height_profile.npy'))
     self.temp_profile = np.load(get('test_height_profile.npy'))
     self.x_data = [0.1, 0.2, 0.3, 0.4, 1.0]
class TestSurfaceFeatureExtractData(TestCase):
    control_file_path = fixtures_path.get("surfaceFeatureExtractDict")

    def setUp(self):
        self.data_dict = SurfaceFeatureExtractData('new_surface.stl')

    def test_update_mesh_file_name(self):
        self.assertEqual('new_surface.stl', self.data_dict._file_name)
        self.assertIn('new_surface.stl', self.data_dict.data)

        self.data_dict.update_mesh_file('another_file')
        self.assertEqual('another_file', self.data_dict._file_name)
        self.assertNotIn('new_surface.stl', self.data_dict.data)
        self.assertIn('another_file.stl', self.data_dict.data)

    def test_write_file(self):

        with TemporaryDirectory() as temp_dir:
            self.data_dict.write_to_file(path=temp_dir)

            file_path = os.path.join(
                temp_dir, self.data_dict.file_localpath)

            with open(self.control_file_path) as control_file:
                control_data = control_file.readlines()
            with open(file_path) as test_file:
                test_data = test_file.readlines()

            # Update control_data info with location of temporary file used
            # for testing
            control_data[5] = test_data[5]
            self.assertEqual(control_data, test_data)
Esempio n. 3
0
class TestMeshData(TestCase):

    control_file_path = fixtures_path.get("blockMeshDict")

    def setUp(self):
        self.data_dict = BlockMeshData()

    def test_write_file(self):

        with TemporaryDirectory() as temp_dir:
            self.data_dict.write_to_file(path=temp_dir)

            file_path = os.path.join(temp_dir, self.data_dict.file_localpath)

            with open(self.control_file_path) as control_file:
                control_data = control_file.readlines()
            with open(file_path) as test_file:
                test_data = test_file.readlines()

            # Update control_data info with location of temporary file
            # used for testing
            control_data[5] = test_data[5]
            control_data = "".join(control_data).replace(" ", "")
            test_data = "".join(test_data).replace(" ", "")
            self.assertEqual(control_data, test_data)

    def test_update_data(self):
        is_updated = self.data_dict.update_data("boundary.Wall.type",
                                                "not_a_wall")
        self.assertTrue(is_updated)
        self.assertEqual("not_a_wall",
                         self.data_dict.data["boundary"][0]["Wall"]["type"])

        is_updated = self.data_dict.update_data("boundary.atmosphere.type",
                                                "not_a_patch")
        self.assertTrue(is_updated)
        self.assertEqual(
            "not_a_patch",
            self.data_dict.data["boundary"][0]["atmosphere"]["type"],
        )
        self.assertEqual("not_a_wall",
                         self.data_dict.data["boundary"][0]["Wall"]["type"])

        is_updated = self.data_dict.update_data("mergePatchPairs.not_a_label",
                                                42)
        self.assertFalse(is_updated)

    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):
        self.plugin = {'id': '0', 'name': 'test'}
        self.factory = PUFoamPostProcessingFactory(plugin=self.plugin)
        self.data_source = self.factory.create_data_source()
        self.model = self.factory.create_model()

        self.filepath = get("cellSource.dat")
        self.mesh = DummyRectangularMesh()
        self.markers, self.data = self.data_source.read_datafile(
            self.filepath, {"n_system_lines": self.model.n_system_lines}
        )
Esempio n. 5
0
 def setUp(self):
     self.factory = PUFoamFactory(plugin={'id': '0', 'name': 'test'})
     self.data_source = self.factory.create_data_source()
     self.model = self.factory.create_model()
     self.rectangle = RectangularMesh(length=10,
                                      width=2,
                                      height=20,
                                      resolution=5,
                                      units="cm")
     self.cylinder = CylinderMesh(radius=6, resolution=10, units="cm")
     self.complex = ComplexMesh(source_path=get("cone.stl"),
                                inside_location=[0, 0, 2.5],
                                units="cm")
    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)
 def test_read_data(self):
     filepath = get("cellSource.dat")
     markers, data = self.data_source.read_datafile(
         filepath, {"n_system_lines": self.model.n_system_lines}
     )
     self.assertEqual(
         [
             "Time",
             "volAverage(alpha.gas)",
             "volAverage(muFoamCorr)",
             "volAverage(mZero)",
             "volAverage(mOne)",
             "volAverage(rho_foam)",
             "volAverage(rho)",
             "volAverage(TS)",
         ],
         markers,
     )
     self.assertEqual((50, 8), data.shape)
Esempio n. 8
0
class TestControlDictData(TestCase):

    control_file_path = fixtures_path.get("controlDict")

    def setUp(self):
        self.data_dict = ControlDictData()

    def test_write_file(self):
        with TemporaryDirectory() as temp_dir:
            self.data_dict.write_to_file(path=temp_dir)

            file_path = os.path.join(temp_dir, self.data_dict.file_localpath)

            with open(self.control_file_path) as control_file:
                control_data = control_file.readlines()
            with open(file_path) as test_file:
                test_data = test_file.readlines()

            # Update control_data info with location of temporary file
            # used for testing
            control_data[5] = test_data[5]
            self.assertEqual(control_data, test_data)
    def test_write_file(self):

        for mesh_type, control_dict in zip(
            ('Box', 'Cylinder'),
            ("setFieldsDict_box", "setFieldsDict_cylinder")):
            self.data_dict.mesh_type = mesh_type
            self.control_file_path = fixtures_path.get(control_dict)
            with TemporaryDirectory() as temp_dir:
                self.data_dict.write_to_file(path=temp_dir)

                file_path = os.path.join(temp_dir,
                                         self.data_dict.file_localpath)

                with open(self.control_file_path) as control_file:
                    control_data = control_file.readlines()
                with open(file_path) as test_file:
                    test_data = test_file.readlines()

                # Update control_data info with location of temporary file
                # used for testing
                control_data[5] = test_data[5]
                self.assertEqual(control_data, test_data)
class TestSnappyHexMeshData(TestCase):
    control_file_path = fixtures_path.get("snappyHexMeshDict")

    def setUp(self):
        self.data_dict = SnappyHexMeshData()

    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 test_write_file(self):

        with TemporaryDirectory() as temp_dir:
            self.data_dict.write_to_file(path=temp_dir)

            file_path = os.path.join(temp_dir, self.data_dict.file_localpath)

            with open(self.control_file_path) as control_file:
                control_data = control_file.readlines()
            with open(file_path) as test_file:
                test_data = test_file.readlines()

            # Update control_data info with location of temporary file used
            # for testing
            control_data[5] = test_data[5]
            self.assertEqual(control_data, test_data)
class TestKineticsData(TestCase):

    control_file_path = fixtures_path.get("control_kinetics")

    def setUp(self):
        self.data_dict = KineticData()

    def test_file_properties(self):
        self.assertEqual(
            '"constant"', self.data_dict.data["FoamFile"]["location"]
        )
        self.assertEqual(
            "kineticsProperties", self.data_dict.data["FoamFile"]["object"]
        )
        self.assertEqual(
            os.path.join("constant", "kineticsProperties"),
            self.data_dict.file_localpath
        )

    def test_write_file(self):

        with TemporaryDirectory() as temp_dir:
            self.data_dict.write_to_file(path=temp_dir)

            file_path = os.path.join(
                temp_dir, self.data_dict.file_localpath)

            with open(self.control_file_path) as control_file:
                control_data = control_file.readlines()
            with open(file_path) as test_file:
                test_data = test_file.readlines()

            # Update control_data info with location of temporary file used
            # for testing
            control_data[5] = test_data[5]
            self.assertEqual(control_data, test_data)
class TestPUFoamDataDict(TestCase):
    updates = (
        ("Entry", "new"),
        ("dispersion", -1),
        ("entry_2", -1),
        ("Group", {"new_entry": "new_data"}),
        ("ListGroup", 42),
        ("dict_entry", -41),
    )
    control_file_path = fixtures_path.get("control_file")

    def setUp(self):
        self.data_dict = PUFoamDataDict()
        self.data_dict.data = {
            **self.data_dict.data,
            "Group": {"entry_1": 1, "entry_2": 2},
            "Entry": 42,
            "Group2": {"entry_1": 100, "entry_2": 200},
            "ListGroup": [[1, 2, 3], {"dict_entry": 41}],
        }

    def test_update_by_label(self):
        is_updated = self.data_dict.update_data(*self.updates[0])
        self.assertTrue(is_updated)
        self.assertEqual("new", self.data_dict.data["Entry"])

        is_updated = self.data_dict.update_data(*self.updates[1])
        self.assertFalse(is_updated)

        is_updated = self.data_dict.update_data(*self.updates[2])
        self.assertTrue(is_updated)
        self.assertEqual(-1, self.data_dict.data["Group"]["entry_2"])
        self.assertEqual(200, self.data_dict.data["Group2"]["entry_2"])

        is_updated = self.data_dict.update_data(*self.updates[3])
        self.assertTrue(is_updated)
        self.assertEqual(
            {"new_entry": "new_data"}, self.data_dict.data["Group"]
        )

        is_updated = self.data_dict.update_data(*self.updates[5])
        self.assertTrue(is_updated)
        self.assertEqual(
            -41, self.data_dict.data["ListGroup"][1]["dict_entry"]
        )

        is_updated = self.data_dict.update_data(*self.updates[4])
        self.assertTrue(is_updated)
        self.assertEqual(42, self.data_dict.data["ListGroup"])

    def test_update_by_sequence(self):
        is_updated = self.data_dict.update_data("Group.entry_1", -1)
        self.assertTrue(is_updated)
        self.assertEqual(-1, self.data_dict.data["Group"]["entry_1"])
        self.assertEqual(100, self.data_dict.data["Group2"]["entry_1"])

        is_updated = self.data_dict.update_data("Group2.entry_1", -100)
        self.assertTrue(is_updated)
        self.assertEqual(-1, self.data_dict.data["Group"]["entry_1"])
        self.assertEqual(-100, self.data_dict.data["Group2"]["entry_1"])

        is_updated = self.data_dict.update_data("Group2.entry_3", -100)
        self.assertFalse(is_updated)

    def test_file_location(self):
        self.assertEqual('default', self.data_dict.file_localpath)

        directory = os.path.join("some", "path")

        self.data_dict.data["FoamFile"]["location"] = directory
        self.assertEqual(directory, self.data_dict.file_dir)
        self.assertEqual(
            os.path.join(directory, 'default'),
            self.data_dict.file_localpath
        )

    def test_write_to_file(self):

        with TemporaryDirectory() as temp_dir:
            temp_file = os.path.join(temp_dir, 'temporary')

            self.data_dict.data["FoamFile"]["location"] = temp_file
            self.data_dict.write_to_file()

            with open(self.control_file_path) as control_file:
                control_data = control_file.readlines()
            with open(self.data_dict.file_localpath) as test_file:
                test_data = test_file.readlines()

            # Update control_data info with location of temporary file used
            # for testing
            control_data[5] = test_data[5]
            self.assertListEqual(control_data, test_data)
 def setUp(self):
     self.control_file_path = fixtures_path.get("setFieldsDict_box")
     self.data_dict = FieldsDictData()