29 #include <boost/filesystem.hpp> 
   40            "The \"DUMPEMFIELDS\" statement dumps a field map to a user-defined " 
   41            "field file, for checking that fields are generated correctly. " 
   42            "The fields are written out on a grid in space and time."),
 
   48         (
"FILE_NAME", 
"Name of the file to which field data is dumped");
 
   51         (
"COORDINATE_SYSTEM", 
"Choose to use CARTESIAN or CYLINDRICAL coordinates", {
"CARTESIAN", 
"CYLINDRICAL"}, 
"CARTESIAN");
 
   54         (
"X_START", 
"(Cartesian) Start point in the grid in x [m]");
 
   57         (
"DX", 
"(Cartesian) Grid step size in x [m]");
 
   60         (
"X_STEPS", 
"(Cartesian) Number of steps in x");
 
   63         (
"Y_START", 
"(Cartesian) Start point in the grid in y [m]");
 
   66         (
"DY", 
"(Cartesian) Grid step size in y [m]");
 
   69         (
"Y_STEPS", 
"(Cartesian) Number of steps in y");
 
   72         (
"Z_START", 
"Start point in the grid in z [m]");
 
   75         (
"DZ", 
"Grid step size in z [m]");
 
   78         (
"Z_STEPS", 
"Number of steps in z");
 
   81         (
"T_START", 
"Start point in the grid in time [ns]");
 
   84         (
"DT", 
"Grid step size in time [ns]");
 
   87         (
"T_STEPS", 
"Number of steps in time");
 
   90         (
"R_START", 
"(Cylindrical) Start point in the grid in radius [m]");
 
   93         (
"DR", 
"(Cylindrical) Grid step size in radius [m]");
 
   96         (
"R_STEPS", 
"(Cylindrical) Number of steps in radius");
 
   99         (
"PHI_START", 
"(Cylindrical) Start point in the grid in phi [rad]");
 
  102         (
"DPHI", 
"(Cylindrical) Grid step size in phi [rad]");
 
  105         (
"PHI_STEPS", 
"(Cylindrical) Number of steps in phi");
 
  135     if (coordStr == 
"CYLINDRICAL") {
 
  137     } 
else if (coordStr == 
"CARTESIAN") {
 
  152     std::vector<double> spacing(4);
 
  153     std::vector<double> origin(4);
 
  154     std::vector<int> gridSize(4);
 
  206         (*it)->writeFieldThis(field);
 
  214                             "Value for " + 
name +
 
  215                             " should be an integer but a real value was found");
 
  219                             "Value for " + 
name + 
" should be 1 or more");
 
  226         fout << 1 << 
"  r [mm]\n";
 
  227         fout << 2 << 
"  phi [degree]\n";
 
  229         fout << 1 << 
"  x [mm]\n";
 
  230         fout << 2 << 
"  y [mm]\n";
 
  232     fout << 3 << 
"  z [mm]\n";
 
  233     fout << 4 << 
"  t [ns]\n";
 
  235         fout << 5 << 
"  Br [kGauss]\n";
 
  236         fout << 6 << 
"  Bphi [kGauss]\n";
 
  237         fout << 7 << 
"  Bz [kGauss]\n";
 
  238         fout << 8 << 
"  Er [MV/m]\n";
 
  239         fout << 9 << 
"  Ephi [MV/m]\n";
 
  240         fout << 10 << 
" Ez [MV/m]\n";
 
  242         fout << 5 << 
"  Bx [kGauss]\n";
 
  243         fout << 6 << 
"  By [kGauss]\n";
 
  244         fout << 7 << 
"  Bz [kGauss]\n";
 
  245         fout << 8 << 
"  Ex [MV/m]\n";
 
  246         fout << 9 << 
"  Ey [MV/m]\n";
 
  247         fout << 10 << 
