sfepy.discrete.equations module

Classes of equations composed of terms.

class sfepy.discrete.equations.Equation(name, terms)[source]
collect_conn_info(conn_info)[source]
collect_materials()[source]

Collect materials present in the terms of the equation.

collect_variables()[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.

evaluate(mode=’eval’, dw_mode=’vector’, term_mode=None, asm_obj=None)[source]
Parameters:
mode : one of ‘eval’, ‘el_eval’, ‘el_avg’, ‘qp’, ‘weak’

The evaluation mode.

static from_desc(name, desc, variables, regions, materials, integrals, user=None)[source]
class sfepy.discrete.equations.Equations(equations)[source]
add_equation(equation)[source]

Add a new equation.

Parameters:
equation : Equation instance

The new equation.

advance(ts)[source]
apply_ebc(vec, force_values=None)[source]

Apply essential (Dirichlet) boundary conditions to a state vector.

apply_ic(vec, force_values=None)[source]

Apply initial conditions to a state vector.

collect_conn_info()[source]

Collect connectivity information as defined by the equations.

collect_materials()[source]

Collect materials present in the terms of all equations.

collect_variables()[source]

Collect variables present in the terms of all equations.

create_matrix_graph(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_conn : bool

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, cdcs : arrays, optional

Additional row and column DOF connectivities, corresponding to the variables used in the equations.

shape : tuple, 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_only : bool

If True, the matrix graph has reduced size and is created with the reduced (active DOFs only) numbering.

verbose : bool

If False, reduce verbosity.

Returns:
matrix : csr_matrix

The matrix graph in the form of a CSR matrix with preallocated structure and zero data.

create_state_vector()[source]
create_stripped_state_vector()[source]
create_subequations(var_names, known_var_names=None)[source]

Create sub-equations containing only terms with the given virtual variables.

Parameters:
var_names : list

The list of names of virtual variables.

known_var_names : list

The list of names of (already) known state variables.

Returns:
subequations : Equations instance

The sub-equations.

eval_residuals(state, by_blocks=False, names=None)[source]

Evaluate (assemble) residual vectors.

Parameters:
state : array

The vector of DOF values. Note that it is needed only in nonlinear terms.

by_blocks : bool

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’.

names : list of str, optional

Optionally, select only blocks with the given names, if by_blocks is True.

Returns:
out : array 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(state, tangent_matrix, by_blocks=False, names=None)[source]

Evaluate (assemble) tangent matrices.

Parameters:
state : array

The vector of DOF values. Note that it is needed only in nonlinear terms.

tangent_matrix : csr_matrix

The preallocated CSR matrix with zero data.

by_blocks : bool

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’.

names : list of str, optional

Optionally, select only blocks with the given names, if by_blocks is True.

Returns:
out : csr_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(names=None, mode=’eval’, dw_mode=’vector’, term_mode=None, asm_obj=None)[source]

Evaluate the equations.

Parameters:
mode : one of ‘eval’, ‘el_avg’, ‘qp’, ‘weak’

The evaluation mode.

names : str or sequence of str, optional

Evaluate only equations of the given name(s).

Returns:
out : dict 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.

static from_conf(conf, variables, regions, materials, integrals, user=None, verbose=True)[source]
get_domain()[source]
get_graph_conns(any_dof_conn=False, rdcs=None, cdcs=None, active_only=True)[source]

Get DOF connectivities needed for creating tangent matrix graph.

Parameters:
any_dof_conn : bool

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, cdcs : arrays, optional

Additional row and column DOF connectivities, corresponding to the variables used in the equations.

active_only : bool

If True, the active DOF connectivities have reduced size and are created with the reduced (active DOFs only) numbering.

Returns:
rdcs, cdcs : arrays

The row and column DOF connectivities defining the matrix graph blocks.

get_lcbc_operator()[source]
get_state_parts(vec=None)[source]

Return parts of a state vector corresponding to individual state variables.

Parameters:
vec : array, optional

The state vector. If not given, then the data stored in the variables are returned instead.

Returns:
out : dict

The dictionary of the state parts.

get_variable(name)[source]
get_variable_dependencies()[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:
deps : dict

The dependencies as a dictionary with virtual variable names as keys and sets of state/parameter variables as values.

get_variable_names()[source]

Return the list of names of all variables used in equations.

init_time(ts)[source]
invalidate_term_caches()[source]

Invalidate evaluate caches of variables present in equations.

make_full_vec(svec, force_value=None)[source]

Make a full DOF vector satisfying E(P)BCs from a reduced DOF vector.

print_terms()[source]

Print names of equations and their terms.

reset_materials()[source]

Clear material data so that next materials.time_update() is performed even for stationary materials.

set_data(data, step=0, ignore_unknown=False)[source]

Set data (vectors of DOF values) of variables.

Parameters:
data : array

The dictionary of {variable_name : data vector}.

step : int, optional

The time history step, 0 (default) = current.

ignore_unknown : bool, optional

Ignore unknown variable names if data is a dict.

set_variables_from_state(vec, step=0)[source]

Set data (vectors of DOF values) of variables.

Parameters:
data : array

The state vector.

step : int

The time history step, 0 (default) = current.

setup_initial_conditions(ics, functions=None)[source]
state_to_output(vec, fill_value=None, var_info=None, extend=True)[source]
strip_state_vector(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(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:
ts : TimeStepper instance

The time stepper.

ebcs : Conditions instance, optional

The essential (Dirichlet) boundary conditions.

epbcs : Conditions instance, optional

The periodic boundary conditions.

lcbcs : Conditions instance, optional

The linear combination boundary conditions.

functions : Functions instance, optional

The user functions for boundary conditions, materials, etc.

problem : Problem instance, optional

The problem that can be passed to user functions as a context.

active_only : bool

If True, the active DOF connectivities and matrix graph have reduced size and are created with the reduced (active DOFs only) numbering.

verbose : bool

If False, reduce verbosity.

Returns:
graph_changed : bool

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(ts, mode=’normal’, problem=None, verbose=True)[source]

Update data materials for current time and possibly also state.

Parameters:
ts : TimeStepper instance

The time stepper.

mode : ‘normal’, ‘update’ or ‘force’

The update mode, see sfepy.discrete.materials.Material.time_update().

problem : Problem instance, optional

The problem that can be passed to user functions as a context.

verbose : bool

If False, reduce verbosity.

sfepy.discrete.equations.get_expression_arg_names(expression, strip_dots=True)[source]

Parse expression and return set of all argument names. For arguments with attribute-like syntax (e.g. materials), if strip_dots is True, only base argument names are returned.

sfepy.discrete.equations.parse_definition(equation_def)[source]

Parse equation definition string to create term description list.