solver module

Python wrapper for the native fedem dynamics solver. Used for convenience in order to hide native type convertions.

exception solver.FedemException(errmsg)[source]

Bases: Exception

General exception-type for solver exceptions.

Parameters:
errmsgstr

Error message to print.

class solver.FedemSolver(lib_path, solver_options=None, use_internal_state=False)[source]

Bases: object

This class mirrors the functionality of the fedem dynamics solver library (libfedem_solver_core.so on Linux, fedem_solver_core.dll on Windows). See also the header file ../../../proprietary/vpmSolver/solverInterface.h

In addition to the methods for conducting the simulation itself, the class also contains several methods for accessing and manipulating the linearized equation system, to facilitate use by external solution algorithms.

Parameters:
lib_pathstr

Absolute path to the solver shared object library

solver_optionslist of str, default=None

List of command-line arguments passed to the solver

use_internal_statebool, default=False

If True, internal state arrays are allocated (for microbatching)

Methods

solver_init:

Processes the input and sets up necessary data structures

restart_from_state:

Re-initializes the mechanism objects with data from state array

solve_window:

Solves the problem for a time/load step window

get_state_size:

Returns the length of the state vector

get_gauge_size:

Returns the length of the initial strain gauge array

get_transformation_state_size:

Returns the length of the state vector holding transformation matrices

get_part_deformation_state_size:

Returns the length of the state vector holding deformation data

get_part_stress_state_size:

Returns the length of the state vector holding von Mises stress data

save_state:

Stores current solver state in the self.state_data array

save_gauges:

Stores initial gauge strains in the self.gauge_data array

save_transformation_state:

Stores current transformation state in provided core array

save_part_state:

Stores current deformation- and stress states in provided core arrays

solve_next:

Advances the solution one time/load step forward

start_step:

Starts a new time (or load) step

solve_iteration:

Solves current linearized equation system and updates state variables

finish_step:

Completes current time (or load) step

solve_modes:

Solves the eigenvalue problem at current time step

solve_inverse:

Solves the inverse problem at current time/load step

solver_done:

Closes down the model and cleans up heap memory and things on disk

solver_close:

Cleans up heap memory (singleton objects) on close

run_all:

Runs through the dynamics solver without any user intervention.

set_ext_func:

Assigns new value to an external function

get_current_time:

Returns the current physical time of the simulation

get_next_time:

Returns the physical time of the next step of the simulation

get_function:

Evaluates a general function in the model and returns its value

get_functions:

Evaluates several general functions in the model and returns their value

get_function_ids:

Returns a list of user Ids of tagged general functions

get_equations:

Returns the equation numbers associated with the DOFs of an object

get_system_size:

Returns the number of equations in the linearized system

get_system_dofs:

Returns the number of DOFs in the system

get_newton_matrix:

Returns current content of the system Newton matrix

get_stiffness_matrix:

Returns current content of the system stiffness matrix

get_mass_matrix:

Returns current content of the system mass matrix

get_damping_matrix:

Returns current content of the system damping matrix

get_element_stiffness_matrix:

Returns the content of a (beam) element stiffness matrix

get_rhs_vector:

Returns the content of the system right-hand-side vector

get_external_force_vector:

Returns the content of the external force vector

set_rhs_vector:

Replaces current content of the system right-hand-side vector

add_rhs_vector:

Updates the content of the system right-hand-side vector

compute_strains_from_displ:

Computes the strain tensor at gauges for given displacement field

get_current_strains:

Returns the current strain tensor for the specified gauges

compute_rel_dist_from_displ:

Computes relative distance at sensors for given displacement field

compute_int_forces_from_displ:

Computes beam section forces in triads for given displacement field

compute_spring_var_from_displ:

Computes one of the spring variables for given displacement field

get_joint_spring_stiffness:

Returns current joint spring stiffness coefficient(s)

add_rhs_vector(r_vec)[source]

Utility updating the content of the system right-hand-side vector.

check_times(xtimes, use_times=True)[source]

Utility checking that a given time series starts with the current solver time.

