51#define MAX_NUM_INSTANCES 10
216 "too many OpalData instances stashed");
226 "no OpalData instances stashed");
237 return p->maxTrackSteps_m;
241 p->maxTrackSteps_m = s;
245 p->maxTrackSteps_m += s;
259 p->hasPriorRun_m =
false;
260 p->isRestart_m =
false;
261 p->hasRestartFile_m =
false;
262 p->hasBunchAllocated_m =
false;
263 p->hasDataSinkAllocated_m =
false;
264 p->gPhaseShift_m = 0.0;
265 p->maxPhases_m.clear();
266 p->isInOPALCyclMode_m =
false;
267 p->isInOPALTMode_m =
false;
268 p->isInPrepState_m =
false;
269 p->isOptimizerFlag_m =
false;
273 return p->isInOPALCyclMode_m;
277 return p->isInOPALTMode_m;
281 return p->isOptimizerFlag_m;
285 p->isInOPALCyclMode_m =
true;
289 p->isInOPALTMode_m =
true;
293 p->isOptimizerFlag_m =
true;
297 return p->isInPrepState_m;
301 p->isInPrepState_m = state;
305 return p->hasPriorRun_m;
309 p->hasPriorRun_m = value;
313 return p->isRestart_m;
317 p->isRestart_m = value;
321 p->restartStep_m = s;
325 return p->restartStep_m;
329 return p->restartFn_m;
334 p->hasRestartFile_m =
true;
338 return p->hasRestartFile_m;
342 p->restart_dump_freq_m = N;
346 return p->restart_dump_freq_m;
350 p->openMode_m = openMode;
354 return p->openMode_m;
358 p->last_step_m = step;
362 return p->last_step_m;
366 return p->hasBunchAllocated_m;
370 p->hasBunchAllocated_m =
true;
382 return p->hasDataSinkAllocated_m;
387 p->hasDataSinkAllocated_m =
true;
391 return p->dataSink_m;
399 return p->maxPhases_m.begin();
403 return p->maxPhases_m.end();
407 return p->maxPhases_m.size();
411 p->energyEvolution_m.insert(std::make_pair(spos, ekin));
415 return p->energyEvolution_m.begin();
419 return p->energyEvolution_m.end();
449 p->gPhaseShift_m = shift;
454 return p->gPhaseShift_m;
466 return p->bg_m !=
nullptr;
470 for (ObjectDir::iterator i =
p->mainDirectory.begin();
471 i !=
p->mainDirectory.end(); ++i) {
481 if (oldObject !=
nullptr) {
483 "You cannot replace the object \"" +
name +
"\".");
485 p->mainDirectory.insert(
name, newObject);
494 if (oldObject !=
nullptr && oldObject != newObject) {
499 "\" is protected and can't be used to name an object.");
502 "You cannot replace the already defined object \""
512 while(i !=
p->tableDirectory.end()) {
516 const std::string &tableName = table->
getOpalName();
520 std::cerr << std::endl <<
"Erasing dependent table \""
521 << tableName <<
"\"." << std::endl;
532 for (ObjectDir::iterator i =
p->mainDirectory.begin();
533 i !=
p->mainDirectory.end(); ++i) {
534 (*i).second->replace(oldObject, newObject);
544 p->mainDirectory.insert(
name, newObject);
557 if (oldObject !=
nullptr) {
559 for (ObjectDir::iterator i =
p->mainDirectory.begin();
560 i !=
p->mainDirectory.end(); ++i) {
561 Object *child = &*i->second;
567 p->mainDirectory.erase(
name);
572 return p->mainDirectory.find(
name);
587 os << std::endl <<
"Object names matching the pattern \""
588 << pattern <<
"\":" << std::endl;
590 for (ObjectDir::const_iterator index =
p->mainDirectory.begin();
591 index !=
p->mainDirectory.end(); ++index) {
592 const std::string
name = (*index).first;
598 column +=
name.length();
603 }
while((column % 20) != 0);
611 if (column) os << std::endl;
616 std::vector<std::string> name_list;
617 for (ObjectDir::const_iterator index =
p->mainDirectory.begin();
618 index !=
p->mainDirectory.end(); ++index) {
619 const std::string
name = (*index).first;
620 name_list.push_back(
name);
627 p->tableDirectory.push_back(table);
632 i !=
p->tableDirectory.end();) {
634 if (*j == table)
p->tableDirectory.erase(j);
639 p->exprDirectory.insert(expr);
643 p->exprDirectory.erase(expr);
647 p->referenceMomentum = p0;
651 p->itsTitle_m = title;
663 return p->itsTitle_m;
675 std::string & fn =
p->inputFn_m;
676 int const pdot = fn.rfind(
".");
677 return fn.substr(0, pdot);
681 if (
p->outFiles_m.count(outfn) == 0) {
682 p->outFiles_m.insert(outfn);
685 "OpalData::checkAndAddOutputFileName",
686 "Duplicate file name for output, '" + outfn +
"', detected");
695 i !=
p->exprDirectory.end(); ++i) {
701 i !=
p->tableDirectory.end(); ++i) {
706 for (ObjectDir::iterator i =
p->mainDirectory.begin();
707 i !=
p->mainDirectory.end(); ++i) {
708 (*i).second->update();
717 std::map<std::string, std::string> udata;
719 for (
auto& uvar : uvars) {
723 udata[uvar] = std::to_string(variable->
getReal());
729 "Type of '" + uvar +
"' not supported. "
730 "Only support for REAL and STRING.");
737 std::vector<std::string> result;
739 for (ObjectDir::const_iterator index =
p->mainDirectory.begin();
740 index !=
p->mainDirectory.end(); ++index) {
741 std::string tmpName = (*index).first;
742 if (!tmpName.empty()) {
745 if (!tmpObject || tmpObject->
isBuiltin())
748 result.push_back(tmpName);
757 if (
p->problemSize_m.find(
name) !=
p->problemSize_m.end()) {
758 p->problemSize_m.insert(std::make_pair(
name, value));
760 p->problemSize_m[
name] = value;
765 return p->problemSize_m;
769 p->arguments_m.clear();
770 for (
int i = 0; i < argc; ++ i) {
771 p->arguments_m.push_back(argv[i]);
776 return p->arguments_m;
UniformCartesian< 3, double > Mesh_t
ParticleSpatialLayout< double, 3, Mesh_t > Layout_t
CenteredFieldLayout< 3, Mesh_t, Center_t > FieldLayout_t
#define MAX_NUM_INSTANCES
std::map< double, double > energyEvolution_t
std::pair< std::string, double > MaxPhasesT
Inform & endl(Inform &inf)
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.
std::list< Table * > tableDirectory
PartBunchBase< double, 3 > * bunch_m
energyEvolution_t energyEvolution_m
std::set< AttributeBase * > exprDirectory
std::list< Table * >::iterator tableIterator
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
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 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()
unsigned long long getMaxTrackSteps()
void storeInputFn(const std::string &fn)
store opals input filename
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
void setPartBunch(PartBunchBase< double, 3 > *p)
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
std::vector< std::string > getAllNames() const
Get a list of all objects.
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
PartBunchBase< double, 3 > * getPartBunch()
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.