OpalData.cpp 19.4 KB
Newer Older
gsell's avatar
gsell committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
// ------------------------------------------------------------------------
// $RCSfile: OpalData.cpp,v $
// ------------------------------------------------------------------------
// $Revision: 1.1.1.1.4.2 $
// ------------------------------------------------------------------------
// Copyright: see Copyright.readme
// ------------------------------------------------------------------------
//
// Class: OpalData
//   The global OPAL structure.
//   The OPAL object holds all global data required for a OPAL execution.
//
// ------------------------------------------------------------------------
//
// $Date: 2004/11/12 20:10:11 $
// $Author: adelmann $
//
// ------------------------------------------------------------------------

#include "AbstractObjects/OpalData.h"
21 22
#include "Structure/DataSink.h"
#include "Structure/BoundaryGeometry.h"
gsell's avatar
gsell committed
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
#include "AbstractObjects/Attribute.h"
#include "AbstractObjects/Directory.h"
#include "AbstractObjects/Object.h"
#include "AbstractObjects/ObjectFunction.h"
#include "AbstractObjects/Table.h"
#include "AbstractObjects/ValueDefinition.h"
#include "Utilities/OpalException.h"
#include "Utilities/Options.h"
#include "Utilities/RegularExpression.h"
#include <iostream>
#include <list>
#include <set>

// DTA
#include "AbstractObjects/Expressions.h"
#include "Attributes/Attributes.h"
#include "ValueDefinitions/RealVariable.h"
#include "ValueDefinitions/StringConstant.h"
#include "OpalParser/OpalParser.h"
#include "Parser/FileStream.h"
#include "Parser/StringStream.h"
44
#include "Algorithms/PartBunchBase.h"
gsell's avatar
gsell committed
45 46
// /DTA

47
#define MAX_NUM_INSTANCES 10
gsell's avatar
gsell committed
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
using namespace std;

// Class OpalData::ClearReference
// ------------------------------------------------------------------------

void OpalData::ClearReference::operator()(Object *object) const {
    object->clear();
}


// Struct OpalDataImpl.
// ------------------------------------------------------------------------

struct OpalDataImpl {
    OpalDataImpl();
    ~OpalDataImpl();

    // The main object directory.
    Directory mainDirectory;

    // The value of the global momentum.
    ValueDefinition *referenceMomentum;

    // The flag telling that something has changed.
    bool modified;

    // Directory of tables, for recalculation when something changes.
    std::list<Table *> tableDirectory;
    typedef std::list<Table *>::iterator tableIterator;

    // The set of expressions to be invalidated when something changes.
    std::set <AttributeBase *> exprDirectory;
    typedef std::set<AttributeBase *>::iterator exprIterator;

    // The page title from the latest TITLE command.
83 84 85
    std::string itsTitle_m;

    bool hasPriorRun_m;
gsell's avatar
gsell committed
86 87

    // true if we restart a simulation
88
    bool isRestart_m;
gsell's avatar
gsell committed
89 90

    // Input file name
91
    std::string inputFn_m;
gsell's avatar
gsell committed
92 93

    // Where to resume in a restart run
94
    int restartStep_m;
gsell's avatar
gsell committed
95 96

    // Where to resume in a restart run
97
    std::string restartFn_m;
gsell's avatar
gsell committed
98 99 100 101 102 103 104

    // true if the name of a restartFile is specified
    bool hasRestartFile_m;

    // dump frequency as found in restart file
    int restart_dump_freq_m;

105 106 107
    /// Mode for writing files
    OpalData::OPENMODE openMode_m = OpalData::OPENMODE::WRITE;

gsell's avatar
gsell committed
108 109 110 111 112
    // last step of a run
    int last_step_m;

    bool hasBunchAllocated_m;
    // The particle bunch to be tracked.
113
    PartBunchBase<double, 3> *bunch_m;
gsell's avatar
gsell committed
114

115 116
    bool hasDataSinkAllocated_m;

gsell's avatar
gsell committed
117 118 119 120 121 122 123
    DataSink *dataSink_m;

    // In units of seconds. This is half of tEmission
    double gPhaseShift_m;

    BoundaryGeometry *bg_m;

124
    std::vector<MaxPhasesT> maxPhases_m;
125
    energyEvolution_t energyEvolution_m;
126

127 128 129 130 131 132 133 134
    // The cartesian mesh
    Mesh_t *mesh_m;

    // The field layout f
    FieldLayout_t *FL_m;

