Skip to content

Commit 7717356

Browse files
dipinknairclatapieDipin Nairpre-commit-ci[bot]MaxJPRey
authored
feat: adding PyMAPDL + PyDPF example (#89)
Co-authored-by: clatapie <[email protected]> Co-authored-by: Dipin Nair <[email protected]> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Maxime Rey <[email protected]> Co-authored-by: Roberto Pastor Muela <[email protected]>
1 parent 6d271fb commit 7717356

File tree

8 files changed

+877
-0
lines changed

8 files changed

+877
-0
lines changed

.github/workflows/docs.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,12 @@ jobs:
3535
with:
3636
doc-build: true
3737

38+
mapdl-dpf:
39+
uses: ./.github/workflows/mapdl-dpf.yml
40+
secrets: inherit
41+
with:
42+
doc-build: true
43+
3844
speos-optislang:
3945
uses: ./.github/workflows/speos-optislang.yml
4046
secrets: inherit
@@ -94,6 +100,12 @@ jobs:
94100
name: speos-optislang-docs
95101
path: doc/
96102

103+
- name: Download artifacts for pymapdl-dpf
104+
uses: actions/download-artifact@v5
105+
with:
106+
name: pymapdl-dpf-docs
107+
path: doc/
108+
97109
- name: Build the documentation
98110
run: |
99111
cd doc

.github/workflows/mapdl-dpf.yml

Lines changed: 199 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,199 @@
1+
name: MAPDL-DPF Workflow
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
doc-build:
7+
required: false
8+
default: false
9+
type: boolean
10+
description: 'Whether to build the documentation'
11+
workflow_call:
12+
inputs:
13+
doc-build:
14+
required: false
15+
default: false
16+
type: boolean
17+
description: 'Whether to build the documentation'
18+
push:
19+
branches:
20+
- main
21+
pull_request:
22+
paths:
23+
- 'mapdl-dpf/**'
24+
25+
env:
26+
ANSYSLMD_LICENSE_FILE: ${{ format('1055@{0}', secrets.LICENSE_SERVER )}}
27+
MAIN_PYTHON_VERSION: "3.11"
28+
MAPDL_DOCKER_IMAGE: 'ghcr.io/ansys/mapdl'
29+
DPF_DOCKER_IMAGE: ghcr.io/ansys/mapdl:v25.2-rocky-dpf-standalone
30+
PYANSYS_WORKFLOWS_CI: true
31+
ANSYS_RELEASE_FOR_DOCS: 25.2
32+
DPF_START_SERVER: false
33+
ANSYS_DPF_ACCEPT_LA: Y
34+
MAPDL_IMAGE_VERSION_DOCS_BUILD: v25.2.4-ubuntu-cicd
35+
PYMAPDL_PORT_0: 21000
36+
PYMAPDL_DB_PORT_0: 21001
37+
PYMAPDL_PORT_1: 21002
38+
PYMAPDL_DB_PORT_1: 21003
39+
DPF_PORT_0: 21004
40+
DPF_PORT_1: 21005
41+
PYVISTA_OFF_SCREEN: true
42+
43+
jobs:
44+
45+
is-only-docs-required:
46+
uses: ./.github/workflows/check-docs-required.yml
47+
with:
48+
doc-build: ${{ inputs.doc-build || false }}
49+
50+
mapdl-dpf:
51+
name: MAPDL-DPF
52+
runs-on: ubuntu-22.04
53+
needs: is-only-docs-required
54+
container:
55+
image: "ghcr.io/ansys/mapdl:v25.2.4-ubuntu-cicd"
56+
options: -u=0:0 --oom-kill-disable --memory=6656MB --memory-swap=16896MB --shm-size=1gb --entrypoint /bin/bash
57+
credentials:
58+
username: ${{ github.actor }}
59+
password: ${{ secrets.GITHUB_TOKEN }}
60+
strategy:
61+
fail-fast: false
62+
matrix:
63+
ansys-release: ${{ needs.is-only-docs-required.outputs.only-docs == 'true' && fromJSON('[25.2]') || fromJSON('[25.2]') }}
64+
env:
65+
PYMAPDL_START_INSTANCE: FALSE
66+
ON_DOCUMENTATION: TRUE
67+
ON_CICD: TRUE
68+
69+
steps:
70+
71+
- name: Checkout code
72+
uses: actions/checkout@v4
73+
74+
- name: Set up Python ${{ env.MAIN_PYTHON_VERSION }}
75+
uses: actions/setup-python@v5
76+
with:
77+
python-version: ${{ env.MAIN_PYTHON_VERSION }}
78+
79+
- name: Create a virtual environment
80+
shell: bash
81+
run: |
82+
python -m venv .venv
83+
. .venv/bin/activate
84+
apt-get update && apt-get -y install gcc mono-mcs g++
85+
86+
- name: Install dependencies
87+
shell: bash
88+
run: |
89+
. .venv/bin/activate
90+
python -m pip install --upgrade pip --root-user-action=ignore
91+
pip install -r mapdl-dpf/requirements_${{ matrix.ansys-release }}.txt --root-user-action=ignore
92+
93+
- name: "Start MAPDL service directly (inside container)"
94+
id: start_mapdl
95+
shell: bash
96+
env:
97+
DISTRIBUTED_MODE: "dmp"
98+
LICENSE_SERVER: ${{ secrets.LICENSE_SERVER }}
99+
MAPDL_VERSION: ${{ env.MAPDL_IMAGE_VERSION_DOCS_BUILD }}
100+
MAPDL_PACKAGE: ${{ env.MAPDL_DOCKER_IMAGE }}
101+
ANSYSLMD_LICENSE_FILE: ${{ env.ANSYSLMD_LICENSE_FILE }}
102+
ANSYS_DPF_ACCEPT_LA: ${{ env.ANSYS_DPF_ACCEPT_LA }}
103+
run: |
104+
. .venv/bin/activate
105+
106+
echo "Launching first MAPDL instance..."
107+
export INSTANCE_NAME=MAPDL_0
108+
export PYMAPDL_PORT=$PYMAPDL_PORT_0
109+
export PYMAPDL_DB_PORT=$PYMAPDL_DB_PORT_0
110+
export DPF_PORT=$DPF_PORT_0
111+
mapdl-dpf/.ci/start_mapdl.sh & export MAPDL_PID=$!
112+
echo "Launching MAPDL service at PID: $MAPDL_PID"
113+
echo "MAPDL_PID=$(echo $MAPDL_PID)" >> $GITHUB_OUTPUT
114+
115+
echo "Launching second MAPDL instance..."
116+
export INSTANCE_NAME=MAPDL_1
117+
export PYMAPDL_PORT=$PYMAPDL_PORT_1
118+
export PYMAPDL_DB_PORT=$PYMAPDL_DB_PORT_1
119+
export DPF_PORT=$DPF_PORT_1
120+
mapdl-dpf/.ci/start_mapdl.sh & export MAPDL_PID_1=$!
121+
echo "Launching second MAPDL service at PID: $MAPDL_PID_1"
122+
echo "MAPDL_PID_1=$(echo $MAPDL_PID_1)" >> $GITHUB_OUTPUT
123+
124+
- name: "DPF server setup"
125+
shell: bash
126+
run: |
127+
. .venv/bin/activate
128+
echo "DPF service will be available through MAPDL container"
129+
echo "DPF_PORT: $DPF_PORT"
130+
# DPF is already available in the MAPDL container
131+
132+
- name: "Test virtual framebuffer"
133+
shell: bash
134+
run: |
135+
. .venv/bin/activate
136+
echo "Testing virtual framebuffer..."
137+
# Install xvfb if not available
138+
which xvfb-run || (apt-get update && apt-get install -y xvfb)
139+
140+
# Test display if the script exists
141+
if [ -f "mapdl-dpf/.ci/display_test.py" ]; then
142+
xvfb-run python mapdl-dpf/.ci/display_test.py
143+
else
144+
echo "Display test script not found, skipping..."
145+
fi
146+
147+
- name: "Retrieve PyMAPDL version"
148+
id: version
149+
shell: bash
150+
run: |
151+
. .venv/bin/activate
152+
echo "PYMAPDL_VERSION=$(python -c 'from ansys.mapdl.core import __version__; print(__version__)')" >> $GITHUB_OUTPUT
153+
echo "PyMAPDL version is: $(python -c "from ansys.mapdl.core import __version__; print(__version__)")"
154+
155+
- name: Run the MAPDL-DPF script
156+
shell: bash
157+
env:
158+
LIBGL_ALWAYS_SOFTWARE: 1
159+
PYANSYS_VISUALIZER_HTML_BACKEND: true
160+
run: |
161+
. .venv/bin/activate
162+
echo "Building MAPDL-DPF workflow..."
163+
echo "PYMAPDL_START_INSTANCE: $PYMAPDL_START_INSTANCE"
164+
xvfb-run python mapdl-dpf/wf_mapdl-dpf.py
165+
166+
- name: "Install make"
167+
shell: bash
168+
run: |
169+
apt-get update -qq && apt-get install -y make
170+
171+
- name: (DOCS) Build the documentation (only on ${{ env.ANSYS_RELEASE_FOR_DOCS}})
172+
if: needs.is-only-docs-required.outputs.only-docs == 'true' && matrix.ansys-release == env.ANSYS_RELEASE_FOR_DOCS
173+
shell: bash
174+
env:
175+
BUILD_DOCS_SCRIPT: 'mapdl-dpf/wf_mapdl-dpf.py'
176+
run: |
177+
. .venv/bin/activate
178+
cd doc
179+
pip install -r requirements.txt --root-user-action=ignore
180+
xvfb-run make html
181+
pymapdl stop --all
182+
183+
- name: (DOCS) Upload docs artifacts
184+
if: needs.is-only-docs-required.outputs.only-docs == 'true' && matrix.ansys-release == env.ANSYS_RELEASE_FOR_DOCS
185+
uses: actions/upload-artifact@v4
186+
with:
187+
name: mapdl-dpf-docs
188+
path: |
189+
doc/_build/
190+
doc/source/examples/mapdl-dpf/
191+
overwrite: true
192+
193+
- name: print MAPDL log
194+
if: failure()
195+
shell: bash
196+
run: |
197+
pymapdl stop --all
198+
echo "Printing MAPDL log for debugging..."
199+
cat MAPDL_0.log

doc/source/_static/bvp.png

393 KB
Loading

mapdl-dpf/.ci/display_test.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Copyright (C) 2024 - 2025 ANSYS, Inc. and/or its affiliates.
2+
# SPDX-License-Identifier: MIT
3+
#
4+
#
5+
# Permission is hereby granted, free of charge, to any person obtaining a copy
6+
# of this software and associated documentation files (the "Software"), to deal
7+
# in the Software without restriction, including without limitation the rights
8+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
# copies of the Software, and to permit persons to whom the Software is
10+
# furnished to do so, subject to the following conditions:
11+
#
12+
# The above copyright notice and this permission notice shall be included in all
13+
# copies or substantial portions of the Software.
14+
#
15+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
# SOFTWARE.
22+
23+
"""Quickly check if VTK off screen plotting works."""
24+
25+
import pyvista
26+
from pyvista.plotting import system_supports_plotting
27+
28+
print("system_supports_plotting", system_supports_plotting())
29+
pyvista.OFF_SCREEN = True
30+
pyvista.plot(pyvista.Sphere())

0 commit comments

Comments
 (0)