42 std::string(
"The \"DUMPEMFIELDS\" statement dumps a field map to a user-defined")+
43 std::string(
" field file, for checking that fields are generated correctly.")+
44 std::string(
" The fields are written out on a grid in space and time.");
47 Action(20,
"DUMPEMFIELDS", dumpemfields_docstring.c_str()),
48 grid_m(NULL), filename_m(
"") {
51 (
"X_START",
"(Cartesian) Start point in the grid in x [m]");
53 (
"DX",
"(Cartesian) Grid step size in x [m]");
55 (
"X_STEPS",
"(Cartesian) Number of steps in x");
57 (
"Y_START",
"(Cartesian) Start point in the grid in y [m]");
59 (
"DY",
"(Cartesian) Grid step size in y [m]");
61 (
"Y_STEPS",
"(Cartesian) Number of steps in y");
63 (
"Z_START",
"Start point in the grid in z [m]");
65 (
"DZ",
"Grid step size in z [m]");
67 (
"Z_STEPS",
"Number of steps in z");
69 (
"T_START",
"Start point in the grid in time [ns]");
71 (
"DT",
"Grid step size in time [ns]");
73 (
"T_STEPS",
"Number of steps in time");
75 (
"FILE_NAME",
"Name of the file to which field data is dumped");
77 "Choose to use 'Cartesian' or 'Cylindrical' coordinates");
79 (
"R_START",
"(Cylindrical) Start point in the grid in radius [m]");
81 (
"DR",
"(Cylindrical) Grid step size in radius [m]");
83 (
"R_STEPS",
"(Cylindrical) Number of steps in radius");
85 (
"PHI_START",
"(Cylindrical) Start point in the grid in phi [rad]");
87 (
"DPHI",
"(Cylindrical) Grid step size in phi [rad]");
89 (
"PHI_STEPS",
"(Cylindrical) Number of steps in phi");
116 for (
size_t i = 0; i < coordStr.size(); ++i) {
117 coordStr[i] = tolower(coordStr[i]);
119 if (coordStr ==
"cylindrical") {
121 }
else if (coordStr ==
"cartesian") {
126 std::string(
"'. OPAL expected either 'cylindrical' or 'cartesian'."));
140 std::vector<double> spacing(4);
141 std::vector<double> origin(4);
142 std::vector<int> gridSize(4);
194 (*it)->writeFieldThis(field);
200 if (
fabs(
floor(real) - real) > 2*tolerance) {
203 " should be an integer but a real value was found");
205 if (
floor(real) < 0.5) {
207 "Value for "+name+
" should be 1 or more");
214 fout << 1 <<
" r [mm]\n";
215 fout << 2 <<
" phi [degree]\n";
217 fout << 1 <<
" x [mm]\n";
218 fout << 2 <<
" y [mm]\n";
220 fout << 3 <<
" z [mm]\n";
221 fout << 4 <<
" t [ns]\n";
223 fout << 5 <<
" Br [kGauss]\n";
224 fout << 6 <<
" Bphi [kGauss]\n";
225 fout << 7 <<
" Bz [kGauss]\n";
226 fout << 8 <<
" Er [MV/m]\n";
227 fout << 9 <<
" Ephi [MV/m]\n";
228 fout << 10 <<
" Ez [MV/m]\n";
230 fout << 5 <<
" Bx [kGauss]\n";
231 fout << 6 <<
" By [kGauss]\n";
232 fout << 7 <<
" Bz [kGauss]\n";
233 fout << 8 <<
" Ex [MV/m]\n";
234 fout << 9 <<
" Ey [MV/m]\n";
235 fout << 10 <<
" Ez [MV/m]\n";
243 std::ofstream& fout)
const {
250 point[0] =
cos(pointIn[1])*pointIn[0];
251 point[1] =
sin(pointIn[1])*pointIn[0];
254 field->
apply(point, centroid, time, E, B);
259 Bout[0] = B[0]*
cos(pointIn[1])+B[1]*
sin(pointIn[1]);
260 Bout[1] = -B[0]*
sin(pointIn[1])+B[1]*
cos(pointIn[1]);
261 Eout[0] = E[0]*
cos(pointIn[1])+E[1]*
sin(pointIn[1]);
262 Eout[1] = -E[0]*
sin(pointIn[1])+E[1]*
cos(pointIn[1]);
263 fout << pointIn[0] <<
" " << pointIn[1]*
DEGREE <<
" " << pointIn[2] <<
" " << time <<
" ";
265 fout << pointIn[0] <<
" " << pointIn[1] <<
" " << pointIn[2] <<
" " << time <<
" ";
268 fout << Bout[0] <<
" " << Bout[1] <<
" " << Bout[2] <<
" ";
269 fout << Eout[0] <<
" " << Eout[1] <<
" " << Eout[2] <<
"\n";
275 "The grid was NULL; there was a problem with the DumpEMFields initialisation.");
280 "The field to be written was NULL.");
282 std::vector<double> point_std(4);
286 fout.open(
filename_m.c_str(), std::ofstream::out);
287 }
catch (std::exception& exc) {
289 "Failed to open DumpEMFields file "+
filename_m);
293 "Failed to open DumpEMFields file "+
filename_m);
300 it.getPosition(&point_std[0]);
301 for (
size_t i = 0; i < 3; ++i) {
302 point[i] = point_std[i];
304 double time = point_std[3];
309 "Something went wrong during writing "+
filename_m);
virtual bool apply(const size_t &i, const double &t, Vector_t &E, Vector_t &B)
void parseCoordinateSystem()
The base class for all OPAL actions.
PETE_TUTree< FnFabs, typename T::PETE_Expr_t > fabs(const PETE_Expr< T > &l)
The base class for all OPAL exceptions.
Tps< T > sin(const Tps< T > &x)
Sine.
static std::unordered_set< DumpEMFields * > dumpsSet_m
void writeFieldLine(Component *field, const Vector_t &point, const double &time, std::ofstream &fout) const
std::vector< Attribute > itsAttr
The object attributes (see Attribute.hh).
FLieGenerator< T, N > real(const FLieGenerator< std::complex< T >, N > &)
Take real part of a complex generator.
static void checkInt(double value, std::string name, double tolerance=1e-9)
Mesh::Iterator end() const
static std::string dumpemfields_docstring
static void writeFields(Component *field)
static constexpr double DEGREE
virtual DumpEMFields * clone(const std::string &name)
Tps< T > cos(const Tps< T > &x)
Cosine.
CoordinateSystem coordinates_m
interpolation::NDGrid * grid_m
std::string::iterator iterator
Interface for a single beam element.
double getReal(const Attribute &attr)
Return real value.
Attribute makeString(const std::string &name, const std::string &help)
Make string attribute.
Mesh::Iterator begin() const
Attribute makeReal(const std::string &name, const std::string &help)
Make real attribute.
virtual void writeFieldThis(Component *field)
void writeHeader(std::ofstream &fout) const
PETE_TUTree< FnFloor, typename T::PETE_Expr_t > floor(const PETE_Expr< T > &l)
Inform & endl(Inform &inf)
std::string getString(const Attribute &attr)
Get string value.