xref: /libCEED/examples/ceed/index.md (revision f80f4a748154eed4bc661c135f695b92b1bc45b9)
1# Standalone libCEED
2
3The following two examples have no dependencies, and are designed to be self-contained.
4For additional examples that use external discretization libraries (MFEM, PETSc, Nek5000
5etc.) see the subdirectories in {file}`examples/`.
6
7(ex1-volume)=
8
9## Ex1-Volume
10
11This example is located in the subdirectory {file}`examples/ceed`. It illustrates a
12simple usage of libCEED to compute the volume of a given body using a matrix-free
13application of the mass operator. Arbitrary mesh and solution orders in 1D, 2D, and 3D
14are supported from the same code.
15
16This example shows how to compute line/surface/volume integrals of a 1D, 2D, or 3D
17domain $\Omega$ respectively, by applying the mass operator to a vector of
18$1$s. It computes:
19
20$$
21I = \int_{\Omega} 1 \, dV .
22$$ (eq-ex1-volume)
23
24Using the same notation as in {ref}`theoretical-framework`, we write here the vector
25$u(x)\equiv 1$ in the Galerkin approximation,
26and find the volume of $\Omega$ as
27
28$$
29\sum_e \int_{\Omega_e} v(x) 1 \, dV
30$$ (volume-sum)
31
32with $v(x) \in \mathcal{V}_p = \{ v \in H^{1}(\Omega_e) \,|\, v \in P_p(\bm{I}), e=1,\ldots,N_e \}$,
33the test functions.
34
35(ex2-surface)=
36
37## Ex2-Surface
38
39This example is located in the subdirectory {file}`examples/ceed`. It computes the
40surface area of a given body using matrix-free application of a diffusion operator.
41Similar to {ref}`Ex1-Volume`, arbitrary mesh and solution orders in 1D, 2D, and 3D
42are supported from the same code. It computes:
43
44$$
45I = \int_{\partial \Omega} 1 \, dS ,
46$$ (eq-ex2-surface)
47
48by applying the divergence theorem.
49In 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$.
50
51Given Laplace's equation,
52
53$$
54\nabla \cdot \nabla u = 0, \textrm{ for  } \bm{x} \in \Omega ,
55$$
56
57let us multiply by a test function $v$ and integrate by parts to obtain
58
59$$
60\int_\Omega \nabla v \cdot \nabla u \, dV - \int_{\partial \Omega} v \nabla u \cdot \hat{\bm n}\, dS = 0 .
61$$
62
63Since 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
64
65$$
66\int_\Omega \nabla v \cdot \nabla u \, dV \approx \sum_e \int_{\partial \Omega_e} v(x) 1 \, dS .
67$$
68