Skip to content

Commit ec32033

Browse files
committed
benchmark
1 parent efae05c commit ec32033

File tree

1 file changed

+145
-8
lines changed

1 file changed

+145
-8
lines changed

benchmark.py

Lines changed: 145 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -108,14 +108,14 @@ def _elevate_degree(mesh, degree):
108108
return mesh
109109

110110

111-
T = 4.0 # 12.0
111+
T = 10.0 # 12.0
112112
dt = .05 #0.001
113113
ntimesteps = int(T / dt)
114114
t = Constant(0.0)
115115
dim = 2
116116
h = 0.10
117-
degree = 3 # 2 - 4
118-
nref = 2 # 2 - 5 tested
117+
degree = 2 #3 # 2 - 4
118+
nref = 1 # # 2 - 5 tested for CSM 1 and 2
119119
mesh = make_mesh(h)
120120
if nref > 0:
121121
mh = MeshHierarchy(mesh, nref)
@@ -140,7 +140,7 @@ def _elevate_degree(mesh, degree):
140140
x_s, y_s = SpatialCoordinate(mesh_s)
141141
n_s = FacetNormal(mesh_s)
142142

143-
case = "CSM1"
143+
case = "FSI1"
144144

145145
if case in ["CFD1", "CFD2", "CFD3"]:
146146
if case == "CFD1":
@@ -268,7 +268,8 @@ def _elevate_degree(mesh, degree):
268268
"ksp_type": "gmres",
269269
"pc_type": "gamg",
270270
"mg_levels_pc_type": "sor",
271-
#'mg_levels_ksp_max_it': 3,
271+
'mg_levels_ksp_max_it': 3,
272+
#"pc_type": "lu",
272273
#"pc_factor_mat_solver_type": "mumps"
273274
}
274275
near_nullspace = VectorSpaceBasis(vecs=[assemble(Function(V).interpolate(rigid_body_mode)) \
@@ -286,11 +287,147 @@ def _elevate_degree(mesh, degree):
286287
# u_s.at(pointA) = [-0.00722496 -0.06629327]
287288
print(V.dim())
288289
print(u_s.at(pointA))
289-
assert np.allclose(u_s.at(pointA), [-0.007187, -0.06610], rtol=1e-03)
290+
#assert np.allclose(u_s.at(pointA), [-0.007187, -0.06610], rtol=1e-03)
290291
else: # CSM3
291-
pass
292+
V0 = VectorFunctionSpace(mesh_s, "P", degree)
293+
V = V0 * V0
294+
solution = Function(V)
295+
solution_0 = Function(V)
296+
v_s, u_s = split(solution)
297+
v_s_0, u_s_0 = split(solution_0)
298+
dv_s, du_s = split(TestFunction(V))
299+
F = Identity(dim) + grad(u_s)
300+
E = 1. / 2. * (dot(transpose(F), F) - Identity(dim))
301+
S = lambda_s * tr(E) * Identity(dim) + 2.0 * mu_s * E
302+
residual = inner((u_s - u_s_0) / dt - v_s, dv_s) * dx + \
303+
rho_s * inner(v_s - v_s_0, du_s) / dt * dx + \
304+
inner(dot(F, S), grad(du_s)) * dx - \
305+
rho_s * inner(as_vector([0., - g_s_float]), du_s) * dx
306+
bc_v = DirichletBC(V.sub(0), as_vector([0., 0.]), label_struct_base)
307+
bc_u = DirichletBC(V.sub(1), as_vector([0., 0.]), label_struct_base)
308+
solver_parameters = {
309+
"mat_type": "aij",
310+
"snes_monitor": None,
311+
"ksp_monitor": None,
312+
#"ksp_view": None,
313+
"ksp_type": "gmres",
314+
#"pc_type": "gamg",
315+
#"mg_levels_pc_type": "sor",
316+
#'mg_levels_ksp_max_it': 3,
317+
"pc_type": "lu",
318+
"pc_factor_mat_solver_type": "mumps"
319+
}
320+
problem = NonlinearVariationalProblem(residual, solution, bcs=[bc_v, bc_u])
321+
solver = NonlinearVariationalSolver(problem, solver_parameters=solver_parameters)
322+
for itimestep in range(ntimesteps):
323+
print(f"{itimestep} / {ntimesteps}", flush=True)
324+
t.assign((itimestep + 1) * dt)
325+
solver.solve()
326+
for subfunction, subfunction_0 in zip(solution.subfunctions, solution_0.subfunctions):
327+
subfunction_0.assign(subfunction)
328+
print(solution.subfunctions[1].at(pointA))
292329
elif case in ["FSI1", "FSI2", "FSI3"]:
293-
pass
330+
if case == "FSI1":
331+
rho_s = 1.e+3
332+
nu_s = 0.4
333+
mu_s = 0.5 * 1.e+6
334+
rho_f = 1.e+3
335+
nu_f = 1.e-3
336+
Ubar = 0.2
337+
# Re = 20.
338+
elif case == "FSI2":
339+
rho_s = 10. * 1.e+3
340+
nu_s = 0.4
341+
mu_s = 0.5 * 1.e+6
342+
rho_f = 1.e+3
343+
nu_f = 1.e-3
344+
Ubar = 1.0
345+
# Re = 100.
346+
elif case == "FSI3":
347+
rho_s = 1. * 1.e+3
348+
nu_s = 0.4
349+
mu_s = 2.0 * 1.e+6
350+
rho_f = 1.e+3
351+
nu_f = 1.e-3
352+
Ubar = 2.0
353+
# Re = 200.
354+
else:
355+
raise ValueError
356+
g_s = 2.0
357+
E_s = mu_s * 2 * (1 + nu_s)
358+
lambda_s = nu_s * E_s / (1 + nu_s) / (1 - 2 * nu_s)
359+
V_0 = VectorFunctionSpace(mesh_f, "P", degree)
360+
V_1 = FunctionSpace(mesh_f, "P", degree - 2)
361+
V = V_0 * V_1
362+
solution = Function(V)
363+
solution_0 = Function(V)
364+
v_f, p_f = split(solution)
365+
u_f = Function(V_0)
366+
v_f_0, p_f_0 = split(solution_0)
367+
dv_f, dp_f = split(TestFunction(V))
368+
residual = (
369+
rho_f * inner(v_f - v_f_0, dv_f) / dt +
370+
rho_f * inner(dot(grad(v_f), v_f), dv_f) +
371+
rho_f * nu_f * inner(2 * sym(grad(v_f)), grad(dv_f)) -
372+
inner(p_f, div(dv_f)) +
373+
inner(div(v_f), dp_f)) * dx
374+
v_f_left = 1.5 * Ubar * y_f * (H - y_f) / ((H / 2) ** 2) * conditional(t < 2.0, (1 - cos(pi / 2 * t)) / 2., 1.)
375+
bc_inflow = DirichletBC(V.sub(0), as_vector([v_f_left, 0.]), label_left)
376+
bc_noslip = DirichletBC(V.sub(0), Constant((0, 0)), label_bottom + label_top + label_circle + label_interface)
377+
#bc_inflow = EquationBC(inner(v_f - as_vector([v_f_left, 0.]), dv_f) * ds(label_left) == 0, solution, label_left, V=V.sub(0))
378+
#bc_noslip = EquationBC(inner(v_f, dv_f) * ds(label_bottom + label_top + label_circle + label_interface) == 0, solution, label_bottom + label_top + label_circle + label_interface, V=V.sub(0))
379+
solver_parameters = {
380+
"mat_type": "aij",
381+
"snes_monitor": None,
382+
"ksp_type": "gmres",
383+
"pc_type": "lu",
384+
"pc_factor_mat_solver_type": "mumps"
385+
}
386+
"""
387+
solver_parameters = {
388+
#'mat_type': 'matfree',
389+
'pc_type': 'fieldsplit',
390+
'ksp_type': 'preonly',
391+
'pc_fieldsplit_type': 'schur',
392+
'fieldsplit_schur_fact_type': 'full',
393+
'fieldsplit_0': {
394+
#'ksp_type': 'cg',
395+
'ksp_type': 'gmres', # equationBC is nonsym
396+
'pc_type': 'python',
397+
'pc_python_type': 'firedrake.AssembledPC',
398+
'assembled_pc_type': 'gamg',
399+
'assembled_mg_levels_pc_type': 'sor',
400+
'assembled_mg_levels_pc_sor_diagonal_shift': 1e-100, # See https://gitlab.com/petsc/petsc/-/issues/1221
401+
'ksp_rtol': 1e-7,
402+
'ksp_converged_reason': None,
403+
},
404+
'fieldsplit_1': {
405+
'ksp_type': 'fgmres',
406+
'ksp_converged_reason': None,
407+
'pc_type': 'python',
408+
'pc_python_type': 'firedrake.MassInvPC',
409+
'Mp_pc_type': 'ksp',
410+
'Mp_ksp_ksp_type': 'cg',
411+
'Mp_ksp_pc_type': 'sor',
412+
'ksp_rtol': '1e-5',
413+
'ksp_monitor': None,
414+
},
415+
"snes_monitor": None,
416+
}
417+
"""
418+
problem = NonlinearVariationalProblem(residual, solution, bcs=[bc_inflow, bc_noslip])
419+
solver = NonlinearVariationalSolver(problem, solver_parameters=solver_parameters)
420+
for itimestep in range(ntimesteps):
421+
print(f"{itimestep} / {ntimesteps}", flush=True)
422+
t.assign((itimestep + 1) * dt)
423+
solver.solve()
424+
for subfunction, subfunction_0 in zip(solution.subfunctions, solution_0.subfunctions):
425+
subfunction_0.assign(subfunction)
426+
FD = assemble((-p_f * n_f + rho_f * nu_f * dot(2 * sym(grad(v_f)), n_f))[0] * ds(label_circle + label_interface))
427+
FL = assemble((-p_f * n_f + rho_f * nu_f * dot(2 * sym(grad(v_f)), n_f))[1] * ds(label_circle + label_interface))
428+
print(f"FD = {FD}")
429+
print(f"FL = {FL}")
430+
print("num cells = ", mesh_f.comm.allreduce(mesh_f.cell_set.size))
294431
else:
295432
raise ValueError
296433

0 commit comments

Comments
 (0)