From 4a13f8289acc859343835b0474bbdcf43a0c4adf Mon Sep 17 00:00:00 2001 From: dkunhamb Date: Fri, 13 Dec 2024 12:12:22 -0600 Subject: [PATCH 01/68] exhaust manifold ini --- fluent-mechanical/README.rst | 8 ++ fluent-mechanical/requirements_24.1.txt | 2 + fluent-mechanical/requirements_24.2.txt | 2 + fluent-mechanical/wf_fm_02_mechanical.py | 94 ++++++++++++++++++++++++ 4 files changed, 106 insertions(+) create mode 100644 fluent-mechanical/README.rst create mode 100644 fluent-mechanical/requirements_24.1.txt create mode 100644 fluent-mechanical/requirements_24.2.txt create mode 100644 fluent-mechanical/wf_fm_02_mechanical.py diff --git a/fluent-mechanical/README.rst b/fluent-mechanical/README.rst new file mode 100644 index 00000000..1da01669 --- /dev/null +++ b/fluent-mechanical/README.rst @@ -0,0 +1,8 @@ +Geometry, mechanical and post-processing +======================================== + +This workflow demonstrates how to create a printed circuit board (PCB) geometry, mesh, +run steady state and transient thermal analysis, and post-process using DPF. The geometry +generated is a simple PCB with multiple chips. The exported CAD file (PMDB format) is then +imported inside Ansys Mechanical to run a steady-state thermal analysis followed by transient +analysis. diff --git a/fluent-mechanical/requirements_24.1.txt b/fluent-mechanical/requirements_24.1.txt new file mode 100644 index 00000000..9eda404d --- /dev/null +++ b/fluent-mechanical/requirements_24.1.txt @@ -0,0 +1,2 @@ +ansys-mechanical-core==0.11.10 +ansys-fluent-core==0.27.0 diff --git a/fluent-mechanical/requirements_24.2.txt b/fluent-mechanical/requirements_24.2.txt new file mode 100644 index 00000000..9eda404d --- /dev/null +++ b/fluent-mechanical/requirements_24.2.txt @@ -0,0 +1,2 @@ +ansys-mechanical-core==0.11.10 +ansys-fluent-core==0.27.0 diff --git a/fluent-mechanical/wf_fm_02_mechanical.py b/fluent-mechanical/wf_fm_02_mechanical.py new file mode 100644 index 00000000..0070dc58 --- /dev/null +++ b/fluent-mechanical/wf_fm_02_mechanical.py @@ -0,0 +1,94 @@ +# Copyright (C) 2024 ANSYS, Inc. and/or its affiliates. +# SPDX-License-Identifier: MIT +# +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. +""" +.. _ref_fluent_mechanical_02-mechanical: + +Mechanical - +############################# + +""" # noqa: D400, D415 + +import os +from pathlib import Path + +from ansys.mechanical.core import launch_mechanical +from ansys.mechanical.core.examples import download_file +from matplotlib import image as mpimg +from matplotlib import pyplot as plt + +############################################################################### +# Preparing the environment +# ------------------------- +# This section is only necessary for workflow runs and docs generation. It checks +# the environment variables to determine which image to use for the mechanical service. +# If you are running this script outside of a workflow, you can ignore this section. +# + +version = None +if "ANSYS_MECHANICAL_RELEASE" in os.environ: + image_tag = os.environ["ANSYS_MECHANICAL_RELEASE"] + version = int(image_tag.replace(".", "")) + +# sphinx_gallery_start_ignore +# Check if the __file__ variable is defined. If not, set it. +# This is a workaround to run the script in Sphinx-Gallery. +if "__file__" not in locals(): + __file__ = Path(os.getcwd(), "wf_gmd_02_mechanical.py") +# sphinx_gallery_end_ignore + +############################################################################### +# Parameters for the script +# ------------------------- +# The following parameters are used to control the script execution. You can +# modify these parameters to suit your needs. +# +GRAPHICS_BOOL = False # Set to True to display the graphics +OUTPUT_DIR = Path(Path(__file__).parent, "outputs") # Output directory + +# sphinx_gallery_start_ignore +if "DOC_BUILD" in os.environ: + GRAPHICS_BOOL = True +# sphinx_gallery_end_ignore + +############################################################################### +# Start a PyMechanical app +# ------------------------ +# +mechanical = launch_mechanical(batch=False, cleanup_on_exit=False) +print(mechanical) + + +def display_image(image_name): + plt.figure(figsize=(16, 9)) + plt.imshow(mpimg.imread(os.path.join(OUTPUT_DIR, image_name))) + plt.xticks([]) + plt.yticks([]) + plt.axis("off") + plt.show() + + +geometry_path = download_file( + "Exhaust_Manifold_Geometry.pmdb", "pyansys-workflow", "exhaust-manifold", "pymechanical" +) +material_path = download_file( + "Nonlinear_Material.xml", "pyansys-workflow", "exhaust-manifold", "pymechanical" +) From c3c9651c4825cce3e62e2870ca60a3767c2f7128 Mon Sep 17 00:00:00 2001 From: dkunhamb Date: Fri, 13 Dec 2024 13:44:50 -0600 Subject: [PATCH 02/68] update ci cd --- .github/workflows/fluent-mechanical.yml | 236 +++++++++++++++++++++++ fluent-mechanical/wf_fm_01_fluent.py | 23 +++ fluent-mechanical/wf_fm_02_mechanical.py | 3 + 3 files changed, 262 insertions(+) create mode 100644 .github/workflows/fluent-mechanical.yml create mode 100644 fluent-mechanical/wf_fm_01_fluent.py diff --git a/.github/workflows/fluent-mechanical.yml b/.github/workflows/fluent-mechanical.yml new file mode 100644 index 00000000..5f7617b0 --- /dev/null +++ b/.github/workflows/fluent-mechanical.yml @@ -0,0 +1,236 @@ +name: Geometry Mesh Fluent Workflow + +on: + workflow_dispatch: + inputs: + doc-build: + required: false + default: false + type: boolean + description: 'Whether to build the documentation' + workflow_call: + inputs: + doc-build: + required: false + default: false + type: boolean + description: 'Whether to build the documentation' + push: + branches: + - main + pull_request: + paths: + - 'fluent-mechanical/**' + +env: + MAIN_PYTHON_VERSION: '3.12' + FLUENT_DOCKER_IMAGE: 'ghcr.io/ansys/pyfluent' + MECHANICAL_DOCKER_IMAGE: 'ghcr.io/ansys/mechanical' + ANSYSLMD_LICENSE_FILE: ${{ format('1055@{0}', secrets.LICENSE_SERVER )}} + PYANSYS_WORKFLOWS_CI: true + ANSYS_RELEASE_FOR_DOCS: 24.2 + RUN_DOC_BUILD: false + +jobs: + fluent: + name: Fluent + runs-on: public-ubuntu-latest-8-cores + strategy: + fail-fast: false + matrix: + ansys-release: [24.1, 24.2] + steps: + + - name: Checkout code + uses: actions/checkout@v4 + with: + sparse-checkout: | + fluent-mechanical + doc + + - name: Set up Python ${{ env.MAIN_PYTHON_VERSION }} + uses: actions/setup-python@v5 + with: + python-version: ${{ env.MAIN_PYTHON_VERSION }} + + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install -r fluent-mechanical/requirements_${{ matrix.ansys-release }}.txt + + - name: Login to GitHub Container Registry + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Download Fluent service container + run: docker pull ${{ env.FLUENT_DOCKER_IMAGE }}:v${{ matrix.ansys-release }}.0 + + - name: Check out the geometry outputs + uses: actions/download-artifact@v4 + with: + name: fluent-mechanical-workflow-fluent-outputs-${{ matrix.ansys-release }} + path: fluent-mechanical/outputs + + - name: Run the Fluent meshing script + env: + FLUENT_IMAGE_TAG: v${{ matrix.ansys-release }}.0 + run: | + python fluent-mechanical/wf_fm_01_fluent.py + + - name: Store the outputs + uses: actions/upload-artifact@v4 + with: + name: fluent-mechanical-workflow-fluent-outputs-${{ matrix.ansys-release }} + path: | + fluent-mechanical/outputs/htc_temp_mapping_LOW_TEMP + fluent-mechanical/outputs/htc_temp_mapping_MEDIUM_TEMP.csv + fluent-mechanical/outputs/htc_temp_mapping_HIGH_TEMP.csv + + - name: Stop all containers (if any) + run: | + if [ -n "$(docker ps -a -q)" ]; then + docker rm -f $(docker ps -a -q) + fi + + - name: (DOCS) Check if docs should be built + if: (github.event_name == 'workflow_dispatch' || github.event_name == 'schedule') && inputs.doc-build + run: | + echo "Requested to build docs..." + if [ "${{ matrix.ansys-release }}" == "${{ env.ANSYS_RELEASE_FOR_DOCS }}" ]; then + echo "Building docs" + echo "RUN_DOC_BUILD=true" >> $GITHUB_ENV + else + echo "Not building docs - since not primary release" + echo "RUN_DOC_BUILD=false" >> $GITHUB_ENV + fi + + - name: (DOCS) Download the docs artifacts + uses: actions/download-artifact@v4 + if: ${{ env.RUN_DOC_BUILD == 'true' }} + with: + name: fluent-mechanical-docs-stage-fluent + path: doc + + - name: (DOCS) Build the documentation (only on ${{ env.ANSYS_RELEASE_FOR_DOCS}}) + if: ${{ env.RUN_DOC_BUILD == 'true' }} + env: + FLUENT_IMAGE_TAG: v${{ matrix.ansys-release }}.0 + BUILD_DOCS_SCRIPT: 'fluent-mechanical/wf_fm_01_fluent.py' + run: | + cd doc + find . -type f -exec sed -i 's|C:\\Users\\ansys\\actions-runner\\_work\\pyansys-workflows\\pyansys-workflows\\doc\\source\\examples\\fluent-mechanical\\images\\|./images/|g' {} + + pip install -r requirements.txt + make html + + - name: (DOCS) Upload docs artifacts + if: ${{ env.RUN_DOC_BUILD == 'true' }} + uses: actions/upload-artifact@v4 + with: + name: fluent-mechanical-docs-stage-fluent + path: | + doc/_build/ + doc/source/examples/fluent-mechanical/ + overwrite: true + + geometry: + name: Mechanical + runs-on: [public-ubuntu-latest-8-cores] + needs: fluent + strategy: + fail-fast: false + matrix: + ansys-release: [24.1, 24.2] + steps: + + - name: Checkout code + uses: actions/checkout@v4 + with: + sparse-checkout: | + fluent-mechanical + doc + + - name: Set up Python ${{ env.MAIN_PYTHON_VERSION }} + uses: actions/setup-python@v5 + with: + python-version: ${{ env.MAIN_PYTHON_VERSION }} + + - name: Install system dependencies + run: | + sudo apt-get update + sudo apt-get install -y nodejs npm graphviz + npm install -g @mermaid-js/mermaid-cli + + - name: Install dependencies + run: | + python -m pip install --upgrade pip + python -m venv .venv + .venv/bin/activate + pip install -r fluent-mechanical/requirements_${{ matrix.ansys-release }}.txt + + - name: Login to GitHub Container Registry + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Download (if needed) and run Mechanical container + run: | + docker pull ${{ env.MECHANICAL_DOCKER_IMAGE }} + + - name: Run the PyMechanical script + env: + ANSYS_MECHANICAL_RELEASE: ${{ matrix.ansys-release }} + run: | + .venv/Scripts/activate + python fluent-mechanical/wf_fm_01_fluent.py + + - name: Store the outputs + uses: actions/upload-artifact@v4 + with: + name: fluent-mechanical-workflow-mechanical-outputs-${{ matrix.ansys-release }} + path: fluent-mechanical/outputs + + - name: (DOCS) Check if docs should be built + if: (github.event_name == 'workflow_dispatch' || github.event_name == 'schedule') && inputs.doc-build + run: | + Write-Host "Requested to build docs..." + if ("${{ matrix.ansys-release }}" -eq $env:ANSYS_RELEASE_FOR_DOCS) { + Write-Host "Building docs" + echo "RUN_DOC_BUILD=true" >> $env:GITHUB_ENV + } else { + Write-Host "Not building docs - since not primary release" + echo "RUN_DOC_BUILD=false" >> $env:GITHUB_ENV + } + + - name: (DOCS) Build the documentation (only on ${{ env.ANSYS_RELEASE_FOR_DOCS }}) + if: ${{ env.RUN_DOC_BUILD == 'true' }} + env: + ANSYS_GEOMETRY_RELEASE: ${{ matrix.ansys-release }} + BUILD_DOCS_SCRIPT: 'fluent-mechanical/wf_fm_01_fluent.py' + run: | + .venv/bin/activate + cd doc + pip install -r requirements.txt + ./make.bat html + + - name: (DOCS) Upload docs artifacts + if: ${{ env.RUN_DOC_BUILD == 'true' }} + uses: actions/upload-artifact@v4 + with: + name: fluent-mechanical-docs-stage-mechanical + path: | + doc/_build/ + doc/source/examples/fluent-mechanical/ + + - name: Stop any remaining containers + if: always() + run: | + $dockerContainers = docker ps -a -q + if (-not [string]::IsNullOrEmpty($dockerContainers)) { + docker stop $dockerContainers + docker rm $dockerContainers + } \ No newline at end of file diff --git a/fluent-mechanical/wf_fm_01_fluent.py b/fluent-mechanical/wf_fm_01_fluent.py new file mode 100644 index 00000000..028086af --- /dev/null +++ b/fluent-mechanical/wf_fm_01_fluent.py @@ -0,0 +1,23 @@ +# Copyright (C) 2024 ANSYS, Inc. and/or its affiliates. +# SPDX-License-Identifier: MIT +# +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. + +print("Hello World") diff --git a/fluent-mechanical/wf_fm_02_mechanical.py b/fluent-mechanical/wf_fm_02_mechanical.py index 0070dc58..c481574f 100644 --- a/fluent-mechanical/wf_fm_02_mechanical.py +++ b/fluent-mechanical/wf_fm_02_mechanical.py @@ -92,3 +92,6 @@ def display_image(image_name): material_path = download_file( "Nonlinear_Material.xml", "pyansys-workflow", "exhaust-manifold", "pymechanical" ) + + +print("Hello World") From 573298004c21f68546cd0321e0c8d2aee1c5346b Mon Sep 17 00:00:00 2001 From: dkunhamb Date: Fri, 13 Dec 2024 13:49:25 -0600 Subject: [PATCH 03/68] doc cicd update --- .github/workflows/docs.yml | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml index 33f45089..6bfb230c 100644 --- a/.github/workflows/docs.yml +++ b/.github/workflows/docs.yml @@ -14,23 +14,29 @@ jobs: uses: ./.github/workflows/geometry-mesh.yml secrets: inherit with: - doc-build: true + doc-build: false #testing geometry-mesh-fluent: uses: ./.github/workflows/geometry-mesh-fluent.yml secrets: inherit with: - doc-build: true + doc-build: false #testing geometry-mechanical-dpf: uses: ./.github/workflows/geometry-mechanical-dpf.yml secrets: inherit + with: + doc-build: false #testing + + fluent-mechanical: + uses: ./.github/workflows/fluent-mechanical.yml + secrets: inherit with: doc-build: true compile-docs: runs-on: ubuntu-latest - needs: [geometry-mesh, geometry-mesh-fluent, geometry-mechanical-dpf] + needs: [geometry-mesh, geometry-mesh-fluent, geometry-mechanical-dpf, fluent-mechanical] steps: - name: Checkout code uses: actions/checkout@v4 @@ -66,6 +72,12 @@ jobs: name: geometry-mechanical-dpf-docs path: doc/ + - name: Download artifacts for fluent-mechanical + uses: actions/download-artifact@v4 + with: + name: fluent-mechanical-docs + path: doc/ + - name: Build the documentation run: | cd doc From 8fda7784750ac605c933894a4700d333c1039819 Mon Sep 17 00:00:00 2001 From: dkunhamb Date: Fri, 13 Dec 2024 13:50:15 -0600 Subject: [PATCH 04/68] update ci cd title --- .github/workflows/fluent-mechanical.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/fluent-mechanical.yml b/.github/workflows/fluent-mechanical.yml index 5f7617b0..c7aa33be 100644 --- a/.github/workflows/fluent-mechanical.yml +++ b/.github/workflows/fluent-mechanical.yml @@ -1,4 +1,4 @@ -name: Geometry Mesh Fluent Workflow +name: Fluent - Mechanical Exhaust Manifold Workflow on: workflow_dispatch: From 5d491674a5bedae7300e4b41af6026ee3d98c61e Mon Sep 17 00:00:00 2001 From: dkunhamb Date: Fri, 13 Dec 2024 13:52:25 -0600 Subject: [PATCH 05/68] readme tbd --- fluent-mechanical/README.rst | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/fluent-mechanical/README.rst b/fluent-mechanical/README.rst index 1da01669..e673f1da 100644 --- a/fluent-mechanical/README.rst +++ b/fluent-mechanical/README.rst @@ -1,8 +1,4 @@ -Geometry, mechanical and post-processing -======================================== +Fluent - Mechanical workflow +============================ -This workflow demonstrates how to create a printed circuit board (PCB) geometry, mesh, -run steady state and transient thermal analysis, and post-process using DPF. The geometry -generated is a simple PCB with multiple chips. The exported CAD file (PMDB format) is then -imported inside Ansys Mechanical to run a steady-state thermal analysis followed by transient -analysis. +TBD From 53399e54fd19e1cb1d46e2bc880e1ddcf5e61b2e Mon Sep 17 00:00:00 2001 From: dkunhamb Date: Fri, 13 Dec 2024 16:00:21 -0600 Subject: [PATCH 06/68] update ci cd for mechanical --- .github/workflows/fluent-mechanical.yml | 61 +++++++++++-------------- 1 file changed, 26 insertions(+), 35 deletions(-) diff --git a/.github/workflows/fluent-mechanical.yml b/.github/workflows/fluent-mechanical.yml index c7aa33be..0b204cca 100644 --- a/.github/workflows/fluent-mechanical.yml +++ b/.github/workflows/fluent-mechanical.yml @@ -68,13 +68,7 @@ jobs: - name: Download Fluent service container run: docker pull ${{ env.FLUENT_DOCKER_IMAGE }}:v${{ matrix.ansys-release }}.0 - - name: Check out the geometry outputs - uses: actions/download-artifact@v4 - with: - name: fluent-mechanical-workflow-fluent-outputs-${{ matrix.ansys-release }} - path: fluent-mechanical/outputs - - - name: Run the Fluent meshing script + - name: Run the Fluent script env: FLUENT_IMAGE_TAG: v${{ matrix.ansys-release }}.0 run: | @@ -135,7 +129,7 @@ jobs: doc/source/examples/fluent-mechanical/ overwrite: true - geometry: + mechanical: name: Mechanical runs-on: [public-ubuntu-latest-8-cores] needs: fluent @@ -167,7 +161,7 @@ jobs: run: | python -m pip install --upgrade pip python -m venv .venv - .venv/bin/activate + . .venv/bin/activate pip install -r fluent-mechanical/requirements_${{ matrix.ansys-release }}.txt - name: Login to GitHub Container Registry @@ -181,12 +175,18 @@ jobs: run: | docker pull ${{ env.MECHANICAL_DOCKER_IMAGE }} + - name: Check out the geometry outputs + uses: actions/download-artifact@v4 + with: + name: fluent-mechanical-workflow-fluent-outputs-${{ matrix.ansys-release }} + path: fluent-mechanical/outputs + - name: Run the PyMechanical script env: ANSYS_MECHANICAL_RELEASE: ${{ matrix.ansys-release }} run: | - .venv/Scripts/activate - python fluent-mechanical/wf_fm_01_fluent.py + . .venv/bin/activate + xvfb-run python fluent-mechanical - name: Store the outputs uses: actions/upload-artifact@v4 @@ -197,25 +197,25 @@ jobs: - name: (DOCS) Check if docs should be built if: (github.event_name == 'workflow_dispatch' || github.event_name == 'schedule') && inputs.doc-build run: | - Write-Host "Requested to build docs..." - if ("${{ matrix.ansys-release }}" -eq $env:ANSYS_RELEASE_FOR_DOCS) { - Write-Host "Building docs" - echo "RUN_DOC_BUILD=true" >> $env:GITHUB_ENV - } else { - Write-Host "Not building docs - since not primary release" - echo "RUN_DOC_BUILD=false" >> $env:GITHUB_ENV - } + echo "Requested to build docs..." + if [ "${{ matrix.ansys-release }}" = "${{ env.ANSYS_RELEASE_FOR_DOCS }}" ]; then + echo "Building docs" + echo "RUN_DOC_BUILD=true" >> $GITHUB_ENV + else + echo "Not building docs - since not primary release" + echo "RUN_DOC_BUILD=false" >> $GITHUB_ENV + fi - name: (DOCS) Build the documentation (only on ${{ env.ANSYS_RELEASE_FOR_DOCS }}) if: ${{ env.RUN_DOC_BUILD == 'true' }} env: - ANSYS_GEOMETRY_RELEASE: ${{ matrix.ansys-release }} - BUILD_DOCS_SCRIPT: 'fluent-mechanical/wf_fm_01_fluent.py' + ANSYS_MECHANICAL_RELEASE: ${{ matrix.ansys-release }} + BUILD_DOCS_SCRIPT: 'geometry-mechanical-dpf/wf_gmd_02_mechanical.py' run: | - .venv/bin/activate - cd doc - pip install -r requirements.txt - ./make.bat html + . .venv/bin/activate + find . -type f -exec sed -i 's|C:\\Users\\ansys\\actions-runner\\_work\\pyansys-workflows\\pyansys-workflows\\doc\\source\\examples\\fluent-mechanical\\images\\|./images/|g' {} + + pip install -r ./doc/requirements.txt + xvfb-run make -C doc html - name: (DOCS) Upload docs artifacts if: ${{ env.RUN_DOC_BUILD == 'true' }} @@ -224,13 +224,4 @@ jobs: name: fluent-mechanical-docs-stage-mechanical path: | doc/_build/ - doc/source/examples/fluent-mechanical/ - - - name: Stop any remaining containers - if: always() - run: | - $dockerContainers = docker ps -a -q - if (-not [string]::IsNullOrEmpty($dockerContainers)) { - docker stop $dockerContainers - docker rm $dockerContainers - } \ No newline at end of file + doc/source/examples/fluent-mechanical/ \ No newline at end of file From d38123bd7f386bea53a16cece6dd82be003333b9 Mon Sep 17 00:00:00 2001 From: dkunhamb Date: Fri, 13 Dec 2024 16:53:22 -0600 Subject: [PATCH 07/68] updated pymech script --- fluent-mechanical/wf_fm_02_mechanical copy.py | 935 ++++++++++++++++++ fluent-mechanical/wf_fm_02_mechanical.py | 856 +++++++++++++++- 2 files changed, 1788 insertions(+), 3 deletions(-) create mode 100644 fluent-mechanical/wf_fm_02_mechanical copy.py diff --git a/fluent-mechanical/wf_fm_02_mechanical copy.py b/fluent-mechanical/wf_fm_02_mechanical copy.py new file mode 100644 index 00000000..3eb91907 --- /dev/null +++ b/fluent-mechanical/wf_fm_02_mechanical copy.py @@ -0,0 +1,935 @@ +# Copyright (C) 2024 ANSYS, Inc. and/or its affiliates. +# SPDX-License-Identifier: MIT +# +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. +""" +.. _ref_fluent_mechanical_02-mechanical: + +Thermo-mechanical assessment of representative exhaust manifold model +##################################################################### + +MultiPhysics example: Thermo-Mechanical simulation on a representative exhuast manifold +model. + +""" # noqa: D400, D415 + +import os +from pathlib import Path + +from ansys.mechanical.core import launch_mechanical +from ansys.mechanical.core.examples import download_file +from matplotlib import image as mpimg +from matplotlib import pyplot as plt + +############################################################################### +# Preparing the environment +# ------------------------- +# This section is only necessary for workflow runs and docs generation. It checks +# the environment variables to determine which image to use for the mechanical service. +# If you are running this script outside of a workflow, you can ignore this section. +# + +version = None +if "ANSYS_MECHANICAL_RELEASE" in os.environ: + image_tag = os.environ["ANSYS_MECHANICAL_RELEASE"] + version = int(image_tag.replace(".", "")) + +# sphinx_gallery_start_ignore +# Check if the __file__ variable is defined. If not, set it. +# This is a workaround to run the script in Sphinx-Gallery. +if "__file__" not in locals(): + __file__ = Path(os.getcwd(), "wf_gmd_02_mechanical.py") +# sphinx_gallery_end_ignore + +############################################################################### +# Parameters for the script +# ------------------------- +# The following parameters are used to control the script execution. You can +# modify these parameters to suit your needs. +# +GRAPHICS_BOOL = False # Set to True to display the graphics +OUTPUT_DIR = Path(Path(__file__).parent, "outputs") # Output directory + +# sphinx_gallery_start_ignore +if "DOC_BUILD" in os.environ: + GRAPHICS_BOOL = True +# sphinx_gallery_end_ignore + +############################################################################### +# Start a PyMechanical app +# ------------------------ +# +mechanical = launch_mechanical(batch=False, cleanup_on_exit=False) +print(mechanical) + + +def display_image(image_name): + plt.figure(figsize=(16, 9)) + plt.imshow(mpimg.imread(os.path.join(OUTPUT_DIR, image_name))) + plt.xticks([]) + plt.yticks([]) + plt.axis("off") + plt.show() + + +############################################################################### +# Input files needed for the simulation +# ---------------- -------------------- +# Download the input files needed for the simulation. +# +geometry_path = download_file( + "Exhaust_Manifold_Geometry.pmdb", "pyansys-workflow", "exhaust-manifold", "pymechanical" +) +material_path = download_file( + "Nonlinear_Material.xml", "pyansys-workflow", "exhaust-manifold", "pymechanical" +) + +# Files necessary for the thermal simulation from fluent analysis + +temp_htc_data_high_path = os.path.join(OUTPUT_DIR, "htc_temp_mapping_HIGH_TEMP.csv") +temp_htc_data_med_path = os.path.join(OUTPUT_DIR, "htc_temp_mapping_MEDIUM_TEMP.csv") +temp_htc_data_low_path = os.path.join(OUTPUT_DIR, "htc_temp_mapping_LOW_TEMP.csv") + +all_input_files = { + "geometry_path": geometry_path, + "material_path": material_path, + "temp_htc_data_high_path": temp_htc_data_high_path, + "temp_htc_data_med_path": temp_htc_data_med_path, + "temp_htc_data_low_path": temp_htc_data_low_path, +} + +# Upload to Mechanical Remote session server and get the file paths + +project_directory = mechanical.project_directory +print(f"project directory = {project_directory}") +for input_file_name, input_file_path in all_input_files.items(): + + # Upload the file to the project directory. + mechanical.upload(file_name=input_file_path, file_location_destination=project_directory) + + # Build the path relative to project directory. + base_name = os.path.basename(input_file_path) + combined_path = os.path.join(project_directory, base_name) + server_file_path = combined_path.replace("\\", "\\\\") + mechanical.run_python_script(f"{input_file_name} = '{server_file_path}'") + result = mechanical.run_python_script(f"{input_file_name}") + print(f"path of {input_file_name} on server: {result}") + + +############################################################################### +# Configure graphics for image export +# ----------------------------------- +# + +mechanical.run_python_script( + """ +ExtAPI.Graphics.Camera.SetSpecificViewOrientation( + Ansys.Mechanical.DataModel.Enums.ViewOrientationType.Iso +) +ExtAPI.Graphics.Camera.SetFit() +image_export_format = Ansys.Mechanical.DataModel.Enums.GraphicsImageExportFormat.PNG +settings_720p = Ansys.Mechanical.Graphics.GraphicsImageExportSettings() +settings_720p.Resolution = ( + Ansys.Mechanical.DataModel.Enums.GraphicsResolutionType.EnhancedResolution +) +settings_720p.Background = Ansys.Mechanical.DataModel.Enums.GraphicsBackgroundType.White +settings_720p.Width = 1280 +settings_720p.Height = 720 +settings_720p.CurrentGraphicsDisplay = False +""" +) + +############################################################################### +# Import geometry +# --------------- +# + + +import os + +geometry_import_group = Model.GeometryImportGroup +geometry_import = geometry_import_group.AddGeometryImport() +geometry_import_format = Ansys.Mechanical.DataModel.Enums.GeometryImportPreference.Format.Automatic +geometry_import_preferences = Ansys.ACT.Mechanical.Utilities.GeometryImportPreferences() +geometry_import_preferences.ProcessNamedSelections = True +geometry_import_preferences.NamedSelectionKey = "" +geometry_import_preferences.ProcessMaterialProperties = True +geometry_import_preferences.ProcessCoordinateSystems = True +geometry_import.Import(geometry_path, geometry_import_format, geometry_import_preferences) +project_directory = ExtAPI.DataModel.Project.ProjectDirectory +ExtAPI.Graphics.Camera.SetFit() +ExtAPI.Graphics.ExportImage( + os.path.join(project_directory, "geometry.png"), image_export_format, settings_720p +) + +mechanical.download(files=os.path.join(project_directory, "geometry.png"), target_dir=OUTPUT_DIR) +display_image("geometry.png") + + +############################################################################### +# Import material, assign it to the bodies and create Named Selections +# -------------------------------------------------------------------- +# + + +materials = ExtAPI.DataModel.Project.Model.Materials +materials.Import(material_path) +materials.RefreshMaterials() + +PRT1 = [x for x in ExtAPI.DataModel.Tree.AllObjects if x.Name == "Geom-2\Geom-1\solid"][0] + +# Assign it to the bodies +nmat = "1_HiSi_Model3_Exhaust Manifold updated" +PRT1.Material = nmat + + +# Select MKS units +ExtAPI.Application.ActiveUnitSystem = Ansys.ACT.Interfaces.Common.MechanicalUnitSystem.StandardMKS + +# Store all main tree nodes as variables +GEOM = Model.Geometry +MAT_GRP = Model.Materials + +# Create NS for Named Selection. + +NS_GRP = ExtAPI.DataModel.Project.Model.NamedSelections +BRACKET_FIX_NS = [x for x in ExtAPI.DataModel.Tree.AllObjects if x.Name == "bracket_fix"][0] +INTERFACE_SURFACE_NS = [ + x for x in ExtAPI.DataModel.Tree.AllObjects if x.Name == "interface_surface" +][0] +EXHAUST_MANIFOLD_NS = [x for x in ExtAPI.DataModel.Tree.AllObjects if x.Name == "exhaust_manifold"][ + 0 +] +TOP_BRACKET_SURFACE_NS = [ + x for x in ExtAPI.DataModel.Tree.AllObjects if x.Name == "top_bracket_surface" +][0] +SPACERS_NS = [x for x in ExtAPI.DataModel.Tree.AllObjects if x.Name == "spacers"][0] +EM_OUTER_SURFACE_NS = [x for x in ExtAPI.DataModel.Tree.AllObjects if x.Name == "em_outer_surface"][ + 0 +] + +MESH = Model.Mesh +MESH.ElementSize = Quantity(0.004, "m") +MESH.UseAdaptiveSizing = False +MESH.MaximumSize = Quantity(0.004, "m") +MESH.ShapeChecking = 0 +body_sizing = MESH.AddSizing() +selection = NS_GRP.Children[5] +body_sizing.Location = selection +body_sizing.ElementSize = Quantity(4e-3, "m") +# body_sizing.CaptureCurvature = True +# body_sizing.CurvatureNormalAngle = Quantity(0.31, "rad") +# body_sizing.LocalMinimumSize = Quantity(0.00025, "m") + +Tree.Activate([MESH]) +MESH.GenerateMesh() + +# Export mesh image + +ExtAPI.Graphics.Camera.SetFit() +ExtAPI.Graphics.ExportImage( + os.path.join(project_directory, "mesh.png"), image_export_format, settings_720p +) + +mechanical.download(files=os.path.join(project_directory, "mesh.png"), target_dir=OUTPUT_DIR) +display_image("mesh.png") + +############################################################################### +# Add Transient Thermal Analysis and set up the analysis settings +# --------------------------------------------------------------- +# + + +Model.AddTransientThermalAnalysis() + +# Store all main tree nodes as variables + +TRANS_THERM = Model.Analyses[0] +TRANS_THERM_SOLN = TRANS_THERM.Solution +ANA_SETTINGS = TRANS_THERM.Children[1] + +# Setup transient thermal analysis settings + +# ANA_SETTINGS.AutomaticTimeStepping = AutomaticTimeStepping.On +ANA_SETTINGS.SolverType = SolverType.Direct +ANA_SETTINGS.NonLinearFormulation = NonLinearFormulationType.Full + +ANA_SETTINGS.NumberOfSteps = 1 +ANA_SETTINGS.SetStepEndTime(1, Quantity("720[s]")) +ANA_SETTINGS.NumberOfSteps = 14 +analysis_step = ( + (1, Quantity("1e-3[s]")), + (2, Quantity("2e-3[s]")), + (3, Quantity("20[s]")), + (4, Quantity("30[s]")), + (5, Quantity("320[s]")), + (6, Quantity("330[s]")), + (7, Quantity("350[s]")), + (8, Quantity("360[s]")), + (9, Quantity("380[s]")), + (10, Quantity("390[s]")), + (11, Quantity("680[s]")), + (12, Quantity("690[s]")), + (13, Quantity("710[s]")), + (14, Quantity("720[s]")), +) +for i, q in analysis_step: + ANA_SETTINGS.SetStepEndTime(i, q) + +# Applied External HTCs and Temperature data + +External_Convection_Load_1 = TRANS_THERM.AddConvection() +selection = NS_GRP.Children[8] +External_Convection_Load_1.Location = selection + +External_Convection_Load_1.FilmCoefficient.Inputs[0].DiscreteValues = [ + Quantity("0[s]"), + Quantity("1e-3[s]"), + Quantity("2e-3[s]"), + Quantity("20[s]"), + Quantity("30[s]"), + Quantity("320[s]"), + Quantity("330[s]"), + Quantity("350[s]"), + Quantity("360[s]"), + Quantity("380[s]"), + Quantity("390[s]"), + Quantity("680[s]"), + Quantity("690[s]"), + Quantity("710[s]"), + Quantity("720[s]"), +] + +External_Convection_Load_1.FilmCoefficient.Output.DiscreteValues = [ + Quantity("60[W m^-1 m^-1 K^-1]"), + Quantity("60[W m^-1 m^-1 K^-1]"), + Quantity("60[W m^-1 m^-1 K^-1]"), + Quantity("60[W m^-1 m^-1 K^-1]"), + Quantity("60[W m^-1 m^-1 K^-1]"), + Quantity("60[W m^-1 m^-1 K^-1]"), + Quantity("60[W m^-1 m^-1 K^-1]"), + Quantity("60[W m^-1 m^-1 K^-1]"), + Quantity("60[W m^-1 m^-1 K^-1]"), + Quantity("60[W m^-1 m^-1 K^-1]"), + Quantity("60[W m^-1 m^-1 K^-1]"), + Quantity("60[W m^-1 m^-1 K^-1]"), + Quantity("60[W m^-1 m^-1 K^-1]"), + Quantity("60[W m^-1 m^-1 K^-1]"), + Quantity("60[W m^-1 m^-1 K^-1]"), +] + +External_Convection_Load_1.AmbientTemperature.Inputs[0].DiscreteValues = [ + Quantity("0[s]"), + Quantity("1e-3[s]"), + Quantity("2e-3[s]"), + Quantity("20[s]"), + Quantity("30[s]"), + Quantity("320[s]"), + Quantity("330[s]"), + Quantity("350[s]"), + Quantity("360[s]"), + Quantity("380[s]"), + Quantity("390[s]"), + Quantity("680[s]"), + Quantity("690[s]"), + Quantity("710[s]"), + Quantity("720[s]"), +] + +External_Convection_Load_1.AmbientTemperature.Output.DiscreteValues = [ + Quantity("473.15[K]"), + Quantity("473.15[K]"), + Quantity("473.15[K]"), + Quantity("473.15[K]"), + Quantity("473.15[K]"), + Quantity("473.15[K]"), + Quantity("473.15[K]"), + Quantity("473.15[K]"), + Quantity("473.15[K]"), + Quantity("473.15[K]"), + Quantity("473.15[K]"), + Quantity("473.15[K]"), + Quantity("473.15[K]"), + Quantity("473.15[K]"), + Quantity("473.15[K]"), +] + + +External_Convection_Load_2 = TRANS_THERM.AddConvection() +selection = NS_GRP.Children[7] +External_Convection_Load_2.Location = selection + +External_Convection_Load_2.FilmCoefficient.Inputs[0].DiscreteValues = [ + Quantity("0[s]"), + Quantity("1e-3[s]"), + Quantity("2e-3[s]"), + Quantity("20[s]"), + Quantity("30[s]"), + Quantity("320[s]"), + Quantity("330[s]"), + Quantity("350[s]"), + Quantity("360[s]"), + Quantity("380[s]"), + Quantity("390[s]"), + Quantity("680[s]"), + Quantity("690[s]"), + Quantity("710[s]"), + Quantity("720[s]"), +] + +External_Convection_Load_2.FilmCoefficient.Output.DiscreteValues = [ + Quantity("20[W m^-1 m^-1 K^-1]"), + Quantity("20[W m^-1 m^-1 K^-1]"), + Quantity("20[W m^-1 m^-1 K^-1]"), + Quantity("20[W m^-1 m^-1 K^-1]"), + Quantity("20[W m^-1 m^-1 K^-1]"), + Quantity("20[W m^-1 m^-1 K^-1]"), + Quantity("20[W m^-1 m^-1 K^-1]"), + Quantity("20[W m^-1 m^-1 K^-1]"), + Quantity("20[W m^-1 m^-1 K^-1]"), + Quantity("20[W m^-1 m^-1 K^-1]"), + Quantity("20[W m^-1 m^-1 K^-1]"), + Quantity("20[W m^-1 m^-1 K^-1]"), + Quantity("20[W m^-1 m^-1 K^-1]"), + Quantity("20[W m^-1 m^-1 K^-1]"), + Quantity("20[W m^-1 m^-1 K^-1]"), +] + +External_Convection_Load_2.AmbientTemperature.Inputs[0].DiscreteValues = [ + Quantity("0[s]"), + Quantity("1e-3[s]"), + Quantity("2e-3[s]"), + Quantity("20[s]"), + Quantity("30[s]"), + Quantity("320[s]"), + Quantity("330[s]"), + Quantity("350[s]"), + Quantity("360[s]"), + Quantity("380[s]"), + Quantity("390[s]"), + Quantity("680[s]"), + Quantity("690[s]"), + Quantity("710[s]"), + Quantity("720[s]"), +] + +External_Convection_Load_2.AmbientTemperature.Output.DiscreteValues = [ + Quantity("498.15[K]"), + Quantity("498.15[K]"), + Quantity("498.15[K]"), + Quantity("498.15[K]"), + Quantity("498.15[K]"), + Quantity("498.15[K]"), + Quantity("498.15[K]"), + Quantity("498.15[K]"), + Quantity("498.15[K]"), + Quantity("498.15[K]"), + Quantity("498.15[K]"), + Quantity("498.15[K]"), + Quantity("498.15[K]"), + Quantity("498.15[K]"), + Quantity("498.15[K]"), +] + + +External_Convection_Load_3 = TRANS_THERM.AddConvection() +selection = NS_GRP.Children[6] +External_Convection_Load_3.Location = selection + +External_Convection_Load_3.FilmCoefficient.Inputs[0].DiscreteValues = [ + Quantity("0[s]"), + Quantity("1e-3[s]"), + Quantity("2e-3[s]"), + Quantity("20[s]"), + Quantity("30[s]"), + Quantity("320[s]"), + Quantity("330[s]"), + Quantity("350[s]"), + Quantity("360[s]"), + Quantity("380[s]"), + Quantity("390[s]"), + Quantity("680[s]"), + Quantity("690[s]"), + Quantity("710[s]"), + Quantity("720[s]"), +] + +External_Convection_Load_3.FilmCoefficient.Output.DiscreteValues = [ + Quantity("500[W m^-1 m^-1 K^-1]"), + Quantity("500[W m^-1 m^-1 K^-1]"), + Quantity("500[W m^-1 m^-1 K^-1]"), + Quantity("500[W m^-1 m^-1 K^-1]"), + Quantity("500[W m^-1 m^-1 K^-1]"), + Quantity("500[W m^-1 m^-1 K^-1]"), + Quantity("500[W m^-1 m^-1 K^-1]"), + Quantity("500[W m^-1 m^-1 K^-1]"), + Quantity("500[W m^-1 m^-1 K^-1]"), + Quantity("500[W m^-1 m^-1 K^-1]"), + Quantity("500[W m^-1 m^-1 K^-1]"), + Quantity("500[W m^-1 m^-1 K^-1]"), + Quantity("500[W m^-1 m^-1 K^-1]"), + Quantity("500[W m^-1 m^-1 K^-1]"), + Quantity("500[W m^-1 m^-1 K^-1]"), +] + +External_Convection_Load_3.AmbientTemperature.Inputs[0].DiscreteValues = [ + Quantity("0[s]"), + Quantity("1e-3[s]"), + Quantity("2e-3[s]"), + Quantity("20[s]"), + Quantity("30[s]"), + Quantity("320[s]"), + Quantity("330[s]"), + Quantity("350[s]"), + Quantity("360[s]"), + Quantity("380[s]"), + Quantity("390[s]"), + Quantity("680[s]"), + Quantity("690[s]"), + Quantity("710[s]"), + Quantity("720[s]"), +] + +External_Convection_Load_3.AmbientTemperature.Output.DiscreteValues = [ + Quantity("373.15[K]"), + Quantity("373.15[K]"), + Quantity("373.15[K]"), + Quantity("373.15[K]"), + Quantity("373.15[K]"), + Quantity("373.15[K]"), + Quantity("373.15[K]"), + Quantity("373.15[K]"), + Quantity("373.15[K]"), + Quantity("373.15[K]"), + Quantity("373.15[K]"), + Quantity("373.15[K]"), + Quantity("373.15[K]"), + Quantity("373.15[K]"), + Quantity("373.15[K]"), +] + +group_list = [External_Convection_Load_1, External_Convection_Load_2, External_Convection_Load_3] +grouping_folder = Tree.Group(group_list) +tree_grouping_folder_70 = DataModel.GetObjectsByName("New Folder") + + +############################################################################### +# Use the ouput from Fluent to import the temperature and HTC data +# --------------------------------------------------------------- +# + +# Import HTCs and Temperature data From Fluent run + +Imported_Load_Group = TRANS_THERM.AddImportedLoadExternalData() +imported_load_group_61 = Imported_Load_Group +imported_convection_62 = imported_load_group_61.AddImportedConvection() + +external_data_files = Ansys.Mechanical.ExternalData.ExternalDataFileCollection() +external_data_files.SaveFilesWithProject = False +external_data_file_1 = Ansys.Mechanical.ExternalData.ExternalDataFile() +external_data_files.Add(external_data_file_1) +external_data_file_1.Identifier = "File1" +external_data_file_1.Description = "High" +external_data_file_1.IsMainFile = True +external_data_file_1.FilePath = temp_htc_data_high_path +external_data_file_1.ImportSettings = ( + Ansys.Mechanical.ExternalData.ImportSettingsFactory.GetSettingsForFormat( + MechanicalEnums.ExternalData.ImportFormat.Delimited + ) +) +import_settings = external_data_file_1.ImportSettings +import_settings.SkipRows = 1 +import_settings.SkipFooter = 0 +import_settings.Delimiter = "," +import_settings.AverageCornerNodesToMidsideNodes = False +import_settings.UseColumn(0, MechanicalEnums.ExternalData.VariableType.NodeId, "", "Node ID@A") +import_settings.UseColumn( + 1, MechanicalEnums.ExternalData.VariableType.XCoordinate, "m", "X Coordinate@B" +) +import_settings.UseColumn( + 2, MechanicalEnums.ExternalData.VariableType.YCoordinate, "m", "Y Coordinate@C" +) +import_settings.UseColumn( + 3, MechanicalEnums.ExternalData.VariableType.ZCoordinate, "m", "Z Coordinate@D" +) +import_settings.UseColumn( + 4, MechanicalEnums.ExternalData.VariableType.Temperature, "K", "Temperature@E" +) +import_settings.UseColumn( + 5, + MechanicalEnums.ExternalData.VariableType.HeatTransferCoefficient, + "W m^-2 K^-1", + "Heat Transfer Coefficient@F", +) +external_data_file_2 = Ansys.Mechanical.ExternalData.ExternalDataFile() +external_data_files.Add(external_data_file_2) +external_data_file_2.Identifier = "File2" +external_data_file_2.Description = "Med" +external_data_file_2.IsMainFile = False +external_data_file_2.FilePath = temp_htc_data_med_path +external_data_file_2.ImportSettings = ( + Ansys.Mechanical.ExternalData.ImportSettingsFactory.GetSettingsForFormat( + MechanicalEnums.ExternalData.ImportFormat.Delimited + ) +) +import_settings = external_data_file_2.ImportSettings +import_settings.SkipRows = 1 +import_settings.SkipFooter = 0 +import_settings.Delimiter = "," +import_settings.AverageCornerNodesToMidsideNodes = False +import_settings.UseColumn(0, MechanicalEnums.ExternalData.VariableType.NodeId, "", "Node ID@A") +import_settings.UseColumn( + 1, MechanicalEnums.ExternalData.VariableType.XCoordinate, "m", "X Coordinate@B" +) +import_settings.UseColumn( + 2, MechanicalEnums.ExternalData.VariableType.YCoordinate, "m", "Y Coordinate@C" +) +import_settings.UseColumn( + 3, MechanicalEnums.ExternalData.VariableType.ZCoordinate, "m", "Z Coordinate@D" +) +import_settings.UseColumn( + 4, MechanicalEnums.ExternalData.VariableType.Temperature, "K", "Temperature@E" +) +import_settings.UseColumn( + 5, + MechanicalEnums.ExternalData.VariableType.HeatTransferCoefficient, + "W m^-2 K^-1", + "Heat Transfer Coefficient@F", +) +external_data_file_3 = Ansys.Mechanical.ExternalData.ExternalDataFile() +external_data_files.Add(external_data_file_3) +external_data_file_3.Identifier = "File3" +external_data_file_3.Description = "Low" +external_data_file_3.IsMainFile = False +external_data_file_3.FilePath = temp_htc_data_low_path +external_data_file_3.ImportSettings = ( + Ansys.Mechanical.ExternalData.ImportSettingsFactory.GetSettingsForFormat( + MechanicalEnums.ExternalData.ImportFormat.Delimited + ) +) +import_settings = external_data_file_3.ImportSettings +import_settings.SkipRows = 1 +import_settings.SkipFooter = 0 +import_settings.Delimiter = "," +import_settings.AverageCornerNodesToMidsideNodes = False +import_settings.UseColumn(0, MechanicalEnums.ExternalData.VariableType.NodeId, "", "Node ID@A") +import_settings.UseColumn( + 1, MechanicalEnums.ExternalData.VariableType.XCoordinate, "m", "X Coordinate@B" +) +import_settings.UseColumn( + 2, MechanicalEnums.ExternalData.VariableType.YCoordinate, "m", "Y Coordinate@C" +) +import_settings.UseColumn( + 3, MechanicalEnums.ExternalData.VariableType.ZCoordinate, "m", "Z Coordinate@D" +) +import_settings.UseColumn( + 4, MechanicalEnums.ExternalData.VariableType.Temperature, "K", "Temperature@E" +) +import_settings.UseColumn( + 5, + MechanicalEnums.ExternalData.VariableType.HeatTransferCoefficient, + "W m^-2 K^-1", + "Heat Transfer Coefficient@F", +) + +imported_load_group_61.ImportExternalDataFiles(external_data_files) + +table = imported_load_group_61.Children[0].GetTableByName("Film Coefficient") +numofsteps = 15 +Film_Coeff = [ + "File1:Heat Transfer Coefficient@F", + "File2:Heat Transfer Coefficient@F", + "File3:Heat Transfer Coefficient@F", +] +Amb_Temp = ["File1:Temperature@E", "File2:Temperature@E", "File3:Temperature@E"] +Ana_time = [ + "0", + "1e-3", + "2e-3", + "20", + "30", + "320", + "330", + "350", + "360", + "380", + "390", + "680", + "690", + "710", + "720", +] + +for i in range(numofsteps - 1): + table.Add(None) + +table[0][0] = Film_Coeff[2] +table[0][1] = Amb_Temp[2] +table[0][2] = Ana_time[0] + +table[1][0] = Film_Coeff[2] +table[1][1] = Amb_Temp[2] +table[1][2] = Ana_time[1] + +table[2][0] = Film_Coeff[2] +table[2][1] = Amb_Temp[2] +table[2][2] = Ana_time[2] + +table[3][0] = Film_Coeff[2] +table[3][1] = Amb_Temp[2] +table[3][2] = Ana_time[3] + +table[4][0] = Film_Coeff[0] +table[4][1] = Amb_Temp[0] +table[4][2] = Ana_time[4] + +table[5][0] = Film_Coeff[0] +table[5][1] = Amb_Temp[0] +table[5][2] = Ana_time[5] + +table[6][0] = Film_Coeff[1] +table[6][1] = Amb_Temp[1] +table[6][2] = Ana_time[6] + +table[7][0] = Film_Coeff[1] +table[7][1] = Amb_Temp[1] +table[7][2] = Ana_time[7] + +table[8][0] = Film_Coeff[2] +table[8][1] = Amb_Temp[2] +table[8][2] = Ana_time[8] + +table[9][0] = Film_Coeff[2] +table[9][1] = Amb_Temp[2] +table[9][2] = Ana_time[9] + +table[10][0] = Film_Coeff[0] +table[10][1] = Amb_Temp[0] +table[10][2] = Ana_time[10] + +table[11][0] = Film_Coeff[0] +table[11][1] = Amb_Temp[0] +table[11][2] = Ana_time[11] + +table[12][0] = Film_Coeff[1] +table[12][1] = Amb_Temp[1] +table[12][2] = Ana_time[12] + +table[13][0] = Film_Coeff[1] +table[13][1] = Amb_Temp[1] +table[13][2] = Ana_time[13] + +table[14][0] = Film_Coeff[2] +table[14][1] = Amb_Temp[2] +table[14][2] = Ana_time[14] + +selection = NS_GRP.Children[4] +imported_convection_62.Location = selection +imported_load_id = imported_convection_62.ObjectId +imported_load = DataModel.GetObjectById(imported_load_id) + +# !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! +# imported_convection_62.InternalObject.ExternalLoadSteppingType = 1 +# !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +imported_load.ImportLoad() + +Tree.Activate([imported_load]) +ExtAPI.Graphics.Camera.SetFit() +ExtAPI.Graphics.ExportImage( + os.path.join(project_directory, "imported_temperature.png"), image_export_format, settings_720p +) + +mechanical.download( + files=os.path.join(project_directory, "imported_temperature.png"), target_dir=OUTPUT_DIR +) +if GRAPHICS_BOOL: + display_image("imported_temperature.png") + +############################################################################### +# Solve and post-process the results +# ---------------------------------- +# + +# Insert results objects + +Temp = TRANS_THERM_SOLN.AddTemperature() +Temp.DisplayTime = Quantity("680 [s]") + +# Run Solution: Transient Thermal Simulation + +# TRANS_THERM_SOLN.Solve(True) +TRANS_THERM_SS = TRANS_THERM_SOLN.Status + +# Export temperature image + +Tree.Activate([Temp]) +ExtAPI.Graphics.ViewOptions.ResultPreference.ExtraModelDisplay = ( + Ansys.Mechanical.DataModel.MechanicalEnums.Graphics.ExtraModelDisplay.NoWireframe +) +ExtAPI.Graphics.ExportImage( + os.path.join(project_directory, "temperature.png"), image_export_format, settings_720p +) + +mechanical.download(files=os.path.join(project_directory, "temperature.png"), target_dir=OUTPUT_DIR) +if GRAPHICS_BOOL: + display_image("temperature.png") + + +############################################################################### +# Setup Structural Analysis +# ------------------------- +# + +Model.AddStaticStructuralAnalysis() + +# Define analysis settings + +# Setup static structural analysis settings +STAT_STRUC = Model.Analyses[1] +STAT_STRUC_SOLN = STAT_STRUC.Solution +STAT_STRUC_ANA_SETTING = STAT_STRUC.Children[0] + +STAT_STRUC_ANA_SETTING.NumberOfSteps = 1 +STAT_STRUC_ANA_SETTING.SetStepEndTime(1, Quantity("720[s]")) +STAT_STRUC_ANA_SETTING.NumberOfSteps = 14 + +analysis_step = ( + (1, Quantity("1e-3[s]")), + (2, Quantity("2e-3[s]")), + (3, Quantity("20[s]")), + (4, Quantity("30[s]")), + (5, Quantity("320[s]")), + (6, Quantity("330[s]")), + (7, Quantity("350[s]")), + (8, Quantity("360[s]")), + (9, Quantity("380[s]")), + (10, Quantity("390[s]")), + (11, Quantity("680[s]")), + (12, Quantity("690[s]")), + (13, Quantity("710[s]")), + (14, Quantity("720[s]")), +) +for i, q in analysis_step: + STAT_STRUC_ANA_SETTING.SetStepEndTime(i, q) +STAT_STRUC_ANA_SETTING.Activate() + + +# Add Imported Body Temperature load from Transient Thermal Run + +STAT_STRUC.ImportLoad(Model.Analyses[0]) +imported_load = DataModel.GetObjectsByName("Imported Body Temperature")[0] + +table = imported_load.GetTableByName("Source Time") +numofsteps = 14 +nCol = 2 +Ana_time = [ + "1e-3", + "2e-3", + "20", + "30", + "320", + "330", + "350", + "360", + "380", + "390", + "680", + "690", + "710", + "720", +] + +for i in range(numofsteps - 1): + table.Add(None) + +for i in range(numofsteps): + for j in range(nCol): + table[i][j] = Ana_time[i] + +imported_load.ImportLoad() + +# Apply Fixed Support Condition + +Fixed_Support = STAT_STRUC.AddFixedSupport() +selection = NS_GRP.Children[3] +Fixed_Support.Location = selection + +############################################################################### +# Sovle and post-process the results +# ---------------------------------- +# + +SOLN = STAT_STRUC.Solution + +TOT_DEF1 = SOLN.AddTotalDeformation() +TOT_DEF1.DisplayTime = Quantity("680 [s]") + +EQV_STRS1 = SOLN.AddEquivalentStress() +EQV_STRS1.DisplayTime = Quantity("680 [s]") + +EQV_PLAS_STRN1 = SOLN.AddEquivalentPlasticStrain() +EQV_PLAS_STRN1.DisplayTime = Quantity("680 [s]") + +THERM_STRN1 = SOLN.AddThermalStrain() +THERM_STRN1.DisplayTime = Quantity("680 [s]") + +# Solve Nonlinear Static Simulation + +# SOLN.Solve(True) +STAT_STRUC_SS = SOLN.Status + +# Export results images + +Tree.Activate([TOT_DEF1]) +ExtAPI.Graphics.ViewOptions.ResultPreference.ExtraModelDisplay = ( + Ansys.Mechanical.DataModel.MechanicalEnums.Graphics.ExtraModelDisplay.NoWireframe +) +ExtAPI.Graphics.ExportImage( + os.path.join(project_directory, "deformation.png"), image_export_format, settings_720p +) + +Tree.Activate([EQV_STRS1]) +ExtAPI.Graphics.ExportImage( + os.path.join(project_directory, "stress.png"), image_export_format, settings_720p +) + +Tree.Activate([EQV_PLAS_STRN1]) +ExtAPI.Graphics.ExportImage( + os.path.join(project_directory, "plastic_strain.png"), image_export_format, settings_720p +) + +mechanical.download(files=os.path.join(project_directory, "deformation.png"), target_dir=OUTPUT_DIR) +mechanical.download(files=os.path.join(project_directory, "stress.png"), target_dir=OUTPUT_DIR) +mechanical.download( + files=os.path.join(project_directory, "plastic_strain.png"), target_dir=OUTPUT_DIR +) + +# Display the resilts +if GRAPHICS_BOOL: + display_image("deformation.png") + display_image("stress.png") + display_image("plastic_strain.png") + +############################################################################### +# Close the Mechanical +# -------------------- +# +mechanical.exit() diff --git a/fluent-mechanical/wf_fm_02_mechanical.py b/fluent-mechanical/wf_fm_02_mechanical.py index c481574f..8fbdd25f 100644 --- a/fluent-mechanical/wf_fm_02_mechanical.py +++ b/fluent-mechanical/wf_fm_02_mechanical.py @@ -22,8 +22,11 @@ """ .. _ref_fluent_mechanical_02-mechanical: -Mechanical - -############################# +Thermo-mechanical assessment of representative exhaust manifold model +##################################################################### + +MultiPhysics example: Thermo-Mechanical simulation on a representative exhuast manifold +model. """ # noqa: D400, D415 @@ -86,6 +89,11 @@ def display_image(image_name): plt.show() +############################################################################### +# Input files needed for the simulation +# ---------------- -------------------- +# Download the input files needed for the simulation. +# geometry_path = download_file( "Exhaust_Manifold_Geometry.pmdb", "pyansys-workflow", "exhaust-manifold", "pymechanical" ) @@ -93,5 +101,847 @@ def display_image(image_name): "Nonlinear_Material.xml", "pyansys-workflow", "exhaust-manifold", "pymechanical" ) +# Files necessary for the thermal simulation from fluent analysis + +temp_htc_data_high_path = os.path.join(OUTPUT_DIR, "htc_temp_mapping_HIGH_TEMP.csv") +temp_htc_data_med_path = os.path.join(OUTPUT_DIR, "htc_temp_mapping_MEDIUM_TEMP.csv") +temp_htc_data_low_path = os.path.join(OUTPUT_DIR, "htc_temp_mapping_LOW_TEMP.csv") + +all_input_files = { + "geometry_path": geometry_path, + "material_path": material_path, + "temp_htc_data_high_path": temp_htc_data_high_path, + "temp_htc_data_med_path": temp_htc_data_med_path, + "temp_htc_data_low_path": temp_htc_data_low_path, +} + +# Upload to Mechanical Remote session server and get the file paths + +project_directory = mechanical.project_directory +print(f"project directory = {project_directory}") +for input_file_name, input_file_path in all_input_files.items(): + + # Upload the file to the project directory. + mechanical.upload(file_name=input_file_path, file_location_destination=project_directory) + + # Build the path relative to project directory. + base_name = os.path.basename(input_file_path) + combined_path = os.path.join(project_directory, base_name) + server_file_path = combined_path.replace("\\", "\\\\") + mechanical.run_python_script(f"{input_file_name} = '{server_file_path}'") + result = mechanical.run_python_script(f"{input_file_name}") + print(f"path of {input_file_name} on server: {result}") + + +############################################################################### +# Configure graphics for image export +# ----------------------------------- +# + +mechanical.run_python_script( + """ +ExtAPI.Graphics.Camera.SetSpecificViewOrientation( + Ansys.Mechanical.DataModel.Enums.ViewOrientationType.Iso +) +ExtAPI.Graphics.Camera.SetFit() +image_export_format = Ansys.Mechanical.DataModel.Enums.GraphicsImageExportFormat.PNG +settings_720p = Ansys.Mechanical.Graphics.GraphicsImageExportSettings() +settings_720p.Resolution = ( + Ansys.Mechanical.DataModel.Enums.GraphicsResolutionType.EnhancedResolution +) +settings_720p.Background = Ansys.Mechanical.DataModel.Enums.GraphicsBackgroundType.White +settings_720p.Width = 1280 +settings_720p.Height = 720 +settings_720p.CurrentGraphicsDisplay = False +""" +) + +############################################################################### +# Import geometry +# --------------- +# + +mechanical.run_python_script( + """ +import os +geometry_import_group = Model.GeometryImportGroup +geometry_import = geometry_import_group.AddGeometryImport() +geometry_import_format = ( + Ansys.Mechanical.DataModel.Enums.GeometryImportPreference.Format.Automatic +) +geometry_import_preferences = Ansys.ACT.Mechanical.Utilities.GeometryImportPreferences() +geometry_import_preferences.ProcessNamedSelections = True +geometry_import_preferences.NamedSelectionKey = "" +geometry_import_preferences.ProcessMaterialProperties = True +geometry_import_preferences.ProcessCoordinateSystems = True +geometry_import.Import( + geometry_path, geometry_import_format, geometry_import_preferences +) +project_directory = ExtAPI.DataModel.Project.ProjectDirectory +ExtAPI.Graphics.Camera.SetFit() +ExtAPI.Graphics.ExportImage( + os.path.join(project_directory, "geometry.png"), image_export_format, settings_720p +) +""" +) +mechanical.download(files=os.path.join(project_directory, "geometry.png"), target_dir=OUTPUT_DIR) +display_image("geometry.png") + + +############################################################################### +# Import material, assign it to the bodies and create Named Selections +# -------------------------------------------------------------------- +# + +mechanical.run_python_script( + """ +materials = ExtAPI.DataModel.Project.Model.Materials +materials.Import(material_path) +materials.RefreshMaterials() + +PRT1 = [x for x in ExtAPI.DataModel.Tree.AllObjects if x.Name == "Geom-2\Geom-1\solid"][0] + +# Assign it to the bodies +nmat = "1_HiSi_Model3_Exhaust Manifold updated" +PRT1.Material = nmat + + +# Select MKS units +ExtAPI.Application.ActiveUnitSystem = (Ansys.ACT.Interfaces.Common.MechanicalUnitSystem.StandardMKS) + +# Store all main tree nodes as variables +GEOM = Model.Geometry +MAT_GRP = Model.Materials + +# Create NS for Named Selection. + +NS_GRP = ExtAPI.DataModel.Project.Model.NamedSelections +BRACKET_FIX_NS = [x for x in ExtAPI.DataModel.Tree.AllObjects if x.Name == "bracket_fix"][0] +INTERFACE_SURFACE_NS = [ + x for x in ExtAPI.DataModel.Tree.AllObjects if x.Name == "interface_surface" +][0] +EXHAUST_MANIFOLD_NS = [x for x in ExtAPI.DataModel.Tree.AllObjects if x.Name == "exhaust_manifold"][ + 0 +] +TOP_BRACKET_SURFACE_NS = [ + x for x in ExtAPI.DataModel.Tree.AllObjects if x.Name == "top_bracket_surface" +][0] +SPACERS_NS = [x for x in ExtAPI.DataModel.Tree.AllObjects if x.Name == "spacers"][0] +EM_OUTER_SURFACE_NS = [x for x in ExtAPI.DataModel.Tree.AllObjects if x.Name == "em_outer_surface"][ + 0 +] +""" +) + +############################################################################### +# Set up the mesh and generate +# ---------------------------- +# + +mechanical.run_python_script( + """ +MESH = Model.Mesh +MESH.ElementSize = Quantity(0.004, "m") +MESH.UseAdaptiveSizing = False +MESH.MaximumSize = Quantity(0.004, "m") +MESH.ShapeChecking = 0 +body_sizing = MESH.AddSizing() +selection = NS_GRP.Children[5] +body_sizing.Location = selection +body_sizing.ElementSize = Quantity(4e-3, "m") +#body_sizing.CaptureCurvature = True +#body_sizing.CurvatureNormalAngle = Quantity(0.31, "rad") +#body_sizing.LocalMinimumSize = Quantity(0.00025, "m") + +Tree.Activate([MESH]) +MESH.GenerateMesh() + +# Export mesh image -print("Hello World") +ExtAPI.Graphics.Camera.SetFit() +ExtAPI.Graphics.ExportImage( + os.path.join(project_directory, "mesh.png"), image_export_format, settings_720p +) +""" +) +mechanical.download(files=os.path.join(project_directory, "mesh.png"), target_dir=OUTPUT_DIR) +display_image("mesh.png") + +############################################################################### +# Add Transient Thermal Analysis and set up the analysis settings +# --------------------------------------------------------------- +# + +mechanical.run_python_script( + """ +Model.AddTransientThermalAnalysis() + +# Store all main tree nodes as variables + +TRANS_THERM = Model.Analyses[0] +TRANS_THERM_SOLN = TRANS_THERM.Solution +ANA_SETTINGS = TRANS_THERM.Children[1] + +# Setup transient thermal analysis settings + +#ANA_SETTINGS.AutomaticTimeStepping = AutomaticTimeStepping.On +ANA_SETTINGS.SolverType = SolverType.Direct +ANA_SETTINGS.NonLinearFormulation = NonLinearFormulationType.Full + +ANA_SETTINGS.NumberOfSteps = 1 +ANA_SETTINGS.SetStepEndTime(1, Quantity('720[s]')) +ANA_SETTINGS.NumberOfSteps = 14 +analysis_step = ( + (1, Quantity('1e-3[s]')), + (2, Quantity('2e-3[s]')), + (3, Quantity('20[s]')), + (4, Quantity('30[s]')), + (5, Quantity('320[s]')), + (6, Quantity('330[s]')), + (7, Quantity('350[s]')), + (8, Quantity('360[s]')), + (9, Quantity('380[s]')), + (10, Quantity('390[s]')), + (11, Quantity('680[s]')), + (12, Quantity('690[s]')), + (13, Quantity('710[s]')), + (14, Quantity('720[s]')) +) + +for i, q in analysis_step: + ANA_SETTINGS.SetStepEndTime(i,q) + +# Applied External HTCs and Temperature data + +External_Convection_Load_1 = TRANS_THERM.AddConvection() +selection = NS_GRP.Children[8] +External_Convection_Load_1.Location = selection + +External_Convection_Load_1.FilmCoefficient.Inputs[0].DiscreteValues = [ + Quantity("0[s]"), + Quantity("1e-3[s]"), + Quantity("2e-3[s]"), + Quantity("20[s]"), + Quantity("30[s]"), + Quantity("320[s]"), + Quantity("330[s]"), + Quantity("350[s]"), + Quantity("360[s]"), + Quantity("380[s]"), + Quantity("390[s]"), + Quantity("680[s]"), + Quantity("690[s]"), + Quantity("710[s]"), + Quantity("720[s]"), +] + +External_Convection_Load_1.FilmCoefficient.Output.DiscreteValues = [ + Quantity("60[W m^-1 m^-1 K^-1]"), + Quantity("60[W m^-1 m^-1 K^-1]"), + Quantity("60[W m^-1 m^-1 K^-1]"), + Quantity("60[W m^-1 m^-1 K^-1]"), + Quantity("60[W m^-1 m^-1 K^-1]"), + Quantity("60[W m^-1 m^-1 K^-1]"), + Quantity("60[W m^-1 m^-1 K^-1]"), + Quantity("60[W m^-1 m^-1 K^-1]"), + Quantity("60[W m^-1 m^-1 K^-1]"), + Quantity("60[W m^-1 m^-1 K^-1]"), + Quantity("60[W m^-1 m^-1 K^-1]"), + Quantity("60[W m^-1 m^-1 K^-1]"), + Quantity("60[W m^-1 m^-1 K^-1]"), + Quantity("60[W m^-1 m^-1 K^-1]"), + Quantity("60[W m^-1 m^-1 K^-1]"), +] + +External_Convection_Load_1.AmbientTemperature.Inputs[0].DiscreteValues = [ + Quantity("0[s]"), + Quantity("1e-3[s]"), + Quantity("2e-3[s]"), + Quantity("20[s]"), + Quantity("30[s]"), + Quantity("320[s]"), + Quantity("330[s]"), + Quantity("350[s]"), + Quantity("360[s]"), + Quantity("380[s]"), + Quantity("390[s]"), + Quantity("680[s]"), + Quantity("690[s]"), + Quantity("710[s]"), + Quantity("720[s]"), +] + +External_Convection_Load_1.AmbientTemperature.Output.DiscreteValues = [ + Quantity("473.15[K]"), + Quantity("473.15[K]"), + Quantity("473.15[K]"), + Quantity("473.15[K]"), + Quantity("473.15[K]"), + Quantity("473.15[K]"), + Quantity("473.15[K]"), + Quantity("473.15[K]"), + Quantity("473.15[K]"), + Quantity("473.15[K]"), + Quantity("473.15[K]"), + Quantity("473.15[K]"), + Quantity("473.15[K]"), + Quantity("473.15[K]"), + Quantity("473.15[K]"), +] + + +External_Convection_Load_2 = TRANS_THERM.AddConvection() +selection = NS_GRP.Children[7] +External_Convection_Load_2.Location = selection + +External_Convection_Load_2.FilmCoefficient.Inputs[0].DiscreteValues = [ + Quantity("0[s]"), + Quantity("1e-3[s]"), + Quantity("2e-3[s]"), + Quantity("20[s]"), + Quantity("30[s]"), + Quantity("320[s]"), + Quantity("330[s]"), + Quantity("350[s]"), + Quantity("360[s]"), + Quantity("380[s]"), + Quantity("390[s]"), + Quantity("680[s]"), + Quantity("690[s]"), + Quantity("710[s]"), + Quantity("720[s]"), +] + +External_Convection_Load_2.FilmCoefficient.Output.DiscreteValues = [ + Quantity("20[W m^-1 m^-1 K^-1]"), + Quantity("20[W m^-1 m^-1 K^-1]"), + Quantity("20[W m^-1 m^-1 K^-1]"), + Quantity("20[W m^-1 m^-1 K^-1]"), + Quantity("20[W m^-1 m^-1 K^-1]"), + Quantity("20[W m^-1 m^-1 K^-1]"), + Quantity("20[W m^-1 m^-1 K^-1]"), + Quantity("20[W m^-1 m^-1 K^-1]"), + Quantity("20[W m^-1 m^-1 K^-1]"), + Quantity("20[W m^-1 m^-1 K^-1]"), + Quantity("20[W m^-1 m^-1 K^-1]"), + Quantity("20[W m^-1 m^-1 K^-1]"), + Quantity("20[W m^-1 m^-1 K^-1]"), + Quantity("20[W m^-1 m^-1 K^-1]"), + Quantity("20[W m^-1 m^-1 K^-1]"), +] + +External_Convection_Load_2.AmbientTemperature.Inputs[0].DiscreteValues = [ + Quantity("0[s]"), + Quantity("1e-3[s]"), + Quantity("2e-3[s]"), + Quantity("20[s]"), + Quantity("30[s]"), + Quantity("320[s]"), + Quantity("330[s]"), + Quantity("350[s]"), + Quantity("360[s]"), + Quantity("380[s]"), + Quantity("390[s]"), + Quantity("680[s]"), + Quantity("690[s]"), + Quantity("710[s]"), + Quantity("720[s]"), +] + +External_Convection_Load_2.AmbientTemperature.Output.DiscreteValues = [ + Quantity("498.15[K]"), + Quantity("498.15[K]"), + Quantity("498.15[K]"), + Quantity("498.15[K]"), + Quantity("498.15[K]"), + Quantity("498.15[K]"), + Quantity("498.15[K]"), + Quantity("498.15[K]"), + Quantity("498.15[K]"), + Quantity("498.15[K]"), + Quantity("498.15[K]"), + Quantity("498.15[K]"), + Quantity("498.15[K]"), + Quantity("498.15[K]"), + Quantity("498.15[K]"), +] + + +External_Convection_Load_3 = TRANS_THERM.AddConvection() +selection = NS_GRP.Children[6] +External_Convection_Load_3.Location = selection + +External_Convection_Load_3.FilmCoefficient.Inputs[0].DiscreteValues = [ + Quantity("0[s]"), + Quantity("1e-3[s]"), + Quantity("2e-3[s]"), + Quantity("20[s]"), + Quantity("30[s]"), + Quantity("320[s]"), + Quantity("330[s]"), + Quantity("350[s]"), + Quantity("360[s]"), + Quantity("380[s]"), + Quantity("390[s]"), + Quantity("680[s]"), + Quantity("690[s]"), + Quantity("710[s]"), + Quantity("720[s]"), +] + +External_Convection_Load_3.FilmCoefficient.Output.DiscreteValues = [ + Quantity("500[W m^-1 m^-1 K^-1]"), + Quantity("500[W m^-1 m^-1 K^-1]"), + Quantity("500[W m^-1 m^-1 K^-1]"), + Quantity("500[W m^-1 m^-1 K^-1]"), + Quantity("500[W m^-1 m^-1 K^-1]"), + Quantity("500[W m^-1 m^-1 K^-1]"), + Quantity("500[W m^-1 m^-1 K^-1]"), + Quantity("500[W m^-1 m^-1 K^-1]"), + Quantity("500[W m^-1 m^-1 K^-1]"), + Quantity("500[W m^-1 m^-1 K^-1]"), + Quantity("500[W m^-1 m^-1 K^-1]"), + Quantity("500[W m^-1 m^-1 K^-1]"), + Quantity("500[W m^-1 m^-1 K^-1]"), + Quantity("500[W m^-1 m^-1 K^-1]"), + Quantity("500[W m^-1 m^-1 K^-1]"), +] + +External_Convection_Load_3.AmbientTemperature.Inputs[0].DiscreteValues = [ + Quantity("0[s]"), + Quantity("1e-3[s]"), + Quantity("2e-3[s]"), + Quantity("20[s]"), + Quantity("30[s]"), + Quantity("320[s]"), + Quantity("330[s]"), + Quantity("350[s]"), + Quantity("360[s]"), + Quantity("380[s]"), + Quantity("390[s]"), + Quantity("680[s]"), + Quantity("690[s]"), + Quantity("710[s]"), + Quantity("720[s]"), +] + +External_Convection_Load_3.AmbientTemperature.Output.DiscreteValues = [ + Quantity("373.15[K]"), + Quantity("373.15[K]"), + Quantity("373.15[K]"), + Quantity("373.15[K]"), + Quantity("373.15[K]"), + Quantity("373.15[K]"), + Quantity("373.15[K]"), + Quantity("373.15[K]"), + Quantity("373.15[K]"), + Quantity("373.15[K]"), + Quantity("373.15[K]"), + Quantity("373.15[K]"), + Quantity("373.15[K]"), + Quantity("373.15[K]"), + Quantity("373.15[K]"), +] + +group_list = [External_Convection_Load_1,External_Convection_Load_2,External_Convection_Load_3] +grouping_folder = Tree.Group(group_list) +tree_grouping_folder_70 = DataModel.GetObjectsByName("New Folder") +""" +) + +############################################################################### +# Use the ouput from Fluent to import the temperature and HTC data +# --------------------------------------------------------------- +# +mechanical.run_python_script( + """ + +# Import HTCs and Temperature data From Fluent run + +Imported_Load_Group = TRANS_THERM.AddImportedLoadExternalData() +imported_load_group_61 = Imported_Load_Group +imported_convection_62 = imported_load_group_61.AddImportedConvection() + +external_data_files = Ansys.Mechanical.ExternalData.ExternalDataFileCollection() +external_data_files.SaveFilesWithProject = False +external_data_file_1 = Ansys.Mechanical.ExternalData.ExternalDataFile() +external_data_files.Add(external_data_file_1) +external_data_file_1.Identifier = "File1" +external_data_file_1.Description = "High" +external_data_file_1.IsMainFile = True +external_data_file_1.FilePath= temp_htc_data_high_path +external_data_file_1.ImportSettings = ( + Ansys.Mechanical.ExternalData.ImportSettingsFactory.GetSettingsForFormat( + MechanicalEnums.ExternalData.ImportFormat.Delimited + ) +) +import_settings = external_data_file_1.ImportSettings +import_settings.SkipRows = 1 +import_settings.SkipFooter = 0 +import_settings.Delimiter = "," +import_settings.AverageCornerNodesToMidsideNodes = False +import_settings.UseColumn(0, MechanicalEnums.ExternalData.VariableType.NodeId, "", "Node ID@A") +import_settings.UseColumn( + 1, MechanicalEnums.ExternalData.VariableType.XCoordinate, "m", "X Coordinate@B" +) +import_settings.UseColumn( + 2, MechanicalEnums.ExternalData.VariableType.YCoordinate, "m", "Y Coordinate@C" +) +import_settings.UseColumn( + 3, MechanicalEnums.ExternalData.VariableType.ZCoordinate, "m", "Z Coordinate@D" +) +import_settings.UseColumn( + 4, MechanicalEnums.ExternalData.VariableType.Temperature, "K", "Temperature@E" +) +import_settings.UseColumn( + 5, + MechanicalEnums.ExternalData.VariableType.HeatTransferCoefficient, + "W m^-2 K^-1", + "Heat Transfer Coefficient@F", +) +external_data_file_2 = Ansys.Mechanical.ExternalData.ExternalDataFile() +external_data_files.Add(external_data_file_2) +external_data_file_2.Identifier = "File2" +external_data_file_2.Description = "Med" +external_data_file_2.IsMainFile = False +external_data_file_2.FilePath= temp_htc_data_med_path +external_data_file_2.ImportSettings = ( + Ansys.Mechanical.ExternalData.ImportSettingsFactory.GetSettingsForFormat( + MechanicalEnums.ExternalData.ImportFormat.Delimited + ) +) +import_settings = external_data_file_2.ImportSettings +import_settings.SkipRows = 1 +import_settings.SkipFooter = 0 +import_settings.Delimiter = "," +import_settings.AverageCornerNodesToMidsideNodes = False +import_settings.UseColumn( + 1, MechanicalEnums.ExternalData.VariableType.XCoordinate, "m", "X Coordinate@B" +) +import_settings.UseColumn( + 2, MechanicalEnums.ExternalData.VariableType.YCoordinate, "m", "Y Coordinate@C" +) +import_settings.UseColumn( + 3, MechanicalEnums.ExternalData.VariableType.ZCoordinate, "m", "Z Coordinate@D" +) +import_settings.UseColumn( + 4, MechanicalEnums.ExternalData.VariableType.Temperature, "K", "Temperature@E" +) +import_settings.UseColumn( + 5, + MechanicalEnums.ExternalData.VariableType.HeatTransferCoefficient, + "W m^-2 K^-1", + "Heat Transfer Coefficient@F", +) +external_data_file_3 = Ansys.Mechanical.ExternalData.ExternalDataFile() +external_data_files.Add(external_data_file_3) +external_data_file_3.Identifier = "File3" +external_data_file_3.Description = "Low" +external_data_file_3.IsMainFile = False +external_data_file_3.FilePath= temp_htc_data_low_path +external_data_file_3.ImportSettings = ( + Ansys.Mechanical.ExternalData.ImportSettingsFactory.GetSettingsForFormat( + MechanicalEnums.ExternalData.ImportFormat.Delimited + ) +) +import_settings = external_data_file_3.ImportSettings +import_settings.SkipRows = 1 +import_settings.SkipFooter = 0 +import_settings.Delimiter = "," +import_settings.AverageCornerNodesToMidsideNodes = False +import_settings.UseColumn(0, MechanicalEnums.ExternalData.VariableType.NodeId, "", "Node ID@A") +import_settings.UseColumn( + 1, MechanicalEnums.ExternalData.VariableType.XCoordinate, "m", "X Coordinate@B" +) +import_settings.UseColumn( + 2, MechanicalEnums.ExternalData.VariableType.YCoordinate, "m", "Y Coordinate@C" +) +import_settings.UseColumn( + 3, MechanicalEnums.ExternalData.VariableType.ZCoordinate, "m", "Z Coordinate@D" +) +import_settings.UseColumn( + 4, MechanicalEnums.ExternalData.VariableType.Temperature, "K", "Temperature@E" +) +import_settings.UseColumn( + 5, + MechanicalEnums.ExternalData.VariableType.HeatTransferCoefficient, + "W m^-2 K^-1", + "Heat Transfer Coefficient@F", +) +imported_load_group_61.ImportExternalDataFiles(external_data_files) + +table = imported_load_group_61.Children[0].GetTableByName("Film Coefficient") +numofsteps = 15 +Film_Coeff = [ + "File1:Heat Transfer Coefficient@F", + "File2:Heat Transfer Coefficient@F", + "File3:Heat Transfer Coefficient@F", +] +Amb_Temp = ["File1:Temperature@E","File2:Temperature@E","File3:Temperature@E"] +Ana_time = [ + "0", + "1e-3", + "2e-3", + "20", + "30", + "320", + "330", + "350", + "360", + "380", + "390", + "680", + "690", + "710", + "720", +] + +for i in range(numofsteps-1): + table.Add(None) + +table[0][0] = Film_Coeff[2] +table[0][1] = Amb_Temp[2] +table[0][2] = Ana_time[0] + +table[1][0] = Film_Coeff[2] +table[1][1] = Amb_Temp[2] +table[1][2] = Ana_time[1] + +table[2][0] = Film_Coeff[2] +table[2][1] = Amb_Temp[2] +table[2][2] = Ana_time[2] + +table[3][0] = Film_Coeff[2] +table[3][1] = Amb_Temp[2] +table[3][2] = Ana_time[3] + +table[4][0] = Film_Coeff[0] +table[4][1] = Amb_Temp[0] +table[4][2] = Ana_time[4] + +table[5][0] = Film_Coeff[0] +table[5][1] = Amb_Temp[0] +table[5][2] = Ana_time[5] + +table[6][0] = Film_Coeff[1] +table[6][1] = Amb_Temp[1] +table[6][2] = Ana_time[6] + +table[7][0] = Film_Coeff[1] +table[7][1] = Amb_Temp[1] +table[7][2] = Ana_time[7] + +table[8][0] = Film_Coeff[2] +table[8][1] = Amb_Temp[2] +table[8][2] = Ana_time[8] + +table[9][0] = Film_Coeff[2] +table[9][1] = Amb_Temp[2] +table[9][2] = Ana_time[9] + +table[10][0] = Film_Coeff[0] +table[10][1] = Amb_Temp[0] +table[10][2] = Ana_time[10] + +table[11][0] = Film_Coeff[0] +table[11][1] = Amb_Temp[0] +table[11][2] = Ana_time[11] + +table[12][0] = Film_Coeff[1] +table[12][1] = Amb_Temp[1] +table[12][2] = Ana_time[12] + +table[13][0] = Film_Coeff[1] +table[13][1] = Amb_Temp[1] +table[13][2] = Ana_time[13] + +table[14][0] = Film_Coeff[2] +table[14][1] = Amb_Temp[2] +table[14][2] = Ana_time[14] + +selection = NS_GRP.Children[4] +imported_convection_62.Location = selection +imported_load_id = imported_convection_62.ObjectId +imported_load = DataModel.GetObjectById(imported_load_id) + +# !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! +# imported_convection_62.InternalObject.ExternalLoadSteppingType = 1 +# !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +imported_load.ImportLoad() + +Tree.Activate([imported_load]) +ExtAPI.Graphics.Camera.SetFit() +ExtAPI.Graphics.ExportImage( + os.path.join(project_directory, "imported_temperature.png"), image_export_format, settings_720p +) +""" +) +mechanical.download( + files=os.path.join(project_directory, "imported_temperature.png"), target_dir=OUTPUT_DIR +) +if GRAPHICS_BOOL: + display_image("imported_temperature.png") + +############################################################################### +# Solve and post-process the results +# ---------------------------------- +# +mechanical.run_python_script( + """ +# Insert results objects + +Temp = TRANS_THERM_SOLN.AddTemperature() +Temp.DisplayTime = Quantity("680 [s]") + +# Run Solution: Transient Thermal Simulation + +#TRANS_THERM_SOLN.Solve(True) +TRANS_THERM_SS = TRANS_THERM_SOLN.Status + +# Export temperature image + +Tree.Activate([Temp]) +ExtAPI.Graphics.ViewOptions.ResultPreference.ExtraModelDisplay = ( + Ansys.Mechanical.DataModel.MechanicalEnums.Graphics.ExtraModelDisplay.NoWireframe +) +ExtAPI.Graphics.ExportImage( + os.path.join(project_directory, "temperature.png"), image_export_format, settings_720p +) +""" +) +mechanical.download(files=os.path.join(project_directory, "temperature.png"), target_dir=OUTPUT_DIR) +if GRAPHICS_BOOL: + display_image("temperature.png") + + +############################################################################### +# Setup Structural Analysis +# ------------------------- +# +mechanical.run_python_script( + """ +Model.AddStaticStructuralAnalysis() + +# Define analysis settings + +# Setup static structural analysis settings +STAT_STRUC = Model.Analyses[1] +STAT_STRUC_SOLN = STAT_STRUC.Solution +STAT_STRUC_ANA_SETTING = STAT_STRUC.Children[0] + +STAT_STRUC_ANA_SETTING.NumberOfSteps = 1 +STAT_STRUC_ANA_SETTING.SetStepEndTime(1, Quantity('720[s]')) +STAT_STRUC_ANA_SETTING.NumberOfSteps = 14 + +analysis_step = ( + (1, Quantity('1e-3[s]')), + (2, Quantity('2e-3[s]')), + (3, Quantity('20[s]')), + (4, Quantity('30[s]')), + (5, Quantity('320[s]')), + (6, Quantity('330[s]')), + (7, Quantity('350[s]')), + (8, Quantity('360[s]')), + (9, Quantity('380[s]')), + (10, Quantity('390[s]')), + (11, Quantity('680[s]')), + (12, Quantity('690[s]')), + (13, Quantity('710[s]')), + (14, Quantity('720[s]')) +) +for i, q in analysis_step: + STAT_STRUC_ANA_SETTING.SetStepEndTime(i,q) +STAT_STRUC_ANA_SETTING.Activate() + + +# Add Imported Body Temperature load from Transient Thermal Run + +STAT_STRUC.ImportLoad(Model.Analyses[0]) +imported_load = DataModel.GetObjectsByName("Imported Body Temperature")[0] + +table = imported_load.GetTableByName("Source Time") +numofsteps = 14 +nCol = 2 +Ana_time = ["1e-3","2e-3","20","30","320","330","350","360","380","390","680","690","710","720"] + +for i in range(numofsteps-1): + table.Add(None) + +for i in range(numofsteps): + for j in range(nCol): + table[i][j] = Ana_time[i] + +imported_load.ImportLoad() + +# Apply Fixed Support Condition + +Fixed_Support = STAT_STRUC.AddFixedSupport() +selection = NS_GRP.Children[3] +Fixed_Support.Location = selection +""" +) + +############################################################################### +# Sovle and post-process the results +# ---------------------------------- +# +mechanical.run_python_script( + """ +SOLN = STAT_STRUC.Solution + +TOT_DEF1 = SOLN.AddTotalDeformation() +TOT_DEF1.DisplayTime = Quantity("680 [s]") + +EQV_STRS1 = SOLN.AddEquivalentStress() +EQV_STRS1.DisplayTime = Quantity("680 [s]") + +EQV_PLAS_STRN1 = SOLN.AddEquivalentPlasticStrain() +EQV_PLAS_STRN1.DisplayTime = Quantity("680 [s]") + +THERM_STRN1 = SOLN.AddThermalStrain() +THERM_STRN1.DisplayTime = Quantity("680 [s]") + +# Solve Nonlinear Static Simulation + +#SOLN.Solve(True) +STAT_STRUC_SS = SOLN.Status + +# Export results images + +Tree.Activate([TOT_DEF1]) +ExtAPI.Graphics.ViewOptions.ResultPreference.ExtraModelDisplay = ( + Ansys.Mechanical.DataModel.MechanicalEnums.Graphics.ExtraModelDisplay.NoWireframe +) +ExtAPI.Graphics.ExportImage( + os.path.join(project_directory, "deformation.png"), image_export_format, settings_720p +) + +Tree.Activate([EQV_STRS1]) +ExtAPI.Graphics.ExportImage( + os.path.join(project_directory, "stress.png"), image_export_format, settings_720p +) + +Tree.Activate([EQV_PLAS_STRN1]) +ExtAPI.Graphics.ExportImage( + os.path.join(project_directory, "plastic_strain.png"), image_export_format, settings_720p +) +""" +) +mechanical.download(files=os.path.join(project_directory, "deformation.png"), target_dir=OUTPUT_DIR) +mechanical.download(files=os.path.join(project_directory, "stress.png"), target_dir=OUTPUT_DIR) +mechanical.download( + files=os.path.join(project_directory, "plastic_strain.png"), target_dir=OUTPUT_DIR +) + +# Display the resilts +if GRAPHICS_BOOL: + display_image("deformation.png") + display_image("stress.png") + display_image("plastic_strain.png") + +############################################################################### +# Close the Mechanical +# -------------------- +# +mechanical.exit() From 33fc66be01a3cbf8b6e0833c33fd39c1d39ab9af Mon Sep 17 00:00:00 2001 From: dkunhamb Date: Fri, 13 Dec 2024 16:54:25 -0600 Subject: [PATCH 08/68] deleted copy file --- fluent-mechanical/wf_fm_02_mechanical copy.py | 935 ------------------ 1 file changed, 935 deletions(-) delete mode 100644 fluent-mechanical/wf_fm_02_mechanical copy.py diff --git a/fluent-mechanical/wf_fm_02_mechanical copy.py b/fluent-mechanical/wf_fm_02_mechanical copy.py deleted file mode 100644 index 3eb91907..00000000 --- a/fluent-mechanical/wf_fm_02_mechanical copy.py +++ /dev/null @@ -1,935 +0,0 @@ -# Copyright (C) 2024 ANSYS, Inc. and/or its affiliates. -# SPDX-License-Identifier: MIT -# -# -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), to deal -# in the Software without restriction, including without limitation the rights -# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -# copies of the Software, and to permit persons to whom the Software is -# furnished to do so, subject to the following conditions: -# -# The above copyright notice and this permission notice shall be included in all -# copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -# SOFTWARE. -""" -.. _ref_fluent_mechanical_02-mechanical: - -Thermo-mechanical assessment of representative exhaust manifold model -##################################################################### - -MultiPhysics example: Thermo-Mechanical simulation on a representative exhuast manifold -model. - -""" # noqa: D400, D415 - -import os -from pathlib import Path - -from ansys.mechanical.core import launch_mechanical -from ansys.mechanical.core.examples import download_file -from matplotlib import image as mpimg -from matplotlib import pyplot as plt - -############################################################################### -# Preparing the environment -# ------------------------- -# This section is only necessary for workflow runs and docs generation. It checks -# the environment variables to determine which image to use for the mechanical service. -# If you are running this script outside of a workflow, you can ignore this section. -# - -version = None -if "ANSYS_MECHANICAL_RELEASE" in os.environ: - image_tag = os.environ["ANSYS_MECHANICAL_RELEASE"] - version = int(image_tag.replace(".", "")) - -# sphinx_gallery_start_ignore -# Check if the __file__ variable is defined. If not, set it. -# This is a workaround to run the script in Sphinx-Gallery. -if "__file__" not in locals(): - __file__ = Path(os.getcwd(), "wf_gmd_02_mechanical.py") -# sphinx_gallery_end_ignore - -############################################################################### -# Parameters for the script -# ------------------------- -# The following parameters are used to control the script execution. You can -# modify these parameters to suit your needs. -# -GRAPHICS_BOOL = False # Set to True to display the graphics -OUTPUT_DIR = Path(Path(__file__).parent, "outputs") # Output directory - -# sphinx_gallery_start_ignore -if "DOC_BUILD" in os.environ: - GRAPHICS_BOOL = True -# sphinx_gallery_end_ignore - -############################################################################### -# Start a PyMechanical app -# ------------------------ -# -mechanical = launch_mechanical(batch=False, cleanup_on_exit=False) -print(mechanical) - - -def display_image(image_name): - plt.figure(figsize=(16, 9)) - plt.imshow(mpimg.imread(os.path.join(OUTPUT_DIR, image_name))) - plt.xticks([]) - plt.yticks([]) - plt.axis("off") - plt.show() - - -############################################################################### -# Input files needed for the simulation -# ---------------- -------------------- -# Download the input files needed for the simulation. -# -geometry_path = download_file( - "Exhaust_Manifold_Geometry.pmdb", "pyansys-workflow", "exhaust-manifold", "pymechanical" -) -material_path = download_file( - "Nonlinear_Material.xml", "pyansys-workflow", "exhaust-manifold", "pymechanical" -) - -# Files necessary for the thermal simulation from fluent analysis - -temp_htc_data_high_path = os.path.join(OUTPUT_DIR, "htc_temp_mapping_HIGH_TEMP.csv") -temp_htc_data_med_path = os.path.join(OUTPUT_DIR, "htc_temp_mapping_MEDIUM_TEMP.csv") -temp_htc_data_low_path = os.path.join(OUTPUT_DIR, "htc_temp_mapping_LOW_TEMP.csv") - -all_input_files = { - "geometry_path": geometry_path, - "material_path": material_path, - "temp_htc_data_high_path": temp_htc_data_high_path, - "temp_htc_data_med_path": temp_htc_data_med_path, - "temp_htc_data_low_path": temp_htc_data_low_path, -} - -# Upload to Mechanical Remote session server and get the file paths - -project_directory = mechanical.project_directory -print(f"project directory = {project_directory}") -for input_file_name, input_file_path in all_input_files.items(): - - # Upload the file to the project directory. - mechanical.upload(file_name=input_file_path, file_location_destination=project_directory) - - # Build the path relative to project directory. - base_name = os.path.basename(input_file_path) - combined_path = os.path.join(project_directory, base_name) - server_file_path = combined_path.replace("\\", "\\\\") - mechanical.run_python_script(f"{input_file_name} = '{server_file_path}'") - result = mechanical.run_python_script(f"{input_file_name}") - print(f"path of {input_file_name} on server: {result}") - - -############################################################################### -# Configure graphics for image export -# ----------------------------------- -# - -mechanical.run_python_script( - """ -ExtAPI.Graphics.Camera.SetSpecificViewOrientation( - Ansys.Mechanical.DataModel.Enums.ViewOrientationType.Iso -) -ExtAPI.Graphics.Camera.SetFit() -image_export_format = Ansys.Mechanical.DataModel.Enums.GraphicsImageExportFormat.PNG -settings_720p = Ansys.Mechanical.Graphics.GraphicsImageExportSettings() -settings_720p.Resolution = ( - Ansys.Mechanical.DataModel.Enums.GraphicsResolutionType.EnhancedResolution -) -settings_720p.Background = Ansys.Mechanical.DataModel.Enums.GraphicsBackgroundType.White -settings_720p.Width = 1280 -settings_720p.Height = 720 -settings_720p.CurrentGraphicsDisplay = False -""" -) - -############################################################################### -# Import geometry -# --------------- -# - - -import os - -geometry_import_group = Model.GeometryImportGroup -geometry_import = geometry_import_group.AddGeometryImport() -geometry_import_format = Ansys.Mechanical.DataModel.Enums.GeometryImportPreference.Format.Automatic -geometry_import_preferences = Ansys.ACT.Mechanical.Utilities.GeometryImportPreferences() -geometry_import_preferences.ProcessNamedSelections = True -geometry_import_preferences.NamedSelectionKey = "" -geometry_import_preferences.ProcessMaterialProperties = True -geometry_import_preferences.ProcessCoordinateSystems = True -geometry_import.Import(geometry_path, geometry_import_format, geometry_import_preferences) -project_directory = ExtAPI.DataModel.Project.ProjectDirectory -ExtAPI.Graphics.Camera.SetFit() -ExtAPI.Graphics.ExportImage( - os.path.join(project_directory, "geometry.png"), image_export_format, settings_720p -) - -mechanical.download(files=os.path.join(project_directory, "geometry.png"), target_dir=OUTPUT_DIR) -display_image("geometry.png") - - -############################################################################### -# Import material, assign it to the bodies and create Named Selections -# -------------------------------------------------------------------- -# - - -materials = ExtAPI.DataModel.Project.Model.Materials -materials.Import(material_path) -materials.RefreshMaterials() - -PRT1 = [x for x in ExtAPI.DataModel.Tree.AllObjects if x.Name == "Geom-2\Geom-1\solid"][0] - -# Assign it to the bodies -nmat = "1_HiSi_Model3_Exhaust Manifold updated" -PRT1.Material = nmat - - -# Select MKS units -ExtAPI.Application.ActiveUnitSystem = Ansys.ACT.Interfaces.Common.MechanicalUnitSystem.StandardMKS - -# Store all main tree nodes as variables -GEOM = Model.Geometry -MAT_GRP = Model.Materials - -# Create NS for Named Selection. - -NS_GRP = ExtAPI.DataModel.Project.Model.NamedSelections -BRACKET_FIX_NS = [x for x in ExtAPI.DataModel.Tree.AllObjects if x.Name == "bracket_fix"][0] -INTERFACE_SURFACE_NS = [ - x for x in ExtAPI.DataModel.Tree.AllObjects if x.Name == "interface_surface" -][0] -EXHAUST_MANIFOLD_NS = [x for x in ExtAPI.DataModel.Tree.AllObjects if x.Name == "exhaust_manifold"][ - 0 -] -TOP_BRACKET_SURFACE_NS = [ - x for x in ExtAPI.DataModel.Tree.AllObjects if x.Name == "top_bracket_surface" -][0] -SPACERS_NS = [x for x in ExtAPI.DataModel.Tree.AllObjects if x.Name == "spacers"][0] -EM_OUTER_SURFACE_NS = [x for x in ExtAPI.DataModel.Tree.AllObjects if x.Name == "em_outer_surface"][ - 0 -] - -MESH = Model.Mesh -MESH.ElementSize = Quantity(0.004, "m") -MESH.UseAdaptiveSizing = False -MESH.MaximumSize = Quantity(0.004, "m") -MESH.ShapeChecking = 0 -body_sizing = MESH.AddSizing() -selection = NS_GRP.Children[5] -body_sizing.Location = selection -body_sizing.ElementSize = Quantity(4e-3, "m") -# body_sizing.CaptureCurvature = True -# body_sizing.CurvatureNormalAngle = Quantity(0.31, "rad") -# body_sizing.LocalMinimumSize = Quantity(0.00025, "m") - -Tree.Activate([MESH]) -MESH.GenerateMesh() - -# Export mesh image - -ExtAPI.Graphics.Camera.SetFit() -ExtAPI.Graphics.ExportImage( - os.path.join(project_directory, "mesh.png"), image_export_format, settings_720p -) - -mechanical.download(files=os.path.join(project_directory, "mesh.png"), target_dir=OUTPUT_DIR) -display_image("mesh.png") - -############################################################################### -# Add Transient Thermal Analysis and set up the analysis settings -# --------------------------------------------------------------- -# - - -Model.AddTransientThermalAnalysis() - -# Store all main tree nodes as variables - -TRANS_THERM = Model.Analyses[0] -TRANS_THERM_SOLN = TRANS_THERM.Solution -ANA_SETTINGS = TRANS_THERM.Children[1] - -# Setup transient thermal analysis settings - -# ANA_SETTINGS.AutomaticTimeStepping = AutomaticTimeStepping.On -ANA_SETTINGS.SolverType = SolverType.Direct -ANA_SETTINGS.NonLinearFormulation = NonLinearFormulationType.Full - -ANA_SETTINGS.NumberOfSteps = 1 -ANA_SETTINGS.SetStepEndTime(1, Quantity("720[s]")) -ANA_SETTINGS.NumberOfSteps = 14 -analysis_step = ( - (1, Quantity("1e-3[s]")), - (2, Quantity("2e-3[s]")), - (3, Quantity("20[s]")), - (4, Quantity("30[s]")), - (5, Quantity("320[s]")), - (6, Quantity("330[s]")), - (7, Quantity("350[s]")), - (8, Quantity("360[s]")), - (9, Quantity("380[s]")), - (10, Quantity("390[s]")), - (11, Quantity("680[s]")), - (12, Quantity("690[s]")), - (13, Quantity("710[s]")), - (14, Quantity("720[s]")), -) -for i, q in analysis_step: - ANA_SETTINGS.SetStepEndTime(i, q) - -# Applied External HTCs and Temperature data - -External_Convection_Load_1 = TRANS_THERM.AddConvection() -selection = NS_GRP.Children[8] -External_Convection_Load_1.Location = selection - -External_Convection_Load_1.FilmCoefficient.Inputs[0].DiscreteValues = [ - Quantity("0[s]"), - Quantity("1e-3[s]"), - Quantity("2e-3[s]"), - Quantity("20[s]"), - Quantity("30[s]"), - Quantity("320[s]"), - Quantity("330[s]"), - Quantity("350[s]"), - Quantity("360[s]"), - Quantity("380[s]"), - Quantity("390[s]"), - Quantity("680[s]"), - Quantity("690[s]"), - Quantity("710[s]"), - Quantity("720[s]"), -] - -External_Convection_Load_1.FilmCoefficient.Output.DiscreteValues = [ - Quantity("60[W m^-1 m^-1 K^-1]"), - Quantity("60[W m^-1 m^-1 K^-1]"), - Quantity("60[W m^-1 m^-1 K^-1]"), - Quantity("60[W m^-1 m^-1 K^-1]"), - Quantity("60[W m^-1 m^-1 K^-1]"), - Quantity("60[W m^-1 m^-1 K^-1]"), - Quantity("60[W m^-1 m^-1 K^-1]"), - Quantity("60[W m^-1 m^-1 K^-1]"), - Quantity("60[W m^-1 m^-1 K^-1]"), - Quantity("60[W m^-1 m^-1 K^-1]"), - Quantity("60[W m^-1 m^-1 K^-1]"), - Quantity("60[W m^-1 m^-1 K^-1]"), - Quantity("60[W m^-1 m^-1 K^-1]"), - Quantity("60[W m^-1 m^-1 K^-1]"), - Quantity("60[W m^-1 m^-1 K^-1]"), -] - -External_Convection_Load_1.AmbientTemperature.Inputs[0].DiscreteValues = [ - Quantity("0[s]"), - Quantity("1e-3[s]"), - Quantity("2e-3[s]"), - Quantity("20[s]"), - Quantity("30[s]"), - Quantity("320[s]"), - Quantity("330[s]"), - Quantity("350[s]"), - Quantity("360[s]"), - Quantity("380[s]"), - Quantity("390[s]"), - Quantity("680[s]"), - Quantity("690[s]"), - Quantity("710[s]"), - Quantity("720[s]"), -] - -External_Convection_Load_1.AmbientTemperature.Output.DiscreteValues = [ - Quantity("473.15[K]"), - Quantity("473.15[K]"), - Quantity("473.15[K]"), - Quantity("473.15[K]"), - Quantity("473.15[K]"), - Quantity("473.15[K]"), - Quantity("473.15[K]"), - Quantity("473.15[K]"), - Quantity("473.15[K]"), - Quantity("473.15[K]"), - Quantity("473.15[K]"), - Quantity("473.15[K]"), - Quantity("473.15[K]"), - Quantity("473.15[K]"), - Quantity("473.15[K]"), -] - - -External_Convection_Load_2 = TRANS_THERM.AddConvection() -selection = NS_GRP.Children[7] -External_Convection_Load_2.Location = selection - -External_Convection_Load_2.FilmCoefficient.Inputs[0].DiscreteValues = [ - Quantity("0[s]"), - Quantity("1e-3[s]"), - Quantity("2e-3[s]"), - Quantity("20[s]"), - Quantity("30[s]"), - Quantity("320[s]"), - Quantity("330[s]"), - Quantity("350[s]"), - Quantity("360[s]"), - Quantity("380[s]"), - Quantity("390[s]"), - Quantity("680[s]"), - Quantity("690[s]"), - Quantity("710[s]"), - Quantity("720[s]"), -] - -External_Convection_Load_2.FilmCoefficient.Output.DiscreteValues = [ - Quantity("20[W m^-1 m^-1 K^-1]"), - Quantity("20[W m^-1 m^-1 K^-1]"), - Quantity("20[W m^-1 m^-1 K^-1]"), - Quantity("20[W m^-1 m^-1 K^-1]"), - Quantity("20[W m^-1 m^-1 K^-1]"), - Quantity("20[W m^-1 m^-1 K^-1]"), - Quantity("20[W m^-1 m^-1 K^-1]"), - Quantity("20[W m^-1 m^-1 K^-1]"), - Quantity("20[W m^-1 m^-1 K^-1]"), - Quantity("20[W m^-1 m^-1 K^-1]"), - Quantity("20[W m^-1 m^-1 K^-1]"), - Quantity("20[W m^-1 m^-1 K^-1]"), - Quantity("20[W m^-1 m^-1 K^-1]"), - Quantity("20[W m^-1 m^-1 K^-1]"), - Quantity("20[W m^-1 m^-1 K^-1]"), -] - -External_Convection_Load_2.AmbientTemperature.Inputs[0].DiscreteValues = [ - Quantity("0[s]"), - Quantity("1e-3[s]"), - Quantity("2e-3[s]"), - Quantity("20[s]"), - Quantity("30[s]"), - Quantity("320[s]"), - Quantity("330[s]"), - Quantity("350[s]"), - Quantity("360[s]"), - Quantity("380[s]"), - Quantity("390[s]"), - Quantity("680[s]"), - Quantity("690[s]"), - Quantity("710[s]"), - Quantity("720[s]"), -] - -External_Convection_Load_2.AmbientTemperature.Output.DiscreteValues = [ - Quantity("498.15[K]"), - Quantity("498.15[K]"), - Quantity("498.15[K]"), - Quantity("498.15[K]"), - Quantity("498.15[K]"), - Quantity("498.15[K]"), - Quantity("498.15[K]"), - Quantity("498.15[K]"), - Quantity("498.15[K]"), - Quantity("498.15[K]"), - Quantity("498.15[K]"), - Quantity("498.15[K]"), - Quantity("498.15[K]"), - Quantity("498.15[K]"), - Quantity("498.15[K]"), -] - - -External_Convection_Load_3 = TRANS_THERM.AddConvection() -selection = NS_GRP.Children[6] -External_Convection_Load_3.Location = selection - -External_Convection_Load_3.FilmCoefficient.Inputs[0].DiscreteValues = [ - Quantity("0[s]"), - Quantity("1e-3[s]"), - Quantity("2e-3[s]"), - Quantity("20[s]"), - Quantity("30[s]"), - Quantity("320[s]"), - Quantity("330[s]"), - Quantity("350[s]"), - Quantity("360[s]"), - Quantity("380[s]"), - Quantity("390[s]"), - Quantity("680[s]"), - Quantity("690[s]"), - Quantity("710[s]"), - Quantity("720[s]"), -] - -External_Convection_Load_3.FilmCoefficient.Output.DiscreteValues = [ - Quantity("500[W m^-1 m^-1 K^-1]"), - Quantity("500[W m^-1 m^-1 K^-1]"), - Quantity("500[W m^-1 m^-1 K^-1]"), - Quantity("500[W m^-1 m^-1 K^-1]"), - Quantity("500[W m^-1 m^-1 K^-1]"), - Quantity("500[W m^-1 m^-1 K^-1]"), - Quantity("500[W m^-1 m^-1 K^-1]"), - Quantity("500[W m^-1 m^-1 K^-1]"), - Quantity("500[W m^-1 m^-1 K^-1]"), - Quantity("500[W m^-1 m^-1 K^-1]"), - Quantity("500[W m^-1 m^-1 K^-1]"), - Quantity("500[W m^-1 m^-1 K^-1]"), - Quantity("500[W m^-1 m^-1 K^-1]"), - Quantity("500[W m^-1 m^-1 K^-1]"), - Quantity("500[W m^-1 m^-1 K^-1]"), -] - -External_Convection_Load_3.AmbientTemperature.Inputs[0].DiscreteValues = [ - Quantity("0[s]"), - Quantity("1e-3[s]"), - Quantity("2e-3[s]"), - Quantity("20[s]"), - Quantity("30[s]"), - Quantity("320[s]"), - Quantity("330[s]"), - Quantity("350[s]"), - Quantity("360[s]"), - Quantity("380[s]"), - Quantity("390[s]"), - Quantity("680[s]"), - Quantity("690[s]"), - Quantity("710[s]"), - Quantity("720[s]"), -] - -External_Convection_Load_3.AmbientTemperature.Output.DiscreteValues = [ - Quantity("373.15[K]"), - Quantity("373.15[K]"), - Quantity("373.15[K]"), - Quantity("373.15[K]"), - Quantity("373.15[K]"), - Quantity("373.15[K]"), - Quantity("373.15[K]"), - Quantity("373.15[K]"), - Quantity("373.15[K]"), - Quantity("373.15[K]"), - Quantity("373.15[K]"), - Quantity("373.15[K]"), - Quantity("373.15[K]"), - Quantity("373.15[K]"), - Quantity("373.15[K]"), -] - -group_list = [External_Convection_Load_1, External_Convection_Load_2, External_Convection_Load_3] -grouping_folder = Tree.Group(group_list) -tree_grouping_folder_70 = DataModel.GetObjectsByName("New Folder") - - -############################################################################### -# Use the ouput from Fluent to import the temperature and HTC data -# --------------------------------------------------------------- -# - -# Import HTCs and Temperature data From Fluent run - -Imported_Load_Group = TRANS_THERM.AddImportedLoadExternalData() -imported_load_group_61 = Imported_Load_Group -imported_convection_62 = imported_load_group_61.AddImportedConvection() - -external_data_files = Ansys.Mechanical.ExternalData.ExternalDataFileCollection() -external_data_files.SaveFilesWithProject = False -external_data_file_1 = Ansys.Mechanical.ExternalData.ExternalDataFile() -external_data_files.Add(external_data_file_1) -external_data_file_1.Identifier = "File1" -external_data_file_1.Description = "High" -external_data_file_1.IsMainFile = True -external_data_file_1.FilePath = temp_htc_data_high_path -external_data_file_1.ImportSettings = ( - Ansys.Mechanical.ExternalData.ImportSettingsFactory.GetSettingsForFormat( - MechanicalEnums.ExternalData.ImportFormat.Delimited - ) -) -import_settings = external_data_file_1.ImportSettings -import_settings.SkipRows = 1 -import_settings.SkipFooter = 0 -import_settings.Delimiter = "," -import_settings.AverageCornerNodesToMidsideNodes = False -import_settings.UseColumn(0, MechanicalEnums.ExternalData.VariableType.NodeId, "", "Node ID@A") -import_settings.UseColumn( - 1, MechanicalEnums.ExternalData.VariableType.XCoordinate, "m", "X Coordinate@B" -) -import_settings.UseColumn( - 2, MechanicalEnums.ExternalData.VariableType.YCoordinate, "m", "Y Coordinate@C" -) -import_settings.UseColumn( - 3, MechanicalEnums.ExternalData.VariableType.ZCoordinate, "m", "Z Coordinate@D" -) -import_settings.UseColumn( - 4, MechanicalEnums.ExternalData.VariableType.Temperature, "K", "Temperature@E" -) -import_settings.UseColumn( - 5, - MechanicalEnums.ExternalData.VariableType.HeatTransferCoefficient, - "W m^-2 K^-1", - "Heat Transfer Coefficient@F", -) -external_data_file_2 = Ansys.Mechanical.ExternalData.ExternalDataFile() -external_data_files.Add(external_data_file_2) -external_data_file_2.Identifier = "File2" -external_data_file_2.Description = "Med" -external_data_file_2.IsMainFile = False -external_data_file_2.FilePath = temp_htc_data_med_path -external_data_file_2.ImportSettings = ( - Ansys.Mechanical.ExternalData.ImportSettingsFactory.GetSettingsForFormat( - MechanicalEnums.ExternalData.ImportFormat.Delimited - ) -) -import_settings = external_data_file_2.ImportSettings -import_settings.SkipRows = 1 -import_settings.SkipFooter = 0 -import_settings.Delimiter = "," -import_settings.AverageCornerNodesToMidsideNodes = False -import_settings.UseColumn(0, MechanicalEnums.ExternalData.VariableType.NodeId, "", "Node ID@A") -import_settings.UseColumn( - 1, MechanicalEnums.ExternalData.VariableType.XCoordinate, "m", "X Coordinate@B" -) -import_settings.UseColumn( - 2, MechanicalEnums.ExternalData.VariableType.YCoordinate, "m", "Y Coordinate@C" -) -import_settings.UseColumn( - 3, MechanicalEnums.ExternalData.VariableType.ZCoordinate, "m", "Z Coordinate@D" -) -import_settings.UseColumn( - 4, MechanicalEnums.ExternalData.VariableType.Temperature, "K", "Temperature@E" -) -import_settings.UseColumn( - 5, - MechanicalEnums.ExternalData.VariableType.HeatTransferCoefficient, - "W m^-2 K^-1", - "Heat Transfer Coefficient@F", -) -external_data_file_3 = Ansys.Mechanical.ExternalData.ExternalDataFile() -external_data_files.Add(external_data_file_3) -external_data_file_3.Identifier = "File3" -external_data_file_3.Description = "Low" -external_data_file_3.IsMainFile = False -external_data_file_3.FilePath = temp_htc_data_low_path -external_data_file_3.ImportSettings = ( - Ansys.Mechanical.ExternalData.ImportSettingsFactory.GetSettingsForFormat( - MechanicalEnums.ExternalData.ImportFormat.Delimited - ) -) -import_settings = external_data_file_3.ImportSettings -import_settings.SkipRows = 1 -import_settings.SkipFooter = 0 -import_settings.Delimiter = "," -import_settings.AverageCornerNodesToMidsideNodes = False -import_settings.UseColumn(0, MechanicalEnums.ExternalData.VariableType.NodeId, "", "Node ID@A") -import_settings.UseColumn( - 1, MechanicalEnums.ExternalData.VariableType.XCoordinate, "m", "X Coordinate@B" -) -import_settings.UseColumn( - 2, MechanicalEnums.ExternalData.VariableType.YCoordinate, "m", "Y Coordinate@C" -) -import_settings.UseColumn( - 3, MechanicalEnums.ExternalData.VariableType.ZCoordinate, "m", "Z Coordinate@D" -) -import_settings.UseColumn( - 4, MechanicalEnums.ExternalData.VariableType.Temperature, "K", "Temperature@E" -) -import_settings.UseColumn( - 5, - MechanicalEnums.ExternalData.VariableType.HeatTransferCoefficient, - "W m^-2 K^-1", - "Heat Transfer Coefficient@F", -) - -imported_load_group_61.ImportExternalDataFiles(external_data_files) - -table = imported_load_group_61.Children[0].GetTableByName("Film Coefficient") -numofsteps = 15 -Film_Coeff = [ - "File1:Heat Transfer Coefficient@F", - "File2:Heat Transfer Coefficient@F", - "File3:Heat Transfer Coefficient@F", -] -Amb_Temp = ["File1:Temperature@E", "File2:Temperature@E", "File3:Temperature@E"] -Ana_time = [ - "0", - "1e-3", - "2e-3", - "20", - "30", - "320", - "330", - "350", - "360", - "380", - "390", - "680", - "690", - "710", - "720", -] - -for i in range(numofsteps - 1): - table.Add(None) - -table[0][0] = Film_Coeff[2] -table[0][1] = Amb_Temp[2] -table[0][2] = Ana_time[0] - -table[1][0] = Film_Coeff[2] -table[1][1] = Amb_Temp[2] -table[1][2] = Ana_time[1] - -table[2][0] = Film_Coeff[2] -table[2][1] = Amb_Temp[2] -table[2][2] = Ana_time[2] - -table[3][0] = Film_Coeff[2] -table[3][1] = Amb_Temp[2] -table[3][2] = Ana_time[3] - -table[4][0] = Film_Coeff[0] -table[4][1] = Amb_Temp[0] -table[4][2] = Ana_time[4] - -table[5][0] = Film_Coeff[0] -table[5][1] = Amb_Temp[0] -table[5][2] = Ana_time[5] - -table[6][0] = Film_Coeff[1] -table[6][1] = Amb_Temp[1] -table[6][2] = Ana_time[6] - -table[7][0] = Film_Coeff[1] -table[7][1] = Amb_Temp[1] -table[7][2] = Ana_time[7] - -table[8][0] = Film_Coeff[2] -table[8][1] = Amb_Temp[2] -table[8][2] = Ana_time[8] - -table[9][0] = Film_Coeff[2] -table[9][1] = Amb_Temp[2] -table[9][2] = Ana_time[9] - -table[10][0] = Film_Coeff[0] -table[10][1] = Amb_Temp[0] -table[10][2] = Ana_time[10] - -table[11][0] = Film_Coeff[0] -table[11][1] = Amb_Temp[0] -table[11][2] = Ana_time[11] - -table[12][0] = Film_Coeff[1] -table[12][1] = Amb_Temp[1] -table[12][2] = Ana_time[12] - -table[13][0] = Film_Coeff[1] -table[13][1] = Amb_Temp[1] -table[13][2] = Ana_time[13] - -table[14][0] = Film_Coeff[2] -table[14][1] = Amb_Temp[2] -table[14][2] = Ana_time[14] - -selection = NS_GRP.Children[4] -imported_convection_62.Location = selection -imported_load_id = imported_convection_62.ObjectId -imported_load = DataModel.GetObjectById(imported_load_id) - -# !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -# imported_convection_62.InternalObject.ExternalLoadSteppingType = 1 -# !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! - -imported_load.ImportLoad() - -Tree.Activate([imported_load]) -ExtAPI.Graphics.Camera.SetFit() -ExtAPI.Graphics.ExportImage( - os.path.join(project_directory, "imported_temperature.png"), image_export_format, settings_720p -) - -mechanical.download( - files=os.path.join(project_directory, "imported_temperature.png"), target_dir=OUTPUT_DIR -) -if GRAPHICS_BOOL: - display_image("imported_temperature.png") - -############################################################################### -# Solve and post-process the results -# ---------------------------------- -# - -# Insert results objects - -Temp = TRANS_THERM_SOLN.AddTemperature() -Temp.DisplayTime = Quantity("680 [s]") - -# Run Solution: Transient Thermal Simulation - -# TRANS_THERM_SOLN.Solve(True) -TRANS_THERM_SS = TRANS_THERM_SOLN.Status - -# Export temperature image - -Tree.Activate([Temp]) -ExtAPI.Graphics.ViewOptions.ResultPreference.ExtraModelDisplay = ( - Ansys.Mechanical.DataModel.MechanicalEnums.Graphics.ExtraModelDisplay.NoWireframe -) -ExtAPI.Graphics.ExportImage( - os.path.join(project_directory, "temperature.png"), image_export_format, settings_720p -) - -mechanical.download(files=os.path.join(project_directory, "temperature.png"), target_dir=OUTPUT_DIR) -if GRAPHICS_BOOL: - display_image("temperature.png") - - -############################################################################### -# Setup Structural Analysis -# ------------------------- -# - -Model.AddStaticStructuralAnalysis() - -# Define analysis settings - -# Setup static structural analysis settings -STAT_STRUC = Model.Analyses[1] -STAT_STRUC_SOLN = STAT_STRUC.Solution -STAT_STRUC_ANA_SETTING = STAT_STRUC.Children[0] - -STAT_STRUC_ANA_SETTING.NumberOfSteps = 1 -STAT_STRUC_ANA_SETTING.SetStepEndTime(1, Quantity("720[s]")) -STAT_STRUC_ANA_SETTING.NumberOfSteps = 14 - -analysis_step = ( - (1, Quantity("1e-3[s]")), - (2, Quantity("2e-3[s]")), - (3, Quantity("20[s]")), - (4, Quantity("30[s]")), - (5, Quantity("320[s]")), - (6, Quantity("330[s]")), - (7, Quantity("350[s]")), - (8, Quantity("360[s]")), - (9, Quantity("380[s]")), - (10, Quantity("390[s]")), - (11, Quantity("680[s]")), - (12, Quantity("690[s]")), - (13, Quantity("710[s]")), - (14, Quantity("720[s]")), -) -for i, q in analysis_step: - STAT_STRUC_ANA_SETTING.SetStepEndTime(i, q) -STAT_STRUC_ANA_SETTING.Activate() - - -# Add Imported Body Temperature load from Transient Thermal Run - -STAT_STRUC.ImportLoad(Model.Analyses[0]) -imported_load = DataModel.GetObjectsByName("Imported Body Temperature")[0] - -table = imported_load.GetTableByName("Source Time") -numofsteps = 14 -nCol = 2 -Ana_time = [ - "1e-3", - "2e-3", - "20", - "30", - "320", - "330", - "350", - "360", - "380", - "390", - "680", - "690", - "710", - "720", -] - -for i in range(numofsteps - 1): - table.Add(None) - -for i in range(numofsteps): - for j in range(nCol): - table[i][j] = Ana_time[i] - -imported_load.ImportLoad() - -# Apply Fixed Support Condition - -Fixed_Support = STAT_STRUC.AddFixedSupport() -selection = NS_GRP.Children[3] -Fixed_Support.Location = selection - -############################################################################### -# Sovle and post-process the results -# ---------------------------------- -# - -SOLN = STAT_STRUC.Solution - -TOT_DEF1 = SOLN.AddTotalDeformation() -TOT_DEF1.DisplayTime = Quantity("680 [s]") - -EQV_STRS1 = SOLN.AddEquivalentStress() -EQV_STRS1.DisplayTime = Quantity("680 [s]") - -EQV_PLAS_STRN1 = SOLN.AddEquivalentPlasticStrain() -EQV_PLAS_STRN1.DisplayTime = Quantity("680 [s]") - -THERM_STRN1 = SOLN.AddThermalStrain() -THERM_STRN1.DisplayTime = Quantity("680 [s]") - -# Solve Nonlinear Static Simulation - -# SOLN.Solve(True) -STAT_STRUC_SS = SOLN.Status - -# Export results images - -Tree.Activate([TOT_DEF1]) -ExtAPI.Graphics.ViewOptions.ResultPreference.ExtraModelDisplay = ( - Ansys.Mechanical.DataModel.MechanicalEnums.Graphics.ExtraModelDisplay.NoWireframe -) -ExtAPI.Graphics.ExportImage( - os.path.join(project_directory, "deformation.png"), image_export_format, settings_720p -) - -Tree.Activate([EQV_STRS1]) -ExtAPI.Graphics.ExportImage( - os.path.join(project_directory, "stress.png"), image_export_format, settings_720p -) - -Tree.Activate([EQV_PLAS_STRN1]) -ExtAPI.Graphics.ExportImage( - os.path.join(project_directory, "plastic_strain.png"), image_export_format, settings_720p -) - -mechanical.download(files=os.path.join(project_directory, "deformation.png"), target_dir=OUTPUT_DIR) -mechanical.download(files=os.path.join(project_directory, "stress.png"), target_dir=OUTPUT_DIR) -mechanical.download( - files=os.path.join(project_directory, "plastic_strain.png"), target_dir=OUTPUT_DIR -) - -# Display the resilts -if GRAPHICS_BOOL: - display_image("deformation.png") - display_image("stress.png") - display_image("plastic_strain.png") - -############################################################################### -# Close the Mechanical -# -------------------- -# -mechanical.exit() From 675776beb3bbb97f95b3dcc788f4af75dbb38804 Mon Sep 17 00:00:00 2001 From: dkunhamb Date: Fri, 13 Dec 2024 17:06:53 -0600 Subject: [PATCH 09/68] rename --- .github/workflows/fluent-mechanical.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/fluent-mechanical.yml b/.github/workflows/fluent-mechanical.yml index 0b204cca..416c0caa 100644 --- a/.github/workflows/fluent-mechanical.yml +++ b/.github/workflows/fluent-mechanical.yml @@ -175,7 +175,7 @@ jobs: run: | docker pull ${{ env.MECHANICAL_DOCKER_IMAGE }} - - name: Check out the geometry outputs + - name: Check out the fluent outputs uses: actions/download-artifact@v4 with: name: fluent-mechanical-workflow-fluent-outputs-${{ matrix.ansys-release }} From 73fe27aa2492fc535a749dc7c5b42b71f87ec345 Mon Sep 17 00:00:00 2001 From: Dipin <26918585+dipinknair@users.noreply.github.com> Date: Fri, 13 Dec 2024 17:07:15 -0600 Subject: [PATCH 10/68] Update fluent-mechanical/wf_fm_02_mechanical.py --- fluent-mechanical/wf_fm_02_mechanical.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fluent-mechanical/wf_fm_02_mechanical.py b/fluent-mechanical/wf_fm_02_mechanical.py index 8fbdd25f..8fbe3f34 100644 --- a/fluent-mechanical/wf_fm_02_mechanical.py +++ b/fluent-mechanical/wf_fm_02_mechanical.py @@ -796,7 +796,7 @@ def display_image(image_name): # Run Solution: Transient Thermal Simulation -#TRANS_THERM_SOLN.Solve(True) +TRANS_THERM_SOLN.Solve(True) TRANS_THERM_SS = TRANS_THERM_SOLN.Status # Export temperature image From 44072e4737fbb269e851de2ff3d70bc151efa933 Mon Sep 17 00:00:00 2001 From: Dipin <26918585+dipinknair@users.noreply.github.com> Date: Fri, 13 Dec 2024 17:07:21 -0600 Subject: [PATCH 11/68] Update fluent-mechanical/wf_fm_02_mechanical.py --- fluent-mechanical/wf_fm_02_mechanical.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fluent-mechanical/wf_fm_02_mechanical.py b/fluent-mechanical/wf_fm_02_mechanical.py index 8fbe3f34..9ac6020d 100644 --- a/fluent-mechanical/wf_fm_02_mechanical.py +++ b/fluent-mechanical/wf_fm_02_mechanical.py @@ -904,7 +904,7 @@ def display_image(image_name): # Solve Nonlinear Static Simulation -#SOLN.Solve(True) +SOLN.Solve(True) STAT_STRUC_SS = SOLN.Status # Export results images From 67fa31f2bcda73c78256f108eee1b221d668657a Mon Sep 17 00:00:00 2001 From: achitwar Date: Mon, 16 Dec 2024 14:52:38 +0530 Subject: [PATCH 12/68] Pyfluent CHT workflow --- fluent-mechanical/wf_fm_01_fluent.py | 249 ++++++++++++++++++++++++++- 1 file changed, 248 insertions(+), 1 deletion(-) diff --git a/fluent-mechanical/wf_fm_01_fluent.py b/fluent-mechanical/wf_fm_01_fluent.py index 028086af..bff06150 100644 --- a/fluent-mechanical/wf_fm_01_fluent.py +++ b/fluent-mechanical/wf_fm_01_fluent.py @@ -20,4 +20,251 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE # SOFTWARE. -print("Hello World") +""".. _exhaust_manifold_cfd_workflow: + +Conjugate Heat Transfer Workflow for Exhaust Manifold +##################################################### + +This workflow demonstrates the typical solver setup involved in performing a CFD +simulation for the conjugate heat transfer (CHT) analysis of an exhaust manifold. +A conjugate heat transfer analysis is a type of simulation that involves the +simultaneous solution of heat transfer in both solid and fluid domains. In this +case, the exhaust manifold is a solid domain, and the fluid domain is the gas +flowing through the manifold. The heat transfer between the solid and fluid domains +is modeled using the heat transfer coefficient (HTC) at the interface between the two +domains. +This workflow provides a step-by-step guide to set up a CHT analysis for an exhaust +manifold using Ansys Flueent Pyfluetn API's. The workflow includes usage of API's to +setup the physics, material properties, boundary conditions, solver settings, and +exporting the results to a CSV file for further use in a Thermo-Mechanical Analysis. + +Problem Description: +------------------- + +The geometry is an exhaust manifold with a fluid domain (gas) and a solid domain(metal) +meshed with a conformal Polyhedral mesh.The hot gas flows through the manifold, +and the heat is transferred to the solid domain. The objective is to calculate the +heat transfer coefficient (HTC) at the interface between the fluid and solid domains, +the temperature distribution in the solid domain, and export the results to a CSV +file for further use in a Thermo-Mechanical Analysis. +The workflow includes the following steps: +- Launch Fluent +- Load the mesh file +- Define the material properties +- Define the boundary conditions +- Define the solver settings +- Initialize the solution +- Run the solver +- Export the results to CSV file +- Close Fluent +This workflow will generate the following files as output: +- exhaust_manifold_results_HIGH_TEMP.cas.h5 +- exhaust_manifold_results_MEDIUM_TEMP.cas.h5 +- exhaust_manifold_results_LOW_TEMP.cas.h5 +- exhaust_manifold_results_HIGH_TEMP.dat.h5 +- exhaust_manifold_results_MEDIUM_TEMP.dat.h5 +- exhaust_manifold_results_LOW_TEMP.dat.h5 +- htc_temp_mapping_HIGH_TEMP.csv +- htc_temp_mapping_MEDIUM_TEMP.csv +- htc_temp_mapping_LOW_TEMP.csv +- Fluent transcript file (fluent-YYYYMMDD-HHMMSS-.trn) + +""" # noqa: D400, D415 + + +# Perform required imports +# ------------------------ +# Perform required imports, which includes downloading the mesh file from the +# examples. + +import ansys.fluent.core as pyfluent +from ansys.fluent.core import examples + +import_mesh_file = examples.download_file( + "exhaust_manifold_conf.msh.h5", "pyansys-workflow/exhaust-manifold/pyfluent" +) + +############################################################################### +# Launch Fluent +# ------------- +# Launch Fluent as a service in solver mode with double precision running on +# four processors and print Fluent version. + +solver = pyfluent.launch_fluent( + precision="double", + processor_count=4, + mode="solver", +) +print(solver.get_fluent_version()) + +############################################################################### +# Read the mesh file +# ------------------ +# Read the mesh file into the Fluent solver and check the mesh information. + +solver.settings.file.read_mesh(file_name=import_mesh_file) +solver.mesh.check() + + +############################################################################### +# Define the Physics +# ------------------ +# Define the physics of the problem by setting energy and turbulence models. + +solver.settings.setup.models.energy.enabled = True +solver.settings.setup.models.viscous.model.allowed_values() +solver.settings.setup.models.viscous.model = "k-epsilon" +solver.settings.setup.models.viscous.k_epsilon_model = "realizable" +solver.settings.setup.models.viscous.near_wall_treatment.wall_treatment = "enhanced-wall-treatment" + +############################################################################### +# Define the Material Properties +# ------------------------------- +# Define the material properties of the fluid, solid and assign the +# material to the appropriate cell zones. + +# Fluid Material Properties +fluid_mat = solver.settings.setup.materials.fluid["air"] +fluid_mat.rename("fluid-material") +fluid_mat = solver.settings.setup.materials.fluid["fluid-material"] +fluid_mat.density.option = "ideal-gas" +fluid_mat.viscosity.value = 4.25e-05 +fluid_mat.specific_heat.value = 1148 +fluid_mat.thermal_conductivity.value = 0.0686 + +# Solid Material Properties +solid_mat = solver.settings.setup.materials.solid["aluminum"] +solid_mat.rename("solid-material") +solid_mat = solver.settings.setup.materials.solid["solid-material"] +solid_mat.density.value = 8030 +solid_mat.specific_heat.value = 502.4 +solid_mat.thermal_conductivity.value = 60.5 + +# Assign Material to Cell Zones +solver.settings.setup.cell_zone_conditions.fluid["*fluid*"].general.material = "fluid-material" +solver.settings.setup.materials.print_state() +solver.settings.setup.cell_zone_conditions.solid["*solid*"].general.material = "solid-material" + +# Print the material properties for verification +solver.settings.setup.materials.print_state() + +############################################################################### +# Define the Named Expressions +# ---------------------------- +# Define the named expressions for the boundary conditions. + +solver.settings.setup.named_expressions.create("in_temperature") +solver.settings.setup.named_expressions["in_temperature"].definition = "1023.15 [K]" +solver.settings.setup.named_expressions["in_temperature"].input_parameter = True +solver.settings.setup.named_expressions.create("mass_flow_rate") +solver.settings.setup.named_expressions["mass_flow_rate"].definition = ( + "abs((0.1559 [kg/s] *log(in_temperature/(1 [K^1])))-0.9759 [kg/s])" +) + +solver.settings.setup.named_expressions.create("pressure_out") +solver.settings.setup.named_expressions["pressure_out"].definition = ( + "(-0.3383 [Pa]*in_temperature^2/(1 [K^2]))+954.75 [Pa]*in_temperature/(1 [K])-356085 [Pa]" +) + +solver.settings.setup.named_expressions.create("temperature_out") +solver.settings.setup.named_expressions["temperature_out"].definition = "in_temperature-23.00 [K]" + +############################################################################### +# Define the Boundary Conditions +# ------------------------------ +# Define the boundary conditions for the problem. + +# Convection Boundary Condition +solver.settings.setup.boundary_conditions.wall["solid:1"].thermal.thermal_condition = "Convection" +solver.settings.setup.boundary_conditions.wall["solid:1"].thermal.heat_transfer_coeff.value = 60 + +ref_temp = 200 + 273.15 +solver.settings.setup.boundary_conditions.wall["solid:1"].thermal.free_stream_temp.value = ref_temp + +# Inlet Boundary Conditions +solver.settings.setup.boundary_conditions.mass_flow_inlet.list() + +for inlet_bc in solver.settings.setup.boundary_conditions.mass_flow_inlet.keys(): + solver.settings.setup.boundary_conditions.mass_flow_inlet[ + inlet_bc + ].momentum.mass_flow_rate.value = "mass_flow_rate" + solver.settings.setup.boundary_conditions.mass_flow_inlet[ + inlet_bc + ].thermal.total_temperature.value = "in_temperature" + +# Outlet Boundary Conditions +solver.settings.setup.boundary_conditions.pressure_outlet.list() +solver.settings.setup.boundary_conditions.pressure_outlet[ + "pressure_outlet" +].momentum.gauge_pressure.value = "pressure_out" +solver.settings.setup.boundary_conditions.pressure_outlet[ + "pressure_outlet" +].thermal.backflow_total_temperature.value = "temperature_out" + +############################################################################### +# Define the Solution Methods and Solver Settings +# ----------------------------------------------- +# Define the solution methods and solver settings for the problem. + +# Solution Methods & controls +solver.settings.solution.methods.pseudo_time_method.formulation.coupled_solver = "off" +solver.settings.solution.controls.p_v_controls.flow_courant_number = 50 + +# Solver Settings initialization & set the iteration count +solver.settings.solution.initialization.hybrid_initialize() +solver.settings.solution.run_calculation.iter_count = 200 + + +############################################################################### +# Run the Solver & Export the Results to CSV +# ------------------------------------------ +# Run the solver to solve the problem and export the results to a CSV file. + +# Define a tuple with temperature values +temperature_values = ( + ("HIGH_TEMP", 1023.15), + ("MEDIUM_TEMP", 683.15), + ("LOW_TEMP", 483.15), +) + +# Retrieve fluid and solid zones +fluid_zones = list(solver.settings.setup.cell_zone_conditions.fluid.keys()) +solid_zones = list(solver.settings.setup.cell_zone_conditions.solid.keys()) +cell_zone_names = fluid_zones + solid_zones + +# Iterate over the temperature values tuple +for temp_name, temp_value in temperature_values: + # Running the simulation for each temperature value with initialization and iteration + solver.solution.initialization.hybrid_initialize() + solver.settings.setup.named_expressions["in_temperature"].definition = f"{temp_value} [K]" + solver.solution.run_calculation.iterate(iter_count=200) + + # Exporting Data for Thermo-Mechanical Simulation + mapping_file = f"htc_temp_mapping_{temp_name}.csv" + solver.settings.file.export.ascii( + file_name=mapping_file, + surface_name_list=["interface_solid"], + delimiter="comma", + cell_func_domain=["temperature", "heat-transfer-coef-wall"], + location="node", + ) + + # Export graphics result for the temperature distribution on interface_solid + temp_interface_contour = solver.settings.results.graphics.contour.create( + f"temp_interface_contour_{temp_name}" + ) + temp_interface_contour(field="temperature", surfaces_list=["interface_solid"]) + temp_interface_contour.display() + solver.settings.results.graphics.views.auto_scale() + solver.settings.results.graphics.picture.save_picture( + file_name=f"temp_interface_contour_{temp_name}.png" + ) + + solver.settings.file.write_case_data(file_name=f"exhaust_manifold_results_{temp_name}.cas.h5") + +############################################################################### +# Exit the Solver +# --------------- +# Close the Fluent solver. + +solver.exit() From fe8d7d979e64426f224ebe6537c72a16618835bf Mon Sep 17 00:00:00 2001 From: achitwar Date: Mon, 16 Dec 2024 20:36:55 +0530 Subject: [PATCH 13/68] defined the working dir --- fluent-mechanical/wf_fm_01_fluent.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/fluent-mechanical/wf_fm_01_fluent.py b/fluent-mechanical/wf_fm_01_fluent.py index bff06150..50857baf 100644 --- a/fluent-mechanical/wf_fm_01_fluent.py +++ b/fluent-mechanical/wf_fm_01_fluent.py @@ -77,6 +77,8 @@ # Perform required imports, which includes downloading the mesh file from the # examples. +import os + import ansys.fluent.core as pyfluent from ansys.fluent.core import examples @@ -84,6 +86,8 @@ "exhaust_manifold_conf.msh.h5", "pyansys-workflow/exhaust-manifold/pyfluent" ) +WORKING_DIR = os.path.join(os.path.dirname(__file__), "outputs") + ############################################################################### # Launch Fluent # ------------- @@ -94,6 +98,7 @@ precision="double", processor_count=4, mode="solver", + cwd=WORKING_DIR, ) print(solver.get_fluent_version()) From 6b7e98a45da2f4fddb7f324c1a97201d7971192a Mon Sep 17 00:00:00 2001 From: dkunhamb Date: Mon, 16 Dec 2024 09:34:30 -0600 Subject: [PATCH 14/68] update output folder --- fluent-mechanical/requirements_24.1.txt | 2 +- fluent-mechanical/requirements_24.2.txt | 2 +- fluent-mechanical/wf_fm_01_fluent.py | 38 +++++++++++++++++++++++++ 3 files changed, 40 insertions(+), 2 deletions(-) diff --git a/fluent-mechanical/requirements_24.1.txt b/fluent-mechanical/requirements_24.1.txt index 9eda404d..6000de7d 100644 --- a/fluent-mechanical/requirements_24.1.txt +++ b/fluent-mechanical/requirements_24.1.txt @@ -1,2 +1,2 @@ ansys-mechanical-core==0.11.10 -ansys-fluent-core==0.27.0 +ansys-fluent-core==0.26.1 diff --git a/fluent-mechanical/requirements_24.2.txt b/fluent-mechanical/requirements_24.2.txt index 9eda404d..6000de7d 100644 --- a/fluent-mechanical/requirements_24.2.txt +++ b/fluent-mechanical/requirements_24.2.txt @@ -1,2 +1,2 @@ ansys-mechanical-core==0.11.10 -ansys-fluent-core==0.27.0 +ansys-fluent-core==0.26.1 diff --git a/fluent-mechanical/wf_fm_01_fluent.py b/fluent-mechanical/wf_fm_01_fluent.py index bff06150..8a133c74 100644 --- a/fluent-mechanical/wf_fm_01_fluent.py +++ b/fluent-mechanical/wf_fm_01_fluent.py @@ -77,8 +77,31 @@ # Perform required imports, which includes downloading the mesh file from the # examples. +import os + import ansys.fluent.core as pyfluent from ansys.fluent.core import examples +from matplotlib import image as mpimg +from matplotlib import pyplot as plt + +# sphinx_gallery_start_ignore +# Check if the __file__ variable is defined. If not, set it. +# This is a workaround to run the script in Sphinx-Gallery. +from pathlib import Path # isort:skip + +if "__file__" not in locals(): + __file__ = Path(os.getcwd(), "wf_fm_01_fluent.py") +# sphinx_gallery_end_ignore + +GRAPHICS_BOOL = False # Set to True to display the graphics +WORKING_DIR = Path(Path(__file__).parent, "outputs") # Output directory +os.makedirs(WORKING_DIR, exist_ok=True) + +# sphinx_gallery_start_ignore +if "DOC_BUILD" in os.environ: + GRAPHICS_BOOL = True +# sphinx_gallery_end_ignore + import_mesh_file = examples.download_file( "exhaust_manifold_conf.msh.h5", "pyansys-workflow/exhaust-manifold/pyfluent" @@ -94,9 +117,20 @@ precision="double", processor_count=4, mode="solver", + cwd=WORKING_DIR, ) print(solver.get_fluent_version()) + +def display_image(image_name): + plt.figure(figsize=(16, 9)) + plt.imshow(mpimg.imread(os.path.join(OUTPUT_DIR, image_name))) + plt.xticks([]) + plt.yticks([]) + plt.axis("off") + plt.show() + + ############################################################################### # Read the mesh file # ------------------ @@ -262,6 +296,10 @@ solver.settings.file.write_case_data(file_name=f"exhaust_manifold_results_{temp_name}.cas.h5") +# Display the resilts +if GRAPHICS_BOOL: + for temp_name, temp_value in temperature_values: + display_image(f"temp_interface_contour_{temp_name}.png") ############################################################################### # Exit the Solver # --------------- From 227e34f4a576a087d0b8262bfd733296862d8030 Mon Sep 17 00:00:00 2001 From: dkunhamb Date: Mon, 16 Dec 2024 09:35:42 -0600 Subject: [PATCH 15/68] update working dir --- fluent-mechanical/wf_fm_01_fluent.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/fluent-mechanical/wf_fm_01_fluent.py b/fluent-mechanical/wf_fm_01_fluent.py index 7f919fd5..13d3a3fd 100644 --- a/fluent-mechanical/wf_fm_01_fluent.py +++ b/fluent-mechanical/wf_fm_01_fluent.py @@ -107,8 +107,6 @@ "exhaust_manifold_conf.msh.h5", "pyansys-workflow/exhaust-manifold/pyfluent" ) -WORKING_DIR = os.path.join(os.path.dirname(__file__), "outputs") - ############################################################################### # Launch Fluent # ------------- @@ -126,7 +124,7 @@ def display_image(image_name): plt.figure(figsize=(16, 9)) - plt.imshow(mpimg.imread(os.path.join(OUTPUT_DIR, image_name))) + plt.imshow(mpimg.imread(os.path.join(WORKING_DIR, image_name))) plt.xticks([]) plt.yticks([]) plt.axis("off") From 24409bf450c9b33026b9a23e700efb52fefcaec6 Mon Sep 17 00:00:00 2001 From: dkunhamb Date: Mon, 16 Dec 2024 09:42:07 -0600 Subject: [PATCH 16/68] add matplotlib --- fluent-mechanical/requirements_24.1.txt | 1 + fluent-mechanical/requirements_24.2.txt | 1 + 2 files changed, 2 insertions(+) diff --git a/fluent-mechanical/requirements_24.1.txt b/fluent-mechanical/requirements_24.1.txt index 6000de7d..b09d90fa 100644 --- a/fluent-mechanical/requirements_24.1.txt +++ b/fluent-mechanical/requirements_24.1.txt @@ -1,2 +1,3 @@ ansys-mechanical-core==0.11.10 ansys-fluent-core==0.26.1 +matplotlib==3.10.0 \ No newline at end of file diff --git a/fluent-mechanical/requirements_24.2.txt b/fluent-mechanical/requirements_24.2.txt index 6000de7d..f431217a 100644 --- a/fluent-mechanical/requirements_24.2.txt +++ b/fluent-mechanical/requirements_24.2.txt @@ -1,2 +1,3 @@ ansys-mechanical-core==0.11.10 ansys-fluent-core==0.26.1 +matplotlib==3.10.0 From 01a9a5eb033ed453fc31d20a4a2fe0b1c7ffaa59 Mon Sep 17 00:00:00 2001 From: dkunhamb Date: Mon, 16 Dec 2024 10:07:19 -0600 Subject: [PATCH 17/68] fluent container change --- fluent-mechanical/wf_fm_01_fluent.py | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/fluent-mechanical/wf_fm_01_fluent.py b/fluent-mechanical/wf_fm_01_fluent.py index 13d3a3fd..4dd304ba 100644 --- a/fluent-mechanical/wf_fm_01_fluent.py +++ b/fluent-mechanical/wf_fm_01_fluent.py @@ -112,13 +112,29 @@ # ------------- # Launch Fluent as a service in solver mode with double precision running on # four processors and print Fluent version. +if os.getenv("PYANSYS_WORKFLOWS_CI") == "true": + container_dict = { + "fluent_image": f"{os.environ['FLUENT_DOCKER_IMAGE']}:{os.environ['FLUENT_IMAGE_TAG']}", + "host_mount_path": WORKING_DIR, + "license_server": os.environ["ANSYSLMD_LICENSE_FILE"], + "timeout": 300, + } + # https://fluent.docs.pyansys.com/version/stable/api/general/launcher/fluent_container.html + solver = pyfluent.launch_fluent( + precision="double", + processor_count=4, + mode="solver", + cwd=WORKING_DIR, + container_dict=container_dict, + ) +else: + solver = pyfluent.launch_fluent( + precision="double", + processor_count=4, + mode="solver", + cwd=WORKING_DIR, + ) -solver = pyfluent.launch_fluent( - precision="double", - processor_count=4, - mode="solver", - cwd=WORKING_DIR, -) print(solver.get_fluent_version()) From 3e855a384d3a9c8663698a74acf092617b2b274e Mon Sep 17 00:00:00 2001 From: dkunhamb Date: Mon, 16 Dec 2024 10:28:26 -0600 Subject: [PATCH 18/68] update container_dic --- fluent-mechanical/wf_fm_01_fluent.py | 29 +++++++++++++--------------- 1 file changed, 13 insertions(+), 16 deletions(-) diff --git a/fluent-mechanical/wf_fm_01_fluent.py b/fluent-mechanical/wf_fm_01_fluent.py index 4dd304ba..56a897ab 100644 --- a/fluent-mechanical/wf_fm_01_fluent.py +++ b/fluent-mechanical/wf_fm_01_fluent.py @@ -106,35 +106,32 @@ import_mesh_file = examples.download_file( "exhaust_manifold_conf.msh.h5", "pyansys-workflow/exhaust-manifold/pyfluent" ) +print(import_mesh_file) + ############################################################################### # Launch Fluent # ------------- # Launch Fluent as a service in solver mode with double precision running on # four processors and print Fluent version. + +container_dict = None + if os.getenv("PYANSYS_WORKFLOWS_CI") == "true": container_dict = { "fluent_image": f"{os.environ['FLUENT_DOCKER_IMAGE']}:{os.environ['FLUENT_IMAGE_TAG']}", - "host_mount_path": WORKING_DIR, + "mount_source": WORKING_DIR, "license_server": os.environ["ANSYSLMD_LICENSE_FILE"], "timeout": 300, } - # https://fluent.docs.pyansys.com/version/stable/api/general/launcher/fluent_container.html - solver = pyfluent.launch_fluent( - precision="double", - processor_count=4, - mode="solver", - cwd=WORKING_DIR, - container_dict=container_dict, - ) -else: - solver = pyfluent.launch_fluent( - precision="double", - processor_count=4, - mode="solver", - cwd=WORKING_DIR, - ) +solver = pyfluent.launch_fluent( + precision="double", + processor_count=4, + mode="solver", + cwd=WORKING_DIR, + container_dict=container_dict, +) print(solver.get_fluent_version()) From 84886c644cc2d55e90ea8cd8790ce74f1f5d6345 Mon Sep 17 00:00:00 2001 From: dkunhamb Date: Mon, 16 Dec 2024 10:33:35 -0600 Subject: [PATCH 19/68] udpate download file --- fluent-mechanical/wf_fm_01_fluent.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/fluent-mechanical/wf_fm_01_fluent.py b/fluent-mechanical/wf_fm_01_fluent.py index 56a897ab..903cbfe0 100644 --- a/fluent-mechanical/wf_fm_01_fluent.py +++ b/fluent-mechanical/wf_fm_01_fluent.py @@ -104,7 +104,9 @@ import_mesh_file = examples.download_file( - "exhaust_manifold_conf.msh.h5", "pyansys-workflow/exhaust-manifold/pyfluent" + filename="exhaust_manifold_conf.msh.h5", + directory="pyansys-workflow/exhaust-manifold/pyfluent", + save_path=WORKING_DIR, ) print(import_mesh_file) From 3213ae5d9f851af931f8f373e6dfd18d3e6bf531 Mon Sep 17 00:00:00 2001 From: dkunhamb Date: Mon, 16 Dec 2024 10:38:50 -0600 Subject: [PATCH 20/68] minor --- fluent-mechanical/wf_fm_01_fluent.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/fluent-mechanical/wf_fm_01_fluent.py b/fluent-mechanical/wf_fm_01_fluent.py index 903cbfe0..cf51257b 100644 --- a/fluent-mechanical/wf_fm_01_fluent.py +++ b/fluent-mechanical/wf_fm_01_fluent.py @@ -104,9 +104,9 @@ import_mesh_file = examples.download_file( - filename="exhaust_manifold_conf.msh.h5", - directory="pyansys-workflow/exhaust-manifold/pyfluent", - save_path=WORKING_DIR, + "exhaust_manifold_conf.msh.h5", + "pyansys-workflow/exhaust-manifold/pyfluent", + WORKING_DIR, ) print(import_mesh_file) From 3e830305ec719473d6114c54bd7b0f563bb4f170 Mon Sep 17 00:00:00 2001 From: dkunhamb Date: Mon, 16 Dec 2024 12:10:01 -0600 Subject: [PATCH 21/68] test --- fluent-mechanical/wf_fm_01_fluent.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/fluent-mechanical/wf_fm_01_fluent.py b/fluent-mechanical/wf_fm_01_fluent.py index cf51257b..471849e4 100644 --- a/fluent-mechanical/wf_fm_01_fluent.py +++ b/fluent-mechanical/wf_fm_01_fluent.py @@ -106,11 +106,9 @@ import_mesh_file = examples.download_file( "exhaust_manifold_conf.msh.h5", "pyansys-workflow/exhaust-manifold/pyfluent", - WORKING_DIR, ) print(import_mesh_file) - ############################################################################### # Launch Fluent # ------------- @@ -154,7 +152,8 @@ def display_image(image_name): solver.settings.file.read_mesh(file_name=import_mesh_file) solver.mesh.check() - +import sys +sys.exit(0) ############################################################################### # Define the Physics # ------------------ From a52d85a7676331d5afa6dfe44ba10cd8a8945b10 Mon Sep 17 00:00:00 2001 From: dkunhamb Date: Mon, 16 Dec 2024 18:40:48 -0600 Subject: [PATCH 22/68] fix --- fluent-mechanical/wf_fm_01_fluent.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/fluent-mechanical/wf_fm_01_fluent.py b/fluent-mechanical/wf_fm_01_fluent.py index 471849e4..dd10e400 100644 --- a/fluent-mechanical/wf_fm_01_fluent.py +++ b/fluent-mechanical/wf_fm_01_fluent.py @@ -152,8 +152,6 @@ def display_image(image_name): solver.settings.file.read_mesh(file_name=import_mesh_file) solver.mesh.check() -import sys -sys.exit(0) ############################################################################### # Define the Physics # ------------------ From c334ca5d79bd861d4d55a530ece04e434c917b99 Mon Sep 17 00:00:00 2001 From: Roberto Pastor Muela <37798125+RobPasMue@users.noreply.github.com> Date: Tue, 17 Dec 2024 08:11:08 +0100 Subject: [PATCH 23/68] fix: fluent launcher method --- fluent-mechanical/wf_fm_01_fluent.py | 35 +++++++++++++++++----------- 1 file changed, 22 insertions(+), 13 deletions(-) diff --git a/fluent-mechanical/wf_fm_01_fluent.py b/fluent-mechanical/wf_fm_01_fluent.py index dd10e400..72db3fec 100644 --- a/fluent-mechanical/wf_fm_01_fluent.py +++ b/fluent-mechanical/wf_fm_01_fluent.py @@ -93,8 +93,11 @@ __file__ = Path(os.getcwd(), "wf_fm_01_fluent.py") # sphinx_gallery_end_ignore -GRAPHICS_BOOL = False # Set to True to display the graphics -WORKING_DIR = Path(Path(__file__).parent, "outputs") # Output directory +# Set to True to display the graphics +GRAPHICS_BOOL = False + +# Output directory +WORKING_DIR = os.path.join(os.path.dirname(__file__), "outputs") os.makedirs(WORKING_DIR, exist_ok=True) # sphinx_gallery_start_ignore @@ -114,9 +117,6 @@ # ------------- # Launch Fluent as a service in solver mode with double precision running on # four processors and print Fluent version. - -container_dict = None - if os.getenv("PYANSYS_WORKFLOWS_CI") == "true": container_dict = { "fluent_image": f"{os.environ['FLUENT_DOCKER_IMAGE']}:{os.environ['FLUENT_IMAGE_TAG']}", @@ -124,14 +124,23 @@ "license_server": os.environ["ANSYSLMD_LICENSE_FILE"], "timeout": 300, } - -solver = pyfluent.launch_fluent( - precision="double", - processor_count=4, - mode="solver", - cwd=WORKING_DIR, - container_dict=container_dict, -) + solver = pyfluent.launch_fluent( + precision="double", + processor_count=4, + mode="solver", + cwd="/mnt/pyfluent", + container_dict=container_dict, + start_container=True, + ui_mode="no_gui_or_graphics", + cleanup_on_exit=False, + ) +else: + solver = pyfluent.launch_fluent( + precision="double", + processor_count=4, + mode="solver", + cwd=WORKING_DIR, + ) print(solver.get_fluent_version()) From beaba2f1fe45007d7815082e401d3df2016c12e2 Mon Sep 17 00:00:00 2001 From: Roberto Pastor Muela <37798125+RobPasMue@users.noreply.github.com> Date: Tue, 17 Dec 2024 08:36:58 +0100 Subject: [PATCH 24/68] fix: missing dir --- fluent-mechanical/wf_fm_01_fluent.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/fluent-mechanical/wf_fm_01_fluent.py b/fluent-mechanical/wf_fm_01_fluent.py index 72db3fec..2d74593a 100644 --- a/fluent-mechanical/wf_fm_01_fluent.py +++ b/fluent-mechanical/wf_fm_01_fluent.py @@ -134,6 +134,8 @@ ui_mode="no_gui_or_graphics", cleanup_on_exit=False, ) + # From here on, the working directory is the mounted directory + WORKING_DIR = "/mnt/pyfluent" else: solver = pyfluent.launch_fluent( precision="double", From 815e120944afb58a0a8cf1925a09178fcb46ec11 Mon Sep 17 00:00:00 2001 From: Roberto Pastor Muela <37798125+RobPasMue@users.noreply.github.com> Date: Tue, 17 Dec 2024 08:50:07 +0100 Subject: [PATCH 25/68] chore: add logging --- fluent-mechanical/wf_fm_01_fluent.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/fluent-mechanical/wf_fm_01_fluent.py b/fluent-mechanical/wf_fm_01_fluent.py index 2d74593a..eafa3871 100644 --- a/fluent-mechanical/wf_fm_01_fluent.py +++ b/fluent-mechanical/wf_fm_01_fluent.py @@ -118,6 +118,7 @@ # Launch Fluent as a service in solver mode with double precision running on # four processors and print Fluent version. if os.getenv("PYANSYS_WORKFLOWS_CI") == "true": + print("Configuring Fluent for CI") container_dict = { "fluent_image": f"{os.environ['FLUENT_DOCKER_IMAGE']}:{os.environ['FLUENT_IMAGE_TAG']}", "mount_source": WORKING_DIR, @@ -144,6 +145,7 @@ cwd=WORKING_DIR, ) print(solver.get_fluent_version()) +print(f"Working directory: {WORKING_DIR}") def display_image(image_name): From d998041f9f670c624be128e23eeb2783aa832242 Mon Sep 17 00:00:00 2001 From: Roberto Pastor Muela <37798125+RobPasMue@users.noreply.github.com> Date: Tue, 17 Dec 2024 08:55:57 +0100 Subject: [PATCH 26/68] fix: download file to shared folder --- fluent-mechanical/wf_fm_01_fluent.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fluent-mechanical/wf_fm_01_fluent.py b/fluent-mechanical/wf_fm_01_fluent.py index eafa3871..97c6530d 100644 --- a/fluent-mechanical/wf_fm_01_fluent.py +++ b/fluent-mechanical/wf_fm_01_fluent.py @@ -108,7 +108,7 @@ import_mesh_file = examples.download_file( "exhaust_manifold_conf.msh.h5", - "pyansys-workflow/exhaust-manifold/pyfluent", + WORKING_DIR, ) print(import_mesh_file) From ebede03449545a042c84c64cf752c5f9e174a438 Mon Sep 17 00:00:00 2001 From: Roberto Pastor Muela <37798125+RobPasMue@users.noreply.github.com> Date: Tue, 17 Dec 2024 09:03:23 +0100 Subject: [PATCH 27/68] Revert "fix: download file to shared folder" This reverts commit d998041f9f670c624be128e23eeb2783aa832242. --- fluent-mechanical/wf_fm_01_fluent.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fluent-mechanical/wf_fm_01_fluent.py b/fluent-mechanical/wf_fm_01_fluent.py index 97c6530d..eafa3871 100644 --- a/fluent-mechanical/wf_fm_01_fluent.py +++ b/fluent-mechanical/wf_fm_01_fluent.py @@ -108,7 +108,7 @@ import_mesh_file = examples.download_file( "exhaust_manifold_conf.msh.h5", - WORKING_DIR, + "pyansys-workflow/exhaust-manifold/pyfluent", ) print(import_mesh_file) From 2f6c30a0e410359926187558b8f5b7b324859123 Mon Sep 17 00:00:00 2001 From: Roberto Pastor Muela <37798125+RobPasMue@users.noreply.github.com> Date: Tue, 17 Dec 2024 09:04:27 +0100 Subject: [PATCH 28/68] fix: store in dedicated location --- fluent-mechanical/wf_fm_01_fluent.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/fluent-mechanical/wf_fm_01_fluent.py b/fluent-mechanical/wf_fm_01_fluent.py index eafa3871..95594773 100644 --- a/fluent-mechanical/wf_fm_01_fluent.py +++ b/fluent-mechanical/wf_fm_01_fluent.py @@ -107,8 +107,9 @@ import_mesh_file = examples.download_file( - "exhaust_manifold_conf.msh.h5", - "pyansys-workflow/exhaust-manifold/pyfluent", + file_name="exhaust_manifold_conf.msh.h5", + directory="pyansys-workflow/exhaust-manifold/pyfluent", + save_path=WORKING_DIR, ) print(import_mesh_file) From ef2967d89c2ffac7019e85e9d82fc7c6e65e44f5 Mon Sep 17 00:00:00 2001 From: Roberto Pastor Muela <37798125+RobPasMue@users.noreply.github.com> Date: Tue, 17 Dec 2024 09:16:36 +0100 Subject: [PATCH 29/68] fix: paths --- fluent-mechanical/wf_fm_01_fluent.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/fluent-mechanical/wf_fm_01_fluent.py b/fluent-mechanical/wf_fm_01_fluent.py index 95594773..a829b638 100644 --- a/fluent-mechanical/wf_fm_01_fluent.py +++ b/fluent-mechanical/wf_fm_01_fluent.py @@ -138,6 +138,9 @@ ) # From here on, the working directory is the mounted directory WORKING_DIR = "/mnt/pyfluent" + + # Fix the path to the mesh file + import_mesh_file = os.path.join(WORKING_DIR, "exhaust_manifold_conf.msh.h5") else: solver = pyfluent.launch_fluent( precision="double", @@ -149,9 +152,9 @@ print(f"Working directory: {WORKING_DIR}") -def display_image(image_name): +def display_image(work_dir, image_name): plt.figure(figsize=(16, 9)) - plt.imshow(mpimg.imread(os.path.join(WORKING_DIR, image_name))) + plt.imshow(mpimg.imread(os.path.join(work_dir, image_name))) plt.xticks([]) plt.yticks([]) plt.axis("off") @@ -325,7 +328,7 @@ def display_image(image_name): # Display the resilts if GRAPHICS_BOOL: for temp_name, temp_value in temperature_values: - display_image(f"temp_interface_contour_{temp_name}.png") + display_image(WORKING_DIR, f"temp_interface_contour_{temp_name}.png") ############################################################################### # Exit the Solver # --------------- From c223ad2ab6f0042c52fd7efd6e07c1f3febfb020 Mon Sep 17 00:00:00 2001 From: achitwar Date: Tue, 17 Dec 2024 22:57:06 +0530 Subject: [PATCH 30/68] changes to support 24r1 & 24r2 --- fluent-mechanical/wf_fm_01_fluent.py | 47 ++++++++++++++++++++++------ 1 file changed, 37 insertions(+), 10 deletions(-) diff --git a/fluent-mechanical/wf_fm_01_fluent.py b/fluent-mechanical/wf_fm_01_fluent.py index a829b638..5fa73e20 100644 --- a/fluent-mechanical/wf_fm_01_fluent.py +++ b/fluent-mechanical/wf_fm_01_fluent.py @@ -138,7 +138,7 @@ ) # From here on, the working directory is the mounted directory WORKING_DIR = "/mnt/pyfluent" - + # Fix the path to the mesh file import_mesh_file = os.path.join(WORKING_DIR, "exhaust_manifold_conf.msh.h5") else: @@ -204,9 +204,14 @@ def display_image(work_dir, image_name): solid_mat.thermal_conductivity.value = 60.5 # Assign Material to Cell Zones -solver.settings.setup.cell_zone_conditions.fluid["*fluid*"].general.material = "fluid-material" -solver.settings.setup.materials.print_state() -solver.settings.setup.cell_zone_conditions.solid["*solid*"].general.material = "solid-material" +if solver.get_fluent_version() < pyfluent.FluentVersion.v242: + solver.settings.setup.cell_zone_conditions.fluid["fluid"].material = "fluid-material" + solver.settings.setup.materials.print_state() + solver.settings.setup.cell_zone_conditions.solid["solid"].material = "solid-material" +else: + solver.settings.setup.cell_zone_conditions.fluid["*fluid*"].general.material = "fluid-material" + solver.settings.setup.materials.print_state() + solver.settings.setup.cell_zone_conditions.solid["*solid*"].general.material = "solid-material" # Print the material properties for verification solver.settings.setup.materials.print_state() @@ -238,11 +243,25 @@ def display_image(work_dir, image_name): # Define the boundary conditions for the problem. # Convection Boundary Condition -solver.settings.setup.boundary_conditions.wall["solid:1"].thermal.thermal_condition = "Convection" -solver.settings.setup.boundary_conditions.wall["solid:1"].thermal.heat_transfer_coeff.value = 60 +# Reference temperature for the convection boundary condition ref_temp = 200 + 273.15 -solver.settings.setup.boundary_conditions.wall["solid:1"].thermal.free_stream_temp.value = ref_temp + +if solver.get_fluent_version() < pyfluent.FluentVersion.v242: + solver.settings.setup.boundary_conditions.wall["solid:1"].thermal.thermal_bc = "Convection" + + solver.settings.setup.boundary_conditions.wall["solid:1"].thermal.h.value = 60 + + solver.settings.setup.boundary_conditions.wall["solid:1"].thermal.tinf.value = ref_temp +else: + solver.settings.setup.boundary_conditions.wall["solid:1"].thermal.thermal_condition = ( + "Convection" + ) + solver.settings.setup.boundary_conditions.wall["solid:1"].thermal.heat_transfer_coeff.value = 60 + + solver.settings.setup.boundary_conditions.wall["solid:1"].thermal.free_stream_temp.value = ( + ref_temp + ) # Inlet Boundary Conditions solver.settings.setup.boundary_conditions.mass_flow_inlet.list() @@ -260,9 +279,17 @@ def display_image(work_dir, image_name): solver.settings.setup.boundary_conditions.pressure_outlet[ "pressure_outlet" ].momentum.gauge_pressure.value = "pressure_out" -solver.settings.setup.boundary_conditions.pressure_outlet[ - "pressure_outlet" -].thermal.backflow_total_temperature.value = "temperature_out" + + +if solver.get_fluent_version() < pyfluent.FluentVersion.v242: + solver.settings.setup.boundary_conditions.pressure_outlet[ + "pressure_outlet" + ].thermal.t0.value = "temperature_out" + +else: + solver.settings.setup.boundary_conditions.pressure_outlet[ + "pressure_outlet" + ].thermal.backflow_total_temperature.value = "temperature_out" ############################################################################### # Define the Solution Methods and Solver Settings From 444890914faa3ac8b423104e08d797846b5b65b3 Mon Sep 17 00:00:00 2001 From: dkunhamb Date: Tue, 17 Dec 2024 12:20:28 -0600 Subject: [PATCH 31/68] 16 cores --- .github/workflows/fluent-mechanical.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/fluent-mechanical.yml b/.github/workflows/fluent-mechanical.yml index 416c0caa..724898a6 100644 --- a/.github/workflows/fluent-mechanical.yml +++ b/.github/workflows/fluent-mechanical.yml @@ -34,7 +34,7 @@ env: jobs: fluent: name: Fluent - runs-on: public-ubuntu-latest-8-cores + runs-on: public-ubuntu-latest-16-cores strategy: fail-fast: false matrix: From 6cf2596e716f0505d8a7a5a18cf15bd093c76ac2 Mon Sep 17 00:00:00 2001 From: dkunhamb Date: Tue, 17 Dec 2024 12:41:28 -0600 Subject: [PATCH 32/68] missing name in cicd --- .github/workflows/fluent-mechanical.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/fluent-mechanical.yml b/.github/workflows/fluent-mechanical.yml index 724898a6..536caec7 100644 --- a/.github/workflows/fluent-mechanical.yml +++ b/.github/workflows/fluent-mechanical.yml @@ -79,7 +79,7 @@ jobs: with: name: fluent-mechanical-workflow-fluent-outputs-${{ matrix.ansys-release }} path: | - fluent-mechanical/outputs/htc_temp_mapping_LOW_TEMP + fluent-mechanical/outputs/htc_temp_mapping_LOW_TEMP.csv fluent-mechanical/outputs/htc_temp_mapping_MEDIUM_TEMP.csv fluent-mechanical/outputs/htc_temp_mapping_HIGH_TEMP.csv From a2a989faf318bc1f5672a148a7dad59c71b2e838 Mon Sep 17 00:00:00 2001 From: Roberto Pastor Muela <37798125+RobPasMue@users.noreply.github.com> Date: Wed, 18 Dec 2024 07:47:49 +0100 Subject: [PATCH 33/68] revert to 8 cores --- .github/workflows/fluent-mechanical.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/fluent-mechanical.yml b/.github/workflows/fluent-mechanical.yml index 536caec7..29be23d0 100644 --- a/.github/workflows/fluent-mechanical.yml +++ b/.github/workflows/fluent-mechanical.yml @@ -34,7 +34,7 @@ env: jobs: fluent: name: Fluent - runs-on: public-ubuntu-latest-16-cores + runs-on: public-ubuntu-latest-8-cores strategy: fail-fast: false matrix: From 9bdedc7fd2f09009767c20c1ed4da65fc832546e Mon Sep 17 00:00:00 2001 From: Roberto Pastor Muela <37798125+RobPasMue@users.noreply.github.com> Date: Wed, 18 Dec 2024 08:26:02 +0100 Subject: [PATCH 34/68] ci: attempt to use PyFluent runners --- .github/workflows/fluent-mechanical.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/fluent-mechanical.yml b/.github/workflows/fluent-mechanical.yml index 416c0caa..94ebfc30 100644 --- a/.github/workflows/fluent-mechanical.yml +++ b/.github/workflows/fluent-mechanical.yml @@ -34,7 +34,9 @@ env: jobs: fluent: name: Fluent - runs-on: public-ubuntu-latest-8-cores + runs-on: + group: pyansys-self-hosted + labels: [self-hosted, Linux, pyfluent] strategy: fail-fast: false matrix: From e20ea5c695496fb0c7204627f27b31ec518af9bb Mon Sep 17 00:00:00 2001 From: Roberto Pastor Muela <37798125+RobPasMue@users.noreply.github.com> Date: Wed, 18 Dec 2024 08:27:37 +0100 Subject: [PATCH 35/68] feat: use venv --- .github/workflows/fluent-mechanical.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/fluent-mechanical.yml b/.github/workflows/fluent-mechanical.yml index 4160cb35..e2c6c2fa 100644 --- a/.github/workflows/fluent-mechanical.yml +++ b/.github/workflows/fluent-mechanical.yml @@ -58,6 +58,8 @@ jobs: - name: Install dependencies run: | python -m pip install --upgrade pip + python -m venv .venv + source .venv/bin/activate pip install -r fluent-mechanical/requirements_${{ matrix.ansys-release }}.txt - name: Login to GitHub Container Registry @@ -74,6 +76,7 @@ jobs: env: FLUENT_IMAGE_TAG: v${{ matrix.ansys-release }}.0 run: | + source .venv/bin/activate python fluent-mechanical/wf_fm_01_fluent.py - name: Store the outputs @@ -116,6 +119,7 @@ jobs: FLUENT_IMAGE_TAG: v${{ matrix.ansys-release }}.0 BUILD_DOCS_SCRIPT: 'fluent-mechanical/wf_fm_01_fluent.py' run: | + source .venv/bin/activate cd doc find . -type f -exec sed -i 's|C:\\Users\\ansys\\actions-runner\\_work\\pyansys-workflows\\pyansys-workflows\\doc\\source\\examples\\fluent-mechanical\\images\\|./images/|g' {} + pip install -r requirements.txt From 4fcd4548bffbb803e701cb9b7d6dc1ba74e79a08 Mon Sep 17 00:00:00 2001 From: Roberto Pastor Muela <37798125+RobPasMue@users.noreply.github.com> Date: Wed, 18 Dec 2024 08:46:33 +0100 Subject: [PATCH 36/68] revert: usage of self-hosted runners --- .github/workflows/fluent-mechanical.yml | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/.github/workflows/fluent-mechanical.yml b/.github/workflows/fluent-mechanical.yml index e2c6c2fa..416c0caa 100644 --- a/.github/workflows/fluent-mechanical.yml +++ b/.github/workflows/fluent-mechanical.yml @@ -34,9 +34,7 @@ env: jobs: fluent: name: Fluent - runs-on: - group: pyansys-self-hosted - labels: [self-hosted, Linux, pyfluent] + runs-on: public-ubuntu-latest-8-cores strategy: fail-fast: false matrix: @@ -58,8 +56,6 @@ jobs: - name: Install dependencies run: | python -m pip install --upgrade pip - python -m venv .venv - source .venv/bin/activate pip install -r fluent-mechanical/requirements_${{ matrix.ansys-release }}.txt - name: Login to GitHub Container Registry @@ -76,7 +72,6 @@ jobs: env: FLUENT_IMAGE_TAG: v${{ matrix.ansys-release }}.0 run: | - source .venv/bin/activate python fluent-mechanical/wf_fm_01_fluent.py - name: Store the outputs @@ -84,7 +79,7 @@ jobs: with: name: fluent-mechanical-workflow-fluent-outputs-${{ matrix.ansys-release }} path: | - fluent-mechanical/outputs/htc_temp_mapping_LOW_TEMP.csv + fluent-mechanical/outputs/htc_temp_mapping_LOW_TEMP fluent-mechanical/outputs/htc_temp_mapping_MEDIUM_TEMP.csv fluent-mechanical/outputs/htc_temp_mapping_HIGH_TEMP.csv @@ -119,7 +114,6 @@ jobs: FLUENT_IMAGE_TAG: v${{ matrix.ansys-release }}.0 BUILD_DOCS_SCRIPT: 'fluent-mechanical/wf_fm_01_fluent.py' run: | - source .venv/bin/activate cd doc find . -type f -exec sed -i 's|C:\\Users\\ansys\\actions-runner\\_work\\pyansys-workflows\\pyansys-workflows\\doc\\source\\examples\\fluent-mechanical\\images\\|./images/|g' {} + pip install -r requirements.txt From 7a20c8ff6092045c11d70069dc1ff661812a6797 Mon Sep 17 00:00:00 2001 From: Roberto Pastor Muela <37798125+RobPasMue@users.noreply.github.com> Date: Wed, 18 Dec 2024 08:47:07 +0100 Subject: [PATCH 37/68] fix: typo --- .github/workflows/fluent-mechanical.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/fluent-mechanical.yml b/.github/workflows/fluent-mechanical.yml index 416c0caa..29be23d0 100644 --- a/.github/workflows/fluent-mechanical.yml +++ b/.github/workflows/fluent-mechanical.yml @@ -79,7 +79,7 @@ jobs: with: name: fluent-mechanical-workflow-fluent-outputs-${{ matrix.ansys-release }} path: | - fluent-mechanical/outputs/htc_temp_mapping_LOW_TEMP + fluent-mechanical/outputs/htc_temp_mapping_LOW_TEMP.csv fluent-mechanical/outputs/htc_temp_mapping_MEDIUM_TEMP.csv fluent-mechanical/outputs/htc_temp_mapping_HIGH_TEMP.csv From a2177602b5e9d2fc22131a0000bee66f4952bf25 Mon Sep 17 00:00:00 2001 From: dkunhamb Date: Thu, 2 Jan 2025 09:35:52 -0600 Subject: [PATCH 38/68] test only 242 --- .github/workflows/fluent-mechanical.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/fluent-mechanical.yml b/.github/workflows/fluent-mechanical.yml index 29be23d0..fa137d2c 100644 --- a/.github/workflows/fluent-mechanical.yml +++ b/.github/workflows/fluent-mechanical.yml @@ -38,7 +38,7 @@ jobs: strategy: fail-fast: false matrix: - ansys-release: [24.1, 24.2] + ansys-release: [24.2] # testing only steps: - name: Checkout code From ca503f3c0a4af39e28752b8122ac3d4d0f0d30f4 Mon Sep 17 00:00:00 2001 From: dkunhamb Date: Thu, 2 Jan 2025 10:50:05 -0600 Subject: [PATCH 39/68] update license --- LICENSE | 2 +- doc/source/conf.py | 2 +- fluent-mechanical/wf_fm_01_fluent.py | 2 +- fluent-mechanical/wf_fm_02_mechanical.py | 2 +- geometry-mechanical-dpf/wf_gmd_01_geometry.py | 2 +- geometry-mechanical-dpf/wf_gmd_02_mechanical.py | 2 +- geometry-mechanical-dpf/wf_gmd_03_dpf.py | 2 +- geometry-mesh-fluent/wf_gmf_01_geometry.py | 2 +- geometry-mesh-fluent/wf_gmf_02_fluent_meshing.py | 2 +- geometry-mesh-fluent/wf_gmf_03_fluent_solver.py | 2 +- geometry-mesh/wf_gm_01_geometry.py | 2 +- geometry-mesh/wf_gm_02_mesh.py | 2 +- 12 files changed, 12 insertions(+), 12 deletions(-) diff --git a/LICENSE b/LICENSE index 0add1578..860f5859 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2024 ANSYS, Inc. and/or its affiliates. +Copyright (c) 2024 - 2025 ANSYS, Inc. and/or its affiliates. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in diff --git a/doc/source/conf.py b/doc/source/conf.py index 25edd9e9..9f7896a8 100644 --- a/doc/source/conf.py +++ b/doc/source/conf.py @@ -1,4 +1,4 @@ -# Copyright (C) 2024 ANSYS, Inc. and/or its affiliates. +# Copyright (C) 2024 - 2025 ANSYS, Inc. and/or its affiliates. # SPDX-License-Identifier: MIT # # diff --git a/fluent-mechanical/wf_fm_01_fluent.py b/fluent-mechanical/wf_fm_01_fluent.py index 5fa73e20..e9304eab 100644 --- a/fluent-mechanical/wf_fm_01_fluent.py +++ b/fluent-mechanical/wf_fm_01_fluent.py @@ -1,4 +1,4 @@ -# Copyright (C) 2024 ANSYS, Inc. and/or its affiliates. +# Copyright (C) 2024 - 2025 ANSYS, Inc. and/or its affiliates. # SPDX-License-Identifier: MIT # # diff --git a/fluent-mechanical/wf_fm_02_mechanical.py b/fluent-mechanical/wf_fm_02_mechanical.py index 9ac6020d..7827edbf 100644 --- a/fluent-mechanical/wf_fm_02_mechanical.py +++ b/fluent-mechanical/wf_fm_02_mechanical.py @@ -1,4 +1,4 @@ -# Copyright (C) 2024 ANSYS, Inc. and/or its affiliates. +# Copyright (C) 2024 - 2025 ANSYS, Inc. and/or its affiliates. # SPDX-License-Identifier: MIT # # diff --git a/geometry-mechanical-dpf/wf_gmd_01_geometry.py b/geometry-mechanical-dpf/wf_gmd_01_geometry.py index c1952756..2da8f765 100644 --- a/geometry-mechanical-dpf/wf_gmd_01_geometry.py +++ b/geometry-mechanical-dpf/wf_gmd_01_geometry.py @@ -1,4 +1,4 @@ -# Copyright (C) 2024 ANSYS, Inc. and/or its affiliates. +# Copyright (C) 2024 - 2025 ANSYS, Inc. and/or its affiliates. # SPDX-License-Identifier: MIT # # diff --git a/geometry-mechanical-dpf/wf_gmd_02_mechanical.py b/geometry-mechanical-dpf/wf_gmd_02_mechanical.py index d11b3be4..8e5d418b 100644 --- a/geometry-mechanical-dpf/wf_gmd_02_mechanical.py +++ b/geometry-mechanical-dpf/wf_gmd_02_mechanical.py @@ -1,4 +1,4 @@ -# Copyright (C) 2024 ANSYS, Inc. and/or its affiliates. +# Copyright (C) 2024 - 2025 ANSYS, Inc. and/or its affiliates. # SPDX-License-Identifier: MIT # # diff --git a/geometry-mechanical-dpf/wf_gmd_03_dpf.py b/geometry-mechanical-dpf/wf_gmd_03_dpf.py index 7bfac6ed..4713e9cc 100644 --- a/geometry-mechanical-dpf/wf_gmd_03_dpf.py +++ b/geometry-mechanical-dpf/wf_gmd_03_dpf.py @@ -1,4 +1,4 @@ -# Copyright (C) 2024 ANSYS, Inc. and/or its affiliates. +# Copyright (C) 2024 - 2025 ANSYS, Inc. and/or its affiliates. # SPDX-License-Identifier: MIT # # diff --git a/geometry-mesh-fluent/wf_gmf_01_geometry.py b/geometry-mesh-fluent/wf_gmf_01_geometry.py index f729aba9..6a079988 100644 --- a/geometry-mesh-fluent/wf_gmf_01_geometry.py +++ b/geometry-mesh-fluent/wf_gmf_01_geometry.py @@ -1,4 +1,4 @@ -# Copyright (C) 2024 ANSYS, Inc. and/or its affiliates. +# Copyright (C) 2024 - 2025 ANSYS, Inc. and/or its affiliates. # SPDX-License-Identifier: MIT # # diff --git a/geometry-mesh-fluent/wf_gmf_02_fluent_meshing.py b/geometry-mesh-fluent/wf_gmf_02_fluent_meshing.py index fe9f2ae7..b096c9a3 100644 --- a/geometry-mesh-fluent/wf_gmf_02_fluent_meshing.py +++ b/geometry-mesh-fluent/wf_gmf_02_fluent_meshing.py @@ -1,4 +1,4 @@ -# Copyright (C) 2024 ANSYS, Inc. and/or its affiliates. +# Copyright (C) 2024 - 2025 ANSYS, Inc. and/or its affiliates. # SPDX-License-Identifier: MIT # # diff --git a/geometry-mesh-fluent/wf_gmf_03_fluent_solver.py b/geometry-mesh-fluent/wf_gmf_03_fluent_solver.py index a498a494..36fa54bf 100644 --- a/geometry-mesh-fluent/wf_gmf_03_fluent_solver.py +++ b/geometry-mesh-fluent/wf_gmf_03_fluent_solver.py @@ -1,4 +1,4 @@ -# Copyright (C) 2024 ANSYS, Inc. and/or its affiliates. +# Copyright (C) 2024 - 2025 ANSYS, Inc. and/or its affiliates. # SPDX-License-Identifier: MIT # # diff --git a/geometry-mesh/wf_gm_01_geometry.py b/geometry-mesh/wf_gm_01_geometry.py index 9a731802..efc4c49d 100644 --- a/geometry-mesh/wf_gm_01_geometry.py +++ b/geometry-mesh/wf_gm_01_geometry.py @@ -1,4 +1,4 @@ -# Copyright (C) 2024 ANSYS, Inc. and/or its affiliates. +# Copyright (C) 2024 - 2025 ANSYS, Inc. and/or its affiliates. # SPDX-License-Identifier: MIT # # diff --git a/geometry-mesh/wf_gm_02_mesh.py b/geometry-mesh/wf_gm_02_mesh.py index e8dfe137..38995ea4 100644 --- a/geometry-mesh/wf_gm_02_mesh.py +++ b/geometry-mesh/wf_gm_02_mesh.py @@ -1,4 +1,4 @@ -# Copyright (C) 2024 ANSYS, Inc. and/or its affiliates. +# Copyright (C) 2024 - 2025 ANSYS, Inc. and/or its affiliates. # SPDX-License-Identifier: MIT # # From 8e7078498fd0bb7ce3eb4cfbe50f6357b57a3b3a Mon Sep 17 00:00:00 2001 From: dkunhamb Date: Thu, 2 Jan 2025 11:18:35 -0600 Subject: [PATCH 40/68] test 242 only --- .github/workflows/fluent-mechanical.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/fluent-mechanical.yml b/.github/workflows/fluent-mechanical.yml index fa137d2c..5414fff3 100644 --- a/.github/workflows/fluent-mechanical.yml +++ b/.github/workflows/fluent-mechanical.yml @@ -136,7 +136,7 @@ jobs: strategy: fail-fast: false matrix: - ansys-release: [24.1, 24.2] + ansys-release: [24.2] # testing only steps: - name: Checkout code From fb7cde17620c0303ff610507bd3e75db6ad946b5 Mon Sep 17 00:00:00 2001 From: dkunhamb Date: Thu, 2 Jan 2025 12:15:34 -0600 Subject: [PATCH 41/68] remove version --- fluent-mechanical/wf_fm_02_mechanical.py | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/fluent-mechanical/wf_fm_02_mechanical.py b/fluent-mechanical/wf_fm_02_mechanical.py index 7827edbf..9ab30636 100644 --- a/fluent-mechanical/wf_fm_02_mechanical.py +++ b/fluent-mechanical/wf_fm_02_mechanical.py @@ -38,19 +38,6 @@ from matplotlib import image as mpimg from matplotlib import pyplot as plt -############################################################################### -# Preparing the environment -# ------------------------- -# This section is only necessary for workflow runs and docs generation. It checks -# the environment variables to determine which image to use for the mechanical service. -# If you are running this script outside of a workflow, you can ignore this section. -# - -version = None -if "ANSYS_MECHANICAL_RELEASE" in os.environ: - image_tag = os.environ["ANSYS_MECHANICAL_RELEASE"] - version = int(image_tag.replace(".", "")) - # sphinx_gallery_start_ignore # Check if the __file__ variable is defined. If not, set it. # This is a workaround to run the script in Sphinx-Gallery. From 016fa8f59e802741a645925eea5e2f18fdaecff9 Mon Sep 17 00:00:00 2001 From: dkunhamb Date: Thu, 2 Jan 2025 12:17:29 -0600 Subject: [PATCH 42/68] update run script action --- .github/workflows/fluent-mechanical.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/fluent-mechanical.yml b/.github/workflows/fluent-mechanical.yml index 5414fff3..9f432c22 100644 --- a/.github/workflows/fluent-mechanical.yml +++ b/.github/workflows/fluent-mechanical.yml @@ -186,7 +186,7 @@ jobs: ANSYS_MECHANICAL_RELEASE: ${{ matrix.ansys-release }} run: | . .venv/bin/activate - xvfb-run python fluent-mechanical + xvfb-run python fluent-mechanical/wf_fm_02_mechanical.py - name: Store the outputs uses: actions/upload-artifact@v4 From 6fd7049fc35cff808fd98040fd1f53c9494b062f Mon Sep 17 00:00:00 2001 From: dkunhamb Date: Thu, 2 Jan 2025 14:09:40 -0600 Subject: [PATCH 43/68] update cicd --- .github/workflows/fluent-mechanical.yml | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/.github/workflows/fluent-mechanical.yml b/.github/workflows/fluent-mechanical.yml index 9f432c22..49d70b45 100644 --- a/.github/workflows/fluent-mechanical.yml +++ b/.github/workflows/fluent-mechanical.yml @@ -26,6 +26,8 @@ env: MAIN_PYTHON_VERSION: '3.12' FLUENT_DOCKER_IMAGE: 'ghcr.io/ansys/pyfluent' MECHANICAL_DOCKER_IMAGE: 'ghcr.io/ansys/mechanical' + DOCKER_MECH_CONTAINER_NAME: mechanical + PYMECHANICAL_PORT: 10000 ANSYSLMD_LICENSE_FILE: ${{ format('1055@{0}', secrets.LICENSE_SERVER )}} PYANSYS_WORKFLOWS_CI: true ANSYS_RELEASE_FOR_DOCS: 24.2 @@ -171,9 +173,13 @@ jobs: username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} - - name: Download (if needed) and run Mechanical container + - name: Download (if needed) launch, and validate Mechanical service + env: + LICENSE_SERVER: ${{ secrets.LICENSE_SERVER }} run: | docker pull ${{ env.MECHANICAL_DOCKER_IMAGE }} + docker run --restart always --name ${{ env.DOCKER_MECH_CONTAINER_NAME }} -e ANSYSLMD_LICENSE_FILE=1055@${{ env.LICENSE_SERVER }} -p ${{ env.PYMECHANICAL_PORT }}:10000 ${{ env.MECHANICAL_DOCKER_IMAGE }} > log.txt & + grep -q 'WB Initialize Done' <(timeout 60 tail -f log.txt) - name: Check out the fluent outputs uses: actions/download-artifact@v4 From 2b5ccc11b152e59ce54b821759b2afd954fe7148 Mon Sep 17 00:00:00 2001 From: dkunhamb Date: Wed, 8 Jan 2025 10:53:06 -0600 Subject: [PATCH 44/68] update processor count 2 --- .github/workflows/fluent-mechanical.yml | 4 ++-- fluent-mechanical/wf_fm_01_fluent.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/fluent-mechanical.yml b/.github/workflows/fluent-mechanical.yml index 49d70b45..565ad850 100644 --- a/.github/workflows/fluent-mechanical.yml +++ b/.github/workflows/fluent-mechanical.yml @@ -40,7 +40,7 @@ jobs: strategy: fail-fast: false matrix: - ansys-release: [24.2] # testing only + ansys-release: [24.1, 24.2] steps: - name: Checkout code @@ -138,7 +138,7 @@ jobs: strategy: fail-fast: false matrix: - ansys-release: [24.2] # testing only + ansys-release: [24.1, 24.2] steps: - name: Checkout code diff --git a/fluent-mechanical/wf_fm_01_fluent.py b/fluent-mechanical/wf_fm_01_fluent.py index e9304eab..81363bd4 100644 --- a/fluent-mechanical/wf_fm_01_fluent.py +++ b/fluent-mechanical/wf_fm_01_fluent.py @@ -128,7 +128,7 @@ } solver = pyfluent.launch_fluent( precision="double", - processor_count=4, + processor_count=2, mode="solver", cwd="/mnt/pyfluent", container_dict=container_dict, @@ -144,7 +144,7 @@ else: solver = pyfluent.launch_fluent( precision="double", - processor_count=4, + processor_count=2, mode="solver", cwd=WORKING_DIR, ) From 23a301a0a32103a65963541d478757a8ed0ef2a3 Mon Sep 17 00:00:00 2001 From: Raphael Luciano Date: Wed, 8 Jan 2025 12:37:18 -0500 Subject: [PATCH 45/68] making path host-system independent container is always Linux, host may be Windows or Linux, so os.path is not appropriate as it won't work properly when host is Windows --- fluent-mechanical/wf_fm_01_fluent.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/fluent-mechanical/wf_fm_01_fluent.py b/fluent-mechanical/wf_fm_01_fluent.py index 81363bd4..9bf8a555 100644 --- a/fluent-mechanical/wf_fm_01_fluent.py +++ b/fluent-mechanical/wf_fm_01_fluent.py @@ -78,6 +78,7 @@ # examples. import os +from pathlib import PurePosixPath import ansys.fluent.core as pyfluent from ansys.fluent.core import examples @@ -140,7 +141,8 @@ WORKING_DIR = "/mnt/pyfluent" # Fix the path to the mesh file - import_mesh_file = os.path.join(WORKING_DIR, "exhaust_manifold_conf.msh.h5") + import_mesh_file = PurePosixPath(WORKING_DIR) / "exhaust_manifold_conf.msh.h5" + print(f"\nImport mesh path for container: {import_mesh_file}\n") else: solver = pyfluent.launch_fluent( precision="double", From a72cd6b2db1bcbd5b7cd45d6d53f4183dd709323 Mon Sep 17 00:00:00 2001 From: Raphael Luciano Date: Wed, 8 Jan 2025 12:38:35 -0500 Subject: [PATCH 46/68] cleaning up unused and unnecessary arguments --- fluent-mechanical/wf_fm_01_fluent.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/fluent-mechanical/wf_fm_01_fluent.py b/fluent-mechanical/wf_fm_01_fluent.py index 9bf8a555..8682faf7 100644 --- a/fluent-mechanical/wf_fm_01_fluent.py +++ b/fluent-mechanical/wf_fm_01_fluent.py @@ -131,11 +131,7 @@ precision="double", processor_count=2, mode="solver", - cwd="/mnt/pyfluent", container_dict=container_dict, - start_container=True, - ui_mode="no_gui_or_graphics", - cleanup_on_exit=False, ) # From here on, the working directory is the mounted directory WORKING_DIR = "/mnt/pyfluent" From 6aae41d9183e2211fba0233eb5963f4921852701 Mon Sep 17 00:00:00 2001 From: Raphael Luciano Date: Wed, 8 Jan 2025 12:41:15 -0500 Subject: [PATCH 47/68] 2 processors didn't work, reverting back to 4 --- fluent-mechanical/wf_fm_01_fluent.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/fluent-mechanical/wf_fm_01_fluent.py b/fluent-mechanical/wf_fm_01_fluent.py index 8682faf7..6645f76d 100644 --- a/fluent-mechanical/wf_fm_01_fluent.py +++ b/fluent-mechanical/wf_fm_01_fluent.py @@ -129,7 +129,7 @@ } solver = pyfluent.launch_fluent( precision="double", - processor_count=2, + processor_count=4, mode="solver", container_dict=container_dict, ) @@ -142,7 +142,7 @@ else: solver = pyfluent.launch_fluent( precision="double", - processor_count=2, + processor_count=4, mode="solver", cwd=WORKING_DIR, ) From 0c59dbd5ac0c4652641f2a48336e6e12dba292d1 Mon Sep 17 00:00:00 2001 From: Raphael Luciano Date: Wed, 8 Jan 2025 13:15:49 -0500 Subject: [PATCH 48/68] suggestion: removing unnecessary container config dict specification this lets PyFluent figure this out, which makes it run without change in different systems (i.e. mine) --- fluent-mechanical/wf_fm_01_fluent.py | 2 -- geometry-mesh-fluent/wf_gmf_02_fluent_meshing.py | 2 -- geometry-mesh-fluent/wf_gmf_03_fluent_solver.py | 2 -- 3 files changed, 6 deletions(-) diff --git a/fluent-mechanical/wf_fm_01_fluent.py b/fluent-mechanical/wf_fm_01_fluent.py index 6645f76d..2dc5cdb2 100644 --- a/fluent-mechanical/wf_fm_01_fluent.py +++ b/fluent-mechanical/wf_fm_01_fluent.py @@ -122,9 +122,7 @@ if os.getenv("PYANSYS_WORKFLOWS_CI") == "true": print("Configuring Fluent for CI") container_dict = { - "fluent_image": f"{os.environ['FLUENT_DOCKER_IMAGE']}:{os.environ['FLUENT_IMAGE_TAG']}", "mount_source": WORKING_DIR, - "license_server": os.environ["ANSYSLMD_LICENSE_FILE"], "timeout": 300, } solver = pyfluent.launch_fluent( diff --git a/geometry-mesh-fluent/wf_gmf_02_fluent_meshing.py b/geometry-mesh-fluent/wf_gmf_02_fluent_meshing.py index b096c9a3..6fa5c996 100644 --- a/geometry-mesh-fluent/wf_gmf_02_fluent_meshing.py +++ b/geometry-mesh-fluent/wf_gmf_02_fluent_meshing.py @@ -195,9 +195,7 @@ def generate_mesh( if os.getenv("PYANSYS_WORKFLOWS_CI") == "true": container_dict = { - "fluent_image": f"{os.environ['FLUENT_DOCKER_IMAGE']}:{os.environ['FLUENT_IMAGE_TAG']}", "host_mount_path": DATA_DIR, - "license_server": os.environ["ANSYSLMD_LICENSE_FILE"], "timeout": 300, } # https://fluent.docs.pyansys.com/version/stable/api/general/launcher/fluent_container.html diff --git a/geometry-mesh-fluent/wf_gmf_03_fluent_solver.py b/geometry-mesh-fluent/wf_gmf_03_fluent_solver.py index 36fa54bf..9edbe457 100644 --- a/geometry-mesh-fluent/wf_gmf_03_fluent_solver.py +++ b/geometry-mesh-fluent/wf_gmf_03_fluent_solver.py @@ -246,9 +246,7 @@ def solve_airfoil_flow( if os.getenv("PYANSYS_WORKFLOWS_CI") == "true": container_dict = { - "fluent_image": f"{os.environ['FLUENT_DOCKER_IMAGE']}:{os.environ['FLUENT_IMAGE_TAG']}", "host_mount_path": DATA_DIR, - "license_server": os.environ["ANSYSLMD_LICENSE_FILE"], "timeout": 300, } # https://fluent.docs.pyansys.com/version/stable/api/general/launcher/fluent_container.html From ea38b03e49eb6ffad34f543f938e4d25652cb91d Mon Sep 17 00:00:00 2001 From: Dipin <26918585+dipinknair@users.noreply.github.com> Date: Wed, 8 Jan 2025 12:18:05 -0600 Subject: [PATCH 49/68] Update fluent-mechanical/wf_fm_02_mechanical.py --- fluent-mechanical/wf_fm_02_mechanical.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fluent-mechanical/wf_fm_02_mechanical.py b/fluent-mechanical/wf_fm_02_mechanical.py index 9ab30636..52625ae0 100644 --- a/fluent-mechanical/wf_fm_02_mechanical.py +++ b/fluent-mechanical/wf_fm_02_mechanical.py @@ -63,7 +63,7 @@ # Start a PyMechanical app # ------------------------ # -mechanical = launch_mechanical(batch=False, cleanup_on_exit=False) +mechanical = launch_mechanical(batch=True, cleanup_on_exit=False) print(mechanical) From a4876b0419837e8f65bff01875d9b0cd2b89c676 Mon Sep 17 00:00:00 2001 From: dkunhamb Date: Wed, 8 Jan 2025 13:20:24 -0600 Subject: [PATCH 50/68] set pymechanical start instance false --- .github/workflows/fluent-mechanical.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/fluent-mechanical.yml b/.github/workflows/fluent-mechanical.yml index 565ad850..c1835078 100644 --- a/.github/workflows/fluent-mechanical.yml +++ b/.github/workflows/fluent-mechanical.yml @@ -32,6 +32,7 @@ env: PYANSYS_WORKFLOWS_CI: true ANSYS_RELEASE_FOR_DOCS: 24.2 RUN_DOC_BUILD: false + PYMECHANICAL_START_INSTANCE: false jobs: fluent: From 9e160b5d895aa3cde8915fbba58e847c8a2e714b Mon Sep 17 00:00:00 2001 From: dkunhamb Date: Mon, 13 Jan 2025 15:52:01 -0600 Subject: [PATCH 51/68] test coarse mesh --- fluent-mechanical/wf_fm_02_mechanical.py | 25 +++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/fluent-mechanical/wf_fm_02_mechanical.py b/fluent-mechanical/wf_fm_02_mechanical.py index 52625ae0..3e83d105 100644 --- a/fluent-mechanical/wf_fm_02_mechanical.py +++ b/fluent-mechanical/wf_fm_02_mechanical.py @@ -228,17 +228,20 @@ def display_image(image_name): mechanical.run_python_script( """ MESH = Model.Mesh -MESH.ElementSize = Quantity(0.004, "m") -MESH.UseAdaptiveSizing = False -MESH.MaximumSize = Quantity(0.004, "m") -MESH.ShapeChecking = 0 -body_sizing = MESH.AddSizing() -selection = NS_GRP.Children[5] -body_sizing.Location = selection -body_sizing.ElementSize = Quantity(4e-3, "m") -#body_sizing.CaptureCurvature = True -#body_sizing.CurvatureNormalAngle = Quantity(0.31, "rad") -#body_sizing.LocalMinimumSize = Quantity(0.00025, "m") +# MESH.ElementSize = Quantity(0.004, "m") +# MESH.UseAdaptiveSizing = False +# MESH.MaximumSize = Quantity(0.004, "m") +# MESH.ShapeChecking = 0 +# body_sizing = MESH.AddSizing() +# selection = NS_GRP.Children[5] +# body_sizing.Location = selection +# body_sizing.ElementSize = Quantity(4e-3, "m") +# #body_sizing.CaptureCurvature = True +# #body_sizing.CurvatureNormalAngle = Quantity(0.31, "rad") +# #body_sizing.LocalMinimumSize = Quantity(0.00025, "m") + +MESH.UseAdaptiveSizing = True +MESH.TransitionOption = 1 Tree.Activate([MESH]) MESH.GenerateMesh() From 70bcfe64aca4d1bfb1e1ddbf87b3fd965a1d17f7 Mon Sep 17 00:00:00 2001 From: dkunhamb Date: Tue, 14 Jan 2025 08:17:12 -0600 Subject: [PATCH 52/68] update mechancial image version --- .github/workflows/fluent-mechanical.yml | 467 ++++++++++++------------ 1 file changed, 234 insertions(+), 233 deletions(-) diff --git a/.github/workflows/fluent-mechanical.yml b/.github/workflows/fluent-mechanical.yml index c1835078..b8e95643 100644 --- a/.github/workflows/fluent-mechanical.yml +++ b/.github/workflows/fluent-mechanical.yml @@ -1,234 +1,235 @@ -name: Fluent - Mechanical Exhaust Manifold Workflow - -on: - workflow_dispatch: - inputs: - doc-build: - required: false - default: false - type: boolean - description: 'Whether to build the documentation' - workflow_call: - inputs: - doc-build: - required: false - default: false - type: boolean - description: 'Whether to build the documentation' - push: - branches: - - main - pull_request: - paths: - - 'fluent-mechanical/**' - -env: - MAIN_PYTHON_VERSION: '3.12' - FLUENT_DOCKER_IMAGE: 'ghcr.io/ansys/pyfluent' - MECHANICAL_DOCKER_IMAGE: 'ghcr.io/ansys/mechanical' - DOCKER_MECH_CONTAINER_NAME: mechanical - PYMECHANICAL_PORT: 10000 - ANSYSLMD_LICENSE_FILE: ${{ format('1055@{0}', secrets.LICENSE_SERVER )}} - PYANSYS_WORKFLOWS_CI: true - ANSYS_RELEASE_FOR_DOCS: 24.2 - RUN_DOC_BUILD: false - PYMECHANICAL_START_INSTANCE: false - -jobs: - fluent: - name: Fluent - runs-on: public-ubuntu-latest-8-cores - strategy: - fail-fast: false - matrix: - ansys-release: [24.1, 24.2] - steps: - - - name: Checkout code - uses: actions/checkout@v4 - with: - sparse-checkout: | - fluent-mechanical - doc - - - name: Set up Python ${{ env.MAIN_PYTHON_VERSION }} - uses: actions/setup-python@v5 - with: - python-version: ${{ env.MAIN_PYTHON_VERSION }} - - - name: Install dependencies - run: | - python -m pip install --upgrade pip - pip install -r fluent-mechanical/requirements_${{ matrix.ansys-release }}.txt - - - name: Login to GitHub Container Registry - uses: docker/login-action@v3 - with: - registry: ghcr.io - username: ${{ github.actor }} - password: ${{ secrets.GITHUB_TOKEN }} - - - name: Download Fluent service container - run: docker pull ${{ env.FLUENT_DOCKER_IMAGE }}:v${{ matrix.ansys-release }}.0 - - - name: Run the Fluent script - env: - FLUENT_IMAGE_TAG: v${{ matrix.ansys-release }}.0 - run: | - python fluent-mechanical/wf_fm_01_fluent.py - - - name: Store the outputs - uses: actions/upload-artifact@v4 - with: - name: fluent-mechanical-workflow-fluent-outputs-${{ matrix.ansys-release }} - path: | - fluent-mechanical/outputs/htc_temp_mapping_LOW_TEMP.csv - fluent-mechanical/outputs/htc_temp_mapping_MEDIUM_TEMP.csv - fluent-mechanical/outputs/htc_temp_mapping_HIGH_TEMP.csv - - - name: Stop all containers (if any) - run: | - if [ -n "$(docker ps -a -q)" ]; then - docker rm -f $(docker ps -a -q) - fi - - - name: (DOCS) Check if docs should be built - if: (github.event_name == 'workflow_dispatch' || github.event_name == 'schedule') && inputs.doc-build - run: | - echo "Requested to build docs..." - if [ "${{ matrix.ansys-release }}" == "${{ env.ANSYS_RELEASE_FOR_DOCS }}" ]; then - echo "Building docs" - echo "RUN_DOC_BUILD=true" >> $GITHUB_ENV - else - echo "Not building docs - since not primary release" - echo "RUN_DOC_BUILD=false" >> $GITHUB_ENV - fi - - - name: (DOCS) Download the docs artifacts - uses: actions/download-artifact@v4 - if: ${{ env.RUN_DOC_BUILD == 'true' }} - with: - name: fluent-mechanical-docs-stage-fluent - path: doc - - - name: (DOCS) Build the documentation (only on ${{ env.ANSYS_RELEASE_FOR_DOCS}}) - if: ${{ env.RUN_DOC_BUILD == 'true' }} - env: - FLUENT_IMAGE_TAG: v${{ matrix.ansys-release }}.0 - BUILD_DOCS_SCRIPT: 'fluent-mechanical/wf_fm_01_fluent.py' - run: | - cd doc - find . -type f -exec sed -i 's|C:\\Users\\ansys\\actions-runner\\_work\\pyansys-workflows\\pyansys-workflows\\doc\\source\\examples\\fluent-mechanical\\images\\|./images/|g' {} + - pip install -r requirements.txt - make html - - - name: (DOCS) Upload docs artifacts - if: ${{ env.RUN_DOC_BUILD == 'true' }} - uses: actions/upload-artifact@v4 - with: - name: fluent-mechanical-docs-stage-fluent - path: | - doc/_build/ - doc/source/examples/fluent-mechanical/ - overwrite: true - - mechanical: - name: Mechanical - runs-on: [public-ubuntu-latest-8-cores] - needs: fluent - strategy: - fail-fast: false - matrix: - ansys-release: [24.1, 24.2] - steps: - - - name: Checkout code - uses: actions/checkout@v4 - with: - sparse-checkout: | - fluent-mechanical - doc - - - name: Set up Python ${{ env.MAIN_PYTHON_VERSION }} - uses: actions/setup-python@v5 - with: - python-version: ${{ env.MAIN_PYTHON_VERSION }} - - - name: Install system dependencies - run: | - sudo apt-get update - sudo apt-get install -y nodejs npm graphviz - npm install -g @mermaid-js/mermaid-cli - - - name: Install dependencies - run: | - python -m pip install --upgrade pip - python -m venv .venv - . .venv/bin/activate - pip install -r fluent-mechanical/requirements_${{ matrix.ansys-release }}.txt - - - name: Login to GitHub Container Registry - uses: docker/login-action@v3 - with: - registry: ghcr.io - username: ${{ github.actor }} - password: ${{ secrets.GITHUB_TOKEN }} - - - name: Download (if needed) launch, and validate Mechanical service - env: - LICENSE_SERVER: ${{ secrets.LICENSE_SERVER }} - run: | - docker pull ${{ env.MECHANICAL_DOCKER_IMAGE }} - docker run --restart always --name ${{ env.DOCKER_MECH_CONTAINER_NAME }} -e ANSYSLMD_LICENSE_FILE=1055@${{ env.LICENSE_SERVER }} -p ${{ env.PYMECHANICAL_PORT }}:10000 ${{ env.MECHANICAL_DOCKER_IMAGE }} > log.txt & - grep -q 'WB Initialize Done' <(timeout 60 tail -f log.txt) - - - name: Check out the fluent outputs - uses: actions/download-artifact@v4 - with: - name: fluent-mechanical-workflow-fluent-outputs-${{ matrix.ansys-release }} - path: fluent-mechanical/outputs - - - name: Run the PyMechanical script - env: - ANSYS_MECHANICAL_RELEASE: ${{ matrix.ansys-release }} - run: | - . .venv/bin/activate - xvfb-run python fluent-mechanical/wf_fm_02_mechanical.py - - - name: Store the outputs - uses: actions/upload-artifact@v4 - with: - name: fluent-mechanical-workflow-mechanical-outputs-${{ matrix.ansys-release }} - path: fluent-mechanical/outputs - - - name: (DOCS) Check if docs should be built - if: (github.event_name == 'workflow_dispatch' || github.event_name == 'schedule') && inputs.doc-build - run: | - echo "Requested to build docs..." - if [ "${{ matrix.ansys-release }}" = "${{ env.ANSYS_RELEASE_FOR_DOCS }}" ]; then - echo "Building docs" - echo "RUN_DOC_BUILD=true" >> $GITHUB_ENV - else - echo "Not building docs - since not primary release" - echo "RUN_DOC_BUILD=false" >> $GITHUB_ENV - fi - - - name: (DOCS) Build the documentation (only on ${{ env.ANSYS_RELEASE_FOR_DOCS }}) - if: ${{ env.RUN_DOC_BUILD == 'true' }} - env: - ANSYS_MECHANICAL_RELEASE: ${{ matrix.ansys-release }} - BUILD_DOCS_SCRIPT: 'geometry-mechanical-dpf/wf_gmd_02_mechanical.py' - run: | - . .venv/bin/activate - find . -type f -exec sed -i 's|C:\\Users\\ansys\\actions-runner\\_work\\pyansys-workflows\\pyansys-workflows\\doc\\source\\examples\\fluent-mechanical\\images\\|./images/|g' {} + - pip install -r ./doc/requirements.txt - xvfb-run make -C doc html - - - name: (DOCS) Upload docs artifacts - if: ${{ env.RUN_DOC_BUILD == 'true' }} - uses: actions/upload-artifact@v4 - with: - name: fluent-mechanical-docs-stage-mechanical - path: | - doc/_build/ +name: Fluent - Mechanical Exhaust Manifold Workflow + +on: + workflow_dispatch: + inputs: + doc-build: + required: false + default: false + type: boolean + description: 'Whether to build the documentation' + workflow_call: + inputs: + doc-build: + required: false + default: false + type: boolean + description: 'Whether to build the documentation' + push: + branches: + - main + pull_request: + paths: + - 'fluent-mechanical/**' + +env: + MAIN_PYTHON_VERSION: '3.12' + FLUENT_DOCKER_IMAGE: 'ghcr.io/ansys/pyfluent' + MECHANICAL_DOCKER_IMAGE: 'ghcr.io/ansys/mechanical' + DOCKER_MECH_CONTAINER_NAME: mechanical + PYMECHANICAL_PORT: 10000 + ANSYSLMD_LICENSE_FILE: ${{ format('1055@{0}', secrets.LICENSE_SERVER )}} + PYANSYS_WORKFLOWS_CI: true + ANSYS_RELEASE_FOR_DOCS: 24.2 + RUN_DOC_BUILD: false + PYMECHANICAL_START_INSTANCE: false + +jobs: + fluent: + name: Fluent + runs-on: public-ubuntu-latest-8-cores + strategy: + fail-fast: false + matrix: + ansys-release: [24.1, 24.2] + steps: + + - name: Checkout code + uses: actions/checkout@v4 + with: + sparse-checkout: | + fluent-mechanical + doc + + - name: Set up Python ${{ env.MAIN_PYTHON_VERSION }} + uses: actions/setup-python@v5 + with: + python-version: ${{ env.MAIN_PYTHON_VERSION }} + + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install -r fluent-mechanical/requirements_${{ matrix.ansys-release }}.txt + + - name: Login to GitHub Container Registry + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Download Fluent service container + run: docker pull ${{ env.FLUENT_DOCKER_IMAGE }}:v${{ matrix.ansys-release }}.0 + + - name: Run the Fluent script + env: + FLUENT_IMAGE_TAG: v${{ matrix.ansys-release }}.0 + run: | + python fluent-mechanical/wf_fm_01_fluent.py + + - name: Store the outputs + uses: actions/upload-artifact@v4 + with: + name: fluent-mechanical-workflow-fluent-outputs-${{ matrix.ansys-release }} + path: | + fluent-mechanical/outputs/htc_temp_mapping_LOW_TEMP.csv + fluent-mechanical/outputs/htc_temp_mapping_MEDIUM_TEMP.csv + fluent-mechanical/outputs/htc_temp_mapping_HIGH_TEMP.csv + + - name: Stop all containers (if any) + run: | + if [ -n "$(docker ps -a -q)" ]; then + docker rm -f $(docker ps -a -q) + fi + + - name: (DOCS) Check if docs should be built + if: (github.event_name == 'workflow_dispatch' || github.event_name == 'schedule') && inputs.doc-build + run: | + echo "Requested to build docs..." + if [ "${{ matrix.ansys-release }}" == "${{ env.ANSYS_RELEASE_FOR_DOCS }}" ]; then + echo "Building docs" + echo "RUN_DOC_BUILD=true" >> $GITHUB_ENV + else + echo "Not building docs - since not primary release" + echo "RUN_DOC_BUILD=false" >> $GITHUB_ENV + fi + + - name: (DOCS) Download the docs artifacts + uses: actions/download-artifact@v4 + if: ${{ env.RUN_DOC_BUILD == 'true' }} + with: + name: fluent-mechanical-docs-stage-fluent + path: doc + + - name: (DOCS) Build the documentation (only on ${{ env.ANSYS_RELEASE_FOR_DOCS}}) + if: ${{ env.RUN_DOC_BUILD == 'true' }} + env: + FLUENT_IMAGE_TAG: v${{ matrix.ansys-release }}.0 + BUILD_DOCS_SCRIPT: 'fluent-mechanical/wf_fm_01_fluent.py' + run: | + cd doc + find . -type f -exec sed -i 's|C:\\Users\\ansys\\actions-runner\\_work\\pyansys-workflows\\pyansys-workflows\\doc\\source\\examples\\fluent-mechanical\\images\\|./images/|g' {} + + pip install -r requirements.txt + make html + + - name: (DOCS) Upload docs artifacts + if: ${{ env.RUN_DOC_BUILD == 'true' }} + uses: actions/upload-artifact@v4 + with: + name: fluent-mechanical-docs-stage-fluent + path: | + doc/_build/ + doc/source/examples/fluent-mechanical/ + overwrite: true + + mechanical: + name: Mechanical + runs-on: [public-ubuntu-latest-8-cores] + needs: fluent + strategy: + fail-fast: false + matrix: + ansys-release: [24.1, 24.2] + steps: + + - name: Checkout code + uses: actions/checkout@v4 + with: + sparse-checkout: | + fluent-mechanical + doc + + - name: Set up Python ${{ env.MAIN_PYTHON_VERSION }} + uses: actions/setup-python@v5 + with: + python-version: ${{ env.MAIN_PYTHON_VERSION }} + + - name: Install system dependencies + run: | + sudo apt-get update + sudo apt-get install -y nodejs npm graphviz + npm install -g @mermaid-js/mermaid-cli + + - name: Install dependencies + run: | + python -m pip install --upgrade pip + python -m venv .venv + . .venv/bin/activate + pip install -r fluent-mechanical/requirements_${{ matrix.ansys-release }}.txt + + - name: Login to GitHub Container Registry + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Download (if needed) launch, and validate Mechanical service + env: + LICENSE_SERVER: ${{ secrets.LICENSE_SERVER }} + MECHANICAL_IMAGE: ${{ env.MECHANICAL_DOCKER_IMAGE }}:${{ matrix.ansys-release }}.0 + run: | + docker pull ${{ env.MECHANICAL_IMAGE }} + docker run --restart always --name ${{ env.DOCKER_MECH_CONTAINER_NAME }} -e ANSYSLMD_LICENSE_FILE=1055@${{ env.LICENSE_SERVER }} -p ${{ env.PYMECHANICAL_PORT }}:10000 ${{ env.MECHANICAL_IMAGE }} > log.txt & + grep -q 'WB Initialize Done' <(timeout 60 tail -f log.txt) + + - name: Check out the fluent outputs + uses: actions/download-artifact@v4 + with: + name: fluent-mechanical-workflow-fluent-outputs-${{ matrix.ansys-release }} + path: fluent-mechanical/outputs + + - name: Run the PyMechanical script + env: + ANSYS_MECHANICAL_RELEASE: ${{ matrix.ansys-release }} + run: | + . .venv/bin/activate + xvfb-run python fluent-mechanical/wf_fm_02_mechanical.py + + - name: Store the outputs + uses: actions/upload-artifact@v4 + with: + name: fluent-mechanical-workflow-mechanical-outputs-${{ matrix.ansys-release }} + path: fluent-mechanical/outputs + + - name: (DOCS) Check if docs should be built + if: (github.event_name == 'workflow_dispatch' || github.event_name == 'schedule') && inputs.doc-build + run: | + echo "Requested to build docs..." + if [ "${{ matrix.ansys-release }}" = "${{ env.ANSYS_RELEASE_FOR_DOCS }}" ]; then + echo "Building docs" + echo "RUN_DOC_BUILD=true" >> $GITHUB_ENV + else + echo "Not building docs - since not primary release" + echo "RUN_DOC_BUILD=false" >> $GITHUB_ENV + fi + + - name: (DOCS) Build the documentation (only on ${{ env.ANSYS_RELEASE_FOR_DOCS }}) + if: ${{ env.RUN_DOC_BUILD == 'true' }} + env: + ANSYS_MECHANICAL_RELEASE: ${{ matrix.ansys-release }} + BUILD_DOCS_SCRIPT: 'geometry-mechanical-dpf/wf_gmd_02_mechanical.py' + run: | + . .venv/bin/activate + find . -type f -exec sed -i 's|C:\\Users\\ansys\\actions-runner\\_work\\pyansys-workflows\\pyansys-workflows\\doc\\source\\examples\\fluent-mechanical\\images\\|./images/|g' {} + + pip install -r ./doc/requirements.txt + xvfb-run make -C doc html + + - name: (DOCS) Upload docs artifacts + if: ${{ env.RUN_DOC_BUILD == 'true' }} + uses: actions/upload-artifact@v4 + with: + name: fluent-mechanical-docs-stage-mechanical + path: | + doc/_build/ doc/source/examples/fluent-mechanical/ \ No newline at end of file From 460333c7599af5aed8decfe9fc04e9917fcb1bfb Mon Sep 17 00:00:00 2001 From: dkunhamb Date: Tue, 21 Jan 2025 12:04:49 -0600 Subject: [PATCH 53/68] test: working in local --- fluent-mechanical/wf_fm_02_mechanical.py | 438 ++++++----------------- 1 file changed, 113 insertions(+), 325 deletions(-) diff --git a/fluent-mechanical/wf_fm_02_mechanical.py b/fluent-mechanical/wf_fm_02_mechanical.py index 3e83d105..fdfe65c1 100644 --- a/fluent-mechanical/wf_fm_02_mechanical.py +++ b/fluent-mechanical/wf_fm_02_mechanical.py @@ -267,13 +267,12 @@ def display_image(image_name): Model.AddTransientThermalAnalysis() # Store all main tree nodes as variables - TRANS_THERM = Model.Analyses[0] TRANS_THERM_SOLN = TRANS_THERM.Solution ANA_SETTINGS = TRANS_THERM.Children[1] +#ANA_SETTINGS = ExtAPI.DataModel.Project.Model.Analyses[0].AnalysisSettings # Setup transient thermal analysis settings - #ANA_SETTINGS.AutomaticTimeStepping = AutomaticTimeStepping.On ANA_SETTINGS.SolverType = SolverType.Direct ANA_SETTINGS.NonLinearFormulation = NonLinearFormulationType.Full @@ -281,257 +280,108 @@ def display_image(image_name): ANA_SETTINGS.NumberOfSteps = 1 ANA_SETTINGS.SetStepEndTime(1, Quantity('720[s]')) ANA_SETTINGS.NumberOfSteps = 14 -analysis_step = ( - (1, Quantity('1e-3[s]')), - (2, Quantity('2e-3[s]')), - (3, Quantity('20[s]')), - (4, Quantity('30[s]')), - (5, Quantity('320[s]')), - (6, Quantity('330[s]')), - (7, Quantity('350[s]')), - (8, Quantity('360[s]')), - (9, Quantity('380[s]')), - (10, Quantity('390[s]')), - (11, Quantity('680[s]')), - (12, Quantity('690[s]')), - (13, Quantity('710[s]')), - (14, Quantity('720[s]')) +analysis_step = ( + (1, Quantity('1e-3[s]')), + (2, Quantity('2e-3[s]')), + (3, Quantity('20[s]')), + (4, Quantity('30[s]')), + (5, Quantity('320[s]')), + (6, Quantity('330[s]')), + (7, Quantity('350[s]')), + (8, Quantity('360[s]')), + (9, Quantity('380[s]')), + (10, Quantity('390[s]')), + (11, Quantity('680[s]')), + (12, Quantity('690[s]')), + (13, Quantity('710[s]')), + (14, Quantity('720[s]')) ) - for i, q in analysis_step: ANA_SETTINGS.SetStepEndTime(i,q) - -# Applied External HTCs and Temperature data +ANA_SETTINGS.Activate() External_Convection_Load_1 = TRANS_THERM.AddConvection() selection = NS_GRP.Children[8] External_Convection_Load_1.Location = selection -External_Convection_Load_1.FilmCoefficient.Inputs[0].DiscreteValues = [ - Quantity("0[s]"), - Quantity("1e-3[s]"), - Quantity("2e-3[s]"), - Quantity("20[s]"), - Quantity("30[s]"), - Quantity("320[s]"), - Quantity("330[s]"), - Quantity("350[s]"), - Quantity("360[s]"), - Quantity("380[s]"), - Quantity("390[s]"), - Quantity("680[s]"), - Quantity("690[s]"), - Quantity("710[s]"), - Quantity("720[s]"), -] +External_Convection_Load_1.FilmCoefficient.Inputs[0].DiscreteValues=[Quantity('0[s]'),Quantity('1e-3[s]'), \ + Quantity('2e-3[s]'),Quantity('20[s]'),Quantity('30[s]'),Quantity('320[s]'),Quantity('330[s]'), \ + Quantity('350[s]'),Quantity('360[s]'),Quantity('380[s]'),Quantity('390[s]'),Quantity('680[s]'), \ + Quantity('690[s]'),Quantity('710[s]'),Quantity('720[s]')] -External_Convection_Load_1.FilmCoefficient.Output.DiscreteValues = [ - Quantity("60[W m^-1 m^-1 K^-1]"), - Quantity("60[W m^-1 m^-1 K^-1]"), - Quantity("60[W m^-1 m^-1 K^-1]"), - Quantity("60[W m^-1 m^-1 K^-1]"), - Quantity("60[W m^-1 m^-1 K^-1]"), - Quantity("60[W m^-1 m^-1 K^-1]"), - Quantity("60[W m^-1 m^-1 K^-1]"), - Quantity("60[W m^-1 m^-1 K^-1]"), - Quantity("60[W m^-1 m^-1 K^-1]"), - Quantity("60[W m^-1 m^-1 K^-1]"), - Quantity("60[W m^-1 m^-1 K^-1]"), - Quantity("60[W m^-1 m^-1 K^-1]"), - Quantity("60[W m^-1 m^-1 K^-1]"), - Quantity("60[W m^-1 m^-1 K^-1]"), - Quantity("60[W m^-1 m^-1 K^-1]"), -] +External_Convection_Load_1.FilmCoefficient.Output.DiscreteValues=[Quantity('60[W m^-1 m^-1 K^-1]'), \ + Quantity('60[W m^-1 m^-1 K^-1]'), Quantity('60[W m^-1 m^-1 K^-1]'), Quantity('60[W m^-1 m^-1 K^-1]'), \ + Quantity('60[W m^-1 m^-1 K^-1]'), Quantity('60[W m^-1 m^-1 K^-1]'), Quantity('60[W m^-1 m^-1 K^-1]'), \ + Quantity('60[W m^-1 m^-1 K^-1]'), Quantity('60[W m^-1 m^-1 K^-1]'), Quantity('60[W m^-1 m^-1 K^-1]'), \ + Quantity('60[W m^-1 m^-1 K^-1]'), Quantity('60[W m^-1 m^-1 K^-1]'), Quantity('60[W m^-1 m^-1 K^-1]'), \ + Quantity('60[W m^-1 m^-1 K^-1]'),Quantity('60[W m^-1 m^-1 K^-1]')] -External_Convection_Load_1.AmbientTemperature.Inputs[0].DiscreteValues = [ - Quantity("0[s]"), - Quantity("1e-3[s]"), - Quantity("2e-3[s]"), - Quantity("20[s]"), - Quantity("30[s]"), - Quantity("320[s]"), - Quantity("330[s]"), - Quantity("350[s]"), - Quantity("360[s]"), - Quantity("380[s]"), - Quantity("390[s]"), - Quantity("680[s]"), - Quantity("690[s]"), - Quantity("710[s]"), - Quantity("720[s]"), -] +External_Convection_Load_1.AmbientTemperature.Inputs[0].DiscreteValues=[Quantity('0[s]'),Quantity('1e-3[s]'), \ + Quantity('2e-3[s]'),Quantity('20[s]'),Quantity('30[s]'),Quantity('320[s]'),Quantity('330[s]'), \ + Quantity('350[s]'),Quantity('360[s]'),Quantity('380[s]'),Quantity('390[s]'),Quantity('680[s]'), \ + Quantity('690[s]'),Quantity('710[s]'),Quantity('720[s]')] -External_Convection_Load_1.AmbientTemperature.Output.DiscreteValues = [ - Quantity("473.15[K]"), - Quantity("473.15[K]"), - Quantity("473.15[K]"), - Quantity("473.15[K]"), - Quantity("473.15[K]"), - Quantity("473.15[K]"), - Quantity("473.15[K]"), - Quantity("473.15[K]"), - Quantity("473.15[K]"), - Quantity("473.15[K]"), - Quantity("473.15[K]"), - Quantity("473.15[K]"), - Quantity("473.15[K]"), - Quantity("473.15[K]"), - Quantity("473.15[K]"), -] +External_Convection_Load_1.AmbientTemperature.Output.DiscreteValues=[Quantity('473.15[K]'), Quantity('473.15[K]'), \ + Quantity('473.15[K]'), Quantity('473.15[K]'),Quantity('473.15[K]'),Quantity('473.15[K]'), \ + Quantity('473.15[K]'), Quantity('473.15[K]'),Quantity('473.15[K]'),Quantity('473.15[K]'), \ + Quantity('473.15[K]'), Quantity('473.15[K]'),Quantity('473.15[K]'),Quantity('473.15[K]'),Quantity('473.15[K]')] External_Convection_Load_2 = TRANS_THERM.AddConvection() selection = NS_GRP.Children[7] External_Convection_Load_2.Location = selection -External_Convection_Load_2.FilmCoefficient.Inputs[0].DiscreteValues = [ - Quantity("0[s]"), - Quantity("1e-3[s]"), - Quantity("2e-3[s]"), - Quantity("20[s]"), - Quantity("30[s]"), - Quantity("320[s]"), - Quantity("330[s]"), - Quantity("350[s]"), - Quantity("360[s]"), - Quantity("380[s]"), - Quantity("390[s]"), - Quantity("680[s]"), - Quantity("690[s]"), - Quantity("710[s]"), - Quantity("720[s]"), -] +External_Convection_Load_2.FilmCoefficient.Inputs[0].DiscreteValues=[Quantity('0[s]'),Quantity('1e-3[s]'), \ + Quantity('2e-3[s]'),Quantity('20[s]'),Quantity('30[s]'),Quantity('320[s]'),Quantity('330[s]'), \ + Quantity('350[s]'),Quantity('360[s]'),Quantity('380[s]'),Quantity('390[s]'),Quantity('680[s]'), \ + Quantity('690[s]'),Quantity('710[s]'),Quantity('720[s]')] -External_Convection_Load_2.FilmCoefficient.Output.DiscreteValues = [ - Quantity("20[W m^-1 m^-1 K^-1]"), - Quantity("20[W m^-1 m^-1 K^-1]"), - Quantity("20[W m^-1 m^-1 K^-1]"), - Quantity("20[W m^-1 m^-1 K^-1]"), - Quantity("20[W m^-1 m^-1 K^-1]"), - Quantity("20[W m^-1 m^-1 K^-1]"), - Quantity("20[W m^-1 m^-1 K^-1]"), - Quantity("20[W m^-1 m^-1 K^-1]"), - Quantity("20[W m^-1 m^-1 K^-1]"), - Quantity("20[W m^-1 m^-1 K^-1]"), - Quantity("20[W m^-1 m^-1 K^-1]"), - Quantity("20[W m^-1 m^-1 K^-1]"), - Quantity("20[W m^-1 m^-1 K^-1]"), - Quantity("20[W m^-1 m^-1 K^-1]"), - Quantity("20[W m^-1 m^-1 K^-1]"), -] +External_Convection_Load_2.FilmCoefficient.Output.DiscreteValues=[Quantity('20[W m^-1 m^-1 K^-1]'), \ + Quantity('20[W m^-1 m^-1 K^-1]'), Quantity('20[W m^-1 m^-1 K^-1]'), Quantity('20[W m^-1 m^-1 K^-1]'), \ + Quantity('20[W m^-1 m^-1 K^-1]'), Quantity('20[W m^-1 m^-1 K^-1]'), Quantity('20[W m^-1 m^-1 K^-1]'), \ + Quantity('20[W m^-1 m^-1 K^-1]'), Quantity('20[W m^-1 m^-1 K^-1]'), Quantity('20[W m^-1 m^-1 K^-1]'), \ + Quantity('20[W m^-1 m^-1 K^-1]'),Quantity('20[W m^-1 m^-1 K^-1]'),Quantity('20[W m^-1 m^-1 K^-1]'), \ + Quantity('20[W m^-1 m^-1 K^-1]'),Quantity('20[W m^-1 m^-1 K^-1]')] -External_Convection_Load_2.AmbientTemperature.Inputs[0].DiscreteValues = [ - Quantity("0[s]"), - Quantity("1e-3[s]"), - Quantity("2e-3[s]"), - Quantity("20[s]"), - Quantity("30[s]"), - Quantity("320[s]"), - Quantity("330[s]"), - Quantity("350[s]"), - Quantity("360[s]"), - Quantity("380[s]"), - Quantity("390[s]"), - Quantity("680[s]"), - Quantity("690[s]"), - Quantity("710[s]"), - Quantity("720[s]"), -] +External_Convection_Load_2.AmbientTemperature.Inputs[0].DiscreteValues=[Quantity('0[s]'),Quantity('1e-3[s]'), \ + Quantity('2e-3[s]'),Quantity('20[s]'),Quantity('30[s]'),Quantity('320[s]'),Quantity('330[s]'), \ + Quantity('350[s]'),Quantity('360[s]'),Quantity('380[s]'),Quantity('390[s]'),Quantity('680[s]'), \ + Quantity('690[s]'),Quantity('710[s]'),Quantity('720[s]')] + +External_Convection_Load_2.AmbientTemperature.Output.DiscreteValues=[Quantity('498.15[K]'), Quantity('498.15[K]'), \ + Quantity('498.15[K]'), Quantity('498.15[K]'),Quantity('498.15[K]'),Quantity('498.15[K]'),Quantity('498.15[K]'), \ + Quantity('498.15[K]'), Quantity('498.15[K]'),Quantity('498.15[K]'),Quantity('498.15[K]'),Quantity('498.15[K]'), \ + Quantity('498.15[K]'), Quantity('498.15[K]'), Quantity('498.15[K]')] -External_Convection_Load_2.AmbientTemperature.Output.DiscreteValues = [ - Quantity("498.15[K]"), - Quantity("498.15[K]"), - Quantity("498.15[K]"), - Quantity("498.15[K]"), - Quantity("498.15[K]"), - Quantity("498.15[K]"), - Quantity("498.15[K]"), - Quantity("498.15[K]"), - Quantity("498.15[K]"), - Quantity("498.15[K]"), - Quantity("498.15[K]"), - Quantity("498.15[K]"), - Quantity("498.15[K]"), - Quantity("498.15[K]"), - Quantity("498.15[K]"), -] External_Convection_Load_3 = TRANS_THERM.AddConvection() selection = NS_GRP.Children[6] External_Convection_Load_3.Location = selection -External_Convection_Load_3.FilmCoefficient.Inputs[0].DiscreteValues = [ - Quantity("0[s]"), - Quantity("1e-3[s]"), - Quantity("2e-3[s]"), - Quantity("20[s]"), - Quantity("30[s]"), - Quantity("320[s]"), - Quantity("330[s]"), - Quantity("350[s]"), - Quantity("360[s]"), - Quantity("380[s]"), - Quantity("390[s]"), - Quantity("680[s]"), - Quantity("690[s]"), - Quantity("710[s]"), - Quantity("720[s]"), -] +External_Convection_Load_3.FilmCoefficient.Inputs[0].DiscreteValues=[Quantity('0[s]'),Quantity('1e-3[s]'), \ + Quantity('2e-3[s]'),Quantity('20[s]'),Quantity('30[s]'),Quantity('320[s]'),Quantity('330[s]'), \ + Quantity('350[s]'),Quantity('360[s]'),Quantity('380[s]'),Quantity('390[s]'),Quantity('680[s]'), \ + Quantity('690[s]'),Quantity('710[s]'),Quantity('720[s]')] -External_Convection_Load_3.FilmCoefficient.Output.DiscreteValues = [ - Quantity("500[W m^-1 m^-1 K^-1]"), - Quantity("500[W m^-1 m^-1 K^-1]"), - Quantity("500[W m^-1 m^-1 K^-1]"), - Quantity("500[W m^-1 m^-1 K^-1]"), - Quantity("500[W m^-1 m^-1 K^-1]"), - Quantity("500[W m^-1 m^-1 K^-1]"), - Quantity("500[W m^-1 m^-1 K^-1]"), - Quantity("500[W m^-1 m^-1 K^-1]"), - Quantity("500[W m^-1 m^-1 K^-1]"), - Quantity("500[W m^-1 m^-1 K^-1]"), - Quantity("500[W m^-1 m^-1 K^-1]"), - Quantity("500[W m^-1 m^-1 K^-1]"), - Quantity("500[W m^-1 m^-1 K^-1]"), - Quantity("500[W m^-1 m^-1 K^-1]"), - Quantity("500[W m^-1 m^-1 K^-1]"), -] +External_Convection_Load_3.FilmCoefficient.Output.DiscreteValues=[Quantity('500[W m^-1 m^-1 K^-1]'), \ + Quantity('500[W m^-1 m^-1 K^-1]'), Quantity('500[W m^-1 m^-1 K^-1]'), Quantity('500[W m^-1 m^-1 K^-1]'), \ + Quantity('500[W m^-1 m^-1 K^-1]'), Quantity('500[W m^-1 m^-1 K^-1]'), Quantity('500[W m^-1 m^-1 K^-1]'), \ + Quantity('500[W m^-1 m^-1 K^-1]'), Quantity('500[W m^-1 m^-1 K^-1]'), Quantity('500[W m^-1 m^-1 K^-1]'), \ + Quantity('500[W m^-1 m^-1 K^-1]'),Quantity('500[W m^-1 m^-1 K^-1]'),Quantity('500[W m^-1 m^-1 K^-1]'), \ + Quantity('500[W m^-1 m^-1 K^-1]'),Quantity('500[W m^-1 m^-1 K^-1]')] + +External_Convection_Load_3.AmbientTemperature.Inputs[0].DiscreteValues=[Quantity('0[s]'),Quantity('1e-3[s]'), \ + Quantity('2e-3[s]'),Quantity('20[s]'),Quantity('30[s]'),Quantity('320[s]'),Quantity('330[s]'), \ + Quantity('350[s]'),Quantity('360[s]'),Quantity('380[s]'),Quantity('390[s]'),Quantity('680[s]'), \ + Quantity('690[s]'),Quantity('710[s]'),Quantity('720[s]')] + +External_Convection_Load_3.AmbientTemperature.Output.DiscreteValues=[Quantity('373.15[K]'), Quantity('373.15[K]'), \ + Quantity('373.15[K]'), Quantity('373.15[K]'),Quantity('373.15[K]'),Quantity('373.15[K]'),Quantity('373.15[K]'), \ + Quantity('373.15[K]'), Quantity('373.15[K]'),Quantity('373.15[K]'),Quantity('373.15[K]'),Quantity('373.15[K]'), \ + Quantity('373.15[K]'), Quantity('373.15[K]'), Quantity('373.15[K]')] -External_Convection_Load_3.AmbientTemperature.Inputs[0].DiscreteValues = [ - Quantity("0[s]"), - Quantity("1e-3[s]"), - Quantity("2e-3[s]"), - Quantity("20[s]"), - Quantity("30[s]"), - Quantity("320[s]"), - Quantity("330[s]"), - Quantity("350[s]"), - Quantity("360[s]"), - Quantity("380[s]"), - Quantity("390[s]"), - Quantity("680[s]"), - Quantity("690[s]"), - Quantity("710[s]"), - Quantity("720[s]"), -] -External_Convection_Load_3.AmbientTemperature.Output.DiscreteValues = [ - Quantity("373.15[K]"), - Quantity("373.15[K]"), - Quantity("373.15[K]"), - Quantity("373.15[K]"), - Quantity("373.15[K]"), - Quantity("373.15[K]"), - Quantity("373.15[K]"), - Quantity("373.15[K]"), - Quantity("373.15[K]"), - Quantity("373.15[K]"), - Quantity("373.15[K]"), - Quantity("373.15[K]"), - Quantity("373.15[K]"), - Quantity("373.15[K]"), - Quantity("373.15[K]"), -] group_list = [External_Convection_Load_1,External_Convection_Load_2,External_Convection_Load_3] grouping_folder = Tree.Group(group_list) @@ -543,15 +393,16 @@ def display_image(image_name): # Use the ouput from Fluent to import the temperature and HTC data # --------------------------------------------------------------- # -mechanical.run_python_script( - """ - -# Import HTCs and Temperature data From Fluent run +result = mechanical.run_python_script( + """ Imported_Load_Group = TRANS_THERM.AddImportedLoadExternalData() -imported_load_group_61 = Imported_Load_Group -imported_convection_62 = imported_load_group_61.AddImportedConvection() - +imported_load_group_61=Imported_Load_Group +imported_convection_62 = Imported_Load_Group.AddImportedConvection() +""" +) +result = mechanical.run_python_script( + """ external_data_files = Ansys.Mechanical.ExternalData.ExternalDataFileCollection() external_data_files.SaveFilesWithProject = False external_data_file_1 = Ansys.Mechanical.ExternalData.ExternalDataFile() @@ -560,131 +411,66 @@ def display_image(image_name): external_data_file_1.Description = "High" external_data_file_1.IsMainFile = True external_data_file_1.FilePath= temp_htc_data_high_path -external_data_file_1.ImportSettings = ( - Ansys.Mechanical.ExternalData.ImportSettingsFactory.GetSettingsForFormat( - MechanicalEnums.ExternalData.ImportFormat.Delimited - ) -) +external_data_file_1.ImportSettings = Ansys.Mechanical.ExternalData.ImportSettingsFactory.GetSettingsForFormat(MechanicalEnums.ExternalData.ImportFormat.Delimited) import_settings = external_data_file_1.ImportSettings import_settings.SkipRows = 1 import_settings.SkipFooter = 0 import_settings.Delimiter = "," import_settings.AverageCornerNodesToMidsideNodes = False import_settings.UseColumn(0, MechanicalEnums.ExternalData.VariableType.NodeId, "", "Node ID@A") -import_settings.UseColumn( - 1, MechanicalEnums.ExternalData.VariableType.XCoordinate, "m", "X Coordinate@B" -) -import_settings.UseColumn( - 2, MechanicalEnums.ExternalData.VariableType.YCoordinate, "m", "Y Coordinate@C" -) -import_settings.UseColumn( - 3, MechanicalEnums.ExternalData.VariableType.ZCoordinate, "m", "Z Coordinate@D" -) -import_settings.UseColumn( - 4, MechanicalEnums.ExternalData.VariableType.Temperature, "K", "Temperature@E" -) -import_settings.UseColumn( - 5, - MechanicalEnums.ExternalData.VariableType.HeatTransferCoefficient, - "W m^-2 K^-1", - "Heat Transfer Coefficient@F", -) +import_settings.UseColumn(1, MechanicalEnums.ExternalData.VariableType.XCoordinate, "m", "X Coordinate@B") +import_settings.UseColumn(2, MechanicalEnums.ExternalData.VariableType.YCoordinate, "m", "Y Coordinate@C") +import_settings.UseColumn(3, MechanicalEnums.ExternalData.VariableType.ZCoordinate, "m", "Z Coordinate@D") +import_settings.UseColumn(4, MechanicalEnums.ExternalData.VariableType.Temperature, "K", "Temperature@E") +import_settings.UseColumn(5, MechanicalEnums.ExternalData.VariableType.HeatTransferCoefficient, "W m^-2 K^-1", "Heat Transfer Coefficient@F") external_data_file_2 = Ansys.Mechanical.ExternalData.ExternalDataFile() external_data_files.Add(external_data_file_2) external_data_file_2.Identifier = "File2" external_data_file_2.Description = "Med" external_data_file_2.IsMainFile = False external_data_file_2.FilePath= temp_htc_data_med_path -external_data_file_2.ImportSettings = ( - Ansys.Mechanical.ExternalData.ImportSettingsFactory.GetSettingsForFormat( - MechanicalEnums.ExternalData.ImportFormat.Delimited - ) -) +external_data_file_2.ImportSettings = Ansys.Mechanical.ExternalData.ImportSettingsFactory.GetSettingsForFormat(MechanicalEnums.ExternalData.ImportFormat.Delimited) import_settings = external_data_file_2.ImportSettings import_settings.SkipRows = 1 import_settings.SkipFooter = 0 import_settings.Delimiter = "," import_settings.AverageCornerNodesToMidsideNodes = False -import_settings.UseColumn( - 1, MechanicalEnums.ExternalData.VariableType.XCoordinate, "m", "X Coordinate@B" -) -import_settings.UseColumn( - 2, MechanicalEnums.ExternalData.VariableType.YCoordinate, "m", "Y Coordinate@C" -) -import_settings.UseColumn( - 3, MechanicalEnums.ExternalData.VariableType.ZCoordinate, "m", "Z Coordinate@D" -) -import_settings.UseColumn( - 4, MechanicalEnums.ExternalData.VariableType.Temperature, "K", "Temperature@E" -) -import_settings.UseColumn( - 5, - MechanicalEnums.ExternalData.VariableType.HeatTransferCoefficient, - "W m^-2 K^-1", - "Heat Transfer Coefficient@F", -) +import_settings.UseColumn(0, MechanicalEnums.ExternalData.VariableType.NodeId, "", "Node ID@A") +import_settings.UseColumn(1, MechanicalEnums.ExternalData.VariableType.XCoordinate, "m", "X Coordinate@B") +import_settings.UseColumn(2, MechanicalEnums.ExternalData.VariableType.YCoordinate, "m", "Y Coordinate@C") +import_settings.UseColumn(3, MechanicalEnums.ExternalData.VariableType.ZCoordinate, "m", "Z Coordinate@D") +import_settings.UseColumn(4, MechanicalEnums.ExternalData.VariableType.Temperature, "K", "Temperature@E") +import_settings.UseColumn(5, MechanicalEnums.ExternalData.VariableType.HeatTransferCoefficient, "W m^-2 K^-1", "Heat Transfer Coefficient@F") external_data_file_3 = Ansys.Mechanical.ExternalData.ExternalDataFile() external_data_files.Add(external_data_file_3) external_data_file_3.Identifier = "File3" external_data_file_3.Description = "Low" external_data_file_3.IsMainFile = False external_data_file_3.FilePath= temp_htc_data_low_path -external_data_file_3.ImportSettings = ( - Ansys.Mechanical.ExternalData.ImportSettingsFactory.GetSettingsForFormat( - MechanicalEnums.ExternalData.ImportFormat.Delimited - ) -) +external_data_file_3.ImportSettings = Ansys.Mechanical.ExternalData.ImportSettingsFactory.GetSettingsForFormat(MechanicalEnums.ExternalData.ImportFormat.Delimited) import_settings = external_data_file_3.ImportSettings import_settings.SkipRows = 1 import_settings.SkipFooter = 0 import_settings.Delimiter = "," import_settings.AverageCornerNodesToMidsideNodes = False import_settings.UseColumn(0, MechanicalEnums.ExternalData.VariableType.NodeId, "", "Node ID@A") -import_settings.UseColumn( - 1, MechanicalEnums.ExternalData.VariableType.XCoordinate, "m", "X Coordinate@B" -) -import_settings.UseColumn( - 2, MechanicalEnums.ExternalData.VariableType.YCoordinate, "m", "Y Coordinate@C" -) -import_settings.UseColumn( - 3, MechanicalEnums.ExternalData.VariableType.ZCoordinate, "m", "Z Coordinate@D" -) -import_settings.UseColumn( - 4, MechanicalEnums.ExternalData.VariableType.Temperature, "K", "Temperature@E" -) -import_settings.UseColumn( - 5, - MechanicalEnums.ExternalData.VariableType.HeatTransferCoefficient, - "W m^-2 K^-1", - "Heat Transfer Coefficient@F", -) +import_settings.UseColumn(1, MechanicalEnums.ExternalData.VariableType.XCoordinate, "m", "X Coordinate@B") +import_settings.UseColumn(2, MechanicalEnums.ExternalData.VariableType.YCoordinate, "m", "Y Coordinate@C") +import_settings.UseColumn(3, MechanicalEnums.ExternalData.VariableType.ZCoordinate, "m", "Z Coordinate@D") +import_settings.UseColumn(4, MechanicalEnums.ExternalData.VariableType.Temperature, "K", "Temperature@E") +import_settings.UseColumn(5, MechanicalEnums.ExternalData.VariableType.HeatTransferCoefficient, "W m^-2 K^-1", "Heat Transfer Coefficient@F") + imported_load_group_61.ImportExternalDataFiles(external_data_files) +""" +) +result = mechanical.run_python_script( + """ table = imported_load_group_61.Children[0].GetTableByName("Film Coefficient") numofsteps = 15 -Film_Coeff = [ - "File1:Heat Transfer Coefficient@F", - "File2:Heat Transfer Coefficient@F", - "File3:Heat Transfer Coefficient@F", -] +Film_Coeff = ["File1:Heat Transfer Coefficient@F","File2:Heat Transfer Coefficient@F","File3:Heat Transfer Coefficient@F"] Amb_Temp = ["File1:Temperature@E","File2:Temperature@E","File3:Temperature@E"] -Ana_time = [ - "0", - "1e-3", - "2e-3", - "20", - "30", - "320", - "330", - "350", - "360", - "380", - "390", - "680", - "690", - "710", - "720", -] +Ana_time = ["0","1e-3","2e-3","20","30","320","330","350","360","380","390","680","690","710","720"] for i in range(numofsteps-1): table.Add(None) @@ -753,11 +539,13 @@ def display_image(image_name): imported_convection_62.Location = selection imported_load_id = imported_convection_62.ObjectId imported_load = DataModel.GetObjectById(imported_load_id) - +""" +) # !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! # imported_convection_62.InternalObject.ExternalLoadSteppingType = 1 # !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! - +mechanical.run_python_script( + """ imported_load.ImportLoad() Tree.Activate([imported_load]) @@ -776,7 +564,7 @@ def display_image(image_name): ############################################################################### # Solve and post-process the results # ---------------------------------- -# + mechanical.run_python_script( """ # Insert results objects From a15546d9af50812c6bf73ab9f90244a9f333d0b3 Mon Sep 17 00:00:00 2001 From: dkunhamb Date: Tue, 21 Jan 2025 15:55:12 -0600 Subject: [PATCH 54/68] till meshing --- fluent-mechanical/wf_fm_02_mechanical.py | 930 +++++++++++------------ 1 file changed, 465 insertions(+), 465 deletions(-) diff --git a/fluent-mechanical/wf_fm_02_mechanical.py b/fluent-mechanical/wf_fm_02_mechanical.py index fdfe65c1..de914829 100644 --- a/fluent-mechanical/wf_fm_02_mechanical.py +++ b/fluent-mechanical/wf_fm_02_mechanical.py @@ -257,469 +257,469 @@ def display_image(image_name): mechanical.download(files=os.path.join(project_directory, "mesh.png"), target_dir=OUTPUT_DIR) display_image("mesh.png") -############################################################################### -# Add Transient Thermal Analysis and set up the analysis settings -# --------------------------------------------------------------- -# - -mechanical.run_python_script( - """ -Model.AddTransientThermalAnalysis() - -# Store all main tree nodes as variables -TRANS_THERM = Model.Analyses[0] -TRANS_THERM_SOLN = TRANS_THERM.Solution -ANA_SETTINGS = TRANS_THERM.Children[1] -#ANA_SETTINGS = ExtAPI.DataModel.Project.Model.Analyses[0].AnalysisSettings - -# Setup transient thermal analysis settings -#ANA_SETTINGS.AutomaticTimeStepping = AutomaticTimeStepping.On -ANA_SETTINGS.SolverType = SolverType.Direct -ANA_SETTINGS.NonLinearFormulation = NonLinearFormulationType.Full - -ANA_SETTINGS.NumberOfSteps = 1 -ANA_SETTINGS.SetStepEndTime(1, Quantity('720[s]')) -ANA_SETTINGS.NumberOfSteps = 14 -analysis_step = ( - (1, Quantity('1e-3[s]')), - (2, Quantity('2e-3[s]')), - (3, Quantity('20[s]')), - (4, Quantity('30[s]')), - (5, Quantity('320[s]')), - (6, Quantity('330[s]')), - (7, Quantity('350[s]')), - (8, Quantity('360[s]')), - (9, Quantity('380[s]')), - (10, Quantity('390[s]')), - (11, Quantity('680[s]')), - (12, Quantity('690[s]')), - (13, Quantity('710[s]')), - (14, Quantity('720[s]')) -) -for i, q in analysis_step: - ANA_SETTINGS.SetStepEndTime(i,q) -ANA_SETTINGS.Activate() - -External_Convection_Load_1 = TRANS_THERM.AddConvection() -selection = NS_GRP.Children[8] -External_Convection_Load_1.Location = selection - -External_Convection_Load_1.FilmCoefficient.Inputs[0].DiscreteValues=[Quantity('0[s]'),Quantity('1e-3[s]'), \ - Quantity('2e-3[s]'),Quantity('20[s]'),Quantity('30[s]'),Quantity('320[s]'),Quantity('330[s]'), \ - Quantity('350[s]'),Quantity('360[s]'),Quantity('380[s]'),Quantity('390[s]'),Quantity('680[s]'), \ - Quantity('690[s]'),Quantity('710[s]'),Quantity('720[s]')] - -External_Convection_Load_1.FilmCoefficient.Output.DiscreteValues=[Quantity('60[W m^-1 m^-1 K^-1]'), \ - Quantity('60[W m^-1 m^-1 K^-1]'), Quantity('60[W m^-1 m^-1 K^-1]'), Quantity('60[W m^-1 m^-1 K^-1]'), \ - Quantity('60[W m^-1 m^-1 K^-1]'), Quantity('60[W m^-1 m^-1 K^-1]'), Quantity('60[W m^-1 m^-1 K^-1]'), \ - Quantity('60[W m^-1 m^-1 K^-1]'), Quantity('60[W m^-1 m^-1 K^-1]'), Quantity('60[W m^-1 m^-1 K^-1]'), \ - Quantity('60[W m^-1 m^-1 K^-1]'), Quantity('60[W m^-1 m^-1 K^-1]'), Quantity('60[W m^-1 m^-1 K^-1]'), \ - Quantity('60[W m^-1 m^-1 K^-1]'),Quantity('60[W m^-1 m^-1 K^-1]')] - -External_Convection_Load_1.AmbientTemperature.Inputs[0].DiscreteValues=[Quantity('0[s]'),Quantity('1e-3[s]'), \ - Quantity('2e-3[s]'),Quantity('20[s]'),Quantity('30[s]'),Quantity('320[s]'),Quantity('330[s]'), \ - Quantity('350[s]'),Quantity('360[s]'),Quantity('380[s]'),Quantity('390[s]'),Quantity('680[s]'), \ - Quantity('690[s]'),Quantity('710[s]'),Quantity('720[s]')] - -External_Convection_Load_1.AmbientTemperature.Output.DiscreteValues=[Quantity('473.15[K]'), Quantity('473.15[K]'), \ - Quantity('473.15[K]'), Quantity('473.15[K]'),Quantity('473.15[K]'),Quantity('473.15[K]'), \ - Quantity('473.15[K]'), Quantity('473.15[K]'),Quantity('473.15[K]'),Quantity('473.15[K]'), \ - Quantity('473.15[K]'), Quantity('473.15[K]'),Quantity('473.15[K]'),Quantity('473.15[K]'),Quantity('473.15[K]')] - - -External_Convection_Load_2 = TRANS_THERM.AddConvection() -selection = NS_GRP.Children[7] -External_Convection_Load_2.Location = selection - -External_Convection_Load_2.FilmCoefficient.Inputs[0].DiscreteValues=[Quantity('0[s]'),Quantity('1e-3[s]'), \ - Quantity('2e-3[s]'),Quantity('20[s]'),Quantity('30[s]'),Quantity('320[s]'),Quantity('330[s]'), \ - Quantity('350[s]'),Quantity('360[s]'),Quantity('380[s]'),Quantity('390[s]'),Quantity('680[s]'), \ - Quantity('690[s]'),Quantity('710[s]'),Quantity('720[s]')] - -External_Convection_Load_2.FilmCoefficient.Output.DiscreteValues=[Quantity('20[W m^-1 m^-1 K^-1]'), \ - Quantity('20[W m^-1 m^-1 K^-1]'), Quantity('20[W m^-1 m^-1 K^-1]'), Quantity('20[W m^-1 m^-1 K^-1]'), \ - Quantity('20[W m^-1 m^-1 K^-1]'), Quantity('20[W m^-1 m^-1 K^-1]'), Quantity('20[W m^-1 m^-1 K^-1]'), \ - Quantity('20[W m^-1 m^-1 K^-1]'), Quantity('20[W m^-1 m^-1 K^-1]'), Quantity('20[W m^-1 m^-1 K^-1]'), \ - Quantity('20[W m^-1 m^-1 K^-1]'),Quantity('20[W m^-1 m^-1 K^-1]'),Quantity('20[W m^-1 m^-1 K^-1]'), \ - Quantity('20[W m^-1 m^-1 K^-1]'),Quantity('20[W m^-1 m^-1 K^-1]')] - -External_Convection_Load_2.AmbientTemperature.Inputs[0].DiscreteValues=[Quantity('0[s]'),Quantity('1e-3[s]'), \ - Quantity('2e-3[s]'),Quantity('20[s]'),Quantity('30[s]'),Quantity('320[s]'),Quantity('330[s]'), \ - Quantity('350[s]'),Quantity('360[s]'),Quantity('380[s]'),Quantity('390[s]'),Quantity('680[s]'), \ - Quantity('690[s]'),Quantity('710[s]'),Quantity('720[s]')] - -External_Convection_Load_2.AmbientTemperature.Output.DiscreteValues=[Quantity('498.15[K]'), Quantity('498.15[K]'), \ - Quantity('498.15[K]'), Quantity('498.15[K]'),Quantity('498.15[K]'),Quantity('498.15[K]'),Quantity('498.15[K]'), \ - Quantity('498.15[K]'), Quantity('498.15[K]'),Quantity('498.15[K]'),Quantity('498.15[K]'),Quantity('498.15[K]'), \ - Quantity('498.15[K]'), Quantity('498.15[K]'), Quantity('498.15[K]')] - - - -External_Convection_Load_3 = TRANS_THERM.AddConvection() -selection = NS_GRP.Children[6] -External_Convection_Load_3.Location = selection - -External_Convection_Load_3.FilmCoefficient.Inputs[0].DiscreteValues=[Quantity('0[s]'),Quantity('1e-3[s]'), \ - Quantity('2e-3[s]'),Quantity('20[s]'),Quantity('30[s]'),Quantity('320[s]'),Quantity('330[s]'), \ - Quantity('350[s]'),Quantity('360[s]'),Quantity('380[s]'),Quantity('390[s]'),Quantity('680[s]'), \ - Quantity('690[s]'),Quantity('710[s]'),Quantity('720[s]')] - -External_Convection_Load_3.FilmCoefficient.Output.DiscreteValues=[Quantity('500[W m^-1 m^-1 K^-1]'), \ - Quantity('500[W m^-1 m^-1 K^-1]'), Quantity('500[W m^-1 m^-1 K^-1]'), Quantity('500[W m^-1 m^-1 K^-1]'), \ - Quantity('500[W m^-1 m^-1 K^-1]'), Quantity('500[W m^-1 m^-1 K^-1]'), Quantity('500[W m^-1 m^-1 K^-1]'), \ - Quantity('500[W m^-1 m^-1 K^-1]'), Quantity('500[W m^-1 m^-1 K^-1]'), Quantity('500[W m^-1 m^-1 K^-1]'), \ - Quantity('500[W m^-1 m^-1 K^-1]'),Quantity('500[W m^-1 m^-1 K^-1]'),Quantity('500[W m^-1 m^-1 K^-1]'), \ - Quantity('500[W m^-1 m^-1 K^-1]'),Quantity('500[W m^-1 m^-1 K^-1]')] - -External_Convection_Load_3.AmbientTemperature.Inputs[0].DiscreteValues=[Quantity('0[s]'),Quantity('1e-3[s]'), \ - Quantity('2e-3[s]'),Quantity('20[s]'),Quantity('30[s]'),Quantity('320[s]'),Quantity('330[s]'), \ - Quantity('350[s]'),Quantity('360[s]'),Quantity('380[s]'),Quantity('390[s]'),Quantity('680[s]'), \ - Quantity('690[s]'),Quantity('710[s]'),Quantity('720[s]')] - -External_Convection_Load_3.AmbientTemperature.Output.DiscreteValues=[Quantity('373.15[K]'), Quantity('373.15[K]'), \ - Quantity('373.15[K]'), Quantity('373.15[K]'),Quantity('373.15[K]'),Quantity('373.15[K]'),Quantity('373.15[K]'), \ - Quantity('373.15[K]'), Quantity('373.15[K]'),Quantity('373.15[K]'),Quantity('373.15[K]'),Quantity('373.15[K]'), \ - Quantity('373.15[K]'), Quantity('373.15[K]'), Quantity('373.15[K]')] - - - -group_list = [External_Convection_Load_1,External_Convection_Load_2,External_Convection_Load_3] -grouping_folder = Tree.Group(group_list) -tree_grouping_folder_70 = DataModel.GetObjectsByName("New Folder") -""" -) - -############################################################################### -# Use the ouput from Fluent to import the temperature and HTC data -# --------------------------------------------------------------- -# - -result = mechanical.run_python_script( - """ -Imported_Load_Group = TRANS_THERM.AddImportedLoadExternalData() -imported_load_group_61=Imported_Load_Group -imported_convection_62 = Imported_Load_Group.AddImportedConvection() -""" -) -result = mechanical.run_python_script( - """ -external_data_files = Ansys.Mechanical.ExternalData.ExternalDataFileCollection() -external_data_files.SaveFilesWithProject = False -external_data_file_1 = Ansys.Mechanical.ExternalData.ExternalDataFile() -external_data_files.Add(external_data_file_1) -external_data_file_1.Identifier = "File1" -external_data_file_1.Description = "High" -external_data_file_1.IsMainFile = True -external_data_file_1.FilePath= temp_htc_data_high_path -external_data_file_1.ImportSettings = Ansys.Mechanical.ExternalData.ImportSettingsFactory.GetSettingsForFormat(MechanicalEnums.ExternalData.ImportFormat.Delimited) -import_settings = external_data_file_1.ImportSettings -import_settings.SkipRows = 1 -import_settings.SkipFooter = 0 -import_settings.Delimiter = "," -import_settings.AverageCornerNodesToMidsideNodes = False -import_settings.UseColumn(0, MechanicalEnums.ExternalData.VariableType.NodeId, "", "Node ID@A") -import_settings.UseColumn(1, MechanicalEnums.ExternalData.VariableType.XCoordinate, "m", "X Coordinate@B") -import_settings.UseColumn(2, MechanicalEnums.ExternalData.VariableType.YCoordinate, "m", "Y Coordinate@C") -import_settings.UseColumn(3, MechanicalEnums.ExternalData.VariableType.ZCoordinate, "m", "Z Coordinate@D") -import_settings.UseColumn(4, MechanicalEnums.ExternalData.VariableType.Temperature, "K", "Temperature@E") -import_settings.UseColumn(5, MechanicalEnums.ExternalData.VariableType.HeatTransferCoefficient, "W m^-2 K^-1", "Heat Transfer Coefficient@F") -external_data_file_2 = Ansys.Mechanical.ExternalData.ExternalDataFile() -external_data_files.Add(external_data_file_2) -external_data_file_2.Identifier = "File2" -external_data_file_2.Description = "Med" -external_data_file_2.IsMainFile = False -external_data_file_2.FilePath= temp_htc_data_med_path -external_data_file_2.ImportSettings = Ansys.Mechanical.ExternalData.ImportSettingsFactory.GetSettingsForFormat(MechanicalEnums.ExternalData.ImportFormat.Delimited) -import_settings = external_data_file_2.ImportSettings -import_settings.SkipRows = 1 -import_settings.SkipFooter = 0 -import_settings.Delimiter = "," -import_settings.AverageCornerNodesToMidsideNodes = False -import_settings.UseColumn(0, MechanicalEnums.ExternalData.VariableType.NodeId, "", "Node ID@A") -import_settings.UseColumn(1, MechanicalEnums.ExternalData.VariableType.XCoordinate, "m", "X Coordinate@B") -import_settings.UseColumn(2, MechanicalEnums.ExternalData.VariableType.YCoordinate, "m", "Y Coordinate@C") -import_settings.UseColumn(3, MechanicalEnums.ExternalData.VariableType.ZCoordinate, "m", "Z Coordinate@D") -import_settings.UseColumn(4, MechanicalEnums.ExternalData.VariableType.Temperature, "K", "Temperature@E") -import_settings.UseColumn(5, MechanicalEnums.ExternalData.VariableType.HeatTransferCoefficient, "W m^-2 K^-1", "Heat Transfer Coefficient@F") -external_data_file_3 = Ansys.Mechanical.ExternalData.ExternalDataFile() -external_data_files.Add(external_data_file_3) -external_data_file_3.Identifier = "File3" -external_data_file_3.Description = "Low" -external_data_file_3.IsMainFile = False -external_data_file_3.FilePath= temp_htc_data_low_path -external_data_file_3.ImportSettings = Ansys.Mechanical.ExternalData.ImportSettingsFactory.GetSettingsForFormat(MechanicalEnums.ExternalData.ImportFormat.Delimited) -import_settings = external_data_file_3.ImportSettings -import_settings.SkipRows = 1 -import_settings.SkipFooter = 0 -import_settings.Delimiter = "," -import_settings.AverageCornerNodesToMidsideNodes = False -import_settings.UseColumn(0, MechanicalEnums.ExternalData.VariableType.NodeId, "", "Node ID@A") -import_settings.UseColumn(1, MechanicalEnums.ExternalData.VariableType.XCoordinate, "m", "X Coordinate@B") -import_settings.UseColumn(2, MechanicalEnums.ExternalData.VariableType.YCoordinate, "m", "Y Coordinate@C") -import_settings.UseColumn(3, MechanicalEnums.ExternalData.VariableType.ZCoordinate, "m", "Z Coordinate@D") -import_settings.UseColumn(4, MechanicalEnums.ExternalData.VariableType.Temperature, "K", "Temperature@E") -import_settings.UseColumn(5, MechanicalEnums.ExternalData.VariableType.HeatTransferCoefficient, "W m^-2 K^-1", "Heat Transfer Coefficient@F") - -imported_load_group_61.ImportExternalDataFiles(external_data_files) -""" -) - -result = mechanical.run_python_script( - """ -table = imported_load_group_61.Children[0].GetTableByName("Film Coefficient") -numofsteps = 15 -Film_Coeff = ["File1:Heat Transfer Coefficient@F","File2:Heat Transfer Coefficient@F","File3:Heat Transfer Coefficient@F"] -Amb_Temp = ["File1:Temperature@E","File2:Temperature@E","File3:Temperature@E"] -Ana_time = ["0","1e-3","2e-3","20","30","320","330","350","360","380","390","680","690","710","720"] - -for i in range(numofsteps-1): - table.Add(None) - -table[0][0] = Film_Coeff[2] -table[0][1] = Amb_Temp[2] -table[0][2] = Ana_time[0] - -table[1][0] = Film_Coeff[2] -table[1][1] = Amb_Temp[2] -table[1][2] = Ana_time[1] - -table[2][0] = Film_Coeff[2] -table[2][1] = Amb_Temp[2] -table[2][2] = Ana_time[2] - -table[3][0] = Film_Coeff[2] -table[3][1] = Amb_Temp[2] -table[3][2] = Ana_time[3] - -table[4][0] = Film_Coeff[0] -table[4][1] = Amb_Temp[0] -table[4][2] = Ana_time[4] - -table[5][0] = Film_Coeff[0] -table[5][1] = Amb_Temp[0] -table[5][2] = Ana_time[5] - -table[6][0] = Film_Coeff[1] -table[6][1] = Amb_Temp[1] -table[6][2] = Ana_time[6] - -table[7][0] = Film_Coeff[1] -table[7][1] = Amb_Temp[1] -table[7][2] = Ana_time[7] - -table[8][0] = Film_Coeff[2] -table[8][1] = Amb_Temp[2] -table[8][2] = Ana_time[8] - -table[9][0] = Film_Coeff[2] -table[9][1] = Amb_Temp[2] -table[9][2] = Ana_time[9] - -table[10][0] = Film_Coeff[0] -table[10][1] = Amb_Temp[0] -table[10][2] = Ana_time[10] - -table[11][0] = Film_Coeff[0] -table[11][1] = Amb_Temp[0] -table[11][2] = Ana_time[11] - -table[12][0] = Film_Coeff[1] -table[12][1] = Amb_Temp[1] -table[12][2] = Ana_time[12] - -table[13][0] = Film_Coeff[1] -table[13][1] = Amb_Temp[1] -table[13][2] = Ana_time[13] - -table[14][0] = Film_Coeff[2] -table[14][1] = Amb_Temp[2] -table[14][2] = Ana_time[14] - -selection = NS_GRP.Children[4] -imported_convection_62.Location = selection -imported_load_id = imported_convection_62.ObjectId -imported_load = DataModel.GetObjectById(imported_load_id) -""" -) -# !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -# imported_convection_62.InternalObject.ExternalLoadSteppingType = 1 -# !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -mechanical.run_python_script( - """ -imported_load.ImportLoad() - -Tree.Activate([imported_load]) -ExtAPI.Graphics.Camera.SetFit() -ExtAPI.Graphics.ExportImage( - os.path.join(project_directory, "imported_temperature.png"), image_export_format, settings_720p -) -""" -) -mechanical.download( - files=os.path.join(project_directory, "imported_temperature.png"), target_dir=OUTPUT_DIR -) -if GRAPHICS_BOOL: - display_image("imported_temperature.png") - -############################################################################### -# Solve and post-process the results -# ---------------------------------- - -mechanical.run_python_script( - """ -# Insert results objects - -Temp = TRANS_THERM_SOLN.AddTemperature() -Temp.DisplayTime = Quantity("680 [s]") - -# Run Solution: Transient Thermal Simulation - -TRANS_THERM_SOLN.Solve(True) -TRANS_THERM_SS = TRANS_THERM_SOLN.Status - -# Export temperature image - -Tree.Activate([Temp]) -ExtAPI.Graphics.ViewOptions.ResultPreference.ExtraModelDisplay = ( - Ansys.Mechanical.DataModel.MechanicalEnums.Graphics.ExtraModelDisplay.NoWireframe -) -ExtAPI.Graphics.ExportImage( - os.path.join(project_directory, "temperature.png"), image_export_format, settings_720p -) -""" -) -mechanical.download(files=os.path.join(project_directory, "temperature.png"), target_dir=OUTPUT_DIR) -if GRAPHICS_BOOL: - display_image("temperature.png") - - -############################################################################### -# Setup Structural Analysis -# ------------------------- -# -mechanical.run_python_script( - """ -Model.AddStaticStructuralAnalysis() - -# Define analysis settings - -# Setup static structural analysis settings -STAT_STRUC = Model.Analyses[1] -STAT_STRUC_SOLN = STAT_STRUC.Solution -STAT_STRUC_ANA_SETTING = STAT_STRUC.Children[0] - -STAT_STRUC_ANA_SETTING.NumberOfSteps = 1 -STAT_STRUC_ANA_SETTING.SetStepEndTime(1, Quantity('720[s]')) -STAT_STRUC_ANA_SETTING.NumberOfSteps = 14 - -analysis_step = ( - (1, Quantity('1e-3[s]')), - (2, Quantity('2e-3[s]')), - (3, Quantity('20[s]')), - (4, Quantity('30[s]')), - (5, Quantity('320[s]')), - (6, Quantity('330[s]')), - (7, Quantity('350[s]')), - (8, Quantity('360[s]')), - (9, Quantity('380[s]')), - (10, Quantity('390[s]')), - (11, Quantity('680[s]')), - (12, Quantity('690[s]')), - (13, Quantity('710[s]')), - (14, Quantity('720[s]')) -) -for i, q in analysis_step: - STAT_STRUC_ANA_SETTING.SetStepEndTime(i,q) -STAT_STRUC_ANA_SETTING.Activate() - - -# Add Imported Body Temperature load from Transient Thermal Run - -STAT_STRUC.ImportLoad(Model.Analyses[0]) -imported_load = DataModel.GetObjectsByName("Imported Body Temperature")[0] - -table = imported_load.GetTableByName("Source Time") -numofsteps = 14 -nCol = 2 -Ana_time = ["1e-3","2e-3","20","30","320","330","350","360","380","390","680","690","710","720"] - -for i in range(numofsteps-1): - table.Add(None) - -for i in range(numofsteps): - for j in range(nCol): - table[i][j] = Ana_time[i] - -imported_load.ImportLoad() - -# Apply Fixed Support Condition - -Fixed_Support = STAT_STRUC.AddFixedSupport() -selection = NS_GRP.Children[3] -Fixed_Support.Location = selection -""" -) - -############################################################################### -# Sovle and post-process the results -# ---------------------------------- -# -mechanical.run_python_script( - """ -SOLN = STAT_STRUC.Solution - -TOT_DEF1 = SOLN.AddTotalDeformation() -TOT_DEF1.DisplayTime = Quantity("680 [s]") - -EQV_STRS1 = SOLN.AddEquivalentStress() -EQV_STRS1.DisplayTime = Quantity("680 [s]") - -EQV_PLAS_STRN1 = SOLN.AddEquivalentPlasticStrain() -EQV_PLAS_STRN1.DisplayTime = Quantity("680 [s]") - -THERM_STRN1 = SOLN.AddThermalStrain() -THERM_STRN1.DisplayTime = Quantity("680 [s]") - -# Solve Nonlinear Static Simulation - -SOLN.Solve(True) -STAT_STRUC_SS = SOLN.Status - -# Export results images - -Tree.Activate([TOT_DEF1]) -ExtAPI.Graphics.ViewOptions.ResultPreference.ExtraModelDisplay = ( - Ansys.Mechanical.DataModel.MechanicalEnums.Graphics.ExtraModelDisplay.NoWireframe -) -ExtAPI.Graphics.ExportImage( - os.path.join(project_directory, "deformation.png"), image_export_format, settings_720p -) - -Tree.Activate([EQV_STRS1]) -ExtAPI.Graphics.ExportImage( - os.path.join(project_directory, "stress.png"), image_export_format, settings_720p -) - -Tree.Activate([EQV_PLAS_STRN1]) -ExtAPI.Graphics.ExportImage( - os.path.join(project_directory, "plastic_strain.png"), image_export_format, settings_720p -) -""" -) -mechanical.download(files=os.path.join(project_directory, "deformation.png"), target_dir=OUTPUT_DIR) -mechanical.download(files=os.path.join(project_directory, "stress.png"), target_dir=OUTPUT_DIR) -mechanical.download( - files=os.path.join(project_directory, "plastic_strain.png"), target_dir=OUTPUT_DIR -) - -# Display the resilts -if GRAPHICS_BOOL: - display_image("deformation.png") - display_image("stress.png") - display_image("plastic_strain.png") - -############################################################################### -# Close the Mechanical -# -------------------- -# +# ############################################################################### +# # Add Transient Thermal Analysis and set up the analysis settings +# # --------------------------------------------------------------- +# # + +# mechanical.run_python_script( +# """ +# Model.AddTransientThermalAnalysis() + +# # Store all main tree nodes as variables +# TRANS_THERM = Model.Analyses[0] +# TRANS_THERM_SOLN = TRANS_THERM.Solution +# ANA_SETTINGS = TRANS_THERM.Children[1] +# #ANA_SETTINGS = ExtAPI.DataModel.Project.Model.Analyses[0].AnalysisSettings + +# # Setup transient thermal analysis settings +# #ANA_SETTINGS.AutomaticTimeStepping = AutomaticTimeStepping.On +# ANA_SETTINGS.SolverType = SolverType.Direct +# ANA_SETTINGS.NonLinearFormulation = NonLinearFormulationType.Full + +# ANA_SETTINGS.NumberOfSteps = 1 +# ANA_SETTINGS.SetStepEndTime(1, Quantity('720[s]')) +# ANA_SETTINGS.NumberOfSteps = 14 +# analysis_step = ( +# (1, Quantity('1e-3[s]')), +# (2, Quantity('2e-3[s]')), +# (3, Quantity('20[s]')), +# (4, Quantity('30[s]')), +# (5, Quantity('320[s]')), +# (6, Quantity('330[s]')), +# (7, Quantity('350[s]')), +# (8, Quantity('360[s]')), +# (9, Quantity('380[s]')), +# (10, Quantity('390[s]')), +# (11, Quantity('680[s]')), +# (12, Quantity('690[s]')), +# (13, Quantity('710[s]')), +# (14, Quantity('720[s]')) +# ) +# for i, q in analysis_step: +# ANA_SETTINGS.SetStepEndTime(i,q) +# ANA_SETTINGS.Activate() + +# External_Convection_Load_1 = TRANS_THERM.AddConvection() +# selection = NS_GRP.Children[8] +# External_Convection_Load_1.Location = selection + +# External_Convection_Load_1.FilmCoefficient.Inputs[0].DiscreteValues=[Quantity('0[s]'),Quantity('1e-3[s]'), \ +# Quantity('2e-3[s]'),Quantity('20[s]'),Quantity('30[s]'),Quantity('320[s]'),Quantity('330[s]'), \ +# Quantity('350[s]'),Quantity('360[s]'),Quantity('380[s]'),Quantity('390[s]'),Quantity('680[s]'), \ +# Quantity('690[s]'),Quantity('710[s]'),Quantity('720[s]')] + +# External_Convection_Load_1.FilmCoefficient.Output.DiscreteValues=[Quantity('60[W m^-1 m^-1 K^-1]'), \ +# Quantity('60[W m^-1 m^-1 K^-1]'), Quantity('60[W m^-1 m^-1 K^-1]'), Quantity('60[W m^-1 m^-1 K^-1]'), \ +# Quantity('60[W m^-1 m^-1 K^-1]'), Quantity('60[W m^-1 m^-1 K^-1]'), Quantity('60[W m^-1 m^-1 K^-1]'), \ +# Quantity('60[W m^-1 m^-1 K^-1]'), Quantity('60[W m^-1 m^-1 K^-1]'), Quantity('60[W m^-1 m^-1 K^-1]'), \ +# Quantity('60[W m^-1 m^-1 K^-1]'), Quantity('60[W m^-1 m^-1 K^-1]'), Quantity('60[W m^-1 m^-1 K^-1]'), \ +# Quantity('60[W m^-1 m^-1 K^-1]'),Quantity('60[W m^-1 m^-1 K^-1]')] + +# External_Convection_Load_1.AmbientTemperature.Inputs[0].DiscreteValues=[Quantity('0[s]'),Quantity('1e-3[s]'), \ +# Quantity('2e-3[s]'),Quantity('20[s]'),Quantity('30[s]'),Quantity('320[s]'),Quantity('330[s]'), \ +# Quantity('350[s]'),Quantity('360[s]'),Quantity('380[s]'),Quantity('390[s]'),Quantity('680[s]'), \ +# Quantity('690[s]'),Quantity('710[s]'),Quantity('720[s]')] + +# External_Convection_Load_1.AmbientTemperature.Output.DiscreteValues=[Quantity('473.15[K]'), Quantity('473.15[K]'), \ +# Quantity('473.15[K]'), Quantity('473.15[K]'),Quantity('473.15[K]'),Quantity('473.15[K]'), \ +# Quantity('473.15[K]'), Quantity('473.15[K]'),Quantity('473.15[K]'),Quantity('473.15[K]'), \ +# Quantity('473.15[K]'), Quantity('473.15[K]'),Quantity('473.15[K]'),Quantity('473.15[K]'),Quantity('473.15[K]')] + + +# External_Convection_Load_2 = TRANS_THERM.AddConvection() +# selection = NS_GRP.Children[7] +# External_Convection_Load_2.Location = selection + +# External_Convection_Load_2.FilmCoefficient.Inputs[0].DiscreteValues=[Quantity('0[s]'),Quantity('1e-3[s]'), \ +# Quantity('2e-3[s]'),Quantity('20[s]'),Quantity('30[s]'),Quantity('320[s]'),Quantity('330[s]'), \ +# Quantity('350[s]'),Quantity('360[s]'),Quantity('380[s]'),Quantity('390[s]'),Quantity('680[s]'), \ +# Quantity('690[s]'),Quantity('710[s]'),Quantity('720[s]')] + +# External_Convection_Load_2.FilmCoefficient.Output.DiscreteValues=[Quantity('20[W m^-1 m^-1 K^-1]'), \ +# Quantity('20[W m^-1 m^-1 K^-1]'), Quantity('20[W m^-1 m^-1 K^-1]'), Quantity('20[W m^-1 m^-1 K^-1]'), \ +# Quantity('20[W m^-1 m^-1 K^-1]'), Quantity('20[W m^-1 m^-1 K^-1]'), Quantity('20[W m^-1 m^-1 K^-1]'), \ +# Quantity('20[W m^-1 m^-1 K^-1]'), Quantity('20[W m^-1 m^-1 K^-1]'), Quantity('20[W m^-1 m^-1 K^-1]'), \ +# Quantity('20[W m^-1 m^-1 K^-1]'),Quantity('20[W m^-1 m^-1 K^-1]'),Quantity('20[W m^-1 m^-1 K^-1]'), \ +# Quantity('20[W m^-1 m^-1 K^-1]'),Quantity('20[W m^-1 m^-1 K^-1]')] + +# External_Convection_Load_2.AmbientTemperature.Inputs[0].DiscreteValues=[Quantity('0[s]'),Quantity('1e-3[s]'), \ +# Quantity('2e-3[s]'),Quantity('20[s]'),Quantity('30[s]'),Quantity('320[s]'),Quantity('330[s]'), \ +# Quantity('350[s]'),Quantity('360[s]'),Quantity('380[s]'),Quantity('390[s]'),Quantity('680[s]'), \ +# Quantity('690[s]'),Quantity('710[s]'),Quantity('720[s]')] + +# External_Convection_Load_2.AmbientTemperature.Output.DiscreteValues=[Quantity('498.15[K]'), Quantity('498.15[K]'), \ +# Quantity('498.15[K]'), Quantity('498.15[K]'),Quantity('498.15[K]'),Quantity('498.15[K]'),Quantity('498.15[K]'), \ +# Quantity('498.15[K]'), Quantity('498.15[K]'),Quantity('498.15[K]'),Quantity('498.15[K]'),Quantity('498.15[K]'), \ +# Quantity('498.15[K]'), Quantity('498.15[K]'), Quantity('498.15[K]')] + + + +# External_Convection_Load_3 = TRANS_THERM.AddConvection() +# selection = NS_GRP.Children[6] +# External_Convection_Load_3.Location = selection + +# External_Convection_Load_3.FilmCoefficient.Inputs[0].DiscreteValues=[Quantity('0[s]'),Quantity('1e-3[s]'), \ +# Quantity('2e-3[s]'),Quantity('20[s]'),Quantity('30[s]'),Quantity('320[s]'),Quantity('330[s]'), \ +# Quantity('350[s]'),Quantity('360[s]'),Quantity('380[s]'),Quantity('390[s]'),Quantity('680[s]'), \ +# Quantity('690[s]'),Quantity('710[s]'),Quantity('720[s]')] + +# External_Convection_Load_3.FilmCoefficient.Output.DiscreteValues=[Quantity('500[W m^-1 m^-1 K^-1]'), \ +# Quantity('500[W m^-1 m^-1 K^-1]'), Quantity('500[W m^-1 m^-1 K^-1]'), Quantity('500[W m^-1 m^-1 K^-1]'), \ +# Quantity('500[W m^-1 m^-1 K^-1]'), Quantity('500[W m^-1 m^-1 K^-1]'), Quantity('500[W m^-1 m^-1 K^-1]'), \ +# Quantity('500[W m^-1 m^-1 K^-1]'), Quantity('500[W m^-1 m^-1 K^-1]'), Quantity('500[W m^-1 m^-1 K^-1]'), \ +# Quantity('500[W m^-1 m^-1 K^-1]'),Quantity('500[W m^-1 m^-1 K^-1]'),Quantity('500[W m^-1 m^-1 K^-1]'), \ +# Quantity('500[W m^-1 m^-1 K^-1]'),Quantity('500[W m^-1 m^-1 K^-1]')] + +# External_Convection_Load_3.AmbientTemperature.Inputs[0].DiscreteValues=[Quantity('0[s]'),Quantity('1e-3[s]'), \ +# Quantity('2e-3[s]'),Quantity('20[s]'),Quantity('30[s]'),Quantity('320[s]'),Quantity('330[s]'), \ +# Quantity('350[s]'),Quantity('360[s]'),Quantity('380[s]'),Quantity('390[s]'),Quantity('680[s]'), \ +# Quantity('690[s]'),Quantity('710[s]'),Quantity('720[s]')] + +# External_Convection_Load_3.AmbientTemperature.Output.DiscreteValues=[Quantity('373.15[K]'), Quantity('373.15[K]'), \ +# Quantity('373.15[K]'), Quantity('373.15[K]'),Quantity('373.15[K]'),Quantity('373.15[K]'),Quantity('373.15[K]'), \ +# Quantity('373.15[K]'), Quantity('373.15[K]'),Quantity('373.15[K]'),Quantity('373.15[K]'),Quantity('373.15[K]'), \ +# Quantity('373.15[K]'), Quantity('373.15[K]'), Quantity('373.15[K]')] + + + +# group_list = [External_Convection_Load_1,External_Convection_Load_2,External_Convection_Load_3] +# grouping_folder = Tree.Group(group_list) +# tree_grouping_folder_70 = DataModel.GetObjectsByName("New Folder") +# """ +# ) + +# ############################################################################### +# # Use the ouput from Fluent to import the temperature and HTC data +# # --------------------------------------------------------------- +# # + +# result = mechanical.run_python_script( +# """ +# Imported_Load_Group = TRANS_THERM.AddImportedLoadExternalData() +# imported_load_group_61=Imported_Load_Group +# imported_convection_62 = Imported_Load_Group.AddImportedConvection() +# """ +# ) +# result = mechanical.run_python_script( +# """ +# external_data_files = Ansys.Mechanical.ExternalData.ExternalDataFileCollection() +# external_data_files.SaveFilesWithProject = False +# external_data_file_1 = Ansys.Mechanical.ExternalData.ExternalDataFile() +# external_data_files.Add(external_data_file_1) +# external_data_file_1.Identifier = "File1" +# external_data_file_1.Description = "High" +# external_data_file_1.IsMainFile = True +# external_data_file_1.FilePath= temp_htc_data_high_path +# external_data_file_1.ImportSettings = Ansys.Mechanical.ExternalData.ImportSettingsFactory.GetSettingsForFormat(MechanicalEnums.ExternalData.ImportFormat.Delimited) +# import_settings = external_data_file_1.ImportSettings +# import_settings.SkipRows = 1 +# import_settings.SkipFooter = 0 +# import_settings.Delimiter = "," +# import_settings.AverageCornerNodesToMidsideNodes = False +# import_settings.UseColumn(0, MechanicalEnums.ExternalData.VariableType.NodeId, "", "Node ID@A") +# import_settings.UseColumn(1, MechanicalEnums.ExternalData.VariableType.XCoordinate, "m", "X Coordinate@B") +# import_settings.UseColumn(2, MechanicalEnums.ExternalData.VariableType.YCoordinate, "m", "Y Coordinate@C") +# import_settings.UseColumn(3, MechanicalEnums.ExternalData.VariableType.ZCoordinate, "m", "Z Coordinate@D") +# import_settings.UseColumn(4, MechanicalEnums.ExternalData.VariableType.Temperature, "K", "Temperature@E") +# import_settings.UseColumn(5, MechanicalEnums.ExternalData.VariableType.HeatTransferCoefficient, "W m^-2 K^-1", "Heat Transfer Coefficient@F") +# external_data_file_2 = Ansys.Mechanical.ExternalData.ExternalDataFile() +# external_data_files.Add(external_data_file_2) +# external_data_file_2.Identifier = "File2" +# external_data_file_2.Description = "Med" +# external_data_file_2.IsMainFile = False +# external_data_file_2.FilePath= temp_htc_data_med_path +# external_data_file_2.ImportSettings = Ansys.Mechanical.ExternalData.ImportSettingsFactory.GetSettingsForFormat(MechanicalEnums.ExternalData.ImportFormat.Delimited) +# import_settings = external_data_file_2.ImportSettings +# import_settings.SkipRows = 1 +# import_settings.SkipFooter = 0 +# import_settings.Delimiter = "," +# import_settings.AverageCornerNodesToMidsideNodes = False +# import_settings.UseColumn(0, MechanicalEnums.ExternalData.VariableType.NodeId, "", "Node ID@A") +# import_settings.UseColumn(1, MechanicalEnums.ExternalData.VariableType.XCoordinate, "m", "X Coordinate@B") +# import_settings.UseColumn(2, MechanicalEnums.ExternalData.VariableType.YCoordinate, "m", "Y Coordinate@C") +# import_settings.UseColumn(3, MechanicalEnums.ExternalData.VariableType.ZCoordinate, "m", "Z Coordinate@D") +# import_settings.UseColumn(4, MechanicalEnums.ExternalData.VariableType.Temperature, "K", "Temperature@E") +# import_settings.UseColumn(5, MechanicalEnums.ExternalData.VariableType.HeatTransferCoefficient, "W m^-2 K^-1", "Heat Transfer Coefficient@F") +# external_data_file_3 = Ansys.Mechanical.ExternalData.ExternalDataFile() +# external_data_files.Add(external_data_file_3) +# external_data_file_3.Identifier = "File3" +# external_data_file_3.Description = "Low" +# external_data_file_3.IsMainFile = False +# external_data_file_3.FilePath= temp_htc_data_low_path +# external_data_file_3.ImportSettings = Ansys.Mechanical.ExternalData.ImportSettingsFactory.GetSettingsForFormat(MechanicalEnums.ExternalData.ImportFormat.Delimited) +# import_settings = external_data_file_3.ImportSettings +# import_settings.SkipRows = 1 +# import_settings.SkipFooter = 0 +# import_settings.Delimiter = "," +# import_settings.AverageCornerNodesToMidsideNodes = False +# import_settings.UseColumn(0, MechanicalEnums.ExternalData.VariableType.NodeId, "", "Node ID@A") +# import_settings.UseColumn(1, MechanicalEnums.ExternalData.VariableType.XCoordinate, "m", "X Coordinate@B") +# import_settings.UseColumn(2, MechanicalEnums.ExternalData.VariableType.YCoordinate, "m", "Y Coordinate@C") +# import_settings.UseColumn(3, MechanicalEnums.ExternalData.VariableType.ZCoordinate, "m", "Z Coordinate@D") +# import_settings.UseColumn(4, MechanicalEnums.ExternalData.VariableType.Temperature, "K", "Temperature@E") +# import_settings.UseColumn(5, MechanicalEnums.ExternalData.VariableType.HeatTransferCoefficient, "W m^-2 K^-1", "Heat Transfer Coefficient@F") + +# imported_load_group_61.ImportExternalDataFiles(external_data_files) +# """ +# ) + +# result = mechanical.run_python_script( +# """ +# table = imported_load_group_61.Children[0].GetTableByName("Film Coefficient") +# numofsteps = 15 +# Film_Coeff = ["File1:Heat Transfer Coefficient@F","File2:Heat Transfer Coefficient@F","File3:Heat Transfer Coefficient@F"] +# Amb_Temp = ["File1:Temperature@E","File2:Temperature@E","File3:Temperature@E"] +# Ana_time = ["0","1e-3","2e-3","20","30","320","330","350","360","380","390","680","690","710","720"] + +# for i in range(numofsteps-1): +# table.Add(None) + +# table[0][0] = Film_Coeff[2] +# table[0][1] = Amb_Temp[2] +# table[0][2] = Ana_time[0] + +# table[1][0] = Film_Coeff[2] +# table[1][1] = Amb_Temp[2] +# table[1][2] = Ana_time[1] + +# table[2][0] = Film_Coeff[2] +# table[2][1] = Amb_Temp[2] +# table[2][2] = Ana_time[2] + +# table[3][0] = Film_Coeff[2] +# table[3][1] = Amb_Temp[2] +# table[3][2] = Ana_time[3] + +# table[4][0] = Film_Coeff[0] +# table[4][1] = Amb_Temp[0] +# table[4][2] = Ana_time[4] + +# table[5][0] = Film_Coeff[0] +# table[5][1] = Amb_Temp[0] +# table[5][2] = Ana_time[5] + +# table[6][0] = Film_Coeff[1] +# table[6][1] = Amb_Temp[1] +# table[6][2] = Ana_time[6] + +# table[7][0] = Film_Coeff[1] +# table[7][1] = Amb_Temp[1] +# table[7][2] = Ana_time[7] + +# table[8][0] = Film_Coeff[2] +# table[8][1] = Amb_Temp[2] +# table[8][2] = Ana_time[8] + +# table[9][0] = Film_Coeff[2] +# table[9][1] = Amb_Temp[2] +# table[9][2] = Ana_time[9] + +# table[10][0] = Film_Coeff[0] +# table[10][1] = Amb_Temp[0] +# table[10][2] = Ana_time[10] + +# table[11][0] = Film_Coeff[0] +# table[11][1] = Amb_Temp[0] +# table[11][2] = Ana_time[11] + +# table[12][0] = Film_Coeff[1] +# table[12][1] = Amb_Temp[1] +# table[12][2] = Ana_time[12] + +# table[13][0] = Film_Coeff[1] +# table[13][1] = Amb_Temp[1] +# table[13][2] = Ana_time[13] + +# table[14][0] = Film_Coeff[2] +# table[14][1] = Amb_Temp[2] +# table[14][2] = Ana_time[14] + +# selection = NS_GRP.Children[4] +# imported_convection_62.Location = selection +# imported_load_id = imported_convection_62.ObjectId +# imported_load = DataModel.GetObjectById(imported_load_id) +# """ +# ) +# # !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! +# # imported_convection_62.InternalObject.ExternalLoadSteppingType = 1 +# # !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! +# mechanical.run_python_script( +# """ +# imported_load.ImportLoad() + +# Tree.Activate([imported_load]) +# ExtAPI.Graphics.Camera.SetFit() +# ExtAPI.Graphics.ExportImage( +# os.path.join(project_directory, "imported_temperature.png"), image_export_format, settings_720p +# ) +# """ +# ) +# mechanical.download( +# files=os.path.join(project_directory, "imported_temperature.png"), target_dir=OUTPUT_DIR +# ) +# if GRAPHICS_BOOL: +# display_image("imported_temperature.png") + +# ############################################################################### +# # Solve and post-process the results +# # ---------------------------------- + +# mechanical.run_python_script( +# """ +# # Insert results objects + +# Temp = TRANS_THERM_SOLN.AddTemperature() +# Temp.DisplayTime = Quantity("680 [s]") + +# # Run Solution: Transient Thermal Simulation + +# TRANS_THERM_SOLN.Solve(True) +# TRANS_THERM_SS = TRANS_THERM_SOLN.Status + +# # Export temperature image + +# Tree.Activate([Temp]) +# ExtAPI.Graphics.ViewOptions.ResultPreference.ExtraModelDisplay = ( +# Ansys.Mechanical.DataModel.MechanicalEnums.Graphics.ExtraModelDisplay.NoWireframe +# ) +# ExtAPI.Graphics.ExportImage( +# os.path.join(project_directory, "temperature.png"), image_export_format, settings_720p +# ) +# """ +# ) +# mechanical.download(files=os.path.join(project_directory, "temperature.png"), target_dir=OUTPUT_DIR) +# if GRAPHICS_BOOL: +# display_image("temperature.png") + + +# ############################################################################### +# # Setup Structural Analysis +# # ------------------------- +# # +# mechanical.run_python_script( +# """ +# Model.AddStaticStructuralAnalysis() + +# # Define analysis settings + +# # Setup static structural analysis settings +# STAT_STRUC = Model.Analyses[1] +# STAT_STRUC_SOLN = STAT_STRUC.Solution +# STAT_STRUC_ANA_SETTING = STAT_STRUC.Children[0] + +# STAT_STRUC_ANA_SETTING.NumberOfSteps = 1 +# STAT_STRUC_ANA_SETTING.SetStepEndTime(1, Quantity('720[s]')) +# STAT_STRUC_ANA_SETTING.NumberOfSteps = 14 + +# analysis_step = ( +# (1, Quantity('1e-3[s]')), +# (2, Quantity('2e-3[s]')), +# (3, Quantity('20[s]')), +# (4, Quantity('30[s]')), +# (5, Quantity('320[s]')), +# (6, Quantity('330[s]')), +# (7, Quantity('350[s]')), +# (8, Quantity('360[s]')), +# (9, Quantity('380[s]')), +# (10, Quantity('390[s]')), +# (11, Quantity('680[s]')), +# (12, Quantity('690[s]')), +# (13, Quantity('710[s]')), +# (14, Quantity('720[s]')) +# ) +# for i, q in analysis_step: +# STAT_STRUC_ANA_SETTING.SetStepEndTime(i,q) +# STAT_STRUC_ANA_SETTING.Activate() + + +# # Add Imported Body Temperature load from Transient Thermal Run + +# STAT_STRUC.ImportLoad(Model.Analyses[0]) +# imported_load = DataModel.GetObjectsByName("Imported Body Temperature")[0] + +# table = imported_load.GetTableByName("Source Time") +# numofsteps = 14 +# nCol = 2 +# Ana_time = ["1e-3","2e-3","20","30","320","330","350","360","380","390","680","690","710","720"] + +# for i in range(numofsteps-1): +# table.Add(None) + +# for i in range(numofsteps): +# for j in range(nCol): +# table[i][j] = Ana_time[i] + +# imported_load.ImportLoad() + +# # Apply Fixed Support Condition + +# Fixed_Support = STAT_STRUC.AddFixedSupport() +# selection = NS_GRP.Children[3] +# Fixed_Support.Location = selection +# """ +# ) + +# ############################################################################### +# # Sovle and post-process the results +# # ---------------------------------- +# # +# mechanical.run_python_script( +# """ +# SOLN = STAT_STRUC.Solution + +# TOT_DEF1 = SOLN.AddTotalDeformation() +# TOT_DEF1.DisplayTime = Quantity("680 [s]") + +# EQV_STRS1 = SOLN.AddEquivalentStress() +# EQV_STRS1.DisplayTime = Quantity("680 [s]") + +# EQV_PLAS_STRN1 = SOLN.AddEquivalentPlasticStrain() +# EQV_PLAS_STRN1.DisplayTime = Quantity("680 [s]") + +# THERM_STRN1 = SOLN.AddThermalStrain() +# THERM_STRN1.DisplayTime = Quantity("680 [s]") + +# # Solve Nonlinear Static Simulation + +# SOLN.Solve(True) +# STAT_STRUC_SS = SOLN.Status + +# # Export results images + +# Tree.Activate([TOT_DEF1]) +# ExtAPI.Graphics.ViewOptions.ResultPreference.ExtraModelDisplay = ( +# Ansys.Mechanical.DataModel.MechanicalEnums.Graphics.ExtraModelDisplay.NoWireframe +# ) +# ExtAPI.Graphics.ExportImage( +# os.path.join(project_directory, "deformation.png"), image_export_format, settings_720p +# ) + +# Tree.Activate([EQV_STRS1]) +# ExtAPI.Graphics.ExportImage( +# os.path.join(project_directory, "stress.png"), image_export_format, settings_720p +# ) + +# Tree.Activate([EQV_PLAS_STRN1]) +# ExtAPI.Graphics.ExportImage( +# os.path.join(project_directory, "plastic_strain.png"), image_export_format, settings_720p +# ) +# """ +# ) +# mechanical.download(files=os.path.join(project_directory, "deformation.png"), target_dir=OUTPUT_DIR) +# mechanical.download(files=os.path.join(project_directory, "stress.png"), target_dir=OUTPUT_DIR) +# mechanical.download( +# files=os.path.join(project_directory, "plastic_strain.png"), target_dir=OUTPUT_DIR +# ) + +# # Display the resilts +# if GRAPHICS_BOOL: +# display_image("deformation.png") +# display_image("stress.png") +# display_image("plastic_strain.png") + +# ############################################################################### +# # Close the Mechanical +# # -------------------- +# # mechanical.exit() From 0ecdb375d287201d986a137246011e2865aa8d9d Mon Sep 17 00:00:00 2001 From: dkunhamb Date: Tue, 21 Jan 2025 23:14:49 -0600 Subject: [PATCH 55/68] add prints and rectify name --- fluent-mechanical/wf_fm_02_mechanical.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/fluent-mechanical/wf_fm_02_mechanical.py b/fluent-mechanical/wf_fm_02_mechanical.py index de914829..7d369691 100644 --- a/fluent-mechanical/wf_fm_02_mechanical.py +++ b/fluent-mechanical/wf_fm_02_mechanical.py @@ -179,14 +179,14 @@ def display_image(image_name): # Import material, assign it to the bodies and create Named Selections # -------------------------------------------------------------------- # - +print("Importing material and creating Named Selections") mechanical.run_python_script( """ materials = ExtAPI.DataModel.Project.Model.Materials materials.Import(material_path) materials.RefreshMaterials() -PRT1 = [x for x in ExtAPI.DataModel.Tree.AllObjects if x.Name == "Geom-2\Geom-1\solid"][0] +PRT1 = [x for x in ExtAPI.DataModel.Tree.AllObjects if x.Name == r"Geom-2\Geom-1\solid"][0] # Assign it to the bodies nmat = "1_HiSi_Model3_Exhaust Manifold updated" @@ -224,7 +224,7 @@ def display_image(image_name): # Set up the mesh and generate # ---------------------------- # - +print("Setting up the mesh and generating it") mechanical.run_python_script( """ MESH = Model.Mesh From 1a2387da94a551cd2915b568342de750d4c228c7 Mon Sep 17 00:00:00 2001 From: dkunhamb Date: Tue, 21 Jan 2025 23:18:57 -0600 Subject: [PATCH 56/68] display image conditionally --- fluent-mechanical/wf_fm_02_mechanical.py | 906 ++++++++++++----------- 1 file changed, 455 insertions(+), 451 deletions(-) diff --git a/fluent-mechanical/wf_fm_02_mechanical.py b/fluent-mechanical/wf_fm_02_mechanical.py index 7d369691..5901d638 100644 --- a/fluent-mechanical/wf_fm_02_mechanical.py +++ b/fluent-mechanical/wf_fm_02_mechanical.py @@ -171,15 +171,17 @@ def display_image(image_name): ) """ ) + +# Download the image and display it mechanical.download(files=os.path.join(project_directory, "geometry.png"), target_dir=OUTPUT_DIR) -display_image("geometry.png") +if GRAPHICS_BOOL: + display_image("geometry.png") ############################################################################### # Import material, assign it to the bodies and create Named Selections # -------------------------------------------------------------------- # -print("Importing material and creating Named Selections") mechanical.run_python_script( """ materials = ExtAPI.DataModel.Project.Model.Materials @@ -224,7 +226,6 @@ def display_image(image_name): # Set up the mesh and generate # ---------------------------- # -print("Setting up the mesh and generating it") mechanical.run_python_script( """ MESH = Model.Mesh @@ -254,469 +255,472 @@ def display_image(image_name): ) """ ) + +# Download the image and display it mechanical.download(files=os.path.join(project_directory, "mesh.png"), target_dir=OUTPUT_DIR) -display_image("mesh.png") +if GRAPHICS_BOOL: + display_image("mesh.png") -# ############################################################################### -# # Add Transient Thermal Analysis and set up the analysis settings -# # --------------------------------------------------------------- -# # +############################################################################### +# Add Transient Thermal Analysis and set up the analysis settings +# --------------------------------------------------------------- +# -# mechanical.run_python_script( -# """ -# Model.AddTransientThermalAnalysis() - -# # Store all main tree nodes as variables -# TRANS_THERM = Model.Analyses[0] -# TRANS_THERM_SOLN = TRANS_THERM.Solution -# ANA_SETTINGS = TRANS_THERM.Children[1] -# #ANA_SETTINGS = ExtAPI.DataModel.Project.Model.Analyses[0].AnalysisSettings - -# # Setup transient thermal analysis settings -# #ANA_SETTINGS.AutomaticTimeStepping = AutomaticTimeStepping.On -# ANA_SETTINGS.SolverType = SolverType.Direct -# ANA_SETTINGS.NonLinearFormulation = NonLinearFormulationType.Full - -# ANA_SETTINGS.NumberOfSteps = 1 -# ANA_SETTINGS.SetStepEndTime(1, Quantity('720[s]')) -# ANA_SETTINGS.NumberOfSteps = 14 -# analysis_step = ( -# (1, Quantity('1e-3[s]')), -# (2, Quantity('2e-3[s]')), -# (3, Quantity('20[s]')), -# (4, Quantity('30[s]')), -# (5, Quantity('320[s]')), -# (6, Quantity('330[s]')), -# (7, Quantity('350[s]')), -# (8, Quantity('360[s]')), -# (9, Quantity('380[s]')), -# (10, Quantity('390[s]')), -# (11, Quantity('680[s]')), -# (12, Quantity('690[s]')), -# (13, Quantity('710[s]')), -# (14, Quantity('720[s]')) -# ) -# for i, q in analysis_step: -# ANA_SETTINGS.SetStepEndTime(i,q) -# ANA_SETTINGS.Activate() - -# External_Convection_Load_1 = TRANS_THERM.AddConvection() -# selection = NS_GRP.Children[8] -# External_Convection_Load_1.Location = selection - -# External_Convection_Load_1.FilmCoefficient.Inputs[0].DiscreteValues=[Quantity('0[s]'),Quantity('1e-3[s]'), \ -# Quantity('2e-3[s]'),Quantity('20[s]'),Quantity('30[s]'),Quantity('320[s]'),Quantity('330[s]'), \ -# Quantity('350[s]'),Quantity('360[s]'),Quantity('380[s]'),Quantity('390[s]'),Quantity('680[s]'), \ -# Quantity('690[s]'),Quantity('710[s]'),Quantity('720[s]')] - -# External_Convection_Load_1.FilmCoefficient.Output.DiscreteValues=[Quantity('60[W m^-1 m^-1 K^-1]'), \ -# Quantity('60[W m^-1 m^-1 K^-1]'), Quantity('60[W m^-1 m^-1 K^-1]'), Quantity('60[W m^-1 m^-1 K^-1]'), \ -# Quantity('60[W m^-1 m^-1 K^-1]'), Quantity('60[W m^-1 m^-1 K^-1]'), Quantity('60[W m^-1 m^-1 K^-1]'), \ -# Quantity('60[W m^-1 m^-1 K^-1]'), Quantity('60[W m^-1 m^-1 K^-1]'), Quantity('60[W m^-1 m^-1 K^-1]'), \ -# Quantity('60[W m^-1 m^-1 K^-1]'), Quantity('60[W m^-1 m^-1 K^-1]'), Quantity('60[W m^-1 m^-1 K^-1]'), \ -# Quantity('60[W m^-1 m^-1 K^-1]'),Quantity('60[W m^-1 m^-1 K^-1]')] - -# External_Convection_Load_1.AmbientTemperature.Inputs[0].DiscreteValues=[Quantity('0[s]'),Quantity('1e-3[s]'), \ -# Quantity('2e-3[s]'),Quantity('20[s]'),Quantity('30[s]'),Quantity('320[s]'),Quantity('330[s]'), \ -# Quantity('350[s]'),Quantity('360[s]'),Quantity('380[s]'),Quantity('390[s]'),Quantity('680[s]'), \ -# Quantity('690[s]'),Quantity('710[s]'),Quantity('720[s]')] - -# External_Convection_Load_1.AmbientTemperature.Output.DiscreteValues=[Quantity('473.15[K]'), Quantity('473.15[K]'), \ -# Quantity('473.15[K]'), Quantity('473.15[K]'),Quantity('473.15[K]'),Quantity('473.15[K]'), \ -# Quantity('473.15[K]'), Quantity('473.15[K]'),Quantity('473.15[K]'),Quantity('473.15[K]'), \ -# Quantity('473.15[K]'), Quantity('473.15[K]'),Quantity('473.15[K]'),Quantity('473.15[K]'),Quantity('473.15[K]')] - - -# External_Convection_Load_2 = TRANS_THERM.AddConvection() -# selection = NS_GRP.Children[7] -# External_Convection_Load_2.Location = selection - -# External_Convection_Load_2.FilmCoefficient.Inputs[0].DiscreteValues=[Quantity('0[s]'),Quantity('1e-3[s]'), \ -# Quantity('2e-3[s]'),Quantity('20[s]'),Quantity('30[s]'),Quantity('320[s]'),Quantity('330[s]'), \ -# Quantity('350[s]'),Quantity('360[s]'),Quantity('380[s]'),Quantity('390[s]'),Quantity('680[s]'), \ -# Quantity('690[s]'),Quantity('710[s]'),Quantity('720[s]')] - -# External_Convection_Load_2.FilmCoefficient.Output.DiscreteValues=[Quantity('20[W m^-1 m^-1 K^-1]'), \ -# Quantity('20[W m^-1 m^-1 K^-1]'), Quantity('20[W m^-1 m^-1 K^-1]'), Quantity('20[W m^-1 m^-1 K^-1]'), \ -# Quantity('20[W m^-1 m^-1 K^-1]'), Quantity('20[W m^-1 m^-1 K^-1]'), Quantity('20[W m^-1 m^-1 K^-1]'), \ -# Quantity('20[W m^-1 m^-1 K^-1]'), Quantity('20[W m^-1 m^-1 K^-1]'), Quantity('20[W m^-1 m^-1 K^-1]'), \ -# Quantity('20[W m^-1 m^-1 K^-1]'),Quantity('20[W m^-1 m^-1 K^-1]'),Quantity('20[W m^-1 m^-1 K^-1]'), \ -# Quantity('20[W m^-1 m^-1 K^-1]'),Quantity('20[W m^-1 m^-1 K^-1]')] - -# External_Convection_Load_2.AmbientTemperature.Inputs[0].DiscreteValues=[Quantity('0[s]'),Quantity('1e-3[s]'), \ -# Quantity('2e-3[s]'),Quantity('20[s]'),Quantity('30[s]'),Quantity('320[s]'),Quantity('330[s]'), \ -# Quantity('350[s]'),Quantity('360[s]'),Quantity('380[s]'),Quantity('390[s]'),Quantity('680[s]'), \ -# Quantity('690[s]'),Quantity('710[s]'),Quantity('720[s]')] - -# External_Convection_Load_2.AmbientTemperature.Output.DiscreteValues=[Quantity('498.15[K]'), Quantity('498.15[K]'), \ -# Quantity('498.15[K]'), Quantity('498.15[K]'),Quantity('498.15[K]'),Quantity('498.15[K]'),Quantity('498.15[K]'), \ -# Quantity('498.15[K]'), Quantity('498.15[K]'),Quantity('498.15[K]'),Quantity('498.15[K]'),Quantity('498.15[K]'), \ -# Quantity('498.15[K]'), Quantity('498.15[K]'), Quantity('498.15[K]')] - - - -# External_Convection_Load_3 = TRANS_THERM.AddConvection() -# selection = NS_GRP.Children[6] -# External_Convection_Load_3.Location = selection - -# External_Convection_Load_3.FilmCoefficient.Inputs[0].DiscreteValues=[Quantity('0[s]'),Quantity('1e-3[s]'), \ -# Quantity('2e-3[s]'),Quantity('20[s]'),Quantity('30[s]'),Quantity('320[s]'),Quantity('330[s]'), \ -# Quantity('350[s]'),Quantity('360[s]'),Quantity('380[s]'),Quantity('390[s]'),Quantity('680[s]'), \ -# Quantity('690[s]'),Quantity('710[s]'),Quantity('720[s]')] - -# External_Convection_Load_3.FilmCoefficient.Output.DiscreteValues=[Quantity('500[W m^-1 m^-1 K^-1]'), \ -# Quantity('500[W m^-1 m^-1 K^-1]'), Quantity('500[W m^-1 m^-1 K^-1]'), Quantity('500[W m^-1 m^-1 K^-1]'), \ -# Quantity('500[W m^-1 m^-1 K^-1]'), Quantity('500[W m^-1 m^-1 K^-1]'), Quantity('500[W m^-1 m^-1 K^-1]'), \ -# Quantity('500[W m^-1 m^-1 K^-1]'), Quantity('500[W m^-1 m^-1 K^-1]'), Quantity('500[W m^-1 m^-1 K^-1]'), \ -# Quantity('500[W m^-1 m^-1 K^-1]'),Quantity('500[W m^-1 m^-1 K^-1]'),Quantity('500[W m^-1 m^-1 K^-1]'), \ -# Quantity('500[W m^-1 m^-1 K^-1]'),Quantity('500[W m^-1 m^-1 K^-1]')] - -# External_Convection_Load_3.AmbientTemperature.Inputs[0].DiscreteValues=[Quantity('0[s]'),Quantity('1e-3[s]'), \ -# Quantity('2e-3[s]'),Quantity('20[s]'),Quantity('30[s]'),Quantity('320[s]'),Quantity('330[s]'), \ -# Quantity('350[s]'),Quantity('360[s]'),Quantity('380[s]'),Quantity('390[s]'),Quantity('680[s]'), \ -# Quantity('690[s]'),Quantity('710[s]'),Quantity('720[s]')] - -# External_Convection_Load_3.AmbientTemperature.Output.DiscreteValues=[Quantity('373.15[K]'), Quantity('373.15[K]'), \ -# Quantity('373.15[K]'), Quantity('373.15[K]'),Quantity('373.15[K]'),Quantity('373.15[K]'),Quantity('373.15[K]'), \ -# Quantity('373.15[K]'), Quantity('373.15[K]'),Quantity('373.15[K]'),Quantity('373.15[K]'),Quantity('373.15[K]'), \ -# Quantity('373.15[K]'), Quantity('373.15[K]'), Quantity('373.15[K]')] - - - -# group_list = [External_Convection_Load_1,External_Convection_Load_2,External_Convection_Load_3] -# grouping_folder = Tree.Group(group_list) -# tree_grouping_folder_70 = DataModel.GetObjectsByName("New Folder") -# """ -# ) +mechanical.run_python_script( + """ +Model.AddTransientThermalAnalysis() -# ############################################################################### -# # Use the ouput from Fluent to import the temperature and HTC data -# # --------------------------------------------------------------- -# # +# Store all main tree nodes as variables +TRANS_THERM = Model.Analyses[0] +TRANS_THERM_SOLN = TRANS_THERM.Solution +ANA_SETTINGS = TRANS_THERM.Children[1] +#ANA_SETTINGS = ExtAPI.DataModel.Project.Model.Analyses[0].AnalysisSettings + +# Setup transient thermal analysis settings +#ANA_SETTINGS.AutomaticTimeStepping = AutomaticTimeStepping.On +ANA_SETTINGS.SolverType = SolverType.Direct +ANA_SETTINGS.NonLinearFormulation = NonLinearFormulationType.Full + +ANA_SETTINGS.NumberOfSteps = 1 +ANA_SETTINGS.SetStepEndTime(1, Quantity('720[s]')) +ANA_SETTINGS.NumberOfSteps = 14 +analysis_step = ( + (1, Quantity('1e-3[s]')), + (2, Quantity('2e-3[s]')), + (3, Quantity('20[s]')), + (4, Quantity('30[s]')), + (5, Quantity('320[s]')), + (6, Quantity('330[s]')), + (7, Quantity('350[s]')), + (8, Quantity('360[s]')), + (9, Quantity('380[s]')), + (10, Quantity('390[s]')), + (11, Quantity('680[s]')), + (12, Quantity('690[s]')), + (13, Quantity('710[s]')), + (14, Quantity('720[s]')) +) +for i, q in analysis_step: + ANA_SETTINGS.SetStepEndTime(i,q) +ANA_SETTINGS.Activate() + +External_Convection_Load_1 = TRANS_THERM.AddConvection() +selection = NS_GRP.Children[8] +External_Convection_Load_1.Location = selection + +External_Convection_Load_1.FilmCoefficient.Inputs[0].DiscreteValues=[Quantity('0[s]'),Quantity('1e-3[s]'), \ + Quantity('2e-3[s]'),Quantity('20[s]'),Quantity('30[s]'),Quantity('320[s]'),Quantity('330[s]'), \ + Quantity('350[s]'),Quantity('360[s]'),Quantity('380[s]'),Quantity('390[s]'),Quantity('680[s]'), \ + Quantity('690[s]'),Quantity('710[s]'),Quantity('720[s]')] + +External_Convection_Load_1.FilmCoefficient.Output.DiscreteValues=[Quantity('60[W m^-1 m^-1 K^-1]'), \ + Quantity('60[W m^-1 m^-1 K^-1]'), Quantity('60[W m^-1 m^-1 K^-1]'), Quantity('60[W m^-1 m^-1 K^-1]'), \ + Quantity('60[W m^-1 m^-1 K^-1]'), Quantity('60[W m^-1 m^-1 K^-1]'), Quantity('60[W m^-1 m^-1 K^-1]'), \ + Quantity('60[W m^-1 m^-1 K^-1]'), Quantity('60[W m^-1 m^-1 K^-1]'), Quantity('60[W m^-1 m^-1 K^-1]'), \ + Quantity('60[W m^-1 m^-1 K^-1]'), Quantity('60[W m^-1 m^-1 K^-1]'), Quantity('60[W m^-1 m^-1 K^-1]'), \ + Quantity('60[W m^-1 m^-1 K^-1]'),Quantity('60[W m^-1 m^-1 K^-1]')] + +External_Convection_Load_1.AmbientTemperature.Inputs[0].DiscreteValues=[Quantity('0[s]'),Quantity('1e-3[s]'), \ + Quantity('2e-3[s]'),Quantity('20[s]'),Quantity('30[s]'),Quantity('320[s]'),Quantity('330[s]'), \ + Quantity('350[s]'),Quantity('360[s]'),Quantity('380[s]'),Quantity('390[s]'),Quantity('680[s]'), \ + Quantity('690[s]'),Quantity('710[s]'),Quantity('720[s]')] + +External_Convection_Load_1.AmbientTemperature.Output.DiscreteValues=[Quantity('473.15[K]'), Quantity('473.15[K]'), \ + Quantity('473.15[K]'), Quantity('473.15[K]'),Quantity('473.15[K]'),Quantity('473.15[K]'), \ + Quantity('473.15[K]'), Quantity('473.15[K]'),Quantity('473.15[K]'),Quantity('473.15[K]'), \ + Quantity('473.15[K]'), Quantity('473.15[K]'),Quantity('473.15[K]'),Quantity('473.15[K]'),Quantity('473.15[K]')] + + +External_Convection_Load_2 = TRANS_THERM.AddConvection() +selection = NS_GRP.Children[7] +External_Convection_Load_2.Location = selection + +External_Convection_Load_2.FilmCoefficient.Inputs[0].DiscreteValues=[Quantity('0[s]'),Quantity('1e-3[s]'), \ + Quantity('2e-3[s]'),Quantity('20[s]'),Quantity('30[s]'),Quantity('320[s]'),Quantity('330[s]'), \ + Quantity('350[s]'),Quantity('360[s]'),Quantity('380[s]'),Quantity('390[s]'),Quantity('680[s]'), \ + Quantity('690[s]'),Quantity('710[s]'),Quantity('720[s]')] + +External_Convection_Load_2.FilmCoefficient.Output.DiscreteValues=[Quantity('20[W m^-1 m^-1 K^-1]'), \ + Quantity('20[W m^-1 m^-1 K^-1]'), Quantity('20[W m^-1 m^-1 K^-1]'), Quantity('20[W m^-1 m^-1 K^-1]'), \ + Quantity('20[W m^-1 m^-1 K^-1]'), Quantity('20[W m^-1 m^-1 K^-1]'), Quantity('20[W m^-1 m^-1 K^-1]'), \ + Quantity('20[W m^-1 m^-1 K^-1]'), Quantity('20[W m^-1 m^-1 K^-1]'), Quantity('20[W m^-1 m^-1 K^-1]'), \ + Quantity('20[W m^-1 m^-1 K^-1]'),Quantity('20[W m^-1 m^-1 K^-1]'),Quantity('20[W m^-1 m^-1 K^-1]'), \ + Quantity('20[W m^-1 m^-1 K^-1]'),Quantity('20[W m^-1 m^-1 K^-1]')] + +External_Convection_Load_2.AmbientTemperature.Inputs[0].DiscreteValues=[Quantity('0[s]'),Quantity('1e-3[s]'), \ + Quantity('2e-3[s]'),Quantity('20[s]'),Quantity('30[s]'),Quantity('320[s]'),Quantity('330[s]'), \ + Quantity('350[s]'),Quantity('360[s]'),Quantity('380[s]'),Quantity('390[s]'),Quantity('680[s]'), \ + Quantity('690[s]'),Quantity('710[s]'),Quantity('720[s]')] + +External_Convection_Load_2.AmbientTemperature.Output.DiscreteValues=[Quantity('498.15[K]'), Quantity('498.15[K]'), \ + Quantity('498.15[K]'), Quantity('498.15[K]'),Quantity('498.15[K]'),Quantity('498.15[K]'),Quantity('498.15[K]'), \ + Quantity('498.15[K]'), Quantity('498.15[K]'),Quantity('498.15[K]'),Quantity('498.15[K]'),Quantity('498.15[K]'), \ + Quantity('498.15[K]'), Quantity('498.15[K]'), Quantity('498.15[K]')] + + + +External_Convection_Load_3 = TRANS_THERM.AddConvection() +selection = NS_GRP.Children[6] +External_Convection_Load_3.Location = selection + +External_Convection_Load_3.FilmCoefficient.Inputs[0].DiscreteValues=[Quantity('0[s]'),Quantity('1e-3[s]'), \ + Quantity('2e-3[s]'),Quantity('20[s]'),Quantity('30[s]'),Quantity('320[s]'),Quantity('330[s]'), \ + Quantity('350[s]'),Quantity('360[s]'),Quantity('380[s]'),Quantity('390[s]'),Quantity('680[s]'), \ + Quantity('690[s]'),Quantity('710[s]'),Quantity('720[s]')] + +External_Convection_Load_3.FilmCoefficient.Output.DiscreteValues=[Quantity('500[W m^-1 m^-1 K^-1]'), \ + Quantity('500[W m^-1 m^-1 K^-1]'), Quantity('500[W m^-1 m^-1 K^-1]'), Quantity('500[W m^-1 m^-1 K^-1]'), \ + Quantity('500[W m^-1 m^-1 K^-1]'), Quantity('500[W m^-1 m^-1 K^-1]'), Quantity('500[W m^-1 m^-1 K^-1]'), \ + Quantity('500[W m^-1 m^-1 K^-1]'), Quantity('500[W m^-1 m^-1 K^-1]'), Quantity('500[W m^-1 m^-1 K^-1]'), \ + Quantity('500[W m^-1 m^-1 K^-1]'),Quantity('500[W m^-1 m^-1 K^-1]'),Quantity('500[W m^-1 m^-1 K^-1]'), \ + Quantity('500[W m^-1 m^-1 K^-1]'),Quantity('500[W m^-1 m^-1 K^-1]')] + +External_Convection_Load_3.AmbientTemperature.Inputs[0].DiscreteValues=[Quantity('0[s]'),Quantity('1e-3[s]'), \ + Quantity('2e-3[s]'),Quantity('20[s]'),Quantity('30[s]'),Quantity('320[s]'),Quantity('330[s]'), \ + Quantity('350[s]'),Quantity('360[s]'),Quantity('380[s]'),Quantity('390[s]'),Quantity('680[s]'), \ + Quantity('690[s]'),Quantity('710[s]'),Quantity('720[s]')] + +External_Convection_Load_3.AmbientTemperature.Output.DiscreteValues=[Quantity('373.15[K]'), Quantity('373.15[K]'), \ + Quantity('373.15[K]'), Quantity('373.15[K]'),Quantity('373.15[K]'),Quantity('373.15[K]'),Quantity('373.15[K]'), \ + Quantity('373.15[K]'), Quantity('373.15[K]'),Quantity('373.15[K]'),Quantity('373.15[K]'),Quantity('373.15[K]'), \ + Quantity('373.15[K]'), Quantity('373.15[K]'), Quantity('373.15[K]')] + + + +group_list = [External_Convection_Load_1,External_Convection_Load_2,External_Convection_Load_3] +grouping_folder = Tree.Group(group_list) +tree_grouping_folder_70 = DataModel.GetObjectsByName("New Folder") +""" +) -# result = mechanical.run_python_script( -# """ -# Imported_Load_Group = TRANS_THERM.AddImportedLoadExternalData() -# imported_load_group_61=Imported_Load_Group -# imported_convection_62 = Imported_Load_Group.AddImportedConvection() -# """ -# ) -# result = mechanical.run_python_script( -# """ -# external_data_files = Ansys.Mechanical.ExternalData.ExternalDataFileCollection() -# external_data_files.SaveFilesWithProject = False -# external_data_file_1 = Ansys.Mechanical.ExternalData.ExternalDataFile() -# external_data_files.Add(external_data_file_1) -# external_data_file_1.Identifier = "File1" -# external_data_file_1.Description = "High" -# external_data_file_1.IsMainFile = True -# external_data_file_1.FilePath= temp_htc_data_high_path -# external_data_file_1.ImportSettings = Ansys.Mechanical.ExternalData.ImportSettingsFactory.GetSettingsForFormat(MechanicalEnums.ExternalData.ImportFormat.Delimited) -# import_settings = external_data_file_1.ImportSettings -# import_settings.SkipRows = 1 -# import_settings.SkipFooter = 0 -# import_settings.Delimiter = "," -# import_settings.AverageCornerNodesToMidsideNodes = False -# import_settings.UseColumn(0, MechanicalEnums.ExternalData.VariableType.NodeId, "", "Node ID@A") -# import_settings.UseColumn(1, MechanicalEnums.ExternalData.VariableType.XCoordinate, "m", "X Coordinate@B") -# import_settings.UseColumn(2, MechanicalEnums.ExternalData.VariableType.YCoordinate, "m", "Y Coordinate@C") -# import_settings.UseColumn(3, MechanicalEnums.ExternalData.VariableType.ZCoordinate, "m", "Z Coordinate@D") -# import_settings.UseColumn(4, MechanicalEnums.ExternalData.VariableType.Temperature, "K", "Temperature@E") -# import_settings.UseColumn(5, MechanicalEnums.ExternalData.VariableType.HeatTransferCoefficient, "W m^-2 K^-1", "Heat Transfer Coefficient@F") -# external_data_file_2 = Ansys.Mechanical.ExternalData.ExternalDataFile() -# external_data_files.Add(external_data_file_2) -# external_data_file_2.Identifier = "File2" -# external_data_file_2.Description = "Med" -# external_data_file_2.IsMainFile = False -# external_data_file_2.FilePath= temp_htc_data_med_path -# external_data_file_2.ImportSettings = Ansys.Mechanical.ExternalData.ImportSettingsFactory.GetSettingsForFormat(MechanicalEnums.ExternalData.ImportFormat.Delimited) -# import_settings = external_data_file_2.ImportSettings -# import_settings.SkipRows = 1 -# import_settings.SkipFooter = 0 -# import_settings.Delimiter = "," -# import_settings.AverageCornerNodesToMidsideNodes = False -# import_settings.UseColumn(0, MechanicalEnums.ExternalData.VariableType.NodeId, "", "Node ID@A") -# import_settings.UseColumn(1, MechanicalEnums.ExternalData.VariableType.XCoordinate, "m", "X Coordinate@B") -# import_settings.UseColumn(2, MechanicalEnums.ExternalData.VariableType.YCoordinate, "m", "Y Coordinate@C") -# import_settings.UseColumn(3, MechanicalEnums.ExternalData.VariableType.ZCoordinate, "m", "Z Coordinate@D") -# import_settings.UseColumn(4, MechanicalEnums.ExternalData.VariableType.Temperature, "K", "Temperature@E") -# import_settings.UseColumn(5, MechanicalEnums.ExternalData.VariableType.HeatTransferCoefficient, "W m^-2 K^-1", "Heat Transfer Coefficient@F") -# external_data_file_3 = Ansys.Mechanical.ExternalData.ExternalDataFile() -# external_data_files.Add(external_data_file_3) -# external_data_file_3.Identifier = "File3" -# external_data_file_3.Description = "Low" -# external_data_file_3.IsMainFile = False -# external_data_file_3.FilePath= temp_htc_data_low_path -# external_data_file_3.ImportSettings = Ansys.Mechanical.ExternalData.ImportSettingsFactory.GetSettingsForFormat(MechanicalEnums.ExternalData.ImportFormat.Delimited) -# import_settings = external_data_file_3.ImportSettings -# import_settings.SkipRows = 1 -# import_settings.SkipFooter = 0 -# import_settings.Delimiter = "," -# import_settings.AverageCornerNodesToMidsideNodes = False -# import_settings.UseColumn(0, MechanicalEnums.ExternalData.VariableType.NodeId, "", "Node ID@A") -# import_settings.UseColumn(1, MechanicalEnums.ExternalData.VariableType.XCoordinate, "m", "X Coordinate@B") -# import_settings.UseColumn(2, MechanicalEnums.ExternalData.VariableType.YCoordinate, "m", "Y Coordinate@C") -# import_settings.UseColumn(3, MechanicalEnums.ExternalData.VariableType.ZCoordinate, "m", "Z Coordinate@D") -# import_settings.UseColumn(4, MechanicalEnums.ExternalData.VariableType.Temperature, "K", "Temperature@E") -# import_settings.UseColumn(5, MechanicalEnums.ExternalData.VariableType.HeatTransferCoefficient, "W m^-2 K^-1", "Heat Transfer Coefficient@F") - -# imported_load_group_61.ImportExternalDataFiles(external_data_files) -# """ -# ) - -# result = mechanical.run_python_script( -# """ -# table = imported_load_group_61.Children[0].GetTableByName("Film Coefficient") -# numofsteps = 15 -# Film_Coeff = ["File1:Heat Transfer Coefficient@F","File2:Heat Transfer Coefficient@F","File3:Heat Transfer Coefficient@F"] -# Amb_Temp = ["File1:Temperature@E","File2:Temperature@E","File3:Temperature@E"] -# Ana_time = ["0","1e-3","2e-3","20","30","320","330","350","360","380","390","680","690","710","720"] - -# for i in range(numofsteps-1): -# table.Add(None) - -# table[0][0] = Film_Coeff[2] -# table[0][1] = Amb_Temp[2] -# table[0][2] = Ana_time[0] - -# table[1][0] = Film_Coeff[2] -# table[1][1] = Amb_Temp[2] -# table[1][2] = Ana_time[1] - -# table[2][0] = Film_Coeff[2] -# table[2][1] = Amb_Temp[2] -# table[2][2] = Ana_time[2] - -# table[3][0] = Film_Coeff[2] -# table[3][1] = Amb_Temp[2] -# table[3][2] = Ana_time[3] - -# table[4][0] = Film_Coeff[0] -# table[4][1] = Amb_Temp[0] -# table[4][2] = Ana_time[4] - -# table[5][0] = Film_Coeff[0] -# table[5][1] = Amb_Temp[0] -# table[5][2] = Ana_time[5] - -# table[6][0] = Film_Coeff[1] -# table[6][1] = Amb_Temp[1] -# table[6][2] = Ana_time[6] - -# table[7][0] = Film_Coeff[1] -# table[7][1] = Amb_Temp[1] -# table[7][2] = Ana_time[7] - -# table[8][0] = Film_Coeff[2] -# table[8][1] = Amb_Temp[2] -# table[8][2] = Ana_time[8] - -# table[9][0] = Film_Coeff[2] -# table[9][1] = Amb_Temp[2] -# table[9][2] = Ana_time[9] - -# table[10][0] = Film_Coeff[0] -# table[10][1] = Amb_Temp[0] -# table[10][2] = Ana_time[10] - -# table[11][0] = Film_Coeff[0] -# table[11][1] = Amb_Temp[0] -# table[11][2] = Ana_time[11] - -# table[12][0] = Film_Coeff[1] -# table[12][1] = Amb_Temp[1] -# table[12][2] = Ana_time[12] - -# table[13][0] = Film_Coeff[1] -# table[13][1] = Amb_Temp[1] -# table[13][2] = Ana_time[13] - -# table[14][0] = Film_Coeff[2] -# table[14][1] = Amb_Temp[2] -# table[14][2] = Ana_time[14] - -# selection = NS_GRP.Children[4] -# imported_convection_62.Location = selection -# imported_load_id = imported_convection_62.ObjectId -# imported_load = DataModel.GetObjectById(imported_load_id) -# """ -# ) -# # !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -# # imported_convection_62.InternalObject.ExternalLoadSteppingType = 1 -# # !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -# mechanical.run_python_script( -# """ -# imported_load.ImportLoad() - -# Tree.Activate([imported_load]) -# ExtAPI.Graphics.Camera.SetFit() -# ExtAPI.Graphics.ExportImage( -# os.path.join(project_directory, "imported_temperature.png"), image_export_format, settings_720p -# ) -# """ -# ) -# mechanical.download( -# files=os.path.join(project_directory, "imported_temperature.png"), target_dir=OUTPUT_DIR -# ) -# if GRAPHICS_BOOL: -# display_image("imported_temperature.png") +############################################################################### +# Use the ouput from Fluent to import the temperature and HTC data +# --------------------------------------------------------------- +# -# ############################################################################### -# # Solve and post-process the results -# # ---------------------------------- +result = mechanical.run_python_script( + """ +Imported_Load_Group = TRANS_THERM.AddImportedLoadExternalData() +imported_load_group_61=Imported_Load_Group +imported_convection_62 = Imported_Load_Group.AddImportedConvection() +""" +) +result = mechanical.run_python_script( + """ +external_data_files = Ansys.Mechanical.ExternalData.ExternalDataFileCollection() +external_data_files.SaveFilesWithProject = False +external_data_file_1 = Ansys.Mechanical.ExternalData.ExternalDataFile() +external_data_files.Add(external_data_file_1) +external_data_file_1.Identifier = "File1" +external_data_file_1.Description = "High" +external_data_file_1.IsMainFile = True +external_data_file_1.FilePath= temp_htc_data_high_path +external_data_file_1.ImportSettings = Ansys.Mechanical.ExternalData.ImportSettingsFactory.GetSettingsForFormat(MechanicalEnums.ExternalData.ImportFormat.Delimited) +import_settings = external_data_file_1.ImportSettings +import_settings.SkipRows = 1 +import_settings.SkipFooter = 0 +import_settings.Delimiter = "," +import_settings.AverageCornerNodesToMidsideNodes = False +import_settings.UseColumn(0, MechanicalEnums.ExternalData.VariableType.NodeId, "", "Node ID@A") +import_settings.UseColumn(1, MechanicalEnums.ExternalData.VariableType.XCoordinate, "m", "X Coordinate@B") +import_settings.UseColumn(2, MechanicalEnums.ExternalData.VariableType.YCoordinate, "m", "Y Coordinate@C") +import_settings.UseColumn(3, MechanicalEnums.ExternalData.VariableType.ZCoordinate, "m", "Z Coordinate@D") +import_settings.UseColumn(4, MechanicalEnums.ExternalData.VariableType.Temperature, "K", "Temperature@E") +import_settings.UseColumn(5, MechanicalEnums.ExternalData.VariableType.HeatTransferCoefficient, "W m^-2 K^-1", "Heat Transfer Coefficient@F") +external_data_file_2 = Ansys.Mechanical.ExternalData.ExternalDataFile() +external_data_files.Add(external_data_file_2) +external_data_file_2.Identifier = "File2" +external_data_file_2.Description = "Med" +external_data_file_2.IsMainFile = False +external_data_file_2.FilePath= temp_htc_data_med_path +external_data_file_2.ImportSettings = Ansys.Mechanical.ExternalData.ImportSettingsFactory.GetSettingsForFormat(MechanicalEnums.ExternalData.ImportFormat.Delimited) +import_settings = external_data_file_2.ImportSettings +import_settings.SkipRows = 1 +import_settings.SkipFooter = 0 +import_settings.Delimiter = "," +import_settings.AverageCornerNodesToMidsideNodes = False +import_settings.UseColumn(0, MechanicalEnums.ExternalData.VariableType.NodeId, "", "Node ID@A") +import_settings.UseColumn(1, MechanicalEnums.ExternalData.VariableType.XCoordinate, "m", "X Coordinate@B") +import_settings.UseColumn(2, MechanicalEnums.ExternalData.VariableType.YCoordinate, "m", "Y Coordinate@C") +import_settings.UseColumn(3, MechanicalEnums.ExternalData.VariableType.ZCoordinate, "m", "Z Coordinate@D") +import_settings.UseColumn(4, MechanicalEnums.ExternalData.VariableType.Temperature, "K", "Temperature@E") +import_settings.UseColumn(5, MechanicalEnums.ExternalData.VariableType.HeatTransferCoefficient, "W m^-2 K^-1", "Heat Transfer Coefficient@F") +external_data_file_3 = Ansys.Mechanical.ExternalData.ExternalDataFile() +external_data_files.Add(external_data_file_3) +external_data_file_3.Identifier = "File3" +external_data_file_3.Description = "Low" +external_data_file_3.IsMainFile = False +external_data_file_3.FilePath= temp_htc_data_low_path +external_data_file_3.ImportSettings = Ansys.Mechanical.ExternalData.ImportSettingsFactory.GetSettingsForFormat(MechanicalEnums.ExternalData.ImportFormat.Delimited) +import_settings = external_data_file_3.ImportSettings +import_settings.SkipRows = 1 +import_settings.SkipFooter = 0 +import_settings.Delimiter = "," +import_settings.AverageCornerNodesToMidsideNodes = False +import_settings.UseColumn(0, MechanicalEnums.ExternalData.VariableType.NodeId, "", "Node ID@A") +import_settings.UseColumn(1, MechanicalEnums.ExternalData.VariableType.XCoordinate, "m", "X Coordinate@B") +import_settings.UseColumn(2, MechanicalEnums.ExternalData.VariableType.YCoordinate, "m", "Y Coordinate@C") +import_settings.UseColumn(3, MechanicalEnums.ExternalData.VariableType.ZCoordinate, "m", "Z Coordinate@D") +import_settings.UseColumn(4, MechanicalEnums.ExternalData.VariableType.Temperature, "K", "Temperature@E") +import_settings.UseColumn(5, MechanicalEnums.ExternalData.VariableType.HeatTransferCoefficient, "W m^-2 K^-1", "Heat Transfer Coefficient@F") + +imported_load_group_61.ImportExternalDataFiles(external_data_files) +""" +) -# mechanical.run_python_script( -# """ -# # Insert results objects +result = mechanical.run_python_script( + """ +table = imported_load_group_61.Children[0].GetTableByName("Film Coefficient") +numofsteps = 15 +Film_Coeff = ["File1:Heat Transfer Coefficient@F","File2:Heat Transfer Coefficient@F","File3:Heat Transfer Coefficient@F"] +Amb_Temp = ["File1:Temperature@E","File2:Temperature@E","File3:Temperature@E"] +Ana_time = ["0","1e-3","2e-3","20","30","320","330","350","360","380","390","680","690","710","720"] + +for i in range(numofsteps-1): + table.Add(None) + +table[0][0] = Film_Coeff[2] +table[0][1] = Amb_Temp[2] +table[0][2] = Ana_time[0] + +table[1][0] = Film_Coeff[2] +table[1][1] = Amb_Temp[2] +table[1][2] = Ana_time[1] + +table[2][0] = Film_Coeff[2] +table[2][1] = Amb_Temp[2] +table[2][2] = Ana_time[2] + +table[3][0] = Film_Coeff[2] +table[3][1] = Amb_Temp[2] +table[3][2] = Ana_time[3] + +table[4][0] = Film_Coeff[0] +table[4][1] = Amb_Temp[0] +table[4][2] = Ana_time[4] + +table[5][0] = Film_Coeff[0] +table[5][1] = Amb_Temp[0] +table[5][2] = Ana_time[5] + +table[6][0] = Film_Coeff[1] +table[6][1] = Amb_Temp[1] +table[6][2] = Ana_time[6] + +table[7][0] = Film_Coeff[1] +table[7][1] = Amb_Temp[1] +table[7][2] = Ana_time[7] + +table[8][0] = Film_Coeff[2] +table[8][1] = Amb_Temp[2] +table[8][2] = Ana_time[8] + +table[9][0] = Film_Coeff[2] +table[9][1] = Amb_Temp[2] +table[9][2] = Ana_time[9] + +table[10][0] = Film_Coeff[0] +table[10][1] = Amb_Temp[0] +table[10][2] = Ana_time[10] + +table[11][0] = Film_Coeff[0] +table[11][1] = Amb_Temp[0] +table[11][2] = Ana_time[11] + +table[12][0] = Film_Coeff[1] +table[12][1] = Amb_Temp[1] +table[12][2] = Ana_time[12] + +table[13][0] = Film_Coeff[1] +table[13][1] = Amb_Temp[1] +table[13][2] = Ana_time[13] + +table[14][0] = Film_Coeff[2] +table[14][1] = Amb_Temp[2] +table[14][2] = Ana_time[14] + +selection = NS_GRP.Children[4] +imported_convection_62.Location = selection +imported_load_id = imported_convection_62.ObjectId +imported_load = DataModel.GetObjectById(imported_load_id) +""" +) +# !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! +# imported_convection_62.InternalObject.ExternalLoadSteppingType = 1 +# !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! +mechanical.run_python_script( + """ +imported_load.ImportLoad() -# Temp = TRANS_THERM_SOLN.AddTemperature() -# Temp.DisplayTime = Quantity("680 [s]") +Tree.Activate([imported_load]) +ExtAPI.Graphics.Camera.SetFit() +ExtAPI.Graphics.ExportImage( + os.path.join(project_directory, "imported_temperature.png"), image_export_format, settings_720p +) +""" +) +mechanical.download( + files=os.path.join(project_directory, "imported_temperature.png"), target_dir=OUTPUT_DIR +) +if GRAPHICS_BOOL: + display_image("imported_temperature.png") -# # Run Solution: Transient Thermal Simulation +############################################################################### +# Solve and post-process the results +# ---------------------------------- -# TRANS_THERM_SOLN.Solve(True) -# TRANS_THERM_SS = TRANS_THERM_SOLN.Status +mechanical.run_python_script( + """ +# Insert results objects -# # Export temperature image +Temp = TRANS_THERM_SOLN.AddTemperature() +Temp.DisplayTime = Quantity("680 [s]") -# Tree.Activate([Temp]) -# ExtAPI.Graphics.ViewOptions.ResultPreference.ExtraModelDisplay = ( -# Ansys.Mechanical.DataModel.MechanicalEnums.Graphics.ExtraModelDisplay.NoWireframe -# ) -# ExtAPI.Graphics.ExportImage( -# os.path.join(project_directory, "temperature.png"), image_export_format, settings_720p -# ) -# """ -# ) -# mechanical.download(files=os.path.join(project_directory, "temperature.png"), target_dir=OUTPUT_DIR) -# if GRAPHICS_BOOL: -# display_image("temperature.png") +# Run Solution: Transient Thermal Simulation +TRANS_THERM_SOLN.Solve(True) +TRANS_THERM_SS = TRANS_THERM_SOLN.Status -# ############################################################################### -# # Setup Structural Analysis -# # ------------------------- -# # -# mechanical.run_python_script( -# """ -# Model.AddStaticStructuralAnalysis() - -# # Define analysis settings - -# # Setup static structural analysis settings -# STAT_STRUC = Model.Analyses[1] -# STAT_STRUC_SOLN = STAT_STRUC.Solution -# STAT_STRUC_ANA_SETTING = STAT_STRUC.Children[0] - -# STAT_STRUC_ANA_SETTING.NumberOfSteps = 1 -# STAT_STRUC_ANA_SETTING.SetStepEndTime(1, Quantity('720[s]')) -# STAT_STRUC_ANA_SETTING.NumberOfSteps = 14 - -# analysis_step = ( -# (1, Quantity('1e-3[s]')), -# (2, Quantity('2e-3[s]')), -# (3, Quantity('20[s]')), -# (4, Quantity('30[s]')), -# (5, Quantity('320[s]')), -# (6, Quantity('330[s]')), -# (7, Quantity('350[s]')), -# (8, Quantity('360[s]')), -# (9, Quantity('380[s]')), -# (10, Quantity('390[s]')), -# (11, Quantity('680[s]')), -# (12, Quantity('690[s]')), -# (13, Quantity('710[s]')), -# (14, Quantity('720[s]')) -# ) -# for i, q in analysis_step: -# STAT_STRUC_ANA_SETTING.SetStepEndTime(i,q) -# STAT_STRUC_ANA_SETTING.Activate() - - -# # Add Imported Body Temperature load from Transient Thermal Run - -# STAT_STRUC.ImportLoad(Model.Analyses[0]) -# imported_load = DataModel.GetObjectsByName("Imported Body Temperature")[0] - -# table = imported_load.GetTableByName("Source Time") -# numofsteps = 14 -# nCol = 2 -# Ana_time = ["1e-3","2e-3","20","30","320","330","350","360","380","390","680","690","710","720"] - -# for i in range(numofsteps-1): -# table.Add(None) - -# for i in range(numofsteps): -# for j in range(nCol): -# table[i][j] = Ana_time[i] - -# imported_load.ImportLoad() - -# # Apply Fixed Support Condition - -# Fixed_Support = STAT_STRUC.AddFixedSupport() -# selection = NS_GRP.Children[3] -# Fixed_Support.Location = selection -# """ -# ) +# Export temperature image -# ############################################################################### -# # Sovle and post-process the results -# # ---------------------------------- -# # -# mechanical.run_python_script( -# """ -# SOLN = STAT_STRUC.Solution - -# TOT_DEF1 = SOLN.AddTotalDeformation() -# TOT_DEF1.DisplayTime = Quantity("680 [s]") - -# EQV_STRS1 = SOLN.AddEquivalentStress() -# EQV_STRS1.DisplayTime = Quantity("680 [s]") - -# EQV_PLAS_STRN1 = SOLN.AddEquivalentPlasticStrain() -# EQV_PLAS_STRN1.DisplayTime = Quantity("680 [s]") - -# THERM_STRN1 = SOLN.AddThermalStrain() -# THERM_STRN1.DisplayTime = Quantity("680 [s]") - -# # Solve Nonlinear Static Simulation - -# SOLN.Solve(True) -# STAT_STRUC_SS = SOLN.Status - -# # Export results images - -# Tree.Activate([TOT_DEF1]) -# ExtAPI.Graphics.ViewOptions.ResultPreference.ExtraModelDisplay = ( -# Ansys.Mechanical.DataModel.MechanicalEnums.Graphics.ExtraModelDisplay.NoWireframe -# ) -# ExtAPI.Graphics.ExportImage( -# os.path.join(project_directory, "deformation.png"), image_export_format, settings_720p -# ) - -# Tree.Activate([EQV_STRS1]) -# ExtAPI.Graphics.ExportImage( -# os.path.join(project_directory, "stress.png"), image_export_format, settings_720p -# ) - -# Tree.Activate([EQV_PLAS_STRN1]) -# ExtAPI.Graphics.ExportImage( -# os.path.join(project_directory, "plastic_strain.png"), image_export_format, settings_720p -# ) -# """ -# ) -# mechanical.download(files=os.path.join(project_directory, "deformation.png"), target_dir=OUTPUT_DIR) -# mechanical.download(files=os.path.join(project_directory, "stress.png"), target_dir=OUTPUT_DIR) -# mechanical.download( -# files=os.path.join(project_directory, "plastic_strain.png"), target_dir=OUTPUT_DIR -# ) - -# # Display the resilts -# if GRAPHICS_BOOL: -# display_image("deformation.png") -# display_image("stress.png") -# display_image("plastic_strain.png") +Tree.Activate([Temp]) +ExtAPI.Graphics.ViewOptions.ResultPreference.ExtraModelDisplay = ( + Ansys.Mechanical.DataModel.MechanicalEnums.Graphics.ExtraModelDisplay.NoWireframe +) +ExtAPI.Graphics.ExportImage( + os.path.join(project_directory, "temperature.png"), image_export_format, settings_720p +) +""" +) +mechanical.download(files=os.path.join(project_directory, "temperature.png"), target_dir=OUTPUT_DIR) +if GRAPHICS_BOOL: + display_image("temperature.png") + + +############################################################################### +# Setup Structural Analysis +# ------------------------- +# +mechanical.run_python_script( + """ +Model.AddStaticStructuralAnalysis() + +# Define analysis settings + +# Setup static structural analysis settings +STAT_STRUC = Model.Analyses[1] +STAT_STRUC_SOLN = STAT_STRUC.Solution +STAT_STRUC_ANA_SETTING = STAT_STRUC.Children[0] + +STAT_STRUC_ANA_SETTING.NumberOfSteps = 1 +STAT_STRUC_ANA_SETTING.SetStepEndTime(1, Quantity('720[s]')) +STAT_STRUC_ANA_SETTING.NumberOfSteps = 14 + +analysis_step = ( + (1, Quantity('1e-3[s]')), + (2, Quantity('2e-3[s]')), + (3, Quantity('20[s]')), + (4, Quantity('30[s]')), + (5, Quantity('320[s]')), + (6, Quantity('330[s]')), + (7, Quantity('350[s]')), + (8, Quantity('360[s]')), + (9, Quantity('380[s]')), + (10, Quantity('390[s]')), + (11, Quantity('680[s]')), + (12, Quantity('690[s]')), + (13, Quantity('710[s]')), + (14, Quantity('720[s]')) +) +for i, q in analysis_step: + STAT_STRUC_ANA_SETTING.SetStepEndTime(i,q) +STAT_STRUC_ANA_SETTING.Activate() + + +# Add Imported Body Temperature load from Transient Thermal Run + +STAT_STRUC.ImportLoad(Model.Analyses[0]) +imported_load = DataModel.GetObjectsByName("Imported Body Temperature")[0] + +table = imported_load.GetTableByName("Source Time") +numofsteps = 14 +nCol = 2 +Ana_time = ["1e-3","2e-3","20","30","320","330","350","360","380","390","680","690","710","720"] + +for i in range(numofsteps-1): + table.Add(None) + +for i in range(numofsteps): + for j in range(nCol): + table[i][j] = Ana_time[i] + +imported_load.ImportLoad() + +# Apply Fixed Support Condition + +Fixed_Support = STAT_STRUC.AddFixedSupport() +selection = NS_GRP.Children[3] +Fixed_Support.Location = selection +""" +) + +############################################################################### +# Sovle and post-process the results +# ---------------------------------- +# +mechanical.run_python_script( + """ +SOLN = STAT_STRUC.Solution + +TOT_DEF1 = SOLN.AddTotalDeformation() +TOT_DEF1.DisplayTime = Quantity("680 [s]") + +EQV_STRS1 = SOLN.AddEquivalentStress() +EQV_STRS1.DisplayTime = Quantity("680 [s]") + +EQV_PLAS_STRN1 = SOLN.AddEquivalentPlasticStrain() +EQV_PLAS_STRN1.DisplayTime = Quantity("680 [s]") + +THERM_STRN1 = SOLN.AddThermalStrain() +THERM_STRN1.DisplayTime = Quantity("680 [s]") + +# Solve Nonlinear Static Simulation + +SOLN.Solve(True) +STAT_STRUC_SS = SOLN.Status + +# Export results images + +Tree.Activate([TOT_DEF1]) +ExtAPI.Graphics.ViewOptions.ResultPreference.ExtraModelDisplay = ( + Ansys.Mechanical.DataModel.MechanicalEnums.Graphics.ExtraModelDisplay.NoWireframe +) +ExtAPI.Graphics.ExportImage( + os.path.join(project_directory, "deformation.png"), image_export_format, settings_720p +) + +Tree.Activate([EQV_STRS1]) +ExtAPI.Graphics.ExportImage( + os.path.join(project_directory, "stress.png"), image_export_format, settings_720p +) + +Tree.Activate([EQV_PLAS_STRN1]) +ExtAPI.Graphics.ExportImage( + os.path.join(project_directory, "plastic_strain.png"), image_export_format, settings_720p +) +""" +) +mechanical.download(files=os.path.join(project_directory, "deformation.png"), target_dir=OUTPUT_DIR) +mechanical.download(files=os.path.join(project_directory, "stress.png"), target_dir=OUTPUT_DIR) +mechanical.download( + files=os.path.join(project_directory, "plastic_strain.png"), target_dir=OUTPUT_DIR +) + +# Display the results +if GRAPHICS_BOOL: + display_image("deformation.png") + display_image("stress.png") + display_image("plastic_strain.png") # ############################################################################### # # Close the Mechanical From ab89fba490c28e81d42a98939579081360ed8bc4 Mon Sep 17 00:00:00 2001 From: dkunhamb Date: Wed, 22 Jan 2025 09:24:45 -0600 Subject: [PATCH 57/68] fix style --- fluent-mechanical/wf_fm_02_mechanical.py | 403 +++++++++++++---------- 1 file changed, 237 insertions(+), 166 deletions(-) diff --git a/fluent-mechanical/wf_fm_02_mechanical.py b/fluent-mechanical/wf_fm_02_mechanical.py index 5901d638..3cf1c54a 100644 --- a/fluent-mechanical/wf_fm_02_mechanical.py +++ b/fluent-mechanical/wf_fm_02_mechanical.py @@ -191,12 +191,13 @@ def display_image(image_name): PRT1 = [x for x in ExtAPI.DataModel.Tree.AllObjects if x.Name == r"Geom-2\Geom-1\solid"][0] # Assign it to the bodies + nmat = "1_HiSi_Model3_Exhaust Manifold updated" PRT1.Material = nmat # Select MKS units -ExtAPI.Application.ActiveUnitSystem = (Ansys.ACT.Interfaces.Common.MechanicalUnitSystem.StandardMKS) +ExtAPI.Application.ActiveUnitSystem = MechanicalUnitSystem.StandardMKS # Store all main tree nodes as variables GEOM = Model.Geometry @@ -274,120 +275,180 @@ def display_image(image_name): TRANS_THERM = Model.Analyses[0] TRANS_THERM_SOLN = TRANS_THERM.Solution ANA_SETTINGS = TRANS_THERM.Children[1] -#ANA_SETTINGS = ExtAPI.DataModel.Project.Model.Analyses[0].AnalysisSettings +# ANA_SETTINGS = TRANS_THERM.AnalysisSettings # Setup transient thermal analysis settings -#ANA_SETTINGS.AutomaticTimeStepping = AutomaticTimeStepping.On ANA_SETTINGS.SolverType = SolverType.Direct ANA_SETTINGS.NonLinearFormulation = NonLinearFormulationType.Full ANA_SETTINGS.NumberOfSteps = 1 ANA_SETTINGS.SetStepEndTime(1, Quantity('720[s]')) ANA_SETTINGS.NumberOfSteps = 14 -analysis_step = ( - (1, Quantity('1e-3[s]')), - (2, Quantity('2e-3[s]')), - (3, Quantity('20[s]')), - (4, Quantity('30[s]')), - (5, Quantity('320[s]')), - (6, Quantity('330[s]')), - (7, Quantity('350[s]')), - (8, Quantity('360[s]')), - (9, Quantity('380[s]')), - (10, Quantity('390[s]')), - (11, Quantity('680[s]')), - (12, Quantity('690[s]')), - (13, Quantity('710[s]')), - (14, Quantity('720[s]')) +analysis_step = ( + (1, Quantity('1e-3[s]')), + (2, Quantity('2e-3[s]')), + (3, Quantity('20[s]')), + (4, Quantity('30[s]')), + (5, Quantity('320[s]')), + (6, Quantity('330[s]')), + (7, Quantity('350[s]')), + (8, Quantity('360[s]')), + (9, Quantity('380[s]')), + (10, Quantity('390[s]')), + (11, Quantity('680[s]')), + (12, Quantity('690[s]')), + (13, Quantity('710[s]')), + (14, Quantity('720[s]')) ) for i, q in analysis_step: - ANA_SETTINGS.SetStepEndTime(i,q) + ANA_SETTINGS.SetStepEndTime(i, q) ANA_SETTINGS.Activate() External_Convection_Load_1 = TRANS_THERM.AddConvection() selection = NS_GRP.Children[8] External_Convection_Load_1.Location = selection -External_Convection_Load_1.FilmCoefficient.Inputs[0].DiscreteValues=[Quantity('0[s]'),Quantity('1e-3[s]'), \ - Quantity('2e-3[s]'),Quantity('20[s]'),Quantity('30[s]'),Quantity('320[s]'),Quantity('330[s]'), \ - Quantity('350[s]'),Quantity('360[s]'),Quantity('380[s]'),Quantity('390[s]'),Quantity('680[s]'), \ - Quantity('690[s]'),Quantity('710[s]'),Quantity('720[s]')] - -External_Convection_Load_1.FilmCoefficient.Output.DiscreteValues=[Quantity('60[W m^-1 m^-1 K^-1]'), \ - Quantity('60[W m^-1 m^-1 K^-1]'), Quantity('60[W m^-1 m^-1 K^-1]'), Quantity('60[W m^-1 m^-1 K^-1]'), \ - Quantity('60[W m^-1 m^-1 K^-1]'), Quantity('60[W m^-1 m^-1 K^-1]'), Quantity('60[W m^-1 m^-1 K^-1]'), \ - Quantity('60[W m^-1 m^-1 K^-1]'), Quantity('60[W m^-1 m^-1 K^-1]'), Quantity('60[W m^-1 m^-1 K^-1]'), \ - Quantity('60[W m^-1 m^-1 K^-1]'), Quantity('60[W m^-1 m^-1 K^-1]'), Quantity('60[W m^-1 m^-1 K^-1]'), \ - Quantity('60[W m^-1 m^-1 K^-1]'),Quantity('60[W m^-1 m^-1 K^-1]')] +External_Convection_Load_1.FilmCoefficient.Inputs[0].DiscreteValues = [ + Quantity('0[s]'), Quantity('1e-3[s]'), + Quantity('2e-3[s]'), Quantity('20[s]'), + Quantity('30[s]'), Quantity('320[s]'), + Quantity('330[s]'), Quantity('350[s]'), + Quantity('360[s]'), Quantity('380[s]'), + Quantity('390[s]'), Quantity('680[s]'), + Quantity('690[s]'), Quantity('710[s]'), + Quantity('720[s]') +] -External_Convection_Load_1.AmbientTemperature.Inputs[0].DiscreteValues=[Quantity('0[s]'),Quantity('1e-3[s]'), \ - Quantity('2e-3[s]'),Quantity('20[s]'),Quantity('30[s]'),Quantity('320[s]'),Quantity('330[s]'), \ - Quantity('350[s]'),Quantity('360[s]'),Quantity('380[s]'),Quantity('390[s]'),Quantity('680[s]'), \ - Quantity('690[s]'),Quantity('710[s]'),Quantity('720[s]')] +External_Convection_Load_1.FilmCoefficient.Output.DiscreteValues = [ + Quantity('60[W m^-1 m^-1 K^-1]'), Quantity('60[W m^-1 m^-1 K^-1]'), + Quantity('60[W m^-1 m^-1 K^-1]'), Quantity('60[W m^-1 m^-1 K^-1]'), + Quantity('60[W m^-1 m^-1 K^-1]'), Quantity('60[W m^-1 m^-1 K^-1]'), + Quantity('60[W m^-1 m^-1 K^-1]'), Quantity('60[W m^-1 m^-1 K^-1]'), + Quantity('60[W m^-1 m^-1 K^-1]'), Quantity('60[W m^-1 m^-1 K^-1]'), + Quantity('60[W m^-1 m^-1 K^-1]'), Quantity('60[W m^-1 m^-1 K^-1]'), + Quantity('60[W m^-1 m^-1 K^-1]'), Quantity('60[W m^-1 m^-1 K^-1]'), + Quantity('60[W m^-1 m^-1 K^-1]') +] -External_Convection_Load_1.AmbientTemperature.Output.DiscreteValues=[Quantity('473.15[K]'), Quantity('473.15[K]'), \ - Quantity('473.15[K]'), Quantity('473.15[K]'),Quantity('473.15[K]'),Quantity('473.15[K]'), \ - Quantity('473.15[K]'), Quantity('473.15[K]'),Quantity('473.15[K]'),Quantity('473.15[K]'), \ - Quantity('473.15[K]'), Quantity('473.15[K]'),Quantity('473.15[K]'),Quantity('473.15[K]'),Quantity('473.15[K]')] +External_Convection_Load_1.AmbientTemperature.Inputs[0].DiscreteValues = [ + Quantity('0[s]'), Quantity('1e-3[s]'), + Quantity('2e-3[s]'), Quantity('20[s]'), + Quantity('30[s]'), Quantity('320[s]'), + Quantity('330[s]'), Quantity('350[s]'), + Quantity('360[s]'), Quantity('380[s]'), + Quantity('390[s]'), Quantity('680[s]'), + Quantity('690[s]'), Quantity('710[s]'), + Quantity('720[s]') +] +External_Convection_Load_1.AmbientTemperature.Output.DiscreteValues = [ + Quantity('473.15[K]'), Quantity('473.15[K]'), + Quantity('473.15[K]'), Quantity('473.15[K]'), + Quantity('473.15[K]'), Quantity('473.15[K]'), + Quantity('473.15[K]'), Quantity('473.15[K]'), + Quantity('473.15[K]'), Quantity('473.15[K]'), + Quantity('473.15[K]'), Quantity('473.15[K]'), + Quantity('473.15[K]'), Quantity('473.15[K]'), + Quantity('473.15[K]') +] External_Convection_Load_2 = TRANS_THERM.AddConvection() selection = NS_GRP.Children[7] External_Convection_Load_2.Location = selection -External_Convection_Load_2.FilmCoefficient.Inputs[0].DiscreteValues=[Quantity('0[s]'),Quantity('1e-3[s]'), \ - Quantity('2e-3[s]'),Quantity('20[s]'),Quantity('30[s]'),Quantity('320[s]'),Quantity('330[s]'), \ - Quantity('350[s]'),Quantity('360[s]'),Quantity('380[s]'),Quantity('390[s]'),Quantity('680[s]'), \ - Quantity('690[s]'),Quantity('710[s]'),Quantity('720[s]')] - -External_Convection_Load_2.FilmCoefficient.Output.DiscreteValues=[Quantity('20[W m^-1 m^-1 K^-1]'), \ - Quantity('20[W m^-1 m^-1 K^-1]'), Quantity('20[W m^-1 m^-1 K^-1]'), Quantity('20[W m^-1 m^-1 K^-1]'), \ - Quantity('20[W m^-1 m^-1 K^-1]'), Quantity('20[W m^-1 m^-1 K^-1]'), Quantity('20[W m^-1 m^-1 K^-1]'), \ - Quantity('20[W m^-1 m^-1 K^-1]'), Quantity('20[W m^-1 m^-1 K^-1]'), Quantity('20[W m^-1 m^-1 K^-1]'), \ - Quantity('20[W m^-1 m^-1 K^-1]'),Quantity('20[W m^-1 m^-1 K^-1]'),Quantity('20[W m^-1 m^-1 K^-1]'), \ - Quantity('20[W m^-1 m^-1 K^-1]'),Quantity('20[W m^-1 m^-1 K^-1]')] - -External_Convection_Load_2.AmbientTemperature.Inputs[0].DiscreteValues=[Quantity('0[s]'),Quantity('1e-3[s]'), \ - Quantity('2e-3[s]'),Quantity('20[s]'),Quantity('30[s]'),Quantity('320[s]'),Quantity('330[s]'), \ - Quantity('350[s]'),Quantity('360[s]'),Quantity('380[s]'),Quantity('390[s]'),Quantity('680[s]'), \ - Quantity('690[s]'),Quantity('710[s]'),Quantity('720[s]')] +External_Convection_Load_2.FilmCoefficient.Inputs[0].DiscreteValues = [ + Quantity('0[s]'), Quantity('1e-3[s]'), + Quantity('2e-3[s]'), Quantity('20[s]'), + Quantity('30[s]'), Quantity('320[s]'), + Quantity('330[s]'), Quantity('350[s]'), + Quantity('360[s]'), Quantity('380[s]'), + Quantity('390[s]'), Quantity('680[s]'), + Quantity('690[s]'), Quantity('710[s]'), + Quantity('720[s]') +] -External_Convection_Load_2.AmbientTemperature.Output.DiscreteValues=[Quantity('498.15[K]'), Quantity('498.15[K]'), \ - Quantity('498.15[K]'), Quantity('498.15[K]'),Quantity('498.15[K]'),Quantity('498.15[K]'),Quantity('498.15[K]'), \ - Quantity('498.15[K]'), Quantity('498.15[K]'),Quantity('498.15[K]'),Quantity('498.15[K]'),Quantity('498.15[K]'), \ - Quantity('498.15[K]'), Quantity('498.15[K]'), Quantity('498.15[K]')] +External_Convection_Load_2.FilmCoefficient.Output.DiscreteValues = [ + Quantity('20[W m^-1 m^-1 K^-1]'), Quantity('20[W m^-1 m^-1 K^-1]'), + Quantity('20[W m^-1 m^-1 K^-1]'), Quantity('20[W m^-1 m^-1 K^-1]'), + Quantity('20[W m^-1 m^-1 K^-1]'), Quantity('20[W m^-1 m^-1 K^-1]'), + Quantity('20[W m^-1 m^-1 K^-1]'), Quantity('20[W m^-1 m^-1 K^-1]'), + Quantity('20[W m^-1 m^-1 K^-1]'), Quantity('20[W m^-1 m^-1 K^-1]'), + Quantity('20[W m^-1 m^-1 K^-1]'), Quantity('20[W m^-1 m^-1 K^-1]'), + Quantity('20[W m^-1 m^-1 K^-1]'), Quantity('20[W m^-1 m^-1 K^-1]'), + Quantity('20[W m^-1 m^-1 K^-1]') +] +External_Convection_Load_2.AmbientTemperature.Inputs[0].DiscreteValues = [ + Quantity('0[s]'), Quantity('1e-3[s]'), + Quantity('2e-3[s]'),Quantity('20[s]'), + Quantity('30[s]'), Quantity('320[s]'), + Quantity('330[s]'), Quantity('350[s]'), + Quantity('360[s]'), Quantity('380[s]'), + Quantity('390[s]'), Quantity('680[s]'), + Quantity('690[s]'), Quantity('710[s]'), + Quantity('720[s]') +] +External_Convection_Load_2.AmbientTemperature.Output.DiscreteValues = [ + Quantity('498.15[K]'), Quantity('498.15[K]'), + Quantity('498.15[K]'), Quantity('498.15[K]'), + Quantity('498.15[K]'), Quantity('498.15[K]'), + Quantity('498.15[K]'), Quantity('498.15[K]'), + Quantity('498.15[K]'), Quantity('498.15[K]'), + Quantity('498.15[K]'), Quantity('498.15[K]'), + Quantity('498.15[K]'), Quantity('498.15[K]'), + Quantity('498.15[K]') +] External_Convection_Load_3 = TRANS_THERM.AddConvection() selection = NS_GRP.Children[6] External_Convection_Load_3.Location = selection -External_Convection_Load_3.FilmCoefficient.Inputs[0].DiscreteValues=[Quantity('0[s]'),Quantity('1e-3[s]'), \ - Quantity('2e-3[s]'),Quantity('20[s]'),Quantity('30[s]'),Quantity('320[s]'),Quantity('330[s]'), \ - Quantity('350[s]'),Quantity('360[s]'),Quantity('380[s]'),Quantity('390[s]'),Quantity('680[s]'), \ - Quantity('690[s]'),Quantity('710[s]'),Quantity('720[s]')] - -External_Convection_Load_3.FilmCoefficient.Output.DiscreteValues=[Quantity('500[W m^-1 m^-1 K^-1]'), \ - Quantity('500[W m^-1 m^-1 K^-1]'), Quantity('500[W m^-1 m^-1 K^-1]'), Quantity('500[W m^-1 m^-1 K^-1]'), \ - Quantity('500[W m^-1 m^-1 K^-1]'), Quantity('500[W m^-1 m^-1 K^-1]'), Quantity('500[W m^-1 m^-1 K^-1]'), \ - Quantity('500[W m^-1 m^-1 K^-1]'), Quantity('500[W m^-1 m^-1 K^-1]'), Quantity('500[W m^-1 m^-1 K^-1]'), \ - Quantity('500[W m^-1 m^-1 K^-1]'),Quantity('500[W m^-1 m^-1 K^-1]'),Quantity('500[W m^-1 m^-1 K^-1]'), \ - Quantity('500[W m^-1 m^-1 K^-1]'),Quantity('500[W m^-1 m^-1 K^-1]')] - -External_Convection_Load_3.AmbientTemperature.Inputs[0].DiscreteValues=[Quantity('0[s]'),Quantity('1e-3[s]'), \ - Quantity('2e-3[s]'),Quantity('20[s]'),Quantity('30[s]'),Quantity('320[s]'),Quantity('330[s]'), \ - Quantity('350[s]'),Quantity('360[s]'),Quantity('380[s]'),Quantity('390[s]'),Quantity('680[s]'), \ - Quantity('690[s]'),Quantity('710[s]'),Quantity('720[s]')] +External_Convection_Load_3.FilmCoefficient.Inputs[0].DiscreteValues = [ + Quantity('0[s]'), Quantity('1e-3[s]'), + Quantity('2e-3[s]'), Quantity('20[s]'), + Quantity('30[s]'), Quantity('320[s]'), + Quantity('330[s]'), Quantity('350[s]'), + Quantity('360[s]'), Quantity('380[s]'), + Quantity('390[s]'), Quantity('680[s]'), + Quantity('690[s]'), Quantity('710[s]'), + Quantity('720[s]') +] -External_Convection_Load_3.AmbientTemperature.Output.DiscreteValues=[Quantity('373.15[K]'), Quantity('373.15[K]'), \ - Quantity('373.15[K]'), Quantity('373.15[K]'),Quantity('373.15[K]'),Quantity('373.15[K]'),Quantity('373.15[K]'), \ - Quantity('373.15[K]'), Quantity('373.15[K]'),Quantity('373.15[K]'),Quantity('373.15[K]'),Quantity('373.15[K]'), \ - Quantity('373.15[K]'), Quantity('373.15[K]'), Quantity('373.15[K]')] +External_Convection_Load_3.FilmCoefficient.Output.DiscreteValues = [ + Quantity('500[W m^-1 m^-1 K^-1]'), Quantity('500[W m^-1 m^-1 K^-1]'), + Quantity('500[W m^-1 m^-1 K^-1]'), Quantity('500[W m^-1 m^-1 K^-1]'), + Quantity('500[W m^-1 m^-1 K^-1]'), Quantity('500[W m^-1 m^-1 K^-1]'), + Quantity('500[W m^-1 m^-1 K^-1]'), Quantity('500[W m^-1 m^-1 K^-1]'), + Quantity('500[W m^-1 m^-1 K^-1]'), Quantity('500[W m^-1 m^-1 K^-1]'), + Quantity('500[W m^-1 m^-1 K^-1]'), Quantity('500[W m^-1 m^-1 K^-1]'), + Quantity('500[W m^-1 m^-1 K^-1]'), Quantity('500[W m^-1 m^-1 K^-1]'), + Quantity('500[W m^-1 m^-1 K^-1]') +] +External_Convection_Load_3.AmbientTemperature.Inputs[0].DiscreteValues = [ + Quantity('0[s]'), Quantity('1e-3[s]'), + Quantity('2e-3[s]'), Quantity('20[s]'), + Quantity('30[s]'), Quantity('320[s]'), + Quantity('330[s]'), Quantity('350[s]'), + Quantity('360[s]'), Quantity('380[s]'), + Quantity('390[s]'), Quantity('680[s]'), + Quantity('690[s]'), Quantity('710[s]'), + Quantity('720[s]') +] +External_Convection_Load_3.AmbientTemperature.Output.DiscreteValues = [ + Quantity('373.15[K]'), Quantity('373.15[K]'), + Quantity('373.15[K]'), Quantity('373.15[K]'), + Quantity('373.15[K]'), Quantity('373.15[K]'), + Quantity('373.15[K]'), Quantity('373.15[K]'), + Quantity('373.15[K]'), Quantity('373.15[K]'), + Quantity('373.15[K]'), Quantity('373.15[K]'), + Quantity('373.15[K]'), Quantity('373.15[K]'), + Quantity('373.15[K]') +] -group_list = [External_Convection_Load_1,External_Convection_Load_2,External_Convection_Load_3] +group_list = [External_Convection_Load_1, External_Convection_Load_2, External_Convection_Load_3] grouping_folder = Tree.Group(group_list) tree_grouping_folder_70 = DataModel.GetObjectsByName("New Folder") """ @@ -409,60 +470,114 @@ def display_image(image_name): """ external_data_files = Ansys.Mechanical.ExternalData.ExternalDataFileCollection() external_data_files.SaveFilesWithProject = False + external_data_file_1 = Ansys.Mechanical.ExternalData.ExternalDataFile() external_data_files.Add(external_data_file_1) external_data_file_1.Identifier = "File1" external_data_file_1.Description = "High" external_data_file_1.IsMainFile = True -external_data_file_1.FilePath= temp_htc_data_high_path -external_data_file_1.ImportSettings = Ansys.Mechanical.ExternalData.ImportSettingsFactory.GetSettingsForFormat(MechanicalEnums.ExternalData.ImportFormat.Delimited) +external_data_file_1.FilePath = temp_htc_data_high_path +external_data_file_1.ImportSettings = ( + Ansys.Mechanical.ExternalData.ImportSettingsFactory.GetSettingsForFormat( + MechanicalEnums.ExternalData.ImportFormat.Delimited + ) +) import_settings = external_data_file_1.ImportSettings import_settings.SkipRows = 1 import_settings.SkipFooter = 0 import_settings.Delimiter = "," import_settings.AverageCornerNodesToMidsideNodes = False -import_settings.UseColumn(0, MechanicalEnums.ExternalData.VariableType.NodeId, "", "Node ID@A") -import_settings.UseColumn(1, MechanicalEnums.ExternalData.VariableType.XCoordinate, "m", "X Coordinate@B") -import_settings.UseColumn(2, MechanicalEnums.ExternalData.VariableType.YCoordinate, "m", "Y Coordinate@C") -import_settings.UseColumn(3, MechanicalEnums.ExternalData.VariableType.ZCoordinate, "m", "Z Coordinate@D") -import_settings.UseColumn(4, MechanicalEnums.ExternalData.VariableType.Temperature, "K", "Temperature@E") -import_settings.UseColumn(5, MechanicalEnums.ExternalData.VariableType.HeatTransferCoefficient, "W m^-2 K^-1", "Heat Transfer Coefficient@F") +import_settings.UseColumn( + 0, MechanicalEnums.ExternalData.VariableType.NodeId, "", "Node ID@A" +) +import_settings.UseColumn( + 1, MechanicalEnums.ExternalData.VariableType.XCoordinate, "m", "X Coordinate@B" +) +import_settings.UseColumn( + 2, MechanicalEnums.ExternalData.VariableType.YCoordinate, "m", "Y Coordinate@C" +) +import_settings.UseColumn( + 3, MechanicalEnums.ExternalData.VariableType.ZCoordinate, "m", "Z Coordinate@D" +) +import_settings.UseColumn( + 4, MechanicalEnums.ExternalData.VariableType.Temperature, "K", "Temperature@E" +) +import_settings.UseColumn( + 5, MechanicalEnums.ExternalData.VariableType.HeatTransferCoefficient, + "W m^-2 K^-1", "Heat Transfer Coefficient@F" +) + external_data_file_2 = Ansys.Mechanical.ExternalData.ExternalDataFile() external_data_files.Add(external_data_file_2) external_data_file_2.Identifier = "File2" external_data_file_2.Description = "Med" external_data_file_2.IsMainFile = False -external_data_file_2.FilePath= temp_htc_data_med_path -external_data_file_2.ImportSettings = Ansys.Mechanical.ExternalData.ImportSettingsFactory.GetSettingsForFormat(MechanicalEnums.ExternalData.ImportFormat.Delimited) +external_data_file_2.FilePath = temp_htc_data_med_path +external_data_file_2.ImportSettings = ( + Ansys.Mechanical.ExternalData.ImportSettingsFactory.GetSettingsForFormat( + MechanicalEnums.ExternalData.ImportFormat.Delimited + ) +) import_settings = external_data_file_2.ImportSettings import_settings.SkipRows = 1 import_settings.SkipFooter = 0 import_settings.Delimiter = "," import_settings.AverageCornerNodesToMidsideNodes = False -import_settings.UseColumn(0, MechanicalEnums.ExternalData.VariableType.NodeId, "", "Node ID@A") -import_settings.UseColumn(1, MechanicalEnums.ExternalData.VariableType.XCoordinate, "m", "X Coordinate@B") -import_settings.UseColumn(2, MechanicalEnums.ExternalData.VariableType.YCoordinate, "m", "Y Coordinate@C") -import_settings.UseColumn(3, MechanicalEnums.ExternalData.VariableType.ZCoordinate, "m", "Z Coordinate@D") -import_settings.UseColumn(4, MechanicalEnums.ExternalData.VariableType.Temperature, "K", "Temperature@E") -import_settings.UseColumn(5, MechanicalEnums.ExternalData.VariableType.HeatTransferCoefficient, "W m^-2 K^-1", "Heat Transfer Coefficient@F") +import_settings.UseColumn( + 0, MechanicalEnums.ExternalData.VariableType.NodeId, "", "Node ID@A" +) +import_settings.UseColumn( + 1, MechanicalEnums.ExternalData.VariableType.XCoordinate, "m", "X Coordinate@B" +) +import_settings.UseColumn( + 2, MechanicalEnums.ExternalData.VariableType.YCoordinate, "m", "Y Coordinate@C" +) +import_settings.UseColumn( + 3, MechanicalEnums.ExternalData.VariableType.ZCoordinate, "m", "Z Coordinate@D" +) +import_settings.UseColumn( + 4, MechanicalEnums.ExternalData.VariableType.Temperature, "K", "Temperature@E" +) +import_settings.UseColumn( + 5, MechanicalEnums.ExternalData.VariableType.HeatTransferCoefficient, + "W m^-2 K^-1", "Heat Transfer Coefficient@F" +) + external_data_file_3 = Ansys.Mechanical.ExternalData.ExternalDataFile() external_data_files.Add(external_data_file_3) external_data_file_3.Identifier = "File3" external_data_file_3.Description = "Low" external_data_file_3.IsMainFile = False -external_data_file_3.FilePath= temp_htc_data_low_path -external_data_file_3.ImportSettings = Ansys.Mechanical.ExternalData.ImportSettingsFactory.GetSettingsForFormat(MechanicalEnums.ExternalData.ImportFormat.Delimited) +external_data_file_3.FilePath = temp_htc_data_low_path +external_data_file_3.ImportSettings = ( + Ansys.Mechanical.ExternalData.ImportSettingsFactory.GetSettingsForFormat( + MechanicalEnums.ExternalData.ImportFormat.Delimited + ) +) import_settings = external_data_file_3.ImportSettings import_settings.SkipRows = 1 import_settings.SkipFooter = 0 import_settings.Delimiter = "," import_settings.AverageCornerNodesToMidsideNodes = False -import_settings.UseColumn(0, MechanicalEnums.ExternalData.VariableType.NodeId, "", "Node ID@A") -import_settings.UseColumn(1, MechanicalEnums.ExternalData.VariableType.XCoordinate, "m", "X Coordinate@B") -import_settings.UseColumn(2, MechanicalEnums.ExternalData.VariableType.YCoordinate, "m", "Y Coordinate@C") -import_settings.UseColumn(3, MechanicalEnums.ExternalData.VariableType.ZCoordinate, "m", "Z Coordinate@D") -import_settings.UseColumn(4, MechanicalEnums.ExternalData.VariableType.Temperature, "K", "Temperature@E") -import_settings.UseColumn(5, MechanicalEnums.ExternalData.VariableType.HeatTransferCoefficient, "W m^-2 K^-1", "Heat Transfer Coefficient@F") +import_settings.UseColumn( + 0, MechanicalEnums.ExternalData.VariableType.NodeId, "", "Node ID@A" +) +import_settings.UseColumn( + 1, MechanicalEnums.ExternalData.VariableType.XCoordinate, "m", "X Coordinate@B" +) +import_settings.UseColumn( + 2, MechanicalEnums.ExternalData.VariableType.YCoordinate, "m", "Y Coordinate@C" +) +import_settings.UseColumn( + 3, MechanicalEnums.ExternalData.VariableType.ZCoordinate, "m", "Z Coordinate@D" +) +import_settings.UseColumn( + 4, MechanicalEnums.ExternalData.VariableType.Temperature, "K", "Temperature@E" +) +import_settings.UseColumn( + 5, MechanicalEnums.ExternalData.VariableType.HeatTransferCoefficient, + "W m^-2 K^-1", "Heat Transfer Coefficient@F" +) imported_load_group_61.ImportExternalDataFiles(external_data_files) """ @@ -472,72 +587,28 @@ def display_image(image_name): """ table = imported_load_group_61.Children[0].GetTableByName("Film Coefficient") numofsteps = 15 -Film_Coeff = ["File1:Heat Transfer Coefficient@F","File2:Heat Transfer Coefficient@F","File3:Heat Transfer Coefficient@F"] -Amb_Temp = ["File1:Temperature@E","File2:Temperature@E","File3:Temperature@E"] -Ana_time = ["0","1e-3","2e-3","20","30","320","330","350","360","380","390","680","690","710","720"] +Film_Coeff = [ + "File1:Heat Transfer Coefficient@F", + "File2:Heat Transfer Coefficient@F", + "File3:Heat Transfer Coefficient@F" +] +Amb_Temp = [ + "File1:Temperature@E", + "File2:Temperature@E", + "File3:Temperature@E" +] +Ana_time = [ + "0", "1e-3", "2e-3", "20", "30", "320", "330", "350", "360", "380", "390", + "680", "690", "710", "720" +] -for i in range(numofsteps-1): +for i in range(numofsteps - 1): table.Add(None) -table[0][0] = Film_Coeff[2] -table[0][1] = Amb_Temp[2] -table[0][2] = Ana_time[0] - -table[1][0] = Film_Coeff[2] -table[1][1] = Amb_Temp[2] -table[1][2] = Ana_time[1] - -table[2][0] = Film_Coeff[2] -table[2][1] = Amb_Temp[2] -table[2][2] = Ana_time[2] - -table[3][0] = Film_Coeff[2] -table[3][1] = Amb_Temp[2] -table[3][2] = Ana_time[3] - -table[4][0] = Film_Coeff[0] -table[4][1] = Amb_Temp[0] -table[4][2] = Ana_time[4] - -table[5][0] = Film_Coeff[0] -table[5][1] = Amb_Temp[0] -table[5][2] = Ana_time[5] - -table[6][0] = Film_Coeff[1] -table[6][1] = Amb_Temp[1] -table[6][2] = Ana_time[6] - -table[7][0] = Film_Coeff[1] -table[7][1] = Amb_Temp[1] -table[7][2] = Ana_time[7] - -table[8][0] = Film_Coeff[2] -table[8][1] = Amb_Temp[2] -table[8][2] = Ana_time[8] - -table[9][0] = Film_Coeff[2] -table[9][1] = Amb_Temp[2] -table[9][2] = Ana_time[9] - -table[10][0] = Film_Coeff[0] -table[10][1] = Amb_Temp[0] -table[10][2] = Ana_time[10] - -table[11][0] = Film_Coeff[0] -table[11][1] = Amb_Temp[0] -table[11][2] = Ana_time[11] - -table[12][0] = Film_Coeff[1] -table[12][1] = Amb_Temp[1] -table[12][2] = Ana_time[12] - -table[13][0] = Film_Coeff[1] -table[13][1] = Amb_Temp[1] -table[13][2] = Ana_time[13] - -table[14][0] = Film_Coeff[2] -table[14][1] = Amb_Temp[2] -table[14][2] = Ana_time[14] +for i in range(numofsteps): + table[i][0] = Film_Coeff[i % 3] + table[i][1] = Amb_Temp[i % 3] + table[i][2] = Ana_time[i] selection = NS_GRP.Children[4] imported_convection_62.Location = selection From 9df1930190b7575b81274c62201e0801858fb80a Mon Sep 17 00:00:00 2001 From: Dipin <26918585+dipinknair@users.noreply.github.com> Date: Wed, 22 Jan 2025 09:25:26 -0600 Subject: [PATCH 58/68] Update .github/workflows/docs.yml --- .github/workflows/docs.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml index 6bfb230c..f2d31af0 100644 --- a/.github/workflows/docs.yml +++ b/.github/workflows/docs.yml @@ -14,7 +14,7 @@ jobs: uses: ./.github/workflows/geometry-mesh.yml secrets: inherit with: - doc-build: false #testing + doc-build: true geometry-mesh-fluent: uses: ./.github/workflows/geometry-mesh-fluent.yml From ccb2f0f1feea42e653d3bb35345d85146368ccce Mon Sep 17 00:00:00 2001 From: dkunhamb Date: Wed, 22 Jan 2025 09:28:00 -0600 Subject: [PATCH 59/68] enable doc build --- .github/workflows/docs.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml index f2d31af0..55551e0f 100644 --- a/.github/workflows/docs.yml +++ b/.github/workflows/docs.yml @@ -20,13 +20,13 @@ jobs: uses: ./.github/workflows/geometry-mesh-fluent.yml secrets: inherit with: - doc-build: false #testing + doc-build: true geometry-mechanical-dpf: uses: ./.github/workflows/geometry-mechanical-dpf.yml secrets: inherit with: - doc-build: false #testing + doc-build: true fluent-mechanical: uses: ./.github/workflows/fluent-mechanical.yml From ba9bfcbc4373df12f5cb72d3561ca60186f96f41 Mon Sep 17 00:00:00 2001 From: dkunhamb Date: Wed, 22 Jan 2025 09:37:03 -0600 Subject: [PATCH 60/68] fix doc build --- .github/workflows/fluent-mechanical.yml | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/.github/workflows/fluent-mechanical.yml b/.github/workflows/fluent-mechanical.yml index b8e95643..2647bb83 100644 --- a/.github/workflows/fluent-mechanical.yml +++ b/.github/workflows/fluent-mechanical.yml @@ -214,6 +214,13 @@ jobs: echo "RUN_DOC_BUILD=false" >> $GITHUB_ENV fi + - name: (DOCS) Download the docs artifacts + uses: actions/download-artifact@v4 + if: ${{ env.RUN_DOC_BUILD == 'true' }} + with: + name: fluent-mechanical-docs-stage-fluent + path: doc + - name: (DOCS) Build the documentation (only on ${{ env.ANSYS_RELEASE_FOR_DOCS }}) if: ${{ env.RUN_DOC_BUILD == 'true' }} env: @@ -225,11 +232,17 @@ jobs: pip install -r ./doc/requirements.txt xvfb-run make -C doc html + - name: (DOCS) Adapt the documentation paths + if: ${{ env.RUN_DOC_BUILD == 'true' }} + run: | + find . -type f -exec sed -i 's|/__w/pyansys-workflows/pyansys-workflows/doc/source/examples/fluent-mechanical/images|./images/|g' {} + + - name: (DOCS) Upload docs artifacts if: ${{ env.RUN_DOC_BUILD == 'true' }} uses: actions/upload-artifact@v4 with: - name: fluent-mechanical-docs-stage-mechanical + name: fluent-mechanical-docs path: | doc/_build/ - doc/source/examples/fluent-mechanical/ \ No newline at end of file + doc/source/examples/fluent-mechanical/ + overwrite: true \ No newline at end of file From 08183bcdddbac5bcb6e352df75698bc59b454732 Mon Sep 17 00:00:00 2001 From: dkunhamb Date: Wed, 22 Jan 2025 12:47:42 -0600 Subject: [PATCH 61/68] change unitsystem --- fluent-mechanical/wf_fm_02_mechanical.py | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/fluent-mechanical/wf_fm_02_mechanical.py b/fluent-mechanical/wf_fm_02_mechanical.py index 3cf1c54a..857aa139 100644 --- a/fluent-mechanical/wf_fm_02_mechanical.py +++ b/fluent-mechanical/wf_fm_02_mechanical.py @@ -197,7 +197,7 @@ def display_image(image_name): # Select MKS units -ExtAPI.Application.ActiveUnitSystem = MechanicalUnitSystem.StandardMKS +ExtAPI.Application.ActiveUnitSystem = MechanicalUnitSystem.StandardNMM # Store all main tree nodes as variables GEOM = Model.Geometry @@ -230,17 +230,6 @@ def display_image(image_name): mechanical.run_python_script( """ MESH = Model.Mesh -# MESH.ElementSize = Quantity(0.004, "m") -# MESH.UseAdaptiveSizing = False -# MESH.MaximumSize = Quantity(0.004, "m") -# MESH.ShapeChecking = 0 -# body_sizing = MESH.AddSizing() -# selection = NS_GRP.Children[5] -# body_sizing.Location = selection -# body_sizing.ElementSize = Quantity(4e-3, "m") -# #body_sizing.CaptureCurvature = True -# #body_sizing.CurvatureNormalAngle = Quantity(0.31, "rad") -# #body_sizing.LocalMinimumSize = Quantity(0.00025, "m") MESH.UseAdaptiveSizing = True MESH.TransitionOption = 1 From 8a96e95663e224300acc8d3b98b62bf6b1b7b99c Mon Sep 17 00:00:00 2001 From: dkunhamb Date: Wed, 22 Jan 2025 13:02:03 -0600 Subject: [PATCH 62/68] update description --- fluent-mechanical/README.rst | 17 +++++++++++--- fluent-mechanical/wf_fm_01_fluent.py | 28 ++++++++---------------- fluent-mechanical/wf_fm_02_mechanical.py | 24 ++++++++++---------- 3 files changed, 35 insertions(+), 34 deletions(-) diff --git a/fluent-mechanical/README.rst b/fluent-mechanical/README.rst index e673f1da..959ce606 100644 --- a/fluent-mechanical/README.rst +++ b/fluent-mechanical/README.rst @@ -1,4 +1,15 @@ -Fluent - Mechanical workflow -============================ +Conjugate Heat Transfer Workflow for Exhaust Manifold +===================================================== -TBD +This workflow demonstrates the typical solver setup involved in performing a CFD +simulation for the conjugate heat transfer (CHT) analysis of an exhaust manifold. +A conjugate heat transfer analysis is a type of simulation that involves the +simultaneous solution of heat transfer in both solid and fluid domains. In this +case, the exhaust manifold is a solid domain, and the fluid domain is the gas +flowing through the manifold. The heat transfer between the solid and fluid domains +is modeled using the heat transfer coefficient (HTC) at the interface between the two +domains. +This workflow provides a step-by-step guide to set up a CHT analysis for an exhaust +manifold using Ansys Fluent PyFluent APIs. The workflow includes usage of APIs to +setup the physics, material properties, boundary conditions, solver settings, and +exporting the results to a CSV file for further use in a Thermo-Mechanical Analysis. diff --git a/fluent-mechanical/wf_fm_01_fluent.py b/fluent-mechanical/wf_fm_01_fluent.py index 2dc5cdb2..e921215b 100644 --- a/fluent-mechanical/wf_fm_01_fluent.py +++ b/fluent-mechanical/wf_fm_01_fluent.py @@ -25,21 +25,6 @@ Conjugate Heat Transfer Workflow for Exhaust Manifold ##################################################### -This workflow demonstrates the typical solver setup involved in performing a CFD -simulation for the conjugate heat transfer (CHT) analysis of an exhaust manifold. -A conjugate heat transfer analysis is a type of simulation that involves the -simultaneous solution of heat transfer in both solid and fluid domains. In this -case, the exhaust manifold is a solid domain, and the fluid domain is the gas -flowing through the manifold. The heat transfer between the solid and fluid domains -is modeled using the heat transfer coefficient (HTC) at the interface between the two -domains. -This workflow provides a step-by-step guide to set up a CHT analysis for an exhaust -manifold using Ansys Flueent Pyfluetn API's. The workflow includes usage of API's to -setup the physics, material properties, boundary conditions, solver settings, and -exporting the results to a CSV file for further use in a Thermo-Mechanical Analysis. - -Problem Description: -------------------- The geometry is an exhaust manifold with a fluid domain (gas) and a solid domain(metal) meshed with a conformal Polyhedral mesh.The hot gas flows through the manifold, @@ -47,6 +32,7 @@ heat transfer coefficient (HTC) at the interface between the fluid and solid domains, the temperature distribution in the solid domain, and export the results to a CSV file for further use in a Thermo-Mechanical Analysis. + The workflow includes the following steps: - Launch Fluent - Load the mesh file @@ -57,6 +43,7 @@ - Run the solver - Export the results to CSV file - Close Fluent + This workflow will generate the following files as output: - exhaust_manifold_results_HIGH_TEMP.cas.h5 - exhaust_manifold_results_MEDIUM_TEMP.cas.h5 @@ -119,6 +106,7 @@ # ------------- # Launch Fluent as a service in solver mode with double precision running on # four processors and print Fluent version. +# if os.getenv("PYANSYS_WORKFLOWS_CI") == "true": print("Configuring Fluent for CI") container_dict = { @@ -131,10 +119,9 @@ mode="solver", container_dict=container_dict, ) - # From here on, the working directory is the mounted directory + WORKING_DIR = "/mnt/pyfluent" - # Fix the path to the mesh file import_mesh_file = PurePosixPath(WORKING_DIR) / "exhaust_manifold_conf.msh.h5" print(f"\nImport mesh path for container: {import_mesh_file}\n") else: @@ -161,6 +148,7 @@ def display_image(work_dir, image_name): # Read the mesh file # ------------------ # Read the mesh file into the Fluent solver and check the mesh information. +# solver.settings.file.read_mesh(file_name=import_mesh_file) solver.mesh.check() @@ -169,6 +157,7 @@ def display_image(work_dir, image_name): # Define the Physics # ------------------ # Define the physics of the problem by setting energy and turbulence models. +# solver.settings.setup.models.energy.enabled = True solver.settings.setup.models.viscous.model.allowed_values() @@ -216,6 +205,7 @@ def display_image(work_dir, image_name): # Define the Named Expressions # ---------------------------- # Define the named expressions for the boundary conditions. +# solver.settings.setup.named_expressions.create("in_temperature") solver.settings.setup.named_expressions["in_temperature"].definition = "1023.15 [K]" @@ -305,7 +295,6 @@ def display_image(work_dir, image_name): # Run the Solver & Export the Results to CSV # ------------------------------------------ # Run the solver to solve the problem and export the results to a CSV file. - # Define a tuple with temperature values temperature_values = ( ("HIGH_TEMP", 1023.15), @@ -352,9 +341,10 @@ def display_image(work_dir, image_name): if GRAPHICS_BOOL: for temp_name, temp_value in temperature_values: display_image(WORKING_DIR, f"temp_interface_contour_{temp_name}.png") + ############################################################################### # Exit the Solver # --------------- # Close the Fluent solver. - +# solver.exit() diff --git a/fluent-mechanical/wf_fm_02_mechanical.py b/fluent-mechanical/wf_fm_02_mechanical.py index 857aa139..f4beddd5 100644 --- a/fluent-mechanical/wf_fm_02_mechanical.py +++ b/fluent-mechanical/wf_fm_02_mechanical.py @@ -172,7 +172,7 @@ def display_image(image_name): """ ) -# Download the image and display it +# Download the geomtry image and display it mechanical.download(files=os.path.join(project_directory, "geometry.png"), target_dir=OUTPUT_DIR) if GRAPHICS_BOOL: display_image("geometry.png") @@ -246,7 +246,7 @@ def display_image(image_name): """ ) -# Download the image and display it +# Download the mesh image and display it mechanical.download(files=os.path.join(project_directory, "mesh.png"), target_dir=OUTPUT_DIR) if GRAPHICS_BOOL: display_image("mesh.png") @@ -444,10 +444,10 @@ def display_image(image_name): ) ############################################################################### -# Use the ouput from Fluent to import the temperature and HTC data -# --------------------------------------------------------------- +# Use the output from Fluent to import the temperature and HTC data +# ----------------------------------------------------------------- # - +# Add imported convection result = mechanical.run_python_script( """ Imported_Load_Group = TRANS_THERM.AddImportedLoadExternalData() @@ -605,9 +605,7 @@ def display_image(image_name): imported_load = DataModel.GetObjectById(imported_load_id) """ ) -# !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -# imported_convection_62.InternalObject.ExternalLoadSteppingType = 1 -# !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + mechanical.run_python_script( """ imported_load.ImportLoad() @@ -628,7 +626,7 @@ def display_image(image_name): ############################################################################### # Solve and post-process the results # ---------------------------------- - +# mechanical.run_python_script( """ # Insert results objects @@ -652,6 +650,8 @@ def display_image(image_name): ) """ ) + +# Download the temperature image and display it mechanical.download(files=os.path.join(project_directory, "temperature.png"), target_dir=OUTPUT_DIR) if GRAPHICS_BOOL: display_image("temperature.png") @@ -783,7 +783,7 @@ def display_image(image_name): display_image("plastic_strain.png") # ############################################################################### -# # Close the Mechanical -# # -------------------- -# # +# Close the Mechanical +# -------------------- +# mechanical.exit() From db1c1436afa79da33abdb0648eefd14259cb1107 Mon Sep 17 00:00:00 2001 From: dkunhamb Date: Wed, 22 Jan 2025 13:18:20 -0600 Subject: [PATCH 63/68] revert readme --- fluent-mechanical/README.rst | 13 +------------ fluent-mechanical/wf_fm_01_fluent.py | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/fluent-mechanical/README.rst b/fluent-mechanical/README.rst index 959ce606..940d3a4f 100644 --- a/fluent-mechanical/README.rst +++ b/fluent-mechanical/README.rst @@ -1,15 +1,4 @@ Conjugate Heat Transfer Workflow for Exhaust Manifold ===================================================== -This workflow demonstrates the typical solver setup involved in performing a CFD -simulation for the conjugate heat transfer (CHT) analysis of an exhaust manifold. -A conjugate heat transfer analysis is a type of simulation that involves the -simultaneous solution of heat transfer in both solid and fluid domains. In this -case, the exhaust manifold is a solid domain, and the fluid domain is the gas -flowing through the manifold. The heat transfer between the solid and fluid domains -is modeled using the heat transfer coefficient (HTC) at the interface between the two -domains. -This workflow provides a step-by-step guide to set up a CHT analysis for an exhaust -manifold using Ansys Fluent PyFluent APIs. The workflow includes usage of APIs to -setup the physics, material properties, boundary conditions, solver settings, and -exporting the results to a CSV file for further use in a Thermo-Mechanical Analysis. +TODO: Add a description of the workflow. \ No newline at end of file diff --git a/fluent-mechanical/wf_fm_01_fluent.py b/fluent-mechanical/wf_fm_01_fluent.py index e921215b..4ff50635 100644 --- a/fluent-mechanical/wf_fm_01_fluent.py +++ b/fluent-mechanical/wf_fm_01_fluent.py @@ -25,6 +25,21 @@ Conjugate Heat Transfer Workflow for Exhaust Manifold ##################################################### +This workflow demonstrates the typical solver setup involved in performing a CFD +simulation for the conjugate heat transfer (CHT) analysis of an exhaust manifold. +A conjugate heat transfer analysis is a type of simulation that involves the +simultaneous solution of heat transfer in both solid and fluid domains. In this +case, the exhaust manifold is a solid domain, and the fluid domain is the gas +flowing through the manifold. The heat transfer between the solid and fluid domains +is modeled using the heat transfer coefficient (HTC) at the interface between the two +domains. +This workflow provides a step-by-step guide to set up a CHT analysis for an exhaust +manifold using Ansys Fluent PyFluent APIs. The workflow includes usage of APIs to +setup the physics, material properties, boundary conditions, solver settings, and +exporting the results to a CSV file for further use in a Thermo-Mechanical Analysis. + +Problem Description +------------------- The geometry is an exhaust manifold with a fluid domain (gas) and a solid domain(metal) meshed with a conformal Polyhedral mesh.The hot gas flows through the manifold, From 4ed2f2f5525d42f61a17111073ce0559ac9675ed Mon Sep 17 00:00:00 2001 From: dkunhamb Date: Wed, 22 Jan 2025 13:25:41 -0600 Subject: [PATCH 64/68] update readme --- fluent-mechanical/README.rst | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/fluent-mechanical/README.rst b/fluent-mechanical/README.rst index 940d3a4f..9bf49602 100644 --- a/fluent-mechanical/README.rst +++ b/fluent-mechanical/README.rst @@ -1,4 +1,7 @@ -Conjugate Heat Transfer Workflow for Exhaust Manifold -===================================================== +Fluent and mechanical heat transfer workflow for exhaust manifold +================================================================= -TODO: Add a description of the workflow. \ No newline at end of file +This workflow demonstrates the typical solver setup involved in performing a CFD +simulation for the conjugate heat transfer (CHT) analysis of an exhaust manifold +using Ansys Fluent and followed by Thermo-Mechanical analysis using +Ansys Mechanical. From b175bbf1788dd355f96c8b19ab5591128da677dd Mon Sep 17 00:00:00 2001 From: dkunhamb Date: Wed, 22 Jan 2025 13:27:17 -0600 Subject: [PATCH 65/68] update pymech --- fluent-mechanical/wf_fm_02_mechanical.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/fluent-mechanical/wf_fm_02_mechanical.py b/fluent-mechanical/wf_fm_02_mechanical.py index f4beddd5..16dcd74f 100644 --- a/fluent-mechanical/wf_fm_02_mechanical.py +++ b/fluent-mechanical/wf_fm_02_mechanical.py @@ -25,8 +25,7 @@ Thermo-mechanical assessment of representative exhaust manifold model ##################################################################### -MultiPhysics example: Thermo-Mechanical simulation on a representative exhuast manifold -model. +# TODO - Add a brief description of the workflow """ # noqa: D400, D415 @@ -172,7 +171,7 @@ def display_image(image_name): """ ) -# Download the geomtry image and display it +# Download the geometry image and display it mechanical.download(files=os.path.join(project_directory, "geometry.png"), target_dir=OUTPUT_DIR) if GRAPHICS_BOOL: display_image("geometry.png") @@ -725,7 +724,7 @@ def display_image(image_name): ) ############################################################################### -# Sovle and post-process the results +# Solve and post-process the results # ---------------------------------- # mechanical.run_python_script( From 2e672afcea8722eeb21cb89484fbe6988758b533 Mon Sep 17 00:00:00 2001 From: dkunhamb Date: Fri, 24 Jan 2025 12:35:34 -0600 Subject: [PATCH 66/68] readme and description --- README.md | 4 +++ fluent-mechanical/wf_fm_02_mechanical.py | 38 ++++++++++++++++++++++-- 2 files changed, 40 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index b63b101e..b5631d10 100644 --- a/README.md +++ b/README.md @@ -35,6 +35,10 @@ for every part of the simulation process. The available workflows are: - For geometry: Ansys SpaceClaim / Ansys Discovery / Ansys Geometry Service - For simulation: Ansys Mechanical - For post-procesing: Ansys Data Processing Framework +- [Fluent and mechanical analysis](https://github.com/ansys/pyansys-workflows/tree/main/fluent-mechanical): this workflow demonstrates how to perform a Conjugate Heat Transfer (CHT) analysis for an exhaust manifold to simulate heat transfer between solid and fluid domains, calculate heat transfer coefficients (HTCs) and temperature distribution, and export results for thermo-mechanical analysis. The thermo-mechanical assessment is then performed to evaluate the exhaust manifold's performance under thermal cycling, aiding in design optimization for durability + The involved Ansys products are: + - For : Ansys Fluent + - For thermal analysis: Ansys Mechanical ## How to run the workflows diff --git a/fluent-mechanical/wf_fm_02_mechanical.py b/fluent-mechanical/wf_fm_02_mechanical.py index 16dcd74f..6e7082ab 100644 --- a/fluent-mechanical/wf_fm_02_mechanical.py +++ b/fluent-mechanical/wf_fm_02_mechanical.py @@ -25,8 +25,42 @@ Thermo-mechanical assessment of representative exhaust manifold model ##################################################################### -# TODO - Add a brief description of the workflow - +Background +---------- + +The turbine housing/exhaust manifold is a critical component as it is subjected to extreme +temperature cycling. This induces fatigue in the housing material and leads to early +failure. Simulation helps to design housing and other parts for extended service life. + +Thermo-mechanical workflow +-------------------------- + +A comprehensive CFD analysis of the exhaust manifold component is executed as a +steady-state examination, focusing on the specified duty cycle. This process involves +two recurring duty cycles, during which the temperature and other crucial operating +parameters, such as mass flow and pressure, maintain a consistent pseudo-steady state. + +Three unique operating conditions are chosen from the duty cycle, and steady-state +calculations are performed corresponding to the exhaust gas temperature in each case. +The resulting Heat Transfer Coefficients (HTCs) and temperatures at the solid-fluid +interface are exported to a CSV file, which serves as the input for subsequent thermal +calculations in the Mechanical run. + +The Mechanical run encompasses Structural Transient Thermal and Non-linear (NL) Static +analyses, employing temperature-dependent Bilinear Kinematic hardening material +properties for a thorough structural evaluation. + +In the Transient Thermal run, imported HTCs and reference temperatures from the +CFD runs are mapped onto the structural mesh of the exhaust manifold assembly. External +convection loads and other boundary conditions are applied to calculate the temperature +distribution across the exhaust manifold assembly. + +Subsequently, a non-linear static analysis is conducted to determine the plastic strain, +taking into account the temperature distribution calculated in the Transient Thermal +solve and other relevant structural boundary conditions. + +This approach leads to a more impactful and precise understanding of the exhaust +manifold's performance subjected to thermal cycling. """ # noqa: D400, D415 import os From 4f0d2c743c588f21be411347e6d82591db59d885 Mon Sep 17 00:00:00 2001 From: dkunhamb Date: Mon, 27 Jan 2025 09:00:29 -0600 Subject: [PATCH 67/68] review changes --- .github/workflows/fluent-mechanical.yml | 14 -------------- README.md | 4 ++-- fluent-mechanical/README.rst | 3 +-- 3 files changed, 3 insertions(+), 18 deletions(-) diff --git a/.github/workflows/fluent-mechanical.yml b/.github/workflows/fluent-mechanical.yml index 2647bb83..b36f9fc7 100644 --- a/.github/workflows/fluent-mechanical.yml +++ b/.github/workflows/fluent-mechanical.yml @@ -104,13 +104,6 @@ jobs: echo "RUN_DOC_BUILD=false" >> $GITHUB_ENV fi - - name: (DOCS) Download the docs artifacts - uses: actions/download-artifact@v4 - if: ${{ env.RUN_DOC_BUILD == 'true' }} - with: - name: fluent-mechanical-docs-stage-fluent - path: doc - - name: (DOCS) Build the documentation (only on ${{ env.ANSYS_RELEASE_FOR_DOCS}}) if: ${{ env.RUN_DOC_BUILD == 'true' }} env: @@ -118,7 +111,6 @@ jobs: BUILD_DOCS_SCRIPT: 'fluent-mechanical/wf_fm_01_fluent.py' run: | cd doc - find . -type f -exec sed -i 's|C:\\Users\\ansys\\actions-runner\\_work\\pyansys-workflows\\pyansys-workflows\\doc\\source\\examples\\fluent-mechanical\\images\\|./images/|g' {} + pip install -r requirements.txt make html @@ -228,15 +220,9 @@ jobs: BUILD_DOCS_SCRIPT: 'geometry-mechanical-dpf/wf_gmd_02_mechanical.py' run: | . .venv/bin/activate - find . -type f -exec sed -i 's|C:\\Users\\ansys\\actions-runner\\_work\\pyansys-workflows\\pyansys-workflows\\doc\\source\\examples\\fluent-mechanical\\images\\|./images/|g' {} + pip install -r ./doc/requirements.txt xvfb-run make -C doc html - - name: (DOCS) Adapt the documentation paths - if: ${{ env.RUN_DOC_BUILD == 'true' }} - run: | - find . -type f -exec sed -i 's|/__w/pyansys-workflows/pyansys-workflows/doc/source/examples/fluent-mechanical/images|./images/|g' {} + - - name: (DOCS) Upload docs artifacts if: ${{ env.RUN_DOC_BUILD == 'true' }} uses: actions/upload-artifact@v4 diff --git a/README.md b/README.md index b5631d10..64938155 100644 --- a/README.md +++ b/README.md @@ -35,9 +35,9 @@ for every part of the simulation process. The available workflows are: - For geometry: Ansys SpaceClaim / Ansys Discovery / Ansys Geometry Service - For simulation: Ansys Mechanical - For post-procesing: Ansys Data Processing Framework -- [Fluent and mechanical analysis](https://github.com/ansys/pyansys-workflows/tree/main/fluent-mechanical): this workflow demonstrates how to perform a Conjugate Heat Transfer (CHT) analysis for an exhaust manifold to simulate heat transfer between solid and fluid domains, calculate heat transfer coefficients (HTCs) and temperature distribution, and export results for thermo-mechanical analysis. The thermo-mechanical assessment is then performed to evaluate the exhaust manifold's performance under thermal cycling, aiding in design optimization for durability +- [Fluent and mechanical analysis](https://github.com/ansys/pyansys-workflows/tree/main/fluent-mechanical): this workflow demonstrateshow to perform a Conjugate Heat Transfer (CHT) analysis for an exhaust manifold to simulate heat transfer between solid and fluid domains, calculate heat transfer coefficients (HTCs) and temperature distribution, and export results for thermo-mechanical analysis. The thermo-mechanical assessment is then performed to evaluate the exhaust manifold's performance under thermal cycling, aiding in design optimization for durability The involved Ansys products are: - - For : Ansys Fluent + - For fluids analysis: Ansys Fluent - For thermal analysis: Ansys Mechanical ## How to run the workflows diff --git a/fluent-mechanical/README.rst b/fluent-mechanical/README.rst index 9bf49602..a3c51722 100644 --- a/fluent-mechanical/README.rst +++ b/fluent-mechanical/README.rst @@ -3,5 +3,4 @@ Fluent and mechanical heat transfer workflow for exhaust manifold This workflow demonstrates the typical solver setup involved in performing a CFD simulation for the conjugate heat transfer (CHT) analysis of an exhaust manifold -using Ansys Fluent and followed by Thermo-Mechanical analysis using -Ansys Mechanical. +using Ansys Fluent and followed by Thermo-Mechanical analysis using Ansys Mechanical. From 5f483641857833f2eaba29a6870c149cfc6057dc Mon Sep 17 00:00:00 2001 From: Roberto Pastor Muela <37798125+RobPasMue@users.noreply.github.com> Date: Mon, 27 Jan 2025 16:02:07 +0100 Subject: [PATCH 68/68] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 64938155..52d19bf0 100644 --- a/README.md +++ b/README.md @@ -35,7 +35,7 @@ for every part of the simulation process. The available workflows are: - For geometry: Ansys SpaceClaim / Ansys Discovery / Ansys Geometry Service - For simulation: Ansys Mechanical - For post-procesing: Ansys Data Processing Framework -- [Fluent and mechanical analysis](https://github.com/ansys/pyansys-workflows/tree/main/fluent-mechanical): this workflow demonstrateshow to perform a Conjugate Heat Transfer (CHT) analysis for an exhaust manifold to simulate heat transfer between solid and fluid domains, calculate heat transfer coefficients (HTCs) and temperature distribution, and export results for thermo-mechanical analysis. The thermo-mechanical assessment is then performed to evaluate the exhaust manifold's performance under thermal cycling, aiding in design optimization for durability +- [Fluent and mechanical analysis](https://github.com/ansys/pyansys-workflows/tree/main/fluent-mechanical): this workflow demonstrates how to perform a Conjugate Heat Transfer (CHT) analysis for an exhaust manifold to simulate heat transfer between solid and fluid domains, calculate heat transfer coefficients (HTCs) and temperature distribution, and export results for thermo-mechanical analysis. The thermo-mechanical assessment is then performed to evaluate the exhaust manifold's performance under thermal cycling, aiding in design optimization for durability The involved Ansys products are: - For fluids analysis: Ansys Fluent - For thermal analysis: Ansys Mechanical