Removed possibility of Nphi > 1
This commit is contained in:
@@ -7,14 +7,10 @@
|
||||
#include "simulation/species.h"
|
||||
#include "simulation/mpi_communication.h"
|
||||
|
||||
void CpuSynchronizer::sumToAll(blitz::Array<double, 4>& array,
|
||||
blitz::Array<double, 4>& last_sync_array) {
|
||||
void CpuSynchronizer::sumToAll(blitz::Array<double, 4>& array) {
|
||||
int size = array.size();
|
||||
blitz::Array<double, 4> delta(array.extent());
|
||||
delta = array - last_sync_array;
|
||||
MPI_Allreduce(MPI_IN_PLACE, delta.data(), size, MPI_DOUBLE,
|
||||
MPI_Allreduce(MPI_IN_PLACE, array.data(), size, MPI_DOUBLE,
|
||||
MPI_SUM, MPI_COMM_WORLD);
|
||||
last_sync_array += delta;
|
||||
}
|
||||
|
||||
void CpuSynchronizer::sumToAll(blitz::Array<double, 5>& array) {
|
||||
@@ -77,6 +73,14 @@ void CpuSynchronizer::sumToRoot(blitz::Array<double, 3>& array) {
|
||||
MPI_Reduce(array.data(), nullptr, size, MPI_DOUBLE, MPI_SUM, root, MPI_COMM_WORLD);
|
||||
}
|
||||
|
||||
void CpuSynchronizer::sumToRoot(blitz::Array<double, 2>& array) {
|
||||
int size = array.size();
|
||||
if(MpiCommunication::mpi_rank == root)
|
||||
MPI_Reduce(MPI_IN_PLACE, array.data(), size, MPI_DOUBLE, MPI_SUM, root, MPI_COMM_WORLD);
|
||||
else
|
||||
MPI_Reduce(array.data(), nullptr, size, MPI_DOUBLE, MPI_SUM, root, MPI_COMM_WORLD);
|
||||
}
|
||||
|
||||
void CpuSynchronizer::sumToRoot(long int& value) {
|
||||
int size = 1;
|
||||
if(MpiCommunication::mpi_rank == root) {
|
||||
@@ -110,8 +114,8 @@ void CpuSynchronizer::synchronize(Timer* timer, Timer* last_sync_timer) {
|
||||
// array storing the previous timestep
|
||||
void CpuSynchronizer::synchronize(DynamicDensityField* field) {
|
||||
if (field) {
|
||||
sumToAll(field->sync_time_in_bin_s_);
|
||||
field->time_in_bin_s_ = field->sync_time_in_bin_s_;
|
||||
sumToAll(field->sync_number_in_bin_);
|
||||
field->number_in_bin_ = field->sync_number_in_bin_;
|
||||
field->recalculateDensityArray();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,17 +21,16 @@ CurrentCollector::CurrentCollector(const CylinderBinning& position_binning,
|
||||
// sync_phi_positive_crossings(createCrossingsAzimuthal(position_binning))
|
||||
{}
|
||||
|
||||
blitz::Array<double, 3> CurrentCollector::createAreaLongitudinal(
|
||||
blitz::Array<double, 2> CurrentCollector::createAreaLongitudinal(
|
||||
const CylinderBinning& position_binning) {
|
||||
const blitz::TinyVector<int, 3> bin_index_min =
|
||||
const blitz::TinyVector<int, 2> bin_index_min =
|
||||
position_binning.binIndexMin();
|
||||
const blitz::TinyVector<int, 3> bin_index_max =
|
||||
const blitz::TinyVector<int, 2> bin_index_max =
|
||||
position_binning.binIndexMax();
|
||||
|
||||
blitz::Array<double, 3> area_z(
|
||||
blitz::Array<double, 2> area_z(
|
||||
blitz::Range(bin_index_min(0), bin_index_max(0)),
|
||||
blitz::Range(bin_index_min(1), bin_index_max(1)),
|
||||
blitz::Range(0, bin_index_max(2)));
|
||||
blitz::Range(0, bin_index_max(1)));
|
||||
|
||||
for (int ir = 0; ir <= area_z.ubound(0); ++ir) {
|
||||
const double dr = position_binning.stepsize()(0);
|
||||
@@ -39,106 +38,100 @@ blitz::Array<double, 3> CurrentCollector::createAreaLongitudinal(
|
||||
const double r2 = (ir + 1) * dr;
|
||||
// const double area_element =
|
||||
// (std::pow(r2, 2) - std::pow(r1, 2)) * M_PI / (area_z.extent(1));
|
||||
const double area_element =
|
||||
(r2*r2 - r1*r1) * M_PI / (area_z.extent(1));
|
||||
area_z(ir, blitz::Range::all(), blitz::Range::all()) = area_element;
|
||||
const double area_element = (r2*r2 - r1*r1) * M_PI;
|
||||
area_z(ir, blitz::Range::all()) = area_element;
|
||||
}
|
||||
return area_z;
|
||||
}
|
||||
|
||||
blitz::Array<double, 3> CurrentCollector::createCrossingsLongitudinal(
|
||||
blitz::Array<double, 2> CurrentCollector::createCrossingsLongitudinal(
|
||||
const CylinderBinning& position_binning) {
|
||||
const blitz::TinyVector<int, 3> bin_index_min =
|
||||
const blitz::TinyVector<int, 2> bin_index_min =
|
||||
position_binning.binIndexMin();
|
||||
const blitz::TinyVector<int, 3> bin_index_max =
|
||||
const blitz::TinyVector<int, 2> bin_index_max =
|
||||
position_binning.binIndexMax();
|
||||
|
||||
blitz::Array<double, 3> crossings_longitudinal(
|
||||
blitz::Array<double, 2> crossings_longitudinal(
|
||||
blitz::Range(bin_index_min(0), bin_index_max(0)),
|
||||
blitz::Range(bin_index_min(1), bin_index_max(1)),
|
||||
blitz::Range(0, bin_index_max(2)));
|
||||
blitz::Range(0, bin_index_max(1)));
|
||||
crossings_longitudinal = 0.;
|
||||
return crossings_longitudinal;
|
||||
}
|
||||
|
||||
blitz::Array<double, 3> CurrentCollector::createAreaRadial(
|
||||
blitz::Array<double, 2> CurrentCollector::createAreaRadial(
|
||||
const CylinderBinning& position_binning) {
|
||||
const blitz::TinyVector<int, 3> bin_index_min =
|
||||
const blitz::TinyVector<int, 2> bin_index_min =
|
||||
position_binning.binIndexMin();
|
||||
const blitz::TinyVector<int, 3> bin_index_max =
|
||||
const blitz::TinyVector<int, 2> bin_index_max =
|
||||
position_binning.binIndexMax();
|
||||
|
||||
blitz::Array<double, 3> area_r(
|
||||
blitz::Array<double, 2> area_r(
|
||||
blitz::Range(bin_index_min(0), bin_index_max(0) - 1),
|
||||
blitz::Range(bin_index_min(1), bin_index_max(1)),
|
||||
blitz::Range(bin_index_min(2), bin_index_max(2)));
|
||||
blitz::Range(bin_index_min(1), bin_index_max(1)));
|
||||
|
||||
for (int ir = 0; ir <= area_r.ubound(0); ++ir) {
|
||||
const double dr = position_binning.stepsize()(0);
|
||||
const double dz = position_binning.stepsize()(2);
|
||||
const double dz = position_binning.stepsize()(1);
|
||||
const double r = (ir + 1) * dr;
|
||||
const double area_element = (2 * M_PI * r) / area_r.extent(1) * dz;
|
||||
const double area_element = (2 * M_PI * r) * dz;
|
||||
|
||||
area_r(ir, blitz::Range::all(), blitz::Range::all()) = area_element;
|
||||
area_r(ir, blitz::Range::all()) = area_element;
|
||||
}
|
||||
return area_r;
|
||||
}
|
||||
|
||||
blitz::Array<double, 3> CurrentCollector::createCrossingsRadial(
|
||||
blitz::Array<double, 2> CurrentCollector::createCrossingsRadial(
|
||||
const CylinderBinning& position_binning) {
|
||||
const blitz::TinyVector<int, 3> bin_index_min =
|
||||
const blitz::TinyVector<int, 2> bin_index_min =
|
||||
position_binning.binIndexMin();
|
||||
const blitz::TinyVector<int, 3> bin_index_max =
|
||||
const blitz::TinyVector<int, 2> bin_index_max =
|
||||
position_binning.binIndexMax();
|
||||
|
||||
blitz::Array<double, 3> crossings_radial(
|
||||
blitz::Array<double, 2> crossings_radial(
|
||||
blitz::Range(bin_index_min(0), bin_index_max(0) - 1),
|
||||
blitz::Range(bin_index_min(1), bin_index_max(1)),
|
||||
blitz::Range(bin_index_min(2), bin_index_max(2)));
|
||||
blitz::Range(bin_index_min(1), bin_index_max(1)));
|
||||
crossings_radial = 0.;
|
||||
return crossings_radial;
|
||||
}
|
||||
|
||||
blitz::Array<double, 3> CurrentCollector::createAreaAzimuthal(
|
||||
blitz::Array<double, 2> CurrentCollector::createAreaAzimuthal(
|
||||
const CylinderBinning& position_binning) {
|
||||
const blitz::TinyVector<int, 3> bin_index_min =
|
||||
const blitz::TinyVector<int, 2> bin_index_min =
|
||||
position_binning.binIndexMin();
|
||||
const blitz::TinyVector<int, 3> bin_index_max =
|
||||
const blitz::TinyVector<int, 2> bin_index_max =
|
||||
position_binning.binIndexMax();
|
||||
|
||||
blitz::Array<double, 3> area_phi(
|
||||
blitz::Array<double, 2> area_phi(
|
||||
blitz::Range(bin_index_min(0), bin_index_max(0)),
|
||||
blitz::Range(bin_index_min(1), bin_index_max(1)),
|
||||
blitz::Range(bin_index_min(2), bin_index_max(2)));
|
||||
blitz::Range(bin_index_min(1), bin_index_max(1)));
|
||||
|
||||
const double dr = position_binning.stepsize()(0);
|
||||
const double dz = position_binning.stepsize()(2);
|
||||
const double dz = position_binning.stepsize()(1);
|
||||
const double area_element = dr * dz;
|
||||
area_phi(blitz::Range::all(), blitz::Range::all(), blitz::Range::all()) =
|
||||
area_phi(blitz::Range::all(), blitz::Range::all()) =
|
||||
area_element;
|
||||
return area_phi;
|
||||
}
|
||||
|
||||
blitz::Array<double, 3> CurrentCollector::createCrossingsAzimuthal(
|
||||
blitz::Array<double, 2> CurrentCollector::createCrossingsAzimuthal(
|
||||
const CylinderBinning& position_binning) {
|
||||
const blitz::TinyVector<int, 3> bin_index_min =
|
||||
const blitz::TinyVector<int, 2> bin_index_min =
|
||||
position_binning.binIndexMin();
|
||||
const blitz::TinyVector<int, 3> bin_index_max =
|
||||
const blitz::TinyVector<int, 2> bin_index_max =
|
||||
position_binning.binIndexMax();
|
||||
|
||||
blitz::Array<double, 3> crossings_azimuthal(
|
||||
blitz::Array<double, 2> crossings_azimuthal(
|
||||
blitz::Range(bin_index_min(0), bin_index_max(0)),
|
||||
blitz::Range(bin_index_min(1), bin_index_max(1)),
|
||||
blitz::Range(bin_index_min(2), bin_index_max(2)));
|
||||
blitz::Range(bin_index_min(1), bin_index_max(1)));
|
||||
crossings_azimuthal = 0;
|
||||
return crossings_azimuthal;
|
||||
}
|
||||
|
||||
void CurrentCollector::collect(particle::Particle* particle,
|
||||
const Coordinate& old_position) {
|
||||
blitz::TinyVector<int, 3> bin_old =
|
||||
blitz::TinyVector<int, 2> bin_old =
|
||||
position_binning_.bin(old_position.cylinderEntries());
|
||||
blitz::TinyVector<int, 3> bin_new =
|
||||
blitz::TinyVector<int, 2> bin_new =
|
||||
position_binning_.bin(particle->cylinderPosition().cylinderEntries());
|
||||
|
||||
const double weight = particle->weight();
|
||||
@@ -149,108 +142,103 @@ void CurrentCollector::collect(particle::Particle* particle,
|
||||
}
|
||||
|
||||
void CurrentCollector::collectRadialMovement(
|
||||
const blitz::TinyVector<int, 3>& bin_old,
|
||||
const blitz::TinyVector<int, 3>& bin_new,
|
||||
const blitz::TinyVector<int, 2>& bin_old,
|
||||
const blitz::TinyVector<int, 2>& bin_new,
|
||||
const double weight) {
|
||||
if (bin_new(0) < bin_old(0)) {
|
||||
r_negative_crossings(bin_new(0), bin_old(1), bin_old(2)) += weight;
|
||||
r_negative_crossings(bin_new(0), bin_old(1)) += weight;
|
||||
} else if (bin_new(0) > bin_old(0)) {
|
||||
r_positive_crossings(bin_new(0) - 1, bin_old(1), bin_old(2)) += weight;
|
||||
r_positive_crossings(bin_new(0) - 1, bin_old(1)) += weight;
|
||||
}
|
||||
}
|
||||
void CurrentCollector::collectLongitudinalMovement(
|
||||
const blitz::TinyVector<int, 3>& bin_old,
|
||||
const blitz::TinyVector<int, 3>& bin_new,
|
||||
const blitz::TinyVector<int, 2>& bin_old,
|
||||
const blitz::TinyVector<int, 2>& bin_new,
|
||||
const double weight) {
|
||||
if (bin_new(2) < bin_old(2)) {
|
||||
z_negative_crossings(bin_old(0), bin_old(1), bin_new(2) + 1) += weight;
|
||||
} else if (bin_new(2) > bin_old(2)) {
|
||||
z_positive_crossings(bin_old(0), bin_old(1), bin_new(2)) += weight;
|
||||
if (bin_new(1) < bin_old(1)) {
|
||||
z_negative_crossings(bin_old(0), bin_new(1) + 1) += weight;
|
||||
} else if (bin_new(1) > bin_old(1)) {
|
||||
z_positive_crossings(bin_old(0), bin_old(1)) += weight;
|
||||
}
|
||||
}
|
||||
// does not work!
|
||||
void CurrentCollector::collectAzimuthalMovement(
|
||||
const blitz::TinyVector<int, 3>& bin_old,
|
||||
const blitz::TinyVector<int, 3>& bin_new,
|
||||
const blitz::TinyVector<int, 2>& bin_old,
|
||||
const blitz::TinyVector<int, 2>& bin_new,
|
||||
const double weight) {
|
||||
if ((bin_new(1) < bin_old(1)) ||
|
||||
((bin_old(1) == 0) &&
|
||||
(bin_new(1) == position_binning_.binIndexMax()(1)))) {
|
||||
phi_negative_crossings(bin_old(0), bin_new(1), bin_old(2)) += weight;
|
||||
phi_negative_crossings(bin_old(0), bin_new(1)) += weight;
|
||||
} else if ((bin_new(1) > bin_old(1)) ||
|
||||
((bin_old(1) == position_binning_.binIndexMax()(1)) &&
|
||||
(bin_new(1) == 0))) {
|
||||
phi_positive_crossings(bin_old(0), bin_new(1) - 1, bin_old(2)) += weight;
|
||||
phi_positive_crossings(bin_old(0), bin_new(1) - 1) += weight;
|
||||
}
|
||||
}
|
||||
|
||||
blitz::Array<double, 3> CurrentCollector::negativeCrossingsInZ() const {
|
||||
blitz::Array<double, 2> CurrentCollector::negativeCrossingsInZ() const {
|
||||
return z_negative_crossings;
|
||||
}
|
||||
blitz::Array<double, 3> CurrentCollector::positiveCrossingsInZ() const {
|
||||
blitz::Array<double, 2> CurrentCollector::positiveCrossingsInZ() const {
|
||||
return z_positive_crossings;
|
||||
}
|
||||
|
||||
blitz::Array<double, 3> CurrentCollector::negativeCrossingsInPhi() const {
|
||||
blitz::Array<double, 2> CurrentCollector::negativeCrossingsInPhi() const {
|
||||
return phi_negative_crossings;
|
||||
}
|
||||
blitz::Array<double, 3> CurrentCollector::positiveCrossingsInPhi() const {
|
||||
blitz::Array<double, 2> CurrentCollector::positiveCrossingsInPhi() const {
|
||||
return phi_positive_crossings;
|
||||
}
|
||||
|
||||
blitz::Array<double, 3> CurrentCollector::negativeCrossingsInR() const {
|
||||
blitz::Array<double, 2> CurrentCollector::negativeCrossingsInR() const {
|
||||
return r_negative_crossings;
|
||||
}
|
||||
blitz::Array<double, 3> CurrentCollector::positiveCrossingsInR() const {
|
||||
blitz::Array<double, 2> CurrentCollector::positiveCrossingsInR() const {
|
||||
return r_positive_crossings;
|
||||
}
|
||||
|
||||
blitz::Array<double, 3> CurrentCollector::areaInR() const {
|
||||
blitz::Array<double, 2> CurrentCollector::areaInR() const {
|
||||
return collector_areas_r;
|
||||
}
|
||||
blitz::Array<double, 3> CurrentCollector::areaInPhi() const {
|
||||
blitz::Array<double, 2> CurrentCollector::areaInPhi() const {
|
||||
return collector_areas_phi;
|
||||
}
|
||||
blitz::Array<double, 3> CurrentCollector::areaInZ() const {
|
||||
blitz::Array<double, 2> CurrentCollector::areaInZ() const {
|
||||
return collector_areas_z;
|
||||
}
|
||||
|
||||
blitz::Array<double, 3> CurrentCollector::currentInZ() const {
|
||||
blitz::Array<double, 3> current_in_z = z_positive_crossings.copy();
|
||||
current_in_z(blitz::Range::all(), blitz::Range::all(), blitz::Range::all()) =
|
||||
(z_positive_crossings(blitz::Range::all(), blitz::Range::all(),
|
||||
blitz::Range::all()) -
|
||||
z_negative_crossings(blitz::Range::all(), blitz::Range::all(),
|
||||
blitz::Range::all())) /
|
||||
blitz::Array<double, 2> CurrentCollector::currentInZ() const {
|
||||
blitz::Array<double, 2> current_in_z = z_positive_crossings.copy();
|
||||
current_in_z(blitz::Range::all(), blitz::Range::all()) =
|
||||
(z_positive_crossings(blitz::Range::all(), blitz::Range::all()) -
|
||||
z_negative_crossings(blitz::Range::all(), blitz::Range::all())) /
|
||||
(physicalTime() * collector_areas_z(blitz::Range::all(),
|
||||
blitz::Range::all(),
|
||||
blitz::Range::all()));
|
||||
return current_in_z;
|
||||
}
|
||||
blitz::Array<double, 3> CurrentCollector::currentInPhi() const {
|
||||
blitz::Array<double, 3> current_in_phi = phi_positive_crossings.copy();
|
||||
current_in_phi(blitz::Range::all(), blitz::Range::all(),
|
||||
blitz::Range::all()) =
|
||||
(phi_positive_crossings(blitz::Range::all(), blitz::Range::all(),
|
||||
blitz::Range::all()) -
|
||||
phi_negative_crossings(blitz::Range::all(), blitz::Range::all(),
|
||||
blitz::Range::all())) /
|
||||
|
||||
// does not work due to wrong phi_{positive/negative}_crossings
|
||||
blitz::Array<double, 2> CurrentCollector::currentInPhi() const {
|
||||
blitz::Array<double, 2> current_in_phi = phi_positive_crossings.copy();
|
||||
current_in_phi(blitz::Range::all(), blitz::Range::all()) =
|
||||
(phi_positive_crossings(blitz::Range::all(), blitz::Range::all()) -
|
||||
phi_negative_crossings(blitz::Range::all(), blitz::Range::all())) /
|
||||
(physicalTime() * collector_areas_phi(blitz::Range::all(),
|
||||
blitz::Range::all(),
|
||||
blitz::Range::all()));
|
||||
return current_in_phi;
|
||||
}
|
||||
blitz::Array<double, 3> CurrentCollector::currentInR() const {
|
||||
blitz::Array<double, 3> current_in_r = r_positive_crossings.copy();
|
||||
current_in_r(blitz::Range::all(), blitz::Range::all(), blitz::Range::all()) =
|
||||
(r_positive_crossings(blitz::Range::all(), blitz::Range::all(),
|
||||
blitz::Range::all()) -
|
||||
r_negative_crossings(blitz::Range::all(), blitz::Range::all(),
|
||||
blitz::Range::all())) /
|
||||
|
||||
blitz::Array<double, 2> CurrentCollector::currentInR() const {
|
||||
blitz::Array<double, 2> current_in_r = r_positive_crossings.copy();
|
||||
current_in_r(blitz::Range::all(), blitz::Range::all()) =
|
||||
(r_positive_crossings(blitz::Range::all(), blitz::Range::all()) -
|
||||
r_negative_crossings(blitz::Range::all(), blitz::Range::all())) /
|
||||
(physicalTime() * collector_areas_r(blitz::Range::all(),
|
||||
blitz::Range::all(),
|
||||
blitz::Range::all()));
|
||||
return current_in_r;
|
||||
}
|
||||
|
||||
double CurrentCollector::physicalTime() const {
|
||||
return timer_->getDeltaT();
|
||||
}
|
||||
|
||||
@@ -9,11 +9,20 @@
|
||||
#include "tools/simulation_time.h"
|
||||
|
||||
template <class T>
|
||||
blitz::Array<T, 4> initiate4DArray(blitz::Range radial,
|
||||
blitz::Range phi,
|
||||
blitz::Array<T, 3> initiate3DArray(blitz::Range radial,
|
||||
blitz::Range longitudinal,
|
||||
blitz::Range energy) {
|
||||
blitz::Array<T, 4> data(radial, phi, longitudinal, energy);
|
||||
blitz::Array<T, 3> data(radial, longitudinal, energy);
|
||||
data = static_cast<T>(0);
|
||||
return data.copy();
|
||||
}
|
||||
|
||||
template <class T>
|
||||
blitz::Array<T, 4> initiate4DArray(blitz::Range radial,
|
||||
blitz::Range longitudinal,
|
||||
blitz::Range energy,
|
||||
blitz::Range pitchangle) {
|
||||
blitz::Array<T, 4> data(radial, longitudinal, energy, pitchangle);
|
||||
data = static_cast<T>(0);
|
||||
return data.copy();
|
||||
}
|
||||
@@ -29,24 +38,23 @@ blitz::Array<T, 5> initiate5DArray(blitz::Range radial,
|
||||
return data.copy();
|
||||
}
|
||||
|
||||
blitz::Array<double, 3> initiateVolumeArray(
|
||||
blitz::Array<double, 2> initiateVolumeArray(
|
||||
blitz::Range radial,
|
||||
blitz::Range phi,
|
||||
blitz::Range longitudinal,
|
||||
const blitz::TinyVector<double, 3>& position_spacing) {
|
||||
blitz::Array<double, 3> volume(radial, phi, longitudinal);
|
||||
const blitz::TinyVector<double, 2>& position_spacing) {
|
||||
blitz::Array<double, 2> volume(radial, longitudinal);
|
||||
|
||||
for (int ir = 0; ir <= volume.ubound(0); ++ir) {
|
||||
const double r1 = ir * position_spacing(0);
|
||||
const double r2 = (ir + 1) * position_spacing(0);
|
||||
for (int iz = volume.lbound(2); iz <= volume.ubound(2); ++iz) {
|
||||
const double z1 = iz * position_spacing(2);
|
||||
const double z2 = (iz + 1) * position_spacing(2);
|
||||
for (int iz = volume.lbound(1); iz <= volume.ubound(1); ++iz) {
|
||||
const double z1 = iz * position_spacing(1);
|
||||
const double z2 = (iz + 1) * position_spacing(1);
|
||||
|
||||
const double bin_volume =
|
||||
M_PI * ((r2*r2) - (r1*r1)) * (z2 - z1) / phi.length();
|
||||
M_PI * ((r2*r2) - (r1*r1)) * (z2 - z1);
|
||||
|
||||
volume(ir, blitz::Range::all(), iz) = bin_volume;
|
||||
volume(ir, iz) = bin_volume;
|
||||
}
|
||||
}
|
||||
return volume.copy();
|
||||
@@ -61,33 +69,27 @@ DynamicDensityField::DynamicDensityField(
|
||||
energy_binning_(energy_binning),
|
||||
pitch_angle_binning_(pitch_angle_binning),
|
||||
timer_(timer),
|
||||
time_in_bin_s_(initiate5DArray<double>(
|
||||
number_in_bin_(initiate4DArray<double>(
|
||||
blitz::Range(position_binning.radial_binning.binIndexMin(),
|
||||
position_binning.radial_binning.binIndexMax()),
|
||||
blitz::Range(position_binning.azimuth_binning.binIndexMin(),
|
||||
position_binning.azimuth_binning.binIndexMax()),
|
||||
blitz::Range(position_binning.longitudinal_binning.binIndexMin(),
|
||||
position_binning.longitudinal_binning.binIndexMax()),
|
||||
blitz::Range(pitch_angle_binning.binIndexMin(),
|
||||
pitch_angle_binning.binIndexMax()),
|
||||
blitz::Range(energy_binning.binIndexMin(),
|
||||
energy_binning.binIndexMax()))),
|
||||
sync_time_in_bin_s_(initiate5DArray<double>(
|
||||
sync_number_in_bin_(initiate4DArray<double>(
|
||||
blitz::Range(position_binning.radial_binning.binIndexMin(),
|
||||
position_binning.radial_binning.binIndexMax()),
|
||||
blitz::Range(position_binning.azimuth_binning.binIndexMin(),
|
||||
position_binning.azimuth_binning.binIndexMax()),
|
||||
blitz::Range(position_binning.longitudinal_binning.binIndexMin(),
|
||||
position_binning.longitudinal_binning.binIndexMax()),
|
||||
blitz::Range(pitch_angle_binning.binIndexMin(),
|
||||
pitch_angle_binning.binIndexMax()),
|
||||
blitz::Range(energy_binning.binIndexMin(),
|
||||
energy_binning.binIndexMax()))),
|
||||
density_per_m3_(initiate4DArray<double>(
|
||||
density_per_m3_(initiate3DArray<double>(
|
||||
blitz::Range(position_binning.radial_binning.binIndexMin(),
|
||||
position_binning.radial_binning.binIndexMax()),
|
||||
blitz::Range(position_binning.azimuth_binning.binIndexMin(),
|
||||
position_binning.azimuth_binning.binIndexMax()),
|
||||
blitz::Range(position_binning.longitudinal_binning.binIndexMin(),
|
||||
position_binning.longitudinal_binning.binIndexMax()),
|
||||
blitz::Range(energy_binning.binIndexMin(),
|
||||
@@ -95,8 +97,6 @@ DynamicDensityField::DynamicDensityField(
|
||||
bin_volume_m3_(initiateVolumeArray(
|
||||
blitz::Range(position_binning.radial_binning.binIndexMin(),
|
||||
position_binning.radial_binning.binIndexMax()),
|
||||
blitz::Range(position_binning.azimuth_binning.binIndexMin(),
|
||||
position_binning.azimuth_binning.binIndexMax()),
|
||||
blitz::Range(position_binning.longitudinal_binning.binIndexMin(),
|
||||
position_binning.longitudinal_binning.binIndexMax()),
|
||||
position_binning.stepsize())) {
|
||||
@@ -106,7 +106,7 @@ DynamicDensityField::DynamicDensityField(
|
||||
}
|
||||
|
||||
double DynamicDensityField::density(const Coordinate& position) {
|
||||
const blitz::TinyVector<int, 3> position_bin =
|
||||
const blitz::TinyVector<int, 2> position_bin =
|
||||
position_binning_.bin(position.cylinderEntries());
|
||||
|
||||
#ifdef debug_level1
|
||||
@@ -117,7 +117,7 @@ double DynamicDensityField::density(const Coordinate& position) {
|
||||
}
|
||||
#endif
|
||||
|
||||
return blitz::sum(density_per_m3_(position_bin(0), position_bin(1), position_bin(2),
|
||||
return blitz::sum(density_per_m3_(position_bin(0), position_bin(1),
|
||||
blitz::Range::all()));
|
||||
|
||||
/*/
|
||||
@@ -136,33 +136,31 @@ double DynamicDensityField::density(const Coordinate& position) {
|
||||
|
||||
double DynamicDensityField::density(const Coordinate& position,
|
||||
double energy_eV) {
|
||||
const blitz::TinyVector<int, 3> position_bin =
|
||||
const blitz::TinyVector<int, 2> position_bin =
|
||||
position_binning_.bin(position.cylinderEntries());
|
||||
|
||||
const int energy_bin = energy_binning_.bin(energy_eV);
|
||||
// const double t = timer_->getDeltaT();
|
||||
const double time_in_bin = blitz::sum(time_in_bin_s_(
|
||||
position_bin(0), position_bin(1), position_bin(2),
|
||||
blitz::Range::all(), energy_bin));
|
||||
const double number_in_bin = blitz::sum(number_in_bin_(
|
||||
position_bin(0), position_bin(1), blitz::Range::all(), energy_bin));
|
||||
// const long deleted_particles = blitz::sum(deleted_particles_(
|
||||
// position_bin(0), position_bin(1), position_bin(2),
|
||||
// blitz::Range::all(), energy_bin));
|
||||
|
||||
return (time_in_bin) / // - deleted_particles) /
|
||||
bin_volume_m3_(position_bin(0), position_bin(1), position_bin(2));
|
||||
return (number_in_bin) / // - deleted_particles) /
|
||||
bin_volume_m3_(position_bin(0), position_bin(1));
|
||||
}
|
||||
|
||||
bool DynamicDensityField::changedPositionBin(
|
||||
const Coordinate& old_position,
|
||||
const Coordinate& new_position) const {
|
||||
const blitz::TinyVector<int, 3> old_bin =
|
||||
const blitz::TinyVector<int, 2> old_bin =
|
||||
position_binning_.bin(old_position.cylinderEntries());
|
||||
|
||||
const blitz::TinyVector<int, 3> new_bin =
|
||||
const blitz::TinyVector<int, 2> new_bin =
|
||||
position_binning_.bin(new_position.cylinderEntries());
|
||||
|
||||
return !((old_bin(0) == new_bin(0)) && (old_bin(1) == new_bin(1)) &&
|
||||
(old_bin(2) == new_bin(2)));
|
||||
return !((old_bin(0) == new_bin(0)) && (old_bin(1) == new_bin(1)));
|
||||
}
|
||||
|
||||
bool DynamicDensityField::changedEnergyBin(double old_energy_eV,
|
||||
@@ -194,50 +192,48 @@ void DynamicDensityField::logMovement(const Coordinate& position,
|
||||
double pitch_angle,
|
||||
double weight) {
|
||||
|
||||
const blitz::TinyVector<int, 3> position_bin =
|
||||
const blitz::TinyVector<int, 2> position_bin =
|
||||
position_binning_.bin(position.cylinderEntries());
|
||||
const int energy_bin = energy_binning_.bin(energy_eV);
|
||||
const int pitch_angle_bin = pitch_angle_binning_.bin(pitch_angle);
|
||||
|
||||
sync_time_in_bin_s_(position_bin(0), position_bin(1), position_bin(2),
|
||||
sync_number_in_bin_(position_bin(0), position_bin(1),
|
||||
pitch_angle_bin, energy_bin) += weight;
|
||||
}
|
||||
|
||||
blitz::Array<double, 3> DynamicDensityField::densityArray() {
|
||||
blitz::Array<double, 2> DynamicDensityField::densityArray() {
|
||||
#ifdef debug_level3
|
||||
DEBUG_LEVEL_3("recalc Density array");
|
||||
#endif
|
||||
// recalculated after a timestep reset (as of now hope that's enough and works correctly)
|
||||
// recalculateDensityArray();
|
||||
|
||||
blitz::TinyVector<int,3> lowerbound(density_per_m3_.lbound(0),
|
||||
density_per_m3_.lbound(1),
|
||||
density_per_m3_.lbound(2));
|
||||
blitz::TinyVector<int,3> extent(density_per_m3_.extent(0),
|
||||
density_per_m3_.extent(1),
|
||||
density_per_m3_.extent(2));
|
||||
blitz::Array<double, 3> density(lowerbound, extent);
|
||||
blitz::TinyVector<int,2> lowerbound(density_per_m3_.lbound(0),
|
||||
density_per_m3_.lbound(1));
|
||||
blitz::TinyVector<int,2> extent(density_per_m3_.extent(0),
|
||||
density_per_m3_.extent(1));
|
||||
blitz::Array<double, 2> density(lowerbound, extent);
|
||||
|
||||
blitz::fourthIndex iE;
|
||||
blitz::thirdIndex iE;
|
||||
// DEBUG_LEVEL_3("density sum");
|
||||
density = blitz::sum(density_per_m3_, iE);
|
||||
return density.copy();
|
||||
}
|
||||
|
||||
blitz::Array<double, 4> DynamicDensityField::spectrumArray() {
|
||||
blitz::Array<double, 3> DynamicDensityField::spectrumArray() {
|
||||
// recalculateDensityArray();
|
||||
return density_per_m3_;
|
||||
}
|
||||
|
||||
blitz::Array<double, 5> DynamicDensityField::timeInBinArray() const {
|
||||
return time_in_bin_s_;
|
||||
blitz::Array<double, 4> DynamicDensityField::numberInBinArray() const {
|
||||
return number_in_bin_;
|
||||
}
|
||||
|
||||
// blitz::Array<long int, 5> DynamicDensityField::deletedParticlesArray() const {
|
||||
// return deleted_particles_;
|
||||
// }
|
||||
|
||||
blitz::Array<double, 3> DynamicDensityField::binVolumeArray() const {
|
||||
blitz::Array<double, 2> DynamicDensityField::binVolumeArray() const {
|
||||
return bin_volume_m3_;
|
||||
}
|
||||
|
||||
@@ -264,18 +260,17 @@ double DynamicDensityField::timeResolution() const {
|
||||
void DynamicDensityField::recalculateDensityArray() {
|
||||
// SimulationTimer::eventStartPoint("recalcDensityArray");
|
||||
blitz::firstIndex ir;
|
||||
blitz::secondIndex iphi;
|
||||
blitz::thirdIndex iz;
|
||||
blitz::fourthIndex ipitch;
|
||||
blitz::fifthIndex iE;
|
||||
blitz::secondIndex iz;
|
||||
blitz::thirdIndex ipitch;
|
||||
blitz::fourthIndex iE;
|
||||
|
||||
// reduction only seems to work for the last dimension (iE)
|
||||
// -> first reorder (by exchanging iE and ipitch) and afterwards doing
|
||||
// the reduction over iE (which now contains the pitch dimension)
|
||||
// blitz::Array<double, 5> temp((time_in_bin_s_(ir, iphi, iz, ipitch, iE)));
|
||||
|
||||
density_per_m3_ = blitz::sum((time_in_bin_s_(ir, iphi, iz, iE, ipitch)), iE) /
|
||||
bin_volume_m3_(ir, iphi, iz);
|
||||
density_per_m3_ = blitz::sum((number_in_bin_(ir, iz, iE, ipitch)), iE) /
|
||||
bin_volume_m3_(ir, iz);
|
||||
// SimulationTimer::eventStopPoint("recalcDensityArray");
|
||||
}
|
||||
|
||||
@@ -283,7 +278,7 @@ void DynamicDensityField::recalculateDensityArray() {
|
||||
// particle number
|
||||
blitz::Array<double, 1> DynamicDensityField::sliceSpectrumArray(
|
||||
const Coordinate& position) const {
|
||||
blitz::TinyVector<int, 3> position_bin =
|
||||
blitz::TinyVector<int, 2> position_bin =
|
||||
position_binning_.bin(position.cylinderEntries());
|
||||
|
||||
// blitz::Array<double, 4> check = density_per_m3_.copy();
|
||||
@@ -292,25 +287,25 @@ blitz::Array<double, 1> DynamicDensityField::sliceSpectrumArray(
|
||||
// ERROR("splice specturm array: check failed.");
|
||||
// }
|
||||
|
||||
return density_per_m3_(position_bin(0), position_bin(1), position_bin(2),
|
||||
return density_per_m3_(position_bin(0), position_bin(1),
|
||||
blitz::Range(energy_binning_.binIndexMin(),
|
||||
energy_binning_.binIndexMax()-1));
|
||||
}
|
||||
|
||||
blitz::Array<double, 1> DynamicDensityField::sliceTimeInBinArray(
|
||||
blitz::Array<double, 1> DynamicDensityField::sliceNumberInBinArray(
|
||||
const Coordinate& position, double energy_eV) const {
|
||||
blitz::TinyVector<int, 3> position_bin =
|
||||
blitz::TinyVector<int, 2> position_bin =
|
||||
position_binning_.bin(position.cylinderEntries());
|
||||
int energy_bin = energy_binning_.bin(energy_eV);
|
||||
|
||||
return time_in_bin_s_(position_bin(0), position_bin(1), position_bin(2),
|
||||
return number_in_bin_(position_bin(0), position_bin(1),
|
||||
blitz::Range(0, pitch_angle_binning_.binIndexMax()-1),
|
||||
energy_bin);
|
||||
}
|
||||
|
||||
// resets the field that logs the new density
|
||||
void DynamicDensityField::resetDynamicDensityField() {
|
||||
sync_time_in_bin_s_ = 0.;
|
||||
sync_number_in_bin_ = 0.;
|
||||
}
|
||||
|
||||
void DynamicDensityField::restartTimer(double time, double delta_t) {
|
||||
@@ -324,15 +319,15 @@ void DynamicDensityField::restartTimer(double time, double delta_t) {
|
||||
timer_->setDeltaT(delta_t);
|
||||
}
|
||||
|
||||
void DynamicDensityField::restartTimeInBin(blitz::Array<double, 5> time_in_bin) {
|
||||
if(!blitz::all(time_in_bin_s_.length() == time_in_bin.length())) {
|
||||
void DynamicDensityField::restartNumberInBin(blitz::Array<double, 4> number_in_bin) {
|
||||
if(!blitz::all(number_in_bin_.length() == number_in_bin.length())) {
|
||||
std::stringstream out;
|
||||
out << "Expected a size of " << time_in_bin_s_.length();
|
||||
out << ", received a length of " << time_in_bin.length();
|
||||
out << "Expected a size of " << number_in_bin_.length();
|
||||
out << ", received a length of " << number_in_bin.length();
|
||||
out << " for time_in_bin array";
|
||||
ERROR(out.str());
|
||||
}
|
||||
time_in_bin_s_ = time_in_bin.copy().reindex(time_in_bin_s_.lbound());
|
||||
number_in_bin_ = number_in_bin.copy().reindex(number_in_bin_.lbound());
|
||||
}
|
||||
|
||||
// void DynamicDensityField::restartDeletedParticlesArray(
|
||||
|
||||
@@ -117,46 +117,40 @@ int BinningWithOverAndUnderflow::binIndexMax() const {
|
||||
|
||||
CylinderBinning::CylinderBinning(int num_bins_radial,
|
||||
double radius,
|
||||
int num_bins_azimuthal,
|
||||
int num_bins_longitudinal,
|
||||
double height)
|
||||
: radial_binning(num_bins_radial, radius),
|
||||
azimuth_binning(num_bins_azimuthal, 2 * M_PI),
|
||||
longitudinal_binning(num_bins_longitudinal, height) {}
|
||||
|
||||
blitz::TinyVector<int, 3> CylinderBinning::bin(
|
||||
blitz::TinyVector<int, 2> CylinderBinning::bin(
|
||||
const blitz::TinyVector<double, 3>& cylinder_position) const {
|
||||
return blitz::TinyVector<int, 3>(
|
||||
return blitz::TinyVector<int, 2>(
|
||||
radial_binning.bin(cylinder_position(0)),
|
||||
azimuth_binning.bin(cylinder_position(1)),
|
||||
longitudinal_binning.bin(cylinder_position(2)));
|
||||
}
|
||||
|
||||
blitz::TinyVector<int, 3> CylinderBinning::numBins() const {
|
||||
return blitz::TinyVector<int, 3>(
|
||||
radial_binning.numBinsWithoutOverflow(), azimuth_binning.numBins(),
|
||||
blitz::TinyVector<int, 2> CylinderBinning::numBins() const {
|
||||
return blitz::TinyVector<int, 2>(
|
||||
radial_binning.numBinsWithoutOverflow(),
|
||||
longitudinal_binning.numBinsWithoutOverUnderflow());
|
||||
}
|
||||
|
||||
blitz::TinyVector<double, 3> CylinderBinning::stepsize() const {
|
||||
return blitz::TinyVector<double, 3>(radial_binning.stepsize(),
|
||||
azimuth_binning.stepsize(),
|
||||
blitz::TinyVector<double, 2> CylinderBinning::stepsize() const {
|
||||
return blitz::TinyVector<double, 2>(radial_binning.stepsize(),
|
||||
longitudinal_binning.stepsize());
|
||||
}
|
||||
|
||||
blitz::TinyVector<int, 3> CylinderBinning::numBinsIncludingOverUnderflow()
|
||||
blitz::TinyVector<int, 2> CylinderBinning::numBinsIncludingOverUnderflow()
|
||||
const {
|
||||
return blitz::TinyVector<int, 3>(
|
||||
radial_binning.numBinsWithOverflow(), azimuth_binning.numBins(),
|
||||
return blitz::TinyVector<int, 2>(
|
||||
radial_binning.numBinsWithOverflow(),
|
||||
longitudinal_binning.numBinsWithOverUnderflow());
|
||||
}
|
||||
blitz::TinyVector<int, 3> CylinderBinning::binIndexMin() const {
|
||||
return blitz::TinyVector<int, 3>(radial_binning.binIndexMin(),
|
||||
azimuth_binning.binIndexMin(),
|
||||
blitz::TinyVector<int, 2> CylinderBinning::binIndexMin() const {
|
||||
return blitz::TinyVector<int, 2>(radial_binning.binIndexMin(),
|
||||
longitudinal_binning.binIndexMin());
|
||||
}
|
||||
blitz::TinyVector<int, 3> CylinderBinning::binIndexMax() const {
|
||||
return blitz::TinyVector<int, 3>(radial_binning.binIndexMax(),
|
||||
azimuth_binning.binIndexMax(),
|
||||
blitz::TinyVector<int, 2> CylinderBinning::binIndexMax() const {
|
||||
return blitz::TinyVector<int, 2>(radial_binning.binIndexMax(),
|
||||
longitudinal_binning.binIndexMax());
|
||||
}
|
||||
|
||||
@@ -188,8 +188,8 @@ void Simulation::start() {
|
||||
|
||||
#if defined(debug_level1) || defined(debug_level2) || defined(debug_level3)
|
||||
DEBUG_LEVEL_1("Processing timestep: " + std::to_string(timestep));
|
||||
DEBUG_LEVEL_1("Leftover events this timestep: " +
|
||||
std::to_string(leftover_events_time_resolution));
|
||||
// DEBUG_LEVEL_1("Leftover events this timestep: " +
|
||||
// std::to_string(leftover_events_time_resolution));
|
||||
#endif
|
||||
|
||||
#ifdef debug
|
||||
@@ -557,7 +557,7 @@ void Simulation::collisionTime(particle::Particle& particle, RandomNumbers* rand
|
||||
particle.indexNextInteration((min_iterator - collision_times.begin()));
|
||||
particle.timeUntilCollision(*min_iterator);
|
||||
|
||||
#ifdef debug
|
||||
#ifdef debug_level1
|
||||
std::stringstream out;
|
||||
out << "collision times ";
|
||||
out << particle.specie()->name() <<":\n[ ";
|
||||
@@ -604,7 +604,7 @@ interaction::InteractionOutput Simulation::interact(
|
||||
}
|
||||
|
||||
//maybe put that into the poisson solver
|
||||
blitz::Array<double,3> Simulation::chargedensity() {
|
||||
blitz::Array<double,2> Simulation::chargedensity() {
|
||||
#ifdef debug_level3
|
||||
DEBUG_LEVEL_3("Initialize chargedensity Array");
|
||||
#endif
|
||||
@@ -619,9 +619,9 @@ blitz::Array<double,3> Simulation::chargedensity() {
|
||||
if(!firstTracked)
|
||||
ERROR("Extracted pointer is null.");
|
||||
|
||||
blitz::Array<double,3> init = firstTracked->
|
||||
blitz::Array<double,2> init = firstTracked->
|
||||
dynamicDensityField()->densityArray();
|
||||
blitz::Array<double, 3> chargeden(init.lbound(), init.extent());
|
||||
blitz::Array<double, 2> chargeden(init.lbound(), init.extent());
|
||||
chargeden = 0.;
|
||||
|
||||
#ifdef debug_level3
|
||||
|
||||
@@ -3,9 +3,9 @@
|
||||
#include "simulation/coordinates.h"
|
||||
|
||||
VectorFieldFromArray::VectorFieldFromArray(
|
||||
const blitz::Array<double, 3>& radial_component,
|
||||
const blitz::Array<double, 3>& azimuthal_component,
|
||||
const blitz::Array<double, 3>& longitudial_component,
|
||||
const blitz::Array<double, 2>& radial_component,
|
||||
const blitz::Array<double, 2>& azimuthal_component,
|
||||
const blitz::Array<double, 2>& longitudial_component,
|
||||
double radius,
|
||||
double length)
|
||||
: Fr_(radial_component.copy()),
|
||||
@@ -14,17 +14,16 @@ VectorFieldFromArray::VectorFieldFromArray(
|
||||
binning_(CylinderBinning(radial_component.extent(0),
|
||||
radius,
|
||||
radial_component.extent(1),
|
||||
radial_component.extent(2),
|
||||
length)) {}
|
||||
|
||||
CylinderVector VectorFieldFromArray::value(const Coordinate& coordinate) const {
|
||||
const blitz::TinyVector<int, 3> bin =
|
||||
const blitz::TinyVector<int, 2> bin =
|
||||
binning_.bin(coordinate.cylinderEntries());
|
||||
return value(bin);
|
||||
}
|
||||
|
||||
CylinderVector VectorFieldFromArray::value(
|
||||
const blitz::TinyVector<int, 3>& bin) const {
|
||||
const blitz::TinyVector<int, 2>& bin) const {
|
||||
if (Fr_.isInRange(bin)) {
|
||||
return CylinderVector(
|
||||
blitz::TinyVector<double, 3>(Fr_(bin), Fphi_(bin), Fz_(bin)));
|
||||
|
||||
@@ -138,7 +138,7 @@ CartesianVector VelocityDistributionFromDensityField::rollVelocity(
|
||||
|
||||
// SIM_INFO("set mu values");
|
||||
|
||||
const blitz::Array<double, 1> mu_values = density_field_->sliceTimeInBinArray(position, energy_eV);
|
||||
const blitz::Array<double, 1> mu_values = density_field_->sliceNumberInBinArray(position, energy_eV);
|
||||
|
||||
// std::cout << mu_values;
|
||||
|
||||
@@ -211,7 +211,7 @@ CartesianVector VelocityDistributionFromDensityField::rollVelocity(
|
||||
// draw pitch angle from DynamicDensityField
|
||||
|
||||
blitz::Array<double, 1> pitchAngleValues = density_field_->
|
||||
sliceTimeInBinArray(position, energy_eV);
|
||||
sliceNumberInBinArray(position, energy_eV);
|
||||
|
||||
std::piecewise_constant_distribution<double> pitchAngle_dist(
|
||||
pitchAngleBinBorders_.begin(),
|
||||
|
||||
Reference in New Issue
Block a user