| 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 |
#include "Epetra_Map.h" |
| 10 |
#include "NOX_Epetra_SchurCoupler.H" |
| 11 |
|
| 12 |
using namespace NOX; |
| 13 |
using namespace NOX::Epetra; |
| 14 |
|
| 15 |
SchurCoupler::SchurCoupler( Problem_Manager & probManager ) : |
| 16 |
problemManager(probManager), |
| 17 |
label("Schur_Coupler") |
| 18 |
{ |
| 19 |
int numProblems = probManager.getProblemCount(); |
| 20 |
|
| 21 |
// For now, just create diagonal Schur operators |
| 22 |
for( int i = 0; i < numProblems - 1; ++i ) |
| 23 |
schurOperators[i] = Teuchos::rcp( new SchurOp(i, i+1, *this ) ); |
| 24 |
} |
| 25 |
|
| 26 |
SchurCoupler::~SchurCoupler() |
| 27 |
{ |
| 28 |
} |
| 29 |
|
| 30 |
int |
| 31 |
SchurCoupler::SetUseTranspose( bool UseTranspose ) |
| 32 |
{ |
| 33 |
if (UseTranspose == true) |
| 34 |
{ |
| 35 |
std::cout << "ERROR: NOX::Epetra::SchurCoupler::SetUseTranspose() - Transpose is " |
| 36 |
<< "unavailable for this operator!" << std::endl; |
| 37 |
throw std::runtime_error("NOX Error"); |
| 38 |
} |
| 39 |
return (-1); |
| 40 |
} |
| 41 |
|
| 42 |
int |
| 43 |
SchurCoupler::Apply(const Epetra_MultiVector& X, Epetra_MultiVector& Y) const |
| 44 |
{ |
| 45 |
// // Convert X and Y from an Epetra_MultiVectors to Epetra_Vectors |
| 46 |
// // and NOX::Epetra::Vectors. This is done so we use a consistent |
| 47 |
// // vector space for norms and inner products. |
| 48 |
// Teuchos::RCP<Epetra_Vector> wrappedX = Teuchos::rcp(new Epetra_Vector(View, X, 0)); |
| 49 |
// Teuchos::RCP<Epetra_Vector> wrappedY = Teuchos::rcp(new Epetra_Vector(View, Y, 0)); |
| 50 |
// Teuchos::RCP<Epetra_Vector> tempX = Teuchos::rcp(new Epetra_Vector(*wrappedX) ); |
| 51 |
// Teuchos::RCP<Epetra_Vector> tempY = Teuchos::rcp(new Epetra_Vector(*wrappedY) ); |
| 52 |
// |
| 53 |
// // The substance of this operator ----- to do RWH 10/24/2006 |
| 54 |
// |
| 55 |
// //cout << "Incoming X :\n" << *wrappedX << std::endl; |
| 56 |
// problemManager.applyBlockAction( depId, probId, *wrappedX, *tempY); |
| 57 |
// //cout << "After applyBlockAction(" << depId << ", " << probId << ") :\n" << *tempY << std::endl; |
| 58 |
// problemManager.getBlockInverseOperator(depId)->ApplyInverse(*tempY, *tempY); |
| 59 |
// //cout << "After ApplyInverse :\n" << *tempY << std::endl; |
| 60 |
// problemManager.applyBlockAction( probId, depId, *tempY, *tempX); |
| 61 |
// //cout << "After applyBlockAction(" << probId << ", " << depId << ") :\n" << *tempX << std::endl; |
| 62 |
// |
| 63 |
// problemManager.getBlockJacobianMatrix(probId)->Apply(*wrappedX, *wrappedY); |
| 64 |
// //cout << "After Apply of diagonal block :\n" << *wrappedY << std::endl; |
| 65 |
// wrappedY->Update(-1.0, *tempX, 1.0); |
| 66 |
// //cout << "After combingin; final result :\n" << *wrappedY << std::endl; |
| 67 |
// |
| 68 |
return (0); |
| 69 |
} |
| 70 |
|
| 71 |
int |
| 72 |
SchurCoupler::ApplyInverse(const Epetra_MultiVector& X, Epetra_MultiVector& Y) const |
| 73 |
{ |
| 74 |
std::cout << "ERROR: NOX::Epetra::SchurCoupler::ApplyInverse() - Not valid " |
| 75 |
<< "for this operator!" << std::endl; |
| 76 |
throw std::runtime_error("NOX Error"); |
| 77 |
|
| 78 |
return (-1); |
| 79 |
} |
| 80 |
|
| 81 |
double |
| 82 |
SchurCoupler::NormInf() const |
| 83 |
{ |
| 84 |
std::cout << "ERROR: NOX::Epetra::SchurCoupler::NormInf() - Not Available for " |
| 85 |
<< "this operator!" << std::endl; |
| 86 |
throw std::runtime_error("NOX Error"); |
| 87 |
|
| 88 |
return 1.0; |
| 89 |
} |
| 90 |
|
| 91 |
const char* |
| 92 |
SchurCoupler::Label () const |
| 93 |
{ |
| 94 |
return label.c_str(); |
| 95 |
} |
| 96 |
|
| 97 |
bool |
| 98 |
SchurCoupler::UseTranspose() const |
| 99 |
{ |
| 100 |
return false; |
| 101 |
} |
| 102 |
|
| 103 |
bool |
| 104 |
SchurCoupler::HasNormInf() const |
| 105 |
{ |
| 106 |
return false; |
| 107 |
} |
| 108 |
|
| 109 |
const Epetra_Comm & |
| 110 |
SchurCoupler::Comm() const |
| 111 |
{ |
| 112 |
return problemManager.getJacobianOperator()->Comm(); |
| 113 |
} |
| 114 |
|
| 115 |
const Epetra_Map & |
| 116 |
SchurCoupler::OperatorDomainMap() const |
| 117 |
{ |
| 118 |
return *(problemManager.getCompositeMap()); |
| 119 |
} |
| 120 |
|
| 121 |
const Epetra_Map & |
| 122 |
SchurCoupler::OperatorRangeMap() const |
| 123 |
{ |
| 124 |
return *(problemManager.getCompositeMap()); |
| 125 |
} |
| 126 |
|
| 127 |
|
| 128 |
bool |
| 129 |
SchurCoupler::applyBlockAction( int rowBlock, int colBlock, const Epetra_Vector & x, Epetra_Vector & result ) |
| 130 |
{ |
| 131 |
// Note that we need to convert to 1-based when interacting with Problem_Manager |
| 132 |
return problemManager.applyBlockAction( rowBlock+1, colBlock+1, x, result ); |
| 133 |
} |
| 134 |
|
| 135 |
bool |
| 136 |
SchurCoupler::applyBlockInverseAction( int rowBlock, int colBlock, const Epetra_Vector & x, Epetra_Vector & result ) |
| 137 |
{ |
| 138 |
return problemManager.applyBlockInverseAction( rowBlock+1, colBlock+1, x, result ); |
| 139 |
} |
| 140 |
|
| 141 |
bool |
| 142 |
SchurCoupler::hasExplicitOperator( int rowBlock, int colBlock ) |
| 143 |
{ |
| 144 |
return ( rowBlock == colBlock ); |
| 145 |
} |
| 146 |
|
| 147 |
Teuchos::RCP<Epetra_Operator> |
| 148 |
SchurCoupler::getExplicitOperator( int rowBlock, int colBlock ) |
| 149 |
{ |
| 150 |
return problemManager.getBlockJacobianMatrix(rowBlock+1); |
| 151 |
} |
| 152 |
|
| 153 |
Teuchos::RCP<SchurOp> |
| 154 |
SchurCoupler::getSchurOperator( int rowBlock, int colBlock ) |
| 155 |
{ |
| 156 |
|
| 157 |
if( rowBlock != colBlock ) |
| 158 |
{ |
| 159 |
std::cout << "ERROR: NOX::Epetra::SchurCoupler::getSchurOperator() - Off operators not supported." |
| 160 |
<< std::endl; |
| 161 |
throw std::runtime_error("NOX Error"); |
| 162 |
} |
| 163 |
|
| 164 |
return schurOperators[rowBlock]; |
| 165 |
} |
| 166 |
|