    // The particle layout
    Layout_t *PL_m;
135 136

    // the accumulated (over all TRACKs) number of steps
137
    unsigned long long maxTrackSteps_m;
138 139 140

    bool isInOPALCyclMode_m;
    bool isInOPALTMode_m;
141
    bool isOptimizerFlag_m;
142
    bool isInPrepState_m;
143

adelmann's avatar
adelmann committed
144 145
    std::map<std::string, unsigned int> problemSize_m;

146
    std::vector<std::string> arguments_m;
gsell's avatar
gsell committed
147 148 149 150
};


OpalDataImpl::OpalDataImpl():
151
    mainDirectory(), referenceMomentum(0), modified(false), itsTitle_m(),
Christof Metzger-Kraus's avatar
Christof Metzger-Kraus committed
152 153
    hasPriorRun_m(false),
    isRestart_m(false),
snuverink_j's avatar
snuverink_j committed
154
    restartStep_m(0),
Christof Metzger-Kraus's avatar
Christof Metzger-Kraus committed
155
    hasRestartFile_m(false),
156
    restart_dump_freq_m(1), last_step_m(0),
Christof Metzger-Kraus's avatar
Christof Metzger-Kraus committed
157 158 159 160
    hasBunchAllocated_m(false),
    hasDataSinkAllocated_m(false),
    gPhaseShift_m(0.0),
    maxTrackSteps_m(0),
161 162
    isInOPALCyclMode_m(false),
    isInOPALTMode_m(false),
kraus's avatar
kraus committed
163
    isOptimizerFlag_m(false),
adelmann's avatar
adelmann committed
164
    isInPrepState_m(false)
165
{
166 167 168 169 170 171
    bunch_m    = nullptr;
    dataSink_m = nullptr;
    bg_m       = nullptr;
    mesh_m     = nullptr;
    FL_m       = nullptr;
    PL_m       = nullptr;
gsell's avatar
gsell committed
172 173 174 175 176
}

OpalDataImpl::~OpalDataImpl() {
    // Make sure the main directory is cleared before the directories
    // for tables and expressions are deleted.
177
    delete mesh_m;// somehow this needs to be deleted first
snuverink_j's avatar
snuverink_j committed
178
    delete FL_m;
179
    //delete PL_m; //this gets deleted by FL_m
180

181
    delete bunch_m;
ext-rogers_c's avatar
ext-rogers_c committed
182
    delete bg_m;
183 184
    delete dataSink_m;

ext-rogers_c's avatar
ext-rogers_c committed
185

gsell's avatar
gsell committed
186 187 188 189 190 191 192 193 194
    mainDirectory.erase();
    tableDirectory.clear();
    exprDirectory.clear();
}


// Class OpalData
// ------------------------------------------------------------------------

195
bool OpalData::isInstantiated = false;
196
OpalData *OpalData::instance = nullptr;
197
std::stack<OpalData*> OpalData::stashedInstances;
gsell's avatar
gsell committed
198 199

OpalData *OpalData::getInstance() {
200
    if(!isInstantiated) {
gsell's avatar
gsell committed
201
        instance = new OpalData();
202
        isInstantiated = true;
gsell's avatar
gsell committed
203 204 205 206 207 208 209 210
        return instance;
    } else {
        return instance;
    }
}

void OpalData::deleteInstance() {
    delete instance;
211
    instance = nullptr;
212 213 214 215 216 217 218 219 220 221
    isInstantiated = false;
}

void OpalData::stashInstance() {
    if (!isInstantiated) return;
    if (stashedInstances.size() + 1 > MAX_NUM_INSTANCES) {
        throw OpalException("OpalData::stashInstance()",
                            "too many OpalData instances stashed");
    }
    stashedInstances.push(instance);
222
    instance = nullptr;
223 224 225 226 227 228 229 230 231 232 233 234 235 236
    isInstantiated = false;
}

OpalData *OpalData::popInstance() {
    if (stashedInstances.size() == 0) {
        throw OpalException("OpalData::popInstance()",
                            "no OpalData instances stashed");
    }
    if (isInstantiated) deleteInstance();
    instance = stashedInstances.top();
    isInstantiated = true;
    stashedInstances.pop();

    return instance;
gsell's avatar
gsell committed
237 238
}

239
unsigned long long OpalData::getMaxTrackSteps() {
240
    return p->maxTrackSteps_m;
241 242 243
}

