Skip to content

Commit

Permalink
THRIFT: only keep the last substep of the ambipolar files and save time
Browse files Browse the repository at this point in the history
  • Loading branch information
ajchcoelho committed Dec 11, 2024
1 parent 8e07776 commit 9a1362e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 9 deletions.
13 changes: 8 additions & 5 deletions PENTA/Sources/penta_interface_mod.f90
Original file line number Diff line number Diff line change
Expand Up @@ -1243,20 +1243,21 @@ SUBROUTINE penta_run_5_cleanup(lscreen)
! Close(iu_contraflows_out)
END SUBROUTINE penta_run_5_cleanup

SUBROUTINE penta_run_6_merge_files(ns_dkes,proc_string)
SUBROUTINE penta_run_6_merge_files(ns_dkes,proc_string,mytime)

USE safe_open_mod

IMPLICIT NONE
INTEGER :: ierr, iunit_merged, iunit_read, k
INTEGER, INTENT(IN) :: ns_dkes
CHARACTER(LEN=256), INTENT(IN) :: proc_string
CHARACTER(LEN=64) :: temp_str
REAL(rknd), INTENT(IN) :: mytime
CHARACTER(LEN=32), INTENT(IN) :: proc_string
CHARACTER(LEN=32) :: temp_str
CHARACTER(LEN=256) :: input_filename, output_filename, line
iunit_merged = 25
iunit_read = 35

output_filename = 'ambipolar_roots_fluxes.' // TRIM(proc_string)
output_filename = 'ambipolar_roots.' // TRIM(proc_string)

!open merged file
CALL safe_open(iunit_merged, ierr, output_filename, "replace", 'formatted')
Expand All @@ -1266,7 +1267,9 @@ SUBROUTINE penta_run_6_merge_files(ns_dkes,proc_string)
end if

!write header of merged file
Write(iunit_merged,'("*",/,"r/a Er[V/cm] e<a>Er/kTe ", &
Write(iunit_merged,'("*",/,"t [s]")')
Write(iunit_merged,'(f7.3)') mytime
Write(iunit_merged,'("r/a Er[V/cm] e<a>Er/kTe ", &
"Gamma_e [m**-2s**-1] Q_e/T_e [m**-2s**-1] ", &
"Gamma_i [m**-2s**-1] Q_i/T_i [m**-2s**-1]")')

Expand Down
15 changes: 11 additions & 4 deletions THRIFT/Sources/thrift_penta.f90
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@ SUBROUTINE thrift_penta(lscreen,iflag)
!-----------------------------------------------------------------------
INTEGER :: ns_dkes, k, ier, j, i, ncstar, nestar, mystart, myend, &
mysurf, root_max_Er
REAL(rprec) :: s, rho
REAL(rprec) :: s, rho, mytime
REAL(rprec), DIMENSION(:), ALLOCATABLE :: rho_k, iota, phip, chip, btheta, bzeta, bsq, vp, &
te, ne, dtedrho, dnedrho, EparB, JBS_PENTA, etapar_PENTA, Er_PENTA, rho_temp, J_temp, eta_temp, Er_temp
REAL(rprec), DIMENSION(:,:), ALLOCATABLE :: ni,ti, dtidrho, dnidrho
REAL(rprec), DIMENSION(:,:), ALLOCATABLE :: D11, D13, D33
TYPE(EZspline1_r8) :: EparB_spl, J_spl, eta_spl, Er_spl
INTEGER :: bcs0(2)
CHARACTER(LEN=32) :: temp_str
CHARACTER(LEN=32) :: temp_str, temp1_str
!-----------------------------------------------------------------------
! BEGIN SUBROUTINE
!-----------------------------------------------------------------------
Expand All @@ -63,6 +63,8 @@ SUBROUTINE thrift_penta(lscreen,iflag)
JBS_PENTA = 0.0; etapar_PENTA = 0.0; Er_PENTA = 0.0

IF (myworkid == master) THEN

mytime = THRIFT_T(mytimestep)

! EparB Spline
bcs1=(/ 0, 0/)
Expand Down Expand Up @@ -139,6 +141,9 @@ SUBROUTINE thrift_penta(lscreen,iflag)
! VMEC quantities
CALL MPI_BCAST(eq_Aminor,1,MPI_DOUBLE_PRECISION,master,MPI_COMM_MYWORLD,ierr_mpi)
CALL MPI_BCAST(eq_Rmajor,1,MPI_DOUBLE_PRECISION,master,MPI_COMM_MYWORLD,ierr_mpi)
! THRIFT quantities
CALL MPI_BCAST(mytime,1,MPI_DOUBLE_PRECISION,master,MPI_COMM_MYWORLD,ierr_mpi)
CALL MPI_BCAST(mytimestep,1,MPI_DOUBLE_PRECISION,master,MPI_COMM_MYWORLD,ierr_mpi)

#endif

Expand All @@ -162,8 +167,10 @@ SUBROUTINE thrift_penta(lscreen,iflag)
CALL PENTA_SCREEN_INFO
CALL PENTA_ALLOCATE_DKESCOEFF
CALL PENTA_FIT_DXX_COEF

WRITE(temp_str,'(i4.4)') k
CALL PENTA_OPEN_OUTPUT(TRIM(proc_string) // '_k' // TRIM(temp_str))
WRITE(temp1_str,'(i3.3)') mytimestep
CALL PENTA_OPEN_OUTPUT(TRIM(temp1_str) // '_k' // TRIM(temp_str))
CALL PENTA_FIT_RAD_TRANS
! Now the basic steps
CALL PENTA_RUN_2_EFIELD
Expand Down Expand Up @@ -203,7 +210,7 @@ SUBROUTINE thrift_penta(lscreen,iflag)

IF (myworkid == master) THEN

IF(save_all_ambipolar_roots) CALL PENTA_RUN_6_MERGE_FILES(ns_dkes,proc_string)
IF(save_all_ambipolar_roots) CALL PENTA_RUN_6_MERGE_FILES(ns_dkes,temp1_str,mytime)

! Interpolate JBS_PENTA, etapar_PENTA and Er_PENTA at rho=0 and rho=1
ALLOCATE(J_temp(ns_dkes+2),eta_temp(ns_dkes+2),Er_temp(ns_dkes+2),rho_temp(ns_dkes+2))
Expand Down

0 comments on commit 9a1362e

Please sign in to comment.