Finite Element Domain Decomposition Library
FEDDLib
Loading...
Searching...
No Matches
NonLinearProblem_decl.hpp
1#ifndef NONLINEARPROBLEM_DECL_hpp
2#define NONLINEARPROBLEM_DECL_hpp
3
4#include <Thyra_StateFuncModelEvaluatorBase.hpp>
5#include <Thyra_ProductVectorBase.hpp>
6#include <Teko_Utilities.hpp>
7
8#include "feddlib/core/FEDDCore.hpp"
9#include "feddlib/problems/abstract/Problem.hpp"
10
19
20namespace FEDD{
21template<class LO_, class GO_, class NO_>
22class BlockMap;
23
24template <class SC = default_sc,
25 class LO = default_lo,
26 class GO = default_go,
27 class NO = default_no>
28class NonLinearProblem : public Problem<SC,LO,GO,NO> , public Thyra::StateFuncModelEvaluatorBase<SC> {
29
30public:
31
32 typedef Problem<SC,LO,GO,NO> Problem_Type;
33 typedef typename Problem_Type::CommConstPtr_Type CommConstPtr_Type;
34 typedef typename Problem_Type::MapConstPtr_Type MapConstPtr_Type;
35 typedef typename Problem_Type::MultiVector_Type MultiVector_Type;
36 typedef typename Problem_Type::MultiVectorPtr_Type MultiVectorPtr_Type;
37 typedef typename Problem_Type::MultiVectorConstPtr_Type MultiVectorConstPtr_Type;
38 typedef typename Problem_Type::BlockMultiVector_Type BlockMultiVector_Type;
39 typedef typename Problem_Type::BlockMultiVectorPtr_Type BlockMultiVectorPtr_Type;
40
41 typedef typename Problem_Type::Matrix_Type Matrix_Type;
42 typedef typename Problem_Type::MatrixPtr_Type MatrixPtr_Type;
43
44 typedef typename Problem_Type::BlockMatrix_Type BlockMatrix_Type;
45 typedef typename Problem_Type::BlockMatrixPtr_Type BlockMatrixPtr_Type;
46
47
48 typedef Tpetra::Map<LO,GO,NO> TpetraMap_Type;
49 typedef Teuchos::RCP<TpetraMap_Type> TpetraMapPtr_Type;
50 typedef Teuchos::RCP<const TpetraMap_Type> TpetraMapConstPtr_Type;
51 typedef const TpetraMapConstPtr_Type TpetraMapConstPtrConst_Type;
52
53
54 typedef BlockMap<LO,GO,NO> BlockMap_Type;
55 typedef Teuchos::RCP<BlockMap_Type> BlockMapPtr_Type;
56 typedef Teuchos::RCP<const BlockMap_Type> BlockMapConstPtr_Type;
57 typedef Teuchos::Array<BlockMultiVectorPtr_Type> BlockMultiVectorPtrArray_Type;
58
59 using ThyraTypes = ThyraTypedefs<SC>;
60 using TpetraTypes = TpetraTypedefs<SC,LO,GO,NO>;
61 using ThyraVecSpace_Type = typename ThyraTypes::ThyraVecSpace_Type;
62 typedef Teuchos::RCP<const ThyraVecSpace_Type> ThyraVecSpaceConstPtr_Type;
63 using ThyraVec_Type = typename ThyraTypes::ThyraVec_Type;
64 using TpetraMatrix_Type = typename TpetraTypes::TpetraMatrix_Type;
65 using ThyraOp_Type = typename ThyraTypes::ThyraOp_Type;
66 using TpetraOp_Type = typename TpetraTypes::TpetraOp_Type;
67 typedef Thyra::BlockedLinearOpBase<SC> ThyraBlockOp_Type;
68
71 NonLinearProblem(CommConstPtr_Type comm);
72
76 NonLinearProblem(ParameterListPtr_Type &parameterList, CommConstPtr_Type comm);
77
79
80 virtual void info() = 0;
81
84
87 void initializeProblem(int nmbVectors=1);
88
91 virtual void assemble( std::string type = "" ) const = 0;
92
95 virtual void getValuesOfInterest( vec_dbl_Type& values ) = 0;
96
101 int solveAndUpdate( const std::string& criterion , double& criterionValue );
102
106
107
110 virtual void reAssemble( BlockMultiVectorPtr_Type previousSolution ) const = 0;
111
112 void reAssembleAndFill( BlockMatrixPtr_Type bMat, std::string type="FixedPoint" );
113
114 virtual void reAssembleExtrapolation(BlockMultiVectorPtrArray_Type previousSolutions) = 0;
115
118 void initializeVectorsNonLinear(int nmbVectors=1);
119
122 double calculateResidualNorm() const;
123
127 virtual void calculateNonLinResidualVec(std::string type="standard", double time=0.) const = 0; //type=standard or reverse
128
130 virtual void calculateNonLinResidualVec(SmallMatrix<double>& coeff, std::string type="standard", double time=0., BlockMatrixPtr_Type systemMass = Teuchos::null); //type=standard or reverse
131
134 BlockMultiVectorPtr_Type getResidualVector() const;
135
138 BlockMultiVectorPtr_Type getPreviousSolution() const{ return previousSolution_; }
139
140 virtual Thyra::ModelEvaluatorBase::InArgs<SC> getNominalValues() const;
141
142 virtual Teuchos::RCP<const ::Thyra::VectorSpaceBase<SC> > get_x_space() const;
143
144 virtual Teuchos::RCP<const ::Thyra::VectorSpaceBase<SC> > get_f_space() const;
145
146 virtual ::Thyra::ModelEvaluatorBase::InArgs<SC> createInArgs() const;
147
148 void initNOXParameters( );
149
150 void initVectorSpaces( );
151
152 void initVectorSpacesMonolithic( );
153
154 void initVectorSpacesBlock( );
155
156 virtual ::Thyra::ModelEvaluatorBase::OutArgs<SC> createOutArgsImpl() const;
157
158
159 void setNonlinearIterationStep(int newtonStep) { this->newtonStep_ = newtonStep;} // For SolveFixedPoint etc. we need to set the Newton Step manually
160 int getNonlinearIterationStep() const override { return newtonStep_; } // This overrides the default in Problem to provide the actual Newton step
161
162
163 double nonLinearTolerance_;
164 BlockMultiVectorPtr_Type previousSolution_;
165 mutable BlockMultiVectorPtr_Type residualVec_;
166 SmallMatrix<double> coeff_;// coefficients for a time-dependent problem
167
168 mutable int newtonStep_;
169
170 Teuchos::RCP< Thyra::LinearOpBase<SC> > create_W_op() const;
171 Teuchos::RCP< Thyra::LinearOpBase<SC> > create_W_op_Monolithic() const;
172#ifdef FEDD_HAVE_TEKO
173 Teuchos::RCP< Thyra::LinearOpBase<SC> > create_W_op_Block() const;
174#endif
175 Teuchos::RCP<Thyra::PreconditionerBase<SC> > create_W_prec() const;
176
177
178private:
179 mutable bool precInitOnly_; //Help variable to signal that we constructed the initial preconditioner
180 // for NOX already and we do not need to compute it if fill_W_prec is
181 // called for the first time. However, the preconditioner is only correct
182 // if a linear system is solved in the first nonlinear iteration.
183
184
185 Thyra::ModelEvaluatorBase::InArgs<SC> nominalValues_;
186
187 Thyra::ModelEvaluatorBase::InArgs<SC> prototypeInArgs_;
188 Thyra::ModelEvaluatorBase::OutArgs<SC> prototypeOutArgs_;
189
190 Teuchos::RCP<const ThyraVecSpace_Type> xSpace_;
191 Teuchos::RCP<const ThyraVecSpace_Type> fSpace_;
192
193 Teuchos::RCP<ThyraVec_Type> x0_;
194
195 virtual void evalModelImpl(
196 const ::Thyra::ModelEvaluatorBase::InArgs<SC> &inArgs,
197 const ::Thyra::ModelEvaluatorBase::OutArgs<SC> &outArgs
198 ) const;
199
200 void evalModelImplMonolithic(const ::Thyra::ModelEvaluatorBase::InArgs<SC> &inArgs,
201 const ::Thyra::ModelEvaluatorBase::OutArgs<SC> &outArgs) const;
202
203#ifdef FEDD_HAVE_TEKO
204 void evalModelImplBlock(const ::Thyra::ModelEvaluatorBase::InArgs<SC> &inArgs,
205 const ::Thyra::ModelEvaluatorBase::OutArgs<SC> &outArgs) const;
206#endif
207
208
209
210};
211}
212
213#endif
Block Variant of Map class.
Definition BlockMap_decl.hpp:38
void initializeVectorsNonLinear(int nmbVectors=1)
Initialisation of the non-linear vectors like residual and previous solution.
Definition NonLinearProblem_def.hpp:60
BlockMultiVectorPtr_Type getResidualVector() const
Get the residual vector.
Definition NonLinearProblem_def.hpp:172
virtual void assemble(std::string type="") const =0
assemble of type exectuted by the derived specific non-linear problem classes
NonLinearProblem(ParameterListPtr_Type &parameterList, CommConstPtr_Type comm)
Constructor with parameterlist.
Definition NonLinearProblem_def.hpp:32
void initializeProblem(int nmbVectors=1)
Initialisation of the non-linear problem with system, vectors, and Thyra vector spaces for NOX.
Definition NonLinearProblem_def.hpp:45
virtual void calculateNonLinResidualVec(SmallMatrix< double > &coeff, std::string type="standard", double time=0., BlockMatrixPtr_Type systemMass=Teuchos::null)
Calculate the non-linear residual vector with given coefficients for time-dependent problems (if used...
Definition NonLinearProblem_def.hpp:105
int getNonlinearIterationStep() const override
Definition NonLinearProblem_decl.hpp:160
int solveUpdate()
This is where the linear solve specifically happens.
Definition NonLinearProblem_def.hpp:143
virtual void reAssemble(BlockMultiVectorPtr_Type previousSolution) const =0
Reassemble with previous solution. I think it is not used anymore. @TODO: Look into this.
virtual void getValuesOfInterest(vec_dbl_Type &values)=0
Virtual class to extract values of interest that are computed during the solve.
Teuchos::RCP< Thyra::LinearOpBase< SC > > create_W_op() const
Block Approach for Nonlinear Solver NOX. Input. Includes calculation of the residual vector and updat...
Definition NonLinearProblem_def.hpp:578
double calculateResidualNorm() const
Calculate the 2-norm of the residual vector.
Definition NonLinearProblem_def.hpp:133
NonLinearProblem(CommConstPtr_Type comm)
Constructor.
Definition NonLinearProblem_def.hpp:23
BlockMultiVectorPtr_Type getPreviousSolution() const
Get previous solution. Needed for time-dependent problems.
Definition NonLinearProblem_decl.hpp:138
int solveAndUpdate(const std::string &criterion, double &criterionValue)
Solving the non-linear problem and updating the solution.
Definition NonLinearProblem_def.hpp:155
virtual void calculateNonLinResidualVec(std::string type="standard", double time=0.) const =0
Virtual function which is implemented in the specific non-linear problem classes to calculate the non...
void infoNonlinProblem()
Information about the non-linear problem.
Definition NonLinearProblem_def.hpp:91
This class represents a templated small Matrix of type T. Primarily created for 2x2 and 3x3 matrices....
Definition SmallMatrix.hpp:20
Adaptive Mesh Refinement.
Definition AdaptiveMeshRefinement_decl.hpp:36
Definition FEDDCore.hpp:141
Definition FEDDCore.hpp:148