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

CartesianGrid: allow dynamic resizing #624

Merged
merged 1 commit into from
Jan 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
64 changes: 45 additions & 19 deletions src/utils/cart_grid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
// constructor, initializes data structures and parameters

CartesianGrid::CartesianGrid(MeshBlockPack *pmy_pack, Real center[3],
Real extend[3], int numpoints[3], bool is_cheb):
Real extent[3], int numpoints[3], bool is_cheb):
pmy_pack(pmy_pack),
interp_indcs("interp_indcs",1,1,1,1),
interp_wghts("interp_wghts",1,1,1,1,1),
Expand All @@ -37,19 +37,19 @@ CartesianGrid::CartesianGrid(MeshBlockPack *pmy_pack, Real center[3],
center_x3 = center[2];

// grid center
extend_x1 = extend[0];
extend_x2 = extend[1];
extend_x3 = extend[2];
extent_x1 = extent[0];
extent_x2 = extent[1];
extent_x3 = extent[2];

// lower bound
min_x1 = center_x1 - extend_x1;
min_x2 = center_x2 - extend_x2;
min_x3 = center_x3 - extend_x3;
min_x1 = center_x1 - extent_x1;
min_x2 = center_x2 - extent_x2;
min_x3 = center_x3 - extent_x3;

// upper bound
max_x1 = center_x1 + extend_x1;
max_x2 = center_x2 + extend_x2;
max_x3 = center_x3 + extend_x3;
max_x1 = center_x1 + extent_x1;
max_x2 = center_x2 + extent_x2;
max_x3 = center_x3 + extent_x3;

// number of points
nx1 = numpoints[0];
Expand Down Expand Up @@ -83,14 +83,40 @@ void CartesianGrid::ResetCenter(Real center[3]) {
center_x3 = center[2];

// lower bound
min_x1 = center_x1 - extend_x1;
min_x2 = center_x2 - extend_x2;
min_x3 = center_x3 - extend_x3;
min_x1 = center_x1 - extent_x1;
min_x2 = center_x2 - extent_x2;
min_x3 = center_x3 - extent_x3;

// upper bound
max_x1 = center_x1 + extend_x1;
max_x2 = center_x2 + extend_x2;
max_x3 = center_x3 + extend_x3;
max_x1 = center_x1 + extent_x1;
max_x2 = center_x2 + extent_x2;
max_x3 = center_x3 + extent_x3;

SetInterpolationIndices();
SetInterpolationWeights();
}

void CartesianGrid::ResetCenterAndExtent(Real center[3], Real extent[3]) {
// grid center
center_x1 = center[0];
center_x2 = center[1];
center_x3 = center[2];

// grid extent
extent_x1 = extent[0];
extent_x2 = extent[1];
extent_x3 = extent[2];

// lower bound
min_x1 = center_x1 - extent_x1;
min_x2 = center_x2 - extent_x2;
min_x3 = center_x3 - extent_x3;

// upper bound
max_x1 = center_x1 + extent_x1;
max_x2 = center_x2 + extent_x2;
max_x3 = center_x3 + extent_x3;

SetInterpolationIndices();
SetInterpolationWeights();
}
Expand All @@ -108,9 +134,9 @@ void CartesianGrid::SetInterpolationIndices() {
Real x2 = min_x2 + ny * d_x2;
Real x3 = min_x3 + nz * d_x3;
if (is_cheby) {
x1 = center_x1 + extend_x1*std::cos(nx*M_PI/(nx1-1));
x2 = center_x2 + extend_x2*std::cos(ny*M_PI/(nx2-1));
x3 = center_x3 + extend_x3*std::cos(nz*M_PI/(nx3-1));
x1 = center_x1 + extent_x1*std::cos(nx*M_PI/(nx1-1));
x2 = center_x2 + extent_x2*std::cos(ny*M_PI/(nx2-1));
x3 = center_x3 + extent_x3*std::cos(nz*M_PI/(nx3-1));
}
// indices default to -1 if point does not reside in this MeshBlockPack
iindcs.h_view(nx,ny,nz,0) = -1;
Expand Down
5 changes: 3 additions & 2 deletions src/utils/cart_grid.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class CartesianGrid {
public:
// Creates a geodesic grid with refinement level nlev and radius rad
CartesianGrid(MeshBlockPack *pmy_pack, Real center[3],
Real extend[3], int numpoints[3], bool is_cheb = false);
Real extent[3], int numpoints[3], bool is_cheb = false);
~CartesianGrid();

// parameters for the grid
Expand All @@ -30,7 +30,7 @@ class CartesianGrid {
Real max_x1, max_x2, max_x3; // max value for xyz
Real d_x1, d_x2, d_x3; // resolution
int nx1, nx2, nx3; // number of points
Real extend_x1, extend_x2, extend_x3;
Real extent_x1, extent_x2, extent_x3;

// dump on chebyshev or uniform grid, default is uniform
bool is_cheby;
Expand All @@ -39,6 +39,7 @@ class CartesianGrid {
DualArray3D<Real> interp_vals; // container for data interpolated to sphere
void InterpolateToGrid(int nvars, DvceArray5D<Real> &val); // interpolate to sphere
void ResetCenter(Real center[3]); // set indexing for interpolation
void ResetCenterAndExtent(Real center[3], Real extent[3]);

private:
MeshBlockPack* pmy_pack; // ptr to MeshBlockPack containing this Hydro
Expand Down