You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: pages/docs/couple-your-code/couple-your-code-mesh-and-data-access.md
+129Lines changed: 129 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -9,6 +9,13 @@ For coupling, we need coupling meshes. Let's see how we can tell preCICE about o
9
9
10
10
Coupling meshes and associated data fields are defined in the preCICE configuration file, which you probably already know from the tutorials. The concrete values, however, you can access with the API:
Did you see that your fluid solver now also needs to provide the functions `computeForces` and `setDisplacements`? As you are an expert in your fluid code, these functions should be easy to implement. Most probably, you already have such functionality anyway. If you are not an expert in your code try to find an expert :smirk:.
The coordinates of the vertices in a numpy array [N x D] where
124
+
N = number of vertices and D = dimensions of geometry.
125
+
126
+
Returns
127
+
-------
128
+
vertex_ids : numpy.ndarray
129
+
IDs of the created vertices.
130
+
"""
131
+
set_mesh_vertices(mesh_name, positions)
132
+
```
133
+
134
+
*`set_mesh_vertex` defines the coordinates of a single mesh vertex and returns a vertex ID, which you can use to refer to this vertex.
135
+
*`set_mesh_vertices` defines multiple vertices at once. So, you can use this function instead of calling `set_mesh_vertex` multiple times. This is also good practice for performance reasons.
136
+
137
+
To write data to the coupling data structure the following API function is needed:
The relative read time can be anything from the current point in time (`0`) to the end of the time window (`get_max_time_step_size()`). We will talk about the additional argument `relative_read_time` in detail in [the section on time interpolation](couple-your-code-waveform.html).
179
+
180
+
Let's define coupling meshes and access coupling data in our example code:
end_time_step() # e.g. update variables, increment time
211
+
212
+
precice.finalize() # frees data structures and closes communication channels
213
+
turn_off_solver()
214
+
```
215
+
216
+
Did you see that your fluid solver now also needs to provide the functions `compute_forces` and `set_displacements`? As you are an expert in your fluid code, these functions should be easy to implement. Most probably, you already have such functionality anyway. If you are not an expert in your code try to find an expert :smirk:.
217
+
218
+
</div>
219
+
</div>
91
220
92
221
Once your adapter reaches this point, it is a good idea to test your adapter against one of the [solverdummies](couple-your-code-api#minimal-reference-implementation), which then plays the role of the `SolidSolver`.
end_time_step() #e.g. update variables, increment time
41
+
42
+
turn_off_solver()
21
43
```
22
44
45
+
</div>
46
+
</div>
23
47
Probably most solvers have such a structures: something in the beginning (reading input, domain decomposition), a big time loop, and something in the end. Each time step also falls into three parts: some pre-computations (e.g. computing an adaptive time step size), the actual computation (solving a linear or non-linear equation system), and something in the end (updating variables, incrementing time). Try to identify these parts in the code you want to couple.
24
48
25
49
In the following steps, we will slowly add more and more calls to the preCICE API in this code snippet. Some part of the preCICE API is briefly described in each step. More precisely (no pun intended :grin:), we use the native `C++` API of preCICE. The API is, however, also available in other scientific programming languages: plain `C`, `Fortran`, `Python`, `Matlab`, `Julia`, and `Rust` (see [Application Programming Interface](couple-your-code-api)).
Copy file name to clipboardExpand all lines: pages/docs/couple-your-code/couple-your-code-steering-methods.md
+47-7Lines changed: 47 additions & 7 deletions
Original file line number
Diff line number
Diff line change
@@ -9,28 +9,65 @@ summary: "In this step, you get to know the most important API functions of preC
9
9
As a first preparation step, you need to include the preCICE library headers. In C++, you need to include the file [precice.hpp](https://github.com/precice/precice/blob/develop/src/precice/precice.hpp).
10
10
The handle to the preCICE API is the class `precice::Participant`. Its constructor requires the participant's name, the preCICE configuration file's name and the `rank` and `size` of the current thread. Once the basic preCICE interface is set up, we can _steer_ the behaviour of preCICE. For that we need the following functions:
*`initialize` establishes communication channels and sets up data structures of preCICE.
22
61
*`advance` needs to be called after the computation of every time step to _advance_ the coupling. As an argument, you have to pass the solver's last time step size (`dt`). Additionally, it maps coupling data between the coupling meshes, it communicates coupling data between the coupled participants, and it accelerates coupling data. One could say the complete coupling happens within this single function.
23
62
*`finalize` frees the preCICE data structures and closes communication channels.
24
63
25
64
The following function allows us to query the maximum allowed time step size from preCICE:
0 commit comments