Skip to content
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

Add muscle tutorial #471

Draft
wants to merge 42 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 34 commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
822cb19
Create tutorial structure
carme-hp Feb 26, 2024
cc8b43c
Add sample structure for an opendihu participant
carme-hp Feb 26, 2024
feef2d0
Move src code to opendihu-solver folder
carme-hp Feb 27, 2024
cfbe718
Complete opendihu participants
carme-hp Feb 27, 2024
3eb5bb0
Update README
carme-hp Feb 27, 2024
b559c85
Get muscle participant to run
carme-hp Feb 29, 2024
1b4f1fe
Add check for OPENDIHU_HOME
carme-hp Mar 4, 2024
0cb1947
Rename meshName to preciceMeshName
carme-hp Mar 4, 2024
bcbc6fd
Fix rename
carme-hp Mar 4, 2024
ff5ed78
Fix paths, variables and add scripts
carme-hp Mar 4, 2024
a80cfaa
Add remove precice-run to clean.sh
carme-hp Mar 5, 2024
b383782
Fix bc errors
carme-hp Mar 5, 2024
0bdcb05
Setup exchange directory and remove comments
carme-hp Mar 5, 2024
c6091ae
Add information about OpenDiHu
carme-hp Mar 10, 2024
1d31091
Add .gitignore
carme-hp Mar 10, 2024
f555039
Merge branch 'develop' into add-muscle-tutorial
MakisH Mar 11, 2024
6bfa0a9
Fix Markdown linting issues in muscle tutorial README
MakisH Mar 11, 2024
5459862
Fix Markdown linting issues in muscle tutorial README
MakisH Mar 11, 2024
c3b4db8
Remove unrelated results image - fix check.sh
MakisH Mar 11, 2024
b24c63d
Mark shell scripts as executable
MakisH Mar 11, 2024
50333ef
Fix shellcheck errors
MakisH Mar 11, 2024
0a5858a
Format with autopep8
MakisH Mar 11, 2024
e3bd5e2
Bump GItHub Action autopep8 from v1 to v2
MakisH Mar 11, 2024
83f7597
Format more files with autopep8
MakisH Mar 11, 2024
dcd7a3f
Double --aggressive autopep8
MakisH Mar 11, 2024
f9325f3
Double --aggressive autopep8
MakisH Mar 11, 2024
bbfa73e
Minor fixes in muscle tutorial README
MakisH Mar 11, 2024
9660161
Add a clean_opendihu function, adjust cleaning scripts
MakisH Mar 11, 2024
13ccd83
Rename opendihu-solver to solver-opendihu
MakisH Mar 11, 2024
d9141f5
solver-opendihu scripts: set -e -u
MakisH Mar 11, 2024
9ec1cdb
Fix clean_opendihu call to clean_precice_logs
MakisH Mar 11, 2024
b3602f0
Further fixes in solver-opendihu/clean.sh
MakisH Mar 11, 2024
e908415
Apply set -e -u to more shell scripts
MakisH Mar 11, 2024
b7e9272
Format precice-config.xml
MakisH Mar 11, 2024
2e6dc39
Update muscle-tendon-complex/README.md
carme-hp Mar 11, 2024
09d53d6
Update muscle-tendon-complex/solver-opendihu/src/tendon-solver.cpp
carme-hp Mar 11, 2024
37233da
Update muscle-tendon-complex/solver-opendihu/src/muscle-solver.cpp
carme-hp Mar 11, 2024
76b5a0f
Explain activation and add citation
carme-hp Mar 11, 2024
db6820e
Use pre-commit
carme-hp Mar 11, 2024
535342f
Use pre-commit
carme-hp Mar 11, 2024
75c09ff
Merge branch 'add-muscle-tutorial' of github.com:carme-hp/tutorials i…
carme-hp Mar 11, 2024
755c3e4
Add automatically generated folder to gitignore
carme-hp Mar 11, 2024
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
2 changes: 1 addition & 1 deletion .github/workflows/check-pep8.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
- uses: actions/checkout@v2
- name: autopep8
id: autopep8
uses: peter-evans/autopep8@v1
uses: peter-evans/autopep8@v2
with:
args: --recursive --diff --aggressive --aggressive --exit-code --ignore E402 --max-line-length 120 .
- name: Fail if autopep8 made changes
Expand Down
12 changes: 12 additions & 0 deletions muscle-tendon-complex/.gitignore
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See #477 and restrict this to the difference (let's better wait until it is merged).
Are all of these files generated with the default instructions, or are some rules only as "just in case"?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry I don't understand. Which default instructions are you referring to?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I meant "are all these rules to ignore files that will actually be generated when I try to run the tutorial?".

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes! Some when building and some when running

Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
**/__pycache__
**/lib
**/logs
**/out
**/*.log
**/*.txt
**/precice-profiling
**/build_release
**/muscle-solver
**/tendon-solver
**/.sconf_temp
**/.scons*
123 changes: 123 additions & 0 deletions muscle-tendon-complex/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
---
title: Muscle-tendon complex
permalink: tutorials-muscle-tendon-complex.html
keywords: multi-coupling, OpenDiHu, skeletal muscle
summary: In this case, a skeletal muscle (biceps) and three tendons are coupled together using a fully-implicit multi-coupling scheme.
---

