Skip to content
Merged
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
1 change: 1 addition & 0 deletions changelog-entries/687.md
Original file line number Diff line number Diff line change
@@ -0,0 +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)
4 changes: 3 additions & 1 deletion partitioned-heat-conduction/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ preCICE configuration (image generated using the [precice-config-visualizer](htt

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.

* 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].
* 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].

* 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].

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

Expand Down
6 changes: 6 additions & 0 deletions partitioned-heat-conduction/dirichlet-fenicsx/clean.sh
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 .
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"
}
]
}
]
}
8 changes: 8 additions & 0 deletions partitioned-heat-conduction/dirichlet-fenicsx/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/sh
set -e -u

python3 -m venv --system-site-packages .venv
. .venv/bin/activate
pip install -r ../solver-fenicsx/requirements.txt

python3 ../solver-fenicsx/heat.py Dirichlet
6 changes: 6 additions & 0 deletions partitioned-heat-conduction/neumann-fenicsx/clean.sh
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 .
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"
}
]
}
]
}
7 changes: 7 additions & 0 deletions partitioned-heat-conduction/neumann-fenicsx/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/sh
set -e -u

python3 -m venv --system-site-packages .venv
. .venv/bin/activate
pip install -r ../solver-fenicsx/requirements.txt
python3 ../solver-fenicsx/heat.py Neumann
6 changes: 6 additions & 0 deletions partitioned-heat-conduction/solver-fenicsx/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_fenicsx .
21 changes: 21 additions & 0 deletions partitioned-heat-conduction/solver-fenicsx/errorcomputation.py
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 ** -9):
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)
Loading
Loading