-
Notifications
You must be signed in to change notification settings - Fork 318
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
alternative numerical solutions for drainage of ponded water
- Loading branch information
Showing
3 changed files
with
130 additions
and
3 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
module computeFluxMod | ||
|
||
! provides interface for the flux modules | ||
|
||
USE nrtype | ||
implicit none | ||
|
||
abstract interface | ||
subroutine fluxTemplate(x,f,dfdx) | ||
USE nrtype | ||
implicit none | ||
real(dp), intent(in) :: x ! state | ||
real(dp), intent(out) :: f ! f(x) | ||
real(dp), intent(out), optional :: dfdx ! derivative | ||
end subroutine fluxTemplate | ||
end interface | ||
|
||
contains | ||
|
||
subroutine getFlux(func, x, f, dfdx) | ||
procedure(fluxTemplate), pointer :: func | ||
real(dp), intent(in) :: x ! state | ||
real(dp), intent(out) :: f ! f(x) | ||
real(dp), intent(out),optional :: dfdx ! derivative | ||
call func(x,f,dfdx) | ||
end subroutine getFlux | ||
|
||
end module computeFluxMod |
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 |
---|---|---|
@@ -0,0 +1,49 @@ | ||
module implicitEulerMod | ||
|
||
USE nrtype | ||
USE computeFluxMod | ||
implicit none | ||
|
||
contains | ||
|
||
subroutine implicitEuler(funcName, dt, xInit, xNew, err, message) | ||
! dummy variables | ||
procedure(fluxTemplate), pointer :: funcName | ||
real(dp), intent(in) :: dt ! time step | ||
real(dp), intent(in) :: xInit ! initial state | ||
real(dp), intent(out) :: xNew ! updated state | ||
integer(i4b),intent(out) :: err ! error code | ||
character(*),intent(out) :: message ! error message | ||
! local variables | ||
integer(i4b) :: iter ! iteration index | ||
integer(i4b),parameter :: maxiter=20 ! maximum number of iterations | ||
real(dp), parameter :: xTol=1.e-8_dp ! convergence tolerance | ||
real(dp) :: flux ! flux | ||
real(dp) :: dfdx ! derivative | ||
real(dp) :: xRes ! residual error | ||
real(dp) :: delX ! state update | ||
! initialiuze routine | ||
err=0; message='implicitEuler/' | ||
|
||
! initialize | ||
xNew = xInit | ||
|
||
! iterate | ||
do iter=1,maxiter | ||
! get the flux and derivative | ||
call getFlux(funcName, xNew, flux, dfdx) | ||
! get the residual and the update | ||
xRes = xNew - (xInit + dt*flux) | ||
delX = -xRes/(1._dp - dt*dfdx) | ||
! update and check for convergence | ||
xNew = xNew + delX | ||
if(abs(delX) < xTol) exit | ||
! check for non-convergence | ||
if(iter==maxiter)then | ||
message=trim(message)//'the implicit Euler solution did not converge!' | ||
err=20; return | ||
endif | ||
end do | ||
end subroutine implicitEuler | ||
|
||
end module implicitEulerMod |