source: trunk/LMDZ.COMMON/libf/evolution/orbit_param_criterion_mod.F90 @ 3820

Last change on this file since 3820 was 3791, checked in by jbclement, 4 weeks ago

PEM:
Correction and simplification to compute the maximum number of years according to the changes in Lsp + update of "run_PEM.def".
JBC

File size: 8.8 KB
Line 
1MODULE orbit_param_criterion_mod
2
3!=======================================================================
4!
5! Purpose: Compute the maximum number of iteration for PEM based on the
6! stopping criterion given by the orbital parameters
7!
8! Author: RV, JBC
9!=======================================================================
10
11implicit none
12
13!=======================================================================
14contains
15!=======================================================================
16
17SUBROUTINE orbit_param_criterion(i_myear,n_myear_leg)
18
19#ifdef CPP_IOIPSL
20    use IOIPSL,          only: getin
21#else
22    ! if not using IOIPSL, we still need to use (a local version of) getin
23    use ioipsl_getincom, only: getin
24#endif
25#ifndef CPP_STD
26    use planete_h,    only: e_elips, obliquit, lsperi
27    use comcstfi_h,   only: pi
28#else
29    use planete_mod,  only: e_elips, obliquit, lsperi
30    use comcstfi_mod, only: pi
31#endif
32use time_evol_mod,  only: year_bp_ini, var_obl, var_ecc, var_lsp, convert_years
33use lask_param_mod, only: yearlask, obllask, ecclask, lsplask, ini_lask_param_mod, last_ilask
34
35implicit none
36
37!--------------------------------------------------------
38! Input Variables
39!--------------------------------------------------------
40real, intent(in) :: i_myear ! Martian year of the simulation
41
42!--------------------------------------------------------
43! Output Variables
44!--------------------------------------------------------
45real, intent(out) :: n_myear_leg ! Maximum number of iteration of the PEM before orb changes too much
46
47!--------------------------------------------------------
48! Local variables
49!--------------------------------------------------------
50real                            :: Year                                           ! Year of the simulation
51real                            :: Lsp                                            ! Ls perihelion
52real                            :: max_change_obl, max_change_ecc, max_change_lsp ! Maximum admissible change
53real                            :: max_obl, max_ecc, max_lsp                      ! Maximum value of orbit param given the admissible change
54real                            :: min_obl, min_ecc, min_lsp                      ! Minimum value of orbit param given the admissible change
55real                            :: max_obl_iter, max_ecc_iter, max_lsp_iter       ! Maximum year iteration before reaching an inadmissible value of orbit param
56integer                         :: ilask                                          ! Loop variable
57real                            :: xa, xb, ya, yb                                 ! Variables for interpolation
58logical                         :: found_obl, found_ecc, found_lsp                ! Flag variables for orbital parameters
59real                            :: lsp_corr                                       ! Lsp corrected if the "modulo is crossed"
60real                            :: delta                                          ! Intermediate variable
61real, dimension(:), allocatable :: lsplask_unwrap                                 ! Unwrapped sequence of Lsp from Laskar's file
62
63! **********************************************************************
64! 0. Initializations
65! **********************************************************************
66Year = year_bp_ini + i_myear ! We compute the current year
67Lsp = lsperi*180./pi         ! We convert in degree
68
69call ini_lask_param_mod() ! Allocation of variables
70
71write(*,*) 'orbit_param_criterion, Current year =', Year
72write(*,*) 'orbit_param_criterion, Current obl. =', obliquit
73write(*,*) 'orbit_param_criterion, Current ecc. =', e_elips
74write(*,*) 'orbit_param_criterion, Current Lsp  =', Lsp
75
76! We read the file
77open(73,file = 'obl_ecc_lsp.asc')
78last_ilask = 0
79do ilask = 1,size(yearlask,1)
80    read(73,*) yearlask(ilask), obllask(ilask), ecclask(ilask), lsplask(ilask)
81    yearlask(ilask) = yearlask(ilask)*1000./convert_years ! Conversion from Laskar's kilo Earth years to PEM Martian years
82    if (yearlask(ilask) > Year) last_ilask = ilask + 1
83enddo
84close(73)
85if (last_ilask == 0 .or. last_ilask == size(yearlask,1) + 1) then
86    error stop 'The current year could not be found in the file "obl_ecc_lsp.asc".'
87else
88    write(*,*) 'The current year in the "obl_ecc_lsp.asc" file is at line:', last_ilask
89endif
90
91! Unwrap the Lsp changes in Laskar's file
92allocate(lsplask_unwrap(last_ilask))
93lsplask_unwrap(last_ilask) = lsplask(last_ilask)
94do ilask = last_ilask,2,-1
95    delta = lsplask(ilask - 1) - lsplask(ilask)
96    if (delta > 180.) then
97        lsp_corr = lsplask(ilask - 1) - 360.
98    else if (delta < -180.) then
99        lsp_corr = lsplask(ilask - 1) + 360.
100    else
101        lsp_corr = lsplask(ilask - 1)
102    endif
103    lsplask_unwrap(ilask - 1) = lsplask_unwrap(ilask) + lsp_corr - lsplask(ilask)
104enddo
105
106! Correct the current Lsp according to the unwrapping
107delta = Lsp - lsplask_unwrap(last_ilask)
108if (delta > 180.) then
109    Lsp = Lsp - 360.
110else if (delta < -180.) then
111    Lsp = Lsp + 360.
112endif
113
114! Constant max change case
115max_change_obl = 1.
116max_change_ecc = 5.e-3
117max_change_lsp = 20.
118
119call getin('max_change_obl',max_change_obl)
120max_obl = obliquit + max_change_obl
121min_obl = obliquit - max_change_obl
122write(*,*) 'Maximum obliquity accepted =', max_obl
123write(*,*) 'Minimum obliquity accepted =', min_obl
124
125call getin('max_change_ecc',max_change_ecc)
126max_ecc = min(e_elips + max_change_ecc,1. - 1.e-10) ! ecc < 1.
127min_ecc = max(e_elips - max_change_ecc,0.) ! ecc >= 0.
128write(*,*) 'Maximum eccentricity accepted =', max_ecc
129write(*,*) 'Minimum eccentricity accepted =', min_ecc
130
131call getin('max_change_lsp',max_change_lsp)
132max_lsp = Lsp + max_change_lsp
133min_lsp = Lsp - max_change_lsp
134write(*,*) 'Maximum Lsp accepted =', max_lsp
135write(*,*) 'Minimum Lsp accepted =', min_lsp
136! End Constant max change case
137
138! If we do not want some orb parameter to change, they should not be a stopping criterion,
139! So the number of iteration corresponding is set to maximum
140max_obl_iter = 1000000.
141max_ecc_iter = 1000000.
142max_lsp_iter = 1000000.
143
144! The maximum reachable year is found by interpolation according to the maximum admissible change of orbital parameters
145found_obl = .false.
146found_ecc = .false.
147found_lsp = .false.
148if (.not. var_obl) found_obl = .true.
149if (.not. var_ecc) found_ecc = .true.
150if (.not. var_lsp) found_lsp = .true.
151
152do ilask = last_ilask,2,-1
153    xa = yearlask(ilask)
154    xb = yearlask(ilask - 1)
155
156    ! Obliquity
157    if (var_obl .and. .not. found_obl) then
158        ya = obllask(ilask)
159        yb = obllask(ilask - 1)
160        if (yb < min_obl) then ! The minimum accepted is overtaken
161            max_obl_iter = (min_obl - ya)*(xb - xa)/(yb - ya) + xa - Year
162            found_obl = .true.
163        else if (max_obl < yb) then ! The maximum accepted is overtaken
164            max_obl_iter = (max_obl - ya)*(xb - xa)/(yb - ya) + xa - Year
165            found_obl = .true.
166        endif
167    endif
168
169    ! Eccentricity
170    if (var_ecc .and. .not. found_ecc) then
171        ya = ecclask(ilask)
172        yb = ecclask(ilask - 1)
173        if (yb < min_ecc) then ! The minimum accepted is overtaken
174            max_ecc_iter = (min_ecc - ya)*(xb - xa)/(yb - ya) + xa - Year
175            found_ecc = .true.
176        else if (max_ecc < yb) then ! The maximum accepted is overtaken
177            max_ecc_iter = (max_ecc - ya)*(xb - xa)/(yb - ya) + xa - Year
178            found_ecc = .true.
179        endif
180    endif
181
182    ! Lsp
183    if (var_lsp .and. .not. found_lsp) then
184        ya = lsplask_unwrap(ilask)
185        yb = lsplask_unwrap(ilask - 1)
186        if (yb < min_lsp) then ! The minimum accepted is overtaken
187            max_lsp_iter = (min_lsp - ya)*(xb - xa)/(yb - ya) + xa - Year
188            found_lsp = .true.
189        else if (max_lsp < yb) then ! The maximum accepted is overtaken
190            max_lsp_iter = (max_lsp - ya)*(xb - xa)/(yb - ya) + xa - Year
191            found_lsp = .true.
192        endif
193    endif
194
195    if (found_obl .and. found_ecc .and. found_lsp) exit ! The loop is left as soon as everything is found
196enddo
197
198deallocate(lsplask_unwrap)
199
200if (.not. found_obl) write(*,*) 'The maximum reachable year for obl. could not be found in the file "obl_ecc_lsp.asc".'
201if (.not. found_ecc) write(*,*) 'The maximum reachable year for ecc. could not be found in the file "obl_ecc_lsp.asc".'
202if (.not. found_lsp) write(*,*) 'The maximum reachable year for Lsp could not be found in the file "obl_ecc_lsp.asc".'
203
204write(*,*) 'Max. number of iterations for the obl. parameter =', max_obl_iter
205write(*,*) 'Max. number of iterations for the ecc. parameter =', max_ecc_iter
206write(*,*) 'Max. number of iterations for the Lsp parameter  =', max_lsp_iter
207
208n_myear_leg = min(max_obl_iter,max_ecc_iter,max_lsp_iter)
209if (n_myear_leg < 1.) n_myear_leg = 1. ! n_myear_leg should be at least equal to 1
210write(*,*) 'So the max. number of iterations for the orbital criteria =', n_myear_leg
211
212END SUBROUTINE orbit_param_criterion
213
214!***********************************************************************
215
216END MODULE orbit_param_criterion_mod
217
Note: See TracBrowser for help on using the repository browser.