ansys / pyfluent

Pythonic interface to Ansys Fluent
https://fluent.docs.pyansys.com
MIT License
257 stars 41 forks source link

Issue with calculate_patch #3141

Open mcgoldba opened 1 month ago

mcgoldba commented 1 month ago

πŸ” Before submitting the issue

🐞 Description of the bug

When trying to patch the volume mesh with initial values using

solver.solution.initialization.patch.calculate_patch(
    domain = "water", 
    cell_zones = ["volume-volume"], 
    registers = "initial_water", 
    variable = "mp", 
    reference_frame = "Relative to Cell Zone", 
    use_custom_field_function = False, 
    custom_field_function_name = "", 
    value = 1.0
)

The result is that zero cells are marked:

0 cells marked

I get the same result if I try to use the tui module in pyFluent with

solver.tui.solve.patch('water', 'volume-volume', (), 'initial_water', (), 'mp', 1.0 )

When setting values with the same inputs using the TUI in command line Fluent, the cells are marked appropriately for each cell register.

πŸ“ Steps to reproduce

solver = pyfluent.launch_fluent(
        mode='solver',
        processor_count=128,
        additional_arguments="-mpi=intel -pinfiniband"
)
solver.file.read_case(file_name="24-0013-2-run7.cas.h5")
solver.mesh.check()

Output:

 Domain Extents:
   x-coordinate: min (m) = -4.267200e+00, max (m) = 5.334000e+00
   y-coordinate: min (m) = -2.387600e+00, max (m) = 5.080000e+00
   z-coordinate: min (m) = -4.003446e+00, max (m) = 1.656080e+01
 Volume statistics:
   minimum volume (m3): 2.394498e-10
   maximum volume (m3): 1.045566e-03
     total volume (m3): 8.772596e+02
 Face area statistics:
   minimum face area (m2): 3.556312e-08
   maximum face area (m2): 8.958791e-03
 Checking mesh.....................................
Done.
# Define cell register
if 'initial_water' in solver.solution.cell_registers:
    solver.solution.cell_registers.delete('initial_water')
solver.solution.cell_registers.create('initial_water')
initializationPatches.append('initial_water')
initial_water = solver.solution.cell_registers['initial_water']
initial_water.type.option = 'hexahedron'
initial_water.type.hexahedron.min_point = [xmin, ymin, zmin]
initial_water.type.hexahedron.max_point = [
    xmax, 
    ymax, 
    zmax
]
print(inlet_water.get_state())

Output:

{'name': 'initial_water', 'python_name_1': 'initial_water', 'type': {'option': 'hexahedron', 'hexahedron': {'min_point': [-4.2672, -2.3876, -4.003446], 'max_point': [5.334, 4.114599207558671, 16.5608], 'inside': True, 'create_volume_surface': False}}, 'display_options': {'draw_mesh': False, 'filled': False, 'marker': True, 'marker_symbol': 'o', 'marker_size': 0.1, 'wireframe': True, 'color': 'black'}}
solver.solution.initialization.standard_initialize()

solver.solution.initialization.patch.calculate_patch(
    domain = "water", 
    cell_zones = ["volume-volume"], 
    registers = "initial_water, 
    variable = "mp", 
    reference_frame = "Relative to Cell Zone", 
    use_custom_field_function = False, 
    custom_field_function_name = "", 
    value = 1.0
)

Output: 0 cells marked

πŸ’» Which operating system are you using?

Linux

πŸ“€ Which ANSYS version are you using?

2024R1

🐍 Which Python version are you using?

3.12

πŸ“¦ Installed packages

