Git Umzug

This commit is contained in:
Joachim Rupp
2020-08-03 14:46:25 +02:00
parent 10c76c7c96
commit 5d93e33fca
20 changed files with 1000762 additions and 35 deletions
+2
View File
@@ -0,0 +1,2 @@
#include "Bessel.h"
+31
View File
@@ -0,0 +1,31 @@
#ifndef BESSEL_H
#define BESSEL_H
//#include "kinematics.h"
#include "ElectricField.h"
#include "lin_scale.h"
#include "constants.h"
#include "RearwallPotential.h"
class Bessel : public ElectricField, public RearwallPotential{
private:
vec3 efeld_value;
vec3 efeld_loc;
public:
Bessel(vec3 efeld_value);
~Bessel(){};
//int getValue();
vec3 getLoc(const vec3 &loc_m);
vec3 getLoc(const double &z, const double &r, const double &phi);
vec3 getValue(const vec3 &loc_m);
vec3 getValue(const double &z, const double &r, const double &phi);
vec3 getValue();
};
#endif /* BESSEL_H */
+22 -2
View File
@@ -1,6 +1,26 @@
#include "ElectricField.h"
#include <iostream> //cout
int ElectricField::getValue(){
return 0;
vec3 ElectricField::getValue(){
return vec3(0,0,0);
}
vec3 ElectricField::getValue(const vec3 &loc_m){
return vec3(0,0,0);
}
vec3 ElectricField::getValue(const double &z, const double &r, const double &phi){
return vec3(0,0,0);
}
vec3 ElectricField::getLoc(){
return vec3(0,0,0);
}
vec3 ElectricField::getLoc(const vec3 &loc_m){
return vec3(0,0,0);
}
vec3 ElectricField::getLoc(const double &z, const double &r, const double &phi){
return vec3(0,0,0);
}
+6 -2
View File
@@ -6,7 +6,11 @@
class ElectricField{
public:
ElectricField(){};
int getValue();
//virtual vec3 getValue(const vec3 &loc_m);
virtual vec3 getValue();
virtual vec3 getValue(const vec3 &loc_m);
virtual vec3 getValue(const double &z, const double &r, const double &phi);
virtual vec3 getLoc();
virtual vec3 getLoc(const vec3 &loc_m);
virtual vec3 getLoc(const double &z, const double &r, const double &phi);
};
#endif /* ELECTRICFIELD_H */
+18
View File
@@ -0,0 +1,18 @@
#include "Function3d.h"
blitz::TinyVector<double, 3> Function3d::getValue(const blitz::TinyVector<double, 3>& x) const {
return getValue(x(0), x(1), x(2));
}
double Function3d::getValue(const blitz::TinyVector<double, 3>& x, int cart_axis) const {
return getValue(x(0), x(1), x(2), cart_axis);
}
std::ostream & operator << (std::ostream &out, const Function3d& function) {
function.print(out);
return out;
}
void Function3d::print(std::ostream &out) const{
out << "Function3d Base:\n";
}
+24
View File
@@ -0,0 +1,24 @@
#ifndef FUNCTION3D_H
#define FUNCTION3D_H
#include "blitz/array.h"
#include <iostream> // ostream
// Abstract base class for a 3d function
// - can provide an element of the return vector (direction: x, y, z)
// - can prodvie whole vector
class Function3d {
public:
virtual ~Function3d() {};
virtual double getValue(double x, double y, double z, int cart_axis) const = 0;
virtual blitz::TinyVector<double ,3> getValue(double x, double y, double z) const = 0;
double getValue(const blitz::TinyVector<double, 3>& x, int cart_axis) const;
blitz::TinyVector<double, 3> getValue(const blitz::TinyVector<double, 3>& x) const;
friend std::ostream & operator << (std::ostream &out, const Function3d& function);
virtual void print(std::ostream &out) const;
};
#endif /* FUNCTION3D_H */
+14 -1
View File
@@ -13,6 +13,19 @@ vec3 Homogene::getValue(const vec3 &loc_m){
return efeld_value;
}
vec3 Homogene::getValue(const double &z, const double &r, const double &phi){
return efeld_value;
}
vec3 Homogene::getValue(){
return efeld_value;
}
}
vec3 Homogene::getLoc(const vec3 &loc_m){
return loc_m;
}
vec3 Homogene::getLoc(const double &z, const double &r, const double &phi){
return vec3(z, r, phi);
}
+6 -1
View File
@@ -3,20 +3,25 @@
//#include "kinematics.h"
#include "ElectricField.h"
#include "lin_scale.h"
#include "constants.h"
class Homogene : public ElectricField{
private:
vec3 efeld_value;
vec3 efeld_loc;
public:
Homogene(){};
Homogene(vec3 efeld_value);
~Homogene(){};
//int getValue();
void setValue(vec3 efeld_value);
vec3 getLoc(const vec3 &loc_m);
vec3 getLoc(const double &z, const double &r, const double &phi);
vec3 getValue(const vec3 &loc_m);
vec3 getValue(const double &z, const double &r, const double &phi);
vec3 getValue();
};
+297
View File
@@ -0,0 +1,297 @@
#include "RearwallPotential.h"
#include "physconst.H"
#include "constants.h"
#include "enumerations.h"
#include <gsl/gsl_sf_trig.h> // sin/cos/sinh/cosh
#include <gsl/gsl_sf_bessel.h> // bessel function, and zeros
//#include "tools/my_errors.h"
#include "error_types.h"
#include <math.h> // isnan
RearwallPotential::RearwallPotential(double radius, double height,
double rearwall_potential,
const blitz::TinyVector<double, 3>& center,
double minimal_z_for_bessel_calculation,
int max_bessel_zero_order_,
double precision, bool potential_in_si
)
: radius_(radius),
height_(height),
max_bessel_zero_order_(max_bessel_zero_order_),
minimal_z_for_bessel_calculation_(minimal_z_for_bessel_calculation),
maximal_z_for_bessel_calculation_(height),
center_(center) {
if (potential_in_si) {
//rearwall_potential_ = rearwall_potential * 1E8 / PhysicalConstantsSI::c;
rearwall_potential_ = rearwall_potential * 1E8 / c_ms;
} else {
rearwall_potential_ = rearwall_potential;
}
maximal_z_for_bessel_calculation_ = getMaximalZ(radius, precision);
if (maximal_z_for_bessel_calculation_ < height_) {
height_ = maximal_z_for_bessel_calculation_;
}
}
RearwallPotential::~RearwallPotential() {};
void RearwallPotential::print(std::ostream &out) const {
out << "Function3d: RearwallPotential\n";
out << "radius: " << radius_ << "\n";
out << "height: " << height_ << "\n";
out << "minimal z for bessel calculation: " << minimal_z_for_bessel_calculation_ << "\n";
out << "maximal z for bessel calculation: " << maximal_z_for_bessel_calculation_ << "\n";
out << "center: " << center_ << "\n";
out << "potential (cgs): " << rearwall_potential_ << "\n";
}
double RearwallPotential::getValue(double x, double y, double z,
int cart_axis) const {
// convert to local coordinates
x += -center_(0);
y += -center_(1);
z += -center_(2);
// get cylinder coordinates
gsl_sf_result r = {0.0, 0.0};
gsl_sf_result phi = {0.0, 0.0};
if(x == 0.0 && y == 0.0){ // guard for gsl error: 0,0 not defined
r.val = 0.0;
phi.val = 0.0;
} else {
gsl_sf_rect_to_polar(x, y, &r, &phi);
}
if (cart_axis == Cart::Axis::x) {
return getRadialElectricField(r.val, z) * gsl_sf_cos(phi.val);
} else if (cart_axis == Cart::Axis::y) {
return getRadialElectricField(r.val, z) * gsl_sf_sin(phi.val);
} else if (cart_axis == Cart::Axis::z) {
return getLongitudinalElectricField(r.val, z);
} else {
std::stringstream ss;
ss<<"This axis " << cart_axis << " was not implemented. Use x, y or z for getValue." << std::endl;
throw MyException(ss.str());
//PANIC_NORANK(
// "This axis %d was not implemented. Use x, y or z for getValue.\n",
// cart_axis);
return 0.0;
}
}
blitz::TinyVector<double, 3> RearwallPotential::getValue(double z, double r,
double phi) const {
// convert to local coordinates
//x += -center_(0);
//y += -center_(1);
//z += -center_(2);
/*
// get cylinder coordinates
gsl_sf_result r = {0.0, 0.0};
gsl_sf_result phi = {0.0, 0.0};
if(x == 0.0 && y == 0.0){ // guard for gsl error: 0,0 not defined
r.val = 0.0;
phi.val = 0.0;
} else {
gsl_sf_rect_to_polar(x, y, &r, &phi);
}
*/
//std::cout << "ich wurde aufgerufen" << std::endl;
return blitz::TinyVector<double, 3>(
getRadialElectricField(r, z) * gsl_sf_cos(phi),
getRadialElectricField(r, z) * gsl_sf_sin(phi),
getLongitudinalElectricField(r, z));
}
vec3 RearwallPotential::getValue(const double &z, const double &r, const double &phi){
// convert to local coordinates
//x += -center_(0);
//y += -center_(1);
//z += -center_(2);
//double z_loc = z-center_(2);
double z_loc = z-center_(2);
/*
// get cylinder coordinates
gsl_sf_result r = {0.0, 0.0};
gsl_sf_result phi = {0.0, 0.0};
if(x == 0.0 && y == 0.0){ // guard for gsl error: 0,0 not defined
r.val = 0.0;
phi.val = 0.0;
} else {
gsl_sf_rect_to_polar(x, y, &r, &phi);
}
*/
//std::cout << "ich wurde aufgerufen" << std::endl;
//std::cout << getRadialElectricField(r, z_loc) << std::endl;
efeld_value = vec3(getRadialElectricField(r, z_loc) * gsl_sf_cos(phi),
getRadialElectricField(r, z_loc) * gsl_sf_sin(phi),
getLongitudinalElectricField(r, z_loc));
return efeld_value;
}
double RearwallPotential::getElectricField(double radius, double z,
int clynder_axis) const {
if (clynder_axis == Cyl::Axis::rho) {
return getRadialElectricField(radius, z);
} else if (clynder_axis == Cyl::Axis::z) {
return getLongitudinalElectricField(radius, z);
} else if(clynder_axis == Cyl::Axis::phi) {
return 0.0;
}
else {
std::stringstream ss;
ss<<"This axis " << clynder_axis << " was not implemented. Use x, y or z for getElectricField. " << std::endl;
throw MyException(ss.str());
//PANIC_NORANK(
// "This axis %d was not implemented. Use x, y or z for "
// "getElectricField.\n",
// clynder_axis);
return 0.0;
}
}
double RearwallPotential::getRadialElectricField(double radius,
double z) const {
// boundary checks
if (isCoordinateOutsideCylinder(radius, z)) {
//std::cout << "out of cylinder" << std::endl;
return 0.0;
}
// scales linearly from 0 to E(minimal_z_for_bessel_calculation_)
if (z <= minimal_z_for_bessel_calculation_) {
double Er_zmin = 0.0;
for (int order = 1; order <= max_bessel_zero_order_; ++order) {
Er_zmin += getRadialFieldComponent(
radius, minimal_z_for_bessel_calculation_, order);
}
Er_zmin = Er_zmin * z / minimal_z_for_bessel_calculation_;
return Er_zmin;
}
// standard calculation
double Er = 0.0;
for (int order = 1; order <= max_bessel_zero_order_; ++order) {
Er += getRadialFieldComponent(radius, z, order);
}
return Er;
}
double RearwallPotential::getLongitudinalElectricField(double radius,
double z) const {
// boundary checks
if (isCoordinateOutsideCylinder(radius, z)) {
// in contrast to radial component the long. field is not zero
if (z != 0.0) {
return 0.0;
}
}
// uses value of E(minimal_z_for_bessel_calculation_) for smaller z
if (z <= minimal_z_for_bessel_calculation_) {
double Ez_zmin = 0.0;
for (int order = 1; order <= max_bessel_zero_order_; ++order) {
Ez_zmin += getLongitudinalFieldComponent(
radius, minimal_z_for_bessel_calculation_, order);
}
return Ez_zmin;
}
// standard calculation
double Ez = 0.0;
for (int order = 1; order <= max_bessel_zero_order_; ++order) {
Ez += getLongitudinalFieldComponent(radius, z, order);
}
return Ez;
}
double RearwallPotential::getPotential(double r, double z) const {
// check for boundaries
if(z <= 0.0) {
return rearwall_potential_;
} else if(isCoordinateOutsideCylinder(r, z)) {
return 0.0;
}
// standard calculation
double potential = 0.0;
for(int order = 1; order <= max_bessel_zero_order_; ++order) {
potential += getRadialPotentialComponent(r, order) * getLongitudinalPotentialComponent(z, order);
}
potential *= rearwall_potential_;
if(potential > rearwall_potential_) {
potential = rearwall_potential_;
}
return potential;
}
double RearwallPotential::getRadialPotentialComponent(
double r, int bessel_zero_order) const {
long double k0i = gsl_sf_bessel_zero_J0(bessel_zero_order);
return gsl_sf_bessel_J0(k0i*r/radius_)/(k0i * gsl_sf_bessel_J1(k0i));
}
double RearwallPotential::getLongitudinalPotentialComponent(
double z, int bessel_zero_order) const {
double k0i = gsl_sf_bessel_zero_J0(bessel_zero_order);
double b = k0i * height_/radius_;
double b_z = k0i/radius_*(height_ - z);
double V_long = 2.0*exp(gsl_sf_lnsinh(b_z) - gsl_sf_lnsinh(b));
if(isnan(V_long) || isinf(V_long)) {
return 0.0;
} else {
return V_long;
}
}
double RearwallPotential::getLongitudinalFieldComponent(
double r, double z, int bessel_zero_order) const {
double k0i = gsl_sf_bessel_zero_J0(bessel_zero_order);
double b = k0i * height_ / radius_;
double b_z = k0i / radius_ * (height_ - z);
// cosh(b_z)/sinh(b):
double cosh_sinh = exp(gsl_sf_lncosh(b_z) - gsl_sf_lnsinh(b));
if (isnan(cosh_sinh) || isinf(cosh_sinh)) {
cosh_sinh = 0.0;
}
double potential_z_derivative = 0.0;
if (z <= 0.0) {
potential_z_derivative = 2.0 * k0i / radius_;
} else {
potential_z_derivative = 2.0 * k0i / radius_ * cosh_sinh;
}
return rearwall_potential_ * potential_z_derivative *
getRadialPotentialComponent(r, bessel_zero_order);
}
double RearwallPotential::getRadialFieldComponent(double r, double z,
int bessel_zero_order) const {
double k0i = gsl_sf_bessel_zero_J0(bessel_zero_order);
double Er_i = rearwall_potential_ *
getLongitudinalPotentialComponent(z, bessel_zero_order) *
gsl_sf_bessel_J1(k0i * r / radius_) /
(radius_ * gsl_sf_bessel_J1(k0i));
return Er_i;
}
bool RearwallPotential::isCoordinateOutsideCylinder(double radius, double z) const {
return z<=0.0 || z>= maximal_z_for_bessel_calculation_ || radius > radius_;
}
double RearwallPotential::getMaximalZ(double radius, double precision) const {
return (-1.0) * log(precision) * radius / gsl_sf_bessel_zero_J0(1);
}
+50
View File
@@ -0,0 +1,50 @@
#ifndef REARWALLPOTENTIAL_H
#define REARWALLPOTENTIAL_H
#include "Function3d.h"
#include "ElectricField.h"
class RearwallPotential : public ElectricField, public Function3d {
public:
RearwallPotential(double radius, double height, double rearwall_potential, const blitz::TinyVector<double, 3>& center,
double minimal_z_for_bessel_calculation = 0.05, int max_bessel_zero_order_ = 1000,
double precision = 1E-15, bool potential_in_si = false);
~RearwallPotential();
void print(std::ostream &out) const;
double getValue(double x, double y, double z, int cart_axis) const;
blitz::TinyVector<double, 3> getValue(double x, double y, double z) const;
vec3 getValue(const double &z, const double &r, const double &phi);
double getElectricField(double radius, double z, int clinder_axis) const; // only used for debugging
double getPotential(double r, double z) const; // only used for debugging
private:
double radius_;
double height_;
double max_bessel_zero_order_;
double rearwall_potential_;
double minimal_z_for_bessel_calculation_;
double maximal_z_for_bessel_calculation_;
const blitz::TinyVector<double, 3> center_;
vec3 efeld_value;
// use that for large values of z the result of the potential/field is smaller than double precision
// the bessel calculation is only done up to this z value
double getMaximalZ(double radius, double precision) const;
double getRadialElectricField(double radius, double z) const;
double getLongitudinalElectricField(double radius, double z) const;
double getRadialPotentialComponent(double r, int bessel_zero_order) const;
double getLongitudinalPotentialComponent(double z, int bessel_zero_order) const;
double getLongitudinalFieldComponent(double r, double z, int bessel_zero_order) const;
double getRadialFieldComponent(double r, double z, int bessel_zero_order) const;
bool isCoordinateOutsideCylinder(double radius, double z) const;
};
#endif /* REARWALLPOTENTIAL_H */
+130
View File
@@ -0,0 +1,130 @@
#ifndef ENUMERATIONS_H
#define ENUMERATIONS_H
namespace Cart {
enum Axis {
x = 0,
y = 1,
z = 2
};
};
namespace Cyl {
enum Axis {
rho = 0,
phi = 1,
z = 2
};
};
namespace AXIS {
static const int X = 0;
static const int Y = 1;
static const int Z = 2;
static const int Rho = 3;
static const int Phi = 4;
}
namespace GEOMETRY {
static const int undefined = -1;
static const int cylinder = 1;
static const int cube = 2;
}
namespace FORMFACTOR {
static const int undefined = -1;
static const int Default = 5;
static const int NGP = 1;
static const int NGPCIC = 2;
static const int CIC = 3;
static const int CICTSC = 4;
static const int TSC = 5;
static const int TSCPQS = 6;
static const int PQS = 7;
static const int PQSPCS = 8;
static const int PCS = 9;
static const int SUDS1 = 10;
static const int SUDS2 = 11;
static const int COS = 12;
}
namespace PARTICLE_PUSHER {
static const int undefined = -1;
static const int Default = 1;
static const int boris = 1;
static const int vay = 2;
}
namespace CURRENT_ASSIGNMENT {
static const int undefined = -1;
static const int Default = 1;
static const int esirkepov = 1;
static const int umeda = 2;
}
namespace MAXWELL_SOLVER {
static const int undefined = -1;
static const int Default = 1;
static const int yee = 1;
static const int ck = 2;
static const int ck5 = 3;
static const int O4 = 4;
static const int M24 = 5;
static const int ES = 6;
static const int darwin = 7;
static const int deymittra = 8;
}
namespace CURRENT_BACKGROUND {
static const int undefined = -1;
static const int precalculated = 1;
static const int homogeneous = 2;
static const int polynomial = 3;
}
namespace MAGENTIC_BACKGROUND {
static const int undefined = -1;
static const int polynomial = 1;
static const int homogeneous = 2;
static const int precalculated = 3;
}
namespace ELECTRIC_BACKGROUND {
static const int undefined = -1;
static const int polynomial = 1;
static const int homogeneous = 2;
static const int precalculated = 3;
static const int rearwall = 4;
}
namespace CAVITY_MODE {
static const int undefined = -1;
static const int TE = 1;
static const int TM = 2;
}
namespace RANDOM_NUMBER_METHOD {
static const int undefined = -1;
static const int rejection = 1;
static const int inverse = 2;
static const int gamma_boltzmann= 3;
static const int histogram = 4;
}
namespace DISTRIBUTION_FUNCTION {
static const int undefined = -1;
static const int boltzmann3D = 1;
static const int T3_beta = 2;
static const int linear = 3;
static const int power = 4;
static const int power_inverse = 5;
}
namespace INJECTION_PLANE_TYPE {
static const int undefined = -1;
static const int density = 1;
static const int current = 2;
}
#endif // ENUMERATIONS_H
+4
View File
@@ -64,8 +64,12 @@ inline double calc_r_m(const vec3 &loc_m) {
}
inline double calc_phi(const vec3 &loc_m) {
if (loc_m[1] == 0 and loc_m[0] == 0){
return 0;
}
if (loc_m[1] >= 0) {
return acos(loc_m[0]/calc_r_m(loc_m));
//return atan(loc_m[1]/loc_m[0]);
} else {
return 2*pi - acos(loc_m[0]/calc_r_m(loc_m));
}
+5 -3
View File
@@ -12,9 +12,11 @@ OBJS := particle_looper.o \
interaction_builder.o BED_eT2_ionization.o uehara_eT2_elastic.o rutherford_elastic.o \
terminator_builder.o \
ElectricField.o \
Homogene.o
Homogene.o \
Function3d.o \
RearwallPotential.o
OBJECTS_TEST := test_ElectricField.o \ test_Homogene.o
OBJECTS_TEST := test_ElectricField.o \ test_Homogene.o \ test_vec3_container.o
CXXFLAGS = $(X_OFLAGS) -I.. $(X_INC) -std=c++11
@@ -23,7 +25,7 @@ MPXFLAGS = $(X_OFLAGS) -I.. $(X_INC) $(X_HDF5P_INC) -std=c++11
LDFLAGS = $(X_LIB) $(X_HDF5P_LIBS)
LOADLIBES = -lblitz -lm -lhdf5 -lhdf5_hl
LOADLIBES = -lblitz -lm -lhdf5 -lhdf5_hl -lgsl -lgslcblas -lm
TARGETS = mcelectron
File diff suppressed because it is too large Load Diff
+3 -1
View File
@@ -7,7 +7,9 @@ SCENARIO("Test the ElectricField class", "[ElectricField]") {
ElectricField electric_field;
WHEN("A value is ordered") {
THEN("Jonas value is returned") {
REQUIRE(electric_field.getValue() == 0);
REQUIRE(electric_field.getValue()[0] == 0);
REQUIRE(electric_field.getValue()[1] == 0);
REQUIRE(electric_field.getValue()[2] == 0);
}
}
}
+72
View File
@@ -0,0 +1,72 @@
#include "catch.hpp"
#include "blitz/array.h"
//#include "function3d/Homogene.h"
//#include "function3d/PolynomialCylinder.h"
//#include "function3d/Zeros.h"
#include "RearwallPotential.h"
#include <memory> // unique_ptr
#include <fstream> // output file
SCENARIO("Test Function3d class", "[Function3d]") {
GIVEN("A RearWall Function3d") {
double dx = 0.10984755318623787;
double radius = 4.5;
double height = dx*3060;
double rearwall_potential = 10.0;
blitz::TinyVector<double, 3> center(4.5, 4.5, 0.0);
double minimal_z_for_bessel_calculation = dx*1;
int max_bessel_zero_order = 1000;
double precision = 1E-15;
bool potential_in_si = true;
RearwallPotential rearwall(radius, height, rearwall_potential, center,
minimal_z_for_bessel_calculation,
max_bessel_zero_order, precision,
potential_in_si);
std::cout << rearwall << "\n";
WHEN("A value in x,y,z direction is ordered"){
THEN("The correct value is returned and saved to file. Look at that file.") {
double increment = dx;
std::ofstream output_file_potential;
output_file_potential.open("rearwall_potential_output.dat");
output_file_potential << "#r z potential\n";
for(double r = 0.0; r <= radius; r+=increment ){
for(double z = 0.0; z <= height; z+=increment){
output_file_potential << r << "," << z << ",";
output_file_potential << rearwall.getPotential(r, z) << "\n";
}
}
output_file_potential.close();
std::ofstream output_file_field;
output_file_field.open("rearwall_field_output.dat");
output_file_field << "#r z Er Ephi Ez\n";
for(double r = 0.0; r <= radius; r+=increment ){
for(double z = 0.0; z <= height; z+=increment){
output_file_field << r << "," << z << ",";
output_file_field << rearwall.getElectricField(r, z, 0) << ",";
output_file_field << rearwall.getElectricField(r, z, 1) << ",";
output_file_field << rearwall.getElectricField(r, z, 2) << "\n";
}
}
output_file_field.close();
REQUIRE(true);
}
}
}
}
+8 -8
View File
@@ -15,13 +15,13 @@ SCENARIO("Test the Homogene class", "[Homogene]") {
REQUIRE(electric_field.getValue()[2] == 0);
}
}
WHEN("The value is changed and ordered"){
electric_field.setValue(vec3(2,2,2));
THEN("Changed Value is returned"){
REQUIRE(electric_field.getValue()[0] == 2);
REQUIRE(electric_field.getValue()[1] == 2);
REQUIRE(electric_field.getValue()[2] == 2);
}
}
//WHEN("The value is changed and ordered"){
// electric_field.setValue(vec3(2,2,2));
// THEN("Changed Value is returned"){
// REQUIRE(electric_field.getValue()[0] == 2);
// REQUIRE(electric_field.getValue()[1] == 2);
// REQUIRE(electric_field.getValue()[2] == 2);
// }
//}
}
}
+16 -11
View File
@@ -2,18 +2,23 @@
#include "vec3_container.hpp"
#include "Homogene.h"
#include "RearwallPotential.h"
#include "constants.h"
#include <fstream>
#include <memory>
SCENARIO("Test the vec3_container Constructor with Electric Field class", "[vec3_container.hpp]") {
SCENARIO("Test the vec3_container Constructor with Electric Field class", "[vec3_container]") {
GIVEN("Vec3 Container initilazed with a homogene electric field") {
Homogene electric_field(vec3(5,0,0));
Vec3_Container efeld(10, 10, 10, electric_field);
//vec3 value(5,0,0);
//vec3 value = blitz::TinyVector<double, 3>(5,0,0)
REQUIRE(efeld.get_data(vec3(0, 0, 0))[0] == 5 );
REQUIRE(efeld.get_data(vec3(0, 0, 0))[1] == 0 );
REQUIRE(efeld.get_data(vec3(0, 0, 0))[2] == 0 );
RearwallPotential electric_field(r_WGTS_m*100, z_WGTS_end_m*100, 10.0, vec3(0, 0, 0), 0.10, 1000, 1e-15, true);
Vec3_Container efeld(1000, 50, 20, electric_field);
THEN("The correct value is returned and saved to file. Look at that file.") {
}
REQUIRE(true);
}
}
}
+50 -6
View File
@@ -21,14 +21,52 @@ Vec3_Container::Vec3_Container(int num_z_bins, int num_r_bins, int num_phi_bins,
}
Vec3_Container::Vec3_Container(int num_z_bins, int num_r_bins, int num_phi_bins, ElectricField &E){
z_scale = Lin_Scale(z_WGTS_start_m, z_WGTS_end_m, num_z_bins);
r_scale = Lin_Scale(0, r_WGTS_m, num_r_bins);
z_scale = Lin_Scale(z_WGTS_start_m*100, z_WGTS_end_m*100, num_z_bins);
r_scale = Lin_Scale(0, r_WGTS_m*100, num_r_bins);
phi_scale = Lin_Scale(0, 180, num_phi_bins);
int num_tot_bins = num_z_bins * num_r_bins * num_phi_bins;
data = new vec3[num_tot_bins];
for(int i=0; i<num_tot_bins; i++){
data[i] = E.getValue();
dataloc = new vec3[num_tot_bins];
std::ofstream output_file_field;
output_file_field.open("../rearwall_electricfield_test.dat");
output_file_field << "#r phi z Er Ephi Ez\n";
for(int i = 0; i < num_z_bins; i++){
for (int j = 0; j < num_r_bins; j++){
for (int k = 0; k < num_phi_bins; k++){
double z = z_scale.get_bin_mid(i);
double r = r_scale.get_bin_mid(j);
double phi = phi_scale.get_bin_mid(k);
//double x = r*cos(phi);
//double y = r*sin(phi);
//std::cout << x << ", " << y << ", " << z << std::endl;
//while(l < num_tot_bins){
// std::cout << l << std::endl;
// data[l] = E.getValue(z, r, phi);
// l++;
//}
//std::cout << i*num_r_bins*num_phi_bins+j*num_phi_bins+k << std::endl;
data[i*num_r_bins*num_phi_bins+j*num_phi_bins+k] = E.getValue(z, r, phi);
//data[i*num_r_bins*num_phi_bins+j*num_phi_bins+k] = E.getPotential(r, z);
//dataloc[i*num_r_bins*num_phi_bins+j*num_phi_bins+k] = E.getLoc(z, r, phi);
dataloc[i*num_r_bins*num_phi_bins+j*num_phi_bins+k] = vec3(z, r, phi);
std::cout << i*num_r_bins*num_phi_bins+j*num_phi_bins+k << " " << dataloc[i*num_r_bins*num_phi_bins+j*num_phi_bins+k] << " " << data[i*num_r_bins*num_phi_bins+j*num_phi_bins+k] << std::endl;
//std::cout << i*num_r_bins*num_phi_bins+j*num_phi_bins+k << " " << dataloc[i*num_r_bins*num_phi_bins+j*num_phi_bins+k] << " " << E.getPotential(r,z) << std::endl;
output_file_field << r << "," << phi << "," << z << ",";
output_file_field << E.getValue(z, r, phi)[0] << ",";
output_file_field << E.getValue(z, r, phi)[1] << ",";
output_file_field << E.getValue(z, r, phi)[2] << "\n";
//output_file_field << E.getPotential(r, z) << "\n";
}
}
}
output_file_field.close();
//int l = calc_data_bin(vec3(0, 0, 5));
//std::cout << "bin " << l << " ort " << dataloc[l] <<std::endl;
}
Vec3_Container::~Vec3_Container() {
@@ -110,9 +148,15 @@ int Vec3_Container::calc_data_bin(const vec3 &loc_m) {
double z_m = calc_z_m(loc_m);
double r_m = calc_r_m(loc_m);
double phi = calc_phi(loc_m);
//double phi = 0;
int z_bin = z_scale.calc_index(z_m);
int r_bin = r_scale.calc_index(r_m);
int phi_bin = phi_scale.calc_index(phi);
//std::cout << "z " << z_m << std::endl;
//std::cout << "r " << r_m << std::endl;
//std::cout << "phi "<< phi << std::endl;
//std::cout << "zbin " << z_bin << std::endl;
//std::cout << "rbin " << r_bin << std::endl;
//std::cout << "phi_bin " << phi_bin << std::endl;
return z_bin * r_scale.get_number_bins() * phi_scale.get_number_bins() + r_bin * phi_scale.get_number_bins() + phi_bin;
};
};
+3
View File
@@ -13,9 +13,12 @@
#include "kinematics.h"
#include "constants.h"
#include "ElectricField.h"
#include "Homogene.h"
#include "RearwallPotential.h"
class Vec3_Container {
vec3 *data;
vec3 *dataloc;
Lin_Scale z_scale, r_scale, phi_scale;
public: