def test_get_elementids_by_physics(self):
        component = StructuralComponent(self.testmesh)
        eleids1 = np.array([1, 2], dtype=int)
        eleids2 = np.array([3], dtype=int)
        component.assign_material(self.mat1, eleids1, 'S', '_eleids')
        component.assign_material(self.mat2, eleids2, 'S', '_eleids')

        eleids_actual = component.get_elementids_by_physics('S')
        eleids_desired = np.array([1, 2, 3], dtype=int)

        assert_array_equal(eleids_actual, eleids_desired)
    def test_get_materials(self):
        component = StructuralComponent(self.testmesh)
        eleids1 = np.array([1, 2], dtype=int)
        eleids2 = np.array([3], dtype=int)
        component.assign_material(self.mat1, eleids1, 'S', '_eleids')
        component.assign_material(self.mat2, eleids2, 'S', '_eleids')

        materials_desired = [self.mat1, self.mat2]
        materials_actual = component.get_materials()

        assert_array_equal(materials_desired, materials_actual)
Example #3
0
    def test_amfe_solution_reader(self):
        self._create_fields()

        amfesolution = AmfeSolution()
        sol = self.fields_desired['Nodefield1']
        for t, q in zip(sol['timesteps'], sol['data'].T):
            amfesolution.write_timestep(t, q)

        mesh = create_amfe_obj()
        meshcomponent = StructuralComponent(mesh)
        # Set a material to get a mapping
        material = KirchhoffMaterial()
        meshcomponent.assign_material(material, 'Tri6', 'S', 'shape')

        postprocessorreader = AmfeSolutionReader(amfesolution, meshcomponent)
    def test_assign_material_by_groups(self):
        # 2 Groups
        #
        component = StructuralComponent(self.testmesh)
        # assign materials
        component.assign_material(self.mat1, ['left', 'right'], 'S', '_groups')
        ele_obj_actual = component.ele_obj
        # check ele_obj is instance array
        self.assertIsInstance(ele_obj_actual, np.ndarray)
        # check each object
        ele_obj_df = component._ele_obj_df
        mask1 = (ele_obj_df['physics'] == 'S') & (ele_obj_df['fk_mesh'] == 1)
        mask2 = (ele_obj_df['physics'] == 'S') & (ele_obj_df['fk_mesh'] == 2)
        mask3 = (ele_obj_df['physics'] == 'S') & (ele_obj_df['fk_mesh'] == 3)
        self.assertIsInstance(ele_obj_df.loc[mask1, 'ele_obj'].values[0], Tri3)
        self.assertIsInstance(ele_obj_df.loc[mask2, 'ele_obj'].values[0], Tri3)
        self.assertIsInstance(ele_obj_df.loc[mask3, 'ele_obj'].values[0], Quad4)

        # check materials
        # check materials
        self.assertEqual(ele_obj_df.loc[mask1, 'ele_obj'].values[0].material.name, 'steel')
        self.assertEqual(ele_obj_df.loc[mask2, 'ele_obj'].values[0].material.name, 'steel')
        self.assertEqual(ele_obj_df.loc[mask3, 'ele_obj'].values[0].material.name, 'steel')

        # 1 Group
        #
        component = StructuralComponent(self.testmesh)
        # assign materials
        component.assign_material(self.mat1, ['left'], 'T')
        ele_obj_actual = component.ele_obj
        # check ele_obj is instance array
        self.assertIsInstance(ele_obj_actual, np.ndarray)
        # check each object
        ele_obj_df = component._ele_obj_df
        with self.assertRaises(IndexError):
            mask1 = (ele_obj_df['physics'] == 'T') & (ele_obj_df['fk_mesh'] == 1)
            temp = ele_obj_df.loc[mask1, 'ele_obj'].values[0]
        with self.assertRaises(IndexError):
            mask2 = (ele_obj_df['physics'] == 'T') & (ele_obj_df['fk_mesh'] == 2)
            temp = ele_obj_df.loc[mask2, 'ele_obj'].values[0]
        mask3 = (ele_obj_df['physics'] == 'T') & (ele_obj_df['fk_mesh'] == 3)
        self.assertIsInstance(ele_obj_df.loc[mask3, 'ele_obj'].values[0], Quad4)
        # check materials
        self.assertEqual(ele_obj_df.loc[mask3, 'ele_obj'].values[0].material.name, 'steel')
    def test_assign_material_by_eleids(self):
        component = StructuralComponent(self.testmesh)
        eleids1 = np.array([1, 2], dtype=int)
        eleids2 = np.array([3], dtype=int)
        component.assign_material(self.mat1, eleids1, 'S', '_eleids')
        ele_obj_actual = component.ele_obj
        # check ele_obj is instance array
        self.assertIsInstance(ele_obj_actual, np.ndarray)
        # check each object
        ele_obj_df = component._ele_obj_df
        mask1 = (ele_obj_df['physics'] == 'S') & (ele_obj_df['fk_mesh'] == 1)
        mask2 = (ele_obj_df['physics'] == 'S') & (ele_obj_df['fk_mesh'] == 2)
        self.assertEqual(len(ele_obj_df.loc[mask1, 'ele_obj'].values), 1)
        self.assertIsInstance(ele_obj_df.loc[mask1, 'ele_obj'].values[0], Tri3)
        self.assertIsInstance(ele_obj_df.loc[mask2, 'ele_obj'].values[0], Tri3)
        # check materials
        self.assertEqual(ele_obj_df.loc[mask1, 'ele_obj'].values[0].material.name, 'steel')
        self.assertEqual(ele_obj_df.loc[mask2, 'ele_obj'].values[0].material.name, 'steel')
        # check mapping
        nodal2global_desired = pd.DataFrame({'ux': {1: -1, 2: 6, 3: 4, 4: -1, 5: 0, 6: 2},
                                             'uy': {1: -1, 2: 7, 3: 5, 4: -1, 5: 1, 6: 3}})
        elements2global_desired = [np.array([0, 1, 2, 3, 4, 5], dtype=int), np.array([4, 5, 6, 7, 0, 1], dtype=int)]
        assert_frame_equal(component.mapping.nodal2global, nodal2global_desired)
        for actual, desired in zip(component.mapping.elements2global, elements2global_desired):
            assert_array_equal(actual, desired)

        # assign second material
        component.assign_material(self.mat2, eleids2, 'S', '_eleids')
        ele_obj_df = component._ele_obj_df
        # check each object
        mask1 = (ele_obj_df['physics'] == 'S') & (ele_obj_df['fk_mesh'] == 1)
        mask2 = (ele_obj_df['physics'] == 'S') & (ele_obj_df['fk_mesh'] == 2)
        mask3 = (ele_obj_df['physics'] == 'S') & (ele_obj_df['fk_mesh'] == 3)
        self.assertIsInstance(ele_obj_df.loc[mask1, 'ele_obj'].values[0], Tri3)
        self.assertIsInstance(ele_obj_df.loc[mask2, 'ele_obj'].values[0], Tri3)
        self.assertIsInstance(ele_obj_df.loc[mask3, 'ele_obj'].values[0], Quad4)
        # check materials
        self.assertEqual(ele_obj_df.loc[mask1, 'ele_obj'].values[0].material.name, 'steel')
        self.assertEqual(ele_obj_df.loc[mask2, 'ele_obj'].values[0].material.name, 'steel')
        self.assertEqual(ele_obj_df.loc[mask3, 'ele_obj'].values[0].material.name, 'rubber')
        nodal2global_desired = pd.DataFrame({'ux': {1: 8, 2: 6, 3: 4, 4: 10, 5: 0, 6: 2},
                                             'uy': {1: 9, 2: 7, 3: 5, 4: 11, 5: 1, 6: 3}})
        elements2global_desired = [np.array([0, 1, 2, 3, 4, 5], dtype=int),
                                   np.array([4, 5, 6, 7, 0, 1], dtype=int),
                                   np.array([8,  9,  6,  7,  4,  5, 10, 11], dtype=int)]
        assert_frame_equal(component.mapping.nodal2global, nodal2global_desired)
        for actual, desired in zip(component.mapping.elements2global, elements2global_desired):
            assert_array_equal(actual, desired)

        component = StructuralComponent(self.testmesh)
        eleids3 = np.array([3, 1], dtype=int)
        component.assign_material(self.mat1, eleids3, 'S', '_eleids')
        ele_obj_actual = component.ele_obj
        # check ele_obj is instance array
        self.assertIsInstance(ele_obj_actual, np.ndarray)
        # check each object
        ele_obj_df = component._ele_obj_df

        mask1 = (ele_obj_df['physics'] == 'S') & (ele_obj_df['fk_mesh'] == 1)
        mask3 = (ele_obj_df['physics'] == 'S') & (ele_obj_df['fk_mesh'] == 3)
        self.assertIsInstance(ele_obj_df.loc[mask1, 'ele_obj'].values[0], Tri3)
        self.assertIsInstance(ele_obj_df.loc[mask3, 'ele_obj'].values[0], Quad4)
        with self.assertRaises(IndexError):
            mask2 = (ele_obj_df['physics'] == 'S') & (ele_obj_df['fk_mesh'] == 2)
            temp = ele_obj_df.loc[mask2, 'ele_obj'].values[0]
        # check materials
        self.assertEqual(ele_obj_df.loc[mask1, 'ele_obj'].values[0].material.name, 'steel')
        self.assertEqual(ele_obj_df.loc[mask3, 'ele_obj'].values[0].material.name, 'steel')
        nodal2global_desired = pd.DataFrame({'ux': {1: 0, 2: 2, 3: 4, 4: 6, 5: 8, 6: 10},
                                             'uy': {1: 1, 2: 3, 3: 5, 4: 7, 5: 9, 6: 11}})
        elements2global_desired = [np.array([0,  1,  2,  3,  4,  5, 6, 7], dtype=int),
                                   np.array([8, 9, 10, 11, 4, 5], dtype=int)]
        assert_frame_equal(component.mapping.nodal2global, nodal2global_desired)
        for actual, desired in zip(component.mapping.elements2global, elements2global_desired):
            assert_array_equal(actual, desired)
 def test_no_of_elements(self):
     component = StructuralComponent(self.testmesh)
     eleids1 = np.array([1, 2], dtype=int)
     component.assign_material(self.mat1, eleids1, 'S', '_eleids')
     no_of_elements_actual = component.no_of_elements
     self.assertEqual(no_of_elements_actual, 2)
