コード例 #1
0
    def test_write_fistr_static_overwrite(self):
        fem_data = FEMData.read_files('fistr', [
            'tests/data/fistr/thermal/hex.msh',
            'tests/data/fistr/thermal/hex.cnt',
            'tests/data/fistr/thermal/hex.res.0.1'
        ])

        write_file_name = 'tests/data/fistr/write_static_overwrite/mesh'
        if os.path.isfile(write_file_name + '.msh'):
            os.remove(write_file_name + '.msh')
        if os.path.isfile(write_file_name + '.cnt'):
            os.remove(write_file_name + '.cnt')

        data = np.random.rand(
            *fem_data.elemental_data.get_attribute_data('lte').shape)
        fem_data.elemental_data.overwrite('lte', data)
        data = np.random.rand(
            *fem_data.elemental_data.get_attribute_data('modulus').shape)
        fem_data.elemental_data.overwrite('modulus', data)
        fem_data.write('fistr', file_name=write_file_name, overwrite=True)

        written_fem_data = FEMData.read_files(
            'fistr', [write_file_name + '.msh', write_file_name + '.cnt'])
        np.testing.assert_almost_equal(
            written_fem_data.elemental_data.get_attribute_data('lte'),
            fem_data.elemental_data.get_attribute_data('lte'))
        np.testing.assert_almost_equal(
            written_fem_data.elemental_data.get_attribute_data('modulus'),
            fem_data.elemental_data.get_attribute_data('modulus'))
コード例 #2
0
    def test_read_heat_nl_tensor_material(self):
        fem_data = FEMData.read_directory('fistr',
                                          'tests/data/fistr/heat_nl_tensor',
                                          read_npy=False,
                                          save=False)
        heat_res = FEMData.read_files(
            'ucd', 'tests/data/fistr/heat_nl_tensor/hex_vis_psf.0100.inp')

        write_dir_name = Path('tests/data/fistr/write_heat_nl_tensor')
        if os.path.exists(write_dir_name):
            shutil.rmtree(write_dir_name)
        fem_data.write('fistr', file_name=write_dir_name / 'mesh')

        written_fem_data = FEMData.read_directory('fistr',
                                                  write_dir_name,
                                                  read_npy=False,
                                                  save=False)
        np.testing.assert_almost_equal(
            written_fem_data.materials['thermal_conductivity_full'].values[0,
                                                                           0],
            fem_data.materials['thermal_conductivity_full'].values[0, 0])

        if RUN_FISTR:
            subprocess.check_call("fistr1", cwd=write_dir_name, shell=True)
            written_res_data = FEMData.read_files(
                'ucd', write_dir_name / 'mesh_vis_psf.0100.inp')
            np.testing.assert_almost_equal(
                written_res_data.nodal_data.get_attribute_data('TEMPERATURE'),
                heat_res.nodal_data.get_attribute_data('TEMPERATURE'))
コード例 #3
0
    def test_write_fistr_heat_steady(self):
        fem_data = FEMData.read_files('fistr', [
            'tests/data/fistr/heat_steady/hex.msh',
            'tests/data/fistr/heat_steady/hex.cnt',
            'tests/data/fistr/heat_steady/hex.res.0.1'
        ])

        write_file_name = 'tests/data/fistr/write_heat_steady/mesh'
        if os.path.isfile(write_file_name + '.msh'):
            os.remove(write_file_name + '.msh')
        if os.path.isfile(write_file_name + '.cnt'):
            os.remove(write_file_name + '.cnt')
        fem_data.write('fistr', file_name=write_file_name, overwrite=True)

        written_fem_data = FEMData.read_files(
            'fistr', [write_file_name + '.msh', write_file_name + '.cnt'])
        np.testing.assert_almost_equal(
            written_fem_data.constraints['fixtemp'].data,
            fem_data.constraints['fixtemp'].data)

        if RUN_FISTR:
            subprocess.check_call("fistr1",
                                  cwd=os.path.dirname(write_file_name),
                                  shell=True)
            written_fem_data_with_res = FEMData.read_files(
                'fistr', [
                    write_file_name + '.msh', write_file_name + '.cnt',
                    write_file_name + '.res.0.1'
                ])
            np.testing.assert_almost_equal(
                written_fem_data_with_res.nodal_data['TEMPERATURE'].data,
                fem_data.nodal_data['TEMPERATURE'].data)
