DedalusProject / dedalus

A flexible framework for solving PDEs with modern spectral methods.
http://dedalus-project.org/
GNU General Public License v3.0
489 stars 115 forks source link

Add option to have evaluator not evaluate on first iteration #261

Open bpbrown opened 1 year ago

bpbrown commented 1 year ago

There are use cases (e.g., checkpointing) where it might be useful to have a particular handler in the evaluator system not evaluate on the first iteration. As a positive, this change would reduce startup time and disk usage. As a negative, this change would lose the automatic recording of the initial conditions (but would be user controlled and default to false)

Usage might go something like this:

checkpoints = solver.evaluator.add_file_handler('checkpoints', wall_dt=checkpoint_wall_dt, max_writes=1, skip_first_evaluation=True)

with a rough sketch of the implementation looking something like this:

class Handler:
<...>
    def __init__(self, dist, vars, group=None, wall_dt=None, sim_dt=None, iter=None, custom_schedule=None, skip_first_evaluation=None):
         <...>
         if skip_first_evaluation:
            self.last_wall_div = np.inf
            self.last_sim_div = np.inf
            self.last_iter_div = np.inf
        else:
            # Set initial divisors to be -1 to trigger output on first iteration
            self.last_wall_div = -1
            self.last_sim_div = -1
            self.last_iter_div = -1
kburns commented 1 year ago

I think the initial divisors should be 0 to skip the first evaluation?