boutproject / BOUT-dev

BOUT++: Plasma fluid finite-difference simulation code in curvilinear coordinate systems
http://boutproject.github.io/
GNU Lesser General Public License v3.0
186 stars 95 forks source link

Running multiple simulations #2355

Open dschwoerer opened 3 years ago

dschwoerer commented 3 years ago

For the python interface it would be nice to run several simulations without having to restart python.

Here is an example to make it work (I think it needs the commit there after to actually work): https://github.com/boutproject/BOUT-dev/commit/fbfcc97288c4a5db1e4ccdb8ac28c4fcf3c06f8a#diff-4202680501c860c316f1061108da6395bc829d3b3151bc48a5f5b4a54adc800bR29

I have been wondering, should the creation of dump files be moved to the models. The only case where we do not want this, if two models are co-evolved, but the outputs should end up in the same file.

Thus maybe having additional options for the model, to pass in existing instances of mesh, options, dumpfile, solver ... would be the cleanest approach?

ZedThree commented 3 years ago

2209 moves the output file ownership to the physics model, and also adds functionality to make it easier to write a Python dict to a BOUT++ dump file from the Python interface. Rather than having a global instance, #2209 adds helper functions for writing an Options to an output file (including one for the main BOUT.dmp.*.nc) that can be called from anywhere.

That PR also makes all writes to the dump files open-close so having two models write to the same file shouldn't be a problem provided a) none of the fields have the same name, and b) they are evolved on the same time dimension.

A slight issue with passing instances of the various globals/pseudo-globals into PhysicsModel is that we'd really need to have a constructor on the user's derived class -- this only needs one line that can be copy-pasted in, but it would need to be present in all models. It might be possible to do some complex template magic to overload a creation function depending on whether or not the constructor is present, but it's probably best not to do that.