diff --git a/examples/NCSX_vv_Anderson/regcoil_out.NCSX_vv_Anderson.reference.nc b/examples/NCSX_vv_Anderson/regcoil_out.NCSX_vv_Anderson.reference.nc index 73b67fa..c10c74d 100644 Binary files a/examples/NCSX_vv_Anderson/regcoil_out.NCSX_vv_Anderson.reference.nc and b/examples/NCSX_vv_Anderson/regcoil_out.NCSX_vv_Anderson.reference.nc differ diff --git a/examples/NCSX_vv_Picard/regcoil_out.NCSX_vv_Picard.reference.nc b/examples/NCSX_vv_Picard/regcoil_out.NCSX_vv_Picard.reference.nc index 9ca749f..64b04d8 100644 Binary files a/examples/NCSX_vv_Picard/regcoil_out.NCSX_vv_Picard.reference.nc and b/examples/NCSX_vv_Picard/regcoil_out.NCSX_vv_Picard.reference.nc differ diff --git a/regcoilPlot b/regcoilPlot index 38cc180..9267af2 100755 --- a/regcoilPlot +++ b/regcoilPlot @@ -11,14 +11,14 @@ import numpy as np from scipy.io import netcdf from scipy.interpolate import interp1d import sys -import math +import os if len(sys.argv) != 2: print "Error! You must specify 1 argument: the regcoil_out.XXX.nc file." exit(1) - -f = netcdf.netcdf_file(sys.argv[1],'r',mmap=False) +filename = sys.argv[1] +f = netcdf.netcdf_file(filename,'r',mmap=False) nfp = f.variables['nfp'][()] ntheta_plasma = f.variables['ntheta_plasma'][()] ntheta_coil = f.variables['ntheta_coil'][()] @@ -178,6 +178,7 @@ for whichPlot in range(4): plt.tight_layout() +plt.figtext(0.5,0.00,os.path.abspath(filename),ha='center',va='bottom',fontsize=7) ######################################################## # Pick the isaved values to show in the 2D plots @@ -249,6 +250,8 @@ plt.tight_layout() plt.subplots_adjust(top=0.95) plt.figtext(0.5,0.99,"Blue dots indicate the points that are plotted in later figures",horizontalalignment='center',verticalalignment='top',fontsize='small') +plt.figtext(0.5,0.00,os.path.abspath(filename),ha='center',va='bottom',fontsize=7) + ######################################################## # Prepare for future plots ######################################################## @@ -312,6 +315,7 @@ for js in range(num_abs_M_figures): plt.tight_layout() plt.subplots_adjust(top=0.94) plt.figtext(0.5,0.99,"Magnitude of the magnetization (|M|, [Amperes / meter])"+title_string,horizontalalignment='center',verticalalignment='top',fontsize='small') + plt.figtext(0.5,0.00,os.path.abspath(filename),ha='center',va='bottom',fontsize=7) ######################################################## # Plot d @@ -348,6 +352,7 @@ for whichPlot in range(numPlots): plt.tight_layout() plt.subplots_adjust(top=0.94) plt.figtext(0.5,0.99,"Thickness d of the magnetization region [meters].",horizontalalignment='center',verticalalignment='top',fontsize='small') +plt.figtext(0.5,0.00,os.path.abspath(filename),ha='center',va='bottom',fontsize=7) ######################################################## # Plot Bnormal @@ -384,6 +389,7 @@ plt.tight_layout() plt.subplots_adjust(top=0.94) plt.figtext(0.5,0.99,"Bnormal [Tesla]",horizontalalignment='center',verticalalignment='top',fontsize='small') +plt.figtext(0.5,0.00,os.path.abspath(filename),ha='center',va='bottom',fontsize=7) ######################################################## diff --git a/regcoil_init_basis_functions.f90 b/regcoil_init_basis_functions.f90 index c2b3980..23d5551 100644 --- a/regcoil_init_basis_functions.f90 +++ b/regcoil_init_basis_functions.f90 @@ -6,7 +6,7 @@ subroutine regcoil_init_basis_functions() implicit none integer :: itheta_coil, izeta_coil - integer :: index_coil, imn, iflag + integer :: index_coil, imn, iflag, offset integer :: tic, toc, countrate real(dp) :: angle, sinangle, cosangle @@ -25,13 +25,14 @@ subroutine regcoil_init_basis_functions() select case (symmetry_option) case (1,2) - num_basis_functions = mnmax_magnetization + 1 + num_basis_functions = mnmax_magnetization case (3) - num_basis_functions = mnmax_magnetization * 2 + 1 + num_basis_functions = mnmax_magnetization * 2 case default print *,"Error! Invalid setting for symmetry_option:",symmetry_option stop end select + if (include_constant_basis_function) num_basis_functions = num_basis_functions + 1 system_size = 3 * ns_magnetization * num_basis_functions @@ -43,10 +44,14 @@ subroutine regcoil_init_basis_functions() allocate(basis_functions_zeta_Z(ntheta_coil*nzeta_coil, num_basis_functions),stat=iflag) if (iflag .ne. 0) stop 'regcoil_build_matrices Allocation error 1!' - ! First basis function is the constant function: - ! (For stellarator symmetry, this basis function always has amplitude=0 for the zeta and Z components of M, but we include it in the code anyway just so the zeta and Z blocks have the same size as the R block.) - basis_functions_R(:, 1) = 1 - basis_functions_zeta_Z(:, 1) = 1 + offset = 0 + if (include_constant_basis_function) then + ! First basis function is the constant function: + ! (For stellarator symmetry, this basis function always has amplitude=0 for the zeta and Z components of M, but we include it in the code anyway just so the zeta and Z blocks have the same size as the R block.) + basis_functions_R(:, 1) = 1 + basis_functions_zeta_Z(:, 1) = 1 + offset = 1 + end if ! Remaining basis functions: ! These loops could be made faster @@ -62,8 +67,8 @@ subroutine regcoil_init_basis_functions() angle = xm_magnetization(imn)*theta_coil(itheta_coil)-xn_magnetization(imn)*zeta_coil(izeta_coil) sinangle = sin(angle) cosangle = cos(angle) - basis_functions_R(index_coil, imn+1) = sinangle - basis_functions_zeta_Z(index_coil, imn+1) = cosangle + basis_functions_R(index_coil, imn + offset) = sinangle + basis_functions_zeta_Z(index_coil, imn + offset) = cosangle end do end do end do @@ -78,10 +83,10 @@ subroutine regcoil_init_basis_functions() angle = xm_magnetization(imn)*theta_coil(itheta_coil)-xn_magnetization(imn)*zeta_coil(izeta_coil) sinangle = sin(angle) cosangle = cos(angle) - basis_functions_R(index_coil, imn + 1) = sinangle - basis_functions_zeta_Z(index_coil, imn + 1) = sinangle - basis_functions_R(index_coil, imn + 1 + mnmax_magnetization) = cosangle - basis_functions_zeta_Z(index_coil, imn + 1 + mnmax_magnetization) = cosangle + basis_functions_R(index_coil, imn + offset) = sinangle + basis_functions_zeta_Z(index_coil, imn + offset) = sinangle + basis_functions_R(index_coil, imn + offset + mnmax_magnetization) = cosangle + basis_functions_zeta_Z(index_coil, imn + offset + mnmax_magnetization) = cosangle end do end do end do diff --git a/regcoil_update_d.f90 b/regcoil_update_d.f90 index de25d9c..9c7ffaf 100644 --- a/regcoil_update_d.f90 +++ b/regcoil_update_d.f90 @@ -35,45 +35,47 @@ subroutine regcoil_update_d(jd,isaved) end if ! Fourier-filter d. First we transform from real to Fourier space: + if (filter_d) then !!$ print *,"d before filtering:" !!$ do j=1,ntheta_coil !!$ print "(*(f7.4))",d(j,:) !!$ end do - d0 = sum(d)/(ntheta_coil*nzeta_coil) - dmnc=0 - dmns=0 - factor = (2.0d+0) / (ntheta_coil * nzeta_coil) - do izeta = 1, nzeta_coil - do itheta = 1, ntheta_coil - do j = 1, mnmax_magnetization - angle = xm_magnetization(j) * theta_coil(itheta) - xn_magnetization(j) * zeta_coil(izeta) - sinangle = sin(angle) - cosangle = cos(angle) - factor2 = factor - ! The next 2 lines ensure inverse Fourier transform(Fourier transform) = identity - if (mod(ntheta_coil,2) == 0 .and. xm_magnetization(j) == (ntheta_coil/2)) factor2 = factor2 / 2 - if (mod( nzeta_coil,2) == 0 .and. abs(xn_magnetization(j)) == nfp*(nzeta_coil/2)) factor2 = factor2 / 2 - dmnc(j) = dmnc(j) + d(itheta, izeta) * cosangle * factor2 - dmns(j) = dmns(j) + d(itheta, izeta) * sinangle * factor2 + d0 = sum(d)/(ntheta_coil*nzeta_coil) + dmnc=0 + dmns=0 + factor = (2.0d+0) / (ntheta_coil * nzeta_coil) + do izeta = 1, nzeta_coil + do itheta = 1, ntheta_coil + do j = 1, mnmax_magnetization + angle = xm_magnetization(j) * theta_coil(itheta) - xn_magnetization(j) * zeta_coil(izeta) + sinangle = sin(angle) + cosangle = cos(angle) + factor2 = factor + ! The next 2 lines ensure inverse Fourier transform(Fourier transform) = identity + if (mod(ntheta_coil,2) == 0 .and. xm_magnetization(j) == (ntheta_coil/2)) factor2 = factor2 / 2 + if (mod( nzeta_coil,2) == 0 .and. abs(xn_magnetization(j)) == nfp*(nzeta_coil/2)) factor2 = factor2 / 2 + dmnc(j) = dmnc(j) + d(itheta, izeta) * cosangle * factor2 + dmns(j) = dmns(j) + d(itheta, izeta) * sinangle * factor2 + end do end do end do - end do - ! Now inverse transform: - d = d0 - do izeta = 1, nzeta_coil - do itheta = 1, ntheta_coil - do j = 1, mnmax_magnetization - angle = xm_magnetization(j)*theta_coil(itheta)-xn_magnetization(j)*zeta_coil(izeta) - sinangle = sin(angle) - cosangle = cos(angle) - d(itheta,izeta) = d(itheta,izeta) + dmnc(j)*cosangle + dmns(j)*sinangle + ! Now inverse transform: + d = d0 + do izeta = 1, nzeta_coil + do itheta = 1, ntheta_coil + do j = 1, mnmax_magnetization + angle = xm_magnetization(j)*theta_coil(itheta)-xn_magnetization(j)*zeta_coil(izeta) + sinangle = sin(angle) + cosangle = cos(angle) + d(itheta,izeta) = d(itheta,izeta) + dmnc(j)*cosangle + dmns(j)*sinangle + end do end do end do - end do !!$ print *,"d after filtering:" !!$ do j=1,ntheta_coil !!$ print "(*(f7.4))",d(j,:) !!$ end do + end if ! Take a mixture of the new and old depths: d = Picard_alpha * d + (1 - Picard_alpha) * last_d diff --git a/regcoil_variables.f90 b/regcoil_variables.f90 index 4cc497c..434cb6a 100644 --- a/regcoil_variables.f90 +++ b/regcoil_variables.f90 @@ -161,6 +161,8 @@ module regcoil_variables integer :: regularization_d_exponent = 1 real(dp) :: d0 real(dp), dimension(:), allocatable :: dmnc, dmns + logical :: filter_d = .true. + logical :: include_constant_basis_function = .true. integer, parameter :: max_nports = 10 integer :: nports @@ -184,7 +186,8 @@ module regcoil_variables d_option, nd, target_mu0_M, Anderson_depth, Anderson_alpha, Picard_alpha, min_d, & write_mgrid, mgrid_ir, mgrid_jz, mgrid_kp, mgrid_rmin, mgrid_rmax, mgrid_zmin, mgrid_zmax, & include_bnormal_from_TF, net_poloidal_current_Amperes, regularization_d_exponent, & - ports_theta0, ports_zeta0, ports_theta_width, ports_zeta_width, ports_sharpness, ports_magnitude + ports_theta0, ports_zeta0, ports_theta_width, ports_zeta_width, ports_sharpness, ports_magnitude, & + filter_d, include_constant_basis_function end module regcoil_variables