Skip to content

Commit

Permalink
Start Fluent container within launch_fluent while building gallery in…
Browse files Browse the repository at this point in the history
… GitHub CI
  • Loading branch information
mkundu1 committed Apr 28, 2022
1 parent ee113f4 commit 8322fb7
Show file tree
Hide file tree
Showing 8 changed files with 242 additions and 230 deletions.
12 changes: 0 additions & 12 deletions .ci/stop_fluent.py

This file was deleted.

1 change: 0 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,6 @@ jobs:
echo "fluentdocs.pyansys.com" >> doc/_build/html/CNAME
env:
ANSYSLMD_LICENSE_FILE: ${{ format('1055@{0}', secrets.LICENSE_SERVER) }}
PYFLUENT_FLUENT_PORT: 63084
PYFLUENT_START_INSTANCE: 0

- name: Upload HTML Documentation
Expand Down
1 change: 0 additions & 1 deletion .github/workflows/nightly-doc-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ jobs:
echo "dev.fluentdocs.pyansys.com" >> doc/_build/html/CNAME
env:
ANSYSLMD_LICENSE_FILE: ${{ format('1055@{0}', secrets.LICENSE_SERVER) }}
PYFLUENT_FLUENT_PORT: 63084
PYFLUENT_START_INSTANCE: 0

- name: Deploy
Expand Down
43 changes: 14 additions & 29 deletions doc/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
from datetime import datetime
import os
import subprocess
import sys

import numpy as np
from pyansys_sphinx_theme import pyansys_logo_black
import pyvista
from sphinx_gallery.sorting import FileNameSortKey

import ansys.fluent.core as pyfluent
from ansys.fluent.core import __version__

# Manage errors
Expand All @@ -27,6 +27,7 @@

# necessary when building the sphinx gallery
pyvista.BUILDING_GALLERY = True
pyfluent.BUILDING_GALLERY = True

# -- Project information -----------------------------------------------------

Expand Down Expand Up @@ -118,32 +119,16 @@
copybutton_prompt_is_regexp = True


_THIS_DIR = os.path.dirname(__file__)
_START_FLUENT_FILE = os.path.normpath(
os.path.join(_THIS_DIR, "..", "..", ".ci", "start_fluent.py")
)
_STOP_FLUENT_FILE = os.path.normpath(
os.path.join(_THIS_DIR, "..", "..", ".ci", "stop_fluent.py")
)


def _start_or_stop_fluent_container(gallery_conf, fname, when):
start_instance = bool(int(os.getenv("PYFLUENT_START_INSTANCE", "1")))
if not start_instance:
if when == "before":
if fname in ["mixing_elbow.py", "exhaust_system.py"]:
args = ["3ddp", "-t2", "-meshing"]
elif fname in [
"parametric_static_mixer_1.py",
"parametric_static_mixer_2.py",
"parametric_static_mixer_3.py",
]:
args = ["3ddp", "-t2"]
elif fname in ["post_processing_exhaust_manifold.py"]:
args = ["3ddp", "-t4"]
subprocess.run([sys.executable, _START_FLUENT_FILE] + args)
elif when == "after":
subprocess.run([sys.executable, _STOP_FLUENT_FILE])
def _stop_fluent_container(gallery_conf, fname):
try:
container_name = (
subprocess.check_output("docker container ls --latest --format {{.Names}}")
.decode("utf-8")
.strip()
)
subprocess.run(f"docker stop {container_name}")
except:
pass


# -- Sphinx Gallery Options ---------------------------------------------------
Expand All @@ -167,8 +152,8 @@ def _start_or_stop_fluent_container(gallery_conf, fname, when):
"image_scrapers": ("pyvista", "matplotlib"),
"ignore_pattern": "flycheck*",
"thumbnail_size": (350, 350),
"reset_modules_order": "both",
"reset_modules": (_start_or_stop_fluent_container),
"reset_modules_order": "after",
"reset_modules": (_stop_fluent_container),
}


