Skip to content

Commit feb2ae4

Browse files
committed
Refactor (again) oscillation test
Refactor (again) oscillation test Why: Sanitize and simplify. Side effects: Emd RK does not use adaptive time step: it uses the same fixed time step of others in order to simplify comparison.
1 parent f36a3d6 commit feb2ae4

21 files changed

+1268
-1972
lines changed

src/lib/foodie.f90

Lines changed: 49 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,8 @@ module foodie
8282

8383
implicit none
8484
private
85-
public :: foodie_integrator
8685
public :: foodie_integrator_class_names
86+
public :: foodie_integrator_factory
8787
public :: foodie_integrator_schemes
8888
public :: integrand_object
8989
public :: integrator_object
@@ -105,32 +105,64 @@ module foodie
105105
public :: is_scheme_available
106106

107107
contains
108-
function foodie_integrator(scheme, stages, tolerance, nu, alpha) result(integrator)
109-
!< Return a concrete instance of [[integrator_object]] given a scheme selection.
110-
!<
111-
!< This is the FOODIE integrators factory.
112-
!<
113-
!< @note If an error occurs the error status of [[integrator_object]] is updated.
114-
character(*), intent(in) :: scheme !< Selected integrator given.
115-
integer(I_P), intent(in), optional :: stages !< Stages of multi-stage methods.
116-
real(R_P), intent(in), optional :: tolerance !< Tolerance on the local truncation error.
117-
real(R_P), intent(in), optional :: nu !< Williams-Robert-Asselin filter coefficient.
118-
real(R_P), intent(in), optional :: alpha !< Robert-Asselin filter coefficient.
119-
class(integrator_object), allocatable :: integrator !< The FOODIE integrator.
108+
pure function foodie_integrator_class_names() result(names)
109+
!< Return the list of available intergrator class of schemes names.
110+
character(len=99), allocatable :: names(:) !< Available integrator class names.
120111
type(integrator_adams_bashforth) :: int_adams_bashforth !< Integrator Adams Bashforth.
121112
type(integrator_adams_bashforth_moulton) :: int_adams_bashforth_moulton !< Integrator Adams Bashforth Moulton.
122113
type(integrator_adams_moulton) :: int_adams_moulton !< Integrator Adams Moulton.
123114
type(integrator_back_df) :: int_back_df !< Integrator back differentiation formula.
124115
type(integrator_euler_explicit) :: int_euler_explicit !< Integrator euler explicit.
125116
type(integrator_leapfrog) :: int_leapfrog !< Integrator leapfrog.
126-
type(integrator_lmm_ssp) :: int_lmm_ssp !< Integrator LMM SSP.
127-
type(integrator_lmm_ssp_vss) :: int_lmm_ssp_vss !< Integrator LMM SSP VSS.
117+
type(integrator_lmm_ssp) :: int_lmm_ssp !< Integrator lmm SSP.
118+
type(integrator_lmm_ssp_vss) :: int_lmm_ssp_vss !< Integrator lmm SSP VSS.
128119
type(integrator_ms_runge_kutta_ssp) :: int_ms_runge_kutta_ssp !< Integrator multistep Runge Kutta ssp.
129-
type(integrator_runge_kutta_emd) :: int_runge_kutta_emd !< Integrator Runge Kutta_embdedded.
120+
type(integrator_runge_kutta_emd) :: int_runge_kutta_emd !< Integrator Runge Kutta embdedded.
130121
type(integrator_runge_kutta_ls) :: int_runge_kutta_ls !< Integrator Runge Kutta low storage.
131122
type(integrator_runge_kutta_lssp) :: int_runge_kutta_lssp !< Integrator linear Runge Kutta SSP.
132123
type(integrator_runge_kutta_ssp) :: int_runge_kutta_ssp !< Integrator Runge Kutta SSP.
133124