compute_int_forces_from_displ(disp, ids)[source]

This method computes beam section forces in triads for the given displacement field.

There are 2 cases:

InternalForce component defined by an array
dofi contains dof number in a certain direction i
ids = [ beamID1, triadID1, dof1, beamID2, triadID2, dof2, ….. ]
InternalSectionForces defined by an array
dofi contains always -1, 6 components are requested
ids = [ beamID1, triadID1, -1, beamID2, triadID2, -1, ….. ]
Parameters:
displist of float

Displacement field

idslist of int

Array with beam and triad identification numbers

Returns:
list of float

Force components

bool

Always True, unless the calculation failed

compute_rel_dist_from_displ(disp, ids)[source]

This method computes the relative distance at sensors for the given displacement field.

Parameters:
displist of float

Displacement field

idslist of int

Array with function identification numbers

Returns:
list of float

Displacement components

bool

Always True, unless the calculation failed

compute_spring_var_from_displ(disp, ids)[source]

This method computes one of the spring variables (length, deflection, force) at sensors for the given displacement field.

Parameters:
displist of float

Displacement field

idslist of int

Array with function identification numbers

Returns:
list of float

Displacement components

bool

Always True, unless the calculation failed

compute_strains_from_displ(disp, gauge_ids)[source]

This method computes the strain tensor at gauges for the given displacement field, or from current state if no displacements provided.

Parameters:
displist of float

Displacement field to evaluate strains from

gauge_idslist of int

Array with gauge identification numbers

Returns:
list of float

Strain components

bool

Always True, unless the calculation failed

finish_step()[source]

This method completes current time (or load) step, by iterating the linearized equation system until convergence is achieved. The self.ierr variable has the value zero on a successful computation. A non-zero value indicates some error that requires the simulation to terminate.

Returns:
bool

Always True, unless current time/load step failed to converge, or the end time of the simulation has been reached

get_current_strains(gauge_ids)[source]

This method computes the strain tensor at gauges from current state.

Parameters:
gauge_idslist of int

Array with gauge identification numbers

Returns:
list of float

Strain components

bool

Always True, unless the calculation failed

get_current_time()[source]

Utility returning the current physical time of the simulation. The self.ierr variable is not touched.

get_damping_matrix()[source]

Utility returning current content of the system damping matrix.

get_element_stiffness_matrix(bid)[source]

Utility returning the initial content of an element stiffness matrix. Use this method for beam elements only, 6 dof per node (total 12).

get_equations(bid)[source]

Utility returning the equation numbers for the DOFs of the object with the specified base Id (bid).

get_external_force_vector()[source]

Utility returning current content of the external force vector.

get_function(uid=0, tag=None, arg=None)[source]

Utility evaluating a general function in the model, identified by the specified user Id uid or tag, and with the function argument arg. If arg is None or contains a negative value, the function is instead evaluated for current state of the sensor object that is defined as the function argument. The same is done if a tag is specified. If the specified function could not be evaluated, the self.ierr variable is decremented. Otherwise, it is not touched.

get_function_ids(tags)[source]

Utility returning a list of user Ids of tagged general functions.

get_functions(uids)[source]

Utility evaluating a list of general functions for current state. The uids argument can be a list of either the user Ids of the functions to be evaluated, or their corresponding objects tags. If the specified functions could not be evaluated, the self.ierr variable is decremented for each problem encountered. Otherwise, it is not touched.

get_gauge_size()[source]

Utility returning the required size of the initial strain gauge array which is used when restarting a simulation from an in-core array. Returns 0 if the model does not contain any strain gauges.

get_joint_spring_stiffness(bid)[source]

Get joint spring stiffness coefficient(s).

Parameters:
bidint

Joint identification number (base ID)

Returns:
list of float

Spring stiffness coefficients for the joint DOFs

bool

Always True, unless the extraction failed

get_mass_matrix()[source]

Utility returning current content of the system mass matrix.

get_newton_matrix()[source]

Utility returning current content of the system Newton matrix.

