Skip to content

Commit

Permalink
fix compilation error
Browse files Browse the repository at this point in the history
  • Loading branch information
zhichen3 committed Sep 25, 2024
1 parent f3cd8cd commit 8129ca4
Show file tree
Hide file tree
Showing 10 changed files with 75 additions and 50 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ void problem_initialize_state_data (int i, int j, int k,
const Real* probhi = geomdata.ProbHi();

#ifdef ROTATION
auto omega = get_omega_vec(j);
auto omega = get_omega_vec(geomdata, j);
#else
// Provide a dummy value so that we can compile without rotation.
Real omega[3] = {0.0_rt, 0.0_rt, 2.0_rt * M_PI};
Expand Down
9 changes: 5 additions & 4 deletions Exec/science/wdmerger/Prob.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -798,6 +798,7 @@ Castro::update_relaxation(Real time, Real dt) {
get_lagrange_points(mass_P, mass_S, com_P, com_S, L1, L2, L3);

const auto dx = geom.CellSizeArray();
const auto coord = geom.Coord();
GeometryData geomdata = geom.data();

MultiFab& phi_new = get_new_data(PhiGrav_Type);
Expand Down Expand Up @@ -833,8 +834,8 @@ Castro::update_relaxation(Real time, Real dt) {

// Compute the effective potential.

auto omega = get_omega_vec(j);
Real phiEff = phi(i,j,k) + rotational_potential(r, omega);
auto omega = get_omega_vec(geomdata, j);
Real phiEff = phi(i,j,k) + rotational_potential(r, omega, coord);

for (int n = 0; n < 3; ++n) {
r[n] -= L1[n];
Expand Down Expand Up @@ -902,8 +903,8 @@ Castro::update_relaxation(Real time, Real dt) {
GpuArray<Real, 3> r;
position(i, j, k, geomdata, r);

auto omega = get_omega_vec(j);
Real phiEff = phi(i,j,k) + rotational_potential(r, omega);
auto omega = get_omega_vec(geomdata, j);
Real phiEff = phi(i,j,k) + rotational_potential(r, omega, coord);

Real done = 0.0_rt;

Expand Down
24 changes: 16 additions & 8 deletions Exec/science/wdmerger/Problem_Derive.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,8 @@ void ca_derphieff(const Box& bx, FArrayBox& derfab, int /*dcomp*/, int /*ncomp*/

const auto dx = geom.CellSizeArray();
const auto problo = geom.ProbLoArray();
const auto coord = geom.Coord();
const auto geomdata = geom.data();

amrex::ParallelFor(bx,
[=] AMREX_GPU_HOST_DEVICE (int i, int j, int k)
Expand All @@ -438,9 +440,9 @@ void ca_derphieff(const Box& bx, FArrayBox& derfab, int /*dcomp*/, int /*ncomp*/
#else
loc[2] = 0.0_rt;
#endif
auto omega = get_omega_vec(j);
auto omega = get_omega_vec(geomdata, j);

der(i,j,k,0) = dat(i,j,k,0) + rotational_potential(loc, omega);
der(i,j,k,0) = dat(i,j,k,0) + rotational_potential(loc, omega, coord);
});
}

Expand All @@ -459,6 +461,8 @@ void ca_derphieffpm_p(const Box& bx, FArrayBox& derfab, int /*dcomp*/, int /*nco

const auto dx = geom.CellSizeArray();
const auto problo = geom.ProbLoArray();
const auto coord = geom.Coord();
const auto geomdata = geom.data();

amrex::ParallelFor(bx,
[=] AMREX_GPU_HOST_DEVICE (int i, int j, int k)
Expand Down Expand Up @@ -493,9 +497,9 @@ void ca_derphieffpm_p(const Box& bx, FArrayBox& derfab, int /*dcomp*/, int /*nco
loc[iloc] -= problem::center[iloc];
}

auto omega = get_omega_vec(j);
auto omega = get_omega_vec(geomdata, j);

der(i,j,k,0) = -C::Gconst * problem::mass_P / r + rotational_potential(loc, omega);
der(i,j,k,0) = -C::Gconst * problem::mass_P / r + rotational_potential(loc, omega, coord);
});
}

Expand All @@ -511,6 +515,8 @@ void ca_derphieffpm_s(const Box& bx, FArrayBox& derfab, int /*dcomp*/, int /*nco

const auto dx = geom.CellSizeArray();
const auto problo = geom.ProbLoArray();
const auto coord = geom.Coord();
const auto geomdata = geom.data();

amrex::ParallelFor(bx,
[=] AMREX_GPU_HOST_DEVICE (int i, int j, int k)
Expand Down Expand Up @@ -545,9 +551,9 @@ void ca_derphieffpm_s(const Box& bx, FArrayBox& derfab, int /*dcomp*/, int /*nco
loc[iloc] -= problem::center[iloc];
}

auto omega = get_omega_vec(j);
auto omega = get_omega_vec(geomdata, j);

der(i,j,k,0) = -C::Gconst * problem::mass_S / r + rotational_potential(loc, omega);
der(i,j,k,0) = -C::Gconst * problem::mass_S / r + rotational_potential(loc, omega, coord);
});
}

Expand Down Expand Up @@ -577,6 +583,8 @@ void ca_derrhophiRot(const Box& bx, FArrayBox& derfab, int /*dcomp*/, int /*ncom

const auto dx = geom.CellSizeArray();
const auto problo = geom.ProbLoArray();
const auto coord = geom.Coord();
const auto geomdata = geom.data();

amrex::ParallelFor(bx,
[=] AMREX_GPU_HOST_DEVICE (int i, int j, int k)
Expand All @@ -597,9 +605,9 @@ void ca_derrhophiRot(const Box& bx, FArrayBox& derfab, int /*dcomp*/, int /*ncom
loc[2] = 0.0_rt;
#endif

auto omega = get_omega_vec(j);
auto omega = get_omega_vec(geomdata, j);

der(i,j,k,0) = dat(i,j,k,0) * rotational_potential(loc, omega);
der(i,j,k,0) = dat(i,j,k,0) * rotational_potential(loc, omega, coord);
});
}

Expand Down
2 changes: 1 addition & 1 deletion Exec/science/wdmerger/problem_initialize_state_data.H
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ void problem_initialize_state_data (int i, int j, int k,
// or secondary (in which case interpolate from the respective model)
// or if we are in an ambient zone.

auto omega = get_omega_vec(j);
auto omega = get_omega_vec(geomdata, j);

GpuArray<Real, 3> loc;
position(i, j, k, geomdata, loc);
Expand Down
4 changes: 2 additions & 2 deletions Exec/science/wdmerger/wdmerger_util.H
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,9 @@ Real stellar_mask (int i, int j, int k,
loc[iloc] -= problem::center[iloc];
}

auto omega = get_omega_vec(j);
auto omega = get_omega_vec(geomdata, j);

Real phi_rot = rotational_potential(loc, omega);
Real phi_rot = rotational_potential(loc, omega, geomdata.Coord());

Real phi_p = -C::Gconst * problem::mass_P / r_P + phi_rot;
Real phi_s = -C::Gconst * problem::mass_S / r_S + phi_rot;
Expand Down
3 changes: 1 addition & 2 deletions Source/driver/sum_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@ Castro::gwstrain (Real time,

GpuArray<Real, 3> pos{r};
#ifdef ROTATION
auto omega = get_omega_vec(j);
auto omega = get_omega_vec(geomdata, j);
pos = inertial_rotation(r, omega, time);
#endif

Expand Down Expand Up @@ -432,7 +432,6 @@ Castro::gwstrain (Real time,

GpuArray<Real, 3> inertial_g{g};
#ifdef ROTATION
auto omega = get_omega_vec(j);
inertial_g = inertial_rotation(g, omega, time);
#endif

Expand Down
35 changes: 23 additions & 12 deletions Source/rotation/Rotation.H
Original file line number Diff line number Diff line change
Expand Up @@ -29,20 +29,21 @@ Real get_omega()
/// Return the omega vector corresponding to the current rotational period
///
AMREX_GPU_HOST_DEVICE AMREX_INLINE
GpuArray<Real, 3> get_omega_vec(const int j)
GpuArray<Real, 3> get_omega_vec(const GeometryData& geomdata,
const int j)
{
GpuArray<Real, 3> omega_vec = {0.0_rt};

const auto coord = geom.Coord();
const auto problo = geom.ProbLoArray();
const auto dx = geom.CellSizeArray();
const auto coord = geomdata.Coord();
const auto problo = geomdata.ProbLo(1);
const auto dtheta = geomdata.CellSize(1);

auto omega = get_omega();

// If coord == 2, i.e. Spherical2D, then it is assumed that rotational axis is in z-axis
// then we convert back to r and theta direction.
if (coord == 2) {
Real theta = problo[1] + (static_cast<Real>(j) + 0.5_rt) * dx[1];
Real theta = problo + (static_cast<Real>(j) + 0.5_rt) * dtheta;
omega_vec[0] = std::cos(theta) * omega;
omega_vec[1] = -std::sin(theta) * omega;
} else {
Expand All @@ -58,13 +59,15 @@ GpuArray<Real, 3> get_omega_vec(const int j)
///
/// @param r distance from origin of rotation vector
/// @param v velocity
/// @param omega angular velocity vector array
/// @param coord coordinate system
/// @param coriolis do we include the Coriolis force
/// @param Sr rotational acceleration
///
AMREX_GPU_HOST_DEVICE AMREX_INLINE
void
rotational_acceleration(const GpuArray<Real, 3>& r, const GpuArray<Real, 3>& v,
const GpuArray<Real, 3>& omega,
const GpuArray<Real, 3>& omega, const int coord,
const bool coriolis, Real* Sr) {

// Given a position and velocity, calculate
Expand All @@ -90,7 +93,6 @@ rotational_acceleration(const GpuArray<Real, 3>& r, const GpuArray<Real, 3>& v,

bool c2 = (castro::rotation_include_coriolis == 1 && coriolis) ? true : false;

const auto coord = geom.Coord();
auto r_vec = r;

GpuArray<Real, 3> omega_cross_v;
Expand Down Expand Up @@ -125,14 +127,13 @@ rotational_acceleration(const GpuArray<Real, 3>& r, const GpuArray<Real, 3>& v,

AMREX_GPU_HOST_DEVICE AMREX_INLINE
Real
rotational_potential(const GpuArray<Real, 3>& r, const GpuArray<Real, 3>& omega) {
rotational_potential(const GpuArray<Real, 3>& r, const GpuArray<Real, 3>& omega,
const int coord) {

// Construct rotational potential, phi_R = -1/2 | omega x r |**2
//

Real phi = 0.0_rt;

const auto coord = geom.Coord();
auto r_vec = r;

if (coord == 2) {
Expand Down Expand Up @@ -176,7 +177,12 @@ inertial_to_rotational_velocity (const int i, const int j, const int k,
loc[dir] -= problem::center[dir];
}

auto omega = get_omega_vec(j);
if (geomdata.Coord() == 2) {
loc[1] = 0.0_rt;
loc[2] = 0.0_rt;
}

auto omega = get_omega_vec(geomdata, j);

// do the cross product Omega x loc
v[0] += -(omega[1]*loc[2] - omega[2]*loc[1]);
Expand Down Expand Up @@ -206,7 +212,12 @@ rotational_to_inertial_velocity (const int i, const int j, const int k,
loc[dir] -= problem::center[dir];
}

auto omega = get_omega_vec(j);
if (geomdata.Coord() == 2) {
loc[1] = 0.0_rt;
loc[2] = 0.0_rt;
}

auto omega = get_omega_vec(geomdata, j);

// do the cross product Omega x loc
v[0] += (omega[1]*loc[2] - omega[2]*loc[1]);
Expand Down
13 changes: 7 additions & 6 deletions Source/rotation/Rotation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,13 @@ Castro::fill_rotational_psi(const Box& bx,
// routine uniquely determines the rotation law. For the other
// rotation laws, we would simply divide by v_0^2 or j_0^2 instead.

auto omega = get_omega();
const auto omega = get_omega();
Real denom = omega * omega;

auto problo = geom.ProbLoArray();

auto dx = geom.CellSizeArray();
const auto problo = geom.ProbLoArray();
const auto dx = geom.CellSizeArray();
const auto coord = geom.Coord();
const auto geomdata = geom.data();

amrex::ParallelFor(bx,
[=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept
Expand All @@ -44,8 +45,8 @@ Castro::fill_rotational_psi(const Box& bx,
#endif

if (denom != 0.0) {
auto omega = get_omega_vec(j);
psi(i,j,k) = rotational_potential(r, omega) / denom;
auto omega = get_omega_vec(geomdata, j);
psi(i,j,k) = rotational_potential(r, omega, coord) / denom;
}
else {
psi(i,j,k) = 0.0;
Expand Down
18 changes: 10 additions & 8 deletions Source/rotation/rotation_sources.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Castro::rsrc(const Box& bx,
const Real dt) {

GeometryData geomdata = geom.data();
const auto coord = geomdata.Coord();

amrex::ParallelFor(bx,
[=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept
Expand All @@ -31,7 +32,7 @@ Castro::rsrc(const Box& bx,
loc[dir] -= problem::center[dir];
}

auto omega = get_omega_vec(j);
auto omega = get_omega_vec(geomdata, j);

Real rho = uold(i,j,k,URHO);
Real rhoInv = 1.0_rt / rho;
Expand All @@ -49,7 +50,7 @@ Castro::rsrc(const Box& bx,
v[2] = uold(i,j,k,UMZ) * rhoInv;

bool coriolis = true;
rotational_acceleration(loc, v, omega, coriolis, Sr);
rotational_acceleration(loc, v, omega, coord, coriolis, Sr);

for (auto& e : Sr) {
e *= rho;
Expand Down Expand Up @@ -169,6 +170,7 @@ Castro::corrrsrc(const Box& bx,
// is the new time at time-level n+1.

GeometryData geomdata = geom.data();
const auto coord = geomdata.Coord();

Real hdtInv = 0.5_rt / dt;

Expand Down Expand Up @@ -200,7 +202,7 @@ Castro::corrrsrc(const Box& bx,
loc[dir] -= problem::center[dir];
}

auto omega = get_omega_vec(j);
auto omega = get_omega_vec(geomdata, j);

Real rhoo = uold(i,j,k,URHO);
Real rhooinv = 1.0_rt / uold(i,j,k,URHO);
Expand All @@ -224,7 +226,7 @@ Castro::corrrsrc(const Box& bx,
vold[2] = uold(i,j,k,UMZ) * rhooinv;

bool coriolis = true;
rotational_acceleration(loc, vold, omega, coriolis, Sr_old);
rotational_acceleration(loc, vold, omega, coord, coriolis, Sr_old);

for (auto& e : Sr_old) {
e *= rhoo;
Expand All @@ -241,7 +243,7 @@ Castro::corrrsrc(const Box& bx,
vnew[1] = unew(i,j,k,UMY) * rhoninv;
vnew[2] = unew(i,j,k,UMZ) * rhoninv;

rotational_acceleration(loc, vnew, omega, coriolis, Sr_new);
rotational_acceleration(loc, vnew, omega, coord, coriolis, Sr_new);

for (auto& e : Sr_new) {
e *= rhon;
Expand All @@ -266,7 +268,7 @@ Castro::corrrsrc(const Box& bx,

Real acc[3];
coriolis = false;
rotational_acceleration(loc, vnew, omega, coriolis, acc);
rotational_acceleration(loc, vnew, omega, coord, coriolis, acc);

Real new_mom_tmp[3];
for (int n = 0; n < 3; n++) {
Expand Down Expand Up @@ -358,7 +360,7 @@ Castro::corrrsrc(const Box& bx,

Real acc[3];
coriolis = true;
rotational_acceleration(loc, vnew, omega, coriolis, acc);
rotational_acceleration(loc, vnew, omega, coord, coriolis, acc);

Sr_new[0] = rhon * acc[0];
Sr_new[1] = rhon * acc[1];
Expand Down Expand Up @@ -416,7 +418,7 @@ Castro::corrrsrc(const Box& bx,
Real temp_Sr[3];

coriolis = false;
rotational_acceleration(loc, temp_vel, omega, coriolis, temp_Sr);
rotational_acceleration(loc, temp_vel, omega, coord, coriolis, temp_Sr);

edge_Sr[dir][edge] = temp_Sr[dir];

Expand Down
Loading

0 comments on commit 8129ca4

Please sign in to comment.