Skip to content
Snippets Groups Projects
Commit 3cf7bde6 authored by Tim Keil's avatar Tim Keil
Browse files

[sliced] move and update to introduce bind of functions

sliced -> base/sliced
parent 7497e417
Branches
Tags
No related merge requests found
...@@ -8,13 +8,13 @@ ...@@ -8,13 +8,13 @@
// Felix Schindler (2017) // Felix Schindler (2017)
// Rene Milk (2018) // Rene Milk (2018)
#ifndef DUNE_XT_FUNCTIONS_SLICED_HH #ifndef DUNE_XT_FUNCTIONS_BASE_SLICED_HH
#define DUNE_XT_FUNCTIONS_SLICED_HH #define DUNE_XT_FUNCTIONS_BASE_SLICED_HH
#if 0
#include <dune/common/typetraits.hh> #include <dune/common/typetraits.hh>
#include <dune/xt/functions/type_traits.hh> #include <dune/xt/functions/type_traits.hh>
#include <dune/xt/functions/interfaces/localizable-function.hh> #include <dune/xt/functions/interfaces/grid-function.hh>
namespace Dune { namespace Dune {
...@@ -23,7 +23,7 @@ namespace Functions { ...@@ -23,7 +23,7 @@ namespace Functions {
template <class LF, size_t r, size_t rC = 1> template <class LF, size_t r, size_t rC = 1>
class SlicedLocalizableFunction class SlicedGridFunction
{ {
static_assert(AlwaysFalse<LF>::value, "Not available for matrix-valued functions (yet)!"); static_assert(AlwaysFalse<LF>::value, "Not available for matrix-valued functions (yet)!");
}; };
...@@ -43,61 +43,67 @@ auto energy = XT::Functions::make_sliced_function<1>(u, {3}, "energy"); ...@@ -43,61 +43,67 @@ auto energy = XT::Functions::make_sliced_function<1>(u, {3}, "energy");
\endcode \endcode
*/ */
template <class LF, size_t r> template <class LF, size_t r>
class SlicedLocalizableFunction<LF, r, 1> class SlicedGridFunction<LF, r, 1> : public XT::Functions::GridFunctionInterface<typename LF::E, r, 1, typename LF::R>
: public XT::Functions::LocalizableFunctionInterface<typename LF::E, typename LF::D, LF::d, typename LF::R, r, 1>
{ {
static_assert(is_localizable_function<LF>::value, ""); static_assert(is_grid_function<LF>::value, "");
static_assert(r <= LF::r, "Does not make sense!"); static_assert(r <= LF::r, "Does not make sense!");
using BaseType = using BaseType = XT::Functions::GridFunctionInterface<typename LF::E, r, 1, typename LF::R>;
XT::Functions::LocalizableFunctionInterface<typename LF::E, typename LF::D, LF::d, typename LF::R, r, 1>;
class SlicedLocalFunction class SlicedLocalFunction : public XT::Functions::ElementFunctionInterface<typename LF::E, r, 1, typename LF::R>
: public XT::Functions::LocalfunctionInterface<typename LF::E, typename LF::D, LF::d, typename LF::R, r, 1>
{ {
using BaseType = XT::Functions::LocalfunctionInterface<typename LF::E, typename LF::D, LF::d, typename LF::R, r, 1>; using BaseType = XT::Functions::ElementFunctionInterface<typename LF::E, r, 1, typename LF::R>;
public: public:
using typename BaseType::EntityType; using typename BaseType::ElementType;
using typename BaseType::DomainType; using typename BaseType::DomainType;
using typename BaseType::RangeType; using typename BaseType::RangeType;
using typename BaseType::JacobianRangeType; using typename BaseType::RangeReturnType;
using typename BaseType::DerivativeRangeType;
using typename BaseType::DerivativeRangeReturnType;
SlicedLocalFunction(const LF& function, const std::array<size_t, r>& dims, const EntityType& ent) SlicedLocalFunction(const LF& function, const std::array<size_t, r>& dims)
: BaseType(ent) : BaseType()
, local_function_(function.local_function(ent)) , local_function_(function.local_function())
, dims_(dims) , dims_(dims)
{ {
} }
size_t order(const XT::Common::Parameter& = {}) const override final void post_bind(const ElementType& element) override final
{
local_function_->post_bind(element);
}
int order(const XT::Common::Parameter& = {}) const override final
{ {
return local_function_->order(); return local_function_->order();
} }
void evaluate(const DomainType& xx, RangeType& ret, const XT::Common::Parameter& mu = {}) const override final RangeReturnType evaluate(const DomainType& xx, const XT::Common::Parameter& param = {}) const override final
{ {
const auto value = local_function_->evaluate(xx, mu); RangeReturnType ret;
const auto value = local_function_->evaluate(xx, param);
for (size_t ii = 0; ii < r; ++ii) for (size_t ii = 0; ii < r; ++ii)
ret[ii] = value[dims_[ii]]; ret[ii] = value[dims_[ii]];
return ret;
} }
void jacobian(const DomainType& /*xx*/, DerivativeRangeReturnType jacobian(const DomainType& /*xx*/,
JacobianRangeType& /*ret*/, const XT::Common::Parameter& /*param*/ = {}) const override final
const XT::Common::Parameter& /*mu*/ = {}) const override final
{ {
DUNE_THROW(NotImplemented, "Yet!"); DUNE_THROW(NotImplemented, "Yet!");
} }
private: private:
const std::unique_ptr<typename LF::LocalfunctionType> local_function_; const std::unique_ptr<typename LF::LocalFunctionType> local_function_;
const std::array<size_t, r>& dims_; const std::array<size_t, r>& dims_;
}; // class SlicedLocalFunction }; // class SlicedLocalFunction
public: public:
using typename BaseType::EntityType; using typename BaseType::ElementType;
using typename BaseType::LocalfunctionType; using typename BaseType::LocalFunctionType;
SlicedLocalizableFunction(const LF& function, const std::array<size_t, r>& dims, const std::string& nm = "") SlicedGridFunction(const LF& function, const std::array<size_t, r>& dims, const std::string& nm = "")
: function_(function) : function_(function)
, dims_(dims) , dims_(dims)
, name_(nm) , name_(nm)
...@@ -115,35 +121,33 @@ public: ...@@ -115,35 +121,33 @@ public:
<< dims_[ii]); << dims_[ii]);
} }
std::string name() const override final const std::string& name() const override final
{ {
return name_.empty() ? "sliced " + function_.name() : name_; return name_.empty() ? "sliced " + function_.name() : name_;
} }
std::unique_ptr<LocalfunctionType> local_function(const EntityType& entity) const override final std::unique_ptr<LocalFunctionType> local_function() const override final
{ {
return std::make_unique<SlicedLocalFunction>(function_, dims_, entity); return std::make_unique<SlicedLocalFunction>(function_, dims_);
} }
private: private:
const LF& function_; const LF& function_;
const std::array<size_t, r> dims_; const std::array<size_t, r> dims_;
const std::string name_; const std::string& name_;
}; // class SlicedLocalizableFunction }; // class SlicedGridFunction
template <size_t sliced_r, class E, class D, size_t d, class R, size_t r> template <size_t sliced_r, class E, size_t r>
SlicedLocalizableFunction<LocalizableFunctionInterface<E, D, d, R, r>, sliced_r> SlicedGridFunction<GridFunctionInterface<E, r>, sliced_r> make_sliced_function(
make_sliced_function(const LocalizableFunctionInterface<E, D, d, R, r>& function, const GridFunctionInterface<E, r>& function, const std::array<size_t, sliced_r>& dims, const std::string& name = "")
const std::array<size_t, sliced_r>& dims,
const std::string& name = "")
{ {
return SlicedLocalizableFunction<LocalizableFunctionInterface<E, D, d, R, r>, sliced_r>(function, dims, name); return SlicedGridFunction<GridFunctionInterface<E, r>, sliced_r>(function, dims, name);
} }
} // namespace Functions } // namespace Functions
} // namespace XT } // namespace XT
} // namespace Dune } // namespace Dune
#endif
#endif // DUNE_XT_FUNCTIONS_SLICED_HH #endif // DUNE_XT_FUNCTIONS_SLICED_HH
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment