20#ifndef DUNE_GRIDGLUE_ADAPTER_GRIDGLUEVTKWRITER_HH
21#define DUNE_GRIDGLUE_ADAPTER_GRIDGLUEVTKWRITER_HH
29#include <dune/common/classname.hh>
30#include <dune/geometry/type.hh>
31#include <dune/geometry/referenceelements.hh>
46 template <
class Glue,
int s
ide>
47 static void writeExtractedPart(
const Glue& glue,
const std::string& filename)
49 static_assert((side==0 || side==1),
"'side' can only be 0 or 1");
53 fgrid.open(filename.c_str());
55 using GridView =
typename Glue::template GridView<side>;
56 using Extractor =
typename Glue::template GridPatch<side>;
58 typedef typename GridView::ctype ctype;
60 const int domdimw = GridView::dimensionworld;
61 const int patchDim = Extractor::dim - Extractor::codim;
64 std::string coordinatePadding;
65 for (
int i=domdimw; i<3; i++)
66 coordinatePadding +=
" 0";
68 fgrid <<
"# vtk DataFile Version 2.0\nFilename: " << filename <<
"\nASCII" << std::endl;
72 std::vector<typename Extractor::Coords> coords;
73 glue.template patch<side>().
getCoords(coords);
75 fgrid << ((patchDim==3) ?
"DATASET UNSTRUCTURED_GRID" :
"DATASET POLYDATA") << std::endl;
76 fgrid <<
"POINTS " << coords.size() <<
" " << Dune::className<ctype>() << std::endl;
78 for (
size_t i=0; i<coords.size(); i++)
79 fgrid << coords[i] << coordinatePadding << std::endl;
86 std::vector<typename Extractor::VertexVector> faces;
87 std::vector<Dune::GeometryType> geometryTypes;
88 glue.template patch<side>().getFaces(faces);
89 glue.template patch<side>().getGeometryTypes(geometryTypes);
91 unsigned int faceCornerCount = 0;
92 for (
size_t i=0; i<faces.size(); i++)
93 faceCornerCount += faces[i].size();
95 fgrid << ((patchDim==3) ?
"CELLS " :
"POLYGONS ")
96 << geometryTypes.size() <<
" " << geometryTypes.size() + faceCornerCount << std::endl;
98 for (
size_t i=0; i<faces.size(); i++) {
100 fgrid << faces[i].size();
104 if (geometryTypes[i].isSimplex()) {
105 for (
int j=0; j<patchDim+1; j++)
106 fgrid <<
" " << faces[i][j];
108 }
else if (geometryTypes[i].isQuadrilateral()) {
109 fgrid <<
" " << faces[i][0] <<
" " << faces[i][1]
110 <<
" " << faces[i][3] <<
" " << faces[i][2];
112 }
else if (geometryTypes[i].isPyramid()) {
113 fgrid <<
" " << faces[i][0] <<
" " << faces[i][1]
114 <<
" " << faces[i][3] <<
" " << faces[i][2] <<
" " << faces[i][4];
116 }
else if (geometryTypes[i].isPrism()) {
117 fgrid <<
" " << faces[i][0] <<
" " << faces[i][2] <<
" " << faces[i][1]
118 <<
" " << faces[i][3] <<
" " << faces[i][5] <<
" " << faces[i][4];
120 }
else if (geometryTypes[i].isHexahedron()) {
121 fgrid <<
" " << faces[i][0] <<
" " << faces[i][1]
122 <<
" " << faces[i][3] <<
" " << faces[i][2]
123 <<
" " << faces[i][4] <<
" " << faces[i][5]
124 <<
" " << faces[i][7] <<
" " << faces[i][6];
127 DUNE_THROW(Dune::NotImplemented,
"Geometry type " << geometryTypes[i] <<
" not supported yet");
138 fgrid <<
"CELL_TYPES " << geometryTypes.size() << std::endl;
140 for (
size_t i=0; i<geometryTypes.size(); i++) {
141 if (geometryTypes[i].isSimplex())
142 fgrid <<
"10" << std::endl;
143 else if (geometryTypes[i].isHexahedron())
144 fgrid <<
"12" << std::endl;
145 else if (geometryTypes[i].isPrism())
146 fgrid <<
"13" << std::endl;
147 else if (geometryTypes[i].isPyramid())
148 fgrid <<
"14" << std::endl;
150 DUNE_THROW(Dune::NotImplemented,
"Geometry type " << geometryTypes[i] <<
" not supported yet");
159 ctype accum = 0.0, delta = 1.0 / (ctype) (gridSubEntityData.size()-1);
161 fgrid <<
"CELL_DATA " << gridSubEntityData.size() << std::endl;
162 fgrid <<
"SCALARS property_coding " << Dune::className<ctype>() <<
" 1" << std::endl;
163 fgrid <<
"LOOKUP_TABLE default" << std::endl;
165 for (
typename GridSubEntityData::const_iterator sEIt = gridSubEntityData.begin();
166 sEIt != gridSubEntityData.end();
167 ++sEIt, accum += delta)
170 fgrid << accum << std::endl;
180 template <
class Glue,
int s
ide>
181 static void writeIntersections(
const Glue& glue,
const std::string& filename)
183 static_assert((side==0 || side==1),
"'side' can only be 0 or 1");
185 std::ofstream fmerged;
187 fmerged.open(filename.c_str());
189 using GridView =
typename Glue::template GridView<side>;
190 typedef typename GridView::ctype ctype;
192 const int domdimw = GridView::dimensionworld;
193 const int intersectionDim = Glue::Intersection::mydim;
196 std::string coordinatePadding;
197 for (
int i=domdimw; i<3; i++)
198 coordinatePadding +=
" 0";
200 int overlaps = glue.size();
204 using Extractor =
typename Glue::template GridPatch<0>;
205 std::vector<typename Extractor::Coords> coords;
206 glue.template patch<side>().
getCoords(coords);
209 fmerged <<
"# vtk DataFile Version 2.0\nFilename: " << filename <<
"\nASCII" << std::endl;
210 fmerged << ((intersectionDim==3) ?
"DATASET UNSTRUCTURED_GRID" :
"DATASET POLYDATA") << std::endl;
211 fmerged <<
"POINTS " << overlaps*(intersectionDim+1) <<
" " << Dune::className<ctype>() << std::endl;
215 const auto& geometry = intersection.geometry();
216 for (
int i = 0; i < geometry.corners(); ++i)
217 fmerged << geometry.corner(i) << coordinatePadding << std::endl;
223 std::vector<typename Extractor::VertexVector> faces;
224 std::vector<Dune::GeometryType> geometryTypes;
225 glue.template patch<side>().getFaces(faces);
226 glue.template patch<side>().getGeometryTypes(geometryTypes);
228 unsigned int faceCornerCount = 0;
229 for (
size_t i=0; i<faces.size(); i++)
230 faceCornerCount += faces[i].size();
232 int grid0SimplexCorners = intersectionDim+1;
233 fmerged << ((intersectionDim==3) ?
"CELLS " :
"POLYGONS ")
234 << overlaps <<
" " << (grid0SimplexCorners+1)*overlaps << std::endl;
236 for (
int i = 0; i < overlaps; ++i) {
237 fmerged << grid0SimplexCorners;
238 for (
int j=0; j<grid0SimplexCorners; j++)
239 fmerged <<
" " << grid0SimplexCorners*i+j;
240 fmerged << std::endl;
244 if (intersectionDim==3) {
246 fmerged <<
"CELL_TYPES " << overlaps << std::endl;
248 for (
int i = 0; i < overlaps; i++)
249 fmerged <<
"10" << std::endl;
256 ctype accum = 0.0, delta = 1.0 / (ctype) (gridSubEntityData.size()-1);
258 fmerged <<
"CELL_DATA " << overlaps << std::endl;
259 fmerged <<
"SCALARS property_coding " << Dune::className<ctype>() <<
" 1" << std::endl;
260 fmerged <<
"LOOKUP_TABLE default" << std::endl;
262 for (
typename GridSubEntityData::const_iterator sEIt = gridSubEntityData.begin();
263 sEIt != gridSubEntityData.end();
264 ++sEIt, accum += delta)
267 for (
int j = 0; j < sEIt->first.second; ++j)
268 fmerged << accum << std::endl;
275 template<
typename Glue>
276 static void write(
const Glue& glue,
const std::string& filenameTrunk)
280 writeExtractedPart<Glue,0>(glue,
281 filenameTrunk +
"-grid0.vtk");
283 writeIntersections<Glue,0>(glue,
284 filenameTrunk +
"-intersections-grid0.vtk");
287 writeExtractedPart<Glue,1>(glue,
288 filenameTrunk +
"-grid1.vtk");
290 writeIntersections<Glue,1>(glue,
291 filenameTrunk +
"-intersections-grid1.vtk");
Write remote intersections to a vtk file for debugging purposes.
Definition: gridgluevtkwriter.hh:41
Central component of the module implementing the coupling of two grids.
Definition: rangegenerators.hh:17