Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
ElmerCSC
GitHub Repository: ElmerCSC/elmerfem
Path: blob/devel/fem/tests/BatteryDischarge/Timefun.F90
5247 views
1
FUNCTION TimeFun(Model, n, tind) RESULT(dt)
2
USE DefUtils
3
IMPLICIT None
4
TYPE(Model_t) :: Model
5
INTEGER :: n
6
REAL(KIND=dp) :: tind, dt
7
8
LOGICAL :: Visited = .FALSE.,maxReached=.FALSE.
9
REAL(KIND=dp) :: dtmax, dt0, q
10
11
SAVE Visited, MaxReached, dtmax, dt0, q
12
13
IF(.NOT. Visited ) THEN
14
dtmax = ListGetConstReal( Model % Simulation,'Max Timestep')
15
dt0 = ListGetConstReal( Model % Simulation,'First Timestep')
16
q = ListGetConstReal( Model % Simulation,'Timestep Ratio')
17
END IF
18
19
! Since q^(tind-1) minght be huge we use constant timestep after reaching the max
20
IF( maxReached ) THEN
21
dt = dtmax
22
RETURN
23
END IF
24
25
! Timestep growing exponetially
26
dt = dt0 * q**(tind-1.0_dp)
27
28
! Until max timestep is reached
29
IF( dt > dtmax ) THEN
30
dt = dtmax
31
maxReached = .TRUE.
32
END IF
33
34
END FUNCTION TimeFun
35
36