| 1 |
// @HEADER |
| 2 |
// ***************************************************************************** |
| 3 |
// NOX: An Object-Oriented Nonlinear Solver Package |
| 4 |
// |
| 5 |
// Copyright 2002 NTESS and the NOX contributors. |
| 6 |
// SPDX-License-Identifier: BSD-3-Clause |
| 7 |
// ***************************************************************************** |
| 8 |
// @HEADER |
| 9 |
#ifndef NOX_TPETRA_ME_HEQ_DECL_HPP |
| 10 |
#define NOX_TPETRA_ME_HEQ_DECL_HPP |
| 11 |
|
| 12 |
#include "Thyra_StateFuncModelEvaluatorBase.hpp" |
| 13 |
#include "Tpetra_CrsMatrix.hpp" |
| 14 |
|
| 15 |
template<class Scalar, class LO, class GO, class Node> |
| 16 |
class EvaluatorTpetraHeq; |
| 17 |
|
| 18 |
template<class Scalar, class LO, class GO, class Node> |
| 19 |
class HeqJacobianOperator; |
| 20 |
|
| 21 |
/** \brief Nonmember constuctor. |
| 22 |
* |
| 23 |
* \relates EvaluatorTpetraHeq |
| 24 |
*/ |
| 25 |
template<class Scalar, class LO, class GO, class Node> |
| 26 |
Teuchos::RCP<EvaluatorTpetraHeq<Scalar, LO, GO, Node> > |
| 27 |
evaluatorTpetraHeq(const Teuchos::RCP<const Teuchos::Comm<int> >& comm, |
| 28 |
const Tpetra::global_size_t numGlobalElements, |
| 29 |
const Scalar omega); |
| 30 |
|
| 31 |
|
| 32 |
/** \brief Chandrasehkar H-equation |
| 33 |
* |
| 34 |
* The equation modeled is: |
| 35 |
|
| 36 |
\verbatim |
| 37 |
|
| 38 |
F(x)_i = (1 - \frac{\omega}{2N}\sum_{j=1}^N \frac{\mu_ix_j}{\mu_i + \mu_j})^{-1} - x_i = 0, 0 <= i <= N-1 |
| 39 |
|
| 40 |
where \omega \in [0,1] is a given parameter and: |
| 41 |
\mu_i = (i + 0.5)/N |
| 42 |
|
| 43 |
\endverbatim |
| 44 |
|
| 45 |
* The Jacobian for this system is dense, so this creates a matrix-free Jacobian operator class. |
| 46 |
* The preconditioner this computes is the inverse diagonal of the Jacobian. |
| 47 |
*/ |
| 48 |
template<class Scalar, class LO, class GO, class Node> |
| 49 |
class EvaluatorTpetraHeq |
| 50 |
: public Thyra::StateFuncModelEvaluatorBase<Scalar> |
| 51 |
{ |
| 52 |
public: |
| 53 |
|
| 54 |
// Public typedefs |
| 55 |
typedef Scalar scalar_type; |
| 56 |
typedef LO local_ordinal_type; |
| 57 |
typedef GO global_ordinal_type; |
| 58 |
typedef Node node_type; |
| 59 |
typedef HeqJacobianOperator<Scalar, LO, GO, Node> jac_op; |
| 60 |
typedef Tpetra::Map<LO, GO, Node> tpetra_map; |
| 61 |
typedef Tpetra::Vector<Scalar, LO, GO, Node> tpetra_vec; |
| 62 |
typedef Tpetra::Operator<Scalar, LO, GO, Node> tpetra_op; |
| 63 |
typedef Tpetra::CrsMatrix<Scalar, LO, GO, Node> tpetra_mat; |
| 64 |
typedef Thyra::VectorSpaceBase<Scalar> thyra_vec_space; |
| 65 |
typedef Thyra::VectorBase<Scalar> thyra_vec; |
| 66 |
typedef Thyra::LinearOpBase<Scalar> thyra_op; |
| 67 |
typedef Thyra::PreconditionerBase<Scalar> thyra_prec; |
| 68 |
|
| 69 |
// Constructor |
| 70 |
EvaluatorTpetraHeq(const Teuchos::RCP<const Teuchos::Comm<int> >& comm, |
| 71 |
const Tpetra::global_size_t numGlobalElements, |
| 72 |
const Scalar omega); |
| 73 |
|
| 74 |
/** \name Initializers/Accessors */ |
| 75 |
//@{ |
| 76 |
|
| 77 |
/** \brief . */ |
| 78 |
void setShowGetInvalidArgs(bool showGetInvalidArg); |
| 79 |
|
| 80 |
void set_W_factory(const Teuchos::RCP<const Thyra::LinearOpWithSolveFactoryBase<Scalar> >& W_factory); |
| 81 |
|
| 82 |
//@} |
| 83 |
|
| 84 |
/** \name Public functions overridden from ModelEvaulator. */ |
| 85 |
//@{ |
| 86 |
|
| 87 |
/** \brief . */ |
| 88 |
Teuchos::RCP<const thyra_vec_space> get_x_space() const; |
| 89 |
/** \brief . */ |
| 90 |
Teuchos::RCP<const thyra_vec_space> get_f_space() const; |
| 91 |
/** \brief . */ |
| 92 |
Thyra::ModelEvaluatorBase::InArgs<Scalar> getNominalValues() const; |
| 93 |
/** \brief . */ |
| 94 |
Teuchos::RCP<thyra_op> create_W_op() const; |
| 95 |
/** \brief . */ |
| 96 |
Teuchos::RCP<const Thyra::LinearOpWithSolveFactoryBase<Scalar> > get_W_factory() const; |
| 97 |
/** \brief . */ |
| 98 |
Thyra::ModelEvaluatorBase::InArgs<Scalar> createInArgs() const; |
| 99 |
/** \brief . */ |
| 100 |
Teuchos::RCP<thyra_prec> create_W_prec() const; |
| 101 |
//@} |
| 102 |
|
| 103 |
private: |
| 104 |
|
| 105 |
/** \name Private functions overridden from ModelEvaulatorDefaultBase. */ |
| 106 |
//@{ |
| 107 |
|
| 108 |
/** \brief . */ |
| 109 |
Thyra::ModelEvaluatorBase::OutArgs<Scalar> createOutArgsImpl() const; |
| 110 |
/** \brief . */ |
| 111 |
void evalModelImpl( |
| 112 |
const Thyra::ModelEvaluatorBase::InArgs<Scalar> &inArgs, |
| 113 |
const Thyra::ModelEvaluatorBase::OutArgs<Scalar> &outArgs |
| 114 |
) const; |
| 115 |
|
| 116 |
//@} |
| 117 |
|
| 118 |
private: // data members |
| 119 |
|
| 120 |
const Teuchos::RCP<const Teuchos::Comm<int> > comm_; |
| 121 |
const Tpetra::global_size_t numGlobalElements_; |
| 122 |
std::vector<std::size_t> procNumElements_; |
| 123 |
std::vector<GO> procMinGIDs_; |
| 124 |
|
| 125 |
Teuchos::RCP<const thyra_vec_space> xSpace_; |
| 126 |
Teuchos::RCP<const tpetra_map> xMap_; |
| 127 |
|
| 128 |
Teuchos::RCP<const thyra_vec_space> fSpace_; |
| 129 |
Teuchos::RCP<const tpetra_map> fMap_; |
| 130 |
|
| 131 |
Teuchos::RCP<const Thyra::LinearOpWithSolveFactoryBase<Scalar> > W_factory_; |
| 132 |
|
| 133 |
const Scalar omega_; |
| 134 |
Teuchos::RCP<tpetra_vec> integralOp_; |
| 135 |
|
| 136 |
Thyra::ModelEvaluatorBase::InArgs<Scalar> nominalValues_; |
| 137 |
Teuchos::RCP<thyra_vec> x0_; |
| 138 |
bool showGetInvalidArg_; |
| 139 |
Thyra::ModelEvaluatorBase::InArgs<Scalar> prototypeInArgs_; |
| 140 |
Thyra::ModelEvaluatorBase::OutArgs<Scalar> prototypeOutArgs_; |
| 141 |
|
| 142 |
mutable Teuchos::RCP<Teuchos::Time> residTimer_; |
| 143 |
mutable Teuchos::RCP<Teuchos::Time> intOpTimer_; |
| 144 |
}; |
| 145 |
|
| 146 |
template<class Scalar, class LO, class GO, class Node> |
| 147 |
class HeqJacobianOperator |
| 148 |
: public Tpetra::Operator<Scalar, LO, GO, Node> |
| 149 |
{ |
| 150 |
public: |
| 151 |
|
| 152 |
// Public typedefs |
| 153 |
typedef Scalar scalar_type; |
| 154 |
typedef LO local_ordinal_type; |
| 155 |
typedef GO global_ordinal_type; |
| 156 |
typedef Node node_type; |
| 157 |
typedef Tpetra::Map<LO, GO, Node> tpetra_map; |
| 158 |
typedef Tpetra::Vector<Scalar, LO, GO, Node> tpetra_vec; |
| 159 |
typedef Tpetra::MultiVector<Scalar, LO, GO, Node> tpetra_mv; |
| 160 |
|
| 161 |
// Constructor |
| 162 |
HeqJacobianOperator(const Teuchos::RCP<const tpetra_map>& map, |
| 163 |
const std::vector<std::size_t>& procNumElements, |
| 164 |
const std::vector<GO>& procMinGIDs); |
| 165 |
|
| 166 |
void initialize(const Scalar& omega, |
| 167 |
const Teuchos::RCP<tpetra_vec>& integralOp); |
| 168 |
|
| 169 |
void unitialize(); |
| 170 |
|
| 171 |
virtual Teuchos::RCP<const tpetra_map> getDomainMap () const; |
| 172 |
|
| 173 |
virtual Teuchos::RCP<const tpetra_map> getRangeMap () const; |
| 174 |
|
| 175 |
virtual void |
| 176 |
apply (const tpetra_mv& X, |
| 177 |
tpetra_mv& Y, |
| 178 |
Teuchos::ETransp mode = Teuchos::NO_TRANS, |
| 179 |
Scalar alpha = Teuchos::ScalarTraits<Scalar>::one(), |
| 180 |
Scalar beta = Teuchos::ScalarTraits<Scalar>::zero()) const; |
| 181 |
|
| 182 |
private: |
| 183 |
|
| 184 |
Teuchos::RCP<const tpetra_map> map_; |
| 185 |
std::vector<std::size_t> procNumElements_; |
| 186 |
std::vector<GO> procMinGIDs_; |
| 187 |
Scalar omega_; |
| 188 |
Teuchos::RCP<tpetra_vec> integralOp_; |
| 189 |
Teuchos::RCP<tpetra_vec> integralOpX_; |
| 190 |
|
| 191 |
}; |
| 192 |
|
| 193 |
//================================================================== |
| 194 |
#include "ME_Tpetra_Heq_def.hpp" |
| 195 |
//================================================================== |
| 196 |
|
| 197 |
#endif |