Skip to content

Commit d9c9f71

Browse files
committed
Updates in new trilinos implementation:
* add timer for the linear solver in Trilinos * add the possibility to read the MueLu Options for the ML preconditioner from file mueluOptions.xml if file is not present built-in parameters are used
1 parent 80d2430 commit d9c9f71

File tree

2 files changed

+34
-2
lines changed

2 files changed

+34
-2
lines changed

Code/Source/solver/trilinos_impl.cpp

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -593,7 +593,15 @@ void trilinos_solve_(const Teuchos::RCP<Trilinos> &trilinos_, double *x, const d
593593

594594
// Run the solver (solve() handles restarts internally)
595595
converged = false;
596+
597+
Teuchos::Time timer("Belos Solve Timer");
598+
timer.start();
599+
596600
Belos::ReturnType result = solverManager->solve();
601+
602+
timer.stop();
603+
604+
solverTime = timer.totalElapsedTime();
597605

598606
if (result == Belos::Converged) {
599607
converged = true;
@@ -735,7 +743,9 @@ void setMueLuPreconditioner(Teuchos::RCP<MueLu_Preconditioner> &MueLuPrec,
735743
const Teuchos::RCP<Tpetra_CrsMatrix> &A)
736744
{
737745
// MueLuPrec is now a Tpetra::Operator that can be plug into BelosProblem
738-
// The following parameters proved to be generally good for big FSI problems
746+
std::string optionsFile = "mueluOptions.xml";
747+
748+
// The following built-in parameters proved to be generally good for big FSI problems
739749
Teuchos::ParameterList mueluParams;
740750

741751
mueluParams.set("verbosity", "none");
@@ -775,7 +785,28 @@ void setMueLuPreconditioner(Teuchos::RCP<MueLu_Preconditioner> &MueLuPrec,
775785
mueluParams.set("coarse: max size", 2000);
776786

777787
// Create MueLu preconditioner from matrix and parameter list, as Tpetra::Operator
778-
MueLuPrec = MueLu::CreateTpetraPreconditioner(Teuchos::rcp_static_cast<Tpetra_Operator>(A), mueluParams);
788+
std::ifstream ifs(optionsFile.c_str());
789+
if (ifs.good())
790+
{
791+
try
792+
{
793+
MueLuPrec = MueLu::CreateTpetraPreconditioner(
794+
Teuchos::rcp_static_cast<Tpetra_Operator>(A), optionsFile);
795+
}
796+
catch (std::exception &e)
797+
{
798+
std::cerr << "[MueLu Warning]: failed to create MueLu from file '" << optionsFile
799+
<< "': " << e.what() << "\n Falling back to built-in parameters.\n";
800+
MueLuPrec = MueLu::CreateTpetraPreconditioner(
801+
Teuchos::rcp_static_cast<Tpetra_Operator>(A), mueluParams);
802+
}
803+
}
804+
else
805+
{
806+
MueLuPrec = MueLu::CreateTpetraPreconditioner(
807+
Teuchos::rcp_static_cast<Tpetra_Operator>(A), mueluParams);
808+
}
809+
779810
}
780811

781812
// ----------------------------------------------------------------------------

Code/Source/solver/trilinos_impl.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
// Theuchos includes
2323
#include "Teuchos_RCP.hpp"
2424
#include "Teuchos_DefaultComm.hpp"
25+
#include <Teuchos_Time.hpp>
2526

2627
#include "Kokkos_Core.hpp"
2728
#include "Tpetra_KokkosCompat_ClassicNodeAPI_Wrapper.hpp"

0 commit comments

Comments
 (0)