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> 40 template<
typename VTKWriter>
41 struct vtk_writer_traits;
44 struct vtk_writer_traits<Dune::
VTKWriter<GV> >
63 template<
typename LFS,
typename Data>
66 template<
typename LFS,
typename Data>
69 template<
typename VTKWriter,
typename Data>
74 template<
typename GFS,
typename X,
typename Pred>
78 template<
typename LFS,
typename Data>
81 template<
typename LFS,
typename Data>
84 template<
typename,
typename>
89 typedef typename X::template ConstLocalView<LFSCache> XView;
91 using EntitySet =
typename GFS::Traits::EntitySet;
92 using Cell =
typename EntitySet::Traits::Element;
93 using IndexSet =
typename EntitySet::Traits::IndexSet;
94 typedef typename IndexSet::IndexType size_type;
96 static const auto dim = EntitySet::dimension;
108 , _x_local(_lfs.maxSize())
109 , _index_set(gfs.entitySet().indexSet())
110 , _current_cell_index(
std::numeric_limits<size_type>::max())
117 auto cell_index = _index_set.uniqueIndex(cell);
118 if (_current_cell_index == cell_index)
123 _x_view.bind(_lfs_cache);
124 _x_view.read(_x_local);
126 _current_cell_index = cell_index;
140 template<
typename LFS,
typename Data>
142 :
public TypeTree::LeafNode
144 typename LFS::Traits::GridView,
145 typename BasisInterfaceSwitch<
146 typename FiniteElementInterfaceSwitch<
147 typename LFS::Traits::FiniteElement
150 BasisInterfaceSwitch<
151 typename FiniteElementInterfaceSwitch<
152 typename LFS::Traits::FiniteElement
155 typename BasisInterfaceSwitch<
156 typename FiniteElementInterfaceSwitch<
157 typename LFS::Traits::FiniteElement
161 DGFTreeLeafFunction<LFS,Data>
165 typedef BasisInterfaceSwitch<
166 typename FiniteElementInterfaceSwitch<
167 typename LFS::Traits::FiniteElement
173 typename LFS::Traits::GridView,
174 typename BasisSwitch::RangeField,
175 BasisSwitch::dimRange,
176 typename BasisSwitch::Range
185 : BaseT(lfs.gridFunctionSpace().dataSetType())
188 , _basis(lfs.maxSize())
193 const typename Traits::DomainType& x,
194 typename Traits::RangeType& y)
const 198 typedef FiniteElementInterfaceSwitch<
199 typename LFS::Traits::FiniteElement
204 FESwitch::basis(_lfs.finiteElement()).evaluateFunction(x,_basis);
205 for (std::size_t i = 0; i < _lfs.size(); ++i)
206 y.axpy(_data->_x_local(_lfs,i),_basis[i]);
210 const typename Traits::GridViewType&
gridView()
const 212 return _lfs.gridFunctionSpace().gridView();
223 const shared_ptr<Data> _data;
224 mutable std::vector<typename Traits::RangeType> _basis;
230 template<
typename LFS,
typename Data>
232 :
public TypeTree::LeafNode
234 typename LFS::Traits::GridView,
235 typename BasisInterfaceSwitch<
236 typename FiniteElementInterfaceSwitch<
237 typename LFS::ChildType::Traits::FiniteElement
240 TypeTree::StaticDegree<LFS>::value,
242 typename BasisInterfaceSwitch<
243 typename FiniteElementInterfaceSwitch<
244 typename LFS::ChildType::Traits::FiniteElement
247 TypeTree::StaticDegree<LFS>::value
250 DGFTreeVectorFunction<LFS,Data>
254 typedef BasisInterfaceSwitch<
255 typename FiniteElementInterfaceSwitch<
256 typename LFS::ChildType::Traits::FiniteElement
260 static_assert(BasisSwitch::dimRange == 1,
261 "Automatic conversion to vector-valued function only supported for scalar components");
265 typename LFS::Traits::GridView,
266 typename BasisSwitch::RangeField,
269 typename BasisSwitch::RangeField,
270 TypeTree::StaticDegree<LFS>::value
280 typedef typename ChildLFS::Traits::FiniteElement::Traits::LocalBasisType::Traits::RangeFieldType
RF;
281 typedef typename ChildLFS::Traits::FiniteElement::Traits::LocalBasisType::Traits::RangeType
RT;
284 : BaseT(lfs.gridFunctionSpace().dataSetType())
287 , _basis(lfs.maxSize())
291 const typename Traits::DomainType& x,
292 typename Traits::RangeType& y)
const 296 typedef FiniteElementInterfaceSwitch<
297 typename ChildLFS::Traits::FiniteElement
302 for (std::size_t k = 0; k < TypeTree::degree(_lfs); ++k)
304 const ChildLFS& child_lfs = _lfs.child(k);
305 FESwitch::basis(child_lfs.finiteElement()).evaluateFunction(x,_basis);
307 for (std::size_t i = 0; i < child_lfs.size(); ++i)
308 y[k] += _data->_x_local(child_lfs,i) * _basis[i];
313 const typename Traits::GridViewType&
gridView()
const 315 return _lfs.gridFunctionSpace().gridView();
326 const shared_ptr<Data> _data;
327 mutable std::vector<typename BasisSwitch::Range> _basis;
337 template<
typename TreePath>
338 std::string
operator()(std::string component_name, TreePath tp)
const 340 if (component_name.empty())
343 if (_prefix.empty() && _suffix.empty())
346 "You need to either name all GridFunctionSpaces " 347 "written to the VTK file or provide a prefix / suffix.");
350 std::stringstream name_stream;
352 if (!_prefix.empty())
353 name_stream << _prefix << _separator;
356 for (std::size_t i = 0; i < tp.size(); ++i)
357 name_stream << (i > 0 ? _separator :
"") << tp.element(i);
359 if (!_suffix.empty())
360 name_stream << _separator << _suffix;
361 return name_stream.str();
366 return _prefix + component_name + _suffix;
384 _separator = separator;
389 std::string suffix =
"",
390 std::string separator =
"_")
393 , _separator(separator)
400 std::string _separator;
410 template<
typename VTKWriter,
typename Data,
typename NameGenerator>
412 :
public TypeTree::DefaultVisitor
413 ,
public TypeTree::DynamicTraversal
417 template<
typename LFS,
typename Child,
typename TreePath>
423 !std::is_convertible<
424 TypeTree::ImplementationTag<typename LFS::Traits::GridFunctionSpace>,
432 template<
typename DGF,
typename TreePath>
435 std::string name = name_generator(dgf->localFunctionSpace().gridFunctionSpace().name(),tp);
436 switch (dgf->dataSetType())
438 case DGF::Output::vertexData:
441 case DGF::Output::cellData:
445 DUNE_THROW(NotImplemented,
"Unsupported data set type");
453 template<
typename LFS,
typename TreePath>
463 template<
typename LFS,
typename TreePath>
480 template<
typename LFS,
typename TreePath>
481 typename std::enable_if<
483 typename LFS::Traits::GridFunctionSpace::Traits::GridView,
484 typename vtk_writer_traits<VTKWriter>::GridView
487 post(
const LFS& lfs, TreePath tp)
492 template<
typename LFS,
typename TreePath>
493 typename std::enable_if<
495 typename LFS::Traits::GridFunctionSpace::Traits::GridView,
496 typename vtk_writer_traits<VTKWriter>::GridView
499 leaf(
const LFS& lfs, TreePath tp)
504 template<
typename LFS,
typename TreePath>
505 typename std::enable_if<
507 typename LFS::Traits::GridFunctionSpace::Traits::GridView,
508 typename vtk_writer_traits<VTKWriter>::GridView
511 post(
const LFS& lfs, TreePath tp)
513 if (predicate(lfs, tp))
514 add_vector_solution(lfs,tp,TypeTree::ImplementationTag<typename LFS::Traits::GridFunctionSpace>());
518 template<
typename LFS,
typename TreePath>
519 typename std::enable_if<
521 typename LFS::Traits::GridFunctionSpace::Traits::GridView,
522 typename vtk_writer_traits<VTKWriter>::GridView
525 leaf(
const LFS& lfs, TreePath tp)
527 if (predicate(lfs, tp))
533 : vtk_writer(vtk_writer_)
535 , name_generator(name_generator_)
536 , predicate(predicate_)
548 template<
typename LFS,
typename TP>
555 template<
typename VTKWriter,
typename Data_>
562 typedef typename Data::GridFunctionSpace
GFS;
566 template<
typename NameGenerator>
571 TypeTree::applyToTree(_data->_lfs,visitor);
575 template<
typename Factory,
typename TreePath>
578 typedef typename std::remove_reference<decltype(*factory.create(_data->_lfs.child(tp),_data))>::type DGF;
583 template<
template<
typename...>
class Function,
typename TreePath,
typename... Params>
586 using LFS = TypeTree::ChildForTreePath<typename Data::LFS,TreePath>;
587 typedef Function<LFS,Data,Params...> DGF;
588 _vtk_writer.addCellData(
590 std::make_shared<DGF>(
591 TypeTree::child(_data->_lfs,tp)
594 std::forward<Params>(params)...
601 template<
typename Factory,
typename TreePath>
604 typedef typename std::remove_reference<decltype(*factory.create(_data->_lfs.child(tp),_data))>::type DGF;
609 template<
template<
typename...>
class Function,
typename TreePath,
typename... Params>
612 using LFS = TypeTree::ChildForTreePath<typename Data::LFS,TreePath>;
613 typedef Function<LFS,Data,Params...> DGF;
614 _vtk_writer.addVertexData(
616 std::make_shared<DGF>(
617 TypeTree::child(_data->_lfs,tp)
620 std::forward<Params>(params)...
628 : _vtk_writer(vtk_writer)
630 , _predicate(predicate)
654 const Predicate& predicate = Predicate())
666 #endif // DUNE_PDELAB_GRIDFUNCTIONSPACE_VTK_HH OutputCollector(VTKWriter &vtk_writer, const shared_ptr< Data > &data, const Predicate &predicate=Predicate())
Definition: vtk.hh:627
DefaultFunctionNameGenerator(std::string prefix="", std::string suffix="", std::string separator="_")
Definition: vtk.hh:388
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:532
static const int dim
Definition: adaptivity.hh:83
Data::Vector Vector
Definition: vtk.hh:563
size_type _current_cell_index
Definition: vtk.hh:134
void evaluate(const typename Traits::ElementType &e, const typename Traits::DomainType &x, typename Traits::RangeType &y) const
Definition: vtk.hh:192
OutputCollector & addCellFunction(TreePath tp, std::string name, Params &&... params)
Definition: vtk.hh:584
typename impl::BackendVectorSelector< GridFunctionSpace, FieldType >::Type Vector
alias of the return type of BackendVectorSelector
Definition: backend/interface.hh:106
const Traits::GridViewType & gridView() const
get a reference to the GridView
Definition: vtk.hh:313
ChildLFS::Traits::FiniteElement::Traits::LocalBasisType::Traits::RangeType RT
Definition: vtk.hh:281
const LFS & localFunctionSpace() const
Definition: vtk.hh:215
void add_to_vtk_writer(const shared_ptr< DGF > &dgf, TreePath tp)
Definition: vtk.hh:433
Helper class for common data of a DGFTree.
Definition: vtk.hh:75
DefaultFunctionNameGenerator defaultNameScheme()
Definition: vtk.hh:404
Data::GridFunctionSpace GFS
Definition: vtk.hh:562
const IndexSet & _index_set
Definition: vtk.hh:133
DGFTreeCommonData(const GFS &gfs, const X &x)
Definition: vtk.hh:104
LFS::ChildType ChildLFS
Definition: vtk.hh:279
BaseT::Traits Traits
Definition: vtk.hh:182
std::string operator()(std::string component_name, TreePath tp) const
Definition: vtk.hh:338
Pred Predicate
Definition: vtk.hh:102
traits class holding the function signature, same as in local function
Definition: function.hh:175
void evaluate(const typename Traits::ElementType &e, const typename Traits::DomainType &x, typename Traits::RangeType &y) const
Definition: vtk.hh:290
X Vector
Definition: vtk.hh:101
XLocalVector _x_local
Definition: vtk.hh:132
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:650
For backward compatibility – Do not use this!
Definition: adaptivity.hh:27
DGFTreeVectorFunction(const LFS &lfs, const shared_ptr< Data > &data)
Definition: vtk.hh:283
ChildLFS::Traits::FiniteElement::Traits::LocalBasisType::Traits::RangeFieldType RF
Definition: vtk.hh:280
OutputCollector & addSolution(const NameGenerator &name_generator)
Definition: vtk.hh:567
VTKWriter & _vtk_writer
Definition: vtk.hh:633
GFS GridFunctionSpace
Definition: vtk.hh:100
LFS _lfs
Definition: vtk.hh:129
Data::Predicate predicate
Definition: vtk.hh:542
wrap a GridFunction so it can be used with the VTKWriter from dune-grid.
Definition: vtkexport.hh:22
DefaultFunctionNameGenerator & suffix(std::string suffix)
Definition: vtk.hh:376
Predicate _predicate
Definition: vtk.hh:635
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:499
LFSCache _lfs_cache
Definition: vtk.hh:130
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:525
const Entity & e
Definition: localfunctionspace.hh:111
static const unsigned int value
Definition: gridfunctionspace/tags.hh:139
OutputCollector & addCellFunction(Factory factory, TreePath tp, std::string name)
Definition: vtk.hh:576
const LFS & localFunctionSpace() const
Definition: vtk.hh:318
Definition: gridfunctionspace/tags.hh:24
T Traits
Export type traits.
Definition: function.hh:191
BaseT::Traits Traits
Definition: vtk.hh:278
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:487
a GridFunction maps x in DomainType to y in RangeType
Definition: function.hh:186
OutputCollector & addVertexFunction(TreePath tp, std::string name, Params &&... params)
Definition: vtk.hh:610
void bind(const Cell &cell)
Definition: vtk.hh:115
Definition: gridfunctionspace/tags.hh:28
OutputCollector & addVertexFunction(Factory factory, TreePath tp, std::string name)
Definition: vtk.hh:602
VTKWriter & vtk_writer
Definition: vtk.hh:539
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:464
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:454
shared_ptr< Data > _data
Definition: vtk.hh:634
shared_ptr< Data > data
Definition: vtk.hh:540
const Traits::GridViewType & gridView() const
get a reference to the GridView
Definition: vtk.hh:210
bool operator()(const LFS &lfs, TP tp) const
Definition: vtk.hh:549
const NameGenerator & name_generator
Definition: vtk.hh:541
DefaultFunctionNameGenerator & prefix(std::string prefix)
Definition: vtk.hh:370
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:511
DGFTreeLeafFunction(const LFS &lfs, const shared_ptr< Data > &data)
Definition: vtk.hh:184
XView _x_view
Definition: vtk.hh:131
Data::Predicate Predicate
Definition: vtk.hh:564
Data_ Data
Common data container (hierarchic LFS, global solution data etc.)
Definition: vtk.hh:560
DefaultFunctionNameGenerator & separator(std::string separator)
Definition: vtk.hh:382