VMEC 8.52
3D Equilibrium solver with nested flux surfaces.
Loading...
Searching...
No Matches
lamcal.f90
Go to the documentation of this file.
1
3
10SUBROUTINE lamcal(overg, guu, guv, gvv)
11 USE vmec_main
12 USE vmec_params, ONLY: ntmax, jlam, lamscale
13 USE realspace, ONLY: sqrts
14
15 use dbgout
16
17 IMPLICIT NONE
18
19 REAL(rprec), DIMENSION(ns,nznt), INTENT(in) :: overg, guu, guv, gvv
20
21 REAL(rprec), PARAMETER :: damping_fac=2.0_dp
22
23 INTEGER :: m,n,js
24 REAL(rprec) :: tnn, tnm, tmm, power, pfactor0, pfactor
25
26 blam(:ns) = sum(guu*overg, dim=2) ! over surface
27 clam(:ns) = sum(gvv*overg, dim=2) ! over surface
28 dlam(:ns) = sum(guv*overg, dim=2) ! over surface
29 blam(1) = blam(2) ! constant extrapolation to axis
30 clam(1) = clam(2) ! constant extrapolation to axis
31 dlam(1) = dlam(2) ! constant extrapolation to axis
32 blam(ns+1) = 0.0_dp ! virtual "ghost" point beyond LCFS
33 clam(ns+1) = 0.0_dp ! virtual "ghost" point beyond LCFS
34 dlam(ns+1) = 0.0_dp ! virtual "ghost" point beyond LCFS
35 DO js = 2, ns
36 blam(js) = cp5*(blam(js) + blam(js+1))
37 clam(js) = cp5*(clam(js) + clam(js+1))
38 dlam(js) = cp5*(dlam(js) + dlam(js+1))
39 END DO
40
41 faclam = 0.0_dp
42 pfactor0 = damping_fac/(2.0_dp*r0scale*lamscale)**2.0_dp
43
44 DO m = 0, mpol1
45 tmm = m*m
46 power = min(tmm/256.0_dp, 8._dp)
47
48 pfactor = pfactor0
49 DO n = 0, ntor
50 IF (m.eq.0 .and. n.eq.0) cycle
51
52 ! sometimes helps convergence
53 ! IF (n .gt. 1) pfactor = pfactor0/4
54
55 tnn = (n*nfp)**2.0_dp
56 tnm = 2.0_dp*m*n*nfp
57 DO js = jlam(m), ns
58
59 ! b: coupling between n and n ?
60 ! d: coupling between n and m ?
61 ! c: coupling between m and m ?
62
63 faclam(js,n,m,1) = (blam(js)*tnn + sign(dlam(js),blam(js))*tnm + clam(js)*tmm)
64 IF (faclam(js,n,m,1) .eq. zero) then
65 faclam(js,n,m,1) = -1.e-10_dp
66 end if
67
68 ! Damps m > 16 modes
69 faclam(js,n,m,1) = (pfactor/faclam(js,n,m,1)) * sqrts(js)**power
70
71 END DO
72 END DO
73 END DO
74
75 ! extend to rest of Fourier basis
76 DO n = 2, ntmax
77 faclam(:ns,0:ntor,0:mpol1,n) = faclam(:ns,0:ntor,0:mpol1,1)
78 END DO
79
80 ! ADD NORM FOR CHIP (PREVIOUSLY IOTA) FORCE, STORED IN lmnsc(m=0,n=0) COMPONENT
81 DO js = 1, ns
82 faclam(js,0,0,1) = (pfactor0*lamscale**2)/blam(js)
83 END DO
84
85 ! check lamcal output
86 if (open_dbg_context("lamcal", num_eqsolve_retries)) then
87
88 call add_real("pfactor0", pfactor0)
89
90 call add_real_1d("blam", ns+1, blam)
91 call add_real_1d("clam", ns+1, clam)
92 call add_real_1d("dlam", ns+1, dlam)
93
94 call add_real_3d("faclam", ns, ntor+1, mpol, faclam(:ns,0:ntor,0:mpol1,1)) !, order=(/ 2, 3, 1 /) ) ! TODO: check order !
95
96 call close_dbg_out()
97 end if
98
99END SUBROUTINE lamcal
subroutine lamcal(overg, guu, guv, gvv)
Normalization parameters for .
Definition lamcal.f90:11
logical function open_dbg_context(context_name, repetition, id)
check if any output is desired for the current iteration check if the given context should be openend...
Definition dbgout.f90:17
real(rprec), dimension(:), allocatable sqrts
sqrt(s), two-dimensional array on full-grid
Definition realspace.f90:32
real(rprec), dimension(:), allocatable dlam
Definition vmec_main.f90:15
real(rprec), dimension(:,:,:,:), allocatable faclam
Definition vmec_main.f90:28
real(rprec), dimension(:), allocatable clam
Definition vmec_main.f90:14
integer num_eqsolve_retries
real(rprec), dimension(:), allocatable blam
Definition vmec_main.f90:13
real(rprec) r0scale
Definition vmec_main.f90:90
integer, dimension(0:mpold), parameter jlam
starting js(m) values for which Lambda is evolved
real(rprec) lamscale
integer ntmax
number of contributing Fourier basis function (can be 1, 2 or 4); assigned in read_indata()