Beispiel #1
0
    def get_var(self, name):
        """
        Return a data array for the variable described by name.  Stored
        variables will be checked first, and then any derived variables
        will be checked.

        For a stored variable, changes made to this are automatically
        reflected in the CellCenterData1d object.

        Parameters
        ----------
        name : str
            The name of the variable to access

        Returns
        -------
        out : ndarray
            The array of data corresponding to the variable name

        """
        try:
            n = self.names.index(name)
        except ValueError:
            for f in self.derives:
                var = f(self, name)
                if len(var) > 0:
                    return var
            raise KeyError("name {} is not valid".format(name))
        else:
            return ai.ArrayIndexer1d(d=self.data[:, n], grid=self.grid)
Beispiel #2
0
 def scratch_array(self, nvar=1):
     """
     return a standard numpy array dimensioned to have the size
     and number of ghostcells as the parent grid
     """
     if nvar == 1:
         _tmp = np.zeros((self.qx, ), dtype=np.float64)
     else:
         _tmp = np.zeros((self.qx, nvar), dtype=np.float64)
     return ai.ArrayIndexer1d(d=_tmp, grid=self)
Beispiel #3
0
    def get_vars(self):
        """
        Return the entire data array.  Any changes made to this
        are automatically reflected in the CellCenterData1d object.

        Returns
        -------
        out : ndarray
            The array of data

        """
        return ai.ArrayIndexer1d(d=self.data, grid=self.grid)
Beispiel #4
0
    def create(self):
        """
        Called after all the variables are registered and allocates
        the storage for the state data.
        """

        if self.initialized == 1:
            msg.fail("ERROR: grid already initialized")

        _tmp = np.zeros((self.grid.qx, self.nvar), dtype=self.dtype)
        self.data = ai.ArrayIndexer1d(_tmp, grid=self.grid)

        self.initialized = 1
Beispiel #5
0
    def get_var_by_index(self, n):
        """
        Return a data array for the variable with index n in the
        data array.  Any changes made to this are automatically
        reflected in the CellCenterData1d object.

        Parameters
        ----------
        n : int
            The index of the variable to access

        Returns
        -------
        out : ndarray
            The array of data corresponding to the index

        """
        return ai.ArrayIndexer1d(d=self.data[:, n], grid=self.grid)