Merge lp:~fluidity-core/fluidity/moving-mesh-checkpoint into lp:fluidity

Proposed by Stephan Kramer
Status: Merged
Approved by: Samuel Parkinson
Approved revision: 3991
Merged at revision: 4221
Proposed branch: lp:~fluidity-core/fluidity/moving-mesh-checkpoint
Merge into: lp:fluidity
Diff against target: 210 lines (+95/-25)
3 files modified
femtools/Checkpoint.F90 (+39/-9)
tests/spherical_patch/spherical_patch.xml (+19/-11)
tests/spherical_patch/spherical_segment.flml (+37/-5)
To merge this branch: bzr merge lp:~fluidity-core/fluidity/moving-mesh-checkpoint
Reviewer Review Type Date Requested Status
Cian Wilson Pending
Review via email: mp+107943@code.launchpad.net

Description of the change

Fix checkpointing for free surface moving mesh simulations by using OriginalCoordinate for the dumping the mesh and the field vtus. The mesh movement will be reapplied at the start of the restart run. Checkpointing with a moving mesh not controlled by free surface movement, now gives a warning (not supported). Switching on mesh movement in spherical patch test case to test this checkpointing.

To post a comment you must log in.
Revision history for this message
Stephan Kramer (s-kramer) wrote :

Thanks for reviewing, Sam. I'll merge in the trunk (as this is a while ago) and see if it goes green again before merging.

3992. By Stephan Kramer

Merging in trunk.

3993. By Stephan Kramer