コード例 #4
0
    def test_stl_to_vtk(self):
        fem_data = FEMData.read_files('stl',
                                      ['tests/data/stl/multiple/multiple.stl'])
        write_file_name = 'tests/data/vtk/write_from_stl/mesh.vtk'
        if os.path.exists(write_file_name):
            os.remove(write_file_name)
        fem_data.write('vtk', write_file_name)

        vtk_fem_data = FEMData.read_files('vtk', write_file_name)
        np.testing.assert_almost_equal(fem_data.nodes.data,
                                       vtk_fem_data.nodes.data)
コード例 #5
0
    def test_write_ucd_mesh_only(self):
        fem_data = FEMData.read_files('fistr',
                                      ['tests/data/fistr/thermal/hex.msh'])
        write_file_name = 'tests/data/ucd/write/mesh_only.inp'
        if os.path.exists(write_file_name):
            os.remove(write_file_name)
        fem_data.write('ucd', write_file_name)

        ucd_fem_data = FEMData.read_files('ucd', write_file_name)
        np.testing.assert_almost_equal(fem_data.nodes.data,
                                       ucd_fem_data.nodes.data)
コード例 #6
0
    def test_write_obj(self):
        fem_data = FEMData.read_files('fistr', [
            'tests/data/fistr/thermal/hex.msh',
            'tests/data/fistr/thermal/hex.cnt',
            'tests/data/fistr/thermal/hex.res.0.1'
        ])
        write_file_name = 'tests/data/obj/write/mesh.obj'
        if os.path.exists(write_file_name):
            os.remove(write_file_name)
        fem_data.write('obj', write_file_name)

        obj_fem_data = FEMData.read_files('obj', write_file_name)
        np.testing.assert_almost_equal(fem_data.nodes.data,
                                       obj_fem_data.nodes.data)
コード例 #7
0
    def test_read_hexprism(self):
        file_name = Path('tests/data/vtk/hexprism/mesh.vtk')

        fem_data = FEMData.read_files('vtk', [file_name])
        write_file_name = Path('tests/data/vtk/write_hexprism/mesh.vtk')

        if os.path.exists(write_file_name):
            os.remove(write_file_name)
        fem_data.write('vtk', write_file_name)
        written_fem_data = FEMData.read_files('vtk', file_name)
        np.testing.assert_almost_equal(written_fem_data.nodes.data,
                                       fem_data.nodes.data)
        np.testing.assert_almost_equal(written_fem_data.elements.data,
                                       fem_data.elements.data)
コード例 #8
0
    def test_write_ucd(self):
        fem_data = FEMData.read_files('fistr', [
            'tests/data/fistr/thermal/hex.msh',
            'tests/data/fistr/thermal/hex.cnt',
            'tests/data/fistr/thermal/hex.res.0.1'
        ])
        write_file_name = 'tests/data/ucd/write/mesh.inp'
        if os.path.exists(write_file_name):
            os.remove(write_file_name)
        fem_data.write('ucd', write_file_name)

        ucd_fem_data = FEMData.read_files('ucd', write_file_name)
        np.testing.assert_almost_equal(
            fem_data.nodal_data.get_attribute_data('NodalSTRESS'),
            ucd_fem_data.nodal_data.get_attribute_data('NodalSTRESS'))
コード例 #9
0
 def test_extract_surface_tet(self):
     tet_data = FEMData.read_files('fistr',
                                   ['tests/data/fistr/tet/tet.msh'])
     ids, _ = tet_data.extract_surface()
     desired = [[0, 2, 1], [0, 1, 3], [0, 3, 2], [1, 2, 4], [1, 4, 3],
                [2, 3, 4]]
     np.testing.assert_array_equal(ids, desired)
コード例 #10
0
    def test_extract_surface_fistr(self):
        file_name = pathlib.Path('tests/data/fistr/tet/tet.msh')
        fem_data = FEMData.read_files('fistr', [file_name])
        surfs = fem_data.extract_surface_fistr()

        expected = np.array([1, 1, 1, 2, 1, 4, 2, 2, 2, 4, 2, 3]).reshape(6, 2)
        np.testing.assert_equal(surfs, expected)
