PyClaw State¶
The State
object records the fields that exist on a given
Patch
. These fields include q
and aux
. The
State
also includes references to the
Patch
that the state belongs to.
In parallel the State
object also handles some of the parallel communication required of the state on the
given patch such that only the parts of the fields local to the process. If you
are interested in the geometry of the local state you can find it through the
Patch
object’s reference to its own
Grid
.
Serial pyclaw.state.State
¶

class
pyclaw.state.
State
(geom, num_eqn, num_aux=0)¶ A PyClaw State object contains the current state on a particular patch, including the unkowns q, the time t, and the auxiliary coefficients aux.
The variables num_eqn and num_aux determine the length of the first dimension of the q and aux arrays.
 State Data
The arrays
q
, andaux
have variable extents based on the patch dimensions and the values ofnum_eqn
andnum_aux
.
A State object is automatically created upon instantiation of a Solution object from a Domain object:
>>> from clawpack import pyclaw >>> x = pyclaw.Dimension('x',0.0,1.0,100) >>> domain = pyclaw.Domain(x) >>> num_eqn = 1 >>> solution = pyclaw.Solution(num_eqn,domain) >>> print solution.state PyClaw State object Patch dimensions: [100] Time t=0.0 Number of conserved quantities: 1
A State lives on a Patch, and can be instantiated directly by first creating a Patch:
>>> x = pyclaw.Dimension('x',0.,1.,100) >>> patch = pyclaw.Patch((x))
The arguments to the constructor are the patch, the number of equations, and the number of auxiliary fields:
>>> state = pyclaw.State(patch,3,2) >>> state.q.shape (3, 100) >>> state.aux.shape (2, 100) >>> state.t 0.0
Note that state.q and state.aux are initialized as empty arrays (not zeroed). Additional parameters, such as scalar values that are used in the Riemann solver, can be set using the dictionary state.problem_data.

get_aux_global
()¶ Returns a copy of state.aux.

get_auxbc_from_aux
(num_ghost, auxbc)¶ Fills in the interior of auxbc by copying aux to it.

get_q_global
()¶ Returns a copy of state.q.

get_qbc_from_q
(num_ghost, qbc)¶ Fills in the interior of qbc by copying q to it.

is_valid
()¶ Checks to see if this state is valid
 The state is declared valid based on the following criteria:
q
is Fortran contiguousaux
is Fortran contiguous
A debug logger message will be sent documenting exactly what was not valid.
 Output
(bool)  True if valid, false otherwise.

set_aux_from_auxbc
(num_ghost, auxbc)¶ Set the value of aux using the array auxbc.

set_cparam
(fortran_module)¶ Set the variables in fortran_module.cparam to the corresponding values in patch.problem_data. This is the mechanism for passing scalar variables to the Fortran Riemann solvers; cparam must be defined as a common block in the Riemann solver.
This function should be called from solver.setup(). This seems like a fragile interdependency between solver and state; perhaps problem_data should belong to solver instead of state.
This function also checks that the set of variables defined in cparam all appear in problem_data.

set_num_ghost
(num_ghost)¶ Virtual routine (does nothing). Overridden in the petclaw.state class.

set_q_from_qbc
(num_ghost, qbc)¶ Set the value of q using the array qbc. Typically this is called after qbc has been updated by the solver.

F
= None¶ (ndarray(mF,…))  Cell averages of output functional densities.

gauge_data
= None¶ (list)  List of numpy.ndarray objects. Each element of the list stores the values of the corresponding gauge if
keep_gauges
is set toTrue

keep_gauges
= None¶ (bool)  Keep gauge values in memory for every time step,
default = False

property
mF
¶ (int)  Number of output functionals

property
mp
¶ (int)  Number of derived quantities

property
num_aux
¶ (int)  Number of auxiliary fields

property
num_eqn
¶ (int)  Number of unknowns (components of q)

p
= None¶ (ndarray(mp,…))  Cell averages of derived quantities.

problem_data
= None¶ (dict)  Dictionary of global values for this patch,
default = {}

t
= None¶ (float)  Current time represented on this patch,
default = 0.0
Parallel petclaw.state.State
¶

class
petclaw.state.
State
(geom, num_eqn, num_aux=0)¶  Parallel State class
Parent Class Documentation:
Module containing all Pyclaw solution objects

get_aux_global
()¶ Returns a copy of the global aux array on process 0, otherwise returns None

get_auxbc_from_aux
(num_ghost, auxbc)¶ Returns aux with ghost cells attached, by accessing the local vector.

get_q_global
()¶ Returns a copy of the global q array on process 0, otherwise returns None

get_qbc_from_q
(num_ghost, qbc)¶ Returns q with ghost cells attached, by accessing the local vector.

set_num_ghost
(num_ghost)¶ This is a hack to deal with the fact that petsc4py doesn’t allow us to change the stencil_width (num_ghost).
Instead, we initially create DAs with stencil_width=0. Then, in solver.setup(), we call this function to replace those DAs with new ones that have the right stencil width.
This could be made more efficient using some PETSc calls, but it only happens once so it seems not to be worth it.

property
F
¶ Array containing pointwise values (densities) of output functionals. This is just used as temporary workspace before summing.

property
aux
¶ We never communicate aux values; every processor should set its own ghost cell values for the aux array. The global aux vector is used only for outputting the aux values to file; everywhere else we use the local vector.

property
fset
¶ Array containing pointwise values (densities) of output functionals. This is just used as temporary workspace before summing.

gauge_data
= None¶ (list)  List of numpy.ndarray objects. Each element of the list stores the values of the corresponding gauge if
keep_gauges
is set toTrue

keep_gauges
= None¶ (bool)  Keep gauge values in memory for every time step,
default = False

property
mF
¶ (int)  Number of derived quantities (components of p)

property
mp
¶ (int)  Number of derived quantities (components of p)

property
num_aux
¶ (int)  Number of auxiliary fields

property
num_eqn
¶ (int)  Number of unknowns (components of q)

property
p
¶ Array containing values of derived quantities for output.

problem_data
= None¶ (dict)  Dictionary of global values for this patch,
default = {}

property
q
¶ Array of solution values.

t
= None¶ (float)  Current time represented on this patch,
default = 0.0