VMEC 8.52
3D Equilibrium solver with nested flux surfaces.
Loading...
Searching...
No Matches
residue_con.f90
Go to the documentation of this file.
1
3
9SUBROUTINE residue_con(gcr, gcz, gcl, fsqrz, old_fsqz)
10
11 USE vmec_main, p5 => cp5
12 USE vmec_params, ONLY: rss, zcs, rsc, zcc, meven, modd, ntmax
13 USE xstuff
14
15 IMPLICIT NONE
16
17 REAL(rprec), DIMENSION(ns,0:ntor,0:mpol1,ntmax), INTENT(inout) :: gcr
18 REAL(rprec), DIMENSION(ns,0:ntor,0:mpol1,ntmax), INTENT(inout) :: gcz
19 REAL(rprec), DIMENSION(ns,0:ntor,0:mpol1,ntmax), INTENT(inout) :: gcl
20 real(rprec), intent(in) :: fsqrz, old_fsqz
21
22 INTEGER, PARAMETER :: n0=0
23 INTEGER, PARAMETER :: m0=0
24 INTEGER, PARAMETER :: m1=1
25 INTEGER, PARAMETER :: n3d=0
26 INTEGER, PARAMETER :: nasym=1
27
28 INTEGER :: jedge, j, n, m, i
29 INTEGER :: delIter
30 REAL(rprec) :: r1
31 logical, parameter :: skip_scalfor_dbg = .true.
32
33 ! IMPOSE M=1 MODE CONSTRAINT TO MAKE THETA ANGLE
34 ! INVARIANT TO PHI-SHIFTS (AND THETA SHIFTS FOR ASYMMETRIC CASE)
35 ! (ZCS = RSS, ZSS = RCS ARE THE CORRECT POLAR RELATIONS)
36
37! #ifndef _HBANGLE
38 ! SYMMETRIC PERTURBATIONS (BASED ON POLAR RELATIONS):
39 ! RSS(n) = ZCS(n), n != 0
40 ! ASYMMETRIC PERTURBATIONS:
41 ! RSC(n) = ZCC(n), ALL n
42 !
43 ! INTERNALLY:
44 ! XC(rss) = .5*(Rss + Zcs), XC(zcs) = .5*(Rss - Zcs) -> 0
45 ! XC(rsc) = .5*(Rsc + Zcc), XC(zcc) = .5*(Rsc - Zcc) -> 0
46 ! THIS IMPLIES THE CONSTRAINT
47 ! 3D ONLY : GC(zcs) = 0;
48 ! ASYM: GC(zcc) = 0
49 IF (lthreed) CALL constrain_m1(gcr(:,:,m1,rss), gcz(:,:,m1,zcs), old_fsqz)
50 IF (lasym) CALL constrain_m1(gcr(:,:,m1,rsc), gcz(:,:,m1,zcc), old_fsqz)
51! #end /* ndef _HBANGLE */
52
53 ! COMPUTE INVARIANT RESIDUALS
54 r1 = one/(2.0_dp*r0scale)**2.0_dp ! --> actually look at r1*fnorm --> scaling factor for forces (?)
55 jedge = 0
56
57 ! SPH-JAH013108: MUST INCLUDE EDGE FORCE (INITIALLY) FOR V3FITA TO WORK
58 ! ADD A V3FIT RELATED FLAG? ADD fsq criterion first
59 deliter = iter2-iter1
60
61 ! Coding for VMEC2000 run stand-alone
62 IF (deliter.lt.50 .and. fsqrz.lt.1.e-6_dp) then
63 ! include edge contribution only if converged well enough fast enough (?)
64! print *, "include edge force in residue"
65 jedge = 1
66 end if
67
68 CALL getfsq (gcr, gcz, fsqr_con, fsqz_con, r1*fnorm, jedge)
69
70 ! PERFORM PRECONDITIONING AND COMPUTE RESIDUES
71
72! #ifndef _HBANGLE
73 ! m = 1 constraint scaling
74 IF (lthreed) CALL scale_m1(gcr(:,:,1,rss), gcz(:,:,1,zcs))
75 IF (lasym) CALL scale_m1(gcr(:,:,1,rsc), gcz(:,:,1,zcc))
76
77 jedge = 0
78 CALL scalfor (gcr, arm, brm, ard, brd, crd, jedge, skip_scalfor_dbg)
79 jedge = 1
80 CALL scalfor (gcz, azm, bzm, azd, bzd, crd, jedge, skip_scalfor_dbg)
81! #end /* ndef _HBANGLE */
82
83 !SPH: add fnorm1 ~ 1/R**2, since preconditioned forces gcr,gcz ~ Rmn or Zmn
84 CALL getfsq (gcr, gcz, fsqr1_con, fsqz1_con, fnorm1, m1) ! m1 is simply == 1 --> include edge
85
86END SUBROUTINE residue_con
subroutine getfsq(gcr, gcz, gnormr, gnormz, gnorm, medge)
Compute total force residual on flux surfaces.
Definition getfsq.f90:13
real(rprec) fsqr_con
real(rprec), dimension(:), allocatable crd
Definition vmec_main.f90:24
real(rprec), dimension(:,:), allocatable brd
Definition vmec_main.f90:18
real(rprec) fsqr1_con
real(rprec), dimension(:,:), allocatable azd
Definition vmec_main.f90:20
integer iter1
number of iterations at which the currently active evolution was branched off from
real(rprec) fnorm
Definition vmec_main.f90:93
real(rprec) fsqz1_con
real(rprec), dimension(:,:), allocatable brm
Definition vmec_main.f90:19
real(rprec), dimension(:,:), allocatable bzd
Definition vmec_main.f90:22
real(rprec), dimension(:,:), allocatable bzm
Definition vmec_main.f90:23
real(rprec), dimension(:,:), allocatable ard
Definition vmec_main.f90:16
real(rprec) fnorm1
Definition vmec_main.f90:97
real(rprec), dimension(:,:), allocatable arm
Definition vmec_main.f90:17
logical lthreed
real(rprec) r0scale
Definition vmec_main.f90:90
integer iter2
total number of iterations
real(rprec) fsqz_con
real(rprec), dimension(:,:), allocatable azm
Definition vmec_main.f90:21
integer, parameter modd
parity selection label for odd poloidal modes of R and Z
integer ntmax
number of contributing Fourier basis function (can be 1, 2 or 4); assigned in read_indata()
integer, parameter meven
parity selection label for even poloidal modes of R and Z
subroutine constrain_m1(gcr, gcz, old_fsqz)
Compute internal gr , gz required for constraint.
Definition residue.f90:168
subroutine scale_m1(gcr, gcz)
Compute internal gr , gz required for constraint.
Definition residue.f90:205
subroutine residue_con(gcr, gcz, gcl, fsqrz, old_fsqz)
Compute invariant residuals.
subroutine scalfor(gcx, axm, bxm, axd, bxd, cx, iflag, skip_scalfor_dbg)
Build forces from different contributions.
Definition scalfor.f90:16