-
Notifications
You must be signed in to change notification settings - Fork 370
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 option to interpolate data on faces linearly in the tangential di… #3794
Merged
WeiqunZhang
merged 9 commits into
AMReX-Codes:development
from
asalmgren:face_cons_linear_interp
Mar 12, 2024
Merged
Changes from 6 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
543feb3
Add option to interpolate data on faces linearly in the tangential di…
asalmgren b1e5990
fix for compilation
asalmgren 8d447be
remove if 0 accidentally left in
asalmgren a6466d2
fix oops
asalmgren 6d7b1b8
add ignore_unused
asalmgren 7f7aa67
allow FaceConservativeLinearInterpolater even if DIM == 1
asalmgren 61f0e38
fixes based on PR feedback
asalmgren ab41da3
fix
asalmgren c41f8c9
revert to original versions of AMReX_InterpFaceReg*
asalmgren File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,8 +15,8 @@ namespace amrex { | |
|
||
// | ||
// Fill fine values with piecewise-constant interpolation of coarse data. | ||
// Operate only on faces that overlap--ie, only fill the fine faces that make up each | ||
// coarse face, leave the in-between faces alone. | ||
// Operate only on faces that overlap -- i.e., only fill the fine faces that | ||
// make up each coarse face, leave the in-between faces alone. | ||
// | ||
template<typename T> | ||
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void | ||
|
@@ -84,6 +84,154 @@ face_linear_face_interp_z (int fi, int fj, int fk, int n, Array4<T> const& fine, | |
} | ||
} | ||
|
||
// | ||
// Fill fine values with tangential interpolation of coarse data. | ||
// Operate only on faces that overlap -- i.e., only fill the fine faces that | ||
// make up each coarse face, leave the in-between faces alone. | ||
// | ||
template<typename T> | ||
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void | ||
face_cons_linear_face_interp (int i, int j, int k, int n, Array4<T> const& fine, | ||
Array4<T const> const& crse, Array4<int const> const& mask, | ||
IntVect const& ratio, Box const& per_grown_domain, int dim) noexcept | ||
{ | ||
int ci = amrex::coarsen(i, ratio[0]); | ||
|
||
#if (AMREX_SPACEDIM == 1) | ||
amrex::ignore_unused(per_grown_domain); | ||
int cj = 0; | ||
#else | ||
int cj = amrex::coarsen(j, ratio[1]); | ||
#endif | ||
|
||
#if (AMREX_SPACEDIM == 3) | ||
int ck = amrex::coarsen(k, ratio[2]); | ||
#else | ||
int ck = 0; | ||
#endif | ||
|
||
if (dim == 0 && ci*ratio[0] == i) { | ||
// Check solve mask to ensure we don't overwrite valid fine data. | ||
if (!mask || mask(ci, cj, ck, n)) { | ||
fine(i, j, k, n) = crse(ci, cj, ck, n); | ||
#if (AMREX_SPACEDIM >= 2) | ||
if (cj != per_grown_domain.smallEnd(1) && cj != per_grown_domain.bigEnd(1) && ratio[1] > 1) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is the testing necessary? The CoarsenBox function grows the coarsened box by one cell. If the testing is necessary, it might be safer to test with |
||
Real sfy = Real(1.0); | ||
Real dc = Real(0.5) * (crse(ci,cj+1,ck,n) - crse(ci,cj-1,ck,n)); | ||
Real df = Real(2.0) * (crse(ci,cj+1,ck,n) - crse(ci,cj ,ck,n)); | ||
Real db = Real(2.0) * (crse(ci,cj ,ck,n) - crse(ci,cj-1,ck,n)); | ||
Real sy = (df*db >= Real(0.0)) ? | ||
amrex::min(std::abs(df),std::abs(db)) : Real(0.); | ||
sy = std::copysign(Real(1.),dc)*amrex::min(sy,std::abs(dc)); | ||
if (dc != Real(0.0)) { | ||
sfy = amrex::min(sfy, sy / dc); | ||
} | ||
Real slope = dc; | ||
Real yoff = (static_cast<Real>(j - cj*ratio[1]) + Real(0.5)) / Real(ratio[1]) - Real(0.5); | ||
fine(i,j,k,n) += yoff * slope * sfy; | ||
} // jc | ||
#if (AMREX_SPACEDIM == 3) | ||
if (ck != per_grown_domain.smallEnd(2) && ck != per_grown_domain.bigEnd(2) && ratio[2] > 1) { | ||
Real sfz = Real(1.0); | ||
Real dc = Real(0.5) * (crse(ci,cj,ck+1,n) - crse(ci,cj,ck-1,n)); | ||
Real df = Real(2.0) * (crse(ci,cj,ck+1,n) - crse(ci,cj,ck ,n)); | ||
Real db = Real(2.0) * (crse(ci,cj,ck ,n) - crse(ci,cj,ck-1,n)); | ||
Real sz = (df*db >= Real(0.0)) ? | ||
amrex::min(std::abs(df),std::abs(db)) : Real(0.); | ||
sz = std::copysign(Real(1.),dc)*amrex::min(sz,std::abs(dc)); | ||
if (dc != Real(0.0)) { | ||
sfz = amrex::min(sfz, sz / dc); | ||
} | ||
Real slope = dc; | ||
Real zoff = (static_cast<Real>(k - ck*ratio[2]) + Real(0.5)) / Real(ratio[2]) - Real(0.5); | ||
fine(i,j,k,n) += zoff * slope * sfz; | ||
} // ck | ||
#endif | ||
#endif | ||
} // mask | ||
} // dim | ||
|
||
#if (AMREX_SPACEDIM >= 2) | ||
if (dim == 1 && cj*ratio[1] == j) { | ||
// Check solve mask to ensure we don't overwrite valid fine data. | ||
if (!mask || mask(ci, cj, ck, n)) { | ||
fine(i, j, k, n) = crse(ci, cj, ck, n); | ||
if (ci != per_grown_domain.smallEnd(0) && ci != per_grown_domain.bigEnd(0) && ratio[0] > 1) { | ||
Real sfx = Real(1.0); | ||
Real dc = Real(0.5) * (crse(ci+1,cj,ck,n) - crse(ci-1,cj,ck,n)); | ||
Real df = Real(2.0) * (crse(ci+1,cj,ck,n) - crse(ci ,cj,ck,n)); | ||
Real db = Real(2.0) * (crse(ci ,cj,ck,n) - crse(ci-1,cj,ck,n)); | ||
Real sx = (df*db >= Real(0.0)) ? | ||
amrex::min(std::abs(df),std::abs(db)) : Real(0.); | ||
sx = std::copysign(Real(1.),dc)*amrex::min(sx,std::abs(dc)); | ||
if (dc != Real(0.0)) { | ||
sfx = amrex::min(sfx, sx / dc); | ||
} | ||
Real slope = dc; | ||
Real xoff = (static_cast<Real>(i - ci*ratio[0]) + Real(0.5)) / Real(ratio[0]) - Real(0.5); | ||
fine(i,j,k,n) += xoff * slope * sfx; | ||
} // ci | ||
#if (AMREX_SPACEDIM == 3) | ||
if (ck != per_grown_domain.smallEnd(2) && ck != per_grown_domain.bigEnd(2) && ratio[2] > 1) { | ||
Real sfz = Real(1.0); | ||
Real dc = Real(0.5) * (crse(ci,cj,ck+1,n) - crse(ci,cj,ck-1,n)); | ||
Real df = Real(2.0) * (crse(ci,cj,ck+1,n) - crse(ci,cj,ck ,n)); | ||
Real db = Real(2.0) * (crse(ci,cj,ck ,n) - crse(ci,cj,ck-1,n)); | ||
Real sz = (df*db >= Real(0.0)) ? | ||
amrex::min(std::abs(df),std::abs(db)) : Real(0.); | ||
sz = std::copysign(Real(1.),dc)*amrex::min(sz,std::abs(dc)); | ||
if (dc != Real(0.0)) { | ||
sfz = amrex::min(sfz, sz / dc); | ||
} | ||
Real slope = dc; | ||
Real zoff = (static_cast<Real>(k - ck*ratio[2]) + Real(0.5)) / Real(ratio[2]) - Real(0.5); | ||
fine(i,j,k,n) += zoff * slope * sfz; | ||
} // ck | ||
#endif // SPACEDIM >= 3 | ||
} // mask | ||
} // dim == 1 | ||
#endif // SPACEDIM >= 2 | ||
|
||
#if (AMREX_SPACEDIM == 3) | ||
if (dim == 2 && ck*ratio[2] == k) { | ||
// Check solve mask to ensure we don't overwrite valid fine data. | ||
if (!mask || mask(ci, cj, ck, n)) { | ||
fine(i, j, k, n) = crse(ci, cj, ck, n); | ||
if (ci != per_grown_domain.smallEnd(0) && ci != per_grown_domain.bigEnd(0) && ratio[0] > 1) { | ||
Real sfx = Real(1.0); | ||
Real dc = Real(0.5) * (crse(ci+1,cj,ck,n) - crse(ci-1,cj,ck,n)); | ||
Real df = Real(2.0) * (crse(ci+1,cj,ck,n) - crse(ci ,cj,ck,n)); | ||
Real db = Real(2.0) * (crse(ci ,cj,ck,n) - crse(ci-1,cj,ck,n)); | ||
Real sx = (df*db >= Real(0.0)) ? | ||
amrex::min(std::abs(df),std::abs(db)) : Real(0.); | ||
sx = std::copysign(Real(1.),dc)*amrex::min(sx,std::abs(dc)); | ||
if (dc != Real(0.0)) { | ||
sfx = amrex::min(sfx, sx / dc); | ||
} | ||
Real slope = dc; | ||
Real xoff = (static_cast<Real>(i - ci*ratio[0]) + Real(0.5)) / Real(ratio[0]) - Real(0.5); | ||
fine(i,j,k,n) += xoff * slope * sfx; | ||
} // ci | ||
if (cj != per_grown_domain.smallEnd(1) && cj != per_grown_domain.bigEnd(1) && ratio[1] > 1) { | ||
Real sfy = Real(1.0); | ||
Real dc = Real(0.5) * (crse(ci,cj+1,ck,n) - crse(ci,cj-1,ck,n)); | ||
Real df = Real(2.0) * (crse(ci,cj+1,ck,n) - crse(ci,cj ,ck,n)); | ||
Real db = Real(2.0) * (crse(ci,cj ,ck,n) - crse(ci,cj-1,ck,n)); | ||
Real sy = (df*db >= Real(0.0)) ? | ||
amrex::min(std::abs(df),std::abs(db)) : Real(0.); | ||
sy = std::copysign(Real(1.),dc)*amrex::min(sy,std::abs(dc)); | ||
if (dc != Real(0.0)) { | ||
sfy = amrex::min(sfy, sy / dc); | ||
} | ||
Real slope = dc; | ||
Real yoff = (static_cast<Real>(j - cj*ratio[1]) + Real(0.5)) / Real(ratio[1]) - Real(0.5); | ||
fine(i,j,k,n) += yoff * slope * sfy; | ||
} // cj | ||
} // mask | ||
} // dim == 2 | ||
#endif | ||
} | ||
|
||
// | ||
// Do linear in dir, pc transverse to dir, leave alone the fine values | ||
// lining up with coarse edges--assume these have been set to hold the | ||
|
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't see it being used anywhere.