1 #ifndef DUNE_PDELAB_GRIDFUNCTIONSPACE_VTK_HH
2 #define DUNE_PDELAB_GRIDFUNCTIONSPACE_VTK_HH
7 #include <dune/common/exceptions.hh>
9 #include <dune/geometry/typeindex.hh>
11 #include <dune/localfunctions/common/interfaceswitch.hh>
13 #include <dune/typetree/visitor.hh>
14 #include <dune/typetree/traversal.hh>
44 template<
typename VTKWriter>
45 struct vtk_writer_traits;
48 struct vtk_writer_traits<Dune::
VTKWriter<GV> >
73 template<
typename LFS,
typename Data>
76 template<
typename LFS,
typename Data>
79 template<
typename VTKWriter,
typename Data>
84 template<
typename GFS,
typename X,
typename Pred>
88 template<
typename LFS,
typename Data>
91 template<
typename LFS,
typename Data>
94 template<
typename,
typename>
99 typedef typename X::template ConstLocalView<LFSCache> XView;
101 typedef typename GFS::Traits::GridView::template Codim<0>::Entity Cell;
102 typedef typename GFS::Traits::SizeType size_type;
103 typedef typename GFS::Traits::GridView::IndexSet IndexSet;
105 static const size_type
dim = GFS::Traits::GridView::dimension;
149 template<
typename LFS,
typename Data>
151 :
public TypeTree::LeafNode
153 typename LFS::Traits::GridView,
154 typename BasisInterfaceSwitch<
155 typename FiniteElementInterfaceSwitch<
156 typename LFS::Traits::FiniteElement
159 BasisInterfaceSwitch<
160 typename FiniteElementInterfaceSwitch<
161 typename LFS::Traits::FiniteElement
164 typename BasisInterfaceSwitch<
165 typename FiniteElementInterfaceSwitch<
166 typename LFS::Traits::FiniteElement
170 DGFTreeLeafFunction<LFS,Data>
174 typedef BasisInterfaceSwitch<
175 typename FiniteElementInterfaceSwitch<
176 typename LFS::Traits::FiniteElement
182 typename LFS::Traits::GridView,
183 typename BasisSwitch::RangeField,
184 BasisSwitch::dimRange,
185 typename BasisSwitch::Range
197 , _basis(lfs.maxSize())
202 const typename Traits::DomainType& x,
203 typename Traits::RangeType& y)
const
207 typedef FiniteElementInterfaceSwitch<
208 typename LFS::Traits::FiniteElement
213 FESwitch::basis(_lfs.finiteElement()).evaluateFunction(x,_basis);
214 for (std::size_t i = 0; i < _lfs.size(); ++i)
215 y.axpy(_data->_x_local(_lfs,i),_basis[i]);
219 const typename Traits::GridViewType&
gridView()
const
221 return _lfs.gridFunctionSpace().gridView();
232 const shared_ptr<Data> _data;
233 mutable std::vector<typename Traits::RangeType> _basis;
239 template<
typename LFS,
typename Data>
240 class DGFTreeVectorFunction
241 :
public TypeTree::LeafNode
243 typename LFS::Traits::GridView,
244 typename BasisInterfaceSwitch<
245 typename FiniteElementInterfaceSwitch<
246 typename LFS::ChildType::Traits::FiniteElement
251 typename BasisInterfaceSwitch<
252 typename FiniteElementInterfaceSwitch<
253 typename LFS::ChildType::Traits::FiniteElement
259 DGFTreeVectorFunction<LFS,Data>
263 typedef BasisInterfaceSwitch<
264 typename FiniteElementInterfaceSwitch<
265 typename LFS::ChildType::Traits::FiniteElement
269 dune_static_assert(BasisSwitch::dimRange == 1,
270 "Automatic conversion to vector-valued function only supported for scalar components");
274 typename LFS::Traits::GridView,
275 typename BasisSwitch::RangeField,
278 typename BasisSwitch::RangeField,
282 DGFTreeVectorFunction<LFS,Data>
289 typedef typename ChildLFS::Traits::FiniteElement::Traits::LocalBasisType::Traits::RangeFieldType
RF;
290 typedef typename ChildLFS::Traits::FiniteElement::Traits::LocalBasisType::Traits::RangeType
RT;
296 , _basis(lfs.maxSize())
300 const typename Traits::DomainType& x,
301 typename Traits::RangeType& y)
const
305 typedef FiniteElementInterfaceSwitch<
306 typename ChildLFS::Traits::FiniteElement
311 for (std::size_t k = 0; k < LFS::CHILDREN; ++k)
313 const ChildLFS& child_lfs = _lfs.child(k);
314 FESwitch::basis(child_lfs.finiteElement()).evaluateFunction(x,_basis);
316 for (std::size_t i = 0; i < child_lfs.size(); ++i)
317 y[k] += _data->_x_local(child_lfs,i) * _basis[i];
322 const typename Traits::GridViewType&
gridView()
const
324 return _lfs.gridFunctionSpace().gridView();
335 const shared_ptr<Data> _data;
336 mutable std::vector<typename BasisSwitch::Range> _basis;
346 template<
typename TreePath>
347 std::string
operator()(std::string component_name, TreePath tp)
const
349 if (component_name.empty())
352 if (_prefix.empty() && _suffix.empty())
355 "You need to either name all GridFunctionSpaces "
356 "written to the VTK file or provide a prefix / suffix.");
359 std::stringstream name_stream;
361 if (!_prefix.empty())
362 name_stream << _prefix << _separator;
365 for (std::size_t i = 0; i < tp.size(); ++i)
366 name_stream << (i > 0 ? _separator :
"") << tp.element(i);
368 if (!_suffix.empty())
369 name_stream << _separator << _suffix;
370 return name_stream.str();
375 return _prefix + component_name + _suffix;
409 std::string _separator;
419 template<
typename VTKWriter,
typename Data,
typename NameGenerator>
421 :
public TypeTree::DefaultVisitor
422 ,
public TypeTree::DynamicTraversal
426 template<
typename LFS,
typename Child,
typename TreePath>
433 typename LFS::Traits::GridFunctionSpace::ImplementationTag,
441 template<
typename DGF,
typename TreePath>
444 std::string name =
name_generator(dgf->localFunctionSpace().gridFunctionSpace().name(),tp);
445 switch (dgf->dataSetType())
447 case DGF::Output::vertexData:
450 case DGF::Output::cellData:
454 DUNE_THROW(NotImplemented,
"Unsupported data set type");
462 template<
typename LFS,
typename TreePath>
472 template<
typename LFS,
typename TreePath,
typename Tag>
489 template<
typename LFS,
typename TreePath>
492 typename LFS::Traits::GridFunctionSpace::Traits::GridView,
493 typename vtk_writer_traits<VTKWriter>::GridView
496 post(
const LFS& lfs, TreePath tp)
501 template<
typename LFS,
typename TreePath>
504 typename LFS::Traits::GridFunctionSpace::Traits::GridView,
505 typename vtk_writer_traits<VTKWriter>::GridView
508 leaf(
const LFS& lfs, TreePath tp)
513 template<
typename LFS,
typename TreePath>
516 typename LFS::Traits::GridFunctionSpace::Traits::GridView,
517 typename vtk_writer_traits<VTKWriter>::GridView
520 post(
const LFS& lfs, TreePath tp)
527 template<
typename LFS,
typename TreePath>
530 typename LFS::Traits::GridFunctionSpace::Traits::GridView,
531 typename vtk_writer_traits<VTKWriter>::GridView
534 leaf(
const LFS& lfs, TreePath tp)
564 template<
typename VTKWriter,
typename Data_>
565 struct OutputCollector
571 typedef typename Data::GridFunctionSpace
GFS;
575 template<
typename NameGenerator>
580 TypeTree::applyToTree(
_data->_lfs,visitor);
584 template<
typename Factory,
typename TreePath>
587 typedef typename TypeTree::extract_child_type<typename Data::LFS,TreePath>::type LFS;
588 typedef typename Factory::template create_type<LFS,Data>::type DGF;
593 template<
typename Factory,
typename TreePath>
596 typedef typename TypeTree::extract_child_type<typename Data::LFS,TreePath>::type LFS;
597 typedef typename Factory::template create_type<LFS,Data>::type DGF;
629 const Predicate& predicate = Predicate())
641 #endif // DUNE_PDELAB_GRIDFUNCTIONSPACE_VTK_HH
OutputCollector(VTKWriter &vtk_writer, const shared_ptr< Data > &data, const Predicate &predicate=Predicate())
Definition: vtk.hh:602
DefaultFunctionNameGenerator(std::string prefix="", std::string suffix="", std::string separator="_")
Definition: vtk.hh:397
const LFS & localFunctionSpace() const
Definition: vtk.hh:327
XView _x_view
Definition: vtk.hh:140
Data::GridFunctionSpace GFS
Definition: vtk.hh:571
enable_if< is_same< typename LFS::Traits::GridFunctionSpace::Traits::GridView, typename vtk_writer_traits< VTKWriter >::GridView >::value >::type leaf(const LFS &lfs, TreePath tp)
Create a standard leaf function for leaf GridFunctionSpaces.
Definition: vtk.hh:534
ChildLFS::Traits::FiniteElement::Traits::LocalBasisType::Traits::RangeFieldType RF
Definition: vtk.hh:289
ChildLFS::Traits::FiniteElement::Traits::LocalBasisType::Traits::RangeType RT
Definition: vtk.hh:290
OutputCollector & addCellFunction(Factory factory, TreePath tp, std::string name)
Definition: vtk.hh:585
const NameGenerator & name_generator
Definition: vtk.hh:550
const Traits::GridViewType & gridView() const
get a reference to the GridView
Definition: vtk.hh:219
X Vector
Definition: vtk.hh:110
void update()
Definition: lfsindexcache.hh:300
void add_vector_solution(const LFS &lfs, TreePath tp, VectorGridFunctionSpaceTag tag)
Tag dispatch-based switch that creates a vector-valued function for a VectorGridFunctionSpace.
Definition: vtk.hh:463
static const bool value
Definition: vtk.hh:430
Output::DataSetType dataSetType() const
Return the data set type of this function.
Definition: function.hh:153
DefaultFunctionNameGenerator & prefix(std::string prefix)
Definition: vtk.hh:379
void evaluate(const typename Traits::ElementType &e, const typename Traits::DomainType &x, typename Traits::RangeType &y) const
Definition: vtk.hh:201
DGFTreeLeafFunction(const LFS &lfs, const shared_ptr< Data > &data)
Definition: vtk.hh:193
shared_ptr< Data > _data
Definition: vtk.hh:609
GFS GridFunctionSpace
Definition: vtk.hh:109
LFS _lfs
Definition: vtk.hh:138
add_solution_to_vtk_writer_visitor(VTKWriter &vtk_writer_, shared_ptr< Data > data_, const NameGenerator &name_generator_, const typename Data::Predicate &predicate_)
Definition: vtk.hh:541
static const int dim
Definition: adaptivity.hh:82
Data::Predicate predicate
Definition: vtk.hh:551
VTKWriter & _vtk_writer
Definition: vtk.hh:608
void add_to_vtk_writer(const shared_ptr< DGF > &dgf, TreePath tp)
Definition: vtk.hh:442
Data::Vector Vector
Definition: vtk.hh:572
Pred Predicate
Definition: vtk.hh:111
const Traits::GridViewType & gridView() const
get a reference to the GridView
Definition: vtk.hh:322
BaseT::Traits Traits
Definition: vtk.hh:191
size_type _current_cell_index
Definition: vtk.hh:143
LFS::ChildType ChildLFS
Definition: vtk.hh:288
DefaultFunctionNameGenerator & suffix(std::string suffix)
Definition: vtk.hh:385
DGFTreeVectorFunction(const LFS &lfs, const shared_ptr< Data > &data)
Definition: vtk.hh:292
Predicate _predicate
Definition: vtk.hh:610
a GridFunction maps x in DomainType to y in RangeType
Definition: function.hh:187
OutputCollector & addSolution(const NameGenerator &name_generator)
Definition: vtk.hh:576
DGFTreeCommonData(const GFS &gfs, const X &x)
Definition: vtk.hh:113
vtk::OutputCollector< VTKWriter, vtk::DGFTreeCommonData< GFS, X, Predicate > > addSolutionToVTKWriter(VTKWriter &vtk_writer, const GFS &gfs, const X &x, const NameGenerator &name_generator=vtk::defaultNameScheme(), const Predicate &predicate=Predicate())
Definition: vtk.hh:625
BaseT::Traits Traits
Definition: vtk.hh:287
XLocalVector _x_local
Definition: vtk.hh:141
enable_if< !is_same< typename LFS::Traits::GridFunctionSpace::Traits::GridView, typename vtk_writer_traits< VTKWriter >::GridView >::value >::type post(const LFS &lfs, TreePath tp)
Definition: vtk.hh:496
static const unsigned int value
Definition: gridfunctionspace/tags.hh:175
Definition: gridfunctionspace/tags.hh:24
VTKWriter & vtk_writer
Definition: vtk.hh:548
DefaultFunctionNameGenerator defaultNameScheme()
Definition: vtk.hh:413
shared_ptr< Data > data
Definition: vtk.hh:549
void add_vector_solution(const LFS &lfs, TreePath tp, Tag tag)
Tag dispatch-based switch that creates a vector-valued function for a VectorGridFunctionSpace.
Definition: vtk.hh:473
traits class holding the function signature, same as in local function
Definition: function.hh:176
size_type map(const Element &e) const
Return the index of the given element.
Definition: elementmapper.hh:157
DefaultFunctionNameGenerator & separator(std::string separator)
Definition: vtk.hh:391
LFSCache _lfs_cache
Definition: vtk.hh:139
T Traits
Export type traits.
Definition: function.hh:192
void bind(const Cell &cell)
Definition: vtk.hh:124
Data_ Data
Common data container (hierarchic LFS, global solution data etc.)
Definition: vtk.hh:569
wrap a GridFunction so it can be used with the VTKWriter from dune-grid.
Definition: common/vtkexport.hh:22
enable_if< is_same< typename LFS::Traits::GridFunctionSpace::Traits::GridView, typename vtk_writer_traits< VTKWriter >::GridView >::value >::type post(const LFS &lfs, TreePath tp)
Handle VectorGridFunctionSpace components in here.
Definition: vtk.hh:520
void evaluate(const typename Traits::ElementType &e, const typename Traits::DomainType &x, typename Traits::RangeType &y) const
Definition: vtk.hh:299
Data::Predicate Predicate
Definition: vtk.hh:573
OutputCollector & addVertexFunction(Factory factory, TreePath tp, std::string name)
Definition: vtk.hh:594
bool operator()(const T &t) const
Definition: vtk.hh:558
ElementMapper< typename GFS::Traits::GridView > _element_mapper
Definition: vtk.hh:142
const E & e
Definition: interpolate.hh:172
std::string operator()(std::string component_name, TreePath tp) const
Definition: vtk.hh:347
enable_if< !is_same< typename LFS::Traits::GridFunctionSpace::Traits::GridView, typename vtk_writer_traits< VTKWriter >::GridView >::value >::type leaf(const LFS &lfs, TreePath tp)
Definition: vtk.hh:508
const LFS & localFunctionSpace() const
Definition: vtk.hh:224
Helper class for common data of a DGFTree.
Definition: vtk.hh:85