From 8e12a8531999392137ce7d8402f3f70709e2a8ea Mon Sep 17 00:00:00 2001 From: Mainak Kundu Date: Tue, 26 Apr 2022 13:09:20 +0530 Subject: [PATCH 1/3] Start Fluent container within launch_fluent while building gallery in GitHub CI --- .ci/start_fluent.py | 63 ------------------------- .ci/stop_fluent.py | 12 ----- .github/workflows/ci.yml | 1 - .github/workflows/nightly-doc-build.yml | 1 - doc/source/conf.py | 45 +++++++----------- 5 files changed, 16 insertions(+), 106 deletions(-) delete mode 100644 .ci/start_fluent.py delete mode 100644 .ci/stop_fluent.py diff --git a/.ci/start_fluent.py b/.ci/start_fluent.py deleted file mode 100644 index 284ad250fd97..000000000000 --- a/.ci/start_fluent.py +++ /dev/null @@ -1,63 +0,0 @@ -import os -import subprocess -import sys -import tempfile -import time -from typing import List - -from ansys.fluent.core import EXAMPLES_PATH - - -def start_fluent_container(args: List[str]) -> None: - fd, sifile = tempfile.mkstemp( - suffix=".txt", prefix="serverinfo-", dir=EXAMPLES_PATH - ) - os.close(fd) - timeout = 100 - license_server = os.environ["ANSYSLMD_LICENSE_FILE"] - port = os.environ["PYFLUENT_FLUENT_PORT"] - - try: - subprocess.run( - [ - "docker", - "run", - "--name", - "fluent_server", - "-d", - "--rm", - "-p", - f"{port}:{port}", - "-v", - f"{EXAMPLES_PATH}:{EXAMPLES_PATH}", - "-e", - f"ANSYSLMD_LICENSE_FILE={license_server}", - "-e", - f"REMOTING_PORTS={port}/portspan=2", - "-e", - "FLUENT_LAUNCHED_FROM_PYFLUENT=1", - "ghcr.io/pyansys/pyfluent", - "-g", - f"-sifile={sifile}", - ] - + args - ) - - sifile_last_mtime = os.stat(sifile).st_mtime - while True: - if os.stat(sifile).st_mtime > sifile_last_mtime: - time.sleep(1) - break - if timeout == 0: - break - time.sleep(1) - timeout -= 1 - except OSError: - pass - finally: - if os.path.exists(sifile): - os.remove(sifile) - - -if __name__ == "__main__": - start_fluent_container(sys.argv[1:]) diff --git a/.ci/stop_fluent.py b/.ci/stop_fluent.py deleted file mode 100644 index 4ec80ff754c6..000000000000 --- a/.ci/stop_fluent.py +++ /dev/null @@ -1,12 +0,0 @@ -import subprocess - - -def stop_fluent_container() -> None: - try: - subprocess.run(["docker", "stop", "fluent_server"]) - except OSError: - pass - - -if __name__ == "__main__": - stop_fluent_container() diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 736b10d88bf3..460b3f39e4f3 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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 diff --git a/.github/workflows/nightly-doc-build.yml b/.github/workflows/nightly-doc-build.yml index 089039b357cf..5ab860127c05 100644 --- a/.github/workflows/nightly-doc-build.yml +++ b/.github/workflows/nightly-doc-build.yml @@ -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 diff --git a/doc/source/conf.py b/doc/source/conf.py index 145ed7c486db..d3461072f06d 100644 --- a/doc/source/conf.py +++ b/doc/source/conf.py @@ -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 @@ -27,6 +27,7 @@ # necessary when building the sphinx gallery pyvista.BUILDING_GALLERY = True +pyfluent.BUILDING_GALLERY = True # -- Project information ----------------------------------------------------- @@ -118,32 +119,18 @@ 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_names = ( + subprocess.check_output("docker container ls --format {{.Names}}") + .decode("utf-8") + .strip() + .split() + ) + for container_name in container_names: + subprocess.run(f"docker stop {container_name}") + except Exception: + pass # -- Sphinx Gallery Options --------------------------------------------------- @@ -167,8 +154,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), } From 802f87ee927cd13246a735619ecb18168dace685 Mon Sep 17 00:00:00 2001 From: Mainak Kundu Date: Mon, 2 May 2022 13:01:05 +0530 Subject: [PATCH 2/3] Try using a smaller case to fix the memory issue --- .../parametric_static_mixer_3.py | 2 + .../post_processing_exhaust_manifold.py | 40 +++++++------------ 2 files changed, 17 insertions(+), 25 deletions(-) diff --git a/examples/01-parametric/parametric_static_mixer_3.py b/examples/01-parametric/parametric_static_mixer_3.py index 75f99fda3eb2..e487c4e8d630 100755 --- a/examples/01-parametric/parametric_static_mixer_3.py +++ b/examples/01-parametric/parametric_static_mixer_3.py @@ -74,6 +74,8 @@ data_frame = pd.read_csv(design_point_table_study_2) print(data_frame) +session.exit() + ######################################################################### # Access a new parametric session using the flprj saved earlier diff --git a/examples/02-postprocessing/post_processing_exhaust_manifold.py b/examples/02-postprocessing/post_processing_exhaust_manifold.py index b2b7ca0f69dd..f047c4ff69ab 100644 --- a/examples/02-postprocessing/post_processing_exhaust_manifold.py +++ b/examples/02-postprocessing/post_processing_exhaust_manifold.py @@ -29,18 +29,15 @@ # 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" + "Static_Mixer_main.cas.h5", "pyfluent/static_mixer" ) 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) +session.tui.solver.solve.initialize.initialize_flow() +session.tui.solver.solve.iterate(50) ############################################################################### # Get the graphics object for mesh display @@ -62,13 +59,9 @@ # Get the surfaces list mesh1.surfaces_list = [ - "in1", - "in2", - "in3", - "out1", - "solid_up:1", - "solid_up:1:830", - "solid_up:1:830-shadow", + "inlet1", + "inlet2", + "outlet", ] mesh1.display("window-1") @@ -81,21 +74,21 @@ ############################################################################### # Create iso-surface on the outlet plane -surf_outlet_plane = graphics.Surfaces["outlet-plane"] +surf_outlet_plane = graphics.Surfaces["outlet"] 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 +iso_surf1.iso_value = 0.0 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 = graphics.Surfaces["plane-4"] 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 +iso_surf2.iso_value = 0.0 surf_mid_plane_x.display("window-4") ############################################################################### @@ -103,7 +96,7 @@ temperature_contour = graphics.Contours["contour-temperature"] temperature_contour.field = "temperature" -temperature_contour.surfaces_list = ["mid-plane-x", "outlet-plane"] +temperature_contour.surfaces_list = ["plane-4", "outlet"] temperature_contour.display("window-4") ############################################################################### @@ -112,12 +105,9 @@ 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", + "inlet1", + "inlet2", + "outlet", ] temperature_contour_manifold.display("window-5") @@ -126,7 +116,7 @@ # 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.surfaces_list = ["outlet"] velocity_vector.scale = 1 velocity_vector.display("window-6") From a75582990eebe359213e840bac59c85a42d31fcd Mon Sep 17 00:00:00 2001 From: Mainak Kundu Date: Wed, 4 May 2022 12:04:59 +0530 Subject: [PATCH 3/3] Error from parametric_static_mixer_3 --- examples/01-parametric/parametric_static_mixer_3.py | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/examples/01-parametric/parametric_static_mixer_3.py b/examples/01-parametric/parametric_static_mixer_3.py index e487c4e8d630..691afc739fd4 100755 --- a/examples/01-parametric/parametric_static_mixer_3.py +++ b/examples/01-parametric/parametric_static_mixer_3.py @@ -74,12 +74,10 @@ data_frame = pd.read_csv(design_point_table_study_2) print(data_frame) -session.exit() - ######################################################################### # Access a new parametric session using the flprj saved earlier -project_session_filepath = str( - Path(pyfluent.EXAMPLES_PATH) / "static_mixer_study_save_as.flprj" -) -new_session = ParametricSession(project_filepath=project_session_filepath) +# project_session_filepath = str( +# Path(pyfluent.EXAMPLES_PATH) / "static_mixer_study_save_as.flprj" +# ) +# new_session = ParametricSession(project_filepath=project_session_filepath)