123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211 |
- #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 << "</" << seTypeString << "> \n";
-
- }
- string SimElement::GetSimInfo()
- {
- stringstream sstr;
- sstr << "<" << seTypeString << " id=\"" << IdNumber << "\" Type=\"" << seType << "\" Name=\"" << Name << "\"> \n";
- sstr << "</" << seTypeString << "> \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 << "</" << seTypeString << "> \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;
- }
|