1#ifndef DAESOLVERINTIME_DEF_hpp
2#define DAESOLVERINTIME_DEF_hpp
5#include "feddlib/problems/specific/FSI.hpp"
6#include "feddlib/core/Mesh/MeshUnstructured.hpp"
7#include "feddlib/core/FE/Domain.hpp"
8#include "feddlib/core/FE/FE.hpp"
22template<
class SC,
class LO,
class GO,
class NO>
23DAESolverInTime<SC,LO,GO,NO>::DAESolverInTime( CommConstPtr_Type comm ):
25verbose_(comm->getRank()==0),
27isTimeSteppingDefined_(false),
33export_solution_vector_(),
34boolExporterSetup_(false)
36,solveProblemTimer_ (Teuchos::TimeMonitor::getNewCounter(
"FEDD - DAETime - Solve Problem"))
38#ifdef FEDD_DETAIL_TIMER
39,reassmbleAddInterfaceRHSTimer_(Teuchos::TimeMonitor::getNewCounter(
"FEDD - DAETime Detail - FSI Interface RHS"))
40,reassmbleUpdateMeshDisplacementTimer_(Teuchos::TimeMonitor::getNewCounter(
"FEDD - DAETime Detail - FSI Update Mesh Displ."))
41,reassmbleSolveGeometryTimer_(Teuchos::TimeMonitor::getNewCounter(
"FEDD - DAETime Detail - FSI Solve Geometry"))
42,reassmbleMoveMeshTimer_(Teuchos::TimeMonitor::getNewCounter(
"FEDD - DAETime Detail - FSI Move Mesh"))
43,reassmbleSolidMassAndRHSTimer_(Teuchos::TimeMonitor::getNewCounter(
"FEDD - DAETime Detail - FSI Assemble Solid Massmatrix and RHS"))
44,reassmbleForTimeTimer_(Teuchos::TimeMonitor::getNewCounter(
"FEDD - DAETime Detail - FSI Assemble Fluid Problem (steady Navier-Stokes)"))
45,reassmbleUpdateFluidInTimeTimer_(Teuchos::TimeMonitor::getNewCounter(
"FEDD - DAETime Detail - FSI Update Fluid Solution"))
52template<
class SC,
class LO,
class GO,
class NO>
53DAESolverInTime<SC,LO,GO,NO>::DAESolverInTime( ParameterListPtr_Type ¶meterList, CommConstPtr_Type comm):
55verbose_(comm->getRank()==0),
56parameterList_(parameterList),
57isTimeSteppingDefined_(false),
63export_solution_vector_(),
64boolExporterSetup_(false)
66,solveProblemTimer_ (Teuchos::TimeMonitor::getNewCounter(
"FEDD - DAETime - Solve Problem"))
68#ifdef FEDD_DETAIL_TIMER
69,reassmbleAddInterfaceRHSTimer_(Teuchos::TimeMonitor::getNewCounter(
"FEDD - DAETime Detail - FSI Interface RHS"))
70,reassmbleUpdateMeshDisplacementTimer_(Teuchos::TimeMonitor::getNewCounter(
"FEDD - DAETime Detail - FSI Update Mesh Displ."))
71,reassmbleSolveGeometryTimer_(Teuchos::TimeMonitor::getNewCounter(
"FEDD - DAETime Detail - FSI Solve Geometry"))
72,reassmbleMoveMeshTimer_(Teuchos::TimeMonitor::getNewCounter(
"FEDD - DAETime Detail - FSI Move Mesh"))
73,reassmbleSolidMassAndRHSTimer_(Teuchos::TimeMonitor::getNewCounter(
"FEDD - DAETime Detail - FSI Assemble Solid Massmatrix and RHS"))
74,reassmbleForTimeTimer_(Teuchos::TimeMonitor::getNewCounter(
"FEDD - DAETime Detail - FSI Assemble Fluid Problem (steady Navier-Stokes)"))
75,reassmbleUpdateFluidInTimeTimer_(Teuchos::TimeMonitor::getNewCounter(
"FEDD - DAETime Detail - FSI Update Fluid Solution"))
82template<
class SC,
class LO,
class GO,
class NO>
83DAESolverInTime<SC,LO,GO,NO>::DAESolverInTime( SmallMatrix<int> &timeStepDef, ParameterListPtr_Type ¶meterList, CommConstPtr_Type comm):
85verbose_(comm->getRank()==0),
86parameterList_(parameterList),
87isTimeSteppingDefined_(false),
93export_solution_vector_(),
94boolExporterSetup_(false)
96,solveProblemTimer_ (Teuchos::TimeMonitor::getNewCounter(
"FEDD - DAETime - Solve Problem"))
98#ifdef FEDD_DETAIL_TIMER
99,reassmbleAddInterfaceRHSTimer_(Teuchos::TimeMonitor::getNewCounter(
"FEDD - DAETime Detail - FSI Interface RHS"))
100,reassmbleUpdateMeshDisplacementTimer_(Teuchos::TimeMonitor::getNewCounter(
"FEDD - DAETime Detail - FSI Update Mesh Displ."))
101,reassmbleSolveGeometryTimer_(Teuchos::TimeMonitor::getNewCounter(
"FEDD - DAETime Detail - FSI Solve Geometry"))
102,reassmbleMoveMeshTimer_(Teuchos::TimeMonitor::getNewCounter(
"FEDD - DAETime Detail - FSI Move Mesh"))
103,reassmbleSolidMassAndRHSTimer_(Teuchos::TimeMonitor::getNewCounter(
"FEDD - DAETime Detail - FSI Assemble Solid Massmatrix and RHS"))
104,reassmbleForTimeTimer_(Teuchos::TimeMonitor::getNewCounter(
"FEDD - DAETime Detail - FSI Assemble Fluid Problem (steady Navier-Stokes)"))
105,reassmbleUpdateFluidInTimeTimer_(Teuchos::TimeMonitor::getNewCounter(
"FEDD - DAETime Detail - FSI Update Fluid Solution"))
109 this->defineTimeStepping(timeStepDef);
112template<
class SC,
class LO,
class GO,
class NO>
113DAESolverInTime<SC,LO,GO,NO>::~DAESolverInTime(){
118template<
class SC,
class LO,
class GO,
class NO>
119void DAESolverInTime<SC,LO,GO,NO>::setProblem(Problem_Type& problem){
121 problem_ = Teuchos::rcpFromRef(problem);
125template<
class SC,
class LO,
class GO,
class NO>
126void DAESolverInTime<SC,LO,GO,NO>::defineTimeStepping(SmallMatrix<int> &timeStepDef){
128 timeStepDef_ = timeStepDef;
129 timeSteppingTool_.reset(
new TimeSteppingTools(sublist(parameterList_,
"Timestepping Parameter") , comm_));
130 isTimeSteppingDefined_ =
true;
135template<
class SC,
class LO,
class GO,
class NO>
136void DAESolverInTime<SC,LO,GO,NO>::advanceInTime(){
138 TEUCHOS_TEST_FOR_EXCEPTION(problemTime_.is_null(), std::logic_error,
"Mass system is null.");
140 checkTimeSteppingDef();
142 if(this->parameterList_->sublist(
"Parameter").get(
"FSI",
false))
147 if (!parameterList_->sublist(
"Timestepping Parameter").get(
"Class",
"Singlestep").compare(
"Loadstepping")) {
148 NonLinProbPtr_Type nonLinProb = Teuchos::rcp_dynamic_cast<NonLinProb_Type>(problem_);
149 if (nonLinProb.is_null()){
150 TEUCHOS_TEST_FOR_EXCEPTION(
true, std::runtime_error,
"Loadstepping only available to nonlinear Problems. (It is a tool to increase Nonlinear Solver convergence.)");
153 advanceWithLoadStepping();
156 if (!parameterList_->sublist(
"Timestepping Parameter").get(
"Class",
"Singlestep").compare(
"Singlestep")) {
157 NonLinProbPtr_Type nonLinProb = Teuchos::rcp_dynamic_cast<NonLinProb_Type>(problem_);
158 if (nonLinProb.is_null()) {
159 advanceInTimeLinear();
162 advanceInTimeNonLinear();
165 else if(!parameterList_->sublist(
"Timestepping Parameter").get(
"Class",
"Singlestep").compare(
"Newmark"))
167 NonLinProbPtr_Type nonLinProb = Teuchos::rcp_dynamic_cast<NonLinProb_Type>(problem_);
168 if (nonLinProb.is_null()) {
169 advanceInTimeLinearNewmark();
173 advanceInTimeNonLinearNewmark();
176 else if( !parameterList_->sublist(
"Timestepping Parameter").get(
"Class",
"Singlestep").compare(
"Multistep") ){
177 NonLinProbPtr_Type nonLinProb = Teuchos::rcp_dynamic_cast<NonLinProb_Type>(problem_);
178 if (nonLinProb.is_null()) {
179 advanceInTimeLinearMultistep();
182 advanceInTimeNonLinearMultistep();
185 else if( !parameterList_->sublist(
"Timestepping Parameter").get(
"Class",
"Singlestep").compare(
"External") ){
186 NonLinProbPtr_Type nonLinProb = Teuchos::rcp_dynamic_cast<NonLinProb_Type>(problem_);
187 if (nonLinProb.is_null()) {
188 advanceInTimeLinearExternal();
191 advanceInTimeNonLinearExternal();
195 TEUCHOS_TEST_FOR_EXCEPTION(
true, std::runtime_error,
"Unknown time discretization type.");
201template<
class SC,
class LO,
class GO,
class NO>
202void DAESolverInTime<SC,LO,GO,NO>::advanceInTimeLinear(){
205 bool print = parameterList_->sublist(
"General").get(
"ParaViewExport",
false);
208 bool fullImplicitPressure =
false;
209 int size = timeStepDef_.size();
211 while (timeSteppingTool_->continueTimeStepping()) {
212 problemTime_->updateTime ( timeSteppingTool_->currentTime() );
213 dt = timeSteppingTool_->get_dt();
214 problemTime_->updateSolutionPreviousStep();
216 Teuchos::Array<BlockMatrixPtr_Type> bMatNonLin_vec_allstages;
217 BlockMultiVectorPtrArray_Type solutionRK_stages;
218 BlockMultiVectorPtrArray_Type sourceTermRK_stages;
220 for (
int s=0; s<timeSteppingTool_->getNmbStages(); s++) {
221 double time = timeSteppingTool_->currentTime() + dt * timeSteppingTool_->getButcherTableC(s);
223 std::cout <<
"Currently in stage " << s+1 <<
" of "<< timeSteppingTool_->getNmbStages() << std::endl;
225 problemTime_->updateRhs();
226 if ( problemTime_->hasSourceTerm() ){
227 TEUCHOS_TEST_FOR_EXCEPTION(
true, std::runtime_error,
"Fix source term.");
228 problemTime_->assembleSourceTerm( time );
231 if (s==0 && timeSteppingTool_->getButcherTableCoefficient(s , s) == 0.0) {
234 else if (s==0 && timeSteppingTool_->getButcherTableCoefficient(s , s) != 0.0) {
235 TEUCHOS_TEST_FOR_EXCEPTION(
true, std::logic_error,
"Not implemented butcher table!");
238 for (
int s_prior=0; s_prior<s; s_prior++) {
239 SmallMatrix<double> coeff(size);
240 for (
int i=0; i<size; i++) {
241 for (
int j=0; j<size; j++) {
242 if (timeStepDef_[i][j]>0) {
243 if (i==0 && j==1 && fullImplicitPressure) {
247 coeff[i][j] = - timeSteppingTool_->getButcherTableCoefficient(s , s_prior);
252 if (problemTime_->hasSourceTerm())
253 this->addRhsDAE(coeff, sourceTermRK_stages[s_prior] );
255 this->addRhsDAE( coeff, problemTime_->getSystem(), solutionRK_stages[s_prior] );
259 SmallMatrix<double> massCoeff(size);
260 SmallMatrix<double> problemCoeff(size);
261 double coeffSourceTerm = 0.;
262 for (
int i=0; i<size; i++) {
263 for (
int j=0; j<size; j++) {
264 if (timeStepDef_[i][j]>0 && i==j) {
265 massCoeff[i][j] = 1. / dt;
267 else if (timeStepDef_[i][j]==2)
268 massCoeff[i][j] = 1. / dt;
270 massCoeff[i][j] = 0.;
274 for (
int i=0; i<size; i++) {
275 for (
int j=0; j<size; j++){
276 if (timeStepDef_[i][j]>0){
277 if (i==0 && j==1 && fullImplicitPressure) {
278 problemCoeff[i][j] = 1.;
279 coeffSourceTerm = timeSteppingTool_->getButcherTableCoefficient(s , s);
282 problemCoeff[i][j] = timeSteppingTool_->getButcherTableCoefficient(s , s);
283 coeffSourceTerm = timeSteppingTool_->getButcherTableCoefficient(s , s);
287 problemCoeff[i][j] = 1.;
292 if (problemTime_->hasSourceTerm())
293 addSourceTermToRHS(coeffSourceTerm);
295 problemTime_->setTimeParameters(massCoeff, problemCoeff);
296 problemTime_->combineSystems();
297 problemTime_->setBoundaries(time);
299 problemTime_->solve();
303 if (s+1 == timeSteppingTool_->getNmbStages()) {
304 BlockMultiVectorPtr_Type tmpSolution = Teuchos::rcp(
new BlockMultiVector_Type ( problemTime_->getSolution() ) );
305 solutionRK_stages.push_back(tmpSolution);
306 BlockMultiVectorPtr_Type tmpSolutionPtr = problemTime_->getSolution();
307 BlockMatrixPtr_Type tmpMassSystem = problemTime_->getMassSystem();
308 timeSteppingTool_->calculateSolution( tmpSolutionPtr, solutionRK_stages, tmpMassSystem);
311 solutionRK_stages.push_back( problemTime_->getSolution() );
312 if ( problemTime_->hasSourceTerm() )
313 sourceTermRK_stages.push_back( problemTime_->getSourceTerm() );
317 timeSteppingTool_->advanceTime(
true);
326 if (parameterList_->sublist(
"NSParameter").get(
"Calculate Coefficients",
false)) {
327 TEUCHOS_TEST_FOR_EXCEPTION(
true, std::logic_error,
"close txt exporters here.");
331template<
class SC,
class LO,
class GO,
class NO>
332void DAESolverInTime<SC,LO,GO,NO>::getMassCoefficients(SmallMatrix<double> &massCoeff){
333 int size = timeStepDef_.size();
334 massCoeff.resize(size);
336 for (
int i=0; i<size; i++) {
337 for (
int j=0; j<size; j++) {
338 if (timeStepDef_[i][j]>0 && i==j)
339 massCoeff[i][j] = 1.;
341 massCoeff[i][j] = 0.;
346template<
class SC,
class LO,
class GO,
class NO>
347void DAESolverInTime<SC,LO,GO,NO>::getMultiStageCoefficients(SmallMatrix<double> &problemCoeff,
int stage,
int stagePrior,
bool forRhs){
348 int size = timeStepDef_.size();
349 problemCoeff.resize(size);
351 for (
int i=0; i<size; i++) {
352 for (
int j=0; j<size; j++) {
353 if (timeStepDef_[i][j]>0)
354 problemCoeff[i][j] = timeSteppingTool_->get_dt()* timeSteppingTool_->getButcherTableCoefficient(stage , stagePrior);
357 problemCoeff[i][j] = 0.;
359 problemCoeff[i][j] = 1.;
365template<
class SC,
class LO,
class GO,
class NO>
366void DAESolverInTime<SC,LO,GO,NO>::buildMultiStageRhs(
int stage, Teuchos::Array<BlockMatrixPtr_Type>& matrixPrevStages, BlockMultiVectorPtrArray_Type& solutionPrevStages ){
368 int size = timeStepDef_.size();
369 SmallMatrix<double> massCoeff(size);
370 SmallMatrix<double> problemCoeff(size);
372 getMassCoefficients(massCoeff);
374 problemTime_->setTimeParameters(massCoeff, problemCoeff);
375 problemTime_->updateRhs();
377 bool fullImplicitPressure = parameterList_->sublist(
"Timestepping Parameter").get(
"Full implicit pressure",
false);
378 for (
int prevStage=0; prevStage<stage; prevStage++) {
380 getMultiStageCoefficients(problemCoeff, stage, prevStage,
true);
381 if (fullImplicitPressure && size>1 )
382 problemCoeff[0][1] = 0.;
384 problemCoeff.scale(-1.);
386 TEUCHOS_TEST_FOR_EXCEPTION(problemTime_->hasSourceTerm(), std::logic_error,
"Using source term must be implemented for single-step methods.");
388 addRhsDAE( problemCoeff, matrixPrevStages[prevStage], solutionPrevStages[prevStage] );
395template<
class SC,
class LO,
class GO,
class NO>
396void DAESolverInTime<SC,LO,GO,NO>::advanceInTimeNonLinear(){
398 bool print = parameterList_->sublist(
"General").get(
"ParaViewExport",
false);
399 BlockMultiVectorPtr_Type solShort;
401 if (parameterList_->sublist(
"Timestepping Parameter").get(
"Print Solution Short",
false)) {
402 solShort = Teuchos::rcp(
new BlockMultiVector_Type (problemTime_->getSolution()) );
403 exportTimestep(solShort);
411 bool fullImplicitPressure = parameterList_->sublist(
"Timestepping Parameter").get(
"Full implicit pressure",
false);
412 bool semiImplicitPressure = parameterList_->sublist(
"Timestepping Parameter").get(
"Semi implicit pressure",
false);
413 bool correctPressure = parameterList_->sublist(
"Timestepping Parameter").get(
"Correct pressure",
false);
414 int size = timeStepDef_.size();
415 SmallMatrix<double> massCoeff(size);
416 SmallMatrix<double> problemCoeff(size);
419 while (timeSteppingTool_->continueTimeStepping()) {
421 dt = timeSteppingTool_->get_dt();
423 if(!parameterList_->sublist(
"General").get(
"Linearization",
"FixedPoint").compare(
"Extrapolation")) {
424 if (timeSteppingTool_->currentTime()!=0.)
425 problemTime_->updateSolutionMultiPreviousStep(2);
427 problemTime_->updateSolutionMultiPreviousStep(1);
430 problemTime_->updateSolutionPreviousStep();
436 TEUCHOS_TEST_FOR_EXCEPTION(timeSteppingTool_->getButcherTableCoefficient(0 , 0) != 0.0, std::logic_error,
"Not implemented butchertable! First stage should have 0 diagonal value");
438 std::cout <<
"Currently in stage " << 1 <<
" of "<< timeSteppingTool_->getNmbStages() <<
" (dummy stage)"<< std::endl;
440 Teuchos::Array<BlockMatrixPtr_Type> matrixPrevStages;
441 BlockMultiVectorPtrArray_Type solutionPrevStages;
443 BlockMatrixPtr_Type blockMatrix = Teuchos::rcp(
new BlockMatrix_Type( problemTime_->getSystem()->size() ) );
444 problemTime_->reAssembleAndFill( blockMatrix );
446 matrixPrevStages.push_back( blockMatrix );
448 BlockMultiVectorPtr_Type sol =
449 Teuchos::rcp(
new BlockMultiVector_Type( problemTime_->getSolution() ) );
450 solutionPrevStages.push_back( sol );
452 for (
int stage=1; stage<timeSteppingTool_->getNmbStages(); stage++) {
453 double time = timeSteppingTool_->currentTime() + dt * timeSteppingTool_->getButcherTableC(stage);
454 problemTime_->updateTime( time );
456 std::cout <<
"Currently in stage " << stage+1 <<
" of "<< timeSteppingTool_->getNmbStages() << std::endl;
458 buildMultiStageRhs( stage, matrixPrevStages, solutionPrevStages );
460 TEUCHOS_TEST_FOR_EXCEPTION(problemTime_->hasSourceTerm(), std::logic_error,
"Using source term must be implemented for single-step methods.");
464 SmallMatrix<double> massCoeff(size);
465 SmallMatrix<double> problemCoeff(size);
467 getMassCoefficients(massCoeff);
468 getMultiStageCoefficients(problemCoeff, stage, stage,
false);
469 if (fullImplicitPressure && size>1 )
470 problemCoeff[0][1] = timeSteppingTool_->get_dt();
472 problemTime_->setTimeParameters(massCoeff, problemCoeff);
474 NonLinearSolver<SC, LO, GO, NO> nlSolver(parameterList_->sublist(
"General").get(
"Linearization",
"FixedPoint"));
475 nlSolver.solve(*problemTime_,time);
477 if (correctPressure) {
478 TEUCHOS_TEST_FOR_EXCEPTION( !fullImplicitPressure && !semiImplicitPressure, std::logic_error,
"There is no pressure that can be corrected." );
480 MultiVectorPtr_Type sol = problemTime_->getSolution()->getBlockNonConst(1);
481 MultiVectorConstPtr_Type solLast = problemTime_->getSolutionPreviousTimestep()->getBlock(1);
482 timeSteppingTool_->correctPressure( sol, solLast );
484 std::cout <<
"Pressure corrected." << std::endl;
487 if (stage+1 == timeSteppingTool_->getNmbStages()) {
489 BlockMultiVectorPtr_Type tmpSolution = Teuchos::rcp(
new BlockMultiVector_Type ( problemTime_->getSolution() ) );
491 solutionPrevStages.push_back( tmpSolution );
492 BlockMultiVectorPtr_Type tmpSolutionPtr = problemTime_->getSolution();
493 BlockMatrixPtr_Type tmpMassSystem = problemTime_->getMassSystem();
494 timeSteppingTool_->calculateSolution( tmpSolutionPtr, solutionPrevStages, tmpMassSystem, solShort);
497 BlockMatrixPtr_Type blockMatrix = Teuchos::rcp(
new BlockMatrix_Type( problemTime_->getSystem()->size() ) );
498 problemTime_->reAssembleAndFill( blockMatrix );
499 matrixPrevStages.push_back( blockMatrix );
501 BlockMultiVectorPtr_Type sol =
502 Teuchos::rcp(
new BlockMultiVector_Type( problemTime_->getSolution() ) );
503 solutionPrevStages.push_back( sol );
505 TEUCHOS_TEST_FOR_EXCEPTION(problemTime_->hasSourceTerm(), std::logic_error,
"Using source term must be implemented for single-step methods.");
509 timeSteppingTool_->advanceTime(
true);
514 if (parameterList_->sublist(
"NSParameter").get(
"Calculate Coefficients",
false)) {
515 vec_dbl_ptr_Type values(
new vec_dbl_Type(4));
516 TEUCHOS_TEST_FOR_EXCEPTION(
true, std::logic_error,
"Drag and Lift are not implemented.");
524 if (parameterList_->sublist(
"NSParameter").get(
"Calculate Coefficients",
false)) {
525 TEUCHOS_TEST_FOR_EXCEPTION(
true, std::logic_error,
"close txt exporters here.");
532template<
class SC,
class LO,
class GO,
class NO>
533void DAESolverInTime<SC,LO,GO,NO>::advanceWithLoadStepping()
536 bool print = parameterList_->sublist(
"General").get(
"ParaViewExport",
false);
537 bool printExtraData = parameterList_->sublist(
"General").get(
"Export Extra Data",
false);
538 bool printData = parameterList_->sublist(
"General").get(
"Export Data",
false);
544 vec_dbl_ptr_Type its = Teuchos::rcp(
new vec_dbl_Type ( 2, 0. ) );
545 ExporterTxtPtr_Type exporterTimeTxt;
546 ExporterTxtPtr_Type exporterIterations;
547 ExporterTxtPtr_Type exporterNewtonIterations;
549 std::string suffix = parameterList_->sublist(
"General").get(
"Export Suffix",
"");
551 exporterTimeTxt = Teuchos::rcp(
new ExporterTxt());
552 exporterTimeTxt->setup(
"time" + suffix, this->comm_ );
554 exporterNewtonIterations = Teuchos::rcp(
new ExporterTxt());
555 exporterNewtonIterations->setup(
"newtonIterations" + suffix, this->comm_ );
557 exporterIterations = Teuchos::rcp(
new ExporterTxt());
558 exporterIterations->setup(
"linearIterations" + suffix, this->comm_ );
561 int size = timeStepDef_.size();
562 TEUCHOS_TEST_FOR_EXCEPTION( size>1, std::runtime_error,
"Loadstepping only implemented or sensible for 1x1 Systems.");
563 double dt = timeSteppingTool_->get_dt();
567 SmallMatrix<double> massCoeff(size);
568 SmallMatrix<double> problemCoeff(size);
569 double coeffSourceTerm = 0.0;
572 massCoeff[0][0] = 0.;
573 problemCoeff[0][0] = 1.0;
575 coeffSourceTerm = 1.0;
578 vec_dbl_Type coeffTemp(1);
579 coeffTemp.at(0) = 1.0;
585 problemTime_->setTimeParameters(massCoeff, problemCoeff);
591 while(timeSteppingTool_->continueTimeStepping())
597 double time = timeSteppingTool_->currentTime() + dt;
598 problemTime_->updateTime ( time );
600 NonLinearSolver<SC, LO, GO, NO> nlSolver(parameterList_->sublist(
"General").get(
"Linearization",
"Newton"));
601 nlSolver.solve( *problemTime_, time, its );
603 timeSteppingTool_->advanceTime(
true);
605 exporterTimeTxt->exportData( timeSteppingTool_->currentTime() );
606 exporterIterations->exportData( (*its)[0] );
607 exporterNewtonIterations->exportData( (*its)[1] );
612 this->problemTime_->assemble(
"UpdateTime");
624template<
class SC,
class LO,
class GO,
class NO>
625void DAESolverInTime<SC,LO,GO,NO>::advanceInTimeLinearNewmark()
631 bool print = parameterList_->sublist(
"General").get(
"ParaViewExport",
false);
638 int size = timeStepDef_.size();
639 TEUCHOS_TEST_FOR_EXCEPTION( size>1, std::runtime_error,
"Newmark only implemented for systems of size 1x1.");
640 double dt = timeSteppingTool_->get_dt();
641 double beta = timeSteppingTool_->get_beta();
642 double gamma = timeSteppingTool_->get_gamma();
645 SmallMatrix<double> massCoeff(size);
646 SmallMatrix<double> problemCoeff(size);
647 double coeffSourceTerm = 0.0;
650 massCoeff[0][0] = 1.0/(dt*dt*beta);
651 problemCoeff[0][0] = 1.0;
653 coeffSourceTerm = 1.0;
656 vec_dbl_Type coeffTemp(1);
657 coeffTemp.at(0) = 1.0;
663 problemTime_->setTimeParameters(massCoeff, problemCoeff);
668 while(timeSteppingTool_->continueTimeStepping())
671 problemTime_->combineSystems();
674 problemTime_->updateSolutionNewmarkPreviousStep(dt, beta, gamma);
676 double time = timeSteppingTool_->currentTime() + dt;
677 problemTime_->updateTime ( timeSteppingTool_->currentTime() );
682 problemTime_->updateNewmarkRhs(dt, beta, gamma, coeffTemp);
686 if ( problemTime_->hasSourceTerm() )
689 problemTime_->assembleSourceTerm(time);
693 addSourceTermToRHS(coeffSourceTerm);
697 problemTime_->setBoundaries(time);
698 problemTime_->solve();
700 timeSteppingTool_->advanceTime(
true);
718template<
class SC,
class LO,
class GO,
class NO>
719void DAESolverInTime<SC,LO,GO,NO>::advanceInTimeNonLinearNewmark()
722 bool print = parameterList_->sublist(
"General").get(
"ParaViewExport",
false);
723 bool printExtraData = parameterList_->sublist(
"General").get(
"Export Extra Data",
false);
724 bool printData = parameterList_->sublist(
"General").get(
"Export Data",
false);
730 vec_dbl_ptr_Type its = Teuchos::rcp(
new vec_dbl_Type ( 2, 0. ) );
731 ExporterTxtPtr_Type exporterTimeTxt;
732 ExporterTxtPtr_Type exporterIterations;
733 ExporterTxtPtr_Type exporterNewtonIterations;
735 std::string suffix = parameterList_->sublist(
"General").get(
"Export Suffix",
"");
737 exporterTimeTxt = Teuchos::rcp(
new ExporterTxt());
738 exporterTimeTxt->setup(
"time" + suffix, this->comm_ );
740 exporterNewtonIterations = Teuchos::rcp(
new ExporterTxt());
741 exporterNewtonIterations->setup(
"newtonIterations" + suffix, this->comm_ );
743 exporterIterations = Teuchos::rcp(
new ExporterTxt());
744 exporterIterations->setup(
"linearIterations" + suffix, this->comm_ );
747 int size = timeStepDef_.size();
748 TEUCHOS_TEST_FOR_EXCEPTION( size>1, std::runtime_error,
"Newmark only implemented for systems of size 1x1.");
749 double dt = timeSteppingTool_->get_dt();
750 double beta = timeSteppingTool_->get_beta();
751 double gamma = timeSteppingTool_->get_gamma();
754 SmallMatrix<double> massCoeff(size);
755 SmallMatrix<double> problemCoeff(size);
756 double coeffSourceTerm = 0.0;
759 massCoeff[0][0] = 1.0/(dt*dt*beta);
760 problemCoeff[0][0] = 1.0;
762 coeffSourceTerm = 1.0;
765 vec_dbl_Type coeffTemp(1);
766 coeffTemp.at(0) = 1.0;
771 problemTime_->setTimeParameters(massCoeff, problemCoeff);
776 while(timeSteppingTool_->continueTimeStepping())
779 problemTime_->combineSystems();
782 problemTime_->updateSolutionNewmarkPreviousStep(dt, beta, gamma);
784 double time = timeSteppingTool_->currentTime() + dt;
785 problemTime_->updateTime ( time );
790 problemTime_->updateNewmarkRhs(dt, beta, gamma, coeffTemp);
794 if (problemTime_->hasSourceTerm())
797 problemTime_->assembleSourceTerm(time);
802 addSourceTermToRHS(coeffSourceTerm);
808 NonLinearSolver<SC, LO, GO, NO> nlSolver(parameterList_->sublist(
"General").get(
"Linearization",
"Newton"));
809 nlSolver.solve( *problemTime_, time, its );
811 timeSteppingTool_->advanceTime(
true);
813 exporterTimeTxt->exportData( timeSteppingTool_->currentTime() );
814 exporterIterations->exportData( (*its)[0] );
815 exporterNewtonIterations->exportData( (*its)[1] );
830template<
class SC,
class LO,
class GO,
class NO>
831void DAESolverInTime<SC,LO,GO,NO>::advanceInTimeFSI()
838 FSIProblemPtr_Type fsi = Teuchos::rcp_dynamic_cast<FSIProblem_Type>( this->problemTime_->getUnderlyingProblem() );
840 bool print = parameterList_->sublist(
"General").get(
"ParaViewExport",
false);
841 bool printData = parameterList_->sublist(
"General").get(
"Export Data",
false);
842 bool printExtraData = parameterList_->sublist(
"General").get(
"Export Extra Data",
false);
843 bool printFlowRate = parameterList_->sublist(
"General").get(
"Export Flow Rate",
true);
851 vec_dbl_ptr_Type its = Teuchos::rcp(
new vec_dbl_Type ( 2, 0. ) );
852 ExporterTxtPtr_Type exporterTimeTxt;
853 ExporterTxtPtr_Type exporterDisplXTxt;
854 ExporterTxtPtr_Type exporterDisplYTxt;
855 ExporterTxtPtr_Type exporterIterations;
856 ExporterTxtPtr_Type exporterNewtonIterations;
857 ExporterTxtPtr_Type exporterFlowRateInlet;
858 ExporterTxtPtr_Type exporterFlowRateOutlet;
859 ExporterTxtPtr_Type exporterAreaInlet;
860 ExporterTxtPtr_Type exporterAreaOutlet;
861 ExporterTxtPtr_Type exporterPressureOutlet;
863 exporterTimeTxt = Teuchos::rcp(
new ExporterTxt());
864 exporterDisplXTxt = Teuchos::rcp(
new ExporterTxt());
865 exporterDisplYTxt = Teuchos::rcp(
new ExporterTxt());
866 exporterTimeTxt->setup(
"time", this->comm_ );
868 std::string suffix = parameterList_->sublist(
"General").get(
"Export Suffix",
"");
870 exporterNewtonIterations = Teuchos::rcp(
new ExporterTxt());
871 exporterNewtonIterations->setup(
"newtonIterations" + suffix, this->comm_ );
873 exporterIterations = Teuchos::rcp(
new ExporterTxt());
874 exporterIterations->setup(
"linearIterations" + suffix, this->comm_ );
876 if (printExtraData) {
878 vec_dbl_Type v(3,-9999.);
879 this->problemTime_->getValuesOfInterest(v);
880 vec_dbl_Type vGathered(this->comm_->getSize());
881 Teuchos::gatherAll<int,double>( *this->comm_, 1, &v[0], vGathered.size(), &vGathered[0] );
883 while (vGathered[targetRank] < 0){
885 TEUCHOS_TEST_FOR_EXCEPTION( targetRank == vGathered.size(), std::runtime_error,
"No targetRank for export of displacements was found!" );
888 std::string suffix = parameterList_->sublist(
"General").get(
"Export Suffix",
"");
890 exporterDisplXTxt->setup(
"displ_x" + suffix, this->comm_ , targetRank);
891 exporterDisplYTxt->setup(
"displ_y" + suffix, this->comm_ , targetRank);
895 std::string suffix = parameterList_->sublist(
"General").get(
"Export Suffix",
"");
897 exporterFlowRateInlet = Teuchos::rcp(
new ExporterTxt());
898 exporterFlowRateInlet->setup(
"flowRateInlet" + suffix, this->comm_ );
900 exporterFlowRateOutlet = Teuchos::rcp(
new ExporterTxt());
901 exporterFlowRateOutlet->setup(
"flowRateOutlet" + suffix, this->comm_ );
903 exporterPressureOutlet = Teuchos::rcp(
new ExporterTxt());
904 exporterPressureOutlet->setup(
"pressureOutlet" + suffix, this->comm_ );
906 exporterAreaInlet = Teuchos::rcp(
new ExporterTxt());
907 exporterAreaInlet->setup(
"areaInlet" + suffix, this->comm_ );
909 exporterAreaOutlet = Teuchos::rcp(
new ExporterTxt());
910 exporterAreaOutlet->setup(
"areaOutlet" + suffix, this->comm_ );
916 bool geometryExplicit = this->parameterList_->sublist(
"Parameter").get(
"Geometry Explicit",
true);
917 int sizeFSI = timeStepDef_.size();
921 int sizeStructure = 1;
923 double dt = timeSteppingTool_->get_dt();
924 double beta = timeSteppingTool_->get_beta();
925 double gamma = timeSteppingTool_->get_gamma();
926 int nmbBDF = timeSteppingTool_->getBDFNumber();
930 SmallMatrix<double> massCoeffFluid(sizeFluid);
931 SmallMatrix<double> problemCoeffFluid(sizeFluid);
932 double coeffSourceTermFluid = 0.0;
934 for (
int i=0; i<sizeFluid; i++) {
935 for (
int j=0; j<sizeFluid; j++) {
936 if (timeStepDef_[i][j]>0 && i==j) {
937 massCoeffFluid[i][j] = timeSteppingTool_->getInformationBDF(0) / dt;
940 massCoeffFluid[i][j] = 0.0;
944 for (
int i=0; i<sizeFluid; i++) {
945 for (
int j=0; j<sizeFluid; j++){
946 if (timeStepDef_[i][j]>0){
947 problemCoeffFluid[i][j] = timeSteppingTool_->getInformationBDF(1);
948 coeffSourceTermFluid = timeSteppingTool_->getInformationBDF(1);
951 problemCoeffFluid[i][j] = 1.;
961 SmallMatrix<double> massCoeffStructure(sizeStructure);
962 SmallMatrix<double> problemCoeffStructure(sizeStructure);
963 double coeffSourceTermStructure = 0.0;
966 for(
int i = 0; i < sizeStructure; i++)
968 for(
int j = 0; j < sizeStructure; j++)
972 if(timeStepDef_[i + sizeFluid][j + sizeFluid] > 0 && i == j)
975 massCoeffStructure[i][j] = 1.0/(dt*dt*beta);
979 massCoeffStructure[i][j] = 0.;
986 for(
int i = 0; i < sizeStructure; i++)
988 for(
int j = 0; j < sizeStructure; j++)
990 if(timeStepDef_[i + sizeFluid][j + sizeFluid] > 0 )
992 problemCoeffStructure[i][j] = 1.0;
994 coeffSourceTermStructure = 1.0;
998 problemCoeffStructure[i][j] = 1.0;
1007 SmallMatrix<double> massCoeffFSI(sizeFSI);
1008 SmallMatrix<double> problemCoeffFSI(sizeFSI);
1009 for (
int i = 0; i < sizeFluid; i++)
1011 for (
int j = 0; j < sizeFluid; j++)
1013 massCoeffFSI[i][j] = massCoeffFluid[i][j];
1014 problemCoeffFSI[i][j] = problemCoeffFluid[i][j];
1018 for (
int i = 0; i < sizeStructure; i++)
1020 for (
int j = 0; j < sizeStructure; j++)
1022 massCoeffFSI[i + sizeFluid][j + sizeFluid] = massCoeffStructure[i][j];
1023 problemCoeffFSI[i + sizeFluid][j + sizeFluid] = problemCoeffStructure[i][j];
1028 problemCoeffFSI[0][3] = 1.0;
1029 problemCoeffFSI[2][3] = 1.0;
1030 problemCoeffFSI[3][0] = 1.0;
1031 problemCoeffFSI[3][2] = 1.0;
1032 if(!geometryExplicit)
1034 problemCoeffFSI[4][2] = 1.0;
1035 problemCoeffFSI[4][4] = 1.0;
1036 std::string linearization = this->parameterList_->sublist(
"General").get(
"Linearization",
"Extrapolation");
1037 if(linearization ==
"Newton" || linearization ==
"NOX")
1039 problemCoeffFSI[0][4] = 1.0;
1040 problemCoeffFSI[1][4] = 1.0;
1044 this->problemTime_->setTimeParameters(massCoeffFSI, problemCoeffFSI);
1046 if (printExtraData) {
1047 exporterTimeTxt->exportData( timeSteppingTool_->currentTime() );
1048 vec_dbl_Type v(3,0.);
1049 this->problemTime_->getValuesOfInterest( v );
1051 exporterDisplXTxt->exportData( v[0] );
1052 exporterDisplYTxt->exportData( v[1] );
1067 TimeMonitor_Type solveTM(*solveProblemTimer_);
1069 while(timeSteppingTool_->continueTimeStepping())
1071 problemTime_->updateTime ( timeSteppingTool_->currentTime() );
1073 std::string linearization = this->parameterList_->sublist(
"General").get(
"Linearization",
"Extrapolation");
1079 if(nmbBDF<2 && !parameterList_->sublist(
"General").get(
"Linearization",
"FixedPoint").compare(
"Extrapolation"))
1081 if (timeSteppingTool_->currentTime() != 0.0)
1083 this->problemTime_->updateSolutionMultiPreviousStep(2);
1087 this->problemTime_->updateSolutionMultiPreviousStep(1);
1092 this->problemTime_->updateSolutionMultiPreviousStep(nmbBDF);
1095#ifdef FEDD_DETAIL_TIMER
1096 TimeMonitor_Type reassmbleTM(*reassmbleAddInterfaceRHSTimer_);
1099 this->problemTime_->assemble(
"AddInterfaceBlockRHS");
1102#ifdef FEDD_DETAIL_TIMER
1103 TimeMonitor_Type reassmbleTM(*reassmbleUpdateMeshDisplacementTimer_);
1106 this->problemTime_->assemble(
"UpdateMeshDisplacement");
1109 if(geometryExplicit)
1112#ifdef FEDD_DETAIL_TIMER
1113 TimeMonitor_Type reassmbleTM(*reassmbleSolveGeometryTimer_);
1115 this->problemTime_->assemble(
"SolveGeometryProblem");
1117#ifdef FEDD_DETAIL_TIMER
1118 TimeMonitor_Type reassmbleTM(*reassmbleMoveMeshTimer_);
1120 this->problemTime_->assemble(
"MoveMesh");
1133#ifdef FEDD_DETAIL_TIMER
1134 TimeMonitor_Type reassmbleTM(*reassmbleSolidMassAndRHSTimer_);
1139 if(timeSteppingTool_->currentTime() == 0.0)
1142 MatrixPtr_Type massmatrix;
1143 fsi->setSolidMassmatrix( massmatrix );
1144 this->problemTime_->systemMass_->addBlock( massmatrix, 2, 2 );
1148 this->problemTime_->assemble(
"ComputeSolidRHSInTime");
1152 if(geometryExplicit)
1154#ifdef FEDD_DETAIL_TIMER
1155 TimeMonitor_Type reassmbleTM(*reassmbleForTimeTimer_);
1157 this->problemTime_->assemble(
"ForTime");
1166#ifdef FEDD_DETAIL_TIMER
1167 TimeMonitor_Type reassmbleTM(*reassmbleUpdateFluidInTimeTimer_);
1170 this->problemTime_->assemble(
"UpdateFluidInTime");
1174 this->problemTime_->assemble(
"ComputePressureRHSInTime");
1181 MatrixPtr_Type massmatrix;
1182 fsi->setFluidMassmatrix( massmatrix );
1183 this->problemTime_->systemMass_->addBlock( massmatrix, 0, 0 );
1187 this->problemTime_->assemble(
"ComputeFluidRHSInTime" );
1195 if (timeSteppingTool_->currentTime() == 0.) {
1196 SmallMatrix<double> massCoeffFluidTmp(sizeFluid);
1198 for (
int i = 0; i < sizeFluid; i++)
1200 for (
int j = 0; j < sizeFluid; j++){
1201 if (massCoeffFSI[i][j] != 0.){
1202 massCoeffFSI[i][j] = 1./dt ;
1203 massCoeffFluidTmp[i][j] = 1./dt;
1207 this->problemTime_->setTimeParameters(massCoeffFSI, problemCoeffFSI);
1208 fsi->problemTimeFluid_->setTimeParameters(massCoeffFluidTmp, problemCoeffFluid);
1213 double time = timeSteppingTool_->currentTime() + dt;
1214 problemTime_->updateTime ( time );
1215 NonLinearSolver<SC, LO, GO, NO> nlSolver(parameterList_->sublist(
"General").get(
"Linearization",
"FixedPoint"));
1217 nlSolver.solve(*this->problemTime_, time, its);
1219 if (timeSteppingTool_->currentTime() <= dt+1.e-10) {
1220 for (
int i = 0; i < sizeFluid; i++)
1222 for (
int j = 0; j < sizeFluid; j++){
1223 massCoeffFSI[i][j] = massCoeffFluid[i][j];
1226 this->problemTime_->setTimeParameters(massCoeffFSI, problemCoeffFSI);
1227 fsi->problemTimeFluid_->setTimeParameters(massCoeffFluid, problemCoeffFluid);
1231 this->problemTime_->computeValuesOfInterestAndExport();
1233 timeSteppingTool_->advanceTime(
true);
1234 this->problemTime_->assemble(
"UpdateTime");
1236 exporterTimeTxt->exportData( timeSteppingTool_->currentTime() );
1237 exporterIterations->exportData( (*its)[0] );
1238 exporterNewtonIterations->exportData( (*its)[1] );
1240 if (printExtraData) {
1241 vec_dbl_Type v(3,-9999.);
1242 this->problemTime_->getValuesOfInterest(v);
1244 exporterDisplXTxt->exportData( v[0] );
1245 exporterDisplYTxt->exportData( v[1] );
1253 fe.addFE(problemTime_->getDomain(0));
1254 double flowRateInlet;
1255 double flowRateOutlet;
1257 int flagInlet = this->parameterList_->sublist(
"General").get(
"Flag Inlet Fluid", 4);
1258 int flagOutlet = this->parameterList_->sublist(
"General").get(
"Flag Outlet Fluid", 5);
1260 MultiVectorPtr_Type u_rep = Teuchos::rcp(
new MultiVector_Type ( problemTime_->getDomain(0)->getMapVecFieldRepeated() ) );
1261 u_rep->importFromVector(problemTime_->getSolution()->getBlock(0),
false,
"Insert");
1262 fe.assemblyFlowRate(problemTime_->getDomain(0)->getDimension(), flowRateInlet, problemTime_->getDomain(0)->getFEType() , problemTime_->getDomain(0)->getDimension(), flagInlet , u_rep);
1263 fe.assemblyFlowRate(problemTime_->getDomain(0)->getDimension(), flowRateOutlet, problemTime_->getDomain(0)->getFEType() , problemTime_->getDomain(0)->getDimension(), flagOutlet , u_rep);
1265 exporterFlowRateInlet->exportData( timeSteppingTool_->currentTime() , flowRateInlet );
1266 exporterFlowRateOutlet->exportData( timeSteppingTool_->currentTime() ,flowRateOutlet );
1268 exporterPressureOutlet->exportData( timeSteppingTool_->currentTime() , fsi->getPressureOutlet() );
1270 double areaInlet=0.;
1271 fe.assemblyArea(problemTime_->getDomain(0)->getDimension(), areaInlet, flagInlet);
1273 double areaOutlet=0.;
1274 fe.assemblyArea(problemTime_->getDomain(0)->getDimension(), areaOutlet, flagOutlet);
1276 exporterAreaInlet->exportData( timeSteppingTool_->currentTime() , areaInlet);
1277 exporterAreaOutlet->exportData( timeSteppingTool_->currentTime() ,areaOutlet );
1283 if (printExtraData) {
1284 exporterTimeTxt->closeExporter();
1285 exporterIterations->closeExporter();
1286 exporterNewtonIterations->closeExporter();
1289 if (printExtraData) {
1290 exporterDisplXTxt->closeExporter();
1291 exporterDisplYTxt->closeExporter();
1301template<
class SC,
class LO,
class GO,
class NO>
1302void DAESolverInTime<SC,LO,GO,NO>::advanceInTimeLinearMultistep(){
1305 bool print = parameterList_->sublist(
"General").get(
"ParaViewExport",
false);
1309 int size = timeStepDef_.size();
1310 double dt = timeSteppingTool_->get_dt();
1311 int nmbBDF = timeSteppingTool_->getBDFNumber();
1312 vec_dbl_Type coeffPrevSteps(nmbBDF);
1313 for (
int i=0; i<coeffPrevSteps.size(); i++) {
1314 coeffPrevSteps.at(i) = timeSteppingTool_->getInformationBDF(i+2) / dt;
1317 SmallMatrix<double> massCoeff(size);
1318 SmallMatrix<double> problemCoeff(size);
1319 double coeffSourceTerm = 0.;
1321 for (
int i=0; i<size; i++) {
1322 for (
int j=0; j<size; j++) {
1323 if (timeStepDef_[i][j]==1 && i==j) {
1324 massCoeff[i][j] = timeSteppingTool_->getInformationBDF(0) / dt;
1327 massCoeff[i][j] = 0.;
1331 for (
int i=0; i<size; i++) {
1332 for (
int j=0; j<size; j++){
1333 if (timeStepDef_[i][j]==1){
1334 problemCoeff[i][j] = timeSteppingTool_->getInformationBDF(1);
1335 coeffSourceTerm = timeSteppingTool_->getInformationBDF(1);
1338 problemCoeff[i][j] = 1.;
1342 problemTime_->setTimeParameters(massCoeff, problemCoeff);
1347 while (timeSteppingTool_->continueTimeStepping()) {
1349 problemTime_->updateSolutionMultiPreviousStep(nmbBDF);
1351 double time = timeSteppingTool_->currentTime() + dt;
1352 problemTime_->updateMultistepRhs(coeffPrevSteps,nmbBDF);
1353 if (problemTime_->hasSourceTerm()) {
1354 problemTime_->assembleSourceTerm(time);
1355 addSourceTermToRHS(coeffSourceTerm);
1358 problemTime_->combineSystems();
1360 problemTime_->setBoundaries(time);
1361 problemTime_->solve();
1363 timeSteppingTool_->advanceTime(
true);
1377template<
class SC,
class LO,
class GO,
class NO>
1378void DAESolverInTime<SC,LO,GO,NO>::advanceInTimeNonLinearMultistep(){
1380 bool print = parameterList_->sublist(
"General").get(
"ParaViewExport",
false);
1381 bool printData = parameterList_->sublist(
"General").get(
"Export Data",
false);
1387 ExporterTxtPtr_Type exporterIterations;
1388 ExporterTxtPtr_Type exporterNewtonIterations;
1389 ExporterTxtPtr_Type exporterTimeTxt;
1390 vec_dbl_ptr_Type its = Teuchos::rcp(
new vec_dbl_Type ( 2, 0. ) );
1393 exporterTimeTxt = Teuchos::rcp(
new ExporterTxt());
1394 exporterTimeTxt->setup(
"time", this->comm_ );
1396 std::string suffix = parameterList_->sublist(
"General").get(
"Export Suffix",
"");
1398 exporterNewtonIterations = Teuchos::rcp(
new ExporterTxt());
1399 exporterNewtonIterations->setup(
"newtonIterations" + suffix, this->comm_ );
1401 exporterIterations = Teuchos::rcp(
new ExporterTxt());
1402 exporterIterations->setup(
"linearIterations" + suffix, this->comm_ );
1405 int size = timeStepDef_.size();
1406 double dt = timeSteppingTool_->get_dt();
1407 int nmbBDF = timeSteppingTool_->getBDFNumber();
1409 vec_dbl_Type coeffPrevSteps(nmbBDF);
1410 for (
int i=0; i<coeffPrevSteps.size(); i++) {
1411 coeffPrevSteps.at(i) = timeSteppingTool_->getInformationBDF(i+2) / dt;
1414 SmallMatrix<double> massCoeff(size);
1415 SmallMatrix<double> problemCoeff(size);
1416 double coeffSourceTerm = 0.;
1418 for (
int i=0; i<size; i++) {
1419 for (
int j=0; j<size; j++) {
1420 if (timeStepDef_[i][j]>0 && i==j) {
1421 massCoeff[i][j] = timeSteppingTool_->getInformationBDF(0) / dt;
1424 massCoeff[i][j] = 0.;
1428 for (
int i=0; i<size; i++) {
1429 for (
int j=0; j<size; j++){
1430 if (timeStepDef_[i][j]>0){
1431 problemCoeff[i][j] = timeSteppingTool_->getInformationBDF(1);
1432 coeffSourceTerm = timeSteppingTool_->getInformationBDF(1);
1435 problemCoeff[i][j] = 1.;
1439 problemTime_->setTimeParameters(massCoeff, problemCoeff);
1444 vec_dbl_Type linearIterations(0);
1445 vec_dbl_Type newtonIterations(0);
1446 NonLinearSolver<SC, LO, GO, NO> nlSolver(parameterList_->sublist(
"General").get(
"Linearization",
"FixedPoint"));
1448 while (timeSteppingTool_->continueTimeStepping()) {
1451 if (timeSteppingTool_->currentTime()==0.) {
1452 SmallMatrix<double> tmpmassCoeff(size);
1453 SmallMatrix<double> tmpproblemCoeff(size);
1454 for (
int i=0; i<size; i++) {
1455 for (
int j=0; j<size; j++) {
1456 if (timeStepDef_[i][j]>0 && i==j) {
1457 tmpmassCoeff[i][j] = 1. / dt;
1460 tmpmassCoeff[i][j] = 0.;
1464 for (
int i=0; i<size; i++) {
1465 for (
int j=0; j<size; j++){
1466 if (timeStepDef_[i][j]>0){
1467 tmpproblemCoeff[i][j] = 1.;
1470 tmpproblemCoeff[i][j] = 1.;
1474 problemTime_->setTimeParameters(tmpmassCoeff, tmpproblemCoeff);
1476 if(nmbBDF<2 && !parameterList_->sublist(
"General").get(
"Linearization",
"FixedPoint").compare(
"Extrapolation")) {
1477 if (timeSteppingTool_->currentTime()!=0.){
1478 problemTime_->updateSolutionMultiPreviousStep(2);
1481 problemTime_->updateSolutionMultiPreviousStep(1);
1485 problemTime_->updateSolutionMultiPreviousStep(nmbBDF);
1487 double time = timeSteppingTool_->currentTime() + dt;
1488 problemTime_->updateTime ( time );
1490 if (timeSteppingTool_->currentTime()==0.) {
1491 vec_dbl_Type tmpcoeffPrevSteps(1, 1. / dt);
1492 problemTime_->updateMultistepRhs(tmpcoeffPrevSteps,1);
1495 problemTime_->updateMultistepRhs(coeffPrevSteps,nmbBDF);
1497 if (problemTime_->hasSourceTerm()) {
1498 TEUCHOS_TEST_FOR_EXCEPTION(
true, std::logic_error,
"Check sourceterm.");
1508 nlSolver.solve(*problemTime_,time,its);
1509 problemTime_->assemble(
"UpdateTime");
1511 if (timeSteppingTool_->currentTime()==0.) {
1512 problemTime_->setTimeParameters(massCoeff, problemCoeff);
1515 timeSteppingTool_->advanceTime(
true);
1517 exporterTimeTxt->exportData( timeSteppingTool_->currentTime() );
1518 exporterIterations->exportData( (*its)[0] );
1519 linearIterations.push_back((*its)[0]);
1520 exporterNewtonIterations->exportData( (*its)[1] );
1521 newtonIterations.push_back((*its)[1]);
1529 exporterTimeTxt->closeExporter();
1530 exporterIterations->closeExporter();
1531 exporterNewtonIterations->closeExporter();
1533 double sumLinear=0., sumNewton=0.;
1534 for(
int i=0; i < linearIterations.size(); i++){
1535 sumLinear += linearIterations[i];
1536 sumNewton += newtonIterations[i];
1538 sumLinear = sumLinear / linearIterations.size();
1539 sumNewton = sumNewton / newtonIterations.size();
1542 std::cout <<
" ######################################################## "<< std::endl;
1543 std::cout <<
" Average linear iteration count over all time steps: " << sumLinear << std::endl;
1544 std::cout <<
" Average Newton iteration count over all time steps: " << sumNewton << std::endl;
1545 std::cout <<
" ######################################################## \n"<< std::endl;
1555template<
class SC,
class LO,
class GO,
class NO>
1556void DAESolverInTime<SC,LO,GO,NO>::advanceInTimeLinearExternal(){
1557 bool print = parameterList_->sublist(
"General").get(
"ParaViewExport",
false);
1562 double dt = timeSteppingTool_->get_dt();
1567 while (timeSteppingTool_->continueTimeStepping()) {
1569 double time = timeSteppingTool_->currentTime() + dt;
1570 problemTime_->updateTime ( time );
1572 problemTime_->assemble(
"Assemble" );
1574 if (problemTime_->hasSourceTerm()){
1575 problemTime_->assembleSourceTerm(time);
1576 problemTime_->addToRhs( problemTime_->getSourceTerm() );
1579 problemTime_->setBoundaries( time );
1581 BlockMultiVectorPtr_Type tmpSol = Teuchos::rcp(
new BlockMultiVector_Type(problemTime_->getSolution()) );
1586 problemTime_->solve();
1590 problemTime_->getSolution()->update( 1., tmpSol, -1. );
1592 problemTime_->assemble(
"SetSolutionNewton" );
1594 problemTime_->assemble(
"OnlyUpdate" );
1596 problemTime_->assemble(
"SetSolutionInTime" );
1598 timeSteppingTool_->advanceTime(
true);
1609template<
class SC,
class LO,
class GO,
class NO>
1610void DAESolverInTime<SC,LO,GO,NO>::advanceInTimeNonLinearExternal(){
1612 bool print = parameterList_->sublist(
"General").get(
"ParaViewExport",
false);
1617 double dt = timeSteppingTool_->get_dt();
1622 while (timeSteppingTool_->continueTimeStepping()) {
1624 double time = timeSteppingTool_->currentTime() + dt;
1625 problemTime_->updateTime ( time );
1627 if (problemTime_->hasSourceTerm()){
1628 problemTime_->assembleSourceTerm(time);
1630 NonLinearSolver<SC, LO, GO, NO> nlSolver(parameterList_->sublist(
"General").get(
"Linearization",
"Newton"));
1631 nlSolver.solve(*problemTime_,time);
1632 problemTime_->assemble(
"OnlyUpdate" );
1634 problemTime_->assemble(
"SetSolutionInTime" );
1636 timeSteppingTool_->advanceTime(
true);
1648template<
class SC,
class LO,
class GO,
class NO>
1649void DAESolverInTime<SC,LO,GO,NO>::addRhsDAE(SmallMatrix<double> coeff, BlockMatrixPtr_Type bMat, BlockMultiVectorPtr_Type vec){
1651 BlockMultiVectorPtr_Type mv = Teuchos::rcp(
new BlockMultiVector_Type( vec ) );
1652 bMat->apply( *vec, *mv , coeff );
1653 problemTime_->getRhs()->update( 1., *mv, 1. );
1656template<
class SC,
class LO,
class GO,
class NO>
1657void DAESolverInTime<SC,LO,GO,NO>::addRhsDAE(SmallMatrix<double> coeff, BlockMultiVectorPtr_Type vec){
1658 TEUCHOS_TEST_FOR_EXCEPTION(
true, std::logic_error,
"Is this correct? addRhsDAE!");
1659 for (
int i=0; i<vec->size(); i++)
1660 problemTime_->getRhs()->getBlockNonConst(i)->update( coeff[i][i], vec->getBlock(i), 1. );
1663template<
class SC,
class LO,
class GO,
class NO>
1664void DAESolverInTime<SC,LO,GO,NO>::addSourceTermToRHS(
double coeff)
1666 BlockMultiVectorPtr_Type tmpMV = problemTime_->getSourceTerm();
1668 problemTime_->getRhs()->update(coeff, *tmpMV, 1.);
1671template<
class SC,
class LO,
class GO,
class NO>
1672void DAESolverInTime<SC,LO,GO,NO>::exportTimestep(){
1674 if (!boolExporterSetup_) {
1678 std::cout <<
"-- Exporting..."<< std::flush;
1680 for (
int i=0; i<exporter_vector_.size(); i++) {
1682 exporter_vector_[i]->save( timeSteppingTool_->currentTime() );
1687 std::cout <<
"done! --"<< std::endl;
1692template<
class SC,
class LO,
class GO,
class NO>
1693void DAESolverInTime<SC,LO,GO,NO>::exportTimestep(BlockMultiVectorPtr_Type& solShort){
1695 if (!boolExporterSetup_) {
1696 setupExporter(solShort);
1699 std::cout <<
"-- Exporting..."<< std::flush;
1701 for (
int i=0; i<exporter_vector_.size(); i++) {
1703 exporter_vector_[i]->save( timeSteppingTool_->currentTime() );
1708 std::cout <<
"done! --"<< std::endl;
1713template<
class SC,
class LO,
class GO,
class NO>
1714void DAESolverInTime<SC,LO,GO,NO>::closeExporter(){
1716 if (boolExporterSetup_) {
1717 for (
int i=0; i<exporter_vector_.size(); i++)
1718 exporter_vector_[i]->closeExporter();
1723template<
class SC,
class LO,
class GO,
class NO>
1724void DAESolverInTime<SC,LO,GO,NO>::setupExporter(){
1725 for (
int i=0; i<timeStepDef_.size(); i++) {
1727 bool exportThisBlock =
true;
1728 if(this->parameterList_->sublist(
"Parameter").get(
"FSI",
false) ==
true )
1729 exportThisBlock = (i != 3);
1730 else if(this->parameterList_->sublist(
"Parameter").get(
"FSCI",
false) ==
true)
1731 exportThisBlock = (i != 4);
1735 ExporterPtr_Type exporterPtr(
new Exporter_Type());
1736 MultiVectorConstPtr_Type exportVector = problemTime_->getSolution()->getBlock(i);
1738 DomainConstPtr_Type dom = problemTime_->getDomain(i);
1740 int exportEveryXTimesteps = parameterList_->sublist(
"Exporter").get(
"Export every X timesteps", 1 );
1741 std::string plSuffix =
"Suffix variable" + std::to_string(i+1);
1742 std::string suffix = parameterList_->sublist(
"Exporter").get(plSuffix,
"" );
1743 std::string varName = problemTime_->getVariableName(i) + suffix;
1744 MeshPtr_Type meshNonConst = Teuchos::rcp_const_cast<Mesh_Type>(dom->getMesh());
1745 exporterPtr->setup(varName, meshNonConst, dom->getFEType(), parameterList_);
1749 UN dofsPerNode = problemTime_->getDofsPerNode(i);
1751 if (dofsPerNode == 1)
1752 exporterPtr->addVariable( exportVector, varName,
"Scalar", dofsPerNode, dom->getMapUnique() );
1754 exporterPtr->addVariable( exportVector, varName,
"Vector", dofsPerNode, dom->getMapUnique() );
1756 exporter_vector_.push_back(exporterPtr);
1757 export_solution_vector_.push_back(exportVector);
1760 boolExporterSetup_ =
true;
1764template<
class SC,
class LO,
class GO,
class NO>
1765void DAESolverInTime<SC,LO,GO,NO>::setupExporter(BlockMultiVectorPtr_Type& solShort){
1766 for (
int i=0; i<timeStepDef_.size(); i++) {
1768 bool exportThisBlock =
true;
1769 exportThisBlock = !(this->parameterList_->sublist(
"Parameter").get(
"FSI",
false) && i == 3);
1772 ExporterPtr_Type exporterPtr(
new Exporter_Type());
1773 MultiVectorConstPtr_Type exportVector = problemTime_->getSolution()->getBlock(i);
1774 MultiVectorConstPtr_Type exportVectorShort = solShort->getBlock(i);
1776 DomainConstPtr_Type dom = problemTime_->getDomain(i);
1778 int exportEveryXTimesteps = parameterList_->sublist(
"Exporter").get(
"Export every X timesteps", 1 );
1779 std::string plSuffix =
"Suffix variable" + std::to_string(i+1);
1780 std::string suffix = parameterList_->sublist(
"Exporter").get(plSuffix,
"" );
1781 std::string varName = problemTime_->getVariableName(i) + suffix;
1782 std::string varNameShort = problemTime_->getVariableName(i) +
"_short_" + suffix;
1784 MeshPtr_Type meshNonConst = Teuchos::rcp_const_cast<Mesh_Type>(dom->getMesh());
1785 exporterPtr->setup(varName, meshNonConst, dom->getFEType(), parameterList_);
1789 UN dofsPerNode = problemTime_->getDofsPerNode(i);
1791 if (dofsPerNode == 1){
1792 exporterPtr->addVariable( exportVector, varName,
"Scalar", dofsPerNode, dom->getMapUnique() );
1793 exporterPtr->addVariable( exportVectorShort, varNameShort,
"Scalar", dofsPerNode, dom->getMapUnique() );
1796 exporterPtr->addVariable( exportVector, varName,
"Vector", dofsPerNode, dom->getMapUnique() );
1797 exporterPtr->addVariable( exportVectorShort, varNameShort,
"Vector", dofsPerNode, dom->getMapUnique() );
1801 exporter_vector_.push_back(exporterPtr);
1802 export_solution_vector_.push_back(exportVector);
1805 boolExporterSetup_ =
true;
1811template<
class SC,
class LO,
class GO,
class NO>
1812void DAESolverInTime<SC,LO,GO,NO>::setupTimeStepping(){
1814 int size = this->problem_->getSystem()->size();
1816 problemTime_.reset(
new TimeProblem<SC,LO,GO,NO>(*this->problem_,comm_));
1819 if(this->parameterList_->sublist(
"Parameter").get(
"FSI",
false) || this->parameterList_->sublist(
"Parameter").get(
"SCI",
false) || this->parameterList_->sublist(
"Parameter").get(
"FSCI",
false))
1823 this->problemTime_->systemMass_.reset(
new BlockMatrix_Type(this->problemTime_->getSystem()->size()));
1824 this->problemTime_->systemCombined_.reset(
new BlockMatrix_Type( this->problemTime_->getSystem()->size() ));
1828 size = timeStepDef_.size();
1829 SmallMatrix<double> massCoeff(size);
1830 SmallMatrix<double> problemCoeff(size);
1832 for (
int i=0; i<size; i++) {
1833 for (
int j=0; j<size; j++) {
1834 if (timeStepDef_[i][j]>1 && i==j) {
1835 massCoeff[i][j] = 1.0;
1838 massCoeff[i][j] = 0.;
1845 problemTime_->setTimeParameters(massCoeff,problemCoeff);
1849 problemTime_->setTimeDef( timeStepDef_ );
1850 problemTime_->assemble(
"MassSystem" );
1856template<
class SC,
class LO,
class GO,
class NO>
1857void DAESolverInTime<SC,LO,GO,NO>::setTimeStep(
double dt){
1859 checkTimeSteppingDef();
1864template<
class SC,
class LO,
class GO,
class NO>
1865void DAESolverInTime<SC,LO,GO,NO>::setFinalTime(
double T){
1867 checkTimeSteppingDef();
1871template<
class SC,
class LO,
class GO,
class NO>
1872void DAESolverInTime<SC,LO,GO,NO>::checkTimeSteppingDef(){
1873#ifdef ASSERTS_WARNINGS
1874 MYASSERT(isTimeSteppingDefined_,
"Time stepping not defined!");
Adaptive Mesh Refinement.
Definition AdaptiveMeshRefinement_decl.hpp:36