adaptivity.html 10.1 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 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352
<!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 3
## Adaptivity and systems of equation

---

# Agenda

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

---

# Motivation
### Mesh adaptivity
- Two-phase flow problem
- Steep transition between two phases

<img src="images/capillary_ellipse.png" width="40%" /><img src="images/capillary_ellipse2.png" width="50%" />

---

# Adaptivity and error estimators: (`poisson3.cc`)
<table width="100%"><tr><td width="60%">
Adative solution strategy:<ul>
<li>Refine elements to reduce global error</li>
<li>Local refinement instead of global refinement</li>
<li>Repeated solution with adapted mesh:</li>
</ul></td><td><img src="images/bisection.png" width="100%" /></td>
</tr></table>

--

.center[
<img src="images/adaption-loop.png" width="90%" />
]

---

# Adaptivity and error estimators: (`poisson3.cc`)

```
prob.assemble(&amp;adaptInfo);
prob.solve(&amp;adaptInfo);
prob.estimate(&amp;adaptInfo); // local error indicator

Flag adapted;
for (int i = 0; i < MAX\_ITER; ++i)
{
  if (adaptInfo.getEstSum(0) < TOL)
    break;
  Flag markFlag = prob.markElements(&amp;adaptInfo); // mesh adaption}
  adapted = prob.refineMesh(&amp;adaptInfo);
  adapted|= prob.coarsenMesh(&amp;adaptInfo);

  prob.buildAfterCoarsen(&amp;adaptInfo, markFlag); // assemble}
  prob.solve(&amp;adaptInfo);
  prob.estimate(&amp;adaptInfo);
}
```

---
class: center, middle
# Better: `AdaptStationary`
--

.left[
### Encapsulation into class:
```
AdaptStationary adaptStat("adapt", prob, adaptInfo);
adaptStat.adapt(); // start adaptive solution process
```
]
---

# Adaptivity and error estimators: (`poisson3.cc`)

Solution strategy: `assemble->solve->estimate->mark->refine/coarsen`
- Estimator type can be set in init-file
--

- e.g. Residual-Estimator: Element error-indicator `\(\eta_T\)`:

\\[
\eta\_T := C\_0 h\_T^2 \||f + \nabla\cdot\mathbb{A}\nabla u\_h\||\_{L\_2(T)} + C\_1 \left(\sum\_{e\subset T} h\_e \left[\left[\mathbb{A}\nabla u\_h\cdot\underline{\nu\_e}\right]\right]^2\right)^{1/2}
\\]
--

- e.g. Recovery Estimator:
\\[
\eta\_T := \||\nabla u\_h^\ast - \nabla u\_h\||\_{L\_2(T)}
\\]
--

- Various *marking strategies*: global refinement, maximum strategy, equidistribution strategy, guaranteed error reduction strategy

---

# Stationary equation with adaptivity
Source-code: see `poisson4.cc`
```
ProblemStat prob("poisson5");
prob.initialize(INIT_ALL);

Operator opL( prob.getFeSpace(), prob.getFeSpace() );
  addSOT( opL, A ); // e.g. A = 1.0
Operator opF( prob.getFeSpace() );
  addZOT( opF, f ); // e.g. f = X()*X() + 1

prob.addMatrixOperator( opL, 0, 0 );
prob.addVectorOperator( opF, 0 );

prob.addDirichletBC( nr, 0, 0, new G );

AdaptInfo adaptInfo("adapt");
AdaptStationary("adapt", prob, adaptInfo).adapt();

prob.writeFiles(&amp;adaptInfo, true);
```

---

# Stationary equation with adaptivity
Init-file: see `poisson4.dat.2d`
```matlab
poisson->estimator[0]: residual % or recovery
poisson->estimator[0]->C0: 0.1 % weight of element residual
poisson->estimator[0]->C1: 0.1 % weight of jump residual

poisson->marker[0]->strategy: 2
% 1... global refinement
% 2... maximum strategy
% 3... equidistribution strategy
% 4... guaranteed error reduction strategy

adapt[0]->tolerance: 1e-4
adapt->max iteration: 5
```

---

# Stationary equation with adaptivity
Visualization of the locally refined grid: TODO: change images!!


<img src="images/local_refinement_0.png" width="30%" /><img src="images/local_refinement_3.png" width="30%" /><img src="images/local_refinement_4.png" width="30%" />

<img src="images/local_refinement_5.png" width="30%" /><img src="images/local_refinement_6.png" width="30%" /><img src="images/local_refinement_10.png" width="30%" />

---

class: center, middle
# System of equations

---

# System of equations
Motivation:
- Navier-Stokes equations
- Phase-Field (Crystal) equation
- Willmore flow

<img src="images/120particle_f3.png" width="30%" />
<img src="images/rho_big.png" width="30%" />
<img src="images/cell.png" width="30%" />

---

# Example: Biharmonic equation

We consider the stream-function formulation for the Stokes equation (2D):
\\[
-\nu\Delta^2\psi = f,\quad\text{ in }\Omega,\qquad\big(\mathbf{v} = -\nabla\times\mathbf{e}\_z \psi\big)
\\]
with `\(\psi|_{\partial\Omega}=\Delta\psi|_{\partial\Omega} = 0\)` and `\(f=(\nabla\times\mathbf{f})_z\)`.
--

Reformulated as system of second order equation, we obtain:
\\[
-\nu\Delta\phi = f,\quad\text{ in }\Omega \\\\
-\Delta\psi + \phi = 0
\\]
--

