VMEC 8.52
3D Equilibrium solver with nested flux surfaces.
Loading...
Searching...
No Matches
residue_mhd.f90
Go to the documentation of this file.
1
3
9SUBROUTINE residue_mhd (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 :: m1=1
23
24 INTEGER :: jedge, delIter
25 REAL(rprec) :: r1
26 logical, parameter :: skip_scalfor_dbg = .true.
27
28 ! IMPOSE M=1 MODE CONSTRAINT TO MAKE THETA ANGLE
29 ! INVARIANT TO PHI-SHIFTS (AND THETA SHIFTS FOR ASYMMETRIC CASE)
30 ! (ZCS = RSS, ZSS = RCS ARE THE CORRECT POLAR RELATIONS)
31
32! #ifndef _HBANGLE
33 ! SYMMETRIC PERTURBATIONS (BASED ON POLAR RELATIONS):
34 ! RSS(n) = ZCS(n), n != 0
35 ! ASYMMETRIC PERTURBATIONS:
36 ! RSC(n) = ZCC(n), ALL n
37 !
38 ! INTERNALLY:
39 ! XC(rss) = .5*(Rss + Zcs), XC(zcs) = .5*(Rss - Zcs) -> 0
40 ! XC(rsc) = .5*(Rsc + Zcc), XC(zcc) = .5*(Rsc - Zcc) -> 0
41 ! THIS IMPLIES THE CONSTRAINT
42 ! 3D ONLY : GC(zcs) = 0;
43 ! ASYM: GC(zcc) = 0
44 IF (lthreed) CALL constrain_m1(gcr(:,:,m1,rss), gcz(:,:,m1,zcs), old_fsqz)
45 IF (lasym) CALL constrain_m1(gcr(:,:,m1,rsc), gcz(:,:,m1,zcc), old_fsqz)
46! #end /* ndef _HBANGLE */
47
48 ! COMPUTE INVARIANT RESIDUALS
49 r1 = one/(2.0_dp*r0scale)**2.0_dp ! --> actually look at r1*fnorm --> scaling factor for forces (?)
50 jedge = 0
51
52 ! SPH-JAH013108: MUST INCLUDE EDGE FORCE (INITIALLY) FOR V3FITA TO WORK
53 ! ADD A V3FIT RELATED FLAG? ADD fsq criterion first
54 deliter = iter2-iter1
55
56 ! Coding for VMEC2000 run stand-alone
57 IF (deliter.lt.50 .and. fsqrz.lt.1.e-6_dp) then
58 ! include edge contribution only if converged well enough fast enough (?)
59! print *, "include edge force in residue"
60 jedge = 1
61 end if
62
63 CALL getfsq (gcr, gcz, fsqr_mhd, fsqz_mhd, r1*fnorm, jedge)
64
65 !fsql = fnormL*SUM(gcl*gcl)
66 !fedge = r1*fnorm * SUM(gcr(ns,:,:,:)**2 + gcz(ns,:,:,:)**2)
67
68 ! PERFORM PRECONDITIONING AND COMPUTE RESIDUES
69
70! #ifndef _HBANGLE
71 ! m = 1 constraint scaling
72 IF (lthreed) CALL scale_m1(gcr(:,:,1,rss), gcz(:,:,1,zcs))
73 IF (lasym) CALL scale_m1(gcr(:,:,1,rsc), gcz(:,:,1,zcc))
74
75 jedge = 0
76 CALL scalfor (gcr, arm, brm, ard, brd, crd, jedge, skip_scalfor_dbg)
77 jedge = 1
78 CALL scalfor (gcz, azm, bzm, azd, bzd, crd, jedge, skip_scalfor_dbg)
79! #end /* ndef _HBANGLE */
80
81 !SPH: add fnorm1 ~ 1/R**2, since preconditioned forces gcr,gcz ~ Rmn or Zmn
82 CALL getfsq (gcr, gcz, fsqr1_mhd, fsqz1_mhd, fnorm1, m1) ! m1 is simply == 1 --> include edge
83
84 !SPH: THIS IS NOT INVARIANT UNDER PHIP->A*PHIP, AM->A**2*AM IN PROFIL1D
85 ! (EXTCUR -> A*EXTCUR for FREE BOUNDARY)
86 gcl = faclam*gcl
87 !fsql1 = hs*SUM(gcl*gcl)
88 !030514 fsql1 = hs*lamscale**2*SUM(gcl*gcl)
89
90END SUBROUTINE residue_mhd
subroutine getfsq(gcr, gcz, gnormr, gnormz, gnorm, medge)
Compute total force residual on flux surfaces.
Definition getfsq.f90:13
real(rprec), dimension(:), allocatable crd
Definition vmec_main.f90:24
real(rprec), dimension(:,:), allocatable brd
Definition vmec_main.f90:18
real(rprec), dimension(:,:), allocatable azd
Definition vmec_main.f90:20
real(rprec), dimension(:,:,:,:), allocatable faclam
Definition vmec_main.f90:28
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), dimension(:,:), allocatable brm
Definition vmec_main.f90:19
real(rprec) fsqr1_mhd
real(rprec) fsqz_mhd
real(rprec) fsqr_mhd
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
real(rprec) fsqz1_mhd
integer iter2
total number of iterations
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_mhd(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