Skip to content

Commit 226d616

Browse files
author
Dilawar Singh
committed
Function is also fixed.
1 parent b68a97b commit 226d616

File tree

4 files changed

+16
-1
lines changed

4 files changed

+16
-1
lines changed

pybind11/Finfo.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,9 +285,20 @@ unsigned int __Finfo__::getNumField()
285285
return __Finfo__::getNumFieldStatic(oid_, f_);
286286
}
287287

288+
bool __Finfo__::setNumField(unsigned int num)
289+
{
290+
return __Finfo__::setNumFieldStatic(oid_, f_, num);
291+
}
292+
288293
unsigned int __Finfo__::getNumFieldStatic(const ObjId& oid, const Finfo* f)
289294
{
290295
auto o = ObjId(oid.path() + '/' + f->name());
291296
return Field<unsigned int>::get(o, "numField");
292297
}
293298

299+
bool __Finfo__::setNumFieldStatic(const ObjId& oid, const Finfo* f,
300+
unsigned int num)
301+
{
302+
auto o = ObjId(oid.path() + '/' + f->name());
303+
return Field<unsigned int>::set(o, "numField", num);
304+
}

pybind11/Finfo.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,11 @@ class __Finfo__ {
5858

5959
// Get attribute (python api);
6060
unsigned int getNumField();
61+
bool setNumField(unsigned int);
6162

6263
static unsigned int getNumFieldStatic(const ObjId& oid, const Finfo* f);
64+
static bool setNumFieldStatic(const ObjId& oid, const Finfo* f,
65+
unsigned int i);
6366

6467
// Exposed to python as __setitem__
6568
bool setItem(const py::object& key, const py::object& val);

pybind11/pymoose.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ PYBIND11_MODULE(_cmoose, m)
149149
py::class_<__Finfo__>(m, "_Finfo", py::dynamic_attr())
150150
.def(py::init<const ObjId &, const Finfo *, const char *>())
151151
.def_property_readonly("type", &__Finfo__::type)
152-
.def_property_readonly("num", &__Finfo__::getNumField) // Only for FieldElementFinfos
152+
.def_property("num", &__Finfo__::getNumField, &__Finfo__::setNumField) // Only for FieldElementFinfos
153153
.def("__call__", &__Finfo__::operator())
154154
.def("__call__", &__Finfo__::operator())
155155
.def("__getitem__", &__Finfo__::getItem)

tests/py_moose/test_function.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ def test_var_order():
2929
dt = 1.0
3030
# fn0 = moose.Function('/fn0')
3131
fn1 = moose.Function('/fn1')
32+
print(fn1.x.num)
3233
fn1.x.num = 2
3334
fn1.expr = 'y1+y0+x1+x0'
3435
fn1.mode = 1

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy