Save results (and plots).
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
logical, | intent(in) | :: | results | Flag for activating results saving. |
||
character(len=*), | intent(in) | :: | output | Output files basename coming from CLI. |
||
character(len=*), | intent(in) | :: | scheme | Selected scheme: must be defined into solvers. |
||
real(kind=R_P), | intent(in) | :: | frequency | Oscillation frequency. |
||
real(kind=R_P), | intent(in) | :: | U0(1:) | Initial state. |
||
logical, | intent(in) | :: | save_exact_solution | Flag for saving exact solution. |
||
real(kind=R_P), | intent(in) | :: | solution(0:,0:) | Solution at each time step. |
subroutine save_results(results, output, scheme, frequency, U0, save_exact_solution, solution)
!< Save results (and plots).
logical, intent(in) :: results !< Flag for activating results saving.
character(*), intent(in) :: output !< Output files basename coming from CLI.
character(*), intent(in) :: scheme !< Selected scheme: must be defined into *solvers*.
real(R_P), intent(in) :: frequency !< Oscillation frequency.
real(R_P), intent(in) :: U0(1:) !< Initial state.
logical, intent(in) :: save_exact_solution !< Flag for saving exact solution.
real(R_P), intent(in) :: solution(0:,0:) !< Solution at each time step.
character(len=:), allocatable :: title !< Output files title.
character(len=:), allocatable :: basename !< Output files basename.
integer(I_P) :: rawfile !< Raw file unit for saving results.
type(integrand_oscillation) :: oscillator !< Oscillation field.
integer(I_P) :: s !< Counter.
basename = trim(adjustl(output))//'-'//trim(strz(ubound(solution, dim=2), 10))//'-time_steps-'//trim(adjustl(scheme))
title = 'oscillation equations integration, solver='//trim(adjustl(scheme))
if (results) then
open(newunit=rawfile, file=basename//'.dat')
write(rawfile, '(A)')'TITLE="'//title//'"'
write(rawfile, '(A)')'VARIABLES="t" "x" "y" "amplitude" "phase"'
write(rawfile, '(A)')'ZONE T="'//trim(adjustl(scheme))//'"'
do s=0, ubound(solution, dim=2)
write(rawfile, '(5('//FR_P//',1X))')solution(:, s), amplitude_phase(solution(1:2, s))
enddo
close(rawfile)
endif
if (save_exact_solution) then
call oscillator%initialize(U0=U0, frequency=frequency)
basename = trim(adjustl(output))//'-'//trim(strz(ubound(solution, dim=2), 10))//'-time_steps-exact_solution'
title = 'linear constant coefficients equation integration, solver=exact solution'
open(newunit=rawfile, file=basename//'.dat')
write(rawfile, '(A)')'TITLE="'//title//'"'
write(rawfile, '(A)')'VARIABLES="t" "u"'
write(rawfile, '(A)')'ZONE T="exact solution"'
do s=0, ubound(solution, dim=2)
write(rawfile, '(5('//FR_P//',1X))')solution(0, s), oscillator%exact_solution(t=solution(0, s)), &
amplitude_phase(oscillator%exact_solution(t=solution(0, s)))
enddo
close(rawfile)
endif
contains
function amplitude_phase(sol) result(ap)
!< Compute amplitude and phase of the solution provided in X-Y domain.
real(R_P), intent(in) :: sol(1:) !< Solution in X-Y domain.
real(R_P) :: ap(1:2) !< Amplitude and phase solution.
ap(1) = sqrt(sol(1)**2 + sol(2)**2)
ap(2) = atan(-sol(1) / sol(2))
endfunction amplitude_phase
endsubroutine save_results