AMDiS 2.10
The Adaptive Multi-Dimensional Simulation Toolbox
NewtonIteration.hpp
1#pragma once
2
3#include <memory>
4#include <string>
5
6#include <amdis/AdaptInfo.hpp>
7#include <amdis/Flag.hpp>
8#include <amdis/Initfile.hpp>
9#include <amdis/ProblemIterationInterface.hpp>
10#include <amdis/ProblemStatBase.hpp>
11
12namespace AMDiS
13{
14 template <class ProblemType>
17 {
18 using Self = NewtonIteration;
19 using Problem = ProblemType;
20
21 using SolutionVector = typename Problem::SolutionVector;
22
23 public:
25 NewtonIteration (std::string name, Problem& prob)
26 : name_(std::move(name))
27 , prob_(&prob)
28 {
29 stepSolution_.reset(new SolutionVector(*prob_->solutionVector()));
30
31 Parameters::get(name_ + "->build cycle", buildCycle_);
32 Parameters::get(name_ + "->norm", norm_);
33 }
34
36 void beginIteration(AdaptInfo& /*adaptInfo*/) override { /* do nothing */ }
37
39 Flag oneIteration(AdaptInfo& adaptInfo, Flag toDo) override;
40
42 void endIteration(AdaptInfo& adaptInfo) override
43 {
44 msg("{:>5} | {:>12} | {:>8} | {:>8} ", "iter.", "error", "red.", "tol");
45 if (errOld_ <= 0)
46 msg("{:5d} | {:12.5e} | {:->8} | {:8.2} ",
47 adaptInfo.spaceIteration()+1, err_, "-",adaptInfo.spaceTolerance(""));
48 else
49 msg("{:5d} | {:12.5e} | {:8.2e} | {:8.2} ",
50 adaptInfo.spaceIteration()+1, err_, err_/errOld_,adaptInfo.spaceTolerance(""));
51
52 errOld_ = err_;
53 }
54
56 ProblemStatBase& problem([[maybe_unused]] int n = 0) override
57 {
58 assert(n == 0); return *prob_;
59 }
60
62 int numProblems() const override { return 1; }
63
65 ProblemStatBase& problem([[maybe_unused]] std::string const& name) override
66 {
67 assert(prob_->name() == name);
68 return *prob_;
69 }
70
72 std::string const& name() const override { return name_; }
73
74
76 std::shared_ptr<SolutionVector const> stepSolutionVector() const
77 {
78 return stepSolution_;
79 }
80
82
86 template <class Range = void, class... Indices>
87 auto stepSolution(Indices... ii) const
88 {
89 return valueOf<Range>(*stepSolution_, ii...);
90 }
91
92 protected:
94 std::string name_;
95
97 Problem* prob_;
98
100 std::shared_ptr<SolutionVector> stepSolution_;
101
103
108 int buildCycle_ = 1;
109
111
116 int norm_ = 1;
117
118 private:
119 double err_ = 0.0;
120 double errOld_ = -1.0;
121 };
122
123} // end namespace AMDiS
124
125#include <amdis/nonlin/NewtonIteration.inc.hpp>
Holds adapt parameters and infos about the problem.
Definition: AdaptInfo.hpp:26
int spaceIteration() const
Returns spaceIteration_.
Definition: AdaptInfo.hpp:165
double spaceTolerance(Key key) const
Returns spaceTolerance.
Definition: AdaptInfo.hpp:404
The Flag class encapsulates flags which represents simple information. Used e.g. while mesh traversal...
Definition: Flag.hpp:14
static std::optional< T > get(std::string const &key)
Get parameter-values from parameter-tree.
Definition: Initfile.hpp:25
Definition: NewtonIteration.hpp:17
int buildCycle_
Build matrix every i'th iteration.
Definition: NewtonIteration.hpp:108
std::shared_ptr< SolutionVector const > stepSolutionVector() const
Returns const-ref of stepSolution_.
Definition: NewtonIteration.hpp:76
ProblemStatBase & problem(int n=0) override
Returns problemStat.
Definition: NewtonIteration.hpp:56
std::string name_
Name of the newton problem, used to access initfile parameters.
Definition: NewtonIteration.hpp:94
std::shared_ptr< SolutionVector > stepSolution_
Solution of the update step.
Definition: NewtonIteration.hpp:100
int numProblems() const override
Implementation of ProblemIterationInterface::numProblems.
Definition: NewtonIteration.hpp:62
Problem * prob_
Problem containing the Jacobian operators and objective function.
Definition: NewtonIteration.hpp:97
std::string const & name() const override
Returns the name of the problem.
Definition: NewtonIteration.hpp:72
ProblemStatBase & problem(std::string const &name) override
Returns the problem with the given name.
Definition: NewtonIteration.hpp:65
NewtonIteration(std::string name, Problem &prob)
Constructs a nonlinear iteration scheme.
Definition: NewtonIteration.hpp:25
auto stepSolution(Indices... ii) const
Return a const view to a stepSolution component.
Definition: NewtonIteration.hpp:87
void endIteration(AdaptInfo &adaptInfo) override
Implementation of ProblemIterationInterface::endIteration.
Definition: NewtonIteration.hpp:42
int norm_
Type of norm to use for estimating the error.
Definition: NewtonIteration.hpp:116
void beginIteration(AdaptInfo &) override
Implementation of ProblemIterationInterface::beginIteration.
Definition: NewtonIteration.hpp:36
Flag oneIteration(AdaptInfo &adaptInfo, Flag toDo) override
Implementation of ProblemIterationInterface::oneIteration.
Definition: NewtonIteration.inc.hpp:9
Interface for master problems needed by the adaption loop. A master problem can handle one single or ...
Definition: ProblemIterationInterface.hpp:30
Interface for time independent problems. Concrete problems must override all pure virtual methods....
Definition: ProblemStatBase.hpp:59