VTKDGDoFWriter.cpp 4.3 KB
Newer Older
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
/*
 * Copyright (c) 2017-2021 Dominik Thoennes, Marcus Mohr, Nils Kohl.
 *
 * This file is part of HyTeG
 * (see https://i10git.cs.fau.de/hyteg/hyteg).
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 */
#include "hyteg/dataexport/VTKDGDoFWriter.hpp"

#include "core/DataTypes.h"

#include "hyteg/dataexport/VTKHelpers.hpp"
#include "hyteg/dataexport/VTKOutput.hpp"

27
28
29
// from walberla
#include "vtk/UtilityFunctions.h"

30
31
namespace hyteg {

32
33
using walberla::vtk::typeToString;

34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
void VTKDGDoFWriter::write( const VTKOutput& mgr, std::ostream& output, const uint_t& level )
{
   if ( mgr.dgFunctions_.size() == 0 )
   {
      return;
   }

   auto storage = mgr.storage_;

   const uint_t numberOfPoints = storage->getNumberOfLocalFaces() * levelinfo::num_microvertices_per_face( level );
   const uint_t numberOfCells  = storage->getNumberOfLocalFaces() * levelinfo::num_microfaces_per_face( level );

   vtk::writePieceHeader( output, numberOfPoints, numberOfCells );

   output << "<Points>\n";
49
   vtk::openDataElement( output, typeToString< real_t >(), "", 3, mgr.vtkDataFormat_ );
50

51
   VTKMeshWriter::writePointsForMicroVertices( mgr, output, storage, level );
52
53
54
55

   output << "\n</DataArray>\n";
   output << "</Points>\n";

56
   VTKMeshWriter::writeCells2D( mgr, output, storage, levelinfo::num_microvertices_per_edge( level ) );
57
58
59

   output << "<CellData>";

60
   for ( const auto& function : mgr.dgFunctions_.getFunctions< double >() )
61
   {
62
63
64
65
66
67
68
69
70
71
      writeScalarFunction( output, function, storage, level, mgr.write2D_, mgr.vtkDataFormat_ );
   }
   for ( const auto& function : mgr.dgFunctions_.getFunctions< int32_t >() )
   {
      writeScalarFunction( output, function, storage, level, mgr.write2D_, mgr.vtkDataFormat_ );
   }
   for ( const auto& function : mgr.dgFunctions_.getFunctions< int64_t >() )
   {
      writeScalarFunction( output, function, storage, level, mgr.write2D_, mgr.vtkDataFormat_ );
   }
72

73
   output << "\n</CellData>\n";
74

75
76
   vtk::writePieceFooter( output );
}
77

78
79
80
81
82
83
84
85
86
template < typename value_t >
void VTKDGDoFWriter::writeScalarFunction( std::ostream&                              output,
                                          const DGFunction< value_t >&               function,
                                          const std::shared_ptr< PrimitiveStorage >& storage,
                                          const uint_t&                              level,
                                          bool                                       write2D,
                                          vtk::DataFormat                            vtkDataFormat )
{
   vtk::openDataElement( output, typeToString< real_t >(), function.getFunctionName(), 1, vtkDataFormat );
87

88
89
90
91
92
93
94
95
96
97
98
99
100
   for ( const auto& it : storage->getFaces() )
   {
      const Face& face = *it.second;

      uint_t rowsize       = levelinfo::num_microvertices_per_edge( level );
      uint_t inner_rowsize = rowsize;
      output << std::scientific;

      uint_t idx;

      for ( size_t j = 0; j < rowsize - 1; ++j )
      {
         for ( size_t i = 0; i < inner_rowsize - 2; ++i )
101
         {
102
103
104
            idx = facedof::macroface::indexFaceFromGrayFace( level, i, j, stencilDirection::CELL_GRAY_C );
            output << face.getData( function.getFaceDataID() )->getPointer( level )[idx] << " ";
            idx = facedof::macroface::indexFaceFromBlueFace( level, i, j, stencilDirection::CELL_BLUE_C );
105
106
            output << face.getData( function.getFaceDataID() )->getPointer( level )[idx] << " ";
         }
107
108
109
         idx = facedof::macroface::indexFaceFromGrayFace( level, inner_rowsize - 2, j, stencilDirection::CELL_GRAY_C );
         output << face.getData( function.getFaceDataID() )->getPointer( level )[idx] << " ";
         --inner_rowsize;
110
111
      }
   }
112
   output << "\n</DataArray>\n";
113
114
115
}

} // namespace hyteg