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

Commit

Permalink
Updated a bit more ..
Browse files Browse the repository at this point in the history
  • Loading branch information
Dilawar Singh committed Mar 28, 2020
1 parent b43c617 commit a979de6
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 19 deletions.
9 changes: 7 additions & 2 deletions pybind11/pymoose.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,12 @@ py::object getFieldGeneric(const ObjId& oid, const string& fname)
return py::cast(getProp<ObjId>(oid, fname));
else if (ftype == "Variable")
return py::cast(getProp<Variable>(oid, fname));
py::print("pymoose::getFieldGeneric::Warning: Unsupported type " + ftype);
else if (ftype == "vector<Id>")
return py::cast(getProp<vector<Id>>(oid, fname));
else if (ftype == "vector<ObjId>")
return py::cast(getProp<vector<ObjId>>(oid, fname));

py::print("Warning: pymoose::getFieldGeneric::Warning: Unsupported type " + ftype);
return pybind11::none();
}

Expand Down Expand Up @@ -255,6 +260,7 @@ PYBIND11_MODULE(_cmoose, m)
.def(py::init<>())
.def("create", &Shell::doCreate2)
.def("addMsg", &Shell::doAddMsg)
.def("getCwe", &Shell::getCwe)
.def("setClock", &Shell::doSetClock)
.def("reinit", &Shell::doReinit)
.def("delete", &Shell::doDelete)
Expand All @@ -277,6 +283,5 @@ PYBIND11_MODULE(_cmoose, m)
m.attr("PI") = PI;
m.attr("FaradayConst") = FaradayConst;
m.attr("GasConst") = GasConst;

m.attr("__version__") = MOOSE_VERSION;
}
6 changes: 3 additions & 3 deletions python/moose/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
# some C++ here.
from moose.moose import *

# from moose.server import *
from moose.server import *

# SBML and NML2 support.
# from moose.model_utils import *
from moose.model_utils import *

# Import moose test.
# from moose.moose_test import test
from moose.moose_test import test
17 changes: 3 additions & 14 deletions python/moose/moose.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,6 @@
import logging
logger_ = logging.getLogger('moose')

# String to python classes.
__classmap__ = {}
__SHELL__ = _cmoose.getShell()

def __parent(path):
return path.split('/')[-1]

Expand All @@ -33,9 +29,6 @@ def __init__(self, path, ndata=1):
obj = _cmoose.create(self.__metaclass__, path, ndata)
super(__Neutral__, self).__init__(obj.id)

def __repr__(self):
return self.__repr__()

def __setattr__(self, attr, val):
self.setField(attr, val)

Expand All @@ -45,8 +38,6 @@ def __getattr__(self, attr):
for p in _cmoose.wildcardFind('/##[TYPE=Cinfo]'):
# create a class.
cls = type(p.name, (__Neutral__,), dict(__metaclass__=p.name, objid=p.id))
# Add this class to module and save them in a map for easy reuse later.
__classmap__[p.name] = cls
setattr(moose, cls.__name__, cls)

logger_.info("Declarting classes took %f sec" % (time.time() - t0))
Expand Down Expand Up @@ -74,7 +65,7 @@ def wildcardFind(pattern):
pattern
"""
paths = []
for p in _cmoose._wildcardFind(pattern):
for p in _cmoose.wildcardFind(pattern):
paths.append(p)
return paths

Expand All @@ -86,10 +77,10 @@ def element(pathOrObject):
obj = _cmoose.element(pathOrObject)
else:
obj = _cmoose.element(pathOrObject.path)
return __toMooseObject(obj)
return obj

def getCwe():
return __toMooseObject(_cmoose.getCwe())
return _cmoose.getShell().getCwe()

def exists(path):
return _cmoose.exists(path)
Expand Down Expand Up @@ -447,5 +438,3 @@ def doc(arg, inherited=True, paged=True):
__pager(text)
else:
print(text)


22 changes: 22 additions & 0 deletions tests/pybind11/test_api.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
__author__ = "Dilawar Singh"
__copyright__ = "Copyright 2019-, Dilawar Singh"
__maintainer__ = "Dilawar Singh"
__email__ = "dilawars@ncbs.res.in"

import moose

def test_children():
a1 = moose.Neutral('/a')
a2 = moose.Neutral('/a/b')
moose.Neutral('/a/b/c1')
moose.Neutral('/a/b/c2')
assert len(a1.children) == 1
assert len(a2.children) == 2
print(a1, a2)

def main():
test_children()

if __name__ == '__main__':
main()

0 comments on commit a979de6

Please sign in to comment.