ElmerFoamFSI  2.0
ElmerFoamFSI is fluid-solid interaction simulation application built up from OpenFOAM CFD and Elmer CSM coupled through the IMPACT multiphysics software integration infrastructure.
 All Classes Namespaces Files Functions Variables Typedefs Enumerator Macros Groups Pages
TimeStepper.F90
Go to the documentation of this file.
1 SUBROUTINE deprecatedtimestepper(global,runs)
2 
3  USE generalmodule
4  USE timemodule
5  USE testobject
6 
7 !------------------------------------------------------------------------------
8  IMPLICIT NONE
9 !------------------------------------------------------------------------------
10  include 'comf90.h'
11 
12  TYPE(t_global), POINTER :: global
13  INTEGER :: runs
14 
15  ! Masoud
16  WRITE(*,*) 'Inside MyDeprecatedTimeStepper ... '
17  ! Masoud : End
18 
19  DO interval = 1, timeintervals
20  stepcount = stepcount + timesteps(interval)
21  END DO
22 
23  IF (myverbosity > 3) THEN
24  WRITE(*,*) 'In TimeStepper'
25  WRITE(*,*) 'TimeIntervals = ', timeintervals
26  WRITE(*,*) 'global%nNodes = ', global%nNodes
27  END IF
28 
29  cum_timestep = 0
30  ddt = 0.0d0
31  DO interval = 1,timeintervals
32 
33  IF (myverbosity > 3) THEN
34  WRITE(*,*) 'interval = ', interval
35  END IF
36 !------------------------------------------------------------------------------
37  IF ( transient .OR. scanning ) THEN
38  dt = timestepsizes(interval,1)
39  ELSE
40  dt = 1
41  END IF
42 !------------------------------------------------------------------------------
43 ! go trough number of timesteps within an interval
44 !------------------------------------------------------------------------------
45  timeperiod = listgetcreal(currentmodel % Simulation, 'Time Period',gotit)
46  IF(.NOT.gotit) timeperiod = huge(timeperiod)
47 
48 
49  realtimestep = 1
50  WRITE(*,*) 'Timesteps(interval) = ', timesteps(interval)
51  DO timestep = 1,timesteps(interval)
52 
53  IF (myverbosity > 3) THEN
54  WRITE(6,*) 'timestepper timestep = ', timestep
55  WRITE(6,*) 'sTime(1) = ', stime(1)
56  WRITE(6,*) 'dtfunc = ', dtfunc
57  WRITE(6,*) 'dt = ', dt
58  END IF
59 
60  IF (myverbosity > 3) WRITE(*,*) 'TimeStepper Calling &
61  UpdateLoads'
62  CALL updateloads(global,runs)
63 
64  cum_timestep = cum_timestep + 1
65  sstep(1) = cum_timestep
66 
67  dtfunc = listgetconstreal( currentmodel % Simulation, &
68  'Timestep Function', gotit)
69  IF(gotit) THEN
70  CALL warn('ExecSimulation','Obsolite keyword > Timestep Function < , use > Timestep Size < instead')
71  ELSE
72  dtfunc = listgetcreal( currentmodel % Simulation, &
73  'Timestep Size', gotit)
74  END IF
75  IF(gotit) dt = dtfunc
76 
77 !------------------------------------------------------------------------------
78  stime(1) = stime(1) + dt
79  speriodic(1) = stime(1)
80  DO WHILE(speriodic(1) > timeperiod)
81  speriodic(1) = speriodic(1) - timeperiod
82  END DO
83 
84  ! Move the old timesteps one step down the ladder
85  IF(timestep > 1 .OR. interval > 1) THEN
86  DO i = SIZE(sprevsizes,2),2,-1
87  sprevsizes(1,i) = sprevsizes(1,i-1)
88  END DO
89  sprevsizes(1,1) = ssize(1)
90  END IF
91  ssize(1) = dt
92 
93  sinterval(1) = interval
94  IF (.NOT. transient ) steadyit(1) = steadyit(1) + 1
95 !------------------------------------------------------------------------------
96  IF ( parenv % MyPE == 0 ) THEN
97  CALL info( 'MAIN', ' ', level=3 )
98  CALL info( 'MAIN', '-------------------------------------', level=3 )
99 
100  IF ( transient .OR. scanning ) THEN
101  WRITE( message, * ) 'Time: ',trim(i2s(cum_timestep)),'/', &
102  trim(i2s(stepcount)), stime(1)
103  CALL info( 'MAIN', message, level=3 )
104 
105  newtime= realtime()
106 
107  IF( cum_timestep > 1 ) THEN
108  maxtime = listgetconstreal( currentmodel % Simulation,'Real Time Max',gotit)
109  IF( gotit ) THEN
110  WRITE( message,'(A,F8.3)') 'Fraction of real time left: ',&
111  1.0_dp-realtime() / maxtime
112  ELSE
113  timeleft = nint((stepcount-(cum_timestep-1))*(newtime-prevtime)/60._dp);
114  IF (timeleft > 120) THEN
115  WRITE( message, *) 'Estimated time left: ', &
116  trim(i2s(timeleft/60)),' hours.'
117  ELSE IF(timeleft > 60) THEN
118  WRITE( message, *) 'Estimated time left: 1 hour ', &
119  trim(i2s(mod(timeleft,60))), ' minutes.'
120  ELSE IF(timeleft >= 1) THEN
121  WRITE( message, *) 'Estimated time left: ', &
122  trim(i2s(timeleft)),' minutes.'
123  ELSE
124  WRITE( message, *) 'Estimated time left: less than a minute.'
125  END IF
126  END IF
127  CALL info( 'MAIN', message, level=3 )
128  END IF
129  prevtime = newtime
130  ELSE
131  WRITE( message, * ) 'Steady state iteration: ',cum_timestep
132  CALL info( 'MAIN', message, level=3 )
133  END IF
134 
135  CALL info( 'MAIN', '-------------------------------------', level=3 )
136  CALL info( 'MAIN', ' ', level=3 )
137  END IF
138 
139 !------------------------------------------------------------------------------
140 ! Solve any and all governing equations in the system
141 !------------------------------------------------------------------------------
142  adaptivetime = listgetlogical( currentmodel % Simulation, &
143  'Adaptive Timestepping', gotit )
144 
145  IF ( transient .AND. adaptivetime ) THEN
146  adaptivelimit = listgetconstreal( currentmodel % Simulation, &
147  'Adaptive Time Error', gotit )
148 
149  IF ( .NOT. gotit ) THEN
150  WRITE( message, * ) 'Adaptive Time Limit must be given for' // &
151  'adaptive stepping scheme.'
152  CALL fatal( 'ElmerSolver', message )
153  END IF
154 
155  adaptivemaxtimestep = listgetconstreal( currentmodel % Simulation, &
156  'Adaptive Max Timestep', gotit )
157  IF ( .NOT. gotit ) adaptivemaxtimestep = dt
158  adaptivemaxtimestep = min(adaptivemaxtimestep, dt)
159 
160  adaptivemintimestep = listgetconstreal( currentmodel % Simulation, &
161  'Adaptive Min Timestep', gotit )
162 
163  adaptivekeepsmallest = listgetinteger( currentmodel % Simulation, &
164  'Adaptive Keep Smallest', gotit, minv=0 )
165 
166  n = currentmodel % NumberOfSolvers
167  j = 0
168  k = 0
169  DO i=1,n
170  solver => currentmodel % Solvers(i)
171  IF ( ASSOCIATED( solver % Variable % Values ) ) THEN
172  IF ( ASSOCIATED( solver % Variable % PrevValues ) ) THEN
173  j = max( j, SIZE( solver % Variable % PrevValues,2 ) )
174  END IF
175  k = max( k, SIZE( solver % Variable % Values ) )
176  END IF
177  END DO
178  ALLOCATE( xx(n,k), yynrm(n), xxnrm(n), prevxx( n,k,j ) )
179 
180  cumtime = 0.0d0
181  IF ( ddt == 0.0d0 .OR. ddt > adaptivemaxtimestep ) ddt = adaptivemaxtimestep
182 
183  s = stime(1) - dt
184  smallestcount = 0
185  DO WHILE( cumtime < dt-1.0d-12 )
186  ddt = min( dt - cumtime, ddt )
187 
188  DO i=1,currentmodel % NumberOFSolvers
189  solver => currentmodel % Solvers(i)
190  IF ( ASSOCIATED( solver % Variable % Values ) ) THEN
191  n = SIZE( solver % Variable % Values )
192  xx(i,1:n) = solver % Variable % Values
193  xxnrm(i) = solver % Variable % Norm
194  IF ( ASSOCIATED( solver % Variable % PrevValues ) ) THEN
195  DO j=1,SIZE( solver % Variable % PrevValues,2 )
196  prevxx(i,1:n,j) = solver % Variable % PrevValues(:,j)
197  END DO
198  END IF
199  END IF
200  END DO
201 
202  stime(1) = s + cumtime + ddt
203  ssize(1) = ddt
204  CALL solveequations( currentmodel, ddt, transient, &
205  coupledminiter, coupledmaxiter, steadystatereached, realtimestep )
206 
207 
208  maxerr = listgetconstreal( currentmodel % Simulation, &
209  'Adaptive Error Measure', gotit )
210 
211  DO i=1,currentmodel % NumberOFSolvers
212  solver => currentmodel % Solvers(i)
213  IF ( ASSOCIATED( solver % Variable % Values ) ) THEN
214  n = SIZE(solver % Variable % Values)
215  yynrm(i) = solver % Variable % Norm
216  solver % Variable % Values = xx(i,1:n)
217  IF ( ASSOCIATED( solver % Variable % PrevValues ) ) THEN
218  DO j=1,SIZE( solver % Variable % PrevValues,2 )
219  solver % Variable % PrevValues(:,j) = prevxx(i,1:n,j)
220  END DO
221  END IF
222  END IF
223  END DO
224 
225  sstep(1) = ddt / 2
226  stime(1) = s + cumtime + ddt/2
227  CALL solveequations( currentmodel, ddt/2, transient, &
228  coupledminiter, coupledmaxiter, steadystatereached, realtimestep )
229  stime(1) = s + cumtime + ddt
230  CALL solveequations( currentmodel, ddt/2, transient, &
231  coupledminiter, coupledmaxiter, steadystatereached, realtimestep )
232 
233  maxerr = abs( maxerr - listgetconstreal( currentmodel % Simulation, &
234  'Adaptive Error Measure', gotit ) )
235 
236  IF ( .NOT. gotit ) THEN
237  maxerr = 0.0d0
238  DO i=1,currentmodel % NumberOFSolvers
239  solver => currentmodel % Solvers(i)
240  IF ( ASSOCIATED( solver % Variable % Values ) ) THEN
241  IF ( yynrm(i) /= solver % Variable % Norm ) THEN
242  maxerr = max(maxerr,abs(yynrm(i)-solver % Variable % Norm)/yynrm(i))
243  END IF
244  END IF
245  END DO
246  END IF
247 
248  IF ( maxerr < adaptivelimit .OR. ddt <= adaptivemintimestep ) THEN
249  cumtime = cumtime + ddt
250  realtimestep = realtimestep+1
251  IF ( smallestcount >= adaptivekeepsmallest .OR. stepcontrol > 0 ) THEN
252  ddt = min( 2*ddt, adaptivemaxtimestep )
253  stepcontrol = 1
254  smallestcount = 0
255  ELSE
256  stepcontrol = 0
257  smallestcount = smallestcount + 1
258  END IF
259  ELSE
260  DO i=1,currentmodel % NumberOFSolvers
261  solver => currentmodel % Solvers(i)
262  IF ( ASSOCIATED( solver % Variable % Values ) ) THEN
263  n = SIZE(solver % Variable % Values)
264  solver % Variable % Norm = xxnrm(i)
265  solver % Variable % Values = xx(i,1:n)
266  IF ( ASSOCIATED( solver % Variable % PrevValues ) ) THEN
267  DO j=1,SIZE( solver % Variable % PrevValues,2 )
268  solver % Variable % PrevValues(:,j) = prevxx(i,1:n,j)
269  END DO
270  END IF
271  END IF
272  END DO
273  ddt = ddt / 2
274  stepcontrol = -1
275  END IF
276  WRITE(*,'(a,3e20.12)') 'Adaptive(cum,ddt,err): ', cumtime, ddt, maxerr
277  END DO
278  ssize(1) = dt
279  stime(1) = s + dt
280 
281  DEALLOCATE( xx, xxnrm, yynrm, prevxx )
282  ELSE ! Adaptive timestepping
283  IF (myverbosity > 3) THEN
284  WRITE(*,*) 'Calling SolveEquations (no transient and no adaptive)'
285  END IF
286  CALL solveequations( currentmodel, dt, transient, &
287  coupledminiter, coupledmaxiter, steadystatereached, realtimestep )
288  realtimestep = realtimestep+1
289  END IF
290 
291 !------------------------------------------------------------------------------
292 ! Save results to disk, if requested
293 !------------------------------------------------------------------------------
294 
295  lastsaved = .false.
296  IF( outputintervals(interval) /= 0 ) THEN
297 
298  CALL savetopost(0)
299  k = mod( timestep-1, outputintervals(interval) )
300  IF ( k == 0 .OR. steadystatereached ) THEN
301 
302  DO i=1,currentmodel % NumberOfSolvers
303  solver => currentmodel % Solvers(i)
304  IF ( solver % PROCEDURE == 0 ) cycle
305  execthis = ( solver % SolverExecWhen == solver_exec_ahead_save)
306  when = listgetstring( solver % Values, 'Exec Solver', gotit )
307  IF ( gotit ) execthis = ( when == 'before saving')
308  IF( execthis ) CALL solveractivate( currentmodel,solver,dt,transient )
309  END DO
310 
311  CALL savecurrent(timestep)
312  lastsaved = .true.
313 
314  DO i=1,currentmodel % NumberOfSolvers
315  solver => currentmodel % Solvers(i)
316  IF ( solver % PROCEDURE == 0 ) cycle
317  execthis = ( solver % SolverExecWhen == solver_exec_after_save)
318  when = listgetstring( solver % Values, 'Exec Solver', gotit )
319  IF ( gotit ) execthis = ( when == 'after saving')
320  IF( execthis ) CALL solveractivate( currentmodel,solver,dt,transient )
321  END DO
322  END IF
323  END IF
324 !------------------------------------------------------------------------------
325 
326  maxtime = listgetcreal( currentmodel % Simulation,'Real Time Max',gotit)
327  IF( gotit .AND. realtime() - rt0 > maxtime ) THEN
328  CALL info('ElmerSolver','Reached allowed maximum real time, exiting...')
329  goto 100
330  END IF
331 
332  exitcond = listgetcreal( currentmodel % Simulation,'Exit Condition',gotit)
333  IF( gotit .AND. exitcond > 0.0_dp ) THEN
334  CALL info('ElmerSolver','Found a positive exit condition, exiting...')
335  goto 100
336  END IF
337 
338 !------------------------------------------------------------------------------
339 
340  IF ( steadystatereached .AND. .NOT. (transient .OR. scanning) ) THEN
341  IF ( timestep >= coupledminiter ) THEN
342  WRITE(6,*) 'SteadyStateReached, exiting'
343  EXIT
344  END IF
345  END IF
346 
347 !------------------------------------------------------------------------------
348  END DO ! timestep within an iterval
349 !------------------------------------------------------------------------------
350 
351 !------------------------------------------------------------------------------
352  END DO ! timestep intervals, i.e. the simulation
353 
354  IF (myverbosity > 3) THEN
355  write(6,*) 'LastSaved = ', lastsaved
356  END IF
357 
358  runs = 1
359 
360 100 RETURN
361 
362 END SUBROUTINE deprecatedtimestepper
ElmerLib Elmer library routines
Definition: TimeModule.F90:55
subroutine savecurrent(CurrentStep)
Saves current timestep to external files.
subroutine savetopost(CurrentStep)
Saves results file to post processing file of ElmerPost format, if requested.
subroutine updateloads(global, runs)
Definition: TimeModule.F90:96
ElmerLib Elmer library routines
subroutine deprecatedtimestepper(global, runs)
Definition: TimeStepper.F90:1