Skip to content

Commit 80c9a08

Browse files
authored
Merge pull request #108 from keiyamamo/multiple_robin
Multiple robin
2 parents e3e727f + 4f6a03d commit 80c9a08

File tree

2 files changed

+29
-19
lines changed

2 files changed

+29
-19
lines changed

turtleFSI/modules/solid.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,15 @@ def solid_setup(d_, v_, phi, psi, dx_s, ds_s, dx_s_id_list, ds_s_ext_id_list, so
7373
"""
7474
if robin_bc:
7575
info_blue("Robin BC is used for the solid domain.")
76-
for solid_boundaries in range(len(ds_s_ext_id_list)):
77-
F_solid_linear += theta0 * inner((k_s * d_["n"] + c_s * v_["n"]), psi)*ds_s[solid_boundaries]
78-
F_solid_linear += theta1 * inner((k_s * d_["n-1"] + c_s * v_["n-1"]), psi)*ds_s[solid_boundaries]
76+
assert type(k_s) == list, "k_s should be a list."
77+
assert type(c_s) == list, "c_s should be a list."
78+
assert len(k_s) == len(c_s) == len(ds_s_ext_id_list), "k_s, c_s and ds_s_ext_id_list should have the same length."
79+
for solid_boundaries in range(len(ds_s_ext_id_list)):
80+
if MPI.rank(MPI.comm_world) == 0:
81+
print(f"solid_boundaries: {solid_boundaries}, ds_s_ext_id_list: {ds_s_ext_id_list[solid_boundaries]}")
82+
print(f"k_s: {k_s[solid_boundaries]}, c_s: {c_s[solid_boundaries]}")
83+
F_solid_linear += theta0 * inner((k_s[solid_boundaries] * d_["n"] + c_s[solid_boundaries] * v_["n"]), psi)*ds_s[solid_boundaries]
84+
F_solid_linear += theta1 * inner((k_s[solid_boundaries] * d_["n-1"] + c_s[solid_boundaries] * v_["n-1"]), psi)*ds_s[solid_boundaries]
7985

8086

8187
return dict(F_solid_linear=F_solid_linear, F_solid_nonlinear=F_solid_nonlinear)

turtleFSI/problems/RobinBC_validation.py

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
from turtleFSI.problems import *
33
import numpy as np
44
from scipy.integrate import odeint
5-
from turtleFSI.utils.Probe import Probe
65
import matplotlib.pyplot as plt
76

87
"""
@@ -35,8 +34,8 @@ def set_problem_parameters(default_variables, **namespace):
3534
T=0.1, # Simulation end time
3635
dt=0.0005, # Time step size
3736
theta=0.501, # Theta scheme (implicit/explicit time stepping): 0.5 + dt
38-
atol=1e-7, # Absolute tolerance in the Newton solver
39-
rtol=1e-7, # Relative tolerance in the Newton solver
37+
atol=1e-10, # Absolute tolerance in the Newton solver
38+
rtol=1e-10, # Relative tolerance in the Newton solver
4039
mesh_file="cylinder", # Mesh file name
4140
inlet_id=2, # inlet id
4241
outlet_id1=3, # outlet id
@@ -52,14 +51,14 @@ def set_problem_parameters(default_variables, **namespace):
5251
nu_s=nu_s_val, # Solid Poisson ratio [-]
5352
lambda_s=lambda_s_val, # Solid 1rst Lamé coef. [Pa]
5453
robin_bc = True, # Robin BC
55-
k_s = 1.0E5, # elastic response necesary for RobinBC
56-
c_s = 1.0E2, # viscoelastic response necesary for RobinBC
54+
k_s = [1.0E5], # elastic response necesary for RobinBC
55+
c_s = [1.0E2], # viscoelastic response necesary for RobinBC
5756
dx_f_id=1, # ID of marker in the fluid domain
5857
dx_s_id=1002, # ID of marker in the solid domain
5958
extrapolation="laplace", # laplace, elastic, biharmonic, no-extrapolation
6059
extrapolation_sub_type="constant", # constant, small_constant, volume, volume_change, bc1, bc2
6160
recompute=30, # Number of iterations before recompute Jacobian.
62-
recompute_tstep=10, # Number of time steps before recompute Jacobian.
61+
recompute_tstep=100, # Number of time steps before recompute Jacobian.
6362
save_step=1, # Save frequency of files for visualisation
6463
folder="robinbc_validation", # Folder where the results will be stored
6564
checkpoint_step=50, # checkpoint frequency
@@ -108,7 +107,7 @@ def _mass_spring_damper_system_ode(x, t, params_dict):
108107
dxdt = [dx1dt, dx2dt]
109108
return dxdt
110109

111-
def initiate(dvp_, mesh, DVP, **namespace):
110+
def initiate(mesh, **namespace):
112111
# Position to probe
113112
x_coordinate = mesh.coordinates()[:, 0]
114113
y_coordinate = mesh.coordinates()[:, 1]
@@ -119,14 +118,19 @@ def initiate(dvp_, mesh, DVP, **namespace):
119118
z_middle = (z_coordinate.max() + z_coordinate.min())/2
120119

121120
middle_point = np.array([x_middle, y_middle, z_middle])
122-
d_probe = Probe(middle_point, DVP.sub(0))
123-
d_probe(dvp_["n"].sub(0, deepcopy=True))
124-
return dict(d_probe=d_probe)
121+
d_list = []
122+
return dict(d_list=d_list, middle_point=middle_point)
125123

126-
def post_solve(d_probe, dvp_, **namespace):
127-
d_probe(dvp_["n"].sub(0, deepcopy=True))
128124

129-
def finished(T, dt, mesh, rho_s, k_s, c_s, boundaries, gravity, d_probe, **namespace):
125+
def post_solve(dvp_, d_list, middle_point, **namespace):
126+
d = dvp_["n"].sub(0, deepcopy=True)
127+
d_eval = d(middle_point)[1]
128+
d_list.append(d_eval)
129+
130+
return dict(d_list=d_list)
131+
132+
133+
def finished(T, dt, mesh, rho_s, k_s, c_s, boundaries, gravity, d_list, **namespace):
130134
# Define time step and initial conditions
131135
t_analytical = np.linspace(0, T, int(T/dt) + 1)
132136
analytical_solution_init = [0,0]
@@ -135,15 +139,15 @@ def finished(T, dt, mesh, rho_s, k_s, c_s, boundaries, gravity, d_probe, **names
135139
ds_robin = Measure("ds", domain=mesh, subdomain_data=boundaries, subdomain_id=1033)
136140
params_dict = dict()
137141
params_dict["m"] = volume*rho_s
138-
params_dict["k"] = k_s
139-
params_dict["c"] = c_s
142+
params_dict["k"] = k_s[0]
143+
params_dict["c"] = c_s[0]
140144
params_dict["A"] = assemble(1*ds_robin)
141145
params_dict["F"] = -gravity*volume*rho_s
142146
# Solve the ode to compute the analytical solution
143147
analytical_solution = odeint(_mass_spring_damper_system_ode, analytical_solution_init, t_analytical, args=(params_dict,))
144148
analytical_displacement = analytical_solution[:,0]
145149
# Plot both numerical and analytical solutions for a comparison
146-
plt.plot(d_probe.get_probe_sub(1), label="turtleFSI")
150+
plt.plot(d_list, label="turtleFSI")
147151
plt.plot(analytical_displacement, label="analytical")
148152
plt.legend()
149153
plt.show()

0 commit comments

Comments
 (0)