Skip to content
This repository was archived by the owner on Nov 3, 2022. It is now read-only.

Commit aeecc41

Browse files
author
Dilawar Singh
committed
beat the old api in microbenchmarks as well.
1 parent 6e88eff commit aeecc41

File tree

5 files changed

+37
-31
lines changed

5 files changed

+37
-31
lines changed

pybind11/helper.cpp

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -145,15 +145,6 @@ bool mooseExists(const string& p)
145145
return Id(path) != Id() || path == "/" || path == "/root";
146146
}
147147

148-
ObjId mooseObjId(const string& path)
149-
{
150-
ObjId oid(path);
151-
if (oid.bad()) {
152-
cerr << "moose_element: " << path << " does not exist!" << endl;
153-
return ObjId(Id());
154-
}
155-
return oid;
156-
}
157148

158149
ObjId loadModelInternal(const string& fname, const string& modelpath,
159150
const string& solverclass = "")

pybind11/helper.h

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,20 @@ bool mooseExists(const string& path);
3737
void mooseMoveId(const Id& a, const ObjId& b);
3838
void mooseMoveObjId(const ObjId& a, const ObjId& b);
3939

40-
ObjId mooseObjId(const string& path);
40+
inline ObjId mooseObjIdPath(const string& path)
41+
{
42+
ObjId oid(path);
43+
if (oid.bad()) {
44+
cerr << "moose_element: " << path << " does not exist!" << endl;
45+
return ObjId(Id());
46+
}
47+
return oid;
48+
}
49+
50+
inline ObjId mooseObjIdObj(const ObjId& obj)
51+
{
52+
return ObjId(obj.id, obj.dataIndex, obj.fieldIndex);
53+
}
4154

4255
ObjId loadModelInternal(const string& fname, const string& modelpath,
4356
const string& solverclass);

pybind11/pymoose.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,8 @@ PYBIND11_MODULE(_moose, m)
332332
m.def("reinit", &mooseReinit);
333333
m.def("start", &mooseStart, "runtime"_a, "notify"_a = false);
334334
m.def("stop", &mooseStop);
335-
m.def("objid", &mooseObjId);
335+
m.def("element", &mooseObjIdPath);
336+
m.def("element", &mooseObjIdObj);
336337
m.def("exists", &mooseExists);
337338
m.def("getCwe", &mooseGetCwe);
338339
m.def("setCwe", &mooseSetCwe);

python/moose/moose.py

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -64,26 +64,26 @@ def about():
6464
version=_moose.__version__,
6565
docs='https://moose.readthedocs.io/en/latest/')
6666

67-
def element(path):
68-
"""moose.element(arg) -> moose object
69-
Convert a path or an object to the appropriate builtin moose class
70-
instance.
71-
72-
Parameters
73-
----------
74-
arg : str/vec/moose object"
75-
path of the moose element to be converted or another element (possibly
76-
available as a superclass instance).
77-
78-
Returns"
79-
-------"
80-
MOOSE element (object) corresponding to the `arg` converted to an
81-
appropriate class.
82-
"""
83-
if not isinstance(path, str):
84-
path = path.path
85-
obj = _moose.objid(path)
86-
return PyObjId(obj)
67+
#def element(arg):
68+
# """moose.element(arg) -> moose object
69+
# Convert a path or an object to the appropriate builtin moose class
70+
# instance.
71+
#
72+
# Parameters
73+
# ----------
74+
# arg : str/vec/moose object"
75+
# path of the moose element to be converted or another element (possibly
76+
# available as a superclass instance).
77+
#
78+
# Returns"
79+
# -------"
80+
# MOOSE element (object) corresponding to the `arg` converted to an
81+
# appropriate class.
82+
# """
83+
# #if not isinstance(path, str):
84+
# # path = path.path
85+
# #obj = _moose.objid(path)
86+
# return PyObjId(_moose.objid(arg))
8787

8888
def wildcardFind(pattern):
8989
# return _moose.wildcardFind(pattern)

tests/benchmarks/micro_benchmark.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,5 @@ function run_str() {
1111
run_str "import moose"
1212
run_str "a=moose.Neutral('a');moose.delete(a)"
1313
run_str "a=moose.Neutral('a', 10000);moose.delete(a)"
14+
run_str "a1=moose.Neutral('a');a2=moose.element(a1);moose.delete(a1)"
1415
run_str "a1=moose.Neutral('a');a2=moose.element(a1);a1==a2;moose.delete(a1)"

0 commit comments

Comments
 (0)