Skip to content

Commit

Permalink
REFACTOR: Use Mixin to create boundary (#5755)
Browse files Browse the repository at this point in the history
  • Loading branch information
SMoraisAnsys authored Feb 15, 2025
1 parent dad513b commit b48776e
Show file tree
Hide file tree
Showing 12 changed files with 236 additions and 299 deletions.
43 changes: 4 additions & 39 deletions src/ansys/aedt/core/hfss.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
from ansys.aedt.core.generic.general_methods import pyaedt_function_handler
from ansys.aedt.core.generic.general_methods import read_configuration_file
from ansys.aedt.core.generic.settings import settings
from ansys.aedt.core.mixins import CreateBoundaryMixin
from ansys.aedt.core.modeler import cad
from ansys.aedt.core.modeler.cad.component_array import ComponentArray
from ansys.aedt.core.modeler.cad.components_3d import UserDefinedComponent
Expand All @@ -58,7 +59,7 @@
from ansys.aedt.core.modules.setup_templates import SetupKeys


class Hfss(FieldAnalysis3D, ScatteringMethods):
class Hfss(FieldAnalysis3D, ScatteringMethods, CreateBoundaryMixin):
"""Provides the HFSS application interface.
This class allows you to create an interactive instance of HFSS and
Expand Down Expand Up @@ -185,14 +186,6 @@ class Hfss(FieldAnalysis3D, ScatteringMethods):
"""

# def __repr__(self):
# try:
# return "HFSS {} {}. ProjectName:{} DesignName:{} ".format(
# self._aedt_version, self.solution_type, self.project_name, self.design_name
# )
# except Exception:
# return "HFSS Module"

@pyaedt_function_handler(
designname="design",
projectname="project",
Expand Down Expand Up @@ -274,7 +267,7 @@ def field_setup_names(self):
"""
return self.odesign.GetChildObject("Radiation").GetChildNames()

class BoundaryType(object):
class BoundaryType(CreateBoundaryMixin):
"""Creates and manages boundaries."""

(
Expand Down Expand Up @@ -380,34 +373,6 @@ def _get_unique_source_name(self, source_name, root_name):
source_name = generate_unique_name(source_name)
return source_name

@pyaedt_function_handler()
def _create_boundary(self, name, props, boundary_type):
"""Create a boundary.
Parameters
----------
name : str
Name of the boundary.
props : list or dict
List of properties for the boundary.
boundary_type :
Type of the boundary.
Returns
-------
:class:`ansys.aedt.core.modules.boundary.common.BoundaryObject`
Boundary object.
"""

bound = BoundaryObject(self, name, props, boundary_type)
result = bound.create()
if result:
self._boundaries[bound.name] = bound
self.logger.info(f"Boundary {boundary_type} {name} has been correctly created.")
return bound
raise AEDTRuntimeError(f"Failed to create boundary {boundary_type} {name}")

@pyaedt_function_handler(objectname="assignment", portname="port_name")
def _create_lumped_driven(self, assignment, int_line_start, int_line_stop, impedance, port_name, renorm, deemb):
assignment = self.modeler.convert_to_selections(assignment, True)
Expand Down Expand Up @@ -6841,7 +6806,7 @@ def hertzian_dipole_wave(
is_electric=True,
radius="10mm",
name=None,
) -> BoundaryObject:
) -> "BoundaryObject":
"""Create a hertzian dipole wave excitation.
The excitation is assigned in the assigned sphere. Inside this sphere, the field magnitude
Expand Down
131 changes: 40 additions & 91 deletions src/ansys/aedt/core/icepak.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,16 @@
from ansys.aedt.core.generic.data_handlers import _dict2arg
from ansys.aedt.core.generic.data_handlers import random_string
from ansys.aedt.core.generic.errors import AEDTRuntimeError
from ansys.aedt.core.generic.errors import GrpcApiError
from ansys.aedt.core.generic.general_methods import generate_unique_name
from ansys.aedt.core.generic.general_methods import open_file
from ansys.aedt.core.generic.general_methods import pyaedt_function_handler
from ansys.aedt.core.generic.settings import is_linux
from ansys.aedt.core.generic.settings import settings
from ansys.aedt.core.mixins import CreateBoundaryMixin
from ansys.aedt.core.modeler.cad.components_3d import UserDefinedComponent
from ansys.aedt.core.modeler.cad.elements_3d import FacePrimitive
from ansys.aedt.core.modeler.geometry_operators import GeometryOperators
from ansys.aedt.core.modeler.geometry_operators import GeometryOperators as go
from ansys.aedt.core.modules.boundary.common import BoundaryObject
from ansys.aedt.core.modules.boundary.icepak_boundary import BoundaryDictionary
from ansys.aedt.core.modules.boundary.icepak_boundary import ExponentialDictionary
from ansys.aedt.core.modules.boundary.icepak_boundary import LinearDictionary
Expand All @@ -57,13 +56,12 @@
from ansys.aedt.core.modules.boundary.icepak_boundary import PowerLawDictionary
from ansys.aedt.core.modules.boundary.icepak_boundary import SinusoidalDictionary
from ansys.aedt.core.modules.boundary.icepak_boundary import SquareWaveDictionary
from ansys.aedt.core.modules.boundary.icepak_boundary import _create_boundary
from ansys.aedt.core.modules.boundary.layout_boundary import NativeComponentObject
from ansys.aedt.core.modules.boundary.layout_boundary import NativeComponentPCB
from ansys.aedt.core.modules.setup_templates import SetupKeys


class Icepak(FieldAnalysisIcepak):
class Icepak(FieldAnalysisIcepak, CreateBoundaryMixin):
"""Provides the Icepak application interface.
This class allows you to connect to an existing Icepak design or create a
Expand Down Expand Up @@ -301,12 +299,8 @@ def assign_grille(

props["X"] = x_curve
props["Y"] = y_curve
bound = BoundaryObject(self, boundary_name, props, "Grille")
if bound.create():
self._boundaries[bound.name] = bound
self.logger.info("Grille Assigned")
return bound
return None
bound = self._create_boundary(boundary_name, props, "Grille")
return bound

@pyaedt_function_handler()
def assign_openings(self, air_faces):
Expand Down Expand Up @@ -347,12 +341,8 @@ def assign_openings(self, air_faces):
props["External Rad. Temperature"] = "AmbientRadTemp"
props["Inlet Type"] = "Pressure"
props["Total Pressure"] = "AmbientPressure"
bound = BoundaryObject(self, boundary_name, props, "Opening")
if bound.create():
self._boundaries[bound.name] = bound
self.logger.info("Opening Assigned")
return bound
return None
bound = self._create_boundary(boundary_name, props, "Opening")
return bound

@pyaedt_function_handler(setup_name="setup")
def assign_2way_coupling(
Expand Down Expand Up @@ -528,12 +518,8 @@ def create_source_block(
else:
boundary_name = generate_unique_name("Block")

bound = BoundaryObject(self, boundary_name, props, "Block")
if bound.create():
self._boundaries[bound.name] = bound
self.logger.info(f"Block on {object_name} with {input_power} power created correctly.")
return bound
return None
bound = self._create_boundary(boundary_name, props, "Block")
return bound

@pyaedt_function_handler()
def create_conduting_plate(
Expand Down Expand Up @@ -647,8 +633,8 @@ def create_conduting_plate(
}

props["Shell Conduction"] = shell_conduction
bound = BoundaryObject(self, bc_name, props, "Conducting Plate")
return _create_boundary(bound)
bound = self._create_boundary(bc_name, props, "Conducting Plate")
return bound

@pyaedt_function_handler()
def create_source_power(
Expand Down Expand Up @@ -734,8 +720,8 @@ def create_source_power(
props["Surface Heat"] = surface_heat
props["Temperature"] = temperature
props["Radiation"] = {"Radiate": radiate}
bound = BoundaryObject(self, source_name, props, "SourceIcepak")
return _create_boundary(bound)
bound = self._create_boundary(source_name, props, "SourceIcepak")
return bound

@pyaedt_function_handler()
def create_network_block(
Expand Down Expand Up @@ -840,12 +826,8 @@ def create_network_block(
"Link2": ["Face" + str(fcrjb), "Internal", "R", str(rjb) + "cel_per_w"],
}
props["SchematicData"] = {}
bound = BoundaryObject(self, boundary_name, props, "Network")
if bound.create():
self._boundaries[bound.name] = bound
self.modeler[object_name].solve_inside = False
return bound
return None
bound = self._create_boundary(boundary_name, props, "Network")
return bound

@pyaedt_function_handler()
def create_network_blocks(
Expand Down Expand Up @@ -1840,12 +1822,8 @@ def assign_em_losses(
props["SurfaceOnly"] = surfaces

name = generate_unique_name("EMLoss")
bound = BoundaryObject(self, name, props, "EMLoss")
if bound.create():
self._boundaries[bound.name] = bound
self.logger.info("EM losses mapped from design: %s.", design)
return bound
return False
bound = self._create_boundary(name, props, "EMLoss")
return bound

@pyaedt_function_handler()
def eval_surface_quantity_from_field_summary(
Expand Down Expand Up @@ -3444,12 +3422,8 @@ def get_face_normal(obj_face):
}

self.modeler.primitives[object_name].material_name = "Ceramic_material"
boundary = BoundaryObject(self, object_name, props, "Network")
if boundary.create():
self._boundaries[boundary.name] = boundary
self.modeler.primitives[object_name].solve_inside = False
return boundary
return None
bound = self._create_boundary(object_name, props, "Network")
return bound

@pyaedt_function_handler(htc_dataset="htc")
def assign_stationary_wall(
Expand Down Expand Up @@ -3678,8 +3652,8 @@ def assign_stationary_wall(
props["External Surface Radiation"] = ext_surf_rad
props["External Material"] = ext_surf_rad_material
props["External Radiation View Factor"] = ext_surf_rad_view_factor
bound = BoundaryObject(self, name, props, "Stationary Wall")
return _create_boundary(bound)
bound = self._create_boundary(name, props, "Stationary Wall")
return bound

@pyaedt_function_handler()
def assign_stationary_wall_with_heat_flux(
Expand Down Expand Up @@ -4143,12 +4117,8 @@ def assign_source(
else:
props[quantity] = value

bound = BoundaryObject(self, boundary_name, props, "SourceIcepak")
if bound.create():
self._boundaries[bound.name] = bound
return bound
else:
return None
bound = self._create_boundary(boundary_name, props, "SourceIcepak")
return bound

@pyaedt_function_handler()
def create_network_object(self, name=None, props=None, create=False):
Expand Down Expand Up @@ -4371,8 +4341,8 @@ def assign_solid_block(
if not boundary_name:
boundary_name = generate_unique_name("Block")

bound = BoundaryObject(self, boundary_name, props, "Block")
return _create_boundary(bound)
bound = self._create_boundary(boundary_name, props, "Block")
return bound

@pyaedt_function_handler
def assign_hollow_block(
Expand Down Expand Up @@ -4490,8 +4460,8 @@ def assign_hollow_block(
if not boundary_name:
boundary_name = generate_unique_name("Block")

bound = BoundaryObject(self, boundary_name, props, "Block")
return _create_boundary(bound)
bound = self._create_boundary(boundary_name, props, "Block")
return bound

@pyaedt_function_handler(timestep="time_step")
def get_fans_operating_point(self, export_file=None, setup_name=None, time_step=None, design_variation=None):
Expand Down Expand Up @@ -4694,13 +4664,8 @@ def assign_free_opening(

if not boundary_name:
boundary_name = generate_unique_name("Opening")

bound = BoundaryObject(self, boundary_name, props, "Opening")
if bound.create():
self._boundaries[bound.name] = bound
return bound
else:
return None
bound = self._create_boundary(boundary_name, props, "Opening")
return bound

@pyaedt_function_handler()
def assign_pressure_free_opening(
Expand Down Expand Up @@ -4960,8 +4925,8 @@ def assign_symmetry_wall(self, geometry, boundary_name=None):
else:
props["Objects"] = geometry

bound = BoundaryObject(self, boundary_name, props, "Symmetry Wall")
return _create_boundary(bound)
bound = self._create_boundary(boundary_name, props, "Symmetry Wall")
return bound

@pyaedt_function_handler()
def assign_adiabatic_plate(self, assignment, high_radiation_dict=None, low_radiation_dict=None, boundary_name=None):
Expand Down Expand Up @@ -5029,16 +4994,8 @@ def assign_adiabatic_plate(self, assignment, high_radiation_dict=None, low_radia

if not boundary_name:
boundary_name = generate_unique_name("AdiabaticPlate")

bound = BoundaryObject(self, boundary_name, props, "Adiabatic Plate")
try:
if bound.create():
self._boundaries[bound.name] = bound
return bound
else: # pragma: no cover
raise SystemExit
except (GrpcApiError, SystemExit): # pragma: no cover
return None
bound = self._create_boundary(boundary_name, props, "Adiabatic Plate")
return bound

@pyaedt_function_handler()
def assign_resistance(
Expand Down Expand Up @@ -5207,16 +5164,8 @@ def assign_resistance(

if not boundary_name:
boundary_name = generate_unique_name("Resistance")

bound = BoundaryObject(self, boundary_name, props, "Resistance")
try:
if bound.create():
self._boundaries[bound.name] = bound
return bound
else: # pragma: no cover
raise SystemExit
except (GrpcApiError, SystemExit): # pragma: no cover
return None
bound = self._create_boundary(boundary_name, props, "Resistance")
return bound

@pyaedt_function_handler()
def assign_power_law_resistance(
Expand Down Expand Up @@ -5610,8 +5559,8 @@ def assign_recirculation_opening(
if not boundary_name:
boundary_name = generate_unique_name("Recirculating")

bound = BoundaryObject(self, boundary_name, props, "Recirculating")
return _create_boundary(bound)
bound = self._create_boundary(boundary_name, props, "Recirculating")
return bound

@pyaedt_function_handler()
def assign_blower_type1(
Expand Down Expand Up @@ -5807,8 +5756,8 @@ def _assign_blower(
props["Y"] = [str(pt) for pt in fan_curve_pressure]
if not boundary_name:
boundary_name = generate_unique_name("Blower")
bound = BoundaryObject(self, boundary_name, props, "Blower")
return _create_boundary(bound)
bound = self._create_boundary(boundary_name, props, "Blower")
return bound

@pyaedt_function_handler()
def assign_conducting_plate(
Expand Down Expand Up @@ -5927,8 +5876,8 @@ def assign_conducting_plate(
props["Shell Conduction"] = shell_conduction
if not boundary_name:
boundary_name = generate_unique_name("Plate")
bound = BoundaryObject(self, boundary_name, props, "Conducting Plate")
return _create_boundary(bound)
bound = self._create_boundary(boundary_name, props, "Conducting Plate")
return bound

def assign_conducting_plate_with_thickness(
self,
Expand Down
Loading

0 comments on commit b48776e

Please sign in to comment.