void OpalData::setMaxTrackSteps(unsigned long long s) {
244
    p->maxTrackSteps_m = s;
245 246
}

247
void OpalData::incMaxTrackSteps(unsigned long long s) {
248
    p->maxTrackSteps_m += s;
249 250 251
}


gsell's avatar
gsell committed
252 253 254 255 256 257 258 259 260 261 262
OpalData::OpalData() {
    p = new OpalDataImpl();
}

OpalData::~OpalData() {
    delete p;
}

void OpalData::reset() {
    delete p;
    p = new OpalDataImpl();
263 264
    p->hasPriorRun_m = false;
    p->isRestart_m = false;
gsell's avatar
gsell committed
265 266 267 268 269
    p->hasRestartFile_m = false;
    p->hasBunchAllocated_m = false;
    p->hasDataSinkAllocated_m = false;
    p->gPhaseShift_m = 0.0;
    p->maxPhases_m.clear();
270 271
    p->isInOPALCyclMode_m = false;
    p->isInOPALTMode_m = false;
272
    p->isInPrepState_m = false;
273
    p->isOptimizerFlag_m = false;
274 275 276
}

bool OpalData::isInOPALCyclMode() {
277
    return p->isInOPALCyclMode_m;
278 279 280
}

bool OpalData::isInOPALTMode() {
281
    return  p->isInOPALTMode_m;
282
}
283

284 285 286 287
bool OpalData::isOptimizerRun() {
    return p->isOptimizerFlag_m;
}

288
void OpalData::setInOPALCyclMode() {
289
    p->isInOPALCyclMode_m = true;
gsell's avatar
gsell committed
290 291
}

292
void OpalData::setInOPALTMode() {
293
    p->isInOPALTMode_m = true;
294
}
295

296 297 298 299
void OpalData::setOptimizerFlag() {
    p->isOptimizerFlag_m = true;
}

300 301 302 303 304 305 306 307 308 309 310 311 312 313
bool OpalData::isInPrepState() {
    return p->isInPrepState_m;
}

void OpalData::setInPrepState(bool state) {
    p->isInPrepState_m = state;
}

bool OpalData::hasPriorTrack() {
    return p->hasPriorRun_m;
}

void OpalData::setPriorTrack(const bool &value) {
    p->hasPriorRun_m = value;
314
}
315

gsell's avatar
gsell committed
316
bool OpalData::inRestartRun() {
317
    return p->isRestart_m;
gsell's avatar
gsell committed
318 319 320
}

void OpalData::setRestartRun(const bool &value) {
321
    p->isRestart_m = value;
gsell's avatar
gsell committed
322 323 324 325
}


void OpalData::setRestartStep(int s) {
326
    p->restartStep_m = s;
gsell's avatar
gsell committed
327 328 329
}

int OpalData::getRestartStep() {
330
    return p->restartStep_m;
gsell's avatar
gsell committed
331 332 333
}


334
std::string OpalData::getRestartFileName() {
335
    return p->restartFn_m;
gsell's avatar
gsell committed
336 337 338
}


339
void OpalData::setRestartFileName(std::string s) {
340
    p->restartFn_m = s;
gsell's avatar
gsell committed
341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356
    p->hasRestartFile_m = true;
}

bool OpalData::hasRestartFile() {
    return p->hasRestartFile_m;

}

void OpalData::setRestartDumpFreq(const int &N) {
    p->restart_dump_freq_m = N;
}

int OpalData::getRestartDumpFreq() const {
    return p->restart_dump_freq_m;
}

357 358 359 360 361 362 363 364
void OpalData::setOpenMode(OPENMODE openMode) {
    p->openMode_m = openMode;
}

OpalData::OPENMODE OpalData::getOpenMode() const {
    return p->openMode_m;
}

gsell's avatar
gsell committed
365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380
void OpalData::setLastStep(const int &step) {
    p->last_step_m = step;
}

int OpalData::getLastStep() const {
    return p->last_step_m;
}

bool OpalData::hasBunchAllocated() {
    return p->hasBunchAllocated_m;
}

void OpalData::bunchIsAllocated() {
    p->hasBunchAllocated_m = true;
}

381
void OpalData::setPartBunch(PartBunchBase<double, 3> *b) {
gsell's avatar
gsell committed
382 383 384
    p->bunch_m = b;
}

385
PartBunchBase<double, 3> *OpalData::getPartBunch() {
gsell's avatar
gsell committed
386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402
    return p->bunch_m;
}


