Esempio n. 1
0
def solve_modes(system,
                formulation,
                no_of_modes=10,
                x0=None,
                dx0=None,
                t0=0.0,
                hertz=True):
    """
    Computes the modes of a system, and returns them in a AmfeSolution container

    Parameters
    ----------
    system : MechanicalSystem
        mechanical system
    formulation : ConstraintFormulation
        A ConstraintFormulation object that can recover the nodal unconstrained displacements of the component
        from the constrained states of the system
    no_of_modes : int
        number of modes to compute
    x0 : array_like
        state vector at which the system is linearized
    dx0 : array_like
        derivative of the state vector at which the system is linearized
    t0 : array_like
        time at which the system is linearized
    hertz: bool
        specifies if frequency is measured in Hertz, If False, then the unit 1/s (omega) is used

    Returns
    -------
    modes : AmfeSolution
        AMfeSolution container containing the modes as timesteps. The times are the frequencies of the modes and
        the displacements the corresponding mode shapes.
    """

    if x0 is None:
        x0 = np.zeros(system.dimension)
    if dx0 is None:
        dx0 = np.zeros(system.dimension)

    omega, V = vibration_modes(system.K(x0, dx0, t0), system.M(x0, dx0, t0),
                               no_of_modes)
    modes = AmfeSolution()
    for om, phi in zip(omega, V.T):
        if hertz:
            om = om / (2 * np.pi)
        u_unconstr = formulation.u(phi, 0.0)
        modes.write_timestep(om, u_unconstr)
    return modes
Esempio n. 2
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)
Esempio n. 3
0
def solve_linear_static(system, formulation, component):
    """
    Solves a linear, static MechanicalSystem.

    Parameters
    ----------
    system : MechanicalSystem
        MechanicalSystem object describing the equilibrium forces
    formulation : ConstraintFormulation
        A ConstraintFormulation object that can recover the nodal unconstrained displacements of the component
        from the constrained states of the system
    component : StructuralComponent
        Structural Component belonging to the system

    Returns
    -------
    solution : AmfeSolution
        Simple Container for solutions of AMfe simulations
    """
    solfac = SolverFactory()
    solfac.set_system(system)
    solfac.set_analysis_type('static')
    solfac.set_linear_solver('scipy-sparse')

    solver, solver_options = solfac.create_solver()

    solution_writer = AmfeSolution()

    no_of_dofs = system.dimension
    q0 = np.zeros(no_of_dofs)
    dq0 = q0
    ddq0 = dq0

    q = solver.solve(system.K(q0, dq0, 0), system.f_ext(q0, dq0, 0))
    u, du, ddu = formulation.recover(q, dq0, ddq0, 0)
    solution_writer.write_timestep(0, u, None, None)
    logger = logging.getLogger(__name__)
    logger.info(
        'Strains and stresses are currently not supported for linear models. Only nonlinear kinematics are '
        'currently used during their calculation.')

    print('Solution finished')
    return solution_writer
Esempio n. 4
0
def solve_linear_static(component):
    system, formulation = create_mechanical_system(
        component,
        constant_mass=True,
        constant_damping=True,
        constraint_formulation='boolean')

    solver = ScipySparseLinearSolver()

    no_of_dofs = system.dimension
    q0 = np.zeros(no_of_dofs)
    dq0 = q0

    x = solver.solve(system.K(q0, dq0, 0.0), system.f_ext(q0, dq0, 0.0))

    u, _, _ = formulation.recover(x, q0, q0, 0.0)
    solution_writer = AmfeSolution()
    solution_writer.write_timestep(0.0, u, None, None)

    return solution_writer
Esempio n. 5
0
    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)
Esempio n. 6
0
    def test_amfe_solution(self):
        # Only q
        solution = AmfeSolution()
        q1 = np.arange(0, 60, dtype=float)
        q2 = np.arange(10, 70, dtype=float)
        t1 = 0.1
        t2 = 0.5

        solution.write_timestep(t1, q1)
        solution.write_timestep(t2, q2)

        assert_array_equal(solution.q[0], q1)
        assert_array_equal(solution.q[1], q2)
        self.assertEqual(solution.t[0], t1)
        self.assertEqual(solution.t[1], t2)
        self.assertTrue(len(solution.t) == len(solution.q))
        self.assertEqual(len(solution.t), 2)

        # q and dq
        solution = AmfeSolution()
        dq1 = np.arange(20, 80, dtype=float)
        dq2 = np.arange(30, 90, dtype=float)

        solution.write_timestep(t1, q1, dq1)
        solution.write_timestep(t2, q2, dq2)

        assert_array_equal(solution.q[0], q1)
        assert_array_equal(solution.q[1], q2)
        assert_array_equal(solution.dq[0], dq1)
        assert_array_equal(solution.dq[1], dq2)
        self.assertEqual(solution.t[0], t1)
        self.assertEqual(solution.t[1], t2)
        self.assertTrue(len(solution.t) == len(solution.q))
        self.assertTrue(len(solution.t) == len(solution.dq))
        self.assertEqual(len(solution.t), 2)

        # q, dq and ddq
        solution = AmfeSolution()
        ddq1 = np.arange(40, 100, dtype=float)
        ddq2 = np.arange(50, 110, dtype=float)

        solution.write_timestep(t1, q1, dq1, ddq1)
        solution.write_timestep(t2, q2, dq2, ddq2)

        assert_array_equal(solution.q[0], q1)
        assert_array_equal(solution.q[1], q2)
        assert_array_equal(solution.dq[0], dq1)
        assert_array_equal(solution.dq[1], dq2)
        assert_array_equal(solution.ddq[0], ddq1)
        assert_array_equal(solution.ddq[1], ddq2)
        self.assertEqual(solution.t[0], t1)
        self.assertEqual(solution.t[1], t2)
        self.assertTrue(len(solution.t) == len(solution.q))
        self.assertTrue(len(solution.t) == len(solution.dq))
        self.assertTrue(len(solution.t) == len(solution.ddq))
        self.assertEqual(len(solution.t), 2)

        # q and ddq
        solution = AmfeSolution()

        solution.write_timestep(t1, q1, ddq=ddq1)
        solution.write_timestep(t2, q2, ddq=ddq2)

        assert_array_equal(solution.q[0], q1)
        assert_array_equal(solution.q[1], q2)
        assert_array_equal(solution.ddq[0], ddq1)
        assert_array_equal(solution.ddq[1], ddq2)
        self.assertEqual(solution.t[0], t1)
        self.assertEqual(solution.t[1], t2)
        self.assertTrue(len(solution.t) == len(solution.q))
        self.assertTrue(len(solution.t) == len(solution.ddq))
        self.assertEqual(len(solution.t), 2)
        self.assertIsNone(solution.dq[0])
        self.assertIsNone(solution.dq[1])

        # q and strains
        solution = AmfeSolution()
        strains1 = np.random.rand(60, 6)
        strains2 = np.random.rand(60, 6)

        solution.write_timestep(t1, q1, strain=strains1)
        solution.write_timestep(t2, q2, strain=strains2)
        self.assertEqual(solution.t[0], t1)
        self.assertEqual(solution.t[1], t2)
        assert_array_equal(solution.q[0], q1)
        assert_array_equal(solution.q[1], q2)
        assert_array_equal(solution.strain[0], strains1)
        assert_array_equal(solution.strain[1], strains2)
        self.assertIsNone(solution.stress[0])
        self.assertIsNone(solution.stress[1])

        # q, strains and stresses
        solution = AmfeSolution()
        strains1 = np.random.rand(60, 6)
        strains2 = np.random.rand(60, 6)
        stresses1 = np.random.rand(60, 6)
        stresses2 = np.random.rand(60, 6)

        solution.write_timestep(t1, q1, strain=strains1, stress=stresses1)
        solution.write_timestep(t2, q2, strain=strains2, stress=stresses2)
        self.assertEqual(solution.t[0], t1)
        self.assertEqual(solution.t[1], t2)
        assert_array_equal(solution.q[0], q1)
        assert_array_equal(solution.q[1], q2)
        assert_array_equal(solution.strain[0], strains1)
        assert_array_equal(solution.strain[1], strains2)
        assert_array_equal(solution.stress[0], stresses1)
        assert_array_equal(solution.stress[1], stresses2)
        return
Esempio n. 7
0
    structural_composite.assign_constraint('Dirichlet1', dirichlet,
                                           np.array([dof], dtype=int), [])

# FETI-solver
substructured_system = MulticomponentMechanicalSystem(structural_composite,
                                                      'boolean')

fetisolver = FETISolver()
q_dict = fetisolver.solve(substructured_system.mechanical_systems,
                          substructured_system.connections)
u_dict, du_dict, ddu_dict = substructured_system.recover(q_dict)

# Exporter
for i_comp, comp in structural_composite.components.items():
    writer = AmfeSolution()
    writer.write_timestep(0, u_dict[i_comp], None, None)

    mesh = comp._mesh
    preader = AmfeSolutionReader(writer, comp)
    amfeMeshReader = AmfeMeshObjMeshReader(mesh)
    path = amfe_dir(
        'meshes/gmsh/simple_beam_metis_10/results/partition_mesh_' +
        str(i_comp) + '.vtk')
    VTKwriter = VtkMeshConverter(path)

    amfeMeshReader.parse(VTKwriter)
    VTKwriter.return_mesh()

    hdf5resultsfilename = amfe_dir(
        'meshes/gmsh/simple_beam_metis_10/results/partition_mesh_' +
        str(i_comp) + '.hdf5')