dune-grid 2.9.0
vtkwriter.hh
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (C) DUNE Project contributors, see file LICENSE.md in module root
2// SPDX-License-Identifier: LicenseRef-GPL-2.0-only-with-DUNE-exception
3// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
4// vi: set et ts=4 sw=2 sts=2:
5
6#ifndef DUNE_VTKWRITER_HH
7#define DUNE_VTKWRITER_HH
8
9#include <cstring>
10#include <iostream>
11#include <string>
12#include <fstream>
13#include <sstream>
14#include <iomanip>
15#include <memory>
16#include <type_traits>
17#include <vector>
18#include <list>
19#include <map>
20
21#include <dune/common/visibility.hh>
22#include <dune/common/typetraits.hh>
23#include <dune/common/exceptions.hh>
24#include <dune/common/indent.hh>
25#include <dune/common/iteratorfacades.hh>
26#include <dune/common/path.hh>
27#include <dune/geometry/referenceelements.hh>
36
50namespace Dune
51{
52
53 namespace Impl
54 {
55 // Check whether type F has a method 'bind' (see the dune-functions interface)
56 template< class F, class E, class = void >
57 struct IsBindable
58 : std::false_type
59 {};
60
61 template< class F, class E >
62 struct IsBindable< F, E, std::void_t< decltype( std::declval< F & >().bind( std::declval< const E & >() ) ),
63 decltype( std::declval< F & >().unbind() ) > >
64 : std::true_type
65 {};
66
67 // Check whether localFunction(F) can be called (see the dune-functions interface)
68 template< class F, class = void >
69 struct HasLocalFunction
70 : std::false_type
71 {};
72
73 template< class F >
74 struct HasLocalFunction< F, std::void_t< decltype( localFunction( std::declval< F& >() ) ) > >
75 : std::true_type
76 {};
77
78 } // namespace Impl
79
80 // Forward-declaration here, so the class can be friend of VTKWriter
81 template <class GridView>
83 template <class GridView>
85
94 template< class GridView >
95 class VTKWriter {
96
97 // VTKSequenceWriterBase needs getSerialPieceName
98 // and getParallelHeaderName
99 friend class VTKSequenceWriterBase<GridView>;
100 // VTKSequenceWriter needs the grid view, to get the MPI size and rank
101 friend class VTKSequenceWriter<GridView>;
102
103 // extract types
104 typedef typename GridView::Grid Grid;
105 typedef typename GridView::ctype DT;
106 constexpr static int n = GridView::dimension;
107 constexpr static int w = GridView::dimensionworld;
108
109 typedef typename GridView::template Codim< 0 >::Entity Cell;
110 typedef typename GridView::template Codim< n >::Entity Vertex;
111 typedef Cell Entity;
112
113 typedef typename GridView::IndexSet IndexSet;
114
115 static const PartitionIteratorType VTK_Partition = InteriorBorder_Partition;
116 //static const PartitionIteratorType VTK_Partition = All_Partition;
117
118 typedef typename GridView::template Codim< 0 >
119 ::template Partition< VTK_Partition >::Iterator
120 GridCellIterator;
121 typedef typename GridView::template Codim< n >
122 ::template Partition< VTK_Partition >::Iterator
123 GridVertexIterator;
124
125 typedef typename GridCellIterator::Reference EntityReference;
126
127 typedef typename GridView::template Codim< 0 >
128 ::Entity::Geometry::LocalCoordinate Coordinate;
129
131
132 // return true if entity should be skipped in Vertex and Corner iterator
133 static bool skipEntity( const PartitionType entityType )
134 {
135 switch( VTK_Partition )
136 {
137 // for All_Partition no entity has to be skipped
138 case All_Partition: return false;
139 case InteriorBorder_Partition: return ( entityType != InteriorEntity );
140 default: DUNE_THROW(NotImplemented,"Add check for this partition type");
141 }
142 return false ;
143 }
144
145 public:
146
148
149 protected:
150
152
156 {
157
158 public:
159
161
164 {
165
167 virtual void bind(const Entity& e) = 0;
168
170 virtual void unbind() = 0;
171
173
176 virtual void write(const Coordinate& pos, Writer& w, std::size_t count) const = 0;
177
179 {}
180
181 };
182
184 // DUNE_PRIVATE since _f has less visibility
185 template<typename F>
186 struct DUNE_PRIVATE FunctionWrapper
187 : public FunctionWrapperBase
188 {
189 using Function = typename std::decay<F>::type;
190
191 template<typename F_>
193 : _f(std::forward<F_>(f))
194 {}
195
196 virtual void bind(const Entity& e)
197 {
198 _f.bind(e);
199 }
200
201 virtual void unbind()
202 {
203 _f.unbind();
204 }
205
206 virtual void write(const Coordinate& pos, Writer& w, std::size_t count) const
207 {
208 auto r = _f(pos);
209 // we need to do different things here depending on whether r supports indexing into it or not.
210 do_write(w,r,count,IsIndexable<decltype(r)>());
211 }
212
213 private:
214
215 template<typename R>
216 void do_write(Writer& w, const R& r, std::size_t count, std::true_type) const
217 {
218 for (std::size_t i = 0; i < count; ++i)
219 w.write(r[i]);
220 }
221
222 template<typename R>
223 void do_write(Writer& w, const R& r, std::size_t count, std::false_type) const
224 {
225 assert(count == 1);
226 w.write(r);
227 }
228
229 Function _f;
230 };
231
233 template<typename F>
235 : public FunctionWrapperBase
236 {
237 using Function = typename std::decay<F>::type;
238
239 template<typename F_>
241 : _f(std::forward<F_>(f))
242 , element_(nullptr)
243 {}
244
245 virtual void bind(const Entity& e)
246 {
247 element_ = &e;
248 }
249
250 virtual void unbind()
251 {
252 element_ = nullptr;
253 }
254
255 virtual void write(const Coordinate& pos, Writer& w, std::size_t count) const
256 {
257 auto globalPos = element_->geometry().global(pos);
258 auto r = _f(globalPos);
259 if constexpr (IsIndexable<decltype(r)>()) {
260 for (std::size_t i = 0; i < count; ++i)
261 w.write(r[i]);
262 }
263 else {
264 assert(count == 1);
265 w.write(r);
266 }
267 }
268 private:
269 Function _f;
270 const Entity* element_;
271 };
272
275 : public FunctionWrapperBase
276 {
277 VTKFunctionWrapper(const std::shared_ptr< const VTKFunction >& f)
278 : _f(f)
279 , _entity(nullptr)
280 {}
281
282 virtual void bind(const Entity& e)
283 {
284 _entity = &e;
285 }
286
287 virtual void unbind()
288 {
289 _entity = nullptr;
290 }
291
292 virtual void write(const Coordinate& pos, Writer& w, std::size_t count) const
293 {
294 for (std::size_t i = 0; i < count; ++i)
295 w.write(_f->evaluate(i,*_entity,pos));
296 }
297
298 private:
299
300 std::shared_ptr< const VTKFunction > _f;
301 const Entity* _entity;
302
303 };
304
306 template<typename F, std::enable_if_t<Impl::IsBindable<F, Entity>::value, int> = 0>
308 : _f(std::make_unique<FunctionWrapper<F> >(std::forward<F>(f)))
310 {}
311
313 // That is, a function that you can create a LocalFunction for, and evaluate that in element coordinates
314 template<typename F, std::enable_if_t<not Impl::IsBindable<F, Entity>::value && Impl::HasLocalFunction<F>::value, int> = 0>
316 : _f(std::make_unique< FunctionWrapper<
317 typename std::decay<decltype(localFunction(std::forward<F>(f)))>::type
318 > >(localFunction(std::forward<F>(f))))
320 {}
321
323 // That is, a function that can be evaluated in global coordinates of the domain
324 template<typename F, std::enable_if_t<not Impl::IsBindable<F, Entity>::value && not Impl::HasLocalFunction<F>::value, int> = 0>
326 : _f(std::make_unique< GlobalFunctionWrapper<F> >(std::forward<F>(f)))
328 {}
329
331 explicit VTKLocalFunction (const std::shared_ptr< const VTKFunction >& vtkFunctionPtr)
332 : _f(std::make_unique<VTKFunctionWrapper>(vtkFunctionPtr))
333 , _fieldInfo(
334 vtkFunctionPtr->name(),
335 (vtkFunctionPtr->ncomps() == 2 || vtkFunctionPtr->ncomps() == 3) ? VTK::FieldInfo::Type::vector : VTK::FieldInfo::Type::scalar,
336 vtkFunctionPtr->ncomps(),
337 vtkFunctionPtr->precision()
338 )
339 {}
340
342 std::string name() const
343 {
344 return fieldInfo().name();
345 }
346
349 {
350 return _fieldInfo;
351 }
352
354 void bind(const Entity& e) const
355 {
356 _f->bind(e);
357 }
358
360 void unbind() const
361 {
362 _f->unbind();
363 }
364
366 void write(const Coordinate& pos, Writer& w) const
367 {
368 _f->write(pos,w,fieldInfo().size());
369 }
370
371 std::shared_ptr<FunctionWrapperBase> _f;
373
374 };
375
376 typedef typename std::list<VTKLocalFunction>::const_iterator FunctionIterator;
377
379
384 class CellIterator : public GridCellIterator
385 {
386 public:
388 CellIterator(const GridCellIterator & x) : GridCellIterator(x) {}
391 const FieldVector<DT,n> position() const
392 {
393 return ReferenceElements<DT,n>::general((*this)->type()).position(0,0);
394 }
395 };
396
398 {
399 return gridView_.template begin< 0, VTK_Partition >();
400 }
401
403 {
404 return gridView_.template end< 0, VTK_Partition >();
405 }
406
408
423 public ForwardIteratorFacade<VertexIterator, const Entity, EntityReference, int>
424 {
425 GridCellIterator git;
426 GridCellIterator gend;
427 VTK::DataMode datamode;
428 // Index of the currently visited corner within the current element.
429 // NOTE: this is in Dune-numbering, in contrast to CornerIterator.
430 int cornerIndexDune;
431 const VertexMapper & vertexmapper;
432 std::vector<bool> visited;
433 // in conforming mode, for each vertex id (as obtained by vertexmapper)
434 // hold its number in the iteration order (VertexIterator)
435 int offset;
436
437 // hide operator ->
438 void operator->();
439 protected:
441 {
442 if( git == gend )
443 return;
444 ++cornerIndexDune;
445 const int numCorners = git->subEntities(n);
446 if( cornerIndexDune == numCorners )
447 {
448 offset += numCorners;
449 cornerIndexDune = 0;
450
451 ++git;
452 while( (git != gend) && skipEntity( git->partitionType() ) )
453 ++git;
454 }
455 }
456 public:
457 VertexIterator(const GridCellIterator & x,
458 const GridCellIterator & end,
459 const VTK::DataMode & dm,
460 const VertexMapper & vm) :
461 git(x), gend(end), datamode(dm), cornerIndexDune(0),
462 vertexmapper(vm), visited(vm.size(), false),
463 offset(0)
464 {
465 if (datamode == VTK::conforming && git != gend)
466 visited[vertexmapper.subIndex(*git,cornerIndexDune,n)] = true;
467 }
468 void increment ()
469 {
470 switch (datamode)
471 {
472 case VTK::conforming :
473 while(visited[vertexmapper.subIndex(*git,cornerIndexDune,n)])
474 {
476 if (git == gend) return;
477 }
478 visited[vertexmapper.subIndex(*git,cornerIndexDune,n)] = true;
479 break;
480 case VTK::nonconforming :
482 break;
483 }
484 }
485 bool equals (const VertexIterator & cit) const
486 {
487 return git == cit.git
488 && cornerIndexDune == cit.cornerIndexDune
489 && datamode == cit.datamode;
490 }
491 EntityReference dereference() const
492 {
493 return *git;
494 }
496 int localindex () const
497 {
498 return cornerIndexDune;
499 }
501 FieldVector<DT,n> position () const
502 {
503 return referenceElement<DT,n>(git->type())
504 .position(cornerIndexDune,n);
505 }
506 };
507
509 {
510 return VertexIterator( gridView_.template begin< 0, VTK_Partition >(),
511 gridView_.template end< 0, VTK_Partition >(),
512 datamode, *vertexmapper );
513 }
514
516 {
517 return VertexIterator( gridView_.template end< 0, VTK_Partition >(),
518 gridView_.template end< 0, VTK_Partition >(),
519 datamode, *vertexmapper );
520 }
521
523
538 public ForwardIteratorFacade<CornerIterator, const Entity, EntityReference, int>
539 {
540 GridCellIterator git;
541 GridCellIterator gend;
542 VTK::DataMode datamode;
543 // Index of the currently visited corner within the current element.
544 // NOTE: this is in VTK-numbering, in contrast to VertexIterator.
545 int cornerIndexVTK;
546 const VertexMapper & vertexmapper;
547 // in conforming mode, for each vertex id (as obtained by vertexmapper)
548 // hold its number in the iteration order of VertexIterator (*not*
549 // CornerIterator)
550 const std::vector<int> & number;
551 // holds the number of corners of all the elements we have seen so far,
552 // excluding the current element
553 int offset;
554
555 // hide operator ->
556 void operator->();
557 public:
558 CornerIterator(const GridCellIterator & x,
559 const GridCellIterator & end,
560 const VTK::DataMode & dm,
561 const VertexMapper & vm,
562 const std::vector<int> & num) :
563 git(x), gend(end), datamode(dm), cornerIndexVTK(0),
564 vertexmapper(vm),
565 number(num), offset(0) {}
566 void increment ()
567 {
568 if( git == gend )
569 return;
570 ++cornerIndexVTK;
571 const int numCorners = git->subEntities(n);
572 if( cornerIndexVTK == numCorners )
573 {
574 offset += numCorners;
575 cornerIndexVTK = 0;
576
577 ++git;
578 while( (git != gend) && skipEntity( git->partitionType() ) )
579 ++git;
580 }
581 }
582 bool equals (const CornerIterator & cit) const
583 {
584 return git == cit.git
585 && cornerIndexVTK == cit.cornerIndexVTK
586 && datamode == cit.datamode;
587 }
588 EntityReference dereference() const
589 {
590 return *git;
591 }
593
597 int id () const
598 {
599 switch (datamode)
600 {
601 case VTK::conforming :
602 return
603 number[vertexmapper.subIndex(*git,VTK::renumber(*git,cornerIndexVTK),
604 n)];
605 case VTK::nonconforming :
606 return offset + VTK::renumber(*git,cornerIndexVTK);
607 default :
608 DUNE_THROW(IOError,"VTKWriter: unsupported DataMode" << datamode);
609 }
610 }
611 };
612
614 {
615 return CornerIterator( gridView_.template begin< 0, VTK_Partition >(),
616 gridView_.template end< 0, VTK_Partition >(),
617 datamode, *vertexmapper, number );
618 }
619
621 {
622 return CornerIterator( gridView_.template end< 0, VTK_Partition >(),
623 gridView_.template end< 0, VTK_Partition >(),
624 datamode, *vertexmapper, number );
625 }
626
627 public:
636 explicit VTKWriter ( const GridView &gridView,
639 : gridView_( gridView ),
640 datamode( dm ),
641 coordPrec (coordPrecision),
642 polyhedralCellsPresent_( checkForPolyhedralCells() )
643 { }
644
649 void addCellData (const std::shared_ptr< const VTKFunction > & p)
650 {
651 celldata.push_back(VTKLocalFunction(p));
652 }
653
673 template<typename F>
674 void addCellData(F&& f, VTK::FieldInfo vtkFieldInfo)
675 {
676 celldata.push_back(VTKLocalFunction(std::forward<F>(f),vtkFieldInfo));
677 }
678
694 template<class Container>
695 void addCellData (const Container& v, const std::string &name, int ncomps = 1,
697 {
698 typedef P0VTKFunction<GridView, Container> Function;
699 for (int c=0; c<ncomps; ++c) {
700 std::stringstream compName;
701 compName << name;
702 if (ncomps>1)
703 compName << "[" << c << "]";
704 VTKFunction* p = new Function(gridView_, v, compName.str(), ncomps, c, prec);
705 addCellData(std::shared_ptr< const VTKFunction >(p));
706 }
707 }
708
713 void addVertexData (const std::shared_ptr< const VTKFunction > & p)
714 {
715 vertexdata.push_back(VTKLocalFunction(p));
716 }
717
737 template<typename F>
738 void addVertexData(F&& f, VTK::FieldInfo vtkFieldInfo)
739 {
740 vertexdata.push_back(VTKLocalFunction(std::forward<F>(f),vtkFieldInfo));
741 }
742
743
759 template<class Container>
760 void addVertexData (const Container& v, const std::string &name, int ncomps=1,
762 {
763 typedef P1VTKFunction<GridView, Container> Function;
764 for (int c=0; c<ncomps; ++c) {
765 std::stringstream compName;
766 compName << name;
767 if (ncomps>1)
768 compName << "[" << c << "]";
769 VTKFunction* p = new Function(gridView_, v, compName.str(), ncomps, c, prec);
770 addVertexData(std::shared_ptr< const VTKFunction >(p));
771 }
772 }
773
775 void clear ()
776 {
777 celldata.clear();
778 vertexdata.clear();
779 }
780
783 { return coordPrec; }
784
786 virtual ~VTKWriter ()
787 {
788 this->clear();
789 }
790
803 std::string write ( const std::string &name,
805 {
806 return write( name, type, gridView_.comm().rank(), gridView_.comm().size() );
807 }
808
835 std::string pwrite ( const std::string & name, const std::string & path, const std::string & extendpath,
837 {
838 return pwrite( name, path, extendpath, type, gridView_.comm().rank(), gridView_.comm().size() );
839 }
840
841 protected:
843
855 std::string getParallelPieceName(const std::string& name,
856 const std::string& path,
857 int commRank, int commSize) const
858 {
859 std::ostringstream s;
860 // write path first
861 if(path.size() > 0)
862 {
863 s << path;
864 if(path[path.size()-1] != '/')
865 s << '/';
866 }
867
868 std::string fileprefix;
869 // check if a path was already added to name
870 // and if yes find filename without path
871 auto pos = name.rfind('/');
872 if( pos != std::string::npos )
873 {
874 // extract filename without path
875 fileprefix = name.substr( pos+1 );
876 // extract the path and added it before
877 // the magic below is added
878 std::string newpath = name.substr(0, pos);
879 s << newpath;
880 if(newpath[name.size()-1] != '/')
881 s << '/';
882 }
883 else
884 {
885 // if no path was found just copy the name
886 fileprefix = name;
887 }
888
889 s << 's' << std::setw(4) << std::setfill('0') << commSize << '-';
890 const bool writeHeader = commRank < 0;
891 if( ! writeHeader )
892 {
893 s << 'p' << std::setw(4) << std::setfill('0') << commRank << '-';
894 }
895
896 s << fileprefix << ".";
897 // write p for header files
898 if( writeHeader )
899 s << "p";
900 s << "vt";
901
902 if(GridView::dimension > 1)
903 s << "u";
904 else
905 s << "p";
906 return s.str();
907 }
908
910
920 std::string getParallelHeaderName(const std::string& name,
921 const std::string& path,
922 int commSize) const
923 {
924 return getParallelPieceName( name, path, -1, commSize );
925 }
926
928
940 std::string getSerialPieceName(const std::string& name,
941 const std::string& path) const
942 {
943 static const std::string extension =
944 GridView::dimension == 1 ? ".vtp" : ".vtu";
945
946 return concatPaths(path, name+extension);
947 }
948
965 std::string write ( const std::string &name,
966 VTK::OutputType type,
967 const int commRank,
968 const int commSize )
969 {
970 // in the parallel case, just use pwrite, it has all the necessary
971 // stuff, so we don't need to reimplement it here.
972 if(commSize > 1)
973 {
974 std::string filename = name;
975 std::string path = std::string("");
976
977 // check if a path was already added to name
978 // and if yes find filename without path
979 auto pos = name.rfind('/');
980 if( pos != std::string::npos )
981 {
982 // extract filename without path
983 filename = name.substr( pos+1 );
984
985 // extract the path and added it before
986 // the magic below is added
987 path = name.substr(0, pos);
988 }
989
990 return pwrite(filename, path, "", type, commRank, commSize);
991 }
992
993 // make data mode visible to private functions
994 outputtype = type;
995
996 // generate filename for process data
997 std::string pieceName = getSerialPieceName(name, "");
998
999 // write process data
1000 std::ofstream file;
1001 file.exceptions(std::ios_base::badbit | std::ios_base::failbit |
1002 std::ios_base::eofbit);
1003 // check if file can be opened
1004 try {
1005 file.open( pieceName.c_str(), std::ios::binary );
1006 }
1007 catch(...) {
1008 std::cerr << "Filename: " << pieceName << " could not be opened" << std::endl;
1009 throw;
1010 }
1011 if (! file.is_open())
1012 DUNE_THROW(IOError, "Could not write to piece file " << pieceName);
1013 writeDataFile( file );
1014 file.close();
1015
1016 return pieceName;
1017 }
1018
1020
1043 std::string pwrite(const std::string& name, const std::string& path,
1044 const std::string& extendpath,
1045 VTK::OutputType ot, const int commRank,
1046 const int commSize )
1047 {
1048 // make data mode visible to private functions
1049 outputtype=ot;
1050
1051 // do some magic because paraview can only cope with relative paths to piece files
1052 std::ofstream file;
1053 file.exceptions(std::ios_base::badbit | std::ios_base::failbit |
1054 std::ios_base::eofbit);
1055 std::string piecepath = concatPaths(path, extendpath);
1056 std::string relpiecepath = relativePath(path, piecepath);
1057
1058 // write this processes .vtu/.vtp piece file
1059 std::string fullname = getParallelPieceName(name, piecepath, commRank,
1060 commSize);
1061 // check if file can be opened
1062 try {
1063 file.open(fullname.c_str(),std::ios::binary);
1064 }
1065 catch(...) {
1066 std::cerr << "Filename: " << fullname << " could not be opened" << std::endl;
1067 throw;
1068 }
1069 if (! file.is_open())
1070 DUNE_THROW(IOError, "Could not write to piecefile file " << fullname);
1071 writeDataFile(file);
1072 file.close();
1073 gridView_.comm().barrier();
1074
1075 // if we are rank 0, write .pvtu/.pvtp parallel header
1076 fullname = getParallelHeaderName(name, path, commSize);
1077 if( commRank ==0 )
1078 {
1079 file.open(fullname.c_str());
1080 if (! file.is_open())
1081 DUNE_THROW(IOError, "Could not write to parallel file " << fullname);
1082 writeParallelHeader(file,name,relpiecepath, commSize );
1083 file.close();
1084 }
1085 gridView_.comm().barrier();
1086 return fullname;
1087 }
1088
1089 private:
1091
1108 void writeParallelHeader(std::ostream& s, const std::string& piecename,
1109 const std::string& piecepath, const int commSize)
1110 {
1111 VTK::FileType fileType =
1113
1114 VTK::PVTUWriter writer(s, fileType);
1115
1116 writer.beginMain();
1117
1118 // PPointData
1119 {
1120 std::string scalars, vectors;
1121 std::tie(scalars,vectors) = getDataNames(vertexdata);
1122 writer.beginPointData(scalars, vectors);
1123 }
1124 for (auto it = vertexdata.begin(),
1125 end = vertexdata.end();
1126 it != end;
1127 ++it)
1128 {
1129 unsigned writecomps = it->fieldInfo().size();
1130 if(writecomps == 2) writecomps = 3;
1131 writer.addArray(it->name(), writecomps, it->fieldInfo().precision());
1132 }
1133 writer.endPointData();
1134
1135 // PCellData
1136 {
1137 std::string scalars, vectors;
1138 std::tie(scalars,vectors) = getDataNames(celldata);
1139 writer.beginCellData(scalars, vectors);
1140 }
1141 for (auto it = celldata.begin(),
1142 end = celldata.end();
1143 it != end;
1144 ++it)
1145 {
1146 unsigned writecomps = it->fieldInfo().size();
1147 if(writecomps == 2) writecomps = 3;
1148 writer.addArray(it->name(), writecomps, it->fieldInfo().precision());
1149 }
1150 writer.endCellData();
1151
1152 // PPoints
1153 writer.beginPoints();
1154 writer.addArray("Coordinates", 3, coordPrec);
1155 writer.endPoints();
1156
1157 // Pieces
1158 for( int i = 0; i < commSize; ++i )
1159 {
1160 const std::string& fullname = getParallelPieceName(piecename,
1161 piecepath, i,
1162 commSize);
1163 writer.addPiece(fullname);
1164 }
1165
1166 writer.endMain();
1167 }
1168
1170 void writeDataFile (std::ostream& s)
1171 {
1172 VTK::FileType fileType =
1174
1175 VTK::VTUWriter writer(s, outputtype, fileType);
1176
1177 // Grid characteristics
1178 vertexmapper = new VertexMapper( gridView_, mcmgVertexLayout() );
1179 if (datamode == VTK::conforming)
1180 {
1181 number.resize(vertexmapper->size());
1182 for (std::vector<int>::size_type i=0; i<number.size(); i++) number[i] = -1;
1183 }
1185
1186 writer.beginMain(ncells, nvertices);
1187 writeAllData(writer);
1188 writer.endMain();
1189
1190 // write appended binary data section
1191 if(writer.beginAppended())
1192 writeAllData(writer);
1193 writer.endAppended();
1194
1195 delete vertexmapper; number.clear();
1196 }
1197
1198 void writeAllData(VTK::VTUWriter& writer) {
1199 // PointData
1200 writeVertexData(writer);
1201
1202 // CellData
1203 writeCellData(writer);
1204
1205 // Points
1206 writeGridPoints(writer);
1207
1208 // Cells
1209 writeGridCells(writer);
1210 }
1211
1212 protected:
1213 std::string getFormatString() const
1214 {
1216 return "ascii";
1218 return "binary";
1220 return "appended";
1222 return "appended";
1223 DUNE_THROW(IOError, "VTKWriter: unsupported OutputType" << outputtype);
1224 }
1225
1226 std::string getTypeString() const
1227 {
1228 if (n==1)
1229 return "PolyData";
1230 else
1231 return "UnstructuredGrid";
1232 }
1233
1235 virtual void countEntities(int &nvertices_, int &ncells_, int &ncorners_)
1236 {
1237 nvertices_ = 0;
1238 ncells_ = 0;
1239 ncorners_ = 0;
1240 for (CellIterator it=cellBegin(); it!=cellEnd(); ++it)
1241 {
1242 ncells_++;
1243 // because of the use of vertexmapper->map(), this iteration must be
1244 // in the order of Dune's numbering.
1245 const int subEntities = it->subEntities(n);
1246 for (int i=0; i<subEntities; ++i)
1247 {
1248 ncorners_++;
1249 if (datamode == VTK::conforming)
1250 {
1251 int alpha = vertexmapper->subIndex(*it,i,n);
1252 if (number[alpha]<0)
1253 number[alpha] = nvertices_++;
1254 }
1255 else
1256 {
1257 nvertices_++;
1258 }
1259 }
1260 }
1261 }
1262
1263 template<typename T>
1264 std::tuple<std::string,std::string> getDataNames(const T& data) const
1265 {
1266 std::string scalars = "";
1267 for (auto it = data.begin(),
1268 end = data.end();
1269 it != end;
1270 ++it)
1271 if (it->fieldInfo().type() == VTK::FieldInfo::Type::scalar)
1272 {
1273 scalars = it->name();
1274 break;
1275 }
1276
1277 std::string vectors = "";
1278 for (auto it = data.begin(),
1279 end = data.end();
1280 it != end;
1281 ++it)
1282 if (it->fieldInfo().type() == VTK::FieldInfo::Type::vector)
1283 {
1284 vectors = it->name();
1285 break;
1286 }
1287 return std::make_tuple(scalars,vectors);
1288 }
1289
1290 template<typename Data, typename Iterator>
1291 void writeData(VTK::VTUWriter& writer, const Data& data, const Iterator begin, const Iterator end, int nentries)
1292 {
1293 for (auto it = data.begin(),
1294 iend = data.end();
1295 it != iend;
1296 ++it)
1297 {
1298 const auto& f = *it;
1299 VTK::FieldInfo fieldInfo = f.fieldInfo();
1300 std::size_t writecomps = fieldInfo.size();
1301 switch (fieldInfo.type())
1302 {
1304 break;
1306 // vtk file format: a vector data always should have 3 comps (with
1307 // 3rd comp = 0 in 2D case)
1308 if (writecomps > 3)
1309 DUNE_THROW(IOError,"Cannot write VTK vectors with more than 3 components (components was " << writecomps << ")");
1310 writecomps = 3;
1311 break;
1313 DUNE_THROW(NotImplemented,"VTK output for tensors not implemented yet");
1314 }
1315 std::shared_ptr<VTK::DataArrayWriter> p
1316 (writer.makeArrayWriter(f.name(), writecomps, nentries, fieldInfo.precision()));
1317 if(!p->writeIsNoop())
1318 for (Iterator eit = begin; eit!=end; ++eit)
1319 {
1320 const Entity & e = *eit;
1321 f.bind(e);
1322 f.write(eit.position(),*p);
1323 f.unbind();
1324 // vtk file format: a vector data always should have 3 comps
1325 // (with 3rd comp = 0 in 2D case)
1326 for (std::size_t j=fieldInfo.size(); j < writecomps; ++j)
1327 p->write(0.0);
1328 }
1329 }
1330 }
1331
1333 virtual void writeCellData(VTK::VTUWriter& writer)
1334 {
1335 if(celldata.size() == 0)
1336 return;
1337
1338 std::string scalars, vectors;
1339 std::tie(scalars,vectors) = getDataNames(celldata);
1340
1341 writer.beginCellData(scalars, vectors);
1343 writer.endCellData();
1344 }
1345
1347 virtual void writeVertexData(VTK::VTUWriter& writer)
1348 {
1349 if(vertexdata.size() == 0)
1350 return;
1351
1352 std::string scalars, vectors;
1353 std::tie(scalars,vectors) = getDataNames(vertexdata);
1354
1355 writer.beginPointData(scalars, vectors);
1357 writer.endPointData();
1358 }
1359
1361 virtual void writeGridPoints(VTK::VTUWriter& writer)
1362 {
1363 writer.beginPoints();
1364
1365 std::shared_ptr<VTK::DataArrayWriter> p
1366 (writer.makeArrayWriter("Coordinates", 3, nvertices, coordPrec));
1367 if(!p->writeIsNoop()) {
1368 VertexIterator vEnd = vertexEnd();
1369 for (VertexIterator vit=vertexBegin(); vit!=vEnd; ++vit)
1370 {
1371 int dimw=w;
1372 for (int j=0; j<std::min(dimw,3); j++)
1373 p->write((*vit).geometry().corner(vit.localindex())[j]);
1374 for (int j=std::min(dimw,3); j<3; j++)
1375 p->write(0.0);
1376 }
1377 }
1378 // free the VTK::DataArrayWriter before touching the stream
1379 p.reset();
1380
1381 writer.endPoints();
1382 }
1383
1385 virtual void writeGridCells(VTK::VTUWriter& writer)
1386 {
1387 writer.beginCells();
1388
1389 // connectivity
1390 {
1391 std::shared_ptr<VTK::DataArrayWriter> p1
1392 (writer.makeArrayWriter("connectivity", 1, ncorners, VTK::Precision::int32));
1393 if(!p1->writeIsNoop())
1394 for (CornerIterator it=cornerBegin(); it!=cornerEnd(); ++it)
1395 p1->write(it.id());
1396 }
1397
1398 // offsets
1399 {
1400 std::shared_ptr<VTK::DataArrayWriter> p2
1401 (writer.makeArrayWriter("offsets", 1, ncells, VTK::Precision::int32));
1402 if(!p2->writeIsNoop()) {
1403 int offset = 0;
1404 for (CellIterator it=cellBegin(); it!=cellEnd(); ++it)
1405 {
1406 offset += it->subEntities(n);
1407 p2->write(offset);
1408 }
1409 }
1410 }
1411
1412 // types
1413 if (n>1)
1414 {
1415 {
1416 std::shared_ptr<VTK::DataArrayWriter> p3
1417 (writer.makeArrayWriter("types", 1, ncells, VTK::Precision::uint8));
1418
1419 if(!p3->writeIsNoop())
1420 {
1421 for (CellIterator it=cellBegin(); it!=cellEnd(); ++it)
1422 {
1423 int vtktype = VTK::geometryType(it->type());
1424 p3->write(vtktype);
1425 }
1426 }
1427 }
1428
1429
1430 // if polyhedron cells found also cell faces need to be written
1431 if( polyhedralCellsPresent_ )
1432 {
1433 writeCellFaces( writer );
1434 }
1435 }
1436
1437 writer.endCells();
1438 }
1439
1440 protected:
1442 {
1443 // check if polyhedron cells are present
1444 for( const auto& geomType : gridView_.indexSet().types( 0 ) )
1445 {
1446 if( VTK::geometryType( geomType ) == VTK::polyhedron )
1447 {
1448 return true;
1449 }
1450 }
1451 return false;
1452 }
1453
1455 virtual void writeCellFaces(VTK::VTUWriter& writer)
1456 {
1457 if( ! faceVertices_ )
1458 {
1459 faceVertices_.reset( new std::pair< std::vector<int>, std::vector<int> > () );
1460 // fill face vertex structure
1462 faceVertices_->first, faceVertices_->second );
1463 }
1464
1465 std::vector< int >& faces = faceVertices_->first;
1466 std::vector< int >& faceOffsets = faceVertices_->second;
1467 assert( int(faceOffsets.size()) == ncells );
1468
1469 {
1470 std::shared_ptr<VTK::DataArrayWriter> p4
1471 (writer.makeArrayWriter("faces", 1, faces.size(), VTK::Precision::int32));
1472 if(!p4->writeIsNoop())
1473 {
1474 for( const auto& face : faces )
1475 p4->write( face );
1476 }
1477 }
1478
1479 {
1480 std::shared_ptr<VTK::DataArrayWriter> p5
1481 (writer.makeArrayWriter("faceoffsets", 1, ncells, VTK::Precision::int32));
1482 if(!p5->writeIsNoop())
1483 {
1484 for( const auto& offset : faceOffsets )
1485 p5->write( offset );
1486
1487 // clear face vertex structure
1488 faceVertices_.reset();
1489 }
1490 }
1491 }
1492
1493 template <class CornerIterator, class IndexSet, class T>
1495 const CornerIterator end,
1496 const IndexSet& indexSet,
1497 std::vector<T>& faces,
1498 std::vector<T>& faceOffsets )
1499 {
1500 if( n == 3 && it != end )
1501 {
1502 // clear output arrays
1503 faces.clear();
1504 faces.reserve( 15 * ncells );
1505 faceOffsets.clear();
1506 faceOffsets.reserve( ncells );
1507
1508 int offset = 0;
1509
1510 Cell element = *it;
1511 int elIndex = indexSet.index( element );
1512 std::vector< T > vertices;
1513 vertices.reserve( 30 );
1514 for( ; it != end; ++it )
1515 {
1516 const Cell& cell = *it ;
1517 const int cellIndex = indexSet.index( cell ) ;
1518 if( elIndex != cellIndex )
1519 {
1520 fillFacesForElement( element, indexSet, vertices, offset, faces, faceOffsets );
1521
1522 vertices.clear();
1523 element = cell ;
1524 elIndex = cellIndex ;
1525 }
1526 vertices.push_back( it.id() );
1527 }
1528
1529 // fill faces for last element
1530 fillFacesForElement( element, indexSet, vertices, offset, faces, faceOffsets );
1531 }
1532 }
1533
1534 template <class Entity, class IndexSet, class T>
1535 static void fillFacesForElement( const Entity& element,
1536 const IndexSet& indexSet,
1537 const std::vector<T>& vertices,
1538 T& offset,
1539 std::vector<T>& faces,
1540 std::vector<T>& faceOffsets )
1541 {
1542 const int dim = n;
1543
1544 std::map< T, T > vxMap;
1545
1546 // get number of local faces
1547 const int nVertices = element.subEntities( dim );
1548 for( int vx = 0; vx < nVertices; ++ vx )
1549 {
1550 const int vxIdx = indexSet.subIndex( element, vx, dim );
1551 vxMap[ vxIdx ] = vertices[ vx ];
1552 }
1553
1554 // get number of local faces
1555 const int nFaces = element.subEntities( 1 );
1556 // store number of faces for current element
1557 faces.push_back( nFaces );
1558 ++offset;
1559 // extract each face as a set of vertex indices
1560 for( int fce = 0; fce < nFaces; ++ fce )
1561 {
1562 // obtain face
1563 const auto face = element.template subEntity< 1 > ( fce );
1564
1565 // get all vertex indices from current face
1566 const int nVxFace = face.subEntities( dim );
1567 faces.push_back( nVxFace );
1568 ++offset ;
1569 for( int i=0; i<nVxFace; ++i )
1570 {
1571 const T vxIndex = indexSet.subIndex( face, i, dim );
1572 assert( vxMap.find( vxIndex ) != vxMap.end() );
1573 faces.push_back( vxMap[ vxIndex ] );
1574 ++offset ;
1575 }
1576 }
1577
1578 // store face offset for each element
1579 faceOffsets.push_back( offset );
1580 }
1581
1582 protected:
1583 // the list of registered functions
1584 std::list<VTKLocalFunction> celldata;
1585 std::list<VTKLocalFunction> vertexdata;
1586
1587 // the grid
1589
1590 // temporary grid information
1594 private:
1595 VertexMapper* vertexmapper;
1596 // in conforming mode, for each vertex id (as obtained by vertexmapper)
1597 // hold its number in the iteration order (VertexIterator)
1598 std::vector<int> number;
1599 VTK::DataMode datamode;
1600 VTK::Precision coordPrec;
1601
1602 // true if polyhedral cells are present in the grid
1603 const bool polyhedralCellsPresent_;
1604
1605 // pointer holding face vertex connectivity if needed
1606 std::shared_ptr< std::pair< std::vector<int>, std::vector<int> > > faceVertices_;
1607
1608 protected:
1610 };
1611
1612}
1613
1614#endif
Mapper for multiple codim and multiple geometry types.
Functions for VTK output.
Data array writers for the VTKWriter.
Common stuff for the VTKWriter.
PartitionIteratorType
Parameter to be used for the parallel level- and leaf iterators.
Definition: gridenums.hh:136
PartitionType
Attributes used in the generic overlap model.
Definition: gridenums.hh:30
@ All_Partition
all entities
Definition: gridenums.hh:141
@ InteriorBorder_Partition
interior and border entities
Definition: gridenums.hh:138
@ InteriorEntity
all interior entities
Definition: gridenums.hh:31
const IndexSet & indexSet() const
obtain the index set
Definition: common/gridview.hh:191
Traits::Grid Grid
type of the grid
Definition: common/gridview.hh:83
Traits::IndexSet IndexSet
type of the index set
Definition: common/gridview.hh:86
const Communication & comm() const
obtain communication object
Definition: common/gridview.hh:280
static constexpr int dimension
The dimension of the grid.
Definition: common/gridview.hh:148
Grid::ctype ctype
type used for coordinates in grid
Definition: common/gridview.hh:145
static constexpr int dimensionworld
The dimension of the world the grid lives in.
Definition: common/gridview.hh:151
MCMGLayout mcmgVertexLayout()
layout for vertices (dim-0 entities)
Definition: mcmgmapper.hh:107
STL namespace.
Include standard header files.
Definition: agrid.hh:60
int min(const DofVectorPointer< int > &dofVector)
Definition: dofvector.hh:348
Precision
which precision to use when writing out data to vtk files
Definition: common.hh:271
OutputType
How the bulk data should be stored in the file.
Definition: common.hh:43
@ ascii
Output to the file is in ascii.
Definition: common.hh:45
@ appendedraw
Output is to the file is appended raw binary.
Definition: common.hh:49
@ appendedbase64
Output is to the file is appended base64 binary.
Definition: common.hh:51
@ base64
Output to the file is inline base64 binary.
Definition: common.hh:47
int renumber(const Dune::GeometryType &t, int i)
renumber VTK <-> Dune
Definition: common.hh:186
FileType
which type of VTK file to write
Definition: common.hh:252
@ polyData
for .vtp files (PolyData)
Definition: common.hh:254
@ unstructuredGrid
for .vtu files (UnstructuredGrid)
Definition: common.hh:256
DataMode
Whether to produce conforming or non-conforming output.
Definition: common.hh:67
@ conforming
Output conforming data.
Definition: common.hh:73
@ nonconforming
Output non-conforming data.
Definition: common.hh:81
GeometryType geometryType(const Dune::GeometryType &t)
mapping from GeometryType to VTKGeometryType
Definition: common.hh:151
@ polyhedron
Definition: common.hh:142
Grid view abstract base class.
Definition: common/gridview.hh:66
Implementation class for a multiple codim and multiple geometry type mapper.
Definition: mcmgmapper.hh:129
size_type size() const
Return total number of entities in the entity set managed by the mapper.
Definition: mcmgmapper.hh:204
Index subIndex(const typename GV::template Codim< 0 >::Entity &e, int i, unsigned int codim) const
Map subentity of codim 0 entity to starting index in array for dof block.
Definition: mcmgmapper.hh:185
Descriptor struct for VTK fields.
Definition: common.hh:328
std::size_t size() const
The number of components in the data field.
Definition: common.hh:364
Precision precision() const
The precision used for the output of the data field.
Definition: common.hh:370
@ tensor
tensor field (always 3x3)
@ vector
vector-valued field (always 3D, will be padded if necessary)
Type type() const
The type of the data field.
Definition: common.hh:358
std::string name() const
The name of the data field.
Definition: common.hh:352
base class for data array writers
Definition: dataarraywriter.hh:56
void write(T data)
write one element of data
Definition: dataarraywriter.hh:69
A base class for grid functions with any return type and dimension.
Definition: function.hh:42
Take a vector and interpret it as cell data for the VTKWriter.
Definition: function.hh:97
Take a vector and interpret it as point data for the VTKWriter.
Definition: function.hh:205
Dump a .vtu/.vtp files contents to a stream.
Definition: pvtuwriter.hh:62
Writer for the ouput of grid functions in the vtk format.
Definition: vtksequencewriter.hh:29
Base class to write pvd-files which contains a list of all collected vtk-files.
Definition: vtksequencewriterbase.hh:34
Writer for the ouput of grid functions in the vtk format.
Definition: vtkwriter.hh:95
void addCellData(const Container &v, const std::string &name, int ncomps=1, VTK::Precision prec=VTK::Precision::float32)
Add a grid function (represented by container) that lives on the cells of the grid to the visualizati...
Definition: vtkwriter.hh:695
CornerIterator cornerEnd() const
Definition: vtkwriter.hh:620
void clear()
clear list of registered functions
Definition: vtkwriter.hh:775
std::string write(const std::string &name, VTK::OutputType type=VTK::ascii)
write output (interface might change later)
Definition: vtkwriter.hh:803
VertexIterator vertexBegin() const
Definition: vtkwriter.hh:508
std::string getTypeString() const
Definition: vtkwriter.hh:1226
std::string getParallelHeaderName(const std::string &name, const std::string &path, int commSize) const
return name of a parallel header file
Definition: vtkwriter.hh:920
void addVertexData(const std::shared_ptr< const VTKFunction > &p)
Add a grid function that lives on the vertices of the grid to the visualization.
Definition: vtkwriter.hh:713
Dune::VTKFunction< GridView > VTKFunction
Definition: vtkwriter.hh:147
CellIterator cellEnd() const
Definition: vtkwriter.hh:402
std::list< VTKLocalFunction > vertexdata
Definition: vtkwriter.hh:1585
CornerIterator cornerBegin() const
Definition: vtkwriter.hh:613
std::string getSerialPieceName(const std::string &name, const std::string &path) const
return name of a serial piece file
Definition: vtkwriter.hh:940
void addCellData(const std::shared_ptr< const VTKFunction > &p)
Add a grid function that lives on the cells of the grid to the visualization.
Definition: vtkwriter.hh:649
std::string getFormatString() const
Definition: vtkwriter.hh:1213
bool checkForPolyhedralCells() const
Definition: vtkwriter.hh:1441
void addVertexData(F &&f, VTK::FieldInfo vtkFieldInfo)
Add a function by sampling it on the grid vertices.
Definition: vtkwriter.hh:738
virtual void writeCellData(VTK::VTUWriter &writer)
write cell data
Definition: vtkwriter.hh:1333
virtual void countEntities(int &nvertices_, int &ncells_, int &ncorners_)
count the vertices, cells and corners
Definition: vtkwriter.hh:1235
std::string getParallelPieceName(const std::string &name, const std::string &path, int commRank, int commSize) const
return name of a parallel piece file (or header name)
Definition: vtkwriter.hh:855
CellIterator cellBegin() const
Definition: vtkwriter.hh:397
VTK::OutputType outputtype
Definition: vtkwriter.hh:1609
virtual void writeGridCells(VTK::VTUWriter &writer)
write the connectivity array
Definition: vtkwriter.hh:1385
GridView gridView_
Definition: vtkwriter.hh:1588
virtual void writeCellFaces(VTK::VTUWriter &writer)
write the connectivity array
Definition: vtkwriter.hh:1455
void fillFaceVertices(CornerIterator it, const CornerIterator end, const IndexSet &indexSet, std::vector< T > &faces, std::vector< T > &faceOffsets)
Definition: vtkwriter.hh:1494
std::list< VTKLocalFunction > celldata
Definition: vtkwriter.hh:1584
std::string write(const std::string &name, VTK::OutputType type, const int commRank, const int commSize)
write output (interface might change later)
Definition: vtkwriter.hh:965
VTK::Precision coordPrecision() const
get the precision with which coordinates are written out
Definition: vtkwriter.hh:782
std::list< VTKLocalFunction >::const_iterator FunctionIterator
Definition: vtkwriter.hh:376
std::tuple< std::string, std::string > getDataNames(const T &data) const
Definition: vtkwriter.hh:1264
virtual void writeGridPoints(VTK::VTUWriter &writer)
write the positions of vertices
Definition: vtkwriter.hh:1361
virtual void writeVertexData(VTK::VTUWriter &writer)
write vertex data
Definition: vtkwriter.hh:1347
int nvertices
Definition: vtkwriter.hh:1592
void addCellData(F &&f, VTK::FieldInfo vtkFieldInfo)
Add a function by sampling it on the element centers.
Definition: vtkwriter.hh:674
void addVertexData(const Container &v, const std::string &name, int ncomps=1, VTK::Precision prec=VTK::Precision::float32)
Add a grid function (represented by container) that lives on the vertices of the grid to the visualiz...
Definition: vtkwriter.hh:760
virtual ~VTKWriter()
destructor
Definition: vtkwriter.hh:786
static void fillFacesForElement(const Entity &element, const IndexSet &indexSet, const std::vector< T > &vertices, T &offset, std::vector< T > &faces, std::vector< T > &faceOffsets)
Definition: vtkwriter.hh:1535
void writeData(VTK::VTUWriter &writer, const Data &data, const Iterator begin, const Iterator end, int nentries)
Definition: vtkwriter.hh:1291
int ncells
Definition: vtkwriter.hh:1591
VertexIterator vertexEnd() const
Definition: vtkwriter.hh:515
VTKWriter(const GridView &gridView, VTK::DataMode dm=VTK::conforming, VTK::Precision coordPrecision=VTK::Precision::float32)
Construct a VTKWriter working on a specific GridView.
Definition: vtkwriter.hh:636
std::string pwrite(const std::string &name, const std::string &path, const std::string &extendpath, VTK::OutputType ot, const int commRank, const int commSize)
write output; interface might change later
Definition: vtkwriter.hh:1043
std::string pwrite(const std::string &name, const std::string &path, const std::string &extendpath, VTK::OutputType type=VTK::ascii)
write output (interface might change later)
Definition: vtkwriter.hh:835
int ncorners
Definition: vtkwriter.hh:1593
Type erasure wrapper for VTK data sets.
Definition: vtkwriter.hh:156
void unbind() const
Unbind the data set from the currently bound entity.
Definition: vtkwriter.hh:360
VTKLocalFunction(F &&f, VTK::FieldInfo fieldInfo)
Construct a VTKLocalFunction for a dune-functions style LocalFunction.
Definition: vtkwriter.hh:307
std::string name() const
Returns the name of the data set.
Definition: vtkwriter.hh:342
VTK::FieldInfo _fieldInfo
Definition: vtkwriter.hh:372
VTK::DataArrayWriter Writer
Definition: vtkwriter.hh:160
const VTK::FieldInfo & fieldInfo() const
Returns the VTK::FieldInfo for the data set.
Definition: vtkwriter.hh:348
void bind(const Entity &e) const
Bind the data set to grid entity e.
Definition: vtkwriter.hh:354
VTKLocalFunction(const std::shared_ptr< const VTKFunction > &vtkFunctionPtr)
Construct a VTKLocalFunction for a legacy VTKFunction.
Definition: vtkwriter.hh:331
std::shared_ptr< FunctionWrapperBase > _f
Definition: vtkwriter.hh:371
void write(const Coordinate &pos, Writer &w) const
Write the value of the data set at local coordinate pos to the writer w.
Definition: vtkwriter.hh:366
Base class for polymorphic container of underlying data set.
Definition: vtkwriter.hh:164
virtual void write(const Coordinate &pos, Writer &w, std::size_t count) const =0
Evaluate data set at local position pos inside the current entity and write result to w.
virtual ~FunctionWrapperBase()
Definition: vtkwriter.hh:178
virtual void unbind()=0
Unbind data set from current grid entity - mostly here for performance and symmetry reasons.
virtual void bind(const Entity &e)=0
Bind data set to grid entity - must be called before evaluating (i.e. calling write())
Type erasure implementation for functions conforming to the dune-functions LocalFunction interface.
Definition: vtkwriter.hh:188
typename std::decay< F >::type Function
Definition: vtkwriter.hh:189
FunctionWrapper(F_ &&f)
Definition: vtkwriter.hh:192
virtual void write(const Coordinate &pos, Writer &w, std::size_t count) const
Evaluate data set at local position pos inside the current entity and write result to w.
Definition: vtkwriter.hh:206
virtual void unbind()
Unbind data set from current grid entity - mostly here for performance and symmetry reasons.
Definition: vtkwriter.hh:201
virtual void bind(const Entity &e)
Bind data set to grid entity - must be called before evaluating (i.e. calling write())
Definition: vtkwriter.hh:196
Type erasure implementation for C++ functions, i.e., functions that can be evaluated in global coordi...
Definition: vtkwriter.hh:236
GlobalFunctionWrapper(F_ &&f)
Definition: vtkwriter.hh:240
virtual void unbind()
Unbind data set from current grid entity - mostly here for performance and symmetry reasons.
Definition: vtkwriter.hh:250
typename std::decay< F >::type Function
Definition: vtkwriter.hh:237
virtual void write(const Coordinate &pos, Writer &w, std::size_t count) const
Evaluate data set at local position pos inside the current entity and write result to w.
Definition: vtkwriter.hh:255
virtual void bind(const Entity &e)
Bind data set to grid entity - must be called before evaluating (i.e. calling write())
Definition: vtkwriter.hh:245
Type erasure implementation for legacy VTKFunctions.
Definition: vtkwriter.hh:276
virtual void unbind()
Unbind data set from current grid entity - mostly here for performance and symmetry reasons.
Definition: vtkwriter.hh:287
VTKFunctionWrapper(const std::shared_ptr< const VTKFunction > &f)
Definition: vtkwriter.hh:277
virtual void write(const Coordinate &pos, Writer &w, std::size_t count) const
Evaluate data set at local position pos inside the current entity and write result to w.
Definition: vtkwriter.hh:292
virtual void bind(const Entity &e)
Bind data set to grid entity - must be called before evaluating (i.e. calling write())
Definition: vtkwriter.hh:282
Iterator over the grids elements.
Definition: vtkwriter.hh:385
CellIterator(const GridCellIterator &x)
construct a CellIterator from the gridview's Iterator.
Definition: vtkwriter.hh:388
const FieldVector< DT, n > position() const
Definition: vtkwriter.hh:391
Iterate over the grid's vertices.
Definition: vtkwriter.hh:424
VertexIterator(const GridCellIterator &x, const GridCellIterator &end, const VTK::DataMode &dm, const VertexMapper &vm)
Definition: vtkwriter.hh:457
void basicIncrement()
Definition: vtkwriter.hh:440
void increment()
Definition: vtkwriter.hh:468
EntityReference dereference() const
Definition: vtkwriter.hh:491
bool equals(const VertexIterator &cit) const
Definition: vtkwriter.hh:485
FieldVector< DT, n > position() const
position of vertex inside the entity
Definition: vtkwriter.hh:501
int localindex() const
index of vertex within the entity, in Dune-numbering
Definition: vtkwriter.hh:496
Iterate over the elements' corners.
Definition: vtkwriter.hh:539
void increment()
Definition: vtkwriter.hh:566
CornerIterator(const GridCellIterator &x, const GridCellIterator &end, const VTK::DataMode &dm, const VertexMapper &vm, const std::vector< int > &num)
Definition: vtkwriter.hh:558
int id() const
Process-local consecutive zero-starting vertex id.
Definition: vtkwriter.hh:597
EntityReference dereference() const
Definition: vtkwriter.hh:588
bool equals(const CornerIterator &cit) const
Definition: vtkwriter.hh:582
Dump a .vtu/.vtp files contents to a stream.
Definition: vtuwriter.hh:98
DataArrayWriter * makeArrayWriter(const std::string &name, unsigned ncomps, unsigned nitems, Precision prec)
acquire a DataArrayWriter
Definition: vtuwriter.hh:380
void endCellData()
finish CellData section
Definition: vtuwriter.hh:220
void beginCells()
start section for the grid cells/PolyData lines
Definition: vtuwriter.hh:274
void endPointData()
finish PointData section
Definition: vtuwriter.hh:182
void beginCellData(const std::string &scalars="", const std::string &vectors="")
start CellData section
Definition: vtuwriter.hh:205
void beginPointData(const std::string &scalars="", const std::string &vectors="")
start PointData section
Definition: vtuwriter.hh:167
void endPoints()
finish section for the point coordinates
Definition: vtuwriter.hh:249
void endCells()
start section for the grid cells/PolyData lines
Definition: vtuwriter.hh:285
void beginPoints()
start section for the point coordinates
Definition: vtuwriter.hh:238