Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIELDLINES] allow start from plasma boundary given in VMEC INDATA, not only wout #241

Open
wants to merge 112 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
112 commits
Select commit Hold shift + click to select a range
6922daf
[FIELDLINES] allow to place field line starting locations on plasma b…
jons-pf Jun 3, 2024
72af954
use only 16 lines for now; error message if in unimplemented code branch
jons-pf Jun 3, 2024
32c8a38
remove debugging printout again
jons-pf Jun 3, 2024
a343bb0
add input parameters nstart_pol and nstart_tor to prescribe number of…
jons-pf Jun 3, 2024
b64c101
fix error code printout
jons-pf Jun 3, 2024
43d1f64
use pos_pol, pos_tor also in case of starting from points on plasma b…
jons-pf Jun 3, 2024
68c29bd
pySTEL: Added new library functions as classes.
lazersos May 5, 2024
01bb7cd
LIBSTELL: Added subroutine to help interfacing with python.
lazersos May 5, 2024
84cccf3
pySTEL: Further improvements to the python interface
lazersos May 5, 2024
3428a54
pySTEL: removed coilPlot in favor of calling coils.py directly.
lazersos May 5, 2024
772ac47
pySTEL: Added missing doctext
lazersos May 5, 2024
39db656
BOOTSJ: Removed extra file
lazersos May 5, 2024
a13dfdd
pySTEL: Added Boozer transform routines
lazersos May 5, 2024
b85980d
pySTEL: VMEC routine can now output in_booz file.
lazersos May 5, 2024
a45dcef
pySTEL: Added interface to BOOTSJ namelist and fixed sign issue in sf…
lazersos May 6, 2024
f812578
Updated gitignore for Pythonic things
lazersos May 6, 2024
eb9fbcc
LIBSTELL: Interfacing of writing the BOOTSJ namelist
lazersos May 7, 2024
2525364
pySTELL: Added summary information to VMECplot
lazersos May 7, 2024
01266cd
pySTEL: Fixed bug in fieldlines iota calculation.
lazersos May 7, 2024
db49fce
pySTELL: Improvements to module writing.
lazersos May 7, 2024
55d945e
pySTELL: Boozer code now outputs bootsj input.
lazersos May 7, 2024
8115c4b
pySTELL: Writing of INDATA now handled better.
lazersos May 7, 2024
0229667
pySTEL: Moved BOOZER helper routines to booz_util.
lazersos May 7, 2024
1250101
pySTELL: Improved coils.py interfacing.
lazersos May 7, 2024
cfe4745
pySTEL: Moved helper routines to vmec_utils.py
lazersos May 7, 2024
903852b
pySTEL: Added routines for the FOCUS code.
lazersos May 7, 2024
c34d83c
Fixed .gitignore for python stuff.
lazersos May 7, 2024
fc9f52d
pySTEL: Added second plot to focus_util.py
lazersos May 7, 2024
7aa0437
pySTEL: Added iota plotting routine for focus.
lazersos May 7, 2024
cd38b6b
pySTEL: Created coil utility and implemented wall in libstell
lazersos May 9, 2024
594d9ee
pySTEL: Implemented fieldlines_util.py
lazersos May 9, 2024
bb577f6
pySTEL: Changes to stellopt.py
lazersos May 9, 2024
dc607fc
pySTEL: Defined particle energies in fusion.py
lazersos May 9, 2024
dc944b6
pySTEL: Added routines for handling BNORM file.
lazersos May 10, 2024
826214b
pySTEL: Added ability to compute coil-plasma distance along coil.
lazersos May 10, 2024
cc06041
BNORM: Adjusted Fourier space
lazersos May 12, 2024
15bfa4f
pySTEL: Small cleanup of coils.py
lazersos May 12, 2024
9f02e86
pySTEL: beams3d class interface defined.
lazersos May 15, 2024
f8f6823
pySTEL: Added routine for generating blender Coils.
lazersos May 15, 2024
5746630
pySTEL: Added routine for VMEC surface extrapolation.
lazersos May 15, 2024
1e918a1
pySTEL: Wall routine added for generating a blender vertices and faces.
lazersos May 15, 2024
dc5c882
pySTEL: Added class for collision operator.
lazersos May 15, 2024
6c08859
pySTEL: Added class for BOOTSJ
lazersos May 16, 2024
5f14063
Added a few files for .gitignore
lazersos May 16, 2024
1e8029d
pySTEL: Comment added
lazersos May 16, 2024
8dcdadc
pySTEL: Added routine for helping to import VMEC data into Blender
lazersos May 16, 2024
ab85142
pySTEL: Routine added for generating an offset surface from VMEC
lazersos May 16, 2024
1943fd2
pySTEL: Added blender code for rendering VMEC and coils.
lazersos May 16, 2024
8af27e5
pySTEL: Fixed bug in reading of bnorm harmonics
lazersos May 17, 2024
fe14076
pySTEL: Minor change to out VMEC wall extrapolation is ouptut.
lazersos May 17, 2024
162138d
LIBSTELL: Removed extra cyl_flux.f90 file.
lazersos May 17, 2024
4e56740
pySTEL: Added ability to generate FOCUS boundary and limiter files us…
lazersos May 17, 2024
20174d5
LIBSTELL: Added beams3d_globals.f90 to LIBSTELL in preparation to add…
lazersos May 17, 2024
dbc79ba
BEAMS3D/LIBSTELL: Moved beams3d_input_mod to LIBSTELL using beams3d_g…
lazersos May 19, 2024
3e7e872
BEAMS3D: Cleanup of comments from reorganization.
lazersos May 19, 2024
0baa2a8
BENCHMARKS: Fixes and improvements to the BEAMS3D benchmarks.
lazersos May 19, 2024
5f8a13b
pySTEL: Bug fixes to BEAMS3D interface.
lazersos May 20, 2024
e80c03f
BENCHMARKS: Updated deposition test.
lazersos May 20, 2024
3fa120c
BENCHMARKS: BEAMS3D tests now fully interfaced and updated.
lazersos May 20, 2024
653bf01
pySTEL: Fixed calcAminor in beams3d.py
lazersos May 21, 2024
0fc36ee
pySTEL: Added routine to calculate Er in beams3d.py
lazersos May 21, 2024
e87770b
LIBSTELL: Added helper routines for pulling constants in beams3d_globals
lazersos May 22, 2024
97185a8
LIBSTELL: Fixed to BEAMS3D namelist writing and wrapper routine added.
lazersos May 22, 2024
a71e7cb
pySTEL: Added BEASM3D_INPUT class.
lazersos May 22, 2024
e853228
pySTEL: Added routines for reading BEAMS3D_INPUT and fixed error mess…
lazersos May 22, 2024
df1d919
pySTEL: Added routines to read map and var_labels file in STELLOPT cl…
lazersos May 22, 2024
1a99189
pySTEL: Removed unnecessary import in vmec.py.
lazersos May 22, 2024
4ed5318
LIBSTELL/pySTEL: Fixed interface for reading/writing BEAMS3D_INPUT
lazersos May 25, 2024
cc0155f
pySTEL: Added BEAMS3D routine for calculating profiles and magnetic a…
lazersos May 27, 2024
b95adf3
pySTEL: Fixed bug in calcMagaxis
lazersos May 27, 2024
d90fc1d
LIBSTELL/DIAGNO: Moved diagno_runtime and diagno_input_mod into LIBST…
lazersos May 27, 2024
58e725b
DIAGNO: Removed diagno_input_mod.f90 and diagno_runtime from DIAGNO.
lazersos May 27, 2024
e6b805f
DIAGNO/LIBSTELL/pySTEL: Fixed interface for writing DIAGNO_IN namelists
lazersos May 28, 2024
d410510
pySTEL: removed unnecessary FourierRep import.
lazersos May 28, 2024
7853279
pySTEL: Added routine for reading STELLOPT prof files.
lazersos May 28, 2024
880fe19
pySTEL: Collisions added He3 and He4 mass.
lazersos May 28, 2024
60078fd
LIBSTELL: Created fieldlines_globals.f90 for interfacing fieldlines_i…
lazersos May 28, 2024
f1fdf96
LIBSTELL: Fixed issue with ezspline and diagno_globals.f90
lazersos May 28, 2024
d9ac8e8
STELLOPT/THRIFT: Fixed issue with DIAGNO.
lazersos May 28, 2024
af791bf
FIELDLINES: Implementation of fieldlines_global.f90 from LIBSTELL.
lazersos May 28, 2024
b6689a8
LIBSTELL: Integration of fieldlines_input_mod into LIBSTELL.
lazersos May 28, 2024
8632bc1
FIELDLINES: Integrated using fieldlines_input_mod from LIBSTELL.
lazersos May 28, 2024
2d034f3
BENCHMARKS: Fixed FIELDLINES benchmark.
lazersos May 28, 2024
d2e49c5
LIBSTELL/pySTEL: Added routines to write FIELDLINES_INPUT namelist.
lazersos May 29, 2024
11d5f65
STELLOPT: Cleanup before starting move of stellopt_input_mod to LIBSTELL
lazersos May 31, 2024
4d3fb0a
STELLOPT/LIBSTELL: Moved stellopt_input_mod to LIBSTELL.
lazersos May 31, 2024
206f977
STELLOPT: A bit of cleanup after moving file.
lazersos May 31, 2024
ad83e60
STELLOPT: Removed un-necessary files.
lazersos May 31, 2024
986bbfd
LIBSTELL: Added missing dependency.
lazersos May 31, 2024
630230d
STELLOPT: Cleanup of some dependencies.
lazersos May 31, 2024
8ab9083
LIBSTELL: Added global parameter CTYPES interface routines.
lazersos Jun 1, 2024
f769caf
LIBSTELL/STELLOPT: Removed ithread from read_stellopt_input interface.
lazersos Jun 1, 2024
d4ce53b
LIBSTELL: Removed unused phiedge_old variable.
lazersos Jun 1, 2024
fd9d9d1
pySTEL: Added STELLOPT OPTIMUM reading/writing namelist routines (WIP)
lazersos Jun 1, 2024
80fbf8b
LIBSTELL: Added routine to write OPTIMUM namelist and open file.
lazersos Jun 2, 2024
b47b3a7
pySTEL: Can now read/write STELLOPT OPTIMUM namelists.
lazersos Jun 2, 2024
530db96
LIBSTELL: Added routine for extracting nsd from python.
lazersos Jun 2, 2024
986348f
pySTEL: Added routines for extracting VMEC related constants for INDATA.
lazersos Jun 2, 2024
291fa5c
pySTEL: Added setup routine.
lazersos Jun 2, 2024
03696d7
pySTEL: Removed unnecessary print statements.
lazersos Jun 2, 2024
428ba99
pySTEL: Fixed duplicate line.
lazersos Jun 4, 2024
727e91c
BEAMS3D: precision of FIDASIM helpers
kudav Jun 4, 2024
5e21107
pySTEL: Fixed servers typo.
lazersos Jun 4, 2024
78a39f1
Use a more direct (i.e. no loops) implementation of mpi_calc_myrange.…
jons-pf Jun 3, 2024
1e9ef7e
remove stop statement, add additional comments
jons-pf Jun 4, 2024
09375ab
add comment on upper limit of
jons-pf Jun 4, 2024
0f0d4a1
clarify comment on upper limit of
jons-pf Jun 4, 2024
9bcfbda
comment on integer division
jons-pf Jun 4, 2024
6d9ec9e
improve comment on integer division
jons-pf Jun 4, 2024
ea59040
add input parameters nstart_pol and nstart_tor to prescribe number of…
jons-pf Jun 3, 2024
514aa73
Merge branch 'develop' into fieldlines_start_from_edge_in_vmec_indata
jons-pf Jun 4, 2024
f63173b
adjust to moved FIELDLINES inputs
jons-pf Jun 4, 2024
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
40 changes: 28 additions & 12 deletions FIELDLINES/Sources/fieldlines_init.f90
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
! Authors: S. Lazerson ([email protected])
! Date: 02/21/2012
! Description: This subroutine initializes the fields on the
! R, phi, Z grid.
! R, phi, Z grid.
!-----------------------------------------------------------------------
SUBROUTINE fieldlines_init
!-----------------------------------------------------------------------
Expand Down Expand Up @@ -71,8 +71,8 @@ SUBROUTINE fieldlines_init