(base) bash-4.4$ python -m pip freeze
about-time==4.2.1
alive-progress==3.1.5
anaconda-anon-usage @ file:///croot/anaconda-anon-usage_1710965072196/work
ansys-api-fluent==0.3.26
ansys-api-platform-instancemanagement==1.1.0
ansys-api-tools-filetransfer==0.1.0
ansys-fluent-core==0.22.0
ansys-platform-instancemanagement==1.1.2
ansys-tools-filetransfer==0.1.0
ansys-units==0.3.2
anyio==3.7.1
archspec @ file:///croot/archspec_1709217642129/work
argon2-cffi==23.1.0
argon2-cffi-bindings==21.2.0
arrow==1.3.0
asttokens==2.4.1
async-lru==2.0.4
attrs==23.2.0
Babel==2.15.0
beartype==0.18.5
beautifulsoup4==4.12.3
bleach==6.1.0
boltons @ file:///work/perseverance-python-buildout/croot/boltons_1698851177130/work
Brotli @ file:///croot/brotli-split_1714483155106/work
certifi @ file:///croot/certifi_1720453481653/work/certifi
cffi @ file:///croot/cffi_1714483155441/work
charset-normalizer @ file:///tmp/build/80754af9/charset-normalizer_1630003229654/work
click==8.1.7
comm==0.2.2
conda @ file:///croot/conda_1722004606466/work
conda-content-trust @ file:///croot/conda-content-trust_1714483159009/work
conda-libmamba-solver @ file:///croot/conda-libmamba-solver_1706733287605/work/src
conda-package-handling @ file:///croot/conda-package-handling_1718138267740/work
conda_package_streaming @ file:///croot/conda-package-streaming_1718136078615/work
contourpy @ file:///work/perseverance-python-buildout/croot/contourpy_1701756524386/work
cryptography @ file:///croot/cryptography_1714660666131/work
cycler @ file:///tmp/build/80754af9/cycler_1637851556182/work
debugpy==1.8.2
decorator==5.1.1
defusedxml==0.7.1
distro @ file:///croot/distro_1714488253808/work
docker==7.1.0
executing==2.0.1
fastjsonschema==2.20.0
fonttools @ file:///croot/fonttools_1713551344105/work
fqdn==1.5.1
frozendict @ file:///croot/frozendict_1713194832637/work
grapheme==0.6.0
grpcio==1.65.1
grpcio-health-checking==1.62.2
h11==0.14.0
httpcore==1.0.5
httpx==0.27.0
idna @ file:///croot/idna_1714398848350/work
importlib_metadata==8.2.0
ipykernel==6.29.5
ipython==8.26.0
ipywidgets==8.1.3
isoduration==20.11.0
jedi==0.19.1
Jinja2==3.1.4
joblib==1.4.2
json5==0.9.25
jsonpatch @ file:///croot/jsonpatch_1714483231291/work
jsonpointer==2.1
jsonschema==4.23.0
jsonschema-specifications==2023.12.1
jupyter==1.0.0
jupyter-console==6.6.3
jupyter-events==0.10.0
jupyter-lsp==2.2.5
jupyter_client==8.6.2
jupyter_core==5.7.2
jupyter_server==2.14.2
jupyter_server_terminals==0.5.3
jupyterlab==4.2.4
jupyterlab_pygments==0.3.0
jupyterlab_server==2.27.3
jupyterlab_widgets==3.0.11
kiwisolver @ file:///work/perseverance-python-buildout/croot/kiwisolver_1698847502605/work
libmambapy @ file:///croot/mamba-split_1714483352891/work/libmambapy
lxml==5.2.2
MarkupSafe==2.1.5
matplotlib @ file:///croot/matplotlib-suite_1713336378214/work
matplotlib-inline==0.1.7
menuinst @ file:///croot/menuinst_1718132535249/work
mistune==3.0.2
mkl-fft @ file:///work/perseverance-python-buildout/croot/mkl_fft_1698845673361/work
mkl-random @ file:///work/perseverance-python-buildout/croot/mkl_random_1698845720894/work
mkl-service==2.4.0
nbclient==0.10.0
nbconvert==7.16.4
nbformat==5.10.4
nest-asyncio==1.6.0
nltk==3.8.1
notebook==7.2.1
notebook_shim==0.2.4
numpy @ file:///croot/numpy_and_numpy_base_1708638617955/work/dist/numpy-1.26.4-cp312-cp312-linux_x86_64.whl#sha256=1d700f51d8b4fa684d858c9e3b56b1656bc5c82b6b79ff08d4e3b491c430059f
overrides==7.7.0
packaging @ file:///croot/packaging_1710807400464/work
pandas==2.2.2
pandocfilters==1.5.1
parso==0.8.4
pexpect==4.9.0
pillow @ file:///croot/pillow_1721059439630/work
platformdirs @ file:///work/perseverance-python-buildout/croot/platformdirs_1701732573265/work
pluggy @ file:///work/perseverance-python-buildout/croot/pluggy_1698805497733/work
ply @ file:///work/perseverance-python-buildout/croot/ply_1698846188635/work
prometheus_client==0.20.0
prompt_toolkit==3.0.47
protobuf==4.25.3
psutil==6.0.0
ptyprocess==0.7.0
pure_eval==0.2.3
pycosat @ file:///croot/pycosat_1714510623388/work
pycparser @ file:///tmp/build/80754af9/pycparser_1636541352034/work
Pygments==2.18.0
pyparsing @ file:///work/perseverance-python-buildout/croot/pyparsing_1698847881454/work
PyQt5==5.15.10
PyQt5-sip @ file:///work/perseverance-python-buildout/croot/pyqt-split_1698847927472/work/pyqt_sip
PySocks @ file:///work/perseverance-python-buildout/croot/pysocks_1698845478203/work
python-dateutil @ file:///croot/python-dateutil_1716495738603/work
python-json-logger==2.0.7
pytz==2024.1
PyYAML==6.0.1
pyzmq==26.0.3
qtconsole==5.5.2
QtPy==2.4.1
referencing==0.35.1
regex==2024.5.15
requests @ file:///croot/requests_1721410876868/work
rfc3339-validator==0.1.4
rfc3986-validator==0.1.1
rpds-py==0.19.1
ruamel.yaml @ file:///work/perseverance-python-buildout/croot/ruamel.yaml_1698863605521/work
Send2Trash==1.8.3
setuptools==69.5.1
sip @ file:///work/perseverance-python-buildout/croot/sip_1698846977033/work
six @ file:///tmp/build/80754af9/six_1644875935023/work
sniffio==1.3.1
soupsieve==2.5
stack-data==0.6.3
terminado==0.18.1
tinycss2==1.3.0
tornado @ file:///croot/tornado_1718740109488/work
tqdm @ file:///croot/tqdm_1716395931952/work
traitlets==5.14.3
truststore @ file:///work/perseverance-python-buildout/croot/truststore_1701735771625/work
types-python-dateutil==2.9.0.20240316
tzdata==2024.1
unicodedata2 @ file:///croot/unicodedata2_1713212950228/work
uri-template==1.3.0
urllib3 @ file:///croot/urllib3_1718912636303/work
wcwidth==0.2.13
webcolors==24.6.0
webencodings==0.5.1
websocket-client==1.8.0
wheel==0.43.0
widgetsnbextension==4.0.11
zipp==3.19.2
zstandard @ file:///croot/zstandard_1714677652653/work
prmukherj commented 1 month ago

