Skip to content

Commit

Permalink
Merge branch 'le3_gk' of github.com:gafusion/gacode into le3_gk
Browse files Browse the repository at this point in the history
  • Loading branch information
bellie committed Jan 3, 2025
2 parents 8d2c685 + 63a0503 commit 2aad731
Show file tree
Hide file tree
Showing 127 changed files with 17,547 additions and 604 deletions.
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ all:
cd vgen ; make
cd tglf ; make
cd cgyro ; make
cd xgyro ; make
cd gyro ; make
cd tgyro ; make
cd profiles_gen ; make
Expand All @@ -21,6 +22,7 @@ clean:
cd vgen ; make clean
cd tglf ; make clean
cd cgyro ; make clean
cd xgyro ; make clean
cd gyro ; make clean
cd tgyro ; make clean
cd profiles_gen ; make clean
Expand All @@ -42,6 +44,7 @@ distclean:
cd neo ; make clean
cd tglf ; make clean
cd cgyro ; make clean
cd xgyro ; make clean
cd gyro ; make clean
cd tgyro ; make clean
cd profiles_gen ; make clean
Expand Down
15 changes: 10 additions & 5 deletions cgyro/bin/cgyro_json
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ def opts():
description="CGYRO localdump utility",
epilog=textwrap.dedent(mytext))