or in weak form:
\\[
\langle\nu\nabla\phi,\nabla\theta\rangle -\langle\nu\partial\_n\phi,\theta\rangle\_{\partial\Omega} = \langle f, \theta\rangle,\quad\forall\theta\in V \\\\
\langle\nabla\psi,\nabla\theta'\rangle -\langle\partial\_n\psi,\theta'\rangle\_{\partial\Omega} + \langle\phi,\theta'\rangle = 0,\qquad\forall\theta'\in V'
\\]

with solution components `\((\psi\in V, \phi\in V')\)`.

---

# Example: Biharmonic equation

We consider the stream-function formulation for the Stokes equation (2D):
\\[
-\nu\Delta^2\psi = f,\quad\text{ in }\Omega,\qquad\big(\mathbf{v} = -\nabla\times\mathbf{e}\_z \psi\big)
\\]
with **`\(\psi|_{\partial\Omega}=\Delta\psi|_{\partial\Omega} = 0\)`** and `\(f=(\nabla\times\mathbf{f})_z\)`.

Reformulated as system of second order equation, we obtain:
\\[
-\nu\Delta\phi = f,\quad\text{ in }\Omega \\\\
-\Delta\psi + \phi = 0,\quad\text{ with }\psi|\_{\partial\Omega}=0\text{ and }\phi|\_{\partial\Omega}=0
\\]

or in weak form:
\\[
\langle\nu\nabla\phi,\nabla\theta\rangle  = \langle f, \theta\rangle,\quad\forall\theta\in V\_0 \\\\
\langle\nabla\psi,\nabla\theta'\rangle + \langle\phi,\theta'\rangle = 0,\qquad\forall\theta'\in V'\_0
\\]

with solution components `\((\psi\in V_0, \phi\in V'_0)\)`.

---

# The biharmonic equation
Source-code: see `biharmonic1.cc`
\\[
\overbrace{\langle\nu\nabla\phi,\nabla\theta\rangle}^{\text{opL\_phi}} = \overbrace{\langle f, \theta\rangle}^{\text{opF}}, \\\\
\underbrace{\langle\nabla\psi,\nabla\theta'\rangle}\_{\text{opL\_psi}} + \underbrace{\langle\phi,\theta'\rangle}\_{\text{opM\_phi}} = 0
\\]
```
Operator opL_phi(prob.getFeSpace(0), prob.getFeSpace(1));
  addSOT(opL_phi, nu);
Operator opF(prob.getFeSpace(0));
  addZOT(opF, f);
Operator opL_psi(prob.getFeSpace(1), prob.getFeSpace(0));
  addSOT(opL_psi, 1.0);
Operator opM_phi(prob.getFeSpace(1), prob.getFeSpace(1));
  addZOT(opM_phi, 1.0);

// ===== add operators to problem =====
prob.addMatrixOperator(opL_phi, 0, 1);   // -nu*laplace(phi)
prob.addMatrixOperator(opL_psi, 1, 0);   // -laplace(psi)
prob.addMatrixOperator(opM_phi, 1, 1);   // phi
prob.addVectorOperator(opF,     0);      // f(x)
/// ...
```

---

# The biharmonic equation
Source-code: see `biharmonic1.cc`
```
/// ...
BoundaryType nr = 1;
prob.addDirichletBC(nr, 1, 0, new Constant(0.0));
prob.addDirichletBC(nr, 0, 1, new Constant(0.0));

AdaptInfo adaptInfo("adapt");
AdaptStationary("adapt", prob, adaptInfo).adapt();

prob.writeFiles(&amp;adaptInfo, true);
```

Init-file: see `biharmonic1.dat.2d`
```matlab
biharmonic->mesh:       mesh
biharmonic->components: 2
biharmonic->feSpace[0]: P1
biharmonic->feSpace[1]: P1
biharmonic->dim:        2
biharmonic->name:       [psi,phi]
```

---

# The biharmonic equation
Velocity field `\(\mathbf{v}\)` and stream function `\(\psi\)` for `\(\mathbf{f}=(y, -x)^\top\)`
.center[
<img src="images/biharmonic.png" width="80%" />
]

---
class: center, middle
# Exercise3
## Biharmonic equation
---

# Exercise3: System of equations
Implement the 4th order PDE
\\[
u - \Delta(u -\epsilon\Delta u) = f(x)\quad\text{ in }\Omega, \\\\
\partial\_n u|\_{\partial\Omega} = \partial\_n(u - \epsilon\Delta u)|\_{\partial\Omega} = 0
\\]

in a rectangular domain `\(\Omega\)`, with `\(\epsilon<1\)` and `\(f(x)\in[-1,1]\)` (random values).
1. Formulate Splitting of equation in system of equations.
2. Assemble and solve the system.
3. Vary the value `\(\epsilon\)` from 1 to `\(10^{-3}\)`. Introduce a parameter and read it from init-file. Change the mesh resolution accordingly.

---

# Advanced Exercise3: Error estimators

1. Modify exercise 1 to allow local mesh adaption by an error estimator.
2. Change the init-file correspondingly, i.e. add an entry for estimator and marker.
3. Choose a residual estimator/ recovery estimator and vary the estimator parameters
4. Vary the marking strategies and visualize the effect.

---

# Some hints

### Used functions/classes:
```
// functor that returns random values in mean +- amplitude/2
Random(mean, amplitude);

EXPRESSION: eval(&amp;functor)
```

### Parameters to modify:
```
poisson->estimator[0]: residual / recovery
poisson->marker[0]->strategy: 1/2/3/4
```

### References:
- ALBERT manual, Section 1.5.2 (marker strategies)





    </textarea>
    <script src="lib/remark.js" type="text/javascript"></script>
353
    <script type="text/javascript" src="MathJax/MathJax.js?config=TeX-AMS_HTML"></script>
Praetorius, Simon's avatar
Praetorius, Simon committed
354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376

    <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>