Skip to content

Commit f2760cf

Browse files
authored
add a unit test for the cubic interpolation in pynucastro nets (#1891)
1 parent fbec6d8 commit f2760cf

File tree

7 files changed

+130
-1
lines changed

7 files changed

+130
-1
lines changed

Docs/source/unit_tests.rst

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ by options in the input file.
117117
One-zone tests
118118
==============
119119

120-
.. index:: burn_cell, burn_cell_primordial_chem, burn_cell_sdc, eos_cell, jac_cell, nse_table_cell, nse_net_cell, part_func_cell
120+
.. index:: burn_cell, burn_cell_primordial_chem, burn_cell_sdc, eos_cell, jac_cell, nse_table_cell, nse_net_cell, part_func_cell, interp_cell
121121

122122
* ``burn_cell`` :
123123

@@ -138,6 +138,11 @@ One-zone tests
138138
given a $\rho$, $T$, and $X_k$, call the equation of state and print out
139139
the thermodynamic information. See :ref:`sec:eos_cell` for more information.
140140

141+
* ``interp_cell`` :
142+
143+
This tests the cubic interpolant used in pynucastro networks for interpolating
144+
a rate that is given as pairs of $(T, N_A \langle \sigma v \rangle)$.
145+
141146
* ``jac_cell`` :
142147

143148
for a single thermodynamic state, compute the analytic Jacobian

unit_test/interp_cell/GNUmakefile

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
PRECISION = DOUBLE
2+
PROFILE = FALSE
3+
4+
DEBUG = FALSE
5+
6+
DIM = 3
7+
8+
COMP = gnu
9+
10+
USE_MPI = FALSE
11+
USE_OMP = FALSE
12+
13+
USE_REACT = TRUE
14+
15+
EBASE = main
16+
17+
BL_NO_FORT = TRUE
18+
19+
# define the location of the Microphysics top directory
20+
MICROPHYSICS_HOME := ../..
21+
22+
# This sets the EOS directory
23+
EOS_DIR := helmholtz
24+
25+
# This sets the network directory
26+
NETWORK_DIR := partition_test
27+
28+
CONDUCTIVITY_DIR := stellar
29+
30+
INTEGRATOR_DIR = VODE
31+
32+
EXTERN_SEARCH += .
33+
34+
Bpack := ./Make.package
35+
Blocs := .
36+
37+
include $(MICROPHYSICS_HOME)/unit_test/Make.unit_test
38+
39+

unit_test/interp_cell/Make.package

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
CEXE_sources += main.cpp
2+
CEXE_headers += interp_cell.H

unit_test/interp_cell/README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# `interp_cell`
2+
3+
Test the interpolation functions in `interp_tools.H` in the pynucastro
4+
networks.

unit_test/interp_cell/_parameters

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
@namespace: unit_test
2+
3+
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
#ifndef INTERP_CELL_H
2+
#define INTERP_CELL_H
3+
4+
#include <AMReX_Array.H>
5+
6+
#include <extern_parameters.H>
7+
8+
#include <interp_tools.H>
9+
10+
amrex::Real test_function(amrex::Real x) {
11+
amrex::Real x0{-2.5};
12+
return (2.0_rt/3.0_rt) * amrex::Math::powi<3>(x - x0) - 1.5_rt * amrex::Math::powi<2>(x - x0) + 7.0_rt * (x - x0) - 10.0_rt;
13+
}
14+
15+
AMREX_INLINE
16+
void interp_cell_c()
17+
{
18+
19+
// create some fake data
20+
// our test function is a cubic so we should fit it
21+
// exactly with out interpolation
22+
amrex::Array1D<amrex::Real, 1, 10> x_array{-3.2, -2.5, -1.23, -0.6, 0.01, 0.54, 0.98, 1.35, 1.87, 2.5};
23+
amrex::Array1D<amrex::Real, 1, 10> f_array{};
24+
std::cout << "initial data: " << std::endl;
25+
for (int i = x_array.lo(); i <= x_array.hi(); ++i) {
26+
f_array(i) = test_function(x_array(i));
27+
std::cout << x_array(i) << ", " << f_array(i) << std::endl;
28+
}
29+
std::cout << std::endl;
30+
31+
// now we see if we recover things well
32+
{
33+
amrex::Real x0{-1.1};
34+
constexpr int do_derivative = 1;
35+
const auto [f, fprime] = interp_net::cubic_interp_uneven<do_derivative>(x0, x_array, f_array);
36+
37+
std::cout << f << " " << test_function(x0) << std::endl;
38+
}
39+
40+
{
41+
amrex::Real x0{1.42};
42+
constexpr int do_derivative = 1;
43+
const auto [f, fprime] = interp_net::cubic_interp_uneven<do_derivative>(x0, x_array, f_array);
44+
45+
std::cout << f << " " << test_function(x0) << std::endl;
46+
}
47+
48+
49+
50+
51+
}
52+
#endif

unit_test/interp_cell/main.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#include <iostream>
2+
3+
#include <extern_parameters.H>
4+
#include <eos.H>
5+
#include <network.H>
6+
#include <interp_cell.H>
7+
#include <unit_test.H>
8+
9+
int main(int argc, char *argv[]) {
10+
11+
amrex::Initialize(argc, argv);
12+
13+
init_unit_test();
14+
15+
// C++ EOS initialization (must be done after init_extern_parameters)
16+
eos_init(unit_test_rp::small_temp, unit_test_rp::small_dens);
17+
18+
// C++ Network, RHS, screening, rates initialization
19+
network_init();
20+
21+
interp_cell_c();
22+
23+
amrex::Finalize();
24+
}

0 commit comments

Comments
 (0)