Skip to content

Commit f5882c4

Browse files
committed
Merge branch 'master' into develop
2 parents 1f34300 + 014c135 commit f5882c4

File tree

5 files changed

+206
-81
lines changed

5 files changed

+206
-81
lines changed

src/lib/foodie_integrator_runge_kutta_lssp.f90

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ subroutine initialize(self, scheme, U, stages, stop_on_fail)
248248
allocate(self%alpha(1:self%stages)) ; self%alpha = 0._R_P
249249
call self%initialize_order_s
250250
endselect
251-
self%description_ = trim(adjustl(scheme))//'_stages_'//trim(str(self%stages))
251+
self%description_ = trim(adjustl(scheme))//'_stages_'//trim(str(self%stages, no_sign=.true.))
252252
self%registers = self%stages
253253
if (present(U)) call self%allocate_integrand_members(U=U)
254254
else

src/tests/tester/foodie_test_integrand_ladvection.f90

Lines changed: 74 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -55,15 +55,19 @@ module foodie_test_integrand_ladvection
5555
real(R_P) :: a=0._R_P !< Advection coefficient.
5656
real(R_P), allocatable :: u(:) !< Integrand (state) variable.
5757
class(interpolator_object), allocatable :: interpolator !< WENO interpolator.
58+
character(99) :: initial_state !< Initial state.
5859
contains
5960
! auxiliary methods
6061
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.
62+
procedure, pass(self), public :: dt => compute_dt !< Compute the current time step by means of CFL condition.
63+
procedure, pass(self), public :: compute_dx !< Compute the space step by means of CFL condition.
6364
procedure, pass(self), public :: output !< Extract integrand state field.
6465
! integrand_tester_object deferred methods
6566
procedure, pass(self), public :: description !< Return an informative description of the test.
67+
procedure, pass(self), public :: error !< Return error.
68+
procedure, pass(self), public :: exact_solution !< Return exact solution.
6669
procedure, pass(self), public :: export_tecplot !< Export integrand to Tecplot file.
70+
procedure, pass(self), public :: initialize !< Initialize integrand.
6771
procedure, pass(self), public :: parse_cli !< Initialize from command line interface.
6872
procedure, nopass, public :: set_cli !< Set command line interface.
6973
! integrand_object deferred methods
@@ -117,22 +121,24 @@ pure function compute_dt(self, final_time, t) result(Dt)
117121
real(R_P), intent(in), optional :: t !< Time.
118122
real(R_P) :: Dt !< Time step.
119123

120-
associate(a=>self%a, Ni=>self%Ni, Dx=>self%Dx, CFL=>self%CFL)
124+
associate(a=>self%a, Dx=>self%Dx, CFL=>self%CFL)
121125
Dt = Dx * CFL / abs(a)
122126
if (present(t)) then
123127
if ((t + Dt) > final_time) Dt = final_time - t
124128
endif
125129
endassociate
126130
endfunction compute_dt
127131

128-
pure function exact_solution(self, u0, t) result(exact)
129-
!< Return exact solution.
130-
class(integrand_ladvection), intent(in) :: self !< Integrand.
131-
real(R_P), intent(in) :: u0(1:) !< Initial state
132-
real(R_P), intent(in) :: t !< Time.
133-
real(R_P), allocatable :: exact(:) !< Exact solution.
132+
pure function compute_dx(self, Dt) result(Dx)
133+
!< Compute the space step step by means of CFL condition.
134+
class(integrand_ladvection), intent(in) :: self !< Advection field.
135+
real(R_P), intent(in) :: Dt !< Time step.
136+
real(R_P) :: Dx !< Space step.
134137

135-
endfunction exact_solution
138+
associate(a=>self%a, CFL=>self%CFL)
139+
Dx = Dt / CFL * abs(a)
140+
endassociate
141+
endfunction compute_dx
136142

137143
pure function output(self) result(state)
138144
!< Output the advection field state.
@@ -154,6 +160,45 @@ pure function description(self, prefix) result(desc)
154160
desc = prefix//'linear_advection-Ni_'//trim(strz(self%Ni, 10))
155161
endfunction description
156162

