Skip to content

Commit

Permalink
args
Browse files Browse the repository at this point in the history
  • Loading branch information
gmalinve committed Apr 10, 2024
1 parent 4444f50 commit 126a6c8
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 38 deletions.
24 changes: 13 additions & 11 deletions _unittest_solvers/test_00_analyze.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,11 +185,12 @@ def test_02_hfss_export_results(self, hfss_app):
assert len(exported_files) > 0

fld_file1 = os.path.join(self.local_scratch.path, "test_fld_hfss1.fld")
assert hfss_app.post.export_field_file(quantity="Mag_E", file_name=fld_file1, objects="Box1", intrinsics="1GHz",
phase="5deg")
assert hfss_app.post.export_field_file(quantity="Mag_E", output_dir=fld_file1, assignment="Box1",
intrinsics="1GHz", phase="5deg")
assert os.path.exists(fld_file1)
fld_file2 = os.path.join(self.local_scratch.path, "test_fld_hfss2.fld")
assert hfss_app.post.export_field_file(quantity="Mag_E", file_name=fld_file2, objects="Box1", intrinsics="1GHz")
assert hfss_app.post.export_field_file(quantity="Mag_E", output_dir=fld_file2, assignment="Box1",
intrinsics="1GHz")
assert os.path.exists(fld_file2)

