BEM++  2.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Groups Pages
p0_vector_vtk_function.hpp
1 // Copyright (C) 2011-2012 by the BEM++ Authors
2 //
3 // Permission is hereby granted, free of charge, to any person obtaining a copy
4 // of this software and associated documentation files (the "Software"), to deal
5 // in the Software without restriction, including without limitation the rights
6 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7 // copies of the Software, and to permit persons to whom the Software is
8 // furnished to do so, subject to the following conditions:
9 //
10 // The above copyright notice and this permission notice shall be included in
11 // all copies or substantial portions of the Software.
12 //
13 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19 // THE SOFTWARE.
20 
21 #ifndef bempp_p0_vector_vtk_function_hpp
22 #define bempp_p0_vector_vtk_function_hpp
23 
24 #include "../common/common.hpp"
25 
26 #include <dune/grid/io/file/vtk/function.hh>
27 
28 namespace Bempp
29 {
30 
47 template<typename GV, typename V>
49  : public Dune::VTKFunction<GV>
50 {
52  typedef Dune::VTKFunction<GV> Base;
54  typedef Dune::MultipleCodimMultipleGeomTypeMapper<GV, Dune::MCMGElementLayout> Mapper;
55 
57  const V& v;
59  std::string s;
61  int ncomps_;
64 
65 public:
66  typedef typename Base::Entity Entity;
67  typedef typename Base::ctype ctype;
68  using Base::dim;
69 
71  virtual int ncomps() const
72  {
73  return ncomps_;
74  }
75 
77  virtual double evaluate(int comp, const Entity& e,
78  const Dune::FieldVector<ctype,dim>& xi) const
79  {
80  return v[mapper.map(e)*ncomps_+comp];
81  }
82 
84  virtual std::string name() const
85  {
86  return s;
87  }
88 
104  P0VectorVTKFunction(const GV &gv, const V &v_, const std::string &s_,
105  int ncomps = 1)
106  : v(v_), s(s_), ncomps_(ncomps), mapper(gv)
107  {
108  if (v.size() != (unsigned int)(mapper.size() * ncomps_))
109  DUNE_THROW(Dune::IOError, "VectorP0VTKFunction: size mismatch");
110  }
111 };
112 
113 } // namespace Bempp
114 
115 #endif
P0VectorVTKFunction(const GV &gv, const V &v_, const std::string &s_, int ncomps=1)
Construct from a vector and a name.
Definition: p0_vector_vtk_function.hpp:104
virtual int ncomps() const
return number of components
Definition: p0_vector_vtk_function.hpp:71
int ncomps_
number of components of the field stored in the vector
Definition: p0_vector_vtk_function.hpp:61
virtual std::string name() const
get name
Definition: p0_vector_vtk_function.hpp:84
Dune::VTKFunction< GV > Base
Base class.
Definition: p0_vector_vtk_function.hpp:52
virtual double evaluate(int comp, const Entity &e, const Dune::FieldVector< ctype, dim > &xi) const
evaluate
Definition: p0_vector_vtk_function.hpp:77
Dune::MultipleCodimMultipleGeomTypeMapper< GV, Dune::MCMGElementLayout > Mapper
Mapper for elements.
Definition: p0_vector_vtk_function.hpp:54
Take a vector and interpret it as cell data for the VTKWriter.
Definition: p0_vector_vtk_function.hpp:48
std::string s
name of this function
Definition: p0_vector_vtk_function.hpp:59
Mapper mapper
mapper used to map elements to indices
Definition: p0_vector_vtk_function.hpp:63
const V & v
store a reference to the vector
Definition: p0_vector_vtk_function.hpp:57