Example #7
0
class TestEcsw(TestCase):
    def setUp(self):
        # Define input file path
        file = amfe_dir('tests/meshes/gid_json_4_tets.json')
        # Define Reader Object, initialized with AmfeMeshConverter
        reader = GidJsonMeshReader(file)

        # Initialize component
        converter = AmfeMeshConverter()
        reader.parse(converter)
        self.my_mesh = converter.return_mesh()
        self.my_component = StructuralComponent(self.my_mesh)
        my_material = KirchhoffMaterial()
        self.my_component.assign_material(my_material, ['left', 'right'], 'S')

        # Get number of dofs for snapshot generation
        self.no_of_dofs = self.my_component.mapping.no_of_dofs
        # create 2 random snapshots
        self.no_of_snapshots = 2
        self.S = np.random.rand(self.no_of_dofs, self.no_of_snapshots) * 0.05
        self.W = np.eye(self.no_of_dofs)
        self.timesteps = np.zeros(self.no_of_snapshots)

    def tearDown(self):
        pass

    def test_assemble_g_b(self):
        # store an example for f_int for later comparison to check if the old assembly is recovered
        # after ecsw_assemble_G_and_b has finished
        no_of_dofs = self.S.shape[0]
        dq = ddq = np.zeros(no_of_dofs)
        t = 0.0
        f_old = self.my_component.f_int(self.S[:, 0], dq, t)

        # run ecsw_assemble_G_and_b
        G, b = ecsw_assemble_G_and_b(self.my_component, self.S, self.W,
                                     self.timesteps)

        # test shape of G and b
        no_of_elements = self.my_component.no_of_elements
        self.assertEqual(
            G.shape, (self.no_of_dofs * self.no_of_snapshots, no_of_elements))

        # ----------------------------------
        # Check if G is correct

        # Test first entry of G
        g11_actual = G[0:self.no_of_dofs, 0]
        connectivity = self.my_mesh.get_connectivity_by_elementids([1])[0]
        X_local = self.my_mesh.nodes_df.loc[connectivity].values.reshape(-1)
        u_local_indices = self.my_component.mapping.nodal2global.loc[
            connectivity].values.reshape(-1)
        u_local = self.S[u_local_indices, 0]
        fe_local = self.my_component.ele_obj[0].f_int(X_local, u_local)
        global_dofs = self.my_component.mapping.elements2global[0]
        g11_desired = np.zeros(self.no_of_dofs)
        g11_desired[global_dofs] = fe_local
        assert_allclose(g11_actual, g11_desired)
        # Test second entry of G
        g21_actual = G[self.no_of_dofs:, 0]
        connectivity = self.my_mesh.get_connectivity_by_elementids([1])[0]
        X_local = self.my_mesh.nodes_df.loc[connectivity].values.reshape(-1)
        u_local_indices = self.my_component.mapping.nodal2global.loc[
            connectivity].values.reshape(-1)
        u_local = self.S[u_local_indices, 1]
        fe_local = self.my_component.ele_obj[0].f_int(X_local, u_local)
        global_dofs = self.my_component.mapping.elements2global[0]
        g21_desired = np.zeros(self.no_of_dofs)
        g21_desired[global_dofs] = fe_local
        assert_allclose(g21_actual, g21_desired)
        # Test third entry of G
        g12_actual = G[0:self.no_of_dofs, 1]
        connectivity = self.my_mesh.get_connectivity_by_elementids([2])[0]
        X_local = self.my_mesh.nodes_df.loc[connectivity].values.reshape(-1)
        u_local_indices = self.my_component.mapping.nodal2global.loc[
            connectivity].values.reshape(-1)
        u_local = self.S[u_local_indices, 0]
        fe_local = self.my_component.ele_obj[1].f_int(X_local, u_local)
        global_dofs = self.my_component.mapping.elements2global[1]
        g12_desired = np.zeros(self.no_of_dofs)
        g12_desired[global_dofs] = fe_local
        assert_allclose(g12_actual, g12_desired)

        # --------------------------------------
        # check if b is correct:
        b_desired = np.sum(G, 1)
        assert_allclose(b, b_desired)

        # --------------------------------------
        # Check if old assembly is recovered

        # get f_new for comparison to f_old
        f_new = self.my_component.f_int(self.S[:, 0], dq, t)
        # test if old assembly is recovered in the component
        assert_allclose(f_new, f_old)

    def test_reduce_with_ecsw(self):
        # store old ids:
        comp_id_old = id(self.my_component)
        mesh_id_old = id(self.my_component.mesh)

        # first mode: deepcopy
        weights, indices, stats = ecsw_get_weights_by_component(
            self.my_component, self.S, self.W, self.timesteps, tau=0.01)
        ecsw_component = create_ecsw_hyperreduced_component_from_weights(
            self.my_component, weights, indices, copymode='deep')
        self.assertNotEqual(id(ecsw_component), comp_id_old)
        self.assertNotEqual(id(ecsw_component.mesh), mesh_id_old)
        self.assertIsInstance(ecsw_component.assembly, EcswAssembly)

        # second mode: shallow
        weights, indices, stats = ecsw_get_weights_by_component(
            self.my_component, self.S, self.W, self.timesteps, tau=0.01)
        ecsw_component = create_ecsw_hyperreduced_component_from_weights(
            self.my_component, weights, indices, copymode='shallow')
        self.assertNotEqual(id(ecsw_component), comp_id_old)
        self.assertEqual(id(ecsw_component.mesh), mesh_id_old)
        self.assertIsInstance(ecsw_component.assembly, EcswAssembly)

        # third mode: overwrite
        weights, indices, stats = ecsw_get_weights_by_component(
            self.my_component, self.S, self.W, self.timesteps, tau=0.01)
        ecsw_component = create_ecsw_hyperreduced_component_from_weights(
            self.my_component, weights, indices, copymode='overwrite')
        self.assertEqual(id(ecsw_component), comp_id_old)
        self.assertEqual(id(ecsw_component.mesh), mesh_id_old)
        self.assertIsInstance(ecsw_component.assembly, EcswAssembly)

        # test wrong copymode
        with self.assertRaises(ValueError):
            weights, indices, stats = ecsw_get_weights_by_component(
                self.my_component,
                self.S,
                self.W,
                self.timesteps,
                tau=0.01,
                conv_stats=False)
            ecsw_component = create_ecsw_hyperreduced_component_from_weights(
                self.my_component, weights, indices, copymode='foo')
        # test if function with option stats = false is executable
        weights, indices, stats = ecsw_get_weights_by_component(
            self.my_component,
            self.S,
            self.W,
            self.timesteps,
            tau=0.01,
            conv_stats=False)
        ecsw_component = create_ecsw_hyperreduced_component_from_weights(
            self.my_component, weights, indices)
        self.assertIsInstance(ecsw_component.assembly, EcswAssembly)
