KTH framework for Nek5000 toolboxes; testing version  0.0.1
tstpr.f
Go to the documentation of this file.
1 
7 !=======================================================================
11  subroutine tstpr_register()
12  implicit none
13 
14  include 'SIZE'
15  include 'INPUT'
16  include 'FRAMELP'
17  include 'TSTPRD'
18 
19  ! local variables
20  integer lpmid, il
21  real ltim
22  character*2 str
23 
24  ! functions
25  real dnekclock
26 !-----------------------------------------------------------------------
27  ! timing
28  ltim = dnekclock()
29 
30  ! check if the current module was already registered
31  call mntr_mod_is_name_reg(lpmid,tstpr_name)
32  if (lpmid.gt.0) then
33  call mntr_warn(lpmid,
34  $ 'module ['//trim(tstpr_name)//'] already registered')
35  return
36  endif
37 
38  ! check if conjugated heat transfer module was registered
39  call mntr_mod_is_name_reg(lpmid,'CNHT')
40  if (lpmid.gt.0) then
41  call mntr_warn(lpmid,
42  $ 'module ['//'CNHT'//'] already registered')
43  else
44  call cnht_register()
45  endif
46 
47  ! find parent module
48  call mntr_mod_is_name_reg(lpmid,'FRAME')
49  if (lpmid.le.0) then
50  lpmid = 1
51  call mntr_abort(lpmid,
52  $ 'parent module ['//'FRAME'//'] not registered')
53  endif
54 
55  ! register module
56  call mntr_mod_reg(tstpr_id,lpmid,tstpr_name,
57  $ 'Time stepper')
58 
59  ! register timers
60  call mntr_tmr_is_name_reg(lpmid,'FRM_TOT')
61  ! total time
62  call mntr_tmr_reg(tstpr_tmr_tot_id,lpmid,tstpr_id,
63  $ 'TSTPR_TOT','Time stepper total time',.false.)
64  lpmid = tstpr_tmr_tot_id
65  ! initialisation
66  call mntr_tmr_reg(tstpr_tmr_ini_id,lpmid,tstpr_id,
67  $ 'TSTPR_INI','Time stepper initialisation time',.true.)
68  ! submodule operation
69  call mntr_tmr_reg(tstpr_tmr_evl_id,lpmid,tstpr_id,
70  $ 'TSTPR_EVL','Time stepper evolution time',.true.)
71 
72  ! register and set active section
73  call rprm_sec_reg(tstpr_sec_id,tstpr_id,'_'//adjustl(tstpr_name),
74  $ 'Runtime paramere section for time stepper module')
75  call rprm_sec_set_act(.true.,tstpr_sec_id)
76 
77  ! register parameters
78  call rprm_rp_reg(tstpr_mode_id,tstpr_sec_id,'MODE',
79  $ 'Simulation mode',rpar_str,10,0.0,.false.,'DIR')
80 
81  call rprm_rp_reg(tstpr_step_id,tstpr_sec_id,'STEPS',
82  $ 'Length of stepper phase',rpar_int,40,0.0,.false.,' ')
83 
84  call rprm_rp_reg(tstpr_cmax_id,tstpr_sec_id,'MAXCYC',
85  $ 'Max number of stepper cycles',rpar_int,10,0.0,.false.,' ')
86 
87  call rprm_rp_reg(tstpr_tol_id,tstpr_sec_id,'TOL',
88  $ 'Convergence threshold',rpar_real,0,1.0d-6,.false.,' ')
89 
90  ! place for submodule registration
91  ! register arnoldi or power iterations
92  call stepper_register()
93 
94  ! set initialisation flag
95  tstpr_ifinit=.false.
96 
97  ! timing
98  ltim = dnekclock() - ltim
99  call mntr_tmr_add(tstpr_tmr_ini_id,1,ltim)
100 
101  return
102  end subroutine
103 !=======================================================================
107  subroutine tstpr_init()
108  implicit none
109 
110  include 'SIZE'
111  include 'FRAMELP'
112  include 'TSTEP'
113  include 'INPUT'
114  include 'MASS'
115  include 'SOLN'
116  include 'ADJOINT'
117  include 'TSTPRD'
118 
119  ! local variables
120  integer itmp, il
121  real rtmp, ltim
122  logical ltmp
123  character*20 ctmp
124 
125  ! functions
126  real dnekclock, cnht_glsc2_wt
127  logical cnht_is_initialised
128 !-----------------------------------------------------------------------
129  ! check if the module was already initialised
130  if (tstpr_ifinit) then
131  call mntr_warn(tstpr_id,
132  $ 'module ['//trim(tstpr_name)//'] already initiaised.')
133  return
134  endif
135 
136  ! timing
137  ltim = dnekclock()
138 
139  ! intialise conjugated heat transfer
140  if (.not.cnht_is_initialised()) call cnht_init
141 
142  ! get runtime parameters
143  call rprm_rp_get(itmp,rtmp,ltmp,ctmp,tstpr_mode_id,rpar_str)
144  if (trim(ctmp).eq.'DIR') then
145  tstpr_mode = 1
146  else if (trim(ctmp).eq.'ADJ') then
147  tstpr_mode = 2
148  else if (trim(ctmp).eq.'OIC') then
149  tstpr_mode = 3
150  else
151  call mntr_abort(tstpr_id,
152  $ 'wrong simulation mode; possible values: DIR, ADJ, OIC')
153  endif
154 
155  call rprm_rp_get(itmp,rtmp,ltmp,ctmp,tstpr_step_id,rpar_int)
156  tstpr_step = itmp
157 
158  call rprm_rp_get(itmp,rtmp,ltmp,ctmp,tstpr_cmax_id,rpar_int)
159  tstpr_cmax = itmp
160 
161  call rprm_rp_get(itmp,rtmp,ltmp,ctmp,tstpr_tol_id,rpar_real)
162  tstpr_tol = rtmp
163 
164  ! check simulation parameters
165  if (.not.iftran) call mntr_abort(tstpr_id,
166  $ 'time stepper requres transient simulation; IFTRAN=.T.')
167 
168  if (nsteps.eq.0) call mntr_abort(tstpr_id,
169  $ 'time stepper requres NSTEPS>0')
170 
171  if (param(12).ge.0) call mntr_abort(tstpr_id,
172  $ 'time stepper assumes constant dt')
173 
174  if (.not.ifpert) call mntr_abort(tstpr_id,
175  $ 'time stepper has to be run in perturbation mode')
176 
177  if (ifbase) call mntr_abort(tstpr_id,
178  $ 'time stepper assumes constatnt base flow')
179 
180  if (npert.ne.1) call mntr_abort(tstpr_id,
181  $ 'time stepper requires NPERT=1')
182 
183  if (ifheat.and.tstpr_ht.ne.1) call mntr_abort(tstpr_id,
184  $ 'time stepper requires tstpr_ht=1 for temperature evaluation')
185 
186  ! initialise cycle counters
187  tstpr_istep = 0
188  tstpr_vstep = 0
189 
190  ! vector length
191  tstpr_nv = nx1*ny1*nz1*nelv ! velocity single component
192  if (ifheat) then !temperature
193  tstpr_nt = nx1*ny1*nz1*nelt
194  else
195  tstpr_nt = 0
196  endif
197  tstpr_np = nx2*ny2*nz2*nelv ! presure
198 
199  ! place for submodule initialisation
200  ! arnoldi or power iterations
201  call stepper_init
202 
203  ! zero presure
204  if(tstpr_pr.eq.0) call rzero(prp,tstpr_np)
205 
206  ! set initial time
207  time=0.0
208 
209  ! make sure NSTEPS is bigger than the possible number of iterations
210  ! in time stepper phase; multiplication by 2 for OIC
211  nsteps = max(nsteps,tstpr_step*tstpr_cmax*2+10)
212 
213  ifadj = .false.
214  if (tstpr_mode.eq.2) then
215  ! Is it adjoint mode
216  ifadj = .true.
217  elseif (tstpr_mode.eq.3) then
218  ! If it is optimal initial condition save initial L2 norm
219  tstpr_l2ini = cnht_glsc2_wt(vxp,vyp,vzp,tp,vxp,vyp,vzp,tp,bm1)
220 
221  if (tstpr_l2ini.eq.0.0) call mntr_abort(tstpr_id,
222  $ 'tstpr_init, tstpr_L2ini = 0')
223 
224  call mntr_log(tstpr_id,lp_prd,
225  $ 'Optimal initial condition; direct phase start')
226  endif
227 
228  ! set cpfld for conjugated heat transfer
229  if (ifheat) call cnht_cpfld_set
230 
231  ! everything is initialised
232  tstpr_ifinit=.true.
233 
234  ! timing
235  ltim = dnekclock() - ltim
236  call mntr_tmr_add(tstpr_tmr_ini_id,1,ltim)
237 
238  return
239  end subroutine
240 !=======================================================================
244  logical function tstpr_is_initialised()
245  implicit none
246 
247  include 'SIZE'
248  include 'TSTPRD'
249 !-----------------------------------------------------------------------
250  tstpr_is_initialised = tstpr_ifinit
251 
252  return
253  end function
254 !=======================================================================
258  subroutine tstpr_main()
259  implicit none
260 
261  include 'SIZE' ! NIO
262  include 'TSTEP' ! ISTEP, TIME
263  include 'INPUT' ! IFHEAT, IF3D
264  include 'MASS' ! BM1
265  include 'SOLN' ! V[XYZ]P, PRP, TP, VMULT, V?MASK
266  include 'ADJOINT' ! IFADJ
267  include 'FRAMELP'
268  include 'TSTPRD'
269 
270  ! global comunication in nekton
271  integer nidd,npp,nekcomm,nekgroup,nekreal
272  common /nekmpi/ nidd,npp,nekcomm,nekgroup,nekreal
273 
274  ! local variables
275  real grw ! growth rate
276  real ltim ! timing
277 
278  ! functions
279  real dnekclock, cnht_glsc2_wt
280 !-----------------------------------------------------------------------
281  if (istep.eq.0) return
282 
283  ! step counting
284  tstpr_istep = tstpr_istep + 1
285 
286  ! stepper phase end
287  if (mod(tstpr_istep,tstpr_step).eq.0) then
288  ! timing
289  ltim = dnekclock()
290  ! check for the calculation mode
291  if (tstpr_mode.eq.3.and.(.not.ifadj)) then
292  ! optimal initial condition
293 
294  call mntr_log(tstpr_id,lp_prd,
295  $ 'Optimal initial condition; adjoint phase start')
296 
297  ifadj = .true.
298 
299  ! iteration count
300  tstpr_istep = 0
301 
302  ! set time and iteration number
303  time=0.0
304  istep=0
305 
306  ! get L2 norm after direct phase
307  tstpr_l2dir = cnht_glsc2_wt(vxp,vyp,vzp,tp,
308  $ vxp,vyp,vzp,tp,bm1)
309  ! normalise vector
310  grw = sqrt(tstpr_l2ini/tstpr_l2dir)
311  call cnht_opcmult (vxp,vyp,vzp,tp,grw)
312 
313  if (tstpr_pr.eq.0) then
314  ! zero presure
315  call rzero(prp,tstpr_np)
316  else
317  ! normalise pressure ???????????????????????????
318  call cmult(prp,grw,tstpr_np)
319  endif
320 
321  ! set cpfld for conjugated heat transfer
322  if (ifheat) call cnht_cpfld_set
323  else
324  !stepper phase counting
325  tstpr_istep = 0
326  tstpr_vstep = tstpr_vstep +1
327 
328  call mntr_logi(tstpr_id,lp_prd,'Finished stepper phase:',
329  $ tstpr_vstep)
330 
331  if (tstpr_mode.eq.3) then
332  ! optimal initial condition
333  call mntr_log(tstpr_id,lp_prd,
334  $ 'Optimal initial condition; rescaling solution')
335 
336  ! get L2 norm after direct phase
337  tstpr_l2adj = cnht_glsc2_wt(vxp,vyp,vzp,tp,
338  $ vxp,vyp,vzp,tp,bm1)
339  ! normalise vector after whole cycle
340  grw = sqrt(tstpr_l2dir/tstpr_l2ini)! add direct growth
341  call cnht_opcmult (vxp,vyp,vzp,tp,grw)
342 
343  ! normalise pressure ???????????????????????????
344  if (tstpr_pr.ne.0) call cmult(prp,grw,tstpr_np)
345  endif
346 
347  ! run vector solver (arpack, power iteration)
348  call stepper_vsolve
349 
350  if (lastep.ne.1) then
351  ! stepper restart;
352  ! set time and iteration number
353  time=0.0
354  istep=0
355 
356  ! zero pressure
357  if (tstpr_pr.eq.0) call rzero(prp,tstpr_np)
358 
359  if (tstpr_mode.eq.3) then
360  ! optimal initial condition
361  call mntr_log(tstpr_id,lp_prd,
362  $ 'Optimal initial condition; direct phase start')
363 
364  ifadj = .false.
365 
366  ! get initial L2 norm
367  tstpr_l2ini = cnht_glsc2_wt(vxp,vyp,vzp,tp,
368  $ vxp,vyp,vzp,tp,bm1)
369  ! set cpfld for conjugated heat transfer
370  if (ifheat) call cnht_cpfld_set
371 
372  endif
373  endif
374 
375  endif ! tstpr_mode.eq.3.and.(.not.IFADJ)
376  ! timing
377  ltim = dnekclock() - ltim
378  call mntr_tmr_add(tstpr_tmr_evl_id,1,ltim)
379  endif ! mod(tstpr_istep,tstpr_step).eq.0
380 
381  return
382  end subroutine
383 !=======================================================================
386  subroutine tstpr_dssum
387  implicit none
388 
389  include 'SIZE' ! N[XYZ]1
390  include 'INPUT' ! IFHEAT
391  include 'SOLN' ! V[XYZ]P, TP, [VT]MULT
392  include 'TSTEP' ! IFIELD
393  include 'TSTPRD' ! tstpr_nt
394 
395  ! local variables
396  integer ifield_tmp
397 !-----------------------------------------------------------------------
398  ! make sure the velocity and temperature fields are continuous at
399  ! element faces and edges
400  ifield_tmp = ifield
401  ifield = 1
402 #ifdef AMR
403  call amr_oph1_proj(vxp,vyp,vzp,nx1,ny1,nz1,nelv)
404 #else
405  call opdssum(vxp,vyp,vzp)
406  call opcolv (vxp,vyp,vzp,vmult)
407 #endif
408 
409  if(ifheat) then
410  ifield = 2
411 #ifdef AMR
412  call h1_proj(tp,nx1,ny1,nz1)
413 #else
414  call dssum(tp,nx1,ny1,nz1)
415  call col2 (tp,tmult,tstpr_nt)
416 #endif
417  endif
418  ifield = ifield_tmp
419 
420  return
421  end subroutine
422 !=======================================================================
subroutine h1_proj(u, nx, ny, nz)
Definition: dssum.f:567
subroutine dssum(u, nx, ny, nz)
Definition: dssum.f:34
subroutine stepper_register()
Register Arnoldi ARPACK module.
Definition: arna.f:24
subroutine stepper_vsolve
Create Krylov space, get Ritz values and restart stepper phase.
Definition: arna.f:354
subroutine stepper_init()
Initilise Arnoldi ARPACK module.
Definition: arna.f:97
subroutine cnht_register()
Register conjugated heat transfer tools module.
Definition: cnht_tools.f:12
subroutine cnht_opcmult(a1, a2, a3, a4, const)
Multiply vector by constant A = c*A (single coeff. for velocity and temperature)
Definition: cnht_tools.f:405
subroutine cnht_cpfld_set()
Set cpfld coefficient for given type of simulation.
Definition: cnht_tools.f:206
subroutine cnht_init()
Initilise conjugated heat transfer tools module.
Definition: cnht_tools.f:82
subroutine mntr_logi(mid, priority, logs, ivar)
Write log message adding single integer.
Definition: mntrlog.f:709
subroutine mntr_tmr_is_name_reg(mid, mname)
Check if timer name is registered and return its id.
Definition: mntrtmr.f:146
subroutine mntr_warn(mid, logs)
Write warning message.
Definition: mntrlog.f:803
subroutine mntr_tmr_add(mid, icount, time)
Check if timer id is registered. This operation is performed locally.
Definition: mntrtmr.f:237
subroutine mntr_mod_is_name_reg(mid, mname)
Check if module name is registered and return its id.
Definition: mntrlog.f:459
subroutine mntr_abort(mid, logs)
Abort simulation.
Definition: mntrlog.f:837
subroutine mntr_log(mid, priority, logs)
Write log message.
Definition: mntrlog.f:600
subroutine mntr_mod_reg(mid, pmid, mname, mdscr)
Register new module.
Definition: mntrlog.f:346
subroutine mntr_tmr_reg(mid, pmid, modid, mname, mdscr, ifsum)
Register new timer.
Definition: mntrtmr.f:16
subroutine rprm_rp_get(ipval, rpval, lpval, cpval, rpid, ptype)
Get runtime parameter form active section. This operation is performed locally.
Definition: rprm.f:883
subroutine rprm_rp_reg(rpid, mid, pname, pdscr, ptype, ipval, rpval, lpval, cpval)
Register new runtime parameter.
Definition: rprm.f:484
subroutine rprm_sec_set_act(ifact, rpid)
Set section's activation flag. Master value is broadcasted.
Definition: rprm.f:422
subroutine rprm_sec_reg(rpid, mid, pname, pdscr)
Register new parameter section.
Definition: rprm.f:165
logical function tstpr_is_initialised()
Check if module was initialised.
Definition: tstpr.f:245
subroutine tstpr_main()
Control time stepper after every nek5000 step and call suitable stepper_vsolve of required submodule.
Definition: tstpr.f:259
subroutine tstpr_dssum
Average velocity and temperature at element faces.
Definition: tstpr.f:387
subroutine tstpr_init()
Initilise time stepper module.
Definition: tstpr.f:108
subroutine tstpr_register()
Register time stepper module.
Definition: tstpr.f:12
subroutine col2(a, b, n)
Definition: math.f:564
subroutine cmult(a, const, n)
Definition: math.f:315
subroutine rzero(a, n)
Definition: math.f:208
subroutine opdssum(a, b, c)
Definition: navier1.f:2582
subroutine opcolv(a1, a2, a3, c)
Definition: navier1.f:2418