get_next_time()[source]

Utility returning the physical time of the next step of the simulation. If the time step size is defined by a general function that could not be evaluated, the self.ierr variable is decremented. Otherwise, it is not touched.

get_part_deformation_state_size(base_id)[source]

Utility returning the required length of the state vector which stores deformation data for the FE Part with the given base Id. Returns -1 if the specified Part does not exist.

The size/length of the state vector is:
(number of nodal points in the FE Part) * 3
get_part_stress_state_size(base_id)[source]

Utility returning the required length of the state vector which stores von Mises stresses for the FE Part with the given base Id. Returns -1 if the specified Part does not exist, and 0 if the specified Part does not contain any (shell or solid) elements with stresses.

get_rhs_vector()[source]

Utility returning current content of the system right-hand-side vector.

get_state_size()[source]

Utility returning the required length of the state vector which is used when restarting a simulation from an in-core array.

get_stiffness_matrix()[source]

Utility returning current content of the system stiffness matrix.

get_system_dofs()[source]

Utiloty returning the total number of DOFs of the system.

get_system_size()[source]

Utility returning the dimension (number of equations) of the system.

get_transformation_state_size()[source]

Utility returning the required length of the vector which stores the transformation matrices (rotation and translation) for Triads, Parts and Beams.

The size/length of the state vector is:
3 +
(number of Triads) * 14 +
(number of Parts) * 14
(number of Beams) * 14
restart_from_state(state_data, write_to_rdb=2)[source]

This method re-initializes the mechanism objects with data from the provided state array, such that the simulation can continue from there.

Parameters:
state_datalist of float

Complete state vector to restart simulation from

write_to_rdbint, default=2
Flag for saving response variables to results database,
= 0 : No results saving,
= 1 : Append results to already opened results database,
= 2 : Increment the results database and write to new files
Returns:
int

Zero on success, a negative value indicates some error

run_all(options)[source]

This method runs the dynamics solver with given command-line options, without any user intervention.

save_gauges()[source]

This method stores initial gauge strains in the self.gauge_data array.

Returns:
bool

Always True, unless the self.gauge_data array is too small

save_part_state(base_id, def_state, str_state)[source]

This method stores current deformation- and stress states for the specified FE Part in the provided core arrays.

Parameters:
base_idint

Base Id of the FE Part to save state for

def_statelist of c_double

Array to fill with deformation data

str_statelist of c_couble

Array to fill with stress data

Returns:
bool

Always True, unless one or both of the state arrays are too small

save_state()[source]

This method stores current solver state in the self.state_data array.

Returns:
bool

Always True, unless the self.state_data array is too small

save_transformation_state(state_data)[source]

This method stores current transformation state for Triads, Parts and Beams in the provided core array.

The transformation state data is on the format:

[step number]
[current time]
[current time increment]
for each non-fixed Triad:
1
[rotMatrix column 1]
[rotMatrix column 2]
[rotMatrix column 3]
[translation vector]
for each Part and Beam:
2
[rotMatrix column 1]
[rotMatrix column 2]
[rotMatrix column 3]
[translation vector]
Parameters:
state_datalist of c_double

Array to fill with transformation data

Returns:
bool

Always True, unless the state_data array is too small