Example #8
0
#   Force:  g mm s-2 = µN
#   Stiffness: g s-2 mm-1 = Pa
#   velocity: mm/s
#   acceleration: mm/s^2
#   density: g/mm3

E_alu = 70e6
nu_alu = 0.34
rho_alu = 2.7e-3

logging.basicConfig(level=logging.DEBUG)


input_file = amfe_dir('meshes/amfe_json/simple_beam/simple_beam.json')
my_mesh = GidJsonMeshReader(input_file, AmfeMeshConverter()).parse()

my_material = KirchhoffMaterial(E_alu, nu_alu, rho_alu, thickness=10)

my_component = StructuralComponent(my_mesh)

my_component.assign_material(my_material, 'Quad8', 'S', 'shape')

my_neumann = FixedDirectionNeumann(np.array([0, 1]), time_func = lambda t: 2)
my_component.assign_neumann('Neumann0', my_neumann, ['right_boundary'], '_groups')

my_constraint = my_component.constraints.create_dirichlet_constraint()
fixed_nodeids = np.array([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], dtype=int)
my_component.assign_constraint('Dirichlet0', my_constraint, fixed_nodeids, '_nodeids', 'elim')


print('END')
Example #9
0
from amfe.material import KirchhoffMaterial
from amfe.component import StructuralComponent
from amfe.solver import SolverFactory, AmfeSolution
from amfe.solver.translators import create_constrained_mechanical_system_from_component
from amfe.structural_dynamics import vibration_modes

