BEM++  2.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Groups Pages
p1_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_p1_vector_vtk_function_hpp
22 #define bempp_p1_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 
52 template<typename GV, typename V>
54  : public Dune::VTKFunction<GV>
55 {
57  typedef Dune::VTKFunction<GV> Base;
59  typedef Dune::MultipleCodimMultipleGeomTypeMapper<
60  GV, Dune::MCMGVertexLayout> Mapper;
61 
63  const V& v;
65  std::string s;
67  int ncomps_;
70 
71 public:
72  typedef typename Base::Entity Entity;
73  typedef typename Base::ctype ctype;
74  using Base::dim;
75 
77  virtual int ncomps() const
78  {
79  return ncomps_;
80  }
81 
83  virtual double evaluate(int comp, const Entity& e,
84  const Dune::FieldVector<ctype, dim>& xi) const
85  {
86  double min = 1E100;
87  int imin = -1;
88  Dune::GeometryType gt = e.type();
89  for (int i = 0; i < e.template count<dim>(); ++i)
90  {
91  Dune::FieldVector<ctype,dim> local =
92  Dune::GenericReferenceElements<ctype,dim>::general(gt)
93  .position(i,dim);
94  local -= xi;
95  if (local.infinity_norm() < min)
96  {
97  min = local.infinity_norm();
98  imin = i;
99  }
100  }
101  return v[mapper.map(e, imin, dim) * ncomps_ + comp];
102  }
103 
105  virtual std::string name() const
106  {
107  return s;
108  }
109 
124  P1VectorVTKFunction(const GV& gv, const V &v_, const std::string &s_,
125  int ncomps = 1)
126  : v(v_), s(s_), ncomps_(ncomps), mapper(gv)
127  {
128  if (v.size() != (unsigned int)(mapper.size() * ncomps_))
129  DUNE_THROW(Dune::IOError, "P1VectorVTKFunction: size mismatch");
130  }
131 };
132 
133 } // namespace Bempp
134 
135 #endif
virtual std::string name() const
get name
Definition: p1_vector_vtk_function.hpp:105
Take a vector and interpret it as point data for the VTKWriter.
Definition: p1_vector_vtk_function.hpp:53
Dune::GeometryType GeometryType
Identifier of geometry type.
Definition: geometry_type.hpp:34
const V & v
store a reference to the vector
Definition: p1_vector_vtk_function.hpp:63
Mapper mapper
mapper used to map elements to indices
Definition: p1_vector_vtk_function.hpp:69
virtual int ncomps() const
return number of components
Definition: p1_vector_vtk_function.hpp:77
int ncomps_
number of components of the field stored in the vector
Definition: p1_vector_vtk_function.hpp:67
Dune::MultipleCodimMultipleGeomTypeMapper< GV, Dune::MCMGVertexLayout > Mapper
Mapper for vertices.
Definition: p1_vector_vtk_function.hpp:60
std::string s
name of this function
Definition: p1_vector_vtk_function.hpp:65
Dune::VTKFunction< GV > Base
Base class.
Definition: p1_vector_vtk_function.hpp:57
P1VectorVTKFunction(const GV &gv, const V &v_, const std::string &s_, int ncomps=1)
Construct from a vector and a name.
Definition: p1_vector_vtk_function.hpp:124
virtual double evaluate(int comp, const Entity &e, const Dune::FieldVector< ctype, dim > &xi) const
evaluate
Definition: p1_vector_vtk_function.hpp:83