This file is indexed.

/usr/include/dune/pdelab/function/callableadapter.hh is in libdune-pdelab-dev 2.5.0~20170124g7cf9f47a-1.

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
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
// -*- tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
// vi: set et ts=8 sw=2 sts=2:

#ifndef DUNE_PDELAB_FUNCTION_CALLABLEADAPTER_HH
#define DUNE_PDELAB_FUNCTION_CALLABLEADAPTER_HH

#include <utility>
#include <type_traits>
#include <dune/common/fvector.hh>
#include <dune/common/typetraits.hh>

#include <dune/pdelab/common/function.hh>
#include <dune/pdelab/constraints/common/constraintsparameters.hh>

namespace Dune {
  namespace PDELab {

    /************************
     * Grid function adapters
     ************************/

    /** \brief Adapter for callables f(x) expecting a global coordinate x */
    template<typename GV, typename RF, int n, typename F>
    class GlobalCallableToGridFunctionAdapter
      : public Dune::PDELab::GridFunctionBase<Dune::PDELab::
                                              GridFunctionTraits<GV,RF,n,Dune::FieldVector<RF,n> >,
                                              GlobalCallableToGridFunctionAdapter<GV,RF,n,F> >
    {
      GV gv;
      F f;
    public:
      typedef Dune::PDELab::
      GridFunctionTraits<GV,RF,n,Dune::FieldVector<RF,n> > Traits;

      //! construct from grid view
      GlobalCallableToGridFunctionAdapter (const GV& gv_, const F& f_) : gv(gv_), f(f_) {}

      //! get a reference to the grid view
      inline const GV& getGridView () const {return gv;}

      //! evaluate extended function on element
      inline void evaluate (const typename Traits::ElementType& e,
                            const typename Traits::DomainType& xl,
                            typename Traits::RangeType& y) const
      {
        typename Traits::DomainType xg = e.geometry().global(xl);
        y = f(xg);
      }
    };

    template<typename T>
    struct CallableAdapterGetDim {
      enum {dim=1};
    };

    template<typename T, int n>
    struct CallableAdapterGetDim< FieldVector<T,n> > {
      enum {dim=n};
    };

    template<typename T>
    struct CallableAdapterGetRangeFieldType {
      typedef T Type;
    };

    template<typename T, int n>
    struct CallableAdapterGetRangeFieldType< FieldVector<T,n> > {
      typedef T Type;
    };


    /** \brief Adapter for callables f(e,x) expecting an entity e and a global coordinate x */
    template<typename GV, typename RF, int n, typename F>
    class LocalCallableToGridFunctionAdapter
      : public Dune::PDELab::GridFunctionBase<Dune::PDELab::
                                              GridFunctionTraits<GV,RF,n,Dune::FieldVector<RF,n> >,
                                              LocalCallableToGridFunctionAdapter<GV,RF,n,F> >
    {
      GV gv;
      F f;
    public:
      typedef Dune::PDELab::
      GridFunctionTraits<GV,RF,n,Dune::FieldVector<RF,n> > Traits;

      //! construct from grid view
      LocalCallableToGridFunctionAdapter (const GV& gv_, const F& f_) : gv(gv_), f(f_) {}

      //! get a reference to the grid view
      inline const GV& getGridView () {return gv;}

      //! evaluate extended function on element
      inline void evaluate (const typename Traits::ElementType& e,
                            const typename Traits::DomainType& xl,
                            typename Traits::RangeType& y) const
      {
        y = f(e,xl);
      }
    };

#ifdef DOXYGEN
    //! \brief Create a GridFunction adapter from a callable
    /**
     * \param gv A GridView
     * \param f A callable of one of the two forms:
     *          1. f(x) taking a global coordinate x of type
     *          typename GV::template Codim<0>::Entity::Geometry::GlobalCoordinate.
     *          2. f(e,x) taking an Entity e
     *          coordinate x  or of the form f(e,x) taking an Entity e and a local
     *          coordinate x of type Entity::Geometry::LocalCoordinate.
     * \return A GlobalCallableToGridFunctionAdapter or a LocalCallableToGridFunctionAdapter.
     */
    template <typename GV, typename F>
    WrapperConformingToGridFunctionInterface makeGridFunctionFromCallable (const GV& gv, const F& f)
    {}
#endif

#ifndef DOXYGEN
    /** \brief Create PDELab GridFunction from a callable f(x) that expects a global coordinate x */
    template <typename GV, typename F>
    auto makeGridFunctionFromCallable (const GV& gv, const F& f)
      -> typename std::enable_if<
        AlwaysTrue <
          decltype(f(std::declval<typename GV::template Codim<0>::Entity::Geometry::GlobalCoordinate>()))
          >::value,
        GlobalCallableToGridFunctionAdapter<
          GV,
          typename CallableAdapterGetRangeFieldType<
            decltype(f(std::declval<typename GV::template Codim<0>::Entity::Geometry::GlobalCoordinate>()))
            >::Type,
          CallableAdapterGetDim<
            decltype(f(std::declval<typename GV::template Codim<0>::Entity::Geometry::GlobalCoordinate>()))
            >::dim,
          F>
        >::type
    {
      typedef typename GV::template Codim<0>::Entity::Geometry::GlobalCoordinate X;
      X x;
      typedef decltype(f(x)) ReturnType;
      typedef typename CallableAdapterGetRangeFieldType<ReturnType>::Type RF;
      const int dim = CallableAdapterGetDim<ReturnType>::dim;
      typedef GlobalCallableToGridFunctionAdapter<GV,RF,dim,F> TheType;
      return TheType(gv,f);
    }

    /** \brief Create PDELab GridFunction from a callable f(e,x) that expects
        an entity e and a local coordinate x */
    template <typename GV, typename F>
    auto makeGridFunctionFromCallable (const GV& gv, const F& f)
      -> typename std::enable_if<
        AlwaysTrue <
          decltype(f(
                     std::declval<typename GV::template Codim<0>::Entity>(),
                     std::declval<typename GV::template Codim<0>::Entity::Geometry::LocalCoordinate>()
                     ))
          >::value,
        LocalCallableToGridFunctionAdapter<
          GV,
          typename CallableAdapterGetRangeFieldType<
            decltype(f(
                       std::declval<typename GV::template Codim<0>::Entity>(),
                       std::declval<typename GV::template Codim<0>::Entity::Geometry::LocalCoordinate>()
                       ))
            >::Type,
          CallableAdapterGetDim<
            decltype(f(
                       std::declval<typename GV::template Codim<0>::Entity>(),
                       std::declval<typename GV::template Codim<0>::Entity::Geometry::LocalCoordinate>()
                       ))
            >::dim,
          F>
        >::type
    {
      typedef typename GV::template Codim<0>::Entity E;
      E e;
      typedef typename E::Geometry::LocalCoordinate X;
      X x;
      typedef decltype(f(e,x)) ReturnType;
      typedef typename CallableAdapterGetRangeFieldType<ReturnType>::Type RF;
      const int dim = CallableAdapterGetDim<ReturnType>::dim;
      typedef LocalCallableToGridFunctionAdapter<GV,RF,dim,F> TheType;
      return TheType(gv,f);
    }
#endif // DOXYGEN


    /*************************************
     * Instationary grid function adapters
     *************************************/


    /** \brief return a PDELab GridFunction (with setTime method) defined by a parameter class and a callable f(x)
        global coordinates x */
    template<typename GV, typename RF, int n, typename F, typename P>
    class GlobalCallableToInstationaryGridFunctionAdapter
      : public Dune::PDELab::GridFunctionBase<Dune::PDELab::
                                              GridFunctionTraits<GV,RF,n,Dune::FieldVector<RF,n> >,
                                              GlobalCallableToInstationaryGridFunctionAdapter<GV,RF,n,F,P> >
    {
      GV gv;
      F f;
      P& p;
    public:
      typedef Dune::PDELab::
      GridFunctionTraits<GV,RF,n,Dune::FieldVector<RF,n> > Traits;

      //! construct from grid view
      GlobalCallableToInstationaryGridFunctionAdapter (const GV& gv_, const F& f_, P& p_)
        : gv(gv_), f(f_), p(p_)
      {}

      //! get a reference to the grid view
      inline const GV& getGridView () const {return gv;}

      //! evaluate extended function on element
      inline void evaluate (const typename Traits::ElementType& e,
                            const typename Traits::DomainType& xl,
                            typename Traits::RangeType& y) const
      {
        typename Traits::DomainType xg = e.geometry().global(xl);
        y = f(xg);
      }

      // pass time to parameter object
      void setTime (RF t) {
        p.setTime(t);
      }
    };

