From 1b23e9908a774208dee0e38331b785aca91a35fa Mon Sep 17 00:00:00 2001 From: Jeff Candy Date: Sat, 16 Dec 2023 22:45:24 -0800 Subject: [PATCH 01/23] manual mode working for 1 ion --- profiles_gen/bin/gacode_type_autodetect | 4 ++ profiles_gen/bin/profiles_gen | 4 +- profiles_gen/src/Makefile | 2 + profiles_gen/src/prgen.f90 | 9 +++ profiles_gen/src/prgen_geometry.f90 | 16 +++-- profiles_gen/src/prgen_map_manual.f90 | 37 ++++++++++++ profiles_gen/src/prgen_read_manual.f90 | 78 +++++++++++++++++++++++++ profiles_gen/src/prgen_read_peqdsk.f90 | 1 - 8 files changed, 143 insertions(+), 8 deletions(-) create mode 100644 profiles_gen/src/prgen_map_manual.f90 create mode 100644 profiles_gen/src/prgen_read_manual.f90 diff --git a/profiles_gen/bin/gacode_type_autodetect b/profiles_gen/bin/gacode_type_autodetect index 0b0a1a4d5..41713d1ef 100755 --- a/profiles_gen/bin/gacode_type_autodetect +++ b/profiles_gen/bin/gacode_type_autodetect @@ -26,6 +26,10 @@ if [ "$1" == "null" ] ; then echo "null" exit 0 fi +if [ "$1" == "manual" ] ; then + echo "manual" + exit 0 +fi if [ ! -f $1 ] ; then echo "NOT_FOUND" exit 1 diff --git a/profiles_gen/bin/profiles_gen b/profiles_gen/bin/profiles_gen index db15b84c4..c19bd77db 100755 --- a/profiles_gen/bin/profiles_gen +++ b/profiles_gen/bin/profiles_gen @@ -448,14 +448,14 @@ if [ "$itype" == "GACODE" ] && [ $INFO_FLAG == 1 ] ; then exit 0 fi #============================================================= -# Managing input file (also catches UFILE mode) +# Managing input file if [ "$itype" == "null" ] ; then # gfile-only mode echo "INFO: (profiles_gen) Parsing GFILE only." -else +else echo "INFO: (profiles_gen) $FILE is autodetected as $itype." diff --git a/profiles_gen/src/Makefile b/profiles_gen/src/Makefile index ef2bfa3cd..f37b06202 100644 --- a/profiles_gen/src/Makefile +++ b/profiles_gen/src/Makefile @@ -18,6 +18,7 @@ OBJECTS = prgen_globals.o \ prgen_geometry.o \ prgen_ion_name.o \ prgen_map_iterdb.o \ + prgen_map_manual.o \ prgen_map_null.o \ prgen_map_plasmastate.o \ prgen_map_peqdsk.o \ @@ -27,6 +28,7 @@ OBJECTS = prgen_globals.o \ prgen_read_ti.o \ prgen_read_iterdb.o \ prgen_read_iterdb_nc.o \ + prgen_read_manual.o \ prgen_read_plasmastate.o \ prgen_read_peqdsk.o \ prgen_read_genf.o \ diff --git a/profiles_gen/src/prgen.f90 b/profiles_gen/src/prgen.f90 index 252539474..e9b16654b 100644 --- a/profiles_gen/src/prgen.f90 +++ b/profiles_gen/src/prgen.f90 @@ -12,6 +12,7 @@ ! SWIM (plasmastate) ! PFILE (peqdsk) ! GENF (General Fusion) +! MANUAL (Auto-import of text files) ! ! Autodetected geometry formats: ! GFILE (geqdsk equilibrium data) @@ -96,6 +97,12 @@ program prgen format_type = 4 call prgen_read_genf + case ('manual') ! MANUAL import + print '(a)','INFO: (prgen) Assuming MANUAL file import.' + + format_type = 5 + call prgen_read_manual + case('GACODE') ! Note (we may or may not have gmerge_flag == 1) print '(a)','INFO: (prgen) Assuming input.gacode (GACODE) format.' @@ -150,6 +157,8 @@ program prgen call prgen_map_peqdsk case (4) call prgen_map_genf + case (5) + call prgen_map_manual case (7,8) call prgen_map_inputgacode end select diff --git a/profiles_gen/src/prgen_geometry.f90 b/profiles_gen/src/prgen_geometry.f90 index 0946efbec..e87687530 100644 --- a/profiles_gen/src/prgen_geometry.f90 +++ b/profiles_gen/src/prgen_geometry.f90 @@ -57,13 +57,21 @@ subroutine prgen_geometry read(1) efit_zmaj close(1) + ! Get rho on efit mesh (so have psi,rho,q) + call prgen_get_chi(npsi,efit_q,efit_psi,efit_rho,torfluxa) + + efit_psi = efit_psi-efit_psi(1) + ! PFILE only contains normalized flux if (format_type == 3) then dpsi = (psi1-psi0)*dpsi endif - - efit_psi = efit_psi-efit_psi(1) + ! manual method needs dpsi on statefile grid + if (format_type == 5) then + call bound_interp(efit_rho,efit_psi,npsi,rho,dpsi,nx) + endif + ! Deal with null statefile if (format_type == 0) then nx = npsi @@ -90,13 +98,11 @@ subroutine prgen_geometry endif !-------------------------------------------------------------------------------------- - ! Get rho on efit mesh (so have psi,rho,q) - call prgen_get_chi(npsi,efit_q,efit_psi,efit_rho,torfluxa) ! Get q call cub_spline(efit_psi,efit_q,npsi,dpsi,q,nx) ! Get rho call prgen_get_chi(nx,q,dpsi,rho,torfluxa) - + call bound_interp(efit_rho,efit_rmin,npsi,rho,rmin,nx) call bound_interp(efit_psi,efit_q,npsi,dpsi,q,nx) call bound_interp(efit_psi,efit_p,npsi,dpsi,p_tot,nx) diff --git a/profiles_gen/src/prgen_map_manual.f90 b/profiles_gen/src/prgen_map_manual.f90 new file mode 100644 index 000000000..b572f74e7 --- /dev/null +++ b/profiles_gen/src/prgen_map_manual.f90 @@ -0,0 +1,37 @@ +!------------------------------------------------------------ +! prgen_map_manual.f90 +! +! PURPOSE: +! Map MANUAL data +!------------------------------------------------------------ + +subroutine prgen_map_manual + + use prgen_globals + use expro + + implicit none + + !--------------------------------------------------------- + ! Map profile data onto single array: + ! + expro_n_exp = nx + expro_n_ion = 1 + call expro_init(1) + ! + expro_rho(:) = rho(:) + expro_rmin(:) = rmin(:) + expro_rmaj(:) = rmaj(:) + expro_te(:) = te_kev(:) + expro_ne(:) = ne_e19m3(:) + expro_w0(:) = omega0(:) + + expro_mass(1) = 2.0 + expro_z(1) = 1.0 + expro_name(1) = 'D' + expro_type(1) = type_therm + + expro_ni(1,:) = ni_e19m3(:) + expro_ti(1,:) = ti_kev(:) + +end subroutine prgen_map_manual diff --git a/profiles_gen/src/prgen_read_manual.f90 b/profiles_gen/src/prgen_read_manual.f90 new file mode 100644 index 000000000..d911db7f2 --- /dev/null +++ b/profiles_gen/src/prgen_read_manual.f90 @@ -0,0 +1,78 @@ +!-------------------------------------------------------------- +! prgen_read_genf.f90 +! +! PURPOSE: +! Read profiles from General Fusion Statefile +!-------------------------------------------------------------- + +subroutine prgen_read_manual + + use prgen_globals + + implicit none + + integer :: i,n0 + + character(len=1) :: a + real, dimension(:,:), allocatable :: x + real, dimension(:), allocatable :: rho0 + + ! Number of resampled points + nx = 16 + call prgen_allocate('') + + call getlen('te.txt',n0) + + allocate(x(2,n0)) + allocate(rho0(n0)) + + ! te + open(unit=1,file='te.txt',status='old') + read(1,*) x(:,:) + close(1) + rho0 = x(1,:) + do i=1,nx + rho(i) = rho0(1)+(i-1.0)/(nx-1.0)*(rho0(n0)-rho0(1)) + enddo + call bound_interp(rho0,x(2,:)*1e-3,n0,rho,te_kev,nx) + + ! ti + open(unit=1,file='ti.txt',status='old') + read(1,*) x(:,:) + close(1) + call bound_interp(rho0,x(2,:)*1e-3,n0,rho,ti_kev,nx) + + ! ne + open(unit=1,file='ne.txt',status='old') + read(1,*) x(:,:) + close(1) + call bound_interp(rho0,x(2,:)*1e-19,n0,rho,ne_e19m3,nx) + + ! ni + open(unit=1,file='ni.txt',status='old') + read(1,*) x(:,:) + close(1) + call bound_interp(rho0,x(2,:)*1e-19,n0,rho,ni_e19m3,nx) + +end subroutine prgen_read_manual + +subroutine getlen(infile,n) + + implicit none + + character(len=*), intent(in) :: infile + integer, intent(inout) :: n + character(len=1) :: a + integer :: ios + + open(unit=1,file=trim(infile),status='old') + n = -1 + do + read(1,*,iostat=ios) a + if (ios < 0) exit + n = n+1 + enddo + close(1) + +end subroutine getlen + diff --git a/profiles_gen/src/prgen_read_peqdsk.f90 b/profiles_gen/src/prgen_read_peqdsk.f90 index 223bfcfb9..5d481012d 100644 --- a/profiles_gen/src/prgen_read_peqdsk.f90 +++ b/profiles_gen/src/prgen_read_peqdsk.f90 @@ -20,7 +20,6 @@ subroutine prgen_read_peqdsk !---------------------------------------------------- ! Read the peqdsk file ! - open(unit=1,file='pfile.ne',status='old') read(1,*) i nx = i From 0578e512c655775cd312a81ef3066ddef34cb46f Mon Sep 17 00:00:00 2001 From: Jeff Candy Date: Sun, 17 Dec 2023 21:57:57 -0800 Subject: [PATCH 02/23] Added impurity --- profiles_gen/bin/ufile2.py | 98 ++++++++++++++++++++++++++ profiles_gen/src/prgen_allocate.f90 | 1 + profiles_gen/src/prgen_globals.f90 | 1 + profiles_gen/src/prgen_map_manual.f90 | 10 ++- profiles_gen/src/prgen_read_manual.f90 | 18 +++-- 5 files changed, 121 insertions(+), 7 deletions(-) create mode 100755 profiles_gen/bin/ufile2.py diff --git a/profiles_gen/bin/ufile2.py b/profiles_gen/bin/ufile2.py new file mode 100755 index 000000000..0531e4945 --- /dev/null +++ b/profiles_gen/bin/ufile2.py @@ -0,0 +1,98 @@ +#!/usr/bin/env python +# Usage: +# +# python ufile2.py