def test_03a_icepak_analyze_and_export_summary(self):
Expand Down Expand Up @@ -291,26 +292,26 @@ def test_03d_icepak_eval_tempc(self):
def test_03e_icepak_ExportFLDFil(self):
fld_file = os.path.join(self.local_scratch.path, "test_fld.fld")
self.icepak_app.post.export_field_file(quantity="Temp", solution=self.icepak_app.nominal_sweep, variations={},
file_name=fld_file, objects="box")
output_dir=fld_file, assignment="box")
assert os.path.exists(fld_file)
fld_file_1 = os.path.join(self.local_scratch.path, "test_fld_1.fld")
sample_points_file = os.path.join(local_path, "example_models", test_subfolder, "temp_points.pts")
self.icepak_app.post.export_field_file(quantity="Temp", solution=self.icepak_app.nominal_sweep,
variations=self.icepak_app.available_variations.nominal_w_values_dict,
file_name=fld_file_1, objects="box",
output_dir=fld_file_1, assignment="box",
sample_points_file=sample_points_file)
assert os.path.exists(fld_file_1)
fld_file_2 = os.path.join(self.local_scratch.path, "test_fld_2.fld")
self.icepak_app.post.export_field_file(quantity="Temp", solution=self.icepak_app.nominal_sweep,
variations=self.icepak_app.available_variations.nominal_w_values_dict,
file_name=fld_file_2, objects="box",
output_dir=fld_file_2, assignment="box",
sample_points=[[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="Temp", solution=self.icepak_app.nominal_sweep,
variations=self.icepak_app.available_variations.nominal_w_values_dict,
file_name=fld_file_3, objects="box",
output_dir=fld_file_3, assignment="box",
sample_points=[[0, 0, 0], [3, 6, 8], [4, 7, 9]],
reference_coordinate_system=cs.name, export_in_si_system=False,
export_field_in_reference=False)
Expand Down Expand Up @@ -415,17 +416,18 @@ def test_07_export_maxwell_fields(self, m3dtransient):
m3dtransient.analyze(m3dtransient.active_setup, num_cores=2)
fld_file_3 = os.path.join(self.local_scratch.path, "test_fld_3.fld")
assert m3dtransient.post.export_field_file(quantity="Mag_B", solution=m3dtransient.nominal_sweep, variations={},
file_name=fld_file_3, objects="Coil_A2", objects_type="Surf",
output_dir=fld_file_3, assignment="Coil_A2", objects_type="Surf",
intrinsics="10ms")
assert os.path.exists(fld_file_3)
fld_file_4 = os.path.join(self.local_scratch.path, "test_fld_4.fld")
assert not m3dtransient.post.export_field_file(quantity="Mag_B", solution=m3dtransient.nominal_sweep,
variations=m3dtransient.available_variations.nominal_w_values_dict,
file_name=fld_file_4, objects="Coil_A2", objects_type="invalid")
output_dir=fld_file_4, assignment="Coil_A2",
objects_type="invalid")
setup = m3dtransient.setups[0]
m3dtransient.setups[0].delete()
assert not m3dtransient.post.export_field_file(quantity="Mag_B", variations={}, file_name=fld_file_4,
objects="Coil_A2")
assert not m3dtransient.post.export_field_file(quantity="Mag_B", variations={}, output_dir=fld_file_4,
assignment="Coil_A2")

new_setup = m3dtransient.create_setup(name=setup.name, setup_type=setup.setuptype)
new_setup.props = setup.props
Expand Down
2 changes: 1 addition & 1 deletion examples/03-Maxwell/Maxwell2D_Electrostatic.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@
# Export field line traces plot.
# For field lint traces plot, the export file format is ``.fldplt``.

M2D.post.export_field_plot(plot_name="LineTracesTest", file_path=M2D.toolkit_directory, file_format="fldplt")
M2D.post.export_field_plot(plot_name="LineTracesTest", output_dir=M2D.toolkit_directory, file_format="fldplt")

##########################################################
# Export a field plot to an image file
Expand Down
49 changes: 23 additions & 26 deletions pyaedt/modules/PostProcessor.py
Original file line number Diff line number Diff line change
Expand Up @@ -2716,8 +2716,8 @@ def export_field_file_on_grid(
@pyaedt_function_handler(
quantity_name="quantity",
variation_dict="variations",
filename="file_name",
obj_list="objects",
filename="output_dir",
obj_list="assignment",
obj_type="objects_type",
sample_points_lists="sample_points",
)
Expand All @@ -2726,8 +2726,8 @@ def export_field_file(
quantity,
solution=None,
variations=None,
file_name=None,
objects="AllObjects",
output_dir=None,
assignment="AllObjects",
objects_type="Vol",
intrinsics=None,
phase=None,
Expand All @@ -2750,10 +2750,10 @@ def export_field_file(
variations : dict, optional
Dictionary of all variation variables with their values.
The default is ``None``.
file_name : str, optional
output_dir : str, optional
Full path and name to save the file to.
The default is ``None`` which export file in working_directory.
objects : str, optional
assignment : str, optional
List of objects to export. The default is ``"AllObjects"``.
objects_type : str, optional
Type of objects to export. The default is ``"Vol"``.
Expand Down Expand Up @@ -2803,12 +2803,12 @@ def export_field_file(
self.logger.error("There are no existing sweeps.")
return False
solution = self._app.existing_analysis_sweeps[0]
if not file_name:
if not output_dir:
appendix = ""
ext = ".fld"
file_name = os.path.join(self._app.working_directory, solution.replace(" : ", "_") + appendix + ext)
output_dir = os.path.join(self._app.working_directory, solution.replace(" : ", "_") + appendix + ext)
else:
file_name = file_name.replace("//", "/").replace("\\", "/")
output_dir = output_dir.replace("//", "/").replace("\\", "/")
self.ofieldsreporter.CalcStack("clear")
try:
self.ofieldsreporter.EnterQty(quantity)
Expand Down Expand Up @@ -2837,14 +2837,14 @@ def export_field_file(
variation.append("0deg")
if not sample_points_file and not sample_points:
if objects_type == "Vol":
self.ofieldsreporter.EnterVol(objects)
self.ofieldsreporter.EnterVol(assignment)
elif objects_type == "Surf":
self.ofieldsreporter.EnterSurf(objects)
self.ofieldsreporter.EnterSurf(assignment)
else:
self.logger.error("No correct choice.")
return False
self.ofieldsreporter.CalcOp("Value")
self.ofieldsreporter.CalculatorWrite(file_name, ["Solution:=", solution], variation)
self.ofieldsreporter.CalculatorWrite(output_dir, ["Solution:=", solution], variation)
elif sample_points_file:
export_options = [
"NAME:ExportOption",
Expand All @@ -2858,7 +2858,7 @@ def export_field_file(
export_field_in_reference,
]
self.ofieldsreporter.ExportToFile(
file_name,
output_dir,
sample_points_file,
solution,
variation,
Expand All @@ -2882,32 +2882,29 @@ def export_field_file(
export_field_in_reference,
]
self.ofieldsreporter.ExportToFile(
file_name,
output_dir,
sample_points_file,
solution,
variation,
export_options,
)

if os.path.exists(file_name):
return file_name
if os.path.exists(output_dir):
return output_dir
return False # pragma: no cover

@pyaedt_function_handler(plotname="plot_name", filepath="file_path", filename="file_name")
def export_field_plot(self, plot_name, file_path, file_name="", file_format="aedtplt"):
@pyaedt_function_handler(plotname="plot_name", filepath="output_dir", filename="file_name")
def export_field_plot(self, plot_name, output_dir, file_name="", file_format="aedtplt"):
"""Export a field plot.
Parameters
----------
plot_name : str
Name of the plot.
file_path : str
output_dir : str
Path for saving the file.
file_name : str, optional
Name of the file. The default is ``""``, in which case a name is automatically assigned.
file_format : str, optional
Name of the file extension. The default is ``"aedtplt"``. Options are ``"case"`` and ``"fldplt"``.
Expand All @@ -2922,13 +2919,13 @@ def export_field_plot(self, plot_name, file_path, file_name="", file_format="aed
"""
if not file_name:
file_name = plot_name
file_path = os.path.join(file_path, file_name + "." + file_format)
output_dir = os.path.join(output_dir, file_name + "." + file_format)
try:
self.ofieldsreporter.ExportFieldPlot(plot_name, False, file_path)
self.ofieldsreporter.ExportFieldPlot(plot_name, False, output_dir)
if settings.remote_rpc_session_temp_folder: # pragma: no cover
local_path = os.path.join(settings.remote_rpc_session_temp_folder, file_name + "." + file_format)
file_path = check_and_download_file(local_path, file_path)
return file_path
output_dir = check_and_download_file(local_path, output_dir)
return output_dir
except Exception: # pragma: no cover
self.logger.error("{} file format is not supported for this plot.".format(file_format))
return False
Expand Down

0 comments on commit 126a6c8

Please sign in to comment.