| 1 |
// @HEADER |
| 2 |
// ***************************************************************************** |
| 3 |
// MueLu: A package for multigrid based preconditioning |
| 4 |
// |
| 5 |
// Copyright 2012 NTESS and the MueLu contributors. |
| 6 |
// SPDX-License-Identifier: BSD-3-Clause |
| 7 |
// ***************************************************************************** |
| 8 |
// @HEADER |
| 9 |
|
| 10 |
#ifndef ADR_XPETRAPARAMETERS_HPP |
| 11 |
#define ADR_XPETRAPARAMETERS_HPP |
| 12 |
|
| 13 |
#include <Teuchos_CommandLineProcessor.hpp> |
| 14 |
#include <Teuchos_Describable.hpp> |
| 15 |
#include <Teuchos_ParameterList.hpp> |
| 16 |
#include <Teuchos_RCP.hpp> |
| 17 |
#include <Teuchos_VerboseObject.hpp> |
| 18 |
|
| 19 |
#if defined(_MSC_VER) && !defined(M_PI) |
| 20 |
#define M_PI 3.14159265358979323846 |
| 21 |
#endif |
| 22 |
|
| 23 |
namespace ADR { |
| 24 |
|
| 25 |
namespace Xpetra { |
| 26 |
|
| 27 |
// TODO nx/ny/nz == GO or global_size_t ? But what is the best to do? |
| 28 |
|
| 29 |
template <typename GO> |
| 30 |
class Parameters : public Teuchos::VerboseObject<Parameters<GO> >, public Teuchos::Describable { |
| 31 |
public: |
| 32 |
Parameters(Teuchos::CommandLineProcessor& clp, GO nx = 16, GO ny = -1, GO nz = -1, const std::string& matrixType = "ADR1D", |
| 33 |
int keepBCs = 0, double stretchx = 1.0, double stretchy = 1.0, double stretchz = 1.0, double h = 1.0, double delta = 0.0, |
| 34 |
int PMLXL = 0, int PMLXR = 0, int PMLYL = 0, int PMLYR = 0, int PMLZL = 0, int PMLZR = 0, |
| 35 |
double omega = 2.0 * M_PI, double shift = 0.5, GO mx = -1, GO my = -1, GO mz = -1, int model = 0) |
| 36 |
: nx_(nx) |
| 37 |
, ny_(ny) |
| 38 |
, nz_(nz) |
| 39 |
, mx_(mx) |
| 40 |
, my_(my) |
| 41 |
, mz_(mz) |
| 42 |
, stretchx_(stretchx) |
| 43 |
, stretchy_(stretchy) |
| 44 |
, stretchz_(stretchz) |
| 45 |
, matrixType_(matrixType) |
| 46 |
, keepBCs_(keepBCs) |
| 47 |
, h_(h) |
| 48 |
, delta_(delta) |
| 49 |
, PMLx_left(PMLXL) |
| 50 |
, PMLx_right(PMLXR) |
| 51 |
, PMLy_left(PMLYL) |
| 52 |
, PMLy_right(PMLYR) |
| 53 |
, PMLz_left(PMLZL) |
| 54 |
, PMLz_right(PMLZR) |
| 55 |
, omega_(omega) |
| 56 |
, shift_(shift) |
| 57 |
, model_(model) { |
| 58 |
clp.setOption("nx", &nx_, "mesh points in x-direction."); |
| 59 |
clp.setOption("ny", &ny_, "mesh points in y-direction."); |
| 60 |
clp.setOption("nz", &nz_, "mesh points in z-direction."); |
| 61 |
clp.setOption("mx", &mx_, "processors in x-direction."); |
| 62 |
clp.setOption("my", &my_, "processors in y-direction."); |
| 63 |
clp.setOption("mz", &mz_, "processors in z-direction."); |
| 64 |
clp.setOption("stretchx", &stretchx_, "stretch mesh in x-direction."); |
| 65 |
clp.setOption("stretchy", &stretchy_, "stretch mesh in y-direction."); |
| 66 |
clp.setOption("stretchz", &stretchz_, "stretch mesh in z-direction."); |
| 67 |
clp.setOption("keepBCs", &keepBCs_, "keep Dirichlet boundary rows in matrix (0=false,1=true)"); |
| 68 |
clp.setOption("matrixType", &matrixType_, "matrix type: Laplace1D, Laplace2D, Laplace3D, ..."); // TODO: Star2D, numGlobalElements=... |
| 69 |
clp.setOption("h", &h_, "mesh width for uniform h"); |
| 70 |
clp.setOption("delta", &delta_, "maximum PML damping value"); |
| 71 |
clp.setOption("PMLx_left", &PMLx_left, "PML grid points in x-direction (left boundary)"); |
| 72 |
clp.setOption("PMLx_right", &PMLx_right, "PML grid points in x-direction (right boundary)"); |
| 73 |
clp.setOption("PMLy_left", &PMLy_left, "PML grid points in y-direction (left boundary)"); |
| 74 |
clp.setOption("PMLy_right", &PMLy_right, "PML grid points in y-direction (right boundary)"); |
| 75 |
clp.setOption("PMLz_left", &PMLz_left, "PML grid points in z-direction (left boundary)"); |
| 76 |
clp.setOption("PMLz_right", &PMLz_right, "PML grid points in z-direction (right boundary)"); |
| 77 |
clp.setOption("omega", &omega_, "angular frequency omega"); |
| 78 |
clp.setOption("shift", &shift_, "complex frequency shift"); |
| 79 |
clp.setOption("mx", &mx_, "processors in x-direction."); |
| 80 |
clp.setOption("my", &my_, "processors in y-direction."); |
| 81 |
clp.setOption("mz", &mz_, "processors in z-direction."); |
| 82 |
clp.setOption("model", &model_, "velocity model"); |
| 83 |
} |
| 84 |
|
| 85 |
GO GetNumGlobalElements() const { |
| 86 |
const Teuchos::ParameterList& pL = GetParameterList(); |
| 87 |
|
| 88 |
const std::string& matrixType = pL.get<std::string>("matrixType"); |
| 89 |
const GO nx = pL.get<GO>("nx"); |
| 90 |
const GO ny = pL.get<GO>("ny"); |
| 91 |
const GO nz = pL.get<GO>("nz"); |
| 92 |
|
| 93 |
GO numGlobalElements = -1; |
| 94 |
if (matrixType == "ADR1D") |
| 95 |
numGlobalElements = nx; |
| 96 |
|
| 97 |
else if (matrixType == "ADR2D") |
| 98 |
numGlobalElements = nx * ny; |
| 99 |
|
| 100 |
else if (matrixType == "ADR3D") |
| 101 |
numGlobalElements = nx * ny * nz; |
| 102 |
|
| 103 |
TEUCHOS_TEST_FOR_EXCEPTION(numGlobalElements < 0, std::runtime_error, |
| 104 |
"Gallery: numGlobalElements < 0 (did you forget --ny (or --nz) for 2D (3D) problems?)"); |
| 105 |
|
| 106 |
return numGlobalElements; |
| 107 |
} |
| 108 |
|
| 109 |
const std::string& GetMatrixType() const { |
| 110 |
const Teuchos::ParameterList& paramList = GetParameterList(); |
| 111 |
return paramList.get<std::string>("matrixType"); |
| 112 |
} |
| 113 |
|
| 114 |
void check() const {} |
| 115 |
|
| 116 |
Teuchos::ParameterList& GetParameterList() const { |
| 117 |
if (!paramList_.is_null()) |
| 118 |
return *paramList_; |
| 119 |
|
| 120 |
paramList_ = rcp(new Teuchos::ParameterList()); |
| 121 |
|
| 122 |
paramList_->set("nx", nx_); |
| 123 |
paramList_->set("ny", ny_); |
| 124 |
paramList_->set("nz", nz_); |
| 125 |
paramList_->set("mx", mx_); |
| 126 |
paramList_->set("my", my_); |
| 127 |
paramList_->set("mz", mz_); |
| 128 |
paramList_->set("model", model_); |
| 129 |
paramList_->set("stretchx", stretchx_); |
| 130 |
paramList_->set("stretchy", stretchy_); |
| 131 |
paramList_->set("stretchz", stretchz_); |
| 132 |
paramList_->set("keepBCs", static_cast<bool>(keepBCs_)); |
| 133 |
paramList_->set("matrixType", matrixType_); |
| 134 |
paramList_->set("h", h_); |
| 135 |
paramList_->set("delta", delta_); |
| 136 |
paramList_->set("PMLx_left", PMLx_left); |
| 137 |
paramList_->set("PMLx_right", PMLx_right); |
| 138 |
paramList_->set("PMLy_left", PMLy_left); |
| 139 |
paramList_->set("PMLy_right", PMLy_right); |
| 140 |
paramList_->set("PMLz_left", PMLz_left); |
| 141 |
paramList_->set("PMLz_right", PMLz_right); |
| 142 |
paramList_->set("omega", omega_); |
| 143 |
paramList_->set("shift", shift_); |
| 144 |
|
| 145 |
check(); |
| 146 |
|
| 147 |
return *paramList_; |
| 148 |
} |
| 149 |
|
| 150 |
//! @name Overridden from Teuchos::Describable |
| 151 |
//@{ |
| 152 |
|
| 153 |
//! Return a simple one-line description of this object. |
| 154 |
std::string description() const { |
| 155 |
std::ostringstream out; |
| 156 |
out << Teuchos::Describable::description(); |
| 157 |
out << "{type = " << GetMatrixType() << ", size = " << GetNumGlobalElements() << "} "; |
| 158 |
|
| 159 |
return out.str(); |
| 160 |
} |
| 161 |
|
| 162 |
//! Print the object with some verbosity level to an FancyOStream object. |
| 163 |
void describe(Teuchos::FancyOStream& out, const Teuchos::EVerbosityLevel verbLevel = verbLevel_default) const { |
| 164 |
int vl = (verbLevel == Teuchos::VERB_DEFAULT) ? Teuchos::VERB_LOW : verbLevel; |
| 165 |
if (vl == Teuchos::VERB_NONE) |
| 166 |
return; |
| 167 |
|
| 168 |
if (vl == Teuchos::VERB_LOW) |
| 169 |
out << description() << std::endl; |
| 170 |
else |
| 171 |
out << Teuchos::Describable::description() << std::endl; |
| 172 |
|
| 173 |
if (vl == Teuchos::VERB_MEDIUM || vl == Teuchos::VERB_HIGH || vl == Teuchos::VERB_EXTREME) { |
| 174 |
Teuchos::OSTab tab1(out); |
| 175 |
|
| 176 |
const Teuchos::ParameterList& paramList = GetParameterList(); |
| 177 |
std::string matrixType = paramList.get<std::string>("matrixType"); |
| 178 |
GO nx = paramList.get<GO>("nx"); |
| 179 |
GO ny = paramList.get<GO>("ny"); |
| 180 |
GO nz = paramList.get<GO>("nz"); |
| 181 |
|
| 182 |
out << "Matrix type: " << matrixType << std::endl |
| 183 |
<< "Problem size: " << GetNumGlobalElements(); |
| 184 |
|
| 185 |
if (matrixType == "Laplace2D" || matrixType == "Elasticity2D" || matrixType == "Helmholtz2D") |
| 186 |
out << " (" << nx << "x" << ny << ")"; |
| 187 |
else if (matrixType == "Laplace3D" || matrixType == "Elasticity3D" || matrixType == "Helmholtz3D") |
| 188 |
out << " (" << nx << "x" << ny << "x" << nz << ")"; |
| 189 |
|
| 190 |
out << std::endl; |
| 191 |
} |
| 192 |
} |
| 193 |
|
| 194 |
//@} |
| 195 |
|
| 196 |
private: |
| 197 |
// See Teuchos BUG 5249: https://software.sandia.gov/bugzilla/show_bug.cgi?id=5249 |
| 198 |
mutable GO nx_, ny_, nz_; |
| 199 |
mutable GO mx_, my_, mz_; |
| 200 |
mutable double stretchx_, stretchy_, stretchz_; |
| 201 |
|
| 202 |
std::string matrixType_; |
| 203 |
|
| 204 |
mutable int keepBCs_; |
| 205 |
|
| 206 |
mutable double h_; |
| 207 |
mutable double delta_; |
| 208 |
mutable int PMLx_left, PMLx_right; |
| 209 |
mutable int PMLy_left, PMLy_right; |
| 210 |
mutable int PMLz_left, PMLz_right; |
| 211 |
mutable double omega_; |
| 212 |
mutable double shift_; |
| 213 |
mutable int model_; |
| 214 |
|
| 215 |
// There is a major assumption here: |
| 216 |
// As soon as somebody call GetParameterList(), we freeze all other variables into the list, |
| 217 |
// and ignore them. This allows us to make the modification of the list from outside. |
| 218 |
mutable Teuchos::RCP<Teuchos::ParameterList> paramList_; |
| 219 |
}; |
| 220 |
|
| 221 |
} // namespace Xpetra |
| 222 |
} // namespace ADR |
| 223 |
|
| 224 |
#endif |