! Limit what the user can do
IF (laxis_i .and. .not.lvac) lvac = .true.


! First Read The Input Namelist
iunit = 11
#if defined(MPI_OPT)
Expand Down Expand Up @@ -116,7 +116,7 @@ SUBROUTINE fieldlines_init
END DO
STOP
END IF

! IF (lplasma_only) THEN
! IF (lvmec) THEN
! rmin = 1.2*rmin_surf
Expand All @@ -138,7 +138,7 @@ SUBROUTINE fieldlines_init
ELSE
!rmin_temp = MINVAL(r_start,MASK = r_start > 0)
!zmin_temp = MINVAL(z_start,MASK = r_start > 0)

rmin_temp = r_start(1)
zmin_temp = z_start(1)
phimin_temp = phi_start(1)
Expand All @@ -162,7 +162,7 @@ SUBROUTINE fieldlines_init
eps1 = (rmax-rmin)*small
eps2 = (phimax-phimin)*small
eps3 = (zmax-zmin)*small

! Output some information
IF (lverb .and. .not.lrestart) THEN
WRITE(6,'(A)') '----- Input Parameters -----'
Expand All @@ -180,7 +180,7 @@ SUBROUTINE fieldlines_init
IF (lmu) WRITE(6,'(A)') ' DIFFUSION OPERATOR TURNED ON!'
CALL FLUSH(6)
END IF

