ansys / pyaedt

AEDT Python Client Package
https://aedt.docs.pyansys.com
MIT License
185 stars 107 forks source link

PyAEDT PostProcessing #4889

Open AdamTheEngineer-dev opened 1 week ago

AdamTheEngineer-dev commented 1 week ago

Before submitting the issue

Description of the bug

I was using export_field_file before without issue, I see some parameters have changed names but even when changed I get this:

post.export_field_file('J', solution=solution, variations=None, ... output_dir=j_field_filename, ... assignment='AllObjects', objects_type='Vol', intrinsics=intrinsics, phase=None, ... sample_points_file=sample_points_filename, sample_points=None, ... export_with_sample_points=False) PyAEDT INFO: Exporting J field. Be patient PyAEDT ERROR: ** PyAEDT ERROR: File "", line 1, in PyAEDT ERROR: File "D:\OneDrive_ANSYS\OneDrive - ANSYS, Inc\examples\MHD\Argonne_Generic_ALIP.venv_Argonne_Generic_ALIP\lib\site-packages\pyaedt\modules\PostProcessor.py", line 3050, in export_field_file PyAEDT ERROR: self.ofieldsreporter.ExportToFile( PyAEDT ERROR: AEDT API Error on export_field_file PyAEDT ERROR: Last Electronics Desktop Message - [error] script macro error: abnormal script termination. (10:48:13 am jul 05, 2024)

PyAEDT ERROR: Method arguments: PyAEDT ERROR: quantity = J PyAEDT ERROR: solution = Setup1 : LastAdaptive PyAEDT ERROR: output_dir = J_Field_complex.fld PyAEDT ERROR: assignment = AllObjects PyAEDT ERROR: objects_type = Vol PyAEDT ERROR: intrinsics = {'Freq': '2Hz', 'Phase': '0deg'} PyAEDT ERROR: sample_points_file = sample_points.pts PyAEDT ERROR: ** False

I see from the help pages that intrinsics should be a string but there is no guidance of its form I've tried all possible combinations with "=" and ":=" and space/comma separated key/value pairs. It would seem most sensible to have a dict instead or as well as a string.

Also, output_dir replaces filename. But help says:

output_dir str, optional Full path and name to save the file to. The default is None which export file in working_directory.

but that makes no sense. Is it a full path to a file or a directory???? If it's a file, output_dir is a misleading name.

If it's None, what's the name of the file???

There should be a mandatory filename and an optional output_dir parameter. (Default = "." not None) If the filename is not absolute, it is made absolute (with pathlib.Path(output_dir).resolve() / filename) This is what I've written in my wrapper code: output_dir = "." # default value pathlib import Path sample_points_filename = Path(sample_points_filename) # To convert str to Path if not sample_points_filename.is_absolute(): sample_points_filename = Path.cwd() / sample_points_filename

    output_dir = Path(output_dir).resolve()  # To make absolute if not.

    field_filename = Path(field_filename) # To convert str to Path

    if not field_filename.is_absolute():
        field_filename = output_dir / field_filename

    # post.export_field_file called here which should take Path objects or str for all filenames...

Steps To Reproduce

Enter a call to post.export_field_file using parameters that were working in 24R1

Which Operating System are you using?

Windows

Which Python version are you using?

3.10

Installed packages

pip freeze about-time==4.2.1 alive-progress==3.1.5 annotated-types==0.7.0 ansys-api-fluent==0.3.25 ansys-api-platform-instancemanagement==1.1.0 ansys-api-tools-filetransfer==0.1.0 ansys-fluent-core==0.21.0 ansys-platform-instancemanagement==1.1.2 ansys-pythonnet==3.1.0rc3 ansys-tools-filetransfer==0.1.0 ansys-units==0.3.2 attrs==23.2.0 bcrypt==4.1.3 beartype==0.18.5 certifi==2024.7.4 cffi==1.16.0 charset-normalizer==3.3.2 click==8.1.7 clr-loader==0.2.6 colorama==0.4.6 contourpy==1.2.1 cryptography==42.0.8 cycler==0.12.1 defusedxml==0.7.1 docker==6.1.3 fonttools==4.53.0 fpdf2==2.7.9 grapheme==0.6.0 grpcio==1.64.1 grpcio-health-checking==1.62.2 h5py==3.11.0 idna==3.7 importlib_metadata==8.0.0 joblib==1.4.2 jsonschema==4.22.0 jsonschema-specifications==2023.12.1 kiwisolver==1.4.5 lxml==4.9.4 matplotlib==3.9.1 nltk==3.8.1 numpy==1.26.4 packaging==24.1 pandas==2.2.2 paramiko==3.4.0 pillow==10.4.0 platformdirs==3.11.0 plumbum==1.8.3 protobuf==4.25.3 psutil==5.9.8 pyaedt==0.9.7 pycparser==2.22 pydantic==2.7.4 pydantic_core==2.18.4 pyedb==0.18.0 PyNaCl==1.5.0 pyparsing==3.1.2 python-dateutil==2.9.0.post0 pytomlpp==1.0.13 pytz==2024.1 pywin32==306 PyYAML==6.0.1 referencing==0.35.1 regex==2024.5.15 requests==2.31.0 rpds-py==0.18.1 rpyc==6.0.0 Rtree==1.2.0 SCons==4.7.0 six==1.16.0 toml==0.10.2 tqdm==4.66.4 typing_extensions==4.12.2 tzdata==2024.1 urllib3==2.2.2 websocket-client==1.8.0 zipp==3.19.2

Samuelopez-ansys commented 1 week ago

Hi @AdamTheEngineer-dev ,

You are right regarding the argument name, if you see the code, you can easily understand how it works:

if not output_dir:
    appendix = ""
    ext = ".fld"
    output_dir = os.path.join(self._app.working_directory, solution.replace(" : ", "_") + appendix + ext)
else:
    output_dir = output_dir.replace("//", "/").replace("\\", "/")

Then output_dir, should be replaced with output_file to be consistent with other methods. Please could you create a pull request? Or maybe @gmalinve can help, I checked she was the last one modifying the method.

Regarding intrinsic, it could also be explained better, but the problem with these methods are it is shared between all AEDT solvers, this the most important piece of code of the method:

image

As you can see, the intrinsic depends on the solution type.

Please if you share a project, we can help you to identify the issue.