OGS
NumericalJacobianAssembler.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (c) OpenGeoSys Community (opengeosys.org)
2// SPDX-License-Identifier: BSD-3-Clause
3
4#pragma once
5
7
8namespace ProcessLib
9{
12{
13public:
17 explicit NumericalJacobianAssembler(std::vector<double>&& absolute_epsilons)
18 : absolute_epsilons_(std::move(absolute_epsilons))
19 {
20 if (absolute_epsilons_.empty())
21 {
22 OGS_FATAL(
23 "Numerical Jacobian assembler requires perturbation values "
24 "(epsilons) for finite difference approximation, but none were "
25 "provided.\n"
26 "Please specify <epsilons> in the <jacobian_assembler> section "
27 "of your project file.\n"
28 "Example: <epsilons>1e-8 1e-8</epsilons> for a process with 2 "
29 "non-deformation variables.");
30 }
31 }
32
33 bool needsPicardAssembly() const override { return true; }
34
36 int const max_non_deformation_dofs_per_node) const override
37 {
38 int const num_abs_eps = static_cast<int>(absolute_epsilons_.size());
39 if (num_abs_eps != max_non_deformation_dofs_per_node)
40 {
42 "Mismatch in numerical Jacobian perturbation configuration:\n"
43 " Provided epsilons: {:d}\n"
44 " Required epsilons: {:d} (one per non-deformation variable "
45 "component)\n\n"
46 "Each non-deformation variable needs exactly one epsilon value "
47 "for numerical differentiation.\n"
48 "Deformation variables use analytical Jacobian and do not "
49 "require epsilons.\n"
50 "Please adjust the <epsilons> array in your project file to "
51 "match the number of required components.",
52 num_abs_eps, max_non_deformation_dofs_per_node);
53 }
54 }
55
57 std::vector<int> const& non_deformation_component_ids) override
58 {
59 // So far, the number of specified perturbations is checked inside this
60 // function, assuming the TH2M and THM processes do not use the
61 // staggered scheme. If the staggered scheme is supported in these
62 // processes, call `checkPerturbationSize(...)` and then
63 // `setNonDeformationComponentIDsNoSizeCheck(...)` instead.
64 checkPerturbationSize(non_deformation_component_ids.size());
65
66 non_deformation_component_ids_ = non_deformation_component_ids;
67 }
68
70 std::vector<int> const& non_deformation_component_ids) override
71 {
72 non_deformation_component_ids_ = non_deformation_component_ids;
73 }
74
75protected:
77 {
78 assert(!non_deformation_component_ids_.empty());
79 namespace rv = ranges::views;
81 rv::transform(
82 [this](int comp_id) -> double const&
83 {
84 return absolute_epsilons_[static_cast<std::size_t>(
85 comp_id)];
86 });
87 }
88
97 std::vector<double> const absolute_epsilons_;
98
103};
104} // namespace ProcessLib
#define OGS_FATAL(...)
Definition Error.h:10
Base class for Jacobian assemblers.
void checkPerturbationSize(int const max_non_deformation_dofs_per_node) const override
void setNonDeformationComponentIDs(std::vector< int > const &non_deformation_component_ids) override
void setNonDeformationComponentIDsNoSizeCheck(std::vector< int > const &non_deformation_component_ids) override
NumericalJacobianAssembler(std::vector< double > &&absolute_epsilons)