Finite Element Domain Decomposition Library
FEDDLib
Loading...
Searching...
No Matches
TimeProblem_decl.hpp
1#ifndef TIMEPROBLEM_DECL_hpp
2#define TIMEPROBLEM_DECL_hpp
3
4#include "feddlib/problems/problems_config.h"
5#include "feddlib/core/FEDDCore.hpp"
6#include "feddlib/core/General/DefaultTypeDefs.hpp"
7#include "feddlib/problems/Solver/Preconditioner.hpp"
8#include "NonLinearProblem.hpp"
9//#include "LinearProblem.hpp"
10#include <Thyra_StateFuncModelEvaluatorBase.hpp>
19
20
21/*
22 If nonlinear iterative scheme is used, assemble() always assembles the Oseen system (FixedPoint).
23 reAssemble("Newton") then assembles the Newton system. We need to adapt the functionality to general systems/problems
24 */
25namespace FEDD {
26template<class SC_, class LO_, class GO_, class NO_>
28template<class SC_, class LO_, class GO_, class NO_>
29//class LinearProblem;
30//template<class SC_, class LO_, class GO_, class NO_>
31class Preconditioner;
32template <class SC = default_sc, class LO = default_lo, class GO = default_go, class NO = default_no>
33class TimeProblem: public Thyra::StateFuncModelEvaluatorBase<SC> {
34
35public:
36
37 typedef Problem<SC,LO,GO,NO> Problem_Type;
38 typedef Teuchos::RCP<Problem_Type> ProblemPtr_Type;
39 typedef typename Problem_Type::CommConstPtr_Type CommConstPtr_Type;
40
41 typedef typename Problem_Type::Map_Type Map_Type;
42 typedef typename Problem_Type::MapPtr_Type MapPtr_Type;
43 typedef typename Problem_Type::MapConstPtr_Type MapConstPtr_Type;
44
45 typedef typename Problem_Type::Matrix_Type Matrix_Type;
46 typedef typename Problem_Type::MatrixPtr_Type MatrixPtr_Type;
47 typedef Teuchos::RCP<const Matrix_Type> MatrixConstPtr_Type;
48
49 typedef typename Problem_Type::BlockMatrix_Type BlockMatrix_Type;
50 typedef typename Problem_Type::BlockMatrixPtr_Type BlockMatrixPtr_Type;
51 typedef typename Problem_Type::BlockMatrixConstPtr_Type BlockMatrixConstPtr_Type;
52 typedef Teuchos::Array<BlockMatrixPtr_Type> BlockMatrixPtrArray_Type;
53
54 typedef typename Problem_Type::MultiVector_Type MultiVector_Type;
55 typedef typename Problem_Type::MultiVectorPtr_Type MultiVectorPtr_Type;
56
57 typedef typename Problem_Type::BlockMultiVector_Type BlockMultiVector_Type;
58 typedef typename Problem_Type::BlockMultiVectorPtr_Type BlockMultiVectorPtr_Type;
59 typedef typename Problem_Type::BlockMultiVectorConstPtr_Type BlockMultiVectorConstPtr_Type;
60 typedef Teuchos::Array<BlockMultiVectorPtr_Type> BlockMultiVectorPtrArray_Type;
61
62 typedef typename Problem_Type::DomainConstPtr_Type DomainConstPtr_Type;
63
64 typedef typename Problem_Type::FEFac_Type FEFac_Type;
65 typedef Teuchos::RCP<FEFac_Type> FEFacPtr_Type;
66 typedef Teuchos::RCP<const FEFac_Type> FEFacConstPtr_Type;
67 typedef typename Problem_Type::BCConstPtr_Type BCConstPtr_Type;
68
69 typedef NonLinearProblem<SC,LO,GO,NO> NonLinProb_Type;
70 typedef Teuchos::RCP<NonLinProb_Type> NonLinProbPtr_Type;
71// typedef LinearProblem<SC,LO,GO,NO> LinearProblem_Type;
72
73 typedef typename Problem_Type::Preconditioner_Type Preconditioner_Type;
74 typedef typename Problem_Type::PreconditionerPtr_Type PreconditionerPtr_Type;
75
76 typedef typename Problem_Type::LinSolverBuilderPtr_Type LinSolverBuilderPtr_Type;
77
78 typedef typename NonLinProb_Type::TpetraMatrix_Type TpetraMatrix_Type;
79
80 typedef typename NonLinProb_Type::ThyraVecSpace_Type ThyraVecSpace_Type;
81 typedef typename NonLinProb_Type::ThyraVec_Type ThyraVec_Type;
82 typedef typename NonLinProb_Type::ThyraOp_Type ThyraOp_Type;
83 typedef Thyra::BlockedLinearOpBase<SC> ThyraBlockOp_Type;
84
85 typedef typename NonLinProb_Type::TpetraOp_Type TpetraOp_Type;
86
87 TimeProblem(Problem_Type& problem, CommConstPtr_Type comm);
88
89 void setTimeDef( SmallMatrix<int>& def );
90
91 void assemble(std::string type="") const;
92
93 virtual void reAssembleAndFill( BlockMatrixPtr_Type bMat, std::string type="FixedPoint" );
94
95 void updateRhs();
96
97 void updateMultistepRhs(vec_dbl_Type& coeff, int nmbToUse);
98
99 // Mit Massematrix aus vorherigen Zeitschritten
100 void updateMultistepRhsFSI(vec_dbl_Type& coeff, int nmbToUse);
101
102 // Stelle die rechte Seite des zeitdiskretisierten Systems auf (ohne f_{n+1}).
103 // Bei Newmark lautet dies:
104 // M*[\frac{1}{dt^2*beta}*u_n + \frac{1}{dt*beta}*u'_n + \frac{0.5 - beta}{beta}*u''_n],
105 // wobei u' = v (velocity) und u'' = w (acceleration).
106 void updateNewmarkRhs(double dt, double beta, double gamma, vec_dbl_Type coeff);
107
108 void combineSystems() const;
109
110 void initializeCombinedSystems() const;
111
112 void assembleMassSystem( ) const;
113
114 void setTimeParameters(SmallMatrix<double> &daeParameters, SmallMatrix<double> &timeParameters);
115
116 int solveAndUpdate( const std::string& criterion, double& criterionValue );
117
118 int solveUpdate();
119
120 int update();
121
122 int solve( BlockMultiVectorPtr_Type rhs = Teuchos::null );
123
124 double calculateResidualNorm();
125
126 void calculateNonLinResidualVec(std::string type="standard", double time=0.) const;
127
128 bool getVerbose();
129
130 void addBoundaries(BCConstPtr_Type bcFactory);
131
132 void setBoundaries(double time=.0);
133
134 void setBoundariesRHS(double time=.0);
135
136 void setBoundariesSystem() const;
137
138// void assembleExternal( std::string type ) const;
139
140 BlockMultiVectorPtr_Type getRhs();
141
142 BlockMultiVectorPtr_Type getRhs() const;
143
144 BlockMultiVectorPtr_Type getSolution();
145
146 BlockMultiVectorConstPtr_Type getSolutionConst() const;
147
148 BlockMultiVectorPtr_Type getResidual();
149
150 BlockMultiVectorConstPtr_Type getResidualConst() const;
151
152 DomainConstPtr_Type getDomain(int i) const;
153
154 std::string getFEType(int i);
155
156 std::string getVariableName(int i);
157
158 int getDofsPerNode(int i);
159
160 BlockMatrixPtr_Type getSystem();
161
162 BlockMatrixPtr_Type getSystemCombined();
163
164 BlockMatrixPtr_Type getSystemCombined() const;
165
166 ProblemPtr_Type getUnderlyingProblem();
167
168 void updateSolutionPreviousStep();
169
170 void updateSolutionMultiPreviousStep(int nmbSteps);
171
172 void updateSystemMassMultiPreviousStep(int nmbSteps);
173
174 // Verschiebung (u), Geschwindigkeit (u' = v) und Beschleunigung (u'' = w)
175 // mit Hilfe der Newmark-Vorschrift aktualisieren.
176 // BEACHTE: Wir haben u als primaere Variable (die Variable nach der das GLS geloest wird),
177 // anstatt klassischerweise u''. Fuer die Umformungen siehe MA.
178 void updateSolutionNewmarkPreviousStep(double dt, double beta, double gamma);
179
180 BlockMultiVectorPtr_Type getSolutionPreviousTimestep();
181
182 BlockMultiVectorPtrArray_Type getSolutionAllPreviousTimestep();
183
184 BlockMatrixPtr_Type getMassSystem();
185
186 ParameterListPtr_Type getParameterList();
187
188 void assembleSourceTerm( double time=0. );
189
190 BlockMultiVectorPtr_Type getSourceTerm( );
191
192 bool hasSourceTerm() const;
193
194 CommConstPtr_Type getComm() const{return comm_;};
195
196 LinSolverBuilderPtr_Type getLinearSolverBuilder() const;
197
198 void getValuesOfInterest( vec_dbl_Type& values );
199
200 void computeValuesOfInterestAndExport();
201
202 void updateTime( double time ){ time_ = time;};
203
204 void addToRhs(BlockMultiVectorPtr_Type x);
205
206 ProblemPtr_Type problem_;
207 CommConstPtr_Type comm_;
208
209 mutable BlockMatrixPtr_Type systemCombined_;
210 mutable BlockMatrixPtr_Type systemMass_;
211 mutable SmallMatrix<double> timeParameters_;
212 SmallMatrix<int> timeStepDef_;
213 SmallMatrix<double> massParameters_;
214
215 FEFacPtr_Type feFactory_;
216// bool boolLinearProblem_;
217 int dimension_;
218 bool verbose_;
219 ParameterListPtr_Type parameterList_;
220 mutable BCConstPtr_Type bcFactory_;
221 bool massBCSet_;
222 BlockMultiVectorPtrArray_Type solutionPreviousTimesteps_;
223// std::vector<MultiVector_ptr_Type> solutionPreviousTimesteps_;
224
225 // ###########################
226 // Fuer das Newmark-Verfahren
227 // ###########################
228 BlockMultiVectorPtrArray_Type velocityPreviousTimesteps_; // entspricht u' bzw. v
229 BlockMultiVectorPtrArray_Type accelerationPreviousTimesteps_; // entspricht u'' bzw. w
230
231 // ###########################
232 // Fuer FSI
233 // ###########################
234 BlockMatrixPtrArray_Type systemMassPreviousTimeSteps_;
235
236 double time_;
237protected:
238#define TIMEPROBLEM_TIMER
239#ifdef TIMEPROBLEM_TIMER
240 TimePtr_Type TimeSolveTimer_;
241#endif
242
243 // Functions used for NOX.
244public:
245
246 virtual Thyra::ModelEvaluatorBase::InArgs<SC> getNominalValues() const;
247
248 virtual Teuchos::RCP<const ::Thyra::VectorSpaceBase<SC> > get_x_space() const;
249
250 virtual Teuchos::RCP<const ::Thyra::VectorSpaceBase<SC> > get_f_space() const;
251
252 virtual ::Thyra::ModelEvaluatorBase::InArgs<SC> createInArgs() const;
253
254 virtual ::Thyra::ModelEvaluatorBase::OutArgs<SC> createOutArgsImpl() const;
255
256// void initNOXParameters();
257//
258// void initVectorSpaces( );
259//
260// void initVectorSpacesMonolithic( );
261//
262// void initVectorSpacesBlock( );
263
264 Teuchos::RCP< Thyra::LinearOpBase<SC> > create_W_op() ;
265
266 Teuchos::RCP< Thyra::LinearOpBase<SC> > create_W_op_Monolithic() ;
267
268 Teuchos::RCP< Thyra::LinearOpBase<SC> > create_W_op_Block() ;
269
270 Teuchos::RCP<Thyra::PreconditionerBase<SC> > create_W_prec() ;
271
272 std::string description() const; //reimplement description function and use description of underlying nonLinearProblem
273private:
274
275 virtual void evalModelImpl(
276 const ::Thyra::ModelEvaluatorBase::InArgs<SC> &inArgs,
277 const ::Thyra::ModelEvaluatorBase::OutArgs<SC> &outArgs
278 ) const;
279
280 void evalModelImplMonolithic(const ::Thyra::ModelEvaluatorBase::InArgs<SC> &inArgs,
281 const ::Thyra::ModelEvaluatorBase::OutArgs<SC> &outArgs) const;
282
283 void evalModelImplBlock(const ::Thyra::ModelEvaluatorBase::InArgs<SC> &inArgs,
284 const ::Thyra::ModelEvaluatorBase::OutArgs<SC> &outArgs) const;
285
286 mutable bool precInitOnly_; //Help variable to signal that we constructed the initial preconditioner for NOX with the Stokes system and we do not need to compute it if fill_W_prec is called for the first time. However, the preconditioner is only correct if a Stokes system is solved in the first nonlinear iteration. This only affects the block preconditioners of Teko
287
288};
289}
290
291#endif
Definition NonLinearProblem_decl.hpp:24
Definition Preconditioner_decl.hpp:41
Definition Problem_decl.hpp:38
This class represents a templated small Matrix of type T. Primarily created for 2x2 and 3x3 matrices....
Definition SmallMatrix.hpp:22
Adaptive Mesh Refinement.
Definition AdaptiveMeshRefinement.cpp:5