Skip to content

Commit 01fef75

Browse files
support WR bindings and fenics adapter
1 parent f6ff637 commit 01fef75

File tree

6 files changed

+95
-11
lines changed

6 files changed

+95
-11
lines changed

FSI/cylinderFlap/OpenFOAM-FEniCS/Solid/cyl-flap.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,10 +90,11 @@ def remaining_boundary(x, on_boundary):
9090
# get the adapter ready
9191

9292
# read fenics-adapter json-config-file)
93-
adapter_config_filename = "../tools/precice-adapter-config-fsi-s.json"
93+
adapter_config_filename = "../tools/precice-adapter-config-fsi-s_wr.json"
94+
other_adapter_config_filename = "../tools/precice-adapter-config-excite.json"
9495

9596
# create Adapter
96-
precice = Adapter(adapter_config_filename)
97+
precice = Adapter(adapter_config_filename, other_adapter_config_filename)
9798

9899
# create subdomains used by the adapter
99100
clamped_boundary_domain = AutoSubDomain(left_boundary)
@@ -107,6 +108,7 @@ def remaining_boundary(x, on_boundary):
107108
dimension=dim,
108109
dirichlet_boundary=clamped_boundary_domain)
109110

111+
precice_dt = float(precice_dt)
110112
fenics_dt = precice_dt # if fenics_dt == precice_dt, no subcycling is applied
111113
#fenics_dt = 0.02 # if fenics_dt < precice_dt, subcycling is applied
112114
dt = Constant(np.min([precice_dt, fenics_dt]))
@@ -238,6 +240,7 @@ def avg(x_old, x_new, alpha):
238240
displacement_out << (u_n, t)
239241

240242
u_tip.append(u_n(0.6, 0.2)[1])
243+
print(u_n(0.6, 0.2))
241244
time.append(t)
242245

243246

@@ -251,3 +254,4 @@ def avg(x_old, x_new, alpha):
251254

252255
output_file = open("subiteration_out.txt", "a")
253256
output_file.write("{};{}\n".format(u_tip[-1], dt(0)))
257+
precice.finalize()

FSI/cylinderFlap/OpenFOAM-FEniCS/tools/excitement.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import numpy as np
55
import precice_future as precice
66

7-
force_excitement = np.array([0, 10, 0])
87
omega_excitement = 1
98

109
# beam geometry
@@ -18,7 +17,7 @@
1817
y_attack = .5 * (y_bottom + y_top)
1918

2019

21-
def compute_force(time):
20+
def compute_force(time, force_excitement):
2221
omega = omega_excitement
2322
force_0 = force_excitement
2423
return force_0 * np.sin(omega * time)
@@ -40,7 +39,7 @@ def compute_force(time):
4039
write_data_name = "Forces0"
4140
read_data_name = "Displacements0"
4241

43-
n = 1
42+
n_vertices = 1
4443

4544
solver_process_index = 0
4645
solver_process_size = 1
@@ -51,7 +50,13 @@ def compute_force(time):
5150
mesh_id = interface.get_mesh_id(mesh_name)
5251

5352
dimensions = interface.get_dimensions()
54-
vertices = np.array([x_attack, y_attack, 0])
53+
force_excitement = np.zeros((n_vertices, dimensions))
54+
force_excitement[:, 0] = 0
55+
force_excitement[:, 1] = 10
56+
57+
vertices = np.zeros((n_vertices, dimensions))
58+
vertices[:, 0] = x_attack
59+
vertices[:, 1] = y_attack
5560

5661
vertex_ids = interface.set_mesh_vertices(mesh_id, vertices)
5762
write_data_id = interface.get_data_id(write_data_name, mesh_id)
@@ -61,7 +66,7 @@ def compute_force(time):
6166
t = 0
6267

6368
if interface.is_action_required(precice.action_write_initial_data()):
64-
forces = compute_force(t + dt)
69+
forces = compute_force(t + dt, force_excitement)
6570
interface.write_block_vector_data(write_data_id, vertex_ids, forces)
6671
interface.fulfilled_action(precice.action_write_initial_data())
6772

@@ -73,7 +78,7 @@ def compute_force(time):
7378
print("DUMMY: Writing iteration checkpoint")
7479
interface.fulfilled_action(precice.action_write_iteration_checkpoint())
7580

