Skip to content

Commit

Permalink
Fix examples (#4076)
Browse files Browse the repository at this point in the history
* Fix material override Mechanical example

* fixed bug in ClearMessages

* fixed bug in ClearMessages

---------

Co-authored-by: maxcapodi78 <Shark78>
  • Loading branch information
Samuelopez-ansys authored Jan 15, 2024
1 parent 8539120 commit 3ee0369
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 24 deletions.
8 changes: 0 additions & 8 deletions examples/02-HFSS/Array.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,11 +148,3 @@
# the Theta scan and Phi scan.

ffdata.polar_plot_3d(farfield_quantity='RealizedGain')

###############################################################################
# Analyze and release
# ~~~~~~~~~~~~~~~~~~~~
# Uncomment the ``hfss.analyze`` command if you want to analyze the
# model and release AEDT.

hfss.release_desktop()
31 changes: 16 additions & 15 deletions examples/02-HFSS/Waveguide_Filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@
zstart = "l1/2 - t/2" # Odd number of cavities, even number of irises.
is_even = False


###############################################################################
# Draw parametric waveguide filter
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Expand All @@ -99,15 +100,16 @@

def place_iris(zpos, dz, n):
w_str = "w" + str(n) # Iris width parameter as a string.
this_name = "iris_a_"+str(n) # Iris object name in the HFSS project.
this_name = "iris_a_" + str(n) # Iris object name in the HFSS project.
iris = [] # Return a list of the two objects that make up the iris.
if this_name in hfss.modeler.object_names:
this_name = this_name.replace("a", "c")
iris.append(hfss.modeler.create_box(['-b/2', '-a/2', zpos], ['(b - ' + w_str + ')/2', 'a', dz],
name=this_name, matname="silver"))
iris.append(hfss.modeler.create_box(['-b/2', '-a/2', zpos], ['(b - ' + w_str + ')/2', 'a', dz],
name=this_name, matname="silver"))
iris.append(iris[0].mirror([0, 0, 0], [1, 0, 0], duplicate=True))
return iris


###############################################################################
# Place irises
# ~~~~~~~~~~~~
Expand Down Expand Up @@ -164,7 +166,7 @@ def place_iris(zpos, dz, n):
ports = []
for n, z in enumerate(wg_z):
face_id = hfss.modeler.get_faceid_from_position([0, 0, z], obj_name="waveguide")
u_start = [0, hfss.variable_manager["u_start"].evaluated_value, z]
u_start = [0, hfss.variable_manager["u_start"].evaluated_value, z]
u_end = [0, hfss.variable_manager["u_end"].evaluated_value, z]

ports.append(hfss.wave_port(face_id, integration_line=[u_start, u_end], name="P" + str(n + 1), renormalize=False))
Expand All @@ -178,17 +180,16 @@ def place_iris(zpos, dz, n):
# through the resonant structure while the mesh is refined.

setup = hfss.create_setup("Setup1", setuptype="HFSSDriven",
MultipleAdaptiveFreqsSetup=['9.8GHz', '10.2GHz'],
MaximumPasses=5)
MultipleAdaptiveFreqsSetup=['9.8GHz', '10.2GHz'],
MaximumPasses=5)

setup.create_frequency_sweep(
unit="GHz",
sweepname="Sweep1",
freqstart=9.5,
freqstop=10.5,
sweep_type="Interpolating",
)

)

#################################################################################
# Solve the project with two tasks.
Expand Down Expand Up @@ -217,13 +218,13 @@ def place_iris(zpos, dz, n):
# The following command generates a field plot in HFSS and uses PyVista
# to plot the field in Jupyter.

plot=hfss.post.plot_field(quantity="Mag_E",
objects_list=["Global:XZ"],
plot_type="CutPlane",
setup_name=hfss.nominal_adaptive,
intrinsics={"Freq":"9.8GHz", "Phase":"0deg"},
export_path=hfss.working_directory,
show=False)
plot = hfss.post.plot_field(quantity="Mag_E",
object_list=["Global:XZ"],
plot_type="CutPlane",
setup_name=hfss.nominal_adaptive,
intrinsics={"Freq": "9.8GHz", "Phase": "0deg"},
export_path=hfss.working_directory,
show=False)

###############################################################################
# Save and close the desktop
Expand Down
3 changes: 2 additions & 1 deletion examples/06-Multiphysics/Hfss_Mechanical.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
hfss = pyaedt.Hfss(projectname=project_temp_name, specified_version=version, non_graphical=non_graphical,
new_desktop_session=True)
pin_names = hfss.excitations
hfss.change_material_override(True)

###############################################################################
# Start Circuit
Expand Down Expand Up @@ -114,7 +115,7 @@

mech = pyaedt.Mechanical()
mech.copy_solid_bodies_from(hfss)

mech.change_material_override(True)

###############################################################################
# Get losses from HFSS and assign convection to Mechanical
Expand Down
16 changes: 16 additions & 0 deletions pyaedt/aedt_logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ def __init__(self, level=logging.DEBUG, filename=None, to_stdout=False):
self._std_out_handler = None
self._files_handlers = []
self.level = level
self._non_graphical = None
self.filename = filename or settings.logger_file_path
self._messages = []
settings.logger_file_path = self.filename
Expand Down Expand Up @@ -649,6 +650,8 @@ def clear_messages(self, proj_name=None, des_name=None, level=2):
>>> hfss.clear_messages(proj_name="", des_name="", level=3)
"""
if self.non_graphical:
return
if proj_name is None:
proj_name = self.project_name
if des_name is None:
Expand All @@ -658,6 +661,19 @@ def clear_messages(self, proj_name=None, des_name=None, level=2):
except:
pass

@property
def non_graphical(self):
"""Check if desktop is graphical or not.
Returns
-------
bool
"""
if self._non_graphical is None and self._desktop:
self._non_graphical = self._desktop.GetIsNonGraphical()

return self._non_graphical

@property
def oproject(self):
"""Project object.
Expand Down
2 changes: 2 additions & 0 deletions pyaedt/desktop.py
Original file line number Diff line number Diff line change
Expand Up @@ -1450,6 +1450,8 @@ def release_desktop(self, close_projects=True, close_on_exit=True):
except: # pragma: no cover
self.logger.warning("Failed to close Project {}".format(project))
result = _close_aedt_application(close_on_exit, self.aedt_process_id, self.is_grpc_api)
if result:
self.logger.info("Desktop has been released")
del _desktop_sessions[self.aedt_process_id]
props = [a for a in dir(self) if not a.startswith("__")]
for a in props:
Expand Down

0 comments on commit 3ee0369

Please sign in to comment.