1 | !> \file next-time.f90 |
---|
2 | !! Calcule le pas de temps dt de facon dynamique |
---|
3 | !< |
---|
4 | |
---|
5 | !> SUBROUTINE: next_time() |
---|
6 | !! \author ... |
---|
7 | !! \date ... |
---|
8 | !! @note subroutine qui calcule le pas de temps dt de facon dynamique |
---|
9 | !! @note En entree on donne le "first guess" de dt |
---|
10 | !! @note En sortie on recupere un dt qui permet eventuellement la synchronisation exacte avec dtt |
---|
11 | !< |
---|
12 | subroutine next_time(time,dt,dtt,dtmax,dtmin,isynchro,itracebug,num_tracebug) |
---|
13 | |
---|
14 | integer :: itracebug |
---|
15 | integer :: num_tracebug |
---|
16 | integer :: isynchro |
---|
17 | real :: dt |
---|
18 | real :: dtt |
---|
19 | real :: dtmax |
---|
20 | real :: dtmin |
---|
21 | real (kind=kind(0.d0)) :: time |
---|
22 | real (kind=kind(0.d0)) :: time_loc |
---|
23 | real (kind=kind(0.d0)) :: time2_loc |
---|
24 | real (kind=kind(0.d0)) :: timesup |
---|
25 | real (kind=kind(0.d0)) :: dtt_loc |
---|
26 | |
---|
27 | time_loc=time |
---|
28 | |
---|
29 | ! permet d'avoir dtt_loc sans probleme d'arrondi |
---|
30 | if (dtt.ge.1.) then |
---|
31 | dtt_loc=nint(dtt) |
---|
32 | else |
---|
33 | dtt_loc=nint(dtt*100.)/100. |
---|
34 | endif |
---|
35 | |
---|
36 | ! calcule (timesup) le temps de synchronisation ulterieur |
---|
37 | ! on ajoute dtmin*0.2 pour eviter des problemes d'arrondis |
---|
38 | |
---|
39 | timesup=dtt_loc*(floor((time_loc+0.2*dtmin)/dtt_loc)+1) |
---|
40 | !write(6,*) 'floor',floor((time_loc+0.2*dtmin)/dtt)+1 |
---|
41 | !write(6,*) timesup,real(timesup) |
---|
42 | |
---|
43 | dt=max(dtmin,dt) ! dt > = dtmin |
---|
44 | dt=min(dtmax,dt) ! dt <= dtmax |
---|
45 | |
---|
46 | ! time2_loc est le first guess de next time |
---|
47 | time2_loc=time_loc+dt |
---|
48 | ! write(6,*) dtt,time2_loc |
---|
49 | ! write(6,*)'time,time_loc,dtt,timesup,(floor((time_loc+0.2*dtmin)/dtt)+1),dt' |
---|
50 | ! write(6,*) time,time_loc,dtt_loc,timesup,(floor((time_loc+0.2*dtmin)/dtt)+1),dt |
---|
51 | ! si le nouveau temps est >= timesup next -> time=timesup |
---|
52 | ! idem si le nouveau temps est juste inferieur a timesup mais |
---|
53 | ! que l'ecart est inferieur a dtmin/2 pour éviter un pas de temps trop |
---|
54 | ! petit au pas de temps suivant |
---|
55 | |
---|
56 | if (time2_loc.ge.timesup-dtmin*0.5) then ! synchronisation |
---|
57 | dt=timesup-time |
---|
58 | time=timesup |
---|
59 | isynchro=1 |
---|
60 | |
---|
61 | else |
---|
62 | time=time2_loc |
---|
63 | isynchro=0 |
---|
64 | |
---|
65 | endif |
---|
66 | |
---|
67 | if (itracebug.eq.1)then |
---|
68 | write(num_tracebug,*) |
---|
69 | write(num_tracebug,*)'____________________________________________________' |
---|
70 | write(num_tracebug,888) time, timesup,dt, isynchro |
---|
71 | write(num_tracebug,*) |
---|
72 | end if |
---|
73 | 888 format ('time = ',f0.5,' timesup = ',f0.1,' dt = ',f0.5,' isynchro = ',i1) |
---|
74 | end subroutine next_time |
---|