Commit 6132c8ef authored by ext-calvo_p's avatar ext-calvo_p
Browse files

Resolve "DumpFieldsTest and DumpEMFieldsTest failed"

parent ad2c6977
...@@ -18,14 +18,16 @@ ...@@ -18,14 +18,16 @@
// //
#include "BasicActions/DumpEMFields.h" #include "BasicActions/DumpEMFields.h"
#include "AbsBeamline/Component.h"
#include "AbstractObjects/OpalData.h" #include "AbstractObjects/OpalData.h"
#include "AbsBeamline/Component.h"
#include "Attributes/Attributes.h" #include "Attributes/Attributes.h"
#include "Fields/Interpolation/NDGrid.h" #include "Fields/Interpolation/NDGrid.h"
#include "Physics/Physics.h" #include "Physics/Physics.h"
#include "Utilities/OpalException.h" #include "Utilities/OpalException.h"
#include "Utilities/Util.h" #include "Utilities/Util.h"
#include <boost/filesystem.hpp>
#include <fstream> #include <fstream>
#include <cmath> #include <cmath>
...@@ -39,8 +41,7 @@ DumpEMFields::DumpEMFields() : ...@@ -39,8 +41,7 @@ DumpEMFields::DumpEMFields() :
"field file, for checking that fields are generated correctly. " "field file, for checking that fields are generated correctly. "
"The fields are written out on a grid in space and time."), "The fields are written out on a grid in space and time."),
grid_m(NULL), grid_m(NULL),
filename_m(""), filename_m("") {
coordinates_m(CoordinateSystem::CARTESIAN) {
// would be nice if "steps" could be integer // would be nice if "steps" could be integer
itsAttr[FILE_NAME] = Attributes::makeString itsAttr[FILE_NAME] = Attributes::makeString
...@@ -107,7 +108,7 @@ DumpEMFields::DumpEMFields() : ...@@ -107,7 +108,7 @@ DumpEMFields::DumpEMFields() :
} }
DumpEMFields::DumpEMFields(const std::string& name, DumpEMFields* parent): DumpEMFields::DumpEMFields(const std::string& name, DumpEMFields* parent):
Action(name, parent) Action(name, parent), grid_m(NULL)
{} {}
DumpEMFields::~DumpEMFields() { DumpEMFields::~DumpEMFields() {
...@@ -214,12 +215,12 @@ void DumpEMFields::checkInt(double real, std::string name, double tolerance) { ...@@ -214,12 +215,12 @@ void DumpEMFields::checkInt(double real, std::string name, double tolerance) {
real += tolerance; // prevent rounding error real += tolerance; // prevent rounding error
if (std::abs(std::floor(real) - real) > 2*tolerance) { if (std::abs(std::floor(real) - real) > 2*tolerance) {
throw OpalException("DumpEMFields::checkInt", throw OpalException("DumpEMFields::checkInt",
"Value for "+name+ "Value for " + name +
" should be an integer but a real value was found"); " should be an integer but a real value was found");
} }
if (std::floor(real) < 0.5) { if (std::floor(real) < 0.5) {
throw OpalException("DumpEMFields::checkInt", throw OpalException("DumpEMFields::checkInt",
"Value for "+name+" should be 1 or more"); "Value for " + name + " should be 1 or more");
} }
} }
...@@ -271,9 +272,9 @@ void DumpEMFields::writeFieldLine(Component* field, ...@@ -271,9 +272,9 @@ void DumpEMFields::writeFieldLine(Component* field,
Vector_t Eout = E; Vector_t Eout = E;
if (coordinates_m == CoordinateSystem::CYLINDRICAL) { if (coordinates_m == CoordinateSystem::CYLINDRICAL) {
// pointIn is r, phi, z // pointIn is r, phi, z
Bout[0] = B[0]*std::cos(pointIn[1])+B[1]*std::sin(pointIn[1]); Bout[0] = B[0]*std::cos(pointIn[1])+B[1]*std::sin(pointIn[1]);
Bout[1] = -B[0]*std::sin(pointIn[1])+B[1]*std::cos(pointIn[1]); Bout[1] = -B[0]*std::sin(pointIn[1])+B[1]*std::cos(pointIn[1]);
Eout[0] = E[0]*std::cos(pointIn[1])+E[1]*std::sin(pointIn[1]); Eout[0] = E[0]*std::cos(pointIn[1])+E[1]*std::sin(pointIn[1]);
Eout[1] = -E[0]*std::sin(pointIn[1])+E[1]*std::cos(pointIn[1]); Eout[1] = -E[0]*std::sin(pointIn[1])+E[1]*std::cos(pointIn[1]);
fout << pointIn[0] << " " << pointIn[1]*Physics::rad2deg << " " << pointIn[2] << " " << time << " "; fout << pointIn[0] << " " << pointIn[1]*Physics::rad2deg << " " << pointIn[2] << " " << time << " ";
} else { } else {
...@@ -296,22 +297,28 @@ void DumpEMFields::writeFieldThis(Component* field) { ...@@ -296,22 +297,28 @@ void DumpEMFields::writeFieldThis(Component* field) {
*gmsg << *this << endl; *gmsg << *this << endl;
std::string fname = Util::combineFilePath({ std::string fname;
OpalData::getInstance()->getAuxiliaryOutputDirectory(), if (boost::filesystem::path(filename_m).is_absolute() == true) {
filename_m fname = filename_m;
}); } else {
fname = Util::combineFilePath({
OpalData::getInstance()->getAuxiliaryOutputDirectory(),
filename_m
});
}
std::vector<double> point_std(4); std::vector<double> point_std(4);
Vector_t point(0., 0., 0.); Vector_t point(0., 0., 0.);
std::ofstream fout; std::ofstream fout;
try { try {
fout.open(filename_m.c_str(), std::ofstream::out); fout.open(fname.c_str(), std::ofstream::out);
} catch (std::exception& exc) { } catch (std::exception& exc) {
throw OpalException("DumpEMFields::writeFieldThis", throw OpalException("DumpEMFields::writeFieldThis",
"Failed to open DumpEMFields file "+filename_m); "Failed to open DumpEMFields file " + filename_m);
} }
if (!fout.good()) { if (!fout.good()) {
throw OpalException("DumpEMFields::writeFieldThis", throw OpalException("DumpEMFields::writeFieldThis",
"Failed to open DumpEMFields file "+filename_m); "Failed to open DumpEMFields file " + filename_m);
} }
// set precision // set precision
writeHeader(fout); writeHeader(fout);
...@@ -327,7 +334,7 @@ void DumpEMFields::writeFieldThis(Component* field) { ...@@ -327,7 +334,7 @@ void DumpEMFields::writeFieldThis(Component* field) {
} }
if (!fout.good()) { if (!fout.good()) {
throw OpalException("DumpEMFields::writeFieldThis", throw OpalException("DumpEMFields::writeFieldThis",
"Something went wrong during writing "+filename_m); "Something went wrong during writing " + filename_m);
} }
fout.close(); fout.close();
} }
......
...@@ -79,11 +79,6 @@ public: ...@@ -79,11 +79,6 @@ public:
SIZE SIZE
}; };
enum class CoordinateSystem {
CARTESIAN,
CYLINDRICAL
};
/** Constructor */ /** Constructor */
DumpEMFields(); DumpEMFields();
...@@ -129,6 +124,12 @@ public: ...@@ -129,6 +124,12 @@ public:
void print(std::ostream& os) const; void print(std::ostream& os) const;
private: private:
enum class CoordinateSystem {
CARTESIAN,
CYLINDRICAL
};
virtual void writeFieldThis(Component* field); virtual void writeFieldThis(Component* field);
virtual void buildGrid(); virtual void buildGrid();
void parseCoordinateSystem(); void parseCoordinateSystem();
......
...@@ -17,13 +17,15 @@ ...@@ -17,13 +17,15 @@
// //
#include "BasicActions/DumpFields.h" #include "BasicActions/DumpFields.h"
#include "AbsBeamline/Component.h"
#include "AbstractObjects/OpalData.h" #include "AbstractObjects/OpalData.h"
#include "AbsBeamline/Component.h"
#include "Attributes/Attributes.h" #include "Attributes/Attributes.h"
#include "Fields/Interpolation/ThreeDGrid.h" #include "Fields/Interpolation/ThreeDGrid.h"
#include "Utilities/OpalException.h" #include "Utilities/OpalException.h"
#include "Utilities/Util.h" #include "Utilities/Util.h"
#include <boost/filesystem.hpp>
#include <fstream> #include <fstream>
extern Inform* gmsg; extern Inform* gmsg;
...@@ -134,12 +136,12 @@ void DumpFields::writeFields(Component* field) { ...@@ -134,12 +136,12 @@ void DumpFields::writeFields(Component* field) {
void DumpFields::checkInt(double real, std::string name, double tolerance) { void DumpFields::checkInt(double real, std::string name, double tolerance) {
if (std::abs(std::floor(real) - real) > tolerance) { if (std::abs(std::floor(real) - real) > tolerance) {
throw OpalException("DumpFields::checkInt", throw OpalException("DumpFields::checkInt",
"Value for "+name+ "Value for " + name +
" should be an integer but a real value was found"); " should be an integer but a real value was found");
} }
if (std::floor(real) < 0.5) { if (std::floor(real) < 0.5) {
throw OpalException("DumpFields::checkInt", throw OpalException("DumpFields::checkInt",
"Value for "+name+" should be 1 or more"); "Value for " + name + " should be 1 or more");
} }
} }
...@@ -155,17 +157,23 @@ void DumpFields::writeFieldThis(Component* field) { ...@@ -155,17 +157,23 @@ void DumpFields::writeFieldThis(Component* field) {
*gmsg << *this << endl; *gmsg << *this << endl;
std::string fname = Util::combineFilePath({ std::string fname;
OpalData::getInstance()->getAuxiliaryOutputDirectory(), if (boost::filesystem::path(filename_m).is_absolute() == true) {
filename_m fname = filename_m;
}); } else {
fname = Util::combineFilePath({
OpalData::getInstance()->getAuxiliaryOutputDirectory(),
filename_m
});
}
double time = 0.; double time = 0.;
Vector_t point(0., 0., 0.); Vector_t point(0., 0., 0.);
Vector_t centroid(0., 0., 0.); Vector_t centroid(0., 0., 0.);
std::ofstream fout(fname.c_str(), std::ofstream::out); std::ofstream fout(fname.c_str(), std::ofstream::out);
if (!fout.good()) { if (!fout.good()) {
throw OpalException("DumpFields::writeFieldThis", throw OpalException("DumpFields::writeFieldThis",
"Failed to open DumpFields file "+filename_m); "Failed to open DumpFields file " + filename_m);
} }
// set precision // set precision
fout << grid_m->end().toInteger() << "\n"; fout << grid_m->end().toInteger() << "\n";
...@@ -188,22 +196,22 @@ void DumpFields::writeFieldThis(Component* field) { ...@@ -188,22 +196,22 @@ void DumpFields::writeFieldThis(Component* field) {
} }
if (!fout.good()) { if (!fout.good()) {
throw OpalException("DumpFields::writeFieldThis", throw OpalException("DumpFields::writeFieldThis",
"Something went wrong during writing "+filename_m); "Something went wrong during writing " + filename_m);
} }
fout.close(); fout.close();
} }
void DumpFields::print(std::ostream& os) const { void DumpFields::print(std::ostream& os) const {
os << "* ************* D U M P F I E L D S *********************************************** " << std::endl; os << "* ************* D U M P F I E L D S *********************************************** " << std::endl;
os << "* File name: " << Attributes::getString(itsAttr[FILE_NAME]) << '\n' os << "* File name: " << filename_m << '\n'
<< "* X_START = " << Attributes::getReal(itsAttr[X_START]) << " [m]\n" << "* X_START = " << Attributes::getReal(itsAttr[X_START]) << " [m]\n"
<< "* DX = " << Attributes::getReal(itsAttr[DX]) << " [m]\n" << "* DX = " << Attributes::getReal(itsAttr[DX]) << " [m]\n"
<< "* X_STEPS = " << Attributes::getReal(itsAttr[X_STEPS]) << '\n' << "* X_STEPS = " << Attributes::getReal(itsAttr[X_STEPS]) << '\n'
<< "* Y_START = " << Attributes::getReal(itsAttr[Y_START]) << " [m]\n" << "* Y_START = " << Attributes::getReal(itsAttr[Y_START]) << " [m]\n"
<< "* DY = " << Attributes::getReal(itsAttr[DY]) << " [m]\n" << "* DY = " << Attributes::getReal(itsAttr[DY]) << " [m]\n"
<< "* Y_STEPS = " << Attributes::getReal(itsAttr[Y_STEPS]) << '\n' << "* Y_STEPS = " << Attributes::getReal(itsAttr[Y_STEPS]) << '\n'
<< "* Z_START = " << Attributes::getReal(itsAttr[Z_START]) << " [m]\n" << "* Z_START = " << Attributes::getReal(itsAttr[Z_START]) << " [m]\n"
<< "* DZ = " << Attributes::getReal(itsAttr[DZ]) << " [m]\n" << "* DZ = " << Attributes::getReal(itsAttr[DZ]) << " [m]\n"
<< "* Z_STEPS = " << Attributes::getReal(itsAttr[Z_STEPS]) << '\n'; << "* Z_STEPS = " << Attributes::getReal(itsAttr[Z_STEPS]) << '\n';
os << "* ********************************************************************************** " << std::endl; os << "* ********************************************************************************** " << std::endl;
} }
...@@ -24,7 +24,6 @@ ...@@ -24,7 +24,6 @@
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE. * POSSIBILITY OF SUCH DAMAGE.
*/ */
#include <fstream> #include <fstream>
#include <iostream> #include <iostream>
...@@ -32,9 +31,13 @@ ...@@ -32,9 +31,13 @@
#include "opal_src/Utilities/MockComponent.h" #include "opal_src/Utilities/MockComponent.h"
#include "BasicActions/DumpEMFields.h"
#include "AbstractObjects/OpalData.h"
#include "Attributes/Attributes.h" #include "Attributes/Attributes.h"
#include "Physics/Physics.h"
#include "Utilities/OpalException.h" #include "Utilities/OpalException.h"
#include "BasicActions/DumpEMFields.h" #include "Utilities/Util.h"
#include "opal_test_utilities/SilenceTest.h" #include "opal_test_utilities/SilenceTest.h"
...@@ -64,7 +67,7 @@ void setAttributesCart(DumpEMFields* dump, ...@@ -64,7 +67,7 @@ void setAttributesCart(DumpEMFields* dump,
setOneAttribute(dump, "T_STEPS", nt); setOneAttribute(dump, "T_STEPS", nt);
Attributes::setString(*dump->findAttribute("FILE_NAME"), filename); Attributes::setString(*dump->findAttribute("FILE_NAME"), filename);
if (!defaultCoords) { if (!defaultCoords) {
Attributes::setString(*dump->findAttribute("COORDINATE_SYSTEM"), "cARtesiAN"); Attributes::setUpperCaseString(*dump->findAttribute("COORDINATE_SYSTEM"), "cARtesiAN");
} }
} }
...@@ -87,7 +90,7 @@ void setAttributesCyl(DumpEMFields* dump, ...@@ -87,7 +90,7 @@ void setAttributesCyl(DumpEMFields* dump,
setOneAttribute(dump, "DT", dt); setOneAttribute(dump, "DT", dt);
setOneAttribute(dump, "T_STEPS", nt); setOneAttribute(dump, "T_STEPS", nt);
Attributes::setString(*dump->findAttribute("FILE_NAME"), filename); Attributes::setString(*dump->findAttribute("FILE_NAME"), filename);
Attributes::setString(*dump->findAttribute("COORDINATE_SYSTEM"), "cYLindriCAL"); Attributes::setUpperCaseString(*dump->findAttribute("COORDINATE_SYSTEM"), "cYLindriCAL");
} }
TEST(DumpEMFieldsTest, ConstructorDestructor) { TEST(DumpEMFieldsTest, ConstructorDestructor) {
OpalTestUtilities::SilenceTest silencer; OpalTestUtilities::SilenceTest silencer;
...@@ -97,7 +100,7 @@ TEST(DumpEMFieldsTest, ConstructorDestructor) { ...@@ -97,7 +100,7 @@ TEST(DumpEMFieldsTest, ConstructorDestructor) {
delete dump1; delete dump1;
// grid is not null and it is in the set // grid is not null and it is in the set
DumpEMFields* dump2 = new DumpEMFields(); DumpEMFields* dump2 = new DumpEMFields();
setAttributesCart(dump2, 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., "/dev/null"); setAttributesCart(dump2, 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., "/dev/null");
dump2->execute(); dump2->execute();
delete dump2; delete dump2;
} }
...@@ -117,30 +120,47 @@ TEST(DumpEMFieldsTest, executeTest) { ...@@ -117,30 +120,47 @@ TEST(DumpEMFieldsTest, executeTest) {
// dump the fields // dump the fields
DumpEMFields dump1; DumpEMFields dump1;
execute_throws(&dump1, "should throw due to nsteps < 1"); execute_throws(&dump1, "should throw due to nsteps < 1");
setAttributesCart(&dump1, 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., "/dev/null", true); setAttributesCart(&dump1, 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., "/dev/null", true);
dump1.execute(); // should be okay (normal) dump1.execute(); // should be okay (normal)
setAttributesCart(&dump1, 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., "/dev/null", false); setAttributesCart(&dump1, 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., "/dev/null", false);
dump1.execute(); // should be okay (normal) dump1.execute(); // should be okay (normal)
setAttributesCart(&dump1, -1., -1., 1., -1., -1., 1., -1., -1., 1., 1., 1., 1., "/dev/null"); setAttributesCart(&dump1, -1., -1., 1., -1., -1., 1., -1., -1., 1., 1., 1., 1., "/dev/null");
dump1.execute(); // should be okay (-ve step is okay) dump1.execute(); // should be okay (-ve step is okay)
setAttributesCart(&dump1, -1., -1., 0., -1., -1., 1., -1., -1., 1., 1., 1., 1., "/dev/null"); setAttributesCart(&dump1, -1., -1., 0., -1., -1., 1., -1., -1., 1., 1., 1., 1., "/dev/null");
execute_throws(&dump1, "should throw due to nsteps x < 1"); execute_throws(&dump1, "should throw due to nsteps x < 1");
setAttributesCart(&dump1, -1., -1., 1., -1., -1., 0., -1., -1., 1., 1., 1., 1., "/dev/null"); setAttributesCart(&dump1, -1., -1., 1., -1., -1., 0., -1., -1., 1., 1., 1., 1., "/dev/null");
execute_throws(&dump1, "should throw due to nsteps y < 1"); execute_throws(&dump1, "should throw due to nsteps y < 1");
setAttributesCart(&dump1, -1., -1., 1., -1., -1., 1., -1., -1., 0., 1., 1., 1., "/dev/null"); setAttributesCart(&dump1, -1., -1., 1., -1., -1., 1., -1., -1., 0., 1., 1., 1., "/dev/null");
execute_throws(&dump1, "should throw due to nsteps z < 1"); execute_throws(&dump1, "should throw due to nsteps z < 1");
setAttributesCart(&dump1, -1., -1., 1., -1., -1., 1., -1., -1., 1., 1., 1., 0., "/dev/null"); setAttributesCart(&dump1, -1., -1., 1., -1., -1., 1., -1., -1., 1., 1., 1., 0., "/dev/null");
execute_throws(&dump1, "should throw due to nsteps t < 1"); execute_throws(&dump1, "should throw due to nsteps t < 1");
setAttributesCart(&dump1, -1., -1., 1., -1., -1., 1., -1., -1., 1.5, 1., 1., 1., "/dev/null"); setAttributesCart(&dump1, -1., -1., 1., -1., -1., 1., -1., -1., 1.5, 1., 1., 1., "/dev/null");
execute_throws(&dump1, "should throw due to nsteps not integer"); execute_throws(&dump1, "should throw due to nsteps not integer");
} }
void clear_files() { void clear_files() {
std::string fname1 = Util::combineFilePath({
OpalData::getInstance()->getAuxiliaryOutputDirectory(), "test1"
});
std::string fname2 = Util::combineFilePath({
OpalData::getInstance()->getAuxiliaryOutputDirectory(), "test2"
});
std::string fname3 = Util::combineFilePath({
OpalData::getInstance()->getAuxiliaryOutputDirectory(), "test3"
});
std::string fname4 = Util::combineFilePath({
OpalData::getInstance()->getAuxiliaryOutputDirectory(), "test4"
});
std::string fnameCyl = Util::combineFilePath({
OpalData::getInstance()->getAuxiliaryOutputDirectory(), "testCyl"
});
size_t n_str_array = 0; size_t n_str_array = 0;
std::string str_array[5] = {"test1", "test2", "test3", "test4", "testCyl"}; std::string str_array[5] = {fname1, fname2, fname3, fname4, fnameCyl};
for (size_t i = 0; i < n_str_array; ++i) { for (size_t i = 0; i < n_str_array; ++i) {
if (fopen(str_array[i].c_str(), "r") != NULL) { if (std::fopen(str_array[i].c_str(), "r") != NULL) {
remove(str_array[i].c_str()); std::remove(str_array[i].c_str());
} }
} }
} }
...@@ -148,18 +168,31 @@ void clear_files() { ...@@ -148,18 +168,31 @@ void clear_files() {
TEST(DumpEMFieldsTest, writeFieldsCartTest) { TEST(DumpEMFieldsTest, writeFieldsCartTest) {
OpalTestUtilities::SilenceTest silencer; OpalTestUtilities::SilenceTest silencer;
std::string fname1 = Util::combineFilePath({
OpalData::getInstance()->getAuxiliaryOutputDirectory(), "test1"
});
std::string fname2 = Util::combineFilePath({
OpalData::getInstance()->getAuxiliaryOutputDirectory(), "test2"
});
std::string fname3 = Util::combineFilePath({
OpalData::getInstance()->getAuxiliaryOutputDirectory(), "test3"
});
std::string fname4 = Util::combineFilePath({
OpalData::getInstance()->getAuxiliaryOutputDirectory(), "test4"
});
clear_files(); clear_files();
DumpEMFields dump1; DumpEMFields dump1;
setAttributesCart(&dump1, 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., "test1"); setAttributesCart(&dump1, 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., "test1");
dump1.execute(); dump1.execute();
DumpEMFields dump2; DumpEMFields dump2;
setAttributesCart(&dump2, 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., "test2"); setAttributesCart(&dump2, 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., "test2");
dump2.execute(); dump2.execute();
DumpEMFields dump3; DumpEMFields dump3;
setAttributesCart(&dump3, 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., "test3"); setAttributesCart(&dump3, 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., "test3");
// note we don't execute dump3; so it should not be written // note we don't execute dump3; so it should not be written
DumpEMFields dump4; DumpEMFields dump4;
setAttributesCart(&dump4, 0.1, 0.1, 3., -0.1, 0.2, 2., 0.2, 0.3, 2., 1., 1., 2., "test4"); setAttributesCart(&dump4, 0.1, 0.1, 3., -0.1, 0.2, 2., 0.2, 0.3, 2., 1., 1., 2., "test4");
dump4.execute(); dump4.execute();
MockComponent comp; MockComponent comp;
try { try {
...@@ -167,13 +200,13 @@ TEST(DumpEMFieldsTest, writeFieldsCartTest) { ...@@ -167,13 +200,13 @@ TEST(DumpEMFieldsTest, writeFieldsCartTest) {
} catch (OpalException& exc) { } catch (OpalException& exc) {
EXPECT_TRUE(false) << "Threw OpalException on writefields: " << exc.what() << std::endl;; EXPECT_TRUE(false) << "Threw OpalException on writefields: " << exc.what() << std::endl;;
} }
std::ifstream fin1("test1"); std::ifstream fin1(fname1);
EXPECT_TRUE(fin1.good()); EXPECT_TRUE(fin1.good());
std::ifstream fin2("test2"); std::ifstream fin2(fname2);
EXPECT_TRUE(fin2.good()); EXPECT_TRUE(fin2.good());
std::ifstream fin3("test3"); std::ifstream fin3(fname3);
EXPECT_FALSE(fin3.good()); // does not exist EXPECT_FALSE(fin3.good()); // does not exist
std::ifstream fin4("test4"); std::ifstream fin4(fname4);
EXPECT_TRUE(fin4.good()); EXPECT_TRUE(fin4.good());
int n_lines; int n_lines;
fin4 >> n_lines; fin4 >> n_lines;
...@@ -212,10 +245,14 @@ TEST(DumpEMFieldsTest, writeFieldsCartTest) { ...@@ -212,10 +245,14 @@ TEST(DumpEMFieldsTest, writeFieldsCartTest) {
TEST(DumpEMFieldsTest, writeFieldsCylTest) { TEST(DumpEMFieldsTest, writeFieldsCylTest) {
OpalTestUtilities::SilenceTest silencer; OpalTestUtilities::SilenceTest silencer;
const double rad = M_PI/180.;
std::string fnameCyl = Util::combineFilePath({
OpalData::getInstance()->getAuxiliaryOutputDirectory(), "testCyl"
});
clear_files(); clear_files();
DumpEMFields dump; DumpEMFields dump;
setAttributesCyl(&dump, 0.1, 0.1, 3., 90.*rad, 45.*rad, 16, 0.2, 0.3, 2., 1., 1., 2., "testCyl"); setAttributesCyl(&dump, 0.1, 0.1, 3., 90.*Physics::deg2rad, 45.*Physics::deg2rad, 16, 0.2, 0.3, 2., 1., 1., 2., "testCyl");
dump.execute(); dump.execute();
// depending on execution order, this might write cartesian tests as well... never mind // depending on execution order, this might write cartesian tests as well... never mind
MockComponent comp; MockComponent comp;
...@@ -224,7 +261,7 @@ TEST(DumpEMFieldsTest, writeFieldsCylTest) { ...@@ -224,7 +261,7 @@ TEST(DumpEMFieldsTest, writeFieldsCylTest) {
} catch (OpalException& exc) { } catch (OpalException& exc) {
EXPECT_TRUE(false) << "Threw OpalException on writefields: " << exc.what() << std::endl;; EXPECT_TRUE(false) << "Threw OpalException on writefields: " << exc.what() << std::endl;;
} }
std::ifstream fin("testCyl"); std::ifstream fin(fnameCyl);
EXPECT_TRUE(fin.good()); EXPECT_TRUE(fin.good());
int n_lines; int n_lines;
fin >> n_lines; fin >> n_lines;
...@@ -264,4 +301,5 @@ TEST(DumpEMFieldsTest, writeFieldsCylTest) { ...@@ -264,4 +301,5 @@ TEST(DumpEMFieldsTest, writeFieldsCylTest) {
// EXPECT_TRUE(false) << "Do DumpEMFields cylindrical documentation!"; // EXPECT_TRUE(false) << "Do DumpEMFields cylindrical documentation!";
} }
} }
...@@ -24,16 +24,18 @@ ...@@ -24,16 +24,18 @@
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE. * POSSIBILITY OF SUCH DAMAGE.
*/ */
#include <fstream> #include <fstream>