Correct value for poisson solver and bug fixes
This commit is contained in:
@@ -45,4 +45,9 @@ std::vector<double> Longitudinal::bins() const
|
||||
return bins_;
|
||||
}
|
||||
|
||||
double Longitudinal::minimalBinDistance() const
|
||||
{
|
||||
return std::abs(bins_[1]-bins_[0]);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@ namespace Discrete {
|
||||
bool changedBin(double z_start, double z_end) const;
|
||||
int findBin(double z) const;
|
||||
std::vector<double> bins() const;
|
||||
double minimalBinDistance() const;
|
||||
|
||||
private:
|
||||
const std::vector<double> bins_;
|
||||
|
||||
@@ -36,11 +36,11 @@ InteractionOut T2IT2_CX::do_Interaction (Particle *interPart)
|
||||
const double scalar_product_squared =
|
||||
std::pow(v1_ms(0)*v_new(0) + v1_ms(1)*v_new(1),2)
|
||||
/(v_perp_new_squared*v_perp_old_squared);
|
||||
const double sin_theta = scalar_product_squared >= 1 ?
|
||||
0 : std::sqrt(1-scalar_product_squared); // sin(arcos(x)) = sqrt(1-x^2)
|
||||
const double sin_theta_half = scalar_product_squared >= 1 ?
|
||||
0 : std::sqrt((1-std::sqrt(scalar_product_squared))/2);
|
||||
|
||||
const double rG_m = v_perp_new*interPart->get_m_eV()/(Katrin_Fields::getMagField_T(loc_m)(2)*c_ms*c_ms);
|
||||
const double gyro_centrum_move_m = 2*rG_m * sin_theta;
|
||||
const double gyro_centrum_move_m = 2*rG_m * sin_theta_half;
|
||||
const double phi = rngUni->random() * 2 * pi;
|
||||
const double x_new = loc_m(0) + std::sin(phi)*gyro_centrum_move_m;
|
||||
const double y_new = loc_m(1) + std::cos(phi)*gyro_centrum_move_m;
|
||||
|
||||
@@ -36,12 +36,12 @@ InteractionOut T3IT2_Elastic::do_Interaction (Particle *interPart)
|
||||
|
||||
const double scalar_product_squared =
|
||||
std::pow(v1_ms(0)*v_new(0) + v1_ms(1)*v_new(1),2)
|
||||
/(v_perp_new_squared*v_perp_old_squared);
|
||||
const double sin_theta = scalar_product_squared >= 1 ?
|
||||
0 : std::sqrt(1-scalar_product_squared); // sin(arcos(x)) = sqrt(1-x^2)
|
||||
/(v_perp_new_squared*v_perp_old_squared); // = cos(x)^2
|
||||
const double sin_theta_half = scalar_product_squared >= 1 ?
|
||||
0 : std::sqrt((1-std::sqrt(scalar_product_squared))/2);
|
||||
|
||||
const double rG_m = v_perp_new*interPart->get_m_eV()/(Katrin_Fields::getMagField_T(loc_m)(2)*c_ms*c_ms);
|
||||
const double gyro_centrum_move_m = 2*rG_m * sin_theta;
|
||||
const double gyro_centrum_move_m = 2*rG_m * sin_theta_half;
|
||||
const double phi = rngUni->random() * 2 * pi;
|
||||
const double x_new = loc_m(0) + std::sin(phi)*gyro_centrum_move_m;
|
||||
const double y_new = loc_m(1) + std::cos(phi)*gyro_centrum_move_m;
|
||||
|
||||
@@ -3,6 +3,8 @@
|
||||
#include <cmath>
|
||||
#include "constants.h"
|
||||
|
||||
const double minimalZMovementDistance = 0.005;
|
||||
|
||||
Drift_Base::Drift_Base(
|
||||
species this_species,
|
||||
Particle_Logger_Base *Logger,
|
||||
@@ -23,7 +25,10 @@ void Drift_Base::move(Particle *movePart, const double ¯o_sigma_m) {
|
||||
vec3 oldLoc_m = movePart->get_x_m();
|
||||
vec3 newLoc_m = oldLoc_m;
|
||||
|
||||
const double dz = std::min(Katrin_Fields::E_field_ptr->stepSize(2),0.5);
|
||||
const double dz = std::min(std::min(
|
||||
Katrin_Fields::E_field_ptr->stepSize(2),
|
||||
longitudinal_bins.minimalBinDistance()),
|
||||
minimalZMovementDistance);
|
||||
|
||||
const double distance = 1./macro_sigma_m;
|
||||
|
||||
|
||||
@@ -46,11 +46,11 @@ InteractionOut eT2_Elastic::do_Interaction (Particle *interPart) {
|
||||
const double scalar_product_squared =
|
||||
std::pow(v1_ms(0)*v_new(0) + v1_ms(1)*v_new(1),2)
|
||||
/(v_perp_new_squared*v_perp_old_squared);
|
||||
const double sin_theta = scalar_product_squared >= 1 ?
|
||||
0 : std::sqrt(1-scalar_product_squared); // sin(arcos(x)) = sqrt(1-x^2)
|
||||
const double sin_theta_half = scalar_product_squared >= 1 ?
|
||||
0 : std::sqrt((1-std::sqrt(scalar_product_squared))/2);
|
||||
|
||||
const double rG_m = v_perp_new*interPart->get_m_eV()/(Katrin_Fields::getMagField_T(loc_m)(2)*c_ms*c_ms);
|
||||
const double gyro_centrum_move_m = 2*rG_m * sin_theta;
|
||||
const double gyro_centrum_move_m = 2*rG_m * sin_theta_half;
|
||||
const double phi = rngUni->random() * 2 * pi;
|
||||
const double x_new = loc_m(0) + std::sin(phi)*gyro_centrum_move_m;
|
||||
const double y_new = loc_m(1) + std::cos(phi)*gyro_centrum_move_m;
|
||||
|
||||
@@ -20,11 +20,9 @@ std::unique_ptr<ElectricField> ElectricFieldFactory::build(
|
||||
blitz::Array<double,3> Ez = read(filename, dataset_path_Ez);
|
||||
blitz::Array<double,3> Ephi(Er.shape());
|
||||
Ephi = 0.;
|
||||
std::cout << scale_factor << std::endl;
|
||||
std::cout << Ez(0,0,0) << std::endl;
|
||||
|
||||
Er *= scale_factor;
|
||||
Ez *= scale_factor;
|
||||
std::cout << Ez(0,0,0) << std::endl;
|
||||
|
||||
blitz::TinyVector<int,3> nx( Er.shape()(0), 1, Er.shape()(2));
|
||||
|
||||
|
||||
@@ -63,6 +63,8 @@ def densityToCsvEnergyBound(
|
||||
density = np.sum(total_density[:,:,:,Emin_index:Emax_index+1],3)[:,:,0]*si_to_cgs
|
||||
filename_output = filename_output_prefix + e["filename_suffix"]
|
||||
|
||||
print("Maxmial density: {:e}".format(np.max(density)))
|
||||
|
||||
np.savetxt(
|
||||
filename_output,
|
||||
density,
|
||||
|
||||
@@ -14,25 +14,39 @@ def spectrumToH5(filename, filename_output):
|
||||
|
||||
print("Get Density: e-")
|
||||
total_density_e = getDensities(filename, keys[0])
|
||||
|
||||
print("Get Volumes")
|
||||
volumes_e = getVolumes(filename, keys[0])
|
||||
|
||||
print("Get Particles: e-")
|
||||
particles_e = getParticlesPerBin(filename, keys[0])
|
||||
print("Get density: e-")
|
||||
density_e = total_density_e[:,:,0,:]
|
||||
density_e = np.moveaxis(density_e,1,0)
|
||||
|
||||
|
||||
print("Get Particles: T+")
|
||||
particles_T = getParticlesPerBin(filename, keys[1])
|
||||
print("Get Density: T+")
|
||||
total_density_T = getDensities(filename, keys[1])
|
||||
density_T = total_density_T[:,:,0,:]
|
||||
density_T = np.moveaxis(density_T,1,0)
|
||||
|
||||
print("Get Particles: T2+")
|
||||
particles_T2 = getParticlesPerBin(filename, keys[2])
|
||||
print("Get Density: T2+")
|
||||
total_density_T2 = getDensities(filename, keys[2])
|
||||
density_T2 = total_density_T2[:,:,0,:]
|
||||
density_T2 = np.moveaxis(density_T2,1,0)
|
||||
|
||||
print("Get Particles: T3+")
|
||||
particles_T3 = getParticlesPerBin(filename, keys[3])
|
||||
print("Get Density: T3+")
|
||||
total_density_T3 = getDensities(filename, keys[3])
|
||||
density_T3 = total_density_T3[:,:,0,:]
|
||||
density_T3 = np.moveaxis(density_T3,1,0)
|
||||
|
||||
|
||||
print("Save to h5")
|
||||
si_to_cgs = 1E-6
|
||||
|
||||
f = h5py.File(filename_output, 'a')
|
||||
@@ -40,6 +54,31 @@ def spectrumToH5(filename, filename_output):
|
||||
if key_electrons in f:
|
||||
del f[key_electrons]
|
||||
f.create_dataset(key_electrons, data=(density_e*si_to_cgs), dtype=float)
|
||||
|
||||
key_volumes = "Volumes/volumes_cm3"
|
||||
if key_volumes in f:
|
||||
del f[key_volumes]
|
||||
f.create_dataset(key_volumes, data=(volumes_e/si_to_cgs), dtype=float)
|
||||
|
||||
key_particles_e = "Particles/electrons"
|
||||
if key_particles_e in f:
|
||||
del f[key_particles_e]
|
||||
f.create_dataset(key_particles_e, data=(particles_e), dtype=float)
|
||||
|
||||
key_particles_T3 = "Particles/T3"
|
||||
if key_particles_T3 in f:
|
||||
del f[key_particles_T3]
|
||||
f.create_dataset(key_particles_T3, data=(particles_T3), dtype=float)
|
||||
|
||||
key_particles_T2 = "Particles/T2"
|
||||
if key_particles_T2 in f:
|
||||
del f[key_particles_T2]
|
||||
f.create_dataset(key_particles_T2, data=(particles_T2), dtype=float)
|
||||
|
||||
key_particles_T = "Particles/T"
|
||||
if key_particles_T in f:
|
||||
del f[key_particles_T]
|
||||
f.create_dataset(key_particles_T, data=(particles_T), dtype=float)
|
||||
|
||||
key_T3 = "Spectrum/T3"
|
||||
if key_T3 in f:
|
||||
|
||||
@@ -0,0 +1,75 @@
|
||||
{
|
||||
"metadata": {
|
||||
"language_info": {
|
||||
"codemirror_mode": {
|
||||
"name": "ipython",
|
||||
"version": 3
|
||||
},
|
||||
"file_extension": ".py",
|
||||
"mimetype": "text/x-python",
|
||||
"name": "python",
|
||||
"nbconvert_exporter": "python",
|
||||
"pygments_lexer": "ipython3",
|
||||
"version": "3.8.5"
|
||||
},
|
||||
"orig_nbformat": 2,
|
||||
"kernelspec": {
|
||||
"name": "python385jvsc74a57bd056da61b003f59252fe334bcd2da0b07ae0ea3d3a7a2553430d655234b468fb36",
|
||||
"display_name": "Python 3.8.5 64-bit ('base': conda)"
|
||||
}
|
||||
},
|
||||
"nbformat": 4,
|
||||
"nbformat_minor": 2,
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 3,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"import numpy as np\n",
|
||||
"import h5py as h5py\n",
|
||||
"import os\n",
|
||||
"import sys\n",
|
||||
"import matplotlib\n",
|
||||
"import matplotlib.pyplot as plt"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 4,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"nr = 15\n",
|
||||
"nz = 2800\n",
|
||||
"\n",
|
||||
"total_density = np.zeros((nr, nz))"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 5,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"filename_density = \"./config/zero_density.h5\"\n",
|
||||
"f = h5py.File(filename_density, 'a')\n",
|
||||
"\n",
|
||||
"key_density = \"Density/total\"\n",
|
||||
"if key_density in f:\n",
|
||||
" del f[key_density]\n",
|
||||
"f.create_dataset(key_density, data=total_density, dtype=float)\n",
|
||||
"\n",
|
||||
"f.close()\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": []
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -16,6 +16,16 @@ class Density {
|
||||
blitz::Array<double,2> data_;
|
||||
};
|
||||
|
||||
class ChargeDensity {
|
||||
public:
|
||||
ChargeDensity(const Density& density);
|
||||
ChargeDensity(const ChargeDensity& density);
|
||||
ChargeDensity(blitz::Array<double,2>& data);
|
||||
|
||||
blitz::Array<double, 2> data() const;
|
||||
blitz::Array<double, 2> data_;
|
||||
};
|
||||
|
||||
Density interpolateOnGrid(Density& denstity);
|
||||
|
||||
class Potential {
|
||||
|
||||
@@ -9,7 +9,7 @@ class PoissonSolver {
|
||||
PoissonSolver(double target_accuracy, int num_cycles);
|
||||
|
||||
Fields::Potential solve(
|
||||
Fields::Density& density,
|
||||
Fields::ChargeDensity& density,
|
||||
Boundary& rearwall,
|
||||
Boundary& tubewall,
|
||||
Boundary& dps,
|
||||
@@ -24,7 +24,7 @@ class PoissonSolver {
|
||||
private:
|
||||
void iterationPotential(
|
||||
Fields::Potential& potential,
|
||||
Fields::Density& density,
|
||||
Fields::ChargeDensity& density,
|
||||
Boundary& rearwall,
|
||||
Boundary& tubewall,
|
||||
Boundary& dps,
|
||||
@@ -33,7 +33,7 @@ class PoissonSolver {
|
||||
|
||||
bool converged(
|
||||
Fields::Potential& potential,
|
||||
Fields::Density& density,
|
||||
Fields::ChargeDensity& density,
|
||||
double dr,
|
||||
double dz) const;
|
||||
|
||||
|
||||
@@ -54,6 +54,26 @@ namespace Fields
|
||||
return Density(interpolated);
|
||||
}
|
||||
|
||||
ChargeDensity::ChargeDensity(blitz::Array<double,2>& data):
|
||||
data_(data.copy())
|
||||
{
|
||||
}
|
||||
|
||||
ChargeDensity::ChargeDensity(const ChargeDensity& density):
|
||||
data_(density.data())
|
||||
{}
|
||||
|
||||
// conversion to statC/cm^3
|
||||
ChargeDensity::ChargeDensity(const Density& density):
|
||||
data_(density.data()*4.80320425E-10)
|
||||
{}
|
||||
|
||||
blitz::Array<double,2> ChargeDensity::data() const
|
||||
{
|
||||
return data_.copy();
|
||||
}
|
||||
|
||||
|
||||
Potential::Potential(blitz::Array<double,2>& data):
|
||||
data_(data.copy())
|
||||
{
|
||||
|
||||
@@ -8,7 +8,7 @@ PoissonSolver::PoissonSolver(
|
||||
{}
|
||||
|
||||
Fields::Potential PoissonSolver::solve(
|
||||
Fields::Density& density,
|
||||
Fields::ChargeDensity& density,
|
||||
Boundary& rearwall,
|
||||
Boundary& tubewall,
|
||||
Boundary& dps,
|
||||
@@ -43,7 +43,7 @@ Fields::Potential PoissonSolver::solve(
|
||||
|
||||
void PoissonSolver::iterationPotential(
|
||||
Fields::Potential& potential,
|
||||
Fields::Density& density,
|
||||
Fields::ChargeDensity& density,
|
||||
Boundary& rearwall,
|
||||
Boundary& tubewall,
|
||||
Boundary& dps,
|
||||
@@ -102,7 +102,7 @@ void PoissonSolver::iterationPotential(
|
||||
|
||||
bool PoissonSolver::converged(
|
||||
Fields::Potential& potential,
|
||||
Fields::Density& density,
|
||||
Fields::ChargeDensity& density,
|
||||
double dr,
|
||||
double dz) const
|
||||
{
|
||||
|
||||
@@ -22,9 +22,11 @@ int main(int argc, char *argv[]){
|
||||
|
||||
Fields::Density interpolated(Fields::interpolateOnGrid(density));
|
||||
|
||||
Fields::ChargeDensity charge_density(interpolated);
|
||||
|
||||
PoissonSolver solver = IO::solver(parameter);
|
||||
Fields::Potential potential = solver.solve(
|
||||
interpolated,
|
||||
charge_density,
|
||||
rearwall,
|
||||
tubewall,
|
||||
dps,
|
||||
@@ -38,10 +40,11 @@ int main(int argc, char *argv[]){
|
||||
|
||||
Fields::ElectricField efield_interpolated = Fields::interpolateOnGrid(efield);
|
||||
|
||||
efield_interpolated.data_r_ = 0.;
|
||||
//efield_interpolated.data_r_ = 0.;
|
||||
|
||||
IO::save(potential, parameter);
|
||||
IO::save(efield_interpolated, parameter);
|
||||
//IO::save(efield_interpolated, parameter);
|
||||
IO::save(efield, parameter);
|
||||
IO::save(interpolated, parameter);
|
||||
|
||||
return 0;
|
||||
|
||||
Reference in New Issue
Block a user