• 易迪拓培训,专注于微波、射频、天线设计工程师的培养
首页 > HFSS > HFSS help > User Defined Outputs: Messaging Methods

HFSS15: User Defined Outputs: Messaging Methods

录入:edatop.com     点击:

Messaging methods are provided to convey additional information to the user from any of the UDOs methods. The Compute function is the one typically location where such use is anticipated. Any message sent via these functions are displayed in the application’s message window using the appropriate icon.

These functions can also be used for debugging purposes.

• AddErrorMessage(string): Call this method to convey an error condition to the user.

• AddWarningMessage(string): Call this method to convey a warning message: typically used for conditions that are not ideal but can be tolerated by the script.

• AddInfoMessage(string): Call this method to convey an informational message to the user. This is the call to use when outputting messages for debugging purposes.

##############################################################

# Imports

##############################################################

from Ansys.Ansoft.ModulePluginDotNet.Common.API import *

from Ansys.Ansoft.ModulePluginDotNet.Common.API.Interfaces import *

from Ansys.Ansoft.ModulePluginDotNet.UDO.API.Interfaces import *

from Ansys.Ansoft.ModulePluginDotNet.UDO.API.Data import *

class UDOExtension(IUDOPluginExtension):

def __init__(self):

pass

 

#--- IDA IUDOPluginExtension ------------------------

def GetUDSName(self):

return "MinMaxAvg"

 

#--- ISA IUDOPluginExtension ------------------------

def GetUDSDescription(self):

return "Sample UDO for dimension reducing quantities"

 

 

#--- ISA IUDOPluginExtension ------------------------

# Returns list of category names

def GetCategoryNames(self):

return ["UDOOutputs"]

#--- ISA IUDOPluginExtension ------------------------

# returns a list of quantity names for the supplied category name

def GetQuantityNames(self, catName):

if catName == "UDOOutputs":

return ["min_val", "max_val", "avg_val"]

else:

return []

 

#--- ISA IUDOPluginExtension ------------------------

# Returns an instance of QuantityInfo for the qtyName supplied or None if such a

# quantity could not be found

def GetQuantityInfo(self, qtyName):

# All the quantities we have are simple doubles

# we can leave them unitless

return QuantityInfo(Constants.kDoubleParamStr)

 

#--- ISA IUDOPluginExtension ------------------------

# Returns list of UDSParams and list of dynamic properties

# Adds setup time properties to the propList

def GetInputUDSParams(self, udsParams, propList, userSelectedDynamicProbes):

 

# Add the probes. We need only one double quantity

param1 = UDSProbeParams("probe1",

"double quantity probe",

Constants.kDoubleParamStr,

"", "")

udsParams.Add(param1)

 

# Add the properties we want the user to supply

# In this case, we will ask for a start/end range for

# X parameters. Since we cannot reasonably provide defaults

# as we have no idea what the sweep limits will be, we will

# also ask if the limits are to be activated.

prop = propList.AddNumberProperty("X Min", "0")

prop.Description = "Start X value to consider"

 

prop = propList.AddNumberProperty("X Max", "1")

prop.Description = "End X value to consider"

 

# For menus, the first option is the default.

prop = propList.AddMenuProperty("Activate X Limits", ["No", "Yes"])

prop.Description = "Activate X range"

 

return True

#--- ISA IUDOPluginExtension ------------------------

# Returns list of UDSParams and list of dynamic properties

# output UDSDynamicProbeCollection probes

def GetDynamicProbes(self, probes):

pass

 

#--- ISA IUDOPluginExtension ------------------------

# Returns list of sweeps names

# We have no sweeps as we reduce them.

def GetUDSSweepNames(self):

return []

 

 

#---------------------------------------------------------------------------------

# IUserDefinedSolutionHandle API implementation.

# Calculates output values and sets them using IUDSInputData/IUDSOutputData API.

def Compute(self, inData, outData, propList, progMon):

 

# Get the sweeps associated with the probe and validate

# use the probe name that we had defined earlier

sweeps = inData.GetSweepNamesForProbe("probe1")

if( sweeps == None or sweeps.Count > 1):

AddErrorMessage(self.GetName() + "Unexpected sweep count 0 or > 1 in Compute")

return False

 

 

# Get the data associated with our probe

probeData = inData.GetDoubleProbeData("probe1")

sweepData = inData.GetSweepsDataForProbe("probe1", sweeps[0])

 

# Get the user specified properties.

# Note that ideally, these "X Min" etc names should be written as

# constant members and referred to in both the GetInputUDSParams

# and in Compute to reduce the change of typos.

useXRangeProp = propList.GetMenuProperty("Activate X Limits").SelectedMenuChoice

xRangeStart = propList.GetNumberProperty("X Min").ValueSI

xRangeEnd = propList.GetNumberProperty("X Max").ValueSI

 

# At this stage, one can look at the RequestedQuantities and create

# a dictionary to later check against. However, I am simply computing

# all the quantities.

minVal = 0

maxVal = 0

avgVal = 0

 

# Check if we need to perform range computation

if useXRangeProp == "Yes":

seenAny = False

avgSum = 0

count = 0

 

# zip is used since we also need to pull in sweep data

# an index and the array notation could also have been used

for probeVal, sweepVal in zip(probeData, sweepData):

if sweepVal < xRangeStart or sweepVal > xRangeEnd:

pass

 

# Note that in a better written script, this code would be

# refactored into its own function to avoid code

# duplication

if not seenAny:

minVal = probeVal

maxVal = probeVal

avgSum = probeVal

seenAny = True

count = 1

else:

if probeVal < minVal:

minVal = probeVal

 

if probeVal > maxVal:

maxVal = probeVal

 

avgSum += probeVal

count += 1

 

if seenAny:

avgVal = avgSum/count

 

else:

seenAny = False

avgSum = 0

for probeVal in probeData:

if not seenAny:

minVal = probeVal

maxVal = probeVal

avgSum = probeVal

seenAny = True

else:

if probeVal < minVal:

minVal = probeVal

 

if probeVal > maxVal:

maxVal = probeVal

 

avgSum += probeVal

 

if seenAny:

avgVal = avgSum/probeData.Count

 

# Finally set the output values. Note that these are always set as

# lists even if we have just one item.

outData.SetDoubleQuantityData("min_val", [minVal])

outData.SetDoubleQuantityData("max_val", [maxVal])

outData.SetDoubleQuantityData("avg_val", [avgVal])

 

# And we are done.

return True

HFSS 学习培训课程套装,专家讲解,视频教学,帮助您全面系统地学习掌握HFSS

上一篇:UDSDynamicProbes Class
下一篇:Upgrade Version in History Tree Shortcut Menu

HFSS视频培训课程推荐详情>>
HFSS教程推荐

  网站地图