diff --git a/dune/xt/functions/generic/function.hh b/dune/xt/functions/generic/function.hh index c7f5a645f70da7059ed7c3c9c28b1360a91c68af..4d257c10a86b3a1a2c5e2bd8c1f73e242edc47f8 100644 --- a/dune/xt/functions/generic/function.hh +++ b/dune/xt/functions/generic/function.hh @@ -39,10 +39,13 @@ public: using BaseType::d; using typename BaseType::DerivativeRangeReturnType; using typename BaseType::DomainType; + using typename BaseType::DynamicRangeType; using typename BaseType::RangeReturnType; using GenericOrderFunctionType = std::function<int(const Common::Parameter&)>; using GenericEvaluateFunctionType = std::function<RangeReturnType(const DomainType&, const Common::Parameter&)>; + using GenericDynamicEvaluateFunctionType = + std::function<void(const DomainType&, DynamicRangeType&, const Common::Parameter&)>; using GenericJacobianFunctionType = std::function<DerivativeRangeReturnType(const DomainType&, const Common::Parameter&)>; using GenericDerivativeFunctionType = std::function<DerivativeRangeReturnType( @@ -57,25 +60,58 @@ public: : BaseType(param_type) , order_(order_func) , evaluate_(evaluate_func) + , dynamic_evaluate_(static_to_dynamic_evaluate(evaluate_)) , jacobian_(jacobian_func) , derivative_(derivative_func) , name_(nm) {} GenericFunction(int ord, - GenericEvaluateFunctionType evaluate_lambda = default_evaluate_function(), + GenericEvaluateFunctionType evaluate_func = default_evaluate_function(), + const std::string nm = "smooth_lambda_function", + const Common::ParameterType& param_type = {}, + GenericJacobianFunctionType jacobian_func = default_jacobian_function(), + GenericDerivativeFunctionType derivative_func = default_derivative_function()) + : BaseType(param_type) + , order_([=](const auto& /*param*/) { return ord; }) + , evaluate_(evaluate_func) + , dynamic_evaluate_(static_to_dynamic_evaluate(evaluate_)) + , jacobian_(jacobian_func) + , derivative_(derivative_func) + , name_(nm) + {} + + GenericFunction(GenericOrderFunctionType order_func, + GenericDynamicEvaluateFunctionType dynamic_evaluate_func = default_dynamic_evaluate_function(), + const std::string nm = "smooth_lambda_function", + const Common::ParameterType& param_type = {}, + GenericJacobianFunctionType jacobian_func = default_jacobian_function(), + GenericDerivativeFunctionType derivative_func = default_derivative_function()) + : BaseType(param_type) + , order_(order_func) + , evaluate_(dynamic_to_static_evaluate(dynamic_evaluate_func)) + , dynamic_evaluate_(dynamic_evaluate_func) + , jacobian_(jacobian_func) + , derivative_(derivative_func) + , name_(nm) + {} + + GenericFunction(int ord, + GenericDynamicEvaluateFunctionType dynamic_evaluate_func = default_dynamic_evaluate_function(), const std::string nm = "smooth_lambda_function", const Common::ParameterType& param_type = {}, - GenericJacobianFunctionType jacobian_lambda = default_jacobian_function(), - GenericDerivativeFunctionType derivative_lambda = default_derivative_function()) + GenericJacobianFunctionType jacobian_func = default_jacobian_function(), + GenericDerivativeFunctionType derivative_func = default_derivative_function()) : BaseType(param_type) , order_([=](const auto& /*param*/) { return ord; }) - , evaluate_(evaluate_lambda) - , jacobian_(jacobian_lambda) - , derivative_(derivative_lambda) + , evaluate_(dynamic_to_static_evaluate(dynamic_evaluate_func)) + , dynamic_evaluate_(dynamic_evaluate_func) + , jacobian_(jacobian_func) + , derivative_(derivative_func) , name_(nm) {} + /** * \name ´´These methods are required by FunctionInterface.'' * \{ @@ -92,6 +128,13 @@ public: return evaluate_(point_in_global_coordinates, this->parse_parameter(param)); } + void evaluate(const DomainType& point_in_global_coordinates, + DynamicRangeType& ret, + const Common::Parameter& param = {}) const override final + { + dynamic_evaluate_(point_in_global_coordinates, ret, this->parse_parameter(param)); + } + DerivativeRangeReturnType jacobian(const DomainType& point_in_global_coordinates, const Common::Parameter& param = {}) const override final { @@ -121,10 +164,37 @@ public: return [](const DomainType& /*point_in_global_coordinates*/, const Common::Parameter& /*param*/ = {}) { DUNE_THROW(NotImplemented, "This GenericFunction does not provide evaluations, provide an evaluate_lambda on construction!"); - return RangeReturnType(); + return RangeReturnType{}; + }; + } + + static GenericDynamicEvaluateFunctionType default_dynamic_evaluate_function() + { + return [](const DomainType& /*point_in_global_coordinates*/, + DynamicRangeType& /*ret*/, + const Common::Parameter& /*param*/ = {}) { + DUNE_THROW(NotImplemented, + "This GenericFunction does not provide evaluations, provide an evaluate_lambda on construction!"); + }; + } + + static GenericEvaluateFunctionType dynamic_to_static_evaluate(GenericDynamicEvaluateFunctionType dynamic_eval) + { + return [=](const DomainType& point_in_global_coordinates, const Common::Parameter& param = {}) { + DynamicRangeType ret(range_dim); + dynamic_eval(point_in_global_coordinates, ret, param); + return XT::Common::convert_to<RangeReturnType>(ret); }; } + static GenericDynamicEvaluateFunctionType static_to_dynamic_evaluate(GenericEvaluateFunctionType static_eval) + { + return + [=](const DomainType& point_in_global_coordinates, DynamicRangeType& ret, const Common::Parameter& param = {}) { + ret = XT::Common::convert_to<DynamicRangeType>(static_eval(point_in_global_coordinates, param)); + }; + } + static GenericJacobianFunctionType default_jacobian_function() { return [](const DomainType& /*point_in_global_coordinates*/, const Common::Parameter& /*param*/ = {}) { @@ -153,6 +223,7 @@ public: const GenericOrderFunctionType order_; const GenericEvaluateFunctionType evaluate_; + const GenericDynamicEvaluateFunctionType dynamic_evaluate_; const GenericJacobianFunctionType jacobian_; const GenericDerivativeFunctionType derivative_; const std::string name_; diff --git a/dune/xt/functions/interfaces/element-flux-functions.hh b/dune/xt/functions/interfaces/element-flux-functions.hh index fe137e0f8f8c5cf0685aa3b3241b16f5b097ba3d..192f61bbd20670344dbcb81bdb040699b76307b2 100644 --- a/dune/xt/functions/interfaces/element-flux-functions.hh +++ b/dune/xt/functions/interfaces/element-flux-functions.hh @@ -77,6 +77,7 @@ public: using DomainType = Dune::FieldVector<D, d>; using StateType = Dune::FieldVector<S, s>; + using DynamicStateType = Dune::DynamicVector<S>; using RangeSelector = RangeTypeSelector<R, r, rC>; using JacobianRangeSelector = DerivativeRangeTypeSelector<s, R, r, rC>; @@ -398,6 +399,7 @@ public: using BaseType::rC; using BaseType::s; using typename BaseType::DomainType; + using typename BaseType::DynamicStateType; using typename BaseType::ElementType; using typename BaseType::R; using typename BaseType::S; diff --git a/dune/xt/functions/interfaces/flux-function.hh b/dune/xt/functions/interfaces/flux-function.hh index eeb0059aa940a89f4e0dba39f2c249fce2e800d0..a5ddbf9df54b5bc12f22b1a7445f6cbb8d2377a0 100644 --- a/dune/xt/functions/interfaces/flux-function.hh +++ b/dune/xt/functions/interfaces/flux-function.hh @@ -56,6 +56,7 @@ public: using ElementType = typename LocalFunctionType::ElementType; using DomainFieldType = typename LocalFunctionType::DomainFieldType; using StateType = typename LocalFunctionType::StateType; + using DynamicStateType = typename LocalFunctionType::DynamicStateType; using DomainType = typename LocalFunctionType::DomainType; static const constexpr size_t domain_dim = LocalFunctionType::domain_dim; static const constexpr size_t state_dim = LocalFunctionType::state_dim; diff --git a/dune/xt/la/container/vector-interface.hh b/dune/xt/la/container/vector-interface.hh index 0a9366d0975e266634d137d57d5ddcc27f32ac14..0776f642a29d5fb825490cd46968cf45f72a7e95 100644 --- a/dune/xt/la/container/vector-interface.hh +++ b/dune/xt/la/container/vector-interface.hh @@ -166,8 +166,9 @@ public: virtual void set_all(const ScalarType& val) { - for (auto& element : *this) - element = val; + const auto sz = size(); + for (size_t ii = 0; ii < sz; ++ii) + set_entry(ii, val); } virtual bool valid() const