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
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
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 residuals = list()
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