Skip to content

Commit b6d956d

Browse files
NiklasVinIshaanDesai
authored andcommitted
Add FEniCSx solver for partitioned heat conduction tutorial (precice#687)
* Add FEniCSx version of partitioned heat conduction tutorial --------- Co-authored-by: Ishaan Desai <ishaandesai@gmail.com>
1 parent 5aaaf47 commit b6d956d

15 files changed

Lines changed: 489 additions & 1 deletion

File tree

changelog-entries/687.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
- Added FEniCSx solver for the partitioned heat conduction tutorial following the [FEniCS solver](https://github.com/precice/tutorials/tree/develop/partitioned-heat-conduction/solver-fenics). [#687](https://github.com/precice/tutorials/pull/687)

partitioned-heat-conduction/README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@ preCICE configuration (image generated using the [precice-config-visualizer](htt
3131

3232
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.
3333

34-
* FEniCS. Install [FEniCS](https://fenicsproject.org/download/) and the [FEniCS-adapter](https://github.com/precice/fenics-adapter). The code is largely based on this [fenics-tutorial](https://github.com/hplgit/fenics-tutorial/blob/master/pub/python/vol1/ft03_heat.py) from [1].
34+
* FEniCS. Install [FEniCS](https://fenicsproject.org/download/archive/) and the [FEniCS-adapter](https://github.com/precice/fenics-adapter). The code is largely based on this [fenics-tutorial](https://github.com/hplgit/fenics-tutorial/blob/master/pub/python/vol1/ft03_heat.py) from [1].
35+
36+
* FEniCSx. Install [FEniCSx](https://fenicsproject.org/download/) and the [FEniCSx-adapter](https://github.com/precice/fenicsx-adapter). The code is largely based on this [fenics-tutorial](https://github.com/hplgit/fenics-tutorial/blob/master/pub/python/vol1/ft03_heat.py) from [1].
3537

3638
* Nutils. Install [Nutils](https://nutils.org/install-nutils.html).
3739

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/usr/bin/env sh
2+
set -e -u
3+
4+
. ../../tools/cleaning-tools.sh
5+
6+
clean_fenicsx .
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"participant_name": "Dirichlet",
3+
"precice_config_file_path": "../precice-config.xml",
4+
"interfaces": [
5+
{
6+
"mesh_name": "Dirichlet-Mesh",
7+
"write_data": [
8+
{
9+
"name": "Heat-Flux"
10+
}
11+
],
12+
"read_data": [
13+
{
14+
"name": "Temperature"
15+
}
16+
]
17+
}
18+
]
19+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/bin/sh
2+
set -e -u
3+
4+
python3 -m venv --system-site-packages .venv
5+
. .venv/bin/activate
6+
pip install -r ../solver-fenicsx/requirements.txt
7+
8+
python3 ../solver-fenicsx/heat.py Dirichlet
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/usr/bin/env sh
2+
set -e -u
3+
4+
. ../../tools/cleaning-tools.sh
5+
6+
clean_fenicsx .
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"participant_name": "Neumann",
3+
"precice_config_file_path": "../precice-config.xml",
4+
"interfaces": [
5+
{
6+
"mesh_name": "Neumann-Mesh",
7+
"write_data": [
8+
{
9+
"name": "Temperature"
10+
}
11+
],
12+
"read_data": [
13+
{
14+
"name": "Heat-Flux"
15+
}
16+
]
17+
}
18+
]
19+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/bin/sh
2+
set -e -u
3+
4+
python3 -m venv --system-site-packages .venv
5+
. .venv/bin/activate
6+
pip install -r ../solver-fenicsx/requirements.txt
7+
python3 ../solver-fenicsx/heat.py Neumann
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/bin/sh
2+
set -e -u
3+
4+
. ../../tools/cleaning-tools.sh
5+
6+
clean_fenicsx .
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
from dolfinx import fem
2+
import numpy as np
3+
from mpi4py import MPI
4+
import ufl
5+
6+
7+
def compute_errors(u_approx, u_ref, total_error_tol=10 ** -9):
8+
mesh = u_ref.function_space.mesh
9+
# Compute L2 error and error at nodes
10+
error_L2 = np.sqrt(mesh.comm.allreduce(fem.assemble_scalar(fem.form((u_approx - u_ref)**2 * ufl.dx)), op=MPI.SUM))
11+
if mesh.comm.rank == 0:
12+
print(f"L2-error: {error_L2:.2e}")
13+
14+
# Compute values at mesh vertices
15+
error_max = mesh.comm.allreduce(np.max(np.abs(u_approx.x.array - u_ref.x.array)), op=MPI.MAX)
16+
if mesh.comm.rank == 0:
17+
print(f"Error_max: {error_max:.2e}")
18+
19+
assert (error_L2 < total_error_tol)
20+
21+
return (error_L2, error_max)

0 commit comments

Comments
 (0)