NRL-Plasma-Physics-Division / turbopy

A lightweight computational physics framework, based on the organization of turboWAVE. Implements a "Simulation, PhysicsModule, ComputeTool, Diagnostic" class hierarchy.
https://turbopy.readthedocs.io/
Creative Commons Zero v1.0 Universal
10 stars 18 forks source link

Add incremental file writing to diagnostics.py #148

Closed AOstenfeld closed 4 years ago

AOstenfeld commented 4 years ago

Pull Request

Description

Adds ability to write data to the output files at given time intervals while the program is running.

This pull request addresses #145

Checklist

The following items have been checked for this PR:

AOstenfeld commented 4 years ago

Just for reference I've been testing this using the spring.py file in the block-on-spring repo. Add the "interval" keyword to the "Diagnostics" dictionary like so:

"Diagnostics": {

default values come first

        "directory": "output_leapfrog/",
        "output_type": "csv",
        "clock": {"filename": "time.csv"},
        "interval": 2,
        "BlockDiagnostic": [
            {'component': 'momentum', 'filename': 'block_p.csv'},
            {'component': 'position', 'filename': 'block_x.csv'}
        ]
    }
AOstenfeld commented 4 years ago

Alright, I think this is ready for review.

arichar6 commented 4 years ago

@AOstenfeld sorry to spring this on you, but I've made some changes in main that affect this PR.

I’ve created a new class, IntervalHandler, which lets you specify a function to call, and an interval at which to call it. This separates out the logic for checking the time step, and should make the code easier to write/maintain. As an example of how to use this class, you can look at my HistoryDiagnostic class.

For the issue that you are working on for this, I’d like to see you use the new IntervalHandler class to extend the HistoryDiagnostic class.

AOstenfeld commented 4 years ago

I'm moving this to another PR so that the diagnostics.py file is up to date.