sfepy.discrete.equations module¶
Classes of equations composed of terms.

class
sfepy.discrete.equations.
Equation
(name, terms)[source]¶ 

collect_variables
(self)[source]¶ Collect variables present in the terms of the equation.
Ensures that corresponding primary variables of test/parameter variables are always in the list, even if they are not directly used in the terms.


class
sfepy.discrete.equations.
Equations
(equations)[source]¶ 
add_equation
(self, equation)[source]¶ Add a new equation.
 Parameters
 equationEquation instance
The new equation.

apply_ebc
(self, vec, force_values=None)[source]¶ Apply essential (Dirichlet) boundary conditions to a state vector.

create_matrix_graph
(self, any_dof_conn=False, rdcs=None, cdcs=None, shape=None, active_only=True, verbose=True)[source]¶ Create tangent matrix graph, i.e. preallocate and initialize the sparse storage needed for the tangent matrix. Order of DOF connectivities is not important.
 Parameters
 any_dof_connbool
By default, only volume DOF connectivities are used, with the exception of trace surface DOF connectivities. If True, any kind of DOF connectivities is allowed.
 rdcs, cdcsarrays, optional
Additional row and column DOF connectivities, corresponding to the variables used in the equations.
 shapetuple, optional
The required shape, if it is different from the shape determined by the equations variables. This may be needed if additional row and column DOF connectivities are passed in.
 active_onlybool
If True, the matrix graph has reduced size and is created with the reduced (active DOFs only) numbering.
 verbosebool
If False, reduce verbosity.
 Returns
 matrixcsr_matrix
The matrix graph in the form of a CSR matrix with preallocated structure and zero data.

create_subequations
(self, var_names, known_var_names=None)[source]¶ Create subequations containing only terms with the given virtual variables.
 Parameters
 var_nameslist
The list of names of virtual variables.
 known_var_nameslist
The list of names of (already) known state variables.
 Returns
 subequationsEquations instance
The subequations.

eval_residuals
(self, state, by_blocks=False, names=None)[source]¶ Evaluate (assemble) residual vectors.
 Parameters
 statearray
The vector of DOF values. Note that it is needed only in nonlinear terms.
 by_blocksbool
If True, return the individual blocks composing the whole residual vector. Each equation should then correspond to one required block and should be named as ‘block_name, test_variable_name, unknown_variable_name’.
 nameslist of str, optional
Optionally, select only blocks with the given names, if by_blocks is True.
 Returns
 outarray or dict of array
The assembled residual vector. If by_blocks is True, a dictionary is returned instead, with keys given by block_name part of the individual equation names.

eval_tangent_matrices
(self, state, tangent_matrix, by_blocks=False, names=None)[source]¶ Evaluate (assemble) tangent matrices.
 Parameters
 statearray
The vector of DOF values. Note that it is needed only in nonlinear terms.
 tangent_matrixcsr_matrix
The preallocated CSR matrix with zero data.
 by_blocksbool
If True, return the individual blocks composing the whole matrix. Each equation should then correspond to one required block and should be named as ‘block_name, test_variable_name, unknown_variable_name’.
 nameslist of str, optional
Optionally, select only blocks with the given names, if by_blocks is True.
 Returns
 outcsr_matrix or dict of csr_matrix
The assembled matrix. If by_blocks is True, a dictionary is returned instead, with keys given by block_name part of the individual equation names.

evaluate
(self, names=None, mode='eval', dw_mode='vector', term_mode=None, asm_obj=None)[source]¶ Evaluate the equations.
 Parameters
 modeone of ‘eval’, ‘el_avg’, ‘qp’, ‘weak’
The evaluation mode.
 namesstr or sequence of str, optional
Evaluate only equations of the given name(s).
 Returns
 outdict or result
The evaluation result. In ‘weak’ mode it is the asm_obj. Otherwise, it is a dict of results with equation names as keys or a single result for a single equation.

