Skip to content

Commit ad43b7b

Browse files
committed
add lcce test to tester
1 parent f5882c4 commit ad43b7b

File tree

5 files changed

+195
-87
lines changed

5 files changed

+195
-87
lines changed

src/tests/tester/foodie_test_integrand_ladvection.f90

Lines changed: 26 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ pure function output(self) result(state)
151151
! integrand_tester_object deferred methods
152152
pure function description(self, prefix) result(desc)
153153
!< Return informative integrator description.
154-
class(integrand_ladvection), intent(in) :: self !< Integrator.
154+
class(integrand_ladvection), intent(in) :: self !< Integrand.
155155
character(*), intent(in), optional :: prefix !< Prefixing string.
156156
character(len=:), allocatable :: desc !< Description.
157157
character(len=:), allocatable :: prefix_ !< Prefixing string, local variable.
@@ -160,10 +160,11 @@ pure function description(self, prefix) result(desc)
160160
desc = prefix//'linear_advection-Ni_'//trim(strz(self%Ni, 10))
161161
endfunction description
162162

163-
pure function error(self, t, U0)
163+
pure function error(self, t, t0, U0)
164164
!< Return error.
165165
class(integrand_ladvection), intent(in) :: self !< Integrand.
166166
real(R_P), intent(in) :: t !< Time.
167+
real(R_P), intent(in), optional :: t0 !< Initial time.
167168
class(integrand_object), intent(in), optional :: U0 !< Initial conditions.
168169
real(R_P), allocatable :: error(:) !< Error.
169170
integer(I_P) :: i !< Counter.
@@ -182,10 +183,11 @@ pure function error(self, t, U0)
182183
endif
183184
endfunction error
184185

185-
pure function exact_solution(self, t, U0) result(exact)
186+
pure function exact_solution(self, t, t0, U0) result(exact)
186187
!< Return exact solution.
187188
class(integrand_ladvection), intent(in) :: self !< Integrand.
188189
real(R_P), intent(in) :: t !< Time.
190+
real(R_P), intent(in), optional :: t0 !< Initial time.
189191
class(integrand_object), intent(in), optional :: U0 !< Initial conditions.
190192
real(R_P), allocatable :: exact(:) !< Exact solution.
191193

@@ -252,14 +254,14 @@ subroutine parse_cli(self, cli)
252254

253255
call self%destroy
254256

255-
call cli%get(switch='--cfl', val=self%CFL, error=cli%error) ; if (cli%error/=0) stop
256-
call cli%get(switch='--w-scheme', val=self%w_scheme, error=cli%error) ; if (cli%error/=0) stop
257-
call cli%get(switch='--weno-order', val=self%weno_order, error=cli%error) ; if (cli%error/=0) stop
258-
call cli%get(switch='--weno-eps', val=self%weno_eps, error=cli%error) ; if (cli%error/=0) stop
259-
call cli%get(switch='-a', val=self%a, error=cli%error) ; if (cli%error/=0) stop
260-
call cli%get(switch='--length', val=self%length, error=cli%error) ; if (cli%error/=0) stop
261-
call cli%get(switch='--Ni', val=self%Ni, error=cli%error) ; if (cli%error/=0) stop
262-
call cli%get(switch='-is', val=self%initial_state, error=cli%error) ; if (cli%error/=0) stop
257+
call cli%get(group='linear_advection', switch='--cfl', val=self%CFL, error=cli%error) ; if (cli%error/=0) stop
258+
call cli%get(group='linear_advection', switch='--w-scheme', val=self%w_scheme, error=cli%error) ; if (cli%error/=0) stop
259+
call cli%get(group='linear_advection', switch='--weno-order', val=self%weno_order, error=cli%error) ; if (cli%error/=0) stop
260+
call cli%get(group='linear_advection', switch='--weno-eps', val=self%weno_eps, error=cli%error) ; if (cli%error/=0) stop
261+
call cli%get(group='linear_advection', switch='-a', val=self%a, error=cli%error) ; if (cli%error/=0) stop
262+
call cli%get(group='linear_advection', switch='--length', val=self%length, error=cli%error) ; if (cli%error/=0) stop
263+
call cli%get(group='linear_advection', switch='--Ni', val=self%Ni, error=cli%error) ; if (cli%error/=0) stop
264+
call cli%get(group='linear_advection', switch='-is', val=self%initial_state, error=cli%error) ; if (cli%error/=0) stop
263265

