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 pythoncom issue #3900

Merged
merged 5 commits into from
Nov 23, 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
9 changes: 7 additions & 2 deletions _unittest/test_20_HFSS.py
Original file line number Diff line number Diff line change
Expand Up @@ -1481,8 +1481,13 @@ def test_63_set_phase_center_per_port(self):
name="Wave2",
renormalize=False,
)
assert self.aedtapp.set_phase_center_per_port()
assert self.aedtapp.set_phase_center_per_port(["Global", "Global"])
if self.aedtapp.desktop_class.is_grpc_api:
assert self.aedtapp.set_phase_center_per_port()
assert self.aedtapp.set_phase_center_per_port(["Global", "Global"])
else:
assert not self.aedtapp.set_phase_center_per_port()
assert not self.aedtapp.set_phase_center_per_port(["Global", "Global"])

assert not self.aedtapp.set_phase_center_per_port(["Global"])
assert not self.aedtapp.set_phase_center_per_port("Global")

Expand Down
2 changes: 1 addition & 1 deletion _unittest/test_98_Icepak.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ def test_12a_AssignMeshOperation(self):

@pytest.mark.skipif(config["use_grpc"], reason="GRPC usage leads to SystemExit.")
def test_12b_failing_AssignMeshOperation(self):
assert not self.aedtapp.mesh.assign_mesh_region("N0C0MP", 1, is_submodel=True)
assert self.aedtapp.mesh.assign_mesh_region("N0C0MP", 1, is_submodel=True)
test = self.aedtapp.mesh.assign_mesh_region(["USB_ID"], 1)
b = self.aedtapp.modeler.create_box([0, 0, 0], [1, 1, 1])
b.model = False
Expand Down
2 changes: 2 additions & 0 deletions pyaedt/desktop.py
Original file line number Diff line number Diff line change
Expand Up @@ -833,6 +833,8 @@ def _init_dotnet(
): # pragma: no cover
import pythoncom

pythoncom.CoInitialize()

