version 3.11-dev
Loading...
Searching...
No Matches
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>
19#include <dune/common/ftraits.hh>
22
23namespace Dumux {
24
31template<class Scalar, int numEq>
33{
34 using Magnitude = typename Dune::FieldTraits<Scalar>::real_type;
35 using NumEqVector = Dune::FieldVector<Magnitude, numEq>;
36
37public:
38 explicit NumericEpsilon(const std::string& paramGroup = "")
39 {
40 // get epsilons from input file with invalid default
41 baseEps_ = getParamFromGroup<Magnitude>(paramGroup, "Assembly.NumericDifference.BaseEpsilon", 1e-10);
42 magnitude_ = getParamFromGroup<NumEqVector>(paramGroup, "Assembly.NumericDifference.PriVarMagnitude", NumEqVector(-1));
43 }
44
51 Magnitude operator() (Scalar priVar, int priVarIdx) const noexcept
52 {
53 return magnitude_[priVarIdx] > 0.0 ? baseEps_*magnitude_[priVarIdx]
54 : NumericDifferentiation::epsilon(priVar, baseEps_);
55 }
56
57private:
58 Magnitude baseEps_;
59 NumEqVector magnitude_;
60};
61
62} // end namespace Dumux
63
64#endif
static Magnitude epsilon(const Scalar value, const Magnitude baseEps=1e-10)
Computes the epsilon used for numeric differentiation.
Definition numericdifferentiation.hh:42
Magnitude operator()(Scalar priVar, int priVarIdx) const noexcept
get the epsilon
Definition numericepsilon.hh:51
NumericEpsilon(const std::string &paramGroup="")
Definition numericepsilon.hh:38
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
T getParamFromGroup(Args &&... args)
A free function to get a parameter from the parameter tree singleton with a model group.
Definition parameters.hh:165
Definition adapt.hh:17
A class for numeric differentiation.
The infrastructure to retrieve run-time parameters from Dune::ParameterTrees.