Exemplo n.º 1
0
    def test_write_spring_from_array(self):
        fem_data = FEMData.read_directory('fistr',
                                          'tests/data/fistr/tet_3',
                                          read_npy=False,
                                          save=False)
        fem_data.constraints = {
            'spring':
            FEMAttribute('spring', fem_data.elements.data[0, :3],
                         np.ones((3, 3)) * 1e-6)
        }

        write_dir_name = Path('tests/data/fistr/write_spring_from_array')
        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)
        original_constraints_data = fem_data.constraints['spring'].data
        written_constraints_data = written_fem_data.constraints['spring'].data
        np.testing.assert_almost_equal(
            original_constraints_data[~np.isnan(original_constraints_data)],
            written_constraints_data[~np.isnan(written_constraints_data)])

        if RUN_FISTR:
            subprocess.check_call("fistr1", cwd=write_dir_name, shell=True)
            vis_files = glob(str(write_dir_name / '*.inp'))
            self.assertTrue(len(vis_files) > 0)
Exemplo n.º 2
0
 def test_get_attribute_data(self):
     fem_attributes = FEMAttributes([
         FEMAttribute(f"data_{i}",
                      ids=np.arange(5) + 1,
                      data=np.random.rand(5, 3)) for i in range(3)
     ])
     np.testing.assert_almost_equal(
         fem_attributes.get_attribute_data('data_1'),
         fem_attributes.data['data_1'].data)
Exemplo n.º 3
0
 def test_write_time_series(self):
     fem_data = FEMData.read_directory('fistr',
                                       'tests/data/fistr/heat_tet2_3',
                                       read_npy=False,
                                       save=False,
                                       time_series=True)
     fem_data.elemental_data['volume'] = FEMAttribute(
         'volume', fem_data.elements.ids,
         fem_data.calculate_element_volumes())
     write_dir_name = pathlib.Path('tests/data/ucd/write_heat_tet2_3')
     if os.path.exists(write_dir_name):
         shutil.rmtree(write_dir_name)
     fem_data.write('ucd', write_dir_name / 'mesh.inp')
Exemplo n.º 4
0
    def test_time_series_interfaces(self):
        data = np.reshape(np.arange(10. * 5 * 3), (10, 5, 3))
        time_series = FEMAttribute('TIME_SERIES',
                                   ids=np.arange(5) + 1,
                                   data=data,
                                   time_series=True)
        np.testing.assert_array_equal(time_series.ids, [1, 2, 3, 4, 5])

        np.testing.assert_almost_equal(time_series.iloc[2].values,
                                       data[:, [2], :])
        np.testing.assert_almost_equal(time_series.iloc[[1, 3]].values,
                                       data[:, [1, 3], :])
        np.testing.assert_almost_equal(time_series.iloc[1:3].values,
                                       data[:, 1:3, :])

        np.testing.assert_almost_equal(time_series.loc[2].values, data[:,
                                                                       [1], :])
        np.testing.assert_almost_equal(time_series.loc[[1, 3]].values,
                                       data[:, [0, 2], :])
        np.testing.assert_almost_equal(time_series.loc[1:3].values,
                                       data[:, 0:3, :])

        twice_data = data * 2
        time_series.data = twice_data

        np.testing.assert_almost_equal(time_series.iloc[2].values,
                                       twice_data[:, [2], :])
        np.testing.assert_almost_equal(time_series.iloc[[1, 3]].values,
                                       twice_data[:, [1, 3], :])
        np.testing.assert_almost_equal(time_series.iloc[1:3].values,
                                       twice_data[:, 1:3, :])

        np.testing.assert_almost_equal(time_series.loc[2].values,
                                       twice_data[:, [1], :])
        np.testing.assert_almost_equal(time_series.loc[[1, 3]].values,
                                       twice_data[:, [0, 2], :])
        np.testing.assert_almost_equal(time_series.loc[1:3].values,
                                       twice_data[:, 0:3, :])
Exemplo n.º 5
0
    def test_fem_attribute_multidimension(self):
        a = np.reshape(np.arange(5 * 3 * 3), (5, 3, 3))
        ids = ['A', 'B', 'C', 'D', 'E']
        fem_attribute = FEMAttribute('data', ids=ids, data=a)
        np.testing.assert_array_equal(fem_attribute.loc[['B', 'D']].data,
                                      a[[1, 3]])
        np.testing.assert_array_equal(fem_attribute.loc['C'].data, a[[2]])
        np.testing.assert_array_equal(fem_attribute.iloc[[1, 3]].data,
                                      a[[1, 3]])
        np.testing.assert_array_equal(fem_attribute.iloc[2].data, a[[2]])

        fem_attribute.loc[['E']].data = 100 * np.ones((1, 3, 3))
        np.testing.assert_array_equal(fem_attribute.loc['E'].data,
                                      100 * np.ones((1, 3, 3)))
Exemplo n.º 6
0
 def test_femattribute_length_different_error(self):
     """ValueError should be raised when length of IDs and data differ."""
     with self.assertRaises(ValueError):
         FEMAttribute('', [1, 2, 3], [10., 20., 30., 40.])
Exemplo n.º 7
0
    def test_write_static_with_hand_created_data(self):
        write_fem_data = FEMData(
            nodes=FEMAttribute('NODE',
                               ids=[1, 2, 3, 4, 5],
                               data=np.array([
                                   [0., 0., 0.],
                                   [1., 0., 0.],
                                   [0., 1., 0.],
                                   [0., 0., 1.],
                                   [0., 0., 1.],
                               ])),
            elements=FEMElementalAttribute(
                'ELEMENT', {
                    'tet': FEMAttribute('TET', ids=[1], data=[[1, 2, 3, 4]]),
                    'spring': FEMAttribute('SPRING', ids=[2], data=[[4, 5]])
                }))

        write_fem_data.settings['solution_type'] = 'STATIC'
        write_fem_data.constraints['boundary'] = FEMAttribute(
            'boundary',
            ids=[1, 2, 3, 5],
            data=np.array([
                [0., 0., 0.],
                [np.nan, 0., 0.],
                [np.nan, np.nan, 0.],
                [0., 0., .1],
            ]))
        write_fem_data.element_groups.update({'E_SOLID': [1], 'E_LINE': [2]})
        write_fem_data.materials.update_data(
            'M_SOLID', {
                'Young_modulus': np.array([[10.0]]),
                'Poisson_ratio': np.array([[0.4]])
            })
        write_fem_data.materials.update_data(
            'M_LINE', {
                'Young_modulus': np.array([[10000.0]]),
                'Poisson_ratio': np.array([[0.45]])
            })
        write_fem_data.sections.update_data('M_SOLID', {
            'TYPE': 'SOLID',
            'EGRP': 'E_SOLID'
        })
        write_fem_data.sections.update_data('M_LINE', {
            'TYPE': 'SOLID',
            'EGRP': 'E_LINE'
        })

        write_dir_name = Path('tests/data/fistr/write_hand_created')
        if write_dir_name.exists():
            shutil.rmtree(write_dir_name)
        write_fem_data.write('fistr', write_dir_name / 'mesh')
        if RUN_FISTR:
            subprocess.check_call("fistr1", cwd=write_dir_name, shell=True)
            written_fem_data_with_res = FEMData.read_directory('fistr',
                                                               write_dir_name,
                                                               read_npy=False,
                                                               save=False)
            np.testing.assert_almost_equal(
                written_fem_data_with_res.nodal_data['DISPLACEMENT'].data[3,
                                                                          -1],
                .1,
                decimal=3)