CAFE-AMR: A computational MHD Solar Physics simulation tool that uses AMR
Abstract
The study of our Sun holds significant importance in Space Weather research, encompassing a diverse range of phenomena characterized by distinct temporal and spatial scales. To address these complexities, we developed CAFE-AMR, an implementation of an Adaptive Mesh Refinement (AMR) strategy coupled with a Magnetohydrodynamics (MHD) equation solver, aiming to tackle Solar Physics-related problems. CAFE-AMR employs standard fluid dynamics methods, including Finite Volume discretization, HLL and Roe class flux formulas, linear order reconstructors, second-order Runge-Kutta, and Corner Transport Upwind time stepping. In this paper, we present the core structure of CAFE-AMR, discuss and evaluate mesh refinement criteria strategies, and conduct various tests, including simulations of idealized Solar Wind models, relevant for Space Weather applications.
keywords:
methods: numerical – MHD – Sun: general1 Introduction.
Solar physics has been developed in a constant direction: much of our Sun’s present observed structure and dynamic behavior owe their existence to the magnetic field. In every shell that constitutes the solar atmosphere, being either the photosphere, the chromosphere, the corona, or the heliosphere, there are many endearing and involving questions relating the Sun’s plasma to the magnetic field.
Magnetohydrodynamics (MHD) describes fairly well several of these magnetic field dynamics features. Fortunately both, analytical and numerical advances in our understanding and use of these equations have been made. Moreover, advances regarding the improvement of the usage of computational resources while running simulations based on these equations have been equally important.
A significant breakthrough on Fluid Dynamics simulations, was made a while ago by the implementation of Adaptive Mesh Refinement (AMR) technique, presented in the well known (Berger & Oliger, 1984) and (Berger & Colella, 1989), where it was used in conjunction with the numerical shock capturing solutions of the Euler hydrodynamic equations. AMR is an approach to optimize the efficient use of resources in the solution of initial value problems involving the solution of fluid dynamics; it can be summarized as the use of more resolution, spatial or temporal, only where more structure of the functions involved in the problem demand more accuracy. Physically, AMR is a powerful tool to adequately evolve a fluid when great disparities in the spatial and temporal scales occur simultaneously, when the flow dynamics have very localized features.
A number of codes that employ the AMR strategy for solving MHD equations are available within the scientific community. Some examples are the following: MPI-AMRVAC (Porth et al., 2014): This code is specifically designed to solve MHD and Hall MHD equations, it utilizes finite volume or finite difference methods and can also handle the evolution of dust coupled with a hydrodynamic fluid. A second (Xia et al., 2018) and third (Keppens, R. et al., 2023) versions of this code have been developed; PLUTO (Mignone et al., 2007): which has been used mainly in astrophysical simulations and has gained attraction in the field of solar physics in recent years; FLASH(Fryxell et al., 2000): A widely used astrophysical code; AstroBEAR (Cunningham et al., 2009); RAMSES (Teyssier, 2002); NIRVANA (Ziegler, 2008); ATHENA(Stone et al., 2008); ENZO (Bryan et al., 2014) and BATS-R-US (Tóth et al., 2012) are codes known for their high-performance computing orientation and have been extensively used in various scientific disciplines, including astrophysics and MHD simulations. Some of these codes rely on specialized libraries such as PARAMESH (MacNeice et al., 2000) and CHOMBO (LBNL, 2019), which provide parallelized AMR drivers that can be adapted to solve initial value problems as needed. In the realm of solar physics simulation, noteworthy codes include AMR-CESE-MHD (Feng et al., 2012), ICARUS (Verbeke, C. et al., 2022), which support non cartesian grids, and SFUMATO (Matsumoto et al., 2019), all of which have been successfully used in solar wind simulations.
The AMR strategy, when integrated with parallelization schemes, significantly enhances computational efficiency. State-of-the-art computing systems often adopt a combination of technologies. For example OpenMP-MPI, as demonstrated in the BHAC GR-MHD code (Cielo et al., 2022). Also, the growing adoption of GPUs is expected to further amplify the processing power for handling vast data sets generated by computer simulations. A notable example of this trend is the H-AMR code (Liska et al., 2022).
Even though most of these codes are open source, the complexity of their modular structure might render them inaccessible. As an alternative, developing an original code based on standard numerical schemes, allows one to have an independent tool that serves as a theoretical laboratory that on the one hand helps to confirm results obtained with other codes, and on the other serves to implement the solution of new problems that would be hard to define on top of already existing codes that, due to their degree of sophistication prevent easy soft adjustments. Accessibility and control are an important motivation to build a code.
In this work we present a code, constructed from scratch, that solves the equations of the MHD using AMR based on the methods for the solution of the equations developed for the unigrid original version of CAFE (Lora-Clavijo et al., 2015; González-Avilés et al., 2015). This code is expected to join those others that are in production for Solar and Space Weather Physics. The paper structure is as follows. In section 2, an overview of resistive MHD equations and the numerical methods is presented. Section 3 is an exposition of the adaptive mesh refinement strategy. In Section 4 we describe the numerical methods we use for the solution of the MHD equations and the AMR strategy. In Section 5 we present standard and specialized tests on Solar Physics. Finally in Section 6 we present final comments.
2 MHD equations and numerical methods.
CAFE-AMR has been designed as a primer to solve time dependent initial value problems described by a set of quasilinear hyperbolic time dependent differential equations. This was in consideration of that resistive MHD equations can be written in a way to satisfy hyperbolicity criteria.
2.1 MHD equations.
The set of MHD equations we are using to describe the dynamics of a fluid element are the following:
(1) |
(2) |
(3) |
(4) |
(5) |
where is the plasma mass density, is the local fluid velocity, is the magnetic field, is the gravitational potential, is the total energy density, ) is the total pressure, is the electric current density and is the resistivity.
We assume the thermal pressure of the plasma is given by the equation of state of an ideal gas so that the total energy density is
(6) |
where is the adiabatic index.
In order to maintain the solenoidal constraint, that is , we implement the divergence cleaning scheme proposed in (Dedner et al., 2002), where the divergence of is related to the scalar function that satisfies equation (5). With this correction, numerical errors that produce a non zero divergence of the magnetic field are transported and diffused through the numerical domain, and at the same time the addition of the equation for maintains the hyperbolic-parabolic structure of the equations. The coefficients and in Eq. (5) determine the damping of the divergence of the magnetic field.
2.2 Numerical methods.
The system of equations (1), (2), (3), (4), and (5) is solved as an Initial Value Problem (IVP) defined on the domain described in Cartesian coordinates , provided initial and boundary conditions are given. We define a base cell centered discretization of as follows:
where is the center of a cell of volume ; the indices take values , , ; the spatial resolutions are defined by , and , with are the numbers of cells along each direction. Time is discretized by where time resolution is , where is the Courant-Friedrichs-Lewy factor. In this domain the value of a given grid function at time and position of the numerical domain, will be represented by .
For the system of equations to be solved we define the vector of conservative variables . The finite volume implementation uses a Godunov type of shock capturing flux computation scheme, which prescribes the evolution formula for from time to as:
(7) |
where , , are the numerical fluxes across the faces of each cell perpendicular to , and directions respectively, as specified by the subindices , , . These fluxes are calculated using either the HLLE (Harten et al., 1983) (Einfeldt, 1988) or Roe (Roe, 1981) (Powell et al., 1999) approximate Riemann solvers.
Time evolution is implemented using the method of lines; we have two second order implementations to do so. A TVD second order Runge-Kutta method consistent with cell centering in the space-time volume with an appropriate reconstructor for the inter-cell boundary values; among the reconstructors available in CAFE-AMR, in the tests below we use the linear piecewise second-order Minmod, methods. The other time evolution scheme we have worked out leans on the corner transport Upwind (Colella, 1990) that implements the GLM-MHD equations, using the schemes proposed in (Mignone & Tzeferacos, 2010).
Following the guidelines in (Dedner et al., 2002), for the hyperbolic cleaning, the divergence present in the source term is implemented directly into the equations with the addition of the exact solution for the normal component of the magnetic field of the intercell face and . We use the operator splitting on the parabolic part of the source term, which has an exact solution.
(8) |
where is the evolution of only through the hyperbolic part of the equations. As in (Dedner et al., 2002) we use the parameter to control the parabolic coefficient such that
(9) |
this choice has the overall effect of maintaining a homogeneous decay of the function throughout the whole numerical domain. Throughout the tests in this work, is set to 0.9. The other source terms present in the right hand side of equations (1)-(5), are calculated every time step and in cases when they contains spatial derivatives, these are computed using the centers of each cell for a point-wise second order finite difference approximation.
3 AMR
The Adaptive Mesh Refinement strategy for solving time dependent partial differential equations on rectangular grids, consist of covering the whole spatial domain with a global coarse grid, and grid patches that cover certain regions with smaller cells and in doing so defining a finer mesh on each patch. With this strategy, the numerical time integrator can be applied indistinctly to all of the patches and also the global coarse grid, so that evolution of every subdomain may be done independently.
The implementation uses the standard Berger-Oliger algorithm (Berger & Oliger, 1984) and consists of the following steps:
-
1.
Select regions of to be refined.
-
2.
Generate refined and properly nested grids in such regions.
-
3.
Interpolate the numerical values of the conservative variables at each cell of the refined regions.
-
4.
Once all of the refined grids have been generated, advance in time the domain as well as the nested grids independently until all of them are synchronized.
-
5.
Inject the values of variables calculated on the refined domain into the cells of the coarse domain.
-
6.
In order to maintain flux balance, correct the fluxes at the boundaries between refined and coarse regions.
This sequence may be used recursively and applied to subsequent refinement levels, that is, all the refined patches can be further refined; in this paper, we will be using the label as the superscript to denote the refinement levels. The resolution ratio , between consecutive refinement levels and is set to , so that for every cell of the coarse grid, there will be four cells of the fine grid for a problem defined on two space dimensions, and eight in the case of a problem in three spatial dimensions.
The reminder of this section includes a detailed description of each of these steps.
3.1 Selecting a region to refine.
The selection of the sectors within the numerical domain to be refined need a refinement criterion. There is a certain liberty to define this criterion conveniently, according to the physical scenario that will be simulated. Typically, an arbitrary number of positive finite scalar functions are defined in every cell of the coarse grid, then every cell is flagged to be refined if this scalar function has a value greater than a certain threshold :
(10) |
Among others, in this code we implement two principal refinement criteria:
-
•
Choosing as the evaluating functions the same numerical approximation of the gradients of every conservative variable as the one used to linearly interpolate their values in a new refined grid. That is:
(11) where is the conservative variable.
-
•
The refinement criterion used in (Mignone et al., 2011), based on the second derivative error norm defined in (Löhner, 1987), where
(12) and is a function of the conservative variables, are the undivided forward and backward finite differences along the direction , for example
The last term that appears in the denominator is given by:
adding the term multiplied by the factor prevents the refinement of regions where small ripples are found.
Additionally, when a simulation uses more refinement levels, in order to properly nest them after refinement level , cells are flagged according to the refinement criterion, cells in the level that contain cells of level are also flagged, and finally, level cells that have flagged neighbors of the same level are flagged as well. This procedure is made recursively from the most refined grid to the coarsest one.
3.2 Generating a new refined grid
A mentioned before, the refinement factor we use this work is , so that a coarse cell will be covered with cells of the refined domain, where is the dimension of the domain. In Figure 1 it is shown how the cell volume of refinement level is of a cell in level .

