Skip to content

Commit

Permalink
sanitize tester
Browse files Browse the repository at this point in the history
  • Loading branch information
szaghi committed Jun 1, 2017
1 parent ad43b7b commit c7f2bda
Show file tree
Hide file tree
Showing 6 changed files with 147 additions and 70 deletions.
22 changes: 13 additions & 9 deletions fobos
Original file line number Diff line number Diff line change
Expand Up @@ -219,16 +219,20 @@ rule = tar --xform="s%^%FOODIE/%" -czf FOODIE.tar.gz *
[rule-makecoverage]
help = Rule for performing coverage analysis
rule_1 = FoBiS.py build -f src/tests/tester/fobos -mode gnu-coverage
rule_2 = ./build/tests/tester/foodie_tester
rule_3 = rm -f build/tests/tester/obj/penf* build/tests/tester/obj/face* build/tests/tester/obj/flap* build/tests/tester/obj/wenoof*
rule_4 = gcov -o build/tests/tester/obj/ src/lib/foodie*
rule_5 = rm -f *.gcov
rule_2 = ./build/tests/tester/foodie_tester lcce test -ft 2 -Dt 1e-1 1e-2
rule_3 = ./build/tests/tester/foodie_tester linear_advection -is sin_wave --weno-order 3 test -s runge_kutta_ls -ft 1 -Dt 8e-3 2e-3
rule_4 = ./build/tests/tester/foodie_tester oscillation test -ft 1e4 -Dt 1e1 0.5e1
rule_5 = rm -f build/tests/tester/obj/penf* build/tests/tester/obj/face* build/tests/tester/obj/flap* build/tests/tester/obj/penf* build/tests/tester/obj/wenoof*
rule_6 = gcov -o build/tests/tester/obj/ src/lib/foodie*
rule_7 = rm -f *.gcov

[rule-coverage-analysis]
help = Rule for performing coverage analysis and saving reports in markdown
rule_1 = FoBiS.py build -f src/tests/tester/fobos -mode gnu-coverage
rule_2 = ./build/tests/tester/foodie_tester
rule_3 = rm -f build/tests/tester/obj/penf* build/tests/tester/obj/face* build/tests/tester/obj/flap* build/tests/tester/obj/wenoof*
rule_4 = gcov -o build/tests/tester/obj/ src/lib/foodie*
rule_5 = FoBiS.py rule -gcov_analyzer wiki/ Coverage-Analysis
rule_6 = rm -f *.gcov
rule_2 = ./build/tests/tester/foodie_tester lcce test -ft 2 -Dt 1e-1 1e-2
rule_3 = ./build/tests/tester/foodie_tester linear_advection -is sin_wave --weno-order 3 test -s runge_kutta_ls -ft 1 -Dt 8e-3 2e-3
rule_4 = ./build/tests/tester/foodie_tester oscillation test -ft 1e4 -Dt 1e1 0.5e1
rule_5 = rm -f build/tests/tester/obj/penf* build/tests/tester/obj/face* build/tests/tester/obj/flap* build/tests/tester/obj/penf* build/tests/tester/obj/wenoof*
rule_6 = gcov -o build/tests/tester/obj/ src/lib/foodie*
rule_7 = FoBiS.py rule -gcov_analyzer wiki/ Coverage-Analysis
rule_8 = rm -f *.gcov
83 changes: 60 additions & 23 deletions src/tests/tester/foodie_test_integrand_ladvection.f90
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ module foodie_test_integrand_ladvection
! private methods
procedure, pass(self), private :: impose_boundary_conditions !< Impose boundary conditions.
procedure, pass(self), private :: reconstruct_interfaces !< Reconstruct interface states.
procedure, pass(self), private :: set_sin_wave_initial_state !< Set initial state as a sin wave.
procedure, pass(self), private :: set_square_wave_initial_state !< Set initial state as a square wave.
endtype integrand_ladvection

Expand Down Expand Up @@ -157,7 +158,7 @@ pure function description(self, prefix) result(desc)
character(len=:), allocatable :: prefix_ !< Prefixing string, local variable.

prefix_ = '' ; if (present(prefix)) prefix_ = prefix
desc = prefix//'linear_advection-Ni_'//trim(strz(self%Ni, 10))
desc = prefix//'linear_advection-'//trim(self%initial_state)//'-Ni_'//trim(strz(self%Ni, 10))
endfunction description

pure function error(self, t, t0, U0)
Expand All @@ -175,11 +176,10 @@ pure function error(self, t, t0, U0)
select type(U0)
type is(integrand_ladvection)
do i=1, self%Ni
! error = error + (U0%u(i) - self%u(i)) ** 2
error = max(error, abs(U0%u(i) - self%u(i)))
error = error + (U0%u(i) - self%u(i)) ** 2
enddo
endselect
! error = sqrt(error)
error = self%Dx * sqrt(error)
endif
endfunction error

