Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix group field utility to work with region tree #220

Merged
merged 1 commit into from
Mar 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def readfile(filename, split=False):
# minimal requirements listing
"opencmiss.maths",
"opencmiss.utils >= 0.3",
"opencmiss.zinc >= 3.9",
"opencmiss.zinc >= 3.10.2",
"scipy",
"numpy",
]
Expand Down
15 changes: 9 additions & 6 deletions src/scaffoldmaker/utils/zinc_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
'''

from opencmiss.utils.zinc.field import findOrCreateFieldCoordinates
from opencmiss.utils.zinc.general import ChangeManager
from opencmiss.utils.zinc.general import ChangeManager, HierarchicalChangeManager
from opencmiss.zinc.context import Context
from opencmiss.zinc.element import Mesh, MeshGroup
from opencmiss.zinc.field import Field, FieldGroup
Expand Down Expand Up @@ -173,21 +173,24 @@ def get_next_unused_node_identifier(nodeset: Nodeset, start_identifier=1) -> int

def group_add_group_elements(group : FieldGroup, other_group : FieldGroup, only_dimension=None):
'''
Add to group elements and/or nodes from other_group.
Add to group elements and/or nodes from other_group, which may be in a descendent region.
:param group: The FieldGroup to modify.
:param other_group: FieldGroup within region tree of group's region to add contents from.
:param only_dimension: If set, only add objects of this dimension.
'''
fieldmodule = group.getFieldmodule()
with ChangeManager(fieldmodule):
region = group.getFieldmodule().getRegion()
with HierarchicalChangeManager(region):
other_fieldmodule = other_group.getFieldmodule()
for dimension in [ only_dimension ] if only_dimension else range(4):
if dimension > 0:
mesh = fieldmodule.findMeshByDimension(dimension)
mesh = other_fieldmodule.findMeshByDimension(dimension)
element_group = group.getFieldElementGroup(mesh)
if not element_group.isValid():
element_group = group.createFieldElementGroup(mesh)
mesh_group = element_group.getMeshGroup()
mesh_group.addElementsConditional(other_group.getFieldElementGroup(mesh))
elif dimension == 0:
nodeset = fieldmodule.findNodesetByFieldDomainType(Field.DOMAIN_TYPE_NODES)
nodeset = other_fieldmodule.findNodesetByFieldDomainType(Field.DOMAIN_TYPE_NODES)
node_group = group.getFieldNodeGroup(nodeset)
if not node_group.isValid():
node_group = group.createFieldNodeGroup(nodeset)
Expand Down