Exemplo n.º 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
Exemplo n.º 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
Exemplo n.º 3
0
# ----------------------------------------- NONLINEAR DYNAMIC ANALYSIS ------------------------------------------------

system, formulation = create_constrained_mechanical_system_from_component(my_component, constant_mass=True,
                                                                          constant_damping=True,
                                                                          constraint_formulation='lagrange',
                                                                          scaling=10.0, penalty=3.0)

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(20)
solfac.set_newton_atol(1e-8)
solfac.set_newton_rtol(1e-9)
solfac.set_dt_initial(0.00001)
solfac._alpha_f = 0.25
solfac._alpha_m = 0.25
solfac._gamma = 0.75
solfac._beta = 0.390625


residuals = list()

mysolver = solfac.create_solver()
writer = AmfeSolution()

Exemplo n.º 4
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