OGS
CreateForwardDifferencesJacobianAssembler.cpp
Go to the documentation of this file.
1
11
12#include "BaseLib/ConfigTree.h"
13#include "BaseLib/Error.h"
15
16namespace ProcessLib
17{
18std::unique_ptr<AbstractJacobianAssembler>
20{
22 config.checkConfigParameter("type", "ForwardDifferences");
23
24 // TODO make non-optional.
26 auto rel_eps = config.getConfigParameterOptional<std::vector<double>>(
27 "relative_epsilons");
29 auto comp_mag = config.getConfigParameterOptional<std::vector<double>>(
30 "component_magnitudes");
31
32 if (rel_eps.has_value() != comp_mag.has_value())
33 {
35 "Either both or none of <relative_epsilons> and "
36 "<component_magnitudes> have to be specified.");
37 }
38
39 std::vector<double> abs_eps;
40
41 if (rel_eps)
42 {
43 if (rel_eps->size() != comp_mag->size())
44 {
46 "The numbers of components of <relative_epsilons> and "
47 "<component_magnitudes> do not match.");
48 }
49
50 abs_eps.resize(rel_eps->size());
51 for (std::size_t i = 0; i < rel_eps->size(); ++i)
52 {
53 abs_eps[i] = (*rel_eps)[i] * (*comp_mag)[i];
54 }
55 }
56 else
57 {
58 // By default 1e-8 is used as epsilon for all components.
59 // TODO: remove this default value.
60 abs_eps.emplace_back(1e-8);
61 }
62
63 return std::make_unique<ForwardDifferencesJacobianAssembler>(
64 std::move(abs_eps));
65}
66
67} // namespace ProcessLib
#define OGS_FATAL(...)
Definition Error.h:26
std::optional< T > getConfigParameterOptional(std::string const &param) const
void checkConfigParameter(std::string const &param, std::string_view const value) const
std::unique_ptr< AbstractJacobianAssembler > createForwardDifferencesJacobianAssembler(BaseLib::ConfigTree const &config)