README.md 4.91 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
# Dune-Vtk
File reader and writer for the VTK Format

## Summary
Provides structured and unstructured file writers for the VTK XML File Formats 
that can be opened in the popular ParaView visualization application. Additionally
a file reader is provided to import VTK files into Dune grid and data objects.

## Requirements
For the management of the grids the `dune-grid` module is required. Additionally
for the data evaluation, the `dune-functions` module is used. 

### Optional modules
For tests and examples `dune-spgrid` and `dune-polygongrid` are suggested, that 
support structured grid data or special element types.

## Usage
The VTK writer works similar to the dune-grid `VTKWriter`. It needs to be bound 
to a GridView and then data can be added to the points or cells in the grid.
Points are not necessarily grid vertices, but any coordinates places inside the 
grid cells, so the data must be provided as GridViewFunction to allow the local
evaluation in arbitrary local coordinates.

```c++
Grid grid = ...;
VtkWriter<typename Grid::LeafGridView> vtkWriter(grid.leafGridView());

auto fct = makeAnalyticGridViewFunction([](auto const& x) {
  return std::sin(x[0]);
});

vtkWriter.addPointData(fct, "u_points");
vtkWriter.addCellData(fct, "u_cells");

vtkWriter.write("filename.vtu", Vtk::ASCII);
```

See also the `src/` directory for more examples.

## Comparison with Dune::VTKWriter
In Dune-Grid there is a VTK writer available, that is a bit different from the
proposed one. A comparions:

Praetorius, Simon's avatar
Praetorius, Simon committed
44
| **Property**       | **Dune-Grid** | **Dune-Vtk** |
Praetorius, Simon's avatar
Praetorius, Simon committed
45
46
47
48
49
50
51
52
53
54
55
56
57
58
| ------------------ | :-----------: | :----------: |
| VTK version        | 0.1           | 1.0          |
| UnstructuredGrid   | **x**         | **x**        |
| PolyData           | **x**         | -            |
| StructuredGrid     | -             | **x**        |
| RectilinearGrid    | -             | **x**        |
| ImageData          | -             | **x**        |
| ASCII              | **x**         | **x**        |
| BASE64             | **x**         | -            |
| APPENDED_RAW       | **x**         | **x**        |
| APPENDED_BASE64    | **x**         | -            |
| BASE64_COMPRESSED  | -             | -            |
| APPEDED_COMPRESSED | -             | **x**        |
| Parallel files     | **x**         | **x**        |
Praetorius, Simon's avatar
Praetorius, Simon committed
59
60
61
62
63
| Conforming Data    | **x**         | **x**        |
| NonConforming Data | **x**         | **x**        |
| Quadratic Data     | -             | **x**        |
| Subdivided Data    | **x**         | -            |

Praetorius, Simon's avatar
Praetorius, Simon committed
64
65
66
## Example
Create a fine structured YaspGrid and write it in parallel with 8 cores with
different write modi:
Praetorius, Simon's avatar
Praetorius, Simon committed
67

Praetorius, Simon's avatar
Praetorius, Simon committed
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
### 1. Create the grid

```c++
const int dim = 3;
FieldVector<double,dim> upperRight; upperRight = 1.0;
auto numElements = filledArray<dim,int>(16);
YaspGrid<dim> grid(upperRight,numElements,0,0); // no overlap
grid.globalRefine(3);
auto gridView = grid.leafGridView();
```

### 2. Create a function to write

```c++
auto fct = makeAnalyticGridViewFunction([](auto const& x) {
  return std::sin(10*x[0]) * std::cos(10*x[1]) + std::sin(10*x[2]);
}, gridView);
```

### 3. Write the grid and data to file

```c++
Vtk[FORMAT]Writer<decltype(gridView)> vtkWriter(gridView);
vtkWriter.addPointData(fct, "fct");
vtkWriter.write("filename.vtu", [FORMAT_TYPE], [DATA_TYPE]);
```

where `FORMAT` one of {UnstructuredGrid,StructuredGrid,RectilinearGrid,ImageData}
,`FORMAT_TYPE` one of {ASCII,BINARY,COMPRESSED}, and `DATA_TYPE` one of {FLOAT32,FLOAT64}.

We measure the file size (per processor) and the memory requirement of ParaView
to visualize the data.

| **Setup**                           | **Filesize** | **Memory** |
| ----------------------------------- | ------------ | ---------- |
| UnstructuredGrid, ASCII, FLOAT32    | 26M | 330M |
| *UnstructuredGrid, ASCII, FLOAT64*  | *29M* | *360M* |
| UnstructuredGrid, BINAR, FLOAT32    | 23M | 330M |
| UnstructuredGrid, BINAR, FLOAT64    | 27M | 360M |
| UnstructuredGrid, COMPR, FLOAT32    | 4.5M | 330M |
| UnstructuredGrid, COMPR, FLOAT64    | 5.7M | 360M |
| StructuredGrid, ASCII, FLOAT32      | 10M | 34M |
| StructuredGrid, ASCII, FLOAT64      | 13M | 67M |
| StructuredGrid, BINAR, FLOAT32      | 4.2M | 34M |
| StructuredGrid, BINAR, FLOAT64      | 8.4M | 67M | 
| StructuredGrid, COMPR, FLOAT32      | 1.4M | 34M |
| StructuredGrid, COMPR, FLOAT64      | 2.6M | 67M |
| RectilinearGrid, ASCII, FLOAT32     | 3.0M | 8.4M |
| RectilinearGrid, ASCII, FLOAT64     | 5.3M | 17M |
| RectilinearGrid, BINAR, FLOAT32     | 1.1M | 8.4M |
| RectilinearGrid, BINAR, FLOAT64     | 2.1M | 17M |
| RectilinearGrid, COMPR, FLOAT32     | 970K | 8.4M |
| RectilinearGrid, COMPR, FLOAT64     | 2.0M | 17M |
| ImageData, ASCII, FLOAT32           | 3.0M | 8.4M |
| ImageData, ASCII, FLOAT64           | 5.3M | 17M |
| ImageData, BINAR, FLOAT32           | 1.1M | 8.4M |
| ImageData, BINAR, FLOAT64           | 2.1M | 17M |
| **ImageData, COMPR, FLOAT32**       | **970K** | **8.4M** |
| ImageData, COMPR, FLOAT64           | 2.0M | 17M |