meshfile = amfe_dir('meshes/gmsh/AMFE_logo.msh')
output_file = amfe_dir('results/AMFE_logo/logo_5_v2.xdmf')

material_1 = KirchhoffMaterial(E=5E6, rho=1E4)
material_2 = KirchhoffMaterial(E=5E7, rho=1E4)

mesh = import_mesh_from_file(meshfile)

my_component = StructuralComponent(mesh)
my_component.assign_material(material_1, [299, 300], 'S')
my_component.assign_material(material_2, [301, 302], 'S')

set_dirichlet_by_group(my_component, 298, ('ux', 'uy', 'uz'))

no_of_dofs = my_component.mapping.no_of_dofs
q0 = np.zeros(no_of_dofs)
nodeids = my_component.mesh.nodes_df.index.to_list()
dofnumbers = my_component.mapping.get_dofs_by_nodeids(nodeids, ('uy', ))
M_unconstr = my_component.M(q0, q0, 0.0)

g = np.zeros_like(q0)
for dofnumber in dofnumbers:
    g[dofnumber] = -9.81

f_gravity = M_unconstr @ g
Example #10
0
from amfe.io.postprocessing.writer import Hdf5PostProcessorWriter
from amfe.solver.translators import *


times = dict([])
input_file = amfe_dir('meshes/gmsh/bar.msh')
output_file = amfe_dir('results/test_refactoring/nonlinear_beam_new_translators')