bool OpalData::hasDataSinkAllocated() {
    return p->hasDataSinkAllocated_m;
}

void OpalData::setDataSink(DataSink *s) {
    p->dataSink_m = s;
    p->hasDataSinkAllocated_m = true;
}

DataSink *OpalData::getDataSink() {
    return p->dataSink_m;
}

403
void OpalData::setMaxPhase(std::string elName, double phi) {
gsell's avatar
gsell committed
404 405 406
    p->maxPhases_m.push_back(MaxPhasesT(elName, phi));
}

407
std::vector<MaxPhasesT>::iterator OpalData::getFirstMaxPhases() {
gsell's avatar
gsell committed
408 409 410
    return p->maxPhases_m.begin();
}

411
std::vector<MaxPhasesT>::iterator OpalData::getLastMaxPhases() {
gsell's avatar
gsell committed
412 413 414 415 416 417 418
    return p->maxPhases_m.end();
}

int OpalData::getNumberOfMaxPhases() {
    return p->maxPhases_m.size();
}

419 420 421 422 423 424 425 426 427 428 429 430
void OpalData::addEnergyData(double spos, double ekin) {
    p->energyEvolution_m.insert(std::make_pair(spos, ekin));
}

energyEvolution_t::iterator OpalData::getFirstEnergyData() {
    return p->energyEvolution_m.begin();
}

energyEvolution_t::iterator OpalData::getLastEnergyData() {
    return p->energyEvolution_m.end();
}

gsell's avatar
gsell committed
431

432
// Mesh_t* OpalData::getMesh() {
kraus's avatar
kraus committed
433
//  return p->mesh_m;
434
// }
435

436
// FieldLayout_t* OpalData::getFieldLayout() {
kraus's avatar
kraus committed
437
//  return p->FL_m;
438
// }
gsell's avatar
gsell committed
439

440
// Layout_t* OpalData::getLayout() {
kraus's avatar
kraus committed
441
//  return p->PL_m;
442
// }
gsell's avatar
gsell committed
443

444
// void OpalData::setMesh(Mesh_t *mesh) {
kraus's avatar
kraus committed
445
//  p->mesh_m = mesh;
446
// }
447

448
// void OpalData::setFieldLayout(FieldLayout_t *fieldlayout) {
kraus's avatar
kraus committed
449
//  p->FL_m = fieldlayout;
450
// }
451

452
// void OpalData::setLayout(Layout_t *layout) {
kraus's avatar
kraus committed
453
//  p->PL_m = layout;
454
// }
gsell's avatar
gsell committed
455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473

void OpalData::setGlobalPhaseShift(double shift) {
    /// units: (sec)
    p->gPhaseShift_m = shift;
}

double OpalData::getGlobalPhaseShift() {
    /// units: (sec)
    return p->gPhaseShift_m;
}

void   OpalData::setGlobalGeometry(BoundaryGeometry *bg) {
    p->bg_m = bg;
}

BoundaryGeometry *OpalData::getGlobalGeometry() {
    return p->bg_m;
}

474
bool OpalData::hasGlobalGeometry() {
475
    return p->bg_m != nullptr;
476 477 478 479
}



gsell's avatar
gsell committed
480 481 482 483 484 485 486 487 488 489
void OpalData::apply(const ObjectFunction &fun) {
    for(ObjectDir::iterator i = p->mainDirectory.begin();
        i != p->mainDirectory.end(); ++i) {
        fun(&*i->second);
    }
}


void OpalData::create(Object *newObject) {
    // Test for existing node with same name.
490
    const std::string name = newObject->getOpalName();
gsell's avatar
gsell committed
491 492
    Object *oldObject = p->mainDirectory.find(name);

493
    if(oldObject != nullptr) {
gsell's avatar
gsell committed
494 495 496 497 498 499 500 501 502 503
        throw OpalException("OpalData::create()",
                            "You cannot replace the object \"" + name + "\".");
    } else {
        p->mainDirectory.insert(name, newObject);
    }
}


