File: gridviewfunction.hh

package info (click to toggle)
dune-functions 2.10.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,544 kB
  • sloc: cpp: 14,241; python: 661; makefile: 3
file content (108 lines) | stat: -rw-r--r-- 3,482 bytes parent folder | download
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
// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
// vi: set et ts=4 sw=2 sts=2:

// SPDX-FileCopyrightText: Copyright © DUNE Project contributors, see file AUTHORS.md
// SPDX-License-Identifier: LicenseRef-GPL-2.0-only-with-DUNE-exception OR LGPL-3.0-or-later

#ifndef DUNE_FUNCTIONS_GRIDFUNCTIONS_GRIDVIEWFUNCTION_HH
#define DUNE_FUNCTIONS_GRIDFUNCTIONS_GRIDVIEWFUNCTION_HH

#include <memory>

#include <dune/common/concept.hh>

#include <dune/functions/gridfunctions/gridfunction.hh>
#include <dune/functions/gridfunctions/gridviewentityset.hh>
#include <dune/functions/gridfunctions/analyticgridviewfunction.hh>


namespace Dune {
namespace Functions {



template<class Signature, class GridView, template<class> class DerivativeTraits=DefaultDerivativeTraits, size_t bufferSize=56>
class GridViewFunction
{};



/**
 * \brief Wrapper class for functions defined on a GridView.
 *
 * \ingroup FunctionInterface
 *
 * Being defined on a grid view means in particular that you can evaluate the function
 * in local coordinates of a given element of the grid view.
 *
 * This models the \ref Concept::GridViewFunction<Range(Domain), GridView, DerivativeTraits> concept.
 *
 * \tparam GV The GridView that the function is defined on
 * \tparam Domain The domain type used for function arguments
 * \tparam Range The range type used for function values
 */
template<class Range, class Domain, class GV, template<class> class DerivativeTraits, size_t bufferSize>
class GridViewFunction<Range(Domain), GV, DerivativeTraits, bufferSize> :
  public GridFunction<Range(Domain), GridViewEntitySet<GV, 0>, DerivativeTraits, bufferSize>
{
  using Base = GridFunction<Range(Domain), GridViewEntitySet<GV, 0>, DerivativeTraits, bufferSize>;
public:
  using GridView = GV;

  using Base::Base;
};



/**
 * \brief Construct a function modeling GridViewFunction from function and grid view.
 *
 * This specialization is used for functions that already
 * support `localFunction()`. It will simply return a copy of `f`.
 *
 * \param f A function object supporting argument compatible with global coordinates
 * \param gridView The GridView the function should act on.
 *
 * \returns A function that models the GridViewFunction interface.
 */
template<class F, class GridView,
  std::enable_if_t<
    models< Imp::HasFreeLocalFunction, F>() , int> = 0>
std::decay_t<F>
  makeGridViewFunction(F&& f, const GridView& gridView)
{
  return std::forward<F>(f);
}



/**
 * \brief Construct a function modeling GridViewFunction from function and grid view.
 *
 * This specialization is used for functions that do not
 * support `localFunction()` themselves. It will forward
 * to `makeAnalyticGridViewFunction()`.
 *
 * Notice that the returned function will store a copy of
 * the original function and the GridView.
 *
 * \param f A function object supporting argument compatible with global coordinates
 * \param gridView The GridView the function should act on.
 *
 * \returns A function that models the GridFunction interface.
 */
template<class F, class GridView,
  std::enable_if_t<
    not(models< Imp::HasFreeLocalFunction, F>()) , int> = 0>
auto makeGridViewFunction(F&& f, const GridView& gridView)
  -> decltype(makeAnalyticGridViewFunction(std::forward<F>(f), gridView))
{
  return makeAnalyticGridViewFunction(std::forward<F>(f), gridView);
}



} // end of namespace Dune::Functions
} // end of namespace Dune

#endif // DUNE_FUNCTIONS_GRIDFUNCTIONS_GRIDVIEWFUNCTION_HH