264266
self%Ng = (self%weno_order + 1) / 2
265267
self%Dx = self%length / self%Ni
@@ -274,16 +276,19 @@ subroutine set_cli(cli)
274276
!< Set command line interface.
275277
type(command_line_interface), intent(inout) :: cli !< Command line interface handler.
276278

277-
call cli%add(switch='--w-scheme', help='WENO scheme', required=.false., act='store', def='reconstructor-JS', &
278-
choices='reconstructor-JS,reconstructor-M-JS,reconstructor-M-Z,reconstructor-Z')
279-
call cli%add(switch='--weno-order', help='WENO order', required=.false., act='store', def='1')
280-
call cli%add(switch='--weno-eps', help='WENO epsilon parameter', required=.false., act='store', def='0.000001')
281-
call cli%add(switch='--cfl', help='CFL value', required=.false., act='store', def='0.8')
282-
call cli%add(switch='-a', help='advection coefficient', required=.false., act='store', def='1.0')
283-
call cli%add(switch='--length', help='domain lenth', required=.false., act='store', def='1.0')
284-
call cli%add(switch='--Ni', help='number finite volumes used', required=.false., act='store', def='100')
285-
call cli%add(switch='--initial_state', switch_ab='-is', help='initial state', required=.false., act='store', &
286-
def='square_wave', choices='square_wave')
279+
call cli%add_group(description='linear advection test settings', group='linear_advection')
280+
call cli%add(group='linear_advection', switch='--w-scheme', help='WENO scheme', required=.false., act='store', &
281+
def='reconstructor-JS', choices='reconstructor-JS,reconstructor-M-JS,reconstructor-M-Z,reconstructor-Z')
282+
call cli%add(group='linear_advection', switch='--weno-order', help='WENO order', required=.false., act='store', def='1')
283+
call cli%add(group='linear_advection', switch='--weno-eps', help='WENO epsilon parameter', required=.false., act='store', &
284+
def='0.000001')
285+
call cli%add(group='linear_advection', switch='--cfl', help='CFL value', required=.false., act='store', def='0.8')
286+
call cli%add(group='linear_advection', switch='-a', help='advection coefficient', required=.false., act='store', def='1.0')
287+
call cli%add(group='linear_advection', switch='--length', help='domain lenth', required=.false., act='store', def='1.0')
288+
call cli%add(group='linear_advection', switch='--Ni', help='number finite volumes used', required=.false., act='store', &
289+
def='100')
290+
call cli%add(group='linear_advection', switch='--initial_state', switch_ab='-is', help='initial state', required=.false., &
291+
act='store', def='square_wave', choices='square_wave')
287292
endsubroutine set_cli
288293

289294
! integrand_object deferred methods

src/tests/lcce/foodie_test_integrand_lcce.f90 renamed to src/tests/tester/foodie_test_integrand_lcce.f90

Lines changed: 110 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,16 @@ module foodie_test_integrand_lcce
55
!< Define [[integrand_lcce]], the linear constant coefficients equation test field that is a concrete extension of the
66
!< abstract integrand type.
77

8+
use flap, only : command_line_interface
89
use foodie, only : integrand_object
9-
use penf, only : I_P, R_P
10+
use foodie_test_integrand_tester_object, only : integrand_tester_object
11+
use penf, only : FR_P, R_P, I_P, str
1012

1113
implicit none
1214
private
1315
public :: integrand_lcce
1416

