I would like to write the electric field values and coordinates of each mesh element into a file. Using AEDT API, I can do this by:
# project_name, design_name, volume_name, and file_path are variables
oProject = oDesktop.SetActiveProject(project_name)
oDesign = oProject.SetActiveDesign(design_name)
oModule = oDesign.GetModule("FieldsReporter")
oModule.EnterQty("E")
oModule.EnterVol(volume_name)
oModule.CalcOp("Value")
oModule.CalculatorWrite(file_path,
[
"Solution:=" , "MySetupAuto : LastAdaptive"
], [])
How is this implemented in PyAEDT? Right now, I combine PyAEDT with AEDT API, but I would prefer to do everything with PyAEDT.
Initially, I tried to define a new calculator expression, thinking I can use aedtapp.post.fields_calculator.write()
afterwards.
my_expression = {
"name": "efield_volume",
"description": "Electric field in a volume",
"design_type": ["Maxwell 3D"],
"fields_type": ["Fields"],
"solution_type": "",
"primary_sweep": "Freq",
"assignment": "",
"assignment_type": ["Solid"],
"operations": [
"NameOfExpression('<Ex,Ey,Ez>')",
"EnterVol('assignment')",
"Operation('Value')"
],
"report" : ["Data Table"]
}
new_expression = aedtapp.post.fields_calculator.add_expression(my_expression, assignment=volume_name)
However, I get a PyAEDT error.
PyAEDT ERROR: **************************************************************
PyAEDT ERROR: File "file_name.py", line 48, in <module>
PyAEDT ERROR: new_expression = aedtapp.post.fields_calculator.add_expression(my_expression, assignment=volume_name)
PyAEDT ERROR: File "~\AppData\Roaming\.pyaedt_env\3_10\lib\site-packages\ansys\aedt\core\visualization\post\fields_calculator.py", line 249, in add_expression
PyAEDT ERROR: self.ofieldsreporter.LoadNamedExpressions(
PyAEDT ERROR: AEDT API Error on add_expression
PyAEDT ERROR: Last Electronics Desktop Message - [error] script macro error: abnormal script termination. (01:53:26 pm jan 09, 2025)
PyAEDT ERROR: Method arguments:
PyAEDT ERROR: calculation = {'name': 'efield_voltage_write', 'description': 'Electric field in a volume', 'design_type': ['Maxwell 3D'], 'fields_type': ['Fields'], 'solution_type': '', 'primary_sweep': 'Freq', 'assignment': 'Region', 'assignment_type': ['Solid
PyAEDT ERROR: '], 'operations': ["NameOfExpression('<Ex,Ey,Ez>')", "EnterVol('Region')", "Operation('Value')"], 'report': ['Data Table'], 'dependent_expressions': []}
PyAEDT ERROR: assignment = Region
PyAEDT ERROR: **************************************************************