Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

clean up linear interpolation #2664

Merged
merged 28 commits into from
Dec 26, 2023
Merged
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
4fdc98e
add a 3D slice plot for the subchandra run
zingale Sep 17, 2023
65584e0
Merge branch 'development' of ssh://github.com/AMReX-Astro/Castro int…
zingale Sep 26, 2023
980a103
Merge branch 'development' of ssh://github.com/AMReX-Astro/Castro int…
zingale Oct 18, 2023
e09a5e1
Merge branch 'development' of ssh://github.com/AMReX-Astro/Castro int…
zingale Nov 13, 2023
2b5ea72
Merge branch 'development' of ssh://github.com/AMReX-Astro/Castro int…
zingale Nov 19, 2023
92ed2e8
Merge branch 'development' of ssh://github.com/AMReX-Astro/Castro int…
zingale Nov 26, 2023
755ee13
add an option for cubic interp of the initial model
zingale Nov 28, 2023
4ee0e7a
Merge branch 'development' into add_cubic_interp
zingale Nov 29, 2023
1f7ea68
Merge branch 'development' of ssh://github.com/AMReX-Astro/Castro int…
zingale Nov 29, 2023
362b7b7
fix an offset in the interpolation
zingale Nov 30, 2023
989b6e6
fix space
zingale Nov 30, 2023
e58be0f
Merge branch 'development' into fix_interp
zingale Nov 30, 2023
f1e6c12
add a unit test
zingale Nov 30, 2023
3fc8120
add a model parser unit test action
zingale Nov 30, 2023
9cd1cd2
Merge branch 'development' of ssh://github.com/AMReX-Astro/Castro int…
zingale Nov 30, 2023
2efe768
fix name
zingale Nov 30, 2023
6883bf8
fix castro_home
zingale Nov 30, 2023
7476a37
Merge branch 'development' into fix_interp
zingale Dec 1, 2023
8d080ab
Merge branch 'development' into fix_interp
zingale Dec 2, 2023
ba76d83
Merge branch 'development' into fix_interp
zingale Dec 17, 2023
1d965f2
fix edges
zingale Dec 17, 2023
c0ff821
add more tests
zingale Dec 18, 2023
340a1a5
more cleaning
zingale Dec 18, 2023
3ae4999
add another unit test
zingale Dec 18, 2023
5032dc4
fix comment
zingale Dec 18, 2023
2543d6c
update comment
zingale Dec 18, 2023
db0fedf
some verbosity
zingale Dec 18, 2023
8cc53b0
don't limit for r < r(0)
zingale Dec 22, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions .github/workflows/model_parser.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: model parser

on: [pull_request]
jobs:
model_parser:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Get submodules
run: |
git submodule update --init
cd external/Microphysics
git fetch; git checkout development
cd ../amrex
git fetch; git checkout development
cd ../..

- name: Install dependencies
run: |
sudo apt-get update -y -qq
sudo apt-get -qq -y install curl cmake jq clang g++>=9.3.0

- name: Compile model_parser test
run: |
cd Util/model_parser/test
make -j 4

- name: Run model_parser test
run: |
cd Util/model_parser/test
./Castro3d.gnu.ex
32 changes: 16 additions & 16 deletions Util/model_parser/model_parser.H
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ namespace model_string
}


