Correct current logger bin numbers
This commit is contained in:
@@ -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()
|
||||
@@ -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()
|
||||
|
||||
@@ -2,13 +2,13 @@
|
||||
|
||||
<Parameters>
|
||||
<Geometry>
|
||||
<Length>18</Length>
|
||||
<Length>1300</Length>
|
||||
<Radius>4.5</Radius>
|
||||
</Geometry>
|
||||
|
||||
<DensityGrid>
|
||||
<Bins>
|
||||
<R>5</R>
|
||||
<R>10</R>
|
||||
<Z>16</Z>
|
||||
</Bins>
|
||||
</DensityGrid>
|
||||
@@ -24,7 +24,7 @@
|
||||
<Boundary>
|
||||
<Rear>
|
||||
<Type>1</Type>
|
||||
<Potential>0.003333333333333333</Potential>
|
||||
<Potential>0.0</Potential>
|
||||
</Rear>
|
||||
<Tube>
|
||||
<Type>1</Type>
|
||||
@@ -35,19 +35,31 @@
|
||||
</DPS>
|
||||
</Boundary>
|
||||
|
||||
<MaxIterations>1000</MaxIterations>
|
||||
<Precission>0.0001</Precission>
|
||||
<MaxIterations>10000</MaxIterations>
|
||||
<Precission>1E-6</Precission>
|
||||
</Solver>
|
||||
|
||||
<Output>
|
||||
<Potential>
|
||||
<Filename>./output/potential.dat</Filename>
|
||||
<H5File>
|
||||
<Filename>./output/output.h5</Filename>
|
||||
<H5Group>/Potential</H5Group>
|
||||
<H5DatasetName>potential</H5DatasetName>
|
||||
</H5File>
|
||||
</Potential>
|
||||
<Density>
|
||||
<Filename>./output/density.dat</Filename>
|
||||
<H5File>
|
||||
<Filename>./output/output.h5</Filename>
|
||||
<H5Group>/Density</H5Group>
|
||||
<H5DatasetName>density</H5DatasetName>
|
||||
</H5File>
|
||||
</Density>
|
||||
<Efield>
|
||||
<Filename>./output/efield_z.dat</Filename>
|
||||
<H5File>
|
||||
<Filename>./output/output.h5</Filename>
|
||||
<H5Group>/Efield</H5Group>
|
||||
<H5DatasetName>efield</H5DatasetName>
|
||||
</H5File>
|
||||
</Efield>
|
||||
</Output>
|
||||
|
||||
|
||||
@@ -36,29 +36,7 @@ class ElectricField {
|
||||
blitz::Array<double,2> data_z_;
|
||||
};
|
||||
|
||||
/*
|
||||
Density interpolateOnGrid(Density& denstity);
|
||||
|
||||
class Potential {
|
||||
public:
|
||||
Potential(blitz::Array<double,2>& data);
|
||||
Potential(int nr, int nz);
|
||||
|
||||
blitz::Array<double,2> data() const;
|
||||
|
||||
private:
|
||||
blitz::Array<double,2> data_;
|
||||
};
|
||||
|
||||
class ElectricField {
|
||||
|
||||
};
|
||||
|
||||
ElectricField interpolateOnGrid(
|
||||
ElectricField& electric_field,
|
||||
double dr_new,
|
||||
double dz_new);
|
||||
*/
|
||||
ElectricField interpolateOnGrid(ElectricField& electric_field);
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
#include "Fields.h"
|
||||
#include "Boundary.h"
|
||||
#include "PoissonSolver.h"
|
||||
|
||||
#include <vector>
|
||||
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<std::vector<double>>& data,
|
||||
std::string filename,
|
||||
std::string group,
|
||||
std::string path);
|
||||
|
||||
std::vector<std::vector<double>> convert(const blitz::Array<double,2>& data);
|
||||
};
|
||||
|
||||
#endif /* IO_H */
|
||||
|
||||
@@ -72,5 +72,27 @@ namespace Fields
|
||||
{
|
||||
}
|
||||
|
||||
ElectricField interpolateOnGrid(ElectricField& electric_field)
|
||||
{
|
||||
const blitz::TinyVector<int,2> extent = electric_field.data_r_.extent();
|
||||
const blitz::TinyVector<int,2> interpol_extent =
|
||||
extent - blitz::TinyVector<int,2>(0,1);
|
||||
|
||||
blitz::Array<double,2> interpolated_r(interpol_extent);
|
||||
blitz::Array<double,2> 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);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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<potential.data_.extent(1)-1; ++j){
|
||||
outdata << potential.data_(i,j) << ",";
|
||||
}
|
||||
outdata << potential.data_(i,potential.data_.extent(1)-1) << "\n";
|
||||
}
|
||||
outdata.close();
|
||||
"Parameters/Output/Potential/H5File").child_value("Filename"));
|
||||
|
||||
std::string group = std::string(
|
||||
parameter.document.first_element_by_path(
|
||||
"Parameters/Output/Potential/H5File").child_value("H5Group"));
|
||||
|
||||
std::string path = group + "/" + std::string(
|
||||
parameter.document.first_element_by_path(
|
||||
"Parameters/Output/Potential/H5File").child_value("H5DatasetName"));
|
||||
|
||||
save(convert(potential.data_), filename, group, path);
|
||||
}
|
||||
|
||||
|
||||
void save(const Fields::Density& density, const Parameter& parameter)
|
||||
{
|
||||
std::string filename = std::string(
|
||||
parameter.document.first_element_by_path(
|
||||
"Parameters/Output/Density").child_value("Filename"));
|
||||
std::ofstream outdata;
|
||||
outdata.open(filename);
|
||||
for(int i = 0; i < density.data_.extent(0); ++i){
|
||||
for(int j = 0; j<density.data_.extent(1)-1; ++j){
|
||||
outdata << density.data_(i,j) << ",";
|
||||
}
|
||||
outdata << density.data_(i,density.data_.extent(1)-1) << "\n";
|
||||
}
|
||||
outdata.close();
|
||||
"Parameters/Output/Density/H5File").child_value("Filename"));
|
||||
|
||||
std::string group = std::string(
|
||||
parameter.document.first_element_by_path(
|
||||
"Parameters/Output/Density/H5File").child_value("H5Group"));
|
||||
|
||||
std::string path = group + "/" + std::string(
|
||||
parameter.document.first_element_by_path(
|
||||
"Parameters/Output/Density/H5File").child_value("H5DatasetName"));
|
||||
|
||||
save(convert(density.data_), filename, group, path);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void save(const Fields::ElectricField& field, const Parameter& parameter)
|
||||
{
|
||||
std::string filename = std::string(
|
||||
parameter.document.first_element_by_path(
|
||||
"Parameters/Output/Efield").child_value("Filename"));
|
||||
std::ofstream outdata;
|
||||
outdata.open(filename);
|
||||
for(int i = 0; i < field.data_z_.extent(0); ++i){
|
||||
for(int j = 0; j<field.data_z_.extent(1)-1; ++j){
|
||||
outdata << field.data_z_(i,j) << ",";
|
||||
}
|
||||
outdata << field.data_z_(i,field.data_z_.extent(1)-1) << "\n";
|
||||
}
|
||||
outdata.close();
|
||||
"Parameters/Output/Efield/H5File").child_value("Filename"));
|
||||
|
||||
std::string group = std::string(
|
||||
parameter.document.first_element_by_path(
|
||||
"Parameters/Output/Efield/H5File").child_value("H5Group"));
|
||||
|
||||
std::string path = group + "/" + std::string(
|
||||
parameter.document.first_element_by_path(
|
||||
"Parameters/Output/Efield/H5File").child_value("H5DatasetName"));
|
||||
|
||||
save(convert(field.data_r_), filename, group, path+"_r");
|
||||
save(convert(field.data_z_), filename, group, path+"_z");
|
||||
}
|
||||
|
||||
void save(
|
||||
const std::vector<std::vector<double>>& 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<double>(path, HighFive::DataSpace::From(data));
|
||||
dataset.write(data);
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<std::vector<double>> convert(
|
||||
const blitz::Array<double,2>& data)
|
||||
{
|
||||
const blitz::TinyVector<int,2> start = data.lbound();
|
||||
const blitz::TinyVector<int,2> end = data.ubound();
|
||||
|
||||
std::vector<std::vector<double>> data_v;
|
||||
|
||||
for(int i = start(0); i<=end(0); ++i){
|
||||
std::vector<double> xs;
|
||||
for(int j = start(1); j<=end(1); ++j){
|
||||
xs.push_back(data(i,j));
|
||||
}
|
||||
data_v.push_back(xs);
|
||||
}
|
||||
|
||||
return data_v;
|
||||
}
|
||||
|
||||
};
|
||||
@@ -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<nr; ++i){
|
||||
potential.data_(i,0) = rearwall.data;
|
||||
}
|
||||
}
|
||||
else if (rearwall.type == BoundaryType::pml){
|
||||
else if (rearwall.type == pml){
|
||||
for(int i = 0; i<nr; ++i){
|
||||
potential.data_(i,0) = potential.data_(i,1);
|
||||
}
|
||||
@@ -88,12 +88,12 @@ void PoissonSolver::iterationPotential(
|
||||
|
||||
|
||||
// apply boundary condition right
|
||||
if(dps.type == BoundaryType::pec){
|
||||
if(dps.type == pec){
|
||||
for(int i = 0; i<nr; ++i){
|
||||
potential.data_(i,nz-1) = 0.;
|
||||
}
|
||||
}
|
||||
else if (dps.type == BoundaryType::pml){
|
||||
else if (dps.type == pml){
|
||||
for(int i = 0; i<nr; ++i){
|
||||
potential.data_(i,nz-1) = potential.data_(i,nz-2);
|
||||
}
|
||||
|
||||
@@ -36,8 +36,10 @@ int main(int argc, char *argv[]){
|
||||
radius,
|
||||
length);
|
||||
|
||||
Fields::ElectricField efield_interpolated = Fields::interpolateOnGrid(efield);
|
||||
|
||||
IO::save(potential, parameter);
|
||||
IO::save(efield, parameter);
|
||||
IO::save(efield_interpolated, parameter);
|
||||
IO::save(interpolated, parameter);
|
||||
|
||||
return 0;
|
||||
|
||||
Reference in New Issue
Block a user