! Create the background grid and initialize if necessary
IF (lrestart) THEN
CALL fieldlines_init_restart
Expand All @@ -199,7 +199,7 @@ SUBROUTINE fieldlines_init
FORALL(i = 1:nz) zaxis(i) = (i-1)*(zmax-zmin)/(nz-1) + zmin
FORALL(i = 1:nphi) phiaxis(i) = (i-1)*(phimax-phimin)/(nphi-1) + phimin
B_R = 0; B_PHI = 0; B_Z = 0
IF (lpres) PRES_G = 0
IF (lpres) PRES_G = 0
END IF
! Put the vacuum field on the background grid
IF (lmgrid) THEN
Expand All @@ -216,7 +216,6 @@ SUBROUTINE fieldlines_init
! Do NOTHING
ELSE IF (lvmec .and. .not.lvac) THEN
CALL fieldlines_init_vmec
IF (ledge_start) CALL fieldlines_init_vmec_edgestart
ELSE IF (lpies .and. .not.lvac) THEN
!CALL fieldlines_init_pies
ELSE IF (lspec .and. .not.lvac) THEN
Expand All @@ -229,20 +228,37 @@ SUBROUTINE fieldlines_init
CALL fieldlines_init_eqdsk
END IF

! Optionally, override the field line starting positions
! with points on the plasma boundary.
IF (ledge_start) THEN
IF (lvmec) THEN
! The equilibrium comes from VMEC in this case.
CALL fieldlines_init_vmec_edgestart
ELSE IF (lpies) THEN
! CALL fieldlines_init_pies_edgestart
ELSE IF (lspec) THEN
! CALL fieldlines_init_spec_edgestart
ELSE IF (lhint) THEN
! CALL fieldlines_init_hint_edgestart
ELSE IF (leqdsk) THEN
! CALL fieldlines_init_eqdsk_edgestart
END IF
END IF