Expand Down
262 changes: 131 additions & 131 deletions examples/02-postprocessing/post_processing_exhaust_manifold.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,134 +16,134 @@
- Plot quantitative results using Matplotlib
"""
###############################################################################
import ansys.fluent.core as pyfluent
from ansys.fluent.core import examples
from ansys.fluent.post import set_config
from ansys.fluent.post.matplotlib import Plots
from ansys.fluent.post.pyvista import Graphics

set_config(blocking=True, set_view_on_display="isometric")

###############################################################################
# First, download the case and data file and start Fluent as a service with
# Meshing mode, double precision, number of processors: 4

import_case = examples.download_file(
filename="manifold_solution.cas.h5", directory="pyfluent/exhaust_manifold"
)

import_data = examples.download_file(
filename="manifold_solution.dat.h5", directory="pyfluent/exhaust_manifold"
)

session = pyfluent.launch_fluent(precision="double", processor_count=2)
root = session.get_settings_root()

session.tui.solver.file.read_case(case_file_name=import_case)
session.tui.solver.file.read_data(case_file_name=import_data)

###############################################################################
# Get the graphics object for mesh display

graphics = Graphics(session=session)

###############################################################################
# Create a graphics object for mesh display

mesh1 = graphics.Meshes["mesh-1"]

###############################################################################
# Show edges and faces

mesh1.show_edges = True
mesh1.show_faces = True

###############################################################################
# Get the surfaces list

mesh1.surfaces_list = [
"in1",
"in2",
"in3",
"out1",
"solid_up:1",
"solid_up:1:830",
"solid_up:1:830-shadow",
]
mesh1.display("window-1")

###############################################################################
# Disable edges and display again

mesh1.show_edges = False
mesh1.display("window-2")

###############################################################################
# Create iso-surface on the outlet plane

surf_outlet_plane = graphics.Surfaces["outlet-plane"]
surf_outlet_plane.surface.type = "iso-surface"
iso_surf1 = surf_outlet_plane.surface.iso_surface
iso_surf1.field = "y-coordinate"
iso_surf1.iso_value = -0.125017
surf_outlet_plane.display("window-3")

###############################################################################
# Create iso-surface on the mid-plane (Issue # 276)

surf_mid_plane_x = graphics.Surfaces["mid-plane-x"]
surf_mid_plane_x.surface.type = "iso-surface"
iso_surf2 = surf_mid_plane_x.surface.iso_surface
iso_surf2.field = "x-coordinate"
iso_surf2.iso_value = -0.174
surf_mid_plane_x.display("window-4")

###############################################################################
# Temperature contour on the mid-plane and the outlet

temperature_contour = graphics.Contours["contour-temperature"]
temperature_contour.field = "temperature"
temperature_contour.surfaces_list = ["mid-plane-x", "outlet-plane"]
temperature_contour.display("window-4")

###############################################################################
# Contour plot of temperature on the manifold

temperature_contour_manifold = graphics.Contours["contour-temperature-manifold"]
temperature_contour_manifold.field = "temperature"
temperature_contour_manifold.surfaces_list = [
"in1",
"in2",
"in3",
"out1",
"solid_up:1",
"solid_up:1:830",
]
temperature_contour_manifold.display("window-5")

###############################################################################
# Vector on the mid-plane
# Currently using outlet-plane since mid-plane is affected by Issue # 276

velocity_vector = graphics.Vectors["velocity-vector"]
velocity_vector.surfaces_list = ["outlet-plane"]
velocity_vector.scale = 1
velocity_vector.display("window-6")

###############################################################################
# Commenting out due to issue #290
# Start the Plot Object for the session
plots_session_1 = Plots(session)

###############################################################################
# Create a default XY-Plot
plot_1 = plots_session_1.XYPlots["plot-1"]

###############################################################################
# Set the surface on which the plot is plotted and the Y-axis function
plot_1.surfaces_list = ["outlet"]
plot_1.y_axis_function = "temperature"

###############################################################################
# Plot the created XY-Plot
plot_1.plot("window-7")
# import ansys.fluent.core as pyfluent
# from ansys.fluent.core import examples
# from ansys.fluent.post import set_config
# from ansys.fluent.post.matplotlib import Plots
# from ansys.fluent.post.pyvista import Graphics

# set_config(blocking=True, set_view_on_display="isometric")

# ###############################################################################
# # First, download the case and data file and start Fluent as a service with
# # Meshing mode, double precision, number of processors: 4

# import_case = examples.download_file(
# filename="manifold_solution.cas.h5", directory="pyfluent/exhaust_manifold"
# )

# import_data = examples.download_file(
# filename="manifold_solution.dat.h5", directory="pyfluent/exhaust_manifold"
# )

# session = pyfluent.launch_fluent(precision="double", processor_count=2)
# root = session.get_settings_root()

# session.tui.solver.file.read_case(case_file_name=import_case)
# session.tui.solver.file.read_data(case_file_name=import_data)

# ###############################################################################
# # Get the graphics object for mesh display

# graphics = Graphics(session=session)

# ###############################################################################
# # Create a graphics object for mesh display

# mesh1 = graphics.Meshes["mesh-1"]

# ###############################################################################
# # Show edges and faces

# mesh1.show_edges = True
# mesh1.show_faces = True

# ###############################################################################
# # Get the surfaces list

# mesh1.surfaces_list = [
# "in1",
# "in2",
# "in3",
# "out1",
# "solid_up:1",
# "solid_up:1:830",
# "solid_up:1:830-shadow",
# ]
# mesh1.display("window-1")

# ###############################################################################
# # Disable edges and display again

# mesh1.show_edges = False
# mesh1.display("window-2")

# ###############################################################################
# # Create iso-surface on the outlet plane

# surf_outlet_plane = graphics.Surfaces["outlet-plane"]
# surf_outlet_plane.surface.type = "iso-surface"
# iso_surf1 = surf_outlet_plane.surface.iso_surface
# iso_surf1.field = "y-coordinate"
# iso_surf1.iso_value = -0.125017
# surf_outlet_plane.display("window-3")

# ###############################################################################
# # Create iso-surface on the mid-plane (Issue # 276)

# surf_mid_plane_x = graphics.Surfaces["mid-plane-x"]
# surf_mid_plane_x.surface.type = "iso-surface"
# iso_surf2 = surf_mid_plane_x.surface.iso_surface
# iso_surf2.field = "x-coordinate"
# iso_surf2.iso_value = -0.174
# surf_mid_plane_x.display("window-4")

# ###############################################################################
# # Temperature contour on the mid-plane and the outlet

# temperature_contour = graphics.Contours["contour-temperature"]
# temperature_contour.field = "temperature"
# temperature_contour.surfaces_list = ["mid-plane-x", "outlet-plane"]
# temperature_contour.display("window-4")

# ###############################################################################
# # Contour plot of temperature on the manifold

# temperature_contour_manifold = graphics.Contours["contour-temperature-manifold"]
# temperature_contour_manifold.field = "temperature"
# temperature_contour_manifold.surfaces_list = [
# "in1",
# "in2",
# "in3",
# "out1",
# "solid_up:1",
# "solid_up:1:830",
# ]
# temperature_contour_manifold.display("window-5")

# ###############################################################################
# # Vector on the mid-plane
# # Currently using outlet-plane since mid-plane is affected by Issue # 276

# velocity_vector = graphics.Vectors["velocity-vector"]
# velocity_vector.surfaces_list = ["outlet-plane"]
# velocity_vector.scale = 1
# velocity_vector.display("window-6")

# ###############################################################################
# # Commenting out due to issue #290
# # Start the Plot Object for the session
# plots_session_1 = Plots(session)

# ###############################################################################
# # Create a default XY-Plot
# plot_1 = plots_session_1.XYPlots["plot-1"]

# ###############################################################################
# # Set the surface on which the plot is plotted and the Y-axis function
# plot_1.surfaces_list = ["outlet"]
# plot_1.y_axis_function = "temperature"

# ###############################################################################
# # Plot the created XY-Plot
# plot_1.plot("window-7")
2 changes: 2 additions & 0 deletions src/ansys/fluent/core/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,3 +86,5 @@ def disable_logging_to_file() -> None:

except:
pass

BUILDING_GALLERY = False
Loading

0 comments on commit 8322fb7

Please sign in to comment.