76-
forces = compute_force(t+dt)
81+
forces = compute_force(t+dt, force_excitement)
7782
print("sending forces: {}".format(forces))
7883
interface.write_block_vector_data(write_data_id, vertex_ids, forces)
7984
dt = interface.advance(dt)
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"solver_name": "fenics",
3+
"config_file_name": "../tools/precice-config.xml",
4+
"interface": {
5+
"coupling_mesh_name": "Excitement",
6+
"write_data_name": "Forces0",
7+
"read_data_name": "Displacements0"
8+
},
9+
"waveform": {
10+
"n_substeps": 1
11+
}
12+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"solver_name": "fenics",
3+
"config_file_name": "../tools/precice-config_wr.xml",
4+
"interface": {
5+
"coupling_mesh_name": "Solid",
6+
"write_data_name": "Displacements",
7+
"read_data_name": "Forces"
8+
},
9+
"waveform": {
10+
"n_substeps": 1
11+
}
12+
}

FSI/cylinderFlap/OpenFOAM-FEniCS/tools/precice-config.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<sink type="stream" output="stdout" filter= "%Severity% > debug" format="preCICE:%ColorizedSeverity% %Message%" enabled="true" />
77
</log>
88

9-
<solver-interface dimensions="3" >
9+
<solver-interface dimensions="2" >
1010

1111
<data:vector name="Forces0"/>
1212
<data:vector name="Displacements0"/>
@@ -26,8 +26,8 @@
2626
<use-mesh name="Solid" from="fenics"/>
2727
<write-data name="Forces0" mesh="Excitement-Mesh"/>
2828
<read-data name="Displacements0" mesh="Excitement-Mesh"/>
29-
<mapping:petrbf-thin-plate-splines direction="write" from="Excitement-Mesh" to="Solid" constraint="conservative" z-dead="true"/>
30-
<mapping:petrbf-thin-plate-splines direction="read" from="Solid" to="Excitement-Mesh" constraint="consistent" z-dead="true"/>
29+
<mapping:petrbf-thin-plate-splines direction="write" from="Excitement-Mesh" to="Solid" constraint="conservative" />
30+
<mapping:petrbf-thin-plate-splines direction="read" from="Solid" to="Excitement-Mesh" constraint="consistent" />
3131
</participant>
3232

3333
<participant name="fenics">
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<?xml version="1.0"?>
2+
3+
<precice-configuration>
4+
5+
<log>
6+
<sink type="stream" output="stdout" filter= "%Severity% > debug" format="preCICE:%ColorizedSeverity% %Message%" enabled="true" />
7+
</log>
8+
9+
<solver-interface dimensions="2" >
10+
11+
<data:vector name="Forces1"/>
12+
<data:vector name="Displacements1"/>
13+
14+
<mesh name="Excitement-Mesh">
15+
<use-data name="Forces1"/>
16+
<use-data name="Displacements1"/>
17+
</mesh>
18+
19+
<mesh name="Solid">
20+
<use-data name="Forces1"/>
21+
<use-data name="Displacements1"/>
22+
</mesh>
23+
24+
<participant name="Excitement">
25+
<use-mesh name="Excitement-Mesh" provide="yes"/>
26+
<use-mesh name="Solid" from="fenics"/>
27+
<write-data name="Forces1" mesh="Excitement-Mesh"/>
28+
<read-data name="Displacements1" mesh="Excitement-Mesh"/>
29+
<mapping:petrbf-thin-plate-splines direction="write" from="Excitement-Mesh" to="Solid" constraint="conservative" />
30+
<mapping:petrbf-thin-plate-splines direction="read" from="Solid" to="Excitement-Mesh" constraint="consistent" />
31+
</participant>
32+
33+
<participant name="fenics">
34+
<use-mesh name="Solid" provide="yes"/>
35+
<read-data name="Forces1" mesh="Solid"/>
36+
<write-data name="Displacements1" mesh="Solid"/>
37+
<watch-point mesh="Solid" name="point1" coordinate="0.6;0.2;0." />
38+
</participant>
39+
40+
<m2n:sockets from="Excitement" to="fenics" distribution-type="gather-scatter"/>
41+
42+
<coupling-scheme:serial-explicit>
43+
<participants first="Excitement" second="fenics" />
44+
<max-time value="1"/>
45+
<timestep-length value="0.1" />
46+
<exchange data="Forces1" mesh="Solid" from="Excitement" to="fenics"/>
47+
<exchange data="Displacements1" mesh="Solid" from="fenics" to="Excitement" initialize="0"/>
48+
</coupling-scheme:serial-explicit>
49+
</solver-interface>
50+
51+
</precice-configuration>

0 commit comments

Comments
 (0)