Added Electric Field from H5
This commit is contained in:
Binary file not shown.
@@ -0,0 +1 @@
|
||||
include $(HOMEBASE)/src/makeinclude/first.mak
|
||||
@@ -0,0 +1,21 @@
|
||||
include $(HOMEBASE)/src/makeinclude/include.mak
|
||||
|
||||
OFLAGS = $(X_OFLAGS)
|
||||
CXXFLAGS = $(OFLAGS) $(X_INC)
|
||||
|
||||
ZIP = unzip
|
||||
|
||||
|
||||
NAME = HighFive-master
|
||||
|
||||
all:
|
||||
$(ZIP) ../$(NAME).zip
|
||||
@cp -r $(NAME)/include/highfive $(X_INC_DIR)
|
||||
|
||||
install:
|
||||
make install
|
||||
|
||||
clean:
|
||||
#-rm -rf $(X_INC_DIR)/highfive
|
||||
#$(X_CLEAN)
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
#include "CoordinateConversion.h"
|
||||
|
||||
//#include <cmath>
|
||||
#include <math.h>
|
||||
|
||||
blitz::TinyVector<int,3> CoordinateConversion::cylinderBin(
|
||||
const blitz::TinyVector<double,3>& cylinder_coordinate,
|
||||
const blitz::TinyVector<double,3>& dx)
|
||||
{
|
||||
const double r_bin = std::floor(cylinder_coordinate(0)/dx(0));
|
||||
const double max_phi = 2*M_PI;
|
||||
const double phi_bin = std::floor(std::fmod(cylinder_coordinate(1),max_phi) /dx(1));
|
||||
const double z_bin = std::floor(cylinder_coordinate(2)/dx(2));
|
||||
return blitz::TinyVector<int,3>(r_bin, phi_bin, z_bin);
|
||||
}
|
||||
|
||||
blitz::TinyVector<double,3> CoordinateConversion::cylinderCoordinate(
|
||||
const blitz::TinyVector<double,3>& cartesian_coordinate)
|
||||
{
|
||||
const double x = cartesian_coordinate(0) - cylinder_origin(0);
|
||||
const double y = cartesian_coordinate(1) - cylinder_origin(1);
|
||||
const double z = cartesian_coordinate(2) - cylinder_origin(2);
|
||||
const double radius = std::sqrt(x*x + y*y);
|
||||
const double phi = std::atan2(y,x);
|
||||
|
||||
return blitz::TinyVector<double,3>(
|
||||
radius,
|
||||
phi > 0? phi : 2*M_PI+phi,
|
||||
z);
|
||||
}
|
||||
|
||||
blitz::TinyVector<double,3> CoordinateConversion::cartesianBase(
|
||||
const blitz::TinyVector<double,3>& cylinder_vector,
|
||||
const blitz::TinyVector<double,3>& cylinder_coordinate)
|
||||
{
|
||||
const double A_rho = std::cos(cylinder_coordinate(1))*cylinder_vector(0)
|
||||
- std::sin(cylinder_coordinate(1))*cylinder_vector(1);
|
||||
const double A_phi = std::sin(cylinder_coordinate(1))*cylinder_vector(0)
|
||||
+ std::cos(cylinder_coordinate(1))*cylinder_vector(1);
|
||||
const double A_z = cylinder_vector(2);
|
||||
return blitz::TinyVector<double,3>(A_rho, A_phi, A_z);
|
||||
}
|
||||
|
||||
void CoordinateConversion::setCylinderOrigin(
|
||||
const blitz::TinyVector<double,3>& cylinder_origin)
|
||||
{
|
||||
CoordinateConversion::cylinder_origin = cylinder_origin;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
#ifndef COORDINATECONVERSION_H
|
||||
#define COORDINATECONVERSION_H
|
||||
|
||||
#include <blitz/array.h>
|
||||
|
||||
namespace CoordinateConversion {
|
||||
blitz::TinyVector<int,3> cylinderBin(
|
||||
const blitz::TinyVector<double,3>& position_cylinder,
|
||||
const blitz::TinyVector<double,3>& dx);
|
||||
|
||||
void setCylinderOrigin(const blitz::TinyVector<double,3>& cylinder_origin);
|
||||
static blitz::TinyVector<double,3> cylinder_origin(0., 0., 0.);
|
||||
|
||||
blitz::TinyVector<double,3> cylinderCoordinate(
|
||||
const blitz::TinyVector<double,3>& cartesian_coordinate);
|
||||
|
||||
blitz::TinyVector<double,3> cartesianBase(
|
||||
const blitz::TinyVector<double,3>& cylinder_vector,
|
||||
const blitz::TinyVector<double,3>& cylinder_coordinate);
|
||||
};
|
||||
|
||||
|
||||
#endif /* COORDINATECONVERSION_H */
|
||||
@@ -0,0 +1,22 @@
|
||||
#ifndef ELECTICFIELDFACTORY_H
|
||||
#define ELECTICFIELDFACTORY_H
|
||||
|
||||
#include "electricField.h"
|
||||
#include <string>
|
||||
#include <memory>
|
||||
|
||||
namespace ElectricFieldFactory {
|
||||
std::unique_ptr<ElectricField> build(
|
||||
std::string filename,
|
||||
double cylinder_radius,
|
||||
double cylinder_height);
|
||||
|
||||
blitz::Array<double,3> read(std::string filename, std::string dataset_path);
|
||||
|
||||
blitz::TinyVector<double,3> discretize(
|
||||
const blitz::TinyVector<int,3>& nx,
|
||||
double cylinder_radius,
|
||||
double cylinder_height);
|
||||
};
|
||||
|
||||
#endif /* ELECTICFIELDFACTORY_H */
|
||||
@@ -0,0 +1,34 @@
|
||||
#include "electricField.h"
|
||||
#include "CoordinateConversion.h"
|
||||
|
||||
ElectricField::ElectricField(
|
||||
const blitz::Array<double,3>& Er,
|
||||
const blitz::Array<double,3>& Ephi,
|
||||
const blitz::Array<double,3>& Ez,
|
||||
const blitz::TinyVector<double,3>& dx) :
|
||||
Er_(Er.copy()),
|
||||
Ephi_(Ephi.copy()),
|
||||
Ez_(Ez.copy()),
|
||||
dx_(dx)
|
||||
{}
|
||||
|
||||
blitz::TinyVector<double,3> ElectricField::value(
|
||||
const blitz::TinyVector<double,3>& cylinder_coordinate) const
|
||||
{
|
||||
const blitz::TinyVector<int,3> bin = CoordinateConversion::cylinderBin(
|
||||
cylinder_coordinate,
|
||||
dx_);
|
||||
return value(bin);
|
||||
}
|
||||
|
||||
blitz::TinyVector<double,3> ElectricField::value(
|
||||
const blitz::TinyVector<int,3>& bin) const
|
||||
{
|
||||
if(Er_.isInRange(bin)){
|
||||
return blitz::TinyVector<double,3>(Er_(bin), Ephi_(bin), Ez_(bin));
|
||||
}
|
||||
else{
|
||||
return blitz::TinyVector<double,3>(0., 0., 0.);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
#ifndef ELECTRICFIELD_H
|
||||
#define ELECTRICFIELD_H
|
||||
|
||||
#include <blitz/array.h>
|
||||
#include <string>
|
||||
|
||||
class ElectricField {
|
||||
public:
|
||||
ElectricField(
|
||||
const blitz::Array<double,3>& Er,
|
||||
const blitz::Array<double,3>& Ephi,
|
||||
const blitz::Array<double,3>& Ez,
|
||||
const blitz::TinyVector<double,3>& dx);
|
||||
|
||||
blitz::TinyVector<double,3> value(
|
||||
const blitz::TinyVector<double,3>& cylinder_coordinate) const;
|
||||
|
||||
blitz::TinyVector<double,3> value(const blitz::TinyVector<int,3>& bin) const;
|
||||
|
||||
private:
|
||||
// todo: make sure we use fast axis on z to reduce acess time
|
||||
const blitz::Array<double,3> Er_;
|
||||
const blitz::Array<double,3> Ephi_;
|
||||
const blitz::Array<double,3> Ez_;
|
||||
|
||||
const blitz::TinyVector<double,3> dx_;
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif /* ELECTRICFIELD_H */
|
||||
@@ -0,0 +1,70 @@
|
||||
#include "elecrticFieldFactory.h"
|
||||
|
||||
#include "HighFive/include/highfive/H5File.hpp"
|
||||
#include "HighFive/include/highfive/H5DataSet.hpp"
|
||||
#include "HighFive/include/highfive/H5DataSpace.hpp"
|
||||
|
||||
#include <vector>
|
||||
#include <array>
|
||||
|
||||
std::unique_ptr<ElectricField> ElectricFieldFactory::build(
|
||||
std::string filename,
|
||||
double cylinder_radius,
|
||||
double cylinder_height)
|
||||
{
|
||||
std::string dataset_path_Er("/Er");
|
||||
std::string dataset_path_Ez("/Ez");
|
||||
|
||||
blitz::Array<double,3> Er = read(filename, dataset_path_Er);
|
||||
blitz::Array<double,3> Ez = read(filename, dataset_path_Ez);
|
||||
blitz::Array<double,3> Ephi(Er.shape());
|
||||
Ephi = 0.;
|
||||
|
||||
blitz::TinyVector<int,3> nx( Er.shape()(0), 1, Er.shape()(2));
|
||||
|
||||
|
||||
blitz::TinyVector<double,3> dx = discretize(
|
||||
nx, cylinder_radius, cylinder_height);
|
||||
|
||||
return std::unique_ptr<ElectricField>(
|
||||
new ElectricField(Er, Ephi, Ez, dx));
|
||||
}
|
||||
|
||||
blitz::Array<double,3> ElectricFieldFactory::read(
|
||||
std::string filename, std::string dataset_path)
|
||||
{
|
||||
|
||||
HighFive::File f(filename, HighFive::File::ReadOnly);
|
||||
HighFive::DataSet dataset = f.getDataSet(dataset_path);
|
||||
|
||||
std::vector<std::vector<double>> data;
|
||||
dataset.read(data);
|
||||
|
||||
const int nr = data[0].size();
|
||||
const int nz = data.size();
|
||||
const int nphi = 1;
|
||||
|
||||
blitz::Array<double,3> data_3d(nr, nphi, nz);
|
||||
data_3d = 0.;
|
||||
|
||||
for(int ri = 0; ri<data_3d.shape()(0); ++ri){
|
||||
for(int phii = 0; phii < data_3d.shape()(1); ++phii){
|
||||
for(int zi = 0; zi< data_3d.shape()(2); ++zi){
|
||||
data_3d(ri, phii, zi) = data[zi][ri];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return data_3d.copy();
|
||||
}
|
||||
|
||||
blitz::TinyVector<double,3> ElectricFieldFactory::discretize(
|
||||
const blitz::TinyVector<int,3>& nx,
|
||||
double cylinder_radius,
|
||||
double cylinder_height)
|
||||
{
|
||||
return blitz::TinyVector<double,3>(
|
||||
cylinder_radius/nx(0),
|
||||
2*M_PI/nx(1),
|
||||
cylinder_height/nx(2));
|
||||
}
|
||||
@@ -0,0 +1,218 @@
|
||||
#include "catch.hpp"
|
||||
|
||||
#include "electricField.h"
|
||||
#include "elecrticFieldFactory.h"
|
||||
#include "CoordinateConversion.h"
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <memory>
|
||||
|
||||
#include "HighFive/include/highfive/H5File.hpp"
|
||||
#include "HighFive/include/highfive/H5DataSet.hpp"
|
||||
#include "HighFive/include/highfive/H5DataSpace.hpp"
|
||||
|
||||
TEST_CASE("ElectricField", "[ElectricField]"){
|
||||
const blitz::TinyVector<double,3> cyl_origin(0., 0., 1.);
|
||||
CoordinateConversion::setCylinderOrigin(cyl_origin);
|
||||
|
||||
SECTION("Coordinate Conversion"){
|
||||
const blitz::TinyVector<double,3> cyl_origin(0., 0., 1.);
|
||||
CoordinateConversion::setCylinderOrigin(cyl_origin);
|
||||
|
||||
SECTION("At zero y, radius is x coordinate"){
|
||||
const blitz::TinyVector<double,3> cart(1., 0., 0.);
|
||||
const blitz::TinyVector<double,3> cyl =
|
||||
CoordinateConversion::cylinderCoordinate(cart);
|
||||
REQUIRE(cyl(0) == cart(0));
|
||||
}
|
||||
SECTION("z values stay the same, exept offset"){
|
||||
const blitz::TinyVector<double,3> cart(0., 0., 1.);
|
||||
const blitz::TinyVector<double,3> cyl =
|
||||
CoordinateConversion::cylinderCoordinate(cart);
|
||||
REQUIRE(cyl(2) == cart(2)-cyl_origin(2));
|
||||
}
|
||||
SECTION("Radius is converted correctly"){
|
||||
const blitz::TinyVector<double,3> cart(3.,4., 1.2);
|
||||
const blitz::TinyVector<double,3> cyl =
|
||||
CoordinateConversion::cylinderCoordinate(cart);
|
||||
REQUIRE(cyl(0) == 5.);
|
||||
}
|
||||
SECTION("Angle of diagonal is correct"){
|
||||
const blitz::TinyVector<double,3> cart(1.,1., 1.2);
|
||||
const blitz::TinyVector<double,3> cyl =
|
||||
CoordinateConversion::cylinderCoordinate(cart);
|
||||
REQUIRE(cyl(1) == M_PI/4.);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
SECTION("Bin determination"){
|
||||
const blitz::TinyVector<double,3> cyl_origin(0., 0., 0.);
|
||||
CoordinateConversion::setCylinderOrigin(cyl_origin);
|
||||
|
||||
const blitz::TinyVector<double,3> dx(1., M_PI, 2.);
|
||||
|
||||
SECTION("Positions in center of first bin will result in first bin"){
|
||||
const blitz::TinyVector<double,3> cyl(
|
||||
0.5, 0.5*M_PI, 1.5);
|
||||
const blitz::TinyVector<int,3> bins =
|
||||
CoordinateConversion::cylinderBin(cyl, dx);
|
||||
|
||||
REQUIRE(bins(0) == 0);
|
||||
REQUIRE(bins(1) == 0);
|
||||
REQUIRE(bins(2) == 0);
|
||||
}
|
||||
|
||||
SECTION("Positions in center of second bin will result in first bin"){
|
||||
const blitz::TinyVector<double,3> cyl(
|
||||
1.5, 1.5*M_PI, 2.5);
|
||||
const blitz::TinyVector<int,3> bins =
|
||||
CoordinateConversion::cylinderBin(cyl, dx);
|
||||
|
||||
REQUIRE(bins(0) == 1);
|
||||
REQUIRE(bins(1) == 1);
|
||||
REQUIRE(bins(2) == 1);
|
||||
}
|
||||
|
||||
SECTION("phi value over 2 pi will be reduced to values below 2 pi"){
|
||||
const blitz::TinyVector<double,3> cyl(
|
||||
1.5, 2.5*M_PI, 2.5);
|
||||
const blitz::TinyVector<int,3> bins =
|
||||
CoordinateConversion::cylinderBin(cyl, dx);
|
||||
REQUIRE(bins(1) == 0);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
SECTION("Read Data from File"){
|
||||
std::string filename = "data/test.h5";
|
||||
std::string dataset_path = "/test_field";
|
||||
|
||||
// create file to read back
|
||||
HighFive::File file(filename, HighFive::File::Overwrite);
|
||||
|
||||
std::vector<std::vector<double>> values = {
|
||||
{1.0, 2.0, 4.0, 8.0, 16.0},
|
||||
{32.0, 64.0, 128.0, 256.0, 512.0},
|
||||
{1.5, 2.5, 4.5, 8.5, 16.5}};
|
||||
|
||||
HighFive::DataSet dataset =
|
||||
file.createDataSet<double>(dataset_path, HighFive::DataSpace::From(values));
|
||||
|
||||
dataset.write(values);
|
||||
|
||||
SECTION("Read value will throw if there is no file"){
|
||||
REQUIRE_NOTHROW(ElectricFieldFactory::read(filename, dataset_path));
|
||||
REQUIRE_THROWS(ElectricFieldFactory::read("", dataset_path));
|
||||
}
|
||||
SECTION("Read value will throw if there is no data_path"){
|
||||
REQUIRE_NOTHROW(ElectricFieldFactory::read(filename, dataset_path));
|
||||
REQUIRE_THROWS(ElectricFieldFactory::read(filename, ""));
|
||||
}
|
||||
SECTION("Read value reads correct value"){
|
||||
blitz::Array<double,3> data = ElectricFieldFactory::read(
|
||||
filename, dataset_path);
|
||||
|
||||
REQUIRE(data(0,0,0) == 1.0);
|
||||
REQUIRE(data(1,0,0) == 2.0);
|
||||
REQUIRE(data(0,0,1) == 32.0);
|
||||
REQUIRE(data(4,0,2) == 16.5);
|
||||
}
|
||||
};
|
||||
|
||||
SECTION("Electric Field"){
|
||||
blitz::Array<double,3> Er(5,1,10);
|
||||
Er = 0.;
|
||||
blitz::Array<double,3> Ephi(5,1,10);
|
||||
Ephi = 1.;
|
||||
blitz::Array<double,3> Ez(5,1,10);
|
||||
Ez = -1.;
|
||||
|
||||
blitz::TinyVector<double,3> dx(1.0, 2*M_PI, 2.0);
|
||||
// -> R = 5.0, H = 20.0
|
||||
|
||||
SECTION("Constructor"){
|
||||
REQUIRE_NOTHROW(ElectricField(Er, Ephi, Ez, dx));
|
||||
}
|
||||
SECTION("Values"){
|
||||
ElectricField E(Er, Ephi, Ez, dx);
|
||||
blitz::TinyVector<int,3> bin(0,0,0);
|
||||
REQUIRE(E.value(bin)(0) == 0.);
|
||||
REQUIRE(E.value(bin)(1) == 1.);
|
||||
REQUIRE(E.value(bin)(2) == -1.);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
SECTION("Factory of Electric Field"){
|
||||
std::string filename = "data/test.h5";
|
||||
std::string dataset_path_Er = "/Er";
|
||||
std::string dataset_path_Ez = "/Ez";
|
||||
|
||||
// create file to read back
|
||||
HighFive::File file(filename, HighFive::File::Overwrite);
|
||||
|
||||
std::vector<std::vector<double>> values_Er = {
|
||||
{1.0, 2.0, 4.0, 8.0, 16.0},
|
||||
{32.0, 64.0, 128.0, 256.0, 512.0},
|
||||
{1.5, 2.5, 4.5, 8.5, 16.5}};
|
||||
HighFive::DataSet dataset_Er =
|
||||
file.createDataSet<double>(dataset_path_Er, HighFive::DataSpace::From(values_Er));
|
||||
dataset_Er.write(values_Er);
|
||||
|
||||
std::vector<std::vector<double>> values_Ez = {
|
||||
{-1.0, -2.0, -4.0, -8.0, -16.0},
|
||||
{-32.0, -64.0, -128.0, -256.0, -512.0},
|
||||
{-1.5, -2.5, -4.5, -8.5, -16.5}};
|
||||
HighFive::DataSet dataset_Ez =
|
||||
file.createDataSet<double>(dataset_path_Ez, HighFive::DataSpace::From(values_Ez));
|
||||
dataset_Ez.write(values_Ez);
|
||||
|
||||
SECTION("Reads data from file"){
|
||||
|
||||
std::unique_ptr<ElectricField> E = ElectricFieldFactory::build(
|
||||
filename,
|
||||
0.045,
|
||||
13);
|
||||
|
||||
REQUIRE(E->value(blitz::TinyVector<int,3>(0,0,0))(0) == 1.0);
|
||||
REQUIRE(E->value(blitz::TinyVector<int,3>(0,0,0))(1) == 0.0);
|
||||
REQUIRE(E->value(blitz::TinyVector<int,3>(0,0,0))(2) == -1.0);
|
||||
|
||||
REQUIRE(E->value(blitz::TinyVector<int,3>(2,0,2))(0) == 4.5);
|
||||
REQUIRE(E->value(blitz::TinyVector<int,3>(2,0,2))(1) == 0.0);
|
||||
REQUIRE(E->value(blitz::TinyVector<int,3>(2,0,2))(2) == -4.5);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
SECTION("Create Test Field"){
|
||||
std::string filename = "data/E_field.h5";
|
||||
std::string dataset_path_Er = "/Er";
|
||||
std::string dataset_path_Ez = "/Ez";
|
||||
|
||||
// create file to read back
|
||||
HighFive::File file(filename, HighFive::File::Overwrite);
|
||||
|
||||
std::vector<std::vector<double>> values_Er = {
|
||||
// r rows
|
||||
// z colums
|
||||
{0., 1.},
|
||||
{0., 1.}
|
||||
};
|
||||
HighFive::DataSet dataset_Er =
|
||||
file.createDataSet<double>(dataset_path_Er, HighFive::DataSpace::From(values_Er));
|
||||
dataset_Er.write(values_Er);
|
||||
|
||||
std::vector<std::vector<double>> values_Ez = {
|
||||
// r rows
|
||||
// z colums
|
||||
{-1.0, -1.0},
|
||||
{-2.0, -2.0}
|
||||
};
|
||||
HighFive::DataSet dataset_Ez =
|
||||
file.createDataSet<double>(dataset_path_Ez, HighFive::DataSpace::From(values_Ez));
|
||||
dataset_Ez.write(values_Ez);
|
||||
}
|
||||
}
|
||||
@@ -27,15 +27,20 @@ inline void E_Mover_E_Drift::do_E_calculus(Particle *movePart, const vec3 &oldLo
|
||||
double t_s = 1/macro_sigma_m/calc_vec3_abs(movePart->get_v_ms());
|
||||
vec3 newLoc_m = movePart->get_x_m();
|
||||
vec3 E_Vm = 0.5 * (Katrin_Fields::getElField_Vm(oldLoc_m) + Katrin_Fields::getElField_Vm(newLoc_m));
|
||||
|
||||
double B_T = calc_vec3_abs( 0.5 * (Katrin_Fields::getMagField_T(oldLoc_m) + Katrin_Fields::getMagField_T(newLoc_m)) );
|
||||
|
||||
double E_rad_Vm = calc_r_m(E_Vm);
|
||||
|
||||
double v_rad_ms = E_rad_Vm/B_T;
|
||||
vec3 loc_offset_m = E_Vm;
|
||||
loc_offset_m[2] = 0;
|
||||
loc_offset_m = loc_offset_m/calc_vec3_abs(loc_offset_m) * v_rad_ms * t_s;
|
||||
if((loc_offset_m(0) == 0.) && (loc_offset_m(1) == 0.)){
|
||||
loc_offset_m = 0.;
|
||||
} else{
|
||||
loc_offset_m(2) = 0.;
|
||||
loc_offset_m = loc_offset_m/calc_vec3_abs(loc_offset_m) * v_rad_ms * t_s;
|
||||
}
|
||||
movePart->set_x_m(newLoc_m + loc_offset_m);
|
||||
|
||||
|
||||
vec3 v_boost_ms = vec3(0,0, movePart->get_Z()*e_C/movePart->get_m_eV()*E_Vm[2] * t_s/c_ms/c_ms);
|
||||
movePart->set_v_ms(movePart->get_v_ms() + v_boost_ms);
|
||||
}
|
||||
|
||||
+29
-10
@@ -1,15 +1,34 @@
|
||||
//
|
||||
// katrin_fields.cpp
|
||||
// mc_electron
|
||||
//
|
||||
// Created by Christian Reiling on 03.05.19.
|
||||
// Copyright © 2019 Christian Reiling. All rights reserved.
|
||||
//
|
||||
|
||||
#include "katrin_fields.hpp"
|
||||
|
||||
#include "read_system.h"
|
||||
#include "CoordinateConversion.h"
|
||||
#include "elecrticFieldFactory.h"
|
||||
|
||||
double Katrin_Fields::wgtsMagField_T = 0.;
|
||||
std::shared_ptr<ElectricField> Katrin_Fields::E_field_ptr = nullptr;
|
||||
|
||||
const double Katrin_Fields::wgtsMagField_T = load_parameter("BFIELD");
|
||||
Vec3_Container Katrin_Fields::e_field(1000, 50, 20, get_data_path() + "e_field.dat");
|
||||
blitz::TinyVector<double,3> Katrin_Fields::getMagField_T(
|
||||
blitz::TinyVector<double,3> cartesian_m)
|
||||
{
|
||||
return blitz::TinyVector<double,3>(0., 0., wgtsMagField_T);
|
||||
}
|
||||
|
||||
blitz::TinyVector<double,3> Katrin_Fields::getElField_Vm(
|
||||
blitz::TinyVector<double,3> cartesian_m)
|
||||
{
|
||||
// todo: particles in cylinder coordinates
|
||||
// no conversion back and forth necessary
|
||||
|
||||
const blitz::TinyVector<double,3> cylinder =
|
||||
CoordinateConversion::cylinderCoordinate(cartesian_m);
|
||||
const blitz::TinyVector<double,3> E_cyl =
|
||||
E_field_ptr->value(cylinder);
|
||||
const blitz::TinyVector<double,3> E_cart =
|
||||
CoordinateConversion::cartesianBase(
|
||||
E_cyl,
|
||||
cylinder);
|
||||
|
||||
return E_field_ptr->value(cylinder);
|
||||
|
||||
//return blitz::TinyVector<double,3>(0., 0., 0.01);
|
||||
}
|
||||
+10
-27
@@ -1,36 +1,19 @@
|
||||
//
|
||||
// katrin_fields.hpp
|
||||
// mc_electron
|
||||
//
|
||||
// Created by Christian Reiling on 03.05.19.
|
||||
// Copyright © 2019 Christian Reiling. All rights reserved.
|
||||
//
|
||||
|
||||
#ifndef katrin_fields_hpp
|
||||
#define katrin_fields_hpp
|
||||
|
||||
#include "error_types.h"
|
||||
#include "read_system.h"
|
||||
#include "vec3_container.hpp"
|
||||
|
||||
|
||||
#include "electricField.h"
|
||||
#include <memory>
|
||||
#include "blitz/array.h"
|
||||
class Katrin_Fields {
|
||||
static const double wgtsMagField_T;
|
||||
static Vec3_Container e_field;
|
||||
public:
|
||||
static double wgtsMagField_T;
|
||||
static std::shared_ptr<ElectricField> E_field_ptr;
|
||||
|
||||
public:
|
||||
Katrin_Fields() {};
|
||||
static blitz::TinyVector<double,3> getMagField_T(
|
||||
blitz::TinyVector<double,3> cartesian_m);
|
||||
|
||||
static vec3 getMagField_T(vec3 loc_m) {
|
||||
return vec3(0,0,wgtsMagField_T);
|
||||
}
|
||||
|
||||
static vec3 getElField_Vm(vec3 loc_m) {
|
||||
return e_field.get_data (loc_m);
|
||||
//return vec3(0,0,0);
|
||||
}
|
||||
|
||||
static blitz::TinyVector<double,3> getElField_Vm(
|
||||
blitz::TinyVector<double,3> cartesian_m);
|
||||
};
|
||||
|
||||
|
||||
#endif /* katrin_fields_hpp */
|
||||
|
||||
+3
-3
@@ -28,10 +28,10 @@ int main(int argc, char *argv[]) {
|
||||
if (rank == 0) sleep(600);
|
||||
*/
|
||||
|
||||
Simulation Sim;
|
||||
|
||||
Simulation sim;
|
||||
|
||||
int start_time = MPI_Wtime();
|
||||
Sim.doit();
|
||||
sim.doit();
|
||||
if (rank == 0) {
|
||||
cout<<"Total Time: "<<MPI_Wtime()-start_time<<" s\n";
|
||||
}
|
||||
|
||||
+25
-5
@@ -10,17 +10,22 @@ OBJS := particle_looper.o \
|
||||
population_builder.o \
|
||||
mover_builder.o \
|
||||
interaction_builder.o BED_eT2_ionization.o uehara_eT2_elastic.o rutherford_elastic.o \
|
||||
terminator_builder.o
|
||||
terminator_builder.o \
|
||||
electricField.o \
|
||||
electricFieldFactory.o \
|
||||
CoordinateConversion.o \
|
||||
simulation_init.o \
|
||||
|
||||
|
||||
CXXFLAGS = $(X_OFLAGS) -I.. $(X_INC) -std=c++11
|
||||
|
||||
MPXFLAGS = $(X_OFLAGS) -I.. $(X_INC) $(X_HDF5P_INC) -std=c++11
|
||||
MPXFLAGS = $(X_OFLAGS) -I.. $(X_INC) $(X_HDF5P_INC) -std=c++11
|
||||
#MPXFLAGS = -g -O0 -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
|
||||
LOADLIBES = -lblitz -lm -g -DBZ_DEBUG
|
||||
|
||||
TARGETS = mcelectron
|
||||
|
||||
@@ -33,8 +38,23 @@ mcelectron_serial: main_serial.o simulation_serial.o $(OBJS)
|
||||
$(CXX) -o $@ $^ $(LDFLAGS) $(LOADLIBES)
|
||||
|
||||
%.o : %.cpp
|
||||
$(MPICXX) -c $< $(MPXFLAGS) -o $@ -g
|
||||
$(MPICXX) -c $< $(MPXFLAGS) -o $@
|
||||
|
||||
|
||||
|
||||
TARGETS_TEST = catch
|
||||
ctest: $(TARGETS_TEST)
|
||||
OBJECTS_TEST = electric_field_test.o \
|
||||
electricField.o \
|
||||
electricFieldFactory.o \
|
||||
CoordinateConversion.o
|
||||
|
||||
catch: test_main.o $(OBJECTS_TEST)
|
||||
$(MPICXX) -o $@ $^ $(LDFLAGS) $(LOADLIBES)
|
||||
|
||||
|
||||
clean:
|
||||
rm *.o mcelectron mcelectron_serial
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -31,9 +31,15 @@ inline void Positive_Mover_E_Drift::do_E_calculus(Particle *movePart, const vec3
|
||||
|
||||
double E_rad_Vm = calc_r_m(E_Vm);
|
||||
double v_rad_ms = E_rad_Vm/B_T;
|
||||
|
||||
vec3 loc_offset_m = E_Vm;
|
||||
loc_offset_m[2] = 0;
|
||||
loc_offset_m = loc_offset_m/calc_vec3_abs(loc_offset_m) * v_rad_ms * t_s;
|
||||
if((loc_offset_m(0) == 0.) && (loc_offset_m(1) == 0.)){
|
||||
loc_offset_m = 0.;
|
||||
} else{
|
||||
loc_offset_m(2) = 0.;
|
||||
loc_offset_m = loc_offset_m/calc_vec3_abs(loc_offset_m) * v_rad_ms * t_s;
|
||||
}
|
||||
|
||||
movePart->set_x_m(newLoc_m + loc_offset_m);
|
||||
|
||||
vec3 v_boost_ms = vec3(0,0, movePart->get_Z()*e_C/movePart->get_m_eV()*E_Vm[2] * t_s/c_ms/c_ms);
|
||||
|
||||
@@ -171,7 +171,7 @@ inline std::string get_homebase() {
|
||||
}
|
||||
|
||||
inline std::string get_data_path() {
|
||||
return get_homebase() + "src/mc_electron/data/";
|
||||
return get_homebase() + "src/karl/data/";
|
||||
}
|
||||
|
||||
inline std::string remove_cat (std::string cat_string) {
|
||||
|
||||
@@ -23,6 +23,8 @@ Simulation::Simulation() {
|
||||
MPI_Comm_rank(MPI_COMM_WORLD, &mpi_rank);
|
||||
looper.init(calc_seed(), calc_ID_offset(), calc_outfile_path());
|
||||
init_pop_arrays();
|
||||
init();
|
||||
std::cout << "Init Done" << std::endl;
|
||||
}
|
||||
|
||||
void Simulation::init_pop_arrays() { // Init C-arrays used for MPI-Allgather commands depending on Populations sizes
|
||||
|
||||
@@ -53,6 +53,7 @@ private:
|
||||
|
||||
public:
|
||||
void doit();
|
||||
void init();
|
||||
private:
|
||||
void do_cycle(long int number_total, long int step_size, bool logging);
|
||||
void do_decays(const long int &number_decays, const bool &logging);
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
#include "simulation.hpp"
|
||||
#include "katrin_fields.hpp"
|
||||
|
||||
#include "elecrticFieldFactory.h"
|
||||
#include "CoordinateConversion.h"
|
||||
|
||||
void initCoordinateConversion()
|
||||
{
|
||||
CoordinateConversion::setCylinderOrigin(
|
||||
blitz::TinyVector<double,3>(0., 0., -3.));
|
||||
}
|
||||
|
||||
void initKatrinFields() {
|
||||
Katrin_Fields::wgtsMagField_T = load_parameter("BFIELD");
|
||||
|
||||
Katrin_Fields::E_field_ptr = ElectricFieldFactory::build(
|
||||
"/home/jonas/new_workspace/Coding/Output/KARL/ElectricField/E_field.h5",
|
||||
0.045,
|
||||
13.0);
|
||||
}
|
||||
|
||||
void Simulation::init()
|
||||
{
|
||||
initCoordinateConversion();
|
||||
initKatrinFields();
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
#define CATCH_CONFIG_MAIN
|
||||
#include "catch.hpp"
|
||||
|
||||
TEST_CASE( "1: All tests cases reside in other .cpp files (empty)", "[multi-file:1]" ){
|
||||
}
|
||||
@@ -36,8 +36,8 @@ X_MKL_LIBS = -lmkl_em64t -lmkl_cdft -lmkl_cdft_core -lmkl_intel_lp64 -lmkl_bla
|
||||
X_HDF_LIBS = -lmfhdf -ldf -lz -ljpeg
|
||||
X_HDF5_LIBS = -L/usr/lib/x86_64-linux-gnu/hdf5/serial -lz -lhdf5_cpp -lhdf5_hl -lhdf5
|
||||
X_HDF5_INC = -I/usr/include/hdf5/serial
|
||||
X_HDF5P_LIBS = -L/usr/lib/x86_64-linux-gnu/hdf5/openmpi -lz -lhdf5_hl -lhdf5
|
||||
X_HDF5P_INC = -I/usr/include/hdf5/openmpi
|
||||
X_HDF5P_LIBS = -L$(HDF5_LIB_DIR) -lz -lhdf5_hl -lhdf5
|
||||
X_HDF5P_INC = -I$(HDF5_INC_DIR)
|
||||
|
||||
# FFTW2
|
||||
X_FFTW2_LIBS = -lfftw
|
||||
|
||||
Reference in New Issue
Block a user