/usr/include/dune/functions/gridfunctions/discretescalarglobalbasisfunction.hh is in libdune-functions-dev 2.5.0-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 | // -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
// vi: set et ts=4 sw=2 sts=2:
#ifndef DUNE_FUNCTIONS_GRIDFUNCTIONS_DISCRETESCALARGLOBALBASISFUNCTIONS_HH
#define DUNE_FUNCTIONS_GRIDFUNCTIONS_DISCRETESCALARGLOBALBASISFUNCTIONS_HH
#include <memory>
#include <dune/common/shared_ptr.hh>
#include <dune/common/deprecated.hh>
#include <dune/functions/gridfunctions/gridviewentityset.hh>
#include <dune/functions/gridfunctions/gridfunction.hh>
namespace Dune {
namespace Functions {
/**
* \brief A grid function induced by a global basis and a coefficient vector
*
* \ingroup FunctionImplementations
*
* \deprecated This class is deprecated. Please use DiscreteGlobalBasisFunction instead!
*/
template<typename Basis, typename V>
class DUNE_DEPRECATED_MSG("Use DiscreteGlobalBasisFunction instead!") DiscreteScalarGlobalBasisFunction
{
public:
using GridView = typename Basis::GridView;
using EntitySet = GridViewEntitySet<GridView, 0>;
using Domain = typename EntitySet::GlobalCoordinate;
using Range = typename V::value_type;
using LocalBasisRange = typename Basis::LocalView::Tree::FiniteElement::Traits::LocalBasisType::Traits::RangeType;
using LocalDomain = typename EntitySet::LocalCoordinate;
using Element = typename EntitySet::Element;
using Traits = Imp::GridFunctionTraits<Range(Domain), EntitySet, DefaultDerivativeTraits, 16>;
class LocalFunction
{
using LocalBasisView = typename Basis::LocalView;
using LocalIndexSet = typename Basis::LocalIndexSet;
using size_type = typename LocalBasisView::Tree::size_type;
public:
using GlobalFunction = DiscreteScalarGlobalBasisFunction;
using Domain = LocalDomain;
using Range = GlobalFunction::Range;
using Element = GlobalFunction::Element;
LocalFunction(const DiscreteScalarGlobalBasisFunction& globalFunction)
: globalFunction_(&globalFunction)
, localBasisView_(globalFunction.basis().localView())
, localIndexSet_(globalFunction.basis().localIndexSet())
{
localDoFs_.reserve(localBasisView_.maxSize());
shapeFunctionValues_.reserve(localBasisView_.maxSize());
}
/**
* \brief Bind LocalFunction to grid element.
*
* You must call this method before evaluate()
* and after changes to the coefficient vector.
*/
void bind(const Element& element)
{
localBasisView_.bind(element);
localIndexSet_.bind(localBasisView_);
// Read dofs associated to bound element
localDoFs_.resize(localIndexSet_.size());
for (size_type i = 0; i < localIndexSet_.size(); ++i)
localDoFs_[i] = globalFunction_->dofs()[localIndexSet_.index(i)[0]];
// Prepare result vector for shape function
shapeFunctionValues_.resize(localIndexSet_.size());
}
void unbind()
{
localIndexSet_.unbind();
localBasisView_.unbind();
}
/**
* \brief Evaluate LocalFunction at bound element.
*
* The result of this method is undefined if you did
* not call bind() beforehand or changed the coefficient
* vector after the last call to bind(). In the latter case
* you have to call bind() again in order to make operator()
* usable.
*/
Range operator()(const Domain& x) const
{
auto y = Range(0);
auto& basis = localBasisView_.tree().finiteElement().localBasis();
basis.evaluateFunction(x, shapeFunctionValues_);
for (size_type i = 0; i < basis.size(); ++i)
{
// Here we essentially want to do
//
// y += localDoFs_[i] * shapeFunctionValues_[i];
//
// Currently we support vector valued coefficients and scalar
// local basis functions only. In order to generalize this we
// have to use a more general product implementation here.
// Maybe we want do adopt the framework of dune-fufem.
auto yy = localDoFs_[i];
yy *= shapeFunctionValues_[i];
y += yy;
}
return y;
}
const Element& localContext() const
{
return localBasisView_.element();
}
friend typename Traits::LocalFunctionTraits::DerivativeInterface derivative(const LocalFunction& t)
{
DUNE_THROW(NotImplemented,"not implemented");
}
private:
const DiscreteScalarGlobalBasisFunction* globalFunction_;
LocalBasisView localBasisView_;
LocalIndexSet localIndexSet_;
std::vector<typename V::value_type> localDoFs_;
mutable std::vector<LocalBasisRange> shapeFunctionValues_;
};
DiscreteScalarGlobalBasisFunction(const Basis & basis, const V & dofs)
: entitySet_(basis.gridView())
, basis_(stackobject_to_shared_ptr(basis))
, dofs_(stackobject_to_shared_ptr(dofs))
{}
DiscreteScalarGlobalBasisFunction(std::shared_ptr<Basis> basis, std::shared_ptr<V> dofs)
: entitySet_(basis.gridView())
, basis_(basis)
, dofs_(dofs)
{}
const Basis& basis() const
{
return *basis_;
}
const V& dofs() const
{
return *dofs_;
}
// TODO: Implement this using hierarchic search
Range operator() (const Domain& x) const
{
DUNE_THROW(NotImplemented,"not implemented");
}
friend typename Traits::DerivativeInterface derivative(const DiscreteScalarGlobalBasisFunction& t)
{
DUNE_THROW(NotImplemented,"not implemented");
}
friend LocalFunction localFunction(const DiscreteScalarGlobalBasisFunction& t)
{
return LocalFunction(t);
}
/**
* \brief Get associated EntitySet
*/
const EntitySet& entitySet() const
{
return entitySet_;
}
private:
EntitySet entitySet_;
std::shared_ptr<const Basis> basis_;
std::shared_ptr<const V> dofs_;
};
} // namespace Functions
} // namespace Dune
#endif // DUNE_FUNCTIONS_GRIDFUNCTIONS_DISCRETESCALARGLOBALBASISFUNCTIONS_HH
|