Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Visualize solution variable data #395

Open
mkundu1 opened this issue Jun 18, 2024 · 2 comments · May be fixed by #402
Open

Visualize solution variable data #395

mkundu1 opened this issue Jun 18, 2024 · 2 comments · May be fixed by #402

Comments

@mkundu1
Copy link
Collaborator

mkundu1 commented Jun 18, 2024

It might be useful to visualize the solution variable data in numerical format to understand how the data is ordered in space. For a face-thread, we can draw the background mesh and plot the centroid data as point cloud with variable data as labels. Following is an example code in pyvista without the background mesh:

import ansys.fluent.core as pyfluent
solver = pyfluent.launch_fluent()
solver.file.read_case_data(file_name=r"d:/work/elbow.cas.h5")
centroid_data = solver.fields.solution_variable_data.get_data(solution_variable_name="SV_CENTROID", zone_names=["inlet1"], domain_name="mixture")["inlet1"]
centroid_data = centroid_data.reshape(-1, 3)
pressure_data = solver.fields.solution_variable_data.get_data(solution_variable_name="SV_P", zone_names=["inlet1"], domain_name="mixture")["inlet1"]

import pyvista as pv
poly = pv.PolyData(centroid_data)
poly["Pressure"] = [f"{i},{p:.2f}" for i, p in enumerate(pressure_data)]
plotter = pv.Plotter()
plotter.add_point_labels(poly, "Pressure", point_size=3, point_color='black', font_size=10, bold=False, shape=None)
plotter.show_axes()
plotter.show()

image

@mkundu1
Copy link
Collaborator Author

mkundu1 commented Jun 19, 2024

Some thoughts on the API design:

class Format(Enum):
    DATA_ONLY = 1
    INDEX_AND_DATA = 2

def plot_solution_variables_data(session, variable_names: Union[str, list[str]], zone_names: list[str], domain_name: str, format: Union[Format, Callable]:
    pass

Examples of the format parameter:
plot_solution_variables_data(session, variable_names="SV_P", zone_names=<zone_names>, domain_name=<domain_name>, format=Format.DATA_ONLY will show f"{P[i]}" as label.
plot_solution_variables_data(session, variable_names="SV_P", zone_names=<zone_names>, domain_name=<domain_name>, format=Format.INDEX_AND_DATA will show f"({i}, {P[i]})" as label.
plot_solution_variables_data(session, variable_names=["SV_P", "SV_T"], zone_names=<zone_names>, domain_name=<domain_name>, format=Format.DATA_ONLY will show f"({P[i]}, {T[i]})" as label.
plot_solution_variables_data(session, variable_names=["SV_P", "SV_T"], zone_names=<zone_names>, domain_name=<domain_name>, format=Format.INDEX_AND_DATA will show f"({i}, {P[i]}, {T[i]})" as label.
plot_solution_variables_data(session, variable_names=["SV_P", "SV_T"], zone_names=<zone_names>, domain_name=<domain_name>, format=lambda *args: f"{args[0]} - {args[1]}, {args[2]}" will show f"{i} - {P[i]}, {T[i]}" as label.

Some arguments from pyvista.Plotter.add_point_labels can also be included additionally.

If we provide type-annotations, which one is better?
def plot_solution_variables_data(session, variable_names: Union[str, list[str]], zone_names: list[str], domain_name: str, format: Union[Format, Callable]):
or
def plot_solution_variables_data(session, variables: Union[str, list[str]], zones: list[str], domain: str, format: Union[Format, Callable]):

@mkundu1
Copy link
Collaborator Author

mkundu1 commented Jun 20, 2024

Complete working script in pyfluent-visualization:

import ansys.fluent.core as pyfluent
from ansys.fluent.visualization.pyvista import Graphics, pyvista_windows_manager
import pyvista as pv

solver = pyfluent.launch_fluent()
solver.file.read_case_data(file_name=r"d:/work/elbow.cas.h5")
graphics = Graphics(session=solver)
mesh1 = graphics.Meshes["mesh-1"]
mesh1.show_edges = True
mesh1.surfaces_list = ["inlet1"]
mesh1.display("window-1")

centroid_data = solver.fields.solution_variable_data.get_data(solution_variable_name="SV_CENTROID", zone_names=["inlet1"], domain_name="mixture")["inlet1"]
centroid_data = centroid_data.reshape(-1, 3)
pressure_data = solver.fields.solution_variable_data.get_data(solution_variable_name="SV_P", zone_names=["inlet1"], domain_name="mixture")["inlet1"]

poly = pv.PolyData(centroid_data)
poly["Pressure"] = [f"({i}, {p:.2f})" for i, p in enumerate(pressure_data)]
plotter = pyvista_windows_manager.get_plotter("window-1")
plotter.add_point_labels(poly, "Pressure", point_size=3, point_color='black', font_size=10, bold=False, shape=None)

image

@mkundu1 mkundu1 linked a pull request Jun 22, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant