ansys / pyfluent

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

pyFLUENT TUI - Expose default attributes #2553

Closed som1197 closed 4 months ago

som1197 commented 5 months ago

I wanted to create planes using different methods available in the TUI.

#%% Import require libraries

from pathlib import Path
import os
import ansys.fluent.core as pyfluent
from ansys.fluent.core import examples
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
import plotly.express as px
import plotly.graph_objects as go
import seaborn as sns

#%% Launch the FLUENT session (Local)
solver = pyfluent.launch_fluent(
    product_version="23.2.0",
    mode="solver",
    show_gui=True,
    version="3d",
    precision="double",
    processor_count=16,
    start_transcript=True
)

#%% Check the solver status
solver.health_check_service.check_health()

#%% Read the case and data files

filename = 'case_3a.1.cas.h5'
folderpath = Path(r"")
filepath = os.path.join(folderpath,filename)
solver.file.read(file_type="case-data", file_name=filepath)

solver.tui.surface.point_surface("point-" + str(angle), x, y, z)

Currently I cannot know beforehand the required arguments and their datatypes for the method 'point_surface' and many other methods for the tui module.

I tried to use the 'inspect' module as shown below:

signature = inspect.signature(solver.tui.surface.point_surface)

# Get the parameters
parameters = signature.parameters
for parameter_name, parameter in parameters.items():
    print(f"Parameter name: {parameter_name}")
    print(f"Parameter default value: {parameter.default}")
    print(f"Parameter annotation: {parameter.annotation}")

But this gave me empty values as shown below.

Parameter name: args Parameter default value: <class 'inspect._empty'> Parameter annotation: <class 'inspect._empty'> Parameter name: kwargs Parameter default value: <class 'inspect._empty'> Parameter annotation: <class 'inspect._empty'>

Is there a way to expose these default attributes so that they can be conveniently used without having to use the TUI console in the GUI to know the input arguments?

prmukherj commented 5 months ago

@som1197, you could use the settings-api altenative:

surf_name = "point-" + str(angle) solver.results.surfaces.point_surface.create(surf_name) solver.results.surfaces.point_surface[surf_name].point = [x, y, z]

som1197 commented 5 months ago

@prmukherj : Can you clarify on how to access settings-api?

prmukherj commented 5 months ago

@som1197, the snippet provided above is an alternative to running your script using settings-api. For more information on using settings-api, please look into the pyfluent documentation: https://fluent.docs.pyansys.com/version/stable/

som1197 commented 5 months ago

@prmukherj , yes but I was looking for the expected arguments that the function would need.

For example: solver.setup.models.viscous.model.allowed_values(), solver.setup.models.viscous.model.get_attr('allowed-values'), etc.

I can only find out the required input arguments [point, angle and x,y,z] to the function solver.tui.surface.point_surface("point-" + str(angle), x, y, z) by running this within the fluent TUI console.

mkundu1 commented 5 months ago

The TUI API doesn't have any information about the required parameters. The proceducre to construct TUI commands is described here. This shortcoming is not present in the newer settings API (the commands shared by @prmukherj which will do same the same thing as solver.tui.surface.point_surface(...).

som1197 commented 5 months ago

@mkundu1 , yes thats correct and i have explored the process of converting journal files into pythonized version of the journal files. But I was looking to do this in a way where the function arguments can be defined as class variables which can then be integrated into the function call in an objected oriented way. This can be useful for cases when some of the TUI calls have really long argument list, For eg:

solver.tui.display.objects.create(
    "vector",
    "vector-vel",
    "style",
    "arrow",
    "surface-list",
    "symmetry-xyplane",
    "()",
    "scale",
    "scale-f",
    "4",
    "quit",
    "skip",
    "2",
    "quit",
)
mkundu1 commented 4 months ago

We do not have any metadata for TUI argument names, so that approach won't work here. We are developing the settings API to avoid these issues coming from the legacy TUI.