/usr/include/dune/grid/io/file/vtk/function.hh is in libdune-grid-dev 2.2.1-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 | // -*- tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
// vi: set et ts=8 sw=2 sts=2:
#ifndef DUNE_GRID_IO_FILE_VTK_FUNCTION_HH
#define DUNE_GRID_IO_FILE_VTK_FUNCTION_HH
#include <string>
#include <dune/common/exceptions.hh>
#include <dune/common/fvector.hh>
#include <dune/geometry/type.hh>
#include <dune/geometry/referenceelements.hh>
#include <dune/grid/common/mcmgmapper.hh>
/** @file
@author Peter Bastian, Christian Engwer
@brief Functions for VTK output
*/
namespace Dune
{
//! \addtogroup VTK
//! \{
//////////////////////////////////////////////////////////////////////
//
// Base VTKFunction
//
/** \brief A base class for grid functions with any return type and dimension
Trick : use double as return type
*/
template< class GridView >
class VTKFunction
{
public:
typedef typename GridView::ctype ctype;
enum { dim = GridView::dimension };
typedef typename GridView::template Codim< 0 >::Entity Entity;
//! return number of components (1 for scalar valued functions, 3 for
//! vector valued function in 3D etc.)
virtual int ncomps () const = 0;
//! evaluate single component comp in the entity e at local coordinates xi
/*! Evaluate the function in an entity at local coordinates.
@param[in] comp number of component to be evaluated
@param[in] e reference to grid entity of codimension 0
@param[in] xi point in local coordinates of the reference element
of e
\return value of the component
*/
virtual double evaluate (int comp, const Entity& e,
const Dune::FieldVector<ctype,dim>& xi) const = 0;
//! get name
virtual std::string name () const = 0;
//! virtual destructor
virtual ~VTKFunction () {}
};
//////////////////////////////////////////////////////////////////////
//
// P0VTKFunction
//
//! Take a vector and interpret it as cell data for the VTKWriter
/**
* This class turns a generic vector containing cell data into a
* VTKFunction. The vector must allow read access to the data via
* operator[]() and store the data in the order given by
* MultipleCodimMultipleGeomTypeMapper with a layout class that allows only
* elements. Also, it must support the method size().
*
* While the number of components of the function is always 1, the vector
* may represent a field with multiple components of which one may be
* selected.
*
* \tparam GV Type of GridView the vector applies to.
* \tparam V Type of vector.
*/
template<typename GV, typename V>
class P0VTKFunction
: public VTKFunction< GV >
{
//! Base class
typedef VTKFunction< GV > Base;
//! Mapper for elements
typedef MultipleCodimMultipleGeomTypeMapper<GV, MCMGElementLayout> Mapper;
//! store a reference to the vector
const V& v;
//! name of this function
std::string s;
//! number of components of the field stored in the vector
int ncomps_;
//! index of the component of the field in the vector this function is
//! responsible for
int mycomp_;
//! mapper used to map elements to indices
Mapper mapper;
public:
typedef typename Base::Entity Entity;
typedef typename Base::ctype ctype;
using Base::dim;
//! return number of components
virtual int ncomps () const
{
return 1;
}
//! evaluate
virtual double evaluate (int comp, const Entity& e,
const Dune::FieldVector<ctype,dim>& xi) const
{
return v[mapper.map(e)*ncomps_+mycomp_];
}
//! get name
virtual std::string name () const
{
return s;
}
//! construct from a vector and a name
/**
* \param gv GridView to operate on (used to instantiate a
* MultipleCodimMultipleGeomeTypeMapper, otherwise no
* reference or copy is stored). Note that this must be the
* GridView the vector applies to as well as the GridView
* later used by the VTKWriter -- i.e. we do not implicitly
* restrict or prolongate the data.
* \param v_ Reference to the vector holding the data. The reference
* is stored internally and must be valid for as long as
* this functions evaluate method is used.
* \param s_ Name of this function in the VTK file.
* \param ncomps Number of components of the field represented by the
* vector.
* \param mycomp Number of the field component this function is
* responsible for.
*/
P0VTKFunction(const GV &gv, const V &v_, const std::string &s_,
int ncomps=1, int mycomp=0 )
: v( v_ ),
s( s_ ),
ncomps_(ncomps),
mycomp_(mycomp),
mapper( gv )
{
if (v.size()!=(unsigned int)(mapper.size()*ncomps_))
DUNE_THROW(IOError, "P0VTKFunction: size mismatch");
}
//! destructor
virtual ~P0VTKFunction() {}
};
//////////////////////////////////////////////////////////////////////
//
// P1VTKFunction
//
//! Take a vector and interpret it as point data for the VTKWriter
/**
* This class turns a generic vector containing point data into a
* VTKFunction. The vector must allow read access to the data via
* operator[]() and store the data in the order given by
* MultipleCodimMultipleGeomTypeMapper with a layout class that allows only
* vertices. Also, it must support the method size().
*
* While the number of components of the function is always 1, the vector
* may represent a field with multiple components of which one may be
* selected.
*
* \note While this function may be evaluated anywhere on a given grid
* element, it does not interpolate between the corners of the element
* -- instead, it returns the value at the nearest corner (as
* determined in local coordinates).
*
* \tparam GV Type of GridView the vector applies to.
* \tparam V Type of vector.
*/
template<typename GV, typename V>
class P1VTKFunction
: public VTKFunction< GV >
{
//! Base class
typedef VTKFunction< GV > Base;
//! Mapper for vertices
typedef MultipleCodimMultipleGeomTypeMapper<GV, MCMGVertexLayout> Mapper;
//! store a reference to the vector
const V& v;
//! name of this function
std::string s;
//! number of components of the field stored in the vector
int ncomps_;
//! index of the component of the field in the vector this function is
//! responsible for
int mycomp_;
//! mapper used to map elements to indices
Mapper mapper;
public:
typedef typename Base::Entity Entity;
typedef typename Base::ctype ctype;
using Base::dim;
//! return number of components
virtual int ncomps () const
{
return 1;
}
//! evaluate
virtual double evaluate (int comp, const Entity& e,
const Dune::FieldVector<ctype,dim>& xi) const
{
double min=1E100;
int imin=-1;
Dune::GeometryType gt = e.type();
for (int i=0; i<e.template count<dim>(); ++i)
{
Dune::FieldVector<ctype,dim> local =
Dune::GenericReferenceElements<ctype,dim>::general(gt)
.position(i,dim);
local -= xi;
if (local.infinity_norm()<min)
{
min = local.infinity_norm();
imin = i;
}
}
return v[mapper.map(e,imin,dim)*ncomps_+mycomp_];
}
//! get name
virtual std::string name () const
{
return s;
}
//! construct from a vector and a name
/**
* \param gv GridView to operate on (used to instantiate a
* MultipleCodimMultipleGeomTypeMapper, otherwise no
* reference or copy is stored). Note that this must be the
* GridView the vector applies to as well as the GridView
* later used by the VTKWriter -- i.e. we do not implicitly
* restrict or prolongate the data.
* \param v_ Reference to the vector holding the data. The reference
* is stored internally and must be valid for as long as
* this functions evaluate method is used.
* \param s_ Name of this function in the VTK file.
* \param ncomps Number of components of the field represented by the
* vector.
* \param mycomp Number of the field component this function is
* responsible for.
*/
P1VTKFunction(const GV& gv, const V &v_, const std::string &s_,
int ncomps=1, int mycomp=0 )
: v( v_ ),
s( s_ ),
ncomps_(ncomps),
mycomp_(mycomp),
mapper( gv )
{
if (v.size()!=(unsigned int)(mapper.size()*ncomps_))
DUNE_THROW(IOError,"P1VTKFunction: size mismatch");
}
//! destructor
virtual ~P1VTKFunction() {}
};
//! \} group VTK
} // namespace Dune
#endif // DUNE_GRID_IO_FILE_VTK_FUNCTION_HH
|