mesh_reader = GmshAsciiMeshReader(input_file)
mesh_converter = AmfeMeshConverter()
mesh_reader.parse(mesh_converter)
mesh = mesh_converter.return_mesh()

my_component = StructuralComponent(mesh)
my_material = KirchhoffMaterial(E=210E9, nu=0.3, rho=1E4, plane_stress=True)
my_component.assign_material(my_material, [7], 'S', '_groups')



dirichlet = my_component.constraints.create_dirichlet_constraint()

# Variant A
# (xy, direction)
#nodeids = mesh.get_nodeids_by_groups([8])
#dofs = my_component.mapping.get_dofs_by_nodeids(nodeids, ('ux', 'uy'))
#for dof in dofs.reshape(-1):
    #my_component.assign_constraint('Leftfixation', dirichlet, np.array([dof], dtype=int), np.array([], dtype=int))

#neumann = my_component.neumann.create_fixed_direction_neumann((0, -1),
                                                               #lambda t: 1E8*np.sin(31*t))
Example #11
0
logging.basicConfig(level=logging.DEBUG)

input_file = amfe_dir(
    'meshes/gmsh/simple_beam_metis_10/simple_beam_metis_10.msh')
mesh_reader = GmshAsciiMeshReader(input_file)
mesh_converter = AmfeMeshConverter()
mesh_reader.parse(mesh_converter)
my_mesh = mesh_converter.return_mesh()

