Skip to content

Commit

Permalink
Add new region duplication settings API (#385)
Browse files Browse the repository at this point in the history
* Initial commit

* Update unit tests

* Update linked region to update both regions in single call

* fix test

* Improve testing coverage

* Update string ""

* Improve test coverage for linked_region getter

---------

Co-authored-by: Jack Davies <[email protected]>
Co-authored-by: Jack Davies <[email protected]>
  • Loading branch information
3 people authored Nov 1, 2024
1 parent ebedc21 commit 91a49dd
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 1 deletion.
26 changes: 26 additions & 0 deletions src/ansys/motorcad/core/geometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ def __init__(self, motorcad_instance=None):
self._motorcad_instance = motorcad_instance
self._region_type = RegionType.adaptive
self.mesh_length = 0
self._linked_region = None
self._singular = False

def __eq__(self, other):
"""Override the default equals implementation for Region."""
Expand Down Expand Up @@ -189,6 +191,9 @@ def _from_json(cls, json, motorcad_instance=None):
if "mesh_length" in json:
new_region.mesh_length = json["mesh_length"]

if "singular" in json:
new_region._singular = json["singular"]

return new_region

# method to convert python object to send to Motor-CAD
Expand All @@ -212,6 +217,8 @@ def _to_json(self):
"parent_name": self.parent_name,
"region_type": self._region_type.value,
"mesh_length": self.mesh_length,
"on_boundary": False if self._linked_region is None else True,
"singular": self._singular,
}

return region_dict
Expand Down Expand Up @@ -253,6 +260,25 @@ def parent_name(self):
def parent_name(self, name):
self._parent_name = name

@property
def linked_region(self):
"""Get linked duplication/unite region."""
return self._linked_region

@linked_region.setter
def linked_region(self, region):
self._linked_region = region
region._linked_region = self

@property
def singular(self):
"""Get linked duplication/unite region."""
return self._singular

@singular.setter
def singular(self, singular):
self._singular = singular

@property
def child_names(self):
"""Property for child names list.
Expand Down
27 changes: 26 additions & 1 deletion tests/test_geometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,7 @@ def test_region_from_json():
"child_names": ["Duct", "Duct_1"],
"region type": "Adaptive Region",
"mesh_length": 0.035,
"singular": False,
}

test_region = geometry.Region()
Expand All @@ -366,7 +367,8 @@ def test_region_from_json():
test_region.entities = []
test_region.parent_name = "Insulation"
test_region._child_names = ["Duct", "Duct_1"]
test_region.mesh_length = 0.035
test_region.mesh_length = (0.035,)
test_region.singular = (False,)

region = geometry.Region._from_json(raw_region)

Expand All @@ -386,6 +388,8 @@ def test_region_to_json():
"parent_name": "Insulation",
"region_type": "Adaptive Region",
"mesh_length": 0.035,
"singular": True,
"on_boundary": False,
}

test_region = geometry.Region()
Expand All @@ -399,6 +403,7 @@ def test_region_to_json():
test_region.entities = []
test_region.parent_name = "Insulation"
test_region.mesh_length = 0.035
test_region.singular = True

assert test_region._to_json() == raw_region

Expand All @@ -409,6 +414,26 @@ def test_region_is_closed():
assert region.is_closed()


def test_set_linked_region():
region = generate_constant_region()

region_linked = Region()
region_linked.name = "linked_region_test"
# set linked region
region.linked_region = region_linked

assert region._linked_region.name == region_linked.name
assert region_linked.linked_region.name == region.name


def test_set_singular_region():
region = generate_constant_region()
region.singular = True

assert region._singular is True
assert region.singular is True


def test_region_contains_same_entities():
region = generate_constant_region()

Expand Down

0 comments on commit 91a49dd

Please sign in to comment.