TreeMig Code
Loading...
Searching...
No Matches
Interact.f90
Go to the documentation of this file.
1!==============================================================================
2!
3! Name : Interact
4!
5! Remarks: contains the SUBROUTINEs
6!
7! SeedsDispersedFromThisCell (<LocalDynOneTimeStep<SpatialDynOneTimeStep<
8! TimeLoop<TreeMig)
9! SeedsDispFromThisCellAndSpec (<SeedsDispersedFromThisCell<LocalDynOneTimeStep<
10! SpatialDynOneTimeStep<TimeLoop<TreeMig)
11! UpdateNewSeeds (<DistrLocalDynThisTime<TimeLoop<TreeMig)
12! SeedsFromOutsSimRegion (<DistrLocalDynThisTime<TimeLoop<TreeMig)
13! BoundaryConditions (<SeedsDispFromThisCellAndSpec<SeedsDispersedFromThisCell<
14! LocalDynOneTimeStep<DistrLocalDynThisTime<TimeLoop<TreeMig)
15!
16!==============================================================================
17
18!=================== For For Dispersal without FFT ======================================================
28!===============================================================
29SUBROUTINE seedsdispersedfromthiscell(nspc, lat, lon)
30 IMPLICIT NONE
31
32 INTEGER, INTENT(in) :: nspc, lat, lon ! number of species
33 INTEGER ::isp
34
35 do isp = 1, nspc
36 call seedsdispfromthiscellandspec(isp, lat, lon)
37 end do
38
39 return
40end SUBROUTINE seedsdispersedfromthiscell
41!****<Here the SUBROUTINE ends>********************************************************************
42
43!=================== For Dispersal without FFT ======================================================
76!===============================================================
77SUBROUTINE seedsdispfromthiscellandspec(isp, lat, lon)
78
80 IMPLICIT NONE
81
82 INTEGER, INTENT(in) :: isp, lat, lon
83 REAL :: producedSeeds
84
85 INTEGER :: seeds_inAir, seeds_onGround, & ! number of seeds emitted and fallen to ground
86 latwin, & ! index of relative to source cell window latitude
87 lonwin, & ! index of relative to source cell window longitude
88 wlat, wlon ! indices of absolute window latitude and longitude
89 REAL :: contrib ! contribution of source cell to sink cell
90 REAL :: prob ! probability of seeds landing in sink cell
91 LOGICAL :: dodisp
92
93
94 !----- <See also SUBROUTINE InitAndSetConstHeightClProps for the initialization!>
95 if (stockability(lat, lon) == 0.0) return ! if cell is not stockable then also no seed dispersal from this cell
96
97 producedseeds = stategrid(lat, lon)%sp(isp)%producedSeeds ! all seeds of this species produced in the source cell
98 !----- <Loop through species to perform seed dispersal calculations>
99! ncells = 0
100 if (producedseeds > 0.0) then ! if there are seeds to distribute
101 !----- <Loop for general discrete convolution>
102 !----- Go through all possible (i.e. within radius of dispersal kernel, given as latwin, lonwin window) sink cells around source cell
103
104 looplatwin: do latwin = -spec(isp)%rad, +spec(isp)%rad
105 looplonwin: do lonwin = -spec(isp)%rad, +spec(isp)%rad
106 !----- Determine absolute coordinates from those of source cell
107 wlat = lat - latwin
108 wlon = lon - lonwin
109 !----- what happens if seeds cross edge of simulation domain? Check whether this sink cell is allowed by the boundary conditions
110 call boundaryconditions(wlat, maxlat, wlon, maxlon, dodisp, boundaries)
111
112 if_inallowedarea: IF (dodisp) then
113 ifstock: if ((stockability(wlat, wlon) > 0.0) ) then !---- if sink cell is stockable
114 prob = spec(isp)%kernel(latwin, lonwin) !---- probability of dispersal between source and sink cell
115 if (dostochseeddisp) then
116 seeds_inair = producedseeds !---- only integer numbers of seeds allowed for binomial distribution approach
117 call drawfromdistri(seeds_inair, prob, seeds_onground) !----- Stochastic dispersal (by binomial distribution)
118 contrib = seeds_onground
119 else
120 contrib = prob * producedseeds !----- Deterministic dispersal, probability interpreted as fraction
121 end if
122 !---- add the seeds transported from source to sink cell to all seeds of this species ending in the sink cell
123 seedrain(wlat, wlon)%sp(isp)%verynewSeeds = seedrain(wlat, wlon)%sp(isp)%verynewSeeds + contrib !*cachind
124 end if ifstock
125 end if if_inallowedarea
126 end do looplonwin
127 end do looplatwin
128 end if !----- producedSeeds>0.0
129 ! end if IF_Active
130end SUBROUTINE seedsdispfromthiscellandspec
131!****<Here the SUBROUTINE ends>********************************************************************
132!==============================================================================
157!===============================================================
158SUBROUTINE updatenewseeds(nspc, iam, doDispersal, year, lats, late, lons, lone)
159
160 use all_par, only: maxlat, maxlon, seedrain, spec ! Use control and species parameters
161 use loggermodule
162 IMPLICIT NONE
163
164 INTEGER, INTENT(in) :: nspc, iam, lats, late, lons, lone, year ! number of species
165 LOGICAL, INTENT(in) :: doDispersal ! dispersal on/off flag [=..]
166
167 INTEGER :: latwin, & ! index of relative window latitude
168 lonwin, & ! index of relative window longitude
169 isp ! index of species
170 ! Check whether subarea is within the simulation area
171 if ((lats < 1) .or. (lats > maxlat) .or. (late < 1) .or. (late > maxlat) .or. &
172 (lons < 1) .or. (lons > maxlon) .or. (lone < 1) .or. (lone > maxlon)) then
173 call logerror("Coordinates out of bounds in updateNewseeds")
174 write (logmessage, "(7A15)") "iam", "lats", "lons", "late", "lone", "maxlat", "maxlon"
175 call logerror(logmessage)
176 write (logmessage, "(7I15)") iam, lats, lons, late, lone, maxlat, maxlon
177 call logerror(logmessage)
178 error stop
179 end if
180 !
181 if (dodispersal) then
182 loopspc2: do isp = 1, nspc
183 if (year >= spec(isp)%immi%dat(1)%year) then ! is normally fulfilled
184 looplatwin2: do latwin = lats, late
185 looplonwin2: do lonwin = lons, lone
186 seedrain(latwin, lonwin)%sp(isp)%newSeeds = seedrain(latwin, lonwin)%sp(isp)%verynewSeeds ! this is the update,
187 ! if (seedrain(latwin,lonwin)%sp(isp)%verynewSeeds >0.) &
188 seedrain(latwin, lonwin)%sp(isp)%verynewSeeds = 0.0 ! verynewSeeds is refreshed
189 end do looplonwin2
190 end do looplatwin2
191 end if
192 end do loopspc2
193 end if ! idisp
194end SUBROUTINE updatenewseeds
195!****<Here the SUBROUTINE ends>********************************************************************
196
197!===============================================================
216!===============================================================
217SUBROUTINE seedsfromoutssimregion(nspc, doDispersal, year, lats, late, lons, lone)
218 ! <CALL modules for TYPE definitions and +- fixed variables>---------------------------------------------------------------
219 use all_par, only: outerseeds, seedrain, spec ! Use control and species parameters
220 IMPLICIT NONE
221 ! <Passed variables>--------------------------------------------------------------------------------
222 INTEGER, INTENT(in) :: nspc, lats, late, lons, lone, year ! number of species
223 LOGICAL, INTENT(in) :: doDispersal ! dispersal on/off flag [=..]
224 ! <Local variables>---------------------------------------------------------------------------------
225 INTEGER :: latwin, & ! index of relative window latitude
226 lonwin, & ! index of relative window longitude
227 isp ! index of species
228 if (dodispersal) then
229 if (outerseeds > 0) then !----- outerspace boundary conditions
230 loopspc2: do isp = 1, nspc
231 if (year >= spec(isp)%immi%dat(1)%year) then ! immi%dat(1)%year is now defined in ReadImmigrationData
232 looplatwin2: do latwin = lats, late
233 looplonwin2: do lonwin = lons, lone
234 seedrain(latwin, lonwin)%sp(isp)%newSeeds = seedrain(latwin, lonwin)%sp(isp)%newSeeds + outerseeds
235 end do looplonwin2
236 end do looplatwin2
237 end if
238 end do loopspc2
239 end if
240 end if ! idisp
241end SUBROUTINE seedsfromoutssimregion
242!****<Here the SUBROUTINE ends>********************************************************************
243
244!=================== For Dispersal without FFT ======================================================
261!===============================================================
262SUBROUTINE boundaryconditions(wlat, maxlat, wlon, maxlon, dodisp, boundaries)
263
264
265 IMPLICIT NONE
266
267
268 INTEGER, INTENT(in) :: maxlat, maxlon ! looping variable for longitude [=..]
269 character(1), INTENT(in) :: boundaries ! TYPE of boundary conditions
270 INTEGER, INTENT(inout) :: wlat, & ! variable for latitude [=..]
271 wlon ! variable for longitude [=..]
272 LOGICAL, INTENT(out) :: dodisp ! valid sink cell? [=..]
273
274 ! LOCAL variables>--------------------------------------------------------------------------------
275
276 ! Here the SUBROUTINE starts>**********************************************************************
277 dodisp = .true.
278 select case (boundaries)
279 case('a') !----- absorbing boundary conditions
280 if ((wlat < 1) .OR. (wlat .gt. maxlat) .OR. &
281 (wlon < 1) .OR. (wlon .gt. maxlon)) dodisp = .false.
282 case('w') !----- absorbing boundary conditions in north and south, cyclic in east and west
283 if (wlon .ge. 0) then
284 wlon = mod(wlon, maxlon)
285 else
286 wlon = maxlon - mod(abs(wlon), maxlon)
287 end if
288 if (wlon == 0) wlon=maxlon
289 if ((wlat < 1) .OR. (wlat .gt. maxlat)) dodisp = .false.
290 case('s') !----- absorbing boundary conditions in west and eats, cyclic in south and north
291 if (wlat .ge. 0) then
292 wlat = mod(wlat, maxlat)
293 else
294 wlat = maxlat - mod(abs(wlat), maxlat)
295 end if
296 if (wlat == 0) wlat = maxlat
297 if ((wlon < 1) .OR. (wlon .gt. maxlon)) dodisp = .false.
298 case('c') !----- Cyclic boundary conditions
299 if (wlat .ge. 0) then
300 wlat = mod(wlat, maxlat)
301 else
302 wlat = maxlat - mod(abs(wlat), maxlat)
303 end if
304 if (wlat == 0) wlat = maxlat
305 if (wlon .ge. 0) then
306 wlon = mod(wlon,maxlon)
307 else
308 wlon = maxlon - mod(abs(wlon), maxlon)
309 end if
310 if (wlon == 0) wlon = maxlon
311 case default
312 write(70,*) 'wrong boundary conditions : ', boundaries, ', choose one of a, c, s, w; set to absorbing'
313 if ((wlat < 1) .OR. (wlat .gt. maxlat) .OR. &
314 (wlon < 1) .OR. (wlon .gt. maxlon)) dodisp = .false.
315 end select
316 return
317end SUBROUTINE boundaryconditions
318!done
subroutine drawfromdistri(n, p, ix)
DrawFromDistri
subroutine updatenewseeds(nspc, iam, dodispersal, year, lats, late, lons, lone)
UpdateNewSeeds.
Definition Interact.f90:159
subroutine seedsfromoutssimregion(nspc, dodispersal, year, lats, late, lons, lone)
SeedsFromOutsSimRegion.
Definition Interact.f90:218
subroutine seedsdispersedfromthiscell(nspc, lat, lon)
SeedsDispersedFromThisCell: Does the explicit seed dispersal for all species.
Definition Interact.f90:30
subroutine boundaryconditions(wlat, maxlat, wlon, maxlon, dodisp, boundaries)
BoundaryConditions, evaluates whether the sink cell is in the simulation domain.
Definition Interact.f90:263
subroutine seedsdispfromthiscellandspec(isp, lat, lon)
SeedsDispFromThisCellAndSpec, for brute force dispersal without FFT.
Definition Interact.f90:78
real, dimension(:, :), allocatable stockability
Definition All_par.f90:53
type(specproperties), dimension(maxspc) spec
Definition All_par.f90:345
type(currstateincell), dimension(:, :), allocatable stategrid
Definition All_par.f90:340
integer maxlon
Definition All_par.f90:46
integer outerseeds
Definition All_par.f90:94
type(newseedsincell), dimension(:, :), allocatable seedrain
Definition All_par.f90:342
character(len=:), allocatable boundaries
Definition All_par.f90:93
logical dostochseeddisp
Definition All_par.f90:69
integer maxlat
Definition All_par.f90:45
LoggerModule.
character(len=1024) logmessage
subroutine logerror(msg)
LogError