-
-
Notifications
You must be signed in to change notification settings - Fork 164
Add 3D case for partitioned heat conduction #714
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
NiklasVin
wants to merge
14
commits into
precice:develop
Choose a base branch
from
NiklasVin:partitioned-heat-conduction-3d
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
1f68e18
initial commit
NiklasVin 2447f25
add cleaning scripts
NiklasVin 7c29e80
change perm
NiklasVin 8cec8b9
follow naming convention
NiklasVin 870335b
precommit changes
NiklasVin 752e663
update participant config files
NiklasVin 7296df8
add changelog entry, minor changes in readme and clean scripts
NiklasVin cd720e6
Update changelog-entries/714.md
MakisH e522a46
Merge branch 'develop' into partitioned-heat-conduction-3d
MakisH aee2cb0
Add metadata.yaml
MakisH c0d23c9
Update handling of venv in run.sh scripts
MakisH fcd3656
Merge branch 'develop' into partitioned-heat-conduction-3d
MakisH 02d3f4e
Merge branch 'develop' into partitioned-heat-conduction-3d
MakisH c0cb137
Further updates in venv/shell
MakisH File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| - Added a 3D partitioned heat conduction tutorial with FEniCSx [#714](https://github.com/precice/tutorials/pull/714) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| --- | ||
| title: 3D partitioned heat conduction | ||
| permalink: tutorials-partitioned-heat-conduction-3d.html | ||
| keywords: FEniCSx, Heat conduction | ||
| summary: We solve a simple heat equation on a 3D domain. The domain is partitioned and the coupling is established in a Dirichlet-Neumann fashion. | ||
| --- | ||
|
|
||
| {% note %} | ||
| Get the [case files of this tutorial](https://github.com/precice/tutorials/tree/develop/partitioned-heat-conduction-3d), as continuously rendered here, or see the [latest released version](https://github.com/precice/tutorials/tree/master/partitioned-heat-conduction-3d) (if there is already one). Read how in the [tutorials introduction](https://precice.org/tutorials.html). | ||
| {% endnote %} | ||
|
|
||
| ## Setup | ||
|
|
||
| We solve a partitioned heat equation. For information on the two dimensional non-partitioned case, please refer to [1, p.37ff]. In this tutorial the computational domain is partitioned and coupled via preCICE. The coupling roughly follows the approach described in [2]. | ||
|
|
||
|  | ||
|
|
||
| The computational domain can be seen in the picture above. To get a better overview of the domain, the domains of the participants are translated. | ||
| The domain of the Neumann participant is the small box, and the Dirichlet participant's domain is the rest. In the simulation, the small box is fully contained in the Dirichlet domain. This means, the coupling interface consists of five sides of the box. | ||
|
|
||
| ## Configuration | ||
|
|
||
| preCICE configuration (image generated using the [precice-config-visualizer](https://precice.org/tooling-config-visualization.html)): | ||
|
|
||
|  | ||
|
|
||
| ## Available solvers and dependencies | ||
|
|
||
| You can either couple a solver with itself or different solvers with each other. In any case you will need to have preCICE and the python bindings installed on your system. | ||
|
|
||
| * FEniCSx. Install [FEniCS](https://fenicsproject.org/download/) and the [FEniCSx-adapter](https://github.com/precice/fenicsx-adapter). The code is adapted from the existing [fenics-tutorial](https://github.com/hplgit/fenics-tutorial/blob/master/pub/python/vol1/ft03_heat.py) from [1]. | ||
|
|
||
| ## Running the simulation | ||
|
|
||
| You can find the corresponding `run.sh` script for running the case in the folders corresponding to the participant you want to use: | ||
|
|
||
| ```bash | ||
| cd dirichlet-fenicsx | ||
| ./run.sh | ||
| ``` | ||
|
|
||
| and | ||
|
|
||
| ```bash | ||
| cd neumann-fenicsx | ||
| ./run.sh | ||
| ``` | ||
|
|
||
| ## Visualization | ||
|
|
||
| Output is written into the folders of the FEniCSx solvers (`neumann-fenicsx/output-neumann.bp` and `dirichlet-fenicsx/output-dirichlet.bp`). | ||
|
|
||
| It is sufficient to import the folders to ParaView to get the visualization of the simulation. | ||
|
|
||
| ## References | ||
|
|
||
| [1] Hans Petter Langtangen and Anders Logg. "Solving PDEs in Minutes-The FEniCS Tutorial Volume I." (2016). [pdf](https://fenicsproject.org/pub/tutorial/pdf/fenics-tutorial-vol1.pdf) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| #!/usr/bin/env sh | ||
| set -e -u | ||
|
|
||
| # shellcheck disable=SC1091 | ||
| . ../tools/cleaning-tools.sh | ||
|
|
||
| clean_tutorial . | ||
| clean_precice_logs . | ||
| rm -fv ./*.log | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| #!/usr/bin/env sh | ||
| set -e -u | ||
|
|
||
| . ../../tools/cleaning-tools.sh | ||
|
|
||
| clean_fenicsx . |
19 changes: 19 additions & 0 deletions
19
partitioned-heat-conduction-3d/dirichlet-fenicsx/precice-adapter-config-D.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| { | ||
| "participant_name": "Dirichlet", | ||
| "precice_config_file_path": "../precice-config.xml", | ||
| "interfaces": [ | ||
| { | ||
| "mesh_name": "Dirichlet-Mesh", | ||
| "write_data": [ | ||
| { | ||
| "name": "Heat-Flux" | ||
| } | ||
| ], | ||
| "read_data": [ | ||
| { | ||
| "name": "Temperature" | ||
| } | ||
| ] | ||
| } | ||
| ] | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| #!/usr/bin/env bash | ||
| set -e -u | ||
|
|
||
| if [ ! -v PRECICE_TUTORIALS_NO_VENV ] | ||
| then | ||
| if [ ! -d ".venv" ]; then | ||
| python3 -m venv --system-site-packages .venv | ||
| . .venv/bin/activate | ||
| pip install -r ../solver-fenicsx/requirements.txt | ||
| else | ||
| . .venv/bin/activate | ||
| fi | ||
| fi | ||
|
|
||
| python3 ../solver-fenicsx/heat.py Dirichlet --error-tol 10e-3 |
Binary file added
BIN
+26.2 KB
...ed-heat-conduction-3d/images/tutorials-partitioned-heat-conduction-3d-setup.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| name: Partitioned heat conduction 3D | ||
| path: partitioned-heat-conduction-3d # relative to git repo | ||
| url: https://precice.org/tutorials-partitioned-heat-conduction-3d.html | ||
|
|
||
| participants: | ||
| - Dirichlet | ||
| - Neumann | ||
|
|
||
| cases: | ||
| # dirichlet-fenicsx: | ||
| # participant: Dirichlet | ||
| # directory: ./dirichlet-fenicsx | ||
| # run: ./run.sh | ||
| # component: fenicsx-adapter | ||
|
|
||
| # neumann-fenicsx: | ||
| # participant: Neumann | ||
| # directory: ./neumann-fenicsx | ||
| # run: ./run.sh | ||
| # component: fenicsx-adapter |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| #!/usr/bin/env sh | ||
| set -e -u | ||
|
|
||
| . ../../tools/cleaning-tools.sh | ||
|
|
||
| clean_fenicsx . |
19 changes: 19 additions & 0 deletions
19
partitioned-heat-conduction-3d/neumann-fenicsx/precice-adapter-config-N.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| { | ||
| "participant_name": "Neumann", | ||
| "precice_config_file_path": "../precice-config.xml", | ||
| "interfaces": [ | ||
| { | ||
| "mesh_name": "Neumann-Mesh", | ||
| "write_data": [ | ||
| { | ||
| "name": "Temperature" | ||
| } | ||
| ], | ||
| "read_data": [ | ||
| { | ||
| "name": "Heat-Flux" | ||
| } | ||
| ] | ||
| } | ||
| ] | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| #!/usr/bin/env bash | ||
| set -e -u | ||
|
|
||
| if [ ! -v PRECICE_TUTORIALS_NO_VENV ] | ||
| then | ||
| if [ ! -d ".venv" ]; then | ||
| python3 -m venv --system-site-packages .venv | ||
| . .venv/bin/activate | ||
| pip install -r ../solver-fenicsx/requirements.txt | ||
| else | ||
| . .venv/bin/activate | ||
| fi | ||
| fi | ||
|
|
||
| python3 ../solver-fenicsx/heat.py Neumann --error-tol 10e-3 |
|
MakisH marked this conversation as resolved.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,80 @@ | ||
| <?xml version="1.0" encoding="UTF-8" ?> | ||
| <precice-configuration experimental="false"> | ||
| <log> | ||
| <sink | ||
| filter="%Severity% > debug and %Rank% = 0" | ||
| format="---[precice] %ColorizedSeverity% %Message%" | ||
| enabled="true" /> | ||
| </log> | ||
|
|
||
| <data:scalar name="Temperature" waveform-degree="1" /> | ||
| <data:vector name="Heat-Flux" waveform-degree="1" /> | ||
|
|
||
| <mesh name="Dirichlet-Mesh" dimensions="3"> | ||
| <use-data name="Temperature" /> | ||
| <use-data name="Heat-Flux" /> | ||
| </mesh> | ||
|
|
||
| <mesh name="Neumann-Mesh" dimensions="3"> | ||
| <use-data name="Temperature" /> | ||
| <use-data name="Heat-Flux" /> | ||
| </mesh> | ||
|
|
||
| <participant name="Dirichlet"> | ||
| <provide-mesh name="Dirichlet-Mesh" /> | ||
| <receive-mesh name="Neumann-Mesh" from="Neumann" api-access="false" /> | ||
| <write-data name="Heat-Flux" mesh="Dirichlet-Mesh" /> | ||
| <read-data name="Temperature" mesh="Dirichlet-Mesh" /> | ||
| <mapping:rbf-pum-direct | ||
| direction="read" | ||
| from="Neumann-Mesh" | ||
| to="Dirichlet-Mesh" | ||
| constraint="consistent" | ||
| project-to-input="false" | ||
| relative-overlap="0.75" | ||
| vertices-per-cluster="90" | ||
| polynomial="separate"> | ||
| <basis-function:compact-polynomial-c8 support-radius="2.0" /> | ||
| </mapping:rbf-pum-direct> | ||
| </participant> | ||
|
|
||
| <participant name="Neumann"> | ||
| <provide-mesh name="Neumann-Mesh" /> | ||
| <receive-mesh name="Dirichlet-Mesh" from="Dirichlet" api-access="false" /> | ||
| <write-data name="Temperature" mesh="Neumann-Mesh" /> | ||
| <read-data name="Heat-Flux" mesh="Neumann-Mesh" /> | ||
| <mapping:nearest-neighbor | ||
| direction="read" | ||
| from="Dirichlet-Mesh" | ||
| to="Neumann-Mesh" | ||
| constraint="consistent" /> | ||
| </participant> | ||
|
|
||
| <m2n:sockets acceptor="Dirichlet" connector="Neumann" exchange-directory=".." /> | ||
|
|
||
| <coupling-scheme:serial-implicit> | ||
| <participants first="Dirichlet" second="Neumann" /> | ||
| <max-time value="1.0" /> | ||
| <time-window-size value="0.1" /> | ||
| <max-iterations value="200" /> | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The 2D |
||
| <exchange | ||
| data="Heat-Flux" | ||
| mesh="Dirichlet-Mesh" | ||
| from="Dirichlet" | ||
| to="Neumann" | ||
| initialize="true" | ||
| substeps="true" /> | ||
| <exchange | ||
| data="Temperature" | ||
| mesh="Neumann-Mesh" | ||
| from="Neumann" | ||
| to="Dirichlet" | ||
| initialize="true" | ||
| substeps="true" /> | ||
| <relative-convergence-measure data="Heat-Flux" mesh="Dirichlet-Mesh" limit="1e-10" /> | ||
| <relative-convergence-measure data="Temperature" mesh="Neumann-Mesh" limit="1e-10" /> | ||
| <acceleration:constant> | ||
| <relaxation value="0.2" /> | ||
| </acceleration:constant> | ||
| </coupling-scheme:serial-implicit> | ||
| </precice-configuration> | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| #!/usr/bin/env bash | ||
| set -e -u | ||
|
|
||
| . ../../tools/cleaning-tools.sh | ||
|
|
||
| clean_fenicsx . |
21 changes: 21 additions & 0 deletions
21
partitioned-heat-conduction-3d/solver-fenicsx/errorcomputation.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| from dolfinx import fem | ||
| import numpy as np | ||
| from mpi4py import MPI | ||
| import ufl | ||
|
|
||
|
|
||
| def compute_errors(u_approx, u_ref, total_error_tol=10 ** -7): | ||
| mesh = u_ref.function_space.mesh | ||
| # Compute L2 error and error at nodes | ||
| error_L2 = np.sqrt(mesh.comm.allreduce(fem.assemble_scalar(fem.form((u_approx - u_ref)**2 * ufl.dx)), op=MPI.SUM)) | ||
| if mesh.comm.rank == 0: | ||
| print(f"L2-error: {error_L2:.2e}") | ||
|
|
||
| # Compute values at mesh vertices | ||
| error_max = mesh.comm.allreduce(np.max(np.abs(u_approx.x.array - u_ref.x.array)), op=MPI.MAX) | ||
| if mesh.comm.rank == 0: | ||
| print(f"Error_max: {error_max:.2e}") | ||
|
|
||
| assert (error_L2 < total_error_tol) | ||
|
|
||
| return (error_L2, error_max) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remember to also prepare the respective changes to the website. See the latest PR template: https://github.com/precice/tutorials/blob/develop/.github/pull_request_template.md