Merge branch 'time_resolution' of masterduck.fspanier.de:katrin/karl into time_resolution
This commit is contained in:
@@ -23,12 +23,15 @@ class ElectricField {
|
|||||||
|
|
||||||
class MagneticField {
|
class MagneticField {
|
||||||
public:
|
public:
|
||||||
MagneticField(std::shared_ptr<VectorField> field);
|
MagneticField(std::shared_ptr<VectorField> field,
|
||||||
|
std::shared_ptr<VectorField> gradient);
|
||||||
|
|
||||||
CylinderVector value(const Coordinate& position) const;
|
CylinderVector value(const Coordinate& position) const;
|
||||||
|
CylinderVector gradientValue(const Coordinate& position) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::shared_ptr<VectorField> field_;
|
std::shared_ptr<VectorField> field_;
|
||||||
|
std::shared_ptr<VectorField> gradient_;
|
||||||
};
|
};
|
||||||
|
|
||||||
class GravityField {
|
class GravityField {
|
||||||
|
|||||||
@@ -47,6 +47,8 @@ class Particle {
|
|||||||
void resetTimeInBin();
|
void resetTimeInBin();
|
||||||
double timeInBin() const;
|
double timeInBin() const;
|
||||||
|
|
||||||
|
long int ID() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
CartesianVector velocity_;
|
CartesianVector velocity_;
|
||||||
CartesianCoordinate position_;
|
CartesianCoordinate position_;
|
||||||
|
|||||||
@@ -7,7 +7,8 @@ namespace generator {
|
|||||||
std::shared_ptr<MagneticField> magneticField(json_t* object) {
|
std::shared_ptr<MagneticField> magneticField(json_t* object) {
|
||||||
DEBUG_LEVEL_2("Generating magnetic field.");
|
DEBUG_LEVEL_2("Generating magnetic field.");
|
||||||
return std::shared_ptr<MagneticField>(new MagneticField(
|
return std::shared_ptr<MagneticField>(new MagneticField(
|
||||||
buildVectorField(json_object_by_path(object, {"VectorField"}))));
|
buildVectorField(json_object_by_path(object, {"VectorField"})),
|
||||||
|
buildVectorField(json_object_by_path(object, {"GradientField"}))));
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<MagneticField> magneticField(Parameter& parameter) {
|
std::shared_ptr<MagneticField> magneticField(Parameter& parameter) {
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ blitz::Array<double, 3> readComponentFromFile(json_t* object, int component) {
|
|||||||
std::string absolute_filename =
|
std::string absolute_filename =
|
||||||
readAbsoluteFilename(json_object_by_path(object, {"PathToH5"}));
|
readAbsoluteFilename(json_object_by_path(object, {"PathToH5"}));
|
||||||
std::string key = json_string(
|
std::string key = json_string(
|
||||||
json_array_get(json_object_by_path(object, {"PathToH5"}), component));
|
json_array_get(json_object_by_path(object, {"Keys"}), component));
|
||||||
|
|
||||||
Hdf5Reader reader(absolute_filename);
|
Hdf5Reader reader(absolute_filename);
|
||||||
return reader.readD3Double(key);
|
return reader.readD3Double(key);
|
||||||
|
|||||||
@@ -16,13 +16,18 @@ void ElectricField::updateDynamicField(std::shared_ptr<VectorField> field) {
|
|||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
MagneticField::MagneticField(std::shared_ptr<VectorField> field)
|
MagneticField::MagneticField(std::shared_ptr<VectorField> field,
|
||||||
: field_(field) {}
|
std::shared_ptr<VectorField> gradient)
|
||||||
|
: field_(field), gradient_(gradient) {}
|
||||||
|
|
||||||
CylinderVector MagneticField::value(const Coordinate& position) const {
|
CylinderVector MagneticField::value(const Coordinate& position) const {
|
||||||
return field_->value(position);
|
return field_->value(position);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CylinderVector MagneticField::gradientValue(const Coordinate& position) const {
|
||||||
|
return gradient_->value(position);
|
||||||
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|||||||
@@ -199,7 +199,7 @@ void DriftMover::move(particle::Particle* particle,
|
|||||||
|
|
||||||
old_kinetic_energy = particle->kineticEnergy_eV();
|
old_kinetic_energy = particle->kineticEnergy_eV();
|
||||||
|
|
||||||
const blitz::TinyVector<double, 3> force_over_charge =
|
blitz::TinyVector<double, 3> force_over_charge =
|
||||||
electric_field->value(old_position).cartesianEntries(old_position) +
|
electric_field->value(old_position).cartesianEntries(old_position) +
|
||||||
gravity_field->value(old_position).cartesianEntries(old_position) *
|
gravity_field->value(old_position).cartesianEntries(old_position) *
|
||||||
particle->mass_kg() / particle->charge_C();
|
particle->mass_kg() / particle->charge_C();
|
||||||
@@ -207,6 +207,9 @@ void DriftMover::move(particle::Particle* particle,
|
|||||||
const blitz::TinyVector<double, 3> B =
|
const blitz::TinyVector<double, 3> B =
|
||||||
magnetic_field->value(old_position).cartesianEntries(old_position);
|
magnetic_field->value(old_position).cartesianEntries(old_position);
|
||||||
const double B_norm = kinematic::norm(B);
|
const double B_norm = kinematic::norm(B);
|
||||||
|
|
||||||
|
const blitz::TinyVector<double, 3> gradB =
|
||||||
|
magnetic_field->gradientValue(old_position).cartesianEntries(old_position);
|
||||||
// Todo: add calculation of divB here
|
// Todo: add calculation of divB here
|
||||||
// use Kassiopeia paper for reference
|
// use Kassiopeia paper for reference
|
||||||
|
|
||||||
@@ -218,6 +221,17 @@ void DriftMover::move(particle::Particle* particle,
|
|||||||
kinematic::perpendicularVector(old_velocity.cartesianEntries(), B);
|
kinematic::perpendicularVector(old_velocity.cartesianEntries(), B);
|
||||||
const double v_perp_norm = kinematic::norm(v_perp);
|
const double v_perp_norm = kinematic::norm(v_perp);
|
||||||
|
|
||||||
|
// magnetic moment
|
||||||
|
const double magnetic_moment = (particle->mass_kg()*(v_perp_norm*v_perp_norm)/2)/B_norm;
|
||||||
|
|
||||||
|
force_over_charge += -(magnetic_moment / particle->charge_C() * gradB);
|
||||||
|
|
||||||
|
// curvature force
|
||||||
|
force_over_charge += -(particle->mass_kg()/particle->charge_C() *
|
||||||
|
(v_parallel_norm*v_parallel_norm) *
|
||||||
|
kinematic::perpendicularVector(gradB, B) /
|
||||||
|
B_norm);
|
||||||
|
|
||||||
const blitz::TinyVector<double, 3> v_drift = driftVelocity(force_over_charge, B);
|
const blitz::TinyVector<double, 3> v_drift = driftVelocity(force_over_charge, B);
|
||||||
const double v_drift_norm = kinematic::norm(v_drift);
|
const double v_drift_norm = kinematic::norm(v_drift);
|
||||||
|
|
||||||
@@ -234,6 +248,7 @@ void DriftMover::move(particle::Particle* particle,
|
|||||||
|
|
||||||
const blitz::TinyVector<double, 3> force_over_charge_parallel =
|
const blitz::TinyVector<double, 3> force_over_charge_parallel =
|
||||||
kinematic::parallelVector(force_over_charge, B);
|
kinematic::parallelVector(force_over_charge, B);
|
||||||
|
|
||||||
const blitz::TinyVector<double, 3> dv_electric =
|
const blitz::TinyVector<double, 3> dv_electric =
|
||||||
timestep * particle->charge_C() * force_over_charge_parallel / particle->mass_kg();
|
timestep * particle->charge_C() * force_over_charge_parallel / particle->mass_kg();
|
||||||
|
|
||||||
@@ -249,20 +264,43 @@ void DriftMover::move(particle::Particle* particle,
|
|||||||
|
|
||||||
const double gyro_frequency =
|
const double gyro_frequency =
|
||||||
particle->charge_C() * B_norm / particle->mass_kg();
|
particle->charge_C() * B_norm / particle->mass_kg();
|
||||||
const double total_rotation_angle = gyro_frequency * timestep;
|
const double total_rotation_angle = -gyro_frequency * timestep;
|
||||||
const blitz::TinyVector<double, 3> movement_around_gyro_center =
|
const blitz::TinyVector<double, 3> movement_around_gyro_center =
|
||||||
|
offset_to_gyro_center -
|
||||||
kinematic::rotateVector(offset_to_gyro_center, B,
|
kinematic::rotateVector(offset_to_gyro_center, B,
|
||||||
total_rotation_angle) -
|
total_rotation_angle);
|
||||||
offset_to_gyro_center;
|
|
||||||
|
|
||||||
const blitz::TinyVector<double, 3> v_perp_rotated =
|
const blitz::TinyVector<double, 3> v_perp_rotated =
|
||||||
kinematic::rotateVector(v_perp, B, total_rotation_angle);
|
kinematic::rotateVector(v_perp, B, total_rotation_angle);
|
||||||
|
|
||||||
|
const double v_parallel_norm_new = kinematic::norm(v_parallel + dv_electric);
|
||||||
|
// might be better to do after the actual movement and then just extract
|
||||||
|
// the position again from the particle
|
||||||
|
const blitz::TinyVector<double, 3> new_position = old_position.cartesianEntries()
|
||||||
|
+ movement_parallel
|
||||||
|
+ movement_drift
|
||||||
|
+ movement_around_gyro_center;
|
||||||
|
|
||||||
|
const blitz::TinyVector<double, 3> B_new =
|
||||||
|
magnetic_field->value(CartesianCoordinate(new_position)).
|
||||||
|
cartesianEntries(CartesianCoordinate(new_position));
|
||||||
|
|
||||||
|
const double v_perp_norm_new =
|
||||||
|
sqrt(2*magnetic_moment*kinematic::norm(B_new)/particle->mass_kg());
|
||||||
|
|
||||||
particle->move(CartesianCoordinate(movement_parallel + movement_drift +
|
particle->move(CartesianCoordinate(movement_parallel + movement_drift +
|
||||||
movement_around_gyro_center));
|
movement_around_gyro_center));
|
||||||
|
|
||||||
|
const blitz::TinyVector<double, 3> v_parallel_new =
|
||||||
|
kinematic::parallelVector(v_parallel + dv_electric, B_new);
|
||||||
|
const blitz::TinyVector<double, 3> v_perp_new =
|
||||||
|
kinematic::perpendicularVector(v_perp_rotated, B_new);
|
||||||
|
|
||||||
particle->velocity(
|
const blitz::TinyVector<double, 3> v_new =
|
||||||
CartesianVector(v_parallel + v_perp_rotated + dv_electric));
|
v_parallel_new/kinematic::norm(v_parallel_new)*v_parallel_norm_new +
|
||||||
|
v_perp_new/kinematic::norm(v_perp_new)*v_perp_norm_new;
|
||||||
|
|
||||||
|
particle->velocity(CartesianVector(v_new));
|
||||||
} else {
|
} else {
|
||||||
particle->move(CartesianCoordinate(movement_parallel + movement_drift));
|
particle->move(CartesianCoordinate(movement_parallel + movement_drift));
|
||||||
particle->velocity(CartesianVector(v_parallel + dv_electric));
|
particle->velocity(CartesianVector(v_parallel + dv_electric));
|
||||||
|
|||||||
@@ -111,4 +111,8 @@ double Particle::timeInBin() const {
|
|||||||
return time_in_bin_s_;
|
return time_in_bin_s_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
long int Particle::ID() const {
|
||||||
|
return id_;
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace particle
|
} // namespace particle
|
||||||
|
|||||||
Reference in New Issue
Block a user