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)) :: test_time |
---|
24 | real (kind=kind(0.d0)) :: time2_loc |
---|
25 | real (kind=kind(0.d0)) :: timesup |
---|
26 | real (kind=kind(0.d0)) :: dtt_loc |
---|
27 | |
---|
28 | time_loc=time |
---|
29 | |
---|
30 | ! permet d'avoir dtt_loc sans probleme d'arrondi |
---|
31 | if (dtt.ge.1.) then |
---|
32 | dtt_loc=nint(dtt) |
---|
33 | else |
---|
34 | dtt_loc=nint(dtt*100.)/100. |
---|
35 | endif |
---|
36 | |
---|
37 | ! calcule (timesup) le temps de synchronisation ulterieur |
---|
38 | ! on ajoute dtmin*0.2 pour eviter des problemes d'arrondis |
---|
39 | |
---|
40 | timesup=dtt_loc*(floor((time_loc+0.2*dtmin)/dtt_loc)+1) |
---|
41 | !write(6,*) 'floor',floor((time_loc+0.2*dtmin)/dtt)+1 |
---|
42 | !write(6,*) timesup,real(timesup) |
---|
43 | |
---|
44 | dt=max(dtmin,dt) ! dt > = dtmin |
---|
45 | dt=min(dtmax,dt) ! dt <= dtmax |
---|
46 | |
---|
47 | ! time2_loc est le first guess de next time |
---|
48 | time2_loc=time_loc+dt |
---|
49 | ! write(6,*) dtt,time2_loc |
---|
50 | ! write(6,*)'time,time_loc,dtt,timesup,(floor((time_loc+0.2*dtmin)/dtt)+1),dt' |
---|
51 | ! write(6,*) time,time_loc,dtt_loc,timesup,(floor((time_loc+0.2*dtmin)/dtt)+1),dt |
---|
52 | ! si le nouveau temps est >= timesup next -> time=timesup |
---|
53 | ! idem si le nouveau temps est juste inferieur a timesup mais |
---|
54 | ! que l'ecart est inferieur a dtmin/2 pour éviter un pas de temps trop |
---|
55 | ! petit au pas de temps suivant |
---|
56 | |
---|
57 | if (time2_loc.ge.timesup-dtmin*0.5) then ! synchronisation |
---|
58 | dt=timesup-time |
---|
59 | time=timesup |
---|
60 | isynchro=1 |
---|
61 | |
---|
62 | else |
---|
63 | time=time2_loc |
---|
64 | isynchro=0 |
---|
65 | |
---|
66 | endif |
---|
67 | |
---|
68 | if (itracebug.eq.1)then |
---|
69 | write(num_tracebug,*) |
---|
70 | write(num_tracebug,*)'____________________________________________________' |
---|
71 | write(num_tracebug,888) time, timesup,dt, isynchro |
---|
72 | write(num_tracebug,*) |
---|
73 | end if |
---|
74 | 888 format ('time = ',f0.5,' timesup = ',f0.1,' dt = ',f0.5,' isynchro = ',i1) |
---|
75 | end subroutine next_time |
---|