29#include <boost/filesystem.hpp>
41 "The \"DUMPEMFIELDS\" statement dumps a field map to a user-defined "
42 "field file, for checking that fields are generated correctly. "
43 "The fields are written out on a grid in space and time."),
49 (
"FILE_NAME",
"Name of the file to which field data is dumped");
52 (
"COORDINATE_SYSTEM",
"Choose to use CARTESIAN or CYLINDRICAL coordinates", {
"CARTESIAN",
"CYLINDRICAL"},
"CARTESIAN");
55 (
"X_START",
"(Cartesian) Start point in the grid in x [m]");
58 (
"DX",
"(Cartesian) Grid step size in x [m]");
61 (
"X_STEPS",
"(Cartesian) Number of steps in x");
64 (
"Y_START",
"(Cartesian) Start point in the grid in y [m]");
67 (
"DY",
"(Cartesian) Grid step size in y [m]");
70 (
"Y_STEPS",
"(Cartesian) Number of steps in y");
73 (
"Z_START",
"Start point in the grid in z [m]");
76 (
"DZ",
"Grid step size in z [m]");
79 (
"Z_STEPS",
"Number of steps in z");
82 (
"T_START",
"Start point in the grid in time [ns]");
85 (
"DT",
"Grid step size in time [ns]");
88 (
"T_STEPS",
"Number of steps in time");
91 (
"R_START",
"(Cylindrical) Start point in the grid in radius [m]");
94 (
"DR",
"(Cylindrical) Grid step size in radius [m]");
97 (
"R_STEPS",
"(Cylindrical) Number of steps in radius");
100 (
"PHI_START",
"(Cylindrical) Start point in the grid in phi [rad]");
103 (
"DPHI",
"(Cylindrical) Grid step size in phi [rad]");
106 (
"PHI_STEPS",
"(Cylindrical) Number of steps in phi");
134 static const std::map<std::string, CoordinateSystem> stringCoordinateSystem_s = {
151 std::vector<double> spacing(4);
152 std::vector<double> origin(4);
153 std::vector<int> gridSize(4);
213 (*it)->writeFieldThis(field);
221 "Value for " +
name +
222 " should be an integer but a real value was found");
226 "Value for " +
name +
" should be 1 or more");
234 fout << 1 <<
" x [m]\n";
235 fout << 2 <<
" y [m]\n";
236 fout << 3 <<
" z [m]\n";
237 fout << 4 <<
" t [ns]\n";
238 fout << 5 <<
" Bx [kGauss]\n";
239 fout << 6 <<
" By [kGauss]\n";
240 fout << 7 <<
" Bz [kGauss]\n";
241 fout << 8 <<
" Ex [MV/m]\n";
242 fout << 9 <<
" Ey [MV/m]\n";
243 fout << 10 <<
" Ez [MV/m]\n";
247 fout << 1 <<
" r [m]\n";
248 fout << 2 <<
" phi [deg]\n";
249 fout << 3 <<
" z [m]\n";
250 fout << 4 <<
" t [ns]\n";
251 fout << 5 <<
" Br [kGauss]\n";
252 fout << 6 <<
" Bphi [kGauss]\n";
253 fout << 7 <<
" Bz [kGauss]\n";
254 fout << 8 <<
" Er [MV/m]\n";
255 fout << 9 <<
" Ephi [MV/m]\n";
256 fout << 10 <<
" Ez [MV/m]\n";
266 std::ofstream& fout)
const {
273 point[0] =
std::cos(pointIn[1])*pointIn[0];
274 point[1] =
std::sin(pointIn[1])*pointIn[0];
277 field->
apply(point, centroid, time, E, B);
286 fout << pointIn[0] <<
" " << pointIn[1]*
Units::rad2deg <<
" " << pointIn[2] <<
" " << time <<
" ";
288 fout << pointIn[0] <<
" " << pointIn[1] <<
" " << pointIn[2] <<
" " << time <<
" ";
291 fout << Bout[0] <<
" " << Bout[1] <<
" " << Bout[2] <<
" ";
292 fout << Eout[0] <<
" " << Eout[1] <<
" " << Eout[2] <<
"\n";
298 "The grid was nullptr; there was a problem with the DumpEMFields initialisation.");
300 if (field ==
nullptr) {
302 "The field to be written was nullptr.");
308 if (boost::filesystem::path(
filename_m).is_absolute() ==
true) {
317 std::vector<double> point_std(4);
321 fout.open(fname.c_str(), std::ofstream::out);
322 }
catch (std::exception& exc) {
324 "Failed to open DumpEMFields file " +
filename_m);
328 "Failed to open DumpEMFields file " +
filename_m);
335 it.getPosition(&point_std[0]);
336 for (
size_t i = 0; i < 3; ++i) {
337 point[i] = point_std[i];
339 double time = point_std[3];
344 "Something went wrong during writing " +
filename_m);
350 os <<
"* ************* D U M P E M F I E L D S ****************************************** " <<
std::endl;
351 os <<
"* File name: '" <<
filename_m <<
"'\n";
375 os <<
"* ********************************************************************************** " <<
std::endl;
FLieGenerator< T, N > real(const FLieGenerator< std::complex< T >, N > &)
Take real part of a complex generator.
PartBunchBase< T, Dim >::ConstIterator end(PartBunchBase< T, Dim > const &bunch)
Tps< T > cos(const Tps< T > &x)
Cosine.
Tps< T > sin(const Tps< T > &x)
Sine.
PETE_TUTree< FnFloor, typename T::PETE_Expr_t > floor(const PETE_Expr< T > &l)
PETE_TUTree< FnAbs, typename T::PETE_Expr_t > abs(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.
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.