! Handle error fields
IF (lerror_field) CALL fieldlines_init_errorfield

! Put curtor on axis and calculate the field
IF (laxis_i) CALL fieldlines_init_I

IF (ANY(B_PHI .eq. 0)) THEN
#if defined(MPI_OPT)
CALL MPI_FINALIZE(ierr_mpi)
IF (ierr_mpi /= MPI_SUCCESS) CALL handle_err(MPI_FINE_ERR,'fieldlines_init:B_PHI0',ierr_mpi)
#endif
stop 'ERROR: B_PHI = 0 Found'
END IF

! Handle outputting the B-FIELD
IF (lemc3 .or. lbfield_only .or. lafield_only) THEN
IF (lemc3 .and. myworkid==master) CALL fieldlines_write_emc3
Expand Down Expand Up @@ -389,5 +405,5 @@ SUBROUTINE fieldlines_init
#endif
!-----------------------------------------------------------------------
! End Subroutine
!-----------------------------------------------------------------------
!-----------------------------------------------------------------------
END SUBROUTINE fieldlines_init
41 changes: 30 additions & 11 deletions FIELDLINES/Sources/fieldlines_init_coil.f90
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,15 @@ SUBROUTINE fieldlines_init_coil
USE fieldlines_grid, ONLY: raxis,phiaxis,zaxis, nr, nphi, nz, &
rmin, rmax, zmin, zmax, phimin, &
phimax, B_R, B_Z, B_PHI
USE vparams, ONLY: ntord, mpold
USE vmec_input, ONLY: extcur_in => extcur, read_indata_namelist,&
nv_in => nzeta, nfp_in => nfp, nigroup
nfp_in => nfp, nigroup, &
mpol_in => mpol, ntor_in => ntor, &
rbc_in => rbc, zbs_in => zbs, &
rbs_in => rbs, zbc_in => zbc
USE biotsavart
USE mpi_params
USE mpi_inc
USE mpi_inc
!-----------------------------------------------------------------------
! Local Variables
! ier Error Flag
Expand All @@ -28,7 +32,7 @@ SUBROUTINE fieldlines_init_coil
IMPLICIT NONE
INTEGER :: mylocalid, mylocalmaster
INTEGER :: MPI_COMM_LOCAL
INTEGER :: ier, iunit, s, i, j, mystart, myend, k, ik, ig
INTEGER :: ier, iunit, s, i, j, mystart, myend, k, ik, ig, bdy_size
REAL(rprec) :: br, bphi, bz, current, current_first, &
br_temp, bphi_temp, bz_temp
!-----------------------------------------------------------------------
Expand All @@ -42,7 +46,7 @@ SUBROUTINE fieldlines_init_coil
CALL MPI_COMM_RANK( MPI_COMM_LOCAL, mylocalid, ierr_mpi ) ! MPI
#endif
mylocalmaster = master

