/usr/include/trilinos/MueLu_RefMaxwell_decl.hpp is in libtrilinos-muelu-dev 12.12.1-5.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 | // @HEADER
//
// ***********************************************************************
//
// MueLu: A package for multigrid based preconditioning
// Copyright 2012 Sandia Corporation
//
// Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
// the U.S. Government retains certain rights in this software.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// 1. Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// 2. Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// 3. Neither the name of the Corporation nor the names of the
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// Questions? Contact
// Jonathan Hu (jhu@sandia.gov)
// Andrey Prokopenko (aprokop@sandia.gov)
// Ray Tuminaro (rstumin@sandia.gov)
//
// ***********************************************************************
//
// @HEADER
#ifndef MUELU_REFMAXWELL_DECL_HPP
#define MUELU_REFMAXWELL_DECL_HPP
// TODO move this file to xpetra subfolder
#include "MueLu_ConfigDefs.hpp"
#include "MueLu_BaseClass.hpp"
#include "MueLu_Utilities_fwd.hpp"
#include "MueLu_TentativePFactory_fwd.hpp"
#include "MueLu_SaPFactory_fwd.hpp"
#include "MueLu_UncoupledAggregationFactory_fwd.hpp"
#include "MueLu_SmootherFactory_fwd.hpp"
#include "MueLu_TrilinosSmoother.hpp"
#include "MueLu_Hierarchy.hpp"
#include "Xpetra_Map_fwd.hpp"
#include "Xpetra_Matrix_fwd.hpp"
#include "Xpetra_MatrixFactory_fwd.hpp"
#include "Xpetra_MultiVectorFactory_fwd.hpp"
#include "Xpetra_CrsMatrixWrap_fwd.hpp"
#include "Xpetra_BlockedCrsMatrix_fwd.hpp"
#include "Xpetra_ExportFactory_fwd.hpp"
namespace MueLu {
/*!
@brief Preconditioner (wrapped as a Tpetra::Operator) for Maxwell's equations in curl-curl form.
This uses a 2x2 block reformulation.
Reference:
P. Bochev, J. Hu, C. Siefert, and R. Tuminaro. "An algebraic multigrid approach based on
a compatible gauge reformulation of Maxwell's equations." SIAM Journal on Scientific
Computing, 31(1), 557-583.
@ingroup MueLuAdapters
*/
template <class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
class RefMaxwell : public Xpetra::Operator<Scalar,LocalOrdinal,GlobalOrdinal,Node> {
#undef MUELU_REFMAXWELL_SHORT
#include "MueLu_UseShortNames.hpp"
public:
//! Constructor
RefMaxwell() :
Hierarchy11_(Teuchos::null),
Hierarchy22_(Teuchos::null),
disable_addon_(true),
mode_("additive")
{
}
//! Constructor with Hierarchies
RefMaxwell(Teuchos::RCP<Hierarchy> H11, Teuchos::RCP<Hierarchy> H22) :
Hierarchy11_(H11),
Hierarchy22_(H22),
disable_addon_(false),
mode_("additive")
{
}
/** Constructor with Jacobian (with add on)
*
* \param[in] SM_Matrix Jacobian
* \param[in] D0_Matrix Discrete Gradient
* \param[in] M0inv_Matrix Inverse of lumped nodal mass matrix (add on only)
* \param[in] M1_Matrix Edge mass matrix for the
* \param[in] Nullspace Null space (needed for periodic)
* \param[in] coords Nodal coordinates
* \param[in] precList Parameter list
* \param[in] ComputePrec If true, compute the preconditioner immediately
*/
RefMaxwell(const Teuchos::RCP<Matrix> & SM_Matrix,
const Teuchos::RCP<Matrix> & D0_Matrix,
const Teuchos::RCP<Matrix> & M0inv_Matrix,
const Teuchos::RCP<Matrix> & M1_Matrix,
const Teuchos::RCP<MultiVector> & Nullspace,
const Teuchos::RCP<MultiVector> & Coords,
Teuchos::ParameterList& List,
bool ComputePrec = true)
{
initialize(D0_Matrix,M0inv_Matrix,M1_Matrix,Nullspace,Coords,List);
resetMatrix(SM_Matrix);
// compute preconditioner (optionally)
if(ComputePrec)
compute();
}
/** Constructor without Jacobian (with add on)
*
* \param[in] D0_Matrix Discrete Gradient
* \param[in] M0inv_Matrix Inverse of lumped nodal mass matrix (add on only)
* \param[in] M1_Matrix Edge mass matrix for the
* \param[in] Nullspace Null space (needed for periodic)
* \param[in] coords Nodal coordinates
* \param[in] precList Parameter list
*/
RefMaxwell(const Teuchos::RCP<Matrix> & D0_Matrix,
const Teuchos::RCP<Matrix> & M0inv_Matrix,
const Teuchos::RCP<Matrix> & M1_Matrix,
const Teuchos::RCP<MultiVector> & Nullspace,
const Teuchos::RCP<MultiVector> & Coords,
Teuchos::ParameterList& List) : SM_Matrix_(Teuchos::null)
{
initialize(D0_Matrix,M0inv_Matrix,M1_Matrix,Nullspace,Coords,List);
}
/** Constructor with Jacobian (no add on)
*
* \param[in] SM_Matrix Jacobian
* \param[in] D0_Matrix Discrete Gradient
* \param[in] M1_Matrix Edge mass matrix for the
* \param[in] Nullspace Null space (needed for periodic)
* \param[in] coords Nodal coordinates
* \param[in] precList Parameter list
* \param[in] ComputePrec If true, compute the preconditioner immediately
*/
RefMaxwell(const Teuchos::RCP<Matrix> & SM_Matrix,
const Teuchos::RCP<Matrix> & D0_Matrix,
const Teuchos::RCP<Matrix> & M1_Matrix,
const Teuchos::RCP<MultiVector> & Nullspace,
const Teuchos::RCP<MultiVector> & Coords,
Teuchos::ParameterList& List,
bool ComputePrec = true)
{
initialize(D0_Matrix,Teuchos::null,M1_Matrix,Nullspace,Coords,List);
resetMatrix(SM_Matrix);
// compute preconditioner (optionally)
if(ComputePrec)
compute();
}
/** Constructor without Jacobian (no add on)
*
* \param[in] D0_Matrix Discrete Gradient
* \param[in] M1_Matrix Edge mass matrix for the
* \param[in] Nullspace Null space (needed for periodic)
* \param[in] coords Nodal coordinates
* \param[in] precList Parameter list
*/
RefMaxwell(const Teuchos::RCP<Matrix> & D0_Matrix,
const Teuchos::RCP<Matrix> & M1_Matrix,
const Teuchos::RCP<MultiVector> & Nullspace,
const Teuchos::RCP<MultiVector> & Coords,
Teuchos::ParameterList& List) : SM_Matrix_(Teuchos::null)
{
initialize(D0_Matrix,Teuchos::null,M1_Matrix,Nullspace,Coords,List);
}
//! Destructor.
virtual ~RefMaxwell() {}
//! Returns the Xpetra::Map object associated with the domain of this operator.
Teuchos::RCP<const Map> getDomainMap() const;
//! Returns the Xpetra::Map object associated with the range of this operator.
Teuchos::RCP<const Map> getRangeMap() const;
//! Set parameters
void setParameters(Teuchos::ParameterList& list);
//! Setup the preconditioner
void compute();
//! Setup the prolongator for the (1,1)-block
void buildProlongator();
//! Compute P11^{T}*A*P11 efficiently
void formCoarseMatrix();
//! Reset system matrix
void resetMatrix(Teuchos::RCP<Matrix> SM_Matrix_new);
//! apply additive algorithm for 2x2 solve
void applyInverseAdditive(const MultiVector& RHS, MultiVector& X) const;
//! apply 1-2-1 algorithm for 2x2 solve
void applyInverse121(const MultiVector& RHS, MultiVector& X) const;
//! apply 2-1-2 algorithm for 2x2 solve
void applyInverse212(const MultiVector& RHS, MultiVector& X) const;
//! Returns in Y the result of a Xpetra::Operator applied to a Xpetra::MultiVector X.
//! \param[in] X - MultiVector of dimension NumVectors to multiply with matrix.
//! \param[out] Y - MultiVector of dimension NumVectors containing result.
void apply (const MultiVector& X, MultiVector& Y,
Teuchos::ETransp mode = Teuchos::NO_TRANS,
Scalar alpha = Teuchos::ScalarTraits<Scalar>::one(),
Scalar beta = Teuchos::ScalarTraits<Scalar>::zero()) const;
//! Indicates whether this operator supports applying the adjoint operator.
bool hasTransposeApply() const;
template <class NewNode>
Teuchos::RCP< RefMaxwell<Scalar, LocalOrdinal, GlobalOrdinal, NewNode> >
clone (const RCP<NewNode>& new_node) const {
return Teuchos::rcp (new RefMaxwell<Scalar, LocalOrdinal, GlobalOrdinal, NewNode>
(Hierarchy11_->template clone<NewNode> (new_node),
Hierarchy22_->template clone<NewNode> (new_node)));
}
private:
void findDirichletRows(Teuchos::RCP<Matrix> A,
std::vector<LocalOrdinal>& dirichletRows) {
dirichletRows.resize(0);
for(size_t i=0; i<A->getNodeNumRows(); i++) {
Teuchos::ArrayView<const LocalOrdinal> indices;
Teuchos::ArrayView<const Scalar> values;
A->getLocalRowView(i,indices,values);
int nnz=0;
for (int j=0; j<indices.size(); j++) {
// FIXME (mfh 12 Sep 2015) I just replaced abs with the
// appropriate ScalarTraits call. However, this is NOT
// correct for arbitrary scalar types!!! I'm guessing you
// should use the equivalent of LAPACK's SFMIN or machine
// epsilon here.
if (Teuchos::ScalarTraits<Scalar>::magnitude(values[j]) > 1.0e-16) {
nnz++;
}
}
if (nnz == 1 || nnz == 2) {
dirichletRows.push_back(i);
}
}
}
void findDirichletCols(Teuchos::RCP<Matrix> A,
std::vector<LocalOrdinal>& dirichletRows,
std::vector<LocalOrdinal>& dirichletCols) {
Teuchos::RCP<const Map> domMap = A->getDomainMap();
Teuchos::RCP<const Map> colMap = A->getColMap();
Teuchos::RCP<Export> exporter = ExportFactory::Build(colMap,domMap);
Teuchos::RCP<MultiVector> myColsToZero = MultiVectorFactory::Build(colMap,1);
Teuchos::RCP<MultiVector> globalColsToZero = MultiVectorFactory::Build(domMap,1);
myColsToZero->putScalar((Scalar)0.0);
globalColsToZero->putScalar((Scalar)0.0);
for(size_t i=0; i<dirichletRows.size(); i++) {
Teuchos::ArrayView<const LocalOrdinal> indices;
Teuchos::ArrayView<const Scalar> values;
A->getLocalRowView(dirichletRows[i],indices,values);
for(int j=0; j<indices.size(); j++)
myColsToZero->replaceLocalValue(indices[j],0,(Scalar)1.0);
}
globalColsToZero->doExport(*myColsToZero,*exporter,Xpetra::ADD);
myColsToZero->doImport(*globalColsToZero,*exporter,Xpetra::INSERT);
Teuchos::ArrayRCP<const Scalar> myCols = myColsToZero->getData(0);
dirichletCols.resize(colMap->getNodeNumElements());
for(size_t i=0; i<colMap->getNodeNumElements(); i++) {
if(Teuchos::ScalarTraits<Scalar>::magnitude(myCols[i])>0.0)
dirichletCols[i]=1;
else
dirichletCols[i]=0;
}
}
void Apply_BCsToMatrixRows(Teuchos::RCP<Matrix>& A,
std::vector<LocalOrdinal>& dirichletRows) {
for(size_t i=0; i<dirichletRows.size(); i++) {
Teuchos::ArrayView<const LocalOrdinal> indices;
Teuchos::ArrayView<const Scalar> values;
A->getLocalRowView(dirichletRows[i],indices,values);
std::vector<Scalar> vec;
vec.resize(indices.size());
Teuchos::ArrayView<Scalar> zerovalues(vec);
for(int j=0; j<indices.size(); j++)
zerovalues[j]=(Scalar)1.0e-32;
A->replaceLocalValues(dirichletRows[i],indices,zerovalues);
}
}
void Apply_BCsToMatrixCols(Teuchos::RCP<Matrix>& A,
std::vector<LocalOrdinal>& dirichletCols) {
for(size_t i=0; i<A->getNodeNumRows(); i++) {
Teuchos::ArrayView<const LocalOrdinal> indices;
Teuchos::ArrayView<const Scalar> values;
A->getLocalRowView(i,indices,values);
std::vector<Scalar> vec;
vec.resize(indices.size());
Teuchos::ArrayView<Scalar> zerovalues(vec);
for(int j=0; j<indices.size(); j++) {
if(dirichletCols[indices[j]]==1)
zerovalues[j]=(Scalar)1.0e-32;
else
zerovalues[j]=values[j];
}
A->replaceLocalValues(i,indices,zerovalues);
}
}
void Remove_Zeroed_Rows(Teuchos::RCP<Matrix>& A, double tol=1.0e-14) {
Teuchos::RCP<const Map> rowMap = A->getRowMap();
RCP<Matrix> DiagMatrix = MatrixFactory::Build(rowMap,1);
RCP<Matrix> NewMatrix = MatrixFactory::Build(rowMap,1);
for(size_t i=0; i<A->getNodeNumRows(); i++) {
Teuchos::ArrayView<const LocalOrdinal> indices;
Teuchos::ArrayView<const Scalar> values;
A->getLocalRowView(i,indices,values);
int nnz=0;
for (int j=0; j<indices.size(); j++) {
if (Teuchos::ScalarTraits<Scalar>::magnitude(values[j]) > tol) {
nnz++;
}
}
Scalar one = (Scalar)1.0;
Scalar zero = (Scalar)0.0;
GlobalOrdinal row = rowMap->getGlobalElement(i);
if (nnz == 0) {
DiagMatrix->insertGlobalValues(row,
Teuchos::ArrayView<GlobalOrdinal>(&row,1),
Teuchos::ArrayView<Scalar>(&one,1));
}
else {
DiagMatrix->insertGlobalValues(row,
Teuchos::ArrayView<GlobalOrdinal>(&row,1),
Teuchos::ArrayView<Scalar>(&zero,1));
}
}
DiagMatrix->fillComplete();
A->fillComplete();
// add matrices together
RCP<Teuchos::FancyOStream> out = Teuchos::fancyOStream(Teuchos::rcpFromRef(std::cout));
Xpetra::MatrixMatrix<Scalar,LocalOrdinal,GlobalOrdinal,Node>::TwoMatrixAdd(*DiagMatrix,false,(Scalar)1.0,*A,false,(Scalar)1.0,NewMatrix,*out);
NewMatrix->fillComplete();
A=NewMatrix;
}
/** Initialize with matrices except the Jacobian (don't compute the preconditioner)
*
* \param[in] D0_Matrix Discrete Gradient
* \param[in] M0inv_Matrix Inverse of lumped nodal mass matrix (add on only)
* \param[in] M1_Matrix Edge mass matrix
* \param[in] Nullspace Null space (needed for periodic)
* \param[in] coords Nodal coordinates
* \param[in] precList Parameter list
*/
void initialize(const Teuchos::RCP<Matrix> & D0_Matrix,
const Teuchos::RCP<Matrix> & M0inv_Matrix,
const Teuchos::RCP<Matrix> & M1_Matrix,
const Teuchos::RCP<MultiVector> & Nullspace,
const Teuchos::RCP<MultiVector> & Coords,
Teuchos::ParameterList& List);
//! Two hierarchies: one for the (1,1)-block, another for the (2,2)-block
Teuchos::RCP<Hierarchy> Hierarchy11_, Hierarchy22_, HierarchySmoother_;
//! Top Level
Teuchos::RCP<Level> TopLevel_;
//! Various matrices
Teuchos::RCP<Matrix> SM_Matrix_, D0_Matrix_, M0inv_Matrix_, M1_Matrix_, Ms_Matrix_;
Teuchos::RCP<Matrix> TMT_Matrix_, TMT_Agg_Matrix_, P11_, A11_, A22_;
//! Vectors for BCs
std::vector<LocalOrdinal> BCrows_, BCcols_;
//! Nullspace
Teuchos::RCP<MultiVector> Nullspace_, Coords_;
//! Parameter lists
Teuchos::ParameterList parameterList_, precList11_, precList22_, smootherList_;
//! Some options
bool disable_addon_;
std::string mode_;
};
} // namespace
#define MUELU_REFMAXWELL_SHORT
#endif // MUELU_REFMAXWELL_DECL_HPP
|