///
/// return the index into the model coordinate, loc, such that
/// model::profile(model_index).r(loc) < r < model::profile(model_index).r(loc+1)
///
AMREX_INLINE AMREX_GPU_HOST_DEVICE
int
locate(const Real r, const int model_index) {
Expand All @@ -74,7 +78,7 @@ locate(const Real r, const int model_index) {
loc = 0;

} else if (r > model::profile(model_index).r(model::npts-2)) {
loc = model::npts-1;
loc = model::npts-2;

} else {

Expand All @@ -94,18 +98,14 @@ locate(const Real r, const int model_index) {
loc = ihi;
}

return loc;
return loc-1;
zingale marked this conversation as resolved.
Show resolved Hide resolved
}


AMREX_INLINE AMREX_GPU_HOST_DEVICE
Real
interpolate(const Real r, const int var_index, const int model_index=0) {

// find the value of model_state component var_index at point r
// using linear interpolation. Eventually, we can do something
// fancier here.

int id = locate(r, model_index);

Real slope;
Expand All @@ -119,12 +119,11 @@ interpolate(const Real r, const int var_index, const int model_index=0) {
interp = slope * (r - model::profile(model_index).r(id)) + model::profile(model_index).state(id, var_index);

// safety check to make sure interp lies within the bounding points
Real minvar = amrex::min(model::profile(model_index).state(id+1, var_index),
Real minvar = std::min(model::profile(model_index).state(id+1, var_index),
model::profile(model_index).state(id, var_index));
Real maxvar = amrex::max(model::profile(model_index).state(id+1, var_index),
Real maxvar = std::max(model::profile(model_index).state(id+1, var_index),
model::profile(model_index).state(id, var_index));
interp = amrex::max(interp, minvar);
interp = amrex::min(interp, maxvar);
interp = std::clamp(interp, minvar, maxvar);

} else if (id == model::npts-1) {

Expand All @@ -135,12 +134,11 @@ interpolate(const Real r, const int var_index, const int model_index=0) {


// safety check to make sure interp lies within the bounding points
Real minvar = amrex::min(model::profile(model_index).state(id-1, var_index),
Real minvar = std::min(model::profile(model_index).state(id-1, var_index),
model::profile(model_index).state(id, var_index));
Real maxvar = amrex::max(model::profile(model_index).state(id-1, var_index),
Real maxvar = std::max(model::profile(model_index).state(id-1, var_index),
model::profile(model_index).state(id, var_index));
interp = amrex::max(interp, minvar);
interp = amrex::min(interp, maxvar);
interp = std::clamp(interp, minvar, maxvar);

} else {

Expand All @@ -166,9 +164,11 @@ interpolate(const Real r, const int var_index, const int model_index=0) {

}

// Subsample the interpolation to get an averaged profile. For this we need to know the
// 3D coordinate (relative to the model center) and cell size.

///
/// Subsample the interpolation to get an averaged profile. For this we need to know the
/// 3D coordinate (relative to the model center) and cell size.
///
AMREX_GPU_HOST_DEVICE AMREX_INLINE
Real interpolate_3d (const Real* loc, const Real* dx, int var_index, int nsub = 1, int model_index = 0)
{
Expand Down
33 changes: 33 additions & 0 deletions Util/model_parser/test/GNUmakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
PRECISION = DOUBLE
PROFILE = FALSE

DEBUG = FALSE

DIM = 3

COMP = gnu

USE_MPI = FALSE
USE_OMP = FALSE

USE_ALL_CASTRO = FALSE
USE_AMR_CORE = FALSE

# define the location of the CASTRO top directory
CASTRO_HOME ?= ../../..

USE_MODEL_PARSER = TRUE
NUM_MODELS := 2

# This sets the EOS directory in Castro/EOS
EOS_DIR := helmholtz

# This sets the network directory in Castro/Networks
NETWORK_DIR := subch_simple

EXTERN_SEARCH += .

Bpack := ./Make.package
Blocs := . .. $(CASTRO_HOME)/Source/problems

include $(CASTRO_HOME)/Exec/Make.Castro
4 changes: 4 additions & 0 deletions Util/model_parser/test/Make.package
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
CEXE_sources += main.cpp
CEXE_sources += extern_parameters.cpp
CEXE_headers += extern_parameters.H

4 changes: 4 additions & 0 deletions Util/model_parser/test/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Unit test for model_parser

This simply reads in an initial model and does some checks to make
sure the locate and interpolation routines work as expected.
41 changes: 41 additions & 0 deletions Util/model_parser/test/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#include <iostream>

#include <model_parser.H>


int main(int argc, char *argv[]) {

amrex::Initialize(argc, argv);

// initialize the external runtime parameters in C++

init_extern_parameters();

// now initialize the C++ Microphysics
#ifdef REACTIONS
network_init();
#endif

Real small_temp = 1.e-200;
Real small_dens = 1.e-200;
eos_init(small_temp, small_dens);

std::string model = "sub_chandra.M_WD-1.10.M_He-0.050.hse.CO.N14.N.10.00km";
read_model_file(model);

Real r{3.89e7};

std::cout << "testing locate" << std::endl;

auto idx = locate(r, 0);
AMREX_ALWAYS_ASSERT(r >= model::profile(0).r(idx) &&
r <= model::profile(0).r(idx+1));

std::cout << "testing interpolate" << std::endl;

// density is monotonically decreasing
auto dens = interpolate(r, model::idens);
AMREX_ALWAYS_ASSERT(dens <= model::profile(0).state(idx, model::idens) &&
dens >= model::profile(0).state(idx+1, model::idens));

}
Loading
Loading