TDycores-Project / TDycore

BSD 2-Clause "Simplified" License
4 stars 0 forks source link

Replace "jagged array" allocations with proper C99 multidimensional arrays #234

Open jeff-cohere opened 2 years ago

jeff-cohere commented 2 years ago

In several places, we create arrays of arrays ("jagged arrays") to represent Fortran-90-style multidimensional arrays. For instance, the TDyAllocate_IntegerArray_* and TDyAllocate_RealArray_* functions in private/tdymemoryimpl.h create these jagged arrays.

This is not actually what we want. In Fortran 90, a multidimensional array is stored as a contiguous block of memory. The C language actually provides this capability as well (though it seems not to be widely known or understood, especially by the C++ crowd). PR #233 introduces a set of macros for declaring variables that represent multidimensional arrays whose storage is backed by contiguous blocks of memory.

With these macros, we should replace the calls to the "jagged array" functions above with block allocations, and declare multidimensional arrays wherever they need to be accessed as such. This will simplify our memory allocation interface and provide better performance in logic that manipulates multidimensional array data.

Files in which these jagged arrays appear:

./fv/mpfao/tdympfao.c
./fv/mpfao/tdympfao_steady.c
./fv/mpfao/tdympfao_utils.c
./fv/mpfao/tdyregion.c
./fv/fvtpf/tdyfvtpf.c
./fv/share/tdyugrid.c
./fv/share/tdymeshplex.c
./fv/share/tdymesh.c
./fv/share/tdymeshcustom.c
./tdyutils.c