34 "The \"DUMPEMFIELDS\" statement dumps a field map to a user-defined "
35 "field file, for checking that fields are generated correctly. "
36 "The fields are written out on a grid in space and time.") {
42 "COORDINATE_SYSTEM",
"Choose to use CARTESIAN or CYLINDRICAL coordinates",
43 {
"CARTESIAN",
"CYLINDRICAL"},
"CARTESIAN");
53 "Y_START",
"(Cartesian) Start point in the grid in y (vertical) [m]");
86 "CYL_ORIGIN_X",
"(Cylindrical) The X coordinate of the origin [m]. Default=0", 0.0);
89 "CYL_ORIGIN_Y",
"(Cylindrical) The Y coordinate of the origin [m]. Default=0", 0.0);
92 "CYL_ORIGIN_Z",
"(Cylindrical) The Z coordinate of the origin [m]. Default=0", 0.0);
102 dumper->grid_m.reset(
grid_m->clone());
111 static const std::map<std::string, CoordinateSystem> stringCoordinateSystem_s = {
127 std::vector<double> spacing(4);
128 std::vector<int> gridSize(4);
129 std::vector<double> origin(4);
154 gridSize[0] = rSteps;
175 grid_m = std::make_unique<interpolation::NDGrid>(4, &gridSize[0], &spacing[0], &origin[0]);
192 if (std::abs(std::floor(value) - value) > 2 * tolerance) {
194 "DumpEMFields::checkInt",
195 "Value for " + name +
" should be an integer but a real value was found");
197 if (std::floor(value) < 0.5) {
198 throw OpalException(
"DumpEMFields::checkInt",
"Value for " + name +
" should be 1 or more");
203 fout <<
grid_m->end().toInteger() <<
"\n";
205 fout << 1 <<
" x [m]\n";
206 fout << 2 <<
" y [m]\n";
207 fout << 3 <<
" z [m]\n";
208 fout << 4 <<
" t [ns]\n";
209 fout << 5 <<
" Bx [T]\n";
210 fout << 6 <<
" By [T]\n";
211 fout << 7 <<
" Bz [T]\n";
212 fout << 8 <<
" Ex [MV/m]\n";
213 fout << 9 <<
" Ey [MV/m]\n";
214 fout << 10 <<
" Ez [MV/m]\n";
216 fout << 1 <<
" r [m]\n";
217 fout << 2 <<
" phi [deg]\n";
218 fout << 3 <<
" y [m]\n";
219 fout << 4 <<
" t [ns]\n";
220 fout << 5 <<
" Br [T]\n";
221 fout << 6 <<
" Bphi [T]\n";
222 fout << 7 <<
" By [T]\n";
223 fout << 8 <<
" Er [MV/m]\n";
224 fout << 9 <<
" Ephi [MV/m]\n";
225 fout << 10 <<
" Ey [MV/m]\n";
227 fout << 0 << std::endl;
232 const double& time, std::ofstream& fout)
const {
245 auto transform = element->getCSTrafoGlobal2Local();
249 element->apply(localR, {}, time, localE, localB);
251 localB = transform.rotateTo(localB);
252 localE = transform.rotateTo(localE);
261 Bout[0] = B[0] * std::cos(point[1]) + B[2] * std::sin(point[1]);
262 Bout[1] = -B[0] * std::sin(point[1]) + B[2] * std::cos(point[1]);
264 Eout[0] = E[0] * std::cos(point[1]) + E[2] * std::sin(point[1]);
265 Eout[1] = -E[0] * std::sin(point[1]) + E[2] * std::cos(point[1]);
267 fout << point[0] <<
" " << point[1] *
Units::rad2deg <<
" " << point[2] <<
" " << time
270 fout << point[0] <<
" " << point[1] <<
" " << point[2] <<
" " << time <<
" ";
272 fout << Bout[0] <<
" " << Bout[1] <<
" " << Bout[2] <<
" ";
280 "DumpEMFields::writeFieldThis",
281 "The grid was nullptr; there was a problem with the "
282 "DumpEMFields initialisation.");
285 *
gmsg << level5 << *
this << endl;
288 if (std::filesystem::path(
filename_m).is_absolute() ==
true) {
295 std::vector<double> point_std(4);
298 fout.open(fname.c_str(), std::ofstream::out);
301 "DumpEMFields::writeFieldThis",
"Failed to open DumpEMFields file " +
filename_m);
306 it.getPosition(&point_std[0]);
307 for (
size_t i = 0; i < 3; ++i) {
308 point[i] = point_std[i];
310 double time = point_std[3];
314 fout.setstate(std::ios::badbit);
318 "DumpEMFields::writeFieldThis",
319 "Something went wrong during writing " +
filename_m);
325 os <<
"* ************* D U M P E M F I E L D S ****************************************** "
327 os <<
"* File name: '" <<
filename_m <<
"'\n";
354 os <<
"* ********************************************************************************** "
ippl::Vector< T, Dim > Vector_t
The base class for all OPAL actions.
DumpEMFields * clone(const std::string &name) override
static std::unordered_set< std::unique_ptr< DumpEMFields > > dumpsSet_m
void print(std::ostream &os) const override
Vector_t< double, 3 > cylindricalOrigin_m
void parseCoordinateSystem()
static void checkInt(double value, const std::string &name, double tolerance=1e-9)
static void writeFields(const std::set< std::shared_ptr< Component > > &elements)
CoordinateSystem coordinates_m
void writeHeader(std::ofstream &fout) const
void writeFieldLine(const std::set< std::shared_ptr< Component > > &elements, const Vector_t< double, 3 > &point, const double &time, std::ofstream &fout) const
std::unique_ptr< interpolation::NDGrid > grid_m
virtual void writeFieldThis(const std::set< std::shared_ptr< Component > > &elements)
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
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 Vpm2MVpm
std::string combineFilePath(std::initializer_list< std::string > ilist)