|
Peano
|
If you want to solve systems of PDEs where some PDEs advance on different time scales, solve different problems, are active in different domains, and so forth, you have two options on the table: You can model the solvers as one big system or you can logically code the solvers as two totally separate things and couple them. If you have to run some postprocessing, you also have two options: Either make the postprocessing a "real" postprocessing by adding it as postprocessing step to your solvers of choice, or you add separate mesh sweeps which perform the postprocessing.
The former version is faster, as you read/write data only once and you do not impose additional mesh traversals. The latter version is the way to go if you need some boundary exchange prior such that halos, for example, are up-to-date. It might also be appropriate if you want to couple the hyperbolic solvers to other solvers, such as an elliptic term or a solid in a fluid-structure interaction scenario. When it comes to the coupling of two solvers, the first approach sketched is simple: If the two solvers feature \( N_1\) and \( N_2\) unknowns, you simply create one new solver with \( N_1+N_2\) unknowns and you provide flux functionsm, ncps, ...for all of the components. The big disadvantage of this approach is that all solvers have to advance in time at the same speed, that you might replicate code if you have already two existing solvers, and that you also might run a lot of unneeded calculations if only some PDE equations evolve actually in time. Technically, the implementation of this variant however is straightforward and we will not discuss it further here, i.e. our description from hereon assumes that you work with two solvers and/or separate mesh sweeps.
Using multiple solvers within ExaHyPE is, in principle, straightforward, too. You create two solver instances and you add them to your project. Both solvers then will be embedded into the mesh and run independently. They will hence interact through the adaptive mesh refinement - if one solver refines, the other one will follow - but otherwise be totally independent. While this approach allows us to have a clear separation-of-solvers, the coupling of the two systems is not that straightforward. And we have to couple them if we want to solver our initial setup phrased as system of PDEs.
This tutorial introduces the two flavours of coupling and then walks through the simplest one hands-on: two solvers which run next to each other and share their auxiliary variables, i.e. they reuse one set of data rather than holding a copy each. Afterwards, we postprocess the outputs of the two solvers and compare them. The remaining sections sketch the mechanisms to couple solvers whose solutions feed into each other over time. They are not part of the hands-on part of this tutorial.
How to couple the PDEs depends upon the fact if you want to directly project the solutions onto each other or if you make one PDE feed into the other one via the right-hand side (or in general some "auxiliary" parameters within its PDE other than the evolution unknowns). If you couple PDEs directly, you can use your PDE solvers as they stand.
If one PDE feeds into the other one, there are two cases:
We rerun the tsunami of A tsunami simulation with source code injection, SymPy, auxiliary variables, non-conservative fluxes, and external files, but we run it twice at the same time. Both simulations live in the same project, i.e. they run on the same mesh, but they are two independent solvers: they have their own unknowns, their own time stamps and their own time step sizes. The two simulations only differ in their initial conditions: the hump of water sits at \( x=0\) in the first simulation and at \( x=0.1\) in the second one. Both tsunamis travel over the same sea floor, i.e. the logo of Durham University.
The sea floor is constant in time. Rather than storing and initialising it twice, we model it as one set of auxiliary variables. The first solver which the set is attached to owns the set: it initialises it. The second solver attaches the same set and reuses the data.
We use the surface elevation \( \eta\) as unknown and the PDE terms from A tsunami simulation with source code injection, SymPy, auxiliary variables, non-conservative fluxes, and external files with the non-conservative product. Please consult that tutorial for their derivation.
The three terms read the sea floor from the pointer bathymetry, which ExaHyPE passes in right behind Q. The struct Bathymetry hosts the position of the variable b within the set. We attach the set below, i.e. we do not have to write the signature: ExaHyPE generates it.
Behind each Q, the signature of a term hosts a pointer to each attached set. Behind each deltaQ, it hosts a pointer to the jump of each set. The latter is the pointer deltaBathymetry in the non-conservative product. If we attached a second set, e.g. a mesh distortion, we would find another pointer behind the pointer to the bathymetry.
Next, we create the project and the set of auxiliary variables. We write a small function which creates a solver. It attaches the very same set object to each solver. That is the only thing we have to do to share the sea floor. The initial condition of the owner writes the sea floor. The initial condition of the second solver does not: as it only shares the set, ExaHyPE passes it a const pointer. The sea floor is written with the same C++ code as in A tsunami simulation with source code injection, SymPy, auxiliary variables, non-conservative fluxes, and external files, i.e. the depth is looked up in the external files:
The solver which owns the set has to be added to the project first, as the setup of the second solver has to run after the setup of the first one: the initial condition of the sharing solver may read the sea floor, so ExaHyPE makes it depend on the initial condition of the owner. ExaHyPE complains if you add the solvers in the opposite order.
We plot every 0.01 time units, as we want to compare the two simulations over time afterwards. The rest of the setup is the same as in tutorials_exahype2_11_tsunami:
The sea floor is held by one cell data object, which both solvers use. Each solver additionally has a temporary cell data object which holds the sea floor including a halo layer around the patch, as the Finite Volume scheme needs the sea floor of the neighbouring volumes to evaluate fluxes. These halos belong to one solver, so the two solvers do not overwrite each other's halos while they run next to each other:
The signatures of the PDE terms follow from the set. Both solvers get the pointer to the sea floor behind Q. The second solver is a plain user of the set, i.e. its initial condition receives the pointer as const pointer, whereas the owner receives a non-const pointer:
Stateless terms are called by compute kernels which do not know anything about auxiliary variables. ExaHyPE therefore generates a second overload without the pointers for every stateless term. It slices the pointers out of the data which the kernel works on and forwards the call. We have never written this adapter, and our terms never see it:
The two solvers write their own output files. The solver which owns the sea floor writes the sea floor into a file of its own, too. The solver which only shares it does not write anything for it: the data would be identical anyway.
The two pictures show the surface elevation at \( t=0\) . The hump of the second tsunami sits to the right of the hump of the first one:
Both waves feel the same sea floor, which they find in the very same cell data. They run fast above the deep, purple parts of the logo and slowly above the shallow parts, as we have seen in A tsunami simulation with source code injection, SymPy, auxiliary variables, non-conservative fluxes, and external files.
Does the shifted hump make a difference? We compare when the waves reach a point of the domain. We call the arrival time of a wave in a point the first time at which the surface elevation \( \eta\) is at least 0.002.
We read the outputs of the two solvers. The two solvers advance with their own, adaptive time step sizes. The time stamps of their snapshots hence do not match exactly. The postprocessing therefore keeps the time stamps of each solver, and it interpolates the arrival time linearly between the two snapshots which enclose the moment at which the threshold is exceeded. First, we assemble the volumes of all patches of one snapshot into one array over the whole domain:
Now we determine for each volume the first snapshot at which the threshold is exceeded, and interpolate between this snapshot and the one before:
We pick four points, one on each side of the centre, and compare the arrival times there. As the hump of the second tsunami starts 0.1 further to the right, its wave should arrive earlier on the right and later on the left. As the wave runs with \( \sqrt{gh}\) , i.e. with a speed between 3.13 above the shallow and 6.26 above the deep parts of the logo, we expect shifts between \( 0.1/6.26 \approx 0.016\) and \( 0.1/3.13 \approx 0.032\) time units on the horizontal axis:
Right of the centre, the second wave arrives earlier by 0.017 time units, left of the centre it arrives 0.028 time units later. Both values lie in the range which we have estimated. On the vertical axis, the shift of the hump has a much smaller impact, as the second hump is only slightly closer to the upper than to the lower point. The first tsunami is symmetric, i.e. it arrives at the same time at the two points on the horizontal axis. This confirms that the second solver sees exactly the same sea floor as the first one.
The difference of the arrival times over the whole domain shows the same picture. It is negative where the second wave is faster, and positive where it is slower:
The pictures are created by tutorials/exahype2/illustrations/45_coupling.py.
There are two places where we can add coupling, i.e. map solution data onto each other: It can either be a preprocessing step of the time step or a postprocessing step. While, in principle, both approaches do work here, there's a delicate difference: In the pre-processing step, we have access to the patch data plus the halo. In the post-processing step, we have only access to the patch content.
We note that we exclusively discuss volumetric mapping in this section. This is the only coupling we support at the moment within ExaHyPE, i.e. we do not support mapping of face data onto each other (anymore). Besides volumetric coupling, you can obviously "only" couple global properties with each other. This is however similar to the time step synchronisation as discussed below and therefore not subject of further discussion.
Unless you use fixed time stepping schemes with hard-coded time step sizes that match, any two solvers with ExaHyPE run at their own speed. Even more, each individual cell runs at its own speed and hosts its own time stamp. For local timestepping, different cells may advance at different speed in time. For adaptive timestepping, all cells of one solver will advance with the same time step size.
For most solvers, it is therefore sufficient to plug into getAdmissibleTimeStepSize() of the superclass. Overwrite it, call the superclass' variant and then alter the returned value.
This is the approach used in Euler example with self-gravitation via the Poisson equation. If you want to use local time stepping or run checks on the timestamp per cell, you will have to alter the cell's meta data holding its time stamp. Things in this case become more involved, i.e. you will have to study the underlying action sets and change the generated source code in there.
For the actual solver coupling, four hook-in points are available:
These steps all have differen properties. The global preprocessing precedes any solver routine, i.e. it is called before any compute kernel on any solver is launched. It also is guaranteed to run sequentially, i.e. there is nothing running in parallel to the preprocess actino set. For the postprocessing, similar arguments hold. These steps come after all solvers have updated their solution. The kernel hook-ins (2) and (3) in contrast can run in parallel.
Any coupling can be arbitrary complicated, but there are several off-the-shelf routines offered in toolbox::blockstructured. Interesting variants include toolbox::blockstructured::copyUnknown() and toolbox::blockstructured::computeGradientAndReturnMaxDifference(). Besides those guys, you might also want to use the AMR routines within the blockstructured toolbox and the ExaHyPE folders, where you find, for example, linear interpolation and restriction.
Important: If you couple two solvers, you have to carefully take into account