! Read the input file for the EXTCUR array, NV, and NFP
IF (mylocalid == mylocalmaster) THEN
iunit = 11
Expand All @@ -55,8 +59,23 @@ SUBROUTINE fieldlines_init_coil
#if defined(MPI_OPT)
CALL MPI_BCAST(extcur_in,nigroup,MPI_REAL, mylocalmaster, MPI_COMM_LOCAL,ierr_mpi)
IF (ierr_mpi /=0) CALL handle_err(MPI_BCAST_ERR,'fieldlines_init_coil',ierr_mpi)
CALL MPI_BCAST(nfp_in,1,MPI_INTEGER, mylocalmaster, MPI_COMM_LOCAL,ierr_mpi)
IF (ierr_mpi /=0) CALL handle_err(MPI_BCAST_ERR,'fieldlines_init_coil',ierr_mpi)
CALL MPI_BCAST(mpol_in,1,MPI_INTEGER, mylocalmaster, MPI_COMM_LOCAL,ierr_mpi)
IF (ierr_mpi /=0) CALL handle_err(MPI_BCAST_ERR,'fieldlines_init_mgrid3.1',ierr_mpi)
CALL MPI_BCAST(ntor_in,1,MPI_INTEGER, mylocalmaster, MPI_COMM_LOCAL,ierr_mpi)
IF (ierr_mpi /=0) CALL handle_err(MPI_BCAST_ERR,'fieldlines_init_mgrid3.2',ierr_mpi)
bdy_size = (2 * ntord + 1) * mpold
CALL MPI_BCAST(rbc_in,bdy_size,MPI_REAL, mylocalmaster, MPI_COMM_LOCAL,ierr_mpi)
IF (ierr_mpi /=0) CALL handle_err(MPI_BCAST_ERR,'fieldlines_init_mgrid3.3',ierr_mpi)
CALL MPI_BCAST(zbs_in,bdy_size,MPI_REAL, mylocalmaster, MPI_COMM_LOCAL,ierr_mpi)
IF (ierr_mpi /=0) CALL handle_err(MPI_BCAST_ERR,'fieldlines_init_mgrid3.4',ierr_mpi)
CALL MPI_BCAST(rbs_in,bdy_size,MPI_REAL, mylocalmaster, MPI_COMM_LOCAL,ierr_mpi)
IF (ierr_mpi /=0) CALL handle_err(MPI_BCAST_ERR,'fieldlines_init_mgrid3.5',ierr_mpi)
CALL MPI_BCAST(zbc_in,bdy_size,MPI_REAL, mylocalmaster, MPI_COMM_LOCAL,ierr_mpi)
IF (ierr_mpi /=0) CALL handle_err(MPI_BCAST_ERR,'fieldlines_init_mgrid3.6',ierr_mpi)
#endif

! Read the coils file
CALL parse_coils_file(TRIM(coil_string))
nextcur = SIZE(coil_group) !SAL
Expand All @@ -71,12 +90,12 @@ SUBROUTINE fieldlines_init_coil
END IF
END DO
END DO

! Reset the phi grid limit to match mgrid
phimin = 0.0
phimax = pi2 / nfp_bs
FORALL(i = 1:nphi) phiaxis(i) = (i-1)*(phimax-phimin)/(nphi-1) + phimin

