Commit dadebb2c authored by kraus's avatar kraus

adding renamed files

parent 23889ce0
// ------------------------------------------------------------------------
// $RCSfile: CCollimator.cpp,v $
// ------------------------------------------------------------------------
// $Revision: 1.1.1.1 $
// ------------------------------------------------------------------------
// Copyright: see Copyright.readme
// ------------------------------------------------------------------------
//
// Class: CCollimator
// Defines the abstract interface for a beam collimator for cyclotrons.
//
// ------------------------------------------------------------------------
// Class category: AbsBeamline
// ------------------------------------------------------------------------
//
// $Date: 2000/03/27 09:32:31 $
// $Author: fci $
//
// ------------------------------------------------------------------------
#include "AbsBeamline/CCollimator.h"
#include "Physics/Physics.h"
#include "Algorithms/PartBunchBase.h"
#include "AbsBeamline/BeamlineVisitor.h"
#include "Fields/Fieldmap.h"
#include "Structure/LossDataSink.h"
#include "Utilities/Options.h"
#include "Solvers/ParticleMatterInteractionHandler.hh"
#include "Utilities/Util.h"
#include <memory>
extern Inform *gmsg;
// Class Collimator
// ------------------------------------------------------------------------
CCollimator::CCollimator():
Component(),
filename_m(""),
informed_m(false),
xstart_m(0.0),
xend_m(0.0),
ystart_m(0.0),
yend_m(0.0),
width_m(0.0),
losses_m(0),
lossDs_m(nullptr),
parmatint_m(NULL)
{}
CCollimator::CCollimator(const CCollimator &right):
Component(right),
filename_m(right.filename_m),
informed_m(right.informed_m),
xstart_m(right.xstart_m),
xend_m(right.xend_m),
ystart_m(right.ystart_m),
yend_m(right.yend_m),
zstart_m(right.zstart_m),
zend_m(right.zend_m),
width_m(right.width_m),
losses_m(0),
lossDs_m(nullptr),
parmatint_m(NULL)
{
setGeom();
}
CCollimator::CCollimator(const std::string &name):
Component(name),
filename_m(""),
informed_m(false),
xstart_m(0.0),
xend_m(0.0),
ystart_m(0.0),
yend_m(0.0),
zstart_m(0.0),
zend_m(0.0),
width_m(0.0),
losses_m(0),
lossDs_m(nullptr),
parmatint_m(NULL)
{}
CCollimator::~CCollimator() {
if (online_m)
goOffline();
}
void CCollimator::accept(BeamlineVisitor &visitor) const {
visitor.visitCCollimator(*this);
}
bool CCollimator::apply(const size_t &i, const double &t, Vector_t &E, Vector_t &B) {
return false;
}
bool CCollimator::applyToReferenceParticle(const Vector_t &R, const Vector_t &P, const double &t, Vector_t &E, Vector_t &B) {
return false;
}
bool CCollimator::checkCollimator(Vector_t r, Vector_t rmin, Vector_t rmax) {
double r_start = sqrt(xstart_m * xstart_m + ystart_m * ystart_m);
double r_end = sqrt(xend_m * xend_m + yend_m * yend_m);
double r1 = sqrt(rmax(0) * rmax(0) + rmax(1) * rmax(1));
bool isDead = false;
if (rmax(2) >= zstart_m && rmin(2) <= zend_m) {
if ( r1 > r_start - 10.0 && r1 < r_end + 10.0 ){
if (r(2) < zend_m && r(2) > zstart_m ) {
int pflag = checkPoint(r(0), r(1));
isDead = (pflag != 0);
}
}
}
return isDead;
}
// rectangle collimators in cyclotron cyclindral coordinates
// without particlematterinteraction, the particle hitting collimator is deleted directly
bool CCollimator::checkCollimator(PartBunchBase<double, 3> *bunch, const int turnnumber, const double t, const double tstep) {
bool flagNeedUpdate = false;
Vector_t rmin, rmax;
bunch->get_bounds(rmin, rmax);
double r_start = sqrt(xstart_m * xstart_m + ystart_m * ystart_m);
double r_end = sqrt(xend_m * xend_m + yend_m * yend_m);
double r1 = sqrt(rmax(0) * rmax(0) + rmax(1) * rmax(1));
std::pair<Vector_t, double> boundingSphere;
boundingSphere.first = 0.5 * (rmax + rmin);
boundingSphere.second = euclidean_norm(rmax - boundingSphere.first);
if (rmax(2) >= zstart_m && rmin(2) <= zend_m) {
// if ( r1 > r_start - 10.0 && r1 < r_end + 10.0 ){
if ( r1 > r_start - 100.0 && r1 < r_end + 100.0 ){
size_t tempnum = bunch->getLocalNum();
int pflag = 0;
for (unsigned int i = 0; i < tempnum; ++i) {
if (bunch->PType[i] == ParticleType::REGULAR && bunch->R[i](2) < zend_m && bunch->R[i](2) > zstart_m ) {
pflag = checkPoint(bunch->R[i](0), bunch->R[i](1));
/// bunch->Bin[i] != -1 makes sure the partcile is not stored in more than one collimator
if ((pflag != 0) && (bunch->Bin[i] != -1)) {
if (!parmatint_m)
lossDs_m->addParticle(bunch->R[i], bunch->P[i], bunch->ID[i]);
bunch->Bin[i] = -1;
flagNeedUpdate = true;
}
}
}
}
}
reduce(&flagNeedUpdate, &flagNeedUpdate + 1, &flagNeedUpdate, OpBitwiseOrAssign());
if (flagNeedUpdate && parmatint_m) {
parmatint_m->apply(bunch, boundingSphere);
}
return flagNeedUpdate;
}
void CCollimator::initialise(PartBunchBase<double, 3> *bunch, double &startField, double &endField) {
endField = startField + getElementLength();
initialise(bunch);
}
void CCollimator::initialise(PartBunchBase<double, 3> *bunch) {
RefPartBunch_m = bunch;
parmatint_m = getParticleMatterInteraction();
// if (!parmatint_m) {
if (filename_m == std::string(""))
lossDs_m = std::unique_ptr<LossDataSink>(new LossDataSink(getName(), !Options::asciidump));
else
lossDs_m = std::unique_ptr<LossDataSink>(new LossDataSink(filename_m.substr(0, filename_m.rfind(".")), !Options::asciidump));
// }
goOnline(-1e6);
}
void CCollimator::finalise()
{
if (online_m)
goOffline();
*gmsg << "* Finalize probe" << endl;
}
void CCollimator::goOnline(const double &) {
print();
// PosX_m.reserve((int)(1.1 * RefPartBunch_m->getLocalNum()));
// PosY_m.reserve((int)(1.1 * RefPartBunch_m->getLocalNum()));
// PosZ_m.reserve((int)(1.1 * RefPartBunch_m->getLocalNum()));
// MomentumX_m.reserve((int)(1.1 * RefPartBunch_m->getLocalNum()));
// MomentumY_m.reserve((int)(1.1 * RefPartBunch_m->getLocalNum()));
// MomentumZ_m.reserve((int)(1.1 * RefPartBunch_m->getLocalNum()));
// time_m.reserve((int)(1.1 * RefPartBunch_m->getLocalNum()));
// id_m.reserve((int)(1.1 * RefPartBunch_m->getLocalNum()));
online_m = true;
}
void CCollimator::print() {
if (RefPartBunch_m == NULL) {
if (!informed_m) {
std::string errormsg = Fieldmap::typeset_msg("BUNCH SIZE NOT SET", "warning");
ERRORMSG(errormsg << endl);
if (Ippl::myNode() == 0) {
std::ofstream omsg("errormsg.txt", std::ios_base::app);
omsg << errormsg << std::endl;
omsg.close();
}
informed_m = true;
}
return;
}
*gmsg << "* CCollimator angle start " << xstart_m << " (Deg) angle end " << ystart_m << " (Deg) "
<< "R start " << xend_m << " (mm) R rend " << yend_m << " (mm)" << endl;
}
void CCollimator::goOffline() {
if (online_m && lossDs_m)
lossDs_m->save();
lossDs_m.reset(0);
online_m = false;
}
bool CCollimator::bends() const {
return false;
}
void CCollimator::setOutputFN(std::string fn) {
filename_m = fn;
}
std::string CCollimator::getOutputFN() {
if (filename_m == std::string(""))
return getName();
else
return filename_m.substr(0, filename_m.rfind("."));
}
void CCollimator::getDimensions(double &zBegin, double &zEnd) const {
zBegin = 0.0;
zEnd = getElementLength();
}
ElementBase::ElementType CCollimator::getType() const {
return CCOLLIMATOR;
}
std::string CCollimator::getCollimatorShape() {
return "CCollimator";
}
void CCollimator::setGeom() {
double slope;
if (xend_m == xstart_m)
slope = 1.0e12;
else
slope = (yend_m - ystart_m) / (xend_m - xstart_m);
double coeff2 = sqrt(1 + slope * slope);
double coeff1 = slope / coeff2;
double halfdist = width_m / 2.0;
geom_m[0].x = xstart_m - halfdist * coeff1;
geom_m[0].y = ystart_m + halfdist / coeff2;
geom_m[1].x = xstart_m + halfdist * coeff1;
geom_m[1].y = ystart_m - halfdist / coeff2;
geom_m[2].x = xend_m + halfdist * coeff1;
geom_m[2].y = yend_m - halfdist / coeff2;
geom_m[3].x = xend_m - halfdist * coeff1;
geom_m[3].y = yend_m + halfdist / coeff2;
geom_m[4].x = geom_m[0].x;
geom_m[4].y = geom_m[0].y;
if (zstart_m > zend_m){
double tempz = zstart_m;
zstart_m = zend_m;
zend_m = tempz;
}
}
int CCollimator::checkPoint(const double &x, const double &y) {
int cn = 0;
for (int i = 0; i < 4; i++) {
if (((geom_m[i].y <= y) && (geom_m[i+1].y > y))
|| ((geom_m[i].y > y) && (geom_m[i+1].y <= y))) {
float vt = (float)(y - geom_m[i].y) / (geom_m[i+1].y - geom_m[i].y);
if (x < geom_m[i].x + vt * (geom_m[i+1].x - geom_m[i].x))
++cn;
}
}
return (cn & 1); // 0 if even (out), and 1 if odd (in)
}
\ No newline at end of file
#ifndef CLASSIC_CCollimator_HH
#define CLASSIC_CCollimator_HH
// Class category: AbsBeamline
// ------------------------------------------------------------------------
//
// $Date: 2000/03/27 09:32:31 $
// $Author: fci $
// Copyright: see Copyright.readme
// ------------------------------------------------------------------------
//
// Class: CCollimator
// Defines the abstract interface for a beam CCollimator.
// *** MISSING *** CCollimator interface is still incomplete.
//
// ------------------------------------------------------------------------
// Class category: AbsBeamline
// ------------------------------------------------------------------------
//
// $Date: 2000/03/27 09:32:31 $
// $Author: fci $
//
// ------------------------------------------------------------------------
#include "AbsBeamline/Component.h"
#include "gsl/gsl_spline.h"
#include "gsl/gsl_interp.h"
#include <vector>
class BeamlineVisitor;
class LossDataSink;
// Class CCollimator
// ------------------------------------------------------------------------
/// Abstract collimator.
// Class CCollimator defines the abstract interface for a collimator.
class CCollimator: public Component {
public:
/// Constructor with given name.
explicit CCollimator(const std::string &name);
CCollimator();
CCollimator(const CCollimator &rhs);
virtual ~CCollimator();
/// Apply visitor to CCollimator.
virtual void accept(BeamlineVisitor &) const;
virtual bool apply(const size_t &i, const double &t, Vector_t &E, Vector_t &B);
virtual bool applyToReferenceParticle(const Vector_t &R, const Vector_t &P, const double &t, Vector_t &E, Vector_t &B);
virtual bool checkCollimator(PartBunchBase<double, 3> *bunch, const int turnnumber, const double t, const double tstep);
virtual bool checkCollimator(Vector_t r, Vector_t rmin, Vector_t rmax);
virtual void initialise(PartBunchBase<double, 3> *bunch, double &startField, double &endField);
virtual void initialise(PartBunchBase<double, 3> *bunch);
virtual void finalise();
virtual bool bends() const;
virtual void goOnline(const double &kineticEnergy);
virtual void goOffline();
virtual ElementBase::ElementType getType() const;
virtual void getDimensions(double &zBegin, double &zEnd) const;
void print();
std::string getCollimatorShape();
void setOutputFN(std::string fn);
std::string getOutputFN();
unsigned int getLosses() const;
// void setXsize(double a) ;
// void setYsize(double b) ;
// void setXpos(double x0) ;
// void setYpos(double y0) ;
// double getXsize(double a) ;
// double getYsize(double b) ;
// double getXpos() ;
// double getYpos() ;
// --------Cyclotron collimator
void setXStart(double xstart) ;
void setYStart(double ystart) ;
void setZStart(double zstart) ;
void setXEnd(double xend) ;
void setYEnd(double yend) ;
void setZEnd(double zend) ;
void setWidth(double width) ;
double getXStart() ;
double getYStart() ;
double getZStart() ;
double getXEnd() ;
double getYEnd() ;
double getZEnd() ;
double getWidth() ;
int checkPoint(const double & x, const double & y );
private:
// Not implemented.
void operator=(const CCollimator &);
std::string filename_m; /**< The name of the outputfile*/
bool informed_m;
//parameters for CCollimator
double xstart_m;
double xend_m;
double ystart_m;
double yend_m;
double zstart_m;
double zend_m;
double width_m;
Point geom_m[5];
void setGeom();
unsigned int losses_m;
std::unique_ptr<LossDataSink> lossDs_m;
ParticleMatterInteractionHandler *parmatint_m;
};
inline
unsigned int CCollimator::getLosses() const {
return losses_m;
}
inline
void CCollimator::setXStart(double xstart) {
xstart_m = xstart;
}
inline
void CCollimator::setXEnd(double xend) {
xend_m = xend;
}
inline
void CCollimator::setYStart(double ystart) {
ystart_m = ystart;
}
inline
void CCollimator::setYEnd(double yend) {
yend_m = yend;
}
inline
void CCollimator::setZStart(double zstart) {
zstart_m = zstart;
}
inline
void CCollimator::setZEnd(double zend) {
zend_m = zend;
}
inline
void CCollimator::setWidth(double width) {
width_m = width;
}
inline
double CCollimator::getXStart() {
return xstart_m;
}
inline
double CCollimator::getXEnd() {
return xend_m;
}
inline
double CCollimator::getYStart() {
return ystart_m;
}
inline
double CCollimator::getYEnd() {
return yend_m;
}
inline
double CCollimator::getZStart() {
return zstart_m;
}
inline
double CCollimator::getZEnd() {
return zend_m;
}
inline
double CCollimator::getWidth() {
return width_m;
}
#endif // CLASSIC_CCollimator_HH
\ No newline at end of file
// ------------------------------------------------------------------------
// $RCSfile: CCollimatorRep.cpp,v $
// ------------------------------------------------------------------------
// $Revision: 1.1.1.1 $
// ------------------------------------------------------------------------
// Copyright: see Copyright.readme
// ------------------------------------------------------------------------
//
// Class: CCollimatorRep
// Defines a concrete collimator representation.
//
// ------------------------------------------------------------------------
// Class category: BeamlineCore
// ------------------------------------------------------------------------
//
// $Date: 2000/03/27 09:32:33 $
// $Author: fci $
//
// ------------------------------------------------------------------------
#include "BeamlineCore/CCollimatorRep.h"
#include "AbsBeamline/ElementImage.h"
#include "Channels/IndirectChannel.h"
// Attribute access table.
// ------------------------------------------------------------------------
namespace {
struct Entry {
const char *name;
double(CCollimatorRep::*get)() const;
void (CCollimatorRep::*set)(double);
};
const Entry entries[] = {
{
"L",
&CCollimatorRep::getElementLength,
&CCollimatorRep::setElementLength
},
{ 0, 0, 0 }
};
}
// Class CCollimatorRep
// ------------------------------------------------------------------------
CCollimatorRep::CCollimatorRep():
CCollimator(),
geometry(0.0)
{}
CCollimatorRep::CCollimatorRep(const CCollimatorRep &right):
CCollimator(right),
geometry(right.geometry)
{}
CCollimatorRep::CCollimatorRep(const std::string &name):
CCollimator(name),
geometry()
{}
CCollimatorRep::~CCollimatorRep()
{}
ElementBase *CCollimatorRep::clone() const {
return new CCollimatorRep(*this);
}
Channel *CCollimatorRep::getChannel(const std::string &aKey, bool create) {
for(const Entry *entry = entries; entry->name != 0; ++entry) {
if(aKey == entry->name) {
return new IndirectChannel<CCollimatorRep>(*this, entry->get, entry->set);
}
}
return ElementBase::getChannel(aKey, create);
}
NullField &CCollimatorRep::getField() {
return field;
}
const NullField &CCollimatorRep::getField() const {
return field;
}
StraightGeometry &CCollimatorRep::getGeometry() {
return geometry;
}
const StraightGeometry &CCollimatorRep::getGeometry() const {
return geometry;
}
ElementImage *CCollimatorRep::getImage() const {
ElementImage *image = ElementBase::getImage();
for(const Entry *entry = entries; entry->name != 0; ++entry) {
image->setAttribute(entry->name, (this->*(entry->get))());
}
return image;
}
/*
double CCollimatorRep::getXsize() const
{
return xSize;
}
double CCollimatorRep::getYsize() const
{
return ySize;
}
void CCollimatorRep::setXsize(double size)
{
INFOMSG("void CCollimatorRep::setXsize(double size) " << xSize << endl;);
xSize = size;
}
void CCollimatorRep::setYsize(double size)
{
ySize = size;
}
*/
\ No newline at end of file
#ifndef CLASSIC_CCollimatorRep_HH
#define CLASSIC_CCollimatorRep_HH
// ------------------------------------------------------------------------
// $RCSfile: CCollimatorRep.h,v $