Skip to content

Commit f2106a0

Browse files
committed
Extend step 2 with Python tab
1 parent cc3f2e6 commit f2106a0

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

pages/docs/couple-your-code/couple-your-code-steering-methods.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,13 @@ What do they do?
2424
2525
So, let's extend the code of our fluid solver:
2626
27+
28+
<ul id="apiTabs" class="nav nav-tabs">
29+
<li class="active"><a href="#cpp" data-toggle="tab">C++</a></li>
30+
<li><a href="#python" data-toggle="tab">Python</a></li>
31+
</ul>
32+
<div class="tab-content">
33+
<div role="tabpanel" class="tab-pane active" id="cpp" markdown="1">
2734
```cpp
2835
#include "precice/SolverInterface.hpp"
2936
@@ -45,3 +52,29 @@ while (not simulationDone()){ // time loop
4552
precice.finalize(); // frees data structures and closes communication channels
4653
turnOffSolver();
4754
```
55+
</div>
56+
<div role="tabpanel" class="tab-pane" id="python" markdown="1">
57+
```python
58+
import precice
59+
60+
turn_on_solver() # e.g. setup and partition mesh
61+
62+
precice = precice.Interface(
63+
"FluidSolver", "precice-config.xml", rank, size
64+
)
65+
precice_dt = precice.initialize()
66+
67+
u = initialize_solution()
68+
69+
while t < t_end: # time loop
70+
dt = compute_adaptive_dt()
71+
dt = min(precice_dt, dt) # more about this in Step 5
72+
u = solve_time_step(dt, u) # returns new solution
73+
precice_dt = precice.advance(dt)
74+
t = t + dt
75+
76+
precice.finalize() # frees data structures and closes communication channels
77+
```
78+
</div>
79+
</div>
80+

0 commit comments

Comments
 (0)