Skip to content

Commit

Permalink
Fix Fortran interface for FillPatch for face variables (AMReX-Codes#3541
Browse files Browse the repository at this point in the history
)

## Summary

The stride was wrong when copying MultiFab pointers from a Fortran array
to a Vector of Array of MultiFab pointers.

This also fixes cases when the user passes t_new followed by t_old,
instead of the other order. The issue was then teps was negative. This
was a minor issue, because the FillPatch function in C++ does not care
about the order.

## Additional background

AMReX-Codes#327 (comment)

## Checklist

The proposed changes:
- [x] fix a bug or incorrect behavior in AMReX
- [ ] add new capabilities to AMReX
- [ ] changes answers in the test suite to more than roundoff level
- [ ] are likely to significantly affect the results of downstream AMReX
users
- [ ] include documentation in the code and/or rst files, if appropriate
  • Loading branch information
WeiqunZhang authored Sep 14, 2023
1 parent 4c79a83 commit 5829296
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 20 deletions.
4 changes: 2 additions & 2 deletions Src/F_Interfaces/AmrCore/AMReX_fillpatch_fi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,11 +147,11 @@ extern "C"
Vector<Array<MultiFab*, AMREX_SPACEDIM> > va_fmf(nf);
for (int i = 0; i < nc; ++i) {
for (int d = 0; d < AMREX_SPACEDIM; ++d)
{ va_cmf[i][d] = cmf[i+d*AMREX_SPACEDIM]; }
{ va_cmf[i][d] = cmf[i*AMREX_SPACEDIM+d]; }
}
for (int i = 0; i < nf; ++i) {
for (int d = 0; d < AMREX_SPACEDIM; ++d)
{ va_fmf[i][d] = fmf[i+d*AMREX_SPACEDIM]; }
{ va_fmf[i][d] = fmf[i*AMREX_SPACEDIM+d]; }
}

Array<FPhysBC, AMREX_SPACEDIM> cbc{ AMREX_D_DECL( FPhysBC(cfill[0], cgeom),
Expand Down
36 changes: 18 additions & 18 deletions Src/F_Interfaces/AmrCore/AMReX_fillpatch_mod.F90
Original file line number Diff line number Diff line change
Expand Up @@ -97,12 +97,12 @@ subroutine amrex_fillpatch_single (mf, told, mfold, tnew, mfnew, geom, fill_phys
type(c_ptr) :: smf(2)
integer :: ns

teps = 1.e-4_amrex_real * (tnew - told)
if (abs(time-tnew) .lt. teps) then
teps = 1.e-4_amrex_real * abs(tnew - told)
if (abs(time-tnew) .le. teps) then
ns = 1
smf (1) = mfnew%p
stime(1) = tnew
else if (abs(time-told) .lt. teps) then
else if (abs(time-told) .le. teps) then
ns = 1
smf (1) = mfold%p
stime(1) = told
Expand Down Expand Up @@ -142,12 +142,12 @@ subroutine amrex_fillpatch_two (mf, told_c, mfold_c, tnew_c, mfnew_c, geom_c, fi
integer :: ncrse, nfine, i

! coarse level
teps = 1.e-4_amrex_real * (tnew_c - told_c)
if (abs(time-tnew_c) .lt. teps) then
teps = 1.e-4_amrex_real * abs(tnew_c - told_c)
if (abs(time-tnew_c) .le. teps) then
ncrse= 1
c_mf (1) = mfnew_c%p
c_time(1) = tnew_c
else if (abs(time-told_c) .lt. teps) then
else if (abs(time-told_c) .le. teps) then
ncrse= 1
c_mf (1) = mfold_c%p
c_time(1) = told_c
Expand All @@ -160,12 +160,12 @@ subroutine amrex_fillpatch_two (mf, told_c, mfold_c, tnew_c, mfnew_c, geom_c, fi
end if

! fine level
teps = 1.e-4_amrex_real * (tnew_f - told_f)
if (abs(time-tnew_f) .lt. teps) then
teps = 1.e-4_amrex_real * abs(tnew_f - told_f)
if (abs(time-tnew_f) .le. teps) then
nfine= 1
f_mf (1) = mfnew_f%p
f_time(1) = tnew_f
else if (abs(time-told_f) .lt. teps) then
else if (abs(time-told_f) .le. teps) then
nfine= 1
f_mf (1) = mfold_f%p
f_time(1) = told_f
Expand Down Expand Up @@ -256,14 +256,14 @@ subroutine amrex_fillpatch_two_faces(mf, told_c, mfold_c, tnew_c, mfnew_c, geom_
end do

! coarse level
teps = 1.e-4_amrex_real * (tnew_c - told_c)
if (abs(time-tnew_c) .lt. teps) then
teps = 1.e-4_amrex_real * abs(tnew_c - told_c)
if (abs(time-tnew_c) .le. teps) then
ncrse= 1
c_time(1) = tnew_c
do dim = 1, amrex_spacedim
c_mf(dim) = mfnew_c(dim)%p
end do
else if (abs(time-told_c) .lt. teps) then
else if (abs(time-told_c) .le. teps) then
ncrse= 1
c_time(1) = told_c
do dim = 1, amrex_spacedim
Expand All @@ -280,14 +280,14 @@ subroutine amrex_fillpatch_two_faces(mf, told_c, mfold_c, tnew_c, mfnew_c, geom_
end if

! fine level
teps = 1.e-4_amrex_real * (tnew_f - told_f)
if (abs(time-tnew_f) .lt. teps) then
teps = 1.e-4_amrex_real * abs(tnew_f - told_f)
if (abs(time-tnew_f) .le. teps) then
nfine= 1
f_time(1) = tnew_f
do dim = 1, amrex_spacedim
f_mf(dim) = mfnew_f(dim)%p
enddo
else if (abs(time-told_f) .lt. teps) then
else if (abs(time-told_f) .le. teps) then
nfine= 1
f_time(1) = told_f
do dim = 1, amrex_spacedim
Expand Down Expand Up @@ -353,10 +353,10 @@ subroutine amrex_fillcoarsepatch (mf, told_c, mfold_c, tnew_c, mfnew_c, &
integer :: i

! coarse level
teps = 1.e-4_amrex_real * (tnew_c - told_c)
if (abs(time-tnew_c) .lt. teps) then
teps = 1.e-4_amrex_real * abs(tnew_c - told_c)
if (abs(time-tnew_c) .le. teps) then
c_mf = mfnew_c%p
else if (abs(time-told_c) .lt. teps) then
else if (abs(time-told_c) .le. teps) then
c_mf = mfold_c%p
else
call amrex_abort("amrex_fillcoarsepatch: how did this happen?")
Expand Down

0 comments on commit 5829296

Please sign in to comment.