diff --git a/src/karl/CurrentLogger.cpp b/src/karl/CurrentLogger.cpp index 72e6143..929c1cd 100644 --- a/src/karl/CurrentLogger.cpp +++ b/src/karl/CurrentLogger.cpp @@ -14,19 +14,19 @@ CurrentLogger::CurrentLogger( std::string output_filename): Particle_Logger_Base(this_species), N_pos_r( - num_planes_z, z_min, z_max, + num_planes_z-1, z_min, z_max, // -1 through |[0,n]| = n+1 num_planes_r, r_max, energy_decade_min, energy_decade_max ), N_neg_r( - num_planes_z, z_min, z_max, + num_planes_z-1, z_min, z_max, // -1 through |[0,n]| = n+1 num_planes_r, r_max, energy_decade_min, energy_decade_max ), N_pos_z( - num_planes_z, z_min, z_max, + num_planes_z-1, z_min, z_max, // -1 through |[0,n]| = n+1 num_planes_r, r_max, energy_decade_min, energy_decade_max ), N_neg_z( - num_planes_z, z_min, z_max, + num_planes_z-1, z_min, z_max, // -1 through |[0,n]| = n+1 num_planes_r, r_max, energy_decade_min, energy_decade_max ), output_filename_(output_filename) diff --git a/src/tools/analysis_jkellerer/currents/current_to_h5.py b/src/tools/analysis_jkellerer/currents/current_to_h5.py new file mode 100644 index 0000000..f5fcc16 --- /dev/null +++ b/src/tools/analysis_jkellerer/currents/current_to_h5.py @@ -0,0 +1,55 @@ +import numpy as np +import h5py as h5py +import os +import sys +import matplotlib +import matplotlib.pyplot as plt + +from functions.calculate_currents_from_karl import * +from functions.calculate_density_from_karl import * +import functions.plot_standards as pst + + +def currentToH5(filename_densities, filename_currents, filename_output): + + keys = ["/e-", "/T+", "/T2+", "/T3+"] + + print("Get Current: e-") + total_current_e = particleCurrentZ(filename_currents, filename_densities, keys[0]) + current_e = np.sum(total_current_e,2) + + print("Get Current: T+") + total_current_T = particleCurrentZ(filename_currents, filename_densities, keys[1]) + current_T = np.sum(total_current_T,2) + + print("Get Current: T2+") + total_current_T2 = particleCurrentZ(filename_currents, filename_densities, keys[2]) + current_T2 = np.sum(total_current_T2,2) + + print("Get Current: T3+") + total_current_T3 = particleCurrentZ(filename_currents, filename_densities, keys[3]) + current_T3 = np.sum(total_current_T3,2) + + f = h5py.File(filename_output, 'a') + + key_electrons = "Current/electrons" + if key_electrons in f: + del f[key_electrons] + f.create_dataset(key_electrons, data=current_e, dtype=float) + + key_T = "Current/T+" + if key_T in f: + del f[key_T] + f.create_dataset(key_T, data=current_T, dtype=float) + + key_T2 = "Current/T2+" + if key_T2 in f: + del f[key_T2] + f.create_dataset(key_T2, data=current_T2, dtype=float) + + key_T3 = "Current/T3+" + if key_T3 in f: + del f[key_T3] + f.create_dataset(key_T3, data=current_T3, dtype=float) + + f.close() diff --git a/src/tools/analysis_jkellerer/densities/density_to_h5.py b/src/tools/analysis_jkellerer/densities/density_to_h5.py index 1798b40..dbd0896 100644 --- a/src/tools/analysis_jkellerer/densities/density_to_h5.py +++ b/src/tools/analysis_jkellerer/densities/density_to_h5.py @@ -12,11 +12,6 @@ import functions.plot_standards as pst def densityToH5(filename, filename_output): keys = ["/Populations/e-/e-", "/Populations/T+/T+", "/Populations/T2+/T2+", "/Populations/T3+/T3+"] - zmins = getZBinsMin(filename, keys[0]) - zmaxs = getZBinsMax(filename, keys[0]) - Emins = getEBinsMin(filename, keys[0]) - Emaxs = getEBinsMax(filename, keys[0]) - print("Get Density: e-") total_density_e = getDensities(filename, keys[0]) density_e = np.sum(total_density_e,3)[:,:,0] @@ -33,10 +28,22 @@ def densityToH5(filename, filename_output): total_density_T3 = getDensities(filename, keys[3]) density_T3 = np.sum(total_density_T3,3)[:,:,0] - total_density = np.array((density_T + density_T2 + density_T3 -density_e)/1E6) + total_density = np.array((density_T + density_T2 + density_T3 -density_e)/1E6) - f = h5py.File(filename_output, 'w') + f = h5py.File(filename_output, 'a') key_density = "Density/total" + if key_density in f: + del f[key_density] + f.create_dataset(key_density, data=np.transpose(total_density), dtype=float) + + key_electrons = "Density/electrons" + if key_electrons in f: + del f[key_electrons] + f.create_dataset(key_electrons, data=np.transpose(density_e/1E6), dtype=float) + + key_ions = "Density/ions" + if key_ions in f: + del f[key_ions] + f.create_dataset(key_ions, data=np.transpose((density_T + density_T2 + density_T3)/1E6), dtype=float) - f.create_dataset(key_density, data=total_density, dtype=float) f.close() diff --git a/src/tools/analysis_jkellerer/poissonSolver/config/params.xml b/src/tools/analysis_jkellerer/poissonSolver/config/params.xml index ed7ef31..a85d899 100644 --- a/src/tools/analysis_jkellerer/poissonSolver/config/params.xml +++ b/src/tools/analysis_jkellerer/poissonSolver/config/params.xml @@ -2,13 +2,13 @@ - 18 + 1300 4.5 - 5 + 10 16 @@ -24,7 +24,7 @@ 1 - 0.003333333333333333 + 0.0 1 @@ -35,19 +35,31 @@ - 1000 - 0.0001 + 10000 + 1E-6 - ./output/potential.dat + + ./output/output.h5 + /Potential + potential + - ./output/density.dat + + ./output/output.h5 + /Density + density + - ./output/efield_z.dat + + ./output/output.h5 + /Efield + efield + diff --git a/src/tools/analysis_jkellerer/poissonSolver/include/Fields.h b/src/tools/analysis_jkellerer/poissonSolver/include/Fields.h index 2b3b297..160b038 100644 --- a/src/tools/analysis_jkellerer/poissonSolver/include/Fields.h +++ b/src/tools/analysis_jkellerer/poissonSolver/include/Fields.h @@ -36,29 +36,7 @@ class ElectricField { blitz::Array data_z_; }; -/* -Density interpolateOnGrid(Density& denstity); - -class Potential { - public: - Potential(blitz::Array& data); - Potential(int nr, int nz); - - blitz::Array data() const; - - private: - blitz::Array data_; -}; - -class ElectricField { - -}; - -ElectricField interpolateOnGrid( - ElectricField& electric_field, - double dr_new, - double dz_new); -*/ +ElectricField interpolateOnGrid(ElectricField& electric_field); }; diff --git a/src/tools/analysis_jkellerer/poissonSolver/include/IO.h b/src/tools/analysis_jkellerer/poissonSolver/include/IO.h index 60c2ec2..46924ba 100644 --- a/src/tools/analysis_jkellerer/poissonSolver/include/IO.h +++ b/src/tools/analysis_jkellerer/poissonSolver/include/IO.h @@ -5,7 +5,7 @@ #include "Fields.h" #include "Boundary.h" #include "PoissonSolver.h" - +#include namespace IO { Fields::Density denstiy(const Parameter& parameter); Boundary rearwallBoundary(const Parameter& parameter); @@ -20,6 +20,14 @@ namespace IO { void save(const Fields::Potential& potential, const Parameter& parameter); void save(const Fields::Density& density, const Parameter& parameter); void save(const Fields::ElectricField& density, const Parameter& parameter); + + void save( + const std::vector>& data, + std::string filename, + std::string group, + std::string path); + + std::vector> convert(const blitz::Array& data); }; #endif /* IO_H */ diff --git a/src/tools/analysis_jkellerer/poissonSolver/src/Fields.cpp b/src/tools/analysis_jkellerer/poissonSolver/src/Fields.cpp index 301de18..1cc353d 100644 --- a/src/tools/analysis_jkellerer/poissonSolver/src/Fields.cpp +++ b/src/tools/analysis_jkellerer/poissonSolver/src/Fields.cpp @@ -72,5 +72,27 @@ namespace Fields { } + ElectricField interpolateOnGrid(ElectricField& electric_field) + { + const blitz::TinyVector extent = electric_field.data_r_.extent(); + const blitz::TinyVector interpol_extent = + extent - blitz::TinyVector(0,1); + + blitz::Array interpolated_r(interpol_extent); + blitz::Array interpolated_z(interpol_extent); + interpolated_r = 0.; + interpolated_z = 0.; + + + for(int i = 0; i < interpol_extent(0); ++i){ + for(int j = 0; j < interpol_extent(1); ++j){ + interpolated_r(i,j) = + (electric_field.data_r_(i,j+1) + electric_field.data_r_(i,j))/2; + interpolated_z(i,j) = + (electric_field.data_z_(i+1,j) + electric_field.data_z_(i,j))/2; + } + } + return ElectricField(interpolated_r, interpolated_z); + } } \ No newline at end of file diff --git a/src/tools/analysis_jkellerer/poissonSolver/src/IO.cpp b/src/tools/analysis_jkellerer/poissonSolver/src/IO.cpp index 6e2b194..5d7a3a2 100644 --- a/src/tools/analysis_jkellerer/poissonSolver/src/IO.cpp +++ b/src/tools/analysis_jkellerer/poissonSolver/src/IO.cpp @@ -128,48 +128,99 @@ void save(const Fields::Potential& potential, const Parameter& parameter) { std::string filename = std::string( parameter.document.first_element_by_path( - "Parameters/Output/Potential").child_value("Filename")); - std::ofstream outdata; - outdata.open(filename); - for(int i = 0; i < potential.data_.extent(0); ++i){ - for(int j = 0; j>& data, + std::string filename, + std::string group, + std::string path) +{ + HighFive::File file( + filename, + HighFive::File::ReadWrite | HighFive::File::Create); + + if(!file.exist(group)){ + file.createGroup(group); + } + + if(file.exist(path)){ + HighFive::DataSet dataset = file.getDataSet(path); + dataset.write(data); + } else{ + HighFive::DataSet dataset = + file.createDataSet(path, HighFive::DataSpace::From(data)); + dataset.write(data); + } +} + +std::vector> convert( + const blitz::Array& data) +{ + const blitz::TinyVector start = data.lbound(); + const blitz::TinyVector end = data.ubound(); + + std::vector> data_v; + + for(int i = start(0); i<=end(0); ++i){ + std::vector xs; + for(int j = start(1); j<=end(1); ++j){ + xs.push_back(data(i,j)); + } + data_v.push_back(xs); + } + + return data_v; +} }; \ No newline at end of file diff --git a/src/tools/analysis_jkellerer/poissonSolver/src/PoissonSolver.cpp b/src/tools/analysis_jkellerer/poissonSolver/src/PoissonSolver.cpp index 545dd1d..4229538 100644 --- a/src/tools/analysis_jkellerer/poissonSolver/src/PoissonSolver.cpp +++ b/src/tools/analysis_jkellerer/poissonSolver/src/PoissonSolver.cpp @@ -75,12 +75,12 @@ void PoissonSolver::iterationPotential( } // apply boundary condition left - if(rearwall.type == BoundaryType::pec){ + if(rearwall.type == pec){ for(int i = 0; i