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");
133 static const std::map<std::string, CoordinateSystem> stringCoordinateSystem_s = {
150 std::vector<double> spacing(4);
151 std::vector<double> origin(4);
152 std::vector<int> gridSize(4);
212 (*it)->writeFieldThis(field);
220 fout << 1 <<
" x [m]\n";
221 fout << 2 <<
" y [m]\n";
222 fout << 3 <<
" z [m]\n";
223 fout << 4 <<
" t [ns]\n";
224 fout << 5 <<
" Bx [kGauss]\n";
225 fout << 6 <<
" By [kGauss]\n";
226 fout << 7 <<
" Bz [kGauss]\n";
227 fout << 8 <<
" Ex [MV/m]\n";
228 fout << 9 <<
" Ey [MV/m]\n";
229 fout << 10 <<
" Ez [MV/m]\n";
233 fout << 1 <<
" r [m]\n";
234 fout << 2 <<
" phi [deg]\n";
235 fout << 3 <<
" z [m]\n";
236 fout << 4 <<
" t [ns]\n";
237 fout << 5 <<
" Br [kGauss]\n";
238 fout << 6 <<
" Bphi [kGauss]\n";
239 fout << 7 <<
" Bz [kGauss]\n";
240 fout << 8 <<
" Er [MV/m]\n";
241 fout << 9 <<
" Ephi [MV/m]\n";
242 fout << 10 <<
" Ez [MV/m]\n";
252 std::ofstream& fout)
const {
259 point[0] =
std::cos(pointIn[1])*pointIn[0];
260 point[1] =
std::sin(pointIn[1])*pointIn[0];
263 field->
apply(point, centroid, time, E, B);
272 fout << pointIn[0] <<
" " << pointIn[1]*
Units::rad2deg <<
" " << pointIn[2] <<
" " << time <<
" ";
274 fout << pointIn[0] <<
" " << pointIn[1] <<
" " << pointIn[2] <<
" " << time <<
" ";
277 fout << Bout[0] <<
" " << Bout[1] <<
" " << Bout[2] <<
" ";
278 fout << Eout[0] <<
" " << Eout[1] <<
" " << Eout[2] <<
"\n";
284 "The grid was nullptr; there was a problem with the DumpEMFields initialisation.");
286 if (field ==
nullptr) {
288 "The field to be written was nullptr.");
294 if (std::filesystem::path(
filename_m).is_absolute() ==
true) {
303 std::vector<double> point_std(4);
307 fout.open(fname.c_str(), std::ofstream::out);
308 }
catch (std::exception& exc) {
310 "Failed to open DumpEMFields file " +
filename_m);
314 "Failed to open DumpEMFields file " +
filename_m);
321 it.getPosition(&point_std[0]);
322 for (
size_t i = 0; i < 3; ++i) {
323 point[i] = point_std[i];
325 double time = point_std[3];
330 "Something went wrong during writing " +
filename_m);
336 os <<
"* ************* D U M P E M F I E L D S ****************************************** " <<
std::endl;
337 os <<
"* File name: '" <<
filename_m <<
"'\n";
361 os <<
"* ********************************************************************************** " <<
std::endl;
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.
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)
void checkInt(double real, std::string name, double tolerance)
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
DumpEMFields dumps the dynamically changing fields of a Ring in a user- defined grid.
virtual void writeFieldThis(Component *field)
void print(std::ostream &os) const
Print the attributes of DumpEMFields to standard out.
static std::unordered_set< DumpEMFields * > dumpsSet_m
void parseCoordinateSystem()
static void writeFields(Component *field)
Write the fields for all defined DumpEMFields objects.
interpolation::NDGrid * grid_m
CoordinateSystem coordinates_m
void writeHeader(std::ofstream &fout) const
virtual void execute()
Builds the grid but does not write the field map.
virtual DumpEMFields * clone(const std::string &name)
Make a clone (overloadable copy-constructor).
void writeFieldLine(Component *field, const Vector_t &point, const double &time, std::ofstream &fout) const
DumpEMFields()
Constructor.
virtual ~DumpEMFields()
Destructor deletes grid_m and if in the dumps set, take it out.
Interface for a single beam element.
virtual bool apply(const size_t &i, const double &t, Vector_t &E, Vector_t &B)
Used to loop over some, or all, points in the mesh, as in stl Enables e.g.
int toInteger() const
Return an integer representation of the iterator.
NDGrid holds grid information for a rectilinear grid in some arbitrary dimensional space.
Mesh::Iterator begin() const
Returns the origin of the mesh (lowest possible index in all dimensions)
Mesh::Iterator end() const
Returns the end of the mesh (highest possible index in all dimensions)
NDGrid * clone()
Inheritable copy constructor.
The base class for all OPAL exceptions.