Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

_set_timestep and get_timesteps for in CheckpointFile #3310

Merged
merged 28 commits into from
Jan 31, 2024
Merged
Changes from 1 commit
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
24f5ff2
adding set_timestep and get_timestep for checkpointing
sghelichkhani Jan 8, 2024
fb287d6
Apply suggestions from code review
sghelichkhani Jan 10, 2024
28a2175
Adding timestep, changing timetag to timestamp
sghelichkhani Jan 10, 2024
f826bdd
Fixing the issues from review, handling mixed functions, adding a tes…
sghelichkhani Jan 11, 2024
8ffcd6b
Merge branch 'firedrakeproject:master' into checkpointint-with-time
sghelichkhani Jan 11, 2024
fc56bdc
Apply suggestions from code review
sghelichkhani Jan 15, 2024
51602df
Correcting Doc string
sghelichkhani Jan 15, 2024
1035e31
Hard coding timestamps and timesteps in tests
sghelichkhani Jan 15, 2024
4344789
Definiting CheckpointFile.DEFAULT_REAL
sghelichkhani Jan 16, 2024
9d27108
Merge branch 'firedrakeproject:master' into checkpointint-with-time
sghelichkhani Jan 16, 2024
6d98410
Setting default value to -1.0
sghelichkhani Jan 16, 2024
1c58b1c
Apply suggestions from code review
sghelichkhani Jan 16, 2024
89c44a6
Changing the test to RT
sghelichkhani Jan 16, 2024
bb50d3b
Setting indices before popTimestepping
sghelichkhani Jan 16, 2024
8b3382f
Apply suggestions from code review
sghelichkhani Jan 25, 2024
39c32df
generalising how we provide timestepping_info and maintaining consist…
sghelichkhani Jan 26, 2024
c8e1e29
Merge branch 'checkpointint-with-time' of github.com:sghelichkhani/fi…
sghelichkhani Jan 26, 2024
1576b1f
Fixing linting
sghelichkhani Jan 26, 2024
eaf88eb
Apply suggestions from code review
sghelichkhani Jan 26, 2024
f459dbc
fixing a few issues
sghelichkhani Jan 26, 2024
0110679
Merge branch 'firedrakeproject:master' into checkpointint-with-time
sghelichkhani Jan 27, 2024
9e325c6
Apply suggestions from code review
sghelichkhani Jan 27, 2024
6dbc724
Adding functions for function timestepping paths
sghelichkhani Jan 27, 2024
d17aa3a
Merge branch 'firedrakeproject:master' into checkpointint-with-time
sghelichkhani Jan 30, 2024
20054b4
Update firedrake/checkpointing.py
ksagiyam Jan 31, 2024
baa2b22
Update firedrake/checkpointing.py
ksagiyam Jan 31, 2024
8429aac
Update firedrake/checkpointing.py
ksagiyam Jan 31, 2024
31360d1
typo in docstring.
dham Jan 31, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 45 additions & 1 deletion firedrake/checkpointing.py
Original file line number Diff line number Diff line change
Expand Up @@ -716,6 +716,41 @@ def _save_mesh_topology(self, tmesh):
perm_is.setName(None)
self.viewer.popGroup()

@PETSc.Log.EventDecorator("SetTimstep")
sghelichkhani marked this conversation as resolved.
Show resolved Hide resolved
def _set_timestep(self, mesh, name, idx, time):
# follow the general path rule for storing a function
tmesh_name = self._get_mesh_name_topology_name_map()[mesh.name]
V_name = self._get_function_name_function_space_name_map(tmesh_name, mesh.name)[name]
path = self._path_to_function(tmesh_name, mesh.name, V_name, name)
# check if the function's path has the attribute
if self.has_attr("/"+path if path else "", "stored_time_steps"):
# collect previous indices and timesteps and add the current timestep path to it
old_indices, old_times = self.get_timesteps(mesh, name)
times = np.concatenate((old_times, [time]))
indices = np.concatenate((old_indices, [len(old_indices) if idx is None else idx]))
else:
# initiate timestepping, assuming the saving the function has succeeded
indices = [0 if idx is None else idx]
times = [time]
# store all timesteps and indices
self.set_attr("/"+path if path else "", "stored_time_indices", indices)
self.set_attr("/"+path if path else "", "stored_time_steps", times)
sghelichkhani marked this conversation as resolved.
Show resolved Hide resolved

@PETSc.Log.EventDecorator("GetTimsteps")
sghelichkhani marked this conversation as resolved.
Show resolved Hide resolved
def get_timesteps(self, mesh, name):
sghelichkhani marked this conversation as resolved.
Show resolved Hide resolved
# follow the general path rule for storing a function
tmesh_name = self._get_mesh_name_topology_name_map()[mesh.name]
V_name = self._get_function_name_function_space_name_map(tmesh_name, mesh.name)[name]
path = self._path_to_function(tmesh_name, mesh.name, V_name, name)
# check if timesteps exists for the given name and return them
if self.has_attr("/"+path, "stored_time_steps"):
return (
self.get_attr("/"+path, "stored_time_indices"),
self.get_attr("/"+path, "stored_time_steps"),
)
else:
return [], []

@PETSc.Log.EventDecorator("SaveFunctionSpace")
def _save_function_space(self, V):
mesh = V.mesh()
Expand Down Expand Up @@ -779,7 +814,7 @@ def _save_function_space_topology(self, tV):
topology_dm.setName(base_tmesh_name)

@PETSc.Log.EventDecorator("SaveFunction")
def save_function(self, f, idx=None, name=None):
def save_function(self, f, idx=None, name=None, timetag=None):
sghelichkhani marked this conversation as resolved.
Show resolved Hide resolved
r"""Save a :class:`~.Function`.

:arg f: the :class:`~.Function` to save.
Expand All @@ -792,6 +827,15 @@ def save_function(self, f, idx=None, name=None):
"""
V = f.function_space()
mesh = V.mesh()
if timetag:
sghelichkhani marked this conversation as resolved.
Show resolved Hide resolved
ret = self.save_function(f, idx=idx, name=name)
sghelichkhani marked this conversation as resolved.
Show resolved Hide resolved
self._set_timestep(
mesh=mesh,
name=name if name else f.name(),
idx=idx,
time=timetag,
)
return ret
if name:
g = Function(V, val=f.dat, name=name)
return self.save_function(g, idx=idx)
Expand Down