@seanpearsonuk, Please could you move this to Fluent side. Thank you. cc. @gyeole

seanpearsonuk commented 1 month ago

Hi @mcgoldba

Thank you for providing your detailed report.

You mentioned that the equivalent TUI command works correctly when you use it directly in Fluent. Have you tried the following?

  1. Start Fluent in non-Python (normal) mode
  2. Start writing to Python journal
  3. Execute your TUI commands
  4. Stop writing journal

Note: You can also automate the above procedure either using Fluent command line arguments are with the launch_fluent() function's topy argument.

The generated file should be a Python script that you can use either in PyFluent or in the Fluent Python console. Each solver TUI command call will generate either a Python tui method call or a Python settings call (depending on each TUI command's implementation).

Please let us know if this procedure generates different calls and whether those calls are effective.

cc: @prmukherj

mcgoldba commented 1 month ago

When I record a journal I do not get Python commands, but the following

/file/set-tui-version "24.1"
(cx-gui-do cx-set-list-tree-selections "NavigationPane*Frame2*Table1*List_Tree2" (list "Solution|Initialization"))
(cx-gui-do cx-set-list-tree-selections "NavigationPane*Frame2*Table1*List_Tree2" (list "Solution|Initialization"))
(cx-gui-do cx-activate-item "NavigationPane*Frame2*Table1*List_Tree2")
(cx-gui-do cx-set-list-tree-selections "NavigationPane*Frame2*Table1*List_Tree2" (list "Solution|Initialization"))
(cx-gui-do cx-activate-item "Solution Initialization*Table1*Frame9*PushButton1(Initialize)")
(cx-gui-do cx-activate-item "Question*OK")
(cx-gui-do cx-activate-item "Solution Initialization*Table1*Frame9*PushButton1(Initialize)")
(cx-gui-do cx-activate-item "Question*OK")
(cx-gui-do cx-activate-item "Solution Initialization*Table1*Frame9*PushButton3(Patch)")
(cx-gui-do cx-set-list-selections "Patch*Table1*Frame1*Frame1*Table2*DropDownList1(Phase)" '( 1))
(cx-gui-do cx-activate-item "Patch*Table1*Frame1*Frame1*Table2*DropDownList1(Phase)")
(cx-gui-do cx-set-list-selections "Patch*Table1*Frame1*Frame1*Table2*List2(Variable)" '( 0))
(cx-gui-do cx-activate-item "Patch*Table1*Frame1*Frame1*Table2*List2(Variable)")
(cx-gui-do cx-set-list-selections "Patch*Table1*Frame3*List3(Registers to Patch)" '( 0))
(cx-gui-do cx-activate-item "Patch*Table1*Frame3*List3(Registers to Patch)")
(cx-gui-do cx-activate-item "Patch*PanelButtons*PushButton3(Patch)")
(cx-gui-do cx-set-list-selections "Patch*Table1*Frame3*List3(Registers to Patch)" '( 1))
(cx-gui-do cx-activate-item "Patch*Table1*Frame3*List3(Registers to Patch)")
(cx-gui-do cx-activate-item "Patch*PanelButtons*PushButton3(Patch)")
(cx-gui-do cx-set-list-selections "Patch*Table1*Frame3*List3(Registers to Patch)" '( 2))
(cx-gui-do cx-activate-item "Patch*Table1*Frame3*List3(Registers to Patch)")
(cx-gui-do cx-activate-item "Patch*PanelButtons*PushButton3(Patch)")
(cx-gui-do cx-set-list-selections "Patch*Table1*Frame3*List3(Registers to Patch)" '( 3))
(cx-gui-do cx-activate-item "Patch*Table1*Frame3*List3(Registers to Patch)")
(cx-gui-do cx-activate-item "Patch*PanelButtons*PushButton3(Patch)")
(cx-gui-do cx-set-list-selections "Patch*Table1*Frame3*List3(Registers to Patch)" '( 4))
(cx-gui-do cx-activate-item "Patch*Table1*Frame3*List3(Registers to Patch)")
(cx-gui-do cx-activate-item "Patch*PanelButtons*PushButton3(Patch)")
(cx-gui-do cx-set-list-selections "Patch*Table1*Frame3*List3(Registers to Patch)" '( 5))
(cx-gui-do cx-activate-item "Patch*Table1*Frame3*List3(Registers to Patch)")
(cx-gui-do cx-activate-item "Patch*PanelButtons*PushButton3(Patch)")
(cx-gui-do cx-activate-item "Patch*PanelButtons*PushButton1(Close)")
(cx-gui-do cx-activate-item "MenuBar*WriteSubMenu*Stop Journal")

How do I create a Python journal?

seanpearsonuk commented 1 month ago

How do I create a Python journal?

You can do this either in Fluent or PyFluent.

If you do it in Fluent, you can select a .py extension for the output file when you start journaling.

S-Courtney commented 2 weeks ago

When I record a journal I do not get Python commands, but the following How do I create a Python journal?

Try this:

(api-start-python-journal "file_name.py")

This will give you new output file in your working directory "file_name.py"

This worked for me and generated:

solver.solution.initialization.patch.calculate_patch(domain = "domian", cell_zones = ["zone"], registers = [], variable = "mp", reference_frame = "Relative to Cell Zone", use_custom_field_function = False, custom_field_function_name = "", value = 1)

It should give you something that looks similar.