From 12f256bc74792a1cf052b2989e0c20a4c2d38346 Mon Sep 17 00:00:00 2001 From: Maxwell-Rosen Date: Mon, 22 Jun 2026 16:17:14 -0700 Subject: [PATCH 1/2] Refactor mpack map creation to handle duplicate keys and ensure unique entries --- core/zero/util.c | 90 +++++++++++++++++++++++++++++------------------- 1 file changed, 55 insertions(+), 35 deletions(-) diff --git a/core/zero/util.c b/core/zero/util.c index 2bcc40cf02..4b67f666c7 100644 --- a/core/zero/util.c +++ b/core/zero/util.c @@ -514,45 +514,65 @@ gkyl_msgpack_create_union(int numlist_union, int *nvals_union, const struct gkyl mpack_writer_t writer; mpack_writer_init_growable(&writer, &mdata->meta, &mdata->meta_sz); - mpack_build_map(&writer); + // Flatten the union of lists so we can detect duplicate keys. MessagePack + // maps must have unique keys; a map with duplicates is rejected by the + // reader (mpack_error_data), which would silently corrupt every lookup. + int nvals_tot = 0; + for (int j=0; jkey, flat[m]->key) == 0) { + overridden = true; + break; + } + } + if (overridden) + continue; - int nvals = nvals_union[j]; - const struct gkyl_msgpack_map_elem *elist = elist_union[j]; + const struct gkyl_msgpack_map_elem *elem = flat[k]; + mpack_write_cstr(&writer, elem->key); - for (int i=0; ielem_type) { + case GKYL_MP_BOOL: + mpack_write_bool(&writer, elem->bval); + break; - default: - assert(false); // NYI. - break; - } + case GKYL_MP_UNSIGNED_INT: + mpack_write_u64(&writer, elem->uval); + break; + + case GKYL_MP_INT: + mpack_write_i64(&writer, elem->ival); + break; + + case GKYL_MP_FLOAT: + mpack_write_float(&writer, elem->fval); + break; + + case GKYL_MP_DOUBLE: + mpack_write_double(&writer, elem->dval); + break; + + case GKYL_MP_STRING: + mpack_write_cstr(&writer, elem->cval); + break; + + default: + assert(false); // NYI. + break; } } From 235c1c88d870a87ca66976b3e4944d889e8e1154 Mon Sep 17 00:00:00 2001 From: Maxwell-Rosen Date: Mon, 22 Jun 2026 16:22:35 -0700 Subject: [PATCH 2/2] Update jacobtot_inv_file_name in initialization from file for consistency --- core/zero/util.c | 5 ----- gyrokinetic/creg/rt_gk_wham_1xIC_2x2v_p1.c | 4 ++-- 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/core/zero/util.c b/core/zero/util.c index 4b67f666c7..07806aed6a 100644 --- a/core/zero/util.c +++ b/core/zero/util.c @@ -514,9 +514,6 @@ gkyl_msgpack_create_union(int numlist_union, int *nvals_union, const struct gkyl mpack_writer_t writer; mpack_writer_init_growable(&writer, &mdata->meta, &mdata->meta_sz); - // Flatten the union of lists so we can detect duplicate keys. MessagePack - // maps must have unique keys; a map with duplicates is rejected by the - // reader (mpack_error_data), which would silently corrupt every lookup. int nvals_tot = 0; for (int j=0; jkey, flat[m]->key) == 0) { diff --git a/gyrokinetic/creg/rt_gk_wham_1xIC_2x2v_p1.c b/gyrokinetic/creg/rt_gk_wham_1xIC_2x2v_p1.c index 253cc7887f..43ca8cf397 100644 --- a/gyrokinetic/creg/rt_gk_wham_1xIC_2x2v_p1.c +++ b/gyrokinetic/creg/rt_gk_wham_1xIC_2x2v_p1.c @@ -819,7 +819,7 @@ int main(int argc, char **argv) .init_from_file = { .type = GKYL_IC_IMPORT_F, .file_name = "gk_wham_1x2v_p1-elc_0.gkyl", - // .jacobtot_inv_file_name = "gk_wham_1x2v_p1-jacobtot_inv.gkyl", + .jacobtot_inv_file_name = "gk_wham_1x2v_p1-geo_int_jacobtot_inv.gkyl", }, .mapc2p = { @@ -887,7 +887,7 @@ int main(int argc, char **argv) .init_from_file = { .type = GKYL_IC_IMPORT_F, .file_name = "gk_wham_1x2v_p1-ion_0.gkyl", - .jacobtot_inv_file_name = "gk_wham_1x2v_p1-jacobtot_inv.gkyl", + .jacobtot_inv_file_name = "gk_wham_1x2v_p1-geo_int_jacobtot_inv.gkyl", }, .scale_with_polarization = true,