The refined cells will be centered in positions such that the region covered by them has the same boundaries as the coarse cell. For example, in two dimensions, four refined cells that cover a coarse one will have their centers at positions:
(13) |
where is the coarse cell’s center.
In what follows we use to denote the domain covered with the grid of refinement level .
3.3 Interpolation of data from coarse to refined grid.
Likewise in (Porth et al., 2014) and (Matsumoto, 2007), data reconstruction onto the refined grid is done by a linear interpolation, which lowers the numerical diffusion of shock discontinuities, as well as prevents the generation of spurious shocks on cells that abut on coarser ones. Explicitly, the conservative variables in the domain are:
(14) |
where are the cell positions of , and the position of the cell in , where the conservative variables take values .
The approximation of the gradient operator, , acting on the arbitrary scalar function , is the one presented in (Matsumoto, 2007), given by:
(15) |
and the derivative operation follows the second order accurate centered finite differences:
(16) |
and the Minmod function is given by
(17) |
Similar formulas arise for partial derivatives along and . It is possible to use more robust linear reconstruction formulas, such as MC, or higher order WENO, as long as they preserve overall total variation diminishing properties, which will not affect the overall schemes. However, in the examples of this paper, we have chosen to only use minmod as it is sufficiently precise in regions with big discontinuities, while also being diffusive enough. This helps to prevent the growth of disturbances created by boundaries between refinement levels.
3.4 Time Evolution and Synchronization.
The AMR strategy we implement generates multiple self similar grids, each one of them evolving independently in time by the scheme (7) and only sharing information through their boundaries at the beginning of the evolution from time to .
The Godunov type of finite volume time evolution used for every grid has the Courant-Friedrichs-Lewy (CFL) stability condition that relates the time step with the grid resolution by
(18) |
where is defined as the maximum characteristic speed of the linearized version of equations (1)-(5) throughout the whole domain; the definition of this speed in three dimensional problems reads:
(19) |
where is the maximum magnetosonic speed
(20) |
where , , , and . As stated in (Toro, 2013), the condition is required to preserve stability.
Following the indications in (Berger & Oliger, 1984) and (Berger & Colella, 1989), time step size of refinement level is related with of refinement level by
(21) |
where is the ratio between cell sizes of refinement level and that of level . In this code we chose a constant refinement ratio . To obtain (21) using (18) we get among all subgrids and select the maximum. Also in this step, following (Dedner et al., 2002) we define the coefficient used in equations (5) and (9) of the divergence cleaning method.
A complete evolution cycle of the system from to is considered as done once all of the grids synchronize at the time . This requires that the domain must be evolved times to catch up with the coarsest domain. Figure 2 shows how grids of multiple refinement level advance several times to do so.

