| 1 |
<i> |
| 2 |
This program was contributed by Magdalena Schreter-Fleischhacker |
| 3 |
and Peter Munch. Many ideas presented here are the result of common code |
| 4 |
development with Maximilian Bergbauer, Marco Feder, |
| 5 |
Niklas Fehn, Johannes Heinz, Luca Heltai, Martin Kronbichler, Nils Much, |
| 6 |
and Judith Pauen. |
| 7 |
|
| 8 |
This tutorial is loosely based on chapter 3.4 of the submitted |
| 9 |
PhD thesis "Matrix-free finite element computations at extreme scale and for |
| 10 |
challenging applications" by Peter Munch. Magdalena Schreter-Fleischhacker |
| 11 |
is funded by the Austrian Science Fund (FWF) Schrödinger Fellowship (J4577). |
| 12 |
</i> |
| 13 |
|
| 14 |
@dealiiTutorialDOI{10.5281/zenodo.8411345,https://zenodo.org/badge/DOI/10.5281/zenodo.8411345.svg} |
| 15 |
|
| 16 |
<a name="step_87-Intro"></a> |
| 17 |
<h1>Introduction</h1> |
| 18 |
|
| 19 |
This tutorial presents the advanced point-evaluation functionalities of |
| 20 |
deal.II, specifically useful for evaluating finite element solutions at |
| 21 |
arbitrary points. The underlying finite element mesh can be distributed |
| 22 |
among processes, which makes the operations more involved due to communication. |
| 23 |
In the examples discussed in this tutorial, we focus on point evaluation for |
| 24 |
MPI-parallel computations, like parallel::distributed::Triangulation. |
| 25 |
Nevertheless, the application to non-distributed meshes is also possible. |
| 26 |
|
| 27 |
<h3>%Point evaluation</h3> |
| 28 |
|
| 29 |
In the context of the finite element method (FEM), it is a common task to |
| 30 |
query the solution $u$ at an arbitrary point $\boldsymbol{x}_q$ in the |
| 31 |
domain of interest $\Omega$ |
| 32 |
@f[ |
| 33 |
u(\boldsymbol{x}_q) = \sum_{i} N_i(\boldsymbol{x}_q) u_i \quad\text{with}\quad |
| 34 |
i\in[0,n_{\text{dofs}}), |
| 35 |
@f] |
| 36 |
by evaluating the shape functions $N_i$ at this point together with the |
| 37 |
corresponding solution coefficients $u_i$. |
| 38 |
After identifying the cell $K$ where the point $\boldsymbol{x}_q$ resides, the |
| 39 |
transformation between $\boldsymbol{x}_q$ and the corresponding coordinates in |
| 40 |
the reference cell $\hat{\boldsymbol{x}}_q$ is obtained by the mapping |
| 41 |
$\boldsymbol{x}_q=\boldsymbol{F}_K(\hat{\boldsymbol{x}}_q)$. In this setting, |
| 42 |
the evaluation of the solution at an arbitrary point boils down to a cell-local |
| 43 |
evaluation |
| 44 |
@f[ |
| 45 |
u(\boldsymbol{x}_q) = \sum_{i} \hat{N}^K_i(\hat{\boldsymbol{x}}_q) u_i^K |
| 46 |
\quad\text{with}\quad i\in[0,n_{\text{dofs\_per\_cell}}), |
| 47 |
@f] |
| 48 |
with $\hat{N}^K_i$ being the shape functions defined on the reference cell and |
| 49 |
$u_i^{K}$ the solution coefficients |
| 50 |
restricted to the cell $K$. |
| 51 |
|
| 52 |
Alternatively to point evaluation, evaluating weak-form (integration) operations |
| 53 |
of the type |
| 54 |
@f[ |
| 55 |
u_i |
| 56 |
= |
| 57 |
\left(N_i(\boldsymbol{x}), u(\boldsymbol{x})\right)_\Omega |
| 58 |
= |
| 59 |
\int_{\Omega} N_i(\boldsymbol{x}) u(\boldsymbol{x}) dx |
| 60 |
= |
| 61 |
\sum_q N_i\left(\boldsymbol{x}_q\right) u\left(\boldsymbol{x}_q\right) |J\left( |
| 62 |
\boldsymbol{x}_q\right)| w\left(\boldsymbol{x}_q\right) \quad\text{with}\quad |
| 63 |
i\in[0,n_{\text{dofs}}) |
| 64 |
@f] |
| 65 |
is possible, with $\boldsymbol{x}_q$ being quadrature points at arbitrary |
| 66 |
positions. |
| 67 |
After the values at the quadrature points have been multiplied by the |
| 68 |
integration weights, this operation can be interpreted as the transpose of the |
| 69 |
evaluation. Not surprisingly, such an operation can be also implemented as a |
| 70 |
cell loop. |
| 71 |
|
| 72 |
<h3>Setup and communication</h3> |
| 73 |
|
| 74 |
To determine the cell $K$ and the reference position $\hat{\boldsymbol x}_q$ |
| 75 |
within the cell for a given point $\boldsymbol{x}_q$ on distributed meshes, |
| 76 |
deal.II performs a two-level-search approach. First, all processes whose portion |
| 77 |
of the global mesh might contain the point are determined ("coarse search"). |
| 78 |
For this purpose, e.g., a distributed tree based on bounding boxes around |
| 79 |
locally owned domains using "ArborX" @cite lebrun2020arborx is applied. After |
| 80 |
the potentially owning processes have been determined and the points have been |
| 81 |
sent to them as a request, one can start to find the cells that surround the |
| 82 |
points among locally owned cells ("fine search"). In order to accelerate this |
| 83 |
search, an R-tree from "boost::geometry" built around the vertices of the mesh |
| 84 |
is used. |
| 85 |
|
| 86 |
Once the cell $K$ that surrounds point $\boldsymbol{x}_q$ has been found, |
| 87 |
the reference position $\hat{\boldsymbol{x}}_q$ is obtained by performing the |
| 88 |
minimization: |
| 89 |
@f[ |
| 90 |
\min_{\hat{\boldsymbol{x}}_q}(| \boldsymbol{F}_K(\hat{\boldsymbol{x}}_q) |
| 91 |
- {\boldsymbol{x}_q}|) |
| 92 |
\quad |
| 93 |
\text{with} |
| 94 |
\quad |
| 95 |
\hat{\boldsymbol{x}}_q\in[0,1]^{dim}. |
| 96 |
@f] |
| 97 |
With the determined pieces of information, the desired evaluation can be |
| 98 |
performed by the process that owns the cell. The result can now be communicated |
| 99 |
to the requesting process. |
| 100 |
|
| 101 |
In summary, the coarse search determines, for each point, a list of processes |
| 102 |
that might own it. The subsequent fine search by each process determines whether |
| 103 |
the processes actually own these points by the sequence of request |
| 104 |
("Does the process own the point?") and answer ("Yes."/"No."). |
| 105 |
Processes might post any number of point requests and communicate with |
| 106 |
any process. We propose to collect the point requests to a process to |
| 107 |
use the dynamic, sparse, scalable consensus-based communication |
| 108 |
algorithms @cite hoefler2010scalable, and to consider the obtained information |
| 109 |
to set up point-to-point communication patterns. |
| 110 |
|
| 111 |
<h3>Implementation: Utilities::MPI::RemotePointEvaluation</h3> |
| 112 |
|
| 113 |
The algorithm described above is implemented in |
| 114 |
Utilities::MPI::RemotePointEvaluation (short: "rpe") and related |
| 115 |
classes/functions. In this section, basic functionalities are briefly |
| 116 |
summarized. Their advanced capabilities will be shown subsequently based on |
| 117 |
concrete application cases. |
| 118 |
|
| 119 |
The following code snippet shows the setup steps for the communication pattern: |
| 120 |
@code |
| 121 |
std::vector<Point<dim>> points; // ... (filling of points not shown) |
| 122 |
|
| 123 |
RemotePointEvaluation<dim> rpe; |
| 124 |
rpe.reinit(points, triangulation, mapping); |
| 125 |
@endcode |
| 126 |
|
| 127 |
All what is needed is a list of evaluation points and the mesh with a mapping. |
| 128 |
|
| 129 |
The following code snippet shows the evaluation steps: |
| 130 |
@code |
| 131 |
const std::function<void(const ArrayView<T> &, const CellData &)> |
| 132 |
evaluation_function; |
| 133 |
|
| 134 |
std::vector<T> output; |
| 135 |
rpe.evaluate_and_process(output, evaluation_function); |
| 136 |
|
| 137 |
@endcode |
| 138 |
|
| 139 |
The user provides a function that processes the locally owned points. |
| 140 |
These values are communicated by Utilities::MPI::RemotePointEvaluation. |
| 141 |
|
| 142 |
The relevant class during the local evaluation is |
| 143 |
Utilities::MPI::RemotePointEvaluation::CellData. It allows to loop over |
| 144 |
cells that surround the points. On these cells, |
| 145 |
a cell iterator and the positions in the reference cell of the |
| 146 |
requested points can be queried. Furthermore, this class provides |
| 147 |
controlled access to the output vector of the |
| 148 |
Utilities::MPI::RemotePointEvaluation::evaluate_and_process() function. |
| 149 |
@code |
| 150 |
for (const auto cell_index : cell_data.cell_indices()) |
| 151 |
{ |
| 152 |
const auto cell = cell_data.get_active_cell_iterator(cell_index); |
| 153 |
const auto unit_points = cell_data.get_unit_points(cell_index); |
| 154 |
const auto local_output = cell_data.get_data_view(cell_index, output); |
| 155 |
} |
| 156 |
@endcode |
| 157 |
|
| 158 |
The functions |
| 159 |
@code |
| 160 |
const auto evaluated_values = |
| 161 |
VectorTools::point_values<n_components>(rpe, dof_handler, vector); |
| 162 |
|
| 163 |
const auto evaluated_gradients = |
| 164 |
VectorTools::point_gradients<n_components>(rpe, dof_handler, vector); |
| 165 |
@endcode |
| 166 |
|
| 167 |
evaluate the values and gradients of a solution defined by DoFHandler and a |
| 168 |
vector at the requested points. Internally, a lambda function is passed to |
| 169 |
Utilities::MPI::RemotePointEvaluation. |
| 170 |
Additionally it handles the special case if points belong to multiple cells |
| 171 |
by taking, e.g., the average, the minimum, or |
| 172 |
the maximum via an optional argument of type EvaluationFlags::EvaluationFlags. |
| 173 |
This occurs when a point lies on a cell boundary or within a small tolerance |
| 174 |
around it and might be relevant for discontinuous solution quantities, such |
| 175 |
as values of discontinuous Galerkin methods or gradients in continuous finite |
| 176 |
element methods. |
| 177 |
|
| 178 |
|
| 179 |
<h3>Motivation: two-phase flow</h3> |
| 180 |
|
| 181 |
The minimal code examples (short "mini examples") presented in this tutorial |
| 182 |
are motivated by the application of two-phase-flow simulations formulated in |
| 183 |
a one-fluid setting using a Eulerian framework. In diffuse interface methods, |
| 184 |
the two phases may be implicitly described by a level-set function, here |
| 185 |
chosen as a signed distance function $\phi(\boldsymbol{ x})$ in |
| 186 |
$\Omega$ and illustrated for a popular benchmark case of a rising |
| 187 |
bubble in the following figure. |
| 188 |
|
| 189 |
<table align="center" class="doxtable"> |
| 190 |
<tr> |
| 191 |
<td> |
| 192 |
@image html https://www.dealii.org/images/steps/developer/step_87_rising_bubble.png |
| 193 |
</td> |
| 194 |
</tr> |
| 195 |
</table> |
| 196 |
|
| 197 |
The discrete interface $\Gamma$ is |
| 198 |
represented implicitly through a certain isosurface of the level-set function |
| 199 |
e.g. for the signed-distance function $\Gamma=\{\boldsymbol x \in \Omega~|~\phi |
| 200 |
(\boldsymbol{x})=0\}$. |
| 201 |
We would like to note that deal.II provides a set of analytical signed distance |
| 202 |
functions for simple geometries in the Functions::SignedDistance namespace. |
| 203 |
Those can be combined via Boolean operations to describe more complex |
| 204 |
geometries @cite burman2015cutfem. The temporal evolution of the level-set field |
| 205 |
is obtained by the transport equation |
| 206 |
@f[ |
| 207 |
\frac{\partial \, \phi}{\partial \, t} + \boldsymbol{u}\vert_\Gamma \cdot |
| 208 |
\nabla \phi = 0 |
| 209 |
@f] |
| 210 |
with the transport velocity at the interface $\boldsymbol{u}\vert_\Gamma$, |
| 211 |
which might be approximated by the local fluid velocity $\boldsymbol{u} |
| 212 |
\vert_\Gamma\approx\boldsymbol{u}(\boldsymbol{x})$. To reobtain the |
| 213 |
signed-distance property of the level-set field throughout the numerical |
| 214 |
solution procedure, PDE-based or, alternatively, also geometric reinitialization |
| 215 |
methods are used. For the latter, an algorithm for computing the distance from |
| 216 |
the support points to the discrete interface, e.g., via closest-point point |
| 217 |
projection @cite henri2022geometrical, is needed. This will be part of one of |
| 218 |
the mini examples, where we describe how to obtain the closest point |
| 219 |
$\boldsymbol{x}^*$ to the interface $\Gamma$ for an arbitrary point |
| 220 |
$\boldsymbol{x}$. For the simplest case, the former can be computed from the |
| 221 |
following equation |
| 222 |
@f[ |
| 223 |
\boldsymbol{x}^{*} = \boldsymbol{x} - \boldsymbol{n}(\boldsymbol{x}) |
| 224 |
\phi(\boldsymbol{x}), |
| 225 |
@f] |
| 226 |
assuming that the interface normal vector $\boldsymbol{n}(\boldsymbol{x})$ and |
| 227 |
$\phi(\boldsymbol{x})$ represent exact quantities. Typically, this projection |
| 228 |
is only performed for points located within a narrow band region around the |
| 229 |
interface, indicated in the right panel of the figure above. |
| 230 |
|
| 231 |
Alternatively to the implicit representation of the interface, in sharp |
| 232 |
interface methods, e.g., via front tracking, the interface $\Gamma$ is |
| 233 |
explicitly represented by a surface mesh. The latter is immersed into a |
| 234 |
background mesh, from which the local velocity at the support points of the |
| 235 |
surface mesh is extracted and leads to a movement of the support points of the |
| 236 |
immersed mesh as |
| 237 |
@f[ |
| 238 |
\boldsymbol{x}_q^{(i + 1)} = \boldsymbol{x}_q^{(i)} + \Delta t \cdot |
| 239 |
\boldsymbol{u}(\boldsymbol{x}_q^{(i)}) \quad \text{ for } \boldsymbol{x}_q |
| 240 |
\in \Gamma |
| 241 |
@f] |
| 242 |
which considers an explicit Euler time integration scheme from time step $i$ to |
| 243 |
$i+1$ with time step-size $\Delta t$. |
| 244 |
|
| 245 |
For a two-phase-flow model considering the incompressible Navier-Stokes |
| 246 |
equations, the two phases are usually coupled by a singular surface-tension |
| 247 |
force $\boldsymbol{F}_S$, which results, together with the difference in fluid |
| 248 |
properties, in discontinuities across the interface: |
| 249 |
@f[ |
| 250 |
\boldsymbol{F}_S(\boldsymbol{x})= \sigma \kappa(\boldsymbol{x}) |
| 251 |
\boldsymbol{n}(\boldsymbol{x}) \delta_{\Gamma}(\boldsymbol{x}). |
| 252 |
@f] |
| 253 |
Here $\sigma$ represents the surface-tension coefficient, |
| 254 |
$\boldsymbol{n}(\boldsymbol{x})$ the interface normal vector |
| 255 |
and $\kappa(\boldsymbol{x})$ the interface mean curvature field. |
| 256 |
The singularity at the interface is imposed by the Dirac delta function |
| 257 |
@f[ |
| 258 |
\delta_{\Gamma}(\boldsymbol{x}) = \begin{cases} |
| 259 |
1 & \text{on } \Gamma \\ |
| 260 |
0 & \text{else}\end{cases} |
| 261 |
@f] |
| 262 |
with support on the interface $\Gamma$. |
| 263 |
In a finite element context, the weak form of the surface-tension force |
| 264 |
is needed. The latter can be applied as a sharp surface-tension force model |
| 265 |
@f[ |
| 266 |
(\boldsymbol v, \boldsymbol F_S)_{\Omega} = \left( \boldsymbol{v}, \sigma |
| 267 |
\kappa \boldsymbol{n} \right)_\Gamma, |
| 268 |
@f] |
| 269 |
exploiting the property of the Dirac delta function for any smooth |
| 270 |
function $v$, i.e., |
| 271 |
$\int_\Omega\delta_{\Gamma}\,v\,\text{d}x=\int_\Gamma v\,\text{d}y$. For |
| 272 |
front-tracking methods, the curvature and the normal vector are directly |
| 273 |
computed from the surface mesh. |
| 274 |
|
| 275 |
Alternatively, in regularized surface-tension-force models |
| 276 |
@cite brackbill1992continuum @cite olsson2005conservative |
| 277 |
@cite kronbichler2018fast, the Dirac delta function is approximated by a smooth |
| 278 |
ansatz |
| 279 |
@f[ |
| 280 |
(\boldsymbol v, \boldsymbol F_S)_{\Omega} \approx \left(\boldsymbol v, \sigma |
| 281 |
\kappa \boldsymbol{n} \|\nabla H\| \right)_\Omega |
| 282 |
@f] |
| 283 |
considering the absolute value of the gradient of a regularized indicator |
| 284 |
function $\|\nabla H\|$, which is related to the level-set field. In such |
| 285 |
models, the interface normal vector |
| 286 |
@f[ |
| 287 |
\boldsymbol{n}(\boldsymbol{x}) = \nabla \phi(\boldsymbol{x}), |
| 288 |
@f] |
| 289 |
and the interface curvature field |
| 290 |
@f[ |
| 291 |
\kappa(\boldsymbol{x}) = \nabla \cdot \boldsymbol{n}(\boldsymbol{x})= |
| 292 |
\Delta \phi(\boldsymbol{x}) \,. |
| 293 |
@f] |
| 294 |
are derived from the level-set function. |
| 295 |
|
| 296 |
|
| 297 |
<h3>Overview</h3> |
| 298 |
|
| 299 |
In the following, we present three simple use cases of |
| 300 |
Utilities::MPI::RemotePointEvaluation. |
| 301 |
We start with discussing a serial code in mini example 0. |
| 302 |
In the subsequent mini examples, advanced problems are solved on distributed |
| 303 |
meshes: |
| 304 |
<ul> |
| 305 |
<li>mini example 1: we evaluate values and user quantities along a line;</li> |
| 306 |
<li>mini example 2: we perform a closest-point projection within a narrow band, |
| 307 |
based on a level-set function, use the information to update the distance and |
| 308 |
to perform an extrapolation from the interface;</li> |
| 309 |
<li>mini example 3: we compute the surface-tension term sharply |
| 310 |
with the interface given by an codim-1 mesh, which is advected by |
| 311 |
the velocity from the background mesh (front tracking; |
| 312 |
solution transfer between a background mesh and an immersed surface mesh).</li> |
| 313 |
</ul> |