xref: /libCEED/examples/ceed/index.md (revision eb07d68f27a4df7d950ee845c62e88e28e25414a)
1# Standalone libCEED
2
3The following three examples have no dependencies, and are designed to be self-contained.
4For additional examples that use external discretization libraries (MFEM, PETSc, Nek5000 etc.) see the subdirectories in {file}`examples/`.
5
6(ex1-volume)=
7
8## Ex1-Volume
9
10This example is located in the subdirectory {file}`examples/ceed`.
11It illustrates a simple usage of libCEED to compute the volume of a given body using a matrix-free application of the mass operator.
12Arbitrary mesh and solution orders in 1D, 2D, and 3D are supported from the same code.
13
14This example shows how to compute line/surface/volume integrals of a 1D, 2D, or 3D domain $\Omega$ respectively, by applying the mass operator to a vector of $1$s.
15It computes:
16
17$$
18I = \int_{\Omega} 1 \, dV .
19$$ (eq-ex1-volume)
20
21Using the same notation as in {ref}`theoretical-framework`, we write here the vector $u(x)\equiv 1$ in the Galerkin approximation, and find the volume of $\Omega$ as
22
23$$
24\sum_e \int_{\Omega_e} v(x) 1 \, dV
25$$ (volume-sum)
26
27with $v(x) \in \mathcal{V}_p = \{ v \in H^{1}(\Omega_e) \,|\, v \in P_p(\bm{I}), e=1,\ldots,N_e \}$, the test functions.
28
29(ex2-surface)=
30
31## Ex2-Surface
32
33This example is located in the subdirectory {file}`examples/ceed`.
34It computes the surface area of a given body using matrix-free application of a diffusion operator.
35Similar to {ref}`Ex1-Volume`, arbitrary mesh and solution orders in 1D, 2D, and 3D are supported from the same code.
36It computes:
37
38$$
39I = \int_{\partial \Omega} 1 \, dS ,
40$$ (eq-ex2-surface)
41
42by applying the divergence theorem.
43In particular, we select $u(\bm x) = x_0 + x_1 + x_2$, for which $\nabla u = [1, 1, 1]^T$, and thus $\nabla u \cdot \hat{\bm n} = 1$.
44
45Given Laplace's equation,
46
47$$
48\nabla \cdot \nabla u = 0, \textrm{ for  } \bm{x} \in \Omega ,
49$$
50
51let us multiply by a test function $v$ and integrate by parts to obtain
52
53$$
54\int_\Omega \nabla v \cdot \nabla u \, dV - \int_{\partial \Omega} v \nabla u \cdot \hat{\bm n}\, dS = 0 .
55$$
56
57Since we have chosen $u$ such that $\nabla u \cdot \hat{\bm n} = 1$, the boundary integrand is $v 1 \equiv v$. Hence, similar to {eq}`volume-sum`, we can evaluate the surface integral by applying the volumetric Laplacian as follows
58
59$$
60\int_\Omega \nabla v \cdot \nabla u \, dV \approx \sum_e \int_{\partial \Omega_e} v(x) 1 \, dS .
61$$
62
63(ex3-volume)=
64
65## Ex3-Volume
66
67This example is located in the subdirectory {file}`examples/ceed`.
68It illustrates a more complex usage of libCEED to compute the volume of a given body using a matrix-free application of the screened Poisson operator.
69Arbitrary mesh and solution orders in 1D, 2D, and 3D are supported from the same code.
70
71This example shows how to compute line/surface/volume integrals of a 1D, 2D, or 3D domain $\Omega$ respectively, by applying the screened Poisson operator to a vector of $1$s.
72It computes:
73
74$$
75I = \int_{\Omega} \left( 1 + \nabla^2 1 \right) \, dV .
76$$ (eq-ex3-volume)
77
78Using the same notation as in {ref}`theoretical-framework`, we write here the vector $u(x)\equiv 1$ in the Galerkin approximation, and find the volume of $\Omega$ as
79
80$$
81\sum_e \int_{\Omega_e}\left( v(x) 1 + \nabla v(x) \cdot 0 \right) \, dV
82$$ (volume-sum)
83
84with $v(x) \in \mathcal{V}_p = \{ v \in H^{1}(\Omega_e) \,|\, v \in P_p(\bm{I}), e=1,\ldots,N_e \}$, the test functions.
85
86The addition of the Poisson term is not needed to compute the volume of the region, as shown in example 1.
87Rather, this example illustrates the ability to add multiple evaluation modes for the same input or output vector in a libCEED operator.
88