Update use instructions authored by Adrien Crovato's avatar Adrien Crovato
## 4. Post-processing
Finally, after the case has been solved, the user can access the results generated by the solver and post-process them. The results can be saved to disk for further processing or directly used in python.
**4.1 Saving the results to disk**
The results are stored in the solver objects (dart::Solver and derived classes, and dart::Adjoint). Before they can be written to disk, a gmsh or vtk output utility must first be initialized. This is done by using the tbox::GmshExport class as,
```python
mshWriter = tbox.GmshExport(msh)
```
or, with the tboxVtk::VtkExport class as,
```python
import tboxVtk
mshWriter = tboxVtk.VtkExport(msh)
```
Note that the module `tboxVtk` must be imported before the VTK export utility can be used. This implies that the code has been compiled with VTK support.
The data can then be written to disk with,
```python
solver.save(mshWriter, n = 0)
adjoint.save(mshWriter, n = 0)
```
where `n` is the iteration number when solving cases in sequence. If only one case is solved, `n=0` can be ommited. The save operation will trigger two processes. First, the flow variables (total and perturbation potential), the residuals and the derived quantities (density, Mach number and pressure coefficient) will be written at all mesh nodes in gmsh (.pos) or VTK (.vtu) format. Second, these variables will be written in ascii (.dat) format on each zone specified as a body (with the dart::Body class).
**4.2 Computing derived quantities**
The data can also manipulated directly in python. For example, the pressure coefficient on a 2D airfoil surface (previously defined as `bnd = dart.Body(msh, ['body', 'field'])`) can be extracted and plotted as,
```python
import dart.utils as dartU # or from dartflo.dart import utils as dartU
import tbox.utils as tboxU # or from dartflo.tbox import utils as tboxU
Cp = dartU.extract(bnd.groups[0].tag.elems, solver.Cp)
tboxU.plot(Cp[:,0], Cp[:,3], 'x', 'Cp', 'title', True)
```
where `'title'` will be the plot title and the flag `True` is used to reverse the y-axis.
As another example, the user might also want to extract slices along the span of a 3D wing. This can be done as,
```python
dartU.writeSlices(msh.name, [y_i, ...], id)
```
where `y_i` is the y coordinate of the ith spanwise section and `id` is the number of the physical group (defined in gmsh) of the wing. The data will then be written in Selig order (i.e., from the trailing edge to the trailing edge, passing by the leading edge) in ascii format with the filename(s) 'slice_i.dat'. They can further be plotted with,
```python
data = tboxU.read('slice_2.dat')
tboxU.plot(data[:,3], data[:,4], 'x', 'Cp', 'title', True)
```
This will generate a Cp against x/c plot.