Expand All @@ -190,34 +190,48 @@ pure function exact_solution(self, t, t0, U0) result(exact)
real(R_P), intent(in), optional :: t0 !< Initial time.
class(integrand_object), intent(in), optional :: U0 !< Initial conditions.
real(R_P), allocatable :: exact(:) !< Exact solution.
integer(I_P) :: offset !< Cells offset.
integer(I_P) :: i !< Counter.

allocate(exact(1:self%Ni))
if (present(U0)) then
select type(U0)
type is(integrand_ladvection)
exact = U0%u(1:self%Ni)
offset = nint(mod(self%a * t, self%length) / self%Dx)
do i=1, self%Ni - offset
exact(i + offset) = U0%u(i)
enddo
do i=self%Ni - offset + 1, self%Ni
exact(i - self%Ni + offset) = U0%u(i)
enddo
endselect
else
exact = self%u(1:self%Ni) * 0._R_P
endif
endfunction exact_solution

subroutine export_tecplot(self, file_name, t, scheme, close_file)
subroutine export_tecplot(self, file_name, t, scheme, close_file, with_exact_solution, U0)
!< Export integrand to Tecplot file.
class(integrand_ladvection), intent(in) :: self !< Advection field.
character(*), intent(in), optional :: file_name !< File name.
real(R_P), intent(in), optional :: t !< Time.
character(*), intent(in), optional :: scheme !< Scheme used to integrate integrand.
logical, intent(in), optional :: close_file !< Flag for closing file.
logical, save :: is_open=.false. !< Flag for checking if file is open.
integer(I_P), save :: file_unit !< File unit.
integer(I_P) :: i !< Counter.
class(integrand_ladvection), intent(in) :: self !< Advection field.
character(*), intent(in), optional :: file_name !< File name.
real(R_P), intent(in), optional :: t !< Time.
character(*), intent(in), optional :: scheme !< Scheme used to integrate integrand.
logical, intent(in), optional :: close_file !< Flag for closing file.
logical, intent(in), optional :: with_exact_solution !< Flag for export also exact solution.
class(integrand_object), intent(in), optional :: U0 !< Initial conditions.
logical :: with_exact_solution_ !< Flag for export also exact solution, local variable.
logical, save :: is_open=.false. !< Flag for checking if file is open.
integer(I_P), save :: file_unit !< File unit.
real(R_P), allocatable :: exact_solution(:) !< Exact solution.
integer(I_P) :: i !< Counter.