125+
names = [ int_adams_bashforth % class_name()]
126+
names = [names, int_adams_bashforth_moulton % class_name()]
127+
names = [names, int_adams_moulton % class_name()]
128+
names = [names, int_back_df % class_name()]
129+
names = [names, int_euler_explicit % class_name()]
130+
names = [names, int_leapfrog % class_name()]
131+
names = [names, int_lmm_ssp % class_name()]
132+
names = [names, int_lmm_ssp_vss % class_name()]
133+
names = [names, int_ms_runge_kutta_ssp % class_name()]
134+
names = [names, int_runge_kutta_emd % class_name()]
135+
names = [names, int_runge_kutta_ls % class_name()]
136+
names = [names, int_runge_kutta_lssp % class_name()]
137+
names = [names, int_runge_kutta_ssp % class_name()]
138+
endfunction foodie_integrator_class_names
139+
140+
subroutine foodie_integrator_factory(scheme, integrator, stages, tolerance, nu, alpha)
141+
!< Return a concrete instance of [[integrator_object]] given a scheme selection.
142+
!<
143+
!< This is the FOODIE integrators factory.
144+
!<
145+
!< @note If an error occurs the error status of [[integrator_object]] is updated.
146+
character(*), intent(in) :: scheme !< Selected integrator given.
147+
class(integrator_object), allocatable, intent(out) :: integrator !< The FOODIE integrator.
148+
integer(I_P), optional, intent(in) :: stages !< Stages of multi-stage methods.
149+
real(R_P), optional, intent(in) :: tolerance !< Tolerance on the local truncation error.
150+
real(R_P), optional, intent(in) :: nu !< Williams-Robert-Asselin filter coefficient.
151+
real(R_P), optional, intent(in) :: alpha !< Robert-Asselin filter coefficient.
152+
type(integrator_adams_bashforth) :: int_adams_bashforth !< Integrator Adams Bashforth.
153+
type(integrator_adams_bashforth_moulton) :: int_adams_bashforth_moulton !< Integrator Adams Bashforth Moulton.
154+
type(integrator_adams_moulton) :: int_adams_moulton !< Integrator Adams Moulton.
155+
type(integrator_back_df) :: int_back_df !< Integrator back differentiation formula.
156+
type(integrator_euler_explicit) :: int_euler_explicit !< Integrator euler explicit.
157+
type(integrator_leapfrog) :: int_leapfrog !< Integrator leapfrog.
158+
type(integrator_lmm_ssp) :: int_lmm_ssp !< Integrator LMM SSP.
159+
type(integrator_lmm_ssp_vss) :: int_lmm_ssp_vss !< Integrator LMM SSP VSS.
160+
type(integrator_ms_runge_kutta_ssp) :: int_ms_runge_kutta_ssp !< Integrator multistep Runge Kutta ssp.
161+
type(integrator_runge_kutta_emd) :: int_runge_kutta_emd !< Integrator Runge Kutta_embdedded.
162+
type(integrator_runge_kutta_ls) :: int_runge_kutta_ls !< Integrator Runge Kutta low storage.
163+
type(integrator_runge_kutta_lssp) :: int_runge_kutta_lssp !< Integrator linear Runge Kutta SSP.
164+
type(integrator_runge_kutta_ssp) :: int_runge_kutta_ssp !< Integrator Runge Kutta SSP.
165+
134166
if (index(trim(adjustl(scheme)), trim(int_adams_bashforth_moulton%class_name())) > 0) then
135167
allocate(integrator_adams_bashforth_moulton :: integrator)
136168
select type(integrator)
@@ -209,39 +241,7 @@ function foodie_integrator(scheme, stages, tolerance, nu, alpha) result(integrat
209241
write(stderr, '(A)')'error: "'//trim(adjustl(scheme))//'" scheme is unknown!'
210242
stop
211243
endif
212-
endfunction foodie_integrator
213-
214-
pure function foodie_integrator_class_names() result(names)
215-
!< Return the list of available intergrator class of schemes names.
216-
character(len=99), allocatable :: names(:) !< Available integrator class names.
217-
type(integrator_adams_bashforth) :: int_adams_bashforth !< Integrator Adams Bashforth.
218-
type(integrator_adams_bashforth_moulton) :: int_adams_bashforth_moulton !< Integrator Adams Bashforth Moulton.
219-
type(integrator_adams_moulton) :: int_adams_moulton !< Integrator Adams Moulton.
220-
type(integrator_back_df) :: int_back_df !< Integrator back differentiation formula.
221-
type(integrator_euler_explicit) :: int_euler_explicit !< Integrator euler explicit.
222-
type(integrator_leapfrog) :: int_leapfrog !< Integrator leapfrog.
223-
type(integrator_lmm_ssp) :: int_lmm_ssp !< Integrator lmm SSP.
224-
type(integrator_lmm_ssp_vss) :: int_lmm_ssp_vss !< Integrator lmm SSP VSS.
225-
type(integrator_ms_runge_kutta_ssp) :: int_ms_runge_kutta_ssp !< Integrator multistep Runge Kutta ssp.
226-
type(integrator_runge_kutta_emd) :: int_runge_kutta_emd !< Integrator Runge Kutta embdedded.
227-
type(integrator_runge_kutta_ls) :: int_runge_kutta_ls !< Integrator Runge Kutta low storage.
228-
type(integrator_runge_kutta_lssp) :: int_runge_kutta_lssp !< Integrator linear Runge Kutta SSP.
229-
type(integrator_runge_kutta_ssp) :: int_runge_kutta_ssp !< Integrator Runge Kutta SSP.
230-
231-
names = [ int_adams_bashforth % class_name()]
232-
names = [names, int_adams_bashforth_moulton % class_name()]
233-
names = [names, int_adams_moulton % class_name()]
234-
names = [names, int_back_df % class_name()]
235-
names = [names, int_euler_explicit % class_name()]
236-
names = [names, int_leapfrog % class_name()]
237-
names = [names, int_lmm_ssp % class_name()]
238-
names = [names, int_lmm_ssp_vss % class_name()]
239-
names = [names, int_ms_runge_kutta_ssp % class_name()]
240-
names = [names, int_runge_kutta_emd % class_name()]
241-
names = [names, int_runge_kutta_ls % class_name()]
242-
names = [names, int_runge_kutta_lssp % class_name()]
243-
names = [names, int_runge_kutta_ssp % class_name()]
244-
endfunction foodie_integrator_class_names
244+
endsubroutine foodie_integrator_factory
245245

246246
pure function foodie_integrator_schemes(class_name) result(schemes)
247247
!< Return the list of all available intergrator schemes, or only the schemes belonging to the given class name.

src/lib/foodie_integrator_adams_bashforth.f90

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,22 +53,28 @@ module foodie_integrator_adams_bashforth
5353
trim(class_name_)//'_15', &
5454
trim(class_name_)//'_16'] !< List of supported schemes.
5555

56-
logical, parameter :: has_fast_mode_=.true. !< Flag to check if integrator provides *fast mode* integrate.
56+
logical, parameter :: has_fast_mode_=.true. !< Flag to check if integrator provides *fast mode* integrate.
57+
logical, parameter :: is_multistage_=.false. !< Flag to check if integrator is multistage.
58+
logical, parameter :: is_multistep_=.true. !< Flag to check if integrator is multistep.
5759

5860
type, extends(integrator_object) :: integrator_adams_bashforth
5961
!< FOODIE integrator: provide an explicit class of Adams-Bashforth multi-step schemes, from 1st to 16th order accurate.
6062
!<
6163
!< @note The integrator must be created or initialized (initialize the *b* coefficients) before used.
6264
private
63-
integer(I_P), public :: steps=0 !< Number of time steps.
65+
integer(I_P) :: steps=0 !< Number of time steps.
6466
real(R_P), allocatable :: b(:) !< *b* coefficients.
6567
contains
6668
! deferred methods
6769
procedure, pass(self) :: class_name !< Return the class name of schemes.
6870
procedure, pass(self) :: description !< Return pretty-printed object description.
6971
procedure, pass(self) :: has_fast_mode !< Return .true. if the integrator class has *fast mode* integrate.
7072
procedure, pass(lhs) :: integr_assign_integr !< Operator `=`.
73+
procedure, pass(self) :: is_multistage !< Return .true. for multistage integrator.
74+
procedure, pass(self) :: is_multistep !< Return .true. for multistep integrator.
7175
procedure, pass(self) :: is_supported !< Return .true. if the integrator class support the given scheme.
76+
procedure, pass(self) :: stages_number !< Return number of stages used.
77+
procedure, pass(self) :: steps_number !< Return number of steps used.
7278
procedure, pass(self) :: supported_schemes !< Return the list of supported schemes.
7379
! public methods
7480
procedure, pass(self) :: destroy !< Destroy the integrator.
@@ -128,6 +134,22 @@ pure subroutine integr_assign_integr(lhs, rhs)
128134
endselect
129135
endsubroutine integr_assign_integr
130136

137+
elemental function is_multistage(self)
138+
!< Return .true. for multistage integrator.
139+
class(integrator_adams_bashforth), intent(in) :: self !< Integrator.
140+
logical :: is_multistage !< Inquire result.
141+
142+
is_multistage = is_multistage_
143+
endfunction is_multistage
144+
145+
elemental function is_multistep(self)
146+
!< Return .true. for multistage integrator.
147+
class(integrator_adams_bashforth), intent(in) :: self !< Integrator.
148+
logical :: is_multistep !< Inquire result.
149+
150+
is_multistep = is_multistep_
151+
endfunction is_multistep
152+
131153
elemental function is_supported(self, scheme)
132154
!< Return .true. if the integrator class support the given scheme.
133155
class(integrator_adams_bashforth), intent(in) :: self !< Integrator.
@@ -144,6 +166,22 @@ elemental function is_supported(self, scheme)
144166
enddo
145167
endfunction is_supported
146168

169+
elemental function stages_number(self)
170+
!< Return number of stages used.
171+
class(integrator_adams_bashforth), intent(in) :: self !< Integrator.
172+
integer(I_P) :: stages_number !< Number of stages used.
173+
174+
stages_number = 0
175+
endfunction stages_number
176+
177+
elemental function steps_number(self)
178+
!< Return number of steps used.
179+
class(integrator_adams_bashforth), intent(in) :: self !< Integrator.
180+
integer(I_P) :: steps_number !< Number of steps used.
181+
182+
steps_number = self%steps
183+
endfunction steps_number
184+
147185
pure function supported_schemes(self) result(schemes)
148186
!< Return the list of supported schemes.
149187
class(integrator_adams_bashforth), intent(in) :: self !< Integrator.

src/lib/foodie_integrator_adams_bashforth_moulton.f90

Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,14 +105,16 @@ module foodie_integrator_adams_bashforth_moulton
105105
trim(class_name_)//'_15', &
106106
trim(class_name_)//'_16'] !< List of supported schemes.
107107

108-
logical, parameter :: has_fast_mode_=.true. !< Flag to check if integrator provides *fast mode* integrate.
108+
logical, parameter :: has_fast_mode_=.true. !< Flag to check if integrator provides *fast mode* integrate.
109+
logical, parameter :: is_multistage_=.false. !< Flag to check if integrator is multistage.
110+
logical, parameter :: is_multistep_=.true. !< Flag to check if integrator is multistep.
109111

110112
type, extends(integrator_object) :: integrator_adams_bashforth_moulton
111113
!< FOODIE integrator: provide an explicit class of Adams-Bashforth-Moulton multi-step schemes, from 1st to 4rd order accurate.
112114
!<
113115
!< @note The integrator must be created or initialized (predictor and corrector schemes selection) before used.
114116
private
115-
integer(I_P), public :: steps=0 !< Number of time steps.
117+
integer(I_P) :: steps=0 !< Number of time steps.
116118
type(integrator_adams_bashforth) :: predictor !< Predictor solver.
117119
type(integrator_adams_moulton) :: corrector !< Corrector solver.
118120
contains
@@ -121,7 +123,11 @@ module foodie_integrator_adams_bashforth_moulton
121123
procedure, pass(self) :: description !< Return pretty-printed object description.
122124
procedure, pass(self) :: has_fast_mode !< Return .true. if the integrator class has *fast mode* integrate.
123125
procedure, pass(lhs) :: integr_assign_integr !< Operator `=`.
126+
procedure, pass(self) :: is_multistage !< Return .true. for multistage integrator.
127+
procedure, pass(self) :: is_multistep !< Return .true. for multistep integrator.
124128
procedure, pass(self) :: is_supported !< Return .true. if the integrator class support the given scheme.
129+
procedure, pass(self) :: stages_number !< Return number of stages used.
130+
procedure, pass(self) :: steps_number !< Return number of steps used.
125131
procedure, pass(self) :: supported_schemes !< Return the list of supported schemes.
126132
! public methods
127133
procedure, pass(self) :: destroy !< Destroy the integrator.
@@ -182,6 +188,22 @@ pure subroutine integr_assign_integr(lhs, rhs)
182188
endselect
183189
endsubroutine integr_assign_integr
184190

191+
elemental function is_multistage(self)
192+
!< Return .true. for multistage integrator.
193+
class(integrator_adams_bashforth_moulton), intent(in) :: self !< Integrator.
194+
logical :: is_multistage !< Inquire result.
195+
196+
is_multistage = is_multistage_
197+
endfunction is_multistage
198+
199+
elemental function is_multistep(self)
200+
!< Return .true. for multistage integrator.
201+
class(integrator_adams_bashforth_moulton), intent(in) :: self !< Integrator.
202+
logical :: is_multistep !< Inquire result.
203+
204+
is_multistep = is_multistep_
205+
endfunction is_multistep
206+
185207
elemental function is_supported(self, scheme)
186208
!< Return .true. if the integrator class support the given scheme.
187209
class(integrator_adams_bashforth_moulton), intent(in) :: self !< Integrator.
@@ -198,6 +220,22 @@ elemental function is_supported(self, scheme)
198220
enddo
199221
endfunction is_supported
200222

223+
elemental function stages_number(self)
224+
!< Return number of stages used.
225+
class(integrator_adams_bashforth_moulton), intent(in) :: self !< Integrator.
226+
integer(I_P) :: stages_number !< Number of stages used.
227+
228+
stages_number = 0
229+
endfunction stages_number
230+
231+
elemental function steps_number(self)
232+
!< Return number of steps used.
233+
class(integrator_adams_bashforth_moulton), intent(in) :: self !< Integrator.
234+
integer(I_P) :: steps_number !< Number of steps used.
235+
236+
steps_number = self%steps
237+
endfunction steps_number
238+
201239
pure function supported_schemes(self) result(schemes)
202240
!< Return the list of supported schemes.
203241
class(integrator_adams_bashforth_moulton), intent(in) :: self !< Integrator.
@@ -233,7 +271,7 @@ subroutine initialize(self, scheme)
233271
schemes_am = self%corrector%supported_schemes()
234272
call self%predictor%initialize(scheme=schemes_ab(scheme_number_))
235273
call self%corrector%initialize(scheme=schemes_am(scheme_number_))
236-
self%steps = self%predictor%steps
274+
self%steps = self%predictor%steps_number()
237275
else
238276
call self%trigger_error(error=ERROR_UNSUPPORTED_SCHEME, &
239277
error_message='"'//trim(adjustl(scheme))//'" unsupported scheme', &

0 commit comments

Comments
 (0)