Skip to content

Commit eff08b2

Browse files
author
Dilawar Singh
committed
All test passes. Needs to work on the API now.
1 parent 8791df7 commit eff08b2

File tree

5 files changed

+20
-20
lines changed

5 files changed

+20
-20
lines changed

pybind11/helper.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ ObjId createIdFromPath(string path, string type, size_t numData)
115115
return nId;
116116
}
117117

118-
inline Shell* const getShellPtr(void)
118+
Shell* getShellPtr(void)
119119
{
120120
return reinterpret_cast<Shell*>(Id().eref().data());
121121
}

pybind11/helper.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ Id initShell();
2323

2424
ObjId createIdFromPath(string path, string type, size_t numData=1);
2525

26-
Shell* const getShellPtr();
26+
Shell* getShellPtr();
2727

2828
bool doesExist(const string& path);
2929

pybind11/pymoose.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,10 @@ inline void mooseDelete(const ObjId& oid)
152152
getShellPtr()->doDelete(oid);
153153
}
154154

155+
inline void mooseSetClock(const size_t clockId, double dt)
156+
{
157+
getShellPtr()->doSetClock(clockId, dt);
158+
}
155159

156160
PYBIND11_MODULE(_cmoose, m)
157161
{
@@ -256,8 +260,8 @@ PYBIND11_MODULE(_cmoose, m)
256260
py::return_value_policy::reference);
257261

258262
m.def("wildcardFind", &wildcardFind2);
259-
260263
m.def("delete", &mooseDelete);
264+
m.def("setClock", &mooseSetClock);
261265

262266
// Attributes.
263267
m.attr("NA") = NA;

python/moose/moose.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,6 @@ def __init__(self, path, ndata=1):
4040
def __repr__(self):
4141
return self.cobj.__repr__()
4242

43-
def __del__(self):
44-
__SHELL__.delete(self.cobj)
45-
del self
46-
4743
def connect(self, srcField, dest, destField):
4844
if hasattr(dest, 'cobj'):
4945
dest = dest.cobj
@@ -68,7 +64,6 @@ def name(self, path):
6864

6965
logger_.info("Declarting classes took %f sec" % (time.time() - t0))
7066

71-
7267
#############################################################################
7368
# API #
7469
#############################################################################
@@ -93,12 +88,13 @@ def wildcardFind(pattern):
9388
"""
9489
paths = []
9590
for p in _cmoose._wildcardFind(pattern):
96-
paths.append(__toMooseObject(p))
91+
paths.append(p)
9792
return paths
9893

9994
def delete(a):
100-
moose._cmoose.delete(a.cobj)
101-
del a
95+
if hasattr(a, 'cobj'):
96+
return moose._cmoose.delete(a.cobj)
97+
return moose._cmoose.delete(a)
10298

10399
def element(pathOrObject):
104100
if isinstance(pathOrObject, str):

tests/pybind11/test_shell.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -197,9 +197,8 @@ def makereac1():
197197

198198
def makereac2():
199199
pools = [None]*10
200-
s = M.getShell()
201200
kin = moose.CubeMesh("kinetics", 1)
202-
t = moose.StimulusTable("/kinetics/StimulusTable")
201+
t = moose.StimulusTable("kinetics/StimulusTable")
203202
pools[0] = T = moose.BufPool(kin.path+"/T")
204203
pools[1] = A = moose.Pool(kin.path+"/A")
205204
pools[2] = B = moose.Pool(kin.path + "/B")
@@ -284,8 +283,8 @@ def makereac2():
284283

285284
# Schedule it.
286285
for i in range(11, 18):
287-
s.setClock(i, 0.1);
288-
s.setClock(18, 0.1);
286+
moose.setClock(i, 0.1);
287+
moose.setClock(18, 0.1);
289288
return kin
290289

291290
def run_and_assert(kin, outfile):
@@ -312,8 +311,9 @@ def run_and_assert(kin, outfile):
312311
assert np.allclose(expected, np.array(got)), "Expected %s but got %s" % (
313312
expected, got)
314313
# get data.
315-
s.delete(kin.cobj)
314+
moose.delete(kin)
316315
plt.savefig(outfile)
316+
plt.close()
317317
print("Done ksolve: Saved to %s" % outfile)
318318

319319
def test_ksolve0():
@@ -325,13 +325,13 @@ def test_ksolve1():
325325
run_and_assert(kin, "ksolve1_test1.png")
326326

327327
def test_ksolve2():
328+
print("[INFO ] test 3")
328329
kin = makereac2()
329-
run_and_assert(kin, "ksolve1_test1.png")
330-
330+
run_and_assert(kin, "ksolve1_test2.png")
331331

332332
def main():
333-
#test_ksolve0()
334-
#test_ksolve1()
333+
test_ksolve0()
334+
test_ksolve1()
335335
test_ksolve2()
336336

337337
if __name__ == '__main__':

0 commit comments

Comments
 (0)