Skip to content

Add scripts for running sensitivity analysis #258

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 7 commits into
base: herck/2023paper
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# To get started with Dependabot version updates, you'll need to specify which
# package ecosystems to update and where the package manifests are located.
# Please see the documentation for all configuration options:
# https://docs.github.com/code-security/dependabot/dependabot-version-updates/configuration-options-for-the-dependabot.yml-file

version: 2
updates:
- package-ecosystem: "github-actions" # See documentation for possible values
directory: "/" # Location of package manifests
schedule:
interval: "weekly"
36 changes: 36 additions & 0 deletions .github/workflows/build_docs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: Build documentation

on:
pull_request:
branches: [main]
workflow_call:
workflow_dispatch:

env:
DEB_PYTHON_INSTALL_LAYOUT: deb_system
DISPLAY: ":99.0"

jobs:

build:
runs-on: ubuntu-22.04
container: ghcr.io/scientificcomputing/fenics-gmsh:2023-02-20
env:
PUBLISH_DIR: ./docs/_build/html

steps:
- name: Checkout
uses: actions/checkout@v4


- name: Install dependencies
run: |
python3 -m pip install ".[docs, gui]"

- name: Build docs
run: make docs

- name: Upload artifact
uses: actions/upload-pages-artifact@v3
with:
path: ${{ env.PUBLISH_DIR }}
71 changes: 71 additions & 0 deletions .github/workflows/convergence-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.

name: Run convergence test

on:
workflow_dispatch:
push:
branches:
- "!*"
tags:
- "v*"


jobs:
job_1:
name: run convergence tests
runs-on: ubuntu-latest
strategy:
matrix:
dx: [0.1, 0.2, 0.4]
dt: [0.05]
include:
- dt: 0.025
dx: 0.2
- dt: 0.1
dx: 0.2


container:
image: ghcr.io/scientificcomputing/fenics-gmsh:2023-02-20

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Install dependencies
run: |
python3 -m pip install -e "."

- name: Run benchmark with dx = ${{ matrix.dx }} and dt = ${{ matrix.dt }}
run: python3 -m simcardems.benchmark run convergence_test --dt=${{ matrix.dt }} --dx=${{ matrix.dx }} --sha=${{ github.sha }}

- name: Upload artifacts
uses: actions/upload-artifact@v4
with:
name: "results-${{ matrix.dx }}-${{ matrix.dt }}"
path: convergence_test/results_dx*.json

job_2:
name: Download repost and upload to gist
needs: job_1
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- uses: actions/download-artifact@v4
with:
path: convergence_test

- uses: actions/setup-python@v4
with:
python-version: "3.10"

- name: Install dependencies
run: python3 -m pip install requests

- name: Print files
run: python3 scripts/upload-data.py convergence_test --token=${{ secrets.CONV_TOKEN }}
41 changes: 41 additions & 0 deletions .github/workflows/deploy_docs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: Publish documentation

on:
push:
branches: [main]
workflow_dispatch:


permissions:
contents: read
pages: write
id-token: write

concurrency:
group: "pages"
cancel-in-progress: true

jobs:

build:
uses: ./.github/workflows/build_docs.yml

deploy:
needs: build
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}

runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup Pages
uses: actions/configure-pages@v5


- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4
10 changes: 5 additions & 5 deletions .github/workflows/docker-image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,29 +25,29 @@ jobs:

steps:
- name: Checkout repository
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Set up QEMU
uses: docker/setup-qemu-action@v2
uses: docker/setup-qemu-action@v3

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2

- name: Log in to the Container registry
uses: docker/login-action@v2
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@98669ae865ea3cffbcbaa878cf57c20bbf1c6c38
uses: docker/metadata-action@369eb591f429131d6889c46b94e711f089e6ca96
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}

- name: Build and push Docker image
uses: docker/build-push-action@v3
uses: docker/build-push-action@v6
with:
context: .
push: true
Expand Down
31 changes: 0 additions & 31 deletions .github/workflows/github-pages.yml

