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

Convert sphe to C++ #2579

Merged
merged 2 commits into from
Sep 24, 2023
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
15 changes: 0 additions & 15 deletions Source/radiation/RAD_1D.F90
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,6 @@ module rad_module

contains

subroutine sphe(r, s, n, &
DIMS(reg), dx) bind(C, name="sphe")
use amrex_fort_module, only : rt => amrex_real
implicit none
integer :: DIMDEC(reg)
real(rt) :: r(reg_l1:reg_h1)
real(rt) :: s(1)
integer :: n
real(rt) :: dx(1)
integer :: i
do i = reg_l1, reg_h1
r(i) = r(i)**2
enddo
end subroutine sphe

subroutine rfface(fine, &
DIMS(fbox), &
crse, &
Expand Down
32 changes: 0 additions & 32 deletions Source/radiation/RAD_2D.F90
Original file line number Diff line number Diff line change
Expand Up @@ -11,38 +11,6 @@ module rad_module

contains

subroutine sphe(r, s, n, &
DIMS(reg), dx) bind(C, name="sphe")

use amrex_fort_module, only : rt => amrex_real
integer :: DIMDEC(reg)
real(rt) :: r(reg_l1:reg_h1)
real(rt) :: s(reg_l2:reg_h2)
integer :: n
real(rt) :: dx(2)
real(rt) :: h1, h2, d1, d2
integer :: i, j
if (n == 0) then
do i = reg_l1, reg_h1
r(i) = r(i)**2
enddo
h2 = 0.5e0_rt * dx(2)
d2 = 1.e0_rt / dx(2)
do j = reg_l2, reg_h2
s(j) = d2 * (cos(s(j) - h2) - cos(s(j) + h2))
enddo
else
h1 = 0.5e0_rt * dx(1)
d1 = 1.e0_rt / (3.e0_rt * dx(1))
do i = reg_l1, reg_h1
r(i) = d1 * ((r(i) + h1)**3 - (r(i) - h1)**3)
enddo
do j = reg_l2, reg_h2
s(j) = sin(s(j))
enddo
endif
end subroutine sphe

subroutine rfface(fine, &
DIMS(fbox), &
crse, &
Expand Down
32 changes: 0 additions & 32 deletions Source/radiation/RAD_3D.F90
Original file line number Diff line number Diff line change
Expand Up @@ -14,38 +14,6 @@ module rad_module
! The following routines implement metric terms in 2D and are included
! in the 3D source only to enable the code to link.

subroutine sphe(r, s, n, &
DIMS(reg), dx) bind(C, name="sphe")

use amrex_fort_module, only : rt => amrex_real
integer :: DIMDEC(reg)
real(rt) :: r(reg_l1:reg_h1)
real(rt) :: s(reg_l2:reg_h2)
integer :: n
real(rt) :: dx(2)
real(rt) :: h1, h2, d1, d2
integer :: i, j
if (n == 0) then
do i = reg_l1, reg_h1
r(i) = r(i)**2
enddo
h2 = 0.5e0_rt * dx(2)
d2 = 1.e0_rt / dx(2)
do j = reg_l2, reg_h2
s(j) = d2 * (cos(s(j) - h2) - cos(s(j) + h2))
enddo
else
h1 = 0.5e0_rt * dx(1)
d1 = 1.e0_rt / (3.e0_rt * dx(1))
do i = reg_l1, reg_h1
r(i) = d1 * ((r(i) + h1)**3 - (r(i) - h1)**3)
enddo
do j = reg_l2, reg_h2
s(j) = sin(s(j))
enddo
endif
end subroutine sphe

subroutine rfface(fine, &
DIMS(fbox), &
crse, &
Expand Down
3 changes: 0 additions & 3 deletions Source/radiation/RAD_F.H
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,6 @@ extern "C"
#ifdef __cplusplus
extern "C" {
#endif
void sphe(amrex::Real* r, amrex::Real* s, const int& idim,
ARLIM_P(edgeboxlo), ARLIM_P(edgeboxhi), const amrex::Real* dx);

void fkpn(const int* lo, const int* hi,
BL_FORT_FAB_ARG_3D(fkp),
amrex::Real con, amrex::Real em, amrex::Real en,
Expand Down
42 changes: 37 additions & 5 deletions Source/radiation/RadSolve.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -877,9 +877,18 @@ void RadSolve::levelDterm(int level, MultiFab& Dterm, MultiFab& Er, int igroup)
parent->Geom(level).GetCellLoc(rc, reg, 0);
parent->Geom(level).GetCellLoc(s, reg, 0);
const Box &dbox = Dterm_face[0][fi].box();
sphe(re.dataPtr(), s.dataPtr(), 0,
ARLIM(dbox.loVect()), ARLIM(dbox.hiVect()), dx.data());


for (int i = dbox.loVect()[0]; i <= dbox.hiVect()[0]; ++i) {
re[i] *= re[i];
}
#if AMREX_SPACEDIM >= 2
Real h2 = 0.5e0_rt * dx[1];
Real d2 = 1.e0_rt / dx[1];
for (int j = dbox.loVect()[1]; j <= dbox.hiVect()[1]; ++j) {
s[j] = d2 * (std::cos(s[j] - h2) - std::cos(s[j] + h2));
}
#endif

ca_correct_dterm(D_DECL(BL_TO_FORTRAN(Dterm_face[0][fi]),
BL_TO_FORTRAN(Dterm_face[1][fi]),
BL_TO_FORTRAN(Dterm_face[2][fi])),
Expand Down Expand Up @@ -1160,8 +1169,31 @@ void RadSolve::getEdgeMetric(int idim, const Geometry& geom, const Box& edgebox,
geom.GetEdgeLoc(s, reg, I);
}
const Real *dx = geom.CellSize();
sphe(r.dataPtr(), s.dataPtr(), idim,
ARLIM(edgebox.loVect()), ARLIM(edgebox.hiVect()), dx);

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

aren't we missing the 1-d case here, r = r**2?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and the n = 0 case for multid?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed, I think

if (idim == 0) {
for (int i = edgebox.loVect()[0]; i <= edgebox.hiVect()[0]; ++i) {
r[i] *= r[i];
}
#if AMREX_SPACEDIM >= 2
Real h2 = 0.5e0_rt * dx[1];
Real d2 = 1.e0_rt / dx[1];
for (int j = edgebox.loVect()[1]; j <= edgebox.hiVect()[1]; ++j) {
s[j] = d2 * (std::cos(s[j] - h2) - std::cos(s[j] + h2));
}
#endif
}
else {
Real h1 = 0.5e0_rt * dx[0];
Real d1 = 1.e0_rt / (3.e0_rt * dx[0]);
for (int i = edgebox.loVect()[0]; i <= edgebox.hiVect()[0]; ++i) {
r[i] = d1 * (std::pow(r[i] + h1, 3) - std::pow(r[i] - h1, 3));
}
#if AMREX_SPACEDIM >= 2
for (int j = edgebox.loVect()[1]; j <= edgebox.hiVect()[1]; ++j) {
s[j] = std::sin(s[j]);
}
#endif
}
}
}