parser.add_argument('-dir',
parser.add_argument('-e',
help="working directory (default: cwd)",
type=str,
default='.')

args=parser.parse_args()

return args.dir
return args.e

mydir = opts()

Expand Down Expand Up @@ -105,6 +105,8 @@ d['MACH'] = sim.mach
d['GAMMA_E'] = sim.gamma_e
d['GAMMA_P'] = sim.gamma_p
d['BETAE_UNIT'] = sim.betae_unit
d['NU_EE'] = sim.nu[ielec]
d['Z_EFF'] = sim.z_eff

d['ZMAG'] = sim.zmag
d['DZMAG'] = sim.dzmag
Expand All @@ -129,7 +131,7 @@ d['DLNNDR'] = sim.dlnndr[:].tolist()
d['DLNTDR'] = sim.dlntdr[:].tolist()

# JSON output
with open('json.cgyro.localdump','w') as f:
with open(mydir+'json.cgyro.localdump','w') as f:
json.dump(d,f,indent=2,sort_keys=True)
print('cgyro_json: wrote json.cgyro.localdump')
#==================================================================
Expand All @@ -138,7 +140,7 @@ with open('json.cgyro.localdump','w') as f:
# standard localdump output
#
nmax = 0
with open('out.cgyro.localdump','w') as f:
with open(mydir+'out.cgyro.localdump','w') as f:
for key in d:
x = d[key]
if 'SHAPE' in key:
Expand All @@ -164,6 +166,9 @@ print('cgyro_json: wrote out.cgyro.localdump')

nmax = nmax+1

if nmax < 3:
nmax = 3

# Reference dimensions in CGYRO units
lref=sim.rmaj
vthref = np.sqrt(2.0)
Expand Down Expand Up @@ -227,7 +232,7 @@ d['ds_dr_minor_norm'][1] = sim.s_delta*lref/sim.rmin/np.cos(np.arcsin(sim.delta)
d['ds_dr_minor_norm'][2] = -sim.s_zeta*lref/sim.rmin
#-----------------------------------------------------------------------

with open('json.cgyro.imas','w') as f:
with open(mydir+'json.cgyro.imas','w') as f:
json.dump(d,f,indent=2,sort_keys=True)
print('cgyro_json: wrote json.cgyro.imas')
#==================================================================
Expand Down
52 changes: 36 additions & 16 deletions cgyro/bin/cgyrodb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ from cgyro.data import cgyrodata

pd.set_option('display.max_rows', None)

ignore = 'eslshared'

# Command line option parser
def opts():

Expand All @@ -27,20 +29,32 @@ def opts():
description="CGYRO database utility",
epilog=textwrap.dedent(mytext))

parser.add_argument('-mode',
help='Mode switch (data,update)',
type=str,
default='data')
parser.add_argument('-ref',
help='Refresh directories',
action='store_true')
parser.add_argument('-json',
help='Generate IMAS and localdump files',
action='store_true')
parser.add_argument('-db',
help='Load the DB and print',
action='store_true')
parser.add_argument('-flux',
help='Add flux to DB',
action='store_true')

args=parser.parse_args()

return args.mode
return args.ref,args.json,args.db,args.flux

mode = opts()
ref,json,db,doflux = opts()

meta = {}

def gendict(sim,mode):
if (not ref) and (not json) and (not db):
print('Type "cgyrodb -h" for help')
sys.exit()

def gendict(sim,doflux):

mydict = {}

Expand All @@ -60,9 +74,9 @@ def gendict(sim,mode):
mydict['a/Ln1'] = 0.0
mydict['a/Lt1'] = 0.0

if mode == 'flux':
if doflux:
sim.getflux()
y = np.sum(sim.ky_flux,axis=(2,3))
y = np.sum(sim.ky_flux,axis=(2,3))
for ispec in range(sim.n_species):
g = average(y[ispec,0,:],sim.t,0.5,0.0)
q = average(y[ispec,1,:],sim.t,0.5,0.0)
Expand All @@ -73,25 +87,31 @@ def gendict(sim,mode):

return mydict

ignore = 'eslshared'

# First locate all directories
y = []
for root,xd,xf in os.walk('./'):
if xd == []:
if ignore not in root:
y.append(root)

if mode == 'update':
if ref:
# Run through directories and update
for mdir in y:
print('Updating '+mdir)
os.system('cgyro -t '+mdir)
else:
print('Refreshing '+mdir)
os.system('cd '+mdir+' ; python $GACODE_ROOT/cgyro/bin/cgyro_parse.py')
os.system('cd '+mdir+' ; $GACODE_ROOT/cgyro/src/cgyro ')

if json:
# Run through directories and update
for mdir in y:
print('Dumping '+mdir)
os.system('cgyro_json -e '+mdir)

if db:
# Create master dictionary "meta"
for mdir in tqdm(y):
sim = cgyrodata(mdir+'/',silent=True)
meta[mdir]=gendict(sim,mode)
meta[mdir]=gendict(sim,doflux)

df = pd.DataFrame(meta)
dfpart = df.T[['n_n','n_radial','n_theta','q','s','kappa','a/Ln0','a/Lt0','a/Ln1','a/Lt1','nuee']]
Expand Down
2 changes: 0 additions & 2 deletions cgyro/install/make.ext.AZURE_GPU

This file was deleted.

2 changes: 0 additions & 2 deletions cgyro/install/make.ext.CI_GPU

This file was deleted.

2 changes: 0 additions & 2 deletions cgyro/install/make.ext.CLOUD_GPU

This file was deleted.

2 changes: 0 additions & 2 deletions cgyro/install/make.ext.CRUSHER

This file was deleted.

2 changes: 0 additions & 2 deletions cgyro/install/make.ext.CSD3_AMPERE_GPU

This file was deleted.

2 changes: 0 additions & 2 deletions cgyro/install/make.ext.DAINT_PGI

This file was deleted.

2 changes: 0 additions & 2 deletions cgyro/install/make.ext.FRONTIER

This file was deleted.

2 changes: 0 additions & 2 deletions cgyro/install/make.ext.GASUMMIT_GPU

This file was deleted.

2 changes: 0 additions & 2 deletions cgyro/install/make.ext.LUMI

This file was deleted.

2 changes: 0 additions & 2 deletions cgyro/install/make.ext.MARCONI_LEONARDO

This file was deleted.

2 changes: 0 additions & 2 deletions cgyro/install/make.ext.NEURON

This file was deleted.

2 changes: 0 additions & 2 deletions cgyro/install/make.ext.PERLMUTTER_GPU

This file was deleted.

2 changes: 0 additions & 2 deletions cgyro/install/make.ext.PERLMUTTER_GPU_80G

This file was deleted.

2 changes: 0 additions & 2 deletions cgyro/install/make.ext.STAMPEDE3_GPU_IFX

This file was deleted.

2 changes: 0 additions & 2 deletions cgyro/install/make.ext.SUMMIT

This file was deleted.

6 changes: 6 additions & 0 deletions cgyro/src/cgyro_check_memory.F90
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ subroutine cgyro_check_memory(datafile)
else
call cgyro_alloc_add_3d(io,5,nc,nt_loc,8,'gcoef')
endif
if ((collision_model /= 5) .AND. (collision_field_model == 1)) then
call cgyro_alloc_add_3d(io,n_field,nt_loc,nc,16,'field_v')
call cgyro_alloc_add_3d(io,n_field,nt_loc,nc_loc,16,'field_loc_v')
call cgyro_alloc_add_4d(io,n_field,nv,nt_loc,nc_loc,8,'dvjvec_v')
endif
call cgyro_alloc_add_4d(io,n_field,nc,nv_loc,nt_loc,8,'dvjvec_c')

if (nonlinear_flag == 1) then
write(io,*)
Expand Down
8 changes: 8 additions & 0 deletions cgyro/src/cgyro_cleanup.F90
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,14 @@ subroutine cgyro_cleanup
ccl_del_device(gcoef)
deallocate(gcoef)
endif
if(allocated(field_v)) then
ccl_del_device(field_v)
deallocate(field_v)
endif
if(allocated(field_loc_v)) then
ccl_del_device(field_loc_v)
deallocate(field_loc_v)
endif
if(allocated(field)) then
ccl_del_device(field)
deallocate(field)
Expand Down
48 changes: 16 additions & 32 deletions cgyro/src/cgyro_field.F90
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ subroutine cgyro_field_v_notae_s(start_t)

call timer_lib_in('field')

field_loc(:,:,start_t:nt2) = (0.0,0.0)
field_loc_v(:,:,:) = (0.0,0.0)

! Poisson and Ampere RHS integrals of H

Expand All @@ -37,13 +37,13 @@ subroutine cgyro_field_v_notae_s(start_t)
call parallel_lib_nj_loc(nj_loc)

!$omp parallel do collapse(2) private(ic_loc,iv,ic,k,j)
do itor=start_t,nt2
do ic=nc1,nc2
do ic=nc1,nc2
do itor=start_t,nt2
ic_loc = ic-nc1+1
do k=1,nproc
do j=1,nj_loc
iv = j+(k-1)*nj_loc
field_loc(:,ic,itor) = field_loc(:,ic,itor)+dvjvec_v(:,ic_loc,itor,iv)*fsendf(j,itor,ic_loc,k)
field_loc_v(:,itor,ic) = field_loc_v(:,itor,ic)+dvjvec_v(:,iv,itor,ic_loc)*fsendf(j,itor,ic_loc,k)
enddo
enddo
enddo
Expand All @@ -53,8 +53,7 @@ subroutine cgyro_field_v_notae_s(start_t)

call timer_lib_in('field_com')

call parallel_lib_sum_field(field_loc(:,:,start_t:nt2), &
field(:,:,start_t:nt2))
call parallel_lib_collect_field(field_loc_v, field_v)

call timer_lib_out('field_com')

Expand All @@ -63,8 +62,10 @@ subroutine cgyro_field_v_notae_s(start_t)
! Poisson LHS factors
!$omp parallel do
do itor=start_t,nt2
do ic=1,nc
! assuming (.not.(itor == 0 .and. ae_flag == 1))
field(:,:,itor) = fcoef(:,:,itor)*field(:,:,itor)
field(:,ic,itor) = fcoef(:,ic,itor)*field_v(:,itor,ic)
enddo
enddo

call timer_lib_out('field')
Expand Down Expand Up @@ -117,37 +118,21 @@ subroutine cgyro_field_v_notae_s_gpu(start_t)

#if (!defined(OMPGPU)) && defined(_OPENACC)
!$acc data present(fsendf)
!$acc data present(field,field_loc)
!$acc data present(field,field_v,field_loc_v)
#endif

! Poisson and Ampere RHS integrals of H

#if defined(OMPGPU)
!$omp target teams distribute parallel do simd collapse(3) &
!$omp& map(to:start_t)
#elif defined(_OPENACC)
!$acc parallel loop collapse(3) gang vector &
!$acc& independent copyin(start_t) &
!$acc& present(nt2,nc,n_field) default(none)
#endif
do itor=start_t,nt2
do ic=1,nc
do i_f=1,n_field
field_loc(i_f,ic,itor) = (0.0,0.0)
enddo
enddo
enddo

#if defined(OMPGPU)
!$omp target teams distribute collapse(3) &
!$omp& private(ic_loc,field_loc_l) map(to:start_t,nproc,nj_loc)
#elif defined(_OPENACC)
!$acc parallel loop collapse(3) gang private(ic_loc,field_loc_l) &
!$acc& present(dvjvec_v,fsendf,field_loc) copyin(start_t,nproc,nj_loc) &
!$acc& present(dvjvec_v,fsendf) copyin(start_t,nproc,nj_loc) &
!$acc& present(nt2,nc1,nc2,n_field,nv) default(none)
#endif
do itor=start_t,nt2
do ic=nc1,nc2
do ic=nc1,nc2
do itor=start_t,nt2
do i_f=1,n_field
ic_loc = ic-nc1+1
field_loc_l = (0.0,0.0)
Expand All @@ -160,10 +145,10 @@ subroutine cgyro_field_v_notae_s_gpu(start_t)
do k=1,nproc
do j=1,nj_loc
iv = j+(k-1)*nj_loc
field_loc_l = field_loc_l+dvjvec_v(i_f,ic_loc,itor,iv)*fsendf(j,itor,ic_loc,k)
field_loc_l = field_loc_l+dvjvec_v(i_f,iv,itor,ic_loc)*fsendf(j,itor,ic_loc,k)
enddo
enddo
field_loc(i_f,ic,itor) = field_loc_l
field_loc_v(i_f,itor,ic) = field_loc_l
enddo
enddo
enddo
Expand All @@ -172,8 +157,7 @@ subroutine cgyro_field_v_notae_s_gpu(start_t)

call timer_lib_in('field_com')

call parallel_lib_sum_field_gpu(field_loc(:,:,start_t:nt2), &
field(:,:,start_t:nt2))
call parallel_lib_collect_field_gpu(field_loc_v, field_v)

call timer_lib_out('field_com')

Expand All @@ -191,7 +175,7 @@ subroutine cgyro_field_v_notae_s_gpu(start_t)
! assuming (.not.(itor == 0 .and. ae_flag == 1))
do ic=1,nc
do i_f=1,n_field
field(i_f,ic,itor) = fcoef(i_f,ic,itor)*field(i_f,ic,itor)
field(i_f,ic,itor) = fcoef(i_f,ic,itor)*field_v(i_f,itor,ic)
enddo
enddo
enddo
Expand Down
Loading

0 comments on commit 2aad731

Please sign in to comment.