if is_linux:
raise Exception(
"PyAEDT supports COM initialization in Windows only. To use in Linux, upgrade to AEDT 2022 R2 or later."
Expand Down
2 changes: 1 addition & 1 deletion pyaedt/generic/configurations.py
Original file line number Diff line number Diff line change
Expand Up @@ -1143,7 +1143,7 @@ def _export_general(self, dict_out):
dict_out["general"]["date"] = datetime.now().strftime("%d/%m/%Y %H:%M:%S")
dict_out["general"]["object_mapping"] = {}
dict_out["general"]["output_variables"] = {}
if self._app.output_variables:
if list(self._app.output_variables):
oo_out = os.path.join(tempfile.gettempdir(), generate_unique_name("oo") + ".txt")
self._app.ooutput_variable.ExportOutputVariables(oo_out)
with open(oo_out, "r") as f:
Expand Down
2 changes: 1 addition & 1 deletion pyaedt/hfss.py
Original file line number Diff line number Diff line change
Expand Up @@ -5947,7 +5947,7 @@ def set_phase_center_per_port(self, coordinate_system=None):
"""

if not self.desktop_class.is_grpc_api: # pragma: no cover
self.hfss.logger.warning("Set phase center is not supported by AEDT COM API. Set phase center manually")
self.logger.warning("Set phase center is not supported by AEDT COM API. Set phase center manually")
return False

port_names = []
Expand Down
83 changes: 12 additions & 71 deletions pyaedt/icepak.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
from pyaedt.modules.Boundary import BoundaryObject
from pyaedt.modules.Boundary import NativeComponentObject
from pyaedt.modules.Boundary import NetworkObject
from pyaedt.modules.Boundary import _create_boundary
from pyaedt.modules.monitor_icepak import Monitor


Expand Down Expand Up @@ -630,14 +631,7 @@ def create_conduting_plate(
)
props["Shell Conduction"] = shell_conduction
bound = BoundaryObject(self, bc_name, props, "Conducting Plate")
try:
if bound.create():
self._boundaries[bound.name] = bound
return bound
else: # pragma : no cover
raise SystemExit
except (GrpcApiError, SystemExit):
return None
return _create_boundary(bound)

@pyaedt_function_handler()
def create_source_power(
Expand Down Expand Up @@ -727,14 +721,7 @@ def create_source_power(
props["Temperature"] = temperature
props["Radiation"] = OrderedDict({"Radiate": radiate})
bound = BoundaryObject(self, source_name, props, "SourceIcepak")
try:
if bound.create():
self._boundaries[bound.name] = bound
return bound
else: # pragma : no cover
raise SystemExit
except (GrpcApiError, SystemExit):
return None
return _create_boundary(bound)

@pyaedt_function_handler()
def create_network_block(
Expand Down Expand Up @@ -3486,14 +3473,7 @@ def assign_stationary_wall(
props["External Radiation Reference Temperature"] = ext_surf_rad_ref_temp
props["External Radiation View Factor"] = ext_surf_rad_view_factor
bound = BoundaryObject(self, name, props, "Stationary Wall")
try:
if bound.create():
self._boundaries[bound.name] = bound
return bound
else: # pragma : no cover
raise SystemExit
except (GrpcApiError, SystemExit):
return None
return _create_boundary(bound)

@pyaedt_function_handler()
def assign_stationary_wall_with_heat_flux(
Expand Down Expand Up @@ -4200,14 +4180,7 @@ def assign_solid_block(
boundary_name = generate_unique_name("Block")

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

@pyaedt_function_handler
def assign_hollow_block(
Expand Down Expand Up @@ -4335,14 +4308,7 @@ def assign_hollow_block(
boundary_name = generate_unique_name("Block")

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

@pyaedt_function_handler()
def get_fans_operating_point(self, export_file=None, setup_name=None, timestep=None, design_variation=None):
Expand Down Expand Up @@ -4827,11 +4793,7 @@ def assign_mass_flow_free_opening(
)

@pyaedt_function_handler()
def assign_symmetry_wall(
self,
geometry,
boundary_name=None,
):
def assign_symmetry_wall(self, geometry, boundary_name=None):
"""Assign symmetry wall boundary condition.

Parameters
Expand Down Expand Up @@ -4864,14 +4826,7 @@ def assign_symmetry_wall(
props["Objects"] = geometry

bound = BoundaryObject(self, boundary_name, props, "Symmetry Wall")
try:
if bound.create():
self._boundaries[bound.name] = bound
return bound
else: # pragma : no cover
raise SystemExit
except (GrpcApiError, SystemExit):
return None
return _create_boundary(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 @@ -5044,11 +4999,11 @@ def assign_recirculation_opening(self, face_list, extract_face, thermal_specific
if not len(face_list) == 2:
self.logger.error("Recirculation boundary condition must be assigned to two faces.")
return False
if conductance_external_temperature is not None and thermal_specification is not "Conductance":
if conductance_external_temperature is not None and thermal_specification != "Conductance":
self.logger.warning(
'``conductance_external_temperature`` does not have any effect unless the ``thermal_specification`` '
'is ``"Conductance"``.')
if conductance_external_temperature is not None and thermal_specification is not "Conductance":
if conductance_external_temperature is not None and thermal_specification != "Conductance":
self.logger.warning(
'``conductance_external_temperature`` must be specified when ``thermal_specification`` '
'is ``"Conductance"``. Setting ``conductance_external_temperature`` to ``"AmbientTemp"``.')
Expand Down Expand Up @@ -5122,14 +5077,7 @@ def assign_recirculation_opening(self, face_list, extract_face, thermal_specific
boundary_name = generate_unique_name("Recirculating")

bound = BoundaryObject(self, boundary_name, props, "Recirculating")
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
return _create_boundary(bound)

@pyaedt_function_handler()
def assign_blower_type1(self, faces, inlet_face, fan_curve_pressure, fan_curve_flow, blower_power="0W", blade_rpm=0,
Expand Down Expand Up @@ -5281,11 +5229,4 @@ def _assign_blower(self, props, faces, inlet_face, fan_curve_flow_unit, fan_curv
if not boundary_name:
boundary_name = generate_unique_name("Blower")
bound = BoundaryObject(self, boundary_name, props, "Blower")
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
return _create_boundary(bound)
11 changes: 11 additions & 0 deletions pyaedt/modules/Boundary.py
Original file line number Diff line number Diff line change
Expand Up @@ -4506,3 +4506,14 @@
node_args[k] = val

return node_args


def _create_boundary(bound):
try:
if bound.create():
bound._app._boundaries[bound.name] = bound
return bound
else: # pragma : no cover
raise Exception

Check warning on line 4517 in pyaedt/modules/Boundary.py

View check run for this annotation

Codecov / codecov/patch

pyaedt/modules/Boundary.py#L4517

Added line #L4517 was not covered by tests
except Exception: # pragma: no cover
return None
Loading