예제 #1
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
예제 #2
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
예제 #3
0
set_dirichlet_by_group(my_component, 83, ('ux', 'uy', 'uz'))

set_neumann_by_group(my_component,
                     85,
                     np.array([0.0, 1.0, 0.0]),
                     F=lambda t: 1E6 * t)

#%%
system, formulation = create_constrained_mechanical_system_from_component(
    my_component,
    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()

예제 #4
0
for dof in supportdofs_x.reshape(-1):
    my_component.assign_constraint('Leftfixation', dirichlet, np.array([dof], dtype=int), np.array([], dtype=int))

for dof in supportdofs_y.reshape(-1):
    my_component.assign_constraint('Leftmotion', dirichlet2, np.array([dof], dtype=int), np.array([], dtype=int))
# END Variant B


# ----------------------------------------- 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
예제 #5
0
    my_component.assign_constraint('Leftmotion', dirichlet2,
                                   np.array([dof], dtype=int),
                                   np.array([], dtype=int))
# END Variant B

# ----------------------------------------- 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_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)

residuals = list()

mysolver = solfac.create_solver()
예제 #6
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
예제 #7
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
예제 #8
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