fmm_solver module
Python wrapper for the native fedem dynamics solver which operates directly on fedem mechanism model files (*.fmm).
This module relies on the following environment variables:
The third variable needs to be set only if FE model reduction is to be performed. The fourth variable needs to be set only if a VTFx file is to be exported. The first two variables are mandatory.
This module can also be launched directly, to run a specified model, using the syntax
python -m fedempy.fmm_solver -f mymodel.fmm [--reduce-fem] [--save-model] [-v mymodel.vtfx]
This will then invoke the method fmm_solver.FmmSolver.solve_all()
on the specified model-file (mymodel.fmm). If you already have a directory
populated with Fedem solver input files, you can run the solver directly on
those files by launching this module without arguments, i.e.:
python -m fedempy.fmm_solver
- class fmm_solver.FmmInverse(model_file, config, use_internal_state=False, keep_res=False)[source]
Bases:
FmmSolver
,InverseSolver
This class augments FmmSolver with inverse solution capabilities.
- Parameters:
- model_filestr
Absolute path to the fedem model file to start the simulation on
- configdictionary
Inverse solver configuration
- use_internal_statebool, default=False
If True, internal state arrays are allocated (for microbatching)
- keep_resbool, default=False
Option to not overwrite any existing res-file in the RDB directory
Methods
add_rhs_vector
(r_vec)Utility updating the content of the system right-hand-side vector.
check_times
(xtimes[, use_times])Utility checking that a given time series starts with the current solver time.
close_model
([save, remove_singletons, ...])Closes the currently open model.
compute_int_forces_from_displ
(disp, ids)This method computes beam section forces in triads for the given displacement field.
compute_rel_dist_from_displ
(disp, ids)This method computes the relative distance at sensors for the given displacement field.
compute_spring_var_from_displ
(disp, ids)This method computes one of the spring variables (length, deflection, force) at sensors for the given displacement field.
compute_strains_from_displ
(disp, gauge_ids)This method computes the strain tensor at gauges for the given displacement field, or from current state if no displacements provided.
convert_rev_joint_force
(data)Modify the data set for spring force input for revolute joints with defined spring forces Conversation from force to lenght x=F/k (const.
finish_step
()This method completes current time (or load) step, by iterating the linearized equation system until convergence is achieved.
get_current_strains
(gauge_ids)This method computes the strain tensor at gauges from current state.
get_current_time
()Utility returning the current physical time of the simulation.
get_damping_matrix
()Utility returning current content of the system damping matrix.
get_element_stiffness_matrix
(bid)Utility returning the initial content of an element stiffness matrix.
get_equations
(bid)Utility returning the equation numbers for the DOFs of the object with the specified base Id (bid).
get_external_force_vector
()Utility returning current content of the external force vector.
get_function
([uid, tag, arg])Utility evaluating a general function in the model, identified by the specified user Id uid or tag, and with the function argument arg.
get_function_ids
(tags)Utility returning a list of user Ids of tagged general functions.
get_functions
(uids)Utility evaluating a list of general functions for current state.
get_gauge_size
()Utility returning the required size of the initial strain gauge array which is used when restarting a simulation from an in-core array.
get_joint_spring_stiffness
(bid)Get joint spring stiffness coefficient(s).
get_mass_matrix
()Utility returning current content of the system mass matrix.
get_newton_matrix
()Utility returning current content of the system Newton matrix.
get_next_time
()Utility returning the physical time of the next step of the simulation.
get_part_deformation_state_size
(base_id)Utility returning the required length of the state vector which stores deformation data for the FE Part with the given base Id.
get_part_stress_state_size
(base_id)Utility returning the required length of the state vector which stores von Mises stresses for the FE Part with the given base Id.
get_rhs_vector
()Utility returning current content of the system right-hand-side vector.
get_start_time
()Utility returning the start time of the simulation.
get_state_size
()Utility returning the required length of the state vector which is used when restarting a simulation from an in-core array.
get_stiffness_matrix
()Utility returning current content of the system stiffness matrix.
get_stop_time
()Utility returning the stop time of the simulation.
get_system_dofs
()Utiloty returning the total number of DOFs of the system.
get_system_size
()Utility returning the dimension (number of equations) of the system.
get_transformation_state_size
()Utility returning the required length of the vector which stores the transformation matrices (rotation and translation) for Triads, Parts and Beams.
have_results
()Utility returning whether current time step have results to be saved.
restart_from_state
(state_data[, write_to_rdb])This method re-initializes the mechanism objects with data from the provided state array, such that the simulation can continue from there.
run_all
(options)This method runs the dynamics solver with given command-line options, without any user intervention.
run_inverse
(inp_data, out_def)Collector for different inverse methods.
run_inverse_dyn
(inp_data, out_def)Inverse solution driver (dynamic case).
run_inverse_fedem
(inp_data, out_def)This method uses fedem's inverse solution in fortran
save_gauges
()This method stores initial gauge strains in the self.gauge_data array.
save_part_state
(base_id, def_state, str_state)This method stores current deformation- and stress states for the specified FE Part in the provided core arrays.
save_state
()This method stores current solver state in the self.state_data array.
save_transformation_state
(state_data)This method stores current transformation state for Triads, Parts and Beams in the provided core array.
set_ext_func
(func_id[, value])This method may be used prior to the solve_next call, to assign a sensor value from a physical twin to the specified actuator or load in the model, identified by the argument func_id (external function Id).
set_input
(func_tag[, value])This method may be used prior to the solve_next call, to assign a sensor value from a physical twin to the specified actuator or load in the model, identified by the argument func_tag.
set_rhs_vector
(r_vec)Utility replacing current content of the system right-hand-side vector.
solve_all
(model_file[, save_model, ...])Starts and runs through a simulation on the specified model file.
solve_inverse
(x_val, x_def, g_def[, out_def])This method solves the inverse problem at current time/load step, assuming small deformations only (linear response).
solve_iteration
()This method solves the current linearized equation system and updates all state variables.
solve_modes
(n_modes[, dof_order, use_lapack])This method solves the eigenvalue problem at current time step, and returns the computed eigenvalues and associated eigenvectors.
solve_next
([inp, inp_def, out_def, time_next])This method advances the solution one time/load step forward.
solve_window
(n_step[, inputs, f_out, xtimes])This method solves the problem for a time/load step window, with given values for the external functions, and extraction of results from another set of general functions in the model.
solver_close
()This method needs to be used if solver_done() was invoked with its remove_singletons argument set to False.
solver_done
([remove_singletons, print_res])This method should be used when the time/load step loop is finished.
solver_init
(options[, fsi, state_data, ...])This method processes the input and sets up necessary data structures prior to the time integration loop.
start
(model_file[, keep_old_res, ...])Starts a simulation on the specified model file.
start_step
([time_next])This method starts a new time (or load) step, by calculating the predicted response, the coefficient matrix and right-hand-side vector of the first nonlinear iteration.
- class fmm_solver.FmmSolver(model_file=None, use_internal_state=False, keep_old_res=False)[source]
Bases:
FedemSolver
This subclass of FedemSolver adds the possibility to start a simulation on a specified fedem model file.
- Parameters:
- model_filestr, default=None
Absolute path to the fedem model file to start the simulation on
- use_internal_statebool, default=False
If True, internal state arrays are allocated (for microbatching)
- keep_old_resbool, default=False
Option to not overwrite any existing res-file in the RDB directory
Methods
start:
Starts a simulation on the specified model file
close_model:
Closes the currently open model
solve_all:
Starts and runs through a simulation on the specified model file
set_input:
Assigns sensor value to a tagged external function
- close_model(save=False, remove_singletons=False, fringe_max=-1)[source]
Closes the currently open model.
- Parameters:
- savebool, default=False
If True, the model file is updated based on current result files
- remove_singletonsbool, default=False
If True, heap-allocated singelton objects are also released
- fringe_maxfloat, default=-1
Max fringe range value for VTFx output. If less than zero, the range will be set automatically.
- Returns:
- bool
True on success, otherwise False
- set_input(func_tag, value=None)[source]
This method may be used prior to the solve_next call, to assign a sensor value from a physical twin to the specified actuator or load in the model, identified by the argument func_tag.
- Parameters:
- func_tagstr
Tag of the external function to be assigned new value
- valuefloat, default=None
The value to be assigned
- Returns:
- bool
Always True, unless the specified function is not found
- solve_all(model_file, save_model=True, reduce_fem=False, vtfx_file=None, fringe_max=-1)[source]
Starts and runs through a simulation on the specified model file.
- Parameters:
- model_filestr
Absolute path of the Fedem model file to run the solver on
- save_modelbool, default=True
If True, save the model file with new results when solver finished
- reduce_fembool, default=False
If True, and the model contains FE parts, they will be reduced before the solver is started, unless the reduced matrix files already exist
- vtfx_filestr, default=None
Absolute path of the VTFx output file for visualization in GLview
- fringe_maxfloat, default=-1
Max fringe range value for VTFx output. If less than zero, the range will be set automatically.
- Returns:
- int
Zero on success, otherwise negative
- start(model_file, keep_old_res=False, close_model=False, reduce_fem=False, state_data=None, gauge_data=None, extf_input=None, time_start=None, vtfx_file=None)[source]
Starts a simulation on the specified model file.
- Parameters:
- model_filestr
Absolute path of the Fedem model file to run the solver on
- keep_old_resbool, default=False
Option to not overwrite any existing res-file in the RDB directory
- close_modelbool, default=False
If True, release the model from memory before solver start
- reduce_fembool, default=False
If True, and the model contains FE parts, they will be reduced before the solver is started, unless the reduced matrix files already exist
- state_datalist of float, default=None
Complete state vector to restart simulation from
- gauge_datalist of float, default=None
Initial strain gauge values for restart
- extf_inputlist of float, default=None
Initial external function values, for initial equilibrium iterations
- time_startfloat, default=None
Optional start time of simulation, override setting in model file
- vtfx_filestr, default=None
Absolute path of the VTFx output file for visualization in GLview
- Returns:
- int
Zero on success, otherwise negative