コード例 #11
0
    def test_read_hex(self):
        file_name = Path('tests/data/vtk/hex/mesh.vtk')

        fem_data = FEMData.read_files('vtk', [file_name])
        desired_nodes = np.array([
            [0.0, 0, 0],
            [0.1, 0, 0],
            [0.1, 0.1, 0],
            [0.0, 0.1, 0],
            [0.0, 0, 0.005],
            [0.1, 0, 0.005],
            [0.1, 0.1, 0.005],
            [0.0, 0.1, 0.005],
            [0.0, 0, 0.01],
            [0.1, 0, 0.01],
            [0.1, 0.1, 0.01],
            [0.0, 0.1, 0.01],
        ])
        np.testing.assert_almost_equal(
            fem_data.nodes.data, desired_nodes)

        desired_elements = np.array([
            [1, 2, 3, 4, 5, 6, 7, 8],
            [5, 6, 7, 8, 9, 10, 11, 12],
        ])
        np.testing.assert_almost_equal(
            fem_data.elements.data, desired_elements)
        self.assertEqual(fem_data.elements.element_type, 'hex')
        np.testing.assert_almost_equal(
            fem_data.calculate_element_volumes(),
            np.ones((2, 1)) * .1 * .1 * .005)
コード例 #12
0
 def test_overwrite_alias_nodal_data(self):
     fem_data = FEMData.read_files('fistr',
                                   [FISTR_MSH_FILE, FISTR_RES_FILE])
     fem_data.nodal_data.update_data([3], {'t_init': 1000.},
                                     allow_overwrite=True)
     np.testing.assert_almost_equal(
         fem_data.nodal_data['t_init'].loc[3].values, 1000.)
コード例 #13
0
 def test_add_section(self):
     fem_data = FEMData.read_files('fistr',
                                   [FISTR_MSH_FILE, FISTR_RES_FILE])
     fem_data.sections.update_data('M_ADDITIONAL', {'EGRP': 'E_ADDITIONAL'})
     self.assertEqual(len(fem_data.sections['EGRP']), 3)
     np.testing.assert_array_equal(
         fem_data.sections['EGRP']['M_ADDITIONAL'], ['E_ADDITIONAL'])
コード例 #14
0
 def test_write_fistr_overwrite_error(self):
     fem_data = FEMData.read_files('fistr', [
         'tests/data/fistr/heat/hex.msh', 'tests/data/fistr/heat/hex.cnt',
         'tests/data/fistr/heat/hex.res.0.100'
     ])
     with self.assertRaises(ValueError):
         fem_data.write('fistr', file_name='tests/data/fistr/heat/hex')
コード例 #15
0
 def test_renew_section(self):
     fem_data = FEMData.read_files('fistr',
                                   [FISTR_MSH_FILE, FISTR_RES_FILE])
     fem_data.sections.update_data('M1', {'EGRP': 'E2'},
                                   allow_overwrite=True)
     self.assertEqual(len(fem_data.sections['EGRP']), 2)
     self.assertEqual(fem_data.sections['EGRP']['M1'], ['E2'])
コード例 #16
0
 def test_fistr_element_components(self):
     """Element compoments should be correctly stored."""
     desired_element_components = np.array([[1, 2, 3, 4, 5, 6, 7, 8],
                                            [5, 6, 7, 8, 9, 10, 11, 12]])
     fem_data = FEMData.read_files(
         'fistr', [FISTR_MSH_FILE, FISTR_CNT_FILE, FISTR_RES_FILE])
     np.testing.assert_equal(fem_data.elements.data,
                             desired_element_components)
コード例 #17
0
 def test_fistr_elemental_mises_ids(self):
     """Elemental MISES IDs should be correctly stored."""
     desired_nodal_mises_ids = np.array([1, 2])
     fem_data = FEMData.read_files(
         'fistr', [FISTR_MSH_FILE, FISTR_CNT_FILE, FISTR_RES_FILE])
     np.testing.assert_almost_equal(
         fem_data.elemental_data['ElementalMISES'].ids,
         desired_nodal_mises_ids)
コード例 #18
0
    def test_write_fistr_cload(self):
        fem_data = FEMData.read_files('fistr', [
            'tests/data/fistr/cload/hex.msh', 'tests/data/fistr/cload/hex.cnt'
        ])

        write_file_name = 'tests/data/fistr/write_cload/mesh'
        if os.path.isfile(write_file_name + '.msh'):
            os.remove(write_file_name + '.msh')
        if os.path.isfile(write_file_name + '.cnt'):
            os.remove(write_file_name + '.cnt')
        fem_data.write('fistr', file_name=write_file_name, overwrite=True)

        written_fem_data = FEMData.read_files(
            'fistr', [write_file_name + '.msh', write_file_name + '.cnt'])
        np.testing.assert_almost_equal(
            written_fem_data.constraints['cload'].data,
            fem_data.constraints['cload'].data)
