data_processing.html 8.06 KB
Newer Older
Praetorius, Simon's avatar
Praetorius, Simon committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304
<!DOCTYPE html>
<html>
  <head>
    <title>AMDiS - Adaptive Multi-Dimensional Simulations</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
    <style type="text/css">
      @import url(https://fonts.googleapis.com/css?family=Yanone+Kaffeesatz);
      @import url(https://fonts.googleapis.com/css?family=Raleway);
      @import url(https://fonts.googleapis.com/css?family=Ubuntu);
      @import url(https://fonts.googleapis.com/css?family=Droid+Serif:400,700,400italic);
      @import url(https://fonts.googleapis.com/css?family=Ubuntu+Mono:400,700,400italic);
    </style>
    <!--<link rel="stylesheet" type="text/css" href="style_display.css" />-->
    <link rel="stylesheet" type="text/css" href="style_print.css" />
  </head>
  <body>
    <textarea id="source">

class: center, middle

# Session 2
## Handling data on unstructured grids

---

# Agenda

### Monday
- Scalar linear second order PDEs
- **Handling data on unstructured grids**
- Adaptivity and systems of equations
- Introduction to Student Projects

---

# Motivation
### Extract maxima of solution
<img src="images/ball500.png" width="45%" /><img src="images/pfc_sphere.png" width="45%" />

### Calculate integrals
<img src="images/energy.png" width="45%" />

---

# Working with the discrete solution
Finite-Element function `\(u_h\)` expressed as linear combination of basis-functions `\(\phi_i\)`:
\\[
u\_h(x) = \sum\_i u\_i \phi\_i(x),
\\]
with `\(u_i:=\)` Degrees of Freedom, stored in `DOFVector<value_type> U`:
- Evaluate at DOF index: `U[idx]`
- Iterate over all DOFs:
```
DOFIterator<value_type> it(&U [, USED_DOFS]);
for (it.reset(); !it.end(); ++it)
      *it = value; // idx = it.getDOFIndex()
```

- Evaluate DOFVector at coordinate `\(x\)`:
```
WorldVector<double> x;
x[0] = 0.2; x[1] = 0.3;
value_type value = U(x);
```

---

# Fill a DOFVector}
```
U << EXPRESSION;
```
where `EXPRESSION` can contain e.g.
- The coordinates: `X()`, `X(i)`
- Scalar values: `1.0`, `constant(1.0)`
- Matrix and vector expressions: `two_norm(...)`, `vec * vec`
- Other DOFVectors: `valueOf(V)`, `gradientOf(V)`

([Expressions manual](https://goo.gl/JK8EUI))

### Example:
Let `\(C\)` and `\(U\)` be of type `DOFVector<double>`:
\\[
U(x) := \frac{1}{2}\left(C(x)^2\,(1-C(x))^2 + \frac{1}{\epsilon}\|\nabla C(x)\|^2\right)
\\]

Assign expression on rhs to DOFVector `\(U\)`:
```
U << 0.5*( pow<2>(valueOf(C) * (1.0 - valueOf(C))
      + (1.0/eps) * unary_dot(gradientOf(C)) );
```

---

# Working with the discrete solution
- Reduce the `DOFVector`, i.e. calc integrals, norms:
```
integrate( EXPRESSION [, Mesh*] )
```
```
integrate( valueOf(U) );
integrate( two_norm(gradientOf(U)) );
integrate(pow<2>(valueOf(U)) + unary_dot(gradientOf(U)));
```
- Other reduction operations (over DOFs):
  - `max( EXPRESSION )` `\(\Rightarrow\max\{ expr(x_i)\,:\, x_i\in\Omega \}\)`
  - `min( EXPRESSION )` `\(\Rightarrow\min\{ expr(x_i)\,:\, x_i\in\Omega \}\)`
  - `abs_max( EXPRESSION )` `\(\Rightarrow\max\{ |expr(x_i)|\,:\, x_i\in\Omega \}\)`
  - `abs_min( EXPRESSION )` `\(\Rightarrow\min\{ |expr(x_i)|\,:\, x_i\in\Omega \}\)`

---

# Working with the mesh

.center[
<img src="images/ellipt_macro.png" width="30%" /><img src="images/torus_macro.jpg" width="30%" />
]

### Change position of mesh vertices:
<img src="images/Fsi.png" width="70%" />

---

# Working with the mesh
A Mesh holds all information about a triangulation. Get the mesh from `ProblemStat`:
```
Mesh&amp; mesh = *prob.getMesh();
```
- Number of vertices: `mesh.getNumberOfVertices()`
- Number of triangles (elements): `mesh.getNumberOfElements()`
- World coordinates are stored in `WorldVector<double>`.
- Get the coordinates of all DOFs:
```
DOFVector<WorldVector<double> > Coords(prob.getFeSpace(), "coords");
mesh.getDofCoords(Coords);
```
- Change coordinates of the mesh:
```
ParametricSimple parametric(Coords);
mesh.setParametric(&amp;parametric);
```

---

# Working with the mesh:
- (Advanced) Traverse the mesh element-wise:

```
Flag traverseFlag = Mesh::CALL_LEAF_EL | (FILL_FLAGS);
TraverseStack stack;
ElInfo *elInfo = stack.traverseFirst(&amp;mesh, -1, traverseFlag);
while (elInfo) {
  // do something with elInfo
  elInfo = stack.traverseNext(elInfo);
}
```
- (Advanced) Global Refinement of the mesh: Use `RefinementManager`

```
RefinementManager* refManager = prob.getRefinementManager();

Flag f = refManager->globalRefine(&amp;mesh, 5);
if (f == MESH_REFINED) {
  MSG("Mesh globally refined by 5 levels!\n");
}
```

---

# Example: Print solution with coordinates
Writing out the solution to the screen:
```
DOFVector<WorldVector<double>> C(U.getFeSpace(), "c");
mesh.getDofCoords(C);

DOFIterator<double> it(U);
DOFIterator<WorldVector<double>> c_it(C);
for (it.reset(),c_it.reset();  !it.end();  ++it,++c_it)
  std::cout << "U(" << *c_it << ") = " << *it << "\n";
```
This will print out:
<pre><code style="background: #ddd;">U(0 0) = 0
U(1 0) = 0
U(1 1) = 0
U(0 1) = 0
U(0.5 0.5) = 0.0833333
</code></pre>

---
class: center, middle

# Input/Output

---

# Input/Output
Write DOFVectors to file, for visualization, serialization, ...
- File writer with automatic file-type detection:
  ```
  io::writeFile(DOFVECTOR, FILENAME);
  ```
  Detection by filename extension: ".vtu", ".arh", ".dat", ".2d", ".gnu",...
  - Use **ParaView** for visualization
  - Tool **MeshConv** can convert beween mesh formats
- File reader with automatic file-type detection:
```
io::readFile(FILENAME, DOFVECTOR);
```
- Use ARH format to exchange data (can be converted to VTU by MeshConv.)


---
class: center, middle

# Exercise2
## Poisson equation

---

# Exercise2: Poisson equation
We want to solve the Poisson equation
\\[
-\Delta u = f(x)\quad\text{ in }\Omega,\quad u|\_{\partial\Omega} = g
\\]
in a rectangular domain `\(\Omega\)`, with
\\[
f(x) = 40(1 - 10\|x\|^2)e^{-10.0\|x\|^2}\\\\
g(x) = e^{-10.0\|x\|^2} \\\\
\\]
and with exact solution `\(u^\ast=g\)`.
1. Assemble and solve the equation.
2. Interpolate error `\(ERR := |u_h - g|\)` to DOFVector and write it to a file.
3. Calculate the error-norms `\(\|u_h - g\|_{L_2(\Omega)}\)` and `\(\|u_h - g\|_{H_1(\Omega)}\)`
4. Evaluate the error at the grid-point `\(x=(0.5, 0.5)\)`.
5. Refine the mesh globally and compare error-norms to old error-norms.

---

# Advanced Exercise2: Mesh adaption
The datastructure `AdaptInfo` provides parameters for tolerance and nr. of iterations for an adaption process:
```
AdaptInfo adaptInfo("adapt");
adaptInfo.getMaxSpaceIteration(); // => adapt->max iteration
adaptInfo.getSpaceTolerance(0);   // => adapt[0]->tolerance
```

1. Use AdaptInfo to write an adaption loop that refines the mesh globally to reduce the error until a tolerance is reached.
2. Write the error DOFVector in every adaption iteration to a file.
3. Calculate the exponent in the error estimate `\(\|u_h - I_h u^\ast\|_\#\leq C h^k\)`
4. (optional) Transform the mesh, by `\(x\mapsto 2x\)` and solve again.

---

# Some hints

### Used functions/classes:

```
DOFVector << EXPRESSION;
integrate( EXPRESSION );

// EXPRESSION: {valueOf(U), gradientOf(U), X(), X(i), +,-,*,/,
//              unary_dot(EXPR.), pow<2>(EXPR.), absolute(EXPR.)}

RefinementManager* refManager = prob.getRefinementManager();
refManager->globalRefine(prob.getMesh(), NR_OF_REFINEMENTS);

adaptInfo.getSpaceTolerance(0);
adaptInfo.getMaxSpaceIteration();

io::writeFile( DOFVECTOR, FILENAME );
```

### Parameters to modify:
```matlab
adapt[0]->tolerance: DOUBLE
adapt->max iteration: INTEGER
```

    </textarea>
    <script src="lib/remark.js" type="text/javascript"></script>
    <script type="text/javascript" src="../MathJax/MathJax.js?config=TeX-AMS_HTML"></script>

    <script type="text/javascript">
      var slideshow = remark.create({
        ratio: "4:3",
        highlightLanguage: "cpp"
      });

      // Setup MathJax
      MathJax.Hub.Config({
          tex2jax: {
          skipTags: ['script', 'noscript', 'style', 'textarea', 'pre']
          }
      });
      MathJax.Hub.Queue(function() {
          $(MathJax.Hub.getAllJax()).map(function(index, elem) {
              return(elem.SourceElement());
          }).parent().addClass('has-jax');
      });

      MathJax.Hub.Configured();
    </script>
  </body>
</html>