Skip to content

Commit fbfba2d

Browse files
jeanbraunbenbovy
authored andcommitted
Single flow (#23)
* Added a routine for Flow routing and created different routines for flow routing and stream power law for single flow direction * Added uplift function replacing the lines that imposed the uplift in StreamPowerLaw * Further improve the efficiency when n=1 and flow is single direction * Refactoring bis (to fragment SPL into subroutines and create separate versions for SFD and MFD) * enable marine component in SPL single flow * fix variable name conflict in marine subroutine
1 parent 95c2aef commit fbfba2d

File tree

10 files changed

+771
-336
lines changed

10 files changed

+771
-336
lines changed

CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ set(FASTSCAPELIB_SRC_FILES
1717
${FASTSCAPELIB_SRC_DIR}/Marine.f90
1818
${FASTSCAPELIB_SRC_DIR}/Strati.f90
1919
${FASTSCAPELIB_SRC_DIR}/StreamPowerLaw.f90
20+
${FASTSCAPELIB_SRC_DIR}/FlowRouting.f90
21+
${FASTSCAPELIB_SRC_DIR}/Uplift.f90
2022
${FASTSCAPELIB_SRC_DIR}/VTK.f90
2123
${FASTSCAPELIB_SRC_DIR}/TerrainDerivatives.f90
2224
)

Flexure2D_v1.0/src/flexure2D.f90

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -178,12 +178,12 @@ subroutine flexure (hh2,hp2,nx,ny,xl,yl,rhos2,rhoa,eet,ibc)
178178

179179
! deallocate memory
180180

181-
do j=1,ny
182-
do i=1,nx
183-
ij=(j-1)*nx+i
184-
hh2(ij)=h(i,j)
181+
do j=1,ny
182+
do i=1,nx
183+
ij=(j-1)*nx+i
184+
hh2(ij)=h(i,j)
185+
enddo
185186
enddo
186-
enddo
187187

188188
deallocate (w,h,hp,rhos)
189189

examples/Mountain.f90

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,9 @@ program Mountain
4848
kd = 1.d-1
4949
kdsed = -1.d0
5050
g = 0.d0
51-
call FastScape_Set_Erosional_Parameters (kf, kfsed, m, n, kd, kdsed, g, g, 10.d0)
51+
call FastScape_Set_Erosional_Parameters (kf, kfsed, m, n, kd, kdsed, g, g, -2.d0)
5252

53-
! set uplift rate (uniform while keeping bounaries at base level)
53+
! set uplift rate (uniform while keeping boundaries at base level)
5454
allocate (u(nx*ny))
5555
u = 1.d-3
5656
u(1:nx)=0.d0
@@ -81,7 +81,8 @@ program Mountain
8181
call FastScape_VTK (chi, 2.d0)
8282
! outputs h values
8383
call FastScape_Copy_h (h)
84-
print*,'step',istep,'h range:',minval(h),sum(h)/(nx*ny),maxval(h)
84+
print*,'step',istep
85+
print*,'h range:',minval(h),sum(h)/(nx*ny),maxval(h)
8586
enddo
8687

8788
! output timing

src/FastScape_api.f90

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,9 +213,22 @@ subroutine FastScape_Execute_Step()
213213
timeAdvect = timeAdvect + time_out-time_in
214214
endif
215215

216+
if (runUplift) then
217+
call cpu_time (time_in)
218+
call Uplift()
219+
call cpu_time (time_out)
220+
timeUplift = timeUplift + time_out-time_in
221+
endif
222+
216223
if (runSPL) then
217224
call cpu_time (time_in)
218-
call StreamPowerLaw ()
225+
if (SingleFlowDirection) then
226+
call FlowRoutingSingleFlowDirection
227+
call StreamPowerLawSingleFlowDirection ()
228+
else
229+
call FlowRouting ()
230+
call StreamPowerLaw ()
231+
endif
219232
call cpu_time (time_out)
220233
timeSPL = timeSPL + time_out-time_in
221234
endif

src/FastScape_ctx.f90

Lines changed: 52 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,17 @@ module FastScapeContext
1717
double precision :: sealevel, poro1, poro2, zporo1, zporo2, ratio, layer, kdsea1, kdsea2
1818
integer, dimension(:), allocatable :: stack, ndon, rec
1919
integer, dimension(:,:), allocatable :: don
20-
logical :: runSPL, runAdvect, runDiffusion, runMarine, runStrati
21-
real :: timeSPL, timeAdvect, timeDiffusion, timeMarine, timeStrati
20+
logical :: runSPL, runAdvect, runDiffusion, runStrati, runUplift, runMarine
21+
real :: timeSPL, timeAdvect, timeDiffusion, timeStrati, timeUplift, timeMarine
2222
double precision, dimension(:,:), allocatable :: reflector
2323
double precision, dimension(:,:,:), allocatable :: fields
2424
integer nfield, nfreq, nreflector, nfreqref, ireflector
2525
double precision :: vexref
26-
double precision, dimension(:), allocatable :: lake_depth
26+
logical :: SingleFlowDirection
27+
double precision, dimension(:), allocatable :: lake_depth, hwater
28+
integer, dimension(:), allocatable :: mnrec,mstack
29+
integer, dimension(:,:), allocatable :: mrec
30+
double precision, dimension(:,:), allocatable :: mwrec,mlrec
2731

2832
contains
2933

@@ -36,8 +40,9 @@ subroutine Init()
3640
timeSPL = 0.
3741
timeAdvect = 0.
3842
timeDiffusion = 0.
39-
timeMarine = 0.
40-
timeStrati = 0.
43+
timeStrati = 0.
44+
timeMarine = 0.
45+
timeUplift = 0.
4146

4247
end subroutine Init
4348

@@ -56,7 +61,7 @@ subroutine SetUp()
5661

5762
allocate (h(nn),u(nn),vx(nn),vy(nn),stack(nn),ndon(nn),rec(nn),don(8,nn),catch0(nn),catch(nn),precip(nn))
5863
allocate (length(nn),a(nn),erate(nn),etot(nn),b(nn),Sedflux(nn),Fmix(nn),kf(nn),kd(nn))
59-
allocate (lake_depth(nn))
64+
allocate (lake_depth(nn),hwater(nn),mrec(8,nn),mnrec(nn),mwrec(8,nn),mlrec(8,nn),mstack(nn))
6065

6166
h2(1:nx,1:ny) => h
6267
b2(1:nx,1:ny) => b
@@ -84,8 +89,9 @@ subroutine SetUp()
8489
runSPL = .false.
8590
runAdvect = .false.
8691
runDiffusion = .false.
92+
runStrati = .false.
8793
runMarine = .false.
88-
runStrati = .false.
94+
runUplift = .false.
8995

9096
nGSStreamPowerLaw = 0
9197
nGSMarine = 0
@@ -123,6 +129,13 @@ subroutine Destroy()
123129
if (allocated(reflector)) deallocate(reflector)
124130
if (allocated(fields)) deallocate(fields)
125131
if (allocated(lake_depth)) deallocate(lake_depth)
132+
if (allocated(hwater)) deallocate(hwater)
133+
if (allocated(mrec)) deallocate(mrec)
134+
if (allocated(mnrec)) deallocate(mnrec)
135+
if (allocated(mwrec)) deallocate(mwrec)
136+
if (allocated(mlrec)) deallocate(mlrec)
137+
if (allocated(mstack)) deallocate(mstack)
138+
126139

127140
return
128141

@@ -411,6 +424,11 @@ subroutine SetErosionalParam (kkf,kkfsed,mm,nnn,kkd,kkdsed,gg1,gg2,pp)
411424
g1 = gg1
412425
g2 = gg2
413426
p = pp
427+
SingleFlowDirection = .false.
428+
if (pp.lt.-1.5d0) then
429+
SingleFlowDirection = .true.
430+
p = 1.d0
431+
endif
414432

415433
if (maxval(kd).gt.tiny(kd).or.kdsed.gt.tiny(kdsed)) runDiffusion = .true.
416434

@@ -534,6 +552,7 @@ subroutine Debug ()
534552
if (runDiffusion) write (*,*) 'Diffusion:',timeDiffusion
535553
if (runMarine) write (*,*) 'Marine:',timeMarine
536554
if (runAdvect) write (*,*) 'Advection:',timeAdvect
555+
if (runUplift) write (*,*) 'Uplift:',timeUplift
537556
if (runStrati) write (*,*) 'Strati:',timeStrati
538557

539558
end subroutine Debug
@@ -559,6 +578,8 @@ subroutine SetU (up)
559578
double precision, intent(in) :: up(*)
560579
integer i
561580

581+
runUplift = .true.
582+
562583
do i=1,nn
563584
u(i) = up(i)
564585
enddo
@@ -674,7 +695,7 @@ subroutine Make_VTK (f, vex)
674695
#ifdef ON_WINDOWS
675696
call system ('if not exist "VTK" mkdir VTK')
676697
#else
677-
call system ("mkdir -p VTK")
698+
call system ("mkdir -p VTK")
678699
#endif
679700

680701
write (nxc,'(i6)') nx
@@ -753,7 +774,7 @@ subroutine Activate_Strati (nstepp, nreflectorp, nfreqp, vexp)
753774

754775
fields=0.d0
755776

756-
!call Strati (h, b, Fmix, nx, ny, xl, yl, reflector, nreflector, ireflector, 0, &
777+
!call Strati (b, Fmix, nx, ny, xl, yl, reflector, nreflector, ireflector, 0, &
757778
!fields, nfield, vexref, dt*nfreqref, stack, rec, length, sealevel)
758779

759780
runStrati = .true.
@@ -803,10 +824,7 @@ subroutine compute_fluxes (tectonic_flux, erosion_flux, boundary_flux)
803824
double precision, intent(out) :: tectonic_flux, erosion_flux, boundary_flux
804825
double precision :: surf
805826
logical, dimension(:), allocatable :: bc
806-
double precision, dimension(:), allocatable :: hwater,flux
807-
double precision, dimension(:,:), allocatable :: mwrec,mlrec
808-
integer, dimension(:), allocatable :: mnrec,mstack
809-
integer, dimension(:,:), allocatable :: mrec
827+
double precision, dimension(:), allocatable :: flux
810828
character*4 :: cbc
811829
integer ij,ijk,k
812830

@@ -816,17 +834,29 @@ subroutine compute_fluxes (tectonic_flux, erosion_flux, boundary_flux)
816834
erosion_flux = sum(erate)*surf
817835

818836
! computes receiver and stack information for multi-direction flow
819-
allocate (mrec(8,nn), mnrec(nn), mwrec(8,nn), mlrec(8,nn), mstack(nn), hwater(nn), flux(nn), bc(nn))
820-
call find_mult_rec (h, rec, stack, hwater, mrec, mnrec, mwrec, mlrec, mstack, nx, ny, xl/(nx-1), yl/(ny-1), p, ibc)
837+
!allocate (mrec(8,nn), mnrec(nn), mwrec(8,nn), mlrec(8,nn), mstack(nn), hwater(nn)
838+
!call find_mult_rec (h, rec, stack, hwater, mrec, mnrec, mwrec, mlrec, mstack, nx, ny, xl/(nx-1), yl/(ny-1), p, ibc)
821839
! computes sediment flux
840+
allocate (flux(nn), bc(nn))
841+
822842
flux = erate
823-
do ij = 1, nn
824-
ijk = mstack(ij)
825-
flux(ijk)=max(0.d0,flux(ijk))
826-
do k = 1, mnrec(ijk)
827-
flux(mrec(k,ijk)) = flux(mrec(k,ijk)) + flux(ijk)*mwrec(k,ijk)
843+
844+
if (SingleFlowDirection) then
845+
do ij = nn ,1, -1
846+
ijk = stack(ij)
847+
flux(ijk)=max(0.d0,flux(ijk))
848+
flux(rec(ijk)) = flux(rec(ijk)) + flux(ijk)
828849
enddo
829-
enddo
850+
else
851+
do ij = 1, nn
852+
ijk = mstack(ij)
853+
flux(ijk)=max(0.d0,flux(ijk))
854+
do k = 1, mnrec(ijk)
855+
flux(mrec(k,ijk)) = flux(mrec(k,ijk)) + flux(ijk)*mwrec(k,ijk)
856+
enddo
857+
enddo
858+
endif
859+
830860
! compute boundary flux
831861
write (cbc,'(i4)') ibc
832862
bc=.FALSE.
@@ -836,7 +866,7 @@ subroutine compute_fluxes (tectonic_flux, erosion_flux, boundary_flux)
836866
if (cbc(3:3).eq.'1') bc(nx*(ny - 1) + 1:nn) = .TRUE.
837867
boundary_flux = sum(flux,bc)*surf
838868

839-
deallocate (mrec, mnrec, mwrec, mlrec, mstack, hwater, flux, bc)
869+
deallocate (flux, bc)
840870

841871
end subroutine compute_fluxes
842872

0 commit comments

Comments
 (0)