Skip to content

Commit f0ac785

Browse files
author
Dilawar Singh
committed
LookupField is a function.
1 parent aee928e commit f0ac785

File tree

2 files changed

+29
-14
lines changed

2 files changed

+29
-14
lines changed

pybind11/pymoose.cpp

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -111,17 +111,34 @@ py::object getValueFinfo(const ObjId& oid, const string& fname, const string& rt
111111
return r;
112112
}
113113

114-
py::object getElementFinfo(const ObjId& objid, const string& fname, const size_t i)
114+
inline ObjId getElementFinfoItem(const ObjId& oid, const size_t& i)
115+
{
116+
return ObjId(oid.path(), oid.dataIndex, i);
117+
}
118+
119+
py::list getElementFinfo(const ObjId& objid, const string& fname)
115120
{
116121
auto oid = ObjId(objid.path() + '/' + fname);
117122
auto len = Field<unsigned int>::get(oid, "numField");
118-
assert(len >= 0);
119-
return py::cast(ObjId(oid.path(), oid.dataIndex, i));
123+
vector<ObjId> res(len);
124+
for(size_t i = 0; i < len; i++)
125+
res[i] = ObjId(oid.path(), oid.dataIndex, i);
126+
return py::cast(res);
127+
}
128+
129+
py::object getLookupValueFinfoItem(const ObjId& oid, const string& fname, const string& k)
130+
{
131+
py::object r;
132+
r = py::cast(LookupField<string, bool>::get(oid, fname, k));
133+
return r;
120134
}
121135

122-
py::object getLookValueFinfo(const ObjId& oid, const string& fname, const string& key)
136+
py::object getLookupValueFinfo(const ObjId& oid, const string& fname)
123137
{
124-
return py::cast(LookupField<string, bool>::get(oid, fname, key));
138+
std::function<py::object(const string&)> f = [oid, fname](const string& key) {
139+
return getLookupValueFinfoItem(oid, fname, key);
140+
};
141+
return py::cast(f);
125142
}
126143

127144
py::object getProperty(const ObjId& oid, const string& fname)
@@ -138,18 +155,15 @@ py::object getProperty(const ObjId& oid, const string& fname)
138155
string finfoType = cinfo->getFinfoType(finfo);
139156

140157
if(finfoType == "ValueFinfo")
158+
// return value.
141159
return getValueFinfo(oid, fname, rttType);
142160
else if(finfoType == "FieldElementFinfo") {
143-
std::function<py::object(size_t)> f = [oid, fname](const size_t& i) {
144-
return getElementFinfo(oid, fname, i);
145-
};
146-
return py::cast(f);
161+
// Return list.
162+
return getElementFinfo(oid, fname);
147163
}
148164
else if(finfoType == "LookupValueFinfo") {
149-
std::function<py::object(const string&)> f = [oid, fname](const string& k) {
150-
return getLookValueFinfo(oid, fname, k);
151-
};
152-
return py::cast(f);
165+
// Return function.
166+
return getLookupValueFinfo(oid, fname);
153167
}
154168

155169
cout << "Searching for " << fname << " with rttType "

tests/pybind11/test_shell.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,8 @@ def test_ksolve3():
335335
a = moose.Neutral('x')
336336
a = moose.Neutral('x/x')
337337
print(a.isA)
338-
print(a.isA['Compartment'])
338+
print(a.isA('Compartment'))
339+
#print(a.isA['Compartment'])
339340

340341
def main():
341342
test_ksolve0()

0 commit comments

Comments
 (0)