[Mesa-users] Variable array sizes in s%

Farag, Ebraheem ebraheem.farag at yale.edu
Mon Sep 14 05:55:01 UTC 2026


Hello Mathijs,

MESA carries two alternating sets (buffers) of star pointer arrays, one buffer for the old mesh, and one buffer for the new mesh. In one timestep, extras_start_step is called before the model is remeshed, hence it uses a different buffer than the one called in extras_check_model. The buffers alternate every step, since the solution to the current step becomes the buffer for the pre-remeshed model at the start of the next timestep. Because the buffers in your example happen to differ in length by 2, you are likely observing the total size of the array for e.g. s% m to alternate because the model is switching between each buffer each timestep (where remesh is called). you are accessing a different array of memory with slightly different total size.

Here is an example of what happens when the buffers are fixed in size and differ in length by two:
-------------------------------------------------------------
size(s% m_Buffer1)  = N
Size(s% m_Buffer2) = N+2

s% m => (Buffer1)
extras_start_step : size(s%m) = N
    remesh: s%m => (Buffer2)
     extras_check_model: size(s%m) = N+2
...
extras_start_step : size(s%m) = N+2
    remesh: s%m => (Buffer1)
     extras_check_model: size(s%m) = N
-------------------------------------------------------------

This is a difference in the spare capacity of the array, not a difference in s% nz. The size between the buffers can vary, but this does not matter because s% nz remains a subset of the total array size. When remeshing asks the model to extend an array it extends to:

max(s%prev_mesh_nz, s%nz) + 200

The arrays in each buffer grow asynchronously since they are grown on different timesteps, when a remesh is asked for, and when the requested number of zones exceeds the size of the current buffer's star pointer arrays. Once each buffer's star pointer arrays grow, they do not get smaller. The buffer is grown in a way which attempts to minimize the number of times the star pointer arrays need to be resized/reallocated in memory.

-EbF
________________________________
From: Mesa-users <mesa-users-bounces at lists.mesastar.org> on behalf of Mathijs Vanrespaille via Mesa-users <mesa-users at lists.mesastar.org>
Sent: Monday, September 7, 2026 3:51 PM
To: mesa-users <mesa-users at lists.mesastar.org>
Subject: [Mesa-users] Variable array sizes in s%

Dear MESA users and devs,

I have a question about the array sizes in MESA version 26.4.1. I noticed that the size of the arrays in s%, e.g. s% m changes between extras_start_step and extras_check_model even though the number of zones in s% nz remains unchanged in a rotating model based on the conserve_angular_momentum test case. Specifically, the sizes of the s% arrays alternate between increase by +2 in one step and decreasing by -2 again in the next step. Attached is a basic work directory that prints s% nz and size(s% m) at different stages of each time step to demonstrate this behaviour.
I thought the size of these arrays was meant to be mostly constant to avoid paying the computational cost of de-allocating and re-allocating them, hence why they are also initialised to be larger than s% nz. Is this variable size of the arrays in s% expected and/or desirable? If so, what is its purpose? If not, does anyone have any guesses what may cause it? I took a look in $MESA_DIR/star/private/alloc.f90 and $MESA_DIR/star/private/adjust_mesh.f90, but I didn't spot any obvious clues.

Kind regards,
Mathijs Vanrespaille
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.mesastar.org/pipermail/mesa-users/attachments/20260914/3383ab61/attachment.htm>


More information about the Mesa-users mailing list