Commit dbc17c9f authored by kraus's avatar kraus

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);
std::ofstream out("data/" + itsCavity_m->getName() + "_AP.dat");
track(initialR_m, initialP_m, t + tErr, dt, newPhase, &out);
out.close();
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"
......@@ -367,7 +368,7 @@ MapType Fieldmap::readHeader(std::string Filename) {
h5_file_t file = H5OpenFile (Filename.c_str(), H5_O_RDONLY, props);
assert (file != (h5_file_t)H5_ERR);
H5CloseProp (props);
h5err = H5SetStep(file, 0);
assert (h5err != H5_ERR);
......@@ -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,10 +494,13 @@ 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);
out << std::setw(16) << std::setprecision(8) << *it
<< std::setw(16) << std::setprecision(8) << ez
<< std::setw(16) << std::setprecision(8) << onAxisFieldCheck
<< std::endl;
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();
......@@ -801,4 +806,4 @@ REGISTER_PARSE_TYPE(std::string);
std::string Fieldmap::alpha_numeric("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789.-+\211");
std::map<std::string, Fieldmap::FieldmapDescription> Fieldmap::FieldmapDictionary = std::map<std::string, Fieldmap::FieldmapDescription>();
char Fieldmap::buffer_m[READ_BUFFER_LENGTH];
char Fieldmap::buffer_m[READ_BUFFER_LENGTH];
\ No newline at end of file
......@@ -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();
......
......@@ -36,7 +36,9 @@ OpalFlexibleCollimator::OpalFlexibleCollimator():
itsAttr[DESC] = Attributes::makeString
("DESCRIPTION", "String describing the distribution of holes");
itsAttr[OUTFN] = Attributes::makeString
("OUTFN", "File name of log file for deleted particles");
("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]);
......@@ -415,7 +417,7 @@ void OptimizeCmd::execute() {
stashEnvironment();
try {
CmdArguments_t args(new CmdArguments(argv.size(), &argv[0]));
this->run(args, funcs, dvars, objectives, constraints);
} catch (OptPilotException &e) {
......@@ -442,15 +444,15 @@ void OptimizeCmd::popEnvironment() {
OptimizeCmd::CrossOver OptimizeCmd::crossoverSelection(std::string crossover) {
crossover = Util::toUpper(crossover);
std::map<std::string, CrossOver> map;
map["BLEND"] = CrossOver::Blend;
map["NAIVEONEPOINT"] = CrossOver::NaiveOnePoint;
map["NAIVEUNIFORM"] = CrossOver::NaiveUniform;
map["SIMULATEDBINARY"] = CrossOver::SimulatedBinary;
CrossOver co = CrossOver::Blend;
switch ( map[crossover] ) {
case CrossOver::Blend:
break;
......@@ -467,19 +469,19 @@ OptimizeCmd::CrossOver OptimizeCmd::crossoverSelection(std::string crossover) {
throw OpalException("OptimizeCmd::crossoverSelection",
"No cross over '" + crossover + "' supported.");
}
return co;
}
OptimizeCmd::Mutation OptimizeCmd::mutationSelection(std::string mutation) {
mutation = Util::toUpper(mutation);
std::map<std::string, Mutation> map;
map["INDEPENDENTBIT"] = Mutation::IndependentBit;
map["ONEBIT"] = Mutation::OneBit;
Mutation mut = Mutation::IndependentBit;
switch ( map[mutation] ) {
case Mutation::IndependentBit:
break;
......@@ -490,7 +492,7 @@ OptimizeCmd::Mutation OptimizeCmd::mutationSelection(std::string mutation) {
throw OpalException("OptimizeCmd::mutationSelection",
"No mutation '" + mutation + "' supported.");
}
return mut;
}
......@@ -505,18 +507,18 @@ void OptimizeCmd::run(const CmdArguments_t& args,
typedef CommSplitter< ManyMasterSplit< NoCommTopology > > Comm_t;
typedef SocialNetworkGraph< NoCommTopology > SolPropagationGraph_t;
boost::shared_ptr<Comm_t> comm(new Comm_t(args, MPI_COMM_WORLD));
CrossOver crossover = this->crossoverSelection(Attributes::getString(itsAttr[CROSSOVER]));
Mutation mutation = this->mutationSelection(Attributes::getString(itsAttr[MUTATION]));
switch ( crossover + mutation ) {
case CrossOver::Blend + Mutation::IndependentBit:
{
typedef FixedPisaNsga2< BlendCrossover, IndependentBitMutation > Opt_t;
typedef Pilot<Input_t, Opt_t, Sim_t, SolPropagationGraph_t, Comm_t> pilot_t;
boost::scoped_ptr<pilot_t> pi(new pilot_t(args, comm,
funcs, dvars,
objectives, constraints,
......@@ -527,7 +529,7 @@ void OptimizeCmd::run(const CmdArguments_t& args,
{
typedef FixedPisaNsga2< BlendCrossover, OneBitMutation > Opt_t;
typedef Pilot<Input_t, Opt_t, Sim_t, SolPropagationGraph_t, Comm_t> pilot_t;
boost::scoped_ptr<pilot_t> pi(new pilot_t(args, comm,
funcs, dvars,
objectives, constraints,
......@@ -538,7 +540,7 @@ void OptimizeCmd::run(const CmdArguments_t& args,
{
typedef FixedPisaNsga2< NaiveOnePointCrossover, IndependentBitMutation > Opt_t;
typedef Pilot<Input_t, Opt_t, Sim_t, SolPropagationGraph_t, Comm_t> pilot_t;
boost::scoped_ptr<pilot_t> pi(new pilot_t(args, comm,
funcs, dvars,
objectives, constraints,
......@@ -549,7 +551,7 @@ void OptimizeCmd::run(const CmdArguments_t& args,
{
typedef FixedPisaNsga2< NaiveOnePointCrossover, OneBitMutation > Opt_t;
typedef Pilot<Input_t, Opt_t, Sim_t, SolPropagationGraph_t, Comm_t> pilot_t;
boost::scoped_ptr<pilot_t> pi(new pilot_t(args, comm,
funcs, dvars,
objectives, constraints,
......@@ -560,7 +562,7 @@ void OptimizeCmd::run(const CmdArguments_t& args,
{
typedef FixedPisaNsga2< NaiveUniformCrossover, IndependentBitMutation > Opt_t;
typedef Pilot<Input_t, Opt_t, Sim_t, SolPropagationGraph_t, Comm_t> pilot_t;
boost::scoped_ptr<pilot_t> pi(new pilot_t(args, comm,
funcs, dvars,
objectives, constraints,
......@@ -571,7 +573,7 @@ void OptimizeCmd::run(const CmdArguments_t& args,
{
typedef FixedPisaNsga2< NaiveUniformCrossover, OneBitMutation > Opt_t;
typedef Pilot<Input_t, Opt_t, Sim_t, SolPropagationGraph_t, Comm_t> pilot_t;
boost::scoped_ptr<pilot_t> pi(new pilot_t(args, comm,
funcs, dvars,
objectives, constraints,
......@@ -582,7 +584,7 @@ void OptimizeCmd::run(const CmdArguments_t& args,
{
typedef FixedPisaNsga2< SimulatedBinaryCrossover, IndependentBitMutation > Opt_t;
typedef Pilot<Input_t, Opt_t, Sim_t, SolPropagationGraph_t, Comm_t> pilot_t;
boost::scoped_ptr<pilot_t> pi(new pilot_t(args, comm,
funcs, dvars,
objectives, constraints,
......@@ -593,7 +595,7 @@ void OptimizeCmd::run(const CmdArguments_t& args,
{
typedef FixedPisaNsga2< SimulatedBinaryCrossover, OneBitMutation > Opt_t;
typedef Pilot<Input_t, Opt_t, Sim_t, SolPropagationGraph_t, Comm_t> pilot_t;
boost::scoped_ptr<pilot_t> pi(new pilot_t(args, comm,
funcs, dvars,
objectives, constraints,
......@@ -604,4 +606,4 @@ void OptimizeCmd::run(const CmdArguments_t& args,
throw OpalException("OptimizeCmd::run",
"No such cross over and mutation combination supported.");
}
}
}
\ No newline at end of file
......@@ -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