if (present(close_file)) then
if (close_file .and. is_open) then
close(unit=file_unit)
is_open = .false.
endif
else
with_exact_solution_ = .false. ; if (present(with_exact_solution)) with_exact_solution_ = with_exact_solution
if (present(file_name)) then
if (is_open) close(unit=file_unit)
open(newunit=file_unit, file=trim(adjustl(file_name)))
Expand All @@ -229,6 +243,13 @@ subroutine export_tecplot(self, file_name, t, scheme, close_file)
do i=1, self%Ni
write(unit=file_unit, fmt='(2('//FR_P//',1X))') self%Dx * i - 0.5_R_P * self%Dx, self%u(i)
enddo
if (with_exact_solution_) then
exact_solution = self%exact_solution(t=t, U0=U0)
write(unit=file_unit, fmt='(A)') 'ZONE T="'//str(t)//' exact solution"'
do i=1, self%Ni
write(unit=file_unit, fmt='(2('//FR_P//',1X))') self%Dx * i - 0.5_R_P * self%Dx, exact_solution(i)
enddo
endif
endif
endif
endsubroutine export_tecplot
Expand All @@ -242,6 +263,8 @@ subroutine initialize(self, Dt)
self%Ni = nint(self%length / self%Dx)

select case(trim(adjustl(self%initial_state)))
case('sin_wave')
call self%set_sin_wave_initial_state
case('square_wave')
call self%set_square_wave_initial_state
endselect
Expand Down Expand Up @@ -288,7 +311,7 @@ subroutine set_cli(cli)
call cli%add(group='linear_advection', switch='--Ni', help='number finite volumes used', required=.false., act='store', &
def='100')
call cli%add(group='linear_advection', switch='--initial_state', switch_ab='-is', help='initial state', required=.false., &
act='store', def='square_wave', choices='square_wave')
act='store', def='sin_wave', choices='sin_wave,square_wave')
endsubroutine set_cli

! integrand_object deferred methods
Expand All @@ -310,7 +333,7 @@ function dU_dt(self, t) result(dState_dt)
do i=0, self%Ni
call solve_riemann_problem(state_left=ur(2, i), state_right=ur(1, i+1), flux=f(i))
enddo
allocate(dState_dt(1-self%Ng:self%Ni+self%Ng))
allocate(dState_dt(1:self%Ni))
do i=1, self%Ni
dState_dt(i) = (f(i - 1) - f(i)) / self%Dx
enddo
Expand Down Expand Up @@ -561,20 +584,34 @@ subroutine reconstruct_interfaces(self, conservative, r_conservative)

subroutine set_square_wave_initial_state(self)
!< Set initial state as a square wave.
class(integrand_ladvection), intent(inout) :: self !< Advection field.
real(R_P) :: x(1:self%ni) !< Cell center x-abscissa values.
integer(I_P) :: i !< Space counter.
class(integrand_ladvection), intent(inout) :: self !< Advection field.
real(R_P) :: x !< Cell center x-abscissa values.
integer(I_P) :: i !< Space counter.

if (allocated(self%u)) deallocate(self%u) ; allocate(self%u(1-self%Ng:self%Ni+self%Ng))
if (allocated(self%u)) deallocate(self%u) ; allocate(self%u(1:self%Ni))
do i=1, self%Ni
x(i) = self%Dx * i - 0.5_R_P * self%Dx
if (x(i) < 0.25_R_P) then
x = self%Dx * i - 0.5_R_P * self%Dx
if (x < 0.25_R_P) then
self%u(i) = 0._R_P
elseif (0.25_R_P <= x(i) .and. x(i) < 0.75_R_P) then
elseif (0.25_R_P <= x .and. x < 0.75_R_P) then
self%u(i) = 1._R_P
else
self%u(i) = 0._R_P
endif
enddo
endsubroutine set_square_wave_initial_state

subroutine set_sin_wave_initial_state(self)
!< Set initial state as a sin wave.
class(integrand_ladvection), intent(inout) :: self !< Advection field.
real(R_P) :: x !< Cell center x-abscissa values.
real(R_P), parameter :: pi=4._R_P*atan(1._R_P) !< Pi greek.
integer(I_P) :: i !< Space counter.

if (allocated(self%u)) deallocate(self%u) ; allocate(self%u(1:self%Ni))
do i=1, self%Ni
x = self%Dx * i - 0.5_R_P * self%Dx
self%u(i) = sin(x * 2 * pi)
enddo
endsubroutine set_sin_wave_initial_state
endmodule foodie_test_integrand_ladvection
38 changes: 27 additions & 11 deletions src/tests/tester/foodie_test_integrand_lcce.f90
Original file line number Diff line number Diff line change
Expand Up @@ -136,33 +136,49 @@ pure function exact_solution(self, t, t0, U0) result(exact)
exact(1) = (self%U0 + self%b / self%a) * exp(self%a * (t - t0_)) - self%b / self%a
endfunction exact_solution

subroutine export_tecplot(self, file_name, t, scheme, close_file)
subroutine export_tecplot(self, file_name, t, scheme, close_file, with_exact_solution, U0)
!< Export integrand to Tecplot file.
class(integrand_lcce), intent(in) :: self !< Advection field.
character(*), intent(in), optional :: file_name !< File name.
real(R_P), intent(in), optional :: t !< Time.
character(*), intent(in), optional :: scheme !< Scheme used to integrate integrand.
logical, intent(in), optional :: close_file !< Flag for closing file.
logical, save :: is_open=.false. !< Flag for checking if file is open.
integer(I_P), save :: file_unit !< File unit.
class(integrand_lcce), intent(in) :: self !< Advection field.
character(*), intent(in), optional :: file_name !< File name.
real(R_P), intent(in), optional :: t !< Time.
character(*), intent(in), optional :: scheme !< Scheme used to integrate integrand.
logical, intent(in), optional :: close_file !< Flag for closing file.
logical, intent(in), optional :: with_exact_solution !< Flag for export also exact solution.
class(integrand_object), intent(in), optional :: U0 !< Initial conditions.
logical :: with_exact_solution_ !< Flag for export also exact solution, local variable.
logical, save :: is_open=.false. !< Flag for checking if file is open.
integer(I_P), save :: file_unit !< File unit.

if (present(close_file)) then
if (close_file .and. is_open) then
close(unit=file_unit)
is_open = .false.
endif
else
with_exact_solution_ = .false. ; if (present(with_exact_solution)) with_exact_solution_ = with_exact_solution
if (present(file_name)) then
if (is_open) close(unit=file_unit)
open(newunit=file_unit, file=trim(adjustl(file_name)))
is_open = .true.
write(unit=file_unit, fmt='(A)') 'VARIABLES="t" "x"'
if (with_exact_solution_) then
write(unit=file_unit, fmt='(A)') 'VARIABLES="t" "x" "x_exact"'
else
write(unit=file_unit, fmt='(A)') 'VARIABLES="t" "x"'
endif
endif
if (present(t) .and. present(scheme) .and. is_open) then
write(unit=file_unit, fmt='(A)') 'ZONE T="'//trim(adjustl(scheme))//'"'
write(unit=file_unit, fmt='(2('//FR_P//',1X))') t, self%U
if (with_exact_solution_) then
write(unit=file_unit, fmt='(3('//FR_P//',1X))') t, self%U, self%exact_solution(t=t)
else
write(unit=file_unit, fmt='(2('//FR_P//',1X))') t, self%U
endif
elseif (present(t) .and. is_open) then
write(unit=file_unit, fmt='(2('//FR_P//',1X))') t, self%U
if (with_exact_solution_) then
write(unit=file_unit, fmt='(3('//FR_P//',1X))') t, self%U, self%exact_solution(t=t)
else
write(unit=file_unit, fmt='(2('//FR_P//',1X))') t, self%U
endif
endif
endif
endsubroutine export_tecplot
Expand Down
38 changes: 27 additions & 11 deletions src/tests/tester/foodie_test_integrand_oscillation.f90
Original file line number Diff line number Diff line change
Expand Up @@ -144,33 +144,49 @@ pure function exact_solution(self, t, t0, U0) result(exact)
self%U0(1) * sin(self%f * t) + self%U0(2) * cos(self%f * t)]
endfunction exact_solution

subroutine export_tecplot(self, file_name, t, scheme, close_file)
subroutine export_tecplot(self, file_name, t, scheme, close_file, with_exact_solution, U0)
!< Export integrand to Tecplot file.
class(integrand_oscillation), intent(in) :: self !< Advection field.
character(*), intent(in), optional :: file_name !< File name.
real(R_P), intent(in), optional :: t !< Time.
character(*), intent(in), optional :: scheme !< Scheme used to integrate integrand.
logical, intent(in), optional :: close_file !< Flag for closing file.
logical, save :: is_open=.false. !< Flag for checking if file is open.
integer(I_P), save :: file_unit !< File unit.
class(integrand_oscillation), intent(in) :: self !< Advection field.
character(*), intent(in), optional :: file_name !< File name.
real(R_P), intent(in), optional :: t !< Time.
character(*), intent(in), optional :: scheme !< Scheme used to integrate integrand.
logical, intent(in), optional :: close_file !< Flag for closing file.
logical, intent(in), optional :: with_exact_solution !< Flag for export also exact solution.
class(integrand_object), intent(in), optional :: U0 !< Initial conditions.
logical :: with_exact_solution_ !< Flag for export also exact solution, local variable.
logical, save :: is_open=.false. !< Flag for checking if file is open.
integer(I_P), save :: file_unit !< File unit.

if (present(close_file)) then
if (close_file .and. is_open) then
close(unit=file_unit)
is_open = .false.
endif
else
with_exact_solution_ = .false. ; if (present(with_exact_solution)) with_exact_solution_ = with_exact_solution
if (present(file_name)) then
if (is_open) close(unit=file_unit)
open(newunit=file_unit, file=trim(adjustl(file_name)))
is_open = .true.
write(unit=file_unit, fmt='(A)') 'VARIABLES="t" "x" "y" "amplitude" "phase"'
if (with_exact_solution_) then
write(unit=file_unit, fmt='(A)') 'VARIABLES="t" "x" "y" "amplitude" "phase" "x_e" "y_e"'
else
write(unit=file_unit, fmt='(A)') 'VARIABLES="t" "x" "y" "amplitude" "phase"'
endif
endif
if (present(t) .and. present(scheme) .and. is_open) then
write(unit=file_unit, fmt='(A)') 'ZONE T="'//trim(adjustl(scheme))//'"'
write(unit=file_unit, fmt='(5('//FR_P//',1X))') t, self%U, self%amplitude_phase()
if (with_exact_solution_) then
write(unit=file_unit, fmt='(7('//FR_P//',1X))') t, self%U, self%amplitude_phase(), self%exact_solution(t=t)
else
write(unit=file_unit, fmt='(5('//FR_P//',1X))') t, self%U, self%amplitude_phase()
endif
elseif (present(t) .and. is_open) then
write(unit=file_unit, fmt='(5('//FR_P//',1X))') t, self%U, self%amplitude_phase()
if (with_exact_solution_) then
write(unit=file_unit, fmt='(7('//FR_P//',1X))') t, self%U, self%amplitude_phase(), self%exact_solution(t=t)
else
write(unit=file_unit, fmt='(5('//FR_P//',1X))') t, self%U, self%amplitude_phase()
endif
endif
endif
endsubroutine export_tecplot
Expand Down
Loading

0 comments on commit c7f2bda

Please sign in to comment.