1 #ifndef DUNE_PDELAB_GRIDFUNCTIONSPACE_VTK_HH
2 #define DUNE_PDELAB_GRIDFUNCTIONSPACE_VTK_HH
7 #include <dune/common/exceptions.hh>
8 #include <dune/common/shared_ptr.hh>
10 #include <dune/geometry/typeindex.hh>
12 #include <dune/localfunctions/common/interfaceswitch.hh>
14 #include <dune/typetree/visitor.hh>
15 #include <dune/typetree/traversal.hh>
41 template<
typename VTKWriter>
42 struct vtk_writer_traits;
64 template<
typename LFS,
typename Data>
67 template<
typename LFS,
typename Data>
70 template<
typename VTKWriter,
typename Data>
75 template<
typename GFS,
typename X,
typename Pred>
79 template<
typename LFS,
typename Data>
82 template<
typename LFS,
typename Data>
85 template<
typename,
typename>
90 typedef typename X::template ConstLocalView<LFSCache> XView;
92 using EntitySet =
typename GFS::Traits::EntitySet;
93 using Cell =
typename EntitySet::Traits::Element;
94 using IndexSet =
typename EntitySet::Traits::IndexSet;
95 typedef typename IndexSet::IndexType size_type;
97 static const auto dim = EntitySet::dimension;
119 auto cell_index =
_index_set.uniqueIndex(cell);
140 std::shared_ptr<const X>
x;
145 template<
typename LFS,
typename Data>
148 typename LFS::Traits::GridView,
149 typename BasisInterfaceSwitch<
150 typename FiniteElementInterfaceSwitch<
151 typename LFS::Traits::FiniteElement
154 BasisInterfaceSwitch<
155 typename FiniteElementInterfaceSwitch<
156 typename LFS::Traits::FiniteElement
159 typename BasisInterfaceSwitch<
160 typename FiniteElementInterfaceSwitch<
161 typename LFS::Traits::FiniteElement
165 DGFTreeLeafFunction<LFS,Data>
169 typedef BasisInterfaceSwitch<
170 typename FiniteElementInterfaceSwitch<
171 typename LFS::Traits::FiniteElement
177 typename LFS::Traits::GridView,
178 typename BasisSwitch::RangeField,
179 BasisSwitch::dimRange,
180 typename BasisSwitch::Range
192 , _basis(lfs.maxSize())
197 const typename Traits::DomainType& x,
198 typename Traits::RangeType& y)
const
202 typedef FiniteElementInterfaceSwitch<
203 typename LFS::Traits::FiniteElement
209 FESwitch::basis(_lfs.finiteElement()).evaluateFunction(x,_basis);
210 for (std::size_t i = 0; i < _lfs.size(); ++i)
211 y.axpy(_data->_x_local(_lfs,i),_basis[i]);
216 const typename Traits::GridViewType&
gridView()
const
218 return _lfs.gridFunctionSpace().gridView();
229 const std::shared_ptr<Data> _data;
230 mutable std::vector<typename Traits::RangeType> _basis;
236 template<
typename LFS,
typename Data>
239 typename LFS::Traits::GridView,
240 typename BasisInterfaceSwitch<
241 typename FiniteElementInterfaceSwitch<
242 typename LFS::ChildType::Traits::FiniteElement
245 TypeTree::StaticDegree<LFS>::value,
247 typename BasisInterfaceSwitch<
248 typename FiniteElementInterfaceSwitch<
249 typename LFS::ChildType::Traits::FiniteElement
252 TypeTree::StaticDegree<LFS>::value
255 DGFTreeVectorFunction<LFS,Data>
259 typedef BasisInterfaceSwitch<
260 typename FiniteElementInterfaceSwitch<
261 typename LFS::ChildType::Traits::FiniteElement
265 static_assert(BasisSwitch::dimRange == 1,
266 "Automatic conversion to vector-valued function only supported for scalar components");
270 typename LFS::Traits::GridView,
271 typename BasisSwitch::RangeField,
274 typename BasisSwitch::RangeField,
285 typedef typename ChildLFS::Traits::FiniteElement::Traits::LocalBasisType::Traits::RangeFieldType
RF;
286 typedef typename ChildLFS::Traits::FiniteElement::Traits::LocalBasisType::Traits::RangeType
RT;
292 , _basis(lfs.maxSize())
296 const typename Traits::DomainType& x,
297 typename Traits::RangeType& y)
const
301 typedef FiniteElementInterfaceSwitch<
302 typename ChildLFS::Traits::FiniteElement
307 for (std::size_t k = 0; k < TypeTree::degree(_lfs); ++k)
309 const ChildLFS& child_lfs = _lfs.child(k);
310 FESwitch::basis(child_lfs.finiteElement()).evaluateFunction(x,_basis);
312 for (std::size_t i = 0; i < child_lfs.size(); ++i)
313 y[k] += _data->_x_local(child_lfs,i) * _basis[i];
318 const typename Traits::GridViewType&
gridView()
const
320 return _lfs.gridFunctionSpace().gridView();
331 const std::shared_ptr<Data> _data;
332 mutable std::vector<typename BasisSwitch::Range> _basis;
342 template<
typename TreePath>
343 std::string
operator()(std::string component_name, TreePath tp)
const
345 if (component_name.empty())
348 if (_prefix.empty() && _suffix.empty())
351 "You need to either name all GridFunctionSpaces "
352 "written to the VTK file or provide a prefix / suffix.");
355 std::stringstream name_stream;
357 if (!_prefix.empty())
358 name_stream << _prefix << _separator;
361 for (std::size_t i = 0; i < tp.size(); ++i)
362 name_stream << (i > 0 ? _separator :
"") << tp.element(i);
364 if (!_suffix.empty())
365 name_stream << _separator << _suffix;
366 return name_stream.str();
371 return _prefix + component_name + _suffix;
405 std::string _separator;
415 template<
typename VTKWriter,
typename Data,
typename NameGenerator>
417 :
public TypeTree::DefaultVisitor
418 ,
public TypeTree::DynamicTraversal
422 template<
typename LFS,
typename Child,
typename TreePath>
428 !std::is_convertible<
429 TypeTree::ImplementationTag<typename LFS::Traits::GridFunctionSpace>,
437 template<
typename DGF,
typename TreePath>
440 std::string name =
name_generator(dgf->localFunctionSpace().gridFunctionSpace().name(),tp);
441 switch (dgf->dataSetType())
443 case DGF::Output::vertexData:
446 case DGF::Output::cellData:
450 DUNE_THROW(NotImplemented,
"Unsupported data set type");
458 template<
typename LFS,
typename TreePath>
468 template<
typename LFS,
typename TreePath>
485 template<
typename LFS,
typename TreePath>
486 typename std::enable_if<
488 typename LFS::Traits::GridFunctionSpace::Traits::GridView,
489 typename vtk_writer_traits<VTKWriter>::GridView
492 post(
const LFS& lfs, TreePath tp)
497 template<
typename LFS,
typename TreePath>
498 typename std::enable_if<
500 typename LFS::Traits::GridFunctionSpace::Traits::GridView,
501 typename vtk_writer_traits<VTKWriter>::GridView
504 leaf(
const LFS& lfs, TreePath tp)
509 template<
typename LFS,
typename TreePath>
510 typename std::enable_if<
512 typename LFS::Traits::GridFunctionSpace::Traits::GridView,
513 typename vtk_writer_traits<VTKWriter>::GridView
516 post(
const LFS& lfs, TreePath tp)
519 add_vector_solution(lfs,tp,TypeTree::ImplementationTag<typename LFS::Traits::GridFunctionSpace>());
523 template<
typename LFS,
typename TreePath>
524 typename std::enable_if<
526 typename LFS::Traits::GridFunctionSpace::Traits::GridView,
527 typename vtk_writer_traits<VTKWriter>::GridView
530 leaf(
const LFS& lfs, TreePath tp)
553 template<
typename LFS,
typename TP>
560 template<
typename VTKWriter,
typename Data_>
567 typedef typename Data::GridFunctionSpace
GFS;
571 template<
typename NameGenerator>
576 TypeTree::applyToTree(
_data->_lfs,visitor);
580 template<
typename Factory,
typename TreePath>
583 typedef typename std::remove_reference<decltype(*factory.create(
_data->_lfs.child(tp),
_data))>::type DGF;
588 template<
template<
typename...>
class Function,
typename TreePath,
typename... Params>
591 using LFS = TypeTree::ChildForTreePath<typename Data::LFS,TreePath>;
592 typedef Function<LFS,
Data,Params...> DGF;
595 std::make_shared<DGF>(
596 TypeTree::child(
_data->_lfs,tp)
599 std::forward<Params>(params)...
606 template<
typename Factory,
typename TreePath>
609 typedef typename std::remove_reference<decltype(*factory.create(
_data->_lfs.child(tp),
_data))>::type DGF;
614 template<
template<
typename...>
class Function,
typename TreePath,
typename... Params>
617 using LFS = TypeTree::ChildForTreePath<typename Data::LFS,TreePath>;
618 typedef Function<LFS,
Data,Params...> DGF;
621 std::make_shared<DGF>(
622 TypeTree::child(
_data->_lfs,tp)
625 std::forward<Params>(params)...
659 const Predicate& predicate = Predicate())
662 auto data = std::make_shared<Data>(Dune::stackobject_to_shared_ptr(gfs), Dune::stackobject_to_shared_ptr(x));
672 typename NameGenerator = vtk::DefaultFunctionNameGenerator,
673 typename Predicate = vtk::DefaultPredicate>
674 vtk::OutputCollector<
676 vtk::DGFTreeCommonData<GFS,X,Predicate>
679 std::shared_ptr<GFS> gfs,
680 std::shared_ptr<X> x,
682 const Predicate& predicate = Predicate())
static const int dim
Definition: adaptivity.hh:84
const Entity & e
Definition: localfunctionspace.hh:123
For backward compatibility – Do not use this!
Definition: adaptivity.hh:28
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:655
typename impl::BackendVectorSelector< GridFunctionSpace, FieldType >::Type Vector
alias of the return type of BackendVectorSelector
Definition: backend/interface.hh:106
DefaultFunctionNameGenerator defaultNameScheme()
Definition: vtk.hh:409
Output::DataSetType dataSetType() const
Return the data set type of this function.
Definition: function.hh:154
traits class holding the function signature, same as in local function
Definition: function.hh:183
T Traits
Export type traits.
Definition: function.hh:193
leaf of a function tree
Definition: function.hh:302
wrap a GridFunction so it can be used with the VTKWriter from dune-grid.
Definition: vtkexport.hh:25
void update()
Definition: lfsindexcache.hh:304
Definition: lfsindexcache.hh:979
Definition: gridfunctionspace/tags.hh:24
Definition: gridfunctionspace/tags.hh:28
const LFS & localFunctionSpace() const
Definition: vtk.hh:221
BaseT::Traits Traits
Definition: vtk.hh:186
DGFTreeLeafFunction(const LFS &lfs, const std::shared_ptr< Data > &data)
Definition: vtk.hh:188
void evaluate(const typename Traits::ElementType &e, const typename Traits::DomainType &x, typename Traits::RangeType &y) const
Definition: vtk.hh:196
const Traits::GridViewType & gridView() const
get a reference to the GridView
Definition: vtk.hh:216
const Traits::GridViewType & gridView() const
get a reference to the GridView
Definition: vtk.hh:318
void evaluate(const typename Traits::ElementType &e, const typename Traits::DomainType &x, typename Traits::RangeType &y) const
Definition: vtk.hh:295
ChildLFS::Traits::FiniteElement::Traits::LocalBasisType::Traits::RangeFieldType RF
Definition: vtk.hh:285
DGFTreeVectorFunction(const LFS &lfs, const std::shared_ptr< Data > &data)
Definition: vtk.hh:288
ChildLFS::Traits::FiniteElement::Traits::LocalBasisType::Traits::RangeType RT
Definition: vtk.hh:286
const LFS & localFunctionSpace() const
Definition: vtk.hh:323
BaseT::Traits Traits
Definition: vtk.hh:283
LFS::ChildType ChildLFS
Definition: vtk.hh:284
OutputCollector & addCellFunction(Factory factory, TreePath tp, std::string name)
Definition: vtk.hh:581
VTKWriter & _vtk_writer
Definition: vtk.hh:638
Predicate _predicate
Definition: vtk.hh:640
OutputCollector & addSolution(const NameGenerator &name_generator)
Definition: vtk.hh:572
Data::Predicate Predicate
Definition: vtk.hh:569
Data::GridFunctionSpace GFS
Definition: vtk.hh:567
OutputCollector & addVertexFunction(Factory factory, TreePath tp, std::string name)
Definition: vtk.hh:607
std::shared_ptr< Data > _data
Definition: vtk.hh:639
OutputCollector & addVertexFunction(TreePath tp, std::string name, Params &&... params)
Definition: vtk.hh:615
Data_ Data
Common data container (hierarchic LFS, global solution data etc.)
Definition: vtk.hh:565
OutputCollector(VTKWriter &vtk_writer, const std::shared_ptr< Data > &data, const Predicate &predicate=Predicate())
Definition: vtk.hh:632
OutputCollector & addCellFunction(TreePath tp, std::string name, Params &&... params)
Definition: vtk.hh:589
Data::Vector Vector
Definition: vtk.hh:568
Helper class for common data of a DGFTree.
Definition: vtk.hh:77
size_type _current_cell_index
Definition: vtk.hh:136
std::shared_ptr< const X > x
Definition: vtk.hh:140
void bind(const Cell &cell)
Definition: vtk.hh:117
Pred Predicate
Definition: vtk.hh:103
LFSCache _lfs_cache
Definition: vtk.hh:132
X Vector
Definition: vtk.hh:102
GFS GridFunctionSpace
Definition: vtk.hh:101
XLocalVector _x_local
Definition: vtk.hh:134
XView _x_view
Definition: vtk.hh:133
DGFTreeCommonData(std::shared_ptr< const GFS > gfs, std::shared_ptr< const X > x)
Definition: vtk.hh:105
LFS _lfs
Definition: vtk.hh:131
const IndexSet & _index_set
Definition: vtk.hh:135
DefaultFunctionNameGenerator & suffix(std::string suffix)
Definition: vtk.hh:381
DefaultFunctionNameGenerator(std::string prefix="", std::string suffix="", std::string separator="_")
Definition: vtk.hh:393
DefaultFunctionNameGenerator & separator(std::string separator)
Definition: vtk.hh:387
DefaultFunctionNameGenerator & prefix(std::string prefix)
Definition: vtk.hh:375
std::string operator()(std::string component_name, TreePath tp) const
Definition: vtk.hh:343
std::shared_ptr< Data > data
Definition: vtk.hh:545
std::enable_if< !std::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:492
std::enable_if< !std::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:504
Data::Predicate predicate
Definition: vtk.hh:547
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:459
add_solution_to_vtk_writer_visitor(VTKWriter &vtk_writer_, std::shared_ptr< Data > data_, const NameGenerator &name_generator_, const typename Data::Predicate &predicate_)
Definition: vtk.hh:537
std::enable_if< std::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:530
const NameGenerator & name_generator
Definition: vtk.hh:546
VTKWriter & vtk_writer
Definition: vtk.hh:544
void add_vector_solution(const LFS &lfs, TreePath tp, GridFunctionSpaceTag tag)
Tag dispatch-based switch that creates a vector-valued function for a VectorGridFunctionSpace.
Definition: vtk.hh:469
void add_to_vtk_writer(const std::shared_ptr< DGF > &dgf, TreePath tp)
Definition: vtk.hh:438
std::enable_if< std::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:516
static const bool value
Definition: vtk.hh:426
bool operator()(const LFS &lfs, TP tp) const
Definition: vtk.hh:554
static const unsigned int value
Definition: gridfunctionspace/tags.hh:139