Skip to content

Commit 0862930

Browse files
author
Dilawar Singh
committed
MooseVec can now handle fieldElement as well.
1 parent 1d40e74 commit 0862930

File tree

3 files changed

+22
-5
lines changed

3 files changed

+22
-5
lines changed

pybind11/MooseVec.cpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,19 @@ unsigned int MooseVec::len()
5858

5959
ObjId MooseVec::getItem(const size_t i) const
6060
{
61-
return ObjId(oid_.path(), i, 0);
61+
if (oid_.element()->hasFields())
62+
return getFieldItem(i);
63+
return getDataItem(i);
64+
}
65+
66+
ObjId MooseVec::getDataItem(const size_t i) const
67+
{
68+
return ObjId(oid_.path(), i, oid_.fieldIndex);
69+
}
70+
71+
ObjId MooseVec::getFieldItem(const size_t i) const
72+
{
73+
return ObjId(oid_.path(), oid_.dataIndex, i);
6274
}
6375

6476
void MooseVec::setAttrOneToAll(const string& name, const py::object& val)

pybind11/MooseVec.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,10 @@ class MooseVec {
2929

3030
const ObjId& getItemRef(const size_t i) const;
3131

32+
// Get vector element. Vector element could be `dataIndex` or `fieldIndex`.
3233
ObjId getItem(const size_t i) const;
34+
ObjId getDataItem(const size_t i) const;
35+
ObjId getFieldItem(const size_t i) const;
3336

3437
void setAttrOneToAll(const string& name, const py::object& val);
3538

tests/py_moose/test_api.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
__author__ = "Dilawar Singh"
2-
__copyright__ = "Copyright 2019-, Dilawar Singh"
1+
__author__ = "Dilawar Singh"
2+
__copyright__ = "Copyright 2019-, Dilawar Singh"
33
__maintainer__ = "Dilawar Singh"
4-
__email__ = "[email protected]"
4+
__email__ = "[email protected]"
55

66
import moose
7+
import numpy as np
78

89

910
def test_children():
@@ -57,7 +58,8 @@ def test_finfos():
5758
print(syns.weight)
5859

5960
# this is a shorthand for above for loop.
60-
# syns.weight = 9.0
61+
syns.weight = 11.121
62+
assert np.allclose(syns.weight, 11.121), syns.weight
6163

6264
# try:
6365
# print(syns[11])

0 commit comments

Comments
 (0)