| 1 |
// @HEADER |
| 2 |
// ***************************************************************************** |
| 3 |
// Trilinos: An Object-Oriented Solver Framework |
| 4 |
// |
| 5 |
// Copyright 2001-2024 NTESS and the Trilinos contributors. |
| 6 |
// SPDX-License-Identifier: BSD-3-Clause |
| 7 |
// ***************************************************************************** |
| 8 |
// @HEADER |
| 9 |
|
| 10 |
/** \file example_Maxwell.cpp |
| 11 |
\brief Example solution of the eddy current Maxwell's equations using |
| 12 |
curl-conforming (edge) elements. |
| 13 |
|
| 14 |
|
| 15 |
This example uses the following Trilinos packages: |
| 16 |
\li Pamgen to generate a Hexahedral mesh. |
| 17 |
\li Intrepid to build the discretization matrices and right-hand side. |
| 18 |
\li Epetra to handle the global matrix and vector. |
| 19 |
\li ML to solve the linear system. |
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
\verbatim |
| 24 |
|
| 25 |
Maxwell System: |
| 26 |
|
| 27 |
curl x mu^{-1} curl E + sigma E = f |
| 28 |
|
| 29 |
Corresponding discrete linear system for edge element coeficients (x): |
| 30 |
|
| 31 |
(Kc + Mc)x = b |
| 32 |
|
| 33 |
Kc - Hcurl stiffness matrix |
| 34 |
Mc - Hcurl mass matrix |
| 35 |
b - right hand side vector |
| 36 |
|
| 37 |
\endverbatim |
| 38 |
|
| 39 |
\author Created by P. Bochev, D. Ridzal, K. Peterson, D. Hensinger, C. Siefert. |
| 40 |
|
| 41 |
\remark Usage |
| 42 |
\verbatim |
| 43 |
|
| 44 |
./TrilinosCouplings_examples_scaling_Example_Maxwell.exe inputfile.xml |
| 45 |
|
| 46 |
|
| 47 |
inputfile.xml (optional) - xml input file containing Pamgen mesh description |
| 48 |
and material parameters for each Pamgen block, |
| 49 |
if not present code attempts to read Maxwell.xml. |
| 50 |
|
| 51 |
\endverbatim |
| 52 |
|
| 53 |
Input files available in Trilinos for use with the Maxwell driver: |
| 54 |
|
| 55 |
\li Maxwell.xml - basic input file with box mesh and one mesh block |
| 56 |
\li Ninja.xml - input file with distorted mesh (shaped like Ninja star) and one mesh block |
| 57 |
\li Maxwell_in_block.xml - input file with box mesh with a center block with different material values. |
| 58 |
|
| 59 |
**/ |
| 60 |
|
| 61 |
/**************************************************************/ |
| 62 |
/* Includes */ |
| 63 |
/**************************************************************/ |
| 64 |
// TrilinosCouplings includes |
| 65 |
#include "TrilinosCouplings_config.h" |
| 66 |
#include "TrilinosCouplings_Pamgen_Utils.hpp" |
| 67 |
#include "TrilinosCouplings_Statistics.hpp" |
| 68 |
|
| 69 |
// Intrepid includes |
| 70 |
#include "Intrepid_FunctionSpaceTools.hpp" |
| 71 |
#include "Intrepid_FieldContainer.hpp" |
| 72 |
#include "Intrepid_CellTools.hpp" |
| 73 |
#include "Intrepid_ArrayTools.hpp" |
| 74 |
#include "Intrepid_HCURL_HEX_I1_FEM.hpp" |
| 75 |
#include "Intrepid_HGRAD_HEX_C1_FEM.hpp" |
| 76 |
#include "Intrepid_RealSpaceTools.hpp" |
| 77 |
#include "Intrepid_DefaultCubatureFactory.hpp" |
| 78 |
#include "Intrepid_Utils.hpp" |
| 79 |
|
| 80 |
// Kokkos includes |
| 81 |
#include "Kokkos_Core.hpp" |
| 82 |
|
| 83 |
// Epetra includes |
| 84 |
#include "Epetra_Time.h" |
| 85 |
#include "Epetra_Map.h" |
| 86 |
#ifdef HAVE_MPI |
| 87 |
#include "Epetra_MpiComm.h" |
| 88 |
#else |
| 89 |
#include "Epetra_SerialComm.h" |
| 90 |
#endif |
| 91 |
#include "Epetra_Import.h" |
| 92 |
#include "Epetra_Export.h" |
| 93 |
#include "Epetra_CrsMatrix.h" |
| 94 |
#include "Epetra_FECrsMatrix.h" |
| 95 |
#include "Epetra_FEVector.h" |
| 96 |
#include "Epetra_LinearProblem.h" |
| 97 |
|
| 98 |
// Teuchos includes |
| 99 |
#include "Teuchos_oblackholestream.hpp" |
| 100 |
#include "Teuchos_RCP.hpp" |
| 101 |
#include "Teuchos_BLAS.hpp" |
| 102 |
#include "Teuchos_GlobalMPISession.hpp" |
| 103 |
#include "Teuchos_ParameterList.hpp" |
| 104 |
#include "Teuchos_XMLParameterListHelpers.hpp" |
| 105 |
#include "Teuchos_Comm.hpp" |
| 106 |
#include "Teuchos_DefaultComm.hpp" |
| 107 |
|
| 108 |
// Shards includes |
| 109 |
#include "Shards_CellTopology.hpp" |
| 110 |
|
| 111 |
// EpetraExt includes |
| 112 |
#include "EpetraExt_RowMatrixOut.h" |
| 113 |
#include "EpetraExt_MultiVectorOut.h" |
| 114 |
#include "EpetraExt_VectorOut.h" |
| 115 |
#include "EpetraExt_MatrixMatrix.h" |
| 116 |
|
| 117 |
// AztecOO includes |
| 118 |
#include "AztecOO.h" |
| 119 |
|
| 120 |
// ML Includes |
| 121 |
#include "ml_MultiLevelPreconditioner.h" |
| 122 |
#include "ml_RefMaxwell_11_Operator.h" |
| 123 |
#include "ml_RefMaxwell.h" |
| 124 |
#include "ml_EdgeMatrixFreePreconditioner.h" |
| 125 |
#include "ml_epetra_utils.h" |
| 126 |
|
| 127 |
#ifdef HAVE_TRILINOSCOUPLINGS_MUELU |
| 128 |
// Xpetra |
| 129 |
#include <Xpetra_MultiVector.hpp> |
| 130 |
#include <Xpetra_MultiVectorFactory.hpp> |
| 131 |
#include <Xpetra_CrsMatrix.hpp> |
| 132 |
#include <Xpetra_CrsMatrixWrap.hpp> |
| 133 |
#include <Xpetra_Matrix.hpp> |
| 134 |
|
| 135 |
#ifdef HAVE_TRILINOSCOUPLINGS_AVATAR |
| 136 |
# include "MueLu_AvatarInterface.hpp" |
| 137 |
#endif //HAVE_TRILINOSCOUPLINGS_AVATAR |
| 138 |
|
| 139 |
// MueLu |
| 140 |
#include <MueLu_RefMaxwell.hpp> |
| 141 |
#ifdef HAVE_MUELU_EPETRA |
| 142 |
#include <MueLu_AztecEpetraOperator.hpp> |
| 143 |
#endif |
| 144 |
#include <MueLu_Exceptions.hpp> |
| 145 |
|
| 146 |
#endif |
| 147 |
|
| 148 |
// Pamgen includes |
| 149 |
#include "create_inline_mesh.h" |
| 150 |
#include "pamgen_im_exodusII_l.h" |
| 151 |
#include "pamgen_im_ne_nemesisI_l.h" |
| 152 |
#include "pamgen_extras.h" |
| 153 |
|
| 154 |
|
| 155 |
#ifdef HAVE_TRILINOSCOUPLINGS_STRATIMIKOS |
| 156 |
#include "Stratimikos_DefaultLinearSolverBuilder.hpp" |
| 157 |
#ifdef HAVE_TRILINOSCOUPLINGS_MUELU |
| 158 |
#include <Stratimikos_MueLuHelpers.hpp> |
| 159 |
#endif |
| 160 |
#endif |
| 161 |
|
| 162 |
#include "TrilinosCouplings_IntrepidPoissonExampleHelpers.hpp" |
| 163 |
|
| 164 |
|
| 165 |
#define ABS(x) ((x)>0?(x):-(x)) |
| 166 |
#define SQR(x) ((x)*(x)) |
| 167 |
|
| 168 |
|
| 169 |
/*** Uncomment if you would like output data for plotting ***/ |
| 170 |
|
| 171 |
using namespace std; |
| 172 |
using namespace Intrepid; |
| 173 |
|
| 174 |
|
| 175 |
/*********************************************************/ |
| 176 |
/* Typedefs */ |
| 177 |
/*********************************************************/ |
| 178 |
typedef Intrepid::FunctionSpaceTools IntrepidFSTools; |
| 179 |
typedef Intrepid::RealSpaceTools<double> IntrepidRSTools; |
| 180 |
typedef Intrepid::CellTools<double> IntrepidCTools; |
| 181 |
|
| 182 |
|
| 183 |
struct fecomp{ |
| 184 |
bool operator () ( topo_entity* x, topo_entity* y )const |
| 185 |
{ |
| 186 |
if(x->sorted_local_node_ids < y->sorted_local_node_ids)return true; |
| 187 |
return false; |
| 188 |
} |
| 189 |
}; |
| 190 |
|
| 191 |
template<class Container> |
| 192 |
double distance(Container &nodeCoord, int i1, int i2) { |
| 193 |
double dist = 0.0; |
| 194 |
for(int j=0; j<3; j++) |
| 195 |
dist+= SQR( nodeCoord(i1,j) - nodeCoord(i2,j) ); |
| 196 |
return sqrt(dist); |
| 197 |
} |
| 198 |
|
| 199 |
/**********************************************************************************/ |
| 200 |
/***************** FUNCTION DECLARATION FOR ML PRECONDITIONER *********************/ |
| 201 |
/**********************************************************************************/ |
| 202 |
|
| 203 |
/** \brief ML Preconditioner |
| 204 |
|
| 205 |
\param ProblemType [in] problem type |
| 206 |
\param MLList [in] ML parameter list |
| 207 |
\param CurlCurl [in] H(curl) stiffness matrix |
| 208 |
\param D0clean [in] Edge to node stiffness matrix |
| 209 |
\param M0inv [in] H(grad) mass matrix inverse |
| 210 |
\param Ms [in] H(curl) mass matrix w/ sigma |
| 211 |
\param M1 [in] H(curl) mass matrix w/o sigma |
| 212 |
\param xh [out] solution vector |
| 213 |
\param b [in] right-hand-side vector |
| 214 |
\param TotalErrorResidual [out] error residual |
| 215 |
\param TotalErrorExactSol [out] error in xh |
| 216 |
|
| 217 |
*/ |
| 218 |
void TestMultiLevelPreconditioner_Maxwell(char ProblemType[], |
| 219 |
Teuchos::ParameterList & MLList, |
| 220 |
Epetra_CrsMatrix & CurlCurl, |
| 221 |
Epetra_CrsMatrix & D0clean, |
| 222 |
Epetra_CrsMatrix & M0inv, |
| 223 |
Epetra_CrsMatrix & Ms, |
| 224 |
Epetra_CrsMatrix & M1, |
| 225 |
Epetra_MultiVector & xh, |
| 226 |
Epetra_MultiVector & b, |
| 227 |
double & TotalErrorResidual, |
| 228 |
double & TotalErrorExactSol); |
| 229 |
|
| 230 |
#if defined(HAVE_MUELU_EPETRA) and defined(HAVE_TRILINOSCOUPLINGS_MUELU) |
| 231 |
/** \brief MueLu Preconditioner |
| 232 |
|
| 233 |
\param ProblemType [in] problem type |
| 234 |
\param MLList [in] ML parameter list |
| 235 |
\param CurlCurl [in] H(curl) stiffness matrix |
| 236 |
\param D0clean [in] Edge to node stiffness matrix |
| 237 |
\param M0inv [in] H(grad) mass matrix inverse |
| 238 |
\param Ms [in] H(curl) mass matrix w/ sigma |
| 239 |
\param M1 [in] H(curl) mass matrix w/o sigma |
| 240 |
\param xh [out] solution vector |
| 241 |
\param b [in] right-hand-side vector |
| 242 |
\param TotalErrorResidual [out] error residual |
| 243 |
\param TotalErrorExactSol [out] error in xh |
| 244 |
|
| 245 |
*/ |
| 246 |
void TestMueLuMultiLevelPreconditioner_Maxwell(char ProblemType[], |
| 247 |
Teuchos::ParameterList & MLList, |
| 248 |
Epetra_CrsMatrix & CurlCurl, |
| 249 |
Epetra_CrsMatrix & D0clean, |
| 250 |
Epetra_CrsMatrix & M0inv, |
| 251 |
Epetra_CrsMatrix & Ms, |
| 252 |
Epetra_CrsMatrix & M1, |
| 253 |
Epetra_MultiVector & coords, |
| 254 |
Epetra_MultiVector & xh, |
| 255 |
Epetra_MultiVector & b, |
| 256 |
double & TotalErrorResidual, |
| 257 |
double & TotalErrorExactSol); |
| 258 |
#endif |
| 259 |
|
| 260 |
|
| 261 |
/** \brief ML Preconditioner |
| 262 |
|
| 263 |
\param ProblemType [in] problem type |
| 264 |
\param MLList [in] ML parameter list |
| 265 |
\param CurlCurl [in] H(curl) stiffness matrix |
| 266 |
\param D0clean [in] Edge to node stiffness matrix |
| 267 |
\param M0inv [in] H(grad) mass matrix inverse |
| 268 |
\param Ms [in] H(curl) mass matrix w/ sigma |
| 269 |
\param M1 [in] H(curl) mass matrix w/o sigma |
| 270 |
\param xh [out] solution vector |
| 271 |
\param b [in] right-hand-side vector |
| 272 |
\param TotalErrorResidual [out] error residual |
| 273 |
\param TotalErrorExactSol [out] error in xh |
| 274 |
|
| 275 |
*/ |
| 276 |
#ifdef HAVE_TRILINOSCOUPLINGS_STRATIMIKOS |
| 277 |
void TestMultiLevelPreconditioner_Stratimikos(char ProblemType[], |
| 278 |
Teuchos::ParameterList & MLList, |
| 279 |
Epetra_CrsMatrix & CurlCurl, |
| 280 |
Epetra_CrsMatrix & D0clean, |
| 281 |
Epetra_CrsMatrix & M0inv, |
| 282 |
Epetra_CrsMatrix & Ms, |
| 283 |
Epetra_CrsMatrix & M1, |
| 284 |
Epetra_MultiVector & xh, |
| 285 |
Epetra_MultiVector & b, |
| 286 |
double & TotalErrorResidual, |
| 287 |
double & TotalErrorExactSol); |
| 288 |
|
| 289 |
#if defined(HAVE_MUELU_EPETRA) and defined(HAVE_TRILINOSCOUPLINGS_MUELU) |
| 290 |
/** \brief MueLu Preconditioner |
| 291 |
|
| 292 |
\param ProblemType [in] problem type |
| 293 |
\param MLList [in] ML parameter list |
| 294 |
\param CurlCurl [in] H(curl) stiffness matrix |
| 295 |
\param D0clean [in] Edge to node stiffness matrix |
| 296 |
\param M0inv [in] H(grad) mass matrix inverse |
| 297 |
\param Ms [in] H(curl) mass matrix w/ sigma |
| 298 |
\param M1 [in] H(curl) mass matrix w/o sigma |
| 299 |
\param xh [out] solution vector |
| 300 |
\param b [in] right-hand-side vector |
| 301 |
\param TotalErrorResidual [out] error residual |
| 302 |
\param TotalErrorExactSol [out] error in xh |
| 303 |
|
| 304 |
*/ |
| 305 |
void TestPreconditioner_Stratimikos(char ProblemType[], |
| 306 |
Teuchos::ParameterList & SList, |
| 307 |
Epetra_CrsMatrix & CurlCurl, |
| 308 |
Epetra_CrsMatrix & D0clean, |
| 309 |
Epetra_CrsMatrix & M0inv, |
| 310 |
Epetra_CrsMatrix & Ms, |
| 311 |
Epetra_CrsMatrix & M1, |
| 312 |
Epetra_MultiVector & coords, |
| 313 |
Epetra_Vector & Nx, |
| 314 |
Epetra_Vector & Ny, |
| 315 |
Epetra_Vector & Nz, |
| 316 |
Epetra_MultiVector & xh, |
| 317 |
Epetra_MultiVector & b, |
| 318 |
double & TotalErrorResidual, |
| 319 |
double & TotalErrorExactSol); |
| 320 |
#endif |
| 321 |
#endif |
| 322 |
|
| 323 |
/**********************************************************************************/ |
| 324 |
/******** FUNCTION DECLARATIONS FOR EXACT SOLUTION AND SOURCE TERMS ***************/ |
| 325 |
/**********************************************************************************/ |
| 326 |
|
| 327 |
/** \brief Exact solution evaluation. |
| 328 |
|
| 329 |
\param uExact0 [out] first component of exact solution at (x,y,z) |
| 330 |
\param uExact1 [out] second component of exact solution at (x,y,z) |
| 331 |
\param uExact2 [out] third component of exact solution at (x,y,z) |
| 332 |
\param x [in] x coordinate |
| 333 |
\param y [in] y coordinate |
| 334 |
\param z [in] z coordinate |
| 335 |
*/ |
| 336 |
int evalu(double & uExact0, |
| 337 |
double & uExact1, |
| 338 |
double & uExact2, |
| 339 |
double & x, |
| 340 |
double & y, |
| 341 |
double & z); |
| 342 |
|
| 343 |
/** \brief Curl of exact solution. |
| 344 |
|
| 345 |
\param curlu0 [out] first component of curl of exact solution |
| 346 |
\param curlu1 [out] second component of curl of exact solution |
| 347 |
\param curlu2 [out] third component of curl of exact solution |
| 348 |
\param x [in] x coordinate |
| 349 |
\param y [in] y coordinate |
| 350 |
\param z [in] z coordinate |
| 351 |
\param mu [in] material parameter |
| 352 |
*/ |
| 353 |
int evalCurlu(double & curlu0, |
| 354 |
double & curlu1, |
| 355 |
double & curlu2, |
| 356 |
double & x, |
| 357 |
double & y, |
| 358 |
double & z, |
| 359 |
double & mu); |
| 360 |
|
| 361 |
/** \brief CurlCurl of exact solution. |
| 362 |
|
| 363 |
\param curlcurlu0 [out] first component of curl-curl of exact solution |
| 364 |
\param curlcurlu1 [out] second component of curl-curl of exact solution |
| 365 |
\param curlcurlu2 [out] third component of curl-curl of exact solution |
| 366 |
\param x [in] x coordinate |
| 367 |
\param y [in] y coordinate |
| 368 |
\param z [in] z coordinate |
| 369 |
\param mu [in] material parameter |
| 370 |
*/ |
| 371 |
int evalCurlCurlu(double & curlcurlu0, |
| 372 |
double & curlcurlu1, |
| 373 |
double & curlcurlu2, |
| 374 |
double & x, |
| 375 |
double & y, |
| 376 |
double & z, |
| 377 |
double & mu); |
| 378 |
|
| 379 |
/**********************************************************************************/ |
| 380 |
/**********************************************************************************/ |
| 381 |
/**********************************************************************************/ |
| 382 |
|
| 383 |
|
| 384 |
|
| 385 |
/**********************************************************************************/ |
| 386 |
/******************************** MAIN ********************************************/ |
| 387 |
/**********************************************************************************/ |
| 388 |
int body(int argc, char *argv[]); |
| 389 |
|
| 390 |
int main(int argc, char *argv[]) { |
| 391 |
#ifdef HAVE_MPI |
| 392 |
Teuchos::GlobalMPISession mpiSession(&argc, &argv,0); |
| 393 |
#endif |
| 394 |
Kokkos::initialize(argc,argv); |
| 395 |
body(argc,argv); |
| 396 |
if (!Kokkos::is_finalized()) |
| 397 |
Kokkos::finalize(); |
| 398 |
} |
| 399 |
|
| 400 |
int body(int argc, char *argv[]) { |
| 401 |
// using namespace TrilinosCouplings; |
| 402 |
// using IntrepidPoissonExample::parseCommandLineArguments; |
| 403 |
// using IntrepidPoissonExample::setCommandLineArgumentDefaults; |
| 404 |
// using IntrepidPoissonExample::setMaterialTensorOffDiagonalValue; |
| 405 |
// using IntrepidPoissonExample::setUpCommandLineArguments; |
| 406 |
using Teuchos::CommandLineProcessor; |
| 407 |
|
| 408 |
int error = 0; |
| 409 |
#ifdef HAVE_MPI |
| 410 |
Epetra_MpiComm Comm(MPI_COMM_WORLD); // CHECK: ALLOW MPI_COMM_WORLD |
| 411 |
int rank=Comm.MyPID(); |
| 412 |
int numProcs=Comm.NumProc(); |
| 413 |
int MyPID = Comm.MyPID(); |
| 414 |
#else |
| 415 |
int rank=0; |
| 416 |
int numProcs=1; |
| 417 |
int MyPID = 0; |
| 418 |
Epetra_SerialComm Comm; |
| 419 |
#endif |
| 420 |
Epetra_Time Time(Comm); |
| 421 |
|
| 422 |
|
| 423 |
// Did the user specify --help at the command line to print help |
| 424 |
// with command-line arguments? |
| 425 |
bool printedHelp = false; |
| 426 |
// Values of command-line arguments. |
| 427 |
int nx, ny, nz; |
| 428 |
std::string xmlInFileName, xmlStratimikos; |
| 429 |
bool verbose, debug, jiggle, dump; |
| 430 |
std::string solverName; |
| 431 |
double scaling = 1.0; |
| 432 |
|
| 433 |
// Set default values of command-line arguments. |
| 434 |
nx = 10; |
| 435 |
ny = 10; |
| 436 |
nz = 10; |
| 437 |
xmlInFileName = "Maxwell.xml"; |
| 438 |
xmlStratimikos = "stratimikos.xml"; |
| 439 |
solverName = "default"; |
| 440 |
verbose = false; |
| 441 |
debug = false; |
| 442 |
jiggle = false; |
| 443 |
dump = false; |
| 444 |
// Parse and validate command-line arguments. |
| 445 |
Teuchos::CommandLineProcessor cmdp (false, true); |
| 446 |
cmdp.setOption ("nx", &nx, "Number of cells along the x dimension"); |
| 447 |
cmdp.setOption ("ny", &ny, "Number of cells along the y dimension"); |
| 448 |
cmdp.setOption ("nz", &nz, "Number of cells along the z dimension"); |
| 449 |
cmdp.setOption ("inputParams", &xmlInFileName, "XML file of input " |
| 450 |
"parameters, which we read if specified and not \"\". " |
| 451 |
"If it has a \"meshInput\" parameter, we use its " |
| 452 |
"std::string value as the Pamgen mesh specification. " |
| 453 |
"Otherwise, we tell Pamgen to make a cube, using " |
| 454 |
"nx, ny, and nz."); |
| 455 |
cmdp.setOption ("stratimikosParams", &xmlStratimikos, "XML file with Stratimikos inputs"); |
| 456 |
cmdp.setOption ("solverName", &solverName, "Name of iterative linear solver " |
| 457 |
"to use for solving the linear system. Examples include " |
| 458 |
"\"ML\", \"MueLu\", \"ML-Stratimikos\" and \"Stratimikos\"."); |
| 459 |
cmdp.setOption ("verbose", "quiet", &verbose, |
| 460 |
"Whether to print verbose status output."); |
| 461 |
cmdp.setOption ("debug", "release", &debug, |
| 462 |
"Whether to print copious debugging output to stderr."); |
| 463 |
cmdp.setOption ("scaling", &scaling, "scale mass matrix"); |
| 464 |
cmdp.setOption ("jiggle", "nojiggle", &jiggle, |
| 465 |
"Whether to randomly perturb the mesh."); |
| 466 |
cmdp.setOption ("dump", "nodump", &dump, |
| 467 |
"Whether to dump data."); |
| 468 |
|
| 469 |
if (MyPID == 0) { |
| 470 |
std::cout \ |
| 471 |
<< "===============================================================================\n" \ |
| 472 |
<< "| |\n" \ |
| 473 |
<< "| Example: Solve Div-Curl System on Hexahedral Mesh |\n" \ |
| 474 |
<< "| with Curl-conforming Elements |\n" \ |
| 475 |
<< "| |\n" \ |
| 476 |
<< "| Questions? Contact Pavel Bochev ([email protected]), |\n" \ |
| 477 |
<< "| Denis Ridzal ([email protected]), |\n" \ |
| 478 |
<< "| Kara Peterson ([email protected]). |\n" \ |
| 479 |
<< "| |\n" \ |
| 480 |
<< "| Intrepid's website: http://trilinos.sandia.gov/packages/intrepid |\n" \ |
| 481 |
<< "| Pamgen's website: http://trilinos.sandia.gov/packages/pamgen |\n" \ |
| 482 |
<< "| ML's website: http://trilinos.sandia.gov/packages/ml |\n" \ |
| 483 |
<< "| Trilinos website: http://trilinos.sandia.gov |\n" \ |
| 484 |
<< "| |\n" \ |
| 485 |
<< "===============================================================================\n"; |
| 486 |
} |
| 487 |
|
| 488 |
const CommandLineProcessor::EParseCommandLineReturn parseResult = |
| 489 |
cmdp.parse (argc, argv); |
| 490 |
if (parseResult == CommandLineProcessor::PARSE_HELP_PRINTED) { |
| 491 |
printedHelp = true; |
| 492 |
} |
| 493 |
else { |
| 494 |
printedHelp = false; |
| 495 |
TEUCHOS_TEST_FOR_EXCEPTION( |
| 496 |
parseResult != CommandLineProcessor::PARSE_SUCCESSFUL, |
| 497 |
std::invalid_argument, "Failed to parse command-line arguments."); |
| 498 |
TEUCHOS_TEST_FOR_EXCEPTION( |
| 499 |
xmlInFileName == "" && (nx <= 0 || ny <= 0 || nz <= 0), |
| 500 |
std::invalid_argument, "If no XML parameters filename is specified (via " |
| 501 |
"--inputParams), then the number of cells along each dimension of the " |
| 502 |
"mesh (--nx, --ny, and --nz) must be positive."); |
| 503 |
} |
| 504 |
|
| 505 |
if (printedHelp) { |
| 506 |
// The user specified --help at the command line to print help |
| 507 |
// with command-line arguments. We printed help already, so quit |
| 508 |
// with a happy return code. |
| 509 |
return EXIT_SUCCESS; |
| 510 |
} |
| 511 |
|
| 512 |
long long * node_comm_proc_ids = NULL; |
| 513 |
long long * node_cmap_node_cnts = NULL; |
| 514 |
long long * node_cmap_ids = NULL; |
| 515 |
long long ** comm_node_ids = NULL; |
| 516 |
long long ** comm_node_proc_ids = NULL; |
| 517 |
|
| 518 |
std::set < topo_entity * , fecomp > edge_set; |
| 519 |
std::set < topo_entity * , fecomp > face_set; |
| 520 |
|
| 521 |
std::vector < topo_entity * > edge_vector; |
| 522 |
std::vector < topo_entity * > face_vector; |
| 523 |
|
| 524 |
std::vector < int > edge_comm_procs; |
| 525 |
|
| 526 |
|
| 527 |
/**********************************************************************************/ |
| 528 |
/********************************** GET XML INPUTS ********************************/ |
| 529 |
/**********************************************************************************/ |
| 530 |
|
| 531 |
// Read xml file into parameter list |
| 532 |
Teuchos::ParameterList inputList; |
| 533 |
|
| 534 |
if(xmlInFileName.length()) { |
| 535 |
if (MyPID == 0) { |
| 536 |
std::cout << "\nReading parameter list from the XML file \""<<xmlInFileName<<"\" ...\n\n"; |
| 537 |
} |
| 538 |
Teuchos::updateParametersFromXmlFile(xmlInFileName,Teuchos::ptr (&inputList)); |
| 539 |
if (MyPID == 0) { |
| 540 |
inputList.print(std::cout,2,true,true); |
| 541 |
std::cout << "\n"; |
| 542 |
} |
| 543 |
} |
| 544 |
// Get pamgen mesh definition |
| 545 |
std::string meshInput = \ |
| 546 |
"mesh \n" |
| 547 |
" brick \n" |
| 548 |
" zmin = 0.0 \n" |
| 549 |
" xmin = 0.0 \n" |
| 550 |
" ymin = 0.0 \n" |
| 551 |
" numz 1 \n" |
| 552 |
" zblock 1 1.0 interval " + std::to_string(nz) + "\n" + |
| 553 |
" numx 1 \n" |
| 554 |
" xblock 1 1.0 interval " + std::to_string(nx) + "\n" + |
| 555 |
" numy 1 \n" |
| 556 |
" yblock 1 1.0 interval " + std::to_string(ny) + "\n" + |
| 557 |
" end \n" |
| 558 |
" set assign \n" |
| 559 |
" sideset, ilo, 1 \n" |
| 560 |
" sideset, jlo, 2 \n" |
| 561 |
" sideset, klo, 3 \n" |
| 562 |
" sideset, ihi, 4 \n" |
| 563 |
" sideset, jhi, 5 \n" |
| 564 |
" sideset, khi, 6 \n" |
| 565 |
" end \n" |
| 566 |
"end \n"; |
| 567 |
meshInput = inputList.get("meshInput", meshInput); |
| 568 |
|
| 569 |
// Get the solver name from input deck or command line |
| 570 |
if(solverName == "default") { |
| 571 |
if(inputList.isParameter("Preconditioner")) |
| 572 |
solverName=inputList.get("Preconditioner","MueLu"); |
| 573 |
else |
| 574 |
solverName="MueLu"; |
| 575 |
} |
| 576 |
|
| 577 |
|
| 578 |
|
| 579 |
|
| 580 |
|
| 581 |
/**********************************************************************************/ |
| 582 |
/***************************** GET CELL TOPOLOGY **********************************/ |
| 583 |
/**********************************************************************************/ |
| 584 |
|
| 585 |
// Get cell topology for base hexahedron |
| 586 |
shards::CellTopology cellType(shards::getCellTopologyData<shards::Hexahedron<8> >() ); |
| 587 |
|
| 588 |
// Get dimensions |
| 589 |
int numNodesPerElem = cellType.getNodeCount(); |
| 590 |
int numEdgesPerElem = cellType.getEdgeCount(); |
| 591 |
int numFacesPerElem = cellType.getSideCount(); |
| 592 |
int numNodesPerEdge = 2; |
| 593 |
int numNodesPerFace = 4; |
| 594 |
int numEdgesPerFace = 4; |
| 595 |
int spaceDim = cellType.getDimension(); |
| 596 |
|
| 597 |
// Build reference element edge to node map |
| 598 |
FieldContainer<int> refEdgeToNode(numEdgesPerElem,numNodesPerEdge); |
| 599 |
for (int i=0; i<numEdgesPerElem; i++){ |
| 600 |
refEdgeToNode(i,0)=cellType.getNodeMap(1, i, 0); |
| 601 |
refEdgeToNode(i,1)=cellType.getNodeMap(1, i, 1); |
| 602 |
} |
| 603 |
|
| 604 |
// Build reference element face to node map |
| 605 |
FieldContainer<int> refFaceToNode(numFacesPerElem,numNodesPerFace); |
| 606 |
for (int i=0; i<numFacesPerElem; i++){ |
| 607 |
refFaceToNode(i,0)=cellType.getNodeMap(2, i, 0); |
| 608 |
refFaceToNode(i,1)=cellType.getNodeMap(2, i, 1); |
| 609 |
refFaceToNode(i,2)=cellType.getNodeMap(2, i, 2); |
| 610 |
refFaceToNode(i,3)=cellType.getNodeMap(2, i, 3); |
| 611 |
} |
| 612 |
|
| 613 |
// Build reference element face to edge map (Hardcoded for now) |
| 614 |
FieldContainer<int> refFaceToEdge(numFacesPerElem,numEdgesPerFace); |
| 615 |
refFaceToEdge(0,0)=0; refFaceToEdge(0,1)=9; |
| 616 |
refFaceToEdge(0,2)=4; refFaceToEdge(0,3)=8; |
| 617 |
refFaceToEdge(1,0)=1; refFaceToEdge(1,1)=10; |
| 618 |
refFaceToEdge(1,2)=5; refFaceToEdge(1,3)=9; |
| 619 |
refFaceToEdge(2,0)=2; refFaceToEdge(2,1)=11; |
| 620 |
refFaceToEdge(2,2)=6; refFaceToEdge(2,3)=10; |
| 621 |
refFaceToEdge(3,0)=3; refFaceToEdge(3,1)=8; |
| 622 |
refFaceToEdge(3,2)=7; refFaceToEdge(3,3)=11; |
| 623 |
refFaceToEdge(4,0)=0; refFaceToEdge(4,1)=1; |
| 624 |
refFaceToEdge(4,2)=2; refFaceToEdge(4,3)=3; |
| 625 |
refFaceToEdge(5,0)=4; refFaceToEdge(5,1)=5; |
| 626 |
refFaceToEdge(5,2)=6; refFaceToEdge(5,3)=7; |
| 627 |
|
| 628 |
|
| 629 |
/**********************************************************************************/ |
| 630 |
/******************************* GENERATE MESH ************************************/ |
| 631 |
/**********************************************************************************/ |
| 632 |
|
| 633 |
|
| 634 |
if (MyPID == 0) { |
| 635 |
std::cout << "Generating mesh ... \n\n"; |
| 636 |
} |
| 637 |
|
| 638 |
// Generate mesh with Pamgen |
| 639 |
int dim=3; |
| 640 |
long long maxInt = 9223372036854775807LL; |
| 641 |
long long cr_result = Create_Pamgen_Mesh(meshInput.c_str(), dim, rank, numProcs, maxInt); |
| 642 |
TrilinosCouplings::pamgen_error_check(std::cout,cr_result); |
| 643 |
|
| 644 |
// Get local mesh size info |
| 645 |
char title[100]; |
| 646 |
long long numDim; |
| 647 |
long long numNodes; |
| 648 |
long long numElems; |
| 649 |
long long numElemBlk; |
| 650 |
long long numNodeSets; |
| 651 |
long long numSideSets; |
| 652 |
int id = 0; |
| 653 |
|
| 654 |
im_ex_get_init_l(id, title, &numDim, &numNodes, |
| 655 |
&numElems, &numElemBlk, &numNodeSets, |
| 656 |
&numSideSets); |
| 657 |
|
| 658 |
// Get global mesh size info |
| 659 |
long long numNodesGlobal; |
| 660 |
long long numElemsGlobal; |
| 661 |
long long numElemBlkGlobal; |
| 662 |
long long numNodeSetsGlobal; |
| 663 |
long long numSideSetsGlobal; |
| 664 |
|
| 665 |
im_ne_get_init_global_l(id, &numNodesGlobal, &numElemsGlobal, |
| 666 |
&numElemBlkGlobal, &numNodeSetsGlobal, |
| 667 |
&numSideSetsGlobal); |
| 668 |
#ifdef HAVE_XPETRA_EPETRA |
| 669 |
MachineLearningStatistics_Hex3D<double, int, int, Xpetra::EpetraNode> MLStatistics(numElemsGlobal); |
| 670 |
#endif |
| 671 |
|
| 672 |
long long * block_ids = new long long [numElemBlk]; |
| 673 |
error += im_ex_get_elem_blk_ids_l(id, block_ids); |
| 674 |
|
| 675 |
|
| 676 |
long long *nodes_per_element = new long long [numElemBlk]; |
| 677 |
long long *element_attributes = new long long [numElemBlk]; |
| 678 |
long long *elements = new long long [numElemBlk]; |
| 679 |
char **element_types = new char * [numElemBlk]; |
| 680 |
long long **elmt_node_linkage = new long long * [numElemBlk]; |
| 681 |
|
| 682 |
|
| 683 |
for(long long i = 0; i < numElemBlk; i ++){ |
| 684 |
element_types[i] = new char [MAX_STR_LENGTH + 1]; |
| 685 |
error += im_ex_get_elem_block_l(id, |
| 686 |
block_ids[i], |
| 687 |
element_types[i], |
| 688 |
(long long*)&(elements[i]), |
| 689 |
(long long*)&(nodes_per_element[i]), |
| 690 |
(long long*)&(element_attributes[i])); |
| 691 |
} |
| 692 |
|
| 693 |
/*connectivity*/ |
| 694 |
for(long long b = 0; b < numElemBlk; b++){ |
| 695 |
elmt_node_linkage[b] = new long long [nodes_per_element[b]*elements[b]]; |
| 696 |
error += im_ex_get_elem_conn_l(id,block_ids[b],elmt_node_linkage[b]); |
| 697 |
} |
| 698 |
|
| 699 |
// Get mu value for each block of elements from parameter list |
| 700 |
double *mu = new double [numElemBlk]; |
| 701 |
for(int b = 0; b < numElemBlk; b++){ |
| 702 |
stringstream muBlock; |
| 703 |
muBlock.clear(); |
| 704 |
muBlock << "mu" << b; |
| 705 |
mu[b] = inputList.get(muBlock.str(),1.0); |
| 706 |
} |
| 707 |
|
| 708 |
// Get mu value for each block of elements from parameter list |
| 709 |
double *sigma = new double [numElemBlk]; |
| 710 |
for(int b = 0; b < numElemBlk; b++){ |
| 711 |
stringstream sigmaBlock; |
| 712 |
sigmaBlock.clear(); |
| 713 |
sigmaBlock << "sigma" << b; |
| 714 |
sigma[b] = inputList.get(sigmaBlock.str(),1.0); |
| 715 |
} |
| 716 |
|
| 717 |
// Get node-element connectivity and set element mu/sigma value |
| 718 |
int telct = 0; |
| 719 |
FieldContainer<int> elemToNode(numElems,numNodesPerElem); |
| 720 |
FieldContainer<double> muVal(numElems); |
| 721 |
FieldContainer<double> sigmaVal(numElems); |
| 722 |
|
| 723 |
for(long long b = 0; b < numElemBlk; b++){ |
| 724 |
for(long long el = 0; el < elements[b]; el++){ |
| 725 |
for (int j=0; j<numNodesPerElem; j++) { |
| 726 |
elemToNode(telct,j) = elmt_node_linkage[b][el*numNodesPerElem + j]-1; |
| 727 |
} |
| 728 |
muVal(telct) = mu[b]; |
| 729 |
sigmaVal(telct) = sigma[b]; |
| 730 |
|
| 731 |
telct ++; |
| 732 |
} |
| 733 |
} |
| 734 |
|
| 735 |
// Read node coordinates and place in field container |
| 736 |
FieldContainer<double> nodeCoord(numNodes,dim); |
| 737 |
double * nodeCoordx = new double [numNodes]; |
| 738 |
double * nodeCoordy = new double [numNodes]; |
| 739 |
double * nodeCoordz = new double [numNodes]; |
| 740 |
im_ex_get_coord_l(id,nodeCoordx,nodeCoordy,nodeCoordz); |
| 741 |
for (int i=0; i<numNodes; i++) { |
| 742 |
nodeCoord(i,0)=nodeCoordx[i]; |
| 743 |
nodeCoord(i,1)=nodeCoordy[i]; |
| 744 |
nodeCoord(i,2)=nodeCoordz[i]; |
| 745 |
} |
| 746 |
|
| 747 |
/*parallel info*/ |
| 748 |
long long num_internal_nodes; |
| 749 |
long long num_border_nodes; |
| 750 |
long long num_external_nodes; |
| 751 |
long long num_internal_elems; |
| 752 |
long long num_border_elems; |
| 753 |
long long num_node_comm_maps; |
| 754 |
long long num_elem_comm_maps; |
| 755 |
im_ne_get_loadbal_param_l( id, |
| 756 |
&num_internal_nodes, |
| 757 |
&num_border_nodes, |
| 758 |
&num_external_nodes, |
| 759 |
&num_internal_elems, |
| 760 |
&num_border_elems, |
| 761 |
&num_node_comm_maps, |
| 762 |
&num_elem_comm_maps, |
| 763 |
0/*unused*/ ); |
| 764 |
|
| 765 |
if(num_node_comm_maps > 0){ |
| 766 |
node_comm_proc_ids = new long long [num_node_comm_maps]; |
| 767 |
node_cmap_node_cnts = new long long [num_node_comm_maps]; |
| 768 |
node_cmap_ids = new long long [num_node_comm_maps]; |
| 769 |
comm_node_ids = new long long* [num_node_comm_maps]; |
| 770 |
comm_node_proc_ids = new long long* [num_node_comm_maps]; |
| 771 |
|
| 772 |
long long * elem_cmap_ids = new long long [num_elem_comm_maps]; |
| 773 |
long long * elem_cmap_elem_cnts = new long long [num_elem_comm_maps]; |
| 774 |
if ( im_ne_get_cmap_params_l( id, |
| 775 |
node_cmap_ids, |
| 776 |
(long long*)node_cmap_node_cnts, |
| 777 |
elem_cmap_ids, |
| 778 |
(long long*)elem_cmap_elem_cnts, |
| 779 |
0/*not used proc_id*/ ) < 0 )++error; |
| 780 |
|
| 781 |
for(long long j = 0; j < num_node_comm_maps; j++) { |
| 782 |
comm_node_ids[j] = new long long [node_cmap_node_cnts[j]]; |
| 783 |
comm_node_proc_ids[j] = new long long [node_cmap_node_cnts[j]]; |
| 784 |
if ( im_ne_get_node_cmap_l( id, |
| 785 |
node_cmap_ids[j], |
| 786 |
comm_node_ids[j], |
| 787 |
comm_node_proc_ids[j], |
| 788 |
0/*not used proc_id*/ ) < 0 )++error; |
| 789 |
node_comm_proc_ids[j] = comm_node_proc_ids[j][0]; |
| 790 |
} |
| 791 |
} |
| 792 |
|
| 793 |
|
| 794 |
|
| 795 |
//Calculate global node ids |
| 796 |
long long * globalNodeIds = new long long[numNodes]; |
| 797 |
bool * nodeIsOwned = new bool[numNodes]; |
| 798 |
|
| 799 |
calc_global_node_ids(globalNodeIds, |
| 800 |
nodeIsOwned, |
| 801 |
numNodes, |
| 802 |
num_node_comm_maps, |
| 803 |
node_cmap_node_cnts, |
| 804 |
node_comm_proc_ids, |
| 805 |
comm_node_ids, |
| 806 |
rank); |
| 807 |
|
| 808 |
// Count owned nodes |
| 809 |
int ownedNodes=0; |
| 810 |
for(int i=0;i<numNodes;i++) |
| 811 |
if(nodeIsOwned[i]) ownedNodes++; |
| 812 |
|
| 813 |
// Build a list of the OWNED global ids... |
| 814 |
int *ownedGIDs=new int [ownedNodes]; |
| 815 |
int oidx=0; |
| 816 |
for(int i=0;i<numNodes;i++) |
| 817 |
if(nodeIsOwned[i]){ |
| 818 |
ownedGIDs[oidx]=(int)globalNodeIds[i]; |
| 819 |
oidx++; |
| 820 |
} |
| 821 |
|
| 822 |
FieldContainer<int> elemToEdge(numElems,numEdgesPerElem); |
| 823 |
FieldContainer<int> elemToFace(numElems,numFacesPerElem); |
| 824 |
|
| 825 |
// Calculate edge and face ids |
| 826 |
int elct = 0; |
| 827 |
for(long long b = 0; b < numElemBlk; b++){ |
| 828 |
if(nodes_per_element[b] == 4){ |
| 829 |
} |
| 830 |
else if (nodes_per_element[b] == 8){ |
| 831 |
//loop over all elements and push their edges onto a set if they are not there already |
| 832 |
for(long long el = 0; el < elements[b]; el++){ |
| 833 |
std::set< topo_entity *, fecomp > ::iterator fit; |
| 834 |
for (int i=0; i < numEdgesPerElem; i++){ |
| 835 |
topo_entity * teof = new topo_entity; |
| 836 |
for(int j = 0; j < numNodesPerEdge;j++){ |
| 837 |
teof->add_node(elmt_node_linkage[b][el*numNodesPerElem + refEdgeToNode(i,j)],globalNodeIds); |
| 838 |
} |
| 839 |
teof->sort(); |
| 840 |
fit = edge_set.find(teof); |
| 841 |
if(fit == edge_set.end()){ |
| 842 |
teof->local_id = edge_vector.size(); |
| 843 |
edge_set.insert(teof); |
| 844 |
elemToEdge(elct,i)= edge_vector.size(); |
| 845 |
edge_vector.push_back(teof); |
| 846 |
} |
| 847 |
else{ |
| 848 |
elemToEdge(elct,i) = (*fit)->local_id; |
| 849 |
delete teof; |
| 850 |
} |
| 851 |
} |
| 852 |
for (int i=0; i < numFacesPerElem; i++){ |
| 853 |
topo_entity * teof = new topo_entity; |
| 854 |
for(int j = 0; j < numNodesPerFace;j++){ |
| 855 |
teof->add_node(elmt_node_linkage[b][el*numNodesPerElem + refFaceToNode(i,j)],globalNodeIds); |
| 856 |
} |
| 857 |
teof->sort(); |
| 858 |
fit = face_set.find(teof); |
| 859 |
if(fit == face_set.end()){ |
| 860 |
teof->local_id = face_vector.size(); |
| 861 |
face_set.insert(teof); |
| 862 |
elemToFace(elct,i)= face_vector.size(); |
| 863 |
face_vector.push_back(teof); |
| 864 |
} |
| 865 |
else{ |
| 866 |
elemToFace(elct,i) = (*fit)->local_id; |
| 867 |
delete teof; |
| 868 |
} |
| 869 |
} |
| 870 |
elct ++; |
| 871 |
} |
| 872 |
} |
| 873 |
} |
| 874 |
|
| 875 |
// Edge to Node connectivity |
| 876 |
FieldContainer<int> edgeToNode(edge_vector.size(), numNodesPerEdge); |
| 877 |
for(unsigned ect = 0; ect != edge_vector.size(); ect++){ |
| 878 |
std::list<long long>::iterator elit; |
| 879 |
int nct = 0; |
| 880 |
for(elit = edge_vector[ect]->local_node_ids.begin(); |
| 881 |
elit != edge_vector[ect]->local_node_ids.end(); |
| 882 |
elit ++){ |
| 883 |
edgeToNode(ect,nct) = *elit-1; |
| 884 |
nct++; |
| 885 |
} |
| 886 |
} |
| 887 |
|
| 888 |
// Face to Node connectivity |
| 889 |
FieldContainer<int> faceToNode(face_vector.size(), numNodesPerFace); |
| 890 |
for(unsigned fct = 0; fct != face_vector.size(); fct++){ |
| 891 |
std::list<long long>::iterator flit; |
| 892 |
int nct = 0; |
| 893 |
for(flit = face_vector[fct]->local_node_ids.begin(); |
| 894 |
flit != face_vector[fct]->local_node_ids.end(); |
| 895 |
flit ++){ |
| 896 |
faceToNode(fct,nct) = *flit-1; |
| 897 |
nct++; |
| 898 |
} |
| 899 |
} |
| 900 |
|
| 901 |
// Face to Edge connectivity |
| 902 |
FieldContainer<int> faceToEdge(face_vector.size(), numEdgesPerFace); |
| 903 |
FieldContainer<bool> faceDone(face_vector.size()); |
| 904 |
for (int ielem = 0; ielem < numElems; ielem++){ |
| 905 |
for (int iface = 0; iface < numFacesPerElem; iface++){ |
| 906 |
if (!faceDone(elemToFace(ielem,iface))){ |
| 907 |
for (int iedge = 0; iedge < numEdgesPerFace; iedge++){ |
| 908 |
faceToEdge(elemToFace(ielem,iface),iedge) = |
| 909 |
elemToEdge(ielem,refFaceToEdge(iface,iedge)); |
| 910 |
faceDone(elemToFace(ielem,iface))=1; |
| 911 |
} |
| 912 |
} |
| 913 |
} |
| 914 |
} |
| 915 |
|
| 916 |
int numEdges = edge_vector.size(); |
| 917 |
int numFaces = face_vector.size(); |
| 918 |
|
| 919 |
// Calculate global edge and face numbering |
| 920 |
std::string doing_type; |
| 921 |
doing_type = "EDGES"; |
| 922 |
calc_global_ids(edge_vector, |
| 923 |
comm_node_ids, |
| 924 |
node_comm_proc_ids, |
| 925 |
node_cmap_node_cnts, |
| 926 |
num_node_comm_maps, |
| 927 |
rank, |
| 928 |
doing_type); |
| 929 |
|
| 930 |
|
| 931 |
doing_type = "FACES"; |
| 932 |
calc_global_ids(face_vector, |
| 933 |
comm_node_ids, |
| 934 |
node_comm_proc_ids, |
| 935 |
node_cmap_node_cnts, |
| 936 |
num_node_comm_maps, |
| 937 |
rank, |
| 938 |
doing_type); |
| 939 |
|
| 940 |
// Build list of owned global edge ids |
| 941 |
long long * globalEdgeIds = new long long[numEdges]; |
| 942 |
bool * edgeIsOwned = new bool[numEdges]; |
| 943 |
int numOwnedEdges=0; |
| 944 |
for (int i=0; i<numEdges; i++) { |
| 945 |
edgeIsOwned[i] = edge_vector[i]->owned; |
| 946 |
globalEdgeIds[i] = edge_vector[i]->global_id; |
| 947 |
if (edgeIsOwned[i]){ |
| 948 |
numOwnedEdges++; |
| 949 |
} |
| 950 |
} |
| 951 |
int * ownedEdgeIds = new int[numOwnedEdges]; |
| 952 |
int nedge=0; |
| 953 |
for (int i=0; i<numEdges; i++) { |
| 954 |
if (edgeIsOwned[i]){ |
| 955 |
ownedEdgeIds[nedge]=(int)globalEdgeIds[i]; |
| 956 |
nedge++; |
| 957 |
} |
| 958 |
} |
| 959 |
|
| 960 |
// Build list of owned global face ids |
| 961 |
long long * globalFaceIds = new long long[numFaces]; |
| 962 |
bool * faceIsOwned = new bool[numFaces]; |
| 963 |
int numOwnedFaces=0; |
| 964 |
for (int i=0; i<numFaces; i++) { |
| 965 |
faceIsOwned[i] = face_vector[i]->owned; |
| 966 |
globalFaceIds[i] = face_vector[i]->global_id; |
| 967 |
if (faceIsOwned[i]){ |
| 968 |
numOwnedFaces++; |
| 969 |
} |
| 970 |
} |
| 971 |
int * ownedFaceIds = new int[numOwnedFaces]; |
| 972 |
int nface=0; |
| 973 |
for (int i=0; i<numFaces; i++) { |
| 974 |
if (faceIsOwned[i]){ |
| 975 |
ownedFaceIds[nface]=(int)globalFaceIds[i]; |
| 976 |
nface++; |
| 977 |
} |
| 978 |
} |
| 979 |
|
| 980 |
// Calculate number of global edges and faces |
| 981 |
int numEdgesGlobal; |
| 982 |
int numFacesGlobal; |
| 983 |
#ifdef HAVE_MPI |
| 984 |
Comm.SumAll(&numOwnedEdges,&numEdgesGlobal,1); |
| 985 |
Comm.SumAll(&numOwnedFaces,&numFacesGlobal,1); |
| 986 |
#else |
| 987 |
numEdgesGlobal = numEdges; |
| 988 |
numFacesGlobal = numFaces; |
| 989 |
#endif |
| 990 |
|
| 991 |
|
| 992 |
// Print mesh size information |
| 993 |
if (MyPID == 0) { |
| 994 |
std::cout << " Number of Elements: " << numElemsGlobal << " \n"; |
| 995 |
std::cout << " Number of Nodes: " << numNodesGlobal << " \n"; |
| 996 |
std::cout << " Number of Edges: " << numEdgesGlobal << " \n"; |
| 997 |
std::cout << " Number of Faces: " << numFacesGlobal << " \n\n"; |
| 998 |
} |
| 999 |
|
| 1000 |
|
| 1001 |
|
| 1002 |
// Container indicating whether a face is on the boundary (1-yes 0-no) |
| 1003 |
FieldContainer<int> edgeOnBoundary(numEdges); |
| 1004 |
FieldContainer<int> faceOnBoundary(numFaces); |
| 1005 |
|
| 1006 |
// Get boundary (side set) information |
| 1007 |
long long * sideSetIds = new long long [numSideSets]; |
| 1008 |
long long numSidesInSet; |
| 1009 |
long long numDFinSet; |
| 1010 |
im_ex_get_side_set_ids_l(id,sideSetIds); |
| 1011 |
for (int i=0; i<numSideSets; i++) { |
| 1012 |
im_ex_get_side_set_param_l(id,sideSetIds[i],&numSidesInSet,&numDFinSet); |
| 1013 |
if (numSidesInSet > 0){ |
| 1014 |
long long * sideSetElemList = new long long [numSidesInSet]; |
| 1015 |
long long * sideSetSideList = new long long [numSidesInSet]; |
| 1016 |
im_ex_get_side_set_l(id,sideSetIds[i],sideSetElemList,sideSetSideList); |
| 1017 |
for (int j=0; j<numSidesInSet; j++) { |
| 1018 |
int iface = sideSetSideList[j]-1; |
| 1019 |
faceOnBoundary(elemToFace(sideSetElemList[j]-1,iface))=1; |
| 1020 |
edgeOnBoundary(faceToEdge(elemToFace(sideSetElemList[j]-1,iface),0))=1; |
| 1021 |
edgeOnBoundary(faceToEdge(elemToFace(sideSetElemList[j]-1,iface),1))=1; |
| 1022 |
edgeOnBoundary(faceToEdge(elemToFace(sideSetElemList[j]-1,iface),2))=1; |
| 1023 |
edgeOnBoundary(faceToEdge(elemToFace(sideSetElemList[j]-1,iface),3))=1; |
| 1024 |
} |
| 1025 |
delete [] sideSetElemList; |
| 1026 |
delete [] sideSetSideList; |
| 1027 |
} |
| 1028 |
} |
| 1029 |
|
| 1030 |
delete [] sideSetIds; |
| 1031 |
|
| 1032 |
|
| 1033 |
// Container indicating whether a node is on the boundary (1-yes 0-no) |
| 1034 |
FieldContainer<int> nodeOnBoundary(numNodes); |
| 1035 |
int numEdgeOnBndy=0; |
| 1036 |
for (int i=0; i<numEdges; i++) { |
| 1037 |
if (edgeOnBoundary(i)){ |
| 1038 |
nodeOnBoundary(edgeToNode(i,0))=1; |
| 1039 |
nodeOnBoundary(edgeToNode(i,1))=1; |
| 1040 |
numEdgeOnBndy++; |
| 1041 |
} |
| 1042 |
} |
| 1043 |
|
| 1044 |
// Define global epetra maps |
| 1045 |
Epetra_Map globalMapG(-1,ownedNodes,ownedGIDs,0,Comm); |
| 1046 |
Epetra_Map globalMapC(-1,numOwnedEdges,ownedEdgeIds,0,Comm); |
| 1047 |
|
| 1048 |
if (jiggle) { |
| 1049 |
/***********************************************************************************/ |
| 1050 |
/* This block of code will create a randomly perturbed mesh by jiggling the node */ |
| 1051 |
/* coordinates away from their initial location. */ |
| 1052 |
/***********************************************************************************/ |
| 1053 |
|
| 1054 |
if(MyPID==0) {std::cout << "Jiggling the mesh" << std::endl << std::endl;} |
| 1055 |
|
| 1056 |
// Build an overlapping map. To match globalMapG, we need to convert to int. |
| 1057 |
int * globalNodeIdsInt = new int[numNodes]; |
| 1058 |
for (int i=0; i<numNodes; i++) |
| 1059 |
globalNodeIdsInt[i]=(int)globalNodeIds[i]; |
| 1060 |
Epetra_Map globalMapAllNodes(-1,numNodes,globalNodeIdsInt,0,Comm); |
| 1061 |
|
| 1062 |
// get random numbers between -1.0 and 1.0 wrt to 1-to-1 map |
| 1063 |
Epetra_MultiVector displacementTemp(globalMapG,3); |
| 1064 |
displacementTemp.Random(); |
| 1065 |
|
| 1066 |
// import that to overlapping map |
| 1067 |
Epetra_MultiVector displacement(globalMapAllNodes,3); |
| 1068 |
Epetra_Export MyImporter(globalMapAllNodes,globalMapG); |
| 1069 |
displacement.Import(displacementTemp,MyImporter,Insert); |
| 1070 |
|
| 1071 |
// Side length assuming an initially regular grid |
| 1072 |
double hx = nodeCoord(elemToNode(0,1),0)-nodeCoord(elemToNode(0,0),0); |
| 1073 |
double hy = nodeCoord(elemToNode(0,3),1)-nodeCoord(elemToNode(0,0),1); |
| 1074 |
double hz = nodeCoord(elemToNode(0,4),2)-nodeCoord(elemToNode(0,0),2); |
| 1075 |
|
| 1076 |
const double fac = 0.05; |
| 1077 |
|
| 1078 |
// Loop over nodes |
| 1079 |
for (int inode = 0; inode < numNodes; inode++){ |
| 1080 |
if (!nodeOnBoundary(inode)) { |
| 1081 |
double rx = displacement[0][inode]; |
| 1082 |
double ry = displacement[1][inode]; |
| 1083 |
double rz = displacement[2][inode]; |
| 1084 |
|
| 1085 |
nodeCoord(inode,0) = nodeCoord(inode,0) + fac * hx * rx; |
| 1086 |
nodeCoord(inode,1) = nodeCoord(inode,1) + fac * hy * ry; |
| 1087 |
nodeCoord(inode,2) = nodeCoord(inode,2) + fac * hz * rz; |
| 1088 |
nodeCoordx[inode] = nodeCoord(inode,0); |
| 1089 |
nodeCoordy[inode] = nodeCoord(inode,1); |
| 1090 |
nodeCoordz[inode] = nodeCoord(inode,2); |
| 1091 |
} |
| 1092 |
} |
| 1093 |
} |
| 1094 |
|
| 1095 |
#ifdef HAVE_XPETRA_EPETRA |
| 1096 |
// Statistics: Phase 1 |
| 1097 |
MLStatistics.Phase1(elemToNode,elemToEdge,edgeToNode,nodeCoord,sigmaVal); |
| 1098 |
#endif |
| 1099 |
|
| 1100 |
/**********************************************************************************/ |
| 1101 |
/********************************* GET CUBATURE ***********************************/ |
| 1102 |
/**********************************************************************************/ |
| 1103 |
|
| 1104 |
// Get numerical integration points and weights for cell |
| 1105 |
DefaultCubatureFactory<double> cubFactory; |
| 1106 |
int cubDegree = 2; |
| 1107 |
Teuchos::RCP<Cubature<double> > hexCub = cubFactory.create(cellType, cubDegree); |
| 1108 |
|
| 1109 |
int cubDim = hexCub->getDimension(); |
| 1110 |
int numCubPoints = hexCub->getNumPoints(); |
| 1111 |
|
| 1112 |
FieldContainer<double> cubPoints(numCubPoints, cubDim); |
| 1113 |
FieldContainer<double> cubWeights(numCubPoints); |
| 1114 |
|
| 1115 |
hexCub->getCubature(cubPoints, cubWeights); |
| 1116 |
|
| 1117 |
/**********************************************************************************/ |
| 1118 |
/* Get numerical integration points and weights for hexahedron face */ |
| 1119 |
/* (needed for rhs boundary term) */ |
| 1120 |
/**********************************************************************************/ |
| 1121 |
|
| 1122 |
// Define topology of the face parametrization domain as [-1,1]x[-1,1] |
| 1123 |
shards::CellTopology paramQuadFace(shards::getCellTopologyData<shards::Quadrilateral<4> >() ); |
| 1124 |
|
| 1125 |
// Define cubature |
| 1126 |
DefaultCubatureFactory<double> cubFactoryFace; |
| 1127 |
Teuchos::RCP<Cubature<double> > hexFaceCubature = cubFactoryFace.create(paramQuadFace, 3); |
| 1128 |
int cubFaceDim = hexFaceCubature -> getDimension(); |
| 1129 |
int numFacePoints = hexFaceCubature -> getNumPoints(); |
| 1130 |
|
| 1131 |
// Define storage for cubature points and weights on [-1,1]x[-1,1] |
| 1132 |
FieldContainer<double> paramFaceWeights(numFacePoints); |
| 1133 |
FieldContainer<double> paramFacePoints(numFacePoints,cubFaceDim); |
| 1134 |
|
| 1135 |
// Define storage for cubature points on workset faces |
| 1136 |
hexFaceCubature -> getCubature(paramFacePoints, paramFaceWeights); |
| 1137 |
|
| 1138 |
/**********************************************************************************/ |
| 1139 |
/* Get numerical integration points and weights for hexahedron edge */ |
| 1140 |
/* (needed for inhomogeneous boundary terms) */ |
| 1141 |
/**********************************************************************************/ |
| 1142 |
|
| 1143 |
// Define topology of the edge parametrization domain as [-1,1] |
| 1144 |
shards::CellTopology paramEdge(shards::getCellTopologyData<shards::Line<2> >() ); |
| 1145 |
|
| 1146 |
// Define cubature |
| 1147 |
DefaultCubatureFactory<double> cubFactoryEdge; |
| 1148 |
Teuchos::RCP<Cubature<double> > hexEdgeCubature = cubFactoryEdge.create(paramEdge, 3); |
| 1149 |
int cubEdgeDim = hexEdgeCubature -> getDimension(); |
| 1150 |
int numEdgePoints = hexEdgeCubature -> getNumPoints(); |
| 1151 |
|
| 1152 |
// Define storage for cubature points and weights on [-1,1] |
| 1153 |
FieldContainer<double> paramEdgeWeights(numEdgePoints); |
| 1154 |
FieldContainer<double> paramEdgePoints(numEdgePoints,cubEdgeDim); |
| 1155 |
|
| 1156 |
// Define storage for cubature points on workset faces |
| 1157 |
hexEdgeCubature -> getCubature(paramEdgePoints, paramEdgeWeights); |
| 1158 |
|
| 1159 |
if(MyPID==0) {std::cout << "Getting cubature " |
| 1160 |
<< Time.ElapsedTime() << " sec \n" ; Time.ResetStartTime();} |
| 1161 |
|
| 1162 |
|
| 1163 |
/**********************************************************************************/ |
| 1164 |
/*********************************** GET BASIS ************************************/ |
| 1165 |
/**********************************************************************************/ |
| 1166 |
|
| 1167 |
// Define basis |
| 1168 |
Basis_HCURL_HEX_I1_FEM<double, FieldContainer<double> > hexHCurlBasis; |
| 1169 |
Basis_HGRAD_HEX_C1_FEM<double, FieldContainer<double> > hexHGradBasis; |
| 1170 |
|
| 1171 |
int numFieldsC = hexHCurlBasis.getCardinality(); |
| 1172 |
int numFieldsG = hexHGradBasis.getCardinality(); |
| 1173 |
|
| 1174 |
// Evaluate basis at cubature points |
| 1175 |
FieldContainer<double> HGVals(numFieldsG, numCubPoints); |
| 1176 |
FieldContainer<double> HCVals(numFieldsC, numCubPoints, spaceDim); |
| 1177 |
FieldContainer<double> HCurls(numFieldsC, numCubPoints, spaceDim); |
| 1178 |
FieldContainer<double> worksetCVals(numFieldsC, numFacePoints, spaceDim); |
| 1179 |
|
| 1180 |
hexHCurlBasis.getValues(HCVals, cubPoints, OPERATOR_VALUE); |
| 1181 |
hexHCurlBasis.getValues(HCurls, cubPoints, OPERATOR_CURL); |
| 1182 |
hexHGradBasis.getValues(HGVals, cubPoints, OPERATOR_VALUE); |
| 1183 |
|
| 1184 |
if(MyPID==0) {std::cout << "Getting basis " |
| 1185 |
<< Time.ElapsedTime() << " sec \n" ; Time.ResetStartTime();} |
| 1186 |
|
| 1187 |
|
| 1188 |
/**********************************************************************************/ |
| 1189 |
/********************* BUILD MAPS FOR GLOBAL SOLUTION *****************************/ |
| 1190 |
/**********************************************************************************/ |
| 1191 |
|
| 1192 |
Epetra_FECrsMatrix StiffMatrixC(Copy, globalMapC, numFieldsC); |
| 1193 |
Epetra_FECrsMatrix MassMatrixC (Copy, globalMapC, numFieldsC); |
| 1194 |
Epetra_FECrsMatrix MassMatrixC1 (Copy, globalMapC, numFieldsC);// No sigma |
| 1195 |
Epetra_FECrsMatrix MassMatrixG (Copy, globalMapG, numFieldsG); |
| 1196 |
Epetra_FEVector rhsVector (globalMapC); |
| 1197 |
|
| 1198 |
if(MyPID==0) {std::cout << "Build global maps " |
| 1199 |
<< Time.ElapsedTime() << " sec \n"; Time.ResetStartTime();} |
| 1200 |
|
| 1201 |
|
| 1202 |
/**********************************************************************************/ |
| 1203 |
/************************** OUTPUT CONNECTIVITY (FOR PLOTTING) ********************/ |
| 1204 |
/**********************************************************************************/ |
| 1205 |
|
| 1206 |
|
| 1207 |
// Build the coordinate vectors for ML solver (including owned nodes only) |
| 1208 |
Epetra_Vector Nx(globalMapG), Ny(globalMapG),Nz(globalMapG); |
| 1209 |
for(int i=0,nlid=0;i<numNodes;i++) |
| 1210 |
if(nodeIsOwned[i]) { |
| 1211 |
Nx[nlid]=nodeCoordx[i]; |
| 1212 |
Ny[nlid]=nodeCoordy[i]; |
| 1213 |
Nz[nlid]=nodeCoordz[i]; |
| 1214 |
nlid++; |
| 1215 |
} |
| 1216 |
|
| 1217 |
|
| 1218 |
Epetra_Map globalMapElem(numElemsGlobal, numElems, 0, Comm); |
| 1219 |
|
| 1220 |
// Put coordinates in multivector for output |
| 1221 |
Epetra_MultiVector nCoord(globalMapG,3); |
| 1222 |
|
| 1223 |
int ownedNode = 0; |
| 1224 |
for (int inode=0; inode<numNodes; inode++) { |
| 1225 |
if (nodeIsOwned[inode]) { |
| 1226 |
nCoord[0][ownedNode]=nodeCoord(inode,0); |
| 1227 |
nCoord[1][ownedNode]=nodeCoord(inode,1); |
| 1228 |
nCoord[2][ownedNode]=nodeCoord(inode,2); |
| 1229 |
ownedNode++; |
| 1230 |
} |
| 1231 |
} |
| 1232 |
if (dump){ |
| 1233 |
EpetraExt::MultiVectorToMatrixMarketFile("coords.dat",nCoord,0,0,false); |
| 1234 |
|
| 1235 |
// Put element to node mapping in multivector for output |
| 1236 |
Epetra_MultiVector elem2node(globalMapElem, numNodesPerElem); |
| 1237 |
for (int ielem=0; ielem<numElems; ielem++) { |
| 1238 |
for (int inode=0; inode<numNodesPerElem; inode++) { |
| 1239 |
elem2node[inode][ielem]=globalNodeIds[elemToNode(ielem,inode)]; |
| 1240 |
} |
| 1241 |
} |
| 1242 |
EpetraExt::MultiVectorToMatrixMarketFile("elem2node.dat",elem2node,0,0,false); |
| 1243 |
|
| 1244 |
// Put element to edge mapping in multivector for output |
| 1245 |
Epetra_MultiVector elem2edge(globalMapElem, numEdgesPerElem); |
| 1246 |
for (int ielem=0; ielem<numElems; ielem++) { |
| 1247 |
for (int iedge=0; iedge<numEdgesPerElem; iedge++) { |
| 1248 |
elem2edge[iedge][ielem]=globalEdgeIds[elemToEdge(ielem,iedge)]; |
| 1249 |
} |
| 1250 |
} |
| 1251 |
EpetraExt::MultiVectorToMatrixMarketFile("elem2edge.dat",elem2edge,0,0,false); |
| 1252 |
|
| 1253 |
// Put edge to node mapping in multivector for output |
| 1254 |
Epetra_MultiVector edge2node(globalMapC, numNodesPerEdge); |
| 1255 |
int ownedEdge = 0; |
| 1256 |
for (int iedge=0; iedge<numEdges; iedge++) { |
| 1257 |
if (edgeIsOwned[iedge]) { |
| 1258 |
for (int inode=0; inode<numNodesPerEdge; inode++) { |
| 1259 |
edge2node[inode][ownedEdge]=globalNodeIds[edgeToNode(iedge,inode)]; |
| 1260 |
} |
| 1261 |
ownedEdge++; |
| 1262 |
} |
| 1263 |
} |
| 1264 |
EpetraExt::MultiVectorToMatrixMarketFile("edge2node.dat",edge2node,0,0,false); |
| 1265 |
|
| 1266 |
|
| 1267 |
if(MyPID==0) {Time.ResetStartTime();} |
| 1268 |
} |
| 1269 |
|
| 1270 |
|
| 1271 |
// Define multi-vector for cell edge sign (fill during cell loop) |
| 1272 |
Epetra_MultiVector edgeSign(globalMapElem, numEdgesPerElem); |
| 1273 |
|
| 1274 |
|
| 1275 |
/**********************************************************************************/ |
| 1276 |
/*************************BUILD INCIDENCE MATRIX***********************************/ |
| 1277 |
/**********************************************************************************/ |
| 1278 |
|
| 1279 |
// Edge to node incidence matrix |
| 1280 |
Epetra_FECrsMatrix DGrad(Copy, globalMapC, 2); |
| 1281 |
|
| 1282 |
// Estimate the global CFL based on minimum edge length and assumed dt=1" |
| 1283 |
|
| 1284 |
// Grab edge coordinates (for dumping to disk) |
| 1285 |
Epetra_Vector EDGE_X(globalMapC); |
| 1286 |
Epetra_Vector EDGE_Y(globalMapC); |
| 1287 |
Epetra_Vector EDGE_Z(globalMapC); |
| 1288 |
|
| 1289 |
double vals[2]; |
| 1290 |
vals[0]=-1.0; vals[1]=1.0; |
| 1291 |
for (int j=0, elid=0; j<numEdges; j++){ |
| 1292 |
if (edgeIsOwned[j]){ |
| 1293 |
int rowNum = globalEdgeIds[j]; |
| 1294 |
int colNum[2]; |
| 1295 |
colNum[0] = globalNodeIds[edgeToNode(j,0)]; |
| 1296 |
colNum[1] = globalNodeIds[edgeToNode(j,1)]; |
| 1297 |
DGrad.InsertGlobalValues(1, &rowNum, 2, colNum, vals); |
| 1298 |
EDGE_X[elid] = (nodeCoordx[edgeToNode(j,0)] + nodeCoordx[edgeToNode(j,1)])/2.0; |
| 1299 |
EDGE_Y[elid] = (nodeCoordy[edgeToNode(j,0)] + nodeCoordy[edgeToNode(j,1)])/2.0; |
| 1300 |
EDGE_Z[elid] = (nodeCoordz[edgeToNode(j,0)] + nodeCoordz[edgeToNode(j,1)])/2.0; |
| 1301 |
elid++; |
| 1302 |
} |
| 1303 |
} |
| 1304 |
|
| 1305 |
|
| 1306 |
DGrad.GlobalAssemble(globalMapG,globalMapC); |
| 1307 |
DGrad.FillComplete(MassMatrixG.RowMap(),MassMatrixC.RowMap()); |
| 1308 |
|
| 1309 |
if(MyPID==0) {std::cout << "Building incidence matrix " |
| 1310 |
<< Time.ElapsedTime() << " sec \n" ; Time.ResetStartTime();} |
| 1311 |
|
| 1312 |
// Local CFL Calculations |
| 1313 |
double DOUBLE_MAX = std::numeric_limits<double>::max(); |
| 1314 |
double l_max_sigma=0.0, l_max_mu = 0.0, l_max_cfl = 0.0, l_max_dx = 0.0, l_max_osm=0.0; |
| 1315 |
double l_min_sigma=DOUBLE_MAX, l_min_mu= DOUBLE_MAX, l_min_cfl = DOUBLE_MAX, l_min_dx = DOUBLE_MAX, l_min_osm=DOUBLE_MAX; |
| 1316 |
|
| 1317 |
for(long long b = 0, idx=0; b < numElemBlk; b++){ |
| 1318 |
for(long long el = 0; el < elements[b]; el++){ |
| 1319 |
l_max_sigma = std::max(l_max_sigma,sigmaVal(idx)); |
| 1320 |
l_min_sigma = std::min(l_min_sigma,sigmaVal(idx)); |
| 1321 |
l_max_mu = std::max(l_max_mu,muVal(idx)); |
| 1322 |
l_min_mu = std::min(l_min_mu,muVal(idx)); |
| 1323 |
l_max_osm = std::max(l_max_osm,1/(sigmaVal(idx)*muVal(idx))); |
| 1324 |
l_min_osm = std::min(l_min_osm,1/(sigmaVal(idx)*muVal(idx))); |
| 1325 |
|
| 1326 |
// We'll chose "dx" as the max/min edge length over the cell |
| 1327 |
double my_edge_min = DOUBLE_MAX, my_edge_max=0.0; |
| 1328 |
for(int j=0; j<numEdgesPerElem; j++) { |
| 1329 |
int edge = elemToEdge(idx,j); |
| 1330 |
double my_dx = distance(nodeCoord,edgeToNode(edge,0),edgeToNode(edge,1)); |
| 1331 |
my_edge_max = std::max(my_edge_max,my_dx); |
| 1332 |
my_edge_min = std::min(my_edge_min,my_dx); |
| 1333 |
} |
| 1334 |
|
| 1335 |
l_max_dx = std::max(l_max_dx,my_edge_max); |
| 1336 |
l_min_dx = std::min(l_min_dx,my_edge_min); |
| 1337 |
|
| 1338 |
// Note: The max/min's switch here because they're in the denominator |
| 1339 |
double my_max_cfl = 1.0 / (sigmaVal(idx) * muVal(idx) * l_min_dx * l_min_dx); |
| 1340 |
double my_min_cfl = 1.0 / (sigmaVal(idx) * muVal(idx) * l_max_dx * l_max_dx); |
| 1341 |
l_max_cfl = std::max(l_max_cfl,my_max_cfl); |
| 1342 |
l_min_cfl = std::min(l_min_cfl,my_min_cfl); |
| 1343 |
|
| 1344 |
idx++; |
| 1345 |
} |
| 1346 |
} |
| 1347 |
|
| 1348 |
// CFL Range Calculations (assuming a timestep dt=1) |
| 1349 |
double g_max_dx, g_min_dx, g_max_mu, g_min_mu, g_max_sigma, g_min_sigma, g_max_cfl, g_min_cfl, g_max_osm, g_min_osm; |
| 1350 |
Comm.MaxAll(&l_max_dx,&g_max_dx,1); Comm.MinAll(&l_min_dx,&g_min_dx,1); |
| 1351 |
Comm.MaxAll(&l_max_sigma,&g_max_sigma,1); Comm.MinAll(&l_min_sigma,&g_min_sigma,1); |
| 1352 |
Comm.MaxAll(&l_max_mu,&g_max_mu,1); Comm.MinAll(&l_min_mu,&g_min_mu,1); |
| 1353 |
Comm.MaxAll(&l_max_cfl,&g_max_cfl,1); Comm.MinAll(&l_min_cfl,&g_min_cfl,1); |
| 1354 |
Comm.MaxAll(&l_max_osm,&g_max_osm,1); Comm.MinAll(&l_min_osm,&g_min_osm,1); |
| 1355 |
|
| 1356 |
if(MyPID==0) { |
| 1357 |
std::cout<<"*** Parameter Ranges ***"<<std::endl; |
| 1358 |
std::cout<<"Edge dx Range : "<<g_min_dx << " to "<<g_max_dx<<std::endl; |
| 1359 |
std::cout<<"Sigma Range : "<<g_min_sigma << " to "<<g_max_sigma<<std::endl; |
| 1360 |
std::cout<<"Mu Range : "<<g_min_mu << " to "<<g_max_mu<<std::endl; |
| 1361 |
std::cout<<"1/(Sigma Mu) Range : "<<g_min_osm << " to "<<g_max_osm<<std::endl; |
| 1362 |
std::cout<<"Diffusive CFL Range: "<<g_min_cfl<< " to "<<g_max_cfl<<std::endl; |
| 1363 |
|
| 1364 |
} |
| 1365 |
|
| 1366 |
|
| 1367 |
/**********************************************************************************/ |
| 1368 |
/******************** INHOMOGENEOUS BOUNDARY CONDITIONS ***************************/ |
| 1369 |
/**********************************************************************************/ |
| 1370 |
|
| 1371 |
FieldContainer<double> bndyEdgeVal(numEdgeOnBndy); |
| 1372 |
FieldContainer<int> bndyEdgeToEdge(numEdges); |
| 1373 |
FieldContainer<bool> bndyEdgeDone(numEdges); |
| 1374 |
FieldContainer<double> refEdgePoints(numEdgePoints,spaceDim); |
| 1375 |
FieldContainer<double> bndyEdgePoints(1,numEdgePoints,spaceDim); |
| 1376 |
FieldContainer<double> bndyEdgeJacobians(1,numEdgePoints,spaceDim,spaceDim); |
| 1377 |
FieldContainer<double> edgeTan(1,numEdgePoints,spaceDim); |
| 1378 |
FieldContainer<double> uDotTangent(numEdgePoints); |
| 1379 |
FieldContainer<double> uEdge(numEdgePoints,spaceDim); |
| 1380 |
FieldContainer<double> nodes(1, numNodesPerElem, spaceDim); |
| 1381 |
|
| 1382 |
int ibedge=0; |
| 1383 |
// Evaluate tangent at edge quadrature points |
| 1384 |
for (int ielem=0; ielem<numElems; ielem++) { |
| 1385 |
for (int inode=0; inode<numNodesPerElem; inode++) { |
| 1386 |
nodes(0,inode,0) = nodeCoord(elemToNode(ielem,inode),0); |
| 1387 |
nodes(0,inode,1) = nodeCoord(elemToNode(ielem,inode),1); |
| 1388 |
nodes(0,inode,2) = nodeCoord(elemToNode(ielem,inode),2); |
| 1389 |
} |
| 1390 |
for (int iedge=0; iedge<numEdgesPerElem; iedge++){ |
| 1391 |
if(edgeOnBoundary(elemToEdge(ielem,iedge)) && !bndyEdgeDone(elemToEdge(ielem,iedge))){ |
| 1392 |
|
| 1393 |
// map evaluation points from reference edge to reference cell |
| 1394 |
IntrepidCTools::mapToReferenceSubcell(refEdgePoints, |
| 1395 |
paramEdgePoints, |
| 1396 |
1, iedge, cellType); |
| 1397 |
|
| 1398 |
// calculate Jacobian |
| 1399 |
IntrepidCTools::setJacobian(bndyEdgeJacobians, refEdgePoints, |
| 1400 |
nodes, cellType); |
| 1401 |
|
| 1402 |
// map evaluation points from reference cell to physical cell |
| 1403 |
IntrepidCTools::mapToPhysicalFrame(bndyEdgePoints, |
| 1404 |
refEdgePoints, |
| 1405 |
nodes, cellType); |
| 1406 |
|
| 1407 |
// Compute edge tangents |
| 1408 |
IntrepidCTools::getPhysicalEdgeTangents(edgeTan, |
| 1409 |
bndyEdgeJacobians, |
| 1410 |
iedge, cellType); |
| 1411 |
|
| 1412 |
// evaluate exact solution at edge center and dot with normal |
| 1413 |
for(int nPt = 0; nPt < numEdgePoints; nPt++){ |
| 1414 |
|
| 1415 |
double x = bndyEdgePoints(0, nPt, 0); |
| 1416 |
double y = bndyEdgePoints(0, nPt, 1); |
| 1417 |
double z = bndyEdgePoints(0, nPt, 2); |
| 1418 |
|
| 1419 |
evalu(uEdge(nPt,0), uEdge(nPt,1), uEdge(nPt,2), x, y, z); |
| 1420 |
uDotTangent(nPt)=(uEdge(nPt,0)*edgeTan(0,nPt,0)+uEdge(nPt,1)*edgeTan(0,nPt,1)+uEdge(nPt,2)*edgeTan(0,nPt,2)); |
| 1421 |
} |
| 1422 |
|
| 1423 |
// integrate |
| 1424 |
for(int nPt = 0; nPt < numEdgePoints; nPt++){ |
| 1425 |
bndyEdgeVal(ibedge)=bndyEdgeVal(ibedge)+uDotTangent(nPt)*paramEdgeWeights(nPt); |
| 1426 |
} |
| 1427 |
|
| 1428 |
bndyEdgeToEdge(elemToEdge(ielem,iedge))=ibedge; |
| 1429 |
ibedge++; |
| 1430 |
bndyEdgeDone(elemToEdge(ielem,iedge))=1; |
| 1431 |
} |
| 1432 |
} |
| 1433 |
} |
| 1434 |
|
| 1435 |
// Count of boundary edges |
| 1436 |
int numBCEdges=0; |
| 1437 |
for (int i=0; i<numEdges; i++){ |
| 1438 |
if (edgeOnBoundary(i) && edgeIsOwned[i]){ |
| 1439 |
numBCEdges++; |
| 1440 |
} |
| 1441 |
} |
| 1442 |
|
| 1443 |
// Vector for use in applying BCs |
| 1444 |
Epetra_Vector v(globalMapC,true); |
| 1445 |
v.PutScalar(0.0); |
| 1446 |
|
| 1447 |
// Set v to boundary values on Dirichlet edges |
| 1448 |
int * BCEdges = new int [numBCEdges]; |
| 1449 |
int indbc=0; |
| 1450 |
int iOwned=0; |
| 1451 |
for (int i=0; i<numEdges; i++){ |
| 1452 |
if (edgeIsOwned[i]){ |
| 1453 |
if (edgeOnBoundary(i)){ |
| 1454 |
BCEdges[indbc]=iOwned; |
| 1455 |
indbc++; |
| 1456 |
v[iOwned]=bndyEdgeVal(bndyEdgeToEdge(i)); |
| 1457 |
} |
| 1458 |
iOwned++; |
| 1459 |
} |
| 1460 |
} |
| 1461 |
|
| 1462 |
if(numProcs==1 && dump) { |
| 1463 |
FILE * f=fopen("boundary_edge_list.dat","w"); |
| 1464 |
for(int i=0; i<numBCEdges; i++) |
| 1465 |
fprintf(f,"%d ",BCEdges[i]); |
| 1466 |
fclose(f); |
| 1467 |
} |
| 1468 |
|
| 1469 |
|
| 1470 |
if(MyPID==0) {std::cout << "Boundary Condition Setup " |
| 1471 |
<< Time.ElapsedTime() << " sec \n\n"; Time.ResetStartTime();} |
| 1472 |
|
| 1473 |
/**********************************************************************************/ |
| 1474 |
/******************** DEFINE WORKSETS AND LOOP OVER THEM **************************/ |
| 1475 |
/**********************************************************************************/ |
| 1476 |
|
| 1477 |
// Define desired workset size and count how many worksets there are on this processor's mesh block |
| 1478 |
int desiredWorksetSize = numElems; // change to desired workset size! |
| 1479 |
//int desiredWorksetSize = 100; // change to desired workset size! |
| 1480 |
int numWorksets = numElems/desiredWorksetSize; |
| 1481 |
|
| 1482 |
// When numElems is not divisible by desiredWorksetSize, increase workset count by 1 |
| 1483 |
if(numWorksets*desiredWorksetSize < numElems) numWorksets += 1; |
| 1484 |
|
| 1485 |
if (MyPID == 0) { |
| 1486 |
std::cout << "Building discretization matrix and right hand side... \n\n"; |
| 1487 |
std::cout << "\tDesired workset size: " << desiredWorksetSize <<"\n"; |
| 1488 |
std::cout << "\tNumber of worksets (per processor): " << numWorksets <<"\n\n"; |
| 1489 |
Time.ResetStartTime(); |
| 1490 |
} |
| 1491 |
|
| 1492 |
for(int workset = 0; workset < numWorksets; workset++){ |
| 1493 |
|
| 1494 |
// Compute cell numbers where the workset starts and ends |
| 1495 |
int worksetSize = 0; |
| 1496 |
int worksetBegin = (workset + 0)*desiredWorksetSize; |
| 1497 |
int worksetEnd = (workset + 1)*desiredWorksetSize; |
| 1498 |
|
| 1499 |
// When numElems is not divisible by desiredWorksetSize, the last workset ends at numElems |
| 1500 |
worksetEnd = (worksetEnd <= numElems) ? worksetEnd : numElems; |
| 1501 |
|
| 1502 |
// Now we know the actual workset size and can allocate the array for the cell nodes |
| 1503 |
worksetSize = worksetEnd - worksetBegin; |
| 1504 |
FieldContainer<double> cellWorkset(worksetSize, numNodesPerElem, spaceDim); |
| 1505 |
FieldContainer<double> worksetEdgeSigns(worksetSize, numEdgesPerElem); |
| 1506 |
|
| 1507 |
// Copy coordinates into cell workset |
| 1508 |
int cellCounter = 0; |
| 1509 |
for(int cell = worksetBegin; cell < worksetEnd; cell++){ |
| 1510 |
|
| 1511 |
// Physical cell coordinates |
| 1512 |
for (int inode=0; inode<numNodesPerElem; inode++) { |
| 1513 |
cellWorkset(cellCounter,inode,0) = nodeCoord(elemToNode(cell,inode),0); |
| 1514 |
cellWorkset(cellCounter,inode,1) = nodeCoord(elemToNode(cell,inode),1); |
| 1515 |
cellWorkset(cellCounter,inode,2) = nodeCoord(elemToNode(cell,inode),2); |
| 1516 |
} |
| 1517 |
|
| 1518 |
// Edge signs |
| 1519 |
for (int iedge=0; iedge<numEdgesPerElem; iedge++) { |
| 1520 |
if (elemToNode(cell,refEdgeToNode(iedge,0))==edgeToNode(elemToEdge(cell,iedge),0) && |
| 1521 |
elemToNode(cell,refEdgeToNode(iedge,1))==edgeToNode(elemToEdge(cell,iedge),1)) |
| 1522 |
worksetEdgeSigns(cellCounter,iedge) = 1.0; |
| 1523 |
else |
| 1524 |
worksetEdgeSigns(cellCounter,iedge) = -1.0; |
| 1525 |
} |
| 1526 |
|
| 1527 |
// modify signs for edges that are owned by another processor |
| 1528 |
// (Note: this is particular to the numbering of edges used in Pamgen!!) |
| 1529 |
if (!faceIsOwned[elemToFace(cell,0)]) { |
| 1530 |
worksetEdgeSigns(cellCounter,0)=-1.0*worksetEdgeSigns(cellCounter,0); |
| 1531 |
worksetEdgeSigns(cellCounter,4)=-1.0*worksetEdgeSigns(cellCounter,4); |
| 1532 |
} |
| 1533 |
if (!faceIsOwned[elemToFace(cell,1)]) { |
| 1534 |
worksetEdgeSigns(cellCounter,1)=-1.0*worksetEdgeSigns(cellCounter,1); |
| 1535 |
worksetEdgeSigns(cellCounter,5)=-1.0*worksetEdgeSigns(cellCounter,5); |
| 1536 |
} |
| 1537 |
if (!faceIsOwned[elemToFace(cell,2)]) { |
| 1538 |
worksetEdgeSigns(cellCounter,2)=-1.0*worksetEdgeSigns(cellCounter,2); |
| 1539 |
worksetEdgeSigns(cellCounter,6)=-1.0*worksetEdgeSigns(cellCounter,6); |
| 1540 |
} |
| 1541 |
if (!faceIsOwned[elemToFace(cell,3)]) { |
| 1542 |
worksetEdgeSigns(cellCounter,3)=-1.0*worksetEdgeSigns(cellCounter,3); |
| 1543 |
worksetEdgeSigns(cellCounter,7)=-1.0*worksetEdgeSigns(cellCounter,7); |
| 1544 |
} |
| 1545 |
|
| 1546 |
if (dump){ |
| 1547 |
for (int iedge=0; iedge<numEdgesPerElem; iedge++) { |
| 1548 |
edgeSign[iedge][cell] = worksetEdgeSigns(cellCounter,iedge); |
| 1549 |
} |
| 1550 |
} |
| 1551 |
|
| 1552 |
cellCounter++; |
| 1553 |
|
| 1554 |
} // end loop over workset cells |
| 1555 |
|
| 1556 |
/**********************************************************************************/ |
| 1557 |
/* Allocate arrays */ |
| 1558 |
/**********************************************************************************/ |
| 1559 |
|
| 1560 |
// Containers for Jacobian |
| 1561 |
FieldContainer<double> worksetJacobian (worksetSize, numCubPoints, spaceDim, spaceDim); |
| 1562 |
FieldContainer<double> worksetJacobInv (worksetSize, numCubPoints, spaceDim, spaceDim); |
| 1563 |
FieldContainer<double> worksetJacobDet (worksetSize, numCubPoints); |
| 1564 |
|
| 1565 |
// Container for cubature points in physical space |
| 1566 |
FieldContainer<double> worksetCubPoints (worksetSize,numCubPoints, cubDim); |
| 1567 |
|
| 1568 |
// Containers for element HGRAD mass matrix |
| 1569 |
FieldContainer<double> massMatrixHGrad (worksetSize, numFieldsG, numFieldsG); |
| 1570 |
FieldContainer<double> weightedMeasure (worksetSize, numCubPoints); |
| 1571 |
FieldContainer<double> weightedMeasureMuInv (worksetSize, numCubPoints); |
| 1572 |
FieldContainer<double> HGValsTransformed (worksetSize, numFieldsG, numCubPoints); |
| 1573 |
FieldContainer<double> HGValsTransformedWeighted (worksetSize, numFieldsG, numCubPoints); |
| 1574 |
|
| 1575 |
// Containers for element HCURL mass matrix |
| 1576 |
FieldContainer<double> massMatrixHCurl (worksetSize, numFieldsC, numFieldsC); |
| 1577 |
FieldContainer<double> massMatrixHCurlNoSigma (worksetSize, numFieldsC, numFieldsC); |
| 1578 |
FieldContainer<double> weightedMeasureSigma (worksetSize, numCubPoints); |
| 1579 |
FieldContainer<double> HCValsTransformed (worksetSize, numFieldsC, numCubPoints, spaceDim); |
| 1580 |
FieldContainer<double> HCValsTransformedWeighted (worksetSize, numFieldsC, numCubPoints, spaceDim); |
| 1581 |
FieldContainer<double> HCValsTransformedWeightedNoSigma (worksetSize, numFieldsC, numCubPoints, spaceDim); |
| 1582 |
|
| 1583 |
// Containers for element HCURL stiffness matrix |
| 1584 |
FieldContainer<double> stiffMatrixHCurl (worksetSize, numFieldsC, numFieldsC); |
| 1585 |
FieldContainer<double> weightedMeasureMu (worksetSize, numCubPoints); |
| 1586 |
FieldContainer<double> HCurlsTransformed (worksetSize, numFieldsC, numCubPoints, spaceDim); |
| 1587 |
FieldContainer<double> HCurlsTransformedWeighted (worksetSize, numFieldsC, numCubPoints, spaceDim); |
| 1588 |
|
| 1589 |
// Containers for right hand side vectors |
| 1590 |
FieldContainer<double> rhsDatag (worksetSize, numCubPoints, cubDim); |
| 1591 |
FieldContainer<double> rhsDatah (worksetSize, numCubPoints, cubDim); |
| 1592 |
FieldContainer<double> gC (worksetSize, numFieldsC); |
| 1593 |
FieldContainer<double> hC (worksetSize, numFieldsC); |
| 1594 |
|
| 1595 |
// Containers for right hand side boundary term |
| 1596 |
FieldContainer<double> hCBoundary (1, numFieldsC); |
| 1597 |
FieldContainer<double> refFacePoints (numFacePoints,spaceDim); |
| 1598 |
FieldContainer<double> cellNodes (1, numNodesPerElem, spaceDim); |
| 1599 |
FieldContainer<double> worksetFacePoints (1, numFacePoints, spaceDim); |
| 1600 |
FieldContainer<double> faceJacobians (1, numFacePoints, spaceDim, spaceDim); |
| 1601 |
FieldContainer<double> faceJacobInv (1, numFacePoints, spaceDim, spaceDim); |
| 1602 |
FieldContainer<double> faceNormal (1, numFacePoints, spaceDim); |
| 1603 |
FieldContainer<double> bcFaceCVals (numFieldsC, numFacePoints, spaceDim); |
| 1604 |
FieldContainer<double> faceVFieldVals (1, numFacePoints, spaceDim); |
| 1605 |
FieldContainer<double> bcCValsTransformed (1, numFieldsC, numFacePoints, spaceDim); |
| 1606 |
FieldContainer<double> bcFieldDotNormal (1, numFieldsC, numFacePoints); |
| 1607 |
FieldContainer<double> bcEdgeSigns (1, numFieldsC); |
| 1608 |
|
| 1609 |
|
| 1610 |
/**********************************************************************************/ |
| 1611 |
/* Calculate Jacobians */ |
| 1612 |
/**********************************************************************************/ |
| 1613 |
|
| 1614 |
IntrepidCTools::setJacobian (worksetJacobian, cubPoints, cellWorkset, cellType); |
| 1615 |
IntrepidCTools::setJacobianInv(worksetJacobInv, worksetJacobian ); |
| 1616 |
IntrepidCTools::setJacobianDet(worksetJacobDet, worksetJacobian ); |
| 1617 |
|
| 1618 |
if(MyPID==0) {std::cout << "Calculate Jacobians " |
| 1619 |
<< Time.ElapsedTime() << " sec \n"; Time.ResetStartTime();} |
| 1620 |
|
| 1621 |
|
| 1622 |
/**********************************************************************************/ |
| 1623 |
/* Compute HGRAD Mass Matrix */ |
| 1624 |
/**********************************************************************************/ |
| 1625 |
|
| 1626 |
// transform to physical coordinates |
| 1627 |
IntrepidFSTools::HGRADtransformVALUE<double>(HGValsTransformed, HGVals); |
| 1628 |
|
| 1629 |
// compute weighted measure |
| 1630 |
IntrepidFSTools::computeCellMeasure<double>(weightedMeasure, worksetJacobDet, cubWeights); |
| 1631 |
|
| 1632 |
// combine mu value with weighted measure |
| 1633 |
cellCounter = 0; |
| 1634 |
for(int cell = worksetBegin; cell < worksetEnd; cell++){ |
| 1635 |
for (int nPt = 0; nPt < numCubPoints; nPt++){ |
| 1636 |
weightedMeasureMuInv(cellCounter,nPt) = weightedMeasure(cellCounter,nPt) / muVal(cell); |
| 1637 |
} |
| 1638 |
cellCounter++; |
| 1639 |
} |
| 1640 |
|
| 1641 |
// multiply values with weighted measure |
| 1642 |
IntrepidFSTools::multiplyMeasure<double>(HGValsTransformedWeighted, |
| 1643 |
weightedMeasureMuInv, HGValsTransformed); |
| 1644 |
|
| 1645 |
// integrate to compute element mass matrix |
| 1646 |
IntrepidFSTools::integrate<double>(massMatrixHGrad, |
| 1647 |
HGValsTransformed, HGValsTransformedWeighted, COMP_BLAS); |
| 1648 |
|
| 1649 |
if(MyPID==0) {std::cout << "Compute HGRAD Mass Matrix " |
| 1650 |
<< Time.ElapsedTime() << " sec \n"; Time.ResetStartTime();} |
| 1651 |
|
| 1652 |
#ifdef HAVE_XPETRA_EPETRA |
| 1653 |
// Statistics: Phase 2a |
| 1654 |
MLStatistics.Phase2a(worksetJacobDet,cubWeights); |
| 1655 |
#endif |
| 1656 |
|
| 1657 |
/**********************************************************************************/ |
| 1658 |
/* Compute HCURL Mass Matrix */ |
| 1659 |
/**********************************************************************************/ |
| 1660 |
|
| 1661 |
// transform to physical coordinates |
| 1662 |
IntrepidFSTools::HCURLtransformVALUE<double>(HCValsTransformed, worksetJacobInv, |
| 1663 |
HCVals); |
| 1664 |
|
| 1665 |
// combine sigma value with weighted measure |
| 1666 |
cellCounter = 0; |
| 1667 |
for(int cell = worksetBegin; cell < worksetEnd; cell++){ |
| 1668 |
for (int nPt = 0; nPt < numCubPoints; nPt++){ |
| 1669 |
weightedMeasureSigma(cellCounter,nPt) = weightedMeasure(cellCounter,nPt) * sigmaVal(cell); |
| 1670 |
} |
| 1671 |
cellCounter++; |
| 1672 |
} |
| 1673 |
|
| 1674 |
// multiply by weighted measure |
| 1675 |
IntrepidFSTools::multiplyMeasure<double>(HCValsTransformedWeighted, |
| 1676 |
weightedMeasureSigma, HCValsTransformed); |
| 1677 |
|
| 1678 |
// integrate to compute element mass matrix |
| 1679 |
IntrepidFSTools::integrate<double>(massMatrixHCurl, |
| 1680 |
HCValsTransformed, HCValsTransformedWeighted, |
| 1681 |
COMP_BLAS); |
| 1682 |
|
| 1683 |
// apply edge signs |
| 1684 |
IntrepidFSTools::applyLeftFieldSigns<double> (massMatrixHCurl, worksetEdgeSigns); |
| 1685 |
IntrepidFSTools::applyRightFieldSigns<double>(massMatrixHCurl, worksetEdgeSigns); |
| 1686 |
|
| 1687 |
|
| 1688 |
// Now for the no-sigma version |
| 1689 |
IntrepidFSTools::multiplyMeasure<double>(HCValsTransformedWeightedNoSigma, |
| 1690 |
weightedMeasure, HCValsTransformed); |
| 1691 |
|
| 1692 |
// integrate to compute element mass matrix |
| 1693 |
IntrepidFSTools::integrate<double>(massMatrixHCurlNoSigma, |
| 1694 |
HCValsTransformed, HCValsTransformedWeightedNoSigma, |
| 1695 |
COMP_BLAS); |
| 1696 |
|
| 1697 |
if(MyPID==0) {std::cout << "Compute HCURL Mass Matrix " |
| 1698 |
<< Time.ElapsedTime() << " sec \n"; Time.ResetStartTime();} |
| 1699 |
|
| 1700 |
|
| 1701 |
/**********************************************************************************/ |
| 1702 |
/* Compute HCURL Stiffness Matrix */ |
| 1703 |
/**********************************************************************************/ |
| 1704 |
|
| 1705 |
// transform to physical coordinates |
| 1706 |
IntrepidFSTools::HCURLtransformCURL<double>(HCurlsTransformed, worksetJacobian, worksetJacobDet, |
| 1707 |
HCurls); |
| 1708 |
|
| 1709 |
// combine mu value with weighted measure |
| 1710 |
cellCounter = 0; |
| 1711 |
for(int cell = worksetBegin; cell < worksetEnd; cell++){ |
| 1712 |
for (int nPt = 0; nPt < numCubPoints; nPt++){ |
| 1713 |
weightedMeasureMu(cellCounter,nPt) = weightedMeasure(cellCounter,nPt) * muVal(cell); |
| 1714 |
} |
| 1715 |
cellCounter++; |
| 1716 |
} |
| 1717 |
|
| 1718 |
// multiply by weighted measure |
| 1719 |
IntrepidFSTools::multiplyMeasure<double>(HCurlsTransformedWeighted, |
| 1720 |
weightedMeasureMuInv, HCurlsTransformed); |
| 1721 |
|
| 1722 |
// integrate to compute element stiffness matrix |
| 1723 |
IntrepidFSTools::integrate<double>(stiffMatrixHCurl, |
| 1724 |
HCurlsTransformed, HCurlsTransformedWeighted, |
| 1725 |
COMP_BLAS); |
| 1726 |
|
| 1727 |
// apply edge signs |
| 1728 |
IntrepidFSTools::applyLeftFieldSigns<double> (stiffMatrixHCurl, worksetEdgeSigns); |
| 1729 |
IntrepidFSTools::applyRightFieldSigns<double>(stiffMatrixHCurl, worksetEdgeSigns); |
| 1730 |
|
| 1731 |
if(MyPID==0) {std::cout << "Compute HCURL Stiffness Matrix " |
| 1732 |
<< Time.ElapsedTime() << " sec \n"; Time.ResetStartTime();} |
| 1733 |
|
| 1734 |
|
| 1735 |
/**********************************************************************************/ |
| 1736 |
/* Build Right Hand Side */ |
| 1737 |
/**********************************************************************************/ |
| 1738 |
|
| 1739 |
// transform integration points to physical points |
| 1740 |
IntrepidCTools::mapToPhysicalFrame(worksetCubPoints, cubPoints, cellWorkset, cellType); |
| 1741 |
|
| 1742 |
// evaluate right hand side functions at physical points |
| 1743 |
for(int cell = worksetBegin; cell < worksetEnd; cell++){ |
| 1744 |
|
| 1745 |
// Compute cell ordinal relative to the current workset |
| 1746 |
int worksetCellOrdinal = cell - worksetBegin; |
| 1747 |
|
| 1748 |
for (int nPt = 0; nPt < numCubPoints; nPt++){ |
| 1749 |
double x = worksetCubPoints(worksetCellOrdinal,nPt,0); |
| 1750 |
double y = worksetCubPoints(worksetCellOrdinal,nPt,1); |
| 1751 |
double z = worksetCubPoints(worksetCellOrdinal,nPt,2); |
| 1752 |
double du1, du2, du3; |
| 1753 |
|
| 1754 |
evalCurlCurlu(du1, du2, du3, x, y, z, muVal(cell)); |
| 1755 |
rhsDatag(worksetCellOrdinal,nPt,0) = du1; |
| 1756 |
rhsDatag(worksetCellOrdinal,nPt,1) = du2; |
| 1757 |
rhsDatag(worksetCellOrdinal,nPt,2) = du3; |
| 1758 |
|
| 1759 |
|
| 1760 |
double u1, u2, u3; |
| 1761 |
evalu(u1, u2, u3, x, y, z); |
| 1762 |
rhsDatah(worksetCellOrdinal,nPt,0) = u1; |
| 1763 |
rhsDatah(worksetCellOrdinal,nPt,1) = u2; |
| 1764 |
rhsDatah(worksetCellOrdinal,nPt,2) = u3; |
| 1765 |
|
| 1766 |
} |
| 1767 |
} |
| 1768 |
|
| 1769 |
// integrate (g,curl w) term |
| 1770 |
// IntrepidFSTools::integrate<double>(gC, rhsDatag, HCurlsTransformedWeighted, |
| 1771 |
// COMP_BLAS); |
| 1772 |
|
| 1773 |
// integrate (h,w) term |
| 1774 |
IntrepidFSTools::integrate<double>(gC, rhsDatag, HCValsTransformedWeighted, COMP_BLAS); |
| 1775 |
|
| 1776 |
IntrepidFSTools::integrate<double>(hC, rhsDatah, HCValsTransformedWeighted, COMP_BLAS); |
| 1777 |
|
| 1778 |
|
| 1779 |
// apply signs |
| 1780 |
IntrepidFSTools::applyFieldSigns<double>(gC, worksetEdgeSigns); |
| 1781 |
IntrepidFSTools::applyFieldSigns<double>(hC, worksetEdgeSigns); |
| 1782 |
|
| 1783 |
|
| 1784 |
// evaluate RHS boundary term |
| 1785 |
for(int cell = worksetBegin; cell < worksetEnd; cell++){ |
| 1786 |
|
| 1787 |
// Compute cell ordinal relative to the current workset |
| 1788 |
int worksetCellOrdinal = cell - worksetBegin; |
| 1789 |
|
| 1790 |
// evaluate boundary term |
| 1791 |
for (int iface = 0; iface < numFacesPerElem; iface++){ |
| 1792 |
if (faceOnBoundary(elemToFace(cell,iface))){ |
| 1793 |
|
| 1794 |
// cell nodal coordinates |
| 1795 |
for (int inode =0; inode < numNodesPerElem; inode++){ |
| 1796 |
cellNodes(0,inode,0) = cellWorkset(worksetCellOrdinal,inode,0); |
| 1797 |
cellNodes(0,inode,1) = cellWorkset(worksetCellOrdinal,inode,1); |
| 1798 |
cellNodes(0,inode,2) = cellWorkset(worksetCellOrdinal,inode,2); |
| 1799 |
} |
| 1800 |
|
| 1801 |
// cell edge signs |
| 1802 |
for (int iedge =0; iedge < numEdgesPerElem; iedge++){ |
| 1803 |
bcEdgeSigns(0,iedge) = worksetEdgeSigns(worksetCellOrdinal,iedge); |
| 1804 |
} |
| 1805 |
|
| 1806 |
// map Gauss points on quad to reference face: paramFacePoints -> refFacePoints |
| 1807 |
IntrepidCTools::mapToReferenceSubcell(refFacePoints, |
| 1808 |
paramFacePoints, |
| 1809 |
2, iface, cellType); |
| 1810 |
|
| 1811 |
// get basis values at points on reference cell |
| 1812 |
hexHCurlBasis.getValues(bcFaceCVals, refFacePoints, OPERATOR_VALUE); |
| 1813 |
|
| 1814 |
// compute Jacobians at Gauss pts. on reference face for all parent cells |
| 1815 |
IntrepidCTools::setJacobian(faceJacobians, |
| 1816 |
refFacePoints, |
| 1817 |
cellNodes, cellType); |
| 1818 |
IntrepidCTools::setJacobianInv(faceJacobInv, faceJacobians ); |
| 1819 |
|
| 1820 |
// transform to physical coordinates |
| 1821 |
IntrepidFSTools::HCURLtransformVALUE<double>(bcCValsTransformed, faceJacobInv, |
| 1822 |
bcFaceCVals); |
| 1823 |
|
| 1824 |
// map Gauss points on quad from ref. face to face workset: refFacePoints -> worksetFacePoints |
| 1825 |
IntrepidCTools::mapToPhysicalFrame(worksetFacePoints, |
| 1826 |
refFacePoints, |
| 1827 |
cellNodes, cellType); |
| 1828 |
|
| 1829 |
// Compute face normals |
| 1830 |
IntrepidCTools::getPhysicalFaceNormals(faceNormal, |
| 1831 |
faceJacobians, |
| 1832 |
iface, cellType); |
| 1833 |
|
| 1834 |
// compute the dot product and multiply by Gauss weights |
| 1835 |
for (int nF = 0; nF < numFieldsC; nF++){ |
| 1836 |
for(int nPt = 0; nPt < numFacePoints; nPt++){ |
| 1837 |
bcFieldDotNormal(0,nF,nPt)=0.0; |
| 1838 |
for (int dim = 0; dim < spaceDim; dim++){ |
| 1839 |
bcFieldDotNormal(0,nF,nPt) += bcCValsTransformed(0,nF,nPt,dim) |
| 1840 |
* faceNormal(0,nPt,dim) * paramFaceWeights(nPt); |
| 1841 |
} //dim |
| 1842 |
} //nPt |
| 1843 |
} //nF |
| 1844 |
|
| 1845 |
// integrate |
| 1846 |
// IntrepidFSTools::integrate<double>(hCBoundary, divuFace, bcFieldDotNormal, |
| 1847 |
// COMP_CPP); |
| 1848 |
|
| 1849 |
// apply signs |
| 1850 |
// IntrepidFSTools::applyFieldSigns<double>(hCBoundary, bcEdgeSigns); |
| 1851 |
|
| 1852 |
// add into hC term |
| 1853 |
// for (int nF = 0; nF < numFieldsC; nF++){ |
| 1854 |
// hC(worksetCellOrdinal,nF) = hC(worksetCellOrdinal,nF) - hCBoundary(0,nF); |
| 1855 |
// } |
| 1856 |
|
| 1857 |
} // if faceOnBoundary |
| 1858 |
|
| 1859 |
} // numFaces |
| 1860 |
|
| 1861 |
}// *** workset cell loop ** |
| 1862 |
|
| 1863 |
|
| 1864 |
if(MyPID==0) {std::cout << "Compute right-hand side " |
| 1865 |
<< Time.ElapsedTime() << " sec \n"; Time.ResetStartTime();} |
| 1866 |
|
| 1867 |
|
| 1868 |
/**********************************************************************************/ |
| 1869 |
/* Assemble into Global Matrix */ |
| 1870 |
/**********************************************************************************/ |
| 1871 |
|
| 1872 |
// Loop over workset cells |
| 1873 |
for(int cell = worksetBegin; cell < worksetEnd; cell++){ |
| 1874 |
|
| 1875 |
// Compute cell ordinal relative to the current workset |
| 1876 |
int worksetCellOrdinal = cell - worksetBegin; |
| 1877 |
|
| 1878 |
|
| 1879 |
/*** Assemble H(grad) mass matrix ***/ |
| 1880 |
|
| 1881 |
// loop over nodes for matrix row |
| 1882 |
for (int cellNodeRow = 0; cellNodeRow < numFieldsG; cellNodeRow++){ |
| 1883 |
|
| 1884 |
int localNodeRow = elemToNode(cell, cellNodeRow); |
| 1885 |
int globalNodeRow = globalNodeIds[localNodeRow]; |
| 1886 |
|
| 1887 |
// loop over nodes for matrix column |
| 1888 |
for (int cellNodeCol = 0; cellNodeCol < numFieldsG; cellNodeCol++){ |
| 1889 |
|
| 1890 |
int localNodeCol = elemToNode(cell, cellNodeCol); |
| 1891 |
int globalNodeCol = globalNodeIds[localNodeCol]; |
| 1892 |
double massGContribution = massMatrixHGrad(worksetCellOrdinal, cellNodeRow, cellNodeCol); |
| 1893 |
|
| 1894 |
MassMatrixG.InsertGlobalValues(1, &globalNodeRow, 1, &globalNodeCol, &massGContribution); |
| 1895 |
|
| 1896 |
}// *** cell node col loop *** |
| 1897 |
}// *** cell node row loop *** |
| 1898 |
|
| 1899 |
|
| 1900 |
/*** Assemble H(curl) mass matrix, stiffness matrix and right-hand side ***/ |
| 1901 |
|
| 1902 |
// loop over edges for matrix row |
| 1903 |
for (int cellEdgeRow = 0; cellEdgeRow < numFieldsC; cellEdgeRow++){ |
| 1904 |
|
| 1905 |
int localEdgeRow = elemToEdge(cell, cellEdgeRow); |
| 1906 |
int globalEdgeRow = globalEdgeIds[localEdgeRow]; |
| 1907 |
double rhsContribution = gC(worksetCellOrdinal, cellEdgeRow) + hC(worksetCellOrdinal, cellEdgeRow); |
| 1908 |
|
| 1909 |
rhsVector.SumIntoGlobalValues(1, &globalEdgeRow, &rhsContribution); |
| 1910 |
|
| 1911 |
// loop over edges for matrix column |
| 1912 |
for (int cellEdgeCol = 0; cellEdgeCol < numFieldsC; cellEdgeCol++){ |
| 1913 |
|
| 1914 |
int localEdgeCol = elemToEdge(cell, cellEdgeCol); |
| 1915 |
int globalEdgeCol = globalEdgeIds[localEdgeCol]; |
| 1916 |
|
| 1917 |
double massCContribution = massMatrixHCurl (worksetCellOrdinal, cellEdgeRow, cellEdgeCol); |
| 1918 |
double stiffCContribution = stiffMatrixHCurl(worksetCellOrdinal, cellEdgeRow, cellEdgeCol); |
| 1919 |
|
| 1920 |
double massCContribution1 = massMatrixHCurlNoSigma (worksetCellOrdinal, cellEdgeRow, cellEdgeCol); |
| 1921 |
|
| 1922 |
MassMatrixC.InsertGlobalValues (1, &globalEdgeRow, 1, &globalEdgeCol, &massCContribution); |
| 1923 |
MassMatrixC1.InsertGlobalValues (1, &globalEdgeRow, 1, &globalEdgeCol, &massCContribution1); |
| 1924 |
|
| 1925 |
StiffMatrixC.InsertGlobalValues(1, &globalEdgeRow, 1, &globalEdgeCol, &stiffCContribution); |
| 1926 |
|
| 1927 |
|
| 1928 |
}// *** cell edge col loop *** |
| 1929 |
}// *** cell edge row loop *** |
| 1930 |
|
| 1931 |
}// *** workset cell loop ** |
| 1932 |
}// *** workset loop *** |
| 1933 |
|
| 1934 |
if(MyPID==0) {std::cout << "Assemble Matrices " |
| 1935 |
<< Time.ElapsedTime() << " sec \n"; Time.ResetStartTime();} |
| 1936 |
|
| 1937 |
|
| 1938 |
/**********************************************************************************/ |
| 1939 |
/********************* ASSEMBLE OVER MULTIPLE PROCESSORS **************************/ |
| 1940 |
/**********************************************************************************/ |
| 1941 |
|
| 1942 |
// Assemble over multiple processors, if necessary |
| 1943 |
MassMatrixG.GlobalAssemble(); MassMatrixG.FillComplete(); |
| 1944 |
StiffMatrixC.GlobalAssemble(); StiffMatrixC.FillComplete(); |
| 1945 |
MassMatrixC.GlobalAssemble(); MassMatrixC.FillComplete(); |
| 1946 |
MassMatrixC1.GlobalAssemble(); MassMatrixC1.FillComplete(); |
| 1947 |
rhsVector.GlobalAssemble(); |
| 1948 |
|
| 1949 |
#ifdef HAVE_XPETRA_EPETRA |
| 1950 |
MLStatistics.Phase2b(Teuchos::rcp(&MassMatrixG.Graph(),false),Teuchos::rcp(&nCoord,false)); |
| 1951 |
#endif |
| 1952 |
|
| 1953 |
if(MyPID==0) {std::cout << "Global assembly " |
| 1954 |
<< Time.ElapsedTime() << " sec \n"; Time.ResetStartTime();} |
| 1955 |
|
| 1956 |
if (dump) { |
| 1957 |
// Node Coordinates |
| 1958 |
EpetraExt::VectorToMatrixMarketFile("coordx.dat",Nx,0,0,false); |
| 1959 |
EpetraExt::VectorToMatrixMarketFile("coordy.dat",Ny,0,0,false); |
| 1960 |
EpetraExt::VectorToMatrixMarketFile("coordz.dat",Nz,0,0,false); |
| 1961 |
|
| 1962 |
// Edge Coordinates |
| 1963 |
EpetraExt::VectorToMatrixMarketFile("ecoordx.dat",EDGE_X); |
| 1964 |
EpetraExt::VectorToMatrixMarketFile("ecoordy.dat",EDGE_Y); |
| 1965 |
EpetraExt::VectorToMatrixMarketFile("ecoordz.dat",EDGE_Z); |
| 1966 |
|
| 1967 |
// Boundary Application |
| 1968 |
EpetraExt::VectorToMatrixMarketFile("boundary_v.dat",v); |
| 1969 |
|
| 1970 |
// Edge signs |
| 1971 |
EpetraExt::MultiVectorToMatrixMarketFile("edge_signs.dat",edgeSign,0,0,false); |
| 1972 |
|
| 1973 |
EpetraExt::RowMatrixToMatrixMarketFile("mag_k1_matrix.mat",StiffMatrixC); |
| 1974 |
EpetraExt::RowMatrixToMatrixMarketFile("mag_ms_matrix.mat",MassMatrixC); |
| 1975 |
EpetraExt::RowMatrixToMatrixMarketFile("mag_m1_matrix.mat",MassMatrixC1); |
| 1976 |
EpetraExt::RowMatrixToMatrixMarketFile("mag_t_matrix.mat",DGrad); |
| 1977 |
} |
| 1978 |
|
| 1979 |
|
| 1980 |
/**********************************************************************************/ |
| 1981 |
/*********************** ADJUST MATRICES AND RHS FOR BCs **************************/ |
| 1982 |
/**********************************************************************************/ |
| 1983 |
|
| 1984 |
// Build the inverse diagonal for MassMatrixG |
| 1985 |
Epetra_Vector DiagG(MassMatrixG.RowMap()); |
| 1986 |
DiagG.PutScalar(1.0); |
| 1987 |
MassMatrixG.Multiply(false,DiagG,DiagG); |
| 1988 |
for(int i=0;i<DiagG.MyLength();i++) { |
| 1989 |
DiagG[i]=1.0/DiagG[i]; |
| 1990 |
} |
| 1991 |
Epetra_CrsMatrix MassMatrixGinv(Copy,MassMatrixG.RowMap(),MassMatrixG.RowMap(),1); |
| 1992 |
for(int i=0;i<DiagG.MyLength();i++) { |
| 1993 |
int CID=MassMatrixG.GCID(i); |
| 1994 |
MassMatrixGinv.InsertGlobalValues(MassMatrixG.GRID(i),1,&(DiagG[i]),&CID); |
| 1995 |
} |
| 1996 |
MassMatrixGinv.FillComplete(); |
| 1997 |
|
| 1998 |
// Zero out entries that correspond to boundary nodes |
| 1999 |
for(int i=0;i<numNodes;i++) { |
| 2000 |
if (nodeOnBoundary(i)){ |
| 2001 |
double val=0.0; |
| 2002 |
int index = globalNodeIds[i]; |
| 2003 |
MassMatrixGinv.ReplaceGlobalValues(index,1,&val,&index); |
| 2004 |
} |
| 2005 |
} |
| 2006 |
|
| 2007 |
// Get the full matrix operator Kc += Mc |
| 2008 |
int rv=EpetraExt::MatrixMatrix::Add(MassMatrixC,false,scaling,StiffMatrixC,1.0); |
| 2009 |
if(rv!=0) {printf("EpetraExt::MatrixMatrix:Add FAILED\n"); exit(1);} |
| 2010 |
|
| 2011 |
|
| 2012 |
// Apply it to v |
| 2013 |
Epetra_MultiVector rhsDir(globalMapC,true); |
| 2014 |
StiffMatrixC.Apply(v,rhsDir); |
| 2015 |
|
| 2016 |
// Update right-hand side |
| 2017 |
rhsVector.Update(-1.0,rhsDir,1.0); |
| 2018 |
|
| 2019 |
// Adjust rhs due to Dirichlet boundary conditions |
| 2020 |
indbc=0; |
| 2021 |
int indOwned=0; |
| 2022 |
for (int i=0; i<numEdges; i++){ |
| 2023 |
if (edgeIsOwned[i]){ |
| 2024 |
if (edgeOnBoundary(i)){ |
| 2025 |
indbc++; |
| 2026 |
rhsVector[0][indOwned]=bndyEdgeVal(bndyEdgeToEdge(i)); |
| 2027 |
rhsDir[0][indOwned]=0.0; |
| 2028 |
} |
| 2029 |
indOwned++; |
| 2030 |
} |
| 2031 |
} |
| 2032 |
|
| 2033 |
if (dump) { |
| 2034 |
EpetraExt::RowMatrixToMatrixMarketFile("edge_matrix_nobcs.mat",StiffMatrixC); |
| 2035 |
} |
| 2036 |
|
| 2037 |
// Zero out rows and columns of stiffness matrix corresponding to Dirichlet edges |
| 2038 |
// and add one to diagonal. |
| 2039 |
ML_Epetra::Apply_OAZToMatrix(BCEdges, numBCEdges, StiffMatrixC); |
| 2040 |
|
| 2041 |
delete [] BCEdges; |
| 2042 |
|
| 2043 |
if(MyPID==0) {std::cout << "Adjust global matrix and rhs due to BCs " << Time.ElapsedTime() |
| 2044 |
<< " sec \n"; Time.ResetStartTime();} |
| 2045 |
|
| 2046 |
if (dump) { |
| 2047 |
EpetraExt::RowMatrixToMatrixMarketFile("mag_m0_matrix.mat",MassMatrixG); |
| 2048 |
EpetraExt::RowMatrixToMatrixMarketFile("edge_matrix.mat",StiffMatrixC); |
| 2049 |
} |
| 2050 |
|
| 2051 |
/**********************************************************************************/ |
| 2052 |
/*********************************** SOLVE ****************************************/ |
| 2053 |
/**********************************************************************************/ |
| 2054 |
|
| 2055 |
#ifdef HAVE_XPETRA_EPETRA |
| 2056 |
MLStatistics.Phase3(); |
| 2057 |
Teuchos::ParameterList problemStatistics = MLStatistics.GetStatistics(); |
| 2058 |
if(MyPID==0) { |
| 2059 |
std::cout<<"*** Problem Statistics ***"<<std::endl; |
| 2060 |
std::cout<<problemStatistics<<std::endl; |
| 2061 |
} |
| 2062 |
#endif |
| 2063 |
|
| 2064 |
double TotalErrorResidual=0, TotalErrorExactSol=0; |
| 2065 |
|
| 2066 |
// Parameter list for ML |
| 2067 |
Teuchos::ParameterList MLList; |
| 2068 |
if(inputList.isSublist("ML")) { |
| 2069 |
MLList = inputList.sublist("ML"); |
| 2070 |
} else { |
| 2071 |
ML_Epetra::SetDefaultsRefMaxwell(MLList); |
| 2072 |
Teuchos::ParameterList &List11=MLList.sublist("refmaxwell: 11list"); |
| 2073 |
Teuchos::ParameterList &List11c=List11.sublist("edge matrix free: coarse"); |
| 2074 |
Teuchos::ParameterList &List22=MLList.sublist("refmaxwell: 22list"); |
| 2075 |
// MLList.set("refmaxwell: mode","none"); |
| 2076 |
MLList.set("refmaxwell: mode","additive"); |
| 2077 |
MLList.set("refmaxwell: disable addon",false); |
| 2078 |
MLList.set("aggregation: type","Uncoupled-MIS"); |
| 2079 |
MLList.set("ML output",10); |
| 2080 |
MLList.set("smoother: type","Chebyshev"); |
| 2081 |
// MLList.set("print hierarchy", 0); |
| 2082 |
|
| 2083 |
List11.set("ML output",10); |
| 2084 |
// List11.set("print hierarchy", true); |
| 2085 |
List22.set("coarse: type","Amesos-KLU"); |
| 2086 |
List22.set("ML output",10); |
| 2087 |
|
| 2088 |
List11c.set("coarse: type","Amesos-KLU"); |
| 2089 |
List11c.set("ML output",10); |
| 2090 |
List11c.set("PDE equations",3); |
| 2091 |
} |
| 2092 |
Teuchos::ParameterList &List11=MLList.sublist("refmaxwell: 11list"); |
| 2093 |
List11.set("x-coordinates",&Nx[0]); |
| 2094 |
List11.set("y-coordinates",&Ny[0]); |
| 2095 |
List11.set("z-coordinates",&Nz[0]); |
| 2096 |
|
| 2097 |
Teuchos::ParameterList &List22=MLList.sublist("refmaxwell: 22list"); |
| 2098 |
List22.set("x-coordinates",&Nx[0]); |
| 2099 |
List22.set("y-coordinates",&Ny[0]); |
| 2100 |
List22.set("z-coordinates",&Nz[0]); |
| 2101 |
|
| 2102 |
// Parameter list for MueLu |
| 2103 |
Teuchos::ParameterList MueLuList; |
| 2104 |
Teuchos::RCP<const Teuchos::Comm<int> > comm = Teuchos::DefaultComm<int>::getComm(); |
| 2105 |
|
| 2106 |
if(inputList.isSublist("MueLu")) { |
| 2107 |
MueLuList = inputList.sublist("MueLu"); |
| 2108 |
} else { |
| 2109 |
Teuchos::ParameterList &MueList11=MueLuList.sublist("refmaxwell: 11list"); |
| 2110 |
Teuchos::ParameterList &MueList22=MueLuList.sublist("refmaxwell: 22list"); |
| 2111 |
MueLuList.set("aggregation: type","Uncoupled"); |
| 2112 |
// MueLuList.set("refmaxwell: mode","none"); |
| 2113 |
MueLuList.set("refmaxwell: mode","additive"); |
| 2114 |
MueLuList.set("refmaxwell: disable addon",false);; |
| 2115 |
MueLuList.set("smoother: type","CHEBYSHEV"); |
| 2116 |
|
| 2117 |
Teuchos::ParameterList &MueLuSmootherList=MueLuList.sublist("smoother: params"); |
| 2118 |
MueLuSmootherList.set("chebyshev: degree",2); |
| 2119 |
MueLuSmootherList.set("chebyshev: ratio eigenvalue",30.0); |
| 2120 |
|
| 2121 |
MueList11.set("coarse: max size", 128); |
| 2122 |
MueList11.set("smoother: type", "CHEBYSHEV"); |
| 2123 |
//MueList11.sublist("smoother: params").set("chebyshev: max eigenvalue",1.85123); |
| 2124 |
MueList11.sublist("smoother: params").set("chebyshev: ratio eigenvalue",30.0); |
| 2125 |
MueList11.sublist("smoother: params").set("chebyshev: degree",2); |
| 2126 |
//MueList11.set("coarse: type","Amesos-KLU"); |
| 2127 |
MueList11.set("number of equations",3); |
| 2128 |
|
| 2129 |
MueList22.set("coarse: max size", 128); |
| 2130 |
MueList22.set("smoother: type", "CHEBYSHEV"); |
| 2131 |
//MueList22.sublist("smoother: params").set("chebyshev: max eigenvalue",1.431); |
| 2132 |
MueList22.sublist("smoother: params").set("chebyshev: ratio eigenvalue",30.0); |
| 2133 |
MueList22.sublist("smoother: params").set("chebyshev: degree",2); |
| 2134 |
//MueList22.set("coarse: type","Amesos-KLU"); |
| 2135 |
} |
| 2136 |
|
| 2137 |
|
| 2138 |
#if defined(HAVE_TRILINOSCOUPLINGS_AVATAR) && defined(HAVE_TRILINOSCOUPLINGS_MUELU) && defined(HAVE_XPETRA_EPETRA) |
| 2139 |
Teuchos::ParameterList &MueList11=MueLuList.sublist("refmaxwell: 11list"); |
| 2140 |
Teuchos::ParameterList &MueList22=MueLuList.sublist("refmaxwell: 22list"); |
| 2141 |
|
| 2142 |
std::vector<std::string> AvatarSublists{"Avatar-MueLu-Fine","Avatar-MueLu-11","Avatar-MueLu-22"}; |
| 2143 |
std::vector<Teuchos::ParameterList *> MueLuSublists{&MueLuList,&MueList11,&MueList22}; |
| 2144 |
for (int i=0; i<(int)AvatarSublists.size(); i++) { |
| 2145 |
if (inputList.isSublist(AvatarSublists[i])) { |
| 2146 |
Teuchos::ParameterList problemFeatures = problemStatistics; |
| 2147 |
Teuchos::ParameterList avatarParams = inputList.sublist(AvatarSublists[i]); |
| 2148 |
std::cout<<"*** Avatar["<<AvatarSublists[i]<<"] Parameters ***\n"<<avatarParams<<std::endl; |
| 2149 |
|
| 2150 |
MueLu::AvatarInterface avatar(comm,avatarParams); |
| 2151 |
std::cout<<"*** Avatar Setup ***"<<std::endl; |
| 2152 |
avatar.Setup(); |
| 2153 |
avatar.SetMueLuParameters(problemFeatures,*MueLuSublists[i], true); |
| 2154 |
} |
| 2155 |
} |
| 2156 |
#endif |
| 2157 |
|
| 2158 |
Epetra_FEVector xh(rhsVector); |
| 2159 |
|
| 2160 |
MassMatrixC.SetLabel("Ms"); |
| 2161 |
MassMatrixC1.SetLabel("M1"); |
| 2162 |
StiffMatrixC.SetLabel("K1"); |
| 2163 |
DGrad.SetLabel("D0"); |
| 2164 |
MassMatrixGinv.SetLabel("M0^{-1}"); |
| 2165 |
|
| 2166 |
char probType[12] = "maxwell"; |
| 2167 |
|
| 2168 |
|
| 2169 |
// Form the Stiffness+Mass Matrix |
| 2170 |
StiffMatrixC.SetLabel("CurlCurl+Mass"); |
| 2171 |
|
| 2172 |
if (solverName == "ML") { |
| 2173 |
// ML version |
| 2174 |
if(MyPID==0) {std::cout << "\n\nML solve \n";} |
| 2175 |
TestMultiLevelPreconditioner_Maxwell(probType,MLList,StiffMatrixC, |
| 2176 |
DGrad,MassMatrixGinv,MassMatrixC,MassMatrixC1, |
| 2177 |
xh,rhsVector, |
| 2178 |
TotalErrorResidual, TotalErrorExactSol); |
| 2179 |
} |
| 2180 |
|
| 2181 |
#ifdef HAVE_TRILINOSCOUPLINGS_STRATIMIKOS |
| 2182 |
if (solverName == "ML-Stratimikos") { |
| 2183 |
if(MyPID==0) {std::cout << "\n\nML Stratimikos solve \n";} |
| 2184 |
TestMultiLevelPreconditioner_Stratimikos(probType,MLList,StiffMatrixC, |
| 2185 |
DGrad,MassMatrixGinv,MassMatrixC,MassMatrixC1, |
| 2186 |
xh,rhsVector, |
| 2187 |
TotalErrorResidual, TotalErrorExactSol); |
| 2188 |
} |
| 2189 |
#endif |
| 2190 |
|
| 2191 |
Epetra_MultiVector coords(MassMatrixGinv.RowMap(),3); |
| 2192 |
if (solverName == "MueLu" || solverName == "Stratimikos") { |
| 2193 |
// build coordinates multivector |
| 2194 |
|
| 2195 |
double* xx = coords[0]; |
| 2196 |
double* yy = coords[1]; |
| 2197 |
double* zz = coords[2]; |
| 2198 |
for(int i = 0; i < MassMatrixGinv.RowMap(). NumMyElements(); ++i) { |
| 2199 |
xx[i] = Nx[i]; |
| 2200 |
yy[i] = Ny[i]; |
| 2201 |
zz[i] = Nz[i]; |
| 2202 |
} |
| 2203 |
|
| 2204 |
} |
| 2205 |
|
| 2206 |
#if defined(HAVE_MUELU_EPETRA) and defined(HAVE_TRILINOSCOUPLINGS_MUELU) |
| 2207 |
if (solverName == "MueLu") { |
| 2208 |
// MueLu RefMaxwell |
| 2209 |
if(MyPID==0) {std::cout << "\n\nMueLu solve \n";} |
| 2210 |
TestMueLuMultiLevelPreconditioner_Maxwell(probType,MueLuList,StiffMatrixC, |
| 2211 |
DGrad,MassMatrixGinv,MassMatrixC,MassMatrixC1, |
| 2212 |
coords, |
| 2213 |
xh,rhsVector, |
| 2214 |
TotalErrorResidual, TotalErrorExactSol); |
| 2215 |
} |
| 2216 |
|
| 2217 |
#ifdef HAVE_TRILINOSCOUPLINGS_STRATIMIKOS |
| 2218 |
if (solverName == "Stratimikos") { |
| 2219 |
if(MyPID==0) {std::cout << "\n\nStratimikos solve \n";} |
| 2220 |
Teuchos::ParameterList SList; |
| 2221 |
Teuchos::updateParametersFromXmlFile(xmlStratimikos,Teuchos::ptr (&SList)); |
| 2222 |
TestPreconditioner_Stratimikos(probType,SList,StiffMatrixC, |
| 2223 |
DGrad,MassMatrixGinv,MassMatrixC,MassMatrixC1, |
| 2224 |
coords,Nx,Ny,Nz, |
| 2225 |
xh,rhsVector, |
| 2226 |
TotalErrorResidual, TotalErrorExactSol); |
| 2227 |
} |
| 2228 |
#endif |
| 2229 |
#endif |
| 2230 |
|
| 2231 |
|
| 2232 |
/**********************************************************************************/ |
| 2233 |
/**************************** CALCULATE ERROR *************************************/ |
| 2234 |
/**********************************************************************************/ |
| 2235 |
|
| 2236 |
if (MyPID == 0) {Time.ResetStartTime();} |
| 2237 |
|
| 2238 |
double L2err = 0.0; |
| 2239 |
double HCurlerr = 0.0; |
| 2240 |
double Linferr = 0.0; |
| 2241 |
double L2errTot = 0.0; |
| 2242 |
double HCurlerrTot = 0.0; |
| 2243 |
double LinferrTot = 0.0; |
| 2244 |
|
| 2245 |
#ifdef HAVE_MPI |
| 2246 |
// Import solution onto current processor |
| 2247 |
Epetra_Map solnMap(numEdgesGlobal, numEdgesGlobal, 0, Comm); |
| 2248 |
Epetra_Import solnImporter(solnMap, globalMapC); |
| 2249 |
Epetra_FEVector uCoeff(solnMap); |
| 2250 |
uCoeff.Import(xh, solnImporter, Insert); |
| 2251 |
#endif |
| 2252 |
|
| 2253 |
int numCells = 1; |
| 2254 |
FieldContainer<double> hexEdgeSigns(numCells, numFieldsC); |
| 2255 |
FieldContainer<double> hexNodes(numCells, numFieldsG, spaceDim); |
| 2256 |
|
| 2257 |
// Get cubature points and weights for error calc (may be different from previous) |
| 2258 |
DefaultCubatureFactory<double> cubFactoryErr; |
| 2259 |
int cubDegErr = 3; |
| 2260 |
Teuchos::RCP<Cubature<double> > hexCubErr = cubFactoryErr.create(cellType, cubDegErr); |
| 2261 |
int cubDimErr = hexCubErr->getDimension(); |
| 2262 |
int numCubPointsErr = hexCubErr->getNumPoints(); |
| 2263 |
FieldContainer<double> cubPointsErr(numCubPointsErr, cubDimErr); |
| 2264 |
FieldContainer<double> cubWeightsErr(numCubPointsErr); |
| 2265 |
hexCubErr->getCubature(cubPointsErr, cubWeightsErr); |
| 2266 |
FieldContainer<double> physCubPointsE(numCells,numCubPointsErr, cubDimErr); |
| 2267 |
|
| 2268 |
// Containers for Jacobian |
| 2269 |
FieldContainer<double> hexJacobianE(numCells, numCubPointsErr, spaceDim, spaceDim); |
| 2270 |
FieldContainer<double> hexJacobInvE(numCells, numCubPointsErr, spaceDim, spaceDim); |
| 2271 |
FieldContainer<double> hexJacobDetE(numCells, numCubPointsErr); |
| 2272 |
FieldContainer<double> weightedMeasureE(numCells, numCubPointsErr); |
| 2273 |
|
| 2274 |
// Evaluate basis values and curls at cubature points |
| 2275 |
FieldContainer<double> uhCVals(numFieldsC, numCubPointsErr, spaceDim); |
| 2276 |
FieldContainer<double> uhCValsTrans(numCells,numFieldsC, numCubPointsErr, spaceDim); |
| 2277 |
FieldContainer<double> uhCurls(numFieldsC, numCubPointsErr, spaceDim); |
| 2278 |
FieldContainer<double> uhCurlsTrans(numCells, numFieldsC, numCubPointsErr, spaceDim); |
| 2279 |
hexHCurlBasis.getValues(uhCVals, cubPointsErr, OPERATOR_VALUE); |
| 2280 |
hexHCurlBasis.getValues(uhCurls, cubPointsErr, OPERATOR_CURL); |
| 2281 |
|
| 2282 |
// Loop over elements |
| 2283 |
for (int k=0; k<numElems; k++){ |
| 2284 |
|
| 2285 |
double L2errElem = 0.0; |
| 2286 |
double HCurlerrElem = 0.0; |
| 2287 |
double uExact1, uExact2, uExact3; |
| 2288 |
double curluExact1, curluExact2, curluExact3; |
| 2289 |
|
| 2290 |
// physical cell coordinates |
| 2291 |
for (int i=0; i<numNodesPerElem; i++) { |
| 2292 |
hexNodes(0,i,0) = nodeCoord(elemToNode(k,i),0); |
| 2293 |
hexNodes(0,i,1) = nodeCoord(elemToNode(k,i),1); |
| 2294 |
hexNodes(0,i,2) = nodeCoord(elemToNode(k,i),2); |
| 2295 |
} |
| 2296 |
// Edge signs |
| 2297 |
for (int j=0; j<numEdgesPerElem; j++) { |
| 2298 |
if (elemToNode(k,refEdgeToNode(j,0))==edgeToNode(elemToEdge(k,j),0) && |
| 2299 |
elemToNode(k,refEdgeToNode(j,1))==edgeToNode(elemToEdge(k,j),1)) |
| 2300 |
hexEdgeSigns(0,j) = 1.0; |
| 2301 |
else |
| 2302 |
hexEdgeSigns(0,j) = -1.0; |
| 2303 |
} |
| 2304 |
|
| 2305 |
// modify signs for edges whose signs were defined on another processor |
| 2306 |
if (!faceIsOwned[elemToFace(k,0)]) { |
| 2307 |
hexEdgeSigns(0,0)=-1.0*hexEdgeSigns(0,0); |
| 2308 |
hexEdgeSigns(0,4)=-1.0*hexEdgeSigns(0,4); |
| 2309 |
} |
| 2310 |
if (!faceIsOwned[elemToFace(k,1)]) { |
| 2311 |
hexEdgeSigns(0,1)=-1.0*hexEdgeSigns(0,1); |
| 2312 |
hexEdgeSigns(0,5)=-1.0*hexEdgeSigns(0,5); |
| 2313 |
} |
| 2314 |
if (!faceIsOwned[elemToFace(k,2)]) { |
| 2315 |
hexEdgeSigns(0,2)=-1.0*hexEdgeSigns(0,2); |
| 2316 |
hexEdgeSigns(0,6)=-1.0*hexEdgeSigns(0,6); |
| 2317 |
} |
| 2318 |
if (!faceIsOwned[elemToFace(k,3)]) { |
| 2319 |
hexEdgeSigns(0,3)=-1.0*hexEdgeSigns(0,3); |
| 2320 |
hexEdgeSigns(0,7)=-1.0*hexEdgeSigns(0,7); |
| 2321 |
} |
| 2322 |
|
| 2323 |
// compute cell Jacobians, their inverses and their determinants |
| 2324 |
IntrepidCTools::setJacobian(hexJacobianE, cubPointsErr, hexNodes, cellType); |
| 2325 |
IntrepidCTools::setJacobianInv(hexJacobInvE, hexJacobianE ); |
| 2326 |
IntrepidCTools::setJacobianDet(hexJacobDetE, hexJacobianE ); |
| 2327 |
|
| 2328 |
// transform integration points to physical points |
| 2329 |
IntrepidCTools::mapToPhysicalFrame(physCubPointsE, cubPointsErr, hexNodes, cellType); |
| 2330 |
|
| 2331 |
// transform basis values to physical coordinates |
| 2332 |
IntrepidFSTools::HCURLtransformVALUE<double>(uhCValsTrans, hexJacobInvE, uhCVals); |
| 2333 |
IntrepidFSTools::HCURLtransformCURL<double>(uhCurlsTrans, hexJacobianE, hexJacobDetE, uhCurls); |
| 2334 |
|
| 2335 |
// compute weighted measure |
| 2336 |
IntrepidFSTools::computeCellMeasure<double>(weightedMeasureE, hexJacobDetE, cubWeightsErr); |
| 2337 |
|
| 2338 |
// loop over cubature points |
| 2339 |
for (int nPt = 0; nPt < numCubPointsErr; nPt++){ |
| 2340 |
|
| 2341 |
// get exact solution and curls |
| 2342 |
double x = physCubPointsE(0,nPt,0); |
| 2343 |
double y = physCubPointsE(0,nPt,1); |
| 2344 |
double z = physCubPointsE(0,nPt,2); |
| 2345 |
evalu(uExact1, uExact2, uExact3, x, y, z); |
| 2346 |
double mu = 1.0; // use mu=1 to get the curl without material parameter |
| 2347 |
evalCurlu(curluExact1, curluExact2, curluExact3, x, y, z, mu); |
| 2348 |
|
| 2349 |
// calculate approximate solution and curls |
| 2350 |
double uApprox1 = 0.0; |
| 2351 |
double uApprox2 = 0.0; |
| 2352 |
double uApprox3 = 0.0; |
| 2353 |
double curluApprox1 = 0.0; |
| 2354 |
double curluApprox2= 0.0; |
| 2355 |
double curluApprox3 = 0.0; |
| 2356 |
for (int i = 0; i < numFieldsC; i++){ |
| 2357 |
int rowIndex = globalEdgeIds[elemToEdge(k,i)]; |
| 2358 |
#ifdef HAVE_MPI |
| 2359 |
double uh1 = uCoeff.Values()[rowIndex]; |
| 2360 |
#else |
| 2361 |
double uh1 = xh.Values()[rowIndex]; |
| 2362 |
#endif |
| 2363 |
uApprox1 += uh1*uhCValsTrans(0,i,nPt,0)*hexEdgeSigns(0,i); |
| 2364 |
uApprox2 += uh1*uhCValsTrans(0,i,nPt,1)*hexEdgeSigns(0,i); |
| 2365 |
uApprox3 += uh1*uhCValsTrans(0,i,nPt,2)*hexEdgeSigns(0,i); |
| 2366 |
curluApprox1 += uh1*uhCurlsTrans(0,i,nPt,0)*hexEdgeSigns(0,i); |
| 2367 |
curluApprox2 += uh1*uhCurlsTrans(0,i,nPt,1)*hexEdgeSigns(0,i); |
| 2368 |
curluApprox3 += uh1*uhCurlsTrans(0,i,nPt,2)*hexEdgeSigns(0,i); |
| 2369 |
} |
| 2370 |
|
| 2371 |
// evaluate the error at cubature points |
| 2372 |
Linferr = max(Linferr, abs(uExact1 - uApprox1)); |
| 2373 |
Linferr = max(Linferr, abs(uExact2 - uApprox2)); |
| 2374 |
Linferr = max(Linferr, abs(uExact3 - uApprox3)); |
| 2375 |
L2errElem+=(uExact1 - uApprox1)*(uExact1 - uApprox1)*weightedMeasureE(0,nPt); |
| 2376 |
L2errElem+=(uExact2 - uApprox2)*(uExact2 - uApprox2)*weightedMeasureE(0,nPt); |
| 2377 |
L2errElem+=(uExact3 - uApprox3)*(uExact3 - uApprox3)*weightedMeasureE(0,nPt); |
| 2378 |
HCurlerrElem+=((curluExact1 - curluApprox1)*(curluExact1 - curluApprox1)) |
| 2379 |
*weightedMeasureE(0,nPt); |
| 2380 |
HCurlerrElem+=((curluExact2 - curluApprox2)*(curluExact2 - curluApprox2)) |
| 2381 |
*weightedMeasureE(0,nPt); |
| 2382 |
HCurlerrElem+=((curluExact3 - curluApprox3)*(curluExact3 - curluApprox3)) |
| 2383 |
*weightedMeasureE(0,nPt); |
| 2384 |
} |
| 2385 |
|
| 2386 |
L2err+=L2errElem; |
| 2387 |
HCurlerr+=HCurlerrElem; |
| 2388 |
} |
| 2389 |
|
| 2390 |
|
| 2391 |
#ifdef HAVE_MPI |
| 2392 |
// sum over all processors |
| 2393 |
Comm.SumAll(&L2err,&L2errTot,1); |
| 2394 |
Comm.SumAll(&HCurlerr,&HCurlerrTot,1); |
| 2395 |
Comm.MaxAll(&Linferr,&LinferrTot,1); |
| 2396 |
#else |
| 2397 |
L2errTot = L2err; |
| 2398 |
HCurlerrTot = HCurlerr; |
| 2399 |
LinferrTot = Linferr; |
| 2400 |
#endif |
| 2401 |
|
| 2402 |
if (MyPID == 0) { |
| 2403 |
std::cout << "\n" << "L2 Error: " << sqrt(L2errTot) <<"\n"; |
| 2404 |
std::cout << "HCurl Error: " << sqrt(HCurlerrTot) <<"\n"; |
| 2405 |
std::cout << "LInf Error: " << LinferrTot <<"\n\n"; |
| 2406 |
} |
| 2407 |
|
| 2408 |
|
| 2409 |
// delete mesh |
| 2410 |
Delete_Pamgen_Mesh(); |
| 2411 |
|
| 2412 |
//clean up |
| 2413 |
for(long long b = 0; b < numElemBlk; b++){ |
| 2414 |
delete [] elmt_node_linkage[b]; |
| 2415 |
delete [] element_types[b]; |
| 2416 |
} |
| 2417 |
delete [] block_ids; |
| 2418 |
delete [] nodes_per_element; |
| 2419 |
delete [] element_attributes; |
| 2420 |
delete [] element_types; |
| 2421 |
delete [] elmt_node_linkage; |
| 2422 |
delete [] elements; |
| 2423 |
delete [] nodeCoordx; |
| 2424 |
delete [] nodeCoordy; |
| 2425 |
delete [] nodeCoordz; |
| 2426 |
|
| 2427 |
delete [] globalNodeIds; |
| 2428 |
delete [] nodeIsOwned; |
| 2429 |
delete [] globalEdgeIds; |
| 2430 |
delete [] edgeIsOwned; |
| 2431 |
delete [] globalFaceIds; |
| 2432 |
delete [] faceIsOwned; |
| 2433 |
if(num_node_comm_maps > 0){ |
| 2434 |
delete [] node_comm_proc_ids; |
| 2435 |
delete [] node_cmap_node_cnts; |
| 2436 |
delete [] node_cmap_ids; |
| 2437 |
for(long long i=0;i<num_node_comm_maps;i++){ |
| 2438 |
delete [] comm_node_ids[i]; |
| 2439 |
delete [] comm_node_proc_ids[i]; |
| 2440 |
} |
| 2441 |
|
| 2442 |
delete [] comm_node_ids; |
| 2443 |
delete [] comm_node_proc_ids; |
| 2444 |
} |
| 2445 |
|
| 2446 |
// Summarize timings |
| 2447 |
Teuchos::TimeMonitor::report (comm.ptr(), std::cout); |
| 2448 |
|
| 2449 |
return 0; |
| 2450 |
} |
| 2451 |
/**********************************************************************************/ |
| 2452 |
/********************************* END MAIN ***************************************/ |
| 2453 |
/**********************************************************************************/ |
| 2454 |
|
| 2455 |
|
| 2456 |
/*************************************************************************************/ |
| 2457 |
/****************************** Multiply Ones ****************************************/ |
| 2458 |
/*************************************************************************************/ |
| 2459 |
/** \brief Multiplies Ax = y, where all non-zero entries of A are replaced with the value 1.0 |
| 2460 |
|
| 2461 |
\param A [in] matrix |
| 2462 |
\param x [in] vector |
| 2463 |
\param y [in] vector |
| 2464 |
*/ |
| 2465 |
int Multiply_Ones(const Epetra_CrsMatrix &A,const Epetra_Vector &x,Epetra_Vector &y){ |
| 2466 |
if(!A.Filled()) |
| 2467 |
EPETRA_CHK_ERR(-1); // Matrix must be filled. |
| 2468 |
|
| 2469 |
double* xp = (double*) x.Values(); |
| 2470 |
double* yp = (double*) y.Values(); |
| 2471 |
const Epetra_Import* Importer_=A.Importer(); |
| 2472 |
const Epetra_Export* Exporter_=A.Exporter(); |
| 2473 |
Epetra_Vector *xcopy=0, *ImportVector_=0, *ExportVector_=0; |
| 2474 |
|
| 2475 |
if (&x==&y && Importer_==0 && Exporter_==0) { |
| 2476 |
xcopy = new Epetra_Vector(x); |
| 2477 |
xp = (double *) xcopy->Values(); |
| 2478 |
} |
| 2479 |
else if (Importer_) |
| 2480 |
ImportVector_ = new Epetra_Vector(Importer_->TargetMap()); |
| 2481 |
else if (Exporter_) |
| 2482 |
ExportVector_ = new Epetra_Vector(Exporter_->SourceMap()); |
| 2483 |
|
| 2484 |
|
| 2485 |
// If we have a non-trivial importer, we must import elements that are permuted or are on other processors |
| 2486 |
if(Importer_ != 0) { |
| 2487 |
EPETRA_CHK_ERR(ImportVector_->Import(x, *Importer_, Insert)); |
| 2488 |
xp = (double*) ImportVector_->Values(); |
| 2489 |
} |
| 2490 |
|
| 2491 |
// If we have a non-trivial exporter, we must export elements that are permuted or belong to other processors |
| 2492 |
if(Exporter_ != 0) yp = (double*) ExportVector_->Values(); |
| 2493 |
|
| 2494 |
// Do actual computation |
| 2495 |
for(int i = 0; i < A.NumMyRows(); i++) { |
| 2496 |
int NumEntries,*RowIndices; |
| 2497 |
A.Graph().ExtractMyRowView(i,NumEntries,RowIndices); |
| 2498 |
double sum = 0.0; |
| 2499 |
for(int j = 0; j < NumEntries; j++) |
| 2500 |
sum += xp[*RowIndices++]; |
| 2501 |
yp[i] = sum; |
| 2502 |
} |
| 2503 |
|
| 2504 |
if(Exporter_ != 0) { |
| 2505 |
y.PutScalar(0.0); // Make sure target is zero |
| 2506 |
EPETRA_CHK_ERR(y.Export(*ExportVector_, *Exporter_, Add)); // Fill y with Values from export vector |
| 2507 |
} |
| 2508 |
// Handle case of rangemap being a local replicated map |
| 2509 |
if (!A.Graph().RangeMap().DistributedGlobal() && A.Comm().NumProc()>1) EPETRA_CHK_ERR(y.Reduce()); |
| 2510 |
|
| 2511 |
delete xcopy; |
| 2512 |
delete ImportVector_; |
| 2513 |
delete ExportVector_; |
| 2514 |
|
| 2515 |
|
| 2516 |
return(0); |
| 2517 |
} |
| 2518 |
|
| 2519 |
/*************************************************************************************/ |
| 2520 |
/**************************** GET ML RESIDUAL ****************************************/ |
| 2521 |
/*************************************************************************************/ |
| 2522 |
/** \brief Compute ML solution residual |
| 2523 |
|
| 2524 |
\param A [in] discrete operator |
| 2525 |
\param lhs [in] solution vector |
| 2526 |
\param rhs [in] right hand side vector |
| 2527 |
\param Time [in] elapsed time for output |
| 2528 |
\param TotalErrorResidual [out] error residual |
| 2529 |
\param TotalErrorExactSol [out] error in xh (not an appropriate measure |
| 2530 |
for H(curl) basis functions) |
| 2531 |
*/ |
| 2532 |
void solution_test(string msg, const Epetra_Operator &A,const Epetra_MultiVector &lhs,const Epetra_MultiVector &rhs,const Epetra_MultiVector &xexact,Epetra_Time & Time, double & TotalErrorExactSol, double& TotalErrorResidual){ |
| 2533 |
// ==================================================== // |
| 2534 |
// compute difference between exact solution and ML one // |
| 2535 |
// ==================================================== // |
| 2536 |
double d = 0.0, d_tot = 0.0; |
| 2537 |
for( int i=0 ; i<lhs.Map().NumMyElements() ; ++i ) |
| 2538 |
d += (lhs[0][i] - xexact[0][i]) * (lhs[0][i] - xexact[0][i]); |
| 2539 |
|
| 2540 |
A.Comm().SumAll(&d,&d_tot,1); |
| 2541 |
|
| 2542 |
// ================== // |
| 2543 |
// compute ||Ax - b|| // |
| 2544 |
// ================== // |
| 2545 |
double Norm; |
| 2546 |
Epetra_Vector Ax(rhs.Map()); |
| 2547 |
A.Apply(lhs, Ax); |
| 2548 |
Ax.Update(1.0, rhs, -1.0); |
| 2549 |
Ax.Norm2(&Norm); |
| 2550 |
|
| 2551 |
// NOTE: (x_exact - x) does not make sense for H(curl) or H(grad) basis functions |
| 2552 |
if (A.Comm().MyPID() == 0) { |
| 2553 |
cout << msg << "......Using " << A.Comm().NumProc() << " processes" << endl; |
| 2554 |
cout << msg << "......||A x - b||_2 = " << Norm << endl; |
| 2555 |
// cout << msg << "......||x_exact - x||_2 = " << sqrt(d_tot) << endl; |
| 2556 |
cout << msg << "......Total Time = " << Time.ElapsedTime() << endl; |
| 2557 |
} |
| 2558 |
|
| 2559 |
TotalErrorExactSol += sqrt(d_tot); |
| 2560 |
TotalErrorResidual += Norm; |
| 2561 |
} |
| 2562 |
|
| 2563 |
/*************************************************************************************/ |
| 2564 |
/*************************** MueLu PRECONDITIONER ************************************/ |
| 2565 |
/*************************************************************************************/ |
| 2566 |
void TestMueLuMultiLevelPreconditioner_Maxwell(char ProblemType[], |
| 2567 |
Teuchos::ParameterList & MLList, |
| 2568 |
Epetra_CrsMatrix & CurlCurl, |
| 2569 |
Epetra_CrsMatrix & D0clean, |
| 2570 |
Epetra_CrsMatrix & M0inv, |
| 2571 |
Epetra_CrsMatrix & Ms, |
| 2572 |
Epetra_CrsMatrix & M1, |
| 2573 |
Epetra_MultiVector & coords, |
| 2574 |
Epetra_MultiVector & xh, |
| 2575 |
Epetra_MultiVector & b, |
| 2576 |
double & TotalErrorResidual, |
| 2577 |
double & TotalErrorExactSol){ |
| 2578 |
#if defined(HAVE_MUELU_EPETRA) and defined(HAVE_TRILINOSCOUPLINGS_MUELU) |
| 2579 |
typedef double Scalar; |
| 2580 |
typedef int LocalOrdinal; |
| 2581 |
typedef int GlobalOrdinal; |
| 2582 |
typedef Xpetra::EpetraNode Node; |
| 2583 |
typedef Scalar SC; |
| 2584 |
typedef LocalOrdinal LO; |
| 2585 |
typedef GlobalOrdinal GO; |
| 2586 |
typedef Node NO; |
| 2587 |
typedef Xpetra::Matrix<Scalar,LocalOrdinal,GlobalOrdinal,Node> Matrix; |
| 2588 |
typedef Xpetra::CrsMatrixWrap<Scalar,LocalOrdinal,GlobalOrdinal,Node> CrsMatrixWrap; |
| 2589 |
typedef Xpetra::CrsMatrix<Scalar,LocalOrdinal,GlobalOrdinal,Node> CrsMatrix; |
| 2590 |
typedef Xpetra::EpetraCrsMatrixT<GlobalOrdinal,Node> EpetraCrsMatrix; |
| 2591 |
typedef Xpetra::MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node> MultiVector; |
| 2592 |
typedef Xpetra::EpetraMultiVectorT<GlobalOrdinal,Node> EpetraMultiVector; |
| 2593 |
|
| 2594 |
|
| 2595 |
Epetra_Time SetupTime(CurlCurl.Comm()); |
| 2596 |
|
| 2597 |
Teuchos::RCP<CrsMatrix> ccMat = Teuchos::rcp(new EpetraCrsMatrix(Teuchos::rcpFromRef(CurlCurl))); |
| 2598 |
Teuchos::RCP<CrsMatrixWrap> ccOp = Teuchos::rcp(new CrsMatrixWrap(ccMat)); |
| 2599 |
Teuchos::RCP<Matrix> curlcurlOp = Teuchos::rcp_dynamic_cast<Matrix>(ccOp); |
| 2600 |
|
| 2601 |
Teuchos::RCP<CrsMatrix> d0cMat = Teuchos::rcp(new EpetraCrsMatrix(Teuchos::rcpFromRef(D0clean))); |
| 2602 |
Teuchos::RCP<CrsMatrixWrap> d0cOp = Teuchos::rcp(new CrsMatrixWrap(d0cMat)); |
| 2603 |
Teuchos::RCP<Matrix> D0cleanOp = Teuchos::rcp_dynamic_cast<Matrix>(d0cOp); |
| 2604 |
|
| 2605 |
Teuchos::RCP<CrsMatrix> m0invMat = Teuchos::rcp(new EpetraCrsMatrix(Teuchos::rcpFromRef(M0inv))); |
| 2606 |
Teuchos::RCP<CrsMatrixWrap> m0invOp = Teuchos::rcp(new CrsMatrixWrap(m0invMat)); |
| 2607 |
Teuchos::RCP<Matrix> M0invOp = Teuchos::rcp_dynamic_cast<Matrix>(m0invOp); |
| 2608 |
|
| 2609 |
Teuchos::RCP<CrsMatrix> m1Mat = Teuchos::rcp(new EpetraCrsMatrix(Teuchos::rcpFromRef(M1))); |
| 2610 |
Teuchos::RCP<CrsMatrixWrap> m1Op = Teuchos::rcp(new CrsMatrixWrap(m1Mat)); |
| 2611 |
Teuchos::RCP<Matrix> M1Op = Teuchos::rcp_dynamic_cast<Matrix>(m1Op); |
| 2612 |
|
| 2613 |
Teuchos::RCP<CrsMatrix> msMat = Teuchos::rcp(new EpetraCrsMatrix(Teuchos::rcpFromRef(Ms))); |
| 2614 |
Teuchos::RCP<CrsMatrixWrap> msOp = Teuchos::rcp(new CrsMatrixWrap(msMat)); |
| 2615 |
Teuchos::RCP<Matrix> MsOp = Teuchos::rcp_dynamic_cast<Matrix>(msOp); |
| 2616 |
|
| 2617 |
Teuchos::RCP<MultiVector> xxh = Teuchos::rcp(new EpetraMultiVector(Teuchos::rcpFromRef(xh))); |
| 2618 |
Teuchos::RCP<MultiVector> xb = Teuchos::rcp(new EpetraMultiVector(Teuchos::rcpFromRef(b))); |
| 2619 |
|
| 2620 |
Teuchos::RCP<MultiVector> xcoords = Teuchos::rcp(new EpetraMultiVector(Teuchos::rcpFromRef(coords))); |
| 2621 |
|
| 2622 |
MLList.set("parameterlist: syntax","muelu"); |
| 2623 |
|
| 2624 |
// construct preconditioner |
| 2625 |
Teuchos::RCP<MueLu::RefMaxwell<SC,LO,GO,NO> > preconditioner |
| 2626 |
= Teuchos::rcp( new MueLu::RefMaxwell<SC,LO,GO,NO>(curlcurlOp,d0cOp,MsOp,M0invOp, |
| 2627 |
M1Op,Teuchos::null,xcoords,MLList) ); |
| 2628 |
|
| 2629 |
MueLu::AztecEpetraOperator prec(preconditioner); |
| 2630 |
|
| 2631 |
if(CurlCurl.Comm().MyPID()==0) {std::cout << "Setup time: " << SetupTime.ElapsedTime() |
| 2632 |
<< " sec \n"; SetupTime.ResetStartTime();} |
| 2633 |
|
| 2634 |
Epetra_MultiVector x(xh); |
| 2635 |
x.PutScalar(0.0); |
| 2636 |
Epetra_LinearProblem Problem(&CurlCurl,&x,&b); |
| 2637 |
Epetra_MultiVector* lhs = Problem.GetLHS(); |
| 2638 |
Epetra_MultiVector* rhs = Problem.GetRHS(); |
| 2639 |
|
| 2640 |
Epetra_Time Time(CurlCurl.Comm()); |
| 2641 |
|
| 2642 |
AztecOO solver(Problem); |
| 2643 |
solver.SetAztecOption(AZ_solver, AZ_cg); |
| 2644 |
solver.SetAztecOption(AZ_output, 10); |
| 2645 |
solver.SetPrecOperator(&prec); |
| 2646 |
solver.Iterate(500, 1e-10); |
| 2647 |
|
| 2648 |
// accuracy check |
| 2649 |
Epetra_MultiVector xexact(xh); |
| 2650 |
xexact.PutScalar(0.0); |
| 2651 |
|
| 2652 |
string msg = ProblemType; |
| 2653 |
solution_test(msg,CurlCurl,*lhs,*rhs,xexact,Time,TotalErrorExactSol,TotalErrorResidual); |
| 2654 |
|
| 2655 |
xh = *lhs; |
| 2656 |
#endif |
| 2657 |
} |
| 2658 |
|
| 2659 |
/*************************************************************************************/ |
| 2660 |
/*************************** ML PRECONDITIONER****************************************/ |
| 2661 |
/*************************************************************************************/ |
| 2662 |
void TestMultiLevelPreconditioner_Maxwell(char ProblemType[], |
| 2663 |
Teuchos::ParameterList & MLList, |
| 2664 |
Epetra_CrsMatrix & CurlCurl, |
| 2665 |
Epetra_CrsMatrix & D0clean, |
| 2666 |
Epetra_CrsMatrix & M0inv, |
| 2667 |
Epetra_CrsMatrix & Ms, |
| 2668 |
Epetra_CrsMatrix & M1, |
| 2669 |
Epetra_MultiVector & xh, |
| 2670 |
Epetra_MultiVector & b, |
| 2671 |
double & TotalErrorResidual, |
| 2672 |
double & TotalErrorExactSol){ |
| 2673 |
/* Build RMP */ |
| 2674 |
|
| 2675 |
Epetra_Time SetupTime(CurlCurl.Comm()); |
| 2676 |
|
| 2677 |
ML_Epetra::RefMaxwellPreconditioner RMP(CurlCurl,D0clean,Ms,M0inv,M1,MLList); |
| 2678 |
|
| 2679 |
if(CurlCurl.Comm().MyPID()==0) {std::cout << "Setup time: " << SetupTime.ElapsedTime() |
| 2680 |
<< " sec \n"; SetupTime.ResetStartTime();} |
| 2681 |
|
| 2682 |
/* Build the AztecOO stuff */ |
| 2683 |
Epetra_MultiVector x(xh); |
| 2684 |
x.PutScalar(0.0); |
| 2685 |
|
| 2686 |
Epetra_LinearProblem Problem(&CurlCurl,&x,&b); |
| 2687 |
Epetra_MultiVector* lhs = Problem.GetLHS(); |
| 2688 |
Epetra_MultiVector* rhs = Problem.GetRHS(); |
| 2689 |
|
| 2690 |
Epetra_Time Time(CurlCurl.Comm()); |
| 2691 |
|
| 2692 |
/* Solve! */ |
| 2693 |
AztecOO solver(Problem); |
| 2694 |
solver.SetPrecOperator(&RMP); |
| 2695 |
solver.SetAztecOption(AZ_solver, AZ_cg); |
| 2696 |
solver.SetAztecOption(AZ_output, 10); |
| 2697 |
solver.Iterate(500, 1e-10); |
| 2698 |
|
| 2699 |
// accuracy check |
| 2700 |
Epetra_MultiVector xexact(xh); |
| 2701 |
xexact.PutScalar(0.0); |
| 2702 |
|
| 2703 |
string msg = ProblemType; |
| 2704 |
solution_test(msg,CurlCurl,*lhs,*rhs,xexact,Time,TotalErrorExactSol,TotalErrorResidual); |
| 2705 |
|
| 2706 |
xh = *lhs; |
| 2707 |
} |
| 2708 |
|
| 2709 |
|
| 2710 |
/*************************************************************************************/ |
| 2711 |
/*************************** ML PRECONDITIONER****************************************/ |
| 2712 |
/*************************************************************************************/ |
| 2713 |
#ifdef HAVE_TRILINOSCOUPLINGS_STRATIMIKOS |
| 2714 |
void TestMultiLevelPreconditioner_Stratimikos(char ProblemType[], |
| 2715 |
Teuchos::ParameterList & MLList, |
| 2716 |
Epetra_CrsMatrix & CurlCurl, |
| 2717 |
Epetra_CrsMatrix & D0clean, |
| 2718 |
Epetra_CrsMatrix & M0inv, |
| 2719 |
Epetra_CrsMatrix & Ms, |
| 2720 |
Epetra_CrsMatrix & M1, |
| 2721 |
Epetra_MultiVector & xh, |
| 2722 |
Epetra_MultiVector & b, |
| 2723 |
double & TotalErrorResidual, |
| 2724 |
double & TotalErrorExactSol){ |
| 2725 |
using Teuchos::rcp; |
| 2726 |
using Teuchos::RCP; |
| 2727 |
|
| 2728 |
/* Add matrices to parameterlist */ |
| 2729 |
MLList.set("D0",rcp((const Epetra_CrsMatrix*) &D0clean,false)); |
| 2730 |
MLList.set("M0inv",rcp((const Epetra_CrsMatrix*) &M0inv,false)); |
| 2731 |
MLList.set("M1",rcp((const Epetra_CrsMatrix*) &M1,false)); |
| 2732 |
MLList.set("Ms",rcp((const Epetra_CrsMatrix*) &Ms,false)); |
| 2733 |
|
| 2734 |
|
| 2735 |
/* Build the rest of the Stratimikos list */ |
| 2736 |
Teuchos::ParameterList SList; |
| 2737 |
SList.set("Linear Solver Type","AztecOO"); |
| 2738 |
SList.sublist("Linear Solver Types").sublist("AztecOO").sublist("Forward Solve").sublist("AztecOO Settings").set("Aztec Solver","CG"); |
| 2739 |
SList.sublist("Linear Solver Types").sublist("AztecOO").sublist("Forward Solve").sublist("AztecOO Settings").set("Output Frequency",10); |
| 2740 |
SList.sublist("Linear Solver Types").sublist("AztecOO").sublist("Forward Solve").set("Max Iterations",500); |
| 2741 |
SList.sublist("Linear Solver Types").sublist("AztecOO").sublist("Forward Solve").set("Tolerance",1e-10); |
| 2742 |
SList.sublist("Linear Solver Types").sublist("AztecOO").set("Output Every RHS",true); |
| 2743 |
SList.set("Preconditioner Type","ML"); |
| 2744 |
SList.sublist("Preconditioner Types").sublist("ML").set("Base Method Defaults","refmaxwell"); |
| 2745 |
SList.sublist("Preconditioner Types").sublist("ML").set("ML Settings",MLList); |
| 2746 |
|
| 2747 |
Epetra_Time Time(CurlCurl.Comm()); |
| 2748 |
|
| 2749 |
/* Thyra Wrappers */ |
| 2750 |
Epetra_MultiVector x(xh); |
| 2751 |
x.PutScalar(0.0); |
| 2752 |
|
| 2753 |
RCP<const Thyra::LinearOpBase<double> > At = Thyra::epetraLinearOp( rcp(&CurlCurl,false) ); |
| 2754 |
RCP<Thyra::MultiVectorBase<double> > xt = Thyra::create_MultiVector( rcp(&x,false), At->domain() ); |
| 2755 |
RCP<const Thyra::MultiVectorBase<double> > bt = Thyra::create_MultiVector( rcp(&b,false), At->range() ); |
| 2756 |
|
| 2757 |
/* Stratimikos setup */ |
| 2758 |
Stratimikos::DefaultLinearSolverBuilder linearSolverBuilder; |
| 2759 |
linearSolverBuilder.setParameterList(rcp(&SList,false)); |
| 2760 |
RCP<Thyra::LinearOpWithSolveFactoryBase<double> > lowsFactory = createLinearSolveStrategy(linearSolverBuilder); |
| 2761 |
RCP<Thyra::LinearOpWithSolveBase<double> > lows = Thyra::linearOpWithSolve<double>(*lowsFactory,At); |
| 2762 |
|
| 2763 |
/* Solve */ |
| 2764 |
Thyra::SolveStatus<double> status = Thyra::solve<double>(*lows, Thyra::NOTRANS, *bt, xt.ptr()); |
| 2765 |
|
| 2766 |
// accuracy check |
| 2767 |
Epetra_MultiVector xexact(xh); |
| 2768 |
xexact.PutScalar(0.0); |
| 2769 |
string msg = ProblemType; |
| 2770 |
solution_test(msg,CurlCurl,x,b,xexact,Time,TotalErrorExactSol,TotalErrorResidual); |
| 2771 |
|
| 2772 |
xh = x; |
| 2773 |
|
| 2774 |
} |
| 2775 |
|
| 2776 |
|
| 2777 |
/*************************************************************************************/ |
| 2778 |
/*************************** MueLu PRECONDITIONER ************************************/ |
| 2779 |
/*************************************************************************************/ |
| 2780 |
void TestPreconditioner_Stratimikos(char ProblemType[], |
| 2781 |
Teuchos::ParameterList & SList, |
| 2782 |
Epetra_CrsMatrix & CurlCurl, |
| 2783 |
Epetra_CrsMatrix & D0clean, |
| 2784 |
Epetra_CrsMatrix & M0inv, |
| 2785 |
Epetra_CrsMatrix & Ms, |
| 2786 |
Epetra_CrsMatrix & M1, |
| 2787 |
Epetra_MultiVector & coords, |
| 2788 |
Epetra_Vector & Nx, |
| 2789 |
Epetra_Vector & Ny, |
| 2790 |
Epetra_Vector & Nz, |
| 2791 |
Epetra_MultiVector & xh, |
| 2792 |
Epetra_MultiVector & b, |
| 2793 |
double & TotalErrorResidual, |
| 2794 |
double & TotalErrorExactSol){ |
| 2795 |
using Teuchos::rcp; |
| 2796 |
using Teuchos::RCP; |
| 2797 |
|
| 2798 |
Epetra_Time SetupTime(CurlCurl.Comm()); |
| 2799 |
|
| 2800 |
/* Build the rest of the Stratimikos list */ |
| 2801 |
SList.sublist("Preconditioner Types").sublist("ML").set("Base Method Defaults","refmaxwell"); |
| 2802 |
|
| 2803 |
SList.sublist("Preconditioner Types").sublist("ML").sublist("ML Settings").set("D0","substitute const D0"); |
| 2804 |
SList.sublist("Preconditioner Types").sublist("ML").sublist("ML Settings").set("M0inv","substitute const M0inv"); |
| 2805 |
SList.sublist("Preconditioner Types").sublist("ML").sublist("ML Settings").set("M1","substitute const M1"); |
| 2806 |
SList.sublist("Preconditioner Types").sublist("ML").sublist("ML Settings").set("Ms","substitute const Ms"); |
| 2807 |
SList.sublist("Preconditioner Types").sublist("ML").sublist("ML Settings").sublist("refmaxwell: 11list").set("x-coordinates","substitute x-coordinates"); |
| 2808 |
SList.sublist("Preconditioner Types").sublist("ML").sublist("ML Settings").sublist("refmaxwell: 11list").set("y-coordinates","substitute y-coordinates"); |
| 2809 |
SList.sublist("Preconditioner Types").sublist("ML").sublist("ML Settings").sublist("refmaxwell: 11list").set("z-coordinates","substitute z-coordinates"); |
| 2810 |
SList.sublist("Preconditioner Types").sublist("ML").sublist("ML Settings").sublist("refmaxwell: 22list").set("x-coordinates","substitute x-coordinates"); |
| 2811 |
SList.sublist("Preconditioner Types").sublist("ML").sublist("ML Settings").sublist("refmaxwell: 22list").set("y-coordinates","substitute y-coordinates"); |
| 2812 |
SList.sublist("Preconditioner Types").sublist("ML").sublist("ML Settings").sublist("refmaxwell: 22list").set("z-coordinates","substitute z-coordinates"); |
| 2813 |
|
| 2814 |
SList.sublist("Preconditioner Types").sublist("MueLuRefMaxwell").set("D0","substitute D0"); |
| 2815 |
SList.sublist("Preconditioner Types").sublist("MueLuRefMaxwell").set("M0inv","substitute M0inv"); |
| 2816 |
SList.sublist("Preconditioner Types").sublist("MueLuRefMaxwell").set("M1","substitute M1"); |
| 2817 |
SList.sublist("Preconditioner Types").sublist("MueLuRefMaxwell").set("Ms","substitute Ms"); |
| 2818 |
SList.sublist("Preconditioner Types").sublist("MueLuRefMaxwell").set("Coordinates","substitute Coordinates"); |
| 2819 |
|
| 2820 |
/* Add matrices to parameterlist */ |
| 2821 |
Teuchos::ParameterList& precTypesPL = SList.sublist("Preconditioner Types"); |
| 2822 |
std::list<Teuchos::ParameterList*> sublists; |
| 2823 |
sublists.push_back(&precTypesPL); |
| 2824 |
while (sublists.size() > 0) { |
| 2825 |
Teuchos::ParameterList* sublist = sublists.front(); |
| 2826 |
sublists.pop_front(); |
| 2827 |
std::list<std::string> keys; |
| 2828 |
for (Teuchos::ParameterList::ConstIterator it = sublist->begin(); it != sublist->end(); ++it) { |
| 2829 |
const std::string &entryName = sublist->name(it); |
| 2830 |
const Teuchos::ParameterEntry &theEntry = sublist->entry(it); |
| 2831 |
if (theEntry.isList()) { |
| 2832 |
Teuchos::ParameterList& sl = sublist->sublist(entryName); |
| 2833 |
sublists.push_back(&sl); |
| 2834 |
} else if (theEntry.isType<std::string>() && Teuchos::getValue<std::string>(theEntry).find("substitute ") != std::string::npos) { |
| 2835 |
keys.push_back(entryName); |
| 2836 |
} |
| 2837 |
} |
| 2838 |
for (auto key_it = keys.begin(); key_it != keys.end(); ++key_it) { |
| 2839 |
std::string value = sublist->get<std::string>(*key_it).substr(11, std::string::npos); |
| 2840 |
if (value == "D0") |
| 2841 |
sublist->set(*key_it, rcp((Epetra_CrsMatrix*) &D0clean,false)); |
| 2842 |
else if (value == "M0inv") |
| 2843 |
sublist->set(*key_it, rcp((Epetra_CrsMatrix*) &M0inv,false)); |
| 2844 |
else if (value == "M1") |
| 2845 |
sublist->set(*key_it, rcp((Epetra_CrsMatrix*) &M1,false)); |
| 2846 |
else if (value == "Ms") |
| 2847 |
sublist->set(*key_it, rcp((Epetra_CrsMatrix*) &Ms,false)); |
| 2848 |
else if (value == "Coordinates") |
| 2849 |
sublist->set(*key_it, rcp((Epetra_MultiVector*) &coords,false)); |
| 2850 |
else if (value == "const D0") |
| 2851 |
sublist->set(*key_it, rcp((const Epetra_CrsMatrix*) &D0clean,false)); |
| 2852 |
else if (value == "const M0inv") |
| 2853 |
sublist->set(*key_it, rcp((const Epetra_CrsMatrix*) &M0inv,false)); |
| 2854 |
else if (value == "const M1") |
| 2855 |
sublist->set(*key_it, rcp((const Epetra_CrsMatrix*) &M1,false)); |
| 2856 |
else if (value == "const Ms") |
| 2857 |
sublist->set(*key_it, rcp((const Epetra_CrsMatrix*) &Ms,false)); |
| 2858 |
else if (value == "const Coordinates") |
| 2859 |
sublist->set(*key_it, rcp((const Epetra_MultiVector*) &coords,false)); |
| 2860 |
else if (value == "x-coordinates") |
| 2861 |
sublist->set(*key_it, &Nx[0]); |
| 2862 |
else if (value == "y-coordinates") |
| 2863 |
sublist->set(*key_it, &Ny[0]); |
| 2864 |
else if (value == "z-coordinates") |
| 2865 |
sublist->set(*key_it, &Nz[0]); |
| 2866 |
} |
| 2867 |
} |
| 2868 |
|
| 2869 |
Epetra_Time Time(CurlCurl.Comm()); |
| 2870 |
|
| 2871 |
/* Thyra Wrappers */ |
| 2872 |
Epetra_MultiVector x(xh); |
| 2873 |
x.PutScalar(0.0); |
| 2874 |
|
| 2875 |
RCP<const Thyra::LinearOpBase<double> > At = Thyra::epetraLinearOp( rcp(&CurlCurl,false) ); |
| 2876 |
RCP<Thyra::MultiVectorBase<double> > xt = Thyra::create_MultiVector( rcp(&x,false), At->domain() ); |
| 2877 |
RCP<const Thyra::MultiVectorBase<double> > bt = Thyra::create_MultiVector( rcp(&b,false), At->range() ); |
| 2878 |
|
| 2879 |
/* Stratimikos setup */ |
| 2880 |
Stratimikos::DefaultLinearSolverBuilder linearSolverBuilder; |
| 2881 |
#if defined(HAVE_MUELU_EPETRA) and defined(HAVE_TRILINOSCOUPLINGS_MUELU) |
| 2882 |
// typedef double Scalar; |
| 2883 |
typedef int LocalOrdinal; |
| 2884 |
typedef int GlobalOrdinal; |
| 2885 |
typedef LocalOrdinal LO; |
| 2886 |
typedef GlobalOrdinal GO; |
| 2887 |
typedef Xpetra::EpetraNode Node; |
| 2888 |
Stratimikos::enableMueLuRefMaxwell<double,LO,GO,Node>(linearSolverBuilder); // Register MueLu as a Stratimikos preconditioner strategy. |
| 2889 |
#endif |
| 2890 |
linearSolverBuilder.setParameterList(rcp(&SList,false)); |
| 2891 |
RCP<Thyra::LinearOpWithSolveFactoryBase<double> > lowsFactory = createLinearSolveStrategy(linearSolverBuilder); |
| 2892 |
RCP<Thyra::LinearOpWithSolveBase<double> > lows = Thyra::linearOpWithSolve<double>(*lowsFactory,At); |
| 2893 |
|
| 2894 |
/* Solve */ |
| 2895 |
Thyra::SolveStatus<double> status = Thyra::solve<double>(*lows, Thyra::NOTRANS, *bt, xt.ptr()); |
| 2896 |
|
| 2897 |
// accuracy check |
| 2898 |
Epetra_MultiVector xexact(xh); |
| 2899 |
xexact.PutScalar(0.0); |
| 2900 |
string msg = ProblemType; |
| 2901 |
solution_test(msg,CurlCurl,x,b,xexact,Time,TotalErrorExactSol,TotalErrorResidual); |
| 2902 |
|
| 2903 |
xh = x; |
| 2904 |
} |
| 2905 |
|
| 2906 |
#endif // HAVE_TRILINOSCOUPLINGS_STRATIMIKOS |
| 2907 |
|
| 2908 |
/**********************************************************************************/ |
| 2909 |
/************ USER DEFINED FUNCTIONS FOR EXACT SOLUTION ***************************/ |
| 2910 |
/**********************************************************************************/ |
| 2911 |
|
| 2912 |
// Calculates value of exact solution u |
| 2913 |
int evalu(double & uExact0, double & uExact1, double & uExact2, double & x, double & y, double & z) |
| 2914 |
{ |
| 2915 |
|
| 2916 |
// Exact solution 1 - homogeneous boundary conditions |
| 2917 |
uExact0 = sin(M_PI*x)*sin(M_PI*y); |
| 2918 |
uExact1 = y; |
| 2919 |
uExact2 = z; |
| 2920 |
|
| 2921 |
return 0; |
| 2922 |
} |
| 2923 |
|
| 2924 |
// Calculates curl of exact solution u |
| 2925 |
int evalCurlu(double & curlu0, double & curlu1, double & curlu2, double & x, double & y, double & z, double &mu) |
| 2926 |
{ |
| 2927 |
// Exact solution 1 - homogeneous boundary conditions |
| 2928 |
curlu0 = 0; |
| 2929 |
curlu1 = 0; |
| 2930 |
curlu2 = -mu*M_PI*(sin(M_PI*x)*cos(M_PI*y)); |
| 2931 |
|
| 2932 |
return 0; |
| 2933 |
} |
| 2934 |
|
| 2935 |
|
| 2936 |
|
| 2937 |
// Calculates curl of exact solution u |
| 2938 |
int evalCurlCurlu(double & curlcurlu0, double & curlcurlu1, double & curlcurlu2, double & x, double & y, double & z, double &mu) |
| 2939 |
{ |
| 2940 |
// Exact solution 1 - homogeneous boundary conditions |
| 2941 |
curlcurlu0 = mu*M_PI*M_PI*(sin(M_PI*x)*sin(M_PI*y)); |
| 2942 |
curlcurlu1 = mu*M_PI*M_PI*(cos(M_PI*x)*cos(M_PI*y)); |
| 2943 |
curlcurlu2 = 0; |
| 2944 |
|
| 2945 |
return 0; |
| 2946 |
} |