In (Keppens et al., 2003), it was found that choosing a non-homogeneous refinement ratio independently of the overall scheme can optimize certain aspects of the simulation, leading to faster computing times. However, our observations indicate that the gain from this approach, especially with a refinement ratio greater than 2, is outweighed by the benefits of using the recursive code structure of the fixed ratio. The recursive approach facilitated our control of proper refinement nesting and hierarchical time stepping.
Various AMR codes prove that in many physical simulations, homogeneous time step is preferred, as seen in the Nirvana code (Ziegler, 2008), which employs a single time step, not only for the better handling of simulations with non zero diffusion source terms, but also to realize faster parallelization schemes. In our tests, hierarchical time stepping yielded good results.
Except for the boundaries of the physical domain, the evolution of refined domains starts with the implementation of boundary conditions. This is done by filling ghost cells that extend the domain , filled with appropriate flux values, see e.g. (LeVeque, 2002). Filling of ghost cells depends on the kind of boundary they are extending. As shown in Figure 3, we identify three types of boundaries of domain :
-
•
Shared boundaries with another domain of the same refinement level .
-
•
Shared boundary with domains of lower refinement level, which may be only of level because of how new sub grids are generated.
-
•
Shared boundary with the physical boundary.



According to these types of boundaries ghost cells are filled in the following way:
-
•
If ghost cells have the same position as cells contained on another same refinement level grid, simply copy data values contained on those cells.
-
•
If ghost cells of a domain are contained on a coarse cell from a domain linearly interpolate the data values.
-
•
If ghost cells correspond to a physical boundary, implement the appropriate boundary conditions, such as outflow or rigid, to name a few.
In the case of boundaries between consecutive refinement levels, the values of the variables at ghost cells of are constructed using linear interpolation from the values at cells in in the same way as equation (14), that is
(22) |
where it is necessary to define the coarse grid values , as
(23) |
and where the numerical gradient is an upwind or downwind approximation depending on which face of the coarse level grid abuts on a refined one . For example, if the boundary perpendicular to the direction of is shared with the refined domain , then
(24) |
where is an arbitrary scalar function; if the boundary perpendicular to the direction is the one being shared, then is used instead. A similar formula is used when the faces are perpendicular to , .
3.5 Injection of refined data onto the coarser grid.
Once the variables in the coarse grid and its refinement are synchronized, the values of the conservative variables in the refined grid must be injected onto the coarse one. This is done by overwriting the data values contained in the coarse cell, with the average of the data values in the refined cells that cover it.
In three dimensions this is done using the formula
(25) |
where are the data values of the refined cells that cover the coarse cell at position .
3.6 Flux corrections.
Finite volume methods are based on the conservation of quantities at a given cell. For example, the conservation of mass equation (1) on its finite volume form, equation (7), at cell can be written as:
(26) |
where is the cell volume, is the total mass gain over the time step and =, =, = are the numerical fluxes across the faces of the cell whose normal directions are respectively , , .
Equation (26) establishes that each of the numerical fluxes introduces an amount of mass gain or loss across the faces of a cell. We focus our attention on the face boundary at where the mass gain is
(27) |
Now, consider a boundary between two domains of different refinement level. When a coarse grid cell abuts on refined grid cells to the right along , the mass variation of equation (27) must be equal on both sides of the boundary, as in Figure 4, then the following relation should hold:
(28) |
where indices label the cell of and the cells of abutting on the coarse cell to the left.

By expressing (28) in terms of (27), an equivalence of the numerical fluxes of the cells in refinement level and the cells in refinement level across the shared boundary is exposed:
(29) |
this argument must hold not only for all cell faces abutting on refined grids, but also for all the numerical fluxes of every conservative variables at these faces.
In order to enforce (29) we define a flux correction given by
(30) |
that is subtracted or added, depending on which side of the shared boundary the fine cells are, once the conservative variables on the coarse cell have been updated, that is:
(31) |
Flux corrections along the and directions are implemented in a similar way.
4 Code structure
In this section we present a general overview of CAFE-AMR flow chart as well as its structure. This code is written in Fortran using f90 standard, it uses the mpich library for parallelization, and the hdf5 library to save data. Other than that, CAFE-AMR contains its own libraries and dependencies.
4.1 Data structure
This code works with a self similar block structure, as seen in Figure 5, where every block has the following data:
-
•
A grid discretized with a regular spacing using cells plus ghost cells used at the boundaries.
-
•
The physical location of the center of the block.
-
•
Allocatable arrays. These may contain the values of the conservative variables, or the flux corrections given in (31) to the cells abutting on the boundaries of the block.
-
•
A refinement level flag that indicates the physical volume of the cells on its grid as well as the time step .
-
•
Pointers to other blocks that share physical boundaries which have the same refinement levels. This blocks are referred to as neighbors.
-
•
Pointers to other blocks referred to as children. These specific blocks cover a quadrant, in two dimensions, or an octant, in three dimensions, contained inside the original block.
-
•
Pointer to another block which has a portion of its domain covered by this block. This block is referred to as father.
-
•
Several logical flags. They have various uses, such as defining boundary conditions and deciding whether memory will be used, to name a few.

