"""
Module for handling state variables.
"""
import numpy as nm

from sfepy.base.base import Struct

class State(Struct):
    """
    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()`.
    """

    @staticmethod
    def from_variables(variables):
        """
        Create a State instance for the given variables.

        The DOF vector is created using the DOF data in `variables`.

        Parameters
        ----------
        variables : Variables instance
            The variables.
        """
        parts = variables.get_state_parts()
        vec = variables.create_state_vector()

        for key, part in parts.iteritems():
            indx = variables.get_indx(key)
            vec[indx] = part

        return State(variables, vec)

    def __init__(self, variables, vec=None, preserve_caches=False):
        """
        Create a State instance for the given variables.

        Parameters
        ----------
        variables : Variables instance
            The variables.
        vec : array, optional
            The (initial) DOF vector corresponding to the variables.
        preserve_caches : bool
            If True, do not invalidate evaluate caches of variables.
        """
        
Struct.__init__(self, variables=variables, vec=vec, r_vec=None)