114 std::cout <<
"\t CoarseOperator Type: "
115 << pListThyraPrec->sublist(
"Preconditioner Types").sublist(
"FROSch").get(
"CoarseOperator Type",
"GDSWCoarseOperator") << std::endl;
117 for (
int i = 0; i < this->parameterList_->get(
"Number of blocks", 2); i++)
119 std::cout <<
"\t \t # Block " << i + 1 <<
"\t d.o.f.s: "
120 << pListThyraPrec->sublist(
"Preconditioner Types").sublist(
"FROSch").get(
"DofsPerNode" + std::to_string(i + 1), 1)
121 <<
"\t d.o.f. ordering: "
122 << pListThyraPrec->sublist(
"Preconditioner Types").sublist(
"FROSch").get(
"DofOrdering" + std::to_string(i + 1),
"NodeWise") << std::endl;
127 std::cout <<
"\t ### Full preconditioner information only available for Monolithic preconditioner type ###" << std::endl;
132 template <
class SC,
class LO,
class GO,
class NO>
133 void Problem<SC, LO, GO, NO>::initializeProblem(
int nmbVectors)
136 this->system_.reset(
new BlockMatrix_Type(1));
137 this->initializeVectors(nmbVectors);
140 template <
class SC,
class LO,
class GO,
class NO>
143 this->rhsFuncVec_.push_back(func);
145 template <
class SC,
class LO,
class GO,
class NO>
148 if (this->rhsFuncVec_.size() <= i + 1)
149 this->rhsFuncVec_[i] = func;
150 else if (this->rhsFuncVec_.size() == i)
151 this->rhsFuncVec_.push_back(func);
153 TEUCHOS_TEST_FOR_EXCEPTION(
true, std::runtime_error,
"Insertion Index smaller then size of vector");
175 template <
class SC,
class LO,
class GO,
class NO>
178 return rhsFuncVec_[i];
181 template <
class SC,
class LO,
class GO,
class NO>
182 void Problem<SC, LO, GO, NO>::addVariable(
const DomainConstPtr_Type &domain, std::string FEType, std::string name,
int dofsPerNode)
185 domainPtr_vec_.push_back(domain);
186 domain_FEType_vec_.push_back(FEType);
187 variableName_vec_.push_back(name);
188 feFactory_->addFE(domain);
189 dofsPerNode_vec_.push_back(dofsPerNode);
199 template <
class SC,
class LO,
class GO,
class NO>
200 void Problem<SC, LO, GO, NO>::assembleSourceTerm(
double time)
const
203 TEUCHOS_TEST_FOR_EXCEPTION(sourceTerm_.is_null(), std::runtime_error,
"Initialize source term before you assemble it - sourceTerm pointer is null");
204 this->sourceTerm_->putScalar(0.);
205 std::string sourceType = parameterList_->sublist(
"Parameter").get(
"Source Type",
"volume");
207 if (sourceType ==
"volume")
208 assembleVolumeTerm(time);
209 else if (sourceType ==
"surface")
210 assembleSurfaceTerm(time);
213 template <
class SC,
class LO,
class GO,
class NO>
214 void Problem<SC, LO, GO, NO>::assembleVolumeTerm(
double time)
const
216 for (UN i = 0; i < sourceTerm_->size(); i++)
218 if (this->rhsFuncVec_.size() > i)
220 if (!this->rhsFuncVec_[i].empty())
222 MultiVectorPtr_Type FERhs;
224 vec_dbl_Type funcParameter(1, 0.);
225 funcParameter[0] = time;
228 for (
int j = 0; j < parasSourceFunc_.size(); j++)
229 funcParameter.push_back(parasSourceFunc_[j]);
232 if (this->getDofsPerNode(i) > 1)
234 FERhs = Teuchos::rcp(
new MultiVector_Type(this->domainPtr_vec_.at(i)->getMapVecFieldRepeated()));
239 FERhs = Teuchos::rcp(
new MultiVector_Type(this->domainPtr_vec_.at(i)->getMapRepeated()));
243 this->feFactory_->assemblyRHS(this->dim_,
244 this->domain_FEType_vec_.at(i),
247 this->rhsFuncVec_[i],
250 this->sourceTerm_->getBlockNonConst(i)->exportFromVector(FERhs,
false,
"Add");
256 template <
class SC,
class LO,
class GO,
class NO>
257 void Problem<SC, LO, GO, NO>::assembleSurfaceTerm(
double time)
const
259 for (UN i = 0; i < sourceTerm_->size(); i++)
261 if (this->rhsFuncVec_.size() > i)
264 if (!this->rhsFuncVec_[i].empty())
266 MultiVectorPtr_Type FERhs;
268 vec_dbl_Type funcParameter(1, 0.);
269 funcParameter[0] = time;
272 for (
int j = 0; j < parasSourceFunc_.size(); j++)
273 funcParameter.push_back(parasSourceFunc_[j]);
276 funcParameter.push_back(funcParameter[funcParameter.size() - 1]);
278 if (this->getDofsPerNode(i) > 1)
280 FERhs = Teuchos::rcp(
new MultiVector_Type(this->domainPtr_vec_.at(i)->getMapVecFieldRepeated()));
285 FERhs = Teuchos::rcp(
new MultiVector_Type(this->domainPtr_vec_.at(i)->getMapRepeated()));
289 this->feFactory_->assemblySurfaceIntegral(this->getDomain(i)->getDimension(),
290 this->getDomain(i)->getFEType(),
293 this->rhsFuncVec_[i],
296 this->sourceTerm_->getBlockNonConst(i)->exportFromVector(FERhs,
false,
"Add");
303 template <
class SC,
class LO,
class GO,
class NO>
304 int Problem<SC, LO, GO, NO>::solve(BlockMultiVectorPtr_Type rhs)
308 std::cout <<
"-- Solve System ..." << std::endl;
312 TimeMonitor_Type solveTM(*solveProblemTimer_);
314 LinearSolver<SC, LO, GO, NO> linSolver;
315 std::string type = parameterList_->sublist(
"General").get(
"Preconditioner Method",
"Monolithic");
316 its = linSolver.solve(
this, rhs, type);
320 std::cout <<
" done -- " << std::endl;
325 template <
class SC,
class LO,
class GO,
class NO>
326 void Problem<SC, LO, GO, NO>::setupPreconditioner(std::string type)
const
329 preconditioner_->buildPreconditioner(type);
332 template <
class SC,
class LO,
class GO,
class NO>
333 void Problem<SC, LO, GO, NO>::initializePreconditioner(std::string type)
const
336 preconditioner_->initializePreconditioner(type);
339 template <
class SC,
class LO,
class GO,
class NO>
340 void Problem<SC, LO, GO, NO>::addBoundaries(
const BCConstPtr_Type &bcFactory)
343 bcFactory_ = bcFactory;
346 template <
class SC,
class LO,
class GO,
class NO>
347 void Problem<SC, LO, GO, NO>::setBoundaries(
double time)
const
350 TimeMonitor_Type bcMatTM(*bcMatrixTimer_);
351 TimeMonitor_Type bcRHSTM(*bcRHSTimer_);
353 bcFactory_->set(system_, rhs_, time);
356 template <
class SC,
class LO,
class GO,
class NO>
357 void Problem<SC, LO, GO, NO>::setBoundariesRHS(
double time)
const
360 TimeMonitor_Type bcRHSTM(*bcRHSTimer_);
362 bcFactory_->setRHS(rhs_, time);
365 template <
class SC,
class LO,
class GO,
class NO>
366 void Problem<SC, LO, GO, NO>::setAllDirichletZero(BlockMultiVectorPtr_Type u)
const
369 TimeMonitor_Type bcRHSTM(*bcRHSTimer_);
371 bcFactory_->setAllDirichletZero(u);
374 template <
class SC,
class LO,
class GO,
class NO>
375 void Problem<SC, LO, GO, NO>::setBoundariesSystem()
const
378 TimeMonitor_Type bcMatTM(*bcMatrixTimer_);
380 bcFactory_->setSystem(system_);
383 template <
class SC,
class LO,
class GO,
class NO>
384 void Problem<SC, LO, GO, NO>::initializeVectors(
int nmbVectors)
387 UN size = domainPtr_vec_.size();
388 solution_.reset(
new BlockMultiVector_Type(size));
389 rhs_.reset(
new BlockMultiVector_Type(size));
390 sourceTerm_.reset(
new BlockMultiVector_Type(size));
391 rhsFuncVec_.resize(size);
393 for (UN i = 0; i < size; i++)
395 if (dofsPerNode_vec_[i] > 1)
397 MapConstPtr_Type map = domainPtr_vec_[i]->getMapVecFieldUnique();
398 MultiVectorPtr_Type solutionPart = Teuchos::rcp(
new MultiVector_Type(map));
399 solution_->addBlock(solutionPart, i);
400 MultiVectorPtr_Type rhsPart = Teuchos::rcp(
new MultiVector_Type(map));
401 rhs_->addBlock(rhsPart, i);
402 MultiVectorPtr_Type sourceTermPart = Teuchos::rcp(
new MultiVector_Type(map));
403 sourceTerm_->addBlock(sourceTermPart, i);
407 MapConstPtr_Type map = domainPtr_vec_[i]->getMapUnique();
408 MultiVectorPtr_Type solutionPart = Teuchos::rcp(
new MultiVector_Type(map));
409 solution_->addBlock(solutionPart, i);
410 MultiVectorPtr_Type rhsPart = Teuchos::rcp(
new MultiVector_Type(map));
411 rhs_->addBlock(rhsPart, i);
412 MultiVectorPtr_Type sourceTermPart = Teuchos::rcp(
new MultiVector_Type(map));
413 sourceTerm_->addBlock(sourceTermPart, i);
418 template <
class SC,
class LO,
class GO,
class NO>
419 typename Problem<SC, LO, GO, NO>::BlockMultiVectorPtr_Type Problem<SC, LO, GO, NO>::getRhs()
425 template <
class SC,
class LO,
class GO,
class NO>
426 typename Problem<SC, LO, GO, NO>::BlockMultiVectorPtr_Type Problem<SC, LO, GO, NO>::getRhs()
const
432 template <
class SC,
class LO,
class GO,
class NO>
433 typename Problem<SC, LO, GO, NO>::BlockMultiVectorPtr_Type Problem<SC, LO, GO, NO>::getSolution()
439 template <
class SC,
class LO,
class GO,
class NO>
440 typename Problem<SC, LO, GO, NO>::BlockMatrixPtr_Type Problem<SC, LO, GO, NO>::getSystem()
const
446 template <
class SC,
class LO,
class GO,
class NO>
447 typename Problem<SC, LO, GO, NO>::PreconditionerPtr_Type Problem<SC, LO, GO, NO>::getPreconditioner()
449 return preconditioner_;
452 template <
class SC,
class LO,
class GO,
class NO>
453 typename Problem<SC, LO, GO, NO>::PreconditionerConstPtr_Type Problem<SC, LO, GO, NO>::getPreconditionerConst()
const
455 return preconditioner_;
458 template <
class SC,
class LO,
class GO,
class NO>
459 void Problem<SC, LO, GO, NO>::setPreconditionerThyraFromLinOp(ThyraLinOpPtr_Type precLinOp)
461 preconditioner_->setPreconditionerThyraFromLinOp(precLinOp);
464 template <
class SC,
class LO,
class GO,
class NO>
465 bool Problem<SC, LO, GO, NO>::getVerbose()
const
471 template <
class SC,
class LO,
class GO,
class NO>
472 typename Problem<SC, LO, GO, NO>::FEFacConstPtr_Type Problem<SC, LO, GO, NO>::getFEFactory()
478 template <
class SC,
class LO,
class GO,
class NO>
479 typename Problem<SC, LO, GO, NO>::BCConstPtr_Type Problem<SC, LO, GO, NO>::getBCFactory()
485 template <
class SC,
class LO,
class GO,
class NO>
486 typename Problem<SC, LO, GO, NO>::DomainConstPtr_Type Problem<SC, LO, GO, NO>::getDomain(
int i)
const
489 return domainPtr_vec_.at(i);
492 template <
class SC,
class LO,
class GO,
class NO>
493 std::string Problem<SC, LO, GO, NO>::getFEType(
int i)
const
496 return domain_FEType_vec_.at(i);
499 template <
class SC,
class LO,
class GO,
class NO>
500 std::string Problem<SC, LO, GO, NO>::getVariableName(
int i)
const
503 return variableName_vec_.at(i);
506 template <
class SC,
class LO,
class GO,
class NO>
507 int Problem<SC, LO, GO, NO>::getDofsPerNode(
int i)
const
510 return dofsPerNode_vec_.at(i);
513 template <
class SC,
class LO,
class GO,
class NO>
514 typename Problem<SC, LO, GO, NO>::ParameterListPtr_Type Problem<SC, LO, GO, NO>::getParameterList()
const
517 return parameterList_;
520 template <
class SC,
class LO,
class GO,
class NO>
521 void Problem<SC, LO, GO, NO>::addToRhs(BlockMultiVectorPtr_Type x)
const
524 rhs_->update(1., *x, 1.);
527 template <
class SC,
class LO,
class GO,
class NO>
528 typename Problem<SC, LO, GO, NO>::BlockMultiVectorPtr_Type Problem<SC, LO, GO, NO>::getSourceTerm()
530 TEUCHOS_TEST_FOR_EXCEPTION(sourceTerm_.is_null(), std::runtime_error,
"Problem has no source term to return - source term pointer is null");
534 template <
class SC,
class LO,
class GO,
class NO>
535 bool Problem<SC, LO, GO, NO>::hasSourceTerm()
const
537 for (
int i = 0; i < rhsFuncVec_.size(); i++)
539 if (!rhsFuncVec_[i].empty())
545 template <
class SC,
class LO,
class GO,
class NO>
546 void Problem<SC, LO, GO, NO>::initSolutionWithVector(MultiVector_Type &mv)
548 TEUCHOS_TEST_FOR_EXCEPTION(
true, std::runtime_error,
"initSolutionWithVector not implemented. DO we need this?");
553 template <
class SC,
class LO,
class GO,
class NO>
554 void Problem<SC, LO, GO, NO>::initializeSolverBuilder()
const
557 ParameterListPtr_Type pListThyraPrec = sublist(parameterList_,
"ThyraPreconditioner");
559 linearSolverBuilder_->setParameterList(pListThyraPrec);
567 template <
class SC,
class LO,
class GO,
class NO>
568 double Problem<SC, LO, GO, NO>::calculateL2Norm(MultiVectorConstPtr_Type mv,
int domainInd)
572 M = Teuchos::rcp(
new Matrix_Type(this->domainPtr_vec_.at(domainInd)->getMapUnique(), this->getDomain(domainInd)->getApproxEntriesPerRow()));
573 this->feFactory_->assemblyMass(this->dim_, this->domain_FEType_vec_.at(domainInd),
"Scalar", M);
575 Teuchos::RCP<MultiVector<SC, LO, GO, NO>> mvOutput = Teuchos::rcp(
new MultiVector_Type(this->domainPtr_vec_.at(domainInd)->getMapUnique()));
577 M->apply(*mv, *mvOutput);
579 Teuchos::ArrayRCP<SC> vector = mv->getDataNonConst(0);
580 Teuchos::ArrayRCP<SC> outputVector = mvOutput->getDataNonConst(0);
583 for (
int i = 0; i < vector.size(); i++)
585 result += vector[i] * outputVector[i];
587 reduceAll<int, double>(*comm_, REDUCE_SUM, result, outArg(result));
591 template <
class SC,
class LO,
class GO,
class NO>
592 double Problem<SC, LO, GO, NO>::calculateH1Norm(MultiVectorConstPtr_Type mv,
int blockId1,
int blockId2,
int domainInd)
595 MatrixPtr_Type K = this->getSystem()->getBlock(blockId1, blockId2);
597 Teuchos::RCP<MultiVector<SC, LO, GO, NO>> mvOutput = Teuchos::rcp(
new MultiVector_Type(K->getMap()));
599 K->apply(*mv, *mvOutput);
601 Teuchos::ArrayRCP<SC> vector = mv->getDataNonConst(0);
602 Teuchos::ArrayRCP<SC> outputVector = mvOutput->getDataNonConst(0);
605 for (
int i = 0; i < vector.size(); i++)
607 result += vector[i] * outputVector[i];
609 reduceAll<int, double>(*comm_, REDUCE_SUM, result, outArg(result));