1#ifndef DAESOLVERINTIME_DEF_hpp
2#define DAESOLVERINTIME_DEF_hpp
3#include "DAESolverInTime_decl.hpp"
18template<
class SC,
class LO,
class GO,
class NO>
19DAESolverInTime<SC,LO,GO,NO>::DAESolverInTime( CommConstPtr_Type comm ):
21verbose_(comm->getRank()==0),
23isTimeSteppingDefined_(false),
29export_solution_vector_(),
30boolExporterSetup_(false)
32,solveProblemTimer_ (Teuchos::TimeMonitor::getNewCounter(
"FEDD - DAETime - Solve Problem"))
34#ifdef FEDD_DETAIL_TIMER
35,reassmbleAddInterfaceRHSTimer_(Teuchos::TimeMonitor::getNewCounter(
"FEDD - DAETime Detail - FSI Interface RHS"))
36,reassmbleUpdateMeshDisplacementTimer_(Teuchos::TimeMonitor::getNewCounter(
"FEDD - DAETime Detail - FSI Update Mesh Displ."))
37,reassmbleSolveGeometryTimer_(Teuchos::TimeMonitor::getNewCounter(
"FEDD - DAETime Detail - FSI Solve Geometry"))
38,reassmbleMoveMeshTimer_(Teuchos::TimeMonitor::getNewCounter(
"FEDD - DAETime Detail - FSI Move Mesh"))
39,reassmbleSolidMassAndRHSTimer_(Teuchos::TimeMonitor::getNewCounter(
"FEDD - DAETime Detail - FSI Assemble Solid Massmatrix and RHS"))
40,reassmbleForTimeTimer_(Teuchos::TimeMonitor::getNewCounter(
"FEDD - DAETime Detail - FSI Assemble Fluid Problem (steady Navier-Stokes)"))
41,reassmbleUpdateFluidInTimeTimer_(Teuchos::TimeMonitor::getNewCounter(
"FEDD - DAETime Detail - FSI Update Fluid Solution"))
48template<
class SC,
class LO,
class GO,
class NO>
49DAESolverInTime<SC,LO,GO,NO>::DAESolverInTime( ParameterListPtr_Type ¶meterList, CommConstPtr_Type comm):
51verbose_(comm->getRank()==0),
52parameterList_(parameterList),
53isTimeSteppingDefined_(false),
59export_solution_vector_(),
60boolExporterSetup_(false)
62,solveProblemTimer_ (Teuchos::TimeMonitor::getNewCounter(
"FEDD - DAETime - Solve Problem"))
64#ifdef FEDD_DETAIL_TIMER
65,reassmbleAddInterfaceRHSTimer_(Teuchos::TimeMonitor::getNewCounter(
"FEDD - DAETime Detail - FSI Interface RHS"))
66,reassmbleUpdateMeshDisplacementTimer_(Teuchos::TimeMonitor::getNewCounter(
"FEDD - DAETime Detail - FSI Update Mesh Displ."))
67,reassmbleSolveGeometryTimer_(Teuchos::TimeMonitor::getNewCounter(
"FEDD - DAETime Detail - FSI Solve Geometry"))
68,reassmbleMoveMeshTimer_(Teuchos::TimeMonitor::getNewCounter(
"FEDD - DAETime Detail - FSI Move Mesh"))
69,reassmbleSolidMassAndRHSTimer_(Teuchos::TimeMonitor::getNewCounter(
"FEDD - DAETime Detail - FSI Assemble Solid Massmatrix and RHS"))
70,reassmbleForTimeTimer_(Teuchos::TimeMonitor::getNewCounter(
"FEDD - DAETime Detail - FSI Assemble Fluid Problem (steady Navier-Stokes)"))
71,reassmbleUpdateFluidInTimeTimer_(Teuchos::TimeMonitor::getNewCounter(
"FEDD - DAETime Detail - FSI Update Fluid Solution"))
78template<
class SC,
class LO,
class GO,
class NO>
79DAESolverInTime<SC,LO,GO,NO>::DAESolverInTime( SmallMatrix<int> &timeStepDef, ParameterListPtr_Type ¶meterList, CommConstPtr_Type comm):
81verbose_(comm->getRank()==0),
82parameterList_(parameterList),
83isTimeSteppingDefined_(false),
89export_solution_vector_(),
90boolExporterSetup_(false)
92,solveProblemTimer_ (Teuchos::TimeMonitor::getNewCounter(
"FEDD - DAETime - Solve Problem"))
94#ifdef FEDD_DETAIL_TIMER
95,reassmbleAddInterfaceRHSTimer_(Teuchos::TimeMonitor::getNewCounter(
"FEDD - DAETime Detail - FSI Interface RHS"))
96,reassmbleUpdateMeshDisplacementTimer_(Teuchos::TimeMonitor::getNewCounter(
"FEDD - DAETime Detail - FSI Update Mesh Displ."))
97,reassmbleSolveGeometryTimer_(Teuchos::TimeMonitor::getNewCounter(
"FEDD - DAETime Detail - FSI Solve Geometry"))
98,reassmbleMoveMeshTimer_(Teuchos::TimeMonitor::getNewCounter(
"FEDD - DAETime Detail - FSI Move Mesh"))
99,reassmbleSolidMassAndRHSTimer_(Teuchos::TimeMonitor::getNewCounter(
"FEDD - DAETime Detail - FSI Assemble Solid Massmatrix and RHS"))
100,reassmbleForTimeTimer_(Teuchos::TimeMonitor::getNewCounter(
"FEDD - DAETime Detail - FSI Assemble Fluid Problem (steady Navier-Stokes)"))
101,reassmbleUpdateFluidInTimeTimer_(Teuchos::TimeMonitor::getNewCounter(
"FEDD - DAETime Detail - FSI Update Fluid Solution"))
105 this->defineTimeStepping(timeStepDef);
108template<
class SC,
class LO,
class GO,
class NO>
109DAESolverInTime<SC,LO,GO,NO>::~DAESolverInTime(){
114template<
class SC,
class LO,
class GO,
class NO>
115void DAESolverInTime<SC,LO,GO,NO>::setProblem(Problem_Type& problem){
117 problem_ = Teuchos::rcpFromRef(problem);
121template<
class SC,
class LO,
class GO,
class NO>
122void DAESolverInTime<SC,LO,GO,NO>::defineTimeStepping(SmallMatrix<int> &timeStepDef){
124 timeStepDef_ = timeStepDef;
125 timeSteppingTool_.reset(
new TimeSteppingTools(sublist(parameterList_,
"Timestepping Parameter") , comm_));
126 isTimeSteppingDefined_ =
true;
131template<
class SC,
class LO,
class GO,
class NO>
132void DAESolverInTime<SC,LO,GO,NO>::advanceInTime(){
134 TEUCHOS_TEST_FOR_EXCEPTION(problemTime_.is_null(), std::logic_error,
"Mass system is null.");
136 checkTimeSteppingDef();
138 if(this->parameterList_->sublist(
"Parameter").get(
"FSI",
false))
143 if (!parameterList_->sublist(
"Timestepping Parameter").get(
"Class",
"Singlestep").compare(
"Loadstepping")) {
144 NonLinProbPtr_Type nonLinProb = Teuchos::rcp_dynamic_cast<NonLinProb_Type>(problem_);
145 if (nonLinProb.is_null()){
146 TEUCHOS_TEST_FOR_EXCEPTION(
true, std::runtime_error,
"Loadstepping only available to nonlinear Problems. (It is a tool to increase Nonlinear Solver convergence.)");
149 advanceWithLoadStepping();
152 if (!parameterList_->sublist(
"Timestepping Parameter").get(
"Class",
"Singlestep").compare(
"Singlestep")) {
153 NonLinProbPtr_Type nonLinProb = Teuchos::rcp_dynamic_cast<NonLinProb_Type>(problem_);
154 if (nonLinProb.is_null()) {
155 advanceInTimeLinear();
158 advanceInTimeNonLinear();
161 else if(!parameterList_->sublist(
"Timestepping Parameter").get(
"Class",
"Singlestep").compare(
"Newmark"))
163 NonLinProbPtr_Type nonLinProb = Teuchos::rcp_dynamic_cast<NonLinProb_Type>(problem_);
164 if (nonLinProb.is_null()) {
165 advanceInTimeLinearNewmark();
169 advanceInTimeNonLinearNewmark();
172 else if( !parameterList_->sublist(
"Timestepping Parameter").get(
"Class",
"Singlestep").compare(
"Multistep") ){
173 NonLinProbPtr_Type nonLinProb = Teuchos::rcp_dynamic_cast<NonLinProb_Type>(problem_);
174 if (nonLinProb.is_null()) {
175 advanceInTimeLinearMultistep();
178 advanceInTimeNonLinearMultistep();
181 else if( !parameterList_->sublist(
"Timestepping Parameter").get(
"Class",
"Singlestep").compare(
"External") ){
182 NonLinProbPtr_Type nonLinProb = Teuchos::rcp_dynamic_cast<NonLinProb_Type>(problem_);
183 if (nonLinProb.is_null()) {
184 advanceInTimeLinearExternal();
187 advanceInTimeNonLinearExternal();
191 TEUCHOS_TEST_FOR_EXCEPTION(
true, std::runtime_error,
"Unknown time discretization type.");
197template<
class SC,
class LO,
class GO,
class NO>
198void DAESolverInTime<SC,LO,GO,NO>::advanceInTimeLinear(){
201 bool print = parameterList_->sublist(
"General").get(
"ParaViewExport",
false);
204 bool fullImplicitPressure =
false;
205 int size = timeStepDef_.size();
207 while (timeSteppingTool_->continueTimeStepping()) {
208 problemTime_->updateTime ( timeSteppingTool_->currentTime() );
209 dt = timeSteppingTool_->get_dt();
210 problemTime_->updateSolutionPreviousStep();
212 Teuchos::Array<BlockMatrixPtr_Type> bMatNonLin_vec_allstages;
213 BlockMultiVectorPtrArray_Type solutionRK_stages;
214 BlockMultiVectorPtrArray_Type sourceTermRK_stages;
216 for (
int s=0; s<timeSteppingTool_->getNmbStages(); s++) {
217 double time = timeSteppingTool_->currentTime() + dt * timeSteppingTool_->getButcherTableC(s);
219 std::cout <<
"Currently in stage " << s+1 <<
" of "<< timeSteppingTool_->getNmbStages() << std::endl;
221 problemTime_->updateRhs();
222 if ( problemTime_->hasSourceTerm() ){
223 TEUCHOS_TEST_FOR_EXCEPTION(
true, std::runtime_error,
"Fix source term.");
224 problemTime_->assembleSourceTerm( time );
227 if (s==0 && timeSteppingTool_->getButcherTableCoefficient(s , s) == 0.0) {
230 else if (s==0 && timeSteppingTool_->getButcherTableCoefficient(s , s) != 0.0) {
231 TEUCHOS_TEST_FOR_EXCEPTION(
true, std::logic_error,
"Not implemented butcher table!");
234 for (
int s_prior=0; s_prior<s; s_prior++) {
235 SmallMatrix<double> coeff(size);
236 for (
int i=0; i<size; i++) {
237 for (
int j=0; j<size; j++) {
238 if (timeStepDef_[i][j]>0) {
239 if (i==0 && j==1 && fullImplicitPressure) {
243 coeff[i][j] = - timeSteppingTool_->getButcherTableCoefficient(s , s_prior);
248 if (problemTime_->hasSourceTerm())
249 this->addRhsDAE(coeff, sourceTermRK_stages[s_prior] );
251 this->addRhsDAE( coeff, problemTime_->getSystem(), solutionRK_stages[s_prior] );
255 SmallMatrix<double> massCoeff(size);
256 SmallMatrix<double> problemCoeff(size);
257 double coeffSourceTerm = 0.;
258 for (
int i=0; i<size; i++) {
259 for (
int j=0; j<size; j++) {
260 if (timeStepDef_[i][j]>0 && i==j) {
261 massCoeff[i][j] = 1. / dt;
263 else if (timeStepDef_[i][j]==2)
264 massCoeff[i][j] = 1. / dt;
266 massCoeff[i][j] = 0.;
270 for (
int i=0; i<size; i++) {
271 for (
int j=0; j<size; j++){
272 if (timeStepDef_[i][j]>0){
273 if (i==0 && j==1 && fullImplicitPressure) {
274 problemCoeff[i][j] = 1.;
275 coeffSourceTerm = timeSteppingTool_->getButcherTableCoefficient(s , s);
278 problemCoeff[i][j] = timeSteppingTool_->getButcherTableCoefficient(s , s);
279 coeffSourceTerm = timeSteppingTool_->getButcherTableCoefficient(s , s);
283 problemCoeff[i][j] = 1.;
288 if (problemTime_->hasSourceTerm())
289 addSourceTermToRHS(coeffSourceTerm);
291 problemTime_->setTimeParameters(massCoeff, problemCoeff);
292 problemTime_->combineSystems();
293 problemTime_->setBoundaries(time);
295 problemTime_->solve();
299 if (s+1 == timeSteppingTool_->getNmbStages()) {
300 BlockMultiVectorPtr_Type tmpSolution = Teuchos::rcp(
new BlockMultiVector_Type ( problemTime_->getSolution() ) );
301 solutionRK_stages.push_back(tmpSolution);
302 BlockMultiVectorPtr_Type tmpSolutionPtr = problemTime_->getSolution();
303 BlockMatrixPtr_Type tmpMassSystem = problemTime_->getMassSystem();
304 timeSteppingTool_->calculateSolution( tmpSolutionPtr, solutionRK_stages, tmpMassSystem);
307 solutionRK_stages.push_back( problemTime_->getSolution() );
308 if ( problemTime_->hasSourceTerm() )
309 sourceTermRK_stages.push_back( problemTime_->getSourceTerm() );
313 timeSteppingTool_->advanceTime(
true);
322 if (parameterList_->sublist(
"NSParameter").get(
"Calculate Coefficients",
false)) {
323 TEUCHOS_TEST_FOR_EXCEPTION(
true, std::logic_error,
"close txt exporters here.");
327template<
class SC,
class LO,
class GO,
class NO>
328void DAESolverInTime<SC,LO,GO,NO>::getMassCoefficients(SmallMatrix<double> &massCoeff){
329 int size = timeStepDef_.size();
330 massCoeff.resize(size);
332 for (
int i=0; i<size; i++) {
333 for (
int j=0; j<size; j++) {
334 if (timeStepDef_[i][j]>0 && i==j)
335 massCoeff[i][j] = 1.;
337 massCoeff[i][j] = 0.;
342template<
class SC,
class LO,
class GO,
class NO>
343void DAESolverInTime<SC,LO,GO,NO>::getMultiStageCoefficients(SmallMatrix<double> &problemCoeff,
int stage,
int stagePrior,
bool forRhs){
344 int size = timeStepDef_.size();
345 problemCoeff.resize(size);
347 for (
int i=0; i<size; i++) {
348 for (
int j=0; j<size; j++) {
349 if (timeStepDef_[i][j]>0)
350 problemCoeff[i][j] = timeSteppingTool_->get_dt()* timeSteppingTool_->getButcherTableCoefficient(stage , stagePrior);
353 problemCoeff[i][j] = 0.;
355 problemCoeff[i][j] = 1.;
361template<
class SC,
class LO,
class GO,
class NO>
362void DAESolverInTime<SC,LO,GO,NO>::buildMultiStageRhs(
int stage, Teuchos::Array<BlockMatrixPtr_Type>& matrixPrevStages, BlockMultiVectorPtrArray_Type& solutionPrevStages ){
364 int size = timeStepDef_.size();
365 SmallMatrix<double> massCoeff(size);
366 SmallMatrix<double> problemCoeff(size);
368 getMassCoefficients(massCoeff);
370 problemTime_->setTimeParameters(massCoeff, problemCoeff);
371 problemTime_->updateRhs();
373 bool fullImplicitPressure = parameterList_->sublist(
"Timestepping Parameter").get(
"Full implicit pressure",
false);
374 for (
int prevStage=0; prevStage<stage; prevStage++) {
376 getMultiStageCoefficients(problemCoeff, stage, prevStage,
true);
377 if (fullImplicitPressure && size>1 )
378 problemCoeff[0][1] = 0.;
380 problemCoeff.scale(-1.);
382 TEUCHOS_TEST_FOR_EXCEPTION(problemTime_->hasSourceTerm(), std::logic_error,
"Using source term must be implemented for single-step methods.");
384 addRhsDAE( problemCoeff, matrixPrevStages[prevStage], solutionPrevStages[prevStage] );
391template<
class SC,
class LO,
class GO,
class NO>
392void DAESolverInTime<SC,LO,GO,NO>::advanceInTimeNonLinear(){
394 bool print = parameterList_->sublist(
"General").get(
"ParaViewExport",
false);
395 BlockMultiVectorPtr_Type solShort;
397 if (parameterList_->sublist(
"Timestepping Parameter").get(
"Print Solution Short",
false)) {
398 solShort = Teuchos::rcp(
new BlockMultiVector_Type (problemTime_->getSolution()) );
399 exportTimestep(solShort);
407 bool fullImplicitPressure = parameterList_->sublist(
"Timestepping Parameter").get(
"Full implicit pressure",
false);
408 bool semiImplicitPressure = parameterList_->sublist(
"Timestepping Parameter").get(
"Semi implicit pressure",
false);
409 bool correctPressure = parameterList_->sublist(
"Timestepping Parameter").get(
"Correct pressure",
false);
410 int size = timeStepDef_.size();
411 SmallMatrix<double> massCoeff(size);
412 SmallMatrix<double> problemCoeff(size);
415 while (timeSteppingTool_->continueTimeStepping()) {
417 dt = timeSteppingTool_->get_dt();
419 if(!parameterList_->sublist(
"General").get(
"Linearization",
"FixedPoint").compare(
"Extrapolation")) {
420 if (timeSteppingTool_->currentTime()!=0.)
421 problemTime_->updateSolutionMultiPreviousStep(2);
423 problemTime_->updateSolutionMultiPreviousStep(1);
426 problemTime_->updateSolutionPreviousStep();
432 TEUCHOS_TEST_FOR_EXCEPTION(timeSteppingTool_->getButcherTableCoefficient(0 , 0) != 0.0, std::logic_error,
"Not implemented butchertable! First stage should have 0 diagonal value");
434 std::cout <<
"Currently in stage " << 1 <<
" of "<< timeSteppingTool_->getNmbStages() <<
" (dummy stage)"<< std::endl;
436 Teuchos::Array<BlockMatrixPtr_Type> matrixPrevStages;
437 BlockMultiVectorPtrArray_Type solutionPrevStages;
439 BlockMatrixPtr_Type blockMatrix = Teuchos::rcp(
new BlockMatrix_Type( problemTime_->getSystem()->size() ) );
440 problemTime_->reAssembleAndFill( blockMatrix );
442 matrixPrevStages.push_back( blockMatrix );
444 BlockMultiVectorPtr_Type sol =
445 Teuchos::rcp(
new BlockMultiVector_Type( problemTime_->getSolution() ) );
446 solutionPrevStages.push_back( sol );
448 for (
int stage=1; stage<timeSteppingTool_->getNmbStages(); stage++) {
449 double time = timeSteppingTool_->currentTime() + dt * timeSteppingTool_->getButcherTableC(stage);
450 problemTime_->updateTime( time );
452 std::cout <<
"Currently in stage " << stage+1 <<
" of "<< timeSteppingTool_->getNmbStages() << std::endl;
454 buildMultiStageRhs( stage, matrixPrevStages, solutionPrevStages );
456 TEUCHOS_TEST_FOR_EXCEPTION(problemTime_->hasSourceTerm(), std::logic_error,
"Using source term must be implemented for single-step methods.");
460 SmallMatrix<double> massCoeff(size);
461 SmallMatrix<double> problemCoeff(size);
463 getMassCoefficients(massCoeff);
464 getMultiStageCoefficients(problemCoeff, stage, stage,
false);
465 if (fullImplicitPressure && size>1 )
466 problemCoeff[0][1] = timeSteppingTool_->get_dt();
468 problemTime_->setTimeParameters(massCoeff, problemCoeff);
470 NonLinearSolver<SC, LO, GO, NO> nlSolver(parameterList_->sublist(
"General").get(
"Linearization",
"FixedPoint"));
471 nlSolver.solve(*problemTime_,time);
473 if (correctPressure) {
474 TEUCHOS_TEST_FOR_EXCEPTION( !fullImplicitPressure && !semiImplicitPressure, std::logic_error,
"There is no pressure that can be corrected." );
476 MultiVectorPtr_Type sol = problemTime_->getSolution()->getBlockNonConst(1);
477 MultiVectorConstPtr_Type solLast = problemTime_->getSolutionPreviousTimestep()->getBlock(1);
478 timeSteppingTool_->correctPressure( sol, solLast );
480 std::cout <<
"Pressure corrected." << std::endl;
483 if (stage+1 == timeSteppingTool_->getNmbStages()) {
485 BlockMultiVectorPtr_Type tmpSolution = Teuchos::rcp(
new BlockMultiVector_Type ( problemTime_->getSolution() ) );
487 solutionPrevStages.push_back( tmpSolution );
488 BlockMultiVectorPtr_Type tmpSolutionPtr = problemTime_->getSolution();
489 BlockMatrixPtr_Type tmpMassSystem = problemTime_->getMassSystem();
490 timeSteppingTool_->calculateSolution( tmpSolutionPtr, solutionPrevStages, tmpMassSystem, solShort);
493 BlockMatrixPtr_Type blockMatrix = Teuchos::rcp(
new BlockMatrix_Type( problemTime_->getSystem()->size() ) );
494 problemTime_->reAssembleAndFill( blockMatrix );
495 matrixPrevStages.push_back( blockMatrix );
497 BlockMultiVectorPtr_Type sol =
498 Teuchos::rcp(
new BlockMultiVector_Type( problemTime_->getSolution() ) );
499 solutionPrevStages.push_back( sol );
501 TEUCHOS_TEST_FOR_EXCEPTION(problemTime_->hasSourceTerm(), std::logic_error,
"Using source term must be implemented for single-step methods.");
505 timeSteppingTool_->advanceTime(
true);
510 if (parameterList_->sublist(
"NSParameter").get(
"Calculate Coefficients",
false)) {
511 vec_dbl_ptr_Type values(
new vec_dbl_Type(4));
512 TEUCHOS_TEST_FOR_EXCEPTION(
true, std::logic_error,
"Drag and Lift are not implemented.");
520 if (parameterList_->sublist(
"NSParameter").get(
"Calculate Coefficients",
false)) {
521 TEUCHOS_TEST_FOR_EXCEPTION(
true, std::logic_error,
"close txt exporters here.");
528template<
class SC,
class LO,
class GO,
class NO>
529void DAESolverInTime<SC,LO,GO,NO>::advanceWithLoadStepping()
532 bool print = parameterList_->sublist(
"General").get(
"ParaViewExport",
false);
533 bool printExtraData = parameterList_->sublist(
"General").get(
"Export Extra Data",
false);
534 bool printData = parameterList_->sublist(
"General").get(
"Export Data",
false);
540 vec_dbl_ptr_Type its = Teuchos::rcp(
new vec_dbl_Type ( 2, 0. ) );
541 ExporterTxtPtr_Type exporterTimeTxt;
542 ExporterTxtPtr_Type exporterIterations;
543 ExporterTxtPtr_Type exporterNewtonIterations;
545 std::string suffix = parameterList_->sublist(
"General").get(
"Export Suffix",
"");
547 exporterTimeTxt = Teuchos::rcp(
new ExporterTxt());
548 exporterTimeTxt->setup(
"time" + suffix, this->comm_ );
550 exporterNewtonIterations = Teuchos::rcp(
new ExporterTxt());
551 exporterNewtonIterations->setup(
"newtonIterations" + suffix, this->comm_ );
553 exporterIterations = Teuchos::rcp(
new ExporterTxt());
554 exporterIterations->setup(
"linearIterations" + suffix, this->comm_ );
557 int size = timeStepDef_.size();
558 TEUCHOS_TEST_FOR_EXCEPTION( size>1, std::runtime_error,
"Loadstepping only implemented or sensible for 1x1 Systems.");
559 double dt = timeSteppingTool_->get_dt();
563 SmallMatrix<double> massCoeff(size);
564 SmallMatrix<double> problemCoeff(size);
565 double coeffSourceTerm = 0.0;
568 massCoeff[0][0] = 0.;
569 problemCoeff[0][0] = 1.0;
571 coeffSourceTerm = 1.0;
574 vec_dbl_Type coeffTemp(1);
575 coeffTemp.at(0) = 1.0;
581 problemTime_->setTimeParameters(massCoeff, problemCoeff);
587 while(timeSteppingTool_->continueTimeStepping())
593 double time = timeSteppingTool_->currentTime() + dt;
594 problemTime_->updateTime ( time );
596 NonLinearSolver<SC, LO, GO, NO> nlSolver(parameterList_->sublist(
"General").get(
"Linearization",
"Newton"));
597 nlSolver.solve( *problemTime_, time, its );
599 timeSteppingTool_->advanceTime(
true);
601 exporterTimeTxt->exportData( timeSteppingTool_->currentTime() );
602 exporterIterations->exportData( (*its)[0] );
603 exporterNewtonIterations->exportData( (*its)[1] );
608 this->problemTime_->assemble(
"UpdateTime");
620template<
class SC,
class LO,
class GO,
class NO>
621void DAESolverInTime<SC,LO,GO,NO>::advanceInTimeLinearNewmark()
627 bool print = parameterList_->sublist(
"General").get(
"ParaViewExport",
false);
634 int size = timeStepDef_.size();
635 TEUCHOS_TEST_FOR_EXCEPTION( size>1, std::runtime_error,
"Newmark only implemented for systems of size 1x1.");
636 double dt = timeSteppingTool_->get_dt();
637 double beta = timeSteppingTool_->get_beta();
638 double gamma = timeSteppingTool_->get_gamma();
641 SmallMatrix<double> massCoeff(size);
642 SmallMatrix<double> problemCoeff(size);
643 double coeffSourceTerm = 0.0;
646 massCoeff[0][0] = 1.0/(dt*dt*beta);
647 problemCoeff[0][0] = 1.0;
649 coeffSourceTerm = 1.0;
652 vec_dbl_Type coeffTemp(1);
653 coeffTemp.at(0) = 1.0;
659 problemTime_->setTimeParameters(massCoeff, problemCoeff);
664 while(timeSteppingTool_->continueTimeStepping())
667 problemTime_->combineSystems();
670 problemTime_->updateSolutionNewmarkPreviousStep(dt, beta, gamma);
672 double time = timeSteppingTool_->currentTime() + dt;
673 problemTime_->updateTime ( timeSteppingTool_->currentTime() );
678 problemTime_->updateNewmarkRhs(dt, beta, gamma, coeffTemp);
682 if ( problemTime_->hasSourceTerm() )
685 problemTime_->assembleSourceTerm(time);
689 addSourceTermToRHS(coeffSourceTerm);
693 problemTime_->setBoundaries(time);
694 problemTime_->solve();
696 timeSteppingTool_->advanceTime(
true);
714template<
class SC,
class LO,
class GO,
class NO>
715void DAESolverInTime<SC,LO,GO,NO>::advanceInTimeNonLinearNewmark()
718 bool print = parameterList_->sublist(
"General").get(
"ParaViewExport",
false);
719 bool printExtraData = parameterList_->sublist(
"General").get(
"Export Extra Data",
false);
720 bool printData = parameterList_->sublist(
"General").get(
"Export Data",
false);
726 vec_dbl_ptr_Type its = Teuchos::rcp(
new vec_dbl_Type ( 2, 0. ) );
727 ExporterTxtPtr_Type exporterTimeTxt;
728 ExporterTxtPtr_Type exporterIterations;
729 ExporterTxtPtr_Type exporterNewtonIterations;
731 std::string suffix = parameterList_->sublist(
"General").get(
"Export Suffix",
"");
733 exporterTimeTxt = Teuchos::rcp(
new ExporterTxt());
734 exporterTimeTxt->setup(
"time" + suffix, this->comm_ );
736 exporterNewtonIterations = Teuchos::rcp(
new ExporterTxt());
737 exporterNewtonIterations->setup(
"newtonIterations" + suffix, this->comm_ );
739 exporterIterations = Teuchos::rcp(
new ExporterTxt());
740 exporterIterations->setup(
"linearIterations" + suffix, this->comm_ );
743 int size = timeStepDef_.size();
744 TEUCHOS_TEST_FOR_EXCEPTION( size>1, std::runtime_error,
"Newmark only implemented for systems of size 1x1.");
745 double dt = timeSteppingTool_->get_dt();
746 double beta = timeSteppingTool_->get_beta();
747 double gamma = timeSteppingTool_->get_gamma();
750 SmallMatrix<double> massCoeff(size);
751 SmallMatrix<double> problemCoeff(size);
752 double coeffSourceTerm = 0.0;
755 massCoeff[0][0] = 1.0/(dt*dt*beta);
756 problemCoeff[0][0] = 1.0;
758 coeffSourceTerm = 1.0;
761 vec_dbl_Type coeffTemp(1);
762 coeffTemp.at(0) = 1.0;
767 problemTime_->setTimeParameters(massCoeff, problemCoeff);
772 while(timeSteppingTool_->continueTimeStepping())
775 problemTime_->combineSystems();
778 problemTime_->updateSolutionNewmarkPreviousStep(dt, beta, gamma);
780 double time = timeSteppingTool_->currentTime() + dt;
781 problemTime_->updateTime ( time );
786 problemTime_->updateNewmarkRhs(dt, beta, gamma, coeffTemp);
790 if (problemTime_->hasSourceTerm())
793 problemTime_->assembleSourceTerm(time);
798 addSourceTermToRHS(coeffSourceTerm);
804 NonLinearSolver<SC, LO, GO, NO> nlSolver(parameterList_->sublist(
"General").get(
"Linearization",
"Newton"));
805 nlSolver.solve( *problemTime_, time, its );
807 timeSteppingTool_->advanceTime(
true);
809 exporterTimeTxt->exportData( timeSteppingTool_->currentTime() );
810 exporterIterations->exportData( (*its)[0] );
811 exporterNewtonIterations->exportData( (*its)[1] );
826template<
class SC,
class LO,
class GO,
class NO>
827void DAESolverInTime<SC,LO,GO,NO>::advanceInTimeFSI()
834 FSIProblemPtr_Type fsi = Teuchos::rcp_dynamic_cast<FSIProblem_Type>( this->problemTime_->getUnderlyingProblem() );
836 bool print = parameterList_->sublist(
"General").get(
"ParaViewExport",
false);
837 bool printData = parameterList_->sublist(
"General").get(
"Export Data",
false);
838 bool printExtraData = parameterList_->sublist(
"General").get(
"Export Extra Data",
false);
846 vec_dbl_ptr_Type its = Teuchos::rcp(
new vec_dbl_Type ( 2, 0. ) );
847 ExporterTxtPtr_Type exporterTimeTxt;
848 ExporterTxtPtr_Type exporterDisplXTxt;
849 ExporterTxtPtr_Type exporterDisplYTxt;
850 ExporterTxtPtr_Type exporterIterations;
851 ExporterTxtPtr_Type exporterNewtonIterations;
854 exporterTimeTxt = Teuchos::rcp(
new ExporterTxt());
855 exporterDisplXTxt = Teuchos::rcp(
new ExporterTxt());
856 exporterDisplYTxt = Teuchos::rcp(
new ExporterTxt());
857 exporterTimeTxt->setup(
"time", this->comm_ );
859 std::string suffix = parameterList_->sublist(
"General").get(
"Export Suffix",
"");
861 exporterNewtonIterations = Teuchos::rcp(
new ExporterTxt());
862 exporterNewtonIterations->setup(
"newtonIterations" + suffix, this->comm_ );
864 exporterIterations = Teuchos::rcp(
new ExporterTxt());
865 exporterIterations->setup(
"linearIterations" + suffix, this->comm_ );
867 if (printExtraData) {
869 vec_dbl_Type v(3,-9999.);
870 this->problemTime_->getValuesOfInterest(v);
871 vec_dbl_Type vGathered(this->comm_->getSize());
872 Teuchos::gatherAll<int,double>( *this->comm_, 1, &v[0], vGathered.size(), &vGathered[0] );
874 while (vGathered[targetRank] < 0){
876 TEUCHOS_TEST_FOR_EXCEPTION( targetRank == vGathered.size(), std::runtime_error,
"No targetRank for export of displacements was found!" );
879 std::string suffix = parameterList_->sublist(
"General").get(
"Export Suffix",
"");
881 exporterDisplXTxt->setup(
"displ_x" + suffix, this->comm_ , targetRank);
882 exporterDisplYTxt->setup(
"displ_y" + suffix, this->comm_ , targetRank);
887 bool geometryExplicit = this->parameterList_->sublist(
"Parameter").get(
"Geometry Explicit",
true);
888 int sizeFSI = timeStepDef_.size();
892 int sizeStructure = 1;
894 double dt = timeSteppingTool_->get_dt();
895 double beta = timeSteppingTool_->get_beta();
896 double gamma = timeSteppingTool_->get_gamma();
897 int nmbBDF = timeSteppingTool_->getBDFNumber();
902 SmallMatrix<double> massCoeffFluid(sizeFluid);
903 SmallMatrix<double> problemCoeffFluid(sizeFluid);
904 double coeffSourceTermFluid = 0.0;
906 for (
int i=0; i<sizeFluid; i++) {
907 for (
int j=0; j<sizeFluid; j++) {
908 if (timeStepDef_[i][j]>0 && i==j) {
909 massCoeffFluid[i][j] = timeSteppingTool_->getInformationBDF(0) / dt;
912 massCoeffFluid[i][j] = 0.0;
916 for (
int i=0; i<sizeFluid; i++) {
917 for (
int j=0; j<sizeFluid; j++){
918 if (timeStepDef_[i][j]>0){
919 problemCoeffFluid[i][j] = timeSteppingTool_->getInformationBDF(1);
920 coeffSourceTermFluid = timeSteppingTool_->getInformationBDF(1);
923 problemCoeffFluid[i][j] = 1.;
933 SmallMatrix<double> massCoeffStructure(sizeStructure);
934 SmallMatrix<double> problemCoeffStructure(sizeStructure);
935 double coeffSourceTermStructure = 0.0;
938 for(
int i = 0; i < sizeStructure; i++)
940 for(
int j = 0; j < sizeStructure; j++)
944 if(timeStepDef_[i + sizeFluid][j + sizeFluid] > 0 && i == j)
947 massCoeffStructure[i][j] = 1.0/(dt*dt*beta);
951 massCoeffStructure[i][j] = 0.;
958 for(
int i = 0; i < sizeStructure; i++)
960 for(
int j = 0; j < sizeStructure; j++)
962 if(timeStepDef_[i + sizeFluid][j + sizeFluid] > 0 )
964 problemCoeffStructure[i][j] = 1.0;
966 coeffSourceTermStructure = 1.0;
970 problemCoeffStructure[i][j] = 1.0;
979 SmallMatrix<double> massCoeffFSI(sizeFSI);
980 SmallMatrix<double> problemCoeffFSI(sizeFSI);
981 for (
int i = 0; i < sizeFluid; i++)
983 for (
int j = 0; j < sizeFluid; j++)
985 massCoeffFSI[i][j] = massCoeffFluid[i][j];
986 problemCoeffFSI[i][j] = problemCoeffFluid[i][j];
990 for (
int i = 0; i < sizeStructure; i++)
992 for (
int j = 0; j < sizeStructure; j++)
994 massCoeffFSI[i + sizeFluid][j + sizeFluid] = massCoeffStructure[i][j];
995 problemCoeffFSI[i + sizeFluid][j + sizeFluid] = problemCoeffStructure[i][j];
1000 problemCoeffFSI[0][3] = 1.0;
1001 problemCoeffFSI[2][3] = 1.0;
1002 problemCoeffFSI[3][0] = 1.0;
1003 problemCoeffFSI[3][2] = 1.0;
1004 if(!geometryExplicit)
1006 problemCoeffFSI[4][2] = 1.0;
1007 problemCoeffFSI[4][4] = 1.0;
1008 std::string linearization = this->parameterList_->sublist(
"General").get(
"Linearization",
"Extrapolation");
1009 if(linearization ==
"Newton" || linearization ==
"NOX")
1011 problemCoeffFSI[0][4] = 1.0;
1012 problemCoeffFSI[1][4] = 1.0;
1016 this->problemTime_->setTimeParameters(massCoeffFSI, problemCoeffFSI);
1018 if (printExtraData) {
1019 exporterTimeTxt->exportData( timeSteppingTool_->currentTime() );
1020 vec_dbl_Type v(3,0.);
1021 this->problemTime_->getValuesOfInterest( v );
1023 exporterDisplXTxt->exportData( v[0] );
1024 exporterDisplYTxt->exportData( v[1] );
1039 TimeMonitor_Type solveTM(*solveProblemTimer_);
1041 while(timeSteppingTool_->continueTimeStepping())
1043 problemTime_->updateTime ( timeSteppingTool_->currentTime() );
1045 std::string linearization = this->parameterList_->sublist(
"General").get(
"Linearization",
"Extrapolation");
1051 if(nmbBDF<2 && !parameterList_->sublist(
"General").get(
"Linearization",
"FixedPoint").compare(
"Extrapolation"))
1053 if (timeSteppingTool_->currentTime() != 0.0)
1055 this->problemTime_->updateSolutionMultiPreviousStep(2);
1059 this->problemTime_->updateSolutionMultiPreviousStep(1);
1064 this->problemTime_->updateSolutionMultiPreviousStep(nmbBDF);
1067#ifdef FEDD_DETAIL_TIMER
1068 TimeMonitor_Type reassmbleTM(*reassmbleAddInterfaceRHSTimer_);
1071 this->problemTime_->assemble(
"AddInterfaceBlockRHS");
1074#ifdef FEDD_DETAIL_TIMER
1075 TimeMonitor_Type reassmbleTM(*reassmbleUpdateMeshDisplacementTimer_);
1078 this->problemTime_->assemble(
"UpdateMeshDisplacement");
1081 if(geometryExplicit)
1084#ifdef FEDD_DETAIL_TIMER
1085 TimeMonitor_Type reassmbleTM(*reassmbleSolveGeometryTimer_);
1087 this->problemTime_->assemble(
"SolveGeometryProblem");
1089#ifdef FEDD_DETAIL_TIMER
1090 TimeMonitor_Type reassmbleTM(*reassmbleMoveMeshTimer_);
1092 this->problemTime_->assemble(
"MoveMesh");
1105#ifdef FEDD_DETAIL_TIMER
1106 TimeMonitor_Type reassmbleTM(*reassmbleSolidMassAndRHSTimer_);
1111 if(timeSteppingTool_->currentTime() == 0.0)
1114 MatrixPtr_Type massmatrix;
1115 fsi->setSolidMassmatrix( massmatrix );
1116 this->problemTime_->systemMass_->addBlock( massmatrix, 2, 2 );
1120 this->problemTime_->assemble(
"ComputeSolidRHSInTime");
1124 if(geometryExplicit)
1126#ifdef FEDD_DETAIL_TIMER
1127 TimeMonitor_Type reassmbleTM(*reassmbleForTimeTimer_);
1129 this->problemTime_->assemble(
"ForTime");
1138#ifdef FEDD_DETAIL_TIMER
1139 TimeMonitor_Type reassmbleTM(*reassmbleUpdateFluidInTimeTimer_);
1142 this->problemTime_->assemble(
"UpdateFluidInTime");
1148 MatrixPtr_Type massmatrix;
1149 fsi->setFluidMassmatrix( massmatrix );
1150 this->problemTime_->systemMass_->addBlock( massmatrix, 0, 0 );
1154 this->problemTime_->assemble(
"ComputeFluidRHSInTime" );
1162 if (timeSteppingTool_->currentTime() == 0.) {
1163 for (
int i = 0; i < sizeFluid; i++)
1165 for (
int j = 0; j < sizeFluid; j++){
1166 if (massCoeffFSI[i][j] != 0.)
1167 massCoeffFSI[i][j] = 1./dt ;
1170 this->problemTime_->setTimeParameters(massCoeffFSI, problemCoeffFSI);
1174 double time = timeSteppingTool_->currentTime() + dt;
1175 problemTime_->updateTime ( time );
1176 NonLinearSolver<SC, LO, GO, NO> nlSolver(parameterList_->sublist(
"General").get(
"Linearization",
"FixedPoint"));
1178 nlSolver.solve(*this->problemTime_, time, its);
1180 if (timeSteppingTool_->currentTime() <= dt+1.e-10) {
1181 for (
int i = 0; i < sizeFluid; i++)
1183 for (
int j = 0; j < sizeFluid; j++){
1184 massCoeffFSI[i][j] = massCoeffFluid[i][j];
1187 this->problemTime_->setTimeParameters(massCoeffFSI, problemCoeffFSI);
1190 this->problemTime_->computeValuesOfInterestAndExport();
1192 timeSteppingTool_->advanceTime(
true);
1193 this->problemTime_->assemble(
"UpdateTime");
1195 exporterTimeTxt->exportData( timeSteppingTool_->currentTime() );
1196 exporterIterations->exportData( (*its)[0] );
1197 exporterNewtonIterations->exportData( (*its)[1] );
1199 if (printExtraData) {
1200 vec_dbl_Type v(3,-9999.);
1201 this->problemTime_->getValuesOfInterest(v);
1203 exporterDisplXTxt->exportData( v[0] );
1204 exporterDisplYTxt->exportData( v[1] );
1214 if (printExtraData) {
1215 exporterTimeTxt->closeExporter();
1216 exporterIterations->closeExporter();
1217 exporterNewtonIterations->closeExporter();
1219 if (printExtraData) {
1220 exporterDisplXTxt->closeExporter();
1221 exporterDisplYTxt->closeExporter();
1231template<
class SC,
class LO,
class GO,
class NO>
1232void DAESolverInTime<SC,LO,GO,NO>::advanceInTimeLinearMultistep(){
1235 bool print = parameterList_->sublist(
"General").get(
"ParaViewExport",
false);
1239 int size = timeStepDef_.size();
1240 double dt = timeSteppingTool_->get_dt();
1241 int nmbBDF = timeSteppingTool_->getBDFNumber();
1242 vec_dbl_Type coeffPrevSteps(nmbBDF);
1243 for (
int i=0; i<coeffPrevSteps.size(); i++) {
1244 coeffPrevSteps.at(i) = timeSteppingTool_->getInformationBDF(i+2) / dt;
1247 SmallMatrix<double> massCoeff(size);
1248 SmallMatrix<double> problemCoeff(size);
1249 double coeffSourceTerm = 0.;
1251 for (
int i=0; i<size; i++) {
1252 for (
int j=0; j<size; j++) {
1253 if (timeStepDef_[i][j]==1 && i==j) {
1254 massCoeff[i][j] = timeSteppingTool_->getInformationBDF(0) / dt;
1257 massCoeff[i][j] = 0.;
1261 for (
int i=0; i<size; i++) {
1262 for (
int j=0; j<size; j++){
1263 if (timeStepDef_[i][j]==1){
1264 problemCoeff[i][j] = timeSteppingTool_->getInformationBDF(1);
1265 coeffSourceTerm = timeSteppingTool_->getInformationBDF(1);
1268 problemCoeff[i][j] = 1.;
1272 problemTime_->setTimeParameters(massCoeff, problemCoeff);
1277 while (timeSteppingTool_->continueTimeStepping()) {
1279 problemTime_->updateSolutionMultiPreviousStep(nmbBDF);
1281 double time = timeSteppingTool_->currentTime() + dt;
1282 problemTime_->updateMultistepRhs(coeffPrevSteps,nmbBDF);
1283 if (problemTime_->hasSourceTerm()) {
1284 problemTime_->assembleSourceTerm(time);
1285 addSourceTermToRHS(coeffSourceTerm);
1288 problemTime_->combineSystems();
1290 problemTime_->setBoundaries(time);
1291 problemTime_->solve();
1293 timeSteppingTool_->advanceTime(
true);
1307template<
class SC,
class LO,
class GO,
class NO>
1308void DAESolverInTime<SC,LO,GO,NO>::advanceInTimeNonLinearMultistep(){
1310 bool print = parameterList_->sublist(
"General").get(
"ParaViewExport",
false);
1315 int size = timeStepDef_.size();
1316 double dt = timeSteppingTool_->get_dt();
1317 int nmbBDF = timeSteppingTool_->getBDFNumber();
1319 vec_dbl_Type coeffPrevSteps(nmbBDF);
1320 for (
int i=0; i<coeffPrevSteps.size(); i++) {
1321 coeffPrevSteps.at(i) = timeSteppingTool_->getInformationBDF(i+2) / dt;
1324 SmallMatrix<double> massCoeff(size);
1325 SmallMatrix<double> problemCoeff(size);
1326 double coeffSourceTerm = 0.;
1328 for (
int i=0; i<size; i++) {
1329 for (
int j=0; j<size; j++) {
1330 if (timeStepDef_[i][j]>0 && i==j) {
1331 massCoeff[i][j] = timeSteppingTool_->getInformationBDF(0) / dt;
1334 massCoeff[i][j] = 0.;
1338 for (
int i=0; i<size; i++) {
1339 for (
int j=0; j<size; j++){
1340 if (timeStepDef_[i][j]>0){
1341 problemCoeff[i][j] = timeSteppingTool_->getInformationBDF(1);
1342 coeffSourceTerm = timeSteppingTool_->getInformationBDF(1);
1345 problemCoeff[i][j] = 1.;
1349 problemTime_->setTimeParameters(massCoeff, problemCoeff);
1353 while (timeSteppingTool_->continueTimeStepping()) {
1356 if (timeSteppingTool_->currentTime()==0.) {
1357 SmallMatrix<double> tmpmassCoeff(size);
1358 SmallMatrix<double> tmpproblemCoeff(size);
1359 for (
int i=0; i<size; i++) {
1360 for (
int j=0; j<size; j++) {
1361 if (timeStepDef_[i][j]>0 && i==j) {
1362 tmpmassCoeff[i][j] = 1. / dt;
1365 tmpmassCoeff[i][j] = 0.;
1369 for (
int i=0; i<size; i++) {
1370 for (
int j=0; j<size; j++){
1371 if (timeStepDef_[i][j]>0){
1372 tmpproblemCoeff[i][j] = 1.;
1375 tmpproblemCoeff[i][j] = 1.;
1379 problemTime_->setTimeParameters(tmpmassCoeff, tmpproblemCoeff);
1381 if(nmbBDF<2 && !parameterList_->sublist(
"General").get(
"Linearization",
"FixedPoint").compare(
"Extrapolation")) {
1382 if (timeSteppingTool_->currentTime()!=0.){
1383 problemTime_->updateSolutionMultiPreviousStep(2);
1386 problemTime_->updateSolutionMultiPreviousStep(1);
1390 problemTime_->updateSolutionMultiPreviousStep(nmbBDF);
1392 double time = timeSteppingTool_->currentTime() + dt;
1393 problemTime_->updateTime ( time );
1395 if (timeSteppingTool_->currentTime()==0.) {
1396 vec_dbl_Type tmpcoeffPrevSteps(1, 1. / dt);
1397 problemTime_->updateMultistepRhs(tmpcoeffPrevSteps,1);
1400 problemTime_->updateMultistepRhs(coeffPrevSteps,nmbBDF);
1402 if (problemTime_->hasSourceTerm()) {
1403 TEUCHOS_TEST_FOR_EXCEPTION(
true, std::logic_error,
"Check sourceterm.");
1413 NonLinearSolver<SC, LO, GO, NO> nlSolver(parameterList_->sublist(
"General").get(
"Linearization",
"FixedPoint"));
1414 nlSolver.solve(*problemTime_,time);
1417 if (timeSteppingTool_->currentTime()==0.) {
1418 problemTime_->setTimeParameters(massCoeff, problemCoeff);
1421 timeSteppingTool_->advanceTime(
true);
1434template<
class SC,
class LO,
class GO,
class NO>
1435void DAESolverInTime<SC,LO,GO,NO>::advanceInTimeLinearExternal(){
1436 bool print = parameterList_->sublist(
"General").get(
"ParaViewExport",
false);
1441 double dt = timeSteppingTool_->get_dt();
1446 while (timeSteppingTool_->continueTimeStepping()) {
1448 double time = timeSteppingTool_->currentTime() + dt;
1449 problemTime_->updateTime ( time );
1451 problemTime_->assemble(
"Assemble" );
1453 if (problemTime_->hasSourceTerm()){
1454 problemTime_->assembleSourceTerm(time);
1455 problemTime_->addToRhs( problemTime_->getSourceTerm() );
1458 problemTime_->setBoundaries( time );
1460 BlockMultiVectorPtr_Type tmpSol = Teuchos::rcp(
new BlockMultiVector_Type(problemTime_->getSolution()) );
1465 problemTime_->solve();
1469 problemTime_->getSolution()->update( 1., tmpSol, -1. );
1471 problemTime_->assemble(
"SetSolutionNewton" );
1473 problemTime_->assemble(
"OnlyUpdate" );
1475 problemTime_->assemble(
"SetSolutionInTime" );
1477 timeSteppingTool_->advanceTime(
true);
1488template<
class SC,
class LO,
class GO,
class NO>
1489void DAESolverInTime<SC,LO,GO,NO>::advanceInTimeNonLinearExternal(){
1491 bool print = parameterList_->sublist(
"General").get(
"ParaViewExport",
false);
1496 double dt = timeSteppingTool_->get_dt();
1501 while (timeSteppingTool_->continueTimeStepping()) {
1503 double time = timeSteppingTool_->currentTime() + dt;
1504 problemTime_->updateTime ( time );
1506 if (problemTime_->hasSourceTerm()){
1507 problemTime_->assembleSourceTerm(time);
1509 NonLinearSolver<SC, LO, GO, NO> nlSolver(parameterList_->sublist(
"General").get(
"Linearization",
"Newton"));
1510 nlSolver.solve(*problemTime_,time);
1511 problemTime_->assemble(
"OnlyUpdate" );
1513 problemTime_->assemble(
"SetSolutionInTime" );
1515 timeSteppingTool_->advanceTime(
true);
1527template<
class SC,
class LO,
class GO,
class NO>
1528void DAESolverInTime<SC,LO,GO,NO>::addRhsDAE(SmallMatrix<double> coeff, BlockMatrixPtr_Type bMat, BlockMultiVectorPtr_Type vec){
1530 BlockMultiVectorPtr_Type mv = Teuchos::rcp(
new BlockMultiVector_Type( vec ) );
1531 bMat->apply( *vec, *mv , coeff );
1532 problemTime_->getRhs()->update( 1., *mv, 1. );
1535template<
class SC,
class LO,
class GO,
class NO>
1536void DAESolverInTime<SC,LO,GO,NO>::addRhsDAE(SmallMatrix<double> coeff, BlockMultiVectorPtr_Type vec){
1537 TEUCHOS_TEST_FOR_EXCEPTION(
true, std::logic_error,
"Is this correct? addRhsDAE!");
1538 for (
int i=0; i<vec->size(); i++)
1539 problemTime_->getRhs()->getBlockNonConst(i)->update( coeff[i][i], vec->getBlock(i), 1. );
1542template<
class SC,
class LO,
class GO,
class NO>
1543void DAESolverInTime<SC,LO,GO,NO>::addSourceTermToRHS(
double coeff)
1545 BlockMultiVectorPtr_Type tmpMV = problemTime_->getSourceTerm();
1547 problemTime_->getRhs()->update(coeff, *tmpMV, 1.);
1550template<
class SC,
class LO,
class GO,
class NO>
1551void DAESolverInTime<SC,LO,GO,NO>::exportTimestep(){
1553 if (!boolExporterSetup_) {
1557 std::cout <<
"-- Exporting..."<< std::flush;
1559 for (
int i=0; i<exporter_vector_.size(); i++) {
1561 exporter_vector_[i]->save( timeSteppingTool_->currentTime() );
1566 std::cout <<
"done! --"<< std::endl;
1571template<
class SC,
class LO,
class GO,
class NO>
1572void DAESolverInTime<SC,LO,GO,NO>::exportTimestep(BlockMultiVectorPtr_Type& solShort){
1574 if (!boolExporterSetup_) {
1575 setupExporter(solShort);
1578 std::cout <<
"-- Exporting..."<< std::flush;
1580 for (
int i=0; i<exporter_vector_.size(); i++) {
1582 exporter_vector_[i]->save( timeSteppingTool_->currentTime() );
1587 std::cout <<
"done! --"<< std::endl;
1592template<
class SC,
class LO,
class GO,
class NO>
1593void DAESolverInTime<SC,LO,GO,NO>::closeExporter(){
1595 if (boolExporterSetup_) {
1596 for (
int i=0; i<exporter_vector_.size(); i++)
1597 exporter_vector_[i]->closeExporter();
1602template<
class SC,
class LO,
class GO,
class NO>
1603void DAESolverInTime<SC,LO,GO,NO>::setupExporter(){
1604 for (
int i=0; i<timeStepDef_.size(); i++) {
1606 bool exportThisBlock =
true;
1607 if(this->parameterList_->sublist(
"Parameter").get(
"FSI",
false) ==
true )
1608 exportThisBlock = (i != 3);
1609 else if(this->parameterList_->sublist(
"Parameter").get(
"FSCI",
false) ==
true)
1610 exportThisBlock = (i != 4);
1614 ExporterPtr_Type exporterPtr(
new Exporter_Type());
1615 MultiVectorConstPtr_Type exportVector = problemTime_->getSolution()->getBlock(i);
1617 DomainConstPtr_Type dom = problemTime_->getDomain(i);
1619 int exportEveryXTimesteps = parameterList_->sublist(
"Exporter").get(
"Export every X timesteps", 1 );
1620 std::string plSuffix =
"Suffix variable" + std::to_string(i+1);
1621 std::string suffix = parameterList_->sublist(
"Exporter").get(plSuffix,
"" );
1622 std::string varName = problemTime_->getVariableName(i) + suffix;
1623 MeshPtr_Type meshNonConst = Teuchos::rcp_const_cast<Mesh_Type>(dom->getMesh());
1624 exporterPtr->setup(varName, meshNonConst, dom->getFEType(), parameterList_);
1628 UN dofsPerNode = problemTime_->getDofsPerNode(i);
1630 if (dofsPerNode == 1)
1631 exporterPtr->addVariable( exportVector, varName,
"Scalar", dofsPerNode, dom->getMapUnique() );
1633 exporterPtr->addVariable( exportVector, varName,
"Vector", dofsPerNode, dom->getMapUnique() );
1635 exporter_vector_.push_back(exporterPtr);
1636 export_solution_vector_.push_back(exportVector);
1639 boolExporterSetup_ =
true;
1643template<
class SC,
class LO,
class GO,
class NO>
1644void DAESolverInTime<SC,LO,GO,NO>::setupExporter(BlockMultiVectorPtr_Type& solShort){
1645 for (
int i=0; i<timeStepDef_.size(); i++) {
1647 bool exportThisBlock =
true;
1648 exportThisBlock = !(this->parameterList_->sublist(
"Parameter").get(
"FSI",
false) && i == 3);
1651 ExporterPtr_Type exporterPtr(
new Exporter_Type());
1652 MultiVectorConstPtr_Type exportVector = problemTime_->getSolution()->getBlock(i);
1653 MultiVectorConstPtr_Type exportVectorShort = solShort->getBlock(i);
1655 DomainConstPtr_Type dom = problemTime_->getDomain(i);
1657 int exportEveryXTimesteps = parameterList_->sublist(
"Exporter").get(
"Export every X timesteps", 1 );
1658 std::string plSuffix =
"Suffix variable" + std::to_string(i+1);
1659 std::string suffix = parameterList_->sublist(
"Exporter").get(plSuffix,
"" );
1660 std::string varName = problemTime_->getVariableName(i) + suffix;
1661 std::string varNameShort = problemTime_->getVariableName(i) +
"_short_" + suffix;
1663 MeshPtr_Type meshNonConst = Teuchos::rcp_const_cast<Mesh_Type>(dom->getMesh());
1664 exporterPtr->setup(varName, meshNonConst, dom->getFEType(), parameterList_);
1668 UN dofsPerNode = problemTime_->getDofsPerNode(i);
1670 if (dofsPerNode == 1){
1671 exporterPtr->addVariable( exportVector, varName,
"Scalar", dofsPerNode, dom->getMapUnique() );
1672 exporterPtr->addVariable( exportVectorShort, varNameShort,
"Scalar", dofsPerNode, dom->getMapUnique() );
1675 exporterPtr->addVariable( exportVector, varName,
"Vector", dofsPerNode, dom->getMapUnique() );
1676 exporterPtr->addVariable( exportVectorShort, varNameShort,
"Vector", dofsPerNode, dom->getMapUnique() );
1680 exporter_vector_.push_back(exporterPtr);
1681 export_solution_vector_.push_back(exportVector);
1684 boolExporterSetup_ =
true;
1690template<
class SC,
class LO,
class GO,
class NO>
1691void DAESolverInTime<SC,LO,GO,NO>::setupTimeStepping(){
1693 int size = this->problem_->getSystem()->size();
1695 problemTime_.reset(
new TimeProblem<SC,LO,GO,NO>(*this->problem_,comm_));
1698 if(this->parameterList_->sublist(
"Parameter").get(
"FSI",
false) || this->parameterList_->sublist(
"Parameter").get(
"SCI",
false) || this->parameterList_->sublist(
"Parameter").get(
"FSCI",
false))
1702 this->problemTime_->systemMass_.reset(
new BlockMatrix_Type(this->problemTime_->getSystem()->size()));
1703 this->problemTime_->systemCombined_.reset(
new BlockMatrix_Type( this->problemTime_->getSystem()->size() ));
1707 size = timeStepDef_.size();
1708 SmallMatrix<double> massCoeff(size);
1709 SmallMatrix<double> problemCoeff(size);
1711 for (
int i=0; i<size; i++) {
1712 for (
int j=0; j<size; j++) {
1713 if (timeStepDef_[i][j]>1 && i==j) {
1714 massCoeff[i][j] = 1.0;
1717 massCoeff[i][j] = 0.;
1724 problemTime_->setTimeParameters(massCoeff,problemCoeff);
1728 problemTime_->setTimeDef( timeStepDef_ );
1729 problemTime_->assemble(
"MassSystem" );
1735template<
class SC,
class LO,
class GO,
class NO>
1736void DAESolverInTime<SC,LO,GO,NO>::setTimeStep(
double dt){
1738 checkTimeSteppingDef();
1743template<
class SC,
class LO,
class GO,
class NO>
1744void DAESolverInTime<SC,LO,GO,NO>::setFinalTime(
double T){
1746 checkTimeSteppingDef();
1750template<
class SC,
class LO,
class GO,
class NO>
1751void DAESolverInTime<SC,LO,GO,NO>::checkTimeSteppingDef(){
1752#ifdef ASSERTS_WARNINGS
1753 MYASSERT(isTimeSteppingDefined_,
"Time stepping not defined!");
Adaptive Mesh Refinement.
Definition AdaptiveMeshRefinement.cpp:5