firemodels / fds

Fire Dynamics Simulator
https://pages.nist.gov/fds-smv/
Other
642 stars 614 forks source link

Exchange information with FDS through structured data file in simulation output directory. #11615

Open bwklein opened 1 year ago

bwklein commented 1 year ago

I know you are busy with FDS 7 development now, and this isn't an urgent feature request, but I wanted to document some ideas that have come from past discussions with Kevin, and some interested users of FDS.

The high-level concept is to provide a way to pass information into and out of FDS through a text file that can be updated manually or by tools external to FDS and then be read/used by FDS to set variables and states as more dynamic input to the simulator.

The file format should be something easy to read by people, but even easier for programmatic updates. I can imagine it working well in a format the provides key/value pairs at a minimum, with a potential for more complex data structures as needed. One very common/popular format would be JSON, but I can imagine other formats working as well. I could see something as simple as CSV working too, but it would require more repetitive data in columns for more complex data types.

FDS would look for this file in the run directory and if it exists, parse it to initialize these variables in memory. During the run this file would be read for updates to the data values and if they are changed in the file, the changes would be reflected in FDS. If something in FDS changes what those values should be, then it writes the updated values to the file.

External tools could also be monitoring the file and performing the same kind of read/write updates to values.

Through this mechanism, an external tool could provide information to FDS to change the simulated state and likewise use updated information in the file to change the external application state.

Through this bidirectional coupling the FDS simulation can be updated dynamically.

Here are a couple of example use cases where this could be useful.

I am sure many other examples can be developed. Overall, making this as generic as possible would be flexible and should accommodate any number of use cases.

drjfloyd commented 1 year ago

I have done something like this before in development of FSSIM. There isn't a generic way in Fortran to read in an input file and have it change an arbirtrary source variable. Each source variable you want to change requires its own development effort. Even with something like json. We could use some existing git fortran project for reading a json file, but the parsing of that file into changing FDS variables means code is needed for every variable in FDS that gets changed.

Easiest would be things we can tie to existing control function capability or ramps:

Any new output also requires development effort and long term maintenance effort. We already write a number output files with QUANTITY choices that cover pretty much everthing FDS computes. Is a new output file really needed? For example, if a sprinkler hydraulic tool needs to know what heads have operated, it can just look at the existing devc_ctrl_log file. For a particle representing an agent, we can get data for that particle's exposure via the normal devc.csv file (Though here I think we'd need to add logic so that we use the particle X,Y,Z to set the IJK for the device. I don't think we do that now).

drjfloyd commented 1 year ago

Partial edit of above: For a DEVC using INIT_ID to refer to a particle, we do pass in the I,J,K of the particle (line 6105 of dump.f90).

bwklein commented 1 year ago

@drjfloyd The idea of tying into the existing CTRL and RAMP functions with and EXTERNAL connection is great. I also agree that for outputs from FDS we could easily monitor the output files.

The one issue is that there would be some lag time between the timestep that the action occurred, and when the output file is eventually updated. We would need to set the DUMP frequency high enough to capture that event as close as possible to when it happens in the simulation, or maybe have some kind of event-based DUMP option that updates the file when the event happens instead of at some regular interval.

drjfloyd commented 1 year ago

NFRAMES defaults to 1000. I think in most cases where you have 1000 frames and outputs every few seconds, that monitoring of the normal ouput intervals is going to be suffiicent. I'd say lets first get this working, then worry about edge cases if it turns out they exist in practice and we see what the needs are.

drjfloyd commented 1 year ago

I just pushed up a first crack at this. Attached is an example input file and update file which will become the example case for the User's Guide.

As you can see in the input file I have added: EXTERNAL_FILENAME to MISC. This is the name of a csv file containing changes. DT_EXTERNAL to TIME. This defines how often FDS looks for updates (since file reads take time). The default is 0. When doing a read if FDS cannot read the file (doesn't exist yet or it is locked by another process), then it will keep using the current values and try again the next time step. The FUNCTION_TYPE of EXTERNAL to CTRL. The function will start with the INITIAL_STATE and after that the state is defined by the external csv file The flag EXTERNAL_FILE to RAMP and the real INITIAL_VALUE. The RAMP will start with INITIAL_VALUE and after than the value is defeined by the csv file

The csv file format is type, ID, value where type is RAMP or CTRL ID is the RAMP or CTRL ID that is being controlled. If the ID has a space or , in it, make sure to enclose it in "". Value is a real number that is either used directly as the RAMP output value or sets the CTRL T when > 0 and F when < 0. You do not have to define all externally controlled parameters in the file at each update. Only those you wish to change. Anything not specified will keep using the old value.

The example file has one VENT with a VEL that starts as true and is deactivated a 5 s with the external file and one VENT with a TMP_FRONT that starts at a RAMP of 0.1 and goes to 1 at 5 s.

If the input names and locations seem good, I'll make doc changes and add the test case.

external_test.txt external_test_input.csv

drjfloyd commented 1 year ago

Added the inputs in my prior post to the User's Guide and added the test case. In a new section at the end of the Devices and Control Logic chapter.