163+
pure function error(self, t, U0)
164+
!< Return error.
165+
class(integrand_ladvection), intent(in) :: self !< Integrand.
166+
real(R_P), intent(in) :: t !< Time.
167+
class(integrand_object), intent(in), optional :: U0 !< Initial conditions.
168+
real(R_P), allocatable :: error(:) !< Error.
169+
integer(I_P) :: i !< Counter.
170+
171+
allocate(error(1:1))
172+
error = 0._R_P
173+
if (present(U0)) then
174+
select type(U0)
175+
type is(integrand_ladvection)
176+
do i=1, self%Ni
177+
! error = error + (U0%u(i) - self%u(i)) ** 2
178+
error = max(error, abs(U0%u(i) - self%u(i)))
179+
enddo
180+
endselect
181+
! error = sqrt(error)
182+
endif
183+
endfunction error
184+
185+
pure function exact_solution(self, t, U0) result(exact)
186+
!< Return exact solution.
187+
class(integrand_ladvection), intent(in) :: self !< Integrand.
188+
real(R_P), intent(in) :: t !< Time.
189+
class(integrand_object), intent(in), optional :: U0 !< Initial conditions.
190+
real(R_P), allocatable :: exact(:) !< Exact solution.
191+
192+
if (present(U0)) then
193+
select type(U0)
194+
type is(integrand_ladvection)
195+
exact = U0%u(1:self%Ni)
196+
endselect
197+
else
198+
exact = self%u(1:self%Ni) * 0._R_P
199+
endif
200+
endfunction exact_solution
201+
157202
subroutine export_tecplot(self, file_name, t, scheme, close_file)
158203
!< Export integrand to Tecplot file.
159204
class(integrand_ladvection), intent(in) :: self !< Advection field.
@@ -186,11 +231,24 @@ subroutine export_tecplot(self, file_name, t, scheme, close_file)
186231
endif
187232
endsubroutine export_tecplot
188233

234+
subroutine initialize(self, Dt)
235+
!< Initialize integrand.
236+
class(integrand_ladvection), intent(inout) :: self !< Integrand.
237+
real(R_P), intent(in) :: Dt !< Time step.
238+
239+
self%Dx = self%compute_dx(Dt=Dt)
240+
self%Ni = nint(self%length / self%Dx)
241+
242+
select case(trim(adjustl(self%initial_state)))
243+
case('square_wave')
244+
call self%set_square_wave_initial_state
245+
endselect
246+
endsubroutine initialize
247+
189248
subroutine parse_cli(self, cli)
190249
!< Initialize from command line interface.
191-
class(integrand_ladvection), intent(inout) :: self !< Advection field.
192-
type(command_line_interface), intent(inout) :: cli !< Command line interface handler.
193-
character(99) :: initial_state !< Initial state.
250+
class(integrand_ladvection), intent(inout) :: self !< Advection field.
251+
type(command_line_interface), intent(inout) :: cli !< Command line interface handler.
194252

195253
call self%destroy
196254

@@ -201,16 +259,11 @@ subroutine parse_cli(self, cli)
201259
call cli%get(switch='-a', val=self%a, error=cli%error) ; if (cli%error/=0) stop
202260
call cli%get(switch='--length', val=self%length, error=cli%error) ; if (cli%error/=0) stop
203261
call cli%get(switch='--Ni', val=self%Ni, error=cli%error) ; if (cli%error/=0) stop
204-
call cli%get(switch='-is', val=initial_state, 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
205263

206264
self%Ng = (self%weno_order + 1) / 2
207265
self%Dx = self%length / self%Ni
208266

209-
select case(trim(adjustl(initial_state)))
210-
case('square_wave')
211-
call self%set_square_wave_initial_state
212-
endselect
213-
214267
if (self%weno_order>1) call wenoof_create(interpolator_type=trim(adjustl(self%w_scheme)), &
215268
S=self%Ng, &
216269
interpolator=self%interpolator, &
@@ -425,6 +478,7 @@ pure subroutine assign_integrand(lhs, rhs)
425478
lhs%CFL = rhs%CFL
426479
lhs%Ni = rhs%Ni
427480
lhs%Ng = rhs%Ng
481+
lhs%length = rhs%length
428482
lhs%Dx = rhs%Dx
429483
lhs%a = rhs%a
430484
if (allocated(rhs%u)) then
@@ -439,6 +493,7 @@ pure subroutine assign_integrand(lhs, rhs)
439493
else
440494
if (allocated(lhs%interpolator)) deallocate(lhs%interpolator)
441495
endif
496+
lhs%initial_state = rhs%initial_state
442497
endselect
443498
endsubroutine assign_integrand
444499

src/tests/tester/foodie_test_integrand_oscillation.f90

Lines changed: 33 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,13 @@ module foodie_test_integrand_oscillation
5050
contains
5151
! auxiliary methods
5252
procedure, pass(self), public :: amplitude_phase !< Return amplitude and phase of the oscillation.
53-
procedure, pass(self), public :: exact_solution !< Return exact solution.
54-
procedure, pass(self), public :: initialize !< Initialize integrand.
5553
procedure, pass(self), public :: output !< Extract integrand state field.
5654
! integrand_tester_object deferred methods
5755
procedure, pass(self), public :: description !< Return an informative description of the test.
56+
procedure, pass(self), public :: error !< Return error.
57+
procedure, pass(self), public :: exact_solution !< Return exact solution.
5858
procedure, pass(self), public :: export_tecplot !< Export integrand to Tecplot file.
59+
procedure, pass(self), public :: initialize !< Initialize field.
5960
procedure, pass(self), public :: parse_cli !< Initialize from command line interface.
6061
procedure, nopass, public :: set_cli !< Set command line interface.
6162
! integrand_object deferred methods
@@ -99,27 +100,6 @@ function amplitude_phase(self) result(ap)
99100
ap(2) = atan(-self%U(1) / self%U(2))
100101
endfunction amplitude_phase
101102

102-
pure function exact_solution(self, t) result(exact)
103-
!< Return exact solution.
104-
class(integrand_oscillation), intent(in) :: self !< Integrand.
105-
real(R_P), intent(in) :: t !< Time.
106-
real(R_P) :: exact(1:2) !< Exact solution.
107-
108-
exact(1) = self%U0(1) * cos(self%f * t) - self%U0(2) * sin(self%f * t)
109-
exact(2) = self%U0(1) * sin(self%f * t) + self%U0(2) * cos(self%f * t)
110-
endfunction exact_solution
111-
112-
pure subroutine initialize(self, U0, frequency)
113-
!< Initialize integrand.
114-
class(integrand_oscillation), intent(inout) :: self !< Integrand.
115-
real(R_P), intent(in) :: U0(1:2) !< Initial state.
116-
real(R_P), intent(in) :: frequency !< Frequency of oscillation.
117-
118-
self%U = U0
119-
self%f = frequency
120-
self%U0 = U0
121-
endsubroutine initialize
122-
123103
pure function output(self) result(state)
124104
!< Extract integrand state field.
125105
class(integrand_oscillation), intent(in) :: self !< Integrand.
@@ -140,6 +120,28 @@ pure function description(self, prefix) result(desc)
140120
desc = prefix//'oscillation'
141121
endfunction description
142122

123+
pure function error(self, t, U0)
124+
!< Return error.
125+
class(integrand_oscillation), intent(in) :: self !< Integrand.
126+
real(R_P), intent(in) :: t !< Time.
127+
class(integrand_object), intent(in), optional :: U0 !< Initial conditions.
128+
real(R_P), allocatable :: error(:) !< Error.
129+
130+
allocate(error(1:2))
131+
error = abs(self%U - self%exact_solution(t=t))
132+
endfunction error
133+
134+
pure function exact_solution(self, t, U0) result(exact)
135+
!< Return exact solution.
136+
class(integrand_oscillation), intent(in) :: self !< Integrand.
137+
real(R_P), intent(in) :: t !< Time.
138+
class(integrand_object), intent(in), optional :: U0 !< Initial conditions.
139+
real(R_P), allocatable :: exact(:) !< Exact solution.
140+
141+
exact = [self%U0(1) * cos(self%f * t) - self%U0(2) * sin(self%f * t), &
142+
self%U0(1) * sin(self%f * t) + self%U0(2) * cos(self%f * t)]
143+
endfunction exact_solution
144+
143145
subroutine export_tecplot(self, file_name, t, scheme, close_file)
144146
!< Export integrand to Tecplot file.
145147
class(integrand_oscillation), intent(in) :: self !< Advection field.
@@ -172,6 +174,14 @@ subroutine export_tecplot(self, file_name, t, scheme, close_file)
172174
endif
173175
endsubroutine export_tecplot
174176

177+
pure subroutine initialize(self, Dt)
178+
!< Initialize integrand.
179+
!<
180+
!< Intentionally empty, all is done in `parse_cli` method.
181+
class(integrand_oscillation), intent(inout) :: self !< Integrand.
182+
real(R_P), intent(in) :: Dt !< Time step.
183+
endsubroutine initialize
184+
175185
subroutine parse_cli(self, cli)
176186
!< Initialize from command line interface.
177187
class(integrand_oscillation), intent(inout) :: self !< Advection field.

src/tests/tester/foodie_test_integrand_tester_object.f90

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,10 @@ module foodie_test_integrand_tester_object
1717
!< This abstract provided some auxiliary methods useful for the tester machinery.
1818
contains
1919
procedure(description_interface), pass(self), deferred :: description !< Return an informative description of the test.
20+
procedure(error_interface), pass(self), deferred :: error !< Return error.
21+
procedure(exact_solution_interface), pass(self), deferred :: exact_solution !< Return exact solution.
2022
procedure(export_tecplot_interface), pass(self), deferred :: export_tecplot !< Export integrand to Tecplot file.
23+
procedure(initialize_interface), pass(self), deferred :: initialize !< Initialize integrand.
2124
procedure(parse_cli_interface), pass(self), deferred :: parse_cli !< Initialize from command line interface.
2225
procedure(set_cli_interface), nopass, deferred :: set_cli !< Set command line interface.
2326
endtype integrand_tester_object
@@ -32,20 +35,45 @@ pure function description_interface(self, prefix) result(desc)
3235
character(len=:), allocatable :: desc !< Description.
3336
endfunction description_interface
3437

38+
pure function error_interface(self, t, U0) result(error)
39+
!< Return error.
40+
import :: integrand_object, integrand_tester_object, R_P
41+
class(integrand_tester_object), intent(in) :: self !< Integrand.
42+
real(R_P), intent(in) :: t !< Time.
43+
class(integrand_object), intent(in), optional :: U0 !< Initial conditions.
44+
real(R_P), allocatable :: error(:) !< Error.
45+
endfunction error_interface
46+
47+
pure function exact_solution_interface(self, t, U0) result(exact)
48+
!< Return exact solution.
49+
import :: integrand_object, integrand_tester_object, R_P
50+
class(integrand_tester_object), intent(in) :: self !< Integrand.
51+
real(R_P), intent(in) :: t !< Time.
52+
class(integrand_object), intent(in), optional :: U0 !< Initial conditions.
53+
real(R_P), allocatable :: exact(:) !< Exact solution.
54+
endfunction exact_solution_interface
55+
3556
subroutine export_tecplot_interface(self, file_name, t, scheme, close_file)
3657
!< Export integrand to Tecplot file.
3758
import :: integrand_tester_object, R_P
38-
class(integrand_tester_object), intent(in) :: self !< Advection field.
59+
class(integrand_tester_object), intent(in) :: self !< Integrand.
3960
character(*), intent(in), optional :: file_name !< File name.
4061
real(R_P), intent(in), optional :: t !< Time.
4162
character(*), intent(in), optional :: scheme !< Scheme used to integrate integrand.
4263
logical, intent(in), optional :: close_file !< Flag for closing file.
4364
endsubroutine export_tecplot_interface
4465

66+
subroutine initialize_interface(self, Dt)
67+
!< Initialize integrand.
68+
import :: integrand_tester_object, R_P
69+
class(integrand_tester_object), intent(inout) :: self !< Integrand.
70+
real(R_P), intent(in) :: Dt !< Time step.
71+
endsubroutine initialize_interface
72+
4573
subroutine parse_cli_interface(self, cli)
4674
!< Initialize from command line interface.
4775
import :: command_line_interface, integrand_tester_object
48-
class(integrand_tester_object), intent(inout) :: self !< Advection field.
76+
class(integrand_tester_object), intent(inout) :: self !< Integrand.
4977
type(command_line_interface), intent(inout) :: cli !< Command line interface handler.
5078
endsubroutine parse_cli_interface
5179

0 commit comments

Comments
 (0)