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

add an option for cubic interp of the initial model #2659

Open
wants to merge 44 commits into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 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
ecd3302
Merge branch 'development' into add_cubic_interp
zingale Nov 30, 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
c26cb9a
Merge branch 'fix_interp' into add_cubic_interp
zingale Dec 1, 2023
55a555c
merge
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
aefb902
Merge branch 'development' into add_cubic_interp
zingale Dec 18, 2023
8cc53b0
don't limit for r < r(0)
zingale Dec 22, 2023
cfb0994
Merge branch 'development' into add_cubic_interp
zingale Dec 26, 2023
547fecf
Merge branch 'fix_interp' into add_cubic_interp
zingale Dec 26, 2023
59885de
Merge branch 'development' into add_cubic_interp
zingale Dec 26, 2023
376e79c
make this build again
zingale Dec 26, 2023
70a6a99
Merge branch 'development' into add_cubic_interp
zingale Jan 9, 2024
006ab3a
Merge branch 'development' into add_cubic_interp
zingale Jan 11, 2024
ec24f0d
Merge branch 'development' into add_cubic_interp
zingale Feb 10, 2024
71a150e
Merge branch 'development' into add_cubic_interp
zingale Apr 2, 2024
55ba4de
Merge branch 'development' into add_cubic_interp
zingale Apr 7, 2024
802dc1e
Merge branch 'development' into add_cubic_interp
zingale May 7, 2024
1784113
fix merge
zingale May 7, 2024
adc1770
Merge branch 'development' into add_cubic_interp
zingale May 29, 2024
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
20 changes: 14 additions & 6 deletions Source/driver/_cpp_parameters
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,20 @@ update_sources_after_reflux bool 1
allow_non_unit_aspect_zones int 0


#-----------------------------------------------------------------------------
# category: initialization
#-----------------------------------------------------------------------------

# for fourth order, we usually assume that the initialization is done
# to cell centers and we convert to cell-averages. With this option,
# we take the initialization as cell-averages (except for T, which we
# compute to fourth-order through the EOS after initialization).
initialization_is_cell_average bool 0

# type of interpolation to use for mapping the 1D initial model onto the
# domain. 0 = linear, 1 = cubic
model_interpolation_method int 0

#-----------------------------------------------------------------------------
# category: hydrodynamics
#-----------------------------------------------------------------------------
Expand Down Expand Up @@ -62,12 +76,6 @@ time_integration_method int 0
# do we use a limiter with the fourth-order accurate reconstruction?
limit_fourth_order bool 1

# for fourth order, we usually assume that the initialization is done
# to cell centers and we convert to cell-averages. With this option,
# we take the initialization as cell-averages (except for T, which we
# compute to fourth-order through the EOS after initialization).
initialization_is_cell_average bool 0

# should we use a reconstructed version of Gamma_1 in the Riemann
# solver? or the default zone average (requires SDC
# integration, since we do not trace)
Expand Down
64 changes: 63 additions & 1 deletion Util/model_parser/model_parser.H
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ locate(const Real r, const int model_index) {

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

// this gives us an index such that profile.r(id) < r < profile.r(id+1)

Expand Down Expand Up @@ -137,6 +137,68 @@ interpolate(const Real r, const int var_index, const int model_index=0) {
}


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

int id = locate(r, model_index);
// we will use 4 zones, id-1, id, id+1, id+2
// make sure all are valid indices
id = std::clamp(id, 1, model::npts-3);

// note: we are assuming that everything is equally spaced here

// fit a cubic of the form
// v(r) = a (r - r_i)**3 + b (r - r_i)**2 + c (r - r_i) + d
// to the data (rs, vs)
// we take r_i to be r[1]

const Real vs[4] = {model::profile(model_index).state(id-1, var_index),
model::profile(model_index).state(id, var_index),
model::profile(model_index).state(id+1, var_index),
model::profile(model_index).state(id+2, var_index)};

const Real rs[4] = {model::profile(model_index).r(id-1),
model::profile(model_index).r(id),
model::profile(model_index).r(id+1),
model::profile(model_index).r(id+2)};

const Real dx = rs[1] - rs[0];

Real a = (3 * vs[1] - 3 * vs[2] + vs[3] - vs[0]) / (6 * std::pow(dx, 3));
Real b = (-2 * vs[1] + vs[2] + vs[0]) / (2 * dx * dx);
Real c = (-3 * vs[1] + 6 * vs[2] - vs[3] - 2 * vs[0]) / (6 * dx);
Real d = vs[1];

Real interp = a * std::pow(r - rs[1], 3) + b * std::pow(r - rs[1], 2) + c * (r - rs[1]) + d;

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

return interp;
}


///
/// Find the value of model_state component var_index at point r.
/// This is a wrapper for the specific implementation of the interpolation.
///
AMREX_INLINE AMREX_GPU_HOST_DEVICE
Real
interpolate(const Real r, const int var_index, const int model_index=0) {

if (castro::model_interpolation_method == 0) {
return linear_interpolate(r, var_index, model_index);
} else {
return cubic_interpolate(r, var_index, model_index);
}
}


///
/// 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.
Expand Down
8 changes: 6 additions & 2 deletions Util/model_parser/test/main.cpp
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
#include <iostream>

#include <AMReX_ParmParse.H>
#include <model_parser.H>

#include <castro_declares.H>

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

amrex::Initialize(argc, argv);

// initialize the external runtime parameters in C++
// we need to get some castro runtime parameters
ParmParse pp("castro");
#include <castro_queries.H>

// initialize the external runtime parameters in C++
init_extern_parameters();

// now initialize the C++ Microphysics
Expand Down
Loading