void OpalData::define(Object *newObject) {
    // Test for existing node with same name.
504
    const std::string name = newObject->getOpalName();
gsell's avatar
gsell committed
505 506
    Object *oldObject = p->mainDirectory.find(name);

507
    if(oldObject != nullptr  &&  oldObject != newObject) {
gsell's avatar
gsell committed
508 509 510 511 512 513
        // Attempt to replace an object.
        if(oldObject->isBuiltin()  ||  ! oldObject->canReplaceBy(newObject)) {
            throw OpalException("OpalData::define()",
                                "You cannot replace the object \"" + name + "\".");
        } else {
            if(Options::info) {
514
                INFOMSG("Replacing the object \"" << name << "\"." << endl);
gsell's avatar
gsell committed
515 516 517 518 519 520 521 522
            }

            // Erase all tables which depend on the new object.
            OpalDataImpl::tableIterator i = p->tableDirectory.begin();
            while(i != p->tableDirectory.end()) {
                // We must increment i before calling erase(name),
                // since erase(name) removes "this" from "tables".
                Table *table = *i++;
523
                const std::string &tableName = table->getOpalName();
gsell's avatar
gsell committed
524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562

                if(table->isDependent(name)) {
                    if(Options::info) {
                        cerr << endl << "Erasing dependent table \"" << tableName
                             << "\"." << endl << endl;
                    }

                    // Remove table from directory.
                    // This erases the table from the main directory,
                    // and its destructor unregisters it from the table directory.
                    erase(tableName);
                }
            }

            // Replace all references to this object.
            for(ObjectDir::iterator i = p->mainDirectory.begin();
                i != p->mainDirectory.end(); ++i) {
                (*i).second->replace(oldObject, newObject);
            }

            // Remove old object.
            erase(name);
        }
    }

    // Force re-evaluation of expressions.
    p->modified = true;
    newObject->setDirty(true);
    p->mainDirectory.insert(name, newObject);

    // If this is a new definition of "P0", insert its definition.
    if(name == "P0") {
        if(ValueDefinition *p0 = dynamic_cast<ValueDefinition *>(newObject)) {
            setP0(p0);
        }
    }
}


563
void OpalData::erase(const std::string &name) {
gsell's avatar
gsell committed
564 565
    Object *oldObject = p->mainDirectory.find(name);

566
    if(oldObject != nullptr) {
gsell's avatar
gsell committed
567 568 569 570 571 572 573 574 575 576 577 578 579 580 581
        // Relink all children of "this" to "this->getParent()".
        for(ObjectDir::iterator i = p->mainDirectory.begin();
            i != p->mainDirectory.end(); ++i) {
            Object *child = &*i->second;
            if(child->getParent() == oldObject) {
                child->setParent(oldObject->getParent());
            }
        }

        // Remove the object.
        p->mainDirectory.erase(name);
    }
}


582
Object *OpalData::find(const std::string &name) {
gsell's avatar
gsell committed
583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598
    return p->mainDirectory.find(name);
}


double OpalData::getP0() const {
    static const double energy_scale = 1.0e+9;
    return p->referenceMomentum->getReal() * energy_scale;
}


void OpalData::makeDirty(Object *obj) {
    p->modified = true;
    if(obj) obj->setDirty(true);
}


599
void OpalData::printNames(std::ostream &os, const std::string &pattern) {
gsell's avatar
gsell committed
600 601 602 603 604 605
    int column = 0;
    RegularExpression regex(pattern);
    os << endl << "Object names matching the pattern \""
       << pattern << "\":" << endl;

    for(ObjectDir::const_iterator index = p->mainDirectory.begin();
snuverink_j's avatar
snuverink_j committed
606
        index != p->mainDirectory.end(); ++index) {
607
        const std::string name = (*index).first;
gsell's avatar
gsell committed
608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659

        if(! name.empty()  &&  regex.match(name)) {
            os << name;

            if(column < 80) {
                column += name.length();

                do {
                    os << ' ';
                    column++;
                } while((column % 20) != 0);
            } else {
                os << endl;
                column = 0;
            }
        }
    }

    if(column) os << endl;
    os << endl;
}


void OpalData::registerTable(Table *table) {
    p->tableDirectory.push_back(table);
}


void OpalData::unregisterTable(Table *table) {
    for(OpalDataImpl::tableIterator i = p->tableDirectory.begin();
        i != p->tableDirectory.end();) {
        OpalDataImpl::tableIterator j = i++;
        if(*j == table) p->tableDirectory.erase(j);
    }
}


void OpalData::registerExpression(AttributeBase *expr) {
    p->exprDirectory.insert(expr);
}


void OpalData::unregisterExpression(AttributeBase *expr) {
    p->exprDirectory.erase(expr);
}


void OpalData::setP0(ValueDefinition *p0) {
    p->referenceMomentum = p0;
}


