FEAT 3
Finite Element Analysis Toolbox
Loading...
Searching...
No Matches
nlopt_precond.hpp
1// FEAT3: Finite Element Analysis Toolbox, Version 3
2// Copyright (C) 2010 by Stefan Turek & the FEAT group
3// FEAT3 is released under the GNU General Public License version 3,
4// see the file 'copyright.txt' in the top level directory for details.
5
6#pragma once
8#include <kernel/solver/base.hpp>
9#include <kernel/util/dist.hpp>
10
11namespace FEAT
12{
13 namespace Solver
14 {
31 template<typename VectorType_, typename FilterType_>
32 class NLOptPrecond: public SolverBase<VectorType_>
33 {
34 public:
36 typedef VectorType_ VectorType;
38 typedef FilterType_ FilterType;
39
43 explicit NLOptPrecond()
44 {
45 }
46
50 virtual ~NLOptPrecond()
51 {
52 }
53
64 virtual void prepare(const VectorType& DOXY(vec_state), FilterType& DOXY(filter))=0;
65
72 virtual String name() const override = 0;
73
87 virtual Status apply(VectorType& DOXY(vec_cor), const VectorType& DOXY(vec_def)) override = 0;
88
92 virtual String info() const
93 {
94 return this->name();
95 }
96
97 }; // class NLOptPrecond
98
110 template<typename NonlinearOperator_>
112 : public Solver::NLOptPrecond
113 <
114 typename NonlinearOperator_::SystemLevelType::GlobalSystemVectorR,
115 typename NonlinearOperator_::SystemLevelType::GlobalSystemFilter
116 >
117 {
118 public:
120 typedef typename NonlinearOperator_::SystemLevelType::GlobalSystemVectorR VectorType;
122 typedef typename NonlinearOperator_::SystemLevelType::GlobalSystemFilter FilterType;
125
126 private:
128 NonlinearOperator_ _op;
129
130 public:
134 template<typename... Args_>
135 explicit NonlinearOperatorPrecondWrapper(Args_&&... args):
136 _op(std::forward<Args_>(args)...)
137 {
138 }
139
144 {
145 }
146
148 virtual String name() const override
149 {
150 return "NonlinearOperatorPrecondWrapper<"+_op.name()+">";
151 }
152
154 virtual void prepare(const VectorType& vec_state, FilterType& DOXY(filter)) override
155 {
156 _op.prepare(vec_state);
157 }
158
160 virtual void init_numeric() override
161 {
162 _op.init_numeric();
163 }
164
166 virtual Solver::Status apply(VectorType& vec_cor, const VectorType& vec_def) override
167 {
168 Statistics::add_solver_expression(std::make_shared<ExpressionStartSolve>(this->name()));
169 Statistics::add_solver_expression(std::make_shared<ExpressionCallPrecond>(this->name(), _op.name()));
170
171 Solver::Status st(_op.apply(vec_cor, vec_def));
172
173 Statistics::add_solver_expression(std::make_shared<ExpressionEndSolve>(this->name(), st, 1));
174
175 return st;
176 }
177
179 virtual String info() const override
180 {
181 return this->name() + "[" + _op.info() + "]";
182 }
183
184 }; // class NonlinearOperatorPrecondWrapper
185
197 template<typename NonlinearOperator_, typename... Args_>
198 inline std::shared_ptr<NonlinearOperatorPrecondWrapper<NonlinearOperator_>>
200 {
201 return std::make_shared<NonlinearOperatorPrecondWrapper<NonlinearOperator_>>(std::forward<Args_>(args)...);
202 }
203
204 } // namespace Solver
205}// namespace FEAT
FEAT Kernel base header.
Abstract base class for preconditioners for nonlinear optimization.
virtual void prepare(const VectorType &vec_state, FilterType &filter)=0
Prepares the preconditioner for application.
NLOptPrecond()
Empty default constructor.
virtual String name() const override=0
Returns a descriptive String.
VectorType_ VectorType
Floating point data type.
FilterType_ FilterType
Type of the filter.
virtual Status apply(VectorType &vec_cor, const VectorType &vec_def) override=0
Applies the preconditioner.
virtual String info() const
Returns information.
virtual ~NLOptPrecond()
Empty virtual destructor.
Wrapper class around a (potentially nonlinear) operator.
NonlinearOperatorPrecondWrapper(Args_ &&... args)
Variadic template constructor.
NonlinearOperator_ _op
The operator that defines the preconditioner.
Solver::NLOptPrecond< VectorType, FilterType > BaseClass
Our base class.
virtual String name() const override
Returns a descriptive String.
NonlinearOperator_::SystemLevelType::GlobalSystemVectorR VectorType
The vector type the preconditioner can be applied to.
virtual String info() const override
Returns information.
virtual void prepare(const VectorType &vec_state, FilterType &filter) override
Prepares the preconditioner for application.
virtual void init_numeric() override
Numeric initialization method.
virtual ~NonlinearOperatorPrecondWrapper()
Virtual destructor.
virtual Solver::Status apply(VectorType &vec_cor, const VectorType &vec_def) override
Applies the preconditioner.
NonlinearOperator_::SystemLevelType::GlobalSystemFilter FilterType
The filter type.
Polymorphic solver interface.
Definition: base.hpp:183
String class implementation.
Definition: string.hpp:46
std::shared_ptr< NonlinearOperatorPrecondWrapper< NonlinearOperator_ > > new_nonlinear_operator_precond_wrapper(Args_ &&... args)
Creates a new NonlinearOperatorPrecondWrapper.
Status
Solver status return codes enumeration.
Definition: base.hpp:47
FEAT namespace.
Definition: adjactor.hpp:12