1414//
1515// =====================================================================================
1616
17- #include < stdexcept>
1817#include < memory>
18+ #include < stdexcept>
1919
20+ #include " ../external/pybind11/include/pybind11/functional.h"
21+ #include " ../external/pybind11/include/pybind11/numpy.h"
2022#include " ../external/pybind11/include/pybind11/pybind11.h"
2123#include " ../external/pybind11/include/pybind11/stl.h"
22- #include " ../external/pybind11/include/pybind11/numpy.h"
23- #include " ../external/pybind11/include/pybind11/functional.h"
2424
2525// See
2626// https://pybind11.readthedocs.io/en/stable/advanced/cast/stl.html#binding-stl-containers
2727// #include "../external/pybind11/include/pybind11/stl_bind.h"
2828
29- #include " ../basecode/header.h"
30- #include " ../basecode/global.h"
31- #include " ../basecode/Cinfo.h"
29+ #include " ../randnum/randnum.h"
3230
31+ #include " ../basecode/Cinfo.h"
32+ #include " ../builtins/Variable.h"
33+ #include " ../mpi/PostMaster.h"
34+ #include " ../scheduling/Clock.h"
35+ #include " ../shell/Neutral.h"
3336#include " ../shell/Shell.h"
3437#include " ../shell/Wildcard.h"
35- #include " ../shell/Neutral.h"
36-
37- #include " ../scheduling/Clock.h"
38- #include " ../mpi/PostMaster.h"
39-
40- #include " ../builtins/Variable.h"
41-
4238#include " ../utility/strutil.h"
4339
44- #include " helper.h"
4540#include " Finfo.h"
41+ #include " helper.h"
4642#include " pymoose.h"
4743
4844using namespace std ;
@@ -109,7 +105,8 @@ ObjId createIdFromPath(string path, string type, unsigned int numData)
109105 if (pos != string::npos) {
110106 name = trimmed_path.substr (pos + 1 );
111107 parent_path = trimmed_path.substr (0 , pos);
112- } else {
108+ }
109+ else {
113110 name = trimmed_path;
114111 }
115112 // handle relative path
@@ -119,7 +116,8 @@ ObjId createIdFromPath(string path, string type, unsigned int numData)
119116 parent_path = current_path + " /" + parent_path;
120117 else
121118 parent_path = current_path + parent_path;
122- } else if (parent_path.empty ())
119+ }
120+ else if (parent_path.empty ())
123121 parent_path = " /" ;
124122
125123 ObjId parent_id (parent_path);
@@ -168,7 +166,8 @@ ObjId loadModelInternal(const string& fname, const string& modelpath,
168166 Id model;
169167 if (solverclass.empty ()) {
170168 model = getShellPtr ()->doLoadModel (fname, modelpath);
171- } else {
169+ }
170+ else {
172171 model = getShellPtr ()->doLoadModel (fname, modelpath, solverclass);
173172 }
174173
@@ -205,8 +204,8 @@ ObjId getElementFieldItem(const ObjId& objid, const string& fname,
205204 index += len;
206205 }
207206 if (index < 0 ) {
208- throw runtime_error (" ElementField.getItem: invalid index: " +
209- to_string (index) + " ." );
207+ throw runtime_error (
208+ " ElementField.getItem: invalid index: " + to_string (index) + " ." );
210209 return ObjId ();
211210 }
212211 return ObjId (oid.id , oid.dataIndex , index);
@@ -230,20 +229,14 @@ ObjId shellConnect(const ObjId& src, const string& srcField, const ObjId& tgt,
230229// // return src.connect(srcField, tgt, tgtField, msgType);
231230// }
232231
233- bool mooseDelete (const ObjId& oid)
234- {
235- return getShellPtr ()->doDelete (oid);
236- }
232+ bool mooseDelete (const ObjId& oid) { return getShellPtr ()->doDelete (oid); }
237233
238234bool mooseDelete (const string& path)
239235{
240236 return getShellPtr ()->doDelete (ObjId (path));
241237}
242238
243- void mooseMoveId (const Id& a, const ObjId& b)
244- {
245- getShellPtr ()->doMove (a, b);
246- }
239+ void mooseMoveId (const Id& a, const ObjId& b) { getShellPtr ()->doMove (a, b); }
247240
248241void mooseMoveObjId (const ObjId& a, const ObjId& b)
249242{
@@ -254,7 +247,7 @@ ObjId mooseCreate(const string type, const string& path, unsigned int numdata)
254247{
255248 auto newpath = moose::normalizePath (path);
256249 auto p = moose::splitPath (newpath);
257- if ( ! mooseExists (p.first ))
250+ if (! mooseExists (p.first ))
258251 throw runtime_error (" Parent path " + p.first + " does not exists." );
259252 return getShellPtr ()->doCreate2 (type, ObjId (p.first ), p.second , numdata);
260253}
@@ -276,10 +269,7 @@ void mooseUseClock(size_t tick, const string& path, const string& field)
276269 * @Returns cwe.
277270 */
278271/* ----------------------------------------------------------------------------*/
279- py::object mooseGetCwe ()
280- {
281- return py::cast (getShellPtr ()->getCwe ());
282- }
272+ py::object mooseGetCwe () { return py::cast (getShellPtr ()->getCwe ()); }
283273
284274map<string, string> mooseGetFieldDict (const string& className,
285275 const string& finfoType = " " )
@@ -304,28 +294,33 @@ map<string, string> mooseGetFieldDict(const string& className,
304294 auto * finfo = cinfo->getValueFinfo (ii);
305295 fieldDict[finfo->name ()] = finfo->rttiType ();
306296 }
307- } else if (finfoType == " srcFinfo" || finfoType == " src" ) {
297+ }
298+ else if (finfoType == " srcFinfo" || finfoType == " src" ) {
308299 for (unsigned int ii = 0 ; ii < cinfo->getNumSrcFinfo (); ++ii) {
309300 auto * finfo = cinfo->getSrcFinfo (ii);
310301 fieldDict[finfo->name ()] = finfo->rttiType ();
311302 }
312- } else if (finfoType == " destFinfo" || finfoType == " dest" ) {
303+ }
304+ else if (finfoType == " destFinfo" || finfoType == " dest" ) {
313305 for (unsigned int ii = 0 ; ii < cinfo->getNumDestFinfo (); ++ii) {
314306 auto * finfo = cinfo->getDestFinfo (ii);
315307 fieldDict[finfo->name ()] = finfo->rttiType ();
316308 }
317- } else if (finfoType == " lookupFinfo" || finfoType == " lookup" ) {
309+ }
310+ else if (finfoType == " lookupFinfo" || finfoType == " lookup" ) {
318311 for (unsigned int ii = 0 ; ii < cinfo->getNumLookupFinfo (); ++ii) {
319312 auto * finfo = cinfo->getLookupFinfo (ii);
320313 fieldDict[finfo->name ()] = finfo->rttiType ();
321314 }
322- } else if (finfoType == " sharedFinfo" || finfoType == " shared" ) {
315+ }
316+ else if (finfoType == " sharedFinfo" || finfoType == " shared" ) {
323317 for (unsigned int ii = 0 ; ii < cinfo->getNumSrcFinfo (); ++ii) {
324318 auto * finfo = cinfo->getSrcFinfo (ii);
325319 fieldDict[finfo->name ()] = finfo->rttiType ();
326320 }
327- } else if (finfoType == " fieldElementFinfo" || finfoType == " field" ||
328- finfoType == " fieldElement" ) {
321+ }
322+ else if (finfoType == " fieldElementFinfo" || finfoType == " field" ||
323+ finfoType == " fieldElement" ) {
329324 for (unsigned int ii = 0 ; ii < cinfo->getNumFieldElementFinfo (); ++ii) {
330325 auto * finfo = cinfo->getFieldElementFinfo (ii);
331326 fieldDict[finfo->name ()] = finfo->rttiType ();
@@ -334,10 +329,7 @@ map<string, string> mooseGetFieldDict(const string& className,
334329 return fieldDict;
335330}
336331
337- void mooseReinit ()
338- {
339- getShellPtr ()->doReinit ();
340- }
332+ void mooseReinit () { getShellPtr ()->doReinit (); }
341333
342334void mooseStart (double runtime, bool notify = false )
343335{
@@ -353,3 +345,53 @@ ObjId mooseCopy(const py::object& elem, ObjId newParent, string newName,
353345 copyExtMsgs));
354346}
355347
348+ /* *
349+ Return a vector of field names of specified finfo type. This is from Subha.
350+ */
351+ vector<string> mooseGetFieldNames (string className, string finfoType)
352+ {
353+ vector<string> ret;
354+ const Cinfo* cinfo = Cinfo::find (className);
355+ if (cinfo == NULL ) {
356+ cerr << " Invalid class name." << endl;
357+ return ret;
358+ }
359+
360+ if (finfoType == " valueFinfo" || finfoType == " value" ) {
361+ for (unsigned int ii = 0 ; ii < cinfo->getNumValueFinfo (); ++ii) {
362+ Finfo* finfo = cinfo->getValueFinfo (ii);
363+ ret.push_back (finfo->name ());
364+ }
365+ }
366+ else if (finfoType == " srcFinfo" || finfoType == " src" ) {
367+ for (unsigned int ii = 0 ; ii < cinfo->getNumSrcFinfo (); ++ii) {
368+ Finfo* finfo = cinfo->getSrcFinfo (ii);
369+ ret.push_back (finfo->name ());
370+ }
371+ }
372+ else if (finfoType == " destFinfo" || finfoType == " dest" ) {
373+ for (unsigned int ii = 0 ; ii < cinfo->getNumDestFinfo (); ++ii) {
374+ Finfo* finfo = cinfo->getDestFinfo (ii);
375+ ret.push_back (finfo->name ());
376+ }
377+ }
378+ else if (finfoType == " lookupFinfo" || finfoType == " lookup" ) {
379+ for (unsigned int ii = 0 ; ii < cinfo->getNumLookupFinfo (); ++ii) {
380+ Finfo* finfo = cinfo->getLookupFinfo (ii);
381+ ret.push_back (finfo->name ());
382+ }
383+ }
384+ else if (finfoType == " sharedFinfo" || finfoType == " shared" ) {
385+ for (unsigned int ii = 0 ; ii < cinfo->getNumSrcFinfo (); ++ii) {
386+ Finfo* finfo = cinfo->getSrcFinfo (ii);
387+ ret.push_back (finfo->name ());
388+ }
389+ }
390+ else if (finfoType == " fieldElementFinfo" || finfoType == " fieldElement" ) {
391+ for (unsigned int ii = 0 ; ii < cinfo->getNumFieldElementFinfo (); ++ii) {
392+ Finfo* finfo = cinfo->getFieldElementFinfo (ii);
393+ ret.push_back (finfo->name ());
394+ }
395+ }
396+ return ret;
397+ }
0 commit comments