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

Master dev #13

Merged
merged 3 commits into from
Jul 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
20 changes: 15 additions & 5 deletions Sources/bmw.f
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,10 @@ PROGRAM bmw
flags = IBCLR(flags, bmw_state_flags_ju)
flags = IBCLR(flags, bmw_state_flags_jv)
END IF
IF (cl_parser%is_flag_set('-wvacf')) THEN
flags = IBSET(flags, bmw_state_flags_correct)
flags = IBCLR(flags, bmw_state_flags_siesta)
END IF

flags = IBSET(flags, bmw_state_flags_mgrid)
num_p = 0
Expand All @@ -121,13 +125,11 @@ PROGRAM bmw
IF (cl_parser%is_flag_set('-mgridf')) THEN
context => bmw_context_class(cl_parser%get('-mgridf'), &
& cl_parser%get('-woutf'), &
& cl_parser%get('-wvacf'), &
& cl_parser%get('-siestaf'), &
& flags, num_p, parallel, io_unit)
ELSE
num_p = cl_parser%get('-num_p', 1)
context => bmw_context_class(cl_parser%get('-woutf'), &
& cl_parser%get('-wvacf'), &
& cl_parser%get('-siestaf'), flags, &
& cl_parser%get('-num_r', 1), num_p, &
& cl_parser%get('-num_z', 1), &
Expand All @@ -137,9 +139,17 @@ PROGRAM bmw
& cl_parser%get('-zmin', 0.0_dp), &
& parallel, io_unit)
END IF
CALL context%set_up_grid(cl_parser%get('-p_start', -1), &
& cl_parser%get('-p_end', -1), &
& parallel, io_unit)
IF (cl_parser%is_flag_set('-wvacf')) THEN
CALL context%set_up_grid(cl_parser%get('-wvacf'), &
& num_p*context%m_grid%nfp, flags, &
& cl_parser%get('-p_start', -1), &
& cl_parser%get('-p_end', -1), &
& parallel, io_unit)
ELSE
CALL context%set_up_grid(cl_parser%get('-p_start', -1), &
& cl_parser%get('-p_end', -1), &
& parallel, io_unit)
END IF
CALL context%write(cl_parser%get('-outf'), parallel)

DEALLOCATE(context)
Expand Down
128 changes: 69 additions & 59 deletions Sources/bmw_context.f
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,10 @@ MODULE bmw_context
CONTAINS
PROCEDURE, PASS :: set_up_grid_m => bmw_context_set_up_grid_m
PROCEDURE, PASS :: set_up_grid_a => bmw_context_set_up_grid_a
GENERIC :: set_up_grid => set_up_grid_m, set_up_grid_a
PROCEDURE, PASS :: set_up_grid_c => bmw_context_set_up_grid_c
GENERIC :: set_up_grid => set_up_grid_m, &
& set_up_grid_a, &
& set_up_grid_c
PROCEDURE, PASS :: write => bmw_context_write
FINAL :: bmw_context_destruct
END TYPE
Expand All @@ -56,8 +59,7 @@ MODULE bmw_context
!> Interface for the bmw_context constructor.
!-------------------------------------------------------------------------------
INTERFACE bmw_context_class
MODULE PROCEDURE bmw_context_construct_no_vac, &
& bmw_context_construct, &
MODULE PROCEDURE bmw_context_construct, &
& bmw_context_construct_plasma
END INTERFACE

Expand All @@ -79,55 +81,9 @@ MODULE bmw_context
!> @param[in] io_unit Unit number to write messages to.
!> @returns A pointer to a constructed @ref bmw_context_class object.
!-------------------------------------------------------------------------------
FUNCTION bmw_context_construct_no_vac(mgrid_file_name, &
& wout_file_name, &
& siesta_file_name, flags, &
& num_p, parallel, io_unit)
IMPLICIT NONE

! Declare Arguments
CLASS (bmw_context_class), POINTER :: bmw_context_construct_no_vac
CHARACTER (len=*), INTENT(in) :: mgrid_file_name
CHARACTER (len=*), INTENT(in) :: wout_file_name
CHARACTER (len=*), INTENT(in) :: siesta_file_name
INTEGER, INTENT(in) :: flags
INTEGER, INTENT(inout) :: num_p
CLASS (bmw_parallel_context_class), INTENT(in) :: parallel
INTEGER, INTENT(in) :: io_unit

! local variables
REAL (rprec) :: start_time

! Start of executable code
start_time = profiler_get_start_time()

bmw_context_construct_no_vac => &
& bmw_context_construct(mgrid_file_name, wout_file_name, '', &
& siesta_file_name, flags, num_p, &
& parallel, io_unit)

CALL profiler_set_stop_time('bmw_context_construct_no_vac', &
& start_time)

