DUNE PDELab (2.8)
This recipe shows two implementation issues arising when operator splitting approach is used: Communicating the data between two systems of PDE to another, and calculating operator splitting errors.
Accessing data of another system from inside the LocalOperator
We need a reference to the data vector and its GridFunctionSpace (GFS). GFS tells us which parts of the vector to extract. We store shared pointers to the data vector (type Data) and GFS
The mutable token is necessary, because functions in the local oparator are const.
They are instantiated in the constructor:
We load data with respect to the local Entity. If we are accumulating Skeleton terms, we need to repeat the process to get data from both inside and outside Entity.
We got a vector with local data (from the other system). If the vector is a collection of data from multiple variables, it places values of the same variable together. The data to the first variable are at indices from 0 to lfs.size()-1, the second variable occupies lfs.size() to 2*lfs.size()-1, etc.
Accumulate splitting errors
This example calculates a correction calculated by one operator splitting iteration. Firstly, we need variables storing data (previous and current iteration results). To extract a single data type from a coupled system use GridFunctionSubSpace. The path to the data is defined through TreePath. Create two DiscreteGridFunction-s which are fed to an Adapter (analytic function can be used in Adapter too), and choose the Adapter -we chose DifferenceSquaredAdapter.
Then we use integrateGridFunction to get a vector with (local) results from Adapter,
and sum the corrections. If the program is parallel, communicate.
Note that communication passes a (const) reference and returns a value. Some collective communication is necessary. Otherwise we risk one rank continuing operator splitting iteration and other going to the next step producing a deadlock.
For a short summary of the communication, check Communication in parallel programs
Full example code: recipe-operator-splitting.cc