" Ez [MV/m]\n";
 
  255                                   std::ofstream& fout)
 const {
 
  262         point[0] = 
std::cos(pointIn[1])*pointIn[0];
 
  263         point[1] = 
std::sin(pointIn[1])*pointIn[0];
 
  266     field->
apply(point, centroid, time, E, B);
 
  275         fout << pointIn[0] << 
" " << pointIn[1]*
Physics::rad2deg << 
" " << pointIn[2] << 
" " << time << 
" ";
 
  277         fout << pointIn[0] << 
" " << pointIn[1] << 
" " << pointIn[2] << 
" " << time << 
" ";
 
  280     fout << Bout[0] << 
" " << Bout[1] << 
" " << Bout[2] << 
" ";
 
  281     fout << Eout[0] << 
" " << Eout[1] << 
" " << Eout[2] << 
"\n";
 
  287                             "The grid was NULL; there was a problem with the DumpEMFields initialisation.");
 
  291                             "The field to be written was NULL.");
 
  297     if (boost::filesystem::path(
filename_m).is_absolute() == 
true) {
 
  306     std::vector<double> point_std(4);
 
  310         fout.open(fname.c_str(), std::ofstream::out);
 
  311     } 
catch (std::exception& exc) {
 
  313                             "Failed to open DumpEMFields file " + 
filename_m);
 
  317                             "Failed to open DumpEMFields file " + 
filename_m);
 
  324         it.getPosition(&point_std[0]);
 
  325         for (
size_t i = 0; i < 3; ++i) {
 
  326             point[i] = point_std[i];
 
  328         double time = point_std[3];
 
  333                             "Something went wrong during writing " + 
filename_m);
 
  339     os << 
"* ************* D U M P  E M  F I E L D S ****************************************** " << 
std::endl;
 
  342         os << 
"* Coordinate system: " << 
"Cartesian" << 
'\n' 
  350         os << 
"* Coordinate system: " << 
"Cylindrical" << 
'\n' 
  364     os << 
"* ********************************************************************************** " << 
std::endl;
 
Tps< T > cos(const Tps< T > &x)
Cosine.
 
Tps< T > sin(const Tps< T > &x)
Sine.
 
PartBunchBase< T, Dim >::ConstIterator end(PartBunchBase< T, Dim > const &bunch)
 
FLieGenerator< T, N > real(const FLieGenerator< std::complex< T >, N > &)
Take real part of a complex generator.
 
PETE_TUTree< FnAbs, typename T::PETE_Expr_t > abs(const PETE_Expr< T > &l)
 
PETE_TUTree< FnFloor, typename T::PETE_Expr_t > floor(const PETE_Expr< T > &l)
 
Inform & endl(Inform &inf)
 
double getReal(const Attribute &attr)
Return real value.
 
Attribute makePredefinedString(const std::string &name, const std::string &help, const std::initializer_list< std::string > &predefinedStrings)
Make predefined string attribute.
 
Attribute makeReal(const std::string &name, const std::string &help)
Make real attribute.
 
std::string getString(const Attribute &attr)
Get string value.
 
Attribute makeString(const std::string &name, const std::string &help)
Make string attribute.
 
constexpr double rad2deg
The conversion factor from radians to degrees.
 
std::string::iterator iterator
 
std::string combineFilePath(std::initializer_list< std::string > ilist)
 
The base class for all OPAL actions.
 
void registerOwnership(const AttributeHandler::OwnerType &itsClass) const
 
std::vector< Attribute > itsAttr
The object attributes.
 
static OpalData * getInstance()
 
std::string getAuxiliaryOutputDirectory() const
get the name of the the additional data directory
 
virtual void writeFieldThis(Component *field)
 
void print(std::ostream &os) const
 
static std::unordered_set< DumpEMFields * > dumpsSet_m
 
void parseCoordinateSystem()
 
static void writeFields(Component *field)
 
interpolation::NDGrid * grid_m
 
CoordinateSystem coordinates_m
 
void writeHeader(std::ofstream &fout) const
 
static void checkInt(double value, std::string name, double tolerance=1e-9)
 
virtual DumpEMFields * clone(const std::string &name)
 
void writeFieldLine(Component *field, const Vector_t &point, const double &time, std::ofstream &fout) const
 
Interface for a single beam element.
 
virtual bool apply(const size_t &i, const double &t, Vector_t &E, Vector_t &B)
 
Mesh::Iterator begin() const
 
Mesh::Iterator end() const
 
The base class for all OPAL exceptions.