    /** \brief return a PDELab GridFunction (with setTime method) defined by a parameter class and a callable f(e,x)
        that expects an entity e and local coordinates x */
    template<typename GV, typename RF, int n, typename F, typename P>
    class LocalCallableToInstationaryGridFunctionAdapter
      : public Dune::PDELab::GridFunctionBase<Dune::PDELab::
                                              GridFunctionTraits<GV,RF,n,Dune::FieldVector<RF,n> >,
                                              LocalCallableToInstationaryGridFunctionAdapter<GV,RF,n,F,P> >
    {
      GV gv;
      F f;
      P& p;
    public:
      typedef Dune::PDELab::
      GridFunctionTraits<GV,RF,n,Dune::FieldVector<RF,n> > Traits;

      //! construct from grid view
      LocalCallableToInstationaryGridFunctionAdapter (const GV& gv_, const F& f_, P& p_) : gv(gv_), f(f_), p(p_) {}

      //! get a reference to the grid view
      inline const GV& getGridView () {return gv;}

      //! evaluate extended function on element
      inline void evaluate (const typename Traits::ElementType& e,
                            const typename Traits::DomainType& xl,
                            typename Traits::RangeType& y) const
      {
        y = f(e,xl);
      }

      // pass time to parameter object
      void setTime (RF t) {
        p.setTime(t);
      }
    };

#ifdef DOXYGEN
    //! \brief Create a GridFunction from callable and parameter class with setTime method
    /**
     * \param gv A GridView.
     * \param f A callable of one of the two forms:
     *          1. f(x) taking a global coordinate x of type
     *          typename GV::template Codim<0>::Entity::Geometry::GlobalCoordinate.
     *          2. f(e,x) taking an Entity e
     *          coordinate x  or of the form f(e,x) taking an Entity e and a local
     *          coordinate x of type Entity::Geometry::LocalCoordinate.
     * \param parameter Parameter class.
     * \return A GlobalCallableToInstationaryGridFunctionAdapter or a
     *         LocalCallableToInstationaryGridFunctionAdapter
     */
    template <typename GV, typename F>
    WrapperConformingToGridFunctionInterface makeInstationaryGridFunctionFromCallable (const GV& gv, const F& f)
    {}
#endif

#ifndef DOXYGEN
    /** \brief Create PDELab GridFunction with setTime method from a callable f(e,x)
        that expects an global coordinate x */
    template <typename GV, typename F, typename PARAM>
    auto makeInstationaryGridFunctionFromCallable (const GV& gv, const F& f, PARAM& param)
      -> typename std::enable_if<
        AlwaysTrue <
          decltype(f(std::declval<typename GV::template Codim<0>::Entity::Geometry::GlobalCoordinate>()))
          >::value,
        GlobalCallableToInstationaryGridFunctionAdapter<
          GV,
          typename CallableAdapterGetRangeFieldType<
            decltype(f(std::declval<typename GV::template Codim<0>::Entity::Geometry::GlobalCoordinate>()))
            >::Type,
          CallableAdapterGetDim<
            decltype(f(std::declval<typename GV::template Codim<0>::Entity::Geometry::GlobalCoordinate>()))
            >::dim,
          F,
          PARAM>
        >::type
    {
      typedef typename GV::template Codim<0>::Entity::Geometry::GlobalCoordinate X;
      X x;
      typedef decltype(f(x)) ReturnType;
      typedef typename CallableAdapterGetRangeFieldType<ReturnType>::Type RF;
      const int dim = CallableAdapterGetDim<ReturnType>::dim;
      typedef GlobalCallableToInstationaryGridFunctionAdapter<GV,RF,dim,F,PARAM> TheType;
      return TheType(gv,f,param);
    }

    /** \brief Create PDELab GridFunction with setTime method from a callable f(e,x)
        that expects an entity e and a local coordinate x */
    template <typename GV, typename F, typename PARAM>
    auto makeInstationaryGridFunctionFromCallable (const GV& gv, const F& f, PARAM& param)
      -> typename std::enable_if<
        AlwaysTrue <
          decltype(f(
                     std::declval<typename GV::template Codim<0>::Entity>(),
                     std::declval<typename GV::template Codim<0>::Entity::Geometry::LocalCoordinate>()
                     ))
          >::value,
        LocalCallableToInstationaryGridFunctionAdapter<
          GV,
          typename CallableAdapterGetRangeFieldType<
            decltype(f(
                       std::declval<typename GV::template Codim<0>::Entity>(),
                       std::declval<typename GV::template Codim<0>::Entity::Geometry::LocalCoordinate>()
                       ))
            >::Type,
          CallableAdapterGetDim<
            decltype(f(
                       std::declval<typename GV::template Codim<0>::Entity>(),
                       std::declval<typename GV::template Codim<0>::Entity::Geometry::LocalCoordinate>()
                       ))
            >::dim,
          F,
          PARAM>
        >::type
    {
      typedef typename GV::template Codim<0>::Entity E;
      E e;
      typedef typename E::Geometry::LocalCoordinate X;
      X x;
      typedef decltype(f(e,x)) ReturnType;
      typedef typename CallableAdapterGetRangeFieldType<ReturnType>::Type RF;
      const int dim = CallableAdapterGetDim<ReturnType>::dim;
      typedef LocalCallableToInstationaryGridFunctionAdapter<GV,RF,dim,F,PARAM> TheType;
      return TheType(gv,f,param);
    }
#endif // DOXYGEN


