50#define MAX_NUM_INSTANCES 10
215 throw OpalException(
"OpalData::stashInstance()",
"too many OpalData instances stashed");
224 throw OpalException(
"OpalData::popInstance()",
"no OpalData instances stashed");
236 return p->maxTrackSteps_m;
240 p->maxTrackSteps_m = s;
244 p->maxTrackSteps_m += s;
258 p->hasPriorRun_m =
false;
259 p->isRestart_m =
false;
260 p->hasRestartFile_m =
false;
261 p->hasBunchAllocated_m =
false;
262 p->hasDataSinkAllocated_m =
false;
263 p->gPhaseShift_m = 0.0;
264 p->maxPhases_m.clear();
265 p->isInOPALCyclMode_m =
false;
266 p->isInOPALTMode_m =
false;
267 p->isInPrepState_m =
false;
268 p->isOptimizerFlag_m =
false;
272 return p->isInOPALCyclMode_m;
276 return p->isInOPALTMode_m;
280 return p->isOptimizerFlag_m;
284 p->isInOPALCyclMode_m =
true;
288 p->isInOPALTMode_m =
true;
292 p->isOptimizerFlag_m =
true;
296 return p->isInPrepState_m;
300 p->isInPrepState_m = state;
304 return p->hasPriorRun_m;
308 p->hasPriorRun_m = value;
312 return p->isRestart_m;
316 p->isRestart_m = value;
320 p->restartStep_m = s;
324 return p->restartStep_m;
328 return p->restartFn_m;
333 p->hasRestartFile_m =
true;
337 return p->hasRestartFile_m;
341 p->restart_dump_freq_m = N;
345 return p->restart_dump_freq_m;
349 p->openMode_m = openMode;
353 return p->openMode_m;
357 p->last_step_m = step;
361 return p->last_step_m;
365 return p->hasBunchAllocated_m;
369 p->hasBunchAllocated_m =
true;
381 return p->hasDataSinkAllocated_m;
386 p->hasDataSinkAllocated_m =
true;
390 return p->dataSink_m;
398 return p->maxPhases_m.begin();
402 return p->maxPhases_m.end();
406 return p->maxPhases_m.size();
410 p->energyEvolution_m.insert(std::make_pair(spos, ekin));
414 return p->energyEvolution_m.begin();
418 return p->energyEvolution_m.end();
447 p->gPhaseShift_m = shift;
452 return p->gPhaseShift_m;
464 return p->bg_m !=
nullptr;
468 for (ObjectDir::iterator i =
p->mainDirectory.begin(); i !=
p->mainDirectory.end(); ++i) {
476 Object* oldObject =
p->mainDirectory.find(name);
478 if (oldObject !=
nullptr) {
480 "OpalData::create()",
"You cannot replace the object \"" + name +
"\".");
482 p->mainDirectory.insert(name, newObject);
489 Object* oldObject =
p->mainDirectory.find(name);
491 if (oldObject !=
nullptr && oldObject != newObject) {
495 "OpalData::define()",
"You cannot replace the object \"" + name +
"\".");
498 *ippl::Info <<
"Replacing the object \"" << name <<
"\"." << endl;
503 while (i !=
p->tableDirectory.end()) {
507 const std::string& tableName = table->
getOpalName();
511 std::cerr << std::endl
512 <<
"Erasing dependent table \"" << tableName <<
"\"."
524 for (ObjectDir::iterator i =
p->mainDirectory.begin(); i !=
p->mainDirectory.end();
526 (*i).second->replace(oldObject, newObject);
537 p->mainDirectory.insert(name, newObject);
548 Object* oldObject =
p->mainDirectory.find(name);
550 if (oldObject !=
nullptr) {
552 for (ObjectDir::iterator i =
p->mainDirectory.begin(); i !=
p->mainDirectory.end(); ++i) {
553 Object* child = &*i->second;
559 p->mainDirectory.erase(name);
564 return p->mainDirectory.find(name);
580 os << std::endl <<
"All object names " << std::endl;
582 for (ObjectDir::const_iterator index =
p->mainDirectory.begin();
583 index !=
p->mainDirectory.end(); ++index) {
584 const std::string name = (*index).first;
586 os << name <<
" = " << *(*index).second << std::endl;
609 os << std::endl <<
"Object names matching the pattern \"" << pattern <<
"\":" << std::endl;
611 for (ObjectDir::const_iterator index =
p->mainDirectory.begin();
612 index !=
p->mainDirectory.end(); ++index) {
613 const std::string name = (*index).first;
615 if (!name.empty() && regex.
match(name)) {
619 column += name.length();
624 }
while ((column % 20) != 0);
638 p->tableDirectory.push_back(table);
645 p->tableDirectory.erase(j);
650 p->exprDirectory.insert(expr);
654 p->exprDirectory.erase(expr);
658 p->referenceMomentum = p0;
662 p->itsTitle_m = title;
674 return p->itsTitle_m;
686 std::string& fn =
p->inputFn_m;
687 int const pdot = fn.rfind(
".");
688 return fn.substr(0, pdot);
692 if (
p->outFiles_m.count(outfn) == 0) {
693 p->outFiles_m.insert(outfn);
696 "OpalData::checkAndAddOutputFileName",
697 "Duplicate file name for output, '" + outfn +
"', detected");
702 Inform msg(
"OpalData ");
712 i !=
p->tableDirectory.end(); ++i) {
717 for (ObjectDir::iterator i =
p->mainDirectory.begin(); i !=
p->mainDirectory.end(); ++i) {
718 (*i).second->update();
727 std::map<std::string, std::string> udata;
729 for (
auto& uvar : uvars) {
734 udata[uvar] = std::to_string(variable->
getReal());
741 "Type of '" + uvar +
"' not supported. "
742 "Only support for REAL and STRING.");
749 std::vector<std::string> result;
751 for (ObjectDir::const_iterator index =
p->mainDirectory.begin();
752 index !=
p->mainDirectory.end(); ++index) {
753 std::string tmpName = (*index).first;
754 if (!tmpName.empty()) {
757 if (!tmpObject || tmpObject->
isBuiltin())
760 result.push_back(tmpName);
769 if (
p->problemSize_m.find(name) !=
p->problemSize_m.end()) {
770 p->problemSize_m.insert(std::make_pair(name, value));
772 p->problemSize_m[name] = value;
777 return p->problemSize_m;
781 p->arguments_m.clear();
782 for (
int i = 0; i < argc; ++i) {
783 p->arguments_m.push_back(argv[i]);
788 return p->arguments_m;
PartBunch< PLayout_t< double, 3 >, double, 3 > PartBunch_t
ippl::FieldLayout< Dim > FieldLayout_t
ippl::UniformCartesian< double, 3 > Mesh_t
#define MAX_NUM_INSTANCES
std::map< double, double > energyEvolution_t
std::pair< std::string, double > MaxPhasesT
typename ippl::ParticleSpatialLayout< T, Dim, Mesh_t< Dim > > PLayout_t
Abstract base class for attribute values of different types.
A map of string versus pointer to Object.
The base class for all OPAL objects.
void setParent(Object *)
Set parent object.
virtual bool canReplaceBy(Object *object)
Test if replacement is allowed.
Object * getParent() const
Return parent pointer.
const std::string & getOpalName() const
Return object name.
void setDirty(bool)
Set/reset the [b]modified[/b] flag.
virtual const std::string getCategory() const =0
Return the object category as a string.
bool isBuiltin() const
True, if [b]this[/b] is a built-in object.
Abstract base class for functor objects whose argument is an Object.
energyEvolution_t energyEvolution_m
std::list< Table * >::iterator tableIterator
PLayout_t< double, 3 > * PL_m
std::map< std::string, unsigned int > problemSize_m
std::set< std::string > outFiles_m
std::vector< std::string > arguments_m
bool hasDataSinkAllocated_m
OpalData::OpenMode openMode_m
Mode for writing files.
ValueDefinition * referenceMomentum
FieldLayout_t< 3 > * FL_m
std::list< Table * > tableDirectory
std::set< AttributeBase * > exprDirectory
std::set< AttributeBase * >::iterator exprIterator
unsigned long long maxTrackSteps_m
std::vector< MaxPhasesT > maxPhases_m
The global OPAL structure.
void addEnergyData(double spos, double ekin)
void printAllNames(std::ostream &stream)
void storeTitle(const std::string &)
Store the page title.
double getP0() const
Return value of global reference momentum.
int getLastStep() const
get the last step from a possible previous run
void registerExpression(AttributeBase *)
Register expression.
int getNumberOfMaxPhases()
PartBunch_t * getPartBunch()
unsigned long long getMaxTrackSteps()
void storeInputFn(const std::string &fn)
store opals input filename
void setPartBunch(PartBunch_t *p)
void setRestartDumpFreq(const int &N)
set the dump frequency as found in restart file
std::vector< MaxPhasesT >::iterator getLastMaxPhases()
void erase(const std::string &name)
Delete existing entry.
std::string getInputBasename()
get input file name without extension
void makeDirty(Object *object)
Invalidate expressions.
void setP0(ValueDefinition *p0)
Set the global momentum.
double getGlobalPhaseShift()
units: (sec)
std::map< std::string, std::string > getVariableData()
std::string getTitle()
Get the title string.
void checkAndAddOutputFileName(const std::string &outfn)
checks the output file names of all items to avoid duplicates
std::vector< MaxPhasesT >::iterator getFirstMaxPhases()
void printNames(std::ostream &stream, const std::string &pattern)
Print all objects.
void update()
Update all objects.
void apply(const ObjectFunction &)
Apply a function to all objects.
bool hasRestartFile()
true if we do a restart from specified h5 file
void setRestartRun(const bool &value=true)
set OPAL in restart mode
void setMaxPhase(std::string elName, double phi)
void setLastStep(const int &step)
set the last step in a run for possible follow-up run
std::vector< std::string > getArguments()
static void stashInstance()
int getRestartDumpFreq() const
get the dump frequency as found in restart file
std::string getRestartFileName()
get opals restart h5 format filename
std::string getInputFn()
get opals input filename
void unregisterExpression(AttributeBase *)
Unregister expression.
Object * find(const std::string &name)
Find entry.
bool hasPriorTrack()
true if in follow-up track
static std::stack< OpalData * > stashedInstances
int getRestartStep()
get the step where to restart
void create(Object *newObject)
Create new object.
static OpalData * instance
void printTitle(std::ostream &)
Print the page title.
static void deleteInstance()
void setRestartFileName(std::string s)
store opals restart h5 format filename
void setInPrepState(bool state)
void setPriorTrack(const bool &value=true)
true if in follow-up track
void setDataSink(DataSink *s)
OpenMode getOpenMode() const
bool hasDataSinkAllocated()
true if we already allocated a DataSink object
void setGlobalPhaseShift(double shift)
units: (sec)
bool hasBunchAllocated()
true if we already allocated a ParticleBunch object
energyEvolution_t::iterator getFirstEnergyData()
void unregisterTable(Table *t)
Unregister table.
void reset()
reset object for consecutive runs
static OpalData * getInstance()
void setMaxTrackSteps(unsigned long long s)
void storeArguments(int argc, char *argv[])
static bool isInstantiated
BoundaryGeometry * getGlobalGeometry()
void define(Object *newObject)
Define a new object.
energyEvolution_t::iterator getLastEnergyData()
OpenMode
Enum for writing to files.
void setRestartStep(int s)
store the location where to restart
void setGlobalGeometry(BoundaryGeometry *bg)
void incMaxTrackSteps(unsigned long long s)
static OpalData * popInstance()
void registerTable(Table *t)
Register table.
std::string getAuxiliaryOutputDirectory() const
get the name of the the additional data directory
void addProblemCharacteristicValue(const std::string &name, unsigned int value)
void setOpenMode(OpenMode openMode)
bool inRestartRun()
true if we do a restart run
const std::map< std::string, unsigned int > & getProblemCharacteristicValues() const
std::vector< std::string > getVariableNames()
virtual void operator()(Object *) const
The function to be executed.
The base class for all OPAL tables.
virtual bool isDependent(const std::string &name) const =0
Find out if table depends on the object identified by [b]name[/b].
The base class for all OPAL value definitions.
The base class for all OPAL exceptions.
bool match(const std::string &s) const
Match a string against the pattern.
virtual double getReal() const
Return value.
virtual std::string getString() const
Return value.