From 47474bd7d756aa66589d8659c61a971f43b9f9d9 Mon Sep 17 00:00:00 2001 From: Greg Sjaardema Date: Wed, 19 Jun 2024 16:27:14 -0600 Subject: [PATCH] EXODUS: Add support for lossy compression via netCDF quantize method --- packages/seacas/libraries/exodus/include/exodusII.h | 12 +++++++----- .../seacas/libraries/exodus/include/exodusII_int.h | 2 ++ packages/seacas/libraries/exodus/src/ex_conv.c | 2 ++ packages/seacas/libraries/exodus/src/ex_utils.c | 5 +++++ 4 files changed, 16 insertions(+), 5 deletions(-) diff --git a/packages/seacas/libraries/exodus/include/exodusII.h b/packages/seacas/libraries/exodus/include/exodusII.h index dd545b5ec7..3a3efbb57a 100644 --- a/packages/seacas/libraries/exodus/include/exodusII.h +++ b/packages/seacas/libraries/exodus/include/exodusII.h @@ -55,12 +55,12 @@ #endif /* EXODUS version number */ -#define EXODUS_VERSION "9.00" +#define EXODUS_VERSION "9.01" #define EXODUS_VERSION_MAJOR 9 -#define EXODUS_VERSION_MINOR 0 +#define EXODUS_VERSION_MINOR 1 #define EXODUS_RELEASE_DATE "May 30, 2024" -#define EX_API_VERS 9.00f +#define EX_API_VERS 9.01f #define EX_API_VERS_NODOT (100 * EXODUS_VERSION_MAJOR + EXODUS_VERSION_MINOR) #define EX_VERS EX_API_VERS @@ -242,9 +242,11 @@ NetCDF-4.?.? and later enum ex_option_type { EX_OPT_MAX_NAME_LENGTH = 1, /**< Maximum length of names that will be returned/passed via api call. */ - EX_OPT_COMPRESSION_TYPE, /**< Not currently used; default is gzip */ - EX_OPT_COMPRESSION_LEVEL, /**< In the range [0..9]. A value of 0 indicates no compression */ + EX_OPT_COMPRESSION_TYPE, /**< Default is gzip */ + EX_OPT_COMPRESSION_LEVEL, /**< Range depends on compression type. */ EX_OPT_COMPRESSION_SHUFFLE, /**< 1 if enabled, 0 if disabled */ + EX_OPT_QUANTIZE_NSD, /**< if > 0, Number of significant digits to retain in lossy quantize + compression */ EX_OPT_INTEGER_SIZE_API, /**< 4 or 8 indicating byte size of integers used in api functions. */ EX_OPT_INTEGER_SIZE_DB, /**< Query only, returns 4 or 8 indicating byte size of integers stored on the database. */ diff --git a/packages/seacas/libraries/exodus/include/exodusII_int.h b/packages/seacas/libraries/exodus/include/exodusII_int.h index 8657fa6755..1ad552b07e 100644 --- a/packages/seacas/libraries/exodus/include/exodusII_int.h +++ b/packages/seacas/libraries/exodus/include/exodusII_int.h @@ -696,6 +696,8 @@ struct exi_file_item compression_algorithm : 2; /**< GZIP/ZLIB, SZIP, more may be supported by NetCDF soon */ unsigned int compression_level : 6; /**< 0 (disabled) to 9 (maximum) compression level for gzip, 4..32 and even for szip; NetCDF-4 only */ + unsigned int quantize_nsd : 4; /**< 0 (disabled) to 15 (maximum) number of significant digits + retained for lossy quanitzation compression */ unsigned int user_compute_wordsize : 1; /**< 0 for 4 byte or 1 for 8 byte reals */ unsigned int shuffle : 1; /**< 1 true, 0 false */ unsigned int diff --git a/packages/seacas/libraries/exodus/src/ex_conv.c b/packages/seacas/libraries/exodus/src/ex_conv.c index bbb545e9c3..404c0005e7 100644 --- a/packages/seacas/libraries/exodus/src/ex_conv.c +++ b/packages/seacas/libraries/exodus/src/ex_conv.c @@ -240,6 +240,7 @@ int exi_conv_init(int exoid, int *comp_wordsize, int *io_wordsize, int file_word new_file->assembly_count = 0; new_file->blob_count = 0; new_file->compression_level = 0; + new_file->quantize_nsd = 0; new_file->shuffle = 0; new_file->file_type = filetype - 1; new_file->is_parallel = is_parallel; @@ -454,6 +455,7 @@ int ex_set_option(int exoid, ex_option_type option, int option_value) file->compression_level = 0; } break; + case EX_OPT_QUANTIZE_NSD: file->quantize_nsd = option_value; break; case EX_OPT_COMPRESSION_SHUFFLE: /* 0 (disabled); 1 (enabled) */ file->shuffle = option_value != 0 ? 1 : 0; break; diff --git a/packages/seacas/libraries/exodus/src/ex_utils.c b/packages/seacas/libraries/exodus/src/ex_utils.c index e23c6007b1..84dd936327 100644 --- a/packages/seacas/libraries/exodus/src/ex_utils.c +++ b/packages/seacas/libraries/exodus/src/ex_utils.c @@ -1763,6 +1763,11 @@ void exi_compress_variable(int exoid, int varid, int type) ex_err_fn(exoid, __func__, errmsg, EX_BADPARAM); #endif } + + if (type == 2 && file->quantize_nsd > 0) { + // Lossy compression using netCDF quantize methods. + nc_def_var_quantize(exoid, varid, NC_QUANTIZE_GRANULARBR, file->quantize_nsd); + } } #if defined(PARALLEL_AWARE_EXODUS) if (file->is_parallel) {