    /*****************************
     * Boundary condition adapters
     *****************************/

    /** \brief Adapter for boundary cond from a callable taking global coordinates*/
    template<typename F>
    class GlobalCallableToBoundaryConditionAdapter
      : public Dune::PDELab::DirichletConstraintsParameters
    {
      F f;

    public:
      //! construct from functor
      GlobalCallableToBoundaryConditionAdapter (F f_) : f(f_) {}

      //! Test whether boundary is Dirichlet-constrained
      template<typename I>
      bool isDirichlet(const I & intersection,
                       const Dune::FieldVector<typename I::ctype, I::dimension-1> & coord
                       ) const
      {
        Dune::FieldVector<typename I::ctype, I::dimension> xg = intersection.geometry().global(coord);
        return f(xg);
      }

      template<typename I>
      bool isNeumann(const I & ig,
                     const Dune::FieldVector<typename I::ctype, I::dimension-1> & coord
                     ) const
      {
        return !isDirichlet( ig, coord );
      }

    };

    /** \brief Adapter for boundary cond from a callable taking an entity and local coordinates*/
    template<typename F>
    class LocalCallableToBoundaryConditionAdapter :
      public Dune::PDELab::FluxConstraintsParameters,
      public Dune::PDELab::DirichletConstraintsParameters
    {
      const F f;

    public:

      LocalCallableToBoundaryConditionAdapter(const F& f_ )
        : f( f_ )
      {}

      template<typename I>
      bool isDirichlet(const I & ig, const Dune::FieldVector<typename I::ctype, I::dimension-1> & coord
                       ) const
      {
        return(f(ig.intersection(),coord));
      }

      template<typename I>
      bool isNeumann(const I & ig,
                     const Dune::FieldVector<typename I::ctype, I::dimension-1> & coord
                     ) const
      {
        return !isDirichlet( ig, coord );
      }
    };

#ifdef DOXYGEN
    //! \brief Create a BoundaryConditionAdapter from a callable
    /**
     * \param gv A GridView
     * \param f A callable of one of the two forms:
     *          1. f(x) taking a global coordinate x of type
     *          typename GV::template Codim<0>::Entity::Geometry::GlobalCoordinate.
     *          2. f(e,x) taking an Entity e
     *          coordinate x  or of the form f(e,x) taking an Entity e and a local
     *          coordinate x of type Entity::Geometry::LocalCoordinate.
     * \return A GlobalCallableToBoundaryConditionAdapter or a
     *         LocalCallableToBoundaryConditionAdapter.
     */
    template <typename GV, typename F>
    BoundaryConditionAdapter makebBoundaryConditionFromCallable (const GV& gv, const F& f)
#endif

#ifndef DOXYGEN
    /** \brief Create BoundaryConditionAdapter from a callable f(x) that expects a global coordinate x */
    template<typename GV, typename F>
    auto makeBoundaryConditionFromCallable (const GV& gv, const F& f)
      -> typename std::enable_if<
        AlwaysTrue <
          decltype(f(std::declval<typename GV::template Codim<0>::Entity::Geometry::GlobalCoordinate>()))
          >::value,
        GlobalCallableToBoundaryConditionAdapter<F>
        >::type
    {
      return GlobalCallableToBoundaryConditionAdapter<F>(f);
    }

    /** \brief Create BoundaryConditionAdapter from a callable f(e,x) that expects
        an entity e and a global coordinate x */
    template<typename GV, typename F>
    auto makeBoundaryConditionFromCallable (const GV& gv, const F& f)
      -> typename std::enable_if<
        AlwaysTrue <
          decltype(f(
                     std::declval<typename GV::template Codim<0>::Entity>(),
                     std::declval<typename GV::template Codim<0>::Entity::Geometry::LocalCoordinate>()
                     ))
      >::value,
        LocalCallableToBoundaryConditionAdapter<F>
        >::type
    {
      return LocalCallableToBoundaryConditionAdapter<F>(f);
    }
#endif


  }
}
#endif // DUNE_PDELAB_FUNCTION_CALLABLEADAPTER_HH