AMReX-Microelectronics / FerroX

FerroX is a massively parallel, 3D phase-field simulation framework for modeling ferroelectric materials based scalable logic devices.
Other
9 stars 9 forks source link

implementing and testing sundials time integration methods #55

Closed pebblefoot31 closed 2 months ago

pebblefoot31 commented 3 months ago

This PR adds SUNDIALs support to FerroX and validates its implementation through convergence analysis. The convergence tests utilize the AMReX-based ComparePlotfiles function to determine the convergence rate.

In a new directory, copy over the ComparePlotfiles3d.gnu.ex executable from the _amrex/Tools/Cutil/Convergence/ directory. The ComparePlotfiles function returns a norm that represents the error from the coarse (dt = 5.0e-14) to medium (dt = 2.5e-14) time step and another that represents the error from the medium (dt = 2.5e-14) to fine (dt = 1.25e-14) time step. First, in a directory cleared of all plot files, we copy over the SUNDIALs-compatible executable main3d.gnu.TPROF.MPI.OMP.SUNDIALS.ex and the inputs_sundials_convergence file. In order to use SUNDIALs, we enabled SUNDIALs methods in the inputs_paper_convergence inputs file by modifying the following parameters in the inputs file:

Under the Integration section:

use_sundials = 1
integration.type = RungeKutta

Select the integration method you want to test with the integration.rk.type parameter. Note that:

## integration.rk.type can take the following values:
### 0 = User-specified Butcher Tableau
### 1 = Forward Euler
### 2 = Trapezoid Method
### 3 = SSPRK3 Method
### 4 = RK4 Method

Once we set up the input file to test the convergence for the desired method, we move on to generating plot files in the appropriate order. Under the Problem Domain section, modify the plot-int, dt, and nsteps values incrementally. Since we wanted to reproduce the tests from the first FerroX paper, the dt values were set to the same corresponding coarse, medium, and fine time step values as described in the manuscript. To generate the plot files for the coarse, medium, and fine timesteps, uncomment the following blocks of code (starting at the top) with each successive run:

## plot_int = 8
## dt = 5.0e-14
## nsteps = 8

## plot_int = 16
## dt = 2.5e-14
## nsteps = 16

## plot_int = 32
## dt = 1.25e-14
## nsteps = 32 

After generating the plot files for each time step, move up to the directory that contains the ComparePlotfiles function executable. In this directory, execute the following command to compute the error of coarse to medium:

./ComparePlotfiles3d.gnu.ex infile1 = forwardEuler/plt00000008 reffile = forwardEuler/plt00000016/

Locate the rightmost value in the third row of values displayed in the (comp, L0, L1, L2) format. This is the coarse-medium norm.

(comp,L0,L1,L2) 2 3.697637893e-07 1.641225233e-08 4.006690117e-08

And then run the following command to compute the error of medium to fine (same exact format as the previous command, just different plot files):

./ComparePlotfiles3d.gnu.ex infile1 = forwardEuler/plt00000016 reffile = forwardEuler/plt00000032/

You should view the following output:

(comp,L0,L1,L2) 2 1.845420166e-07 8.174923954e-09 1.996620447e-08

Locate the rightmost value in the third row once again. This is the medium-fine norm.

Compute the Rate using the following formula. The E_mc value is the coarse-medium norm, and the E_fm value is the medium-fine norm.

Rate = log2 (E_mc / E_fm)

For this example:

Rate = log2(4.00669e-8 / 1.99662e-08) = 1.0048

The Rate should approximate to 1, 2, 3, or 4 for Forward Euler, Trapezoid, SSPR3, and RK4 modes respectively depending on which SUNDIALs mode we test. In the example above, we can observe that the Rate approximates to 1, and thereby validates our implementation of the SUNDIALs Forward Euler time integration method. This testing process can be repeated in a similar fashion to validate the other methods.