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 time-dependent 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().
- copy(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(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()[source]¶
Return parts of the DOF vector corresponding to individual state variables.
- Returns
- outdict
The dictionary of the DOF vector parts.
- get_weighted_norm(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()[source]¶
Test whether the essential (Dirichlet) boundary conditions have been applied to the DOF vector.
- set_full(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 sub-vector corresponding to the given variable. If force is True, setting variables with LCBC DOFs is allowed.
- set_parts(parts, force=False)[source]¶
Set parts of the DOF vector corresponding to individual state variables.
- Parameters
- partsdict
The dictionary of the DOF vector parts.