Skip to content

Commit b67b138

Browse files
committed
add intermediate abstract integrand tester
1 parent 112765c commit b67b138

File tree

4 files changed

+140
-94
lines changed

4 files changed

+140
-94
lines changed

src/tests/tester/foodie_test_integrand_ladvection.f90

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,15 @@ module foodie_test_integrand_ladvection
88
use, intrinsic :: iso_fortran_env, only : stderr=>error_unit
99
use flap, only : command_line_interface
1010
use foodie, only : integrand_object
11+
use foodie_test_integrand_tester_object, only : integrand_tester_object
1112
use penf, only : FR_P, I_P, R_P, str
1213
use wenoof, only : interpolator_object, wenoof_create
1314

1415
implicit none
1516
private
1617
public :: integrand_ladvection
1718

18-
type, extends(integrand_object) :: integrand_ladvection
19+
type, extends(integrand_tester_object) :: integrand_ladvection
1920
!< 1D linear advection field.
2021
!<
2122
!< It is a FOODIE integrand class concrete extension.
@@ -56,15 +57,15 @@ module foodie_test_integrand_ladvection
5657
class(interpolator_object), allocatable :: interpolator !< WENO interpolator.
5758
contains
5859
! auxiliary methods
59-
procedure, pass(self), public :: destroy !< Destroy field.
60-
procedure, pass(self), public :: dt => compute_dt !< Compute the current time step, by means of CFL condition.
61-
procedure, pass(self), public :: exact_solution !< Return exact solution.
62-
procedure, pass(self), public :: export_tecplot !< Export integrand to Tecplot file.
63-
procedure, pass(self), public :: output !< Extract integrand state field.
64-
procedure, pass(self), public :: parse_cli !< Initialize from command line interface.
65-
procedure, nopass, public :: set_cli !< Set command line interface.
66-
procedure, pass(self), public :: set_square_wave_initial_state !< Set initial state as a square wave.
67-
! public deferred methods
60+
procedure, pass(self), public :: destroy !< Destroy field.
61+
procedure, pass(self), public :: dt => compute_dt !< Compute the current time step, by means of CFL condition.
62+
procedure, pass(self), public :: exact_solution !< Return exact solution.
63+
procedure, pass(self), public :: output !< Extract integrand state field.
64+
! integrand_tester_object deferred methods
65+
procedure, pass(self), public :: export_tecplot !< Export integrand to Tecplot file.
66+
procedure, pass(self), public :: parse_cli !< Initialize from command line interface.
67+
procedure, nopass, public :: set_cli !< Set command line interface.
68+
! integrand_object deferred methods
6869
procedure, pass(self), public :: integrand_dimension !< Return integrand dimension.
6970
procedure, pass(self), public :: t => dU_dt !< Time derivative, residuals.
7071
! operators
@@ -93,8 +94,9 @@ module foodie_test_integrand_ladvection
9394
! procedure, pass(opr), public :: integrand_multiply_real_scalar_fast !< `* real_scalar` fast operator.
9495
! procedure, pass(opr), public :: integrand_subtract_integrand_fast !< `-` fast operator.
9596
! private methods
96-
procedure, pass(self), private :: impose_boundary_conditions !< Impose boundary conditions.
97-
procedure, pass(self), private :: reconstruct_interfaces !< Reconstruct interface states.
97+
procedure, pass(self), private :: impose_boundary_conditions !< Impose boundary conditions.
98+
procedure, pass(self), private :: reconstruct_interfaces !< Reconstruct interface states.
99+
procedure, pass(self), private :: set_square_wave_initial_state !< Set initial state as a square wave.
98100
endtype integrand_ladvection
99101

100102
contains
@@ -131,6 +133,15 @@ pure function exact_solution(self, u0, t) result(exact)
131133

132134
endfunction exact_solution
133135

136+
pure function output(self) result(state)
137+
!< Output the advection field state.
138+
class(integrand_ladvection), intent(in) :: self !< Advection field.
139+
real(R_P), allocatable :: state(:) !< Advection state
140+
141+
state = self%u(1:self%Ni)
142+
endfunction output
143+
144+
! integrand_tester_object deferred methods
134145
subroutine export_tecplot(self, file_name, t, scheme, close_file)
135146
!< Export integrand to Tecplot file.
136147
class(integrand_ladvection), intent(in) :: self !< Advection field.
@@ -163,14 +174,6 @@ subroutine export_tecplot(self, file_name, t, scheme, close_file)
163174
endif
164175
endsubroutine export_tecplot
165176

