Page MenuHomec4science

cpy.py
No OneTemporary

File Metadata

Created
Mon, Feb 24, 03:31
#!/usr/bin/env python
# This scripts contains routines to, e.g., generate the gk coulomb and others, bluid IS operator from OS,
import numpy as np
import os
import sys
import h5py as h5
def gkcoulomb_default(cwd):
print('Construct gk coulomb default from '+ str( cwd))
gkcoulomb_self( cwd)
gkcoulomb_ei( cwd)
gkcoulomb_ie( cwd)
return
def gkcoulomb_ii(cwd, in_ = 'self.jEnnp.h5', out_ = 'self.h5'):
# construct gkcoulomb operator for ii
print('Create GK Coulomb from ' + cwd)
# Define h5 files
selfcolls_file = os.path.join( cwd, in_)
selfcolls_file_out = os.path.join( cwd, out_)
# Self collisions
print('ii collisions....')
# Open file
selfh5 = h5.File(selfcolls_file, 'r')
selfh5_out = h5.File(selfcolls_file_out, 'w')
# Ion-ion
# get dimension
Pmaxi = selfh5['/Caapj/Ciipjpjnn'].attrs['Pmaxi']
Jmaxi = selfh5['/Caapj/Ciipjpjnn'].attrs['Jmaxi']
def numb(pp,jj):
lbari = (Jmaxi +1)*pp + jj +1
return lbari
# Get 4 dim rows
rows_4dim= selfh5['/Caapj/rows_i']
# Get Cippj
Cpj_4dim=selfh5['/Caapj/Ciipjpjnn']
Cpj = np.zeros((numb(Pmaxi,Jmaxi), numb(Pmaxi,Jmaxi)))
for irow in np.arange(1, numb(Pmaxi,Jmaxi)+1,1):
idx_of_row, = np.where(rows_4dim[0,:] == irow)
Cpj_ = Cpj_4dim[:, idx_of_row]
Cpj[irow-1,:] = np.sum(Cpj_,axis = 1, initial = 0)
# Create output
Cpj_dst = selfh5_out.create_dataset("/Caapj/Ciipj", data = Cpj)
Cpj_dst.attrs['Pmaxi'] = Pmaxi
Cpj_dst.attrs['Jmaxi'] = Jmaxi
Cpj_dst.attrs['kperp'] = selfh5['/Caapj/Ciipjpjnn'].attrs['kperp']
selfh5_out.create_dataset("/files/inputs", data = selfh5['/files/inputs'])
# close file
selfh5_out.close()
selfh5.close()
return
def gkcoulomb_self(cwd, in_ = 'self.jEnnp.h5', out_ = 'self.h5'):
# construct gkcoulomb operator for ii and ee
print('Create GK Coulomb from ' + cwd)
# Define h5 files
selfcolls_file = os.path.join( cwd, in_)
selfcolls_file_out = os.path.join( cwd, out_)
# Open file
selfh5 = h5.File(selfcolls_file, 'r')
selfh5_out = h5.File(selfcolls_file_out, 'w')
# Ion-ion
# get dimension
Pmaxi = selfh5['/Caapj/Ciipjpjnn'].attrs['Pmaxi']
Jmaxi = selfh5['/Caapj/Ciipjpjnn'].attrs['Jmaxi']
def numb(pp,jj):
lbari = (Jmaxi +1)*pp + jj +1
return lbari
# Get 4 dim rows
rows_4dim= selfh5['/Caapj/rows_i']
# Get Cippj
Cpj_4dim=selfh5['/Caapj/Ciipjpjnn']
Cpj = np.zeros((numb(Pmaxi,Jmaxi), numb(Pmaxi,Jmaxi)))
for irow in np.arange(1, numb(Pmaxi,Jmaxi)+1,1):
idx_of_row, = np.where(rows_4dim[0,:] == irow)
Cpj_ = Cpj_4dim[:, idx_of_row]
Cpj[irow-1,:] = np.sum(Cpj_,axis = 1, initial = 0)
# Create output
Cpj_dst = selfh5_out.create_dataset("/Caapj/Ciipj", data = Cpj)
Cpj_dst.attrs['Pmaxi'] = Pmaxi
Cpj_dst.attrs['Jmaxi'] = Jmaxi
Cpj_dst.attrs['kperp'] = selfh5['/Caapj/Ciipjpjnn'].attrs['kperp']
selfh5_out.create_dataset("/files/inputs", data = selfh5['/files/inputs'])
#Electron-Electron
#get dimension
Pmaxe = selfh5['/Caapj/Ceepjpjnn'].attrs['Pmaxe']
Jmaxe = selfh5['/Caapj/Ceepjpjnn'].attrs['Jmaxe']
def numb(pp,jj):
lbari = (Jmaxe +1)*pp + jj +1
return lbari
# Get 4 dim rows
rows_4dim= selfh5['/Caapj/rows_e']
# Get Cippj
Cpj_4dim=selfh5['/Caapj/Ceepjpjnn']
#Cpj_4dim
Cpj = np.zeros((numb(Pmaxe,Jmaxe), numb(Pmaxe,Jmaxe)))
for irow in np.arange(1, numb(Pmaxe,Jmaxe)+1,1):
idx_of_row, = np.where(rows_4dim[0,:] == irow)
Cpj_ = Cpj_4dim[:, idx_of_row]
Cpj[irow-1,:] = np.sum(Cpj_,axis = 1, initial = 0)
#Create output
Cpj_dst = selfh5_out.create_dataset("/Caapj/Ceepj", data = Cpj)
#Cpj_dst = selfh5_out.create_dataset("/Caapj/Ceepj", data = selfeeh5['/Caapj/Ceepj'])
Cpj_dst.attrs['Pmaxe'] = Pmaxe
Cpj_dst.attrs['Jmaxe'] = Jmaxe
Cpj_dst.attrs['kperp'] = selfh5['/Caapj/Ceepjpjnn'].attrs['kperp']
# selfh5_out.create_dataset("/files/fort.90", data = selfh5['/files/fort.90'])
# close file
selfh5_out.close()
selfh5.close()
def gkcoulomb_ee(cwd, in_ = 'self.jEnnp.h5', out_ = 'self.h5'):
# construct gkcoulomb operator for ee
print('Create GK Coulomb from ' + cwd)
# Define h5 files
selfcolls_file = os.path.join( cwd, out_)
selfcolls_file_out = os.path.join( cwd, in_)
# Open file
selfh5 = h5.File(selfcolls_file, 'r')
selfh5_out = h5.File(selfcolls_file_out, 'w')
#Electron-Electron
#get dimension
Pmaxe = selfh5['/Caapj/Ceepjpjnn'].attrs['Pmaxe']
Jmaxe = selfh5['/Caapj/Ceepjpjnn'].attrs['Jmaxe']
def numb(pp,jj):
lbari = (Jmaxe +1)*pp + jj +1
return lbari
# Get 4 dim rows
rows_4dim= selfh5['/Caapj/rows_e']
# Get Cippj
Cpj_4dim=selfh5['/Caapj/Ceepjpjnn']
#Cpj_4dim
Cpj = np.zeros((numb(Pmaxe,Jmaxe), numb(Pmaxe,Jmaxe)))
for irow in np.arange(1, numb(Pmaxe,Jmaxe)+1,1):
idx_of_row, = np.where(rows_4dim[0,:] == irow)
Cpj_ = Cpj_4dim[:, idx_of_row]
Cpj[irow-1,:] = np.sum(Cpj_,axis = 1, initial = 0)
#Create output
Cpj_dst = selfh5_out.create_dataset("/Caapj/Ceepj", data = Cpj)
#Cpj_dst = selfh5_out.create_dataset("/Caapj/Ceepj", data = selfeeh5['/Caapj/Ceepj'])
Cpj_dst.attrs['Pmaxe'] = Pmaxe
Cpj_dst.attrs['Jmaxe'] = Jmaxe
Cpj_dst.attrs['kperp'] = selfh5['/Caapj/Ceepjpjnn'].attrs['kperp']
selfh5_out.create_dataset("/files/inputs", data = selfh5['/files/inputs'])
# close file
selfh5_out.close()
selfh5.close()
return
def gkcoulomb_ei(cwd, in_ = 'ei.jEnnp.h5', out_ = 'ei.h5'):
# construct gkcoulomb operator for ee
print('Create GK Coulomb from ' + cwd)
# Define h5 files input
eicolls_file = os.path.join(cwd, in_)
print( eicolls_file)
# Defines new h5 files
eicolls_file_out = os.path.join(cwd, out_)
# Test component #####
# Open file
eih5 = h5.File(eicolls_file, 'r')
eih5_out = h5.File(eicolls_file_out, 'w')
# get dimension
Pmaxe = eih5['/Ceipj/CeipjTpjnn'].attrs['Pmaxi']
Jmaxe = eih5['/Ceipj/CeipjTpjnn'].attrs['Jmaxi']
def numb(pp,jj):
lbar = (Jmaxe +1)*pp + jj +1
return lbar
# Get 4 dim rows
rows_4dim= eih5['/Ceipj/rows_eT']
# Get Cippj
Cpj_4dim= eih5['/Ceipj/CeipjTpjnn']
Cpj = np.zeros((numb(Pmaxe,Jmaxe), numb(Pmaxe,Jmaxe)))
for irow in np.arange(1, numb(Pmaxe,Jmaxe)+1,1):
idx_of_row, = np.where(rows_4dim[0,:] == irow)
Cpj_ = Cpj_4dim[:, idx_of_row]
Cpj[irow-1,:] = np.sum(Cpj_,axis = 1, initial = 0)
# Cpj = Cpj.transpose()
Cpj_dst = eih5_out.create_dataset("/Ceipj/CeipjT", data = Cpj)
Cpj_dst.attrs['Pmaxe'] = Pmaxe
Cpj_dst.attrs['Jmaxe'] = Jmaxe
Cpj_dst.attrs['kperp'] = eih5['/Ceipj/CeipjTpjnn'].attrs['kperp']
### Field component #####
# get dimension
Pmaxe = eih5['/Ceipj/CeipjFpjnn'].attrs['Pmaxe']
Jmaxe = eih5['/Ceipj/CeipjFpjnn'].attrs['Jmaxe']
def numb(pp,jj):
lbar = (Jmaxe +1)*pp + jj +1
return lbar
# Get 4 dim rows
rows_4dim= eih5['/Ceipj/rows_eF']
# Get Cippj
Cpj_4dim= eih5['/Ceipj/CeipjFpjnn']
Cpj = np.zeros((numb(Pmaxe, Jmaxe), numb(Pmaxe,Jmaxe)))
for irow in np.arange(1, numb(Pmaxe,Jmaxe)+1,1):
idx_of_row, = np.where(rows_4dim[0,:] == irow)
Cpj_ = Cpj_4dim[:, idx_of_row]
Cpj[irow-1,:] = np.sum(Cpj_,axis = 1, initial = 0)
Cpj = Cpj.transpose() # Necessary to match the DK Coulomb !!
Cpj_dst = eih5_out.create_dataset("/Ceipj/CeipjF", data = Cpj)
Cpj_dst.attrs['Pmaxe'] = Pmaxe
Cpj_dst.attrs['Jmaxe'] = Jmaxe
Cpj_dst.attrs['kperp'] = eih5['/Ceipj/CeipjFpjnn'].attrs['kperp']
eih5_out.create_dataset("/files/inputs", data = eih5['/files/inputs'])
# close file
eih5.close()
eih5_out.close()
return
def gkcoulomb_ie( cwd, in_ = 'ie.jEnnp.h5', out_ = 'ie.h5'):
# construct gkcoulomb operator for ee
print('Create GK Coulomb from ' + cwd)
# Define h5 files
iecolls_file = os.path.join(cwd,in_)
iecolls_file_out = os.path.join(cwd,out_)
ieh5 = h5.File(iecolls_file, 'r')
ieh5_out = h5.File(iecolls_file_out, 'w')
### Test component #####
# get dimension
Pmaxi = ieh5['/Ciepj/CiepjTpjnn'].attrs['Pmaxi']
Jmaxi = ieh5['/Ciepj/CiepjTpjnn'].attrs['Jmaxi']
def numb(pp,jj):
lbari = (Jmaxi +1)*pp + jj +1
return lbari
# Get 4 dim rows
rows_4dim= ieh5['/Ciepj/rows_iT']
# Get Cippj
Cpj_4dim= ieh5['/Ciepj/CiepjTpjnn']
Cpj = np.zeros((numb(Pmaxi,Jmaxi), numb(Pmaxi,Jmaxi)))
for irow in np.arange(1, numb(Pmaxi,Jmaxi)+1,1):
idx_of_row, = np.where(rows_4dim[0,:] == irow)
Cpj_ = Cpj_4dim[:, idx_of_row]
Cpj[irow-1,:] = np.sum(Cpj_,axis = 1, initial = 0)
# Cpj = Cpj.transpose()
Cpj_dst = ieh5_out.create_dataset("/Ciepj/CiepjT", data = Cpj)
Cpj_dst.attrs['Pmaxi'] = Pmaxi
Cpj_dst.attrs['Jmaxi'] = Jmaxi
Cpj_dst.attrs['kperp'] = ieh5['/Ciepj/CiepjTpjnn'].attrs['kperp']
### Field component #####
# get dimension
Pmaxi = ieh5['/Ciepj/CiepjFpjnn'].attrs['Pmaxi']
Jmaxi = ieh5['/Ciepj/CiepjFpjnn'].attrs['Jmaxi']
def numb(pp,jj):
lbari = (Jmaxi +1)*pp + jj +1
return lbari
# Get 4 dim rows
rows_4dim= ieh5['/Ciepj/rows_iF']
# Get Cippj
Cpj_4dim= ieh5['/Ciepj/CiepjFpjnn']
Cpj = np.zeros((numb(Pmaxi,Jmaxi), numb(Pmaxi,Jmaxi)))
for irow in np.arange(1, numb(Pmaxi,Jmaxi)+1,1):
idx_of_row, = np.where(rows_4dim[0,:] == irow)
Cpj_ = Cpj_4dim[:, idx_of_row]
Cpj[irow-1,:] = np.sum(Cpj_,axis = 1, initial = 0)
Cpj = Cpj.transpose() # Necessary to match the DK Coulomb !!
Cpj_dst = ieh5_out.create_dataset("/Ciepj/CiepjF", data = Cpj)
Cpj_dst.attrs['Pmaxi'] = Pmaxi
Cpj_dst.attrs['Jmaxi'] = Jmaxi
Cpj_dst.attrs['kperp'] = ieh5['/Ciepj/CiepjFpjnn'].attrs['kperp']
ieh5_out.create_dataset("/files/inputs", data = ieh5['/files/inputs'])
# close file
ieh5.close()
ieh5_out.close()
return
def add_test_sugama(coll_type, in__ , add__, out__):
# read file
inh5 = h5.File(in__ , 'r')
addh5 = h5.File(add__ , 'r')
# create output file
outh5 = h5.File( out__, 'w')
if coll_type == 'eiT':
print('coll type = eiT')
# copy group (test and field)
inh5.copy( inh5['/Ceipj'], outh5, '/Ceipj')
# update values
# outh5['/Ceipj/CeipjT'][...] = inh5['/Ceipj/CeipjT'][...] + addh5['/Ceipj/CeipjT'][...]
outh5['/Ceipj/CeipjT'][...] = addh5['/Ceipj/CeipjT'][...]
if coll_type == 'ieT':
print('coll type = ieT')
# copy group (test and field)
inh5.copy( inh5['/Ciepj'], outh5, '/Ciepj')
# update values
# outh5['/Ciepj/CiepjT'][...] = inh5['/Ciepj/CiepjT'][...] + addh5['/Ciepj/CiepjT'][...]
outh5['/Ciepj/CiepjT'][...] = addh5['/Ciepj/CiepjT'][...]
if coll_type == 'self':
print('coll_type = self')
# copy group (test and field)
inh5.copy( inh5['/Caapj'], outh5, '/Caapj')
# update values (add the test component to the Caa collision operator without it !!!)
outh5['/Caapj/Ceepj'][...] = inh5['/Caapj/Ceepj'][...] + addh5['/Caapj/Ceepj'][...]
outh5['/Caapj/Ciipj'][...] = inh5['/Caapj/Ciipj'][...] + addh5['/Caapj/Ciipj'][...]
# copy file
inh5.copy( inh5['/files'], outh5, '/files')
# close files
inh5.close()
addh5.close()
outh5.close()
return
def add_is_to_os(coll_type, os_, corr_, is_):
# add improved sugama (i.e. the correction term) to OS sugama collision operator
# read and open files
# read file original sugama collision operator and correction term
osh5 = h5.File( os_ , 'r')
corrh5 = h5.File( corr_ , 'r')
# create output file containing the IS collision operator
ish5 = h5.File(is_ , 'w')
if coll_type == 'ei':
# copy group (test and field)
osh5.copy( osh5['/Ceipj'] , ish5, '/Ceipj')
# add correction term to os operator
ish5['/Ceipj/CeipjT'][...] = osh5['/Ceipj/CeipjT'][...] + corrh5['/Ceipj/CeipjT'][...]
ish5['/Ceipj/CeipjF'][...] = osh5['/Ceipj/CeipjF'][...] + corrh5['/Ceipj/CeipjF'][...]
if coll_type == 'ie':
# copy group (test and field)
osh5.copy( osh5['/Ciepj'] , ish5, '/Ciepj')
# add correction term to os operator
ish5['/Ciepj/CiepjT'][...] = osh5['/Ciepj/CiepjT'][...] + corrh5['/Ciepj/CiepjT'][...]
ish5['/Ciepj/CiepjF'][...] = osh5['/Ciepj/CiepjF'][...] + corrh5['/Ciepj/CiepjF'][...]
if coll_type == 'self':
# copy group (test and field)
osh5.copy( osh5['/Caapj'] , ish5, '/Caapj')
# add correction term to os operator
ish5['/Caapj/Ciipj'][...] = osh5['/Caapj/Ciipj'][...] + corrh5['/Caapj/Ciipj'][...]
ish5['/Caapj/Ceepj'][...] = osh5['/Caapj/Ceepj'][...] + corrh5['/Caapj/Ceepj'][...]
# copy file
osh5.copy( osh5['/files'], ish5, '/files')
# close files
osh5.close()
corrh5.close()
ish5.close()
return
def gen_gtdf(coll_type, gkcoll_, dkcoll_, outcoll_):
# generate GTDF model (i.e. GK test and DK field) from
# What is does this script is to overwrite the gk field part of the dk field
# read file
gkh5 = h5.File( gkcoll_, 'r')
dkh5 = h5.File( dkcoll_, 'r')
# create GTDF file
outh5 = h5.File(outcoll_, 'w')
# ei colls
if coll_type == 'ei':
print(' coll type = ei')
# copy gk test and field
gkh5.copy( gkh5['/Ceipj'], outh5, '/Ceipj')
# overite gk field with dk field
outh5['/Ceipj/CeipjF'][...] = dkh5['/Ceipj/CeipjF'][...]
# ie colls
if coll_type == 'ie':
print('coll type = ie')
# copy gk test and field
gkh5.copy( gkh5['/Ciepj'], outh5, '/Ciepj')
# overite gk field with dk field
outh5['/Ciepj/CiepjF'][...] = dkh5['/Ciepj/CiepjF'][...]
if coll_type == 'self':
print( 'coll type = self')
gkh5.copy( gkh5['/Caapj'], outh5, '/Caapj')
# electron-electron
outh5['/Caapj/Ceepj'][...] = outh5['/Caapj/Ceepj'][...] + dkh5['/Caapj/Ceepj'][...]
# # ion-ion
outh5['/Caapj/Ciipj'][...] = outh5['/Caapj/Ciipj'][...] + dkh5['/Caapj/Ciipj'][...]
# copy file
gkh5.copy( gkh5['/files'], outh5, '/files')
# read file
gkh5.close()
dkh5.close()
outh5.close()
return
def gbms_dkcollision_input(cwd, eicolls_filename, iecolls_filename, eecolls_filename, iicolls_filename, outcolls_filename, Pmax,Jmax):
# Define size of matrices (all matrices are assumed to have the same size)
Pmaxi = Pmax
Jmaxi = Jmax
Pmaxe = Pmax
Jmaxe = Jmax
eicolls_file = os.path.join(cwd, eicolls_filename)
iecolls_file = os.path.join(cwd, iecolls_filename)
eecolls_file = os.path.join( cwd, eecolls_filename)
iicolls_file = os.path.join( cwd, iicolls_filename)
# Define output filename
outputfilename = os.path.join( cwd, outcolls_filename)
# Open the h5 files in read mode
eih5 = h5.File(eicolls_file, 'r')
ieh5 = h5.File(iecolls_file, 'r')
eeh5 = h5.File(eecolls_file, 'r')
iih5 = h5.File(iicolls_file, 'r')
#selfh5 = h5.File(selfcolls_file, 'r')
#selfeeh5 = h5.File( selfeecolls_file, 'r')
# Create ouput file
outh5 = h5.File(outputfilename, 'w')
# Flush ei/ie/ee/ii collisions to output h5 file
dst_CeipjF = outh5.create_dataset("/00000/Ceipj/CeipjF", data = eih5['/Ceipj/CeipjF'])
dst_CeipjF.attrs['Pmaxe'] = Pmaxe
dst_CeipjF.attrs['Jmaxe'] = Jmaxe
dst_CeipjT = outh5.create_dataset("/00000/Ceipj/CeipjT", data = eih5['/Ceipj/CeipjT'])
dst_CeipjT.attrs['Jmaxe'] = Jmaxe
dst_CeipjT.attrs['Pmaxe'] = Pmaxe
# outh5.create_dataset("/00000/Ceipj/fort.90", data = eih5['/files/fort.90'])
dst_CiepjF = outh5.create_dataset("/00000/Ciepj/CiepjF", data = ieh5['/Ciepj/CiepjF'])
dst_CiepjF.attrs['Pmaxi'] = Pmaxi
dst_CiepjF.attrs['Jmaxi'] = Jmaxi
dst_CiepjT = outh5.create_dataset("/00000/Ciepj/CiepjT", data = ieh5['/Ciepj/CiepjT'])
dst_CiepjT.attrs['Pmaxi'] = Pmaxi
dst_CiepjT.attrs['Jmaxi'] = Jmaxi
# outh5.create_dataset("/00000/Ciepj/fort.90", data = ieh5['/files/fort.90'])
# helaz syntax
dst_Cii = outh5.create_dataset("/00000/Caapj/Ciipj", data = iih5['/Caapj/Ciipj'])
dst_Cee= outh5.create_dataset("/00000/Caapj/Ceepj", data = eeh5['/Caapj/Ceepj'])
# gbms syntax
# dst_Cii = outh5.create_dataset("/00000/Ciipj", data = iih5['/Caapj/Ciipj'])
# dst_Cee= outh5.create_dataset("/00000/Ceepj", data = eeh5['/Caapj/Ceepj'])
dst_Cii.attrs['Pmaxi'] = Pmaxi
dst_Cii.attrs['Jmaxi'] = Jmaxi
# outh5.create_dataset("/00000/Cii/fort.90", data = iih5['/files/fort.90'])
dst_Cee.attrs['Pmaxe'] = Pmaxe
dst_Cee.attrs['Jmaxe'] = Jmaxe
# outh5.create_dataset("/00000/Cee/fort.90", data = eeh5['/files/fort.90'])
outh5.create_dataset("/dims_i", data = [Pmaxi, Jmaxi])
outh5.create_dataset("/dims_e", data = [Pmaxe, Jmaxe])
# Set to 0 for DK collision operators
outh5.create_dataset("/coordkperp" , data = [0])
# Close file
outh5.close()
print('Created ' + outputfilename)
return
def gbms_gkcollision_input(cwd, kperp_file, outcolls_filename, Pmax, Jmax):
# Define size of matrices (all matrices are assumed to have the same size)
Pmaxi = Pmax
Jmaxi = Jmax
Pmaxe = Pmax
Jmaxe = Jmax
# Get kperp coord
coordkperp = np.loadtxt(os.path.join(cwd, kperp_file))
print(coordkperp)
outh5 = h5.File(os.path.join( cwd, outcolls_filename), 'w')
outh5.create_dataset('/coordkperp', data = coordkperp)
outh5.create_dataset('/Nkperp', data= np.alen(coordkperp))
outh5.create_dataset('/dims_i', data = [Pmaxi, Jmaxi,np.alen(coordkperp)] )
outh5.create_dataset('/dims_e', data = [Pmaxe, Jmaxe,np.alen(coordkperp)])
# gather
for ikperp, kperp in enumerate(coordkperp):
# files path
eicolls_file = os.path.join( cwd, 'ei.' + "{0:05d}".format(ikperp+1) + '.h5' )
iecolls_file = os.path.join( cwd, 'ie.' + "{0:05d}".format(ikperp+1) + '.h5')
selfcolls_file = os.path.join( cwd, 'self.' + "{0:05d}".format(ikperp+1) + '.h5')
print(eicolls_file)
print(iecolls_file)
print(selfcolls_file)
# Open the h5 files in read mode
eih5 = h5.File(eicolls_file, 'r')
ieh5 = h5.File(iecolls_file, 'r')
selfh5 = h5.File(selfcolls_file, 'r')
# Flush Cabpj
# ei
outh5.create_dataset( "{0:05d}".format(ikperp+1) + "/Ceipj/CeipjF/", data = eih5['/Ceipj/CeipjF'])
outh5.create_dataset( "{0:05d}".format(ikperp+1) + "/Ceipj/CeipjT/", data = eih5['/Ceipj/CeipjT'])
outh5.create_dataset( "{0:05d}".format(ikperp+1) + "/Ceipj/inputs", data = eih5['/files/inputs'])
# ie
outh5.create_dataset( "{0:05d}".format(ikperp+1) + "/Ciepj/CiepjF/", data = ieh5['/Ciepj/CiepjF'])
outh5.create_dataset( "{0:05d}".format(ikperp+1) + "/Ciepj/CiepjT/", data = ieh5['/Ciepj/CiepjT'])
outh5.create_dataset( "{0:05d}".format(ikperp+1) + "/Ciepj/inputs", data = ieh5['/files/inputs'])
# ee
outh5.create_dataset( "{0:05d}".format(ikperp+1) + "/Caapj/Ceepj", data = selfh5['/Caapj/Ceepj'])
# ii
outh5.create_dataset( "{0:05d}".format(ikperp+1) + "/Caapj/Ciipj", data = selfh5['/Caapj/Ciipj'])
outh5.create_dataset( "{0:05d}".format(ikperp+1) + "/Caapj/inputs", data = selfh5['/files/inputs'])
eih5.close()
ieh5.close()
selfh5.close()
return
def gen_kperp_grid( Nz, Nkx, kymin, shear, epsilon, out_):
# generate kperp grid where to evaluate the gk collision operators
print('Generates kperp grid...')
# define z-grid
Nkxtot = Nkx
zarray_ = np.linspace( -np.pi, np.pi , Nz, endpoint=False)
# idx = np.where( zarray_ >=0 )
#zarray = zarray_[ idx]
zarray = zarray_
kxarray = np.zeros( Nkxtot)
deltakx = 2 * np.pi * shear* kymin
print('List of kx-mode: ')
for ikx_ in range(Nkx):
kxarray[ ikx_] = deltakx * ikx_
print( ikx_)
print('kx = ' + str(kxarray[ ikx_]))
# Define metric elements
gxy = np.zeros( zarray.size )
gyy = np.zeros( zarray.size )
for iz_ , val_ in enumerate(zarray):
gxy[ iz_ ] = shear * val_
gyy[ iz_ ] = 1 + shear * shear * val_ * val_
# define kperp grid
kperp=np.zeros((zarray.size, kxarray.size))
print('List of kperp values: ')
for ikx_, kx_ in enumerate( kxarray):
for iz_, z_ in enumerate( zarray):
kperp[iz_ , ikx_ ] = np.sqrt( kx_ * kx_ + 2 * gxy[ iz_ ] *kx_ * kymin + kymin * kymin * gyy[ iz_ ]) *( 1 + np.cos( z_) * epsilon)
print('@z = '+ str( z_) + ', @ikx (kx)= ', str(ikx_)+ ' , kperp =' + str(kperp[iz_ , ikx_ ]) )
# Flush out paramscan
cwd = os.getcwd()
with open( os.path.join(cwd, out_) ,'w') as fh:
for ikx_, kx_ in enumerate( kxarray):
for iz_, z_ in enumerate( zarray):
if not(z_ < 0 and ikx_ == 0):
fh.write( "%s \n" % kperp[iz_ , ikx_ ] )
return

Event Timeline