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

apply_ebc(self, force_values=None)[source]

Apply essential (Dirichlet) boundary conditions to the state.

apply_ic(self, force_values=None)[source]

Apply initial 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)
fill(self, value)[source]

Fill the DOF vector with given value.

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_vec(self, active_only)[source]
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.

init_history(self)[source]

Initialize variables with history.

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 sub-vector 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.

set_reduced(self, r_vec, preserve_caches=False)[source]

Set the reduced DOF vector, with EBC and PBC DOFs removed.

Parameters
r_vecarray

The reduced DOF vector corresponding to the variables.

preserve_cachesbool

If True, do not invalidate evaluate caches of variables.

set_vec(self, vec, active_only)[source]