166-
pure function output(self) result(state)
167-
!< Output the advection field state.
168-
class(integrand_ladvection), intent(in) :: self !< Advection field.
169-
real(R_P), allocatable :: state(:) !< Advection state
170-
171-
state = self%u(1:self%Ni)
172-
endfunction output
173-
174177
subroutine parse_cli(self, cli)
175178
!< Initialize from command line interface.
176179
class(integrand_ladvection), intent(inout) :: self !< Advection field.
@@ -218,7 +221,7 @@ subroutine set_cli(cli)
218221
def='square_wave', choices='square_wave')
219222
endsubroutine set_cli
220223

221-
! ADT integrand deferred methods
224+
! integrand_object deferred methods
222225
function dU_dt(self, t) result(dState_dt)
223226
!< Time derivative of advection field, the residuals function.
224227
class(integrand_ladvection), intent(in) :: self !< Advection field.

src/tests/tester/foodie_test_integrand_oscillation.f90

Lines changed: 30 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,14 @@ module foodie_test_integrand_oscillation
55

66
use flap, only : command_line_interface
77
use foodie, only : integrand_object
8+
use foodie_test_integrand_tester_object, only : integrand_tester_object
89
use penf, only : FR_P, R_P, I_P, str
910

1011
implicit none
1112
private
1213
public :: integrand_oscillation
1314

14-
type, extends(integrand_object) :: integrand_oscillation
15+
type, extends(integrand_tester_object) :: integrand_oscillation
1516
!< The oscillation equations field.
1617
!<
1718
!< It is a FOODIE integrand class concrete extension.
@@ -50,12 +51,13 @@ module foodie_test_integrand_oscillation
5051
! auxiliary methods
5152
procedure, pass(self), public :: amplitude_phase !< Return amplitude and phase of the oscillation.
5253
procedure, pass(self), public :: exact_solution !< Return exact solution.
53-
procedure, pass(self), public :: export_tecplot !< Export integrand to Tecplot file.
5454
procedure, pass(self), public :: initialize !< Initialize integrand.
5555
procedure, pass(self), public :: output !< Extract integrand state field.
56-
procedure, pass(self), public :: parse_cli !< Initialize from command line interface.
57-
procedure, nopass, public :: set_cli !< Set command line interface.
58-
! public deferred methods
56+
! integrand_tester_object deferred methods
57+
procedure, pass(self), public :: export_tecplot !< Export integrand to Tecplot file.
58+
procedure, pass(self), public :: parse_cli !< Initialize from command line interface.
59+
procedure, nopass, public :: set_cli !< Set command line interface.
60+
! integrand_object deferred methods
5961
procedure, pass(self), public :: integrand_dimension !< Return integrand dimension.
6062
procedure, pass(self), public :: t => dU_dt !< Time derivative, residuals.
6163
! operators
@@ -106,6 +108,26 @@ pure function exact_solution(self, t) result(exact)
106108
exact(2) = self%U0(1) * sin(self%f * t) + self%U0(2) * cos(self%f * t)
107109
endfunction exact_solution
108110

111+
pure subroutine initialize(self, U0, frequency)
112+
!< Initialize integrand.
113+
class(integrand_oscillation), intent(inout) :: self !< Integrand.
114+
real(R_P), intent(in) :: U0(1:2) !< Initial state.
115+
real(R_P), intent(in) :: frequency !< Frequency of oscillation.
116+
117+
self%U = U0
118+
self%f = frequency
119+
self%U0 = U0
120+
endsubroutine initialize
121+
122+
pure function output(self) result(state)
123+
!< Extract integrand state field.
124+
class(integrand_oscillation), intent(in) :: self !< Integrand.
125+
real(R_P) :: state(1:2) !< State.
126+
127+
state = self%U
128+
endfunction output
129+
130+
! integrand_tester_object deferred methods
109131
subroutine export_tecplot(self, file_name, t, scheme, close_file)
110132
!< Export integrand to Tecplot file.
111133
class(integrand_oscillation), intent(in) :: self !< Advection field.
@@ -138,30 +160,10 @@ subroutine export_tecplot(self, file_name, t, scheme, close_file)
138160
endif
139161
endsubroutine export_tecplot
140162

