| 1 |
// @HEADER |
| 2 |
// ***************************************************************************** |
| 3 |
// ShyLU: Scalable Hybrid LU Preconditioner and Solver |
| 4 |
// |
| 5 |
// Copyright 2011 NTESS and the ShyLU contributors. |
| 6 |
// SPDX-License-Identifier: BSD-3-Clause |
| 7 |
// ***************************************************************************** |
| 8 |
// @HEADER |
| 9 |
|
| 10 |
#ifndef _FROSCH_SUBDOMAINSOLVER_DECL_HPP |
| 11 |
#define _FROSCH_SUBDOMAINSOLVER_DECL_HPP |
| 12 |
|
| 13 |
#include <ShyLU_DDFROSch_config.h> |
| 14 |
|
| 15 |
#include <FROSch_Output.h> |
| 16 |
#include <FROSch_Timers.h> |
| 17 |
|
| 18 |
#include <FROSch_Tools_decl.hpp> |
| 19 |
|
| 20 |
#ifdef HAVE_SHYLU_DDFROSCH_EPETRA |
| 21 |
#include "Epetra_LinearProblem.h" |
| 22 |
#endif |
| 23 |
|
| 24 |
#ifdef HAVE_SHYLU_DDFROSCH_AMESOS |
| 25 |
#include "Amesos_ConfigDefs.h" |
| 26 |
#include "Amesos.h" |
| 27 |
#include "Amesos_BaseSolver.h" |
| 28 |
#endif |
| 29 |
|
| 30 |
#include "Amesos2.hpp" |
| 31 |
|
| 32 |
#ifdef HAVE_SHYLU_DDFROSCH_BELOS |
| 33 |
#include <BelosXpetraAdapterOperator.hpp> |
| 34 |
#include <BelosOperatorT.hpp> |
| 35 |
#include <BelosXpetraAdapter.hpp> |
| 36 |
#include <BelosSolverFactory.hpp> |
| 37 |
#endif |
| 38 |
|
| 39 |
#ifdef HAVE_SHYLU_DDFROSCH_MUELU |
| 40 |
//#include <MueLu.hpp> |
| 41 |
#include <MueLu_TpetraOperator.hpp> |
| 42 |
#include <MueLu_CreateTpetraPreconditioner.hpp> |
| 43 |
#include <MueLu_Utilities.hpp> |
| 44 |
#endif |
| 45 |
|
| 46 |
#ifdef HAVE_SHYLU_DDFROSCH_IFPACK2 |
| 47 |
#include <Ifpack2_Details_OneLevelFactory_decl.hpp> |
| 48 |
#endif |
| 49 |
|
| 50 |
#ifdef HAVE_SHYLU_DDFROSCH_THYRA |
| 51 |
#include "Stratimikos_LinearSolverBuilder.hpp" |
| 52 |
#ifdef HAVE_SHYLU_DDFROSCH_IFPACK2 |
| 53 |
#include "Teuchos_AbstractFactoryStd.hpp" |
| 54 |
#include "Thyra_Ifpack2PreconditionerFactory.hpp" |
| 55 |
#endif |
| 56 |
#endif |
| 57 |
|
| 58 |
|
| 59 |
namespace FROSch { |
| 60 |
|
| 61 |
using namespace std; |
| 62 |
using namespace Teuchos; |
| 63 |
using namespace Xpetra; |
| 64 |
|
| 65 |
template <class SC, |
| 66 |
class LO, |
| 67 |
class GO, |
| 68 |
class NO> |
| 69 |
class OneLevelPreconditioner; |
| 70 |
|
| 71 |
template<class SC, |
| 72 |
class LO, |
| 73 |
class GO, |
| 74 |
class NO> |
| 75 |
class TwoLevelPreconditioner; |
| 76 |
|
| 77 |
template<class SC, |
| 78 |
class LO, |
| 79 |
class GO, |
| 80 |
class NO> |
| 81 |
class TwoLevelBlockPreconditioner; |
| 82 |
|
| 83 |
template <class SC = double, |
| 84 |
class LO = int, |
| 85 |
class GO = DefaultGlobalOrdinal, |
| 86 |
class NO = Tpetra::KokkosClassic::DefaultNode::DefaultNodeType> |
| 87 |
class SubdomainSolver : public Operator<SC,LO,GO,NO> { |
| 88 |
|
| 89 |
protected: |
| 90 |
|
| 91 |
using XMap = Map<LO,GO,NO>; |
| 92 |
using XMapPtr = RCP<XMap>; |
| 93 |
using ConstXMapPtr = RCP<const XMap>; |
| 94 |
using XMapPtrVecPtr = ArrayRCP<XMapPtr>; |
| 95 |
|
| 96 |
using XMatrix = Matrix<SC,LO,GO,NO>; |
| 97 |
using XMatrixPtr = RCP<XMatrix>; |
| 98 |
using ConstXMatrixPtr = RCP<const XMatrix>; |
| 99 |
|
| 100 |
#ifdef HAVE_SHYLU_DDFROSCH_EPETRA |
| 101 |
using ECrsMatrix = Epetra_CrsMatrix; |
| 102 |
using ECrsMatrixPtr = RCP<ECrsMatrix>; |
| 103 |
using ConstECrsMatrixPtr = RCP<const ECrsMatrix>; |
| 104 |
#endif |
| 105 |
using TCrsMatrix = Tpetra::CrsMatrix<SC,LO,GO,NO>; |
| 106 |
using TCrsMatrixPtr = RCP<TCrsMatrix>; |
| 107 |
using ConstTCrsMatrixPtr = RCP<const TCrsMatrix>; |
| 108 |
|
| 109 |
using TRowMatrix = Tpetra::RowMatrix<SC,LO,GO,NO>; |
| 110 |
using TRowMatrixPtr = RCP<TRowMatrix>; |
| 111 |
using ConstTRowMatrixPtr = RCP<const TRowMatrix>; |
| 112 |
|
| 113 |
using XMultiVector = MultiVector<SC,LO,GO,NO>; |
| 114 |
using ConstXMultiVector = const MultiVector<SC,LO,GO,NO>; |
| 115 |
using XMultiVectorPtr = RCP<XMultiVector>; |
| 116 |
using ConstXMultiVectorPtr = RCP<const XMultiVector>; |
| 117 |
using ConstXMultiVectorPtrVecPtr = ArrayRCP<ConstXMultiVectorPtr>; |
| 118 |
|
| 119 |
using TMultiVector = Tpetra::MultiVector<SC,LO,GO,NO>; |
| 120 |
using TMultiVectorPtr = RCP<TMultiVector>; |
| 121 |
|
| 122 |
#ifdef HAVE_SHYLU_DDFROSCH_EPETRA |
| 123 |
using EMultiVector = Epetra_MultiVector; |
| 124 |
using EMultiVectorPtr = RCP<EMultiVector>; |
| 125 |
#endif |
| 126 |
|
| 127 |
using XMultiVectorFactory = MultiVectorFactory<SC,LO,GO,NO>; |
| 128 |
|
| 129 |
using ParameterListPtr = RCP<ParameterList>; |
| 130 |
|
| 131 |
#ifdef HAVE_SHYLU_DDFROSCH_EPETRA |
| 132 |
using ELinearProblem = Epetra_LinearProblem; |
| 133 |
using ELinearProblemPtr = RCP<Epetra_LinearProblem>; |
| 134 |
#endif |
| 135 |
|
| 136 |
#ifdef HAVE_SHYLU_DDFROSCH_AMESOS |
| 137 |
using AmesosSolverPtr = RCP<Amesos_BaseSolver>; |
| 138 |
#endif |
| 139 |
|
| 140 |
#ifdef HAVE_SHYLU_DDFROSCH_EPETRA |
| 141 |
using Amesos2SolverEpetraPtr = RCP<Amesos2::Solver<ECrsMatrix,EMultiVector> >; |
| 142 |
#endif |
| 143 |
using Amesos2SolverTpetraPtr = RCP<Amesos2::Solver<TCrsMatrix,TMultiVector> >; |
| 144 |
|
| 145 |
#ifdef HAVE_SHYLU_DDFROSCH_MUELU |
| 146 |
using MueLuFactoryPtr = RCP<MueLu::HierarchyManager<SC,LO,GO,NO> >; |
| 147 |
using MueLuHierarchyPtr = RCP<MueLu::Hierarchy<SC,LO,GO,NO> >; |
| 148 |
#endif |
| 149 |
|
| 150 |
using UN = unsigned; |
| 151 |
using UNVec = Teuchos::Array<UN>; |
| 152 |
using UNVecPtr = Teuchos::ArrayRCP<UN>; |
| 153 |
|
| 154 |
using GOVecPtr = ArrayRCP<GO>; |
| 155 |
|
| 156 |
public: |
| 157 |
|
| 158 |
/*! |
| 159 |
\brief Constructor |
| 160 |
|
| 161 |
Create the subdomain solver object. |
| 162 |
|
| 163 |
A subdomain solver might require further Trilinos packages at runtime. |
| 164 |
Availability of required packages is tested and |
| 165 |
an error is thrown if required packages are not part of the build configuration. |
| 166 |
|
| 167 |
@param k Matrix |
| 168 |
@param parameterList Parameter list |
| 169 |
@param blockCoarseSize |
| 170 |
*/ |
| 171 |
SubdomainSolver(ConstXMatrixPtr k, |
| 172 |
ParameterListPtr parameterList, |
| 173 |
string description = "undefined", |
| 174 |
GOVecPtr blockCoarseSize=null); |
| 175 |
|
| 176 |
//! Destructor |
| 177 |
virtual ~SubdomainSolver(); |
| 178 |
|
| 179 |
//! Initialize member variables |
| 180 |
virtual int initialize(); |
| 181 |
|
| 182 |
/*! |
| 183 |
\brief Compute/setup this operator/solver |
| 184 |
|
| 185 |
\pre Routine initialize() has been called and #isInitialized_ is set to \c true. |
| 186 |
|
| 187 |
@return Integer error code |
| 188 |
*/ |
| 189 |
virtual int compute(); |
| 190 |
|
| 191 |
/*! \brief Apply subdomain solver to input \c x |
| 192 |
* |
| 193 |
* y = alpha * A^mode * X + beta * Y |
| 194 |
* |
| 195 |
* \param[in] x Input vector |
| 196 |
* \param[out] y result vector |
| 197 |
* \param[in] mode |
| 198 |
*/ |
| 199 |
|
| 200 |
/*! |
| 201 |
\brief Computes the operator-multivector application. |
| 202 |
|
| 203 |
Loosely, performs \f$Y = \alpha \cdot A^{\textrm{mode}} \cdot X + \beta \cdot Y\f$. However, the details of operation |
| 204 |
vary according to the values of \c alpha and \c beta. Specifically |
| 205 |
- if <tt>beta == 0</tt>, apply() <b>must</b> overwrite \c Y, so that any values in \c Y (including NaNs) are ignored. |
| 206 |
- if <tt>alpha == 0</tt>, apply() <b>may</b> short-circuit the operator, so that any values in \c X (including NaNs) are ignored. |
| 207 |
*/ |
| 208 |
virtual void apply(const XMultiVector &x, |
| 209 |
XMultiVector &y, |
| 210 |
ETransp mode=NO_TRANS, |
| 211 |
SC alpha=ScalarTraits<SC>::one(), |
| 212 |
SC beta=ScalarTraits<SC>::zero()) const; |
| 213 |
|
| 214 |
//! Get domain map |
| 215 |
virtual ConstXMapPtr getDomainMap() const; |
| 216 |
|
| 217 |
//! Get range map |
| 218 |
virtual ConstXMapPtr getRangeMap() const; |
| 219 |
|
| 220 |
/*! |
| 221 |
\brief Print description of this object to given output stream |
| 222 |
|
| 223 |
\param out Output stream to be used |
| 224 |
\param Verbosity level used for printing |
| 225 |
*/ |
| 226 |
virtual void describe(FancyOStream &out, |
| 227 |
const EVerbosityLevel verbLevel=Describable::verbLevel_default) const; |
| 228 |
|
| 229 |
/*! |
| 230 |
\brief Get description of this operator |
| 231 |
|
| 232 |
\return String describing this operator |
| 233 |
*/ |
| 234 |
virtual string description() const; |
| 235 |
|
| 236 |
//! @name Access to class members |
| 237 |
//!@{ |
| 238 |
|
| 239 |
//! Get #IsInitialized_ |
| 240 |
bool isInitialized() const; |
| 241 |
|
| 242 |
//! Get #IsComputed_ |
| 243 |
bool isComputed() const; |
| 244 |
|
| 245 |
int resetMatrix(ConstXMatrixPtr k, |
| 246 |
bool reuseInitialize); |
| 247 |
|
| 248 |
/*! |
| 249 |
\brief Computes a residual using the operator |
| 250 |
*/ |
| 251 |
virtual void residual(const XMultiVector & X, |
| 252 |
const XMultiVector & B, |
| 253 |
XMultiVector& R) const; |
| 254 |
|
| 255 |
//!@} |
| 256 |
|
| 257 |
protected: |
| 258 |
|
| 259 |
//! Matrix |
| 260 |
ConstXMatrixPtr K_; |
| 261 |
|
| 262 |
//! Paremter list |
| 263 |
ParameterListPtr ParameterList_; |
| 264 |
|
| 265 |
//! Description of the solver |
| 266 |
string Description_; |
| 267 |
|
| 268 |
mutable XMultiVectorPtr YTmp_; |
| 269 |
|
| 270 |
#ifdef HAVE_SHYLU_DDFROSCH_EPETRA |
| 271 |
ELinearProblemPtr EpetraLinearProblem_; |
| 272 |
#endif |
| 273 |
|
| 274 |
#ifdef HAVE_SHYLU_DDFROSCH_AMESOS |
| 275 |
AmesosSolverPtr AmesosSolver_; |
| 276 |
#endif |
| 277 |
|
| 278 |
#ifdef HAVE_SHYLU_DDFROSCH_EPETRA |
| 279 |
Amesos2SolverEpetraPtr Amesos2SolverEpetra_; |
| 280 |
#endif |
| 281 |
Amesos2SolverTpetraPtr Amesos2SolverTpetra_; |
| 282 |
|
| 283 |
#ifdef HAVE_SHYLU_DDFROSCH_MUELU |
| 284 |
//! Factory to create a MueLu hierarchy |
| 285 |
MueLuFactoryPtr MueLuFactory_; |
| 286 |
|
| 287 |
//! MueLu hierarchy object |
| 288 |
MueLuHierarchyPtr MueLuHierarchy_; |
| 289 |
#endif |
| 290 |
|
| 291 |
#ifdef HAVE_SHYLU_DDFROSCH_BELOS |
| 292 |
RCP<Belos::LinearProblem<SC,MultiVector<SC,LO,GO,NO>,Belos::OperatorT<MultiVector<SC,LO,GO,NO> > > > BelosLinearProblem_; |
| 293 |
RCP<Belos::SolverManager<SC,MultiVector<SC,LO,GO,NO>,Belos::OperatorT<MultiVector<SC,LO,GO,NO> > > > BelosSolverManager_; |
| 294 |
#endif |
| 295 |
|
| 296 |
#ifdef HAVE_SHYLU_DDFROSCH_IFPACK2 |
| 297 |
RCP<Ifpack2::Preconditioner<SC,LO,GO,NO> > Ifpack2Preconditioner_; |
| 298 |
#endif |
| 299 |
|
| 300 |
#ifdef HAVE_SHYLU_DDFROSCH_THYRA |
| 301 |
mutable RCP<Thyra::MultiVectorBase<SC> > ThyraYTmp_; |
| 302 |
RCP<Thyra::LinearOpWithSolveBase<SC> > LOWS_; |
| 303 |
#endif |
| 304 |
|
| 305 |
RCP<TwoLevelBlockPreconditioner<SC,LO,GO,NO> > TLBP; |
| 306 |
RCP<TwoLevelPreconditioner<SC,LO,GO,NO> > TLP; |
| 307 |
|
| 308 |
bool IsInitialized_ = false; |
| 309 |
|
| 310 |
//! Flag to indicated whether this subdomain solver has been setup/computed |
| 311 |
bool IsComputed_ = false; |
| 312 |
}; |
| 313 |
|
| 314 |
} |
| 315 |
|
| 316 |
#endif |