All the blocks are ordered hierarchically in a QuadTree, in two dimensional problems, and an OcTree in three dimensional problems. In Figure 6 a QuadTree is represented. In this data hierarchy, the refinement of the domain is generated in the following way. First the blocks are analyzed by quadrants:
-
1.
Every time a cell of a given quadrant satisfies the refinement criteria (10), the whole quadrant is flagged to be refined.
-
2.
If a Block’s quadrant associated child has children of its own, the quadrant is flagged to be refined.
-
3.
If a quadrant is flagged to be refined, all of its neighbors are also refined, even if they correspond to a different block.
Then all of the flagged quadrants are covered by newly generated data blocks which join the quadtree as children of the block they cover. Later on, all of the unflagged quadrants have their corresponding children deallocated.

This whole procedure is done from the highest refinement level to the base level so that the blocks are properly nested, according the scheme in subsection 3.1. Once the refinement process has ended and all data have been interpolated, the whole neighbor pointer structure is updated. Octrees are refined in the same way.
Finally, if a data block is flagged to abut on a coarser one, a flux correction array is allocated. This array adds on the corrections in order to calculate the terms of Eq. (31). Flags that indicate whether coarse data will be interpolated to fill ghost cells in children blocks are also activated at the end.
4.2 Time evolution
As the data structure suggests, time evolution is done recursively beginning on all the blocks of a given base level to an user specified last level of refinement. The time evolution control flow that holds synchronization of all blocks is the following:
-
1.
Apply physical boundary conditions at refinement level .
-
2.
Copy data values from same level neighbors that share a boundary into ghost cells.
-
3.
Fill ghost cells values to level blocks abutting level blocks by interpolation in a synchronous way following equation (23).
-
4.
Advance level blocks a time-step .
-
5.
Advance recursively blocks a time-step .
-
6.
Fill ghost cell values to level blocks abutting level blocks by interpolation in an asynchronous way following equation (23).
-
7.
Advance recursively blocks a time-step .
-
8.
Inject values of children blocks into the corresponding region they cover on level blocks using equation (25).
-
9.
Apply numerical flux corrections on level blocks following (31).
Flux corrections are implemented by first collecting in allocatable arrays, both, the cells abutting on grids and the corresponding cells on coarse blocks, afterwards these data are used to construct the terms of equation (30).
5 Tests of the code
In this section we present a set of tests that illustrate the ability of the code to handle different problems and the well functioning of the AMR.
5.1 2D Kelvin-Helmholtz instability
Kelvin-Helmholtz instabilities are standard tests for hydrodynamical codes, and in the context of Solar Physics these can occur at the boundaries between different regions of the solar wind with varying velocities or densities as well as in small scale solar jets (Skirvin et al., 2023). As shown in (Mishin & Tomozov, 2016). These instabilities can lead to the formation of turbulent structures and the mixing of plasma, which can affect the propagation and properties of the solar wind. This is a MHD test, in which the discontinuities in counter-flow regions develop spiral-like shapes on, that are a challenge for an AMR method to follow.


The initial conditions for this test are set to:
(34) |
with adiabatic index . In order to trigger the instability, the velocity components are perturbed as follows and , where .
This test is defined in the periodic domain , with a base resolution of cells, time step resolution given by a CFL factor . For this test we use the Roe flux formula and the CTU time stepping scheme. We present three simulations with different refinement criteria as well as different number of refinement levels.
In a first simulation we use criterion (12) with a threshold value of using the density as the evaluating function in (10). We use five refinement levels, which gives an equivalent resolution of cells. In Figure 7 we show a snapshot along with a zoomed region at the interface region, the addition of resolution across the interface manages to develop spiral like shapes in small spatial scales. In Figure 8 we illustrate how the AMR method follows the discontinuity even with a slim refined domain while also maintaining the overall structure of the less dynamical regions.


In Figure 9 we show the results of a second simulation where we use three refinement levels, giving an equivalent resolution of cells. In this case, we compare the use of refinement criterion (11) with and criterion (12) with , acting on the density . In the refinement structure, it is shown that, since the criterion (11) uses all of the conservative variables as evaluating functions to set the refinement regions, the refined grids are set to cover all of the mixing regions whilst in criterion (12) the refinements are located in smaller regions. This results in a difference on small scale structure of the simulation. It is important to keep in mind this in order to define appropriate refinement strategies.




5.2 2D Rayleigh-Taylor Instability
In presence of acceleration, when a fluid in low and high density phases, with the low density supporting the weight of the high density phase, initially in hydrostatic equilibrium, small perturbations give rise to the hydrodynamic Rayleigh-Taylor instability.
The analysis of this type of instability is used to learn how an initial linear perturbation develops a complex non-linear behavior. Rayleigh-Taylor instabilities in solar physics serve to gain insights into the physical processes responsible for solar eruptions, energy release, and the dynamics of the Sun’s atmosphere, (see e.g. Jenkins & Keppens (2022)). At first, in the linear regime, the growth rate of these instabilities depends on the wave number and frequency of the perturbation, for example the amplitude grows faster for shorter wavelengths. After the perturbation evolves into the nonlinear regime, bubbles from the low density region rise and drops from the high density shell fall, crossing the initial interface surface and the dynamics leads to the mixture of the two initial phases. Its complexity is a reason why this is a challenging test of fluid dynamics codes.
In the case of the MHD, the fluid is considered a magnetized ideal gas that responds to a magnetic field, that changes the evolution of the instability (see e.g. (Stone & Gardiner, 2007)). In this test the magnetic field is set parallel to the interface between the two fluid states and inhibits the growth rate of the instability. In order to show that CAFE-AMR can handle this problem, we present the two dimensional Rayleigh-Taylor problem.
We solve the equations on the domain , , and define the interface as the line . Initial conditions assume the density in lower and higher parts of the domain are and respectively, the gravity constant is set to and the system is in hydrostatic equilibrium, consistently with the pressure
(35) |
which in turn defines the speed of sound to and a crossing time of across the interface.