{% note %}
Get the [case files of this tutorial](https://github.com/precice/tutorials/tree/master/muscle-tendon-complex). Read how in the [tutorials introduction](https://www.precice.org/tutorials.html).
{% endnote %}

## Case Setup

In the following tutorial, we model the contraction of a muscle (the biceps). The biceps is attached to the bones by three tendons (one at the bottom and two at the top). We enforce an activation in the muscle which results in its contraction. The tendons move as a result of the muscle contraction. In this case, a muscle and three tendons are coupled together using a fully-implicit multi-coupling scheme. The case setup is shown in the following figure:

![Setup](images/tutorials-muscle-tendon-complex-setup.png)

The muscle participant (in red) is connected to three tendons. The muscle sends traction values to the tendons, which send displacement and velocity values back to the muscle. The end of each tendon which is not attached to the muscle is fixed by a dirichlet boundary condition (in reality, it would be fixed to the bones).

The muscle and tendon meshes are obtained from patient imaging. The interfaces of the tendons and the muscle do not perfectly match, which is a quite common issue due to the limitations of imaging methods and postprocessing tools. Nonetheless, preCICE coupling methods are robust and can handle meshes that do not perfectly match.

TODO: Explain how is the muscle activated!
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't this already covered later on by the following?

The electrical signal triggers chemical reactions which lead to the contraction of sarcomeres, the smallest contraction unit in the muscle.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried to make it clear in a new commit.


## Why multi-coupling?

This is a case with four participants: the muscle and each tendon. In preCICE, there are two options to [couple more than two participants](https://www.precice.org/configuration-coupling-multi.html). The first option is a composition of bi-coupling schemes, in which we must specify the exchange of data in a participant-to-participant manner. However, such a composition is not suited for combining multiple strong fluid-structure interactions [1]. Thus, in this case, we use the second option, fully-implicit multi-coupling. For another multi-coupling tutorial, you can refer to the [multiple perpendicular flaps tutorial](http://precice.org/tutorials-multiple-perpendicular-flaps.html).
carme-hp marked this conversation as resolved.
Show resolved Hide resolved

We can set this in our `precice-config.xml`:

```xml
<coupling-scheme:multi>
<participant name="Muscle" control="yes"/>
<participant name="Tendon-Bottom"/>
<participant name="Tendon-Top-A"/>
<participant name="Tendon-Top-B"/>
```

The participant that has the control is the one that it is connected to all other participants. This is why we have chosen the muscle participant for this task.

## About the solvers

We use solvers based on [OpenDiHu](https://github.com/opendihu/opendihu) for all participants.

**The muscle solver** consists of a multi-physcis multi-scale solver itself. It combines two OpenDiHu solvers in one: the *FastMonodomainSolver* and the *MuscleContractionSolver*. The two solvers are coupled using the OpenDiHu coupling tool for weak coupling.

- The [FastMonodomainSolver](https://opendihu.readthedocs.io/en/latest/settings/fast_monodomain_solver.html) models the electrochemical processes that take place in the muscle fibers, i.e, how an electrical signal propagates from the center to the extremes of the muscle fibers. The electrical signal triggers chemical reactions which lead to the contraction of sarcomeres, the smallest contraction unit in the muscle. The solver solves the so called "monodomain equation" independently for each fiber. The equation has a reaction term (small time scale) and a diffusion term (large time scale) and is solved using Strang splitting. The sarcomeres, i.e., the reaction term, are modelled using a variant of the Shorten model, specified by the CellML file `opendihu/examples/electrophysiology/input/2020_06_03_hodgkin-huxley_shorten_ocallaghan_davidson_soboleva_2007.cellm`.

- The [MuscleContractionSolver](https://opendihu.readthedocs.io/en/latest/settings/muscle_contraction_solver.html) models the mechanics of the muscle. It consists of a dynamic FEM solver that models an hyperelastic active material. The active component is calculated from the active paramter $\gamma$, which ranges from 0 (no activation) to 1 (maximum activation) and is calculated in the *FastMonodomainSolver*. The material parameters are chosen as in [Heidlauf et al.](https://link.springer.com/article/10.1007/s10237-016-0772-7)

**The tendon solver** is a dynamic FEM mechanical solver. It models an hyperelastic passive material. The material parameters are chosen as in [Carniel et al.](https://pubmed.ncbi.nlm.nih.gov/28238424/)

## Running the Simulation

1. Preparation:
- Install OpenDiHu

In the OpenDiHu website you can find detailed [installation instructions](https://opendihu.readthedocs.io/en/latest/user/installation.html).
We recommend to download the code from the [GitHub repository](https://github.com/opendihu/opendihu) and to run `make release_without_tests` in the parent directory.

{% note %}
OpenDiHu automatically downloads dependencies and installs them in the `opendihu/dependencies/` folder. You can avoid that by setting e.g., `PRECICE_DOWNLOAD = False` in the [user-variables.scons.py](https://github.com/opendihu/opendihu/blob/develop/user-variables.scons.py) before building OpenDiHu.
{% endnote %}

- Download input files for OpenDiHu

OpenDiHu requires input files hosted in [Zenodo](https://zenodo.org/records/4705982) which include CellML files (containing model equations) and mesh files. Downloading these files is necessary to simulate muscles and/or tendons with OpenDiHu. You can [directly download the necessary files](https://zenodo.org/record/4705982/files/input.tgz?download=1). Extract the files and place them in the `opendihu/examples/electrophysiology/` directory.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do they really need to be downloaded into the opendihu source directory? What if that is a system directory? What if it is generally a frozen installation?

Can we move these to a local path, or to an OPENDIHU_EXAMPLES directory?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure I understand your point.
Would path/to/opendihu/examples/electrophysiology/ be better?
Or OPENDIHU_HOME/examples/electrophysiology/.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, I mean that it is strange to first get OpenDiHu (imagine in the future a sudo apt install opendihu) and then copy the examples into the installation directory (similarly to sudo apt install opendihu-examples).

What I suggest is to decouple them from the actual installation (for the tutorial) and be able to use them from any directory.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mmh I think you mean the input files and not the examples. The input files are downloaded separately because they are 1.5 GB and thus too big for GitHub.
Alternatives I see instead of moving the downloaded files are

  • option 1: user has to define OPENDIHU_INPUT_DIR
# input files
# -----------
import os
input_dir = os.environ.get('OPENDIHU_INPUT_DIR')
fiber_file = input_dir + "/left_biceps_brachii_9x9fibers.bin"
  • option 2: user has to edit variables.py
# input files
# -----------
input_dir = path/to/input
fiber_file = input_dir + "/left_biceps_brachii_9x9fibers.bin"

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that option 2 is more intuitive for the user, while option 1 is better for scripting/automation.

Anything is fine, as long as this path if configurable.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

okay, I decided for option 2, because I think this is something I could generally do in OpenDiHu.


- Setup `$OPENDIHU_HOME` to your `.bashrc` file

```bash
export OPENDIHU_HOME=/path/to/opendihu
```

- Compile muscle and tendon solvers

```bash
cd solver-opendihu
./build.sh
```

2. Starting the simulation:

We are going to run each solver in a different terminal. It is important that first we navigate to the respective case directory, so that all solvers start from directories with same parent directory (see `exchange-directory` in the `precice-config.xml`).
To start the `Muscle` participant, run:

```bash
cd muscle-opendihu
./run.sh
```

To start the `Tendon-Bottom` participant, run:

```bash
cd tendon-bottom-opendihu
./run.sh
```

To start the `Tendon-Top-A` participant, run:

```bash
cd tendon-top-A-opendihu
./run.sh
```

Finally, to start the `Tendon-Top-B` participant, run:

```bash
cd tendon-top-B-opendihu
./run.sh
```

## Postprocessing... TODO

After the simulation has finished, you can visualize your results using e.g. ParaView.

## References TODO

<!-- markdownlint-configure-file {"MD034": false } -->
[1] H. Bungartz, F. Linder, M. Mehl, B. Uekermann. A plug-and-play coupling approach for parallel multi-field simulations. *Comput Mech* **55**, 1119-1129 (2015). https://doi.org/10.1007/s00466-014-1113-2

{% disclaimer %}
This offering is not approved or endorsed by OpenCFD Limited, producer and distributor of the OpenFOAM software via www.openfoam.com, and owner of the OPENFOAM® and OpenCFD® trade marks.
{% enddisclaimer %}
1 change: 1 addition & 0 deletions muscle-tendon-complex/clean-tutorial.sh
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions muscle-tendon-complex/muscle-opendihu/clean.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/sh
set -e -u

. ../../tools/cleaning-tools.sh

clean_opendihu .
Loading
Loading