Example #1
0
    def test_1d(self):
        vtk_file = self.vtk_files["test_1d"]

        field = UnstructuredField(
            [0, 1, 4, 10], [0, 1, 1, 2, 2, 3], [2, 4, 6], units=("m",)
        )

        field.add_field("point_field", np.arange(4), centering="point", units="C")
        field.add_field("cell_field", np.arange(3) * 10.0, centering="zonal", units="F")

        field_tofile(field, vtk_file, append=False)
Example #2
0
    def test_1d(self):
        vtk_file = self.vtk_files['test_1d']

        field = UnstructuredField([0, 1, 4, 10], [0, 1, 1, 2, 2, 3],
                                  [2, 4, 6], units=('m', ))

        field.add_field('point_field', np.arange(4), centering='point',
                        units='C')
        field.add_field('cell_field', np.arange(3) * 10., centering='zonal',
                        units='F')

        field_tofile(field, vtk_file, append=False)
Example #3
0
def test_unstructured_1(tmpdir):
    field = UnstructuredField([0, 1, 4, 10], [0, 1, 1, 2, 2, 3], [2, 4, 6],
                              units=("m", ))

    field.add_field("point_field", np.arange(4), centering="point", units="C")
    field.add_field("cell_field",
                    np.arange(3) * 10.0,
                    centering="zonal",
                    units="F")

    with tmpdir.as_cwd():
        field_tofile(field, "unstructured.nc", append=False)
        assert os.path.isfile("unstructured.nc")
Example #4
0
    def test_2d(self):
        vtk_file = self.vtk_files["test_2d"]

        field = UnstructuredField(
            [0, 2, 1, 3], [0, 0, 1, 1], [0, 2, 1, 2, 3, 1], [3, 6], units=("m", "m")
        )

        data = np.arange(4)
        field.add_field("point_field", data, centering="point", units="m")

        data = np.arange(2)
        field.add_field("cell_field", data, centering="zonal", units="m^2")

        field_tofile(field, vtk_file, append=False)
Example #5
0
    def test_2d(self):
        vtk_file = self.vtk_files["test_2d"]

        field = UnstructuredField([0, 2, 1, 3], [0, 0, 1, 1],
                                  [0, 2, 1, 2, 3, 1], [3, 6],
                                  units=("m", "m"))

        data = np.arange(4)
        field.add_field("point_field", data, centering="point", units="m")

        data = np.arange(2)
        field.add_field("cell_field", data, centering="zonal", units="m^2")

        field_tofile(field, vtk_file, append=False)
Example #6
0
    def test_2d(self):
        vtk_file = self.vtk_files['test_2d']

        field = UnstructuredField([0, 2, 1, 3], [0, 0, 1, 1],
                                  [0, 2, 1, 2, 3, 1], [3, 6],
                                  units=('m', 'm'))

        data = np.arange(4)
        field.add_field('point_field', data, centering='point', units='m')

        data = np.arange(2)
        field.add_field('cell_field', data, centering='zonal', units='m^2')

        field_tofile(field, vtk_file, append=False)
Example #7
0
def test_unstructured_2(tmpdir):
    field = UnstructuredField([0, 0, 1, 1], [0, 2, 1, 3], [0, 2, 1, 2, 3, 1],
                              [3, 6],
                              units=("m", "m"))

    data = np.arange(4)
    field.add_field("point_field", data, centering="point", units="m")

    data = np.arange(2)
    field.add_field("cell_field", data, centering="zonal", units="m^2")

    with tmpdir.as_cwd():
        field_tofile(field, "unstructured.nc", append=False)
        assert os.path.isfile("unstructured.nc")
Example #8
0
    def test_1d(self):
        vtk_file = self.vtk_files["test_1d"]

        field = UnstructuredField([0, 1, 4, 10], [0, 1, 1, 2, 2, 3], [2, 4, 6],
                                  units=("m", ))

        field.add_field("point_field",
                        np.arange(4),
                        centering="point",
                        units="C")
        field.add_field("cell_field",
                        np.arange(3) * 10.0,
                        centering="zonal",
                        units="F")

        field_tofile(field, vtk_file, append=False)
Example #9
0
    def test_1d(self):
        nc_file = self.temp_file_name(prefix='unstructured.1d.', suffix='.ncu')

        field = UnstructuredField([0, 1, 4, 10], [0, 1, 1, 2, 2, 3], [2, 4, 6],
                                  units=('m', ))

        field.add_field('point_field',
                        np.arange(4),
                        centering='point',
                        units='C')
        field.add_field('cell_field',
                        np.arange(3) * 10.,
                        centering='zonal',
                        units='F')

        field_tofile(field, nc_file, append=False)

        self.assertIsFile(nc_file)
Example #10
0
    def test_2d(self):
        nc_file = self.temp_file_name(prefix='unstructured.2d.', suffix='.ncu')

        field = UnstructuredField([0, 0, 1, 1], [0, 2, 1, 3],
                                  [0, 2, 1, 2, 3, 1], [3, 6],
                                  units=('m', 'm'))

        data = np.arange(4)
        field.add_field('point_field', data, centering='point', units='m')

        data = np.arange(2)
        field.add_field('cell_field', data, centering='zonal', units='m^2')

        field_tofile(field, nc_file, append=False)

        root = self.open_as_netcdf(nc_file)

        self.assertDataVariableNames(root, [
            'mesh', 'point_field', 'cell_field', 'node_x', 'node_y', 'time',
            'face_nodes', 'face_nodes_offset', 'face_nodes_connectivity'
        ])
        self.assertDimensionsEqual(
            root, ['n_face', 'n_node', 'n_vertex', 'n_max_face_nodes', 'time'])
        self.assertDataVariableArrayEqual(root, 'node_x', [0., 2., 1., 3.])
        self.assertDataVariableArrayEqual(root, 'node_y', [0., 0., 1., 1.])
        self.assertDataVariableArrayEqual(root, 'face_nodes_offset', [3, 6])
        self.assertDataVariableArrayEqual(root, 'face_nodes',
                                          np.array([[0, 2, 1], [2, 3, 1]]))

        self.assertDataVariableLongNameEqual(root, 'point_field',
                                             'point_field')
        self.assertDataVariableLongNameEqual(root, 'cell_field', 'cell_field')
        self.assertDataVariableUnitsEqual(root, 'point_field', 'm')
        self.assertDataVariableUnitsEqual(root, 'cell_field', 'm^2')

        root.close()