Skip to content

Commit 9287644

Browse files
committed
added the fenics examples for linear elastic plate with hole benchmark
1 parent 4d17426 commit 9287644

5 files changed

Lines changed: 503 additions & 0 deletions

File tree

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
name: CI
2+
on:
3+
push:
4+
5+
pull_request:
6+
branches: [ main ]
7+
8+
# Allows you to run this workflow manually from the Actions tab
9+
workflow_dispatch:
10+
11+
# Runs the workflow once per day at 3:15am
12+
schedule:
13+
- cron: '3 16 * * *'
14+
15+
env:
16+
CACHE_NUMBER: 1 # increase to reset cache manually
17+
SNAKEMAKE_RESULT_FILE: metadata4ing_provenance
18+
PROVENANACE_FILE_NAME: element_size_vs_max_mises_stress.pdf
19+
20+
jobs:
21+
run-simulation:
22+
runs-on: ubuntu-latest
23+
steps:
24+
- name: checkout repo content
25+
uses: actions/checkout@v2
26+
27+
- name: Setup Mambaforge
28+
uses: conda-incubator/setup-miniconda@v3
29+
with:
30+
miniforge-version: latest
31+
activate-environment: model-validation
32+
use-mamba: true
33+
34+
- name: Set strict channel priority
35+
run: conda config --set channel_priority strict
36+
37+
- name: Update environment
38+
run: mamba env update -n model-validation -f environment_benchmarks.yml
39+
40+
- name: Run Example linear-elastic-plate-with-hole_fenics using Benchmarking package
41+
shell: bash -l {0}
42+
run: |
43+
cd $GITHUB_WORKSPACE/examples/linear-elastic-plate-with-hole/fenics/
44+
python run_benchmark.py
45+
46+
- name: Archive Linear Elastic plate with a hole benchmark data for snakemake
47+
uses: actions/upload-artifact@v4
48+
with:
49+
name: snakemake_results_linear-elastic-plate-with-hole
50+
path: |
51+
examples/linear-elastic-plate-with-hole/fenics/results/
52+
53+
54+
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
name: fenics_simulation
2+
# Environment file for fenics simulation scripts. Called by fenics tool workflow.
3+
4+
channels:
5+
- conda-forge
6+
7+
channel_priority: strict
8+
9+
dependencies:
10+
- python=3.12
11+
- fenics-dolfinx=0.9.*
12+
- mpich
13+
- petsc4py
14+
- pint
15+
- python-gmsh
16+
- sympy
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
from pathlib import Path
2+
import zipfile
3+
import json
4+
import shutil
5+
import subprocess
6+
7+
"""
8+
The script performs the following steps:
9+
10+
1. Extracts the benchmark files from a zip archive (currently assuming that it is an RO-Crate of the benchmark).
11+
2. Iterates through the parameter configuration files, checks the "element-size" value, and if it meets the specified condition (>= 0.025)
12+
, it executes the Snakemake workflow for that configuration.
13+
14+
The results of each run (and the files used by it) are stored in the directory with the configuration name.
15+
"""
16+
17+
####################################################################################################
18+
####################################################################################################
19+
# Benchmark Extraction
20+
####################################################################################################
21+
####################################################################################################
22+
23+
root_zipped_benchmark_dir = Path(__file__).resolve().parent.parent
24+
root_unzipped_benchmark_dir = Path(__file__).resolve().parent
25+
26+
with zipfile.ZipFile(root_zipped_benchmark_dir / "linear-elastic-plate-with-hole.zip", 'r') as zip_ref:
27+
# Extract all files
28+
zip_ref.extractall(root_unzipped_benchmark_dir)
29+
30+
31+
#Creates a directory to store the conda environments. The environments are shared across different parameter configurations.
32+
#To avoid redundant creation of environments, this path will be passed to all snakemake files during execution.
33+
34+
shared_env_dir = root_unzipped_benchmark_dir / "conda_envs"
35+
shared_env_dir.mkdir(parents=True, exist_ok=True)
36+
37+
####################################################################################################
38+
####################################################################################################
39+
# Conditional execution of parameter configurations
40+
####################################################################################################
41+
####################################################################################################
42+
43+
for file in root_unzipped_benchmark_dir.glob("parameters_*.json"):
44+
with open(file, "r") as f:
45+
data = json.load(f)
46+
if data.get("element-size").get("value") >= 0.025:
47+
#if data.get("configuration") == "1":
48+
49+
# Create output directory for the configuration
50+
output_dir = root_unzipped_benchmark_dir / "results" / data.get("configuration")
51+
output_dir.mkdir(parents=True, exist_ok=True)
52+
53+
# Copy the selected parameter file to the output directory with a standardised name
54+
with open(output_dir / "parameters.json", "w") as outfile:
55+
json.dump(data, outfile, indent=2)
56+
57+
# Copy files from benchmark_dir to output_dir, excluding non-matching parameter files.
58+
for item in root_unzipped_benchmark_dir.iterdir():
59+
if item.is_file():
60+
if item.name.startswith("parameters_") and item.suffix == ".json":
61+
continue
62+
else:
63+
shutil.copy(item, output_dir / item.name)
64+
65+
# Run the Snakemake workflow for the configuration
66+
subprocess.run(["snakemake", "--use-conda", "--force", "--cores", "all", "--conda-prefix", str(shared_env_dir)], check=True, cwd=output_dir)
67+
print("Workflow executed successfully.")
68+
69+
# For the scenario where the snakemake workflow doesn't exist, one can directly run the simulation script using the subprocess module, e.g.:
70+
#subprocess.run(["python", "run_fenics_simulation.py" \
71+
#"--input_parameter_file" "parameters.json" \
72+
#"--input_mesh_file" "mesh.msh" \
73+
#"--output_solution_file_zip" "solution_field_data.zip" \
74+
#"--output_metrics_file" "solution_metrics.json"], check=True, cwd=output_dir)
75+
76+
#Assuming the mesh.msh and parameters.json files are present/copied to the output_dir.

0 commit comments

Comments
 (0)