firemodels / fds

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

Add Lower-precision, compressed volumetric output option #11212

Closed rjokonski closed 1 year ago

rjokonski commented 1 year ago

Problem/Opportunity

At Thunderhead, we currently use volumetric data from FDS (e.g. s3d, 3d slices, Plot3d) in a few different ways:

There are some downsides to the to the current volumetric output options for our uses, including the following:

The biggest downsides to us are either the lack of precision in s3d files or very large output files for Plot3D and 3D slices.

Request

We would like to request an alternate volumetric output that can provide the following:

Possible Solutions

I think there might be a few avenues to accomplish this request:

drjfloyd commented 1 year ago

I had developed at one point a two byte real output.

bit 1: flag for negative or positive bits 2-11: 0.000 to 1.000 bits 11-16: E-16 to E15

As an example:

-1,567
-0.157E4

bit 1: 1 (-) bits 2-10: 0010011101 (157) bits 11-16: 10100 (20 - 16 = 4) output: 10010011 10110100

This has an advantage over FP16 in that it gives a much larger real range (FP16 is 2^-14 to 2^15). E-16 should cover anything small that we care about and E+15 should cover anything large that we care about. For the purpose of doing FED calcs or coloring contours, three digits of precision should be good enough.

drjfloyd commented 1 year ago

Be a function like this for the conversion from real to two bytes

INTGER(2), FUNCTION TWO_BYTE_REAL(REAL_IN)
REAL(EB), INTENT(IN) :: REAL_IN
INTEGER:: EXP, TEMP

EXP = MAX(-16_2,MIN(15_2,INT(FLOOR(LOG10(ABS(REAL_IN))),2)))
TEMP = MIN(1000,INT(ABS(REAL_IN*10._EB**(-REAL(EXP+1,EB)+4)),2))
TWO_BYTE_REAL = TEMP*2**5+ EXP + 16
IF (REAL_IN <0._EB) TWO_BTYE_REAL = IBSET(TWO_BYTE_REAL,15)

END FUNCTION TWO_BYTE_REAL
rjokonski commented 1 year ago

I had forgotten about that fairly big range limitation with FP16. I'm certainly open to other formats, such as Jason's two-byte format. I think the normalized integer format could also be a viable option, especially if the data is normalized over the range of the data set for a single frame.

drjfloyd commented 1 year ago

two-byte integer normalized over the range would be pretty good resolution for most quantities. With temperature that would mean 0.02 K with a peak 1200 C. For velocity 4 mm/s for -100 to 100 m/s. CO would be 2 ppm with 2 step-chemistry where the peak could be near 10 %.

mcgratta commented 1 year ago

The smoke3d output is still very specific to visualizing smoke and fire. If you look in smvv.f90, around line 924, you'll see three formats for GAS, FIRE and TEMPERATURE. GAS is aimed at obscuration. For a GAS, the entry in the .smv file is

SMOKF3D     2   8700.000
 Case_old_2_1.s3d
 SOOT DENSITY
 rho_C0.9H0.1
 kg/m3

You see there the 8700 m2/kg with which one could back out the original SOOT DENSITY in kg/m3. That is, the 1 byte integers are 254(1-exp(-8700dx*rho_soot)). TEMPERATURE and FIRE are handled differently.

gforney commented 1 year ago

If anyone wants to play around with something, I've added output for 3d smoke quantities higher in resolution than what we've output earlier but lower than full fledged floating point. fds (in nightly bundles) now outputs .v3d files of 16 bit integers for various 3d smoke values if you put VOL3D=.TRUE. on the &MISC line. Each 16 bit integer VAL16 is computed using VAL16 = (2*16-1)(VAL-VALMIN)/(VALMAX-VALMIN) where VALMIN and VALMAX are the min nad max values for the time frame being output.

For now these files are uncompressed. The header is one record containing INTEGER_ONE,VOL3D_VERSION,VOL3D_COMPRESS,IBP1,JBP1,KBP1 where INTEGER_ONE is the integer 1, VOL3D_VERSION is the file format version, VOL3D_COMPRESS is a flag indicating whether file is compressed , IBP1, JPB1, KPB1 are the node dimensions of the mesh where the data is taken from

Each time frame contains 3 records TIME NVALS,NVALS16_OUT,VOL3D_VALMIN,VOL3D_VALMAX (BUFFER(I),I=1,NVALS)

NVALS is number of 16 bit integers before compression, just IBP1JBP1JBP1, NVALS16_OUT is the number of data values output currently the same as NVALS since there is no compression, VOL3D_VALMIN and VOL3D_VALMAX are the smallest and largest data values in the mesh for that time frame.

I'm looking at compressing these values

mcgratta commented 1 year ago

Is this in the FDS User's Guide?

gforney commented 1 year ago

not yet. give me a few days. think I can get compression figured out in that time.

On Tue, Dec 13, 2022 at 2:32 PM Kevin McGrattan @.***> wrote:

Is this in the FDS User's Guide?

— Reply to this email directly, view it on GitHub https://github.com/firemodels/fds/issues/11212#issuecomment-1349586370, or unsubscribe https://github.com/notifications/unsubscribe-auth/AC6UCRSKRMXQFLKKMBN4HSDWNDFN3ANCNFSM6AAAAAASZUQL2Q . You are receiving this because you were assigned.Message ID: @.***>

-- Glenn Forney

mcgratta commented 1 year ago

Wouldn't compression work the same way as for 8 bit?

drjfloyd commented 1 year ago

RLE won't be nearly as effiicent with 16 bit. Were you thinking of another method?

gforney commented 1 year ago

was going to call a comporession library much the same way that we call routines in the MKL library now using fortran bindings. RLE won't work well for 16 bit data because it is unlikely that two adjacent 16 values will be the same. I will do this in my own branch. then you all call can decide whether you want me to merge my changes.

On Tue, Dec 13, 2022 at 2:42 PM Jason Floyd @.***> wrote:

RLE won't be nearly as effiicent with 16 bit. Were you thinking of another method?

— Reply to this email directly, view it on GitHub https://github.com/firemodels/fds/issues/11212#issuecomment-1349595198, or unsubscribe https://github.com/notifications/unsubscribe-auth/AC6UCRSGMPCMYLUW6E4IBYLWNDGRHANCNFSM6AAAAAASZUQL2Q . You are receiving this because you were assigned.Message ID: @.***>

-- Glenn Forney

mcgratta commented 1 year ago

If that's the case, wouldn't any other compression algorithm be somewhat lossy, and do we want that?

gforney commented 1 year ago

I was going to use the same compression library used by smokeview, zlib. It is lossless. zlib is also used to compress images in png files. There are fortran bindings for it.

On Tue, Dec 13, 2022 at 2:51 PM Kevin McGrattan @.***> wrote:

If that's the case, wouldn't any other compression algorithm be somewhat lossy, and do we want that?

— Reply to this email directly, view it on GitHub https://github.com/firemodels/fds/issues/11212#issuecomment-1349604113, or unsubscribe https://github.com/notifications/unsubscribe-auth/AC6UCRTYWLDPGBQGNULD36DWNDHVPANCNFSM6AAAAAASZUQL2Q . You are receiving this because you were assigned.Message ID: @.***>

-- Glenn Forney

mcgratta commented 1 year ago

Do we have the source code for it, or do we have to link to binaries. I'm not a fan of the latter. Slippery slop to a point where we cannot compile the code anymore.

gforney commented 1 year ago

yes we have the source code. zlib is one of the libraries I build when building smokeview.

On Tue, Dec 13, 2022 at 3:20 PM Kevin McGrattan @.***> wrote:

Do we have the source code for it, or do we have to link to binaries. I'm not a fan of the latter. Slippery slop to a point where we cannot compile the code anymore.

— Reply to this email directly, view it on GitHub https://github.com/firemodels/fds/issues/11212#issuecomment-1349635257, or unsubscribe https://github.com/notifications/unsubscribe-auth/AC6UCRRCDTGSE2LXEEK4DUTWNDLCBANCNFSM6AAAAAASZUQL2Q . You are receiving this because you were assigned.Message ID: @.***>

-- Glenn Forney

mcgratta commented 1 year ago

Mixed C and Fortran? If we can write a simple Fortran routine to do what we need, that would be better. No end of headaches when we start mixing languages.

gforney commented 1 year ago

if there is any interest you can reopen the issue

rjokonski commented 1 year ago

I finally got around to testing this feature. I'm sorry it took so long. I really appreciate how responsive you were when I first opened the case - it actually took me by surprise, but I was bogged down with other projects at the time.

I would like to request a few additions/changes to the feature as it went out in 6.8.0. Should I post them here or in a new issue? If the latter, would it be better to lump them into one issue or each separate?

gforney commented 1 year ago

You can put them here

On Wed, May 3, 2023, 6:03 PM rjokonski @.***> wrote:

I finally got around to testing this feature. I'm sorry it took so long. I really appreciate how responsive you were when I first opened the case - it actually took me by surprise, but I was bogged down with other projects at the time.

I would like to request a few additions/changes to the feature as it went out in 6.8.0. Should I post them here or in a new issue? If the latter, would it be better to lump them into one issue or each separate?

— Reply to this email directly, view it on GitHub https://github.com/firemodels/fds/issues/11212#issuecomment-1533810426, or unsubscribe https://github.com/notifications/unsubscribe-auth/AC6UCRVDHWDJSLLRXHDBOVDXELI2FANCNFSM6AAAAAASZUQL2Q . You are receiving this because you modified the open/close state.Message ID: @.***>

rjokonski commented 1 year ago

Thanks. Here are my requests:

Thanks again for the rapid responses!

rjokonski commented 7 months ago

Hello,

@gforney I was wondering if you ever had a chance to revisit this or think about how the above could be accomplished. Even if we could get the top 3 bullets done, I think that would be a big win for us.

Thanks!

gforney commented 7 months ago

This fell through the cracks so to speak. Ill look at this again