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