get_graph_conns
(self, any_dof_conn=False, rdcs=None, cdcs=None, active_only=True)[source]¶ Get DOF connectivities needed for creating tangent matrix graph.
 Parameters
 any_dof_connbool
By default, only volume DOF connectivities are used, with the exception of trace surface DOF connectivities. If True, any kind of DOF connectivities is allowed.
 rdcs, cdcsarrays, optional
Additional row and column DOF connectivities, corresponding to the variables used in the equations.
 active_onlybool
If True, the active DOF connectivities have reduced size and are created with the reduced (active DOFs only) numbering.
 Returns
 rdcs, cdcsarrays
The row and column DOF connectivities defining the matrix graph blocks.

get_state_parts
(self, vec=None)[source]¶ Return parts of a state vector corresponding to individual state variables.
 Parameters
 vecarray, optional
The state vector. If not given, then the data stored in the variables are returned instead.
 Returns
 outdict
The dictionary of the state parts.

get_variable_dependencies
(self)[source]¶ For each virtual variable get names of state/parameter variables that are present in terms with that virtual variable.
The virtual variables define the actual equations and their dependencies define the variables needed to evaluate the equations.
 Returns
 depsdict
The dependencies as a dictionary with virtual variable names as keys and sets of state/parameter variables as values.

make_full_vec
(self, svec, force_value=None)[source]¶ Make a full DOF vector satisfying E(P)BCs from a reduced DOF vector.

reset_materials
(self)[source]¶ Clear material data so that next materials.time_update() is performed even for stationary materials.

set_data
(self, data, step=0, ignore_unknown=False)[source]¶ Set data (vectors of DOF values) of variables.
 Parameters
 dataarray
The dictionary of {variable_name : data vector}.
 stepint, optional
The time history step, 0 (default) = current.
 ignore_unknownbool, optional
Ignore unknown variable names if data is a dict.

set_variables_from_state
(self, vec, step=0)[source]¶ Set data (vectors of DOF values) of variables.
 Parameters
 dataarray
The state vector.
 stepint
The time history step, 0 (default) = current.

strip_state_vector
(self, vec, follow_epbc=False)[source]¶ Strip a full vector by removing EBC dofs.
Notes
If ‘follow_epbc’ is True, values of EPBC master dofs are not simply thrown away, but added to the corresponding slave dofs, just like when assembling. For vectors with state (unknown) variables it should be set to False, for assembled vectors it should be set to True.

time_update
(self, ts, ebcs=None, epbcs=None, lcbcs=None, functions=None, problem=None, active_only=True, verbose=True)[source]¶ Update the equations for current time step.
The update involves creating the mapping of active DOFs from/to all DOFs for all state variables, the setup of linear combination boundary conditions operators and the setup of active DOF connectivities.
 Parameters
 tsTimeStepper instance
The time stepper.
 ebcsConditions instance, optional
The essential (Dirichlet) boundary conditions.
 epbcsConditions instance, optional
The periodic boundary conditions.
 lcbcsConditions instance, optional
The linear combination boundary conditions.
 functionsFunctions instance, optional
The user functions for boundary conditions, materials, etc.
 problemProblem instance, optional
The problem that can be passed to user functions as a context.
 active_onlybool
If True, the active DOF connectivities and matrix graph have reduced size and are created with the reduced (active DOFs only) numbering.
 verbosebool
If False, reduce verbosity.
 Returns
 graph_changedbool
The flag set to True if the current time step set of active boundary conditions differs from the set of the previous time step.

time_update_materials
(self, ts, mode='normal', problem=None, verbose=True)[source]¶ Update data materials for current time and possibly also state.
 Parameters
 tsTimeStepper instance
The time stepper.
 mode‘normal’, ‘update’ or ‘force’
The update mode, see
sfepy.discrete.materials.Material.time_update()
. problemProblem instance, optional
The problem that can be passed to user functions as a context.
 verbosebool
If False, reduce verbosity.
