sfepy.discrete.state module¶
Module for handling state variables.

class
sfepy.discrete.state.
State
(variables, vec=None, preserve_caches=False)[source]¶ Class holding/manipulating the state variables and corresponding DOF vectors.
Manipulating the state class changes the underlying variables, and hence also the corresponding equations/terms (if any).
Notes
This class allows working with LCBC conditions in timedependent problems, as it keeps track of the reduced DOF vector that cannot be reconstructed from the full DOF vector by using the usual variables.strip_state_vector().

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

copy
(self, deep=False, preserve_caches=False)[source]¶ Copy the state. By default, the new state contains the same variables, and creates new DOF vectors. If deep is True, also the DOF vectors are copied.
 Parameters
 deepbool
If True, make a copy of the DOF vectors.
 preserve_cachesbool
If True, do not invalidate evaluate caches of variables.

create_output_dict
(self, fill_value=None, var_info=None, extend=True, linearization=None)[source]¶ Transforms state to an output dictionary, that can be passed as ‘out’ kwarg to Mesh.write().
Then the dictionary entries are formed by components of the state vector corresponding to unknown variables according to kind of linearization given by linearization.
Examples
>>> out = state.create_output_dict() >>> problem.save_state('file.vtk', out=out)

static
from_variables
(variables)[source]¶ Create a State instance for the given variables.
The DOF vector is created using the DOF data in variables.
 Parameters
 variablesVariables instance
The variables.

get_parts
(self)[source]¶ Return parts of the DOF vector corresponding to individual state variables.
 Returns
 outdict
The dictionary of the DOF vector parts.

get_reduced
(self, follow_epbc=False)[source]¶ Get the reduced DOF vector, with EBC and PBC DOFs removed.

get_weighted_norm
(self, vec, weights=None, return_weights=False)[source]¶ Return the weighted norm of DOF vector vec.
By default, each component of vec is weighted by the 1/norm of the corresponding state part, or 1 if the norm is zero. Alternatively, the weights can be provided explicitly using weights argument.
 Parameters
 vecarray
The DOF vector corresponding to the variables.
 weightsdict, optional
If given, the weights are used instead of the norms of the state parts. Keys of the dictionary must be equal to the names of variables comprising the DOF vector.
 return_weights: bool
If True, return also the used weights.
 Returns
 normfloat
The weighted norm.
 weightsdict, optional
If return_weights is True, the used weights.
Examples
>>> err = state0.get_weighted_norm(state()  state0())

has_ebc
(self)[source]¶ Test whether the essential (Dirichlet) boundary conditions have been applied to the DOF vector.

set_full
(self, vec, var_name=None, force=False)[source]¶ Set the full DOF vector (including EBC and PBC DOFs). If var_name is given, set only the DOF subvector corresponding to the given variable. If force is True, setting variables with LCBC DOFs is allowed.

set_parts
(self, parts, force=False)[source]¶ Set parts of the DOF vector corresponding to individual state variables.
 Parameters
 partsdict
The dictionary of the DOF vector parts.