141-
pure subroutine initialize(self, U0, frequency)
142-
!< Initialize integrand.
143-
class(integrand_oscillation), intent(inout) :: self !< Integrand.
144-
real(R_P), intent(in) :: U0(1:2) !< Initial state.
145-
real(R_P), intent(in) :: frequency !< Frequency of oscillation.
146-
147-
self%U = U0
148-
self%f = frequency
149-
self%U0 = U0
150-
endsubroutine initialize
151-
152-
pure function output(self) result(state)
153-
!< Extract integrand state field.
154-
class(integrand_oscillation), intent(in) :: self !< Integrand.
155-
real(R_P) :: state(1:2) !< State.
156-
157-
state = self%U
158-
endfunction output
159-
160163
subroutine parse_cli(self, cli)
161164
!< Initialize from command line interface.
162-
class(integrand_oscillation), intent(inout) :: self !< Advection field.
163-
type(command_line_interface), intent(inout) :: cli !< Command line interface handler.
164-
character(99) :: initial_state !< Initial state.
165+
class(integrand_oscillation), intent(inout) :: self !< Advection field.
166+
type(command_line_interface), intent(inout) :: cli !< Command line interface handler.
165167

166168
call cli%get(switch='-f', val=self%f, error=cli%error) ; if (cli%error/=0) stop
167169
call cli%get(switch='-U0', val=self%U0, error=cli%error) ; if (cli%error/=0) stop
@@ -176,7 +178,7 @@ subroutine set_cli(cli)
176178
call cli%add(switch='--U0', switch_ab='-U0', nargs='2', help='initial state', required=.false., def='0.0 1.0', act='store')
177179
endsubroutine set_cli
178180

179-
! deferred methods
181+
! integrand_object deferred methods
180182
pure function integrand_dimension(self)
181183
!< return integrand dimension.
182184
class(integrand_oscillation), intent(in) :: self !< integrand.
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
!< Define [[integrand_tester_object]], the abstract tester integrand.
2+
3+
module foodie_test_integrand_tester_object
4+
!< Define [[integrand_tester_object]], the abstract tester integrand.
5+
6+
use flap, only : command_line_interface
7+
use foodie, only : integrand_object
8+
use penf, only : FR_P, R_P, I_P, str
9+
10+
implicit none
11+
private
12+
public :: integrand_tester_object
13+
14+
type, abstract, extends(integrand_object) :: integrand_tester_object
15+
!< The abstract tester integrand.
16+
!<
17+
!< This abstract provided some auxiliary methods useful for the tester machinery.
18+
contains
19+
! auxiliary methods
20+
procedure(export_tecplot_interface), pass(self), deferred :: export_tecplot !< Export integrand to Tecplot file.
21+
procedure(parse_cli_interface), pass(self), deferred :: parse_cli !< Initialize from command line interface.
22+
procedure(set_cli_interface), nopass, deferred :: set_cli !< Set command line interface.
23+
endtype integrand_tester_object
24+
25+
abstract interface
26+
!< Abstract interfaces of [[integrand_tester_object]] class.
27+
subroutine export_tecplot_interface(self, file_name, t, scheme, close_file)
28+
!< Export integrand to Tecplot file.
29+
import :: integrand_tester_object, R_P
30+
class(integrand_tester_object), intent(in) :: self !< Advection field.
31+
character(*), intent(in), optional :: file_name !< File name.
32+
real(R_P), intent(in), optional :: t !< Time.
33+
character(*), intent(in), optional :: scheme !< Scheme used to integrate integrand.
34+
logical, intent(in), optional :: close_file !< Flag for closing file.
35+
endsubroutine export_tecplot_interface
36+
37+
subroutine parse_cli_interface(self, cli)
38+
!< Initialize from command line interface.
39+
import :: command_line_interface, integrand_tester_object
40+
class(integrand_tester_object), intent(inout) :: self !< Advection field.
41+
type(command_line_interface), intent(inout) :: cli !< Command line interface handler.
42+
endsubroutine parse_cli_interface
43+
44+
subroutine set_cli_interface(cli)
45+
!< Set command line interface.
46+
import :: command_line_interface
47+
type(command_line_interface), intent(inout) :: cli !< Command line interface handler.
48+
endsubroutine set_cli_interface
49+
endinterface
50+
endmodule foodie_test_integrand_tester_object
51+

0 commit comments

Comments
 (0)