version 3.11-dev
numericepsilon.hh
Go to the documentation of this file.
1
2// -*- mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
3// vi: set et ts=4 sw=4 sts=4:
4//
5// SPDX-FileCopyrightText: Copyright © DuMux Project contributors, see AUTHORS.md in root folder
6// SPDX-License-Identifier: GPL-3.0-or-later
7//
13#ifndef DUMUX_ASSEMBLY_NUMERIC_EPSILON_HH
14#define DUMUX_ASSEMBLY_NUMERIC_EPSILON_HH
15
16#include <cmath>
17
18#include <dune/common/fvector.hh>
21
22namespace Dumux {
23
30template<class Scalar, int numEq>
32{
33 using Magnitude = std::decay_t<decltype(abs(std::declval<Scalar>()))>;
34 using NumEqVector = Dune::FieldVector<Magnitude, numEq>;
35
36public:
37 explicit NumericEpsilon(const std::string& paramGroup = "")
38 {
39 // get epsilons from input file with invalid default
40 baseEps_ = getParamFromGroup<Scalar>(paramGroup, "Assembly.NumericDifference.BaseEpsilon", 1e-10);
41 magnitude_ = getParamFromGroup<NumEqVector>(paramGroup, "Assembly.NumericDifference.PriVarMagnitude", NumEqVector(-1));
42 }
43
49 Scalar operator() (Scalar priVar, int priVarIdx) const noexcept
50 {
51 return magnitude_[priVarIdx] > 0.0 ? Scalar(baseEps_*magnitude_[priVarIdx])
52 : Scalar(NumericDifferentiation::epsilon(priVar, baseEps_));
53 }
54
55private:
56 Scalar baseEps_;
57 NumEqVector magnitude_;
58};
59
60} // end namespace Dumux
61
62#endif
static Scalar epsilon(const Scalar value, const Scalar baseEps=1e-10)
Computes the epsilon used for numeric differentiation.
Definition: numericdifferentiation.hh:36
A helper class for local assemblers using numeric differentiation to determine the epsilon.
Definition: numericepsilon.hh:32
NumericEpsilon(const std::string &paramGroup="")
Definition: numericepsilon.hh:37
Scalar operator()(Scalar priVar, int priVarIdx) const noexcept
get the epsilon
Definition: numericepsilon.hh:49
typename NumEqVectorTraits< PrimaryVariables >::type NumEqVector
A vector with the same size as numbers of equations This is the default implementation and has to be ...
Definition: numeqvector.hh:34
Definition: adapt.hh:17
A class for numeric differentiation.
The infrastructure to retrieve run-time parameters from Dune::ParameterTrees.