コード例 #19
0
 def test_fistr_displacement_ids(self):
     """Displacement IDs should be correctly stored."""
     desired_displacement_ids = np.array(
         [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12])
     fem_data = FEMData.read_files(
         'fistr', [FISTR_MSH_FILE, FISTR_CNT_FILE, FISTR_RES_FILE])
     np.testing.assert_equal(fem_data.nodal_data['DISPLACEMENT'].ids,
                             desired_displacement_ids)
コード例 #20
0
 def test_relative_incidence_hex(self):
     fem_data = FEMData.read_files('vtk', ['tests/data/vtk/hex/mesh.vtk'])
     facet_fem_data = fem_data.to_facets()
     inc_facet2cell = fem_data.calculate_relative_incidence_metrix_element(
         facet_fem_data, minimum_n_sharing=3)
     desired_inc = np.array([[1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0],
                             [0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1]])
     np.testing.assert_array_equal(inc_facet2cell.toarray().astype(int),
                                   desired_inc)
コード例 #21
0
 def test_fistr_elemental_mises_data(self):
     """Elemental MISES data should be correctly stored."""
     desired_nodal_mises_data = np.array([[1.2858939470519477E+01],
                                          [5.7457980475401499E+01]])
     fem_data = FEMData.read_files(
         'fistr', [FISTR_MSH_FILE, FISTR_CNT_FILE, FISTR_RES_FILE])
     np.testing.assert_almost_equal(
         fem_data.elemental_data['ElementalMISES'].data,
         desired_nodal_mises_data,
         decimal=3)
コード例 #22
0
ファイル: test_fem_data.py プロジェクト: ricosjp/femio
    def test_create_node_group(self):
        file_name = Path('tests/data/fistr/pyramid/pyramid.msh')
        fem_data = FEMData.read_files('fistr', [file_name])

        selected = fem_data.nodes.data[:, 2] == 0
        fem_data.create_node_group('new_group', selected)
        np.testing.assert_equal(fem_data.node_groups['new_group'],
                                np.array([1, 2, 3]))
        with pytest.raises(ValueError):
            fem_data.create_node_group('new_group', selected)
コード例 #23
0
 def test_write_ucd_heat(self):
     fem_data = FEMData.read_files('fistr', [
         'tests/data/fistr/heat_steady/hex.msh',
         'tests/data/fistr/heat_steady/hex.cnt',
         'tests/data/fistr/heat_steady/hex.res.0.1'
     ])
     write_file_name = 'tests/data/ucd/write_heat_steady/mesh.inp'
     if os.path.exists(write_file_name):
         os.remove(write_file_name)
     fem_data.write('ucd', write_file_name)
コード例 #24
0
 def test_fistr_initial_temperature(self):
     """Initial temperature should be correctly stored."""
     fem_data = FEMData.read_files(
         'fistr', [FISTR_MSH_FILE, FISTR_CNT_FILE, FISTR_RES_FILE])
     desired_temperature = np.atleast_2d([
         10.0, 20.0, 30.0, 40.0, 50.0, 60.0, 70.0, 80.0, 90.0, 100.0, 110.0,
         120.0
     ]).T
     np.testing.assert_almost_equal(
         fem_data.nodal_data['INITIAL_TEMPERATURE'].data,
         desired_temperature)
コード例 #25
0
 def test_read_heat_temperature(self):
     heat_data = FEMData.read_files('fistr', [
         'tests/data/fistr/heat/hex.msh', 'tests/data/fistr/heat/hex.cnt',
         'tests/data/fistr/heat/hex.res.0.100'
     ])
     desired_initial_temperature = np.array([[0.0], [0.0], [0.0], [0.0],
                                             [0.0], [0.0], [0.0], [10.0],
                                             [10.0], [0.0]])
     np.testing.assert_almost_equal(
         heat_data.nodal_data['INITIAL_TEMPERATURE'].data[:10],
         desired_initial_temperature)
コード例 #26
0
    def test_write_obj_mixture_solid(self):
        fem_data = FEMData.read_directory(
            'fistr', 'tests/data/fistr/mixture_solid_simple', read_npy=False)
        write_file_name = 'tests/data/obj/write_mixture_solid_simple/mesh.obj'
        if os.path.exists(write_file_name):
            os.remove(write_file_name)
        fem_data.write('obj', write_file_name)

        obj_fem_data = FEMData.read_files('obj', write_file_name)
        np.testing.assert_almost_equal(fem_data.nodes.data,
                                       obj_fem_data.nodes.data)
