Skip to content

Commit 13e1124

Browse files
committed
Add comments on Nutils
1 parent 541bf32 commit 13e1124

File tree

4 files changed

+50
-7
lines changed

4 files changed

+50
-7
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Hints and TODOs
2+
3+
## General hints
4+
5+
- we already have a unidirectional mesh-particle tracing [tutorial](https://precice.org/tutorials-channel-transport-particles.html). This scenario is also available in the [tutorials repository](https://github.com/precice/tutorials/tree/develop/channel-transport-particles) and couples Nutils with MercuryDPM
6+
- the unidirectional tutorial only couples via the fluid velocity and should run out-of-the-box, use `setup-mercurydpm.sh` to run and compile the MercuryDPM participant
7+
- the tutorial uses OpenFOAM or Nutils, and MercuryDPM
8+
- all Nutils simulations use Nutils version 7
9+
- the bidirectional scenario builds upon this tutorial case
10+
11+
## Before starting
12+
13+
- make sure you have the latest develop of preCICE
14+
15+
## The bidirectional coupling
16+
17+
- the bidirectional coupling is pull request [706](https://github.com/precice/tutorials/pull/706)
18+
- from the [tutorials](https://github.com/precice/tutorials/tree/develop/channel-bidirectional), checkout the branch `channel-bidirectional` and navigate to `~/tutorials/channel-transport-particles/`
19+
- run the `setup-mercurydpm.sh` script again (it checks out another branch for the solver)
20+
- the overall setup is no too much physics-motivated, using the same boundary conditions leads to the following
21+
22+
![snapshot-final](../images/tutorials-channel-transport-particles-t-final.png)
23+
24+
- after you completed the case, I would validate it with a more complex scenario
25+
- while the simulation here is 2D, the final validation case will be 3D
26+
- I put all further comments directly into the `fluid.py` code

channel-transport-particles/fluid-nutils/fluid.py

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@
1313

1414
def main():
1515

16+
# COMMENT: nothing to change here
1617
print("Running Nutils")
1718

18-
# define the Nutils mesh
1919
nx = 48
2020
ny = 16
2121
step_start = nx // 3
@@ -28,13 +28,19 @@ def main():
2828
step_start:step_end, :step_hight
2929
].withboundary(wall="left,top,right")
3030

31-
# cloud of Gauss points
3231
gauss = domain.sample("gauss", degree=4)
3332

34-
# Nutils namespace
3533
ns = function.Namespace()
3634
ns.x = geom
3735

36+
# COMMENT: looks like the weak is being defined here: the weak form now needs to incorporate the volume fraction
37+
# Note that preCICE/MercuryDPM provides a field called "Alpha", which is the solid volume fraction. The formula
38+
# 7.1 and 7.2 from the PDF use the fluid volume frection (epsilon_f), which is epsilon_f = (1 - Alpha).
39+
# Note that reading from preCICE makes only sense after the initialize call.
40+
# Moreover, we need to incorporate gravity (ε_f*ρ_f*g) in 7.2 and the drag force. The drag force is here zero either
41+
# Note that the drag force is called "ExplicitMomentum" in preCICE. I
42+
# would maybe later still try to implement the explicit-implicit split,
43+
# that's the only reason
3844
ns.ubasis = domain.basis("std", degree=2).vector(2)
3945
ns.pbasis = domain.basis("std", degree=1)
4046
ns.u_i = "ubasis_ni ?u_n" # solution
@@ -48,7 +54,7 @@ def main():
4854
ures = gauss.integral("ubasis_ni,j σ_ij d:x" @ ns)
4955
pres = gauss.integral("pbasis_n u_k,k d:x" @ ns)
5056

51-
# define Dirichlet boundary condition
57+
# Dirichlet boundary condition
5258
sqr = domain.boundary["inflow"].integral("(u_0 - uin)^2 d:x" @ ns, degree=2)
5359
sqr += domain.boundary["inflow,outflow"].integral("u_1^2 d:x" @ ns, degree=2)
5460
sqr += domain.boundary["wall"].integral("u_k u_k d:x" @ ns, degree=2)
@@ -57,13 +63,16 @@ def main():
5763
# preCICE setup
5864
participant = precice.Participant("Fluid", "../precice-config.xml", 0, 1)
5965

60-
# define coupling mesh
66+
# define coupling mesh (nothing to change)
6167
mesh_name = "Fluid-Mesh"
6268
vertices = gauss.eval(ns.x)
6369
vertex_ids = participant.set_mesh_vertices(mesh_name, vertices)
6470

65-
# coupling data
71+
# COMMENT: names of the new coupling data fields in the preCICE configuration. The velocity was already there before
72+
solid_fraction_name = "Alpha"
73+
drag_force_name = "ExplicitMomentum"
6674
data_name = "Velocity"
75+
pressure_gradient_name = "PressureGradientFull"
6776

6877
participant.initialize()
6978

@@ -90,13 +99,21 @@ def main():
9099
# potentially adjust non-matching timestep sizes
91100
dt = min(solver_dt, precice_dt)
92101

102+
# COMMENT: here we would need to read the solid volume fraction and the drag force from preCICE and incorporate them into the weak form. The pressure gradient would also need to be written to preCICE, but let's start with the velocity first
103+
# Note that the read_data call takes a dt argument, which is the relative read time. For Euler backwards, it would simply be dt
104+
# solid_fraction_values = participant.read_data(mesh_name, solid_fraction_name, vertex_ids, ...)
105+
# drag_force_name = participant.read_data(mesh_name, drag_force_name, vertex_ids, ...)
106+
# Checkpointing for implicit coupling is generally not required
107+
93108
# solve Nutils timestep
94109
state["u0"] = state["u"]
95110
state["dt"] = dt
96111
state = solver.newton(("u", "p"), (ures, pres), constrain=cons, arguments=state).solve(1e-10)
97112

98113
velocity_values = gauss.eval(ns.u, **state)
114+
# COMMENT: here we would also need to write the pressure gradient to preCICE
99115
participant.write_data(mesh_name, data_name, vertex_ids, velocity_values)
116+
# participant.write_data(mesh_name, pressure_gradient_name, vertex_ids, pressure_gradient_values)
100117

101118
# do the coupling
102119
participant.advance(dt)
218 KB
Loading

channel-transport-particles/precice-config.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
<data:vector name="Velocity" waveform-degree="0" />
1717
<data:vector name="PressureGradientFull" waveform-degree="0" />
1818

19-
<mesh name="Fluid-Mesh" dimensions="3">
19+
<mesh name="Fluid-Mesh" dimensions="2">
2020
<use-data name="Velocity" />
2121
<use-data name="PressureGradientFull" />
2222
<use-data name="Alpha" />

0 commit comments

Comments
 (0)