dune-fem  2.6-git
dataoutput.hh
Go to the documentation of this file.
1 #ifndef DUNE_FEM_DATAOUTPUT_HH
2 #define DUNE_FEM_DATAOUTPUT_HH
3 
4 #include <fstream>
5 #include <iostream>
6 #include <limits>
7 #include <memory>
8 #include <string>
9 #include <type_traits>
10 #include <tuple>
11 #include <utility>
12 #include <vector>
13 
14 #ifndef USE_VTKWRITER
15 #define USE_VTKWRITER 1
16 #endif
17 
18 #include <dune/common/hybridutilities.hh>
19 #include <dune/common/std/utility.hh>
20 #include <dune/common/typeutilities.hh>
21 
28 #include <dune/fem/io/parameter.hh>
36 
37 #ifndef ENABLE_VTXPROJECTION
38 #define ENABLE_VTXPROJECTION 1
39 #endif
40 
41 #if USE_VTKWRITER
43 #if ENABLE_VTXPROJECTION
45 #endif // #if ENABLE_VTXPROJECTION
46 #endif // #if USE_VTKWRITER
47 
48 #ifndef USE_GRAPE
49 #define USE_GRAPE HAVE_GRAPE
50 #endif
51 
52 #if USE_GRAPE
53 #include <dune/grid/io/visual/grapedatadisplay.hh>
54 #endif
55 
56 namespace Dune
57 {
58 
59  namespace Fem
60  {
61 
71 #ifndef DOXYGEN
72  : public LocalParameter< DataOutputParameters, DataOutputParameters >
73 #endif
74  {
75  protected:
76  const std::string keyPrefix_;
78 
79  public:
80  explicit DataOutputParameters ( std::string keyPrefix, const ParameterReader &parameter = Parameter::container() )
81  : keyPrefix_( std::move( keyPrefix ) ), parameter_( parameter )
82  {}
83 
85  : keyPrefix_( "fem.io." ), parameter_( parameter )
86  {}
87 
89  virtual std::string path() const
90  {
91  return parameter().getValue< std::string >( keyPrefix_ + "path", "./" );
92  }
93 
94  virtual std::string absolutePath () const
95  {
96  std::string absPath = parameter().getValue< std::string >( "fem.prefix", "." ) + "/";
97  const std::string relPath = path();
98  if( relPath != "./" )
99  absPath += relPath;
100  return absPath;
101  }
102 
104  virtual std::string prefix () const
105  {
106  return parameter().getValue< std::string >( keyPrefix_ + "datafileprefix", "" );
107  }
108 
110  virtual int outputformat () const
111  {
112  static const std::string formatTable[]
113  = { "vtk-cell", "vtk-vertex", "sub-vtk-cell", "binary" , "gnuplot" , "none" };
114  int format = parameter().getEnum( keyPrefix_ + "outputformat", formatTable, 1 );
115  return format;
116  }
117 
118  virtual bool conformingoutput () const
119  {
120  return parameter().getValue< bool >( keyPrefix_ + "conforming", false );
121  }
122 
124  virtual bool grapedisplay () const
125  {
126 #if USE_GRAPE
127  return (parameter().getValue( keyPrefix_ + "grapedisplay", 0 ) == 1);
128 #else
129  return false;
130 #endif
131  }
132 
134  virtual double savestep () const
135  {
136  return parameter().getValue< double >( keyPrefix_ + "savestep", 0 );
137  }
138 
140  virtual int savecount () const
141  {
142  return parameter().getValue< int >( keyPrefix_ + "savecount", 0 );
143  }
144 
146  virtual int subsamplingLevel() const
147  {
148  return parameter().getValue< int >( keyPrefix_ + "subsamplinglevel", 1 );
149  }
150 
152  virtual int startcounter () const
153  {
154  return 0;
155  }
156 
158  virtual int startcall () const
159  {
160  return 0;
161  }
162 
164  virtual double startsavetime () const
165  {
166  return 0.0;
167  }
168 
171  virtual bool willWrite ( bool write ) const
172  {
173  return write;
174  }
175 
178  virtual bool writeMode() const
179  {
180  return true ;
181  }
182 
183  const ParameterReader &parameter () const noexcept { return parameter_; }
184  };
185 
186 
187 
195  template< class GridImp, class DataImp >
197  : public IOInterface
198  {
200 
201 #if USE_VTKWRITER
202  template< class VTKIOType >
203  struct VTKListEntry
204  {
205  virtual ~VTKListEntry ()
206  {}
207  virtual void add ( VTKIOType & ) const = 0;
208 
209  protected:
210  VTKListEntry ()
211  {}
212  };
213 
214 #if ENABLE_VTXPROJECTION
215  template< class VTKIOType, class DFType >
216  class VTKFunc;
217 
218  template< class VTKOut >
219  struct VTKOutputerLagrange;
220 #endif // #if ENABLE_VTXPROJECTION
221 
222  template< class VTKOut >
223  struct VTKOutputerDG;
224 #endif // #if USE_VTKWRITER
225 
226  template< class GridPartType >
227  class GnuplotOutputer;
228 
229  struct FileWriter
230  {
231  FileWriter ( std::string name )
232  : file_( name )
233  {
234  if( !file_ )
235  std::cout << "could not write file: " << name << std::endl;
236  }
237 
238  void operator() ( const std::string &s ) { file_ << s << std::endl; }
239 
240  protected:
241  std::ofstream file_;
242  };
243 
244  struct PVDWriter
245  : public FileWriter
246  {
247  PVDWriter ( std::string name )
248  : FileWriter( name )
249  {
250  file_ << "<?xml version=\"1.0\"?>" << std::endl;
251  file_ << "<VTKFile type=\"Collection\" version=\"0.1\" byte_order=\"LittleEndian\">" << std::endl;
252  file_ << " <Collection>" << std::endl;
253  }
254 
255  ~PVDWriter ()
256  {
257  file_ << " </Collection>" << std::endl;
258  file_ << "</VTKFile>" << std::endl;
259  }
260 
261  void operator() ( double sequenceStamp, std::string filename )
262  {
263  // cH: only use the basename of filename, Paraview will
264  // prepend the leading path correctly, if the pvd-file
265  // resides in the same directory as the data files.
266  auto pos = filename.find_last_of( '/' );
267  if( pos != filename.npos )
268  filename = filename.substr( pos+1, filename.npos );
269  static_cast< FileWriter & >( *this )( " <DataSet timestep=\"" + std::to_string( sequenceStamp ) + "\" group=\"\" part=\"0\" file=\"" + filename + "\"/>" );
270  }
271 
272  private:
273  std::ofstream file_;
274  };
275 
276  public:
277  enum OutputFormat { vtk = 0, vtkvtx = 1, subvtk = 2 , binary = 3, gnuplot = 4, none = 5 };
278 
280  typedef GridImp GridType;
282  typedef DataImp OutPutDataType;
283 
284  public:
291  DataOutput ( const GridType &grid, OutPutDataType &data, std::unique_ptr< const DataOutputParameters > parameters );
292 
299  DataOutput ( const GridType &grid, OutPutDataType &data, const DataOutputParameters &parameter )
300  : DataOutput( grid, data, std::unique_ptr< const DataOutputParameters >( parameter.clone() ) )
301  {}
302 
303  DataOutput ( const GridType &grid, OutPutDataType &data, const ParameterReader &parameter = Parameter::container() )
304  : DataOutput( grid, data, DataOutputParameters( parameter ) )
305  {}
306 
314  DataOutput ( const GridType &grid, OutPutDataType &data, const TimeProviderBase &tp, std::unique_ptr< const DataOutputParameters > parameters )
315  : DataOutput( grid, data, std::move( parameters ) )
316  {
317  consistentSaveStep( tp );
318  }
319 
327  DataOutput ( const GridType &grid, OutPutDataType &data, const TimeProviderBase &tp, const DataOutputParameters &parameter )
328  : DataOutput( grid, data, tp, std::unique_ptr< const DataOutputParameters >( parameter.clone() ) )
329  {}
330 
331  DataOutput ( const GridType &grid, OutPutDataType &data, const TimeProviderBase &tp, const ParameterReader &parameter = Parameter::container() )
332  : DataOutput( grid, data, tp, DataOutputParameters( parameter ) )
333  {}
334 
335  void consistentSaveStep ( const TimeProviderBase &tp ) const;
336 
337  public:
339  virtual bool willWrite ( const TimeProviderBase &tp ) const
340  {
341  // make save step consistent
342  consistentSaveStep( tp );
343 
344  const double saveTimeEps = 2*std::numeric_limits< double >::epsilon()*saveTime_;
345  const bool writeStep = (saveStep_ > 0) && (tp.time() - saveTime_ >= -saveTimeEps);
346  const bool writeCount = (saveCount_ > 0) && (writeCalls_ % saveCount_ == 0);
347  return param_->willWrite( writeStep || writeCount );
348  }
349 
351  virtual bool willWrite () const
352  {
353  return param_->willWrite( (saveCount_ > 0) && (writeCalls_ % saveCount_ == 0) );
354  }
355 
359  void write( const std::string& outstring ) const
360  {
361  if( willWrite() )
362  writeData( writeCalls_, outstring );
363  ++writeCalls_;
364  }
365 
367  void write() const
368  {
369  if( willWrite() )
370  writeData( writeCalls_, "" );
371  ++writeCalls_;
372  }
373 
378  void write(const TimeProviderBase& tp, const std::string& outstring ) const
379  {
380  if( willWrite(tp) )
381  writeData( tp.time(), outstring );
382  ++writeCalls_;
383  }
384 
388  void write( const TimeProviderBase& tp ) const
389  {
390  write( tp, "" );
391  }
392 
397  void writeData ( double sequenceStamp, const std::string &outstring ) const;
398 
402  void writeData ( double sequenceStamp ) const
403  {
404  writeData( sequenceStamp, "" );
405  }
406 
408  virtual const char* myClassName () const
409  {
410  return "DataOutput";
411  }
412 
414  const std::string &path () const
415  {
416  return path_;
417  }
418 
420  int writeStep() const
421  {
422  return writeStep_;
423  }
424 
426  int writeCalls() const
427  {
428  return writeCalls_;
429  }
430 
432  double saveTime() const
433  {
434  return saveTime_;
435  }
436 
437  protected:
438  auto getGridPart() const
439  {
440  static constexpr bool isNotEmpty = std::tuple_size< DataImp >::value > 0;
441  return getGridPart( std::integral_constant< bool, isNotEmpty > () );
442  }
443 
444  auto getGridPart( std::integral_constant< bool, false > ) const
445  {
446  typedef Dune::Fem::LeafGridPart< GridType > GridPartType;
447  return GridPartType( const_cast<GridType&> (grid_) );
448  }
449 
450  auto getGridPart( std::integral_constant< bool, true > ) const
451  {
452  return std::get< 0 >( data_ )->space().gridPart();
453  }
454 
455 #if USE_VTKWRITER
456  std::string writeVTKOutput () const;
457 #endif
458 
459  std::string writeGnuPlotOutput () const;
460 
462  virtual void writeBinaryData ( const double ) const
463  {
464  DUNE_THROW(NotImplemented, "Format 'binary' not supported by DataOutput, use DataWriter instead." );
465  }
466 
468  virtual void display () const
469  {
470  if( grapeDisplay_ )
471  grapeDisplay( data_ );
472  }
473 
475  template< class OutputTupleType >
476  void grapeDisplay ( OutputTupleType &data ) const;
477 
479  const GridType& grid_;
481 
482  // name for data output
483  std::string path_;
484  std::string datapref_;
485  // use grape display
487 
488  // counter for sequence of files
489  mutable int writeStep_;
490  // counter for call to write
491  mutable int writeCalls_;
492  // next point in time to save data
493  mutable double saveTime_;
494  // time interval to save files
495  double saveStep_;
496  // number of write call between writting files
498  // grape, vtk or ...
501  std::unique_ptr< FileWriter > sequence_;
502  std::unique_ptr< PVDWriter > pvd_;
503  std::unique_ptr< const DataOutputParameters > param_;
504  };
505 
506 
507 
508  // DataOutput::VTKFunc
509  // -------------------
510 
511 #if USE_VTKWRITER
512 #if ENABLE_VTXPROJECTION
513  template< class GridImp, class DataImp >
514  template< class VTKIOType, class DFType >
515  class DataOutput< GridImp, DataImp >::VTKFunc
516  : public VTKListEntry< VTKIOType >
517  {
518  typedef typename VTKIOType::GridPartType GridPartType;
519  typedef typename DFType::FunctionSpaceType FunctionSpaceType;
520 
522  typedef AdaptiveDiscreteFunction< LagrangeSpaceType > NewFunctionType;
523 
524  public:
525  VTKFunc ( const GridPartType &gridPart, const DFType &df )
526  : df_( df ),
527  space_( const_cast< GridPartType & >( gridPart ) )
528  {}
529 
530  virtual void add ( VTKIOType &vtkio ) const
531  {
532  func_.reset( new NewFunctionType( df_.name()+"vtx-prj" , space_ ) );
533  if( df_.continuous() )
534  {
535  interpolate( df_, *func_ );
536  }
537  else
538  {
539  WeightDefault<GridPartType> weight;
540  VtxProjectionImpl::project( df_, *func_, weight );
541  }
542  vtkio.addVertexData( *func_ );
543  }
544 
545  VTKFunc ( const VTKFunc & ) = delete;
546 
547  private:
548  const DFType& df_;
549  LagrangeSpaceType space_;
550  mutable std::unique_ptr<NewFunctionType> func_;
551  };
552 #endif // #if ENABLE_VTXPROJECTION
553 #endif // #if USE_VTKWRITER
554 
555 
556 
557  // DataOutput::VTKOutputerDG
558  // -------------------------
559 
560 #if USE_VTKWRITER
561  template< class GridImp, class DataImp >
562  template< class VTKOut >
563  struct DataOutput< GridImp, DataImp >::VTKOutputerDG
564  {
565  template< class... Args >
566  explicit VTKOutputerDG ( bool conforming, Args &&... args )
567  : conforming_( conforming ), vtkOut_( std::forward< Args >( args )... )
568  {}
569 
570  template< typename ... T >
571  void forEach ( const std::tuple< T ... >& data )
572  {
573  Hybrid::forEach( Std::make_index_sequence< sizeof...( T ) >{},
574  [&]( auto i ) {
575  auto df( std::get< i >( data ) );
576  if( df )
577  {
578  if( conforming_ || ( df->order() == 0 ) )
579  vtkOut_.addCellData( *df );
580  else
581  vtkOut_.addVertexData( *df );
582  }
583  });
584  }
585 
586  template< typename T >
587  void forEach ( const T& data )
588  {
589  std::tuple< T > tup( data );
590  forEach( tup );
591  }
592 
593  std::string write ( bool parallel, const std::string &name, const std::string &path )
594  {
595  return (parallel ? vtkOut_.pwrite( name, path, "." ) : vtkOut_.write( name ));
596  }
597 
598  private:
599  bool conforming_;
600  VTKOut vtkOut_;
601  };
602 #endif // #if USE_VTKWRITER
603 
604 
605 
606  // DataOutput::VTKOutputerLagrange
607  // -------------------------------
608 
609 #if USE_VTKWRITER
610 #if ENABLE_VTXPROJECTION
611  template< class GridImp, class DataImp >
612  template< class VTKOut >
613  struct DataOutput< GridImp, DataImp >::VTKOutputerLagrange
614  {
616  template< class... Args >
617  explicit VTKOutputerLagrange ( Args &&... args )
618  : vtkOut_( std::forward< Args >( args )... )
619  {}
620 
621  template< typename ... T >
622  void forEach ( const std::tuple< T ... >& data )
623  {
624  Hybrid::forEach( Std::make_index_sequence< sizeof...( T ) >{},
625  [&]( auto i ) {
626  auto df( std::get< i >( data ) );
627  if( df )
628  {
629  typedef typename std::remove_pointer< decltype( df ) >::type DFType;
630  vec_.emplace_back( new VTKFunc< VTKOut, DFType >( vtkOut_.gridPart(), *df ) );
631  vec_.back()->add( vtkOut_ );
632  }
633  });
634  }
635 
636  template< typename T >
637  void forEach ( const T& data )
638  {
639  std::tuple< T > tup( data );
640  forEach( tup );
641  }
642 
643  std::string write ( bool parallel, const std::string &name, const std::string &path )
644  {
645  return (parallel ? vtkOut_.pwrite( name, path, "." ) : vtkOut_.write( name ));
646  }
647 
648  private:
649  std::vector< std::unique_ptr< VTKListEntry< VTKOut > > > vec_;
650  VTKOut vtkOut_;
651  };
652 #endif // #if ENABLE_VTXPROJECTION
653 #endif // #if USE_VTKWRITER
654 
655 
656 
657  // DataOutput::GnuplotOutputer
658  // ---------------------------
659  template< class GridImp, class DataImp >
660  template< class GridPartType >
661  class DataOutput< GridImp, DataImp >::GnuplotOutputer
662  {
663  typedef typename GridPartType::template Codim< 0 >::IteratorType::Entity Entity;
664  std::ostream& out_;
665  CachingQuadrature<GridPartType,0> &quad_;
666  int i_;
667  const Entity& en_;
668 
669  public:
671  GnuplotOutputer ( std::ostream& out,
672  CachingQuadrature<GridPartType,0> &quad,
673  int i,
674  const Entity &en )
675  : out_(out), quad_(quad), i_(i), en_(en)
676  {}
677 
678  template< typename ... T >
679  void forEach ( const std::tuple< T ... >& data )
680  {
681  Hybrid::forEach( Std::make_index_sequence< sizeof...( T ) >{},
682  [&]( auto i ) {
683  auto df( std::get< i >( data ));
684  if( df )
685  {
686  ConstLocalFunction<std::decay_t<decltype(*df)> > lf(*df);
687  lf.bind(en_);
688  typedef typename std::remove_pointer< decltype( df ) >::type DFType;
689  typename DFType::FunctionSpaceType::RangeType u;
690  lf.evaluate( quad_[ i_ ], u );
691 
692  constexpr int dimRange = DFType::FunctionSpaceType::dimRange;
693  for( auto k = 0; k < dimRange; ++k )
694  out_ << " " << u[ k ];
695  lf.unbind();
696  }
697  });
698  }
699 
700  template< typename T >
701  void forEach ( const T& data )
702  {
703  std::tuple< T > tup( data );
704  forEach( tup );
705  }
706 
707  };
708 
709 
710 
711  // Implementation of DataOutput
712  // ----------------------------
713  template< class GridImp, class DataImp >
715  ::DataOutput ( const GridType &grid, OutPutDataType &data,
716  std::unique_ptr< const DataOutputParameters > parameters )
717  : grid_( grid ),
718  data_( data ),
719  writeStep_(0),
720  writeCalls_(0),
721  saveTime_(0),
722  saveStep_(-1),
723  saveCount_(-1),
724  outputFormat_(vtkvtx),
725  conformingOutput_( false ),
726  param_( std::move( parameters ) )
727  {
728  const bool writeMode = param_->writeMode();
729  path_ = param_->absolutePath();
730 
731  // create path if not already exists
732  if( writeMode )
733  IOInterface :: createGlobalPath ( grid_.comm(), path_ );
734 
735  // add prefix for data file
736  datapref_ += param_->prefix();
737 
738  auto outputFormat = param_->outputformat();
739  switch( outputFormat )
740  {
741  case 0: outputFormat_ = vtk; break;
742  case 1: outputFormat_ = vtkvtx; break;
743  case 2: outputFormat_ = subvtk; break;
744  case 3: outputFormat_ = binary; break;
745  case 4: outputFormat_ = gnuplot; break;
746  case 5: outputFormat_ = none; break;
747  default:
748  DUNE_THROW(NotImplemented,"DataOutput::init: wrong output format");
749  }
750 
751  conformingOutput_ = param_->conformingoutput();
752 
753  grapeDisplay_ = param_->grapedisplay();
754 
755  // get parameters for data writing
756  saveStep_ = param_->savestep();
757  saveCount_ = param_->savecount();
758 
759  // set initial quantities
760  writeStep_ = param_->startcounter();
761  writeCalls_ = param_->startcall();
762  saveTime_ = param_->startsavetime();
763 
764  if( writeMode )
765  {
766  // only write series file for VTK output
767  if ( Parameter :: verbose() && outputFormat_ < binary )
768  {
769  sequence_.reset( new FileWriter( path_ + "/" + datapref_ + ".series" ) );
770  pvd_.reset( new PVDWriter( path_ + "/" + datapref_ + ".pvd" ) );
771  }
772 
773  // write parameter file
774  Parameter::write("parameter.log");
775  }
776  }
777 
778 
779  template< class GridImp, class DataImp >
782  {
783  // set old values according to new time
784  if( saveStep_ > 0 )
785  {
786  const auto oldTime = tp.time() - saveStep_;
787  while( saveTime_ <= oldTime )
788  {
789  ++writeStep_;
790  saveTime_ += saveStep_;
791  }
792  }
793  }
794 
795 
796  template< class GridImp, class DataImp >
798  ::writeData ( double sequenceStamp, const std::string &outstring ) const
799  {
800  std::string filename;
801  // check online display
802  display();
803  switch( outputFormat_ )
804  {
805  // if no output was chosen just return
806  case none: break ;
807  case binary: writeBinaryData( sequenceStamp ); break;
808  case vtk :
809  case vtkvtx :
810  case subvtk :
811 #if USE_VTKWRITER
812  // write data in vtk output format
813  filename = writeVTKOutput();
814  break;
815 #else
816  DUNE_THROW(NotImplemented,"DataOutput::write: VTKWriter was disabled by USE_VTKWRITER 0");
817 #endif // #if USE_VTKWRITER
818  case gnuplot : filename = writeGnuPlotOutput(); break;
819  default:
820  DUNE_THROW(NotImplemented,"DataOutput::write: wrong output format = " << outputFormat_);
821  }
822 
823  if( outputFormat_ != none )
824  {
825  if( sequence_ )
826  (*sequence_)( std::to_string( writeStep_ ) + " " + filename + " " + std::to_string( sequenceStamp ) + outstring );
827 
828  if( pvd_ )
829  (*pvd_)( sequenceStamp, filename );
830 
831  if( Parameter::verbose() )
832  {
833  // only write info for proc 0, otherwise on large number of procs
834  // this is to much output
835  std::cout << myClassName() << "[" << grid_.comm().rank() << "]::write data"
836  << " writestep=" << writeStep_
837  << " sequenceStamp=" << sequenceStamp
838  << outstring
839  << std::endl;
840  }
841  }
842 
843  saveTime_ += saveStep_;
844  ++writeStep_;
845  }
846 
847 #if USE_VTKWRITER
848  template< class GridImp, class DataImp >
850  {
851  std::string filename;
852  // check whether to use vertex data of discontinuous data
853  const bool vertexData = (outputFormat_ == vtkvtx);
854 
855  // check whether we have parallel run
856  const bool parallel = (grid_.comm().size() > 1);
857 
858  // generate filename, with path only for serial run
859  auto name = generateFilename( (parallel ? datapref_ : path_ + "/" + datapref_ ), writeStep_ );
860 
861  // get GridPart
862  const auto& gridPart = getGridPart();
863  typedef typename std::decay< decltype( gridPart ) >::type GridPartType;
864 
865  if( vertexData )
866  {
867 #if ENABLE_VTXPROJECTION
868  // create vtk output handler
869  VTKOutputerLagrange< VTKIO< GridPartType > > io( gridPart, VTK::conforming, param_->parameter() );
870 
871  // add all functions
872  io.forEach( data_ );
873 
874  // write all data
875  filename = io.write( parallel, name, path_ );
876 #endif
877  }
878  else if ( outputFormat_ == vtk )
879  {
880  // create vtk output handler
881  VTKOutputerDG< VTKIO< GridPartType > > io( conformingOutput_, gridPart, conformingOutput_ ? VTK::conforming : VTK::nonconforming, param_->parameter() );
882 
883  // add all functions
884  io.forEach( data_ );
885 
886  // write all data
887  filename = io.write( parallel, name, path_ );
888  }
889  else if ( outputFormat_ == subvtk )
890  {
891  // create vtk output handler
892  VTKOutputerDG< SubsamplingVTKIO < GridPartType > > io( conformingOutput_, gridPart, static_cast< unsigned int >( param_->subsamplingLevel() ), param_->parameter() );
893 
894  // add all functions
895  io.forEach( data_ );
896 
897  // write all data
898  filename = io.write( parallel, name, path_ );
899  }
900  return filename;
901  }
902 #endif // #if USE_VTKWRITER
903 
904 
905  template< class GridImp, class DataImp >
907  {
908  // generate filename
909  auto name = generateFilename( path_ + "/" + datapref_, writeStep_ );
910  name += ".gnu";
911  std::ofstream gnuout(name.c_str());
912  gnuout << std::scientific << std::setprecision( 16 );
913 
914  // start iteration
915  const auto& gridPart = getGridPart();
916  typedef typename std::decay< decltype( gridPart ) >::type GridPartType;
917  for( const auto& entity : elements( gridPart ) )
918  {
919  CachingQuadrature< GridPartType, 0 > quad( entity, 1 );
920  for( decltype(quad.nop()) i = 0; i < quad.nop(); ++i )
921  {
922  const auto x = entity.geometry().global( quad.point( i ) );
923  for( auto k = 0; k < x.dimension; ++k )
924  gnuout << (k > 0 ? " " : "") << x[ k ];
925  GnuplotOutputer< GridPartType > io( gnuout, quad, i, entity );
926  io.forEach( data_ );
927  gnuout << std::endl;
928  }
929  }
930  return name;
931  }
932 
933 
934 #if USE_GRAPE
935  template< class GridImp, class DataImp >
936  template< class OutputTupleType >
937  inline void DataOutput< GridImp, DataImp >::grapeDisplay ( OutputTupleType &data ) const
938  {
939  GrapeDataDisplay<GridType> grape(grid_);
941  grape.display();
942  }
943 #else
944  template< class GridImp, class DataImp >
945  template< class OutputTupleType >
946  inline void DataOutput< GridImp, DataImp >::grapeDisplay ( OutputTupleType &data ) const
947  {
948  std::cerr << "WARNING: HAVE_GRAPE == 0, but grapeDisplay == true, recompile with grape support for online display!" << std::endl;
949  }
950 #endif
951 
952 
953 
954  namespace Impl
955  {
956 
957  // makeIOTuple
958  // -----------
959 
960  template< class DF >
961  inline static auto makeSingleIOTuple ( DF &&df, PriorityTag< 1 > )
962  -> std::enable_if_t< std::is_reference< DF >::value && std::is_base_of< Fem::HasLocalFunction, std::decay_t< DF > >::value,
963  std::tuple< const std::decay_t< DF > * > >
964  {
965  return std::make_tuple( &df );
966  }
967 
968  template< class DF >
969  inline static auto makeSingleIOTuple ( DF &&df, PriorityTag< 0 > )
970  -> std::tuple<>
971  {
972  return {};
973  }
974 
975  template< class... Args >
976  inline static auto makeIOTuple ( Args &&... args )
977  {
978  return std::tuple_cat( makeSingleIOTuple( std::forward< Args >( args ), PriorityTag< 42 >() )... );
979  }
980 
981 
982 
983  // getDataOutputParameters
984  // -----------------------
985 
986  inline static auto getSingleDataOutputParameters ( std::unique_ptr< const DataOutputParameters > parameters )
987  {
988  return std::make_tuple( std::move( parameters ) );
989  }
990 
991  inline static auto getSingleDataOutputParameters ( const DataOutputParameters &parameters )
992  {
993  return std::make_tuple( std::unique_ptr< const DataOutputParameters >( parameters.clone() ) );
994  }
995 
996  inline static auto getSingleDataOutputParameters ( const ParameterReader &parameter )
997  {
998  return std::make_tuple( std::make_unique< const DataOutputParameters >( parameter ) );
999  }
1000 
1001  template< class Arg >
1002  inline static auto getSingleDataOutputParameters ( Arg &&arg, PriorityTag< 1 > )
1003  -> decltype( getSingleDataOutputParameters( std::declval< Arg >() ) )
1004  {
1005  return getSingleDataOutputParameters( std::forward< Arg >( arg ) );
1006  }
1007 
1008  template< class Arg >
1009  inline static std::tuple<> getSingleDataOutputParameters ( Arg &&arg, PriorityTag< 0 > )
1010  {
1011  return {};
1012  }
1013 
1014  template< class... Args >
1015  inline static auto getDataOutputParametersTuple ( Args &&... args )
1016  -> decltype( std::tuple_cat( getSingleDataOutputParameters( std::declval< Args >(), PriorityTag< 42 >() )... ) )
1017  {
1018  return std::tuple_cat( getSingleDataOutputParameters( std::forward< Args >( args ), PriorityTag< 42 >() )... );
1019  }
1020 
1021  template< class... Args >
1022  inline static auto getDataOutputParameters ( Args &&... args )
1023  -> std::enable_if_t< (std::tuple_size< decltype( getDataOutputParametersTuple( std::declval< Args >()... ) ) >::value == 0), std::unique_ptr< const DataOutputParameters > >
1024  {
1025  return std::make_unique< const DataOutputParameters >( Parameter::container() );
1026  }
1027 
1028  template< class... Args >
1029  inline static auto getDataOutputParameters ( Args &&... args )
1030  -> std::enable_if_t< (std::tuple_size< decltype( getDataOutputParametersTuple( std::declval< Args >()... ) ) >::value > 0), std::unique_ptr< const DataOutputParameters > >
1031  {
1032  static_assert( (std::tuple_size< decltype( Impl::getDataOutputParametersTuple( std::declval< Args >()... ) ) >::value == 1), "Cannot pass multiple DataOutputParameters to DataOutput" );
1033  return std::get< 0 >( getDataOutputParametersTuple( std::forward< Args >( args )... ) );
1034  }
1035 
1036 
1037 
1038  // ValidDataOutputArgument
1039  // -----------------------
1040 
1041  template< class Arg, class = void >
1042  struct ValidDataOutputArgument
1043  : public std::false_type
1044  {};
1045 
1046  template< class DF >
1047  struct ValidDataOutputArgument< DF, std::enable_if_t< std::is_base_of< Fem::HasLocalFunction, std::decay_t< DF > >::value > >
1048  : public std::true_type
1049  {};
1050 
1051  template< class Arg >
1052  struct ValidDataOutputArgument< Arg, void_t< decltype( getSingleDataOutputParameters( std::declval< Arg >() ) ) > >
1053  : public std::true_type
1054  {};
1055 
1056  } // namespace Impl
1057 
1058 
1059 
1060  // dataOutput
1061  // ----------
1062 
1063  template< class Grid, class... Args, std::enable_if_t< Std::And( Impl::ValidDataOutputArgument< Args >::value... ), int > = 0 >
1064  inline static auto dataOutput ( const Grid &grid, Args &&... args )
1065  {
1066  auto ioTuple = Impl::makeIOTuple( std::forward< Args >( args )... );
1067  auto parameters = Impl::getDataOutputParameters( std::forward< Args >( args )... );
1068  return DataOutput< Grid, decltype( ioTuple ) >( grid, ioTuple, std::move( parameters ) );
1069  }
1070 
1071  template< class Grid, class... Args, std::enable_if_t< Std::And( Impl::ValidDataOutputArgument< Args >::value... ), int > = 0 >
1072  inline static auto dataOutput ( const Grid &grid, const TimeProviderBase &tp, Args &&... args )
1073  {
1074  auto ioTuple = Impl::makeIOTuple( std::forward< Args >( args )... );
1075  auto parameters = Impl::getDataOutputParameters( std::forward< Args >( args )... );
1076  return DataOutput< Grid, decltype( ioTuple ) >( grid, ioTuple, tp, std::move( parameters ) );
1077  }
1078 
1079  } // namespace Fem
1080 
1081 } // namespace Dune
1082 
1083 #endif // #ifndef DUNE_FEM_DATAOUTPUT_HH
static void interpolate(const GridFunction &u, DiscreteFunction &v)
perform native interpolation of a discrete function space
Definition: common/interpolate.hh:52
Definition: bindguard.hh:11
static auto dataOutput(const Grid &grid, Args &&... args)
Definition: dataoutput.hh:1064
typename Impl::ConstLocalFunction< GridFunction >::Type ConstLocalFunction
Definition: const.hh:451
BasicParameterReader< std::function< const std::string *(const std::string &, const std::string *) > > ParameterReader
Definition: reader.hh:264
std::string generateFilename(const std::string &fn, int ntime, int precision=6)
Definition: iointerface.hh:47
static void forEach(IndexRange< T, sz > range, F &&f)
Definition: hybrid.hh:129
static constexpr bool And()
Definition: utility.hh:125
Definition: function/adaptivefunction/adaptivefunction.hh:45
Parameter class for Dune::Fem::DataOutput.
Definition: dataoutput.hh:74
DataOutputParameters(const ParameterReader &parameter=Parameter::container())
Definition: dataoutput.hh:84
const ParameterReader & parameter() const noexcept
Definition: dataoutput.hh:183
virtual int outputformat() const
format of output (fem.io.outputformat)
Definition: dataoutput.hh:110
virtual int savecount() const
save data every savecount calls to write method (fem.io.savecount)
Definition: dataoutput.hh:140
virtual int subsamplingLevel() const
save data every subsamplingLevel (fem.io.subsamplinglevel)
Definition: dataoutput.hh:146
DataOutputParameters(std::string keyPrefix, const ParameterReader &parameter=Parameter::container())
Definition: dataoutput.hh:80
ParameterReader parameter_
Definition: dataoutput.hh:77
virtual int startcounter() const
number for first data file (no parameter available)
Definition: dataoutput.hh:152
virtual int startcall() const
number of first call (no parameter available)
Definition: dataoutput.hh:158
virtual double startsavetime() const
value of first save time (no parameter available)
Definition: dataoutput.hh:164
virtual bool willWrite(bool write) const
Definition: dataoutput.hh:171
virtual bool conformingoutput() const
Definition: dataoutput.hh:118
virtual std::string prefix() const
base of file name for data file (fem.io.datafileprefix)
Definition: dataoutput.hh:104
virtual std::string absolutePath() const
Definition: dataoutput.hh:94
virtual std::string path() const
path where the data is stored (always relative to fem.prefix)
Definition: dataoutput.hh:89
const std::string keyPrefix_
Definition: dataoutput.hh:76
virtual double savestep() const
save data every savestep interval (fem.io.savestep)
Definition: dataoutput.hh:134
virtual bool writeMode() const
Definition: dataoutput.hh:178
virtual bool grapedisplay() const
use online grape display (fem.io.grapedisplay)
Definition: dataoutput.hh:124
Implementation of the Dune::Fem::IOInterface. This class manages data output. Available output format...
Definition: dataoutput.hh:198
DataOutput(const GridType &grid, OutPutDataType &data, const TimeProviderBase &tp, const DataOutputParameters &parameter)
Constructor creating data writer.
Definition: dataoutput.hh:327
int writeCalls_
Definition: dataoutput.hh:491
int writeStep_
Definition: dataoutput.hh:489
DataOutput(const GridType &grid, OutPutDataType &data, const ParameterReader &parameter=Parameter::container())
Definition: dataoutput.hh:303
virtual const char * myClassName() const
print class name
Definition: dataoutput.hh:408
void write() const
write given data to disc, evaluates parameter savecount
Definition: dataoutput.hh:367
double saveTime_
Definition: dataoutput.hh:493
int writeCalls() const
return write calls
Definition: dataoutput.hh:426
DataOutput(const GridType &grid, OutPutDataType &data, const TimeProviderBase &tp, const ParameterReader &parameter=Parameter::container())
Definition: dataoutput.hh:331
DataOutput(const GridType &grid, OutPutDataType &data, const TimeProviderBase &tp, std::unique_ptr< const DataOutputParameters > parameters)
Constructor creating data writer.
Definition: dataoutput.hh:314
auto getGridPart(std::integral_constant< bool, true >) const
Definition: dataoutput.hh:450
GridImp GridType
type of grid used
Definition: dataoutput.hh:280
void writeData(double sequenceStamp) const
write data with a given sequence stamp
Definition: dataoutput.hh:402
double saveStep_
Definition: dataoutput.hh:495
void write(const std::string &outstring) const
write given data to disc, evaluates parameter savecount
Definition: dataoutput.hh:359
void grapeDisplay(OutputTupleType &data) const
display data with grape
Definition: dataoutput.hh:946
OutputFormat
Definition: dataoutput.hh:277
@ none
Definition: dataoutput.hh:277
@ vtkvtx
Definition: dataoutput.hh:277
@ gnuplot
Definition: dataoutput.hh:277
@ subvtk
Definition: dataoutput.hh:277
@ vtk
Definition: dataoutput.hh:277
@ binary
Definition: dataoutput.hh:277
std::unique_ptr< const DataOutputParameters > param_
Definition: dataoutput.hh:503
virtual void display() const
display data with grape
Definition: dataoutput.hh:468
std::string path_
Definition: dataoutput.hh:483
std::string writeVTKOutput() const
Definition: dataoutput.hh:849
DataImp OutPutDataType
type of data tuple
Definition: dataoutput.hh:282
bool conformingOutput_
Definition: dataoutput.hh:500
int writeStep() const
return write step
Definition: dataoutput.hh:420
void writeData(double sequenceStamp, const std::string &outstring) const
write data with a given sequence stamp and outstring
Definition: dataoutput.hh:798
virtual bool willWrite(const TimeProviderBase &tp) const
returns true if data will be written on next write call
Definition: dataoutput.hh:339
bool grapeDisplay_
Definition: dataoutput.hh:486
OutputFormat outputFormat_
Definition: dataoutput.hh:499
double saveTime() const
return save time
Definition: dataoutput.hh:432
std::unique_ptr< PVDWriter > pvd_
Definition: dataoutput.hh:502
std::string writeGnuPlotOutput() const
Definition: dataoutput.hh:906
OutPutDataType data_
Definition: dataoutput.hh:480
void write(const TimeProviderBase &tp, const std::string &outstring) const
write given data to disc, evaluates parameter savecount and savestep
Definition: dataoutput.hh:378
virtual bool willWrite() const
returns true if data will be written on next write call
Definition: dataoutput.hh:351
virtual void writeBinaryData(const double) const
write binary data
Definition: dataoutput.hh:462
const std::string & path() const
return output path name
Definition: dataoutput.hh:414
std::unique_ptr< FileWriter > sequence_
Definition: dataoutput.hh:501
auto getGridPart(std::integral_constant< bool, false >) const
Definition: dataoutput.hh:444
int saveCount_
Definition: dataoutput.hh:497
DataOutput(const GridType &grid, OutPutDataType &data, const DataOutputParameters &parameter)
Constructor creating data output class.
Definition: dataoutput.hh:299
const GridType & grid_
type of this class
Definition: dataoutput.hh:479
void consistentSaveStep(const TimeProviderBase &tp) const
Definition: dataoutput.hh:781
auto getGridPart() const
Definition: dataoutput.hh:438
std::string datapref_
Definition: dataoutput.hh:484
DataOutput(const GridType &grid, OutPutDataType &data, std::unique_ptr< const DataOutputParameters > parameters)
Constructor creating data output class.
Definition: dataoutput.hh:715
void write(const TimeProviderBase &tp) const
write given data to disc, evaluates parameter savecount and savestep
Definition: dataoutput.hh:388
IOInterface to write data to hard disk.
Definition: iointerface.hh:161
static void createGlobalPath(const CommunicatorType &comm, const std::string &path)
create global path for data output
Definition: iointerface.hh:267
static void addToDisplay(Disp &disp, const DINFO *dinf, double time, Tuple &tuple)
Definition: iotuple.hh:268
int getEnum(const std::string &key, const std::string(&values)[n]) const
Definition: reader.hh:215
T getValue(const std::string &key) const
get mandatory parameter
Definition: reader.hh:149
static bool verbose()
obtain the cached value for fem.verbose
Definition: io/parameter.hh:437
static DUNE_EXPORT ParameterContainer & container()
Definition: io/parameter.hh:192
static void write(const std::string &filename, const std::string &fileextension="", bool writeAll=true)
write the parameter database to a file
Definition: io/parameter.hh:508
Definition: io/parameter.hh:544
static void project(const Function &f, DiscreteFunction &u, Weight &weight)
Definition: vtxprojection.hh:194
general base for time providers
Definition: timeprovider.hh:36
double time() const
obtain the current time
Definition: timeprovider.hh:94