コード例 #27
0
 def test_integrate_node_attribute_over_surface(self):
     file_name = pathlib.Path('tests/data/fistr/tet/tet.msh')
     fem_data = FEMData.read_files('fistr', [file_name])
     fem_data.nodal_data.set_attribute_data(
         'values', np.array([3, 1, 4, 1, 5], np.float32))
     # 123, 124, 134, 235, 245, 345
     sq2 = 2**.5
     areas = [1 / 2, 1 / 2, 1 / 2, sq2 / 2, sq2 / 2, 1 / 2]
     vals = [8 / 3, 5 / 3, 8 / 3, 10 / 3, 7 / 3, 10 / 3]
     desired = sum(x * y for x, y in zip(areas, vals))
     actual = fem_data.integrate_node_attribute_over_surface('values')
     np.testing.assert_almost_equal(actual, desired)
コード例 #28
0
 def test_fistr_node_positions(self):
     """Node positions should be correctly stored."""
     fem_data = FEMData.read_files(
         'fistr', [FISTR_MSH_FILE, FISTR_CNT_FILE, FISTR_RES_FILE])
     desired_node_positions = np.array([[0.0, 0.0, 0.0], [1.0, 0.0, 0.0],
                                        [1.0, 1.0, 0.0], [0.0, 1.0, 0.0],
                                        [0.0, 0.0, 1.0], [1.0, 0.0, 1.0],
                                        [1.0, 1.0, 1.0], [0.0, 1.0, 1.0],
                                        [0.0, 0.0, 2.0], [1.0, 0.0, 2.0],
                                        [1.0, 1.0, 2.0], [0.0, 1.0, 2.0]])
     np.testing.assert_almost_equal(fem_data.nodes.data,
                                    desired_node_positions)
コード例 #29
0
ファイル: test_fem_data.py プロジェクト: ricosjp/femio
 def test_create_element_group_from_node_group_any(self):
     file_name = Path('tests/data/fistr/pyramid/pyramid.msh')
     fem_data = FEMData.read_files('fistr', [file_name])
     fem_data.create_node_group('node_1234',
                                np.array([True, True, True, True, False]))
     fem_data.create_element_group_from_node_group('element_1234',
                                                   'node_1234', 'any')
     np.testing.assert_equal(fem_data.element_groups['element_1234'],
                             np.array([1, 2]))
     with pytest.raises(ValueError):
         fem_data.create_element_group_from_node_group(
             'element_1234', 'node_1234', 'all')
コード例 #30
0
    def test_write_fistr_static_id_not_from_1(self):
        fem_data = FEMData.read_files('fistr', [
            'tests/data/fistr/thermal_id_not_from_1/hex.msh',
            'tests/data/fistr/thermal_id_not_from_1/hex.cnt',
            'tests/data/fistr/thermal_id_not_from_1/hex.res.0.1'
        ])

        write_file_name = 'tests/data/fistr/write_static_id_not_from_1/mesh'
        if os.path.isfile(write_file_name + '.msh'):
            os.remove(write_file_name + '.msh')
        if os.path.isfile(write_file_name + '.cnt'):
            os.remove(write_file_name + '.cnt')
        fem_data.write('fistr', file_name=write_file_name, overwrite=True)

        written_fem_data = FEMData.read_files(
            'fistr', [write_file_name + '.msh', write_file_name + '.cnt'])
        np.testing.assert_almost_equal(
            written_fem_data.elemental_data['ORIENTATION'].data,
            fem_data.elemental_data['ORIENTATION'].data)

        np.testing.assert_array_equal(
            list(fem_data.element_groups.keys()),
            list(written_fem_data.element_groups.keys()))
        for v1, v2 in zip(list(fem_data.element_groups.values()),
                          list(written_fem_data.element_groups.values())):
            np.testing.assert_array_equal(v1, v2)

        if RUN_FISTR:
            subprocess.check_call("fistr1",
                                  cwd=os.path.dirname(write_file_name),
                                  shell=True)
            written_fem_data_with_res = FEMData.read_files(
                'fistr', [
                    write_file_name + '.msh', write_file_name + '.cnt',
                    write_file_name + '.res.0.1'
                ])
            np.testing.assert_almost_equal(
                written_fem_data_with_res.nodal_data['DISPLACEMENT'].data,
                fem_data.nodal_data['DISPLACEMENT'].data,
                decimal=5)