@@ -22,12 +22,9 @@ namespace py = pybind11;
2222
2323MooseVec::MooseVec (const string& path, unsigned int n = 0 ,
2424 const string& dtype = " Neutral" )
25- : path_(path), useDataIndex_( false )
25+ : path_(path)
2626{
27- if (! mooseExists (path))
28- oid_ = mooseCreateFromPath (dtype, path, n);
29- else
30- oid_ = ObjId (path);
27+ oid_ = ObjId (path);
3128}
3229
3330MooseVec::MooseVec (const ObjId& oid) : oid_(oid), path_(oid.path())
@@ -100,14 +97,44 @@ void MooseVec::setAttrOneToOne(const string& name, const py::sequence& val)
10097 setFieldGeneric (getItem (i), name, val[i]);
10198}
10299
103- vector<py::object> MooseVec::getAttr (const string& name)
100+ vector<py::object> MooseVec::getAttribute (const string& name)
104101{
105102 vector<py::object> res (size ());
106103 for (unsigned int i = 0 ; i < size (); i++)
107104 res[i] = getFieldGeneric (getItem (i), name);
108105 return res;
109106}
110107
108+ // FIXME: Only double is supported here. Not sure if this is enough.
109+ py::array_t <double > MooseVec::getAttributeNumpy (const string &name)
110+ {
111+ auto cinfo = oid_.element ()->cinfo ();
112+ auto finfo = cinfo->findFinfo (name);
113+
114+ if (!finfo) {
115+ throw py::key_error (name + " is not found on '" + oid_.path () + " '." );
116+ }
117+
118+ string finfoType = cinfo->getFinfoType (finfo);
119+
120+ // Either return a simple value (ValueFinfo), list, dict or DestFinfo
121+ // setter.
122+ // The DestFinfo setter is a function.
123+
124+ vector<double > res (size ());
125+ if (finfoType == " ValueFinfo" ) {
126+ for (unsigned int i = 0 ; i < size (); i++)
127+ res[i] = getField<double >(getItem (i), name);
128+ return py::array_t <double >(res.size (), res.data ());
129+ }
130+
131+ throw runtime_error (" getAttributeNumpy::NotImplemented : " + name +
132+ " with rttType " + finfo->rttiType () + " and type: '" +
133+ finfoType + " '" );
134+ return py::array_t <double >();
135+ }
136+
137+
111138ObjId MooseVec::connectToSingle (const string& srcfield, const ObjId& tgt,
112139 const string& tgtfield, const string& msgtype)
113140{
@@ -144,11 +171,11 @@ size_t MooseVec::id() const
144171
145172void MooseVec::generateIterator ()
146173{
147- iterator_ .resize (size ());
148- for (size_t i = 0 ; i < size (); i++) iterator_ [i] = getItem (i);
174+ objs_ .resize (size ());
175+ for (size_t i = 0 ; i < size (); i++) objs_ [i] = getItem (i);
149176}
150177
151178const vector<ObjId>& MooseVec::objref () const
152179{
153- return iterator_ ;
180+ return objs_ ;
154181}
0 commit comments