Commit de24fbbf authored by snuverink_j's avatar snuverink_j
Browse files

fix bug in copy constructor Distribution

remove not implemented Distribution attributes: field, surface and dark current emission
cleanup and reduce includes
uses std namespace for math functions
use integer exponents for `std::pow`
remove unused methods `createpriPart`, `createBoundaryGeometry`
use attribute `SECTOR` for tune calculation
parent 4354d457
......@@ -45,6 +45,7 @@
#include "AbsBeamline/ParallelPlate.h"
#include "AbsBeamline/Stripper.h"
#include "Beamlines/Beamline.h"
#include "Beamlines/FlaggedElmPtr.h"
#include "ComponentWrappers/CorrectorWrapper.h"
......
......@@ -264,15 +264,6 @@ public:
// set the mass per simulation particle
void setMass(double mass);
/// \brief Need Ek for the Schottky effect calculation (eV)
double getEkin() const;
/// Need the work function for the Schottky effect calculation (eV)
double getWorkFunctionRf() const;
/// Need the laser energy for the Schottky effect calculation (eV)
double getLaserEnergy() const;
/// get the total charge per simulation particle
double getCharge() const;
......@@ -362,8 +353,6 @@ public:
void calcEMean();
void correctEnergy(double avrgp);
Inform &print(Inform &os);
/*
......
......@@ -1423,33 +1423,6 @@ void PartBunchBase<T, Dim>::setMass(double mass) {
}
/// \brief Need Ek for the Schottky effect calculation (eV)
template <class T, unsigned Dim>
double PartBunchBase<T, Dim>::getEkin() const {
if(dist_m)
return dist_m->getEkin();
else
return 0.0;
}
/// \brief Need the work function for the Schottky effect calculation (eV)
template <class T, unsigned Dim>
double PartBunchBase<T, Dim>::getWorkFunctionRf() const {
if(dist_m)
return dist_m->getWorkFunctionRf();
else
return 0.0;
}
/// \brief Need the laser energy for the Schottky effect calculation (eV)
template <class T, unsigned Dim>
double PartBunchBase<T, Dim>::getLaserEnergy() const {
if(dist_m)
return dist_m->getLaserEnergy();
else
return 0.0;
}
template <class T, unsigned Dim>
double PartBunchBase<T, Dim>::getCharge() const {
return sum(Q);
......@@ -1880,25 +1853,6 @@ void PartBunchBase<T, Dim>::calcEMean() {
eKin_m /= totalNp;
}
template <class T, unsigned Dim>
void PartBunchBase<T, Dim>::correctEnergy(double avrgp_m) {
const double totalNp = static_cast<double>(getTotalNum());
const double locNp = static_cast<double>(getLocalNum());
double avrgp = 0.0;
for(unsigned int k = 0; k < locNp; k++)
avrgp += sqrt(dot(P[k], P[k]));
reduce(avrgp, avrgp, OpAddAssign());
avrgp /= totalNp;
for(unsigned int k = 0; k < locNp; k++)
P[k](2) = P[k](2) - avrgp + avrgp_m;
}
template <class T, unsigned Dim>
Inform &PartBunchBase<T, Dim>::print(Inform &os) {
......
This diff is collapsed.
#ifndef OPAL_Distribution_HH
#define OPAL_Distribution_HH
// ------------------------------------------------------------------------
// $RCSfile: Distribution.h,v $
// ------------------------------------------------------------------------
// $Revision: 1.1.1.1 $
// ------------------------------------------------------------------------
// Copyright: see Copyright.readme
// ------------------------------------------------------------------------
// Distribution class
//
// Class: Distribution
// Copyright (c) 2008-2020
// Paul Scherrer Institut, Villigen PSI, Switzerland
// All rights reserved.
//
// ------------------------------------------------------------------------
//
// $Date: 2000/03/27 09:33:44 $
// $Author: Andreas Adelmann $
//
// ------------------------------------------------------------------------
#include <iosfwd>
// OPAL is licensed under GNU GPL version 3.
#include <fstream>
#include <string>
#include <vector>
#include "AbstractObjects/Definition.h"
#include "Algorithms/PartData.h"
#include "Algorithms/Vektor.h"
#include "Beamlines/Beamline.h"
#include "AppTypes/SymTenzor.h"
#include "Attributes/Attributes.h"
#include "Ippl.h"
#include "H5hut.h"
#include <gsl/gsl_histogram.h>
#include <gsl/gsl_qrng.h>
#include <gsl/gsl_rng.h>
......@@ -41,13 +28,13 @@
#endif
class Beam;
class Beamline;
template <class T, unsigned Dim>
class PartBunchBase;
class PartBins;
class EnvelopeBunch;
class BoundaryGeometry;
class LaserProfile;
class H5PartWrapper;
......@@ -58,9 +45,7 @@ namespace DistrTypeT
GAUSS,
BINOMIAL,
FLATTOP,
MULTIGAUSS,
SURFACEEMISSION,
SURFACERANDCREATE,
MULTIGAUSS,
GUNGAUSSFLATTOPTH,
ASTRAFLATTOPTH,
MATCHEDGAUSS
......@@ -140,8 +125,8 @@ namespace Attrib
CUTOFFPZ,
FTOSCAMPLITUDE,
FTOSCPERIODS,
SEPPEAKS,
NPEAKS,
SEPPEAKS,
NPEAKS,
R, // the correlation matrix (a la transport)
CORRX,
CORRY,
......@@ -159,33 +144,6 @@ namespace Attrib
ROTATE90,
ROTATE180,
ROTATE270,
NPDARKCUR,
INWARDMARGIN,
EINITHR,
FNA,
FNB,
FNY,
FNVYZERO,
FNVYSECOND,
FNPHIW,
FNBETA,
FNFIELDTHR,
FNMAXEMI,
SECONDARYFLAG,
NEMISSIONMODE,
VSEYZERO, // sey_0 in Vaughn's model.
VEZERO, // Energy related to sey_0 in Vaughan's model.
VSEYMAX, // sey max in Vaughan's model.
VEMAX, // Emax in Vaughan's model.
VKENERGY, // Fitting parameter denotes the roughness of
// surface for impact energy in Vaughn's model.
VKTHETA, // Fitting parameter denotes the roughness of
// surface for impact angle in Vaughn's model.
VVTHERMAL, // Thermal velocity of Maxwellian distribution
// of secondaries in Vaughan's model.
VW,
SURFMATERIAL, // Add material type, currently 0 for copper
// and 1 for stainless steel.
EX, // below is for the matched distribution
EY,
ET,
......@@ -252,7 +210,6 @@ public:
virtual void execute();
virtual void update();
size_t getNumOfLocalParticlesToCreate(size_t n);
void createBoundaryGeometry(PartBunchBase<double, 3> *p, BoundaryGeometry &bg);
void createOpalCycl(PartBunchBase<double, 3> *beam,
size_t numberOfParticles,
double current, const Beamline &bl);
......@@ -265,7 +222,6 @@ public:
std::vector<Distribution *> addedDistributions,
size_t &numberOfParticles);
void createOpalT(PartBunchBase<double, 3> *beam, size_t &numberOfParticles);
void createPriPart(PartBunchBase<double, 3> *beam, BoundaryGeometry &bg);
void doRestartOpalT(PartBunchBase<double, 3> *p, size_t Np, int restartStep, H5PartWrapper *h5wrapper);
void doRestartOpalCycl(PartBunchBase<double, 3> *p, size_t Np, int restartStep,
const int specifiedNumBunch, H5PartWrapper *h5wrapper);
......@@ -274,12 +230,6 @@ public:
double getPercentageEmitted() const;
static Distribution *find(const std::string &name);
void eraseXDist();
void eraseBGxDist();
void eraseYDist();
void eraseBGyDist();
void eraseTOrZDist();
void eraseBGzDist();
bool getIfDistEmitting();
int getLastEmittedEnergyBin();
double getMaxTOrZ();
......@@ -289,49 +239,13 @@ public:
double getEmissionDeltaT();
double getEnergyBinDeltaT();
double getWeight();
std::vector<double>& getXDist();
std::vector<double>& getBGxDist();
std::vector<double>& getYDist();
std::vector<double>& getBGyDist();
std::vector<double>& getTOrZDist();
std::vector<double>& getBGzDist();
/// Return the embedded CLASSIC PartData.
const PartData &getReference() const;
double getTEmission();
Vector_t get_pmean() const;
double getEkin() const;
double getLaserEnergy() const;
double getWorkFunctionRf() const;
size_t getNumberOfDarkCurrentParticles();
double getDarkCurrentParticlesInwardMargin();
double getEInitThreshold();
double getWorkFunction();
double getFieldEnhancement();
size_t getMaxFNemissionPartPerTri();
double getFieldFNThreshold();
double getFNParameterA();
double getFNParameterB();
double getFNParameterY();
double getFNParameterVYZero();
double getFNParameterVYSecond();
int getSecondaryEmissionFlag();
bool getEmissionMode() ;
std::string getTypeofDistribution();
double getvSeyZero();//return sey_0 in Vaughan's model
double getvEZero();//return the energy related to sey_0 in Vaughan's model
double getvSeyMax();//return sey max in Vaughan's model
double getvEmax();//return Emax in Vaughan's model
double getvKenergy();//return fitting parameter denotes the roughness of surface for impact energy in Vaughan's model
double getvKtheta();//return fitting parameter denotes the roughness of surface for impact angle in Vaughan's model
double getvVThermal();//return thermal velocity of Maxwellian distribution of secondaries in Vaughan's model
double getVw();//return velocity scalar for parallel plate benchmark;
int getSurfMaterial();//material type for Furman-Pivi's model 0 for copper, 1 for stainless steel
Inform &printInfo(Inform &os) const;
bool Rebin();
......@@ -342,8 +256,6 @@ public:
void shiftBeam(double &maxTOrZ, double &minTOrZ);
double getEmissionTimeShift() const;
bool GetPreviousH5Local() {return previousH5Local_m;}
void setNumberOfDistributions(unsigned int n) { numberOfDistributions_m = n; }
DistrTypeT::DistrTypeT getType() const;
......@@ -361,6 +273,19 @@ private:
Distribution(const Distribution &) = delete;
void operator=(const Distribution &) = delete;
std::vector<double>& getXDist();
std::vector<double>& getBGxDist();
std::vector<double>& getYDist();
std::vector<double>& getBGyDist();
std::vector<double>& getTOrZDist();
std::vector<double>& getBGzDist();
void eraseXDist();
void eraseBGxDist();
void eraseYDist();
void eraseBGyDist();
void eraseTOrZDist();
void eraseBGzDist();
// void printSigma(SigmaGenerator<double,unsigned int>::matrix_type& M, Inform& out);
void addDistributions();
void applyEmissionModel(double lowEnergyLimit, double &px, double &py, double &pz, std::vector<double> &additionalRNs);
......@@ -430,8 +355,6 @@ private:
void printDistFromFile(Inform &os) const;
void printDistGauss(Inform &os) const;
void printDistMatchedGauss(Inform &os) const;
void printDistSurfEmission(Inform &os) const;
void printDistSurfAndCreate(Inform &os) const;
void printEmissionModel(Inform &os) const;
void printEmissionModelAstra(Inform &os) const;
void printEmissionModelNone(Inform &os) const;
......@@ -448,7 +371,6 @@ private:
void setDistParametersMultiGauss(double massIneV);
void setDistParametersGauss(double massIneV);
void setEmissionTime(double &maxT, double &minT);
void setFieldEmissionParameters();
void setupEmissionModel(PartBunchBase<double, 3> *beam);
void setupEmissionModelAstra(PartBunchBase<double, 3> *beam);
void setupEmissionModelNone(PartBunchBase<double, 3> *beam);
......@@ -479,7 +401,7 @@ private:
EmissionModelT::EmissionModelT emissionModel_m;
/// Emission parameters.
double tEmission_m;
double tEmission_m;
static const double percentTEmission_m; /// Increase tEmission_m by twice this percentage
/// to ensure that no particles fall on the leading edge of
/// the first emission time step or the trailing edge of the last
......@@ -534,8 +456,6 @@ private:
// for compatibility reasons
double avrgpz_m;
//Distribution parameters.
InputMomentumUnitsT::InputMomentumUnitsT inputMoUnits_m;
double sigmaTRise_m;
......@@ -551,48 +471,13 @@ private:
// Parameters multiGauss distribution.
double sepPeaks_m;
unsigned nPeaks_m;
// Laser profile.
std::string laserProfileFileName_m;
std::string laserImageName_m;
double laserIntensityCut_m;
LaserProfile *laserProfile_m;
/*
* Dark current calculation parameters.
*/
size_t darkCurrentParts_m; /// Number of dark current particles.
double darkInwardMargin_m; /// Dark current particle initialization position.
/// Inward along the triangle normal, positive.
/// Inside the geometry.
double eInitThreshold_m; /// Field threshold (MV/m) beyond which particles
/// will be initialized.
double workFunction_m; /// Work function of surface material (eV).
double fieldEnhancement_m; /// Field enhancement factor beta for Fowler-
/// Nordheim emission.
double fieldThrFN_m; /// Field threshold for Fowler-Nordheim
/// emission (MV/m).
size_t maxFN_m; /// Max. number of electrons emitted from a
/// single triangle for Fowler-Nordheim emission.
double paraFNA_m; /// Empirical constant A in Fowler-Nordheim
/// emission model.
double paraFNB_m; /// Empirical constant B in Fowler-Nordheim
/// emission model.
double paraFNY_m; /// Constant for image charge effect parameter y(E)
/// in Fowler-Nordheim emission model.
double paraFNVYSe_m; /// Second order constant for v(y) function in
/// Fowler-Nordheim emission model.
double paraFNVYZe_m; /// Zero order constant for v(y) function in
/// Fowler-Nordheim emission model.
int secondaryFlag_m; /// Select the secondary model type:
/// 0 ==> no secondary emission.
/// 1 ==> Furman-Pivi
/// 2 or larger ==> Vaughan's model
double ppVw_m; /// Velocity scalar for parallel plate benchmark.
double vVThermal_m; /// Thermal velocity of Maxwellian distribution
/// of secondaries in Vaughan's model.
// AAA This is for the matched distribution
double I_m;
double E_m;
......@@ -603,9 +488,6 @@ private:
double sigmaRise_m;
double sigmaFall_m;
double cutoff_m;
// Cyclotron for restart in local mode
bool previousH5Local_m;
};
inline Inform &operator<<(Inform &os, const Distribution &d) {
......@@ -627,150 +509,9 @@ double Distribution::getPercentageEmitted() const {
return (double)totalNumberEmittedParticles_m / (double)totalNumberParticles_m;
}
inline
double Distribution::getEkin() const {
return Attributes::getReal(itsAttr[Attrib::Distribution::EKIN]);
}
inline
double Distribution::getLaserEnergy() const {
return Attributes::getReal(itsAttr[Attrib::Distribution::ELASER]);
}
inline
double Distribution::getWorkFunctionRf() const {
return Attributes::getReal(itsAttr[Attrib::Distribution::W]);
}
inline
size_t Distribution::getNumberOfDarkCurrentParticles() {
return (size_t) Attributes::getReal(itsAttr[Attrib::Distribution::NPDARKCUR]);
}
inline
double Distribution::getDarkCurrentParticlesInwardMargin() {
return Attributes::getReal(itsAttr[Attrib::Distribution::INWARDMARGIN]);
}
inline
double Distribution::getEInitThreshold() {
return Attributes::getReal(itsAttr[Attrib::Distribution::EINITHR]);
}
inline
double Distribution::getWorkFunction() {
return Attributes::getReal(itsAttr[Attrib::Distribution::FNPHIW]);
}
inline
double Distribution::getFieldEnhancement() {
return Attributes::getReal(itsAttr[Attrib::Distribution::FNBETA]);
}
inline
size_t Distribution::getMaxFNemissionPartPerTri() {
return (size_t) Attributes::getReal(itsAttr[Attrib::Distribution::FNMAXEMI]);
}
inline
double Distribution::getFieldFNThreshold() {
return Attributes::getReal(itsAttr[Attrib::Distribution::FNFIELDTHR]);
}
inline
double Distribution::getFNParameterA() {
return Attributes::getReal(itsAttr[Attrib::Distribution::FNA]);
}
inline
double Distribution::getFNParameterB() {
return Attributes::getReal(itsAttr[Attrib::Distribution::FNB]);
}
inline
double Distribution::getFNParameterY() {
return Attributes::getReal(itsAttr[Attrib::Distribution::FNY]);
}
inline
double Distribution::getFNParameterVYZero() {
return Attributes::getReal(itsAttr[Attrib::Distribution::FNVYZERO]);
}
inline
double Distribution::getFNParameterVYSecond() {
return Attributes::getReal(itsAttr[Attrib::Distribution::FNVYSECOND]);
}
inline
int Distribution::getSecondaryEmissionFlag() {
return Attributes::getReal(itsAttr[Attrib::Distribution::SECONDARYFLAG]);
}
inline
bool Distribution::getEmissionMode() {
return Attributes::getBool(itsAttr[Attrib::Distribution::NEMISSIONMODE]);
}
inline
std::string Distribution::getTypeofDistribution() {
return (std::string) Attributes::getString(itsAttr[Attrib::Distribution::TYPE]);
}
inline
double Distribution::getvSeyZero() {
// return sey_0 in Vaughan's model
return Attributes::getReal(itsAttr[Attrib::Distribution::VSEYZERO]);
}
inline
double Distribution::getvEZero() {
// return the energy related to sey_0 in Vaughan's model
return Attributes::getReal(itsAttr[Attrib::Distribution::VEZERO]);
}
inline
double Distribution::getvSeyMax() {
// return sey max in Vaughan's model
return Attributes::getReal(itsAttr[Attrib::Distribution::VSEYMAX]);
}
inline
double Distribution::getvEmax() {
// return Emax in Vaughan's model
return Attributes::getReal(itsAttr[Attrib::Distribution::VEMAX]);
}
inline
double Distribution::getvKenergy() {
// return fitting parameter denotes the roughness of surface for
// impact energy in Vaughan's model
return Attributes::getReal(itsAttr[Attrib::Distribution::VKENERGY]);
}
inline
double Distribution::getvKtheta() {
// return fitting parameter denotes the roughness of surface for
// impact angle in Vaughan's model
return Attributes::getReal(itsAttr[Attrib::Distribution::VKTHETA]);
}
inline
double Distribution::getvVThermal() {
// thermal velocity of Maxwellian distribution of secondaries in Vaughan's model
return Attributes::getReal(itsAttr[Attrib::Distribution::VVTHERMAL]);
}
inline
double Distribution::getVw() {
// velocity scalar for parallel plate benchmark;
return Attributes::getReal(itsAttr[Attrib::Distribution::VW]);
}
inline
int Distribution::getSurfMaterial() {
// Surface material number for Furman-Pivi's Model;
return (int)Attributes::getReal(itsAttr[Attrib::Distribution::SURFMATERIAL]);
}
#endif // OPAL_Distribution_HH
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment