Commit dbc17c9f authored by kraus's avatar kraus
Browse files

reduce amount of data that is written in optimizer and sampler runs

parent cf38bb2b
......@@ -144,6 +144,7 @@ struct OpalDataImpl {
bool isInOPALCyclMode_m;
bool isInOPALTMode_m;
bool isInOPALEnvMode_m;
bool isOptimizerFlag_m;
bool isInPrepState_m;
std::map<std::string, unsigned int> problemSize_m;
......@@ -167,6 +168,7 @@ OpalDataImpl::OpalDataImpl():
isInOPALCyclMode_m(false),
isInOPALTMode_m(false),
isInOPALEnvMode_m(false),
isOptimizerFlag_m(true),
isInPrepState_m(false)
{
bunch_m = nullptr;
......@@ -280,6 +282,7 @@ void OpalData::reset() {
p->isInOPALTMode_m = false;
p->isInOPALEnvMode_m = false;
p->isInPrepState_m = false;
p->isOptimizerFlag_m = false;
}
bool OpalData::isInOPALCyclMode() {
......@@ -294,6 +297,10 @@ bool OpalData::isInOPALEnvMode() {
return p->isInOPALEnvMode_m;
}
bool OpalData::isOptimizerRun() {
return p->isOptimizerFlag_m;
}
void OpalData::setInOPALCyclMode() {
p->isInOPALCyclMode_m = true;
}
......@@ -306,6 +313,10 @@ void OpalData::setInOPALEnvMode() {
p->isInOPALEnvMode_m = true;
}
void OpalData::setOptimizerFlag() {
p->isOptimizerFlag_m = true;
}
bool OpalData::isInPrepState() {
return p->isInPrepState_m;
}
......
......@@ -149,10 +149,12 @@ public:
bool isInOPALCyclMode();
bool isInOPALTMode();
bool isInOPALEnvMode();
bool isOptimizerRun();
void setInOPALCyclMode();
void setInOPALTMode();
void setInOPALEnvMode();
void setOptimizerFlag();
bool isInPrepState();
void setInPrepState(bool state);
......
......@@ -128,9 +128,14 @@ double CavityAutophaser::getPhaseAtMaxEnergy(const Vector_t &R,
newPhase = std::fmod(newPhase + basePhase, Physics::two_pi);
auto opal = OpalData::getInstance();
if (!opal->isOptimizerRun()) {
std::ofstream out("data/" + itsCavity_m->getName() + "_AP.dat");
track(initialR_m, initialP_m, t + tErr, dt, newPhase, &out);
out.close();
} else {
track(initialR_m, initialP_m, t + tErr, dt, newPhase, NULL);
}
INFOMSG(level1 << std::fixed << std::setprecision(4)
<< itsCavity_m->getName() << "_phi = " << newPhase * Physics::rad2deg << " [deg], "
......
......@@ -137,6 +137,8 @@ enum elements {
};
void IndexMap::saveSDDS(double startS) const {
auto opal = OpalData::getInstance();
if (opal->isOptimizerRun()) return;
std::string fileName("data/" + OpalData::getInstance()->getInputBasename() + "_ElementPositions.sdds");
std::ofstream sdds;
......
......@@ -44,7 +44,8 @@ OrbitThreader::OrbitThreader(const PartData &ref,
integrator_m(ref),
reference_m(ref)
{
if (Ippl::myNode() == 0) {
auto opal = OpalData::getInstance();
if (Ippl::myNode() == 0 && !opal->isOptimizerRun()) {
std::string fileName = "data/" + OpalData::getInstance()->getInputBasename() + "_DesignPath.dat";
if (Options::openMode == Options::WRITE || !boost::filesystem::exists(fileName)) {
logger_m.open(fileName);
......@@ -164,7 +165,7 @@ void OrbitThreader::integrate(const IndexMap::value_t &activeSet, size_t maxStep
Bf += itsOpalBeamline_m.rotateFromLocalCS(*it, localB);
}
if (step % loggingFrequency_m == 0 && Ippl::myNode() == 0) {
if (step % loggingFrequency_m == 0 && Ippl::myNode() == 0 && !OpalData::getInstance()->isOptimizerRun()) {
logger_m << std::setw(18) << std::setprecision(8) << pathLength_m + std::copysign(euclidean_norm(r_m - oldR), dt_m)
<< std::setw(18) << std::setprecision(8) << r_m(0)
<< std::setw(18) << std::setprecision(8) << r_m(1)
......
......@@ -3,6 +3,7 @@
#include "Utilities/GeneralClassicException.h"
#include "Utilities/Util.h"
#include "Utilities/Options.h"
#include "AbstractObjects/OpalData.h"
#include "Physics/Physics.h"
......@@ -364,13 +365,17 @@ void FM3DDynamic::getOnaxisEz(std::vector<std::pair<double, double> > & F) {
-- index_y;
}
std::ofstream out("data/" + Filename_m);
unsigned int ii = (index_y + index_x * num_gridpy_m) * num_gridpz_m;
for(unsigned int i = 0; i < num_gridpz_m; ++ i) {
F[i].first = hz_m * i;
F[i].second = FieldstrengthEz_m[ii ++] / 1e6;
}
auto opal = OpalData::getInstance();
if (opal->isOptimizerRun()) return;
std::ofstream out("data/" + Filename_m);
for(unsigned int i = 0; i < num_gridpz_m; ++ i) {
Vector_t R(0,0,zbegin_m + F[i].first), B(0.0), E(0.0);
getFieldstrength(R, E, B);
out << std::setw(16) << std::setprecision(8) << F[i].first
......
......@@ -25,6 +25,7 @@
#include "Fields/FMDummy.h"
#include "Utilities/GeneralClassicException.h"
#include "Utilities/Options.h"
#include "AbstractObjects/OpalData.h"
#include "Physics/Physics.h"
#include "H5hut.h"
......@@ -469,8 +470,9 @@ void Fieldmap::checkMap(unsigned int accuracy,
size_t lastSlash = Filename_m.find_last_of("/");
lastSlash = (lastSlash == std::string::npos)? 0: lastSlash + 1;
auto opal = OpalData::getInstance();
std::ofstream out;
if (Ippl::myNode() == 0) {
if (Ippl::myNode() == 0 && !opal->isOptimizerRun()) {
out.open("data/" + Filename_m.substr(lastSlash, lastDot) + ".check");
out << "# z original reproduced\n";
}
......@@ -492,11 +494,14 @@ void Fieldmap::checkMap(unsigned int accuracy,
ezMax = std::abs(ez) > ezMax? std::abs(ez): ezMax;
error += std::pow(difference, 2.0);
ezSquare += std::pow(ez, 2.0);
if (Ippl::myNode() == 0 && !opal->isOptimizerRun()) {
out << std::setw(16) << std::setprecision(8) << *it
<< std::setw(16) << std::setprecision(8) << ez
<< std::setw(16) << std::setprecision(8) << onAxisFieldCheck
<< std::endl;
}
}
out.close();
if (sqrt(error / ezSquare) > 1e-1 || maxDiff > 1e-1 * ezMax) {
......
......@@ -392,7 +392,8 @@ void OpalBeamline::compute3DLattice() {
}
void OpalBeamline::plot3DLattice() {
if (Ippl::myNode() != 0) return;
auto opal = OpalData::getInstance();
if (opal->isOptimizerRun() || Ippl::myNode() != 0) return;
elements_m.sort([](const ClassicField& a, const ClassicField& b) {
double edgeA = 0.0, edgeB = 0.0;
......@@ -455,13 +456,6 @@ void OpalBeamline::plot3DLattice() {
}
}
it = elements_m.begin();
double tau = (minX(0) - origin(0) - 0.3) / direction(0);
origin += tau * direction;
if (origin(0) < minX(0)) minX(0) = origin(0);
if (origin(1) < minX(1)) minX(1) = origin(1);
std::ofstream gpl;
std::string fileName = "data/" + OpalData::getInstance()->getInputBasename() + "_ElementPositions.gpl";
if (Options::openMode == Options::APPEND && boost::filesystem::exists(fileName)) {
......@@ -471,6 +465,7 @@ void OpalBeamline::plot3DLattice() {
}
gpl.precision(8);
it = elements_m.begin();
for (; it != end; ++ it) {
std::shared_ptr<Component> element = (*it).getElement();
......@@ -492,7 +487,7 @@ void OpalBeamline::plot3DLattice() {
}
void OpalBeamline::save3DLattice() {
if (Ippl::myNode() != 0) return;
if (Ippl::myNode() != 0 || OpalData::getInstance()->isOptimizerRun()) return;
elements_m.sort([](const ClassicField& a, const ClassicField& b) {
return a.order_m < b.order_m;
......@@ -647,7 +642,7 @@ namespace {
}
void OpalBeamline::save3DInput() {
if (Ippl::myNode() != 0) return;
if (Ippl::myNode() != 0 || OpalData::getInstance()->isOptimizerRun()) return;
FieldList::iterator it = elements_m.begin();
FieldList::iterator end = elements_m.end();
......
......@@ -37,6 +37,8 @@ OpalFlexibleCollimator::OpalFlexibleCollimator():
("DESCRIPTION", "String describing the distribution of holes");
itsAttr[OUTFN] = Attributes::makeString
("OUTFN", "File name of log file for deleted particles");
itsAttr[DUMP] = Attributes::makeBool
("DUMP", "Save quadtree and holes of collimator", false);
registerStringAttribute("OUTFN");
registerStringAttribute("DESC");
......@@ -109,6 +111,10 @@ void OpalFlexibleCollimator::update() {
coll->setParticleMatterInteraction(partMatInt_m->handler_m);
}
if (Attributes::getBool(itsAttr[DUMP])) {
coll->writeHolesAndQuadtree(getOpalName());
}
// Transmit "unknown" attributes.
OpalElement::updateUnknown(coll);
}
\ No newline at end of file
......@@ -35,6 +35,7 @@ public:
FNAME = COMMON, // The horizontal half-size.
DESC,
OUTFN,
DUMP,
SIZE
};
......
......@@ -169,6 +169,8 @@ void OptimizeCmd::execute() {
namespace fs = boost::filesystem;
auto opal = OpalData::getInstance();
opal->setOptimizerFlag();
fs::path inputfile(Attributes::getString(itsAttr[INPUT]));
std::vector<std::string> dvarsstr = Attributes::getStringArray(itsAttr[DVARS]);
......
......@@ -116,6 +116,8 @@ void SampleCmd::execute() {
namespace fs = boost::filesystem;
auto opal = OpalData::getInstance();
opal->setOptimizerFlag();
fs::path inputfile(Attributes::getString(itsAttr[INPUT]));
unsigned int seed = Attributes::getReal(itsAttr[SEED]);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment