Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update documentation for initialize #186

Merged
merged 20 commits into from
Jun 1, 2023
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
417764e
Documentation for data initialization changes introduced in v3.0.0.
BenjaminRodenberg Jul 16, 2022
a58f804
Add note.
BenjaminRodenberg Jul 16, 2022
63d29bf
Cleanup initializeData.
BenjaminRodenberg Jul 16, 2022
21c3803
Use version block.
BenjaminRodenberg Jul 16, 2022
de3405a
Merge branch 'master' into initialize-data-v3.0.0
BenjaminRodenberg Jul 16, 2022
e8db81c
Add language spec.
BenjaminRodenberg Jul 16, 2022
d6df15a
Update pages/docs/couple-your-code/couple-your-code-initializing-coup…
BenjaminRodenberg Jul 18, 2022
cb7f5f0
Merge branch 'master' into initialize-data-v3.0.0
BenjaminRodenberg Jan 20, 2023
e72d1d8
Update action config docs to v3
uekerman Apr 14, 2023
55a1d0d
Update w.r.t actions.
BenjaminRodenberg Apr 21, 2023
eb785d2
Merge branch 'precice-v3' into initialize-data-v3.0.0
BenjaminRodenberg Apr 21, 2023
5b28c1d
Merge branch 'update-actions-docs-v3' into initialize-data-v3.0.0
BenjaminRodenberg Apr 21, 2023
cd21bcc
Fix occurences of initializeData.
BenjaminRodenberg Apr 21, 2023
cdd2062
Merge branch 'precice-v3' into initialize-data-v3.0.0
BenjaminRodenberg Apr 21, 2023
168b4b2
Update couple-your-code-initializing-coupling-data.md
BenjaminRodenberg Apr 22, 2023
e053fdc
Merge branch 'precice-v3' into initialize-data-v3.0.0
BenjaminRodenberg Apr 24, 2023
3e8a5b5
Merge remote-tracking branch 'origin/precice-v3' into initialize-data…
BenjaminRodenberg Apr 24, 2023
07376d8
Merge branch 'precice-v3' into initialize-data-v3.0.0
BenjaminRodenberg May 28, 2023
ec217b5
Simplify initialization and add note in waveform.
BenjaminRodenberg May 28, 2023
c27eda8
Revert unwanted changes.
BenjaminRodenberg Jun 1, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions pages/docs/configuration/configuration-action.md
BenjaminRodenberg marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ There are two types of coupling actions: pre-implemented ones and user-defined o
## Basics and pre-implemented actions

```xml
<participant name="MySolver1">
<use-mesh name="MyMesh1" provide="yes"/>
<write-data name="Stresses" mesh="MyMesh1"/>
<participant name="MySolver1">
<use-mesh name="MyMesh1" provide="yes"/>
<write-data name="Stresses" mesh="MyMesh1"/>
...
<action:multiply-by-area mesh="MyMesh1" timing="write-mapping-post">
<target-data name="Stresses"/>
Expand All @@ -31,10 +31,10 @@ This example multiplies the stresses values by the respective element area, tran

<details markdown="1"><summary>Older (preCICE version < 2.1.0) timings that are deprecated and revert to one of the above options: (click for details)</summary>

* `regular-prior`: In every `advance` call (also for subcycling) and in `initializeData`, after `write` data is mapped, but _before_ data might be sent. (_v2.1 or later: reverts to `write-mapping-prior`_)
* `regular-post`: In every `advance` call (also for subcycling), in `initializeData` and in `initialize`, before `read` data is mapped, but _after_ data might be received and after acceleration. (_v2.1 or later: reverts to `read-mapping-prior`_)
* `on-exchange-prior`: Only in those `advance` calls which lead to data exchange (and in `initializeData`), after `write` data is mapped, but _before_ data might be sent. (_v2.1 or later: reverts to `write-mapping-post`_)
* `on-exchange-post`: Only in those `advance` calls which lead to data exchange (and in `initializeData` and `ìnitialize`), before `read` data is mapped, but _after_ data might be received. (_v2.1 or later: reverts to `read-mapping-prior`_)
* `regular-prior`: In every `advance` call (also for subcycling) and in `initialize`, after `write` data is mapped, but _before_ data might be sent. (_v2.1 or later: reverts to `write-mapping-prior`_)
* `regular-post`: In every `advance` call (also for subcycling) and in `initialize`, before `read` data is mapped, but _after_ data might be received and after acceleration. (_v2.1 or later: reverts to `read-mapping-prior`_)
* `on-exchange-prior`: Only in those `advance` calls which lead to data exchange (and in `initialize`), after `write` data is mapped, but _before_ data might be sent. (_v2.1 or later: reverts to `write-mapping-post`_)
* `on-exchange-post`: Only in those `advance` calls which lead to data exchange (and in `initialize`), before `read` data is mapped, but _after_ data might be received. (_v2.1 or later: reverts to `read-mapping-prior`_)

</details><br />

Expand Down Expand Up @@ -79,8 +79,8 @@ We show an example for the [1D elastic tube](tutorials-elastic-tube-1d.html):
The callback interface consists of the following three (optional) functions:

```python
performAction(time, sourceData, targetData)
vertexCallback(id, coords, normal)
performAction(time, sourceData, targetData)
vertexCallback(id, coords, normal)
postAction()
```

Expand Down Expand Up @@ -133,7 +133,7 @@ def vertexCallback(id, coords, normal):
global mySourceData # Make global data set in performAction visible
global myTargetData
# Example usage, add data to vertex coords:
# myTargetData[id] += coords[0] + mySourceData[id]
# myTargetData[id] += coords[0] + mySourceData[id]

def postAction():
# This function is called at last, if not omitted.
Expand Down
6 changes: 3 additions & 3 deletions pages/docs/couple-your-code/couple-your-code-coupling-flow.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ In our example, we currently use a serial coupling scheme:
```xml
<coupling-scheme:serial-explicit>
<participants first="FluidSolver" second="SolidSolver"/>
...
...
</coupling-scheme:serial-explicit>
```

`FluidSolver` is first and `SolidSolver` second. This means that `FluidSolver` starts the simulation and computes the first timestep, while `SolidSolver` still waits. Where does it wait? Well, communciation in preCICE only happens within `initialize` and `advance` (and `initializeData`, but more about this in [Step 7](couple-your-code-initializing-coupling-data.html)):
`FluidSolver` is first and `SolidSolver` second. This means that `FluidSolver` starts the simulation and computes the first timestep, while `SolidSolver` still waits. Where does it wait? Well, communciation in preCICE only happens within `initialize` and `advance`:

* `FluidSolver` computes the first timestep and then sends and receives data in `advance`. The receive call blocks.
* `SolidSolver` waits in `initialize` for the first data. When it receives the data it computes its first timestep and then calls `advance`.
Expand All @@ -31,7 +31,7 @@ In our example, we currently use a serial coupling scheme:
***

<img class="img-responsive" src="images/docs/couple-your-code-serial-coupling.svg" alt="Serial coupling flow" style="width:100%">

***

Try to swap the roles of `first` and `second` in your example. Do you see the difference? If everything is just too fast, add some `sleep` calls.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,17 @@ keywords: api, adapter, initialization, coupling scheme, restart
summary: "As default values, preCICE assumes that all coupling variables are zero initially. For fluid-structure interaction, for example, this means that the structure is in its reference state. Sometimes, you want to change this behavior – for instance, you may want to restart your simulation."
---

For initializing coupling data, you can add the following **optional** method:
{% version 3.0.0 %}
`initializeData()` will be removed in preCICE version 3.0.0. You can do data initialization now by calling `initialize()`.
BenjaminRodenberg marked this conversation as resolved.
Show resolved Hide resolved
{% endversion %}

By default preCICE assumes that all coupling variables are zero initially. If you want to provide non-zero initial values, you can write data before calling `initialize()`. This data will then be used as initial data. The preCICE action interface that was introduced in [Step 6](couple-your-code-implicit-coupling) provides the following action to check whether initial data has to be written by a participant:

```cpp
void initializeData();
const std::string& constants::actionWriteInitialData()
BenjaminRodenberg marked this conversation as resolved.
Show resolved Hide resolved
```

Before jumping into the implementation, let's try to clarify how the usual the sequence of events in a serial and in a parallel coupling as studied in [Step 4](couple-your-code-coupling-flow) changes.

TODO: picture

In a serial coupling, only the second participant can send data inside `initializeData()`. In parallel coupling, both participants can initialize data.

The high-level API of preCICE makes it possible to enable this feature at runtime, irrelevant of serial or parallel coupling configuration. To support this feature, we extend our example as follows:
To support data initialization, we extend our example as follows:

```cpp
[...]
Expand All @@ -26,21 +24,19 @@ const std::string& cowid = precice::constants::actionWriteInitialData();

[...]

int displID = precice.getDataID("Displacements", meshID);
int forceID = precice.getDataID("Forces", meshID);
int displID = precice.getDataID("Displacements", meshID);
int forceID = precice.getDataID("Forces", meshID);
double* forces = new double[vertexSize*dim];
double* displacements = new double[vertexSize*dim];

[...]

precice_dt = precice.initialize();

if(precice.isActionRequired(cowid)){
precice.writeBlockVectorData(forceID, vertexSize, vertexIDs, forces);
precice.markActionFulfilled(cowid);
}

precice.initializeData();
precice_dt = precice.initialize();

while (precice.isCouplingOngoing()){
[...]
Expand All @@ -54,3 +50,9 @@ Now, you can specify at runtime if you want to initialize coupling data. For exa
<exchange data="Displacements" mesh="StructureMesh" from="SolidSolver" to="FluidSolver" initialize="yes"/>
[...]
```

If you are using a serial coupling scheme, only initial data that is written from the second to the first participant is actually used. Initial data written from the first to the second participant will be ignored, because in a serial coupling scheme the first participant already computes its first result before the second participant even starts.

{% note %}
preCICE still supports data initialization for both participants, even if a serial coupling scheme is used. You can read our section on [time interpolation](couple-your-code-waveform) to learn more about the reasons.
{% endnote %}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had to read this part three times before understanding it. Could we improve it?
Instead of "written from A to B", I would always say "written to A and then communicated by preCICE from A to B".
Either all in a note or non. Remember that waveform will be the norm with v3 eventually.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No so sure about this whole paragraph anymore, because it makes things more complicated and actually we are now planning to use initial data for every participant for every coupling scheme. Also the second participant in a serial coupling scheme uses the initial data it receives from the first. Even for waveform order = 0 we use the initial data for the relative time = 0. This is a very narrow edge case, but it leads to a consistent treatment across windows. See also the following figure:

Screenshot from 2023-05-28 14-11-10

How about removing this paragraph and opening the whole topic later when we introduce time interpolation?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could also use the figure from above later in the waveform relaxation section, if it is useful. For the section on data initialization, I think it contains too much information that has not been introduced yet.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See ec217b5 for some steps into this direction.