27#include <boost/filesystem.hpp>
37 "The \"DUMPFIELDS\" statement dumps a field map to a user-defined "
38 "field file, for checking that fields are read in correctly "
39 "from disk. The fields are written out on a Cartesian grid.") {
42 (
"FILE_NAME",
"Name of the file to which field data is dumped");
45 (
"X_START",
"Start point in the grid in x [m]");
48 (
"DX",
"Grid step size in x [m]");
51 (
"X_STEPS",
"Number of steps in x");
54 (
"Y_START",
"Start point in the grid in y [m]");
57 (
"DY",
"Grid step size in y [m]");
60 (
"Y_STEPS",
"Number of steps in y");
63 (
"Z_START",
"Start point in the grid in z [m]");
66 (
"DZ",
"Grid step size in z [m]");
69 (
"Z_STEPS",
"Number of steps in z");
132 (*it)->writeFieldThis(field);
137 if (std::abs(std::floor(real) - real) > tolerance) {
139 "Value for " + name +
140 " should be an integer but a real value was found");
142 if (std::floor(real) < 0.5) {
144 "Value for " + name +
" should be 1 or more");
151 "The grid was nullptr; there was a problem with the DumpFields initialisation.");
153 if (field ==
nullptr) {
155 "The field to be written was nullptr.");
161 if (boost::filesystem::path(
filename_m).is_absolute() ==
true) {
173 std::ofstream fout(fname.c_str(), std::ofstream::out);
176 "Failed to open DumpFields file " +
filename_m);
180 fout << 1 <<
" x [m]\n";
181 fout << 2 <<
" y [m]\n";
182 fout << 3 <<
" z [m]\n";
183 fout << 4 <<
" Bx [kGauss]\n";
184 fout << 5 <<
" By [kGauss]\n";
185 fout << 6 <<
" Bz [kGauss]\n";
192 it.getPosition(&point[0]);
193 field->
apply(point, centroid, time, E, B);
194 fout << point[0] <<
" " << point[1] <<
" " << point[2] <<
" ";
195 fout << B[0] <<
" " << B[1] <<
" " << B[2] <<
"\n";
199 "Something went wrong during writing " +
filename_m);
205 os <<
"* ************* D U M P F I E L D S *********************************************** " <<
std::endl;
216 os <<
"* ********************************************************************************** " <<
std::endl;
PartBunch< T, Dim >::ConstIterator end(PartBunch< T, Dim > const &bunch)
Inform & endl(Inform &inf)
double getReal(const Attribute &attr)
Return real value.
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)
Interface for a single beam element.
virtual bool apply(const size_t &i, const double &t, Vector_t< double, 3 > &E, Vector_t< double, 3 > &B)
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
DumpFields dumps the static magnetic field of a Ring in a user-defined grid.
static void checkInt(double value, std::string name, double tolerance=1e-9)
virtual void writeFieldThis(Component *field)
void print(std::ostream &os) const
Print the attributes of DumpFields to standard out.
static void writeFields(Component *field)
Write the fields for all defined DumpFields objects.
static std::unordered_set< DumpFields * > dumpsSet_m
interpolation::ThreeDGrid * grid_m
virtual void execute()
Builds the grid but does not write the field map.
virtual DumpFields * clone(const std::string &name)
Make a clone (overloadable copy-constructor).
virtual ~DumpFields()
Destructor deletes grid_m and if in the dumps set, take it out.
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.
ThreeDGrid holds grid information for a rectangular grid used in e.g.
Mesh::Iterator begin() const
Return an iterator pointing at the first element in the ThreeDGrid.
Mesh::Iterator end() const
Return an iterator pointing at the last+1 element in the ThreeDGrid.
ThreeDGrid * clone()
Deep copy the grid.
The base class for all OPAL exceptions.