29 #include "../scheduling/Clock.h"
54 "Flag: Checks if simulation is in progress",
59 "Current working Element",
66 static DestFinfo handleUseClock(
"useClock",
67 "Deals with assignment of path to a given clock."
68 " Arguments: path, field, tick number. ",
73 "create( class, parent, newElm, name, numData, isGlobal )",
77 "When applied to a regular object, this function operates "
78 "on the Id (element) specified by the ObjId argument. "
79 "The function deletes the entire object "
80 "array on this Id, including all dataEntries on it,"
81 "all its messages, and all its children. The DataIndex here "
82 "is ignored, and all dataEntries are destroyed. \n"
83 "When applied to a message: Destroys only that one specific "
84 "message identified by the full ObjId. \n"
89 "Makes a msg. Arguments are:"
90 " msgtype, src object, src field, dest object, dest field",
94 "Stops simulation running and quits the simulator",
97 "handleMove( Id orig, Id newParent ): "
98 "moves an Element to a new parent",
101 "handleCopy( vector< Id > args, string newName, unsigned int nCopies, bool toGlobal, bool copyExtMsgs ): "
102 " The vector< Id > has Id orig, Id newParent, Id newElm. "
103 "This function copies an Element and all its children to a new parent."
104 " May also expand out the original into nCopies copies."
105 " Normally all messages within the copy tree are also copied. "
106 " If the flag copyExtMsgs is true, then all msgs going out are also copied.",
107 new EpFunc5<
Shell, vector< ObjId >,
string,
unsigned int,
bool,
bool >(
111 "Assigns clock ticks. Args: tick#, dt",
114 static Finfo* shellFinfos[] =
136 sizeof( shellFinfos ) /
sizeof(
Finfo* ),
142 float time = (float(clock() - t)/CLOCKS_PER_SEC);
155 numGetVecReturns_( 0 ),
182 unsigned int numData,
184 unsigned int preferredNode )
191 ss <<
"Shell::doCreate: bad character in name'" << name <<
192 "'. No Element created";
202 ss <<
"Shell::doCreate: Cannot create an object of class '" <<
203 type <<
"' because it is an abstract base class or a FieldElement.\n";
211 ss <<
"Shell::doCreate: Parent Element'" << parent <<
"' not found. No Element created";
223 ss <<
"Object with same path already present : " << parent.
path()
230 NodeBalance nb( numData, nodePolicy, preferredNode );
252 ss <<
"Shell::doCreate: Class '" << type <<
"' not known. No Element created";
270 ObjId src,
const string& srcField,
271 ObjId dest,
const string& destField )
276 cout <<
myNode_ <<
": Error: Shell::doAddMsg: src not found" << endl;
281 cout <<
myNode_ <<
": Error: Shell::doAddMsg: dest not found" << endl;
287 cout <<
myNode_ <<
": Shell::doAddMsg: Error: Failed to find field " << srcField <<
294 cout <<
myNode_ <<
": Shell::doAddMsg: Error: Failed to find field " << destField <<
296 cout <<
"Available fields are : " << endl
303 cout <<
myNode_ <<
": Shell::doAddMsg: Error: Src/Dest Msg type mismatch: " << srcField <<
"/" << destField << endl;
307 const Msg* m =
innerAddMsg( msgType, src, srcField, dest, destField, 0 );
342 vector< ObjId > streamers;
345 for( vector<ObjId>::const_iterator itr = streamers.begin()
346 ; itr != streamers.end(); itr++ )
355 static Id clockId( 1 );
356 assert( clockId.
element() != 0 );
358 return ( reinterpret_cast< const Clock* >(
359 clockId.
eref().
data() ) )->isDoingReinit();
386 "useClock", path, field, tick, msgIndex );
394 cout <<
"Error: Shell::doMove: Cannot move root Element\n";
398 if ( newParent.
element() == 0 )
400 cout <<
"Error: Shell::doMove: Cannot move object to null parent \n";
405 cout <<
"Error: Shell::doMove: Cannot move object to descendant in tree\n";
413 ss <<
"Shell::doMove: Object with same name already present: '"
414 << newParent.
path() <<
"/" << name <<
"'. Move failed.";
425 vector< unsigned int > open;
426 vector< unsigned int > close;
429 if ( s.length() == 0 )
435 for (
unsigned int i = 0; i < s.length(); ++i )
438 open.push_back( i+1 );
439 else if ( s[i] ==
']' )
440 close.push_back( i );
443 if ( open.size() != close.size() )
445 if ( open.size() == 0 )
447 int j = atoi( s.c_str() + open[0] );
470 if ( path.length() == 0 )
475 if ( path[0] == separator )
478 if ( path.length() == 1 )
480 temp = temp.substr( 1 );
483 string::size_type pos = temp.find_first_of( separator );
484 ret.push_back( temp.substr( 0, pos ) );
485 while ( pos != string::npos )
487 temp = temp.substr( pos + 1 );
488 if ( temp.length() == 0 )
490 pos = temp.find_first_of( separator );
491 ret.push_back( temp.substr( 0, pos ) );
501 return ( name.length() > 0 &&
502 name.find_first_of(
"[] #?\"/\\" ) == string::npos );
513 vector< unsigned int >& index )
515 bool isAbsolute =
chopString( path, ret,
'/' );
524 for (
unsigned int i = 0; i < ret.size(); ++i )
526 index.push_back( 0 );
529 if ( ret[i] ==
".." )
535 cout <<
"Error: Shell::chopPath: Failed to parse indices in path '" <<
541 size_t pos = ret[i].find_first_of(
'[' );
542 if ( ret[i].find_first_of(
'[' ) != string::npos )
543 ret[i] = ret[i].substr( 0, pos );
551 if ( path ==
"/" || path ==
"/root" )
555 vector< string > names;
556 vector< unsigned int > indices;
557 bool isAbsolute =
chopPath( path, names, indices );
558 assert( names.size() == indices.size() );
563 for (
unsigned int i = 0; i < names.size(); ++i )
565 if ( names[i] ==
"." )
568 else if ( names[i] ==
".." )
576 if ( curr ==
ObjId() )
622 static Id clockId( 1 );
623 assert( clockId.
element() != 0 );
625 return ( reinterpret_cast< const Clock* >( clockId.
eref().
data() ) )->isRunning();
642 innerCreate( type, parent, newElm, name, nb, parentMsgIndex );
661 assert( !( child.
element() == 0 ) );
662 assert( !( child ==
Id() ) );
663 assert( !( parent.
element() == 0 ) );
672 cout <<
"move: Error: unable to add parent->child msg from " <<
683 return adopt(
ObjId( parent ), child, msgIndex );
707 cout <<
"Error: Shell::innerCreate: Yet to implement SingleNodeDataElement. Making BlockBalance.\n";
713 adopt( parent, newElm, msgIndex );
739 string msgType,
ObjId src,
string srcField,
740 ObjId dest,
string destField,
unsigned int msgIndex )
744 innerAddMsg( msgType, src, srcField, dest, destField, msgIndex );
760 ObjId src,
string srcField,
761 ObjId dest,
string destField,
unsigned int msgIndex )
770 if ( f1 == 0 )
return 0;
772 if ( f2 == 0 )
return 0;
778 if ( msgType ==
"diagonal" || msgType ==
"Diagonal" )
783 else if ( msgType ==
"sparse" || msgType ==
"Sparse" )
787 else if ( msgType ==
"Single" || msgType ==
"single" )
791 else if ( msgType ==
"OneToAll" || msgType ==
"oneToAll" )
795 else if ( msgType ==
"AllToOne" || msgType ==
"allToOne" )
799 else if ( msgType ==
"OneToOne" || msgType ==
"oneToOne" )
806 ": Error: Shell::handleAddMsg: msgType not known: "
820 ": Error: Shell::handleAddMsg: Unable to make/connect Msg: "
833 assert( !( orig ==
Id() ) );
834 assert( !( newParent.
element() == 0 ) );
843 cout <<
"move: Error: unable to add parent->child msg from " <<
864 vector< ObjId >& msgs )
869 for ( vector< Finfo* >::const_iterator j =
870 sf->
dest().begin(); j != sf->
dest().end(); ++j )
876 vector< ObjId > caller;
879 msgs.insert( msgs.end(), caller.begin(), caller.end() );
887 const vector< ObjId >& list,
const string& field )
889 vector< ObjId > msgs;
890 for ( vector< ObjId >::const_iterator
891 i = list.begin(); i != list.end(); ++i )
896 const Finfo* f = i->element()->cinfo()->findFinfo( field );
903 vector< ObjId > caller;
904 if ( i->element()->getInputMsgs( caller, fid ) > 0 )
906 msgs.insert( msgs.end(), caller.begin(), caller.end() );
916 sort( msgs.begin(), msgs.end() );
917 msgs.erase( unique( msgs.begin(), msgs.end() ), msgs.end() );
919 for( vector< ObjId >::iterator i = msgs.begin(); i != msgs.end(); ++i )
925 const vector< ObjId >& list,
const string& field,
unsigned int tick,
926 unsigned int msgIndex )
928 if ( !
Id( 1 ).element() )
932 for ( vector< ObjId >::const_iterator i = list.begin();
933 i != list.end(); ++i )
938 ss <<
"proc" << tick;
941 *i, field, msgIndex++ );
943 i->element()->innerSetTick( tick );
949 unsigned int msgIndex )
951 vector< ObjId > list;
953 if ( list.size() == 0 )
960 if ( field.substr( 0, 4 ) ==
"proc" || field.substr( 0, 4 ) ==
"Proc" )
962 if ( field.substr( 0, 4 ) ==
"init" || field.substr( 0, 4 ) ==
"Init" )
966 for ( vector< ObjId >::iterator
967 i = list.begin(); i != list.end(); ++i )
968 i->id.element()->innerSetTick( tick );
973 string path,
string field,
unsigned int tick,
unsigned int msgIndex )
1008 cout <<
"Error: Shell:: " << text << endl;
1021 for ( vector< Id >::iterator i = kids.begin(); i != kids.end(); ++i )
1023 if ( i->value() > 4 )
1026 ,
"Shell::cleanSimulation: deleted cruft at " <<
1027 i->value() <<
": " << i->path());
int wildcardFind(const string &path, vector< ObjId > &ret)
void doStart(double runtime, bool notify=false)
static unsigned int myNode_
void handleCreate(const Eref &e, string type, ObjId parent, Id newElm, string name, NodeBalance nb, unsigned int parentMsgIndex)
void cleanUp(void)
This function is called from Shell when simulation is called to write the left-over data to streamer ...
static ObjId parent(const Eref &e)
static bool chopString(const string &path, vector< string > &ret, char separator= '/')
static bool set(const ObjId &dest, const string &field, L index, A arg)
void addClockMsgs(const vector< ObjId > &list, const string &field, unsigned int tick, unsigned int msgIndex)
Element * element() const
Synonym for Id::operator()()
void warning(const string &text)
const Msg * innerAddMsg(string msgType, ObjId src, string srcField, ObjId dest, string destField, unsigned int msgIndex)
static bool isParserIdle_
void doSetClock(unsigned int tickNum, double dt)
static void cleanSimulation()
Clean-up MOOSE before shutting down. This function is called whenever keyboard interrupt terminates t...
void handleUseClock(const Eref &e, string path, string field, unsigned int tick, unsigned int msgIndex)
static unsigned int numAcks_
void handleMove(const Eref &e, Id orig, ObjId newParent)
static const Cinfo * shellCinfo
const vector< Finfo * > & dest() const
static bool set(const ObjId &dest, const string &field, A1 arg1, A2 arg2, A3 arg3, A4 arg4, A5 arg5, A6 arg6)
static const Cinfo * find(const std::string &name)
bool innerUseClock(string path, string field, unsigned int tick, unsigned int msgIndex)
static Id child(const Eref &e, const string &name)
static const unsigned int OkStatus
const map< string, Finfo * > & finfoMap() const
ObjId cwe_
Current working Element.
static void children(const Eref &e, vector< Id > &ret)
ObjId doFind(const string &path) const
Id doCreate(string type, ObjId parent, string name, unsigned int numData, NodePolicy nodePolicy=MooseBlockBalance, unsigned int preferredNode=1)
static unsigned int numNodes_
void handleCopy(const Eref &e, vector< ObjId > args, string newName, unsigned int n, bool toGlobal, bool copyExtMsgs)
static bool isBlockedOnParser_
static const Cinfo * initCinfo()
void setShellElement(Element *shelle)
vector< double * > getBuf_
const std::string & name() const
bool innerMove(Id orig, ObjId newParent)
static bool isDescendant(Id me, Id ancestor)
virtual bool checkTarget(const Finfo *target) const
static void deleteMsg(ObjId mid)
ObjId findCaller(FuncId fid) const
virtual bool addMsg(const Finfo *target, ObjId mid, Element *src) const
static bool set(const ObjId &dest, const string &field, A1 arg1, A2 arg2, A3 arg3, A4 arg4)
static bool keepLooping()
virtual bool hasFields() const =0
static unsigned int numCores_
static unsigned int lookupDefaultTick(const string &className)
const Cinfo * cinfo() const
virtual unsigned int numData() const =0
Returns number of data entries across all nodes.
void destroy(const Eref &e, ObjId oid)
static bool set(const ObjId &dest, const string &field)
void insertSharedMsgs(const Finfo *f, const Element *e, vector< ObjId > &msgs)
unsigned int getInputMsgs(vector< ObjId > &caller, FuncId fid) const
Element * element() const
bool extractIndex(const string &s, unsigned int &index)
void destroy(const Eref &e, int stage)
static bool chopPath(const string &path, vector< string > &ret, vector< unsigned int > &index)
#define LOG(t, a)
This macro only expands when not compiling for release.
static void dropClockMsgs(const vector< ObjId > &list, const string &field)
ObjId doAddMsg(const string &msgType, ObjId src, const string &srcField, ObjId dest, const string &destField)
void error(const string &text)
static bool set(const ObjId &dest, const string &field, A arg)
static bool adopt(ObjId parent, Id child, unsigned int msgIndex)
static const unsigned int ErrorStatus
vector< float > initializationTime
static unsigned int myNode()
void doUseClock(string path, string field, unsigned int tick)
static vector< unsigned int > acked_
void innerCreate(string type, ObjId parent, Id newElm, string name, const NodeBalance &nb, unsigned int parentMsgIndex)
static const Cinfo * initCinfo()
void showWarn(string msg)
const string & getName() const
const unsigned int BADINDEX
Used by ObjId and Eref.
void handleQuit()
This function is NOT called when simulation ends normally.
static unsigned int numMsg()
Assign the first DataId.
static bool isNameValid(const string &name)
const Finfo * findFinfo(const string &name) const
void handleAddMsg(const Eref &e, string msgType, ObjId src, string srcField, ObjId dest, string destField, unsigned int msgIndex)
static bool set(const ObjId &dest, const string &field, A1 arg1, A2 arg2)
void doMove(Id orig, ObjId newParent)