9
9
from xml .etree import ElementTree as ET
10
10
11
11
from dolfin import MPI , XDMFFile , HDF5File , FunctionSpace , Function , interpolate , MeshFunction
12
+
12
13
from oasismove .problems import info_red
13
14
14
15
__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,
62
63
return newfolder , tstepfiles
63
64
64
65
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 ,
67
68
** NS_namespace ):
68
69
"""Called at end of timestep. Check for kill and save solution if required."""
69
70
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
78
79
79
80
killoasis = check_if_kill (folder , killtime , total_timer )
80
81
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 )
82
83
83
84
return killoasis
84
85
@@ -116,7 +117,7 @@ def save_tstep_solution_xdmf(tstep, q_, u_, newfolder, tstepfiles, output_timese
116
117
pickle .dump (NS_parameters , f )
117
118
118
119
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 ):
120
121
"""
121
122
Overwrite solution in Checkpoint folder
122
123
"""
@@ -142,6 +143,19 @@ def save_checkpoint_solution_xdmf(q_, q_1, newfolder, u_components, mesh, NS_par
142
143
f .write_checkpoint (q_1 [ui ], '/previous' , append = True )
143
144
MPI .barrier (MPI .comm_world )
144
145
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
+
145
159
# Store mesh and boundary
146
160
MPI .barrier (MPI .comm_world )
147
161
mesh_path = path .join (checkpointfolder , 'mesh.h5' )
@@ -202,7 +216,7 @@ def check_if_reset_statistics(folder):
202
216
return False
203
217
204
218
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 ,
206
220
previous_velocity_degree , mesh , constrained_domain , V , Q , ** NS_namespace ):
207
221
"""Initialize solution from checkpoint files """
208
222
if restart_folder :
@@ -219,6 +233,7 @@ def init_from_restart(restart_folder, sys_comp, uc_comp, u_components, q_, q_1,
219
233
q_prev = dict ((ui , Function (VV_prev [ui ], name = ui )) for ui in sys_comp )
220
234
q_2_prev = dict ((ui , Function (V_prev , name = ui + "_2" )) for ui in u_components )
221
235
236
+ # Load velocity and pressure
222
237
for ui in sys_comp :
223
238
checkpoint_path = path .join (restart_folder , ui + '.xdmf' )
224
239
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,
233
248
# Interpolate
234
249
read_and_interpolate_solution (f , V , previous_velocity_degree , q_2 , q_2_prev , ui ,
235
250
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" )
236
261
237
262
238
263
def read_and_interpolate_solution (f , V , previous_velocity_degree , q_ , q_prev , ui , velocity_degree , name ):
0 commit comments