Page MenuHomec4science

gkcoulomb.py
No OneTemporary

File Metadata

Created
Tue, Feb 25, 03:43

gkcoulomb.py

#!/usr/bin/env python
import numpy as np
import os
import sys
import h5py as h5
# Define directories
cwd = os.getcwd()
# Define h5 files
eicolls_file = os.path.join(cwd, 'ei.h5')
iecolls_file = os.path.join(cwd,'ie.h5')
selfcolls_file = os.path.join( cwd, 'self.h5')
# Defines new h5 files
eicolls_file_out = os.path.join(cwd, 'ei.0.h5')
iecolls_file_out = os.path.join(cwd,'ie.0.h5')
selfcolls_file_out = os.path.join( cwd, 'self.0.h5')
############################################################
# Self 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_4dim
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/Ceepjpjnn'].attrs['kperp']
# 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.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.f90'])
# close file
selfh5_out.close()
selfh5.close()
############################################################
# Ion-elctron collision
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_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_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/fort.90", data = ieh5['/files/fort.f90'])
# close file
ieh5.close()
ieh5_out.close()
############################################################
# Electron-ion collision
### 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_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_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/fort.90", data = eih5['/files/fort.f90'])
# close file
eih5.close()
eih5_out.close()

Event Timeline