KTH framework for Nek5000 toolboxes; testing version  0.0.1
tripl.f
Go to the documentation of this file.
1 
9 !=======================================================================
13  subroutine tripl_register()
14  implicit none
15 
16  include 'SIZE'
17  include 'INPUT'
18  include 'FRAMELP'
19  include 'TRIPLD'
20 
21  ! local variables
22  integer lpmid, il
23  real ltim
24  character*2 str
25 
26  ! functions
27  real dnekclock
28 !-----------------------------------------------------------------------
29  ! timing
30  ltim = dnekclock()
31 
32  ! check if the current module was already registered
33  call mntr_mod_is_name_reg(lpmid,tripl_name)
34  if (lpmid.gt.0) then
35  call mntr_warn(lpmid,
36  $ 'module ['//trim(tripl_name)//'] already registered')
37  return
38  endif
39 
40  ! find parent module
41  call mntr_mod_is_name_reg(lpmid,'FRAME')
42  if (lpmid.le.0) then
43  lpmid = 1
44  call mntr_abort(lpmid,
45  $ 'parent module ['//'FRAME'//'] not registered')
46  endif
47 
48  ! register module
49  call mntr_mod_reg(tripl_id,lpmid,tripl_name,
50  $ 'Tripping along the line')
51 
52  ! register timer
53  call mntr_tmr_is_name_reg(lpmid,'FRM_TOT')
54  call mntr_tmr_reg(tripl_tmr_id,lpmid,tripl_id,
55  $ 'tripl_TOT','Tripping total time',.false.)
56 
57  ! register and set active section
58  call rprm_sec_reg(tripl_sec_id,tripl_id,'_'//adjustl(tripl_name),
59  $ 'Runtime paramere section for tripping module')
60  call rprm_sec_set_act(.true.,tripl_sec_id)
61 
62  ! register parameters
63  call rprm_rp_reg(tripl_nline_id,tripl_sec_id,'NLINE',
64  $ 'Number of tripping lines',rpar_int,0,0.0,.false.,' ')
65 
66  do il=1, tripl_nline_max
67  write(str,'(I2.2)') il
68 
69  call rprm_rp_reg(tripl_tiamp_id(il),tripl_sec_id,'TIAMP'//str,
70  $ 'Time independent amplitude',rpar_real,0,0.0,.false.,' ')
71 
72  call rprm_rp_reg(tripl_tdamp_id(il),tripl_sec_id,'TDAMP'//str,
73  $ 'Time dependent amplitude',rpar_real,0,0.0,.false.,' ')
74 
75  call rprm_rp_reg(tripl_spos_id(1,il),tripl_sec_id,'SPOSX'//str,
76  $ 'Starting point X',rpar_real,0,0.0,.false.,' ')
77 
78  call rprm_rp_reg(tripl_spos_id(2,il),tripl_sec_id,'SPOSY'//str,
79  $ 'Starting point Y',rpar_real,0,0.0,.false.,' ')
80 
81  if (if3d) then
82  call rprm_rp_reg(tripl_spos_id(ldim,il),tripl_sec_id,
83  $ 'SPOSZ'//str,'Starting point Z',
84  $ rpar_real,0,0.0,.false.,' ')
85  endif
86 
87  call rprm_rp_reg(tripl_epos_id(1,il),tripl_sec_id,'EPOSX'//str,
88  $ 'Ending point X',rpar_real,0,0.0,.false.,' ')
89 
90  call rprm_rp_reg(tripl_epos_id(2,il),tripl_sec_id,'EPOSY'//str,
91  $ 'Ending point Y',rpar_real,0,0.0,.false.,' ')
92 
93  if (if3d) then
94  call rprm_rp_reg(tripl_epos_id(ldim,il),tripl_sec_id,
95  $ 'EPOSZ'//str,'Ending point Z',
96  $ rpar_real,0,0.0,.false.,' ')
97  endif
98 
99  call rprm_rp_reg(tripl_smth_id(1,il),tripl_sec_id,'SMTHX'//str,
100  $ 'Smoothing length X',rpar_real,0,0.0,.false.,' ')
101 
102  call rprm_rp_reg(tripl_smth_id(2,il),tripl_sec_id,'SMTHY'//str,
103  $ 'Smoothing length Y',rpar_real,0,0.0,.false.,' ')
104 
105  if (if3d) then
106  call rprm_rp_reg(tripl_smth_id(ldim,il),tripl_sec_id,
107  $ 'SMTHZ'//str,'Smoothing length Z',
108  $ rpar_real,0,0.0,.false.,' ')
109  endif
110 
111  call rprm_rp_reg(tripl_lext_id(il),tripl_sec_id,'LEXT'//str,
112  $ 'Line extension',rpar_log,0,0.0,.false.,' ')
113 
114  call rprm_rp_reg(tripl_rota_id(il),tripl_sec_id,'ROTA'//str,
115  $ 'Rotation angle',rpar_real,0,0.0,.false.,' ')
116  call rprm_rp_reg(tripl_nmode_id(il),tripl_sec_id,'NMODE'//str,
117  $ 'Number of Fourier modes',rpar_int,0,0.0,.false.,' ')
118  call rprm_rp_reg(tripl_tdt_id(il),tripl_sec_id,'TDT'//str,
119  $ 'Time step for tripping',rpar_real,0,0.0,.false.,' ')
120  enddo
121 
122  ! set initialisation flag
123  tripl_ifinit=.false.
124 
125  ! timing
126  ltim = dnekclock() - ltim
127  call mntr_tmr_add(tripl_tmr_id,1,ltim)
128 
129  return
130  end subroutine
131 !=======================================================================
135  subroutine tripl_init()
136  implicit none
137 
138  include 'SIZE'
139  include 'INPUT'
140  include 'GEOM'
141  include 'FRAMELP'
142  include 'TRIPLD'
143 
144  ! local variables
145  integer itmp
146  real rtmp, ltim
147  logical ltmp
148  character*20 ctmp
149 
150  integer il, jl, kl
151  real rtmpv(ldim)
152 
153  ! functions
154  real dnekclock
155 !-----------------------------------------------------------------------
156  call mntr_log(tripl_id,lp_inf,'Initialisation started')
157 
158  ! check if the module was already initialised
159  if (tripl_ifinit) then
160  call mntr_warn(tripl_id,
161  $ 'module ['//trim(tripl_name)//'] already initiaised.')
162  return
163  endif
164 
165  ! timing
166  ltim = dnekclock()
167 
168  ! get runtime parameters
169  call rprm_rp_get(itmp,rtmp,ltmp,ctmp,tripl_nline_id,rpar_int)
170  tripl_nline = itmp
171 
172  do il=1,tripl_nline
173  call rprm_rp_get(itmp,rtmp,ltmp,ctmp,tripl_tiamp_id(il),
174  $ rpar_real)
175  tripl_tiamp(il) = rtmp
176  call rprm_rp_get(itmp,rtmp,ltmp,ctmp,tripl_tdamp_id(il),
177  $ rpar_real)
178  tripl_tdamp(il) = rtmp
179 
180  do jl=1,ldim
181  call rprm_rp_get(itmp,rtmp,ltmp,ctmp,tripl_spos_id(jl,il),
182  $ rpar_real)
183  tripl_spos(jl,il) = rtmp
184  call rprm_rp_get(itmp,rtmp,ltmp,ctmp,tripl_epos_id(jl,il),
185  $ rpar_real)
186  tripl_epos(jl,il) = rtmp
187  call rprm_rp_get(itmp,rtmp,ltmp,ctmp,tripl_smth_id(jl,il),
188  $ rpar_real)
189  tripl_smth(jl,il) = abs(rtmp)
190  enddo
191  call rprm_rp_get(itmp,rtmp,ltmp,ctmp,tripl_lext_id(il),
192  $ rpar_log)
193  tripl_lext(il) = ltmp
194  call rprm_rp_get(itmp,rtmp,ltmp,ctmp,tripl_rota_id(il),
195  $ rpar_real)
196  tripl_rota(il) = rtmp
197  call rprm_rp_get(itmp,rtmp,ltmp,ctmp,tripl_nmode_id(il),
198  $ rpar_int)
199  tripl_nmode(il) = itmp
200  call rprm_rp_get(itmp,rtmp,ltmp,ctmp,tripl_tdt_id(il),
201  $ rpar_real)
202  tripl_tdt(il) = rtmp
203  enddo
204 
205  ! check simulation dimension
206  if (.not.if3d) call mntr_abort(tripl_id,
207  $ '2D simulation is not supported.')
208 
209  ! get line versor, inverse line lengths and scaled smoothing lengths
210  do il=1,tripl_nline
211  call mntr_logi(tripl_id,lp_inf,'Line info; line nr: ',il)
212  tripl_ilngt(il) = 0.0
213 
214  do jl=1,ldim
215  ! the last (third) versor is parallel to the line
216  tripl_vrs(jl,ldim,il) = tripl_epos(jl,il) - tripl_spos(jl,il)
217  tripl_ilngt(il) = tripl_ilngt(il) + tripl_vrs(jl,ldim,il)**2
218  enddo
219  tripl_ilngt(il) = sqrt(tripl_ilngt(il))
220  call mntr_logr(tripl_id,lp_inf,'Line length: ',tripl_ilngt(il))
221  if (tripl_ilngt(il).gt.0.0) then
222  tripl_ilngt(il) = 1.0/tripl_ilngt(il)
223  do jl=1,ldim
224  tripl_vrs(jl,ldim,il) = tripl_vrs(jl,ldim,il)*
225  $ tripl_ilngt(il)
226  enddo
227  else
228  call mntr_abort(tripl_id,
229  $ 'Line with zero lenght is not supported.')
230  endif
231  ! the rest of versors given by cross product starting with the
232  ! second versor
233  call rzero(rtmpv,ldim)
234  ! the first versor guess depends on the last versor coordinates
235  if (tripl_vrs(1,ldim,il).lt.0.95) then
236  rtmpv(1) = 1.0
237  else
238  rtmpv(2) = 1.0
239  endif
240  ! the second versor
241  call cross(tripl_vrs(1,2,il),tripl_vrs(1,ldim,il),rtmpv)
242  ! the first versor
243  call cross(tripl_vrs(1,1,il),tripl_vrs(1,2,il),
244  $ tripl_vrs(1,ldim,il))
245  ! correct versor length
246  do jl = 1, ldim
247  rtmp = 0.0
248  do kl = 1, ldim
249  rtmp = rtmp + tripl_vrs(kl,jl,il)*tripl_vrs(kl,jl,il)
250  end do
251  if (rtmp.gt.0.0) then
252  rtmp = 1.0/sqrt(rtmp)
253  do kl = 1, ldim
254  tripl_vrs(kl,jl,il) = tripl_vrs(kl,jl,il)*rtmp
255  end do
256  else
257  call mntr_abort(tripl_id,
258  $ 'Line versor with zero lenght.')
259  end if
260  end do
261  ! rotate the first and second versors along the third versor
262  do jl = 1, 2
263  call math_rot3da(rtmpv,tripl_vrs(1,jl,il),tripl_vrs(1,ldim,il)
264  $ ,tripl_rota(il))
265  do kl = 1, ldim
266  tripl_vrs(kl,jl,il) = rtmpv(kl)
267  end do
268  end do
269 
270  ! stump the log
271  do jl = 1, ldim
272  call mntr_logi(tripl_id,lp_inf,'Line versor: ',jl)
273  call mntr_logrv(tripl_id,lp_inf,'Coordinates:',
274  $ tripl_vrs(1,jl,il),ldim)
275  end do
276 
277  ! rescale smoothing lengths
278  do jl=1,ldim
279  tripl_smth(jl,il) = tripl_smth(jl,il)*tripl_ilngt(il)
280  enddo
281  ! get inverse smoothing lenght
282  do jl=1,ldim
283  if (tripl_smth(jl,il).gt.0.0) then
284  tripl_ismth(jl,il) = 1.0/tripl_smth(jl,il)
285  else
286  tripl_ismth(jl,il) = 1.0
287  endif
288  enddo
289  enddo
290  call mntr_log(tripl_id,lp_inf,'Local base calculated')
291 
292  ! get 1D projection and array mapping
293  call tripl_1dprj
294  call mntr_log(tripl_id,lp_inf,'1D projection finalised')
295 
296  ! initialise random generator seed and number of time intervals
297  do il=1,tripl_nline
298  tripl_seed(il) = -32*il
299  tripl_ntdt(il) = 1 - tripl_nset_max
300  tripl_ntdt_old(il) = tripl_ntdt(il)
301  enddo
302 
303  ! generate random phases (time independent and time dependent)
304  il = tripl_nmode_max*tripl_nset_max*tripl_nline_max
305  call rzero(tripl_rphs,il)
306  call tripl_rphs_get
307  call mntr_log(tripl_id,lp_inf,'Random phases calculated')
308 
309  ! get forcing
310  call tripl_frcs_get(.true.)
311  call mntr_log(tripl_id,lp_inf,'Forcing calculated')
312 
313 
314  ! everything is initialised
315  tripl_ifinit=.true.
316 
317  call mntr_log(tripl_id,lp_inf,'Initialisation finalised')
318 
319  ! timing
320  ltim = dnekclock() - ltim
321  call mntr_tmr_add(tripl_tmr_id,1,ltim)
322 
323  return
324  end subroutine
325 !=======================================================================
329  logical function tripl_is_initialised()
330  implicit none
331 
332  include 'SIZE'
333  include 'TRIPLD'
334 !-----------------------------------------------------------------------
335  tripl_is_initialised = tripl_ifinit
336 
337  return
338  end function
339 !=======================================================================
342  subroutine tripl_update()
343  implicit none
344 
345  include 'SIZE'
346  include 'TRIPLD'
347 
348  ! local variables
349  real ltim
350 
351  ! functions
352  real dnekclock
353 !-----------------------------------------------------------------------
354  ! timing
355  ltim = dnekclock()
356 
357  ! update random phases (time independent and time dependent)
358  call tripl_rphs_get
359 
360  ! update forcing
361  call tripl_frcs_get(.false.)
362 
363  ! timing
364  ltim = dnekclock() - ltim
365  call mntr_tmr_add(tripl_tmr_id,1,ltim)
366 
367  return
368  end subroutine
369 !=======================================================================
375  subroutine tripl_forcing(ffx,ffy,ffz,ix,iy,iz,ieg)
376  implicit none
377 
378  include 'SIZE'
379  include 'PARALLEL'
380  include 'TRIPLD'
381 
382  ! argument list
383  real ffx, ffy, ffz
384  integer ix,iy,iz,ieg
385 
386  ! local variables
387  integer ipos,iel,il
388  real ffn
389 !-----------------------------------------------------------------------
390  iel=gllel(ieg)
391 
392  do il= 1, tripl_nline
393  ffn = tripl_fsmth(ix,iy,iz,iel,il)
394  if (ffn.gt.0.0) then
395  ipos = tripl_map(ix,iy,iz,iel,il)
396  ffn = tripl_ftrp(ipos,il)*ffn
397 
398  ! I assume forcing direction is given by the second versor
399  ffx = ffx + ffn*tripl_vrs(1,2,il)
400  ffy = ffy + ffn*tripl_vrs(2,2,il)
401  ffz = ffz + ffn*tripl_vrs(ldim,2,il)
402  endif
403  enddo
404 
405  return
406  end subroutine
407 !=======================================================================
410  subroutine tripl_reset()
411  implicit none
412 
413  include 'SIZE'
414  include 'TRIPLD'
415 
416  ! local variables
417  real ltim
418 
419  ! functions
420  real dnekclock
421 !-----------------------------------------------------------------------
422  ! timing
423  ltim = dnekclock()
424 
425  ! get 1D projection and array mapping
426  call tripl_1dprj
427 
428  ! update forcing
429  call tripl_frcs_get(.true.)
430 
431  ! timing
432  ltim = dnekclock() - ltim
433  call mntr_tmr_add(tripl_tmr_id,1,ltim)
434 
435  return
436  end subroutine
437 !=======================================================================
445  subroutine tripl_1dprj()
446  implicit none
447 
448  include 'SIZE'
449  include 'INPUT'
450  include 'GEOM'
451  include 'TRIPLD'
452 
453  ! global memory access
454  real lcoord(LX1*LY1*LZ1*LELT)
455  common /ctmp0/ lcoord
456  integer lmap(LX1*LY1*LZ1*LELT), lmap_el(4,LX1*LY1*LZ1*LELT)
457  common /ctmp1/ lmap, lmap_el
458 
459  ! local variables
460  integer nptot, itmp, itmp2
461  integer il, jl, kl, ll, ml, nl
462  real rota, rtmp, epsl
463  parameter(epsl = 1.0e-10)
464  real rtmpv(ldim), rtmpc(ldim)
465  ! functions
466  real dot
467 !-----------------------------------------------------------------------
468  nptot = nx1*ny1*nz1*nelv
469 
470  ! for each line
471  do il=1,tripl_nline
472  ! reset mapping array
473  call ifill(tripl_map(1,1,1,1,il),-1,nptot)
474  ! initialise number of points per line
475  tripl_npoint(il) = 0
476  ! initialize smoothing factor
477  call rzero(tripl_fsmth(1,1,1,1,il),nptot)
478  ! initialize projected point position
479  call rzero(tripl_prj(1,il),nptot)
480 
481  ! Projection onto the line
482  ! count points on the line
483  itmp = 0
484  do jl = 1, nelv
485  do kl = 1, lz1
486  do ll = 1, ly1
487  do ml = 1, lx1
488  ! get point position relative to the line start
489  rtmpv(1) = xm1(ml,ll,kl,jl)-tripl_spos(1,il)
490  rtmpv(2) = ym1(ml,ll,kl,jl)-tripl_spos(2,il)
491  rtmpv(ldim) = zm1(ml,ll,kl,jl)-tripl_spos(ldim,il)
492  ! get point coordinates in the local line system
493  do nl = 1, ldim
494  rtmpc(nl) = dot(rtmpv,tripl_vrs(1,nl,il),ldim)
495  rtmpc(nl) = rtmpc(nl)*tripl_ilngt(il)
496  end do
497  ! distance from the line
498  ! 2D
499  rtmp = (rtmpc(1)*tripl_ismth(1,il))**2+
500  $ (rtmpc(2)*tripl_ismth(2,il))**2
501  ! do we extend a line beyond its ends
502  if (.not.tripl_lext(il)) then
503  if (rtmpc(ldim).lt.0.0) then
504  rtmp = rtmp +
505  $ (rtmpc(ldim)*tripl_ismth(ldim,il))**2
506  elseif (rtmpc(ldim).gt.1.0) then
507  rtmp = rtmp +
508  $ ((rtmpc(ldim)-1.0)*tripl_ismth(ldim,il))**2
509  end if
510  end if
511 
512  ! get smoothing profile
513  ! Gauss; cannot be used with lines not extended beyond their ending points
514  !tripl_fsmth(itmp,jtmp,ktmp,eltmp,il) = exp(-4.0*rtmp)
515  ! limited support
516  if (rtmp.lt.1.0) then
517  tripl_fsmth(ml,ll,kl,jl,il) =
518  $ exp(-rtmp)*(1-rtmp)**2
519  ! add the point to the list
520  itmp = itmp + 1
521  ! save data
522  ! coordinate along the line in line length unit
523  lcoord(itmp) = rtmpc(ldim)
524  ! point position
525  lmap_el(1,itmp) = jl
526  lmap_el(2,itmp) = kl
527  lmap_el(3,itmp) = ll
528  lmap_el(4,itmp) = ml
529  else
530  tripl_fsmth(ml,ll,kl,jl,il) = 0.0
531  endif
532  end do
533  end do
534  end do
535  end do
536 
537  if (itmp.ge.1) then
538  ! point sorting acording to the last coordinate
539  call sort(lcoord,lmap,itmp)
540 
541  ! identify unique points
542  tripl_npoint(il) = 1
543  tripl_prj(tripl_npoint(il),il) = lcoord(1)
544  ! generate mapping
545  itmp2 = lmap(1)
546  tripl_map(lmap_el(4,itmp2),lmap_el(3,itmp2),
547  $ lmap_el(2,itmp2),lmap_el(1,itmp2),il) = tripl_npoint(il)
548  do jl = 2, itmp
549  ! compare positions along the line
550  if((lcoord(jl)-tripl_prj(tripl_npoint(il),il)).gt.
551  $ max(epsl,abs(epsl*lcoord(jl)))) then
552  tripl_npoint(il) = tripl_npoint(il) + 1
553  tripl_prj(tripl_npoint(il),il) = lcoord(jl)
554  endif
555  ! generate mapping
556  itmp2 = lmap(jl)
557  tripl_map(lmap_el(4,itmp2),lmap_el(3,itmp2),
558  $ lmap_el(2,itmp2),lmap_el(1,itmp2),il) = tripl_npoint(il)
559  end do
560  end if
561  enddo
562 
563  return
564  end subroutine
565 !=======================================================================
568  subroutine tripl_rphs_get
569  implicit none
570 
571  include 'SIZE'
572  include 'TSTEP'
573  include 'PARALLEL'
574  include 'TRIPLD'
575 
576  ! local variables
577  integer il, jl, kl
578  integer itmp
579  real tripl_ran2
580 
581 #ifdef DEBUG
582  character*3 str1, str2
583  integer iunit, ierr
584  ! call number
585  integer icalldl
586  save icalldl
587  data icalldl /0/
588 #endif
589 !-----------------------------------------------------------------------
590  ! time independent part
591  do il = 1, tripl_nline
592  if (tripl_tiamp(il).gt.0.0.and..not.tripl_ifinit) then
593  do jl=1, tripl_nmode(il)
594  tripl_rphs(jl,1,il) = 2.0*pi*tripl_ran2(il)
595  end do
596  end if
597  end do
598 
599  ! time dependent part
600  do il = 1, tripl_nline
601  itmp = int(time/tripl_tdt(il))
602  call bcast(itmp,isize) ! just for safety
603  do kl= tripl_ntdt(il)+1, itmp
604  do jl= tripl_nset_max,3,-1
605  call copy(tripl_rphs(1,jl,il),tripl_rphs(1,jl-1,il),
606  $ tripl_nmode(il))
607  enddo
608  do jl=1, tripl_nmode(il)
609  tripl_rphs(jl,2,il) = 2.0*pi*tripl_ran2(il)
610  enddo
611  enddo
612  ! update time interval
613  tripl_ntdt_old(il) = tripl_ntdt(il)
614  tripl_ntdt(il) = itmp
615  enddo
616 
617 #ifdef DEBUG
618  ! for testing
619  ! to output refinement
620  icalldl = icalldl+1
621  call io_file_freeid(iunit, ierr)
622  write(str1,'(i3.3)') nid
623  write(str2,'(i3.3)') icalldl
624  open(unit=iunit,file='trp_rps.txt'//str1//'i'//str2)
625 
626  do il=1,tripl_nmode(1)
627  write(iunit,*) il,tripl_rphs(il,1:4,1)
628  enddo
629 
630  close(iunit)
631 #endif
632 
633  return
634  end subroutine
635 !=======================================================================
645  real function tripl_ran2(il)
646  implicit none
647 
648  include 'SIZE'
649  include 'TRIPLD'
650 
651  ! argument list
652  integer il
653 
654  ! local variables
655  integer iff(tripl_nline_max), iy(tripl_nline_max)
656  integer ir(97,tripl_nline_max)
657  integer m,ia,ic,j
658  real rm
659  parameter(m=714025,ia=1366,ic=150889,rm=1./m)
660  save iff,ir,iy
661  data iff /tripl_nline_max*0/
662 !-----------------------------------------------------------------------
663  ! initialise
664  if (tripl_seed(il).lt.0.or.iff(il).eq.0) then
665  iff(il)=1
666  tripl_seed(il)=mod(ic-tripl_seed(il),m)
667  do j=1,97
668  tripl_seed(il)=mod(ia*tripl_seed(il)+ic,m)
669  ir(j,il)=tripl_seed(il)
670  end do
671  tripl_seed(il)=mod(ia*tripl_seed(il)+ic,m)
672  iy(il)=tripl_seed(il)
673  end if
674 
675  ! generate random number
676  j=1+(97*iy(il))/m
677  iy(il)=ir(j,il)
678  tripl_ran2=iy(il)*rm
679  tripl_seed(il)=mod(ia*tripl_seed(il)+ic,m)
680  ir(j,il)=tripl_seed(il)
681 
682  end function
683 !=======================================================================
687  subroutine tripl_frcs_get(ifreset)
688  implicit none
689 
690  include 'SIZE'
691  include 'INPUT'
692  include 'TSTEP'
693  include 'TRIPLD'
694 
695  ! argument list
696  logical ifreset
697 
698 #ifdef TRIPL_PR_RST
699  ! variables necessary to reset pressure projection for P_n-P_n-2
700  integer nprv(2)
701  common /orthbi/ nprv
702 
703  ! variables necessary to reset velocity projection for P_n-P_n-2
704  include 'VPROJ'
705 #endif
706  ! local variables
707  integer il, jl, kl, ll
708  integer istart
709  real theta0, theta
710  logical ifntdt_dif
711 
712 #ifdef DEBUG
713  character*3 str1, str2
714  integer iunit, ierr
715  ! call number
716  integer icalldl
717  save icalldl
718  data icalldl /0/
719 #endif
720 !-----------------------------------------------------------------------
721  ! reset all
722  if (ifreset) then
723  do il= 1, tripl_nline
724  ! do we include time independent part?
725  if (tripl_tiamp(il).gt.0.0) then
726  istart = 1
727  else
728  istart = 2
729  endif
730  ! get forcing
731  do jl = istart, tripl_nset_max
732  call rzero(tripl_frcs(1,jl,il),tripl_npoint(il))
733  do kl= 1, tripl_npoint(il)
734  theta0 = 2*pi*tripl_prj(kl,il)
735  do ll= 1, tripl_nmode(il)
736  theta = theta0*ll
737  tripl_frcs(kl,jl,il) = tripl_frcs(kl,jl,il) +
738  $ sin(theta+tripl_rphs(ll,jl,il))
739  enddo
740  enddo
741  enddo
742  ! rescale time independent part
743  if (tripl_tiamp(il).gt.0.0) call cmult(tripl_frcs(1,1,il),
744  $ tripl_tiamp(il),tripl_npoint(il))
745  enddo
746 
747  else
748  ! reset only time dependent part if needed
749  ifntdt_dif = .false.
750  do il= 1, tripl_nline
751  if (tripl_ntdt(il).ne.tripl_ntdt_old(il)) then
752  ifntdt_dif = .true.
753  do jl= tripl_nset_max,3,-1
754  call copy(tripl_frcs(1,jl,il),tripl_frcs(1,jl-1,il),
755  $ tripl_npoint(il))
756  enddo
757  call rzero(tripl_frcs(1,2,il),tripl_npoint(il))
758  do jl= 1, tripl_npoint(il)
759  theta0 = 2*pi*tripl_prj(jl,il)
760  do kl= 1, tripl_nmode(il)
761  theta = theta0*kl
762  tripl_frcs(jl,2,il) = tripl_frcs(jl,2,il) +
763  $ sin(theta+tripl_rphs(kl,2,il))
764  enddo
765  enddo
766  endif
767  enddo
768  if (ifntdt_dif) then
769 #ifdef TRIPL_PR_RST
770  ! reset projection space
771  ! pressure
772  if (int(param(95)).gt.0) then
773  param(95) = istep
774  nprv(1) = 0 ! veloctiy field only
775  endif
776  ! velocity
777  if (int(param(94)).gt.0) then
778  param(94) = istep!+2
779  ivproj(2,1) = 0
780  ivproj(2,2) = 0
781  if (if3d) ivproj(2,3) = 0
782  endif
783 #endif
784  endif
785  endif
786 
787  ! get tripping for current time step
788  do il= 1, tripl_nline
789  if (tripl_tiamp(il).gt.0.0) then
790  call copy(tripl_ftrp(1,il),tripl_frcs(1,1,il),
791  $ tripl_npoint(il))
792  else
793  call rzero(tripl_ftrp(1,il),tripl_npoint(il))
794  end if
795  end do
796  ! interpolation in time
797  do il = 1, tripl_nline
798  theta0= time/tripl_tdt(il)-real(tripl_ntdt(il))
799  if (theta0.gt.0.0) then
800  theta0=theta0*theta0*(3.0-2.0*theta0)
801  !theta0=theta0*theta0*theta0*(10.0+(6.0*theta0-15.0)*theta0)
802  do jl= 1, tripl_npoint(il)
803  tripl_ftrp(jl,il) = tripl_ftrp(jl,il) +
804  $ tripl_tdamp(il)*((1.0-theta0)*tripl_frcs(jl,3,il) +
805  $ theta0*tripl_frcs(jl,2,il))
806  enddo
807  else
808  theta0=theta0+1.0
809  theta0=theta0*theta0*(3.0-2.0*theta0)
810  !theta0=theta0*theta0*theta0*(10.0+(6.0*theta0-15.0)*theta0)
811  do jl= 1, tripl_npoint(il)
812  tripl_ftrp(jl,il) = tripl_ftrp(jl,il) +
813  $ tripl_tdamp(il)*((1.0-theta0)*tripl_frcs(jl,4,il) +
814  $ theta0*tripl_frcs(jl,3,il))
815  enddo
816  endif
817  enddo
818 
819 #ifdef DEBUG
820  ! for testing
821  ! to output refinement
822  icalldl = icalldl+1
823  call io_file_freeid(iunit, ierr)
824  write(str1,'(i3.3)') nid
825  write(str2,'(i3.3)') icalldl
826  open(unit=iunit,file='trp_fcr.txt'//str1//'i'//str2)
827 
828  do il=1,tripl_npoint(1)
829  write(iunit,*) il,tripl_prj(il,1),tripl_ftrp(il,1),
830  $ tripl_frcs(il,1:4,1)
831  enddo
832 
833  close(iunit)
834 #endif
835 
836  return
837  end subroutine
838 !=======================================================================
subroutine bcast(buf, len)
Definition: comm_mpi.f:431
integer function gllel(ieg)
Definition: dprocmap.f:183
subroutine cross(v1, v2, v3)
Definition: genxyz.f:899
subroutine io_file_freeid(iunit, ierr)
Get free file unit number and store max unit value.
Definition: io_tools.f:47
subroutine math_rot3da(vo, vi, va, an)
3D rotation of a vector along given axis.
Definition: math_tools.f:332
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_logr(mid, priority, logs, rvar)
Write log message adding single real.
Definition: mntrlog.f:731
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_logrv(mid, priority, logs, rvarv, rvarn)
Write log message adding real vector of length n.
Definition: mntrlog.f:755
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
subroutine tripl_forcing(ffx, ffy, ffz, ix, iy, iz, ieg)
Compute tripping forcing.
Definition: tripl.f:376
subroutine tripl_register()
Register tripping module.
Definition: tripl.f:14
subroutine tripl_reset()
Reset tripping.
Definition: tripl.f:411
subroutine tripl_update()
Update tripping.
Definition: tripl.f:343
real function tripl_ran2(il)
A simple portable random number generator.
Definition: tripl.f:646
subroutine tripl_frcs_get(ifreset)
Generate forcing along 1D line.
Definition: tripl.f:688
logical function tripl_is_initialised()
Check if module was initialised.
Definition: tripl.f:330
subroutine tripl_rphs_get
Generate set of random phases.
Definition: tripl.f:569
subroutine tripl_1dprj()
Get 1D projection, array mapping and forcing smoothing.
Definition: tripl.f:446
subroutine tripl_init()
Initilise tripping module.
Definition: tripl.f:136
subroutine ifill(ia, ib, n)
Definition: math.f:252
subroutine copy(a, b, n)
Definition: math.f:260
subroutine cmult(a, const, n)
Definition: math.f:315
subroutine rzero(a, n)
Definition: math.f:208
subroutine sort(a, ind, n)
Definition: math.f:1325