vtkreader.cc 3.98 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
// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
// vi: set et ts=4 sw=2 sts=2:

#ifdef HAVE_CONFIG_H
# include "config.h"
#endif

#include <iostream>
#include <vector>

#include <dune/common/parallel/mpihelper.hh> // An initializer of MPI
#include <dune/common/exceptions.hh> // We use exceptions
#include <dune/common/filledarray.hh>

#include <dune/grid/uggrid.hh>
#include <dune/grid/utility/structuredgridfactory.hh>

18
#include <dune/vtk/vtkreader.hh>
Praetorius, Simon's avatar
Praetorius, Simon committed
19
20
#include <dune/vtk/gridcreators/continuousgridcreator.hh>
#include <dune/vtk/gridcreators/discontinuousgridcreator.hh>
21
#include <dune/vtk/writers/vtkunstructuredgridwriter.hh>
Praetorius, Simon's avatar
Praetorius, Simon committed
22
23
24
25
26
27
28
29
30
31
32
33
34
35

using namespace Dune;

int main(int argc, char** argv)
{
  Dune::MPIHelper::instance(argc, argv);

  const int dim = 3;

  using GridType = UGGrid<dim>;
  using GridView = typename GridType::LeafGridView;
  {
    FieldVector<double,dim> lowerLeft; lowerLeft = 0.0;
    FieldVector<double,dim> upperRight; upperRight = 1.0;
36
    auto numElements = filledArray<dim,unsigned int>(4);
Praetorius, Simon's avatar
Praetorius, Simon committed
37
38
39
40
41
    auto gridPtr = StructuredGridFactory<GridType>::createSimplexGrid(lowerLeft, upperRight, numElements);
    auto& grid = *gridPtr;

    GridView gridView = grid.leafGridView();

42
    VtkUnstructuredGridWriter<GridView> vtkWriter1(gridView, Vtk::FormatTypes::ASCII);
43
44
    vtkWriter1.write("test_ascii_float32.vtu");

45
    VtkUnstructuredGridWriter<GridView> vtkWriter2(gridView, Vtk::FormatTypes::BINARY);
46
47
    vtkWriter2.write("test_binary_float32.vtu");

Praetorius, Simon's avatar
Praetorius, Simon committed
48
    VtkUnstructuredGridWriter<GridView> vtkWriter3(gridView, Vtk::FormatTypes::COMPRESSED, Vtk::DataTypes::FLOAT64);
49
    vtkWriter3.write("test_compressed_float64.vtu");
Praetorius, Simon's avatar
Praetorius, Simon committed
50
51
52
  }

  {
53
    std::cout << "read 'test_ascii_float32.vtu'..." << std::endl;
54
    auto gridPtr = VtkReader<GridType>::createGridFromFile("test_ascii_float32.vtu");
Praetorius, Simon's avatar
Praetorius, Simon committed
55
56
    auto& grid = *gridPtr;

57
    VtkUnstructuredGridWriter<GridView> vtkWriter(grid.leafGridView(), Vtk::FormatTypes::ASCII);
58
    vtkWriter.write("test_ascii_float32_2.vtu");
Praetorius, Simon's avatar
Praetorius, Simon committed
59
60
61
  }

  {
62
    std::cout << "read 'test_binary_float32.vtu'..." << std::endl;
63
    auto gridPtr = VtkReader<GridType>::createGridFromFile("test_binary_float32.vtu");
Praetorius, Simon's avatar
Praetorius, Simon committed
64
65
    auto& grid = *gridPtr;

66
    VtkUnstructuredGridWriter<GridView> vtkWriter(grid.leafGridView(), Vtk::FormatTypes::ASCII);
67
    vtkWriter.write("test_ascii_float32_3.vtu");
Praetorius, Simon's avatar
Praetorius, Simon committed
68
69
70
  }

  {
71
    std::cout << "read 'test_compressed_float64.vtu'..." << std::endl;
72
    auto gridPtr = VtkReader<GridType>::createGridFromFile("test_compressed_float64.vtu");
Praetorius, Simon's avatar
Praetorius, Simon committed
73
74
    auto& grid = *gridPtr;

75
    VtkUnstructuredGridWriter<GridView> vtkWriter(grid.leafGridView(), Vtk::FormatTypes::ASCII, Vtk::DataTypes::FLOAT64);
76
    vtkWriter.write("test_ascii_float64_3.vtu");
Praetorius, Simon's avatar
Praetorius, Simon committed
77
  }
78

79
  {
80
    std::cout << "read 'test_ascii_float32.vtu'..." << std::endl;
Stenger, Florian's avatar
Stenger, Florian committed
81
    auto gridPtr = VtkReader<GridType,Vtk::DiscontinuousGridCreator<GridType>>::createGridFromFile("test_ascii_float32.vtu");
82
    auto& grid = *gridPtr;
83

84
    VtkUnstructuredGridWriter<GridView> vtkWriter(grid.leafGridView(), Vtk::FormatTypes::ASCII);
85
    vtkWriter.write("test_ascii_float32_4.vtu");
86
87
  }

Stenger, Florian's avatar
Stenger, Florian committed
88
  if (Vtk::exists("paraview_3d.vtu")) {
89
90
    using GridType3d = UGGrid<3>;
    using GridView3d = typename GridType3d::LeafGridView;
91
92

    std::cout << "read 'paraview_3d.vtu'..." << std::endl;
93
    auto gridPtr = VtkReader<GridType3d>::createGridFromFile("paraview_3d.vtu");
94
95
    auto& grid = *gridPtr;

96
    VtkUnstructuredGridWriter<GridView3d> vtkWriter(grid.leafGridView(), Vtk::FormatTypes::ASCII, Vtk::DataTypes::FLOAT64);
97
    vtkWriter.write("paraview_3d_ascii.vtu");
98
  }
99

Stenger, Florian's avatar
Stenger, Florian committed
100
  if (Vtk::exists("paraview_2d.vtu")) {
Praetorius, Simon's avatar
Praetorius, Simon committed
101
102
103
    std::cout << "paraview_2d_ascii...\n";
    using GridType2d = UGGrid<2>;
    using GridView2d = typename GridType2d::LeafGridView;
104
    std::cout << "read 'paraview_2d.vtu'..." << std::endl;
105
    auto gridPtr = VtkReader<GridType2d>::createGridFromFile("paraview_2d.vtu");
Praetorius, Simon's avatar
Praetorius, Simon committed
106
    auto& grid = *gridPtr;
107

108
    VtkUnstructuredGridWriter<GridView2d> vtkWriter(grid.leafGridView(), Vtk::FormatTypes::ASCII, Vtk::DataTypes::FLOAT64);
109
    vtkWriter.write("paraview_2d_ascii.vtu");
Praetorius, Simon's avatar
Praetorius, Simon committed
110
  }
Praetorius, Simon's avatar
Praetorius, Simon committed
111
}