660
void OpalData::storeTitle(const std::string &title) {
661
    p->itsTitle_m = title;
gsell's avatar
gsell committed
662 663
}

664
void OpalData::storeInputFn(const std::string &fn) {
665
    p->inputFn_m = fn;
gsell's avatar
gsell committed
666 667 668 669
}


void OpalData::printTitle(std::ostream &os) {
670
    os << p->itsTitle_m;
gsell's avatar
gsell committed
671 672
}

673
std::string OpalData::getTitle() {
674
    return p->itsTitle_m;
gsell's avatar
gsell committed
675 676
}

677
std::string OpalData::getInputFn() {
678
    return p->inputFn_m;
gsell's avatar
gsell committed
679 680
}

681
std::string OpalData::getInputBasename() {
682
    std::string & fn = p->inputFn_m;
683 684 685
    int const pdot = fn.rfind(".");
    return fn.substr(0, pdot);
}
gsell's avatar
gsell committed
686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712

void OpalData::update() {
    Inform msg("OpalData ");
    if(p->modified) {
        // Force re-evaluation of expressions.
        for(OpalDataImpl::exprIterator i = p->exprDirectory.begin();
            i != p->exprDirectory.end(); ++i) {
            (*i)->invalidate();
        }

        // Force refilling of dynamic tables.
        for(OpalDataImpl::tableIterator i = p->tableDirectory.begin();
            i != p->tableDirectory.end(); ++i) {
            (*i)->invalidate();
        }

        // Update all definitions.
        for(ObjectDir::iterator i = p->mainDirectory.begin();
            i != p->mainDirectory.end(); ++i) {
            (*i).second->update();
        }

        // Definitions are up-to-date.
        p->modified = false;
    }
}

713 714 715 716 717

std::map<std::string, std::string> OpalData::getVariableData() {
    std::map<std::string, std::string> udata;
    std::vector<std::string> uvars = this->getVariableNames();
    for (auto& uvar : uvars) {
718
        Object *tmpObject = OpalData::getInstance()->find(uvar);
frey_m's avatar
frey_m committed
719 720 721 722 723 724
        if (dynamic_cast<RealVariable*>(tmpObject)) {
            RealVariable* variable = dynamic_cast<RealVariable*>(OpalData::getInstance()->find(uvar));
            udata[uvar] = std::to_string(variable->getReal());
        } else if (dynamic_cast<StringConstant*>(tmpObject)) {
            StringConstant* variable = dynamic_cast<StringConstant*>(OpalData::getInstance()->find(uvar));
            udata[uvar] = variable->getString();
725 726 727 728 729
        } else {
            throw OpalException("OpalData::getVariableData()",
                                "Type of '" + uvar + "' not supported. "
                                "Only support for REAL and STRING.");
        }
730 731 732 733
    }
    return udata;
}

734 735 736 737 738 739 740 741
std::vector<std::string> OpalData::getVariableNames() {
    std::vector<std::string> result;

    for(ObjectDir::const_iterator index = p->mainDirectory.begin();
        index != p->mainDirectory.end(); ++index) {
        std::string tmpName = (*index).first;
        if (!tmpName.empty()) {
            Object *tmpObject = OpalData::getInstance()->find(tmpName);
frey_m's avatar
frey_m committed
742 743 744 745 746 747
            if (tmpObject) {
                if (!tmpObject || tmpObject->isBuiltin())
                    continue;
                if (tmpObject->getCategory() == "VARIABLE") {
                    result.push_back(tmpName);
                }
748 749 750 751 752 753
            }
        }
    }
    return result;
}

adelmann's avatar
adelmann committed
754 755 756 757 758 759 760 761 762 763 764 765
void OpalData::addProblemCharacteristicValue(const std::string &name, unsigned int value) {
    if (p->problemSize_m.find(name) != p->problemSize_m.end()) {
        p->problemSize_m.insert(std::make_pair(name, value));
    } else {
        p->problemSize_m[name] = value;
    }
}

const std::map<std::string, unsigned int> &OpalData::getProblemCharacteristicValues() const {
    return p->problemSize_m;
}

766 767 768 769 770 771 772 773 774 775
void OpalData::storeArguments(int argc, char *argv[]) {
    p->arguments_m.clear();
    for (int i = 0; i < argc; ++ i) {
        p->arguments_m.push_back(argv[i]);
    }
}

std::vector<std::string> OpalData::getArguments() {
    return p->arguments_m;
}