Skip to content

Commit

Permalink
sundials cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
ajnonaka committed Jul 12, 2024
1 parent d47e05a commit 9069d24
Show file tree
Hide file tree
Showing 5 changed files with 118 additions and 40 deletions.
50 changes: 50 additions & 0 deletions ExampleCodes/SUNDIALS/Exec/inputs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
n_cell = 32
max_grid_size = 16

nsteps = 5
plot_int = 5
dt = 1.e-4

#nsteps = 10
#plot_int = 10
#dt = 5.e-5

#nsteps = 20
#plot_int = 20
#dt = 2.5e-5

adapt_dt = true

# INTEGRATION
## integration.type can take on the following values:
## 0 or "ForwardEuler" => Native AMReX Forward Euler integrator
## 1 or "RungeKutta" => Native AMReX Explicit Runge Kutta controlled by integration.rk.type
## 2 or "SUNDIALS" => SUNDIALS backend controlled by integration.sundials.strategy
integration.type = ForwardEuler
#integration.type = RungeKutta
#integration.type = SUNDIALS

## Native AMReX Explicit Runge-Kutta parameters
#
## 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
integration.rk.type = 1

# Set the SUNDIALS method type:
# ERK = Explicit Runge-Kutta method
# DIRK = Diagonally Implicit Runge-Kutta method
#
# Optionally select a specific SUNDIALS method by name, see the SUNDIALS
# documentation for the supported method names

# Use forward Euler (fixed step sizes only)
integration.sundials.type = ERK
integration.sundials.method = ARKODE_FORWARD_EULER_1_1

# Use backward Euler (fixed step sizes only)
#integration.sundials.type = DIRK
#integration.sundials.method = ARKODE_BACKWARD_EULER_1_1
14 changes: 0 additions & 14 deletions ExampleCodes/SUNDIALS/Exec/inputs_forward_euler

This file was deleted.

24 changes: 0 additions & 24 deletions ExampleCodes/SUNDIALS/Exec/inputs_rk3

This file was deleted.

18 changes: 16 additions & 2 deletions ExampleCodes/SUNDIALS/Source/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ void main_main ()
pp.query("reltol",reltol);
pp.query("abstol",abstol);
}

// **********************************
// SIMULATION SETUP

Expand Down Expand Up @@ -129,6 +129,9 @@ void main_main ()
// time = starting time in the simulation
Real time = 0.0;

Print() << "dt = " << dt << std::endl;
Print() << "Diffusive CFL time step = " << dx[0]*dx[0]/(2.*AMREX_SPACEDIM) << std::endl;

// **********************************
// INITIALIZE DATA

Expand Down Expand Up @@ -203,16 +206,23 @@ void main_main ()
integrator.set_time_step(dt);
}

Real evolution_start_time = ParallelDescriptor::second();

for (int step = 1; step <= nsteps; ++step)
{
// Set time to evolve to
time += dt;

Real step_start_time = ParallelDescriptor::second();

// Advance to output time
integrator.evolve(phi, time);

Real step_stop_time = ParallelDescriptor::second() - step_start_time;
ParallelDescriptor::ReduceRealMax(step_stop_time);

// Tell the I/O Processor to write out which step we're doing
amrex::Print() << "Advanced step " << step << "\n";
amrex::Print() << "Advanced step " << step << " in " << step_stop_time << " seconds; time = " << time << "\n";

// Write a plotfile of the current data (plot_int was defined in the inputs file)
if (plot_int > 0 && step%plot_int == 0)
Expand All @@ -221,4 +231,8 @@ void main_main ()
WriteSingleLevelPlotfile(pltfile, phi, {"phi"}, geom, time, step);
}
}

Real evolution_stop_time = ParallelDescriptor::second() - evolution_start_time;
ParallelDescriptor::ReduceRealMax(evolution_stop_time);
amrex::Print() << "Total evolution time = " << evolution_stop_time << " seconds\n";
}
52 changes: 52 additions & 0 deletions ExampleCodes/SUNDIALS_Multirate/Exec/inputs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
n_cell = 32
max_grid_size = 16

nsteps = 5
plot_int = 5
dt = 1.e-4

#nsteps = 10
#plot_int = 10
#dt = 5.e-5

#nsteps = 20
#plot_int = 20
#dt = 2.5e-5

# INTEGRATION
## integration.type can take on the following values:
## 0 or "ForwardEuler" => Native AMReX Forward Euler integrator
## 1 or "RungeKutta" => Native AMReX Explicit Runge Kutta --- controlled by integration.rk.type
## 2 or "SUNDIALS" => SUNDIALS backend --- controlled by integration.sundials.type
integration.type = ForwardEuler
integration.type = RungeKutta
integration.type = SUNDIALS

## Native AMReX Explicit Runge-Kutta parameters
#
## 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
integration.rk.type = 1

# Set the SUNDIALS method type:
# ERK = Explicit Runge-Kutta method
# DIRK = Diagonally Implicit Runge-Kutta method
# IMEX-RK = Implicit-Explicit Additive Runge-Kutta method
# EX-MRI = Explicit Multirate Infatesimal method
# IM-MRI = Implicit Multirate Infatesimal method
# IMEX-MRI = Implicit-Explicit Multirate Infatesimal method
#
# Optionally select a specific SUNDIALS method by name, see the SUNDIALS
# documentation for the supported method names

# Use forward Euler (fixed step sizes only)
integration.sundials.type = ERK
integration.sundials.method = ARKODE_FORWARD_EULER_1_1

# Use backward Euler (fixed step sizes only)
#integration.sundials.type = DIRK
#integration.sundials.method = ARKODE_BACKWARD_EULER_1_1

0 comments on commit 9069d24

Please sign in to comment.