15-
type, extends(integrand_object) :: integrand_lcce
17+
type, extends(integrand_tester_object) :: integrand_lcce
1618
!< The linear constant coefficient equation field.
1719
!<
1820
!< It is a FOODIE integrand class concrete extension.
@@ -47,10 +49,16 @@ module foodie_test_integrand_lcce
4749
real(R_P) :: U0=0._R_P !< Integrand initial state.
4850
contains
4951
! auxiliary methods
50-
procedure, pass(self), public :: exact_solution !< Return exact solution.
51-
procedure, pass(self), public :: initialize !< Initialize integrand.
5252
procedure, pass(self), public :: output !< Extract integrand state field.
53-
! public deferred methods
53+
! integrand_tester_object deferred methods
54+
procedure, pass(self), public :: description !< Return an informative description of the test.
55+
procedure, pass(self), public :: error !< Return error.
56+
procedure, pass(self), public :: exact_solution !< Return exact solution.
57+
procedure, pass(self), public :: export_tecplot !< Export integrand to Tecplot file.
58+
procedure, pass(self), public :: initialize !< Initialize field.
59+
procedure, pass(self), public :: parse_cli !< Initialize from command line interface.
60+
procedure, nopass, public :: set_cli !< Set command line interface.
61+
! integrand_object deferred methods
5462
procedure, pass(self), public :: integrand_dimension !< Return integrand dimension.
5563
procedure, pass(self), public :: t => dU_dt !< Time derivative, residuals.
5664
! operators
@@ -82,39 +90,113 @@ module foodie_test_integrand_lcce
8290

8391
contains
8492
! auxiliary methods
85-
pure function exact_solution(self, t, t0) result(exact)
86-
!< Return exact solution.
87-
class(integrand_lcce), intent(in) :: self !< Integrand.
88-
real(R_P), intent(in) :: t !< Time.
89-
real(R_P), intent(in), optional :: t0 !< Initial time.
90-
real(R_P) :: exact !< Exact solution.
91-
real(R_P) :: t0_ !< Initial time, local variable.
93+
pure function output(self) result(state)
94+
!< Extract integrand state field.
95+
class(integrand_lcce), intent(in) :: self !< Integrand.
96+
real(R_P) :: state !< State.
9297

98+
state = self%U
99+
endfunction output
100+
101+
! integrand_tester_object deferred methods
102+
pure function description(self, prefix) result(desc)
103+
!< Return informative integrator description.
104+
class(integrand_lcce), intent(in) :: self !< Integrand.
105+
character(*), intent(in), optional :: prefix !< Prefixing string.
106+
character(len=:), allocatable :: desc !< Description.
107+
character(len=:), allocatable :: prefix_ !< Prefixing string, local variable.
108+
109+
prefix_ = '' ; if (present(prefix)) prefix_ = prefix
110+
desc = prefix//'linear_constant_coefficients_eq'
111+
endfunction description
112+
113+
pure function error(self, t, t0, U0)
114+
!< Return error.
115+
class(integrand_lcce), intent(in) :: self !< Integrand.
116+
real(R_P), intent(in) :: t !< Time.
117+
real(R_P), intent(in), optional :: t0 !< Initial time.
118+
class(integrand_object), intent(in), optional :: U0 !< Initial conditions.
119+
real(R_P), allocatable :: error(:) !< Error.
120+
121+
allocate(error(1:1))
122+
error = abs([self%U] - self%exact_solution(t=t, t0=t0))
123+
endfunction error
124+
125+
pure function exact_solution(self, t, t0, U0) result(exact)
126+
!< Return exact solution.
127+
class(integrand_lcce), intent(in) :: self !< Integrand.
128+
real(R_P), intent(in) :: t !< Time.
129+
real(R_P), intent(in), optional :: t0 !< Initial time.
130+
class(integrand_object), intent(in), optional :: U0 !< Initial conditions.
131+
real(R_P), allocatable :: exact(:) !< Exact solution.
132+
real(R_P) :: t0_ !< Initial time, local variable.
133+
134+
allocate(exact(1:1))
93135
t0_ = 0._R_P ; if (present(t0)) t0_ = t0
94-
exact = (self%U0 + self%b / self%a) * exp(self%a * (t - t0_)) - self%b / self%a
136+
exact(1) = (self%U0 + self%b / self%a) * exp(self%a * (t - t0_)) - self%b / self%a
95137
endfunction exact_solution
96138