IF (lverb) THEN
WRITE(6,'(A)') '----- COILS Information -----'
WRITE(6,'(A,A)') ' FILE: ',TRIM(coil_string)
Expand Down Expand Up @@ -167,8 +186,8 @@ SUBROUTINE fieldlines_init_coil
CALL FLUSH(6)
CALL backspace_out(6,36)
CALL FLUSH(6)
END IF
END IF

! Free Variables
CALL cleanup_biotsavart

Expand All @@ -180,9 +199,9 @@ SUBROUTINE fieldlines_init_coil
CALL MPI_BARRIER(MPI_COMM_FIELDLINES,ierr_mpi)
IF (ierr_mpi /=0) CALL handle_err(MPI_BARRIER_ERR,'fieldlines_init_coil',ierr_mpi)
#endif

RETURN
!-----------------------------------------------------------------------
! End Subroutine
!-----------------------------------------------------------------------
!-----------------------------------------------------------------------
END SUBROUTINE fieldlines_init_coil
51 changes: 34 additions & 17 deletions FIELDLINES/Sources/fieldlines_init_mgrid.f90
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,14 @@ SUBROUTINE fieldlines_init_mgrid
USE fieldlines_grid, ONLY: raxis,phiaxis,zaxis, nr, nphi, nz, &
rmin, rmax, zmin, zmax, phimin, &
phimax, B_R, B_Z, B_PHI
USE vparams, ONLY: ntord, mpold
USE vmec_input, ONLY: extcur_in => extcur, read_indata_namelist,&
nv_in => nzeta, nfp_in => nfp, nigroup
nv_in => nzeta, nfp_in => nfp, nigroup, &
mpol_in => mpol, ntor_in => ntor, &
rbc_in => rbc, zbs_in => zbs, &
rbs_in => rbs, zbc_in => zbc
USE mgrid_field_mod, pi2_mgrid => pi2
USE mpi_params
USE mpi_params
!-----------------------------------------------------------------------
! Local Variables
! ier Error Flag
Expand All @@ -28,7 +32,7 @@ SUBROUTINE fieldlines_init_mgrid
IMPLICIT NONE
INTEGER :: mylocalid, mylocalmaster
INTEGER :: MPI_COMM_LOCAL
INTEGER :: ier, iunit, s, i, j, mystart, myend, k
INTEGER :: ier, iunit, s, i, j, mystart, myend, k, bdy_size
REAL(rprec) :: br, bphi, bz
!-----------------------------------------------------------------------
! Begin Subroutine
Expand All @@ -52,20 +56,33 @@ SUBROUTINE fieldlines_init_mgrid
CLOSE(iunit)
END IF
#if defined(MPI_OPT)
CALL MPI_BCAST(extcur_in,nigroup,MPI_REAL, mylocalmaster, MPI_COMM_LOCAL,ierr_mpi)
IF (ierr_mpi /=0) CALL handle_err(MPI_BCAST_ERR,'beams3d_init_mgrid1',ierr_mpi)
CALL MPI_BCAST(nv_in,1,MPI_INTEGER, mylocalmaster, MPI_COMM_LOCAL,ierr_mpi)
IF (ierr_mpi /=0) CALL handle_err(MPI_BCAST_ERR,'beams3d_init_mgrid2',ierr_mpi)
CALL MPI_BCAST(nfp_in,1,MPI_INTEGER, mylocalmaster, MPI_COMM_LOCAL,ierr_mpi)
IF (ierr_mpi /=0) CALL handle_err(MPI_BCAST_ERR,'beams3d_init_mgrid3',ierr_mpi)
CALL MPI_BCAST(extcur_in,nigroup,MPI_REAL, mylocalmaster, MPI_COMM_LOCAL,ierr_mpi)
IF (ierr_mpi /=0) CALL handle_err(MPI_BCAST_ERR,'fieldlines_init_mgrid1',ierr_mpi)
CALL MPI_BCAST(nv_in,1,MPI_INTEGER, mylocalmaster, MPI_COMM_LOCAL,ierr_mpi)
IF (ierr_mpi /=0) CALL handle_err(MPI_BCAST_ERR,'fieldlines_init_mgrid2',ierr_mpi)
CALL MPI_BCAST(nfp_in,1,MPI_INTEGER, mylocalmaster, MPI_COMM_LOCAL,ierr_mpi)
IF (ierr_mpi /=0) CALL handle_err(MPI_BCAST_ERR,'fieldlines_init_mgrid3.0',ierr_mpi)
CALL MPI_BCAST(mpol_in,1,MPI_INTEGER, mylocalmaster, MPI_COMM_LOCAL,ierr_mpi)
IF (ierr_mpi /=0) CALL handle_err(MPI_BCAST_ERR,'fieldlines_init_mgrid3.1',ierr_mpi)
CALL MPI_BCAST(ntor_in,1,MPI_INTEGER, mylocalmaster, MPI_COMM_LOCAL,ierr_mpi)
IF (ierr_mpi /=0) CALL handle_err(MPI_BCAST_ERR,'fieldlines_init_mgrid3.2',ierr_mpi)
bdy_size = (2 * ntord + 1) * mpold
CALL MPI_BCAST(rbc_in,bdy_size,MPI_REAL, mylocalmaster, MPI_COMM_LOCAL,ierr_mpi)
IF (ierr_mpi /=0) CALL handle_err(MPI_BCAST_ERR,'fieldlines_init_mgrid3.3',ierr_mpi)
CALL MPI_BCAST(zbs_in,bdy_size,MPI_REAL, mylocalmaster, MPI_COMM_LOCAL,ierr_mpi)
IF (ierr_mpi /=0) CALL handle_err(MPI_BCAST_ERR,'fieldlines_init_mgrid3.4',ierr_mpi)
CALL MPI_BCAST(rbs_in,bdy_size,MPI_REAL, mylocalmaster, MPI_COMM_LOCAL,ierr_mpi)
IF (ierr_mpi /=0) CALL handle_err(MPI_BCAST_ERR,'fieldlines_init_mgrid3.5',ierr_mpi)
CALL MPI_BCAST(zbc_in,bdy_size,MPI_REAL, mylocalmaster, MPI_COMM_LOCAL,ierr_mpi)
IF (ierr_mpi /=0) CALL handle_err(MPI_BCAST_ERR,'fieldlines_init_mgrid3.6',ierr_mpi)
#endif