We use periodic boundary conditions along the direction and fixed conditions at the top and bottom of the domain. The base resolution uses cells and we use five refinement levels, which results in an equivalent resolution of cells with the finest resolution. The refinement criterion used is that in Eq. (12) using hydrodynamic pressure, density and the component of the velocity as evaluating functions together with a threshold parameter . Numerical fluxes are constructed using the Roe flux formula and the minmod limiter. Time resolution is given by a CFL factor of .







The perturbation that triggers the instability is added to the velocity field at the interface line, assuming the profile
(36) |
which is the 2D version of the instability presented in (Mignone et al., 2011); we also define the magnetic field to be constant along the direction, , where
(37) |
In our test we present two cases: unmagnetized , slightly magnetized .



Figure 10 presents the evolution of the density and refinement structure profiles of the instability at for the unmagnetized case. As the denser shell begins to fall along the vertical direction, and due to the difference in velocities of the low and high density regions, the flow develops Kelvin-Helmholtz instabilities which in turn develop further into a highly structured interface at latter times. The refinement strategy selected on this case adequately tracks the overall structure of the interface.
Figure 11 presents the density and refinement structure profiles in the slightly magnetized case , the Kelvin-Helmholtz instabilities are suppressed because the topology of the field lines interrupts the torsion of the fluid interface, the magnetic field works against gravity and helps the denser shell to remain in the upper part which also stops the generation of KH-instabilities. In Figure 12 we show that the magnetic pressure is acting overall only at the interface surface. In Figure 13 we show that because of the augmented precision, we can capture at the lowest region of the interface there is a small scale variation in both density and magnetic pressure.
5.3 Localized Resistivity Current sheet
Solar flares are modelled as events generated magnetic reconnection (see e.g. (Priest, 2014)). In (Yokoyama & Shibata, 2001) two dimensional MHD simulations were employed to show the effect that localized magnetic resistivity has at triggering this process. The AMR strategy used to approach such simulations is advantageous as locality of phenomena is important. With this in mind, we present the localized resistivity Current Sheet (LRCS) test. This test models the generation of flares in a stratified density profile were a current sheet magnetic field is developed with the presence of a localized resistivity with Gaussian profile. The simulation is carried out on a numerical domain of ; fixed boundary conditions at the bottom boundary and outflow boundary conditions on the other sides of the domain; we use an initial resolution of cells with four refinement levels giving an equivalent resolution of ; the refinement criterion used is (11) with a threshold of ; numerical fluxes are constructed using the HLLE formulas with the second order CTU time stepping. A factor was chosen so that time steps capture difussion time scales adequately.
Initial data is defined as follows. Density has the stratified profile
(38) |
where , , , . The magnetic field is defined as
(39) | |||||
(40) | |||||
(41) |
where and ; the localized resistivity function is the same as in (Takasao et al., 2015), that is
(42) |
where , and . Pressure is initially set to and the whole system is initially set at rest.


In Figure 14 it is shown that near the maximum of the resistivity there is an increase in magnetic pressure as well as a decrease in hydrodynamic pressure. The results is that matter enters to this region from the sides and is expelled along the vertical directions as illustrated with the component of the velocity in Figure 15. In this case we use precisely the velocity as the function to be tracked by the refinement criterion, which as seen in the plots, follows the discontinuities of .


5.4 Hydrodynamic Solar Wind
Within the subject of Space Weather, the most commonly studied system is the Solar Wind, including the stationary wind.
In order to simulate this type of processes in the Solar System, we first solve the MHD equations with a null magnetic field in a cubic domain , with , centered at the position of the Sun, and consider bigger than the major semi-axis of Earth’s orbit. For the position of Earth we use Heliocentric Earth Ecliptic (HEE) coordinates, in which Earth’s position moves along the positive part of the axis from perihelion to aphelion.
Solar Wind simulations are carried out in a particular domain of interest, the volume contained from a sphere of (see e.g. (Riley & Gosling, 1998; González-Esparza et al., 2003; Feng et al., 2021)), until the faces of the cubic numerical domain. The reason to use a sphere of radius as an inner boundary is that at that distance from the Sun’s surface, the characteristic speeds of the wind are all pointing outwards, and consequently the flow is in the wind regime, as opposed to the accretion regime which is possible at shorter distances. This allows the injection of the physical properties of a wind or a storm through this inner boundary without the danger of material entering back in an accretion process.
The permanent injection of plasma at the inner boundary can be simulated by maintaining the physical variables of the Solar Wind , with suitable values at , constant in time. Notice however that in Cartesian coordinates this inner boundary is the boundary of a lego-sphere, not an actual sphere, and therefore the implementation of boundary conditions at each face of boundary cubes is delicate (Kleimann et al., 2009). What we do to overcome this problem is to fill-in the whole lego-sphere with values of the primitive variables characterizing the wind at all times with the values at , then the plasma will propagate outwards and eventually will fill the interplanetary space until it settles down to the heliosphere density and velocity profile (Guzmán & Mendoza-Mendoza, 2022).
At the external boundary, namely the faces of the cubic domain, we would like the fluid to continue its way out through the solar system and then use outflow boundary conditions at the outer cubic boundary.
As a particular example we simulate the formation of one of the stationary Solar Winds cases in (González-Esparza et al., 2003), which is spherically symmetric, with no magnetic field, in a domain with inner boundary , density =, velocity , m/s, temperature K and zero magnetic field and adiabatic index . We use the numerical domain to be for the wind to expand and cover at least a volume that contains Earth’s orbit.
Translation from code to physical units. Following (Guzmán & Mendoza-Mendoza, 2022), code and physical units are defined in terms of fixed scales of the state variables, for density , pressure , length , time , velocity , temperature . Notice that there is no restriction on density scale , that we choose to be one.
We define code units by fixing the length scale to one solar radius , time to one hour , which defines the velocity scale . Density scale is fixed to which defines the magnetic field scale . Temperature scale is with kg the Hydrogen molecular mass and Boltzmann’s constant, and pressure and energy scales are and .
Initial conditions are available given for the density, velocity and temperature of the wind as follows:
(46) | |||||
(50) | |||||
(51) |
where . The pressure needed as the primitive variable instead of temperature, is calculated from , then internal energy is given by the equation of state , and finally the total energy is .
The simulation uses a base resolution of cells with 3 refinement levels, producing an equivalent resolution of cells. We use the refinement criterion (11) with a threshold value . Outflow boundary conditions are set at the borders of the numerical domain. Numerical fluxes are computed using the HLLE formula along with the mimod reconstructor. A CFL factor of was used throughout the whole simulation.
At initial time the wind variables have constant values within the sphere of radius , which simulates a stationary pumping of plasma into the heliosphere. The gas fills the numerical domain with the front wave that propagates outwards until it reaches the external boundary and leaves the domain. In Figure 16 we show how the refinement criteria follows this front wave. Once the wave leaves the boundary the flow approaches a stationary state.
The result of this simulation appears in Figure 17, where we show snapshots of density, component of and temperature of the gas along the , until the flow stabilizes in the whole domain by hours. In order to have a reference of the spatial domain, in these coordinates (HEE) the average Earth location is .