97-
pure subroutine initialize(self, a, b, U0)
139+
subroutine export_tecplot(self, file_name, t, scheme, close_file)
140+
!< Export integrand to Tecplot file.
141+
class(integrand_lcce), intent(in) :: self !< Advection field.
142+
character(*), intent(in), optional :: file_name !< File name.
143+
real(R_P), intent(in), optional :: t !< Time.
144+
character(*), intent(in), optional :: scheme !< Scheme used to integrate integrand.
145+
logical, intent(in), optional :: close_file !< Flag for closing file.
146+
logical, save :: is_open=.false. !< Flag for checking if file is open.
147+
integer(I_P), save :: file_unit !< File unit.
148+
149+
if (present(close_file)) then
150+
if (close_file .and. is_open) then
151+
close(unit=file_unit)
152+
is_open = .false.
153+
endif
154+
else
155+
if (present(file_name)) then
156+
if (is_open) close(unit=file_unit)
157+
open(newunit=file_unit, file=trim(adjustl(file_name)))
158+
is_open = .true.
159+
write(unit=file_unit, fmt='(A)') 'VARIABLES="t" "x"'
160+
endif
161+
if (present(t) .and. present(scheme) .and. is_open) then
162+
write(unit=file_unit, fmt='(A)') 'ZONE T="'//trim(adjustl(scheme))//'"'
163+
write(unit=file_unit, fmt='(2('//FR_P//',1X))') t, self%U
164+
elseif (present(t) .and. is_open) then
165+
write(unit=file_unit, fmt='(2('//FR_P//',1X))') t, self%U
166+
endif
167+
endif
168+
endsubroutine export_tecplot
169+
170+
pure subroutine initialize(self, Dt)
98171
!< Initialize integrand.
172+
!<
173+
!< Intentionally empty, all is done in `parse_cli` method.
99174
class(integrand_lcce), intent(inout) :: self !< Integrand.
100-
real(R_P), intent(in) :: a, b !< Equation coefficients.
101-
real(R_P), intent(in) :: U0 !< Initial state of the integrand.
102-
103-
self%a = a
104-
self%b = b
105-
self%U = U0
106-
self%U0 = U0
175+
real(R_P), intent(in) :: Dt !< Time step.
107176
endsubroutine initialize
108177

109-
pure function output(self) result(state)
110-
!< Extract integrand state field.
111-
class(integrand_lcce), intent(in) :: self !< Integrand.
112-
real(R_P) :: state !< State.
178+
subroutine parse_cli(self, cli)
179+
!< Initialize from command line interface.
180+
class(integrand_lcce), intent(inout) :: self !< Advection field.
181+
type(command_line_interface), intent(inout) :: cli !< Command line interface handler.
113182

114-
state = self%U
115-
endfunction output
183+
call cli%get(group='lcce', switch='-a', val=self%a, error=cli%error) ; if (cli%error/=0) stop
184+
call cli%get(group='lcce', switch='-b', val=self%b, error=cli%error) ; if (cli%error/=0) stop
185+
call cli%get(group='lcce', switch='-U0', val=self%U0, error=cli%error) ; if (cli%error/=0) stop
186+
self%U = self%U0
187+
endsubroutine parse_cli
188+
189+
subroutine set_cli(cli)
190+
!< Set command line interface.
191+
type(command_line_interface), intent(inout) :: cli !< Command line interface handler.
192+
193+
call cli%add_group(description='linear constant coefficient equation test settings', group='lcce')
194+
call cli%add(group='lcce', switch='-a', help='"a" coeff of "a * x + b" equation', required=.false., def='-1.0', act='store')
195+
call cli%add(group='lcce', switch='-b', help='"b" coeff of "a * x + b" equation', required=.false., def='0.0', act='store')
196+
call cli%add(group='lcce', switch='-U0', help='initial state', required=.false., def='1.0', act='store')
197+
endsubroutine set_cli
116198

117-
! deferred methods
199+
! integrand_object deferred methods
118200
pure function integrand_dimension(self)
119201
!< return integrand dimension.
120202
class(integrand_lcce), intent(in) :: self !< integrand.

src/tests/tester/foodie_test_integrand_oscillation.f90

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ pure function output(self) result(state)
111111
! integrand_tester_object deferred methods
112112
pure function description(self, prefix) result(desc)
113113
!< Return informative integrator description.
114-
class(integrand_oscillation), intent(in) :: self !< Integrator.
114+
class(integrand_oscillation), intent(in) :: self !< Integrand.
115115
character(*), intent(in), optional :: prefix !< Prefixing string.
116116
character(len=:), allocatable :: desc !< Description.
117117
character(len=:), allocatable :: prefix_ !< Prefixing string, local variable.
@@ -120,21 +120,23 @@ pure function description(self, prefix) result(desc)
120120
desc = prefix//'oscillation'
121121
endfunction description
122122

123-
pure function error(self, t, U0)
123+
pure function error(self, t, t0, U0)
124124
!< Return error.
125125
class(integrand_oscillation), intent(in) :: self !< Integrand.
126126
real(R_P), intent(in) :: t !< Time.
127+
real(R_P), intent(in), optional :: t0 !< Initial time.
127128
class(integrand_object), intent(in), optional :: U0 !< Initial conditions.
128129
real(R_P), allocatable :: error(:) !< Error.
129130

130131
allocate(error(1:2))
131132
error = abs(self%U - self%exact_solution(t=t))
132133
endfunction error
133134

134-
pure function exact_solution(self, t, U0) result(exact)
135+
pure function exact_solution(self, t, t0, U0) result(exact)
135136
!< Return exact solution.
136137
class(integrand_oscillation), intent(in) :: self !< Integrand.
137138
real(R_P), intent(in) :: t !< Time.
139+
real(R_P), intent(in), optional :: t0 !< Initial time.
138140
class(integrand_object), intent(in), optional :: U0 !< Initial conditions.
139141
real(R_P), allocatable :: exact(:) !< Exact solution.
140142

@@ -151,7 +153,6 @@ subroutine export_tecplot(self, file_name, t, scheme, close_file)
151153
logical, intent(in), optional :: close_file !< Flag for closing file.
152154
logical, save :: is_open=.false. !< Flag for checking if file is open.
153155
integer(I_P), save :: file_unit !< File unit.
154-
integer(I_P) :: i !< Counter.
155156

156157
if (present(close_file)) then
157158
if (close_file .and. is_open) then
@@ -187,17 +188,20 @@ subroutine parse_cli(self, cli)
187188
class(integrand_oscillation), intent(inout) :: self !< Advection field.
188189
type(command_line_interface), intent(inout) :: cli !< Command line interface handler.
189190

190-
call cli%get(switch='-f', val=self%f, error=cli%error) ; if (cli%error/=0) stop
191-
call cli%get(switch='-U0', val=self%U0, error=cli%error) ; if (cli%error/=0) stop
191+
call cli%get(group='oscillation', switch='-f', val=self%f, error=cli%error) ; if (cli%error/=0) stop
192+
call cli%get(group='oscillation', switch='-U0', val=self%U0, error=cli%error) ; if (cli%error/=0) stop
192193
self%U = self%U0
193194
endsubroutine parse_cli
194195

195196
subroutine set_cli(cli)
196197
!< Set command line interface.
197198
type(command_line_interface), intent(inout) :: cli !< Command line interface handler.
198199

199-
call cli%add(switch='--frequency', switch_ab='-f', help='frequency', required=.false., def='1e-4', act='store')
200-
call cli%add(switch='--U0', switch_ab='-U0', nargs='2', help='initial state', required=.false., def='0.0 1.0', act='store')
200+
call cli%add_group(description='oscillation test settings', group='oscillation')
201+
call cli%add(group='oscillation', switch='--frequency', switch_ab='-f', help='frequency', required=.false., def='1e-4', &
202+
act='store')
203+
call cli%add(group='oscillation', switch='--U0', switch_ab='-U0', nargs='2', help='initial state', required=.false., &
204+
def='0.0 1.0', act='store')
201205
endsubroutine set_cli
202206

203207
! integrand_object deferred methods

0 commit comments

Comments
 (0)