Skip to content

Commit 63273dd

Browse files
authored
Update all FEniCS participants to be compatible with precice:develop (v3) (precice#333)
* Update all FEniCS participants to be compatible with precice:develop and fenics-adapter updates * Change from thin plate splines mapping to general rbf mapping * Update how dt is used. * Store time in vtk files for better visualization. * Partitioned heat conduction: * Fix config and case definition. (precice/precice#1610) * Use stricter error tolerance.
1 parent 0cd624e commit 63273dd

File tree

13 files changed

+88
-79
lines changed

13 files changed

+88
-79
lines changed

channel-transport-reaction/chemical-fenics/chemical-reaction-advection-diffusion.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,8 @@ def inside(self, x, on_boundary):
2727
# Initialize preCICE
2828
precice = fenicsprecice.Adapter(
2929
adapter_config_filename="chemical-reaction-advection-diffusion.json")
30-
precice_dt = precice.initialize(
31-
coupling_subdomain=CouplingDomain(),
32-
read_function_space=W)
30+
precice.initialize(coupling_subdomain=CouplingDomain(), read_function_space=W)
31+
precice_dt = precice.get_max_time_step_size()
3332

3433
flow_expr = precice.create_coupling_expression()
3534

@@ -95,13 +94,14 @@ def inside(self, x, on_boundary):
9594
# No implicit coupling
9695
while precice.is_coupling_ongoing():
9796

98-
read_data = precice.read_data()
97+
precice_dt = precice.get_max_time_step_size()
98+
dt = np.min([default_dt, precice_dt])
99+
read_data = precice.read_data(dt)
99100
precice.update_coupling_expression(flow_expr, read_data)
100101
flow_old.assign(flow)
101102
flow.interpolate(flow_expr)
102103
# If we add writing, do it here
103104

104-
dt = np.min([default_dt, precice_dt])
105105
k.assign(1. / dt)
106106

107107
t += dt
@@ -128,6 +128,6 @@ def inside(self, x, on_boundary):
128128
vtkfileC << u_C, t
129129
vtkfileFlow << flow, t
130130

131-
precice_dt = precice.advance(dt)
131+
precice.advance(dt)
132132

133133
precice.finalize()

channel-transport-reaction/fluid-fenics/fluid.py

+4-5
Original file line numberDiff line numberDiff line change
@@ -118,10 +118,8 @@ def inside(self, x, on_boundary):
118118

119119

120120
precice = fenicsprecice.Adapter(adapter_config_filename="fluid-config.json")
121-
precice_dt = precice.initialize(
122-
coupling_subdomain=CouplingDomain(),
123-
write_object=u_)
124-
121+
precice.initialize(coupling_subdomain=CouplingDomain(), write_object=u_)
122+
precice_dt = precice.get_max_time_step_size()
125123

126124
dt = np.min([default_dt, precice_dt])
127125
k.assign(dt)
@@ -155,7 +153,8 @@ def inside(self, x, on_boundary):
155153

156154
vtkfile << u_
157155

158-
precice_dt = precice.advance(dt)
156+
precice.advance(dt)
157+
precice_dt = precice.get_max_time_step_size()
159158
dt = np.min([default_dt, precice_dt])
160159
k.assign(dt)
161160

elastic-tube-3d/solid-fenics/solid.py

+11-9
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,8 @@ def neumann_boundary(x, on_boundary):
6565
precice = Adapter(adapter_config_filename="precice-adapter-config-fsi-s.json")
6666

6767
# Initialize the coupling interface
68-
precice_dt = precice.initialize(coupling_boundary, read_function_space=V, write_object=V, fixed_boundary=fixed_boundary)
68+
precice.initialize(coupling_boundary, read_function_space=V, write_object=V, fixed_boundary=fixed_boundary)
69+
precice_dt = precice.get_max_time_step_size()
6970

7071
fenics_dt = precice_dt # if fenics_dt == precice_dt, no subcycling is applied
7172
dt = Constant(np.min([precice_dt, fenics_dt]))
@@ -168,15 +169,18 @@ def avg(x_old, x_new, alpha):
168169

169170
u_n.rename("Displacement", "")
170171
u_np1.rename("Displacement", "")
171-
displacement_out << u_n
172+
displacement_out << (u_n, t)
172173

173174
while precice.is_coupling_ongoing():
174175

175-
if precice.is_action_required(precice.action_write_iteration_checkpoint()): # write checkpoint
176+
if precice.requires_writing_checkpoint(): # write checkpoint
176177
precice.store_checkpoint(u_n, t, n)
177178

179+
precice_dt = precice.get_max_time_step_size()
180+
dt = Constant(np.min([precice_dt, fenics_dt]))
181+
178182
# read data from preCICE and get a new coupling expression
179-
read_data = precice.read_data()
183+
read_data = precice.read_data(dt)
180184

181185
# Update the point sources on the coupling boundary with the new read data
182186
forces_x, forces_y, forces_z = precice.get_point_sources(read_data)
@@ -195,17 +199,15 @@ def avg(x_old, x_new, alpha):
195199
assert (b is not b_forces)
196200
solve(A, u_np1.vector(), b_forces)
197201

198-
dt = Constant(np.min([precice_dt, fenics_dt]))
199-
200202
# Write relative displacements to preCICE
201203
u_delta.vector()[:] = u_np1.vector()[:] - u_n.vector()[:]
202204
precice.write_data(u_delta)
203205

204206
# Call to advance coupling, also returns the optimum time step value
205-
precice_dt = precice.advance(dt(0))
207+
precice.advance(dt(0))
206208

207209
# Either revert to old step if timestep has not converged or move to next timestep
208-
if precice.is_action_required(precice.action_read_iteration_checkpoint()): # roll back to checkpoint
210+
if precice.requires_reading_checkpoint(): # roll back to checkpoint
209211
u_cp, t_cp, n_cp = precice.retrieve_checkpoint()
210212
u_n.assign(u_cp)
211213
t = t_cp
@@ -221,6 +223,6 @@ def avg(x_old, x_new, alpha):
221223
displacement_out << (u_n, t)
222224

223225
# Plot tip displacement evolution
224-
displacement_out << u_n
226+
displacement_out << (u_n, t)
225227

226228
precice.finalize()

flow-over-heated-plate/solid-fenics/solid.py

+10-9
Original file line numberDiff line numberDiff line change
@@ -115,13 +115,14 @@ def determine_heat_flux(V_g, u, k, flux):
115115
# Adapter definition and initialization
116116
precice = Adapter(adapter_config_filename="precice-adapter-config.json")
117117

118-
precice_dt = precice.initialize(coupling_boundary, read_function_space=V, write_object=V_flux_y)
118+
precice.initialize(coupling_boundary, read_function_space=V, write_object=V_flux_y)
119119

120120
# Create a FEniCS Expression to define and control the coupling boundary values
121121
coupling_expression = precice.create_coupling_expression()
122122

123123
# Assigning appropriate dt
124124
dt = Constant(0)
125+
precice_dt = precice.get_max_time_step_size()
125126
dt.assign(np.min([fenics_dt, precice_dt]))
126127

127128
# Define variational problem
@@ -149,7 +150,7 @@ def determine_heat_flux(V_g, u, k, flux):
149150

150151
# Create output file
151152
file_out = File("output/%s.pvd" % precice.get_participant_name())
152-
file_out << u_n
153+
file_out << (u_n, t)
153154

154155
print("output vtk for time = {}".format(float(t)))
155156
n = 0
@@ -159,16 +160,16 @@ def determine_heat_flux(V_g, u, k, flux):
159160

160161
while precice.is_coupling_ongoing():
161162

162-
if precice.is_action_required(precice.action_write_iteration_checkpoint()): # write checkpoint
163+
if precice.requires_writing_checkpoint(): # write checkpoint
163164
precice.store_checkpoint(u_n, t, n)
164165

165-
read_data = precice.read_data()
166+
precice_dt = precice.get_max_time_step_size()
167+
dt.assign(np.min([fenics_dt, precice_dt]))
168+
read_data = precice.read_data(dt)
166169

167170
# Update the coupling expression with the new read data
168171
precice.update_coupling_expression(coupling_expression, read_data)
169172

170-
dt.assign(np.min([fenics_dt, precice_dt]))
171-
172173
# Compute solution
173174
solve(a == L, u_np1, bcs)
174175

@@ -177,9 +178,9 @@ def determine_heat_flux(V_g, u, k, flux):
177178
fluxes_y = fluxes.sub(1) # only exchange y component of flux.
178179
precice.write_data(fluxes_y)
179180

180-
precice_dt = precice.advance(dt(0))
181+
precice.advance(dt(0))
181182

182-
if precice.is_action_required(precice.action_read_iteration_checkpoint()): # roll back to checkpoint
183+
if precice.requires_reading_checkpoint(): # roll back to checkpoint
183184
u_cp, t_cp, n_cp = precice.retrieve_checkpoint()
184185
u_n.assign(u_cp)
185186
t = t_cp
@@ -193,7 +194,7 @@ def determine_heat_flux(V_g, u, k, flux):
193194
tol = 10e-5 # we need some tolerance, since otherwise output might be skipped.
194195
if abs((t + tol) % dt_out) < 2 * tol: # output if t is a multiple of dt_out
195196
print("output vtk for time = {}".format(float(t)))
196-
file_out << u_n
197+
file_out << (u_n, t)
197198

198199
# Update dirichlet BC
199200
u_D.t = t + float(dt)

partitioned-heat-conduction-complex/fenics/heat.py

+11-10
Original file line numberDiff line numberDiff line change
@@ -103,14 +103,15 @@ def determine_gradient(V_g, u, flux):
103103
# Initialize the adapter according to the specific participant
104104
if problem is ProblemType.DIRICHLET:
105105
precice = Adapter(adapter_config_filename="precice-adapter-config-D.json")
106-
precice_dt = precice.initialize(coupling_boundary, read_function_space=V, write_object=f_N_function)
106+
precice.initialize(coupling_boundary, read_function_space=V, write_object=f_N_function)
107107
elif problem is ProblemType.NEUMANN:
108108
precice = Adapter(adapter_config_filename="precice-adapter-config-N.json")
109-
precice_dt = precice.initialize(coupling_boundary, read_function_space=V_g, write_object=u_D_function)
109+
precice.initialize(coupling_boundary, read_function_space=V_g, write_object=u_D_function)
110110

111111
boundary_marker = False
112112

113113
dt = Constant(0)
114+
precice_dt = precice.get_max_time_step_size()
114115
dt.assign(np.min([fenics_dt, precice_dt]))
115116

116117
# Define variational problem
@@ -173,7 +174,7 @@ def determine_gradient(V_g, u, flux):
173174
# output solution and reference solution at t=0, n=0
174175
n = 0
175176
print('output u^%d and u_ref^%d' % (n, n))
176-
temperature_out << u_n
177+
temperature_out << (u_n, t)
177178
ref_out << u_ref
178179
ranks << mesh_rank
179180

@@ -191,10 +192,12 @@ def determine_gradient(V_g, u, flux):
191192
while precice.is_coupling_ongoing():
192193

193194
# write checkpoint
194-
if precice.is_action_required(precice.action_write_iteration_checkpoint()):
195+
if precice.requires_writing_checkpoint():
195196
precice.store_checkpoint(u_n, t, n)
196197

197-
read_data = precice.read_data()
198+
precice_dt = precice.get_max_time_step_size()
199+
dt.assign(np.min([fenics_dt, precice_dt]))
200+
read_data = precice.read_data(dt)
198201
if problem is ProblemType.DIRICHLET and (domain_part is DomainPart.CIRCULAR or domain_part is DomainPart.RECTANGLE):
199202
# We have to data for an arbitrary point that is not on the circle, to obtain exact solution.
200203
# See https://github.com/precice/fenics-adapter/issues/113 for details.
@@ -203,8 +206,6 @@ def determine_gradient(V_g, u, flux):
203206
# Update the coupling expression with the new read data
204207
precice.update_coupling_expression(coupling_expression, read_data)
205208

206-
dt.assign(np.min([fenics_dt, precice_dt]))
207-
208209
# Compute solution u^n+1, use bcs u_D^n+1, u^n and coupling bcs
209210
solve(a == L, u_np1, bcs)
210211

@@ -217,10 +218,10 @@ def determine_gradient(V_g, u, flux):
217218
# Neumann problem reads flux and writes temperature on boundary to Dirichlet problem
218219
precice.write_data(u_np1)
219220

220-
precice_dt = precice.advance(dt(0))
221+
precice.advance(dt(0))
221222

222223
# roll back to checkpoint
223-
if precice.is_action_required(precice.action_read_iteration_checkpoint()):
224+
if precice.requires_reading_checkpoint():
224225
u_cp, t_cp, n_cp = precice.retrieve_checkpoint()
225226
u_n.assign(u_cp)
226227
t = t_cp
@@ -237,7 +238,7 @@ def determine_gradient(V_g, u, flux):
237238
print('n = %d, t = %.2f: L2 error on domain = %.3g' % (n, t, error))
238239
# output solution and reference solution at t_n+1
239240
print('output u^%d and u_ref^%d' % (n, n))
240-
temperature_out << u_n
241+
temperature_out << (u_n, t)
241242
ref_out << u_ref
242243
error_out << error_pointwise
243244

partitioned-heat-conduction-complex/fenics/precice-adapter-config-D.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"config_file_name": "../precice-config.xml",
44
"interface": {
55
"coupling_mesh_name": "Dirichlet-Mesh",
6-
"write_data_name": "Flux",
6+
"write_data_name": "Heat-Flux",
77
"read_data_name": "Temperature"
88
}
99
}

partitioned-heat-conduction-complex/fenics/precice-adapter-config-N.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@
44
"interface": {
55
"coupling_mesh_name": "Neumann-Mesh",
66
"write_data_name": "Temperature",
7-
"read_data_name": "Flux"
7+
"read_data_name": "Heat-Flux"
88
}
99
}

partitioned-heat-conduction-complex/precice-config.xml

+7-7
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,22 @@
66
</log>
77

88
<data:scalar name="Temperature"/>
9-
<data:vector name="Flux"/>
9+
<data:vector name="Heat-Flux"/>
1010

1111
<mesh name="Dirichlet-Mesh" dimensions="2">
1212
<use-data name="Temperature"/>
13-
<use-data name="Flux"/>
13+
<use-data name="Heat-Flux"/>
1414
</mesh>
1515

1616
<mesh name="Neumann-Mesh" dimensions="2">
1717
<use-data name="Temperature"/>
18-
<use-data name="Flux"/>
18+
<use-data name="Heat-Flux"/>
1919
</mesh>
2020

2121
<participant name="Dirichlet">
2222
<provide-mesh name="Dirichlet-Mesh" />
2323
<receive-mesh name="Neumann-Mesh" from="Neumann" />
24-
<write-data name="Flux" mesh="Dirichlet-Mesh" />
24+
<write-data name="Heat-Flux" mesh="Dirichlet-Mesh" />
2525
<read-data name="Temperature" mesh="Dirichlet-Mesh" />
2626
<mapping:nearest-projection direction="read" from="Neumann-Mesh" to="Dirichlet-Mesh" constraint="consistent" />
2727
</participant>
@@ -30,7 +30,7 @@
3030
<provide-mesh name="Neumann-Mesh" />
3131
<receive-mesh name="Dirichlet-Mesh" from="Dirichlet"/>
3232
<write-data name="Temperature" mesh="Neumann-Mesh"/>
33-
<read-data name="Flux" mesh="Neumann-Mesh"/>
33+
<read-data name="Heat-Flux" mesh="Neumann-Mesh"/>
3434
<mapping:nearest-projection direction="read" from="Dirichlet-Mesh" to="Neumann-Mesh" constraint="consistent" />
3535
</participant>
3636

@@ -41,9 +41,9 @@
4141
<max-time value="1.0"/>
4242
<time-window-size value="0.1"/>
4343
<max-iterations value="100"/>
44-
<exchange data="Flux" mesh="Dirichlet-Mesh" from="Dirichlet" to="Neumann" />
44+
<exchange data="Heat-Flux" mesh="Dirichlet-Mesh" from="Dirichlet" to="Neumann" />
4545
<exchange data="Temperature" mesh="Neumann-Mesh" from="Neumann" to="Dirichlet" initialize="true"/>
46-
<relative-convergence-measure data="Flux" mesh="Dirichlet-Mesh" limit="1e-5"/>
46+
<relative-convergence-measure data="Heat-Flux" mesh="Dirichlet-Mesh" limit="1e-5"/>
4747
<relative-convergence-measure data="Temperature" mesh="Neumann-Mesh" limit="1e-5"/>
4848
<acceleration:IQN-ILS>
4949
<data name="Temperature" mesh="Neumann-Mesh"/>

0 commit comments

Comments
 (0)