END FUNCTION
!-------------------------------------------------------------------------------
!> @brief Construct a @ref bmw_context_class object.
!>
!> Allocates memory and initializes a @ref bmw_context_class object.
!>
!> @param[in] mgrid_file_name Path and name of the mgrid file.
!> @param[in] wout_file_name Path and name of the wout file.
!> @param[in] vmec_vac_file Name of the zero beta vmec file.
!> @param[in] siesta_file_name Path and name of the siesta file.
!> @param[in] flags Option flags.
!> @param[in] num_p Number of phi planes per field period.
!> @param[in] parallel @ref bmw_parallel_context_class object instance.
!> @param[in] io_unit Unit number to write messages to.
!> @returns A pointer to a constructed @ref bmw_context_class object.
!-------------------------------------------------------------------------------
FUNCTION bmw_context_construct(mgrid_file_name, vmec_vac_file, &
& wout_file_name, siesta_file_name, &
& flags, num_p, parallel, io_unit)
FUNCTION bmw_context_construct(mgrid_file_name, wout_file_name, &
& siesta_file_name, flags, num_p, &
& parallel, io_unit)
USE bmw_state_flags, Only: bmw_state_flags_mgrid

IMPLICIT NONE
Expand All @@ -136,7 +92,6 @@ FUNCTION bmw_context_construct(mgrid_file_name, vmec_vac_file, &
CLASS (bmw_context_class), POINTER :: bmw_context_construct
CHARACTER (len=*), INTENT(in) :: mgrid_file_name
CHARACTER (len=*), INTENT(in) :: wout_file_name
CHARACTER (len=*), INTENT(in) :: vmec_vac_file
CHARACTER (len=*), INTENT(in) :: siesta_file_name
INTEGER, INTENT(in) :: flags
INTEGER, INTENT(inout) :: num_p
Expand Down Expand Up @@ -166,8 +121,7 @@ FUNCTION bmw_context_construct(mgrid_file_name, vmec_vac_file, &
bmw_context_construct%p_grid => &
& primed_grid_class(num_p*bmw_context_construct%m_grid%nfp, &
& flags, bmw_context_construct%vmec, &
& vmec_vac_file, siesta_file_name, parallel, &
& io_unit)
& siesta_file_name, parallel, io_unit)

CALL profiler_set_stop_time('bmw_context_construct', start_time)

Expand All @@ -183,7 +137,6 @@ FUNCTION bmw_context_construct(mgrid_file_name, vmec_vac_file, &
!>
!> @param[in] mgrid_file_name Path and name of the mgrid file.
!> @param[in] wout_file_name Path and name of the wout file.
!> @param[in] vmec_vac_file Name of the zero beta vmec file.
!> @param[in] siesta_file_name Path and name of the siesta file.
!> @param[in] flags Option flags.
!> @param[in] num_r Number of radial points.
Expand All @@ -198,7 +151,6 @@ FUNCTION bmw_context_construct(mgrid_file_name, vmec_vac_file, &
!> @returns A pointer to a constructed @ref bmw_context_class object.
!-------------------------------------------------------------------------------
FUNCTION bmw_context_construct_plasma(wout_file_name, &
& vmec_vac_file, &
& siesta_file_name, flags, &
& num_r, num_p, num_z, &
& rmax, rmin, zmax, zmin, &
Expand All @@ -210,7 +162,6 @@ FUNCTION bmw_context_construct_plasma(wout_file_name, &
! Declare Arguments
CLASS (bmw_context_class), POINTER :: bmw_context_construct_plasma
CHARACTER (len=*), INTENT(in) :: wout_file_name
CHARACTER (len=*), INTENT(in) :: vmec_vac_file
CHARACTER (len=*), INTENT(in) :: siesta_file_name
INTEGER, INTENT(in) :: flags
INTEGER, INTENT(in) :: num_r
Expand Down Expand Up @@ -244,7 +195,7 @@ FUNCTION bmw_context_construct_plasma(wout_file_name, &
& primed_grid_class( &
& num_p*bmw_context_construct_plasma%m_grid%nfp, &
& flags, bmw_context_construct_plasma%vmec, &
& vmec_vac_file, siesta_file_name, parallel, io_unit)
& siesta_file_name, parallel, io_unit)

CALL profiler_set_stop_time('bmw_context_construct_plasma', &
& start_time)
Expand Down Expand Up @@ -379,6 +330,65 @@ SUBROUTINE bmw_context_set_up_grid_a(this, r_grid, z_grid, dphi, &

END SUBROUTINE

!-------------------------------------------------------------------------------
!> @brief Set the unprimed grid.
!>
!> This initializes the unprimed file using supplied grid as the unprimed
!> grid. This run the vacuum corrected unprimed grid.
!>
!> @param[inout] this A @ref bmw_context_class instance.
!> @param[in] vmec_vac_file Name of the zero beta vmec file.
!> @param[in] num_v Number of toroidal grid points.
!> @param[in] flags Number of toroidal grid points.
!> @param[in] r_grid 3D Array of r positions.
!> @param[in] z_grid 3D Array of z positions.
!> @param[in] dphi Phi grid spacing.
!> @param[in] parallel @ref bmw_parallel_context_class object instance.
!> @param[in] io_unit Unit number to write messages to.
!> @returns A pointer to a constructed @ref bmw_context_class object.
!-------------------------------------------------------------------------------
SUBROUTINE bmw_context_set_up_grid_c(this, vmec_vac_file, &
& num_v, flags, &
& p_start, p_end, &
& parallel, io_unit)

IMPLICIT NONE

! Declare Arguments
CLASS (bmw_context_class), INTENT(inout) :: this
CHARACTER (len=*), INTENT(in) :: vmec_vac_file
INTEGER, INTENT(in) :: num_v
INTEGER, INTENT(in) :: flags
INTEGER, INTENT(in) :: p_start
INTEGER, INTENT(in) :: p_end
CLASS (bmw_parallel_context_class), INTENT(in) :: parallel
INTEGER, INTENT(in) :: io_unit

! local variables
REAL (rprec) :: start_time
CLASS (vmec_file_class), POINTER :: vmec
CLASS (primed_grid_class), POINTER :: p_grid_vac

! Start of executable code
start_time = profiler_get_start_time()

vmec => vmec_file_class(TRIM(vmec_vac_file))
p_grid_vac => primed_grid_construct(num_v, flags, vmec, '', '', &
& parallel, io_unit)
DEALLOCATE(vmec)
vmec => null()
this%up_grid => unprimed_grid_class(this%m_grid, this%p_grid, &
& p_grid_vac, &
& p_start, p_end, &
& parallel, io_unit)
DEALLOCATE(p_grid_vac)
p_grid_vac => null()

CALL profiler_set_stop_time('bmw_context_set_up_grid_c', &
& start_time)

END SUBROUTINE

!*******************************************************************************
! NETCDF SUBROUTINES
!*******************************************************************************
Expand Down
2 changes: 2 additions & 0 deletions Sources/bmw_state_flags.f
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,7 @@ MODULE bmw_state_flags
INTEGER, PARAMETER :: bmw_state_flags_siesta = 3
!> Bit position for mgrid specified number of phi planes.
INTEGER, PARAMETER :: bmw_state_flags_mgrid = 4
!> Bit position for vmec vacuum correction.
INTEGER, PARAMETER :: bmw_state_flags_correct = 5

END MODULE
23 changes: 12 additions & 11 deletions Sources/primed_grid.f
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,15 @@ MODULE primed_grid
!> Interface for the bmw_commandline_parser constructor.
!-------------------------------------------------------------------------------
INTERFACE primed_grid_class
MODULE PROCEDURE primed_grid_construct_no_vac, &
& primed_grid_construct
MODULE PROCEDURE primed_grid_construct, &
& primed_grid_construct_no_vac
END INTERFACE

CONTAINS
!*******************************************************************************
! CONSTRUCTION SUBROUTINES
!*******************************************************************************
! FIXME: This is a temp constructor until the surface code can be updated.
! FIXME: Temp constructor to remove the vaccum vmec argument.
!-------------------------------------------------------------------------------
!> @brief Construct a @ref primed_grid_class object.
!>
Expand All @@ -71,41 +71,42 @@ MODULE primed_grid
!>
!> @param[in] num_v Number of toroidal grid points.
!> @param[in] flags Number of toroidal grid points.
!> @param[in] vmec VMEC file object.
!> @param[in] siesta_file_name Name of the siesta restart file.
!> @param[in] parallel @ref bmw_parallel_context_class object instance.
!> @param[in] io_unit Unit number to write messages to.
!> @returns A pointer to a constructed @ref primed_grid_class object.
!-------------------------------------------------------------------------------
FUNCTION primed_grid_construct_no_vac(num_v, flags, &
& siesta_file_name, &
& parallel, io_unit)
FUNCTION primed_grid_construct_no_vac(num_v, flags, vmec, &
& siesta_file_name, parallel, &
& io_unit)
USE bmw_state_flags
USE vmec_file
USE read_wout_mod, ONLY: read_wout_file

IMPLICIT NONE

! Declare Arguments
TYPE (primed_grid_class), POINTER :: primed_grid_construct_no_vac
INTEGER, INTENT(in) :: num_v
INTEGER, INTENT(in) :: flags
CLASS (vmec_file_class), POINTER, INTENT(in) :: vmec
CHARACTER (len=*), INTENT(in) :: siesta_file_name
TYPE (bmw_parallel_context_class), INTENT(in) :: parallel
INTEGER, INTENT(in) :: io_unit

! local variables
REAL (rprec) :: start_time
CLASS (vmec_file_class), POINTER :: vmec

! Start of executable code
start_time = profiler_get_start_time()

vmec => vmec_file_class('')
primed_grid_construct_no_vac => &
& primed_grid_construct(num_v, flags, vmec, '', &
& siesta_file_name, parallel, io_unit)
& primed_grid_construct(num_v, flags, vmec, '', siesta_file_name, &
& parallel, io_unit)

CALL profiler_set_stop_time('primed_grid_construct_no_vac', &
& start_time)

END FUNCTION

!-------------------------------------------------------------------------------
Expand Down
Loading