After the wind has become stationary, we inject a toy-model of Coronal Mass Ejection (CME). We characterize the CME launched from the inner boundary at by its density, velocity and widening angle . The injection is implemented similarly as the stationary Solar Wind at the inner boundary provided density, velocity and temperature of the CME. As a test we inject a toy CME with the following properties and , conditions taken from (González-Esparza et al., 2003). We launch this CME centered at the solar equator, during a time window of 3 hours. In Figure 18 we show snapshots of density during the propagation of the CME. With this initial setup the initial burst propagates, its density profile smears out and widens. In Figure 19 we show that the structure of the highest refinement level tracks the perturbation.
5.5 Tilted Magnetic Dipole Solar Wind
Beyond the solar corona, the solar wind is fairly well and commonly modelled using ideal MHD. In this context, the macroscopic plasma quantities, such as density, velocity and temperature, can all be related to the topology of the field lines of the magnetic field. Current techniques applied to simulate the interplanetary heliosphere rely on this fact, for example the WSA (Arge et al., 2004) approximation and its implementation in the ENLIL model (Odstrcil, 2003).
In order to explain our implementation of the magnetic field we briefly review the bases of empirical models. The physical domain is partitioned into some basic spherical shells approximately located at given spheres: the photosphere at 1 , the Solar Corona (SC) at , the inner boundary at , and the rest of the numerical domain that includes a volume containing at least the Earth’s orbit, of . The magnetic field at the photosphere is reconstructed from magnetogram synoptic maps, used as input to construct analytic expressions of the magnetic field at the Corona via the potential field source surface method (Newkirk & Altschuler, 1969). Next, the super-radial expansion factor (), that refers to the variation of field strength along a magnetic flux tube is calculated, for example as done in (Shiota et al., 2014):
(52) |
where is the radial component of the magnetic field. The coordinates of the foot point of the magnetic flux tube are located by using a first order integration of the magnetic field lines taking as the starting point; if, after a finite number of steps, the foot point is not found, a default value is chosen so that the radial velocity is minimal according to (53).
Once is calculated, we use the empirical Wang and Sheely formula (Wang & Sheeley, 1990; Arge & Pizzo, 2000) that gives the wind radial velocity at the inner boundary as
(53) |
With this in mind, we have woven a test based on the empirical construction of the solar wind at the inner boundary using an analytical expression of the magnetic field.
Based on the Parker Solar Wind model (Priest, 2014), we use a constant temperature, as well as a magnetic field that fulfills conservation across radial flux tubes:
(54) |
To obtain the solar wind radial velocity profile at the inner boundary in equation (53), we impose the magnetic field of a tilted dipole given by
(55) |
where is the magnetic dipole moment. We use an inertial heliographic reference frame (Burlaga, 1995) that does not have Coriolis forces due to rotation. In this sense, the internal boundary expresses an ejected hot sphere of magnetized plasma that rotates like a solid. To apply the rotation at the internal boundary, we transform the component of the magnetic dipole by , where is the angular frequency of the Sun. This will rotate the inner magnetic field on equation (55) and, because all of the boundary quantities are connected to the magnetic field, they will also experience the same rotation.
The number density is given by a measure of the radial flux of number density at 1 AU in slow wind conditions (Smith, 2009),
(56) |
where , , . Finally the hydrodynamic pressure can be obtained from the equation of state of the ideal gas.
The simulation specifications for this test are the following: The computational domain is the cubic box of size , centered at the Sun’s location. The initial resolution is given by cells with three refinement levels, which corresponds to an equivalent resolution of cells. We use outflow boundary conditions at the edges of the numerical domain and set the internal boundary at . Time stepping is handled with second order RK with a CFL factor of ; numerical fluxes are obtained through the HLLE approximation. The initial temperature of the system is set to , with an adiabatic index of . The magnetic dipole strength is T , its colatitud inclination angle is and the magnetic field at the inner Boundary is given by the radial component of (55).
We use two types of refinement, a fixed one and an adaptive one. In order to minimize the effect of geometrical errors due to the inner boundary to be a lego sphere, we set a fixed mesh refinement near the boundary so that in this region we use maximum spatial and temporal resolution. The adaptive refinement is a mixture of the one proposed by (Matsumoto et al., 2019), where we refine a data block if there is a change in polarity in , and, because we desire to capture the spiral-like behavior in the radial component of the velocity, we choose at equation (12) with a threshold . This refinements are implemented only in regions where so that only the heliospheric current sheet is refined.
Quantity | Normalization |
---|---|
Time | s |
Length | m |
Velocity | m/s |
Temperature | K |
Number Density | |
Density | |
Magnetic Field | Tesla |
In order to simulate this scenario, we connect physical and code units according to the values in Table 1. In Figure 20 we show a meridian cut of the radial velocity, and notice that there are two regions corresponding to a slow streamer belt and a fast wind region near the poles. Figure 21 shows the rotation effect at the zenith cut of the velocity, which develops a gradient in its magnitude typically associated with co-rotating interaction regions.


In reference to mesh refinement, Figure 22 shows the various domains and the resolutions used in each patch, at the plane . The refinement tracks the slower wind at low latitudes as expected because it is also the region where there is a shift on polarity in the magnetic field.


At big interplanetary distances, the magnetic profile of the solar wind is dominated by the dipole moment. Figure 23 shows the magnetic field lines over the whole domain; it can be seen that near the equator, field lines are sporadic, as expected for a magnetic dipole. Certain torsion of the field lines associated with the rotation of the injected boundary can also be noticed. This simulation achieves this specification and also manages to evolve the rotating magnetized solar wind that generates the Parker spirals. This is a test case toward the real more elaborate simulations in practical forecasting, which involve specialized PFSS definitions to extend the range of heliosphere simulations even further.
The issue we are tackling on this test, in the context of solar wind simulations, is of augmenting spatial resolution not only at the internal boundary but also capturing dynamical structures at regions of interest farther away. Certainly AMR on rectilinear grids is not the only strategy. For example, in the project of sun to earth simulations (Narechania, Nishant M. et al., 2021), AMR regriding strategies are employed using hexahedral blocks, obtaining high resolution on the formation of current sheets as well as on the propagation of CME, at the cost of needing special care of the numerical fluxes at intercell boundary faces. Another case is the ICARUS code (Verbeke, C. et al., 2022), which achieves high resolution simulations using AMR on spherical grids, which do not have as complex flux formulas as the hexahedral simulations, but due to the geometry of the equations there is a need of special care of singularities of the equations at the poles. AMR on rectilinear grids do not have neither of this problems, but the issue of having a lego sphere at the internal boundary is a hard problem, it overburdens the usage of the PFSS schemes and the use of co-rotating frames might also induce non physical phenomena; major improvements on this test can be made, in this sense, by applying corrections which could mitigate this geometric problem, for example with the Immersed Boundary method (Mittal & Iaccarino, 2005) or averaging at the excision surface (Kleimann et al., 2009), as in the hydrodynamic solar wind tests from the previous section.
6 Final comments and conclusions
In this paper we have presented a new implementation that uses AMR to solve the MHD equations, with the expectation to have a theoretical laboratory to study and contribute to Space Physics at heliosphere scales.
CAFE-AMR uses simple and standard numerical methods that allow the simulation of various processes of importance, which are concentrated in a series of idealized standard test problems. These tests show the ability of CAFE-AMR to track well known features prominent in solar physics, with particular emphasis on the adaptability of refined domain patches: Standard ideal MHD tests of the Kelvin-Helmholtz and the Rayleigh-Taylor instabilities that are ubiquitous in solar physics and generate highly localized phenomena; the Localized Resistivity current sheet which simulates the evolution of solar flares in regions near the chromosphere-corona interface; heliospheric related tests include the formation and stabilization of a non-magnetized Solar Wind and CME propagation as well as the formation and stabilization of a magnetized Solar Wind which generates a rotating current sheet.
Further work will involve specific applications that include convection and radiation with the scope of modeling chromospheric events and non-ideal MHD effects. The code in this paper is expected to be enriched with the methods and scenarios involving thermal conduction Gonzalez-Avilés & Guzmán (2018); González-Avilés et al. (2020) and radiation (Rivera-Paleo & Guzmán, 2019).
Acknowledgements
Ricardo Ochoa Armenta receives support from CONACyT under CVU 785828. This research is supported by grant CIC-UMSNH-4.9 of Universidad Michoacana. The runs were carried out in the Big Mamma cluster of the Laboratorio de Inteligencia Artificial y Supercómputo, IFM-UMSNH.
Data availability
The data and code underlying this article will be shared on reasonable request to the corresponding author.
References
- Arge & Pizzo (2000) Arge C. N., Pizzo V. J., 2000, Journal of Geophysical Research: Space Physics, 105, 10465
- Arge et al. (2004) Arge C. N., Luhmann J. G., Odstrcil D., Schrijver C. J., Li Y., 2004, Journal of Atmospheric and Solar-Terrestrial Physics, 66, 1295
- Berger & Colella (1989) Berger M., Colella P., 1989, Journal of Computational Physics, 82, 64
- Berger & Oliger (1984) Berger M. J., Oliger J., 1984, Journal of Computational Physics, 53, 484
- Bryan et al. (2014) Bryan G. L., et al., 2014, The Astrophysical Journal Supplement Series, 211, 19
- Burlaga (1995) Burlaga L. F., 1995, Interplanetary magnetohydrodynamics, 3
- Cielo et al. (2022) Cielo S., Porth O., Iapichino L., Karmakar A., Olivares H., Xia C., 2022, Astronomy and Computing, 38, 100509
- Colella (1990) Colella P., 1990, Journal of Computational Physics, 87, 171
- Cunningham et al. (2009) Cunningham A. J., Frank A., Varniére P., Mitran S., Jones T. W., 2009, The Astrophysical Journal Supplement Series, 182, 519
- Dedner et al. (2002) Dedner A., Kemm F., Kr’:oner D., Munz C.-D., Schnitzer T., Wesenberg M., 2002, Journal of Computational Physics, 175, 645
- Einfeldt (1988) Einfeldt B., 1988, SIAM Journal on Numerical Analysis, 25, 294
- Feng et al. (2012) Feng X., Yang L., Xiang C., Jiang C., Ma X., Wu S. T., Zhong D., Zhou Y., 2012, Solar Physics, 279, 207
- Feng et al. (2021) Feng X., Wang H., Xiang C., Liu X., Zhang M., Zhao J., Shen F., 2021, The Astrophysical Journal Supplement Series, 257, 34
- Fryxell et al. (2000) Fryxell B., et al., 2000, The Astrophysical Journal Supplement Series, 131, 273
- Gonzalez-Avilés & Guzmán (2018) Gonzalez-Avilés J. J., Guzmán F. S., 2018, IEEE Transactions on Plasma Science, 46, 2378
- González-Avilés et al. (2015) González-Avilés J. J., Cruz-Osorio A., Lora-Clavijo F. D., Guzmán F. S., 2015, Monthly Notices of the Royal Astronomical Society, 454, 1871
- González-Avilés et al. (2020) González-Avilés J. J., Guzmán F. S., Fedun V., Verth G., 2020, The Astrophysical Journal, 897, 153
- González-Esparza et al. (2003) González-Esparza J., Cantó J., González R., Lara A., Raga A., 2003, Advances in Space Research, 32, 513
- Guzmán & Mendoza-Mendoza (2022) Guzmán F. S., Mendoza-Mendoza L. F., 2022, Journal of Physics: Conference Series, 2307, 012020
- Harten et al. (1983) Harten A., Lax P. D., Leer B. v., 1983, SIAM Review, 25, 35
- Jenkins & Keppens (2022) Jenkins J. M., Keppens R., 2022, Nature Astronomy, 6, 942
- Keppens, R. et al. (2023) Keppens, R. Popescu Braileanu, B. Zhou, Y. Ruan, W. Xia, C. Guo, Y. Claes, N. Bacchini, F. 2023, A&A, 673, A66
- Keppens et al. (2003) Keppens R., Nool M., Tóth G., Goedbloed J., 2003, Computer Physics Communications, 153, 317
- Kleimann et al. (2009) Kleimann J., Kopp A., Fichtner H., Grauer R., 2009, Annales Geophysicae, 27, 989
- LBNL (2019) LBNL 2019, CHOMBO Library, https://commons.lbl.gov/display/chombo/Chombo+-+Software+for+Adaptive+Solutions+of+Partial+Differential+Equations
- LeVeque (2002) LeVeque R. J., 2002, Finite-Volume Methods for Hyperbolic Problems. Cambridge University Press
- Liska et al. (2022) Liska M. T. P., et al., 2022, The Astrophysical Journal Supplement Series, 263, 26
- Löhner (1987) Löhner R., 1987, Computer Methods in Applied Mechanics and Engineering, 61, 323
- Lora-Clavijo et al. (2015) Lora-Clavijo F. D., Cruz-Osorio A., Guzmán F. S., 2015, The Astrophysical Journal Supplement Series, 218, 24
- MacNeice et al. (2000) MacNeice P., Olson K. M., Mobarry C., De Fainchtein R., Packer C., 2000, Computer physics communications, 126, 330
- Matsumoto (2007) Matsumoto T., 2007, Publications of the Astronomical Society of Japan, 59, 905
- Matsumoto et al. (2019) Matsumoto T., Shiota D., Kataoka R., Miyahara H., Miyake S., 2019, Journal of Physics: Conference Series, 1225, 012008
- Mignone & Tzeferacos (2010) Mignone A., Tzeferacos P., 2010, Journal of Computational Physics, 229, 2117
- Mignone et al. (2007) Mignone A., Bodo G., Massaglia S., Matsakos T., Tesileanu O., Zanni C., Ferrari A., 2007, The Astrophysical Journal Supplement Series, 170, 228
- Mignone et al. (2011) Mignone A., Zanni C., Tzeferacos P., van Straalen B., Colella P., Bodo G., 2011, The Astrophysical Journal Supplement Series, 198, 7
- Mishin & Tomozov (2016) Mishin V. V., Tomozov V. M., 2016, Solar Physics, 291, 3165
- Mittal & Iaccarino (2005) Mittal R., Iaccarino G., 2005, Annual Review of Fluid Mechanics, 37, 239
- Narechania, Nishant M. et al. (2021) Narechania, Nishant M. Nikoli´c, Ljubomir Freret, Lucie De Sterck, Hans Groth, Clinton P. T. 2021, J. Space Weather Space Clim., 11, 8
- Newkirk & Altschuler (1969) Newkirk G., Altschuler M., 1969, in Bulletin of the American Astronomical Society. p. 288
- Odstrcil (2003) Odstrcil D., 2003, Advances in Space Research, 32, 497
- Porth et al. (2014) Porth O., Xia C., Hendrix T., Moschou S. P., Keppens R., 2014, The Astrophysical Journal Supplement Series, 214, 4
- Powell et al. (1999) Powell K. G., Roe P. L., Linde T. J., Gombosi T. I., De Zeeuw D. L., 1999, Journal of Computational Physics, 154, 284
- Priest (2014) Priest E., 2014, Magnetohydrodynamics of the Sun. Cambridge University Press
- Riley & Gosling (1998) Riley P., Gosling J. T., 1998, Geophysical Research Letters, 25, 1529
- Rivera-Paleo & Guzmán (2019) Rivera-Paleo F. J., Guzmán F. S., 2019, The Astrophysical Journal Supplement Series, 241, 28
- Roe (1981) Roe P., 1981, Journal of Computational Physics, 43, 357
- Shiota et al. (2014) Shiota D., Kataoka R., Miyoshi Y., Hara T., Tao C., Masunaga K., Futaana Y., Terada N., 2014, Space Weather, 12, 187
- Skirvin et al. (2023) Skirvin S., et al., 2023, Advances in Space Research, 71, 1866
- Smith (2009) Smith C., 2009, Heliophysics I. Plasma Physics of the Local Cosmos
- Stone & Gardiner (2007) Stone J. M., Gardiner T., 2007, Physics of Fluids, 19, 094104
- Stone et al. (2008) Stone J. M., Gardiner T. A., Teuben P., Hawley J. F., Simon J. B., 2008, The Astrophysical Journal Supplement Series, 178, 137
- Takasao et al. (2015) Takasao S., Matsumoto T., Nakamura N., Shibata K., 2015, The Astrophysical Journal, 805, 135
- Teyssier (2002) Teyssier R., 2002, A&A, 385, 337
- Toro (2013) Toro E. F., 2013, Riemann solvers and numerical methods for fluid dynamics: a practical introduction. Springer Science & Business Media
- Tóth et al. (2012) Tóth G., et al., 2012, Journal of Computational Physics, 231, 870
- Verbeke, C. et al. (2022) Verbeke, C. Baratashvili, T. Poedts, S. 2022, A&A, 662, A50
- Wang & Sheeley (1990) Wang Y. M., Sheeley N. R. J., 1990, ApJ, 355, 726
- Xia et al. (2018) Xia C., Teunissen J., Mellah I. E., Chané E., Keppens R., 2018, The Astrophysical Journal Supplement Series, 234, 30
- Yokoyama & Shibata (2001) Yokoyama T., Shibata K., 2001, The Astrophysical Journal, 549, 1160
- Ziegler (2008) Ziegler U., 2008, Computer Physics Communications, 179, 227