my_material = KirchhoffMaterial(E_alu, nu_alu, rho_alu, thickness=10)

my_component = StructuralComponent(my_mesh)

material_tag = ['material']
my_component.assign_material(my_material, material_tag, 'S', '_groups')

glo_dofs_x = my_component.mapping.get_dofs_by_nodeids(
    my_component.mesh.get_nodeids_by_groups(['dirichlet']), ('ux'))
glo_dofs_y = my_component.mapping.get_dofs_by_nodeids(
    my_component.mesh.get_nodeid_by_coordinates(0.0, 0.0, 0.0), ('uy'))
my_composite = MeshComponentComposite(my_component)
# Decomposition of component
tree_builder = TreeBuilder()
tree_builder.add([0], [my_composite])
leaf_id = tree_builder.leaf_paths.max_leaf_id
tree_builder.separate_partitioned_component_by_leafid(leaf_id)

structural_composite = tree_builder.root_composite.components[0]

# Neumann conditions
Example #12
0
class AmfeSolutionReaderTest(TestCase):
    def setUp(self):
        self.timesteps, self.meshreader, self.fields_desired, \
        self.fields_no_of_nodes, self.fields_no_of_timesteps = create_fields(2)

        amfesolution = AmfeSolution()
        sol = self.fields_desired['Nodefield1']
        strains = copy(self.fields_desired['NodefieldStrains'])
        stresses = copy(self.fields_desired['NodefieldStresses'])
        for i in range(len(sol['timesteps'])):
            t = sol['timesteps'][i]
            q = sol['data'][:, i].T
            strain = strains['data'][:, :, i].T
            stress = stresses['data'][:, :, i].T
            amfesolution.write_timestep(t, q, q, q, strain, stress)

        self.mesh = create_amfe_obj()
        self.meshcomponent = StructuralComponent(self.mesh)
        # Set a material to get a mapping
        material = KirchhoffMaterial()
        self.meshcomponent.assign_material(material, 'Tri6', 'S', 'shape')

        self.postprocessorreader = AmfeSolutionReader(amfesolution,
                                                      self.meshcomponent)

    def tearDown(self):
        pass

    def test_parse(self):
        #meshreader = AmfeMeshObjMeshReader(self.mesh)
        postprocessorwriter = DummyPostProcessorWriter(self.meshreader)
        self.postprocessorreader.parse(postprocessorwriter)
        fields_actual = postprocessorwriter.return_result()

        field_desired = self.fields_desired['Nodefield1']
        q = field_desired['data']
        dofs_x = self.meshcomponent.mapping.get_dofs_by_nodeids(
            self.meshcomponent.mesh.nodes_df.index.values, ('ux'))
        dofs_y = self.meshcomponent.mapping.get_dofs_by_nodeids(
            self.meshcomponent.mesh.nodes_df.index.values, ('uy'))
        q_x = q[dofs_x, :]
        q_y = q[dofs_y, :]
        data = np.empty((0, 3, 4), dtype=float)
        for node in self.meshcomponent.mesh.get_nodeidxs_by_all():
            data = np.concatenate(
                (data,
                 np.array([[q_x[node], q_y[node],
                            np.zeros(q_x.shape[1])]])),
                axis=0)
        field_desired['data'] = data

        def _get_desired_strain_stress_fields(nodeidxs, field):
            normal_desired = copy(field)
            shear_desired = copy(field)
            values = field['data']
            data1 = np.empty((0, 3, 4), dtype=float)
            data2 = np.empty((0, 3, 4), dtype=float)

            for node in nodeidxs:
                data1 = np.concatenate(
                    (data1,
                     np.array([[
                         values[0, node], values[1, node], values[2, node]
                     ]])),
                    axis=0)
                data2 = np.concatenate(
                    (data2,
                     np.array([[
                         values[3, node], values[4, node], values[5, node]
                     ]])),
                    axis=0)

            normal_desired['data'] = data1
            shear_desired['data'] = data2
            return normal_desired, shear_desired

        strains_normal_desired, strains_shear_desired = \
            _get_desired_strain_stress_fields(self.meshcomponent.mesh.get_nodeidxs_by_all(),
                                              self.fields_desired['NodefieldStrains'])

        stresses_normal_desired, stresses_shear_desired = \
            _get_desired_strain_stress_fields(self.meshcomponent.mesh.get_nodeidxs_by_all(),
                                              self.fields_desired['NodefieldStresses'])
        # Check no of fields:
        self.assertEqual(len(fields_actual.keys()), 7)
        # Check each field:
        field_displacement_actual = fields_actual['displacement']
        assert_array_equal(field_displacement_actual['timesteps'],
                           field_desired['timesteps'])
        assert_array_equal(field_displacement_actual['data_type'],
                           field_desired['data_type'])
        assert_array_equal(field_displacement_actual['data'],
                           field_desired['data'])
        assert_array_equal(field_displacement_actual['index'],
                           field_desired['index'])
        assert_array_equal(field_displacement_actual['mesh_entity_type'],
                           field_desired['mesh_entity_type'])
        field_velocity_actual = fields_actual['velocity']
        assert_array_equal(field_velocity_actual['timesteps'],
                           field_desired['timesteps'])
        assert_array_equal(field_velocity_actual['data_type'],
                           field_desired['data_type'])
        assert_array_equal(field_velocity_actual['data'],
                           field_desired['data'])
        assert_array_equal(field_velocity_actual['index'],
                           field_desired['index'])
        assert_array_equal(field_velocity_actual['mesh_entity_type'],
                           field_desired['mesh_entity_type'])
        field_acceleration_actual = fields_actual['acceleration']
        assert_array_equal(field_acceleration_actual['timesteps'],
                           field_desired['timesteps'])
        assert_array_equal(field_acceleration_actual['data_type'],
                           field_desired['data_type'])
        assert_array_equal(field_acceleration_actual['data'],
                           field_desired['data'])
        assert_array_equal(field_acceleration_actual['index'],
                           field_desired['index'])
        assert_array_equal(field_acceleration_actual['mesh_entity_type'],
                           field_desired['mesh_entity_type'])
        field_acceleration_actual = fields_actual['strains_normal']
        assert_array_equal(field_acceleration_actual['timesteps'],
                           strains_normal_desired['timesteps'])
        assert_array_equal(field_acceleration_actual['data_type'],
                           strains_normal_desired['data_type'])
        assert_array_equal(field_acceleration_actual['data'],
                           strains_normal_desired['data'])
        assert_array_equal(field_acceleration_actual['index'],
                           strains_normal_desired['index'])
        assert_array_equal(field_acceleration_actual['mesh_entity_type'],
                           strains_normal_desired['mesh_entity_type'])
        field_acceleration_actual = fields_actual['strains_shear']
        assert_array_equal(field_acceleration_actual['timesteps'],
                           strains_shear_desired['timesteps'])
        assert_array_equal(field_acceleration_actual['data_type'],
                           strains_shear_desired['data_type'])
        assert_array_equal(field_acceleration_actual['data'],
                           strains_shear_desired['data'])
        assert_array_equal(field_acceleration_actual['index'],
                           strains_shear_desired['index'])
        assert_array_equal(field_acceleration_actual['mesh_entity_type'],
                           strains_shear_desired['mesh_entity_type'])
        field_acceleration_actual = fields_actual['stresses_normal']
        assert_array_equal(field_acceleration_actual['timesteps'],
                           stresses_normal_desired['timesteps'])
        assert_array_equal(field_acceleration_actual['data_type'],
                           stresses_normal_desired['data_type'])
        assert_array_equal(field_acceleration_actual['data'],
                           stresses_normal_desired['data'])
        assert_array_equal(field_acceleration_actual['index'],
                           stresses_normal_desired['index'])
        assert_array_equal(field_acceleration_actual['mesh_entity_type'],
                           stresses_normal_desired['mesh_entity_type'])
        field_acceleration_actual = fields_actual['stresses_shear']
        assert_array_equal(field_acceleration_actual['timesteps'],
                           stresses_shear_desired['timesteps'])
        assert_array_equal(field_acceleration_actual['data_type'],
                           stresses_shear_desired['data_type'])
        assert_array_equal(field_acceleration_actual['data'],
                           stresses_shear_desired['data'])
        assert_array_equal(field_acceleration_actual['index'],
                           stresses_shear_desired['index'])
        assert_array_equal(field_acceleration_actual['mesh_entity_type'],
                           stresses_shear_desired['mesh_entity_type'])

    def test_convert_data_2_field(self):
        sol = self.fields_desired['Nodefield1']
        data_test = sol['data']
        field_actual = self.postprocessorreader._convert_data_2_field(
            data_test)

        dofs_x = self.meshcomponent.mapping.get_dofs_by_nodeids(
            self.meshcomponent.mesh.nodes_df.index.values, ('ux'))
        dofs_y = self.meshcomponent.mapping.get_dofs_by_nodeids(
            self.meshcomponent.mesh.nodes_df.index.values, ('uy'))
        q_x = data_test[dofs_x, :]
        q_y = data_test[dofs_y, :]
        field_desired = np.empty((0, 3, 4), dtype=float)
        for node in self.meshcomponent.mesh.get_nodeidxs_by_all():
            field_desired = np.concatenate(
                (field_desired,
                 np.array([[q_x[node], q_y[node],
                            np.zeros(q_x.shape[1])]])),
                axis=0)

        assert_array_equal(field_actual, field_desired)

    def test_convert_data_2_normal(self):
        sol = self.fields_desired['NodefieldStrains']
        data_test = sol['data']
        field_actual = self.postprocessorreader._convert_data_2_normal(
            data_test)

        field_desired = np.empty((0, 3, 4), dtype=float)
        for node in self.meshcomponent.mesh.get_nodeidxs_by_all():
            field_desired = np.concatenate(
                (field_desired,
                 np.array([[
                     data_test[0, node], data_test[1, node], data_test[2, node]
                 ]])),
                axis=0)

        assert_array_equal(field_actual, field_desired)

    def test_convert_data_2_shear(self):
        sol = self.fields_desired['NodefieldStrains']
        data_test = sol['data']
        field_actual = self.postprocessorreader._convert_data_2_shear(
            data_test)

        field_desired = np.empty((0, 3, 4), dtype=float)
        for node in self.meshcomponent.mesh.get_nodeidxs_by_all():
            field_desired = np.concatenate(
                (field_desired,
                 np.array([[
                     data_test[3, node], data_test[4, node], data_test[5, node]
                 ]])),
                axis=0)

        assert_array_equal(field_actual, field_desired)