Skip to content

Commit

Permalink
FEAT: Add mesh reuse function (#4842)
Browse files Browse the repository at this point in the history
  • Loading branch information
lorenzovecchietti authored Jun 24, 2024
1 parent e337a7f commit ff00db8
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 2 deletions.
Binary file added _unittest/example_models/T98/cylinder_mesh.msh
Binary file not shown.
27 changes: 26 additions & 1 deletion _unittest/test_98_Icepak.py
Original file line number Diff line number Diff line change
Expand Up @@ -347,8 +347,11 @@ def test_12a_AssignMeshOperation(self):
mesh_level_Filter = "2"
component_name = ["RadioBoard1_1"]
mesh_level_RadioPCB = "1"
test = self.aedtapp.mesh.assign_mesh_level_to_group(mesh_level_Filter, group_name)
assert self.aedtapp.mesh.assign_mesh_level_to_group(mesh_level_Filter, group_name)
test = self.aedtapp.mesh.assign_mesh_level_to_group(mesh_level_Filter, group_name, name="Test")
assert test
test2 = self.aedtapp.mesh.assign_mesh_level_to_group(mesh_level_Filter, group_name, name="Test")
assert test.name != test2.name
# assert self.aedtapp.mesh.assignMeshLevel2Component(mesh_level_RadioPCB, component_name)
test = self.aedtapp.mesh.assign_mesh_region(component_name, mesh_level_RadioPCB, is_submodel=True)
assert test
Expand Down Expand Up @@ -1741,3 +1744,25 @@ def test_78_restart_solution(self):
"test_78-1", "{} : SteadyState".format(s1.name), project="FakeFolder123"
)
assert not s2.start_continue_from_previous_setup("test_78-12", "{} : SteadyState".format(s1.name))

def test_79_mesh_reuse(self):
self.aedtapp.insert_design("test_79")
self.aedtapp.set_active_design("test_79")
cylinder = self.aedtapp.modeler.create_cylinder(1, [0, 0, 0], 5, 30)
assert not self.aedtapp.mesh.assign_mesh_reuse(
cylinder.name,
os.path.join(local_path, "../_unittest/example_models", test_subfolder, "nonexistent_cylinder_mesh.msh"),
)
assert self.aedtapp.mesh.assign_mesh_reuse(
cylinder.name, os.path.join(local_path, "../_unittest/example_models", test_subfolder, "cylinder_mesh.msh")
)
assert self.aedtapp.mesh.assign_mesh_reuse(
cylinder.name,
os.path.join(local_path, "../_unittest/example_models", test_subfolder, "cylinder_mesh.msh"),
"name_reuse",
)
assert self.aedtapp.mesh.assign_mesh_reuse(
cylinder.name,
os.path.join(local_path, "../_unittest/example_models", test_subfolder, "cylinder_mesh.msh"),
"name_reuse",
)
45 changes: 44 additions & 1 deletion pyaedt/modules/MeshIcepak.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

from abc import abstractmethod
from collections import OrderedDict
import os.path
import warnings

from pyaedt.generic.DataHandlers import _dict2arg
Expand Down Expand Up @@ -1638,6 +1638,7 @@ def assign_mesh_level_to_group(
for el in self.meshoperations:
if el.name == name:
name = generate_unique_name(name)
break
else:
name = generate_unique_name("MeshLevel")
props = OrderedDict(
Expand All @@ -1653,3 +1654,45 @@ def assign_mesh_level_to_group(
mop.create()
self.meshoperations.append(mop)
return mop

def assign_mesh_reuse(self, assignment, mesh_file, name=None):
"""Assign a mesh file to objects.
Parameters
----------
assignment : str or list
Names of objects to which the mesh file is assignment.
mesh_file : str
Path to the mesh file.
name : str, optional
Name of the mesh operation. The default is ``None``, in which case it will be
generated automatically.
Returns
-------
:class:`pyaedt.modules.Mesh.MeshOperation`
References
----------
>>> oModule.AssignMeshOperation
"""
if not os.path.exists(mesh_file):
self._app.logger.error("Mesh file does not exist.")
return False
if name:
for el in self.meshoperations:
if el.name == name:
name = generate_unique_name(name)
break
else:
name = generate_unique_name("MeshReuse")
if not isinstance(assignment, list):
assignment = [assignment]
props = OrderedDict(
{"Enable": True, "Mesh Reuse Enabled": True, "Mesh Reuse File": mesh_file, "Objects": assignment}
)
mop = MeshOperation(self, name, props, "Icepak")
mop.create()
self.meshoperations.append(mop)
return mop

0 comments on commit ff00db8

Please sign in to comment.