Skip to content

Commit 18e8a21

Browse files
authored
Merge pull request #23 from KVSlab/store-u-and-d
Store mesh velocity and deformation during checkpointing.
2 parents ba2f977 + 02f5a10 commit 18e8a21

File tree

4 files changed

+36
-6
lines changed

4 files changed

+36
-6
lines changed

codecov.yml

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
ignore:
2+
- "tests/*"

src/oasismove/NSfracStep.py

+4
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,9 @@
111111
q_1 = dict((ui, Function(VV[ui], name=ui + "_1")) for ui in sys_comp)
112112
q_2 = dict((ui, Function(V, name=ui + "_2")) for ui in u_components)
113113

114+
# Create temporary dictionary for the mesh velocity and deformation
115+
w_ = d_ = None
116+
114117
# Read in previous solution if restarting
115118
init_from_restart(**vars())
116119

@@ -119,6 +122,7 @@
119122
u_1 = as_vector([q_1[ui] for ui in u_components]) # Velocity vector at t - dt
120123
u_2 = as_vector([q_2[ui] for ui in u_components]) # Velocity vector at t - 2*dt
121124

125+
122126
# Adams Bashforth projection of velocity at t - dt/2
123127
U_AB = 1.5 * u_1 - 0.5 * u_2
124128

src/oasismove/common/io.py

+30-5
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from xml.etree import ElementTree as ET
1010

1111
from dolfin import MPI, XDMFFile, HDF5File, FunctionSpace, Function, interpolate, MeshFunction
12+
1213
from oasismove.problems import info_red
1314

1415
__all__ = ["create_initial_folders", "save_solution", "save_tstep_solution_xdmf",
@@ -62,8 +63,8 @@ def create_initial_folders(folder, restart_folder, sys_comp, tstep, info_red,
6263
return newfolder, tstepfiles
6364

6465

65-
def save_solution(tstep, t, q_, q_1, folder, newfolder, save_step, checkpoint, NS_parameters, tstepfiles, u_,
66-
u_components, output_timeseries_as_vector, mesh, AssignedVectorFunction, killtime, total_timer,
66+
def save_solution(tstep, t, q_, q_1, w_, d_, folder, newfolder, save_step, checkpoint, NS_parameters, tstepfiles,
67+
u_, u_components, output_timeseries_as_vector, mesh, AssignedVectorFunction, killtime, total_timer,
6768
**NS_namespace):
6869
"""Called at end of timestep. Check for kill and save solution if required."""
6970
NS_parameters.update(t=t, tstep=tstep)
@@ -78,7 +79,7 @@ def save_solution(tstep, t, q_, q_1, folder, newfolder, save_step, checkpoint, N
7879

7980
killoasis = check_if_kill(folder, killtime, total_timer)
8081
if tstep % checkpoint == 0 or killoasis:
81-
save_checkpoint_solution_xdmf(q_, q_1, newfolder, u_components, mesh, NS_parameters)
82+
save_checkpoint_solution_xdmf(q_, q_1, w_, d_, newfolder, u_components, mesh, NS_parameters)
8283

8384
return killoasis
8485

@@ -116,7 +117,7 @@ def save_tstep_solution_xdmf(tstep, q_, u_, newfolder, tstepfiles, output_timese
116117
pickle.dump(NS_parameters, f)
117118

118119

119-
def save_checkpoint_solution_xdmf(q_, q_1, newfolder, u_components, mesh, NS_parameters):
120+
def save_checkpoint_solution_xdmf(q_, q_1, w_, d_, newfolder, u_components, mesh, NS_parameters):
120121
"""
121122
Overwrite solution in Checkpoint folder
122123
"""
@@ -142,6 +143,19 @@ def save_checkpoint_solution_xdmf(q_, q_1, newfolder, u_components, mesh, NS_par
142143
f.write_checkpoint(q_1[ui], '/previous', append=True)
143144
MPI.barrier(MPI.comm_world)
144145

146+
MPI.barrier(MPI.comm_world)
147+
# Store mesh velocity and deformation solution
148+
if w_ is not None:
149+
for ui in w_:
150+
checkpoint_path = path.join(checkpointfolder, ui.replace("u", "w") + '.xdmf')
151+
with XDMFFile(MPI.comm_world, checkpoint_path) as f:
152+
f.write_checkpoint(w_[ui], '/current')
153+
154+
checkpoint_path = path.join(checkpointfolder, ui.replace("u", "d") + '.xdmf')
155+
with XDMFFile(MPI.comm_world, checkpoint_path) as f:
156+
f.write_checkpoint(d_[ui], '/current')
157+
MPI.barrier(MPI.comm_world)
158+
145159
# Store mesh and boundary
146160
MPI.barrier(MPI.comm_world)
147161
mesh_path = path.join(checkpointfolder, 'mesh.h5')
@@ -202,7 +216,7 @@ def check_if_reset_statistics(folder):
202216
return False
203217

204218

205-
def init_from_restart(restart_folder, sys_comp, uc_comp, u_components, q_, q_1, q_2, tstep, velocity_degree,
219+
def init_from_restart(restart_folder, sys_comp, uc_comp, u_components, q_, q_1, q_2, w_, d_, tstep, velocity_degree,
206220
previous_velocity_degree, mesh, constrained_domain, V, Q, **NS_namespace):
207221
"""Initialize solution from checkpoint files """
208222
if restart_folder:
@@ -219,6 +233,7 @@ def init_from_restart(restart_folder, sys_comp, uc_comp, u_components, q_, q_1,
219233
q_prev = dict((ui, Function(VV_prev[ui], name=ui)) for ui in sys_comp)
220234
q_2_prev = dict((ui, Function(V_prev, name=ui + "_2")) for ui in u_components)
221235

236+
# Load velocity and pressure
222237
for ui in sys_comp:
223238
checkpoint_path = path.join(restart_folder, ui + '.xdmf')
224239
with XDMFFile(MPI.comm_world, checkpoint_path) as f:
@@ -233,6 +248,16 @@ def init_from_restart(restart_folder, sys_comp, uc_comp, u_components, q_, q_1,
233248
# Interpolate
234249
read_and_interpolate_solution(f, V, previous_velocity_degree, q_2, q_2_prev, ui,
235250
velocity_degree, "/previous")
251+
# Load mesh velocity and deformation
252+
if w_ is not None:
253+
for ui in u_components:
254+
checkpoint_path = path.join(restart_folder, ui.replace("u", "w") + '.xdmf')
255+
with XDMFFile(MPI.comm_world, checkpoint_path) as f:
256+
f.read_checkpoint(w_[ui], "/current")
257+
258+
checkpoint_path = path.join(restart_folder, ui.replace("u", "d") + '.xdmf')
259+
with XDMFFile(MPI.comm_world, checkpoint_path) as f:
260+
f.read_checkpoint(d_[ui], "/current")
236261

237262

238263
def read_and_interpolate_solution(f, V, previous_velocity_degree, q_, q_prev, ui, velocity_degree, name):

src/oasismove/solvers/NSfracStep/IPCS_ABCN_Move.py

-1
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,6 @@ def mesh_velocity_assemble(A_mesh, ui, bw, bw_tmp, a_mesh, bc_mesh, A_cache, **N
283283
A_mesh.zero()
284284
A_mesh.axpy(1, A_cache[(a_mesh, tuple(bc_mesh[ui]))], True)
285285
bw[ui].zero()
286-
bw[ui].axpy(1., bw_tmp[ui])
287286

288287

289288
def mesh_velocity_solve(A_mesh, bw, wx_, w_, dof_map, dt, dx_, coordinates, w_sol, ui, bc_mesh, **NS_namespace):

0 commit comments

Comments
 (0)