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