Skip to content

Commit 8baffdc

Browse files
author
Dilawar Singh
committed
Support more fieldType. Fixes one more failing script in moose examples.
1 parent b3a3e84 commit 8baffdc

File tree

3 files changed

+28
-8
lines changed

3 files changed

+28
-8
lines changed

basecode/Conv.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ template< class T > class Conv
100100
return "Id";
101101
if ( typeid( T ) == typeid( ObjId ) )
102102
return "ObjId";
103-
return typeid( T ).name(); // this is not portable but may be more useful than "bad"
103+
return typeid(T).name(); // this is not portable but may be more useful than "bad"
104104
}
105105

106106
private:

pybind11/pymoose.cpp

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,19 +51,25 @@ bool setFieldGeneric(const ObjId &oid, const string &fieldName,
5151
throw runtime_error(fieldName + " is not found on " + oid.path());
5252
return false;
5353
}
54+
5455
auto fieldType = finfo->rttiType();
5556

57+
// Remove any space in fieldType
58+
fieldType.erase(
59+
std::remove_if(fieldType.begin(), fieldType.end(), ::isspace),
60+
fieldType.end());
61+
5662
if (fieldType == "double")
5763
return Field<double>::set(oid, fieldName, val.cast<double>());
5864
if (fieldType == "vector<double>")
5965
return Field<vector<double>>::set(oid, fieldName,
6066
val.cast<vector<double>>());
6167
if (fieldType == "float")
6268
return Field<float>::set(oid, fieldName, val.cast<float>());
63-
if (fieldType == "unsigned int")
69+
if (fieldType == "unsignedint")
6470
return Field<unsigned int>::set(oid, fieldName,
6571
val.cast<unsigned int>());
66-
if (fieldType == "unsigned long")
72+
if (fieldType == "unsignedlong")
6773
return Field<unsigned long>::set(oid, fieldName,
6874
val.cast<unsigned long>());
6975
if (fieldType == "int")
@@ -86,11 +92,22 @@ bool setFieldGeneric(const ObjId &oid, const string &fieldName,
8692
// NB: Note that we cast to ObjId here and not to Id.
8793
return Field<Id>::set(oid.id, fieldName, val.cast<ObjId>());
8894
}
95+
if (fieldType == "vector<double>") {
96+
// NB: Note that we cast to ObjId here and not to Id.
97+
return Field<vector<double>>::set(
98+
oid.id, fieldName, val.cast<vector<double>>());
99+
}
100+
if (fieldType == "vector<vector<double>>") {
101+
// NB: Note that we cast to ObjId here and not to Id.
102+
return Field<vector<vector<double>>>::set(
103+
oid.id, fieldName, val.cast<vector<vector<double>>>());
104+
}
89105
if (fieldType == "Variable")
90-
return Field<Variable>::set(oid, fieldName, val.cast<Variable>());
106+
if (fieldType == "Variable")
107+
return Field<Variable>::set(oid, fieldName, val.cast<Variable>());
91108

92-
throw runtime_error("NotImplemented::setField : " + fieldName +
93-
" with value type " + fieldType);
109+
throw runtime_error("NotImplemented::setField: '" + fieldName +
110+
"' with value type '" + fieldType + "'.");
94111
return false;
95112
}
96113

@@ -190,8 +207,10 @@ PYBIND11_MODULE(_moose, m)
190207
.def("__eq__", [](const Id &a, const Id &b) { return a == b; })
191208
.def("__ne__", [](const Id &a, const Id &b) { return a != b; });
192209

193-
// I can use py::metaclass here to generate moose.Neutral etc types but
194-
// lets do it in moose.py.
210+
/**
211+
* @name ObjId. It is a base of all other moose objects.
212+
* @{ */
213+
/** @} */
195214
py::class_<ObjId>(m, "_ObjId")
196215
.def(py::init<>())
197216
.def(py::init<Id>())

python/moose/moose.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ def __init__(self, x, ndata=1, **kwargs):
3939
obj = _moose._ObjId(x)
4040
else:
4141
raise RuntimeError("%s is not supported" % x)
42+
super().__init__(obj.id, obj.dataIndex)
4243
"""
4344
#if self.__class__ is None:
4445
# self.__class__ = x.className

0 commit comments

Comments
 (0)