This file was deleted.

20 changes: 13 additions & 7 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ jobs:
image: ghcr.io/scientificcomputing/fenics-gmsh:2023-02-20

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4

- name: Cache
id: cache-primes
uses: actions/cache@v2
uses: actions/cache@v4
with:
path: |
~/.cache/instant
Expand All @@ -34,12 +34,18 @@ jobs:
run: |
python3 -m pytest

- name: Coverage report
uses: codecov/codecov-action@v3
if: github.ref == 'refs/heads/main'
- name: Extract Coverage
run: |
python3 -m coverage report | sed 's/^/ /' >> $GITHUB_STEP_SUMMARY
python3 -m coverage json
export TOTAL=$(python3 -c "import json;print(json.load(open('coverage.json'))['totals']['percent_covered_display'])")
echo "total=$TOTAL" >> $GITHUB_ENV

- name: Upload HTML report.
uses: actions/upload-artifact@v4
with:
fail_ci_if_error: true
files: ./coverage.xml
name: html-report
path: htmlcov

- name: Install pypa/build
run: >-
Expand Down
24 changes: 0 additions & 24 deletions .github/workflows/mpi.yml

This file was deleted.

5 changes: 0 additions & 5 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,6 @@ repos:
hooks:
- id: flake8

- repo: https://github.com/asottile/add-trailing-comma
rev: v2.4.0
hooks:
- id: add-trailing-comma

- repo: https://github.com/asottile/setup-cfg-fmt
rev: v2.2.0
hooks:
Expand Down
76 changes: 76 additions & 0 deletions demos/stiffness_sensitivity.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
# # Simple demo
#
# In this demo we show the most simple usage of the `simcardems` library using the python API.
#
# Import the necessary libraries
#

from pathlib import Path
import simcardems
import matplotlib.pyplot as plt
import numpy as np

here = Path(__file__).absolute().parent
geometry_path = here / "geometries/slab.h5"
geometry_schema_path = here / "geometries/slab.json"


def run(outdir: Path, a: float = 2.28):
outdir.mkdir(exist_ok=True, parents=True)
results_file = outdir.joinpath("results.h5")
if results_file.exists():
values = np.load(outdir.joinpath("values.npy"), allow_pickle=True).item()

t = values["time"]
lmbda = values["mechanics"]["lambda"]
return t, lmbda
config = simcardems.Config(
outdir=outdir,
geometry_path=geometry_path,
geometry_schema_path=geometry_schema_path,
coupling_type="fully_coupled_ORdmm_Land",
T=1000,
material_parameter_a=a,
)
runner = simcardems.Runner(config)
runner.solve(T=config.T, save_freq=config.save_freq, show_progress_bar=True)

loader = simcardems.datacollector.DataLoader(results_file)
values = simcardems.postprocess.extract_traces(loader, reduction="center")
np.save(outdir.joinpath("values.npy"), values)

t = values["time"]
lmbda = values["mechanics"]["lambda"]
fig, ax = plt.subplots()
ax.plot(t, lmbda)
ax.set_xlabel("Time [ms]")
ax.set_ylabel("Lambda")
ax.set_title(f"Material parameter a = {a}")
fig.savefig(outdir.joinpath(f"lambda_{a}.png"))

return t, lmbda
# simcardems.postprocess.plot_state_traces(outdir.joinpath("results.h5"), "center")


def main():
outdir = here / "results_stiffness_sensitivity"
fig, ax = plt.subplots()
a_default = 2.28
for a in [
a_default / 4.0,
a_default / 2.0,
a_default,
a_default * 2.0,
a_default * 4.0,
]:
t, lmbda = run(outdir=outdir / f"a_{a}", a=a)
ax.plot(t, lmbda, label=f"a = {a}")
ax.legend()
ax.set_xlabel("Time [ms]")
ax.set_ylabel("Lambda")
ax.set_title("Stiffness sensitivity")
fig.savefig(outdir / "stiffness_sensitivity.png")


if __name__ == "__main__":
main()
Loading
Loading