Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions dcon/sing.f
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ SUBROUTINE sing_lim
c-----------------------------------------------------------------------
c use newton iteration to find psilim.
c-----------------------------------------------------------------------
IF(qlim<qmax)THEN
IF(qlim<qmax .AND. (sas_flag .OR. qlim<sq%fs(mpsi,4)))THEN
jpsi=MINLOC(ABS(sq%fs(:,4)-qlim))
IF (jpsi(1)>= mpsi) jpsi(1)=mpsi-1
psilim=sq%xs(jpsi(1))
Expand All @@ -214,7 +214,7 @@ SUBROUTINE sing_lim
CALL program_stop("Can't find psilim.")
ENDIF
ELSE
qlim = qmax
qlim = sq%fs(mpsi,4)
q1lim=sq%fs1(mpsi,4)
psilim=psihigh
ENDIF
Expand Down
53 changes: 53 additions & 0 deletions regression/test/dcon_boundary_q.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
! After make -C install dcon, link only the DCON boundary solver on Linux.
! gfortran -fopenmp -ffunction-sections -fdata-sections -Idcon -Iequil -Ipentrc -Ivacuum -Jdcon &
! -c dcon/sing.f -o /path/to/test_sing.o
! gfortran -fopenmp -Wl,--gc-sections -Idcon -Iequil -Ipentrc -Ivacuum &
! regression/test/dcon_boundary_q.f90 /path/to/test_sing.o dcon/dcon_mod.o &
! -Ldeps/lib -lequil -llapack -lblas -lnetcdff -lnetcdf -o dcon_boundary_q
program dcon_boundary_q
use sing_mod, only: nn, mpsi, sq, spline_alloc, spline_fit_hermite, sing_lim, &
psihigh, psiedge, psilim, sas_flag, qmax, qhigh, qlim, q1lim
use params, only: r8
implicit none
real(r8), parameter :: tol = 1.0e-10_r8
integer :: i

mpsi = 8
nn = 1
sas_flag = .false.
psihigh = 1.0_r8
psiedge = psihigh
call spline_alloc(sq, mpsi, 4)
sq%xs = [(real(i, r8) / mpsi, i = 0, mpsi)]
sq%fs = 0.0_r8
sq%fs1 = 0.0_r8

sq%fs(:, 4) = 2.6_r8 + 2.0_r8 * (sq%xs - 0.6_r8)**2
sq%fs1(:, 4) = 4.0_r8 * (sq%xs - 0.6_r8)
qmax = 3.32_r8
call spline_fit_hermite(sq, "extrap", [.false., .false., .false., .true.])
qhigh = 1000.0_r8
call check_limit(1.0_r8, 2.92_r8, 1.6_r8)
qhigh = 3.1_r8
call check_limit(1.0_r8, 2.92_r8, 1.6_r8)

sq%fs(:, 4) = 2.0_r8 + 2.0_r8 * sq%xs
sq%fs1(:, 4) = 2.0_r8
qmax = 4.0_r8
call spline_fit_hermite(sq, "extrap", [.false., .false., .false., .true.])
qhigh = 3.75_r8
call check_limit(0.875_r8, 3.75_r8, 2.0_r8)

contains

subroutine check_limit(expected_psi, expected_q, expected_qprime)
real(r8), intent(in) :: expected_psi, expected_q, expected_qprime

call sing_lim
print '(a,3f12.8)', "psi, q, qprime at the boundary ", psilim, qlim, q1lim
if (abs(psilim - expected_psi) > tol) error stop "wrong boundary flux"
if (abs(qlim - expected_q) > tol) error stop "wrong boundary safety factor"
if (abs(q1lim - expected_qprime) > tol) error stop "wrong boundary shear"
end subroutine check_limit

end program dcon_boundary_q
Loading