set_ext_func(func_id, 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_id (external function Id).

Parameters:
func_idint

Id 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

set_rhs_vector(r_vec)[source]

Utility replacing current content of the system right-hand-side vector.

solve_inverse(x_val, x_def, g_def, out_def=None)[source]

This method solves the inverse problem at current time/load step, assuming small deformations only (linear response). If an error condition that requires the simulation to terminate occurs, the self.ierr variable is assigned a non-zero value.

Parameters:
x_vallist of float

Specified displacement values at a set of degrees of freedom

x_deflist of int

Equation numbers for the specified displacement values

g_deflist of int

Equation numbers for the DOFs with unknown external forces

out_deflist of int, default=None

User Ids of the functions to evaluate the response for

Returns:
list of float, only if out_def is specified

Evaluated response variables

bool

Always True, unless the simulation has to stop due to some error, or the end of the simulation has been reached

solve_iteration()[source]

This method solves the current linearized equation system and updates all state variables. Then it assembles the linearized system of equations for next iteration, unless convergence has been reached. The self.ierr variable has the value zero on a successful computation. A non-zero value indicates some error that requires the simulation to terminate.

Returns:
bool

Always True, unless the simulation has to stop due to some error, or the current time/load step has converged.

solve_modes(n_modes, dof_order=False, use_lapack=0)[source]

This method solves the eigenvalue problem at current time step, and returns the computed eigenvalues and associated eigenvectors. If an error condition that requires the simulation to terminate occurs, the self.ierr variable is assigned a negative value.

Parameters:
n_modesint

Number of eigenmodes to calculate

dof_orderbool, default=False

If True, the eigenvectors are returned in DOF-order instead of equation order which is the default

use_lapackint, default=0

Flag usage of LAPACK eigensolvers (0=No, 1=DSYGVX, 2=DGGEVX)

Returns:
list of float

The computed eigenvalues

list of list of float

The computed eigenvectors

bool

Always True, unless the computation failed

solve_next(inp=None, inp_def=None, out_def=None, time_next=None)[source]

This method advances the solution one time/load step forward. The self.ierr variable has the value zero on a successful computation. A non-zero value indicates some error that requires the simulation to terminate.

Parameters:
inplist of float, default=None

Input function values

inp_deflist of int, default=None

External function Ids of the functions to assign values

out_deflist of int, default=None

User Ids of the functions to evaluate the response for

time_nextfloat, default=None

Time of next step, to override time step size defined in the model

Returns:
list of float, only if out_def is specified

Evaluated response variables

bool

Always True, unless current time/load step failed to converge, or the end time of the simulation has been reached

solve_window(n_step, inputs=None, f_out=None, xtimes=None)[source]

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.

A non-zero value on self.ierr on exit indicates that an error condition that will require the simulation to terminate has occurred.

Parameters:
n_stepint

Number of time/load steps to solve for from current state

inputslist of float, default=None

List of input sensor values for each time step. The length of this list must be equal to n_step times the number of input sensors.

f_outlist of int, default=None

List of user Ids identifying the output sensors in the model

xtimeslist of float, default=None

List of times associated with the inputs. The length of this list must be equal to n_step.

Returns:
list of float

Output sensor values for each time step

bool

Always True, unless the end of the simulation has been reached

solver_close()[source]

This method needs to be used if solver_done() was invoked with its remove_singletons argument set to False. It will delete those singleton objects here instead.

solver_done(remove_singletons=None)[source]

This method should be used when the time/load step loop is finished. It closes down the model and cleans up heap memory and things on disk.

Parameters:
remove_singletonsbool default=None

If True or None, heap-allocated singelton objects are also released

Returns:
int

Zero on success, non-zero values indicates errors.

solver_init(options, fsi=None, state_data=None, gauge_data=None, extf_input=None)[source]

This method processes the input and sets up necessary data structures prior to the time integration loop. It also performs the license checks.

See the Fedem R7.5 Users Guide, Appendix C.3 for a complete list of all command-line arguments that may be specified and their default values.

If the argument fsi is None, the model is assumed defined in the file specified via the command-line argument -fsifile instead.

Parameters:
optionslist of str

List of command-line arguments passed to the solver

fsistr, default=None

Content of the solver input file describing the model

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

Returns:
int

A negative value indicates an error, otherwise success. A positive value indicates that initial equilibrium iterations was performed with external function values from extf_input

start_step(time_next=None)[source]

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. It has to be followed up by a series of solve_iteration calls in order to continue the simulation, but the linear equation system can be manipulated in between. The self.ierr variable has the value zero on a successful computation. A non-zero value indicates some error that requires the simulation to terminate.

Parameters:
time_nextfloat, default=None

Time of next step, to override time step size defined in the model

Returns:
bool

Always True, unless the simulation has to stop due to some error, or the end time of the simulation has been reached