@@ -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 :: 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.
6264 procedure , pass(self), public :: output ! < Extract integrand state field.
6365 ! integrand_tester_object deferred methods
6466 procedure , pass(self), public :: description ! < Return an informative description of the test.
67+ procedure , pass(self), public :: error ! < Return error.
6568 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,14 +121,25 @@ 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 end function compute_dt
127131
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.
137+
138+ associate(a= >self% a, CFL= >self% CFL)
139+ Dx = Dt / CFL * abs (a)
140+ endassociate
141+ end function compute_dx
142+
128143 pure function output (self ) result(state)
129144 ! < Output the advection field state.
130145 class(integrand_ladvection), intent (in ) :: self ! < Advection field.
@@ -145,6 +160,28 @@ pure function description(self, prefix) result(desc)
145160 desc = prefix// ' linear_advection-Ni_' // trim (strz(self% Ni, 10 ))
146161 end function description
147162
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+
148185 pure function exact_solution (self , t , U0 ) result(exact)
149186 ! < Return exact solution.
150187 class(integrand_ladvection), intent (in ) :: self ! < Integrand.
@@ -194,11 +231,24 @@ subroutine export_tecplot(self, file_name, t, scheme, close_file)
194231 endif
195232 end subroutine export_tecplot
196233
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+ end subroutine initialize
247+
197248 subroutine parse_cli (self , cli )
198249 ! < Initialize from command line interface.
199- class(integrand_ladvection), intent (inout ) :: self ! < Advection field.
200- type (command_line_interface), intent (inout ) :: cli ! < Command line interface handler.
201- 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.
202252
203253 call self% destroy
204254
@@ -209,16 +259,11 @@ subroutine parse_cli(self, cli)
209259 call cli% get(switch= ' -a' , val= self% a, error= cli% error) ; if (cli% error/= 0 ) stop
210260 call cli% get(switch= ' --length' , val= self% length, error= cli% error) ; if (cli% error/= 0 ) stop
211261 call cli% get(switch= ' --Ni' , val= self% Ni, error= cli% error) ; if (cli% error/= 0 ) stop
212- 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
213263
214264 self% Ng = (self% weno_order + 1 ) / 2
215265 self% Dx = self% length / self% Ni
216266
217- select case (trim (adjustl (initial_state)))
218- case (' square_wave' )
219- call self% set_square_wave_initial_state
220- endselect
221-
222267 if (self% weno_order> 1 ) call wenoof_create(interpolator_type= trim (adjustl (self% w_scheme)), &
223268 S= self% Ng, &
224269 interpolator= self% interpolator, &
@@ -433,6 +478,7 @@ pure subroutine assign_integrand(lhs, rhs)
433478 lhs% CFL = rhs% CFL
434479 lhs% Ni = rhs% Ni
435480 lhs% Ng = rhs% Ng
481+ lhs% length = rhs% length
436482 lhs% Dx = rhs% Dx
437483 lhs% a = rhs% a
438484 if (allocated (rhs% u)) then
@@ -447,6 +493,7 @@ pure subroutine assign_integrand(lhs, rhs)
447493 else
448494 if (allocated (lhs% interpolator)) deallocate (lhs% interpolator)
449495 endif
496+ lhs% initial_state = rhs% initial_state
450497 endselect
451498 end subroutine assign_integrand
452499
0 commit comments