Skip to content

Commit

Permalink
Add export option to export_file and export_on_grid (#4390)
Browse files Browse the repository at this point in the history
  • Loading branch information
Samuelopez-ansys committed Mar 21, 2024
1 parent 66af817 commit ddb5cf0
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 7 deletions.
14 changes: 14 additions & 0 deletions _unittest_solvers/test_00_analyze.py
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,20 @@ def test_03e_icepak_ExportFLDFil(self):
sample_points_lists=[[0, 0, 0], [3, 6, 8], [4, 7, 9]],
)
assert os.path.exists(fld_file_2)
cs = self.icepak_app.modeler.create_coordinate_system()
fld_file_3 = os.path.join(self.local_scratch.path, "test_fld_3.fld")
self.icepak_app.post.export_field_file(
quantity_name="Temp",
solution=self.icepak_app.nominal_sweep,
variation_dict=self.icepak_app.available_variations.nominal_w_values_dict,
filename=fld_file_3,
obj_list="box",
sample_points_lists=[[0, 0, 0], [3, 6, 8], [4, 7, 9]],
reference_coordinate_system=cs.name,
export_in_si_system=False,
export_field_in_reference=False,
)
assert os.path.exists(fld_file_3)

def test_04a_3dl_generate_mesh(self):
assert self.hfss3dl_solve.mesh.generate_mesh("Setup1")
Expand Down
84 changes: 77 additions & 7 deletions pyaedt/modules/PostProcessor.py
Original file line number Diff line number Diff line change
Expand Up @@ -2498,13 +2498,17 @@ def export_field_file_on_grid(
variation_dict=None,
filename=None,
gridtype="Cartesian",
grid_center=[0, 0, 0],
grid_start=[0, 0, 0],
grid_stop=[0, 0, 0],
grid_step=[0, 0, 0],
grid_center=None,
grid_start=None,
grid_stop=None,
grid_step=None,
isvector=False,
intrinsics=None,
phase=None,
export_with_sample_points=True,
reference_coordinate_system="Global",
export_in_si_system=True,
export_field_in_reference=True,
):
"""Use the field calculator to create a field file on a grid based on a solution and variation.
Expand Down Expand Up @@ -2542,6 +2546,18 @@ def export_field_file_on_grid(
calculation. The default is ``None``.
phase : str, optional
Field phase. The default is ``None``.
export_with_sample_points : bool, optional
Whether to include the sample points in the file to export.
The default is ``True``.
reference_coordinate_system : str, optional
Reference coordinate system in the file to export.
The default is ``"Global"``.
export_in_si_system : bool, optional
Whether the provided sample points are defined in the SI system or model units.
The default is ``True``.
export_field_in_reference : bool, optional
Whether to export the field in reference coordinate system.
The default is ``True``.
Returns
-------
Expand All @@ -2567,6 +2583,14 @@ def export_field_file_on_grid(
>>> path = "Field.fld"
>>> hfss.post.export_field_file_on_grid("E", setup, var, path, 'Cartesian', [0, 0, 0], intrinsics="8GHz")
"""
if grid_step is None:
grid_step = [0, 0, 0]
if grid_start is None:
grid_start = [0, 0, 0]
if grid_stop is None:
grid_stop = [0, 0, 0]
if grid_center is None:
grid_center = [0, 0, 0]
self.logger.info("Exporting %s field. Be patient", quantity_name)
if not solution:
solution = self._app.existing_analysis_sweeps[0]
Expand Down Expand Up @@ -2629,14 +2653,26 @@ def export_field_file_on_grid(
else:
variation.append("0deg")

export_options = [
"NAME:ExportOption",
"IncludePtInOutput:=",
export_with_sample_points,
"RefCSName:=",
reference_coordinate_system,
"PtInSI:=",
export_in_si_system,
"FieldInRefCS:=",
export_field_in_reference,
]

self.ofieldsreporter.ExportOnGrid(
filename,
grid_start_wu,
grid_stop_wu,
grid_step_wu,
solution,
variation,
True,
export_options,
gridtype,
grid_center,
False,
Expand All @@ -2659,6 +2695,9 @@ def export_field_file(
sample_points_file=None,
sample_points_lists=None,
export_with_sample_points=True,
reference_coordinate_system="Global",
export_in_si_system=True,
export_field_in_reference=True,
):
"""Use the field calculator to create a field file based on a solution and variation.
Expand Down Expand Up @@ -2692,6 +2731,15 @@ def export_field_file(
export_with_sample_points : bool, optional
Whether to include the sample points in the file to export.
The default is ``True``.
reference_coordinate_system : str, optional
Reference coordinate system in the file to export.
The default is ``"Global"``.
export_in_si_system : bool, optional
Whether the provided sample points are defined in the SI system or model units.
The default is ``True``.
export_field_in_reference : bool, optional
Whether to export the field in reference coordinate system.
The default is ``True``.
Returns
-------
Expand Down Expand Up @@ -2758,25 +2806,47 @@ def export_field_file(
self.ofieldsreporter.CalcOp("Value")
self.ofieldsreporter.CalculatorWrite(filename, ["Solution:=", solution], variation)
elif sample_points_file:
export_options = [
"NAME:ExportOption",
"IncludePtInOutput:=",
export_with_sample_points,
"RefCSName:=",
reference_coordinate_system,
"PtInSI:=",
export_in_si_system,
"FieldInRefCS:=",
export_field_in_reference,
]
self.ofieldsreporter.ExportToFile(
filename,
sample_points_file,
solution,
variation,
export_with_sample_points,
export_options,
)
else:
sample_points_file = os.path.join(self._app.working_directory, "temp_points.pts")
with open_file(sample_points_file, "w") as f:
f.write("Unit={}\n".format(self.model_units))
for point in sample_points_lists:
f.write(" ".join([str(i) for i in point]) + "\n")
export_options = [
"NAME:ExportOption",
"IncludePtInOutput:=",
export_with_sample_points,
"RefCSName:=",
reference_coordinate_system,
"PtInSI:=",
export_in_si_system,
"FieldInRefCS:=",
export_field_in_reference,
]
self.ofieldsreporter.ExportToFile(
filename,
sample_points_file,
solution,
variation,
export_with_sample_points,
export_options,
)

if os.path.exists(filename):
Expand Down

0 comments on commit ddb5cf0

Please sign in to comment.