IF (ALLOCATED(extcur)) DEALLOCATE(extcur)
nextcur = nigroup
ALLOCATE(extcur(nextcur))
extcur = 0.0
extcur(1:nextcur) = extcur_in(1:nextcur)

! Read the mgrid file
CALL mgrid_load(mgrid_string,extcur,nextcur,nv_in,nfp_in,ier,mylocalid,MPI_COMM_LOCAL)
IF (lverb) THEN
Expand All @@ -75,7 +92,7 @@ SUBROUTINE fieldlines_init_mgrid
END IF
CALL MPI_BARRIER(MPI_COMM_FIELDLINES,ierr_mpi)
IF (ierr_mpi /=0) CALL handle_err(MPI_BARRIER_ERR,'fieldlines_init_mgrid4',ierr_mpi)

! Check for grid consistency
IF ((rmin < rminb) .or. (rmax > rmaxb) .or. &
(zmin < zminb) .or. (zmax > zmaxb)) THEN
Expand All @@ -93,7 +110,7 @@ SUBROUTINE fieldlines_init_mgrid
#endif
stop
END IF

! Reset the phi grid limit to match mgrid
phimin = 0.0
phimax = pi2 / nfp_in
Expand Down Expand Up @@ -123,15 +140,15 @@ SUBROUTINE fieldlines_init_mgrid
END IF
END DO
END IF

! Clean up the progress bar
IF (lverb) THEN
CALL backspace_out(6,38)
WRITE(6,'(38X)',ADVANCE='no')
CALL backspace_out(6,38)
CALL FLUSH(6)
END IF
END IF

! Free Variables (put this here to make room)
CALL mgrid_free(ier,MPI_COMM_LOCAL)

Expand All @@ -143,9 +160,9 @@ SUBROUTINE fieldlines_init_mgrid
CALL MPI_BARRIER(MPI_COMM_FIELDLINES,ierr_mpi)
IF (ierr_mpi /=0) CALL handle_err(MPI_BARRIER_ERR,'fieldlines_init_mgrid8',ierr_mpi)
#endif

RETURN
!-----------------------------------------------------------------------
! End Subroutine
!-----------------------------------------------------------------------
!-----------------------------------------------------------------------
END SUBROUTINE fieldlines_init_mgrid
Loading