Relax those tolerances a bit.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'femtools/Checkpoint.F90'
2--- femtools/Checkpoint.F90 2012-07-27 11:01:30 +0000
3+++ femtools/Checkpoint.F90 2013-06-12 14:29:25 +0000
4@@ -486,22 +486,35 @@
5 end if
6 end if
7
8+ ! Write out the mesh using a suitable coordinate field
9+ if (mesh%name=="CoordinateMesh") then
10+ if (have_option("/mesh_adaptivity/mesh_movement/free_surface")) then
11+ ! we don't want/need to checkpoint the moved mesh, as the mesh movement will again be applied after the restart
12+ ! based on the checkpointed FreeSurface field.
13+ position => extract_vector_field(state(1), "OriginalCoordinate", stat=stat1)
14+ if (stat1/=0) then
15+ ! some cases (e.g. flredecomp) OriginalCoordinate doesn't exist
16+ position => extract_vector_field(state(1), "Coordinate")
17+ end if
18+ else
19+ position => extract_vector_field(state(1), "Coordinate")
20+ end if
21+ else
22+ position => extract_vector_field(state(1), trim(mesh%name)//"Coordinate")
23+ end if
24+
25 if(get_active_nparts(ele_count(mesh)) > 1) then
26- ! Write out the mesh
27- if (mesh%name=="CoordinateMesh") then
28- position => extract_vector_field(state(1), "Coordinate")
29- else
30- position => extract_vector_field(state(1), trim(mesh%name)//"Coordinate")
31- end if
32 call write_mesh_files(parallel_filename(mesh_filename), mesh_format, position)
33 ! Write out the halos
34 ewrite(2, *) "Checkpointing halos"
35 call write_halos(mesh_filename, mesh)
36 else
37 ! Write out the mesh
38- call write_mesh_files(mesh_filename, mesh_format, state(1), mesh)
39+ call write_mesh_files(mesh_filename, mesh_format, position)
40 end if
41- end if
42+
43+ end if
44+
45 end do
46
47 end subroutine checkpoint_meshes
48@@ -534,7 +547,24 @@
49 assert(len_trim(prefix) > 0)
50
51 do i = 1, size(state)
52- positions => extract_vector_field(state(i), "Coordinate")
53+ if (have_option("/mesh_adaptivity/mesh_movement/free_surface")) then
54+ ! we don't want/need to checkpoint the moved mesh, as the mesh movement will again be applied after the restart
55+ ! based on the checkpointed FreeSurface field.
56+ positions => extract_vector_field(state(i), "OriginalCoordinate", stat=stat)
57+ if (stat/=0) then
58+ ! some cases (e.g. flredecomp) OriginalCoordinate doesn't exist
59+ positions => extract_vector_field(state(1), "Coordinate")
60+ end if
61+ else
62+ if (have_option("/mesh_adaptivity/mesh_movement")) then
63+ ! for other mesh movement schemes we should probably write out the "moved" mesh to retain that information
64+ ! However if the checkpointed mesh is not the "CoordinateMesh", it will have its own MeshNameCoordinate field
65+ ! that hasn't moved; leading to a failure to restart from the checkpoint. This is only one of the possible problems
66+ ! generally this functionality is untested.
67+ ewrite(0,*) "WARNING: using mesh_movement with checkpointing is untested and likely broken."
68+ end if
69+ positions => extract_vector_field(state(i), "Coordinate")
70+ end if
71 do j = 1, size(state(i)%meshes)
72 mesh => state(i)%meshes(j)%ptr
73 nparts = get_active_nparts(ele_count(mesh))
74
75=== modified file 'tests/spherical_patch/spherical_patch.xml'
76--- tests/spherical_patch/spherical_patch.xml 2012-07-24 16:34:10 +0000
77+++ tests/spherical_patch/spherical_patch.xml 2013-06-12 14:29:25 +0000
78@@ -11,16 +11,10 @@
79 <variables>
80 <variable name="volume_before" language="python">from fluidity_tools import stat_parser
81 stat=stat_parser('spherical_segment.stat')
82-# this only works because we don't move the free surface
83-# we actually compute H \int_top \eta, i.e. the volume difference with
84-# equilibrium state multiplied by depth H
85-volume_before=stat['Fields']['FreeSurface']['integral']</variable>
86+volume_before=stat['Fields']['Density']['integral']</variable>
87 <variable name="volume_after" language="python">from fluidity_tools import stat_parser
88 stat=stat_parser('spherical_segment_checkpoint.stat')
89-# this only works because we don't move the free surface
90-# we actually compute H \int_top \eta, i.e. the volume difference with
91-# equilibrium state multiplied by depth H
92-volume_after=stat['Fields']['FreeSurface']['integral']</variable>
93+volume_after=stat['Fields']['Density']['integral']</variable>
94 <variable name="solvers_converged" language="python">import os
95 files = os.listdir("./")
96 solvers_converged = not "matrixdump" in files and not "matrixdump.info" in files</variable>
97@@ -30,19 +24,33 @@
98 <variable name="max_velocity_after" language="python">from fluidity_tools import stat_parser
99 stat=stat_parser('spherical_segment_checkpoint.stat')
100 max_velocity_after=stat['Fields']['Velocity%magnitude']['max']</variable>
101+ <variable name="fs_integral_before" language="python">from fluidity_tools import stat_parser
102+stat=stat_parser('spherical_segment.stat')
103+fs_integral_before=stat['Fields']['FreeSurface']['surface_integral%Bottom']</variable>
104+ <variable name="fs_integral_after" language="python">from fluidity_tools import stat_parser
105+stat=stat_parser('spherical_segment_checkpoint.stat')
106+fs_integral_after=stat['Fields']['FreeSurface']['surface_integral%Bottom']</variable>
107 </variables>
108 <pass_tests>
109 <test name="volume_conservation_run1" language="python">from fluidity_tools import compare_variable
110-compare_variable(volume_before[0], volume_before[-1], 1e-5)</test>
111+compare_variable(volume_before[0], volume_before[-1], 1e-9)</test>
112 <test name="volume_conservation_run12" language="python">from fluidity_tools import compare_variable
113 # compares volume at the end of first run with that of end first timestep second run
114-compare_variable(volume_before[-1], volume_after[0], 1e-5)</test>
115+compare_variable(volume_before[-1], volume_after[0], 1e-9)</test>
116 <test name="volume_conservation_run2" language="python">from fluidity_tools import compare_variable
117-compare_variable(volume_after[0], volume_after[-1], 1e-5)</test>
118+compare_variable(volume_after[0], volume_after[-1], 1e-9)</test>
119 <test name="solvers_converged" language="python">assert solvers_converged</test>
120 <test name="max_velocity_run1" language="python"># make sure we're actually doing something and not blowing up
121 assert all(max_velocity_before&gt;0.01) and all(max_velocity_before&lt;0.02)</test>
122 <test name="max_velocity_run2" language="python"># make sure we're actually doing something and not blowing up
123 assert all(max_velocity_after&gt;0.01) and all(max_velocity_after&lt;0.02)</test>
124+ <test name="fs_integral_run1" language="python">from fluidity_tools import compare_variable
125+compare_variable(fs_integral_before[0], fs_integral_before[-1], 1e-5)</test>
126+ <test name="fs_integral_run2" language="python">from fluidity_tools import compare_variable
127+compare_variable(fs_integral_after[0], fs_integral_after[-1], 1e-5)</test>
128+ <test name="fs_integral_run12" language="python">from fluidity_tools import compare_variable
129+# compares freesurface integral at the end of first run with that of end first timestep second run
130+compare_variable(fs_integral_before[-1], fs_integral_after[0], 1e-5)
131+</test>
132 </pass_tests>
133 </testproblem>
134
135=== modified file 'tests/spherical_patch/spherical_segment.flml'
136--- tests/spherical_patch/spherical_segment.flml 2013-05-30 11:47:42 +0000
137+++ tests/spherical_patch/spherical_segment.flml 2013-06-12 14:29:25 +0000
138@@ -101,14 +101,14 @@
139 </mesh>
140 <quadrature>
141 <degree>
142- <integer_value rank="0">4</integer_value>
143+ <integer_value rank="0">6</integer_value>
144 </degree>
145 <surface_degree>
146- <integer_value rank="0">3</integer_value>
147+ <integer_value rank="0">6</integer_value>
148 </surface_degree>
149 </quadrature>
150 <spherical_earth>
151- <superparametric_mapping/>
152+ <linear_mapping/>
153 </spherical_earth>
154 <ocean_boundaries>
155 <top_surface_ids>
156@@ -366,7 +366,7 @@
157 <real_value rank="0">1.0e-8</real_value>
158 </relative_error>
159 <max_iterations>
160- <integer_value rank="0">10000</integer_value>
161+ <integer_value rank="0">1000</integer_value>
162 </max_iterations>
163 <never_ignore_solver_failures/>
164 <diagnostics>
165@@ -453,7 +453,13 @@
166 <algorithm name="Internal" material_phase_support="multiple"/>
167 <mesh name="PressureMesh"/>
168 <output/>
169- <stat/>
170+ <stat>
171+ <surface_integral type="value" name="Bottom">
172+ <surface_ids>
173+ <integer_value shape="1" rank="1">2</integer_value>
174+ </surface_ids>
175+ </surface_integral>
176+ </stat>
177 <convergence>
178 <include_in_convergence/>
179 </convergence>
180@@ -500,4 +506,30 @@
181 </diagnostic>
182 </scalar_field>
183 </material_phase>
184+ <mesh_adaptivity>
185+ <mesh_movement>
186+ <free_surface>
187+ <move_surface_nodes/>
188+ </free_surface>
189+ <vector_field name="GridVelocity" rank="1">
190+ <diagnostic>
191+ <algorithm name="Internal" material_phase_support="multiple"/>
192+ <mesh name="CoordinateMesh"/>
193+ <output/>
194+ <stat>
195+ <include_in_stat/>
196+ </stat>
197+ <convergence>
198+ <include_in_convergence/>
199+ </convergence>
200+ <detectors>
201+ <include_in_detectors/>
202+ </detectors>
203+ <steady_state>
204+ <include_in_steady_state/>
205+ </steady_state>
206+ </diagnostic>
207+ </vector_field>
208+ </mesh_movement>
209+ </mesh_adaptivity>
210 </fluidity_options>