#include "sys.hpp" // for libcwd #include "debug.hpp" // for libcwd #include "simelement.hpp" #include "simloop.hpp" #include "libcsim.hpp" #include "gslsingleton.h" SimElement::SimElement(SimLoop* _MainSimLoop, int _MacroTimeStep, SimElementType _type) :MainSimLoop(_MainSimLoop), MacroTimeStep(_MacroTimeStep), seType(_type), seTypeString(SimElementTypeStrings[seType]), IdNumber(0), active(true), dt(MainSimLoop->GetDeltaT()), rec(0), BinRec(0), SimTag(""), resetable(true) { /** @todo go back to passing SimLoop to every SimElement instead of using a global SimLoop. Better design. Because no restriction to a single SimLoop. Maybe we want to run two simulations in the same program? element can implement a addToSomLoop() method */ cout << "\n\n Obsolete!!!!!!!!!!!!!!!!! Use GlobalMainSimLoop instead!!\n\n\n"; DataDirectory = ""; if (MainSimLoop != 0) { cout << "Get Global Settings from MainSimLoop\n"; MainSimLoop->Hallo(); gslr = GslSingleton::GetGslSingleton().GetGslRng(); DataDirectory = MainSimLoop->GetDataDirectory(); } else cout << "ERROR: SimElement needs MainSimLoop\n\n"; } SimElement::SimElement(SimElementType _type) : seType(_type), active(true), seTypeString(SimElementTypeStrings[seType]), IdNumber(0), rec(0), BinRec(0), SimTag(""), resetable(true), MainSimLoop(0) { // cout << "SimElement: using GlobalMainSimLoop\n"; MainSimLoop = GetGlobalSimLoop(); if (MainSimLoop == 0) { cerr << "*******ERROR********ERROR**********ERROR**************\n"; cerr << "* routine: SimElement::SimElement: \n"; cerr << "* Global Main Sim Loop not initialized\n"; cerr << "* you need the following line in your main program\n"; cerr << "* before using SimElement objects\n"; cerr << "* SimLoop* MainSimLoop = InitLibCSim(); \n"; cerr << "************************************************************\n\n"; exit(1); } MacroTimeStep = MainSimLoop->GetMacroTimeStep(); dt=MainSimLoop->GetDeltaT(); gslr = GslSingleton::GetGslSingleton().GetGslRng(); DataDirectory = MainSimLoop->GetDataDirectory(); Dout(dc::element,"SimElement::SimElement: generate new SimElement"); Debug( libcw_do.inc_indent(2) ); Dout(dc::element,"DataDirectory = " << DataDirectory); Debug( libcw_do.dec_indent(2) ); } SimElement::~SimElement() { if (rec) delete rec; } int SimElement::proceede(int Time) { } int SimElement::prepare(int step) { if (BinRec) { if (step==0) BinRec->restart(SimTag); BinRec->WriteToFile(); } } void SimElement::SetResetable(bool value) { resetable=value; } bool SimElement::Resetable() { return resetable; } int SimElement::reset(int t) { } void SimElement::SetParameter(ParaType p, double value) { //cout <<"ParaType " << p << "not supported by SimElement " << seTypeString << "\n"; } int SimElement::GetMacroTimeStep() { return MacroTimeStep; } int SimElement::SetMacroTimeStep(int mst) { MacroTimeStep = mst; } float SimElement::GetDeltaT() { return dt; } void SimElement::Hallo() { Debug( libcw_do.inc_indent(2) ); Dout(dc::element, Name); Debug( libcw_do.dec_indent(2) ); } void SimElement::TurnOn() { active = true; } void SimElement::TurnOff() { active = false; } bool SimElement::On() { return active; } int SimElement::SaveSimInfo() { } int SimElement::WriteSimInfo(fstream &fw) { fw << "<" << seTypeString << " id=\"" << IdNumber << "\" Type=\"" << seType << "\" Name=\"" << Name << "\" /> \n"; } int SimElement::WriteSimInfo(fstream &fw, const string &ChildInfo) { fw << "<" << seTypeString << " id=\"" << IdNumber << "\" Type=\"" << seType << "\" Name=\"" << Name << "\"> \n"; fw << AddSpaces(ChildInfo); fw << " \n"; } string SimElement::GetSimInfo() { stringstream sstr; sstr << "<" << seTypeString << " id=\"" << IdNumber << "\" Type=\"" << seType << "\" Name=\"" << Name << "\"> \n"; sstr << " \n"; return sstr.str(); } string SimElement::GetSimInfo(const string &ChildInfo) { stringstream sstr; sstr << "<" << seTypeString << " id=\"" << IdNumber << "\" Type=\"" << seType << "\" Name=\"" << Name << "\"> \n"; sstr << AddSpaces(ChildInfo); sstr << " \n"; return sstr.str(); } void SimElement::SetName(const char* _name) { Name=_name; } void SimElement::SetDataDirectory(const char* _dirname) { DataDirectory = _dirname; } int SimElement::StartRecorder(char* RecName) { if (rec==0) { rec = new Recorder(RecName); } else cout << "Recorder allready running!!"; } void SimElement::SetSimTag(const char* _tag) { SimTag = _tag; } long SimElement::calcMemoryConsumption() { Dout(dc::element, "calcMemoryConsumption() not implemented for " << seTypeString); return 0; }