pyrcel icon indicating copy to clipboard operation
pyrcel copied to clipboard

Extensible I/O module

Open darothen opened this issue 9 years ago • 0 comments

Proposing a user-extensible output module. The basic idea is that a user can pass either a set of default or derived-type classes which encapsulates how to record data to disk. For instance, suppose we have a default writer type

class OutputWriter(object):

    def __init__(self, output_filename):
        self.output_filename = output_filename

    def write_step(self, model_state)
    def finalize(self)

The __init__ and finalize methods take care of maintaining a reference to the output file. The write_step method would be what is called during model runtime. E.g., in a proposed model physics loop:

output_handler = OutputWriter("my_output.csv")

while t < t_end:
    model.step()
    if ( output_step ):
        output_handler.write_step(model.state)
    t += dt

Then any output handlers simply need to implement the interface. Ideally, the write_step file would incrementally add to a file.

darothen avatar Sep 08 '15 14:09 darothen