Dune Core Modules (unstable)

vtkwriter.hh
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: Copyright © 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 
24 #include <dune/common/indent.hh>
26 #include <dune/common/path.hh>
27 #include <dune/geometry/referenceelements.hh>
29 #include <dune/grid/common/gridenums.hh>
33 #include <dune/grid/io/file/vtk/pvtuwriter.hh>
34 #include <dune/grid/io/file/vtk/streams.hh>
35 #include <dune/grid/io/file/vtk/vtuwriter.hh>
36 
50 namespace 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>
82  class VTKSequenceWriterBase;
83  template <class GridView>
84  class VTKSequenceWriter;
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 
178  virtual ~FunctionWrapperBase()
179  {}
180 
181  };
182 
184  // DUNE_PRIVATE since _f has less visibility
185  template<typename F>
187  : public FunctionWrapperBase
188  {
189  using Function = typename std::decay<F>::type;
190 
191  template<typename F_>
192  FunctionWrapper(F_&& 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_>
240  GlobalFunctionWrapper(F_&& 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)))
309  , _fieldInfo(fieldInfo)
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))))
319  , _fieldInfo(fieldInfo)
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)))
327  , _fieldInfo(fieldInfo)
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 
348  const VTK::FieldInfo& fieldInfo() const
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;
372  VTK::FieldInfo _fieldInfo;
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) {}
392  {
393  return ReferenceElements<DT,n>::general((*this)->type()).position(0,0);
394  }
395  };
396 
397  CellIterator cellBegin() const
398  {
399  return gridView_.template begin< 0, VTK_Partition >();
400  }
401 
402  CellIterator cellEnd() const
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:
440  void basicIncrement ()
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  {
475  basicIncrement();
476  if (git == gend) return;
477  }
478  visited[vertexmapper.subIndex(*git,cornerIndexDune,n)] = true;
479  break;
480  case VTK::nonconforming :
481  basicIncrement();
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  }
502  {
503  return referenceElement<DT,n>(git->type())
504  .position(cornerIndexDune,n);
505  }
506  };
507 
508  VertexIterator vertexBegin () const
509  {
510  return VertexIterator( gridView_.template begin< 0, VTK_Partition >(),
511  gridView_.template end< 0, VTK_Partition >(),
512  datamode, *vertexmapper );
513  }
514 
515  VertexIterator vertexEnd () const
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 
613  CornerIterator cornerBegin () const
614  {
615  return CornerIterator( gridView_.template begin< 0, VTK_Partition >(),
616  gridView_.template end< 0, VTK_Partition >(),
617  datamode, *vertexmapper, number );
618  }
619 
620  CornerIterator cornerEnd () const
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,
637  VTK::DataMode dm = VTK::conforming,
638  VTK::Precision coordPrecision = VTK::Precision::float32)
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,
696  VTK::Precision prec = VTK::Precision::float32)
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,
761  VTK::Precision prec = VTK::Precision::float32)
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,
804  VTK::OutputType type = VTK::ascii )
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,
836  VTK::OutputType type = VTK::ascii )
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 =
1112  (n == 1) ? VTK::polyData : VTK::unstructuredGrid;
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  // for 2d vector fields should be written as 3d vector fields
1131  if(it->fieldInfo().type() == VTK::FieldInfo::Type::vector && writecomps == 2)
1132  writecomps = 3;
1133  writer.addArray(it->name(), writecomps, it->fieldInfo().precision());
1134  }
1135  writer.endPointData();
1136 
1137  // PCellData
1138  {
1139  std::string scalars, vectors;
1140  std::tie(scalars,vectors) = getDataNames(celldata);
1141  writer.beginCellData(scalars, vectors);
1142  }
1143  for (auto it = celldata.begin(),
1144  end = celldata.end();
1145  it != end;
1146  ++it)
1147  {
1148  unsigned writecomps = it->fieldInfo().size();
1149  // for 2d vector fields should be written as 3d vector fields
1150  if(it->fieldInfo().type() == VTK::FieldInfo::Type::vector && writecomps == 2)
1151  writecomps = 3;
1152  writer.addArray(it->name(), writecomps, it->fieldInfo().precision());
1153  }
1154  writer.endCellData();
1155 
1156  // PPoints
1157  writer.beginPoints();
1158  writer.addArray("Coordinates", 3, coordPrec);
1159  writer.endPoints();
1160 
1161  // Pieces
1162  for( int i = 0; i < commSize; ++i )
1163  {
1164  const std::string& fullname = getParallelPieceName(piecename,
1165  piecepath, i,
1166  commSize);
1167  writer.addPiece(fullname);
1168  }
1169 
1170  writer.endMain();
1171  }
1172 
1174  void writeDataFile (std::ostream& s)
1175  {
1176  VTK::FileType fileType =
1177  (n == 1) ? VTK::polyData : VTK::unstructuredGrid;
1178 
1179  VTK::VTUWriter writer(s, outputtype, fileType);
1180 
1181  // Grid characteristics
1182  vertexmapper = new VertexMapper( gridView_, mcmgVertexLayout() );
1183  if (datamode == VTK::conforming)
1184  {
1185  number.resize(vertexmapper->size());
1186  for (std::vector<int>::size_type i=0; i<number.size(); i++) number[i] = -1;
1187  }
1188  countEntities(nvertices, ncells, ncorners);
1189 
1190  writer.beginMain(ncells, nvertices);
1191  writeAllData(writer);
1192  writer.endMain();
1193 
1194  // write appended binary data section
1195  if(writer.beginAppended())
1196  writeAllData(writer);
1197  writer.endAppended();
1198 
1199  delete vertexmapper; number.clear();
1200  }
1201 
1202  void writeAllData(VTK::VTUWriter& writer) {
1203  // PointData
1204  writeVertexData(writer);
1205 
1206  // CellData
1207  writeCellData(writer);
1208 
1209  // Points
1210  writeGridPoints(writer);
1211 
1212  // Cells
1213  writeGridCells(writer);
1214  }
1215 
1216  protected:
1217  std::string getFormatString() const
1218  {
1219  if (outputtype==VTK::ascii)
1220  return "ascii";
1221  if (outputtype==VTK::base64)
1222  return "binary";
1223  if (outputtype==VTK::appendedraw)
1224  return "appended";
1225  if (outputtype==VTK::appendedbase64)
1226  return "appended";
1227  DUNE_THROW(IOError, "VTKWriter: unsupported OutputType" << outputtype);
1228  }
1229 
1230  std::string getTypeString() const
1231  {
1232  if (n==1)
1233  return "PolyData";
1234  else
1235  return "UnstructuredGrid";
1236  }
1237 
1239  virtual void countEntities(int &nvertices_, int &ncells_, int &ncorners_)
1240  {
1241  nvertices_ = 0;
1242  ncells_ = 0;
1243  ncorners_ = 0;
1244  for (CellIterator it=cellBegin(); it!=cellEnd(); ++it)
1245  {
1246  ncells_++;
1247  // because of the use of vertexmapper->map(), this iteration must be
1248  // in the order of Dune's numbering.
1249  const int subEntities = it->subEntities(n);
1250  for (int i=0; i<subEntities; ++i)
1251  {
1252  ncorners_++;
1253  if (datamode == VTK::conforming)
1254  {
1255  int alpha = vertexmapper->subIndex(*it,i,n);
1256  if (number[alpha]<0)
1257  number[alpha] = nvertices_++;
1258  }
1259  else
1260  {
1261  nvertices_++;
1262  }
1263  }
1264  }
1265  }
1266 
1267  template<typename T>
1268  std::tuple<std::string,std::string> getDataNames(const T& data) const
1269  {
1270  std::string scalars = "";
1271  for (auto it = data.begin(),
1272  end = data.end();
1273  it != end;
1274  ++it)
1275  if (it->fieldInfo().type() == VTK::FieldInfo::Type::scalar)
1276  {
1277  scalars = it->name();
1278  break;
1279  }
1280 
1281  std::string vectors = "";
1282  for (auto it = data.begin(),
1283  end = data.end();
1284  it != end;
1285  ++it)
1286  if (it->fieldInfo().type() == VTK::FieldInfo::Type::vector)
1287  {
1288  vectors = it->name();
1289  break;
1290  }
1291  return std::make_tuple(scalars,vectors);
1292  }
1293 
1294  template<typename Data, typename Iterator>
1295  void writeData(VTK::VTUWriter& writer, const Data& data, const Iterator begin, const Iterator end, int nentries)
1296  {
1297  for (auto it = data.begin(),
1298  iend = data.end();
1299  it != iend;
1300  ++it)
1301  {
1302  const auto& f = *it;
1303  VTK::FieldInfo fieldInfo = f.fieldInfo();
1304  std::size_t writecomps = fieldInfo.size();
1305  switch (fieldInfo.type())
1306  {
1308  break;
1310  // vtk file format: a vector data always should have 3 comps (with
1311  // 3rd comp = 0 in 2D case)
1312  if (writecomps > 3)
1313  DUNE_THROW(IOError,"Cannot write VTK vectors with more than 3 components (components was " << writecomps << ")");
1314  writecomps = 3;
1315  break;
1317  DUNE_THROW(NotImplemented,"VTK output for tensors not implemented yet");
1318  }
1319  std::shared_ptr<VTK::DataArrayWriter> p
1320  (writer.makeArrayWriter(f.name(), writecomps, nentries, fieldInfo.precision()));
1321  if(!p->writeIsNoop())
1322  for (Iterator eit = begin; eit!=end; ++eit)
1323  {
1324  const Entity & e = *eit;
1325  f.bind(e);
1326  f.write(eit.position(),*p);
1327  f.unbind();
1328  // vtk file format: a vector data always should have 3 comps
1329  // (with 3rd comp = 0 in 2D case)
1330  for (std::size_t j=fieldInfo.size(); j < writecomps; ++j)
1331  p->write(0.0);
1332  }
1333  }
1334  }
1335 
1337  virtual void writeCellData(VTK::VTUWriter& writer)
1338  {
1339  if(celldata.size() == 0)
1340  return;
1341 
1342  std::string scalars, vectors;
1343  std::tie(scalars,vectors) = getDataNames(celldata);
1344 
1345  writer.beginCellData(scalars, vectors);
1346  writeData(writer,celldata,cellBegin(),cellEnd(),ncells);
1347  writer.endCellData();
1348  }
1349 
1351  virtual void writeVertexData(VTK::VTUWriter& writer)
1352  {
1353  if(vertexdata.size() == 0)
1354  return;
1355 
1356  std::string scalars, vectors;
1357  std::tie(scalars,vectors) = getDataNames(vertexdata);
1358 
1359  writer.beginPointData(scalars, vectors);
1360  writeData(writer,vertexdata,vertexBegin(),vertexEnd(),nvertices);
1361  writer.endPointData();
1362  }
1363 
1365  virtual void writeGridPoints(VTK::VTUWriter& writer)
1366  {
1367  writer.beginPoints();
1368 
1369  std::shared_ptr<VTK::DataArrayWriter> p
1370  (writer.makeArrayWriter("Coordinates", 3, nvertices, coordPrec));
1371  if(!p->writeIsNoop()) {
1372  VertexIterator vEnd = vertexEnd();
1373  for (VertexIterator vit=vertexBegin(); vit!=vEnd; ++vit)
1374  {
1375  int dimw=w;
1376  for (int j=0; j<std::min(dimw,3); j++)
1377  p->write((*vit).geometry().corner(vit.localindex())[j]);
1378  for (int j=std::min(dimw,3); j<3; j++)
1379  p->write(0.0);
1380  }
1381  }
1382  // free the VTK::DataArrayWriter before touching the stream
1383  p.reset();
1384 
1385  writer.endPoints();
1386  }
1387 
1389  virtual void writeGridCells(VTK::VTUWriter& writer)
1390  {
1391  writer.beginCells();
1392 
1393  // connectivity
1394  {
1395  std::shared_ptr<VTK::DataArrayWriter> p1
1396  (writer.makeArrayWriter("connectivity", 1, ncorners, VTK::Precision::int32));
1397  if(!p1->writeIsNoop())
1398  for (CornerIterator it=cornerBegin(); it!=cornerEnd(); ++it)
1399  p1->write(it.id());
1400  }
1401 
1402  // offsets
1403  {
1404  std::shared_ptr<VTK::DataArrayWriter> p2
1405  (writer.makeArrayWriter("offsets", 1, ncells, VTK::Precision::int32));
1406  if(!p2->writeIsNoop()) {
1407  int offset = 0;
1408  for (CellIterator it=cellBegin(); it!=cellEnd(); ++it)
1409  {
1410  offset += it->subEntities(n);
1411  p2->write(offset);
1412  }
1413  }
1414  }
1415 
1416  // types
1417  if (n>1)
1418  {
1419  {
1420  std::shared_ptr<VTK::DataArrayWriter> p3
1421  (writer.makeArrayWriter("types", 1, ncells, VTK::Precision::uint8));
1422 
1423  if(!p3->writeIsNoop())
1424  {
1425  for (CellIterator it=cellBegin(); it!=cellEnd(); ++it)
1426  {
1427  int vtktype = VTK::geometryType(it->type());
1428  p3->write(vtktype);
1429  }
1430  }
1431  }
1432 
1433 
1434  // if polyhedron cells found also cell faces need to be written
1435  if( polyhedralCellsPresent_ )
1436  {
1437  writeCellFaces( writer );
1438  }
1439  }
1440 
1441  writer.endCells();
1442  }
1443 
1444  protected:
1445  bool checkForPolyhedralCells() const
1446  {
1447  // check if polyhedron cells are present
1448  for( const auto& geomType : gridView_.indexSet().types( 0 ) )
1449  {
1450  if( VTK::geometryType( geomType ) == VTK::polyhedron )
1451  {
1452  return true;
1453  }
1454  }
1455  return false;
1456  }
1457 
1459  virtual void writeCellFaces(VTK::VTUWriter& writer)
1460  {
1461  if( ! faceVertices_ )
1462  {
1463  faceVertices_.reset( new std::pair< std::vector<int>, std::vector<int> > () );
1464  // fill face vertex structure
1465  fillFaceVertices( cornerBegin(), cornerEnd(), gridView_.indexSet(),
1466  faceVertices_->first, faceVertices_->second );
1467  }
1468 
1469  std::vector< int >& faces = faceVertices_->first;
1470  std::vector< int >& faceOffsets = faceVertices_->second;
1471  assert( int(faceOffsets.size()) == ncells );
1472 
1473  {
1474  std::shared_ptr<VTK::DataArrayWriter> p4
1475  (writer.makeArrayWriter("faces", 1, faces.size(), VTK::Precision::int32));
1476  if(!p4->writeIsNoop())
1477  {
1478  for( const auto& face : faces )
1479  p4->write( face );
1480  }
1481  }
1482 
1483  {
1484  std::shared_ptr<VTK::DataArrayWriter> p5
1485  (writer.makeArrayWriter("faceoffsets", 1, ncells, VTK::Precision::int32));
1486  if(!p5->writeIsNoop())
1487  {
1488  for( const auto& offset : faceOffsets )
1489  p5->write( offset );
1490 
1491  // clear face vertex structure
1492  faceVertices_.reset();
1493  }
1494  }
1495  }
1496 
1497  template <class CornerIterator, class IndexSet, class T>
1498  inline void fillFaceVertices( CornerIterator it,
1499  const CornerIterator end,
1500  const IndexSet& indexSet,
1501  std::vector<T>& faces,
1502  std::vector<T>& faceOffsets )
1503  {
1504  if( n == 3 && it != end )
1505  {
1506  // clear output arrays
1507  faces.clear();
1508  faces.reserve( 15 * ncells );
1509  faceOffsets.clear();
1510  faceOffsets.reserve( ncells );
1511 
1512  int offset = 0;
1513 
1514  Cell element = *it;
1515  int elIndex = indexSet.index( element );
1516  std::vector< T > vertices;
1517  vertices.reserve( 30 );
1518  for( ; it != end; ++it )
1519  {
1520  const Cell& cell = *it ;
1521  const int cellIndex = indexSet.index( cell ) ;
1522  if( elIndex != cellIndex )
1523  {
1524  fillFacesForElement( element, indexSet, vertices, offset, faces, faceOffsets );
1525 
1526  vertices.clear();
1527  element = cell ;
1528  elIndex = cellIndex ;
1529  }
1530  vertices.push_back( it.id() );
1531  }
1532 
1533  // fill faces for last element
1534  fillFacesForElement( element, indexSet, vertices, offset, faces, faceOffsets );
1535  }
1536  }
1537 
1538  template <class Entity, class IndexSet, class T>
1539  static void fillFacesForElement( const Entity& element,
1540  const IndexSet& indexSet,
1541  const std::vector<T>& vertices,
1542  T& offset,
1543  std::vector<T>& faces,
1544  std::vector<T>& faceOffsets )
1545  {
1546  const int dim = n;
1547 
1548  std::map< T, T > vxMap;
1549 
1550  // get number of local faces
1551  const int nVertices = element.subEntities( dim );
1552  for( int vx = 0; vx < nVertices; ++ vx )
1553  {
1554  const int vxIdx = indexSet.subIndex( element, vx, dim );
1555  vxMap[ vxIdx ] = vertices[ vx ];
1556  }
1557 
1558  // get number of local faces
1559  const int nFaces = element.subEntities( 1 );
1560  // store number of faces for current element
1561  faces.push_back( nFaces );
1562  ++offset;
1563  // extract each face as a set of vertex indices
1564  for( int fce = 0; fce < nFaces; ++ fce )
1565  {
1566  // obtain face
1567  const auto face = element.template subEntity< 1 > ( fce );
1568 
1569  // get all vertex indices from current face
1570  const int nVxFace = face.subEntities( dim );
1571  faces.push_back( nVxFace );
1572  ++offset ;
1573  for( int i=0; i<nVxFace; ++i )
1574  {
1575  const T vxIndex = indexSet.subIndex( face, i, dim );
1576  assert( vxMap.find( vxIndex ) != vxMap.end() );
1577  faces.push_back( vxMap[ vxIndex ] );
1578  ++offset ;
1579  }
1580  }
1581 
1582  // store face offset for each element
1583  faceOffsets.push_back( offset );
1584  }
1585 
1586  protected:
1587  // the list of registered functions
1588  std::list<VTKLocalFunction> celldata;
1589  std::list<VTKLocalFunction> vertexdata;
1590 
1591  // the grid
1592  GridView gridView_;
1593 
1594  // temporary grid information
1595  int ncells;
1596  int nvertices;
1597  int ncorners;
1598  private:
1599  VertexMapper* vertexmapper;
1600  // in conforming mode, for each vertex id (as obtained by vertexmapper)
1601  // hold its number in the iteration order (VertexIterator)
1602  std::vector<int> number;
1603  VTK::DataMode datamode;
1604  VTK::Precision coordPrec;
1605 
1606  // true if polyhedral cells are present in the grid
1607  const bool polyhedralCellsPresent_;
1608 
1609  // pointer holding face vertex connectivity if needed
1610  std::shared_ptr< std::pair< std::vector<int>, std::vector<int> > > faceVertices_;
1611 
1612  protected:
1613  VTK::OutputType outputtype;
1614  };
1615 
1616 }
1617 
1618 #endif
vector space out of a tensor product of fields.
Definition: fvector.hh:95
Base class for stl conformant forward iterators.
Definition: iteratorfacades.hh:141
Grid view abstract base class.
Definition: gridview.hh:66
Default exception class for I/O errors.
Definition: exceptions.hh:231
Index Set Interface base class.
Definition: indexidset.hh:78
IndexType index(const typename Traits::template Codim< cc >::Entity &e) const
Map entity to index. The result of calling this method with an entity that is not in the index set is...
Definition: indexidset.hh:113
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
Default exception for dummy implementations.
Definition: exceptions.hh:263
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
A base class for grid functions with any return type and dimension.
Definition: function.hh:42
Base class to write pvd-files which contains a list of all collected vtk-files.
Definition: vtksequencewriterbase.hh:34
Writer for the output of grid functions in the vtk format.
Definition: vtksequencewriter.hh:29
Iterator over the grids elements.
Definition: vtkwriter.hh:385
const FieldVector< DT, n > position() const
Definition: vtkwriter.hh:391
CellIterator(const GridCellIterator &x)
construct a CellIterator from the gridview's Iterator.
Definition: vtkwriter.hh:388
Iterate over the elements' corners.
Definition: vtkwriter.hh:539
int id() const
Process-local consecutive zero-starting vertex id.
Definition: vtkwriter.hh:597
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
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
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
Iterate over the grid's vertices.
Definition: vtkwriter.hh:424
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
Writer for the output 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
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
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
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
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:1337
virtual void countEntities(int &nvertices_, int &ncells_, int &ncorners_)
count the vertices, cells and corners
Definition: vtkwriter.hh:1239
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
virtual void writeGridCells(VTK::VTUWriter &writer)
write the connectivity array
Definition: vtkwriter.hh:1389
virtual void writeCellFaces(VTK::VTUWriter &writer)
write the connectivity array
Definition: vtkwriter.hh:1459
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
virtual void writeGridPoints(VTK::VTUWriter &writer)
write the positions of vertices
Definition: vtkwriter.hh:1365
virtual void writeVertexData(VTK::VTUWriter &writer)
write vertex data
Definition: vtkwriter.hh:1351
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
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
base class for data array writers
Definition: dataarraywriter.hh:56
void write(T data)
write one element of data
Definition: dataarraywriter.hh:69
Descriptor struct for VTK fields.
Definition: common.hh:328
@ tensor
tensor field (always 3x3)
@ vector
vector-valued field (always 3D, will be padded if necessary)
std::string name() const
The name of the data field.
Definition: common.hh:352
Dump a .vtu/.vtp files contents to a stream.
Definition: pvtuwriter.hh:62
Dump a .vtu/.vtp files contents to a stream.
Definition: vtuwriter.hh:98
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
DataArrayWriter * makeArrayWriter(const std::string &name, unsigned ncomps, unsigned nitems, Precision prec)
acquire a DataArrayWriter
Definition: vtuwriter.hh:380
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
Data array writers for the VTKWriter.
A few common exception classes.
Common stuff for the VTKWriter.
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
FileType
which type of VTK file to write
Definition: common.hh:252
DataMode
Whether to produce conforming or non-conforming output.
Definition: common.hh:67
Functions for VTK output.
typename Impl::voider< Types... >::type void_t
Is void for all valid input types. The workhorse for C++11 SFINAE-techniques.
Definition: typetraits.hh:40
#define DUNE_THROW(E, m)
Definition: exceptions.hh:218
const Communication & comm() const
obtain communication object
Definition: gridview.hh:273
Traits ::IndexSet IndexSet
type of the index set
Definition: gridview.hh:86
constexpr static int dimension
The dimension of the grid.
Definition: gridview.hh:134
constexpr static int dimensionworld
The dimension of the world the grid lives in.
Definition: gridview.hh:137
Grid::ctype ctype
type used for coordinates in grid
Definition: gridview.hh:131
Traits ::Grid Grid
type of the grid
Definition: gridview.hh:83
const IndexSet & indexSet() const
obtain the index set
Definition: gridview.hh:177
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
concept GridView
Model of a grid view.
Definition: gridview.hh:81
concept Grid
Requirements for implementations of the Dune::Grid interface.
Definition: grid.hh:98
concept Entity
Model of a grid entity.
Definition: entity.hh:107
concept IndexSet
Model of an index set.
Definition: indexidset.hh:44
constexpr auto min
Function object that returns the smaller of the given values.
Definition: hybridutilities.hh:506
MCMGLayout mcmgVertexLayout()
layout for vertices (dim-0 entities)
Definition: mcmgmapper.hh:107
std::string relativePath(const std::string &newbase, const std::string &p)
compute a relative path between two paths
Definition: path.cc:153
std::string concatPaths(const std::string &base, const std::string &p)
concatenate two paths
Definition: path.cc:32
Utility class for handling nested indentation in output.
This file implements iterator facade classes for writing stl conformant iterators.
Mapper for multiple codim and multiple geometry types.
Dune namespace.
Definition: alignedallocator.hh:13
constexpr std::integral_constant< std::size_t, sizeof...(II)> size(std::integer_sequence< T, II... >)
Return the size of the sequence.
Definition: integersequence.hh:75
Utilities for handling filesystem paths.
Static tag representing a codimension.
Definition: dimension.hh:24
static const ReferenceElement & general(const GeometryType &type)
get general reference elements
Definition: referenceelements.hh:156
Type trait to determine whether an instance of T has an operator[](I), i.e. whether it can be indexed...
Definition: typetraits.hh:250
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 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
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
virtual void unbind()
Unbind data set from current grid entity - mostly here for performance and symmetry reasons.
Definition: vtkwriter.hh:250
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
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
Traits for type conversions and type information.
Definition of macros controlling symbol visibility at the ABI level.
#define DUNE_PRIVATE
Mark a symbol as being for internal use within the current DSO only.
Definition: visibility.hh:28
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.80.0 (Apr 25, 22:37, 2024)