Commit 08556dc2 authored by Steve Russell's avatar Steve Russell

Update of the RBend and SBend elements. Routines are now more robust and accurate. Input angles are

now in radians instead of degrees.
parent 9815e7b0
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
......@@ -3,110 +3,85 @@
#include "Fields/Fieldmap.hh"
// Class FM1DProfile1
//---------------------------------------------------------------------------
/// Field definition for 1D representation of bending magnet.
//
// Class FM1DProfile1 defines a 1D field map for use in bending magnets.
/*
* Class FM1DProfile.
* --------------------------------------------------------------------------
* Field definition for 1D representation of bending magnet.
*
* Class FM1DProfile1 defines a 1D field map for us in bending magnets.
*/
class FM1DProfile1: public Fieldmap {
public:
/// Calculates the normalized (to 1) field strength on axis and the first and
/// second derivatives (strength[0], stength[1], strength[2]) of the profile
/// given the position, X.
virtual bool getFieldstrength(const Vector_t &X, Vector_t &strength, Vector_t &info) const;
virtual bool getFieldDerivative(const Vector_t &X, Vector_t &E, Vector_t &B, const DiffDirection &dir) const;
/// Get field dimensions.
virtual void getFieldDimensions(double &zBegin, double &zEnd, double &rBegin, double &rEnd) const;
virtual void getFieldDimensions(double &xIni, double &xFinal, double &yIni, double &yFinal, double &zIni, double &zFinal) const;
virtual void swap();
/// Get field information.
virtual void getInfo(Inform *);
virtual bool getFieldDerivative(const Vector_t &X,
Vector_t &E,
Vector_t &B,
const DiffDirection &dir) const;
virtual void Get1DProfile1EntranceParam(double &entranceParameter1,
double &entranceParameter2,
double &entranceParameter3);
virtual void Get1DProfile1ExitParam(double &exitParameter1,
double &exitParameter2,
double &exitParameter3);
virtual double GetFieldGap();
virtual void getFieldDimensions(double &zBegin,
double &zEnd,
double &rBegin,
double &rEnd) const;
virtual void getFieldDimensions(double &xIni,
double &xFinal,
double &yIni,
double &yFinal,
double &zIni,
double &zFinal) const;
virtual bool getFieldstrength(const Vector_t &X,
Vector_t &strength,
Vector_t &info) const;
virtual double getFrequency() const;
virtual void getInfo(Inform *);
virtual void setFrequency(double freq);
virtual void setExitFaceSlope(const double &);
/// Set exit edge constants.
virtual void setEdgeConstants(const double &bendAngle, const double &entranceAngle, const double &exitAngle);
/// Set magnet gap.
virtual void setFieldGap(const double &gap);
/// Set distance between Enge function zeros.
virtual void setFieldLength(const double &length);
virtual void Get1DProfile1EngeCoeffs(std::vector<double> &engeCoeffsEntry,
std::vector<double> &engeCoeffsExit);
virtual void swap();
/// Adjust the extend of the fringe field regions. This is used
/// to make sure we don't see funny jumps in the field as we
/// move into and out of the magnet.
virtual bool adjustFringeFields();
virtual void SetFieldGap(double gap);
private:
/// Constructor with field map file name.
FM1DProfile1(std::string aFilename);
FM1DProfile1(std::string Filename);
virtual ~FM1DProfile1();
/// Read field map.
virtual void freeMap();
virtual void readMap();
/// Free field map.
virtual void freeMap();
/*
* Entrance and exit position parameters. These are read in from the input
* input file. Ultimately they are used to determine the origin of the
* field Enge function and the extent of the field map. However, how they
* are used to do this depends on how the bend using the map is setup in the
* OPAL input file. So, we use generic terms to start.
*/
double entranceParameter1_m;
double entranceParameter2_m;
double entranceParameter3_m;
double exitParameter1_m;
double exitParameter2_m;
double exitParameter3_m;
/// Enge coefficients for map entry and exit regions.
double *EngeCoefs_entry_m;
double *EngeCoefs_exit_m;
/// Entry position of field map entry region.
double zbegin_entry_m;
/// End position of field map entry region.
double zend_entry_m;
/// Origin position for Enge function of field map entry region.
double polynomialOrigin_entry_m;
/// Enge function order for entry region.
int polynomialOrder_entry_m;
/// Entry position of field map exit region.
double zbegin_exit_m;
/// End position of field map exit region.
double zend_exit_m;
/// Origin position for Enge function of field map entry region.
double polynomialOrigin_exit_m;
/// Enge functioin order for entry region.
int polynomialOrder_exit_m;
/// Length of map (m).
double length_m;
/// Bend full gap height (m).
double gapHeight_m;
/// x position in local coordinate system where central trajectory intersects
/// the exit edge.
double xExit_m;
/// z position in local coordinate system where central trajectory intersects
/// the exit edge.
double zExit_m;
std::vector<double> engeCoeffsEntry_m;
std::vector<double> engeCoeffsExit_m;
/// Cos and sin of the exit edge rotation with respect to the local coordinates.
double cosExitRotation_m;
double sinExitRotation_m;
int polyOrderEntry_m; /// Enge function order for entry region.
int polyOrderExit_m; /// Enge function order for entry region.
double gapHeight_m; /// Full gap height of field map.
double exit_slope_m;
double sBegin_m; /// Start of field map in s coordinates (m).
double sEnd_m; /// End of field map in s coordinates (m).
friend class Fieldmap;
};
......
......@@ -270,7 +270,7 @@ MapType Fieldmap::readHeader(std::string Filename) {
h5_size_t grid_dims[3];
h5_size_t field_dims;
char name[20];
h5_size_t len_name = sizeof (name);
h5_size_t len_name = sizeof(name);
h5_int64_t ftype;
h5_file_t *file = H5OpenFile(Filename.c_str(), H5_O_RDONLY, Ippl::getComm());
......@@ -296,8 +296,8 @@ MapType Fieldmap::readHeader(std::string Filename) {
h5err = H5CloseFile(file);
if(h5err != H5_SUCCESS)
ERRORMSG("H5 rc= " << h5err << " in " << __FILE__ << " @ line " << __LINE__ << endl);
if (maptype != UNKNOWN)
return maptype;
if(maptype != UNKNOWN)
return maptype;
}
}
if(strcmp(magicnumber, "Astr") == 0) {
......@@ -336,21 +336,12 @@ void Fieldmap::freeMap(std::string Filename) {
}
}
void Fieldmap::setExitFaceSlope(const double &)
{ }
void Fieldmap::setEdgeConstants(const double &bendAngle, const double &entranceAngle, const double &exitAngle)
{};
void Fieldmap::setFieldGap(const double &)
{};
void Fieldmap::setFieldLength(const double &)
{};
bool Fieldmap::adjustFringeFields()
{ return false; };
void Fieldmap::getLine(ifstream &in, int &lines_read, std::string &buffer) {
size_t firstof = 0;
size_t lastof;
......@@ -546,9 +537,33 @@ std::string Fieldmap::typeset_msg(const std::string &msg, const std::string &tit
return return_string;
}
void Fieldmap::getOnaxisEz(vector<pair<double, double> > & onaxis)
void Fieldmap::getOnaxisEz(vector<pair<double, double> > &onaxis)
{ }
void Fieldmap::Get1DProfile1EngeCoeffs(std::vector<double> &engeCoeffsEntry,
std::vector<double> &engeCoeffsExit) {
}
void Fieldmap::Get1DProfile1EntranceParam(double &entranceParameter1,
double &entranceParameter2,
double &entranceParameter3) {
}
void Fieldmap::Get1DProfile1ExitParam(double &exitParameter1,
double &exitParameter2,
double &exitParameter3) {
}
double Fieldmap::GetFieldGap() {
return 0.0;
}
void Fieldmap::SetFieldGap(double gap) {
}
REGISTER_PARSE_TYPE(int);
REGISTER_PARSE_TYPE(double);
......
......@@ -74,11 +74,19 @@ public:
virtual void getInfo(Inform *msg) = 0;
virtual double getFrequency() const = 0;
virtual void setFrequency(double freq) = 0;
virtual void setExitFaceSlope(const double &);
virtual void setEdgeConstants(const double &bendAngle, const double &entranceAngle, const double &exitAngle);
virtual void setFieldGap(const double &);
virtual void setFieldLength(const double &);
virtual bool adjustFringeFields();
virtual void Get1DProfile1EngeCoeffs(std::vector<double> &engeCoeffsEntry,
std::vector<double> &engeCoeffsExit);
virtual void Get1DProfile1EntranceParam(double &entranceParameter1,
double &entranceParameter2,
double &entranceParameter3);
virtual void Get1DProfile1ExitParam(double &exitParameter1,
double &exitParameter2,
double &exitParameter3);
virtual double GetFieldGap();
virtual void SetFieldGap(double gap);
MapType getType() { return Type;}
......
......@@ -64,33 +64,33 @@ void CSRWakeFunction::apply(PartBunch &bunch) {
if(Options::csrDump) {
static string oldBendName;
static unsigned long counter = 0;
if(oldBendName != bendName_m) counter = 0;
const int every = 1;
bool print_criterion = (counter + 1) % every == 0 && Ippl::myNode() == 0;
if(print_criterion) {
static unsigned int file_number = 0;
if(counter == 0) file_number = 0;
std::stringstream filename_str;
filename_str << "data/" << bendName_m << "-CSRWake" << file_number << ".txt";
std::ofstream csr(filename_str.str().c_str());
csr << bunch.get_sPos() << std::endl;
for(unsigned int i = 0; i < lineDensity_m.size(); ++ i) {
csr << i *meshSpacing << "\t"
<< Ez_m[i] << "\t"
<< lineDensity_m[i] << "\t"
<< dlineDensitydz_m[i] << std::endl;
static string oldBendName;
static unsigned long counter = 0;
if(oldBendName != bendName_m) counter = 0;
const int every = 1;
bool print_criterion = (counter + 1) % every == 0 && Ippl::myNode() == 0;
if(print_criterion) {
static unsigned int file_number = 0;
if(counter == 0) file_number = 0;
std::stringstream filename_str;
filename_str << "data/" << bendName_m << "-CSRWake" << file_number << ".txt";
std::ofstream csr(filename_str.str().c_str());
csr << bunch.get_sPos() << std::endl;
for(unsigned int i = 0; i < lineDensity_m.size(); ++ i) {
csr << i *meshSpacing << "\t"
<< Ez_m[i] << "\t"
<< lineDensity_m[i] << "\t"
<< dlineDensitydz_m[i] << std::endl;
}
csr.close();
msg << "** wrote " << filename_str.str() << endl;
++ file_number;
}
csr.close();
msg << "** wrote " << filename_str.str() << endl;
++ file_number;
}
++ counter;
oldBendName = bendName_m;
++ counter;
oldBendName = bendName_m;
}
}
......@@ -99,19 +99,19 @@ void CSRWakeFunction::initialize(const ElementBase *ref) {
double End;
if(dynamic_cast<const RBend *>(ref)) {
const RBend *bend = dynamic_cast<const RBend *>(ref);
bendRadius_m = bend->getR();
bendRadius_m = bend->GetBendRadius();
bend->getDimensions(Begin_m, End);
Length_m = bend->getEffectiveLength();
FieldBegin_m = Begin_m + bend->getEffectiveCenter() - Length_m / 2.0;
totalBendAngle_m = std::abs(bend->getBendAngle());
Length_m = bend->GetEffectiveLength();
FieldBegin_m = Begin_m + bend->GetEffectiveCenter() - Length_m / 2.0;
totalBendAngle_m = std::abs(bend->GetBendAngle());
bendName_m = bend->getName();
} else if(dynamic_cast<const SBend *>(ref)) {
const SBend *bend = dynamic_cast<const SBend *>(ref);
bendRadius_m = bend->getR();
bendRadius_m = bend->GetBendRadius();
bend->getDimensions(Begin_m, End);
Length_m = bend->getEffectiveLength();
FieldBegin_m = Begin_m + bend->getEffectiveCenter() - Length_m / 2.0;
totalBendAngle_m = bend->getBendAngle();
Length_m = bend->GetEffectiveLength();
FieldBegin_m = Begin_m + bend->GetEffectiveCenter() - Length_m / 2.0;
totalBendAngle_m = bend->GetBendAngle();
bendName_m = bend->getName();
}
}
......
This diff is collapsed.
This diff is collapsed.
......@@ -44,11 +44,14 @@ public:
SLICES, STEPSIZE, // Parameters used to determine slicing.
FMAPFN, // File name containing on-axis field.
GAP, // Full gap of magnet.
APERTURE, // Horizontal (non-bend plane) magnet aperture.
ROTATION, // Magnet rotation about z axis.
ALPHA, // The edge angle 1
BETA, // The edge angle 2
DESIGNENERGY, // the design energy of the particles
EXITANGLE, // the relative angle between the entry and the exit face
GREATERTHANPI, // Boolean flag set to true if bend angle is greater
// than 180 degrees.
SIZE // Total number of attributes.
};
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
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