Пример #1
0
def solve_nonlinear_dynamic(component, t0, t_end):
    system, formulation = create_mechanical_system(
        component,
        constant_mass=True,
        constant_damping=True,
        constraint_formulation='boolean')

    solfac = SolverFactory()
    solfac.set_system(system)
    solfac.set_analysis_type('transient')
    solfac.set_integrator('genalpha')
    solfac.set_large_deflection(True)
    solfac.set_nonlinear_solver('newton')
    solfac.set_linear_solver('scipy-sparse')
    solfac.set_acceleration_intializer('zero')
    solfac.set_newton_maxiter(30)
    solfac.set_newton_atol(1e-6)
    solfac.set_newton_rtol(1e-8)
    solfac.set_dt_initial(0.001)

    solver = solfac.create_solver()

    solution_writer = AmfeSolution()

    def write_callback(t, x, dx, ddx):
        u, du, ddu = formulation.recover(x, dx, ddx, t)
        solution_writer.write_timestep(t, u, None, None)

    no_of_dofs = system.dimension
    q0 = np.zeros(no_of_dofs)
    dq0 = q0
    solver.solve(write_callback, t0, q0, dq0, t_end)

    return solution_writer
Пример #2
0
def solve_nonlinear_static(system, formulation, component, load_steps):
    """
    Solves a MechanicalSystem using a nonlinear static method using newton for the nonlinear solver.
    The deformation is divided into an amount of intermediate steps which are defined in the number of load_steps.

    Parameters
    ----------
    system : MechanicalSystem
        Created MechanicalSystem object describing the Structural Component
    formulation : ConstraintFormulation
        A ConstraintFormulation object that can recover the nodal unconstrained displacements of the component
        from the constrained states of the system
    component : StructuralComponent
        StructuralComponent belonging to the system
    load_steps : int
        Number of load steps used for the solution

    Returns
    -------
    solution : amfe.solution.AmfeSolution
        Simple Container for solutions of AMfe simulations
    """
    solfac = SolverFactory()
    solfac.set_system(system)
    solfac.set_analysis_type('static')
    solfac.set_nonlinear_solver('newton')
    solfac.set_linear_solver('scipy-sparse')
    solfac.set_acceleration_intializer('zero')
    solfac.set_newton_maxiter(10)
    solfac.set_newton_atol(1e-8)
    solfac.set_newton_rtol(2e-9)
    solfac.set_dt_initial(1.0 / load_steps)

    solver = solfac.create_solver()

    solution_writer = AmfeSolution()

    no_of_dofs = system.dimension
    q0 = np.zeros(no_of_dofs)
    dq0 = q0
    t0 = 0.0
    t_end = 1.0

    def write_callback(t, x, dx, ddx):
        if isclose(t, t_end):
            u, du, ddu = formulation.recover(x, dx, ddx, t)
            strains, stresses = component.strains_and_stresses(u, du, t)
            solution_writer.write_timestep(t, u, None, None, strains, stresses)

    solver.solve(write_callback, t0, q0, dq0, t_end)

    print('Solution finished')
    return solution_writer
Пример #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
Пример #4
0
    constant_mass=True,
    constant_damping=True,
    constraint_formulation='boolean')

solfac = SolverFactory()

solfac.set_system(system)
solfac.set_analysis_type('static')
solfac.set_dt_initial(0.05)
solfac.set_analysis_type('zero')
solfac.set_linear_solver('pardiso')
solfac.set_newton_verbose(True)
solfac.set_nonlinear_solver('newton')
solfac.set_newton_atol(1e-5)
solfac.set_newton_rtol(1e-7)
solver = solfac.create_solver()

solution = AmfeSolution()


def write_callback(t, x, dx, ddx):
    u, du, ddu = formulation.recover(x, dx, ddx, t)
    solution.write_timestep(t, u, du, ddu)


x0 = np.zeros(system.dimension)
dx0 = x0.copy()
t0 = 0.0
t_end = 1.0

solver.solve(write_callback, t0, x0, dx0, t_end)
Пример #5
0
def solve_nonlinear_dynamic(system,
                            formulation,
                            component,
                            t0,
                            t_end,
                            dt,
                            write_each=1):
    """
    Solves a system

    Parameters
    ----------
    system : MechanicalSystem
        Created MechanicalSystem object describing the Structural Component
    formulation : ConstraintFormulation
        A ConstraintFormulation object that can recover the nodal unconstrained displacements of the component
        from the constrained states of the system
    component : StructuralComponent
        StructuralComponent belonging to the system
    t0 : float
        initial time
    t_end : float
        final time
    dt : float
        increment between time steps
    write_each : int
        Specifies that the solver writes every n'th solution (eg. type 2 to write every second timestep)

    Returns
    -------
    solution : amfe.solution.AmfeSolution
        Simple Container for solutions of AMfe simulations
    """
    solfac = SolverFactory()
    solfac.set_system(system)
    solfac.set_analysis_type('transient')
    solfac.set_integrator('genalpha')
    solfac.set_nonlinear_solver('newton')
    solfac.set_linear_solver('scipy-sparse')
    solfac.set_acceleration_intializer('zero')
    solfac.set_newton_maxiter(10)
    solfac.set_newton_atol(1e-8)
    solfac.set_newton_rtol(2e-11)
    solfac.set_dt_initial(dt)

    solver = solfac.create_solver()

    solution_writer = AmfeSolution()

    def write_callback(t, x, dx, ddx):
        cur_ts = int((t - t0) // dt)
        if abs(cur_ts % write_each) <= 1e-7:
            u, du, ddu = formulation.recover(x, dx, ddx, t)
            strains, stresses = component.strains_and_stresses(u, du, t)
            solution_writer.write_timestep(t, u, du, ddu, strains, stresses)

    no_of_dofs = system.dimension
    q0 = np.zeros(no_of_dofs)
    dq0 = q0
    solver.solve(write_callback, t0, q0, dq0, t_end)

    print('Solution finished')
    return solution_writer
Пример #6
0
def solve_linear_dynamic(system,
                         formulation,
                         component,
                         t0,
                         t_end,
                         dt,
                         write_each=1):
    """
    Solves a linear, dynamic MechanicalSystem from t0 to t_end with dt as intermediate steps.

    Parameters
    ----------
    system : MechanicalSystem
        MechanicalSystem object describing the equations of motion
    formulation : ConstraintFormulation
        A ConstraintFormulation object that can recover the nodal unconstrained displacements of the component
        from the constrained states of the system
    component : StructuralComponent
        StructuralComponent belonging to the system
    t0 : float
        initial time
    t_end : float
        final time
    dt : float
        increment between time steps
    write_each : int
        Specifies that the solver writes every n'th solution (eg. type 2 to write every second timestep)

    Returns
    -------
    solution : amfe.solution.AmfeSolution
        AmfeSolution container that contains the solution
    """
    solfac = SolverFactory()
    solfac.set_system(system)
    solfac.set_analysis_type('transient')
    solfac.set_linear_solver('scipy-sparse')
    solfac.set_integrator('newmarkbeta')
    solfac.set_acceleration_intializer('zero')
    solfac.set_dt_initial(dt)

    solver = solfac.create_solver()

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

    solution_writer = AmfeSolution()

    def write_callback(t, x, dx, ddx):
        cur_ts = int((t - t0) // dt)
        if abs(cur_ts % write_each) <= 1e-7:
            u, du, ddu = formulation.recover(x, dx, ddx, t)
            solution_writer.write_timestep(t, u, du, ddu)

    solver.solve(write_callback, t0, q0, dq0, t_end)

    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