> 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:
U(0 0) = 0
U(1 0) = 0
U(1 1) = 0
U(0 1) = 0
U(0.5 0.5) = 0.0833333
---
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
```