Closed JHopeCollins closed 11 months ago
This is waiting on #136 because the uses of get_field
in the vertical slice scripts need removing, but that PR changes the vertical slice scripts substantially. Once that PR is merged into master I'll merge it in here to update those scripts.
Yes, I prefer it this way!
We will need to warn Hiroe that this has changed a bit.
Great, thanks! I've just posted in the asQ slack about it.
This PR improves how we access the solution at individual timesteps of an
AllAtOnceFunction
.Currently these are accessed via the
get_field
andset_field
methods (and the analogousget_component
andset_component
methods for accessing one component of a timestep when using mixed function spaces). These are a bit clunky and not really a very pythonic style.Instead, we can create a set of
Function
s to view the solution at each timestep. This is analogous to howFunction.subfunctions
works for accessing individual components of a mixedFunction
. Eachsubfunction
is aFunction
in its own right that is a view over the data in the full mixedFunction
.For the
AllAtOnceFunction
, we follow a very similar pattern. We create a tuple ofFunctions
, (AllAtOnceFunction._fields
) each of which views the data for a particular timestep in theMixedFunctionSpace
that represents the local slice of the timeseries. When theFunctionSpace
for a single timestep is mixed, theFunctions
inAllAtOnceFunction._fields
are also mixed.The
Function
s that view each timestep are accessed by indexing theAllAtOnceFunction
. For example, previously we would have written:Now we can just write:
which is much closer to standard Firdrake syntax. To access a particular component (assuming
aaofunc.field_function_space
is mixed):(I'm not completely attached to accessing these
Functions
by directly indexing theAllAtOnceFunction
. We could also name them directly like forfiredrake.Function.subfunctions
. e.g. we could haveAllAtOnceFunction.fields
and access them viaaaofunc.fields[i]
. Happy to discuss.)Another change in this PR is that
AllAtOnceFunction.transform_index
will no longer give you the index for a particular component in the mixed space for the local slice of the timeseries. Getting this index is kind of an implementation detail (specific to the fact that we've implemented each slice as a mixed space) so shouldn't be necessary to use from user-land. There is now the "internal" methodAllAtOnceFunction._component_indices
for when we need to access these indices inside asQ.The changes to the examples and case_studies scripts show how these changes are used. I think it makes things simpler/nicer to read but please let me know what you think!