| 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_StabilizedADR.cpp |
| 11 |
\brief Example solution of a steady-state advection-diffusion-reaction equation with Dirichlet |
| 12 |
boundary conditon on a hexahedral mesh using nodal (Hgrad) elements and stabilization. |
| 13 |
|
| 14 |
This example requires the following Trilinos packages: |
| 15 |
\li Pamgen to generate a Hexahedral mesh; |
| 16 |
\li Sacado to form the source term from user-specified manufactured solution, and |
| 17 |
diffusion, advection and reaction functions. |
| 18 |
\li Intrepid to build the discretization matrix and right-hand side |
| 19 |
\li ML to solve the linear system. |
| 20 |
|
| 21 |
\verbatim |
| 22 |
Steady-state advection-diffusion boundary value problem in conservative form: |
| 23 |
|
| 24 |
-div (A.grad(u) - b.u) + c.u = f in Omega |
| 25 |
u = 0 on Gamma |
| 26 |
where |
| 27 |
A is a symmetric, positive definite diffusivity tensor |
| 28 |
b is advective velocity vector which is not required to be divergence free |
| 29 |
c is a reaction coefficient |
| 30 |
f is a given source term |
| 31 |
|
| 32 |
The user must provide definitions for these quantities and definition for the exact solution |
| 33 |
|
| 34 |
|
| 35 |
Corresponding discrete linear system for nodal coefficients(x): |
| 36 |
|
| 37 |
Kx = d |
| 38 |
|
| 39 |
K - HGrad stiffness matrix |
| 40 |
d - right hand side vector |
| 41 |
|
| 42 |
\endverbatim |
| 43 |
|
| 44 |
\author Created by P. Bochev, D. Ridzal, K. Peterson, D. Hensinger, C. Siefert. |
| 45 |
|
| 46 |
\remark Usage: |
| 47 |
\code ./TrilinosCouplings_examples_scaling_example_StabilizedADR.exe \endcode |
| 48 |
|
| 49 |
\remark Example requires Pamgen formatted mesh input file named ADR.xml. |
| 50 |
*/ |
| 51 |
|
| 52 |
//#define DUMP_DATA |
| 53 |
// TrilinosCouplings includes |
| 54 |
#include "TrilinosCouplings_config.h" |
| 55 |
#include "TrilinosCouplings_Pamgen_Utils.hpp" |
| 56 |
|
| 57 |
// Intrepid includes |
| 58 |
#include "Intrepid_FunctionSpaceTools.hpp" |
| 59 |
#include "Intrepid_FieldContainer.hpp" |
| 60 |
#include "Intrepid_CellTools.hpp" |
| 61 |
#include "Intrepid_ArrayTools.hpp" |
| 62 |
#include "Intrepid_HGRAD_HEX_C1_FEM.hpp" |
| 63 |
#include "Intrepid_RealSpaceTools.hpp" |
| 64 |
#include "Intrepid_DefaultCubatureFactory.hpp" |
| 65 |
#include "Intrepid_Utils.hpp" |
| 66 |
|
| 67 |
#ifdef HAVE_INTREPID_KOKKOS |
| 68 |
#include "Sacado.hpp" |
| 69 |
#else |
| 70 |
// Sacado includes |
| 71 |
#include "Sacado_No_Kokkos.hpp" |
| 72 |
#endif |
| 73 |
|
| 74 |
// Epetra includes |
| 75 |
#include "Epetra_Time.h" |
| 76 |
#include "Epetra_Map.h" |
| 77 |
#ifdef HAVE_MPI |
| 78 |
#include "Epetra_MpiComm.h" |
| 79 |
#else |
| 80 |
#include "Epetra_SerialComm.h" |
| 81 |
#endif |
| 82 |
#include "Epetra_FECrsMatrix.h" |
| 83 |
#include "Epetra_FEVector.h" |
| 84 |
#include "Epetra_Import.h" |
| 85 |
|
| 86 |
// Teuchos includes |
| 87 |
#include "Teuchos_oblackholestream.hpp" |
| 88 |
#include "Teuchos_RCP.hpp" |
| 89 |
#include "Teuchos_BLAS.hpp" |
| 90 |
#include "Teuchos_GlobalMPISession.hpp" |
| 91 |
#include "Teuchos_XMLParameterListHelpers.hpp" |
| 92 |
#include "Teuchos_Assert.hpp" |
| 93 |
|
| 94 |
// Shards includes |
| 95 |
#include "Shards_CellTopology.hpp" |
| 96 |
|
| 97 |
// EpetraExt includes |
| 98 |
#include "EpetraExt_RowMatrixOut.h" |
| 99 |
#include "EpetraExt_MultiVectorOut.h" |
| 100 |
|
| 101 |
// Pamgen includes |
| 102 |
#include "create_inline_mesh.h" |
| 103 |
#include "pamgen_im_exodusII_l.h" |
| 104 |
#include "pamgen_im_ne_nemesisI_l.h" |
| 105 |
#include "pamgen_extras.h" |
| 106 |
|
| 107 |
// AztecOO includes |
| 108 |
#include "AztecOO.h" |
| 109 |
|
| 110 |
// ML Includes |
| 111 |
#include "ml_MultiLevelPreconditioner.h" |
| 112 |
#include "ml_epetra_utils.h" |
| 113 |
|
| 114 |
// STL includes |
| 115 |
#include "map" |
| 116 |
|
| 117 |
|
| 118 |
// Typedefs: FAD with # of ind. vars fixed at 3 |
| 119 |
typedef Sacado::Fad::SFad<double,3> Fad3; |
| 120 |
typedef shards::CellTopology ShardsCellTopology; |
| 121 |
typedef Intrepid::FunctionSpaceTools IntrepidFSTools; |
| 122 |
typedef Intrepid::CellTools<double> IntrepidCTools; |
| 123 |
|
| 124 |
typedef long long int128; |
| 125 |
|
| 126 |
using namespace std; |
| 127 |
using namespace Intrepid; |
| 128 |
|
| 129 |
// Global physics data |
| 130 |
double g_advection[3]={0.,0.,0.}; |
| 131 |
double g_reaction; |
| 132 |
|
| 133 |
|
| 134 |
/************************************************************************************************** |
| 135 |
* * |
| 136 |
* Problem specification: Declaration of user-defined functions for * |
| 137 |
* exact solution, diffusion, advection and reaction terms * |
| 138 |
* * |
| 139 |
**************************************************************************************************/ |
| 140 |
|
| 141 |
/** \brief User-defined exact solution. |
| 142 |
|
| 143 |
\param x [in] x-coordinate of the evaluation point |
| 144 |
\param y [in] y-coordinate of the evaluation point |
| 145 |
\param z [in] z-coordinate of the evaluation point |
| 146 |
|
| 147 |
\return Value of the exact solution at (x,y,z) |
| 148 |
*/ |
| 149 |
template<typename Scalar> |
| 150 |
const Scalar exactSolution(const Scalar& x, const Scalar& y, const Scalar& z); |
| 151 |
|
| 152 |
|
| 153 |
|
| 154 |
/** \brief User-defined diffusion tensor. |
| 155 |
|
| 156 |
\param diffusion [out] 3 x 3 diffusivity tensor evaluated at (x,y,z) |
| 157 |
\param x [in] x-coordinate of the evaluation point |
| 158 |
\param y [in] y-coordinate of the evaluation point |
| 159 |
\param z [in] z-coordinate of the evaluation point |
| 160 |
|
| 161 |
\warning Symmetric and positive definite tensor is required for every (x,y,z). |
| 162 |
*/ |
| 163 |
template<typename Scalar> |
| 164 |
void diffusionTensor(Scalar diffusion[][3], const Scalar& x, const Scalar& y, const Scalar& z); |
| 165 |
|
| 166 |
|
| 167 |
|
| 168 |
/** \brief User-defined advective vector. |
| 169 |
|
| 170 |
\param advection [out] 3-dimensional advective vector evaluated at (x,y,z) |
| 171 |
\param x [in] x-coordinate of the evaluation point |
| 172 |
\param y [in] y-coordinate of the evaluation point |
| 173 |
\param z [in] z-coordinate of the evaluation point |
| 174 |
|
| 175 |
\remark Advective vector is not required to be divergence-free |
| 176 |
*/ |
| 177 |
template<typename Scalar> |
| 178 |
void advectiveVector(Scalar advection[3], const Scalar& x, const Scalar& y, const Scalar& z); |
| 179 |
|
| 180 |
|
| 181 |
|
| 182 |
/** \brief User-defined reaction coefficient. |
| 183 |
|
| 184 |
\param x [in] x-coordinate of the evaluation point |
| 185 |
\param y [in] y-coordinate of the evaluation point |
| 186 |
\param z [in] z-coordinate of the evaluation point |
| 187 |
|
| 188 |
\return Value of the reaction coefficient function at (x,y,z) |
| 189 |
*/ |
| 190 |
template<typename Scalar> |
| 191 |
const Scalar reactionTerm(const Scalar& x, const Scalar& y, const Scalar& z); |
| 192 |
|
| 193 |
|
| 194 |
/************************************************************************************************** |
| 195 |
* * |
| 196 |
* Declarations of auxiliary functions that require user-defined functions for * |
| 197 |
* exact solution, diffusion, advection and reaction terms * |
| 198 |
* * |
| 199 |
**************************************************************************************************/ |
| 200 |
|
| 201 |
|
| 202 |
/** \brief Computes gradient of the exact solution. Requires user-defined exact solution. |
| 203 |
|
| 204 |
\param gradExact [out] gradient of the exact solution evaluated at (x,y,z) |
| 205 |
\param x [in] x-coordinate of the evaluation point |
| 206 |
\param y [in] y-coordinate of the evaluation point |
| 207 |
\param z [in] z-coordinate of the evaluation point |
| 208 |
*/ |
| 209 |
template<typename Scalar> |
| 210 |
void exactSolutionGrad(Scalar gradExact[3], const Scalar& x, const Scalar& y, const Scalar& z); |
| 211 |
|
| 212 |
|
| 213 |
|
| 214 |
/** \brief Computes source term: f = -div(K.grad u - b.u) + c.u. Requires user-defined exact solution, |
| 215 |
diffusion tensor, advective vector and reaction coefficient. |
| 216 |
|
| 217 |
\param x [in] x-coordinate of the evaluation point |
| 218 |
\param y [in] y-coordinate of the evaluation point |
| 219 |
\param z [in] z-coordinate of the evaluation point |
| 220 |
|
| 221 |
\return Source term corresponding to the user-defined exact solution, diffusivity, advection and |
| 222 |
reaction coefficients, evaluated at (x,y,z) |
| 223 |
*/ |
| 224 |
template<typename Scalar> |
| 225 |
const Scalar sourceTerm(Scalar& x, Scalar& y, Scalar& z); |
| 226 |
|
| 227 |
|
| 228 |
/************************************************************************************************** |
| 229 |
* * |
| 230 |
* Evaluation methods accepting multidimensional arrays of points * |
| 231 |
* * |
| 232 |
**************************************************************************************************/ |
| 233 |
|
| 234 |
|
| 235 |
/** \brief Computation of the diffusion tensor at array of points in physical space. |
| 236 |
|
| 237 |
\param worksetDiffusionValues [out] Rank-2, 3 or 4 array with dimensions (C,P), (C,P,D) or (C,P,D,D) |
| 238 |
with the values of the diffusion tensor |
| 239 |
\param evaluationPoints [in] Rank-3 (C,P,D) array with the evaluation points in physical frame |
| 240 |
*/ |
| 241 |
template<class ArrayOut, class ArrayIn> |
| 242 |
void evaluateDiffusionTensor(ArrayOut & worksetDiffusionValues, |
| 243 |
const ArrayIn & evaluationPoints); |
| 244 |
|
| 245 |
|
| 246 |
|
| 247 |
/** \brief Computation of the advective vector at array of points in physical space.. |
| 248 |
|
| 249 |
\param worksetAdvectionValues [out] Rank-3 (C,P,D) array with the values of the advective vector |
| 250 |
\param evaluationPoints [in] Rank-3 (C,P,D) array with the evaluation points in physical frame |
| 251 |
*/ |
| 252 |
template<class ArrayOut, class ArrayIn> |
| 253 |
void evaluateAdvectiveVector(ArrayOut & worksetAdvectionValues, |
| 254 |
const ArrayIn & evaluationPoints); |
| 255 |
|
| 256 |
|
| 257 |
|
| 258 |
/** \brief Computation of the reaction coefficient at array of points in physical space.. |
| 259 |
|
| 260 |
\param worksetReactionValues [out] Rank-2 (C,P) array with the values of the reaction coefficient |
| 261 |
\param evaluationPoints [in] Rank-3 (C,P,D) array with the evaluation points in physical frame |
| 262 |
*/ |
| 263 |
template<class ArrayOut, class ArrayIn> |
| 264 |
void evaluateReactionCoefficient(ArrayOut & worksetReactionValues, |
| 265 |
const ArrayIn & evaluationPoints); |
| 266 |
|
| 267 |
|
| 268 |
|
| 269 |
/** \brief Computation of the source term at array of points in physical space. |
| 270 |
|
| 271 |
\param sourceTermValues [out] Rank-2 (C,P) array with the values of the source term |
| 272 |
\param evaluationPoints [in] Rank-3 (C,P,D) array with the evaluation points in physical frame |
| 273 |
*/ |
| 274 |
template<class ArrayOut, class ArrayIn> |
| 275 |
void evaluateSourceTerm(ArrayOut & sourceTermValues, |
| 276 |
const ArrayIn & evaluationPoints); |
| 277 |
|
| 278 |
|
| 279 |
|
| 280 |
/** \brief Computation of the exact solution at array of points in physical space. |
| 281 |
|
| 282 |
\param exactSolutionValues [out] Rank-2 (C,P) array with the values of the exact solution |
| 283 |
\param evaluationPoints [in] Rank-3 (C,P,D) array with the evaluation points in physical frame |
| 284 |
*/ |
| 285 |
template<class ArrayOut, class ArrayIn> |
| 286 |
void evaluateExactSolution(ArrayOut & exactSolutionValues, |
| 287 |
const ArrayIn & evaluationPoints); |
| 288 |
|
| 289 |
|
| 290 |
|
| 291 |
/** \brief Computation of the gradient of the exact solution at array of points in physical space. |
| 292 |
|
| 293 |
\param exactSolutionGradValues [out] Rank-3 (C,P,D) array with the values of the gradient of the exact solution |
| 294 |
\param evaluationPoints [in] Rank-3 (C,P,D) array with the evaluation points in physical frame |
| 295 |
*/ |
| 296 |
template<class ArrayOut, class ArrayIn> |
| 297 |
void evaluateExactSolutionGrad(ArrayOut & exactSolutionGradValues, |
| 298 |
const ArrayIn & evaluationPoints); |
| 299 |
|
| 300 |
|
| 301 |
/************************************************************************************************** |
| 302 |
* * |
| 303 |
* ML related declarations * |
| 304 |
* * |
| 305 |
**************************************************************************************************/ |
| 306 |
int TestMultiLevelPreconditioner(char ProblemType[], |
| 307 |
Teuchos::ParameterList & MLList, |
| 308 |
Epetra_CrsMatrix & A, |
| 309 |
const Epetra_MultiVector & xexact, |
| 310 |
Epetra_MultiVector & b, |
| 311 |
Epetra_MultiVector & uh, |
| 312 |
double & TotalErrorResidual, |
| 313 |
double & TotalErrorExactSol); |
| 314 |
|
| 315 |
|
| 316 |
|
| 317 |
/************************************************************************************************** |
| 318 |
* * |
| 319 |
* PAMGEN wrapper (UNSTABLE - IN CONSTRUCTION) * |
| 320 |
* * |
| 321 |
**************************************************************************************************/ |
| 322 |
/** \brief Pamgen wrapper |
| 323 |
|
| 324 |
\param localNodeCoordsFC [out] Rank-2 (LN,D) array with the local nodes |
| 325 |
\param localCellToNodeFC [out] Rank-2 (C,N) array with the local nodes connectivity |
| 326 |
\param nodeOnBoundaryFC [out] Rank-1 (LN) array tells which local nodes are on the boundary |
| 327 |
\param nodeIsOwnedFC [out] Rank-1 (LN) array tells which local nodes are owned |
| 328 |
\param globalNodeIdsFC [out] Rank-1 (LN) array with the global node Ids of the local nodes |
| 329 |
\param meshInput [in] The list of parameters for Create_Pamgen_Mesh, extracted from the mesh file |
| 330 |
\param procRank [in] Rank of the processor |
| 331 |
\param numProcs [in] Number of processors |
| 332 |
\param Comm [in] Communicator object |
| 333 |
\param Time [in] Time object used for timings of various mesh tasks in the wrapper |
| 334 |
\param message [in] String that is printed as part of the various diagnostic outputs |
| 335 |
\param verbose [in] Forces diagnostic output if set to 1, default is 0 |
| 336 |
*/ |
| 337 |
template<class Scalar> |
| 338 |
void getPamgenMesh(FieldContainer<Scalar> & localNodeCoordsFC, |
| 339 |
FieldContainer<long long> & localCellToNodeFC, |
| 340 |
FieldContainer<int> & nodeOnBoundaryFC, |
| 341 |
FieldContainer<bool> & nodeIsOwnedFC, |
| 342 |
FieldContainer<long long> & globalNodeIdsFC, |
| 343 |
const std::string & meshInput, |
| 344 |
const int & procRank, |
| 345 |
const int & numProcs, |
| 346 |
const Epetra_Comm & Comm, |
| 347 |
Epetra_Time & Time, |
| 348 |
const string & message, |
| 349 |
const int verbose = 0); |
| 350 |
|
| 351 |
|
| 352 |
|
| 353 |
/************************************************************************************************** |
| 354 |
* * |
| 355 |
* Argument input (UNSTABLE - IN CONSTRUCTION) * |
| 356 |
* * |
| 357 |
**************************************************************************************************/ |
| 358 |
void getInputArguments(Teuchos::ParameterList & inputMeshList, |
| 359 |
std::string & meshInput, |
| 360 |
Teuchos::ParameterList & inputSolverList, |
| 361 |
int & argc, |
| 362 |
char * argv[], |
| 363 |
const Epetra_Comm & Comm, |
| 364 |
const std::string & inputMeshFile = "ADR.xml", |
| 365 |
const std::string & intputSolverFile = "ML_nonsym.xml"); |
| 366 |
|
| 367 |
|
| 368 |
|
| 369 |
/************************************************************************************************** |
| 370 |
* * |
| 371 |
* DRIVER: Advection-Diffusion-Reaction Boundary Value Problem * |
| 372 |
* * |
| 373 |
**************************************************************************************************/ |
| 374 |
|
| 375 |
int main(int argc, char *argv[]) { |
| 376 |
int numProcs = 1; |
| 377 |
int procRank = 0; |
| 378 |
string msg("Advection-diffusion-reaction driver: "); |
| 379 |
|
| 380 |
#ifdef HAVE_MPI |
| 381 |
Teuchos::GlobalMPISession mpiSession(&argc, &argv,0); |
| 382 |
procRank = mpiSession.getRank(); |
| 383 |
numProcs = mpiSession.getNProc(); |
| 384 |
Epetra_MpiComm Comm(MPI_COMM_WORLD); |
| 385 |
#else |
| 386 |
Epetra_SerialComm Comm; |
| 387 |
#endif |
| 388 |
|
| 389 |
int MyPID = Comm.MyPID(); |
| 390 |
Epetra_Time Time(Comm); |
| 391 |
|
| 392 |
if (MyPID == 0){ |
| 393 |
std::cout \ |
| 394 |
<< "===============================================================================\n" \ |
| 395 |
<< "| |\n" \ |
| 396 |
<< "| Example: Solve Advection-diffusion-reaction Equation on Hexahedral Mesh |\n" \ |
| 397 |
<< "| |\n" \ |
| 398 |
<< "| Requires user-defined functions for: |\n" \ |
| 399 |
<< "| |\n" \ |
| 400 |
<< "| the exact solution --> exactSolution(...) |\n" \ |
| 401 |
<< "| the diffusion tensor --> diffusionTensor(...) |\n" \ |
| 402 |
<< "| the advective vector --> advectiveVector(...) |\n" \ |
| 403 |
<< "| the reaction coefficient --> reactionTerm(...) |\n" \ |
| 404 |
<< "| |\n" \ |
| 405 |
<< "| Questions? Contact Pavel Bochev ([email protected]), |\n" \ |
| 406 |
<< "| Denis Ridzal ([email protected]), |\n" \ |
| 407 |
<< "| Kara Peterson ([email protected]). |\n" \ |
| 408 |
<< "| |\n" \ |
| 409 |
<< "| Intrepid's website: http://trilinos.sandia.gov/packages/intrepid |\n" \ |
| 410 |
<< "| Pamgen's website: http://trilinos.sandia.gov/packages/pamgen |\n" \ |
| 411 |
<< "| Sacado's website: http://trilinos.sandia.gov/packages/sacado |\n" \ |
| 412 |
<< "| ML's website: http://trilinos.sandia.gov/packages/ml |\n" \ |
| 413 |
<< "| Trilinos website: http://trilinos.sandia.gov |\n" \ |
| 414 |
<< "| |\n" \ |
| 415 |
<< "===============================================================================\n"; |
| 416 |
} |
| 417 |
|
| 418 |
#ifdef HAVE_MPI |
| 419 |
if (MyPID == 0) { |
| 420 |
std::cout << msg << "PARALLEL executable \n"; |
| 421 |
} |
| 422 |
#else |
| 423 |
if (MyPID == 0) { |
| 424 |
std::cout << msg << "SERIAL executable \n"; |
| 425 |
} |
| 426 |
#endif |
| 427 |
|
| 428 |
/************************************************************************************************* |
| 429 |
* * |
| 430 |
* DISCRETIZATION SETUP: get inputs, generate mesh, choose cell topology, cubature and basis * |
| 431 |
* * |
| 432 |
************************************************************************************************/ |
| 433 |
|
| 434 |
// *********************** Read XML file with mesh specifications ******************************* |
| 435 |
|
| 436 |
Teuchos::ParameterList inputMeshList; |
| 437 |
std::string meshInput; |
| 438 |
Teuchos::ParameterList inputSolverList; |
| 439 |
int verbose = 1; |
| 440 |
|
| 441 |
getInputArguments(inputMeshList, meshInput, inputSolverList, argc, argv, Comm); |
| 442 |
|
| 443 |
|
| 444 |
// ************************************** GENERATE MESH ***************************************** |
| 445 |
|
| 446 |
// Arrays for mesh data: will be resized to required dimensions by the Pamgen wrapper |
| 447 |
FieldContainer<int128> globalNodeOrdinalsFC; |
| 448 |
FieldContainer<int128> localCellToNodeFC; |
| 449 |
FieldContainer<double> localNodeCoordsFC; |
| 450 |
FieldContainer<int> localNodeOnBoundaryFC; |
| 451 |
FieldContainer<bool> localNodeIsMineFC; |
| 452 |
|
| 453 |
// Generate Pamgen mesh and return mesh data in Field Containers |
| 454 |
getPamgenMesh<double>(localNodeCoordsFC, localCellToNodeFC, localNodeOnBoundaryFC, |
| 455 |
localNodeIsMineFC, globalNodeOrdinalsFC, meshInput, |
| 456 |
procRank, numProcs, Comm, |
| 457 |
Time, msg, verbose); |
| 458 |
|
| 459 |
// ********************************* GET PHYSICS INFORMATION ************************************ |
| 460 |
// Read physics info from mesh xml file if it's there. Otherwise do nothing. |
| 461 |
if(inputMeshList.isSublist("Physics Input")){ |
| 462 |
Teuchos::ParameterList & physicsList=inputMeshList.sublist("Physics Input"); |
| 463 |
g_advection[0]=physicsList.get("x advection",0.0); |
| 464 |
g_advection[1]=physicsList.get("y advection",0.0); |
| 465 |
g_advection[2]=physicsList.get("z advection",0.0); |
| 466 |
} |
| 467 |
|
| 468 |
// *********************************** DEFINE CELL TOPOLOGY ************************************* |
| 469 |
|
| 470 |
// All cells in the Pamgen grid are of the Hexahedron<8> type. |
| 471 |
ShardsCellTopology cellType(shards::getCellTopologyData<shards::Hexahedron<8> >() ); |
| 472 |
|
| 473 |
int numNodesPerCell = cellType.getNodeCount(); |
| 474 |
int spaceDim = cellType.getDimension(); |
| 475 |
|
| 476 |
|
| 477 |
// ************************************* DEFINE CUBATURE **************************************** |
| 478 |
|
| 479 |
if (MyPID == 0) std::cout << "Getting cubature ... \n\n"; |
| 480 |
|
| 481 |
// Define cubature of the specified degree for the cellType |
| 482 |
DefaultCubatureFactory<double> cubFactory; |
| 483 |
int cubDegree = 2; |
| 484 |
Teuchos::RCP<Cubature<double> > cellCubature = cubFactory.create(cellType, cubDegree); |
| 485 |
|
| 486 |
int cubDim = cellCubature -> getDimension(); |
| 487 |
int numCubPoints = cellCubature -> getNumPoints(); |
| 488 |
|
| 489 |
// Get numerical integration points and weights |
| 490 |
FieldContainer<double> cubPoints (numCubPoints, cubDim); |
| 491 |
FieldContainer<double> cubWeights(numCubPoints); |
| 492 |
|
| 493 |
cellCubature -> getCubature(cubPoints, cubWeights); |
| 494 |
|
| 495 |
|
| 496 |
// *************************************** DEFINE BASIS **************************************** |
| 497 |
|
| 498 |
if (MyPID == 0) std::cout << "Getting basis ... \n\n"; |
| 499 |
|
| 500 |
// Define basis |
| 501 |
Basis_HGRAD_HEX_C1_FEM<double, FieldContainer<double> > HGB; |
| 502 |
int numHGBFields = HGB.getCardinality(); |
| 503 |
|
| 504 |
FieldContainer<double> HGBValues(numHGBFields, numCubPoints); |
| 505 |
FieldContainer<double> HGBGrads (numHGBFields, numCubPoints, spaceDim); |
| 506 |
|
| 507 |
// Evaluate basis values and gradients at cubature points on the reference Hex cell |
| 508 |
HGB.getValues(HGBValues, cubPoints, OPERATOR_VALUE); |
| 509 |
HGB.getValues(HGBGrads, cubPoints, OPERATOR_GRAD); |
| 510 |
|
| 511 |
|
| 512 |
/************************************************************************************************* |
| 513 |
* * |
| 514 |
* GLOBAL MATRIX PROBLEM SETUP: generate Epetra map & define global Epetra arrays * |
| 515 |
* * |
| 516 |
************************************************************************************************/ |
| 517 |
|
| 518 |
// Count number of myDofs: for the lowest-order nodal FEM = number of myNodes |
| 519 |
int numMyDofs = 0; |
| 520 |
int numMyNodes = 0; |
| 521 |
int numLocalNodes = localNodeCoordsFC.dimension(0); |
| 522 |
|
| 523 |
for(int localNode = 0; localNode < numLocalNodes; localNode++) { |
| 524 |
if(localNodeIsMineFC[localNode]) numMyNodes++; |
| 525 |
} |
| 526 |
numMyDofs = numMyNodes; |
| 527 |
|
| 528 |
// Build a list of the global Dof ordinals of myDofs: for the lowest-order nodal FEM = global node ordinals |
| 529 |
int *myGlobalDofs = new int[numMyDofs]; |
| 530 |
int myGlobalDofOrdinal = 0; |
| 531 |
for(int localNode = 0; localNode < numLocalNodes; localNode++){ |
| 532 |
if(localNodeIsMineFC[localNode]){ |
| 533 |
myGlobalDofs[myGlobalDofOrdinal] = (int)globalNodeOrdinalsFC[localNode]; // NTS: will need to switch back to int128 |
| 534 |
myGlobalDofOrdinal++; |
| 535 |
} |
| 536 |
} |
| 537 |
|
| 538 |
// Define global Epetra arrays |
| 539 |
Epetra_Map globalMapG (-1, numMyDofs, myGlobalDofs, 0, Comm); |
| 540 |
Epetra_FECrsMatrix globalOperatorMatrix (Copy, globalMapG, 5*numHGBFields); |
| 541 |
Epetra_FEVector globalSourceTermVector(globalMapG); |
| 542 |
|
| 543 |
|
| 544 |
/************************************************************************************************* |
| 545 |
* * |
| 546 |
* DIRICHLET BOUNDARY CONDITIONS SETUP: count myDofs that are BV and set BVs into a map * |
| 547 |
* * |
| 548 |
************************************************************************************************/ |
| 549 |
|
| 550 |
// Map, keyed by local node ordinal, with the bdry values at all local nodes that are on the bdry |
| 551 |
std::map<int, double> localBoundaryValuesMap; |
| 552 |
|
| 553 |
// Number of myDofs that are also boundary values: for lowest-order FEM = number of myNodes that are on the bdry |
| 554 |
int numMyBoundaryValueDofs = 0; |
| 555 |
|
| 556 |
|
| 557 |
// Set the map with the local boundary values & count myDofs that are boundary values |
| 558 |
for(int localNode = 0; localNode < numLocalNodes; localNode++){ |
| 559 |
|
| 560 |
// If the localNode is on the boundary compute and set the exact solution value into the map |
| 561 |
if (localNodeOnBoundaryFC(localNode) ){ |
| 562 |
double x = localNodeCoordsFC(localNode, 0); |
| 563 |
double y = localNodeCoordsFC(localNode, 1); |
| 564 |
double z = localNodeCoordsFC(localNode, 2); |
| 565 |
localBoundaryValuesMap[localNode] = exactSolution(x, y, z); |
| 566 |
|
| 567 |
// If this local node is also "mine", i.e., owned, increment counter for myDofs that are bdry values |
| 568 |
if(localNodeIsMineFC[localNode]){ |
| 569 |
numMyBoundaryValueDofs++; |
| 570 |
} |
| 571 |
} |
| 572 |
} |
| 573 |
|
| 574 |
// Lookup table for ML_Epetra::Apply_OAZToMatrix method: myBoundaryValueDofs[myBvOrdinal] = myDofOrdinal |
| 575 |
int * myBoundaryValueDofs = new int [numMyBoundaryValueDofs]; |
| 576 |
int myBvOrdinal = 0; |
| 577 |
int myDofOrdinal = 0; |
| 578 |
|
| 579 |
// Count the bdry values and set their associated myDofOrdinals into the lookup table |
| 580 |
for (int localNode = 0; localNode < numLocalNodes; localNode++){ |
| 581 |
if (localNodeIsMineFC[localNode]){ |
| 582 |
if (localNodeOnBoundaryFC(localNode)){ |
| 583 |
myBoundaryValueDofs[myBvOrdinal] = myDofOrdinal; |
| 584 |
myBvOrdinal++; |
| 585 |
} |
| 586 |
myDofOrdinal++; |
| 587 |
} |
| 588 |
} |
| 589 |
|
| 590 |
|
| 591 |
/************************************************************************************************* |
| 592 |
* * |
| 593 |
* ASSEMBLY OF WORKSET CONTRIBUTIONS TO MATRIX AND RIGHT HAND SIDE: workset loop * |
| 594 |
* * |
| 595 |
************************************************************************************************/ |
| 596 |
|
| 597 |
// Define desired workset size and count how many worksets there are on this processor's mesh block |
| 598 |
int numLocalGridCells = localCellToNodeFC.dimension(0); |
| 599 |
int desiredWorksetSize = numLocalGridCells; // change to desired workset size! |
| 600 |
//int desiredWorksetSize = 100; // change to desired workset size! |
| 601 |
int numWorksets = numLocalGridCells/desiredWorksetSize; |
| 602 |
|
| 603 |
// When numLocalGridCells is not divisible by desiredWorksetSize, increase workset count by 1 |
| 604 |
if(numWorksets*desiredWorksetSize < numLocalGridCells) numWorksets += 1; |
| 605 |
|
| 606 |
if (MyPID == 0) { |
| 607 |
std::cout << "Building discretization matrix and right hand side... \n\n"; |
| 608 |
std::cout << "\tDesired workset size: " << desiredWorksetSize <<"\n"; |
| 609 |
std::cout << "\tNumber of worksets: " << numWorksets <<"\n\n"; |
| 610 |
Time.ResetStartTime(); |
| 611 |
} |
| 612 |
|
| 613 |
|
| 614 |
// ************************************** Loop over worksets ************************************* |
| 615 |
|
| 616 |
for(int workset = 0; workset < numWorksets; workset++){ |
| 617 |
|
| 618 |
// Compute cell numbers where the workset starts and ends |
| 619 |
int worksetSize = 0; |
| 620 |
int worksetBegin = (workset + 0)*desiredWorksetSize; |
| 621 |
int worksetEnd = (workset + 1)*desiredWorksetSize; |
| 622 |
|
| 623 |
// When numLocalGridCells is not divisible by desiredWorksetSize, the last workset ends at numLocalGridCells |
| 624 |
worksetEnd = (worksetEnd <= numLocalGridCells) ? worksetEnd : numLocalGridCells; |
| 625 |
|
| 626 |
// Now we know the actual workset size and can allocate the array for the cell nodes |
| 627 |
worksetSize = worksetEnd - worksetBegin; |
| 628 |
FieldContainer<double> cellWorkset(worksetSize, numNodesPerCell, spaceDim); |
| 629 |
|
| 630 |
// Copy cell nodes to the cell workset |
| 631 |
int cellCounter = 0; |
| 632 |
for(int cell = worksetBegin; cell < worksetEnd; cell++){ |
| 633 |
for (int node = 0; node < numNodesPerCell; node++) { |
| 634 |
cellWorkset(cellCounter, node, 0) = localNodeCoordsFC( localCellToNodeFC(cell, node), 0); |
| 635 |
cellWorkset(cellCounter, node, 1) = localNodeCoordsFC( localCellToNodeFC(cell, node), 1); |
| 636 |
cellWorkset(cellCounter, node, 2) = localNodeCoordsFC( localCellToNodeFC(cell, node), 2); |
| 637 |
} |
| 638 |
cellCounter++; |
| 639 |
} |
| 640 |
|
| 641 |
|
| 642 |
/************************************************************************************************* |
| 643 |
* Allocate arrays * |
| 644 |
************************************************************************************************/ |
| 645 |
|
| 646 |
// Containers for Jacobians, integration measure & cubature points in workset cells |
| 647 |
FieldContainer<double> worksetJacobian (worksetSize, numCubPoints, spaceDim, spaceDim); |
| 648 |
FieldContainer<double> worksetJacobInv (worksetSize, numCubPoints, spaceDim, spaceDim); |
| 649 |
FieldContainer<double> worksetJacobDet (worksetSize, numCubPoints); |
| 650 |
FieldContainer<double> worksetCubWeights(worksetSize, numCubPoints); |
| 651 |
FieldContainer<double> worksetCubPoints (worksetSize, numCubPoints, cubDim); |
| 652 |
|
| 653 |
// Containers for basis values transformed to workset cells and them multiplied by cubature weights |
| 654 |
FieldContainer<double> worksetHGBValues (worksetSize, numHGBFields, numCubPoints); |
| 655 |
FieldContainer<double> worksetHGBValuesWeighted(worksetSize, numHGBFields, numCubPoints); |
| 656 |
FieldContainer<double> worksetHGBGrads (worksetSize, numHGBFields, numCubPoints, spaceDim); |
| 657 |
FieldContainer<double> worksetHGBGradsWeighted (worksetSize, numHGBFields, numCubPoints, spaceDim); |
| 658 |
|
| 659 |
// Containers for diffusive & advective fluxes & non-conservative adv. term and reactive terms |
| 660 |
FieldContainer<double> worksetDiffusiveFlux(worksetSize, numHGBFields, numCubPoints, spaceDim); |
| 661 |
FieldContainer<double> worksetAdvectiveFlux(worksetSize, numHGBFields, numCubPoints, spaceDim); |
| 662 |
FieldContainer<double> worksetAdvectiveTerm(worksetSize, numHGBFields, numCubPoints); |
| 663 |
FieldContainer<double> worksetReactiveTerm (worksetSize, numHGBFields, numCubPoints); |
| 664 |
|
| 665 |
// Containers for diffusion, advection and reaction values. Require user-defined functions |
| 666 |
FieldContainer<double> worksetDiffusion (worksetSize, numCubPoints, spaceDim, spaceDim); |
| 667 |
FieldContainer<double> worksetAdvection (worksetSize, numCubPoints, spaceDim); |
| 668 |
FieldContainer<double> worksetReaction (worksetSize, numCubPoints); |
| 669 |
FieldContainer<double> worksetSourceTerm(worksetSize, numCubPoints); |
| 670 |
|
| 671 |
// Containers for workset contributions to the discretization matrix and the right hand side |
| 672 |
FieldContainer<double> worksetDiffusionMatrix (worksetSize, numHGBFields, numHGBFields); |
| 673 |
FieldContainer<double> worksetAdvectionMatrix (worksetSize, numHGBFields, numHGBFields); |
| 674 |
FieldContainer<double> worksetReactionMatrix (worksetSize, numHGBFields, numHGBFields); |
| 675 |
FieldContainer<double> worksetSourceTermVector(worksetSize, numHGBFields); |
| 676 |
|
| 677 |
|
| 678 |
if(MyPID == 0) { |
| 679 |
std::cout << msg << "Allocate arrays = " << Time.ElapsedTime() << " sec."<< endl; |
| 680 |
Time.ResetStartTime(); |
| 681 |
} |
| 682 |
|
| 683 |
|
| 684 |
|
| 685 |
|
| 686 |
/************************************************************************************************* |
| 687 |
* Reference frame computation: Jacobian data for each cell in the workset * |
| 688 |
************************************************************************************************/ |
| 689 |
|
| 690 |
// Compute cell Jacobians, their inverses and their determinants |
| 691 |
IntrepidCTools::setJacobian (worksetJacobian, cubPoints, cellWorkset, cellType); |
| 692 |
IntrepidCTools::setJacobianInv(worksetJacobInv, worksetJacobian ); |
| 693 |
IntrepidCTools::setJacobianDet(worksetJacobDet, worksetJacobian ); |
| 694 |
|
| 695 |
|
| 696 |
/************************************************************************************************* |
| 697 |
* Physical frame computation: user-defined diffusion, advection, reaction and source terms * |
| 698 |
************************************************************************************************/ |
| 699 |
|
| 700 |
// Map cubature points to workset cells & compute diffusion, adection, reaction and source terms |
| 701 |
IntrepidCTools::mapToPhysicalFrame (worksetCubPoints, cubPoints, cellWorkset, cellType); |
| 702 |
evaluateDiffusionTensor (worksetDiffusion, worksetCubPoints); |
| 703 |
evaluateAdvectiveVector (worksetAdvection, worksetCubPoints); |
| 704 |
evaluateReactionCoefficient (worksetReaction, worksetCubPoints); |
| 705 |
|
| 706 |
if(MyPID == 0) { |
| 707 |
std::cout << msg << "tabulate problem data " << Time.ElapsedTime() << " sec."<< endl; |
| 708 |
Time.ResetStartTime(); |
| 709 |
} |
| 710 |
|
| 711 |
|
| 712 |
evaluateSourceTerm (worksetSourceTerm, worksetCubPoints); |
| 713 |
|
| 714 |
|
| 715 |
if(MyPID == 0) { |
| 716 |
std::cout << msg << "Compute RHS " << Time.ElapsedTime() << " sec."<< endl; |
| 717 |
Time.ResetStartTime(); |
| 718 |
} |
| 719 |
|
| 720 |
|
| 721 |
|
| 722 |
/************************************************************************************************* |
| 723 |
* Transform basis functions and their gradients and compute integration measure * |
| 724 |
************************************************************************************************/ |
| 725 |
|
| 726 |
// Transform basis values to physical frame: |
| 727 |
IntrepidFSTools::HGRADtransformVALUE<double>(worksetHGBValues, // clones basis values (u) |
| 728 |
HGBValues); |
| 729 |
|
| 730 |
// Transform basis gradients to physical frame: |
| 731 |
IntrepidFSTools::HGRADtransformGRAD<double>(worksetHGBGrads, // DF^{-T}(grad u) |
| 732 |
worksetJacobInv, HGBGrads); |
| 733 |
|
| 734 |
// Compute integration measure for workset cells: |
| 735 |
IntrepidFSTools::computeCellMeasure<double>(worksetCubWeights, // Det(DF)*w = J*w |
| 736 |
worksetJacobDet, cubWeights); |
| 737 |
|
| 738 |
// Multiply transformed (workset) values with weighted measure |
| 739 |
IntrepidFSTools::multiplyMeasure<double>(worksetHGBValuesWeighted, // (u)*J*w |
| 740 |
worksetCubWeights, worksetHGBValues); |
| 741 |
|
| 742 |
// Multiply transformed (workset) gradients with weighted measure |
| 743 |
IntrepidFSTools::multiplyMeasure<double>(worksetHGBGradsWeighted, // DF^{-T}(grad u)*J*w |
| 744 |
worksetCubWeights, worksetHGBGrads); |
| 745 |
|
| 746 |
|
| 747 |
if(MyPID == 0) { |
| 748 |
std::cout << msg << "Transform time = " << Time.ElapsedTime() << " sec."<< endl; |
| 749 |
Time.ResetStartTime(); |
| 750 |
} |
| 751 |
|
| 752 |
|
| 753 |
/************************************************************************************************* |
| 754 |
* Diffusion term: DF^{-T}(grad u)*K*DF^{-T}(grad u)*J*w * |
| 755 |
************************************************************************************************/ |
| 756 |
|
| 757 |
// Compute the diffusive flux: |
| 758 |
IntrepidFSTools::tensorMultiplyDataField<double>(worksetDiffusiveFlux, // K*(DF^{-T}(grad u) |
| 759 |
worksetDiffusion, |
| 760 |
worksetHGBGrads); |
| 761 |
|
| 762 |
// Integrate to compute workset diffusion contribution to global matrix: |
| 763 |
IntrepidFSTools::integrate<double>(worksetDiffusionMatrix, // (DF^{-T}(grad u)*J*w)*(K*DF^{-T}(grad u)) |
| 764 |
worksetHGBGradsWeighted, |
| 765 |
worksetDiffusiveFlux, COMP_BLAS); |
| 766 |
|
| 767 |
|
| 768 |
|
| 769 |
if(MyPID == 0) { |
| 770 |
std::cout << msg << "diffusion time = " << Time.ElapsedTime() << " sec."<< endl; |
| 771 |
Time.ResetStartTime(); |
| 772 |
} |
| 773 |
|
| 774 |
|
| 775 |
|
| 776 |
/************************************************************************************************* |
| 777 |
* Advection term: b*DF^{-T}(grad u)*(u)*J*w requires div b = 0 * |
| 778 |
************************************************************************************************/ |
| 779 |
|
| 780 |
// Compute the advective term in non-conservative form: requires div b = 0! |
| 781 |
IntrepidFSTools::dotMultiplyDataField<double>(worksetAdvectiveTerm, // b*(DF^{-T}*(grad u) |
| 782 |
worksetAdvection, |
| 783 |
worksetHGBGrads); |
| 784 |
|
| 785 |
// Integrate to compute workset advection contribution to global matrix: |
| 786 |
IntrepidFSTools::integrate<double>(worksetAdvectionMatrix, // b*(DF^{-T}*(grad u)(u)*J*w |
| 787 |
worksetAdvectiveTerm, |
| 788 |
worksetHGBValuesWeighted, COMP_BLAS); |
| 789 |
|
| 790 |
|
| 791 |
|
| 792 |
if(MyPID == 0) { |
| 793 |
std::cout << msg << "advection time = " << Time.ElapsedTime() << " sec."<< endl; |
| 794 |
Time.ResetStartTime(); |
| 795 |
} |
| 796 |
|
| 797 |
|
| 798 |
|
| 799 |
/************************************************************************************************* |
| 800 |
* Reaction term: C.(u).(u)*J*w * |
| 801 |
************************************************************************************************/ |
| 802 |
|
| 803 |
// Compute the reaction term: |
| 804 |
IntrepidFSTools::scalarMultiplyDataField<double> (worksetReactiveTerm, // C.(u) |
| 805 |
worksetReaction, |
| 806 |
worksetHGBValues); |
| 807 |
|
| 808 |
// Integrate to compute workset reaction contribution to global matrix: |
| 809 |
IntrepidFSTools::integrate<double>(worksetReactionMatrix, // C.(u).(u)*J*w |
| 810 |
worksetReactiveTerm, |
| 811 |
worksetHGBValuesWeighted, COMP_BLAS); |
| 812 |
|
| 813 |
///////////////////**************************** TEST ***********************///////////////////////// |
| 814 |
/* |
| 815 |
// Compute the advective term in non-conservative form: requires div b = 0! |
| 816 |
IntrepidFSTools::dotMultiplyDataField<double>(worksetAdvectiveTerm, // b*(DF^{-T}*(grad u) |
| 817 |
worksetAdvection, |
| 818 |
worksetHGBGrads); |
| 819 |
|
| 820 |
// Compute the reaction term: |
| 821 |
IntrepidFSTools::scalarMultiplyDataField<double> (worksetReactiveTerm, // C.(u) |
| 822 |
worksetReaction, |
| 823 |
worksetHGBValues); |
| 824 |
|
| 825 |
// Add both terms |
| 826 |
Intrepid::RealSpaceTools<double>::add(worksetAdvectiveTerm, worksetReactiveTerm); |
| 827 |
|
| 828 |
// Integrate to compute workset advection contribution to global matrix: |
| 829 |
IntrepidFSTools::integrate<double>(worksetAdvectionMatrix, // b*(DF^{-T}*(grad u)(u)*J*w |
| 830 |
worksetAdvectiveTerm, |
| 831 |
worksetHGBValuesWeighted, COMP_BLAS); |
| 832 |
*/ |
| 833 |
|
| 834 |
if(MyPID == 0) { |
| 835 |
std::cout << msg << "reaction time = " << Time.ElapsedTime() << " sec."<< endl; |
| 836 |
Time.ResetStartTime(); |
| 837 |
} |
| 838 |
|
| 839 |
|
| 840 |
/************************************************************************************************* |
| 841 |
* Source term (right hand side): f.(u)*J*w * |
| 842 |
************************************************************************************************/ |
| 843 |
|
| 844 |
// Integrate worksetSourceTerm against weighted basis function set |
| 845 |
IntrepidFSTools::integrate<double>(worksetSourceTermVector, // f.(u)*J*w |
| 846 |
worksetSourceTerm, |
| 847 |
worksetHGBValuesWeighted, COMP_BLAS); |
| 848 |
|
| 849 |
|
| 850 |
/************************************************************************************************* |
| 851 |
* Assemble into global matrix and RHS vector & adjust RHS vector for inhomogeneous BC * |
| 852 |
************************************************************************************************/ |
| 853 |
|
| 854 |
//"WORKSET CELL" loop: local cell ordinal is relative to numLocalGridCells |
| 855 |
for(int cell = worksetBegin; cell < worksetEnd; cell++){ |
| 856 |
|
| 857 |
// Compute cell ordinal relative to the current workset |
| 858 |
int worksetCellOrdinal = cell - worksetBegin; |
| 859 |
|
| 860 |
// "CELL EQUATION" loop for the workset cell: cellRow is relative to the cell DoF numbering |
| 861 |
for (int cellRow = 0; cellRow < numHGBFields; cellRow++){ |
| 862 |
|
| 863 |
int localRow = localCellToNodeFC(cell, cellRow); |
| 864 |
int globalRow = globalNodeOrdinalsFC[localRow]; |
| 865 |
double sourceTermContribution = worksetSourceTermVector(worksetCellOrdinal, cellRow); |
| 866 |
|
| 867 |
globalSourceTermVector.SumIntoGlobalValues(1, &globalRow, &sourceTermContribution); |
| 868 |
|
| 869 |
// "CELL VARIABLE" loop for the workset cell: cellCol is relative to the cell DoF numbering |
| 870 |
for (int cellCol = 0; cellCol < numHGBFields; cellCol++){ |
| 871 |
|
| 872 |
int localCol = localCellToNodeFC(cell, cellCol); |
| 873 |
int globalCol = globalNodeOrdinalsFC[localCol]; |
| 874 |
double operatorMatrixContribution = |
| 875 |
worksetDiffusionMatrix(worksetCellOrdinal, cellRow, cellCol) + |
| 876 |
worksetAdvectionMatrix(worksetCellOrdinal, cellRow, cellCol) + |
| 877 |
worksetReactionMatrix (worksetCellOrdinal, cellRow, cellCol); |
| 878 |
|
| 879 |
globalOperatorMatrix.InsertGlobalValues(1, &globalRow, 1, &globalCol, &operatorMatrixContribution); |
| 880 |
|
| 881 |
// Adjust global source term for inhomogeneous boundary conditions: |
| 882 |
if(localNodeOnBoundaryFC(localCol) ){ |
| 883 |
map<int,double>::iterator localBvIterator = localBoundaryValuesMap.find(localCol); |
| 884 |
|
| 885 |
if(localBvIterator != localBoundaryValuesMap.end() ) { |
| 886 |
double boundaryValue = localBvIterator -> second; |
| 887 |
double globalSourceAdjustment = -1.0*boundaryValue*operatorMatrixContribution; |
| 888 |
|
| 889 |
globalSourceTermVector.SumIntoGlobalValues(1, &globalRow, &globalSourceAdjustment); |
| 890 |
} |
| 891 |
else{ |
| 892 |
std::cout << " Error: requested boundary value does not exist...exiting!\n"; exit(1); |
| 893 |
} |
| 894 |
}// *** adjust source *** |
| 895 |
}// *** cell col loop *** |
| 896 |
}// *** cell row loop *** |
| 897 |
}// *** workset cell loop ** |
| 898 |
}// *** workset loop *** |
| 899 |
|
| 900 |
|
| 901 |
/************************************************************************************************* |
| 902 |
* * |
| 903 |
* ASSEMBLE OVER MULTIPLE PROCESSORS & CONVERT TO LOCAL INDICES * |
| 904 |
* * |
| 905 |
************************************************************************************************/ |
| 906 |
|
| 907 |
globalOperatorMatrix.GlobalAssemble(); |
| 908 |
globalOperatorMatrix.FillComplete(); |
| 909 |
globalSourceTermVector.GlobalAssemble(); |
| 910 |
|
| 911 |
if(MyPID == 0) { |
| 912 |
std::cout << msg << "Matrix & Right Hand Side Assembly = " << Time.ElapsedTime() << " sec."<< endl; |
| 913 |
Time.ResetStartTime(); |
| 914 |
} |
| 915 |
|
| 916 |
|
| 917 |
/************************************************************************************************* |
| 918 |
* * |
| 919 |
* FINAL ADJUSTMENTS TO GLOBAL MATRIX AND RHS VECTOR FOR INHOMOGENEOUS BOUNDARY CONDITIONS * |
| 920 |
* * |
| 921 |
************************************************************************************************/ |
| 922 |
|
| 923 |
/************************************************************************************************* |
| 924 |
* Step 1 - Adjust RHS vector: set appropriate global RHS entries to the exact boundary values * |
| 925 |
************************************************************************************************/ |
| 926 |
|
| 927 |
// Reset myDof counter |
| 928 |
myDofOrdinal = 0; |
| 929 |
for (int localNode = 0; localNode < numLocalNodes; localNode++){ |
| 930 |
if (localNodeIsMineFC[localNode]){ |
| 931 |
if (localNodeOnBoundaryFC(localNode)){ |
| 932 |
map<int,double>::iterator localBvIterator = localBoundaryValuesMap.find(localNode); |
| 933 |
|
| 934 |
// Replace the global source term value by the exact boundary value |
| 935 |
if(localBvIterator != localBoundaryValuesMap.end() ) { |
| 936 |
globalSourceTermVector[0][myDofOrdinal] = localBvIterator -> second; |
| 937 |
} |
| 938 |
else{ |
| 939 |
std::cout << " Error: requested boundary value does not exist...exiting!\n"; exit(1); |
| 940 |
} |
| 941 |
} |
| 942 |
myDofOrdinal++; |
| 943 |
} |
| 944 |
} |
| 945 |
// Alternative access method to globalSourceTermVector[0][myDofOrdinal] |
| 946 |
// int globalRow = globalNodeIdsFC[localNode]; |
| 947 |
// globalSourceTermVector.ReplaceGlobalValue(globalRow, 0, newValue); |
| 948 |
|
| 949 |
|
| 950 |
/************************************************************************************************* |
| 951 |
* Step 2 - Adjust MATRIX: zero out Dirichlet rows and columns and add 1 to the diagonal * |
| 952 |
************************************************************************************************/ |
| 953 |
|
| 954 |
ML_Epetra::Apply_OAZToMatrix(myBoundaryValueDofs, numMyBoundaryValueDofs, globalOperatorMatrix); |
| 955 |
delete [] myBoundaryValueDofs; |
| 956 |
|
| 957 |
|
| 958 |
#ifdef DUMP_DATA |
| 959 |
// Dump matrices to disk |
| 960 |
EpetraExt::RowMatrixToMatlabFile("ADR_matrix.dat",globalOperatorMatrix); |
| 961 |
EpetraExt::MultiVectorToMatrixMarketFile("ADR_rhs_vector.dat",globalSourceTermVector,0,0,false); |
| 962 |
#endif |
| 963 |
|
| 964 |
|
| 965 |
/************************************************************************************************* |
| 966 |
* * |
| 967 |
* SOLVE THE LINEAR SYSTEM * |
| 968 |
* * |
| 969 |
************************************************************************************************/ |
| 970 |
|
| 971 |
// Run the solver |
| 972 |
Teuchos::ParameterList MLList = inputSolverList; |
| 973 |
ML_Epetra::SetDefaults("SA", MLList, 0, 0, false); |
| 974 |
Epetra_FEVector exactNodalVals(globalMapG); |
| 975 |
Epetra_FEVector femCoefficients(globalMapG); |
| 976 |
double TotalErrorResidual = 0.0; |
| 977 |
double TotalErrorExactSol = 0.0; |
| 978 |
|
| 979 |
// Get exact solution at nodes |
| 980 |
for (int i = 0; i<numLocalNodes; i++) { |
| 981 |
if (localNodeIsMineFC[i]){ |
| 982 |
double x = localNodeCoordsFC(i,0); |
| 983 |
double y = localNodeCoordsFC(i,1); |
| 984 |
double z = localNodeCoordsFC(i,2); |
| 985 |
double exactu = exactSolution(x, y, z); |
| 986 |
|
| 987 |
int rowindex=globalNodeOrdinalsFC[i]; |
| 988 |
exactNodalVals.SumIntoGlobalValues(1, &rowindex, &exactu); |
| 989 |
} |
| 990 |
} |
| 991 |
exactNodalVals.GlobalAssemble(); |
| 992 |
|
| 993 |
char probType[10] = "conv-diff"; |
| 994 |
|
| 995 |
TestMultiLevelPreconditioner(probType, MLList, |
| 996 |
globalOperatorMatrix, exactNodalVals, |
| 997 |
globalSourceTermVector, femCoefficients, |
| 998 |
TotalErrorResidual, TotalErrorExactSol); |
| 999 |
|
| 1000 |
|
| 1001 |
/************************************************************************************************* |
| 1002 |
* * |
| 1003 |
* COMPUTE FINITE ELEMENT ERROR * |
| 1004 |
* * |
| 1005 |
************************************************************************************************/ |
| 1006 |
|
| 1007 |
double L2err = 0.0; |
| 1008 |
double L2errTot = 0.0; |
| 1009 |
double H1err = 0.0; |
| 1010 |
double H1errTot = 0.0; |
| 1011 |
double Linferr = 0.0; |
| 1012 |
double LinferrTot = 0.0; |
| 1013 |
|
| 1014 |
#ifdef HAVE_MPI |
| 1015 |
// Import solution onto current processor |
| 1016 |
int numNodesGlobal = globalMapG.NumGlobalElements(); |
| 1017 |
Epetra_Map solnMap(numNodesGlobal, numNodesGlobal, 0, Comm); |
| 1018 |
Epetra_Import solnImporter(solnMap, globalMapG); |
| 1019 |
Epetra_Vector uCoeff(solnMap); |
| 1020 |
uCoeff.Import(femCoefficients, solnImporter, Insert); |
| 1021 |
#endif |
| 1022 |
|
| 1023 |
// Set workset size to 1 |
| 1024 |
desiredWorksetSize = 1; |
| 1025 |
|
| 1026 |
// Get cubature points and weights for error calc (may be different from previous) |
| 1027 |
DefaultCubatureFactory<double> cubFactoryErr; |
| 1028 |
int cubDegErr = 3; |
| 1029 |
Teuchos::RCP<Cubature<double> > cellCubatureErr = cubFactoryErr.create(cellType, cubDegErr); |
| 1030 |
int cubDimErr = cellCubatureErr->getDimension(); |
| 1031 |
int numCubPointsErr = cellCubatureErr->getNumPoints(); |
| 1032 |
FieldContainer<double> cubPointsErr(numCubPointsErr, cubDimErr); |
| 1033 |
FieldContainer<double> cubWeightsErr(numCubPointsErr); |
| 1034 |
cellCubatureErr->getCubature(cubPointsErr, cubWeightsErr); |
| 1035 |
|
| 1036 |
// Containers for Jacobian |
| 1037 |
FieldContainer<double> worksetJacobianE(desiredWorksetSize, numCubPointsErr, spaceDim, spaceDim); |
| 1038 |
FieldContainer<double> worksetJacobInvE(desiredWorksetSize, numCubPointsErr, spaceDim, spaceDim); |
| 1039 |
FieldContainer<double> worksetJacobDetE(desiredWorksetSize, numCubPointsErr); |
| 1040 |
FieldContainer<double> worksetCubWeightsE(desiredWorksetSize, numCubPointsErr); |
| 1041 |
|
| 1042 |
// Evaluate basis values and gradients at cubature points |
| 1043 |
FieldContainer<double> uhGVals(numHGBFields, numCubPointsErr); |
| 1044 |
FieldContainer<double> uhGValsTrans(desiredWorksetSize,numHGBFields, numCubPointsErr); |
| 1045 |
FieldContainer<double> uhGrads(numHGBFields, numCubPointsErr, spaceDim); |
| 1046 |
FieldContainer<double> uhGradsTrans(desiredWorksetSize, numHGBFields, numCubPointsErr, spaceDim); |
| 1047 |
HGB.getValues(uhGVals, cubPointsErr, OPERATOR_VALUE); |
| 1048 |
HGB.getValues(uhGrads, cubPointsErr, OPERATOR_GRAD); |
| 1049 |
|
| 1050 |
|
| 1051 |
// Loop over elements |
| 1052 |
for (int k=0; k<numLocalGridCells; k++){ |
| 1053 |
|
| 1054 |
double L2errElem = 0.0; |
| 1055 |
double H1errElem = 0.0; |
| 1056 |
double uExact; |
| 1057 |
double graduExact1, graduExact2, graduExact3; |
| 1058 |
|
| 1059 |
// physical cell coordinates |
| 1060 |
FieldContainer<double> cellWorksetEr(desiredWorksetSize,numNodesPerCell, spaceDim); |
| 1061 |
|
| 1062 |
for (int i=0; i<numNodesPerCell; i++) { |
| 1063 |
cellWorksetEr(0,i,0) = localNodeCoordsFC(localCellToNodeFC(k,i),0); |
| 1064 |
cellWorksetEr(0,i,1) = localNodeCoordsFC(localCellToNodeFC(k,i),1); |
| 1065 |
cellWorksetEr(0,i,2) = localNodeCoordsFC(localCellToNodeFC(k,i),2); |
| 1066 |
} |
| 1067 |
|
| 1068 |
// compute cell Jacobians, their inverses and their determinants |
| 1069 |
IntrepidCTools::setJacobian(worksetJacobianE, cubPointsErr, cellWorksetEr, cellType); |
| 1070 |
IntrepidCTools::setJacobianInv(worksetJacobInvE, worksetJacobianE ); |
| 1071 |
IntrepidCTools::setJacobianDet(worksetJacobDetE, worksetJacobianE ); |
| 1072 |
|
| 1073 |
// transform integration points to physical points |
| 1074 |
FieldContainer<double> worksetCubPoints(desiredWorksetSize,numCubPointsErr, cubDimErr); |
| 1075 |
IntrepidCTools::mapToPhysicalFrame(worksetCubPoints, cubPointsErr, cellWorksetEr, cellType); |
| 1076 |
|
| 1077 |
// transform basis values to physical coordinates |
| 1078 |
IntrepidFSTools::HGRADtransformVALUE<double>(uhGValsTrans, uhGVals); |
| 1079 |
IntrepidFSTools::HGRADtransformGRAD<double>(uhGradsTrans, worksetJacobInvE, uhGrads); |
| 1080 |
|
| 1081 |
// compute weighted measure |
| 1082 |
IntrepidFSTools::computeCellMeasure<double>(worksetCubWeightsE, worksetJacobDetE, cubWeightsErr); |
| 1083 |
|
| 1084 |
// loop over cubature points |
| 1085 |
for (int nPt = 0; nPt < numCubPointsErr; nPt++){ |
| 1086 |
|
| 1087 |
// get exact solution and gradients using AD |
| 1088 |
Fad3 x = worksetCubPoints(0,nPt,0); |
| 1089 |
Fad3 y = worksetCubPoints(0,nPt,1); |
| 1090 |
Fad3 z = worksetCubPoints(0,nPt,2); |
| 1091 |
Fad3 grad_u[3]; |
| 1092 |
|
| 1093 |
uExact = exactSolution(x, y, z).val(); |
| 1094 |
exactSolutionGrad(grad_u, x, y, z); |
| 1095 |
|
| 1096 |
graduExact1 = grad_u[0].val(); |
| 1097 |
graduExact2 = grad_u[1].val(); |
| 1098 |
graduExact3 = grad_u[2].val(); |
| 1099 |
|
| 1100 |
// calculate approximate solution and gradients |
| 1101 |
double uApprox = 0.0; |
| 1102 |
double graduApprox1 = 0.0; |
| 1103 |
double graduApprox2= 0.0; |
| 1104 |
double graduApprox3 = 0.0; |
| 1105 |
for (int i = 0; i < numHGBFields; i++){ |
| 1106 |
int rowIndex = globalNodeOrdinalsFC[localCellToNodeFC(k,i)]; |
| 1107 |
#ifdef HAVE_MPI |
| 1108 |
double uh1 = uCoeff.Values()[rowIndex]; |
| 1109 |
#else |
| 1110 |
double uh1 = femCoefficients.Values()[rowIndex]; |
| 1111 |
#endif |
| 1112 |
uApprox += uh1*uhGValsTrans(0,i,nPt); |
| 1113 |
graduApprox1 += uh1*uhGradsTrans(0,i,nPt,0); |
| 1114 |
graduApprox2 += uh1*uhGradsTrans(0,i,nPt,1); |
| 1115 |
graduApprox3 += uh1*uhGradsTrans(0,i,nPt,2); |
| 1116 |
} |
| 1117 |
|
| 1118 |
// REMOVE |
| 1119 |
//std::cout << " exact solution = " << uExact << "\n"; |
| 1120 |
//std::cout << " FEM solution = " << uApprox << "\n\n"; |
| 1121 |
|
| 1122 |
|
| 1123 |
|
| 1124 |
// evaluate the error at cubature points |
| 1125 |
Linferr = max(Linferr, abs(uExact - uApprox)); |
| 1126 |
|
| 1127 |
L2errElem+=(uExact - uApprox)*(uExact - uApprox)*worksetCubWeightsE(0,nPt); |
| 1128 |
H1errElem+=((graduExact1 - graduApprox1)*(graduExact1 - graduApprox1)) |
| 1129 |
*worksetCubWeightsE(0,nPt); |
| 1130 |
H1errElem+=((graduExact2 - graduApprox2)*(graduExact2 - graduApprox2)) |
| 1131 |
*worksetCubWeightsE(0,nPt); |
| 1132 |
H1errElem+=((graduExact3 - graduApprox3)*(graduExact3 - graduApprox3)) |
| 1133 |
*worksetCubWeightsE(0,nPt); |
| 1134 |
} |
| 1135 |
|
| 1136 |
L2err+=L2errElem; |
| 1137 |
H1err+=H1errElem; |
| 1138 |
} |
| 1139 |
|
| 1140 |
|
| 1141 |
#ifdef HAVE_MPI |
| 1142 |
// sum over all processors |
| 1143 |
Comm.SumAll(&L2err,&L2errTot,1); |
| 1144 |
Comm.SumAll(&H1err,&H1errTot,1); |
| 1145 |
Comm.MaxAll(&Linferr,&LinferrTot,1); |
| 1146 |
#else |
| 1147 |
L2errTot = L2err; |
| 1148 |
H1errTot = H1err; |
| 1149 |
LinferrTot = Linferr; |
| 1150 |
#endif |
| 1151 |
|
| 1152 |
if (MyPID == 0) { |
| 1153 |
std::cout << "\n" << "L2 Error: " << sqrt(L2errTot) <<"\n"; |
| 1154 |
std::cout << "H1 Error: " << sqrt(H1errTot) <<"\n"; |
| 1155 |
std::cout << "LInf Error: " << LinferrTot <<"\n"; |
| 1156 |
} |
| 1157 |
|
| 1158 |
// Cleanup |
| 1159 |
delete [] myGlobalDofs; |
| 1160 |
|
| 1161 |
// reset format state of std::cout |
| 1162 |
// std::cout.copyfmt(oldFormatState); |
| 1163 |
|
| 1164 |
#ifdef HAVE_MPI |
| 1165 |
MPI_Finalize(); |
| 1166 |
#endif |
| 1167 |
|
| 1168 |
exit(0); |
| 1169 |
|
| 1170 |
} |
| 1171 |
|
| 1172 |
|
| 1173 |
/************************************************************************************************** |
| 1174 |
* * |
| 1175 |
* Problem specification: * |
| 1176 |
* Begin user-defined functions for exact solution, diffusion, advection and reaction terms * |
| 1177 |
* * |
| 1178 |
**************************************************************************************************/ |
| 1179 |
|
| 1180 |
template<typename Scalar> |
| 1181 |
const Scalar exactSolution(const Scalar& x, const Scalar& y, const Scalar& z) { |
| 1182 |
|
| 1183 |
// Patch test: tri-linear function is in the FE space and should be recovered |
| 1184 |
return 1. + x + y + z + x*y + x*z + y*z + x*y*z; |
| 1185 |
|
| 1186 |
// Analytic solution with homogeneous Dirichlet boundary data |
| 1187 |
// return sin(M_PI*x)*sin(M_PI*y)*sin(M_PI*z)*exp(x+y+z); |
| 1188 |
|
| 1189 |
// Analytic solution with inhomogeneous Dirichlet boundary data |
| 1190 |
// return exp(x + y + z)/(1. + x*y + y*z + x*y*z); |
| 1191 |
} |
| 1192 |
|
| 1193 |
|
| 1194 |
|
| 1195 |
template<typename Scalar> |
| 1196 |
void diffusionTensor(Scalar diffusion[][3], const Scalar& x, const Scalar& y, const Scalar& z) { |
| 1197 |
diffusion[0][0] = 10.; |
| 1198 |
diffusion[0][1] = 0.; |
| 1199 |
diffusion[0][2] = 0.; |
| 1200 |
// |
| 1201 |
diffusion[1][0] = 0.; |
| 1202 |
diffusion[1][1] = 10.; |
| 1203 |
diffusion[1][2] = 0.; |
| 1204 |
// |
| 1205 |
diffusion[2][0] = 0.; |
| 1206 |
diffusion[2][1] = 0.; |
| 1207 |
diffusion[2][2] = 10.; |
| 1208 |
} |
| 1209 |
|
| 1210 |
|
| 1211 |
|
| 1212 |
template<typename Scalar> |
| 1213 |
void advectiveVector(Scalar advection[3], const Scalar& x, const Scalar& y, const Scalar& z){ |
| 1214 |
|
| 1215 |
advection[0] = g_advection[0]; |
| 1216 |
advection[1] = g_advection[1]; |
| 1217 |
advection[2] = g_advection[2]; |
| 1218 |
} |
| 1219 |
|
| 1220 |
|
| 1221 |
template<typename Scalar> |
| 1222 |
const Scalar reactionTerm(const Scalar& x, const Scalar& y, const Scalar& z){ |
| 1223 |
return g_reaction; |
| 1224 |
} |
| 1225 |
|
| 1226 |
|
| 1227 |
|
| 1228 |
/************************************************************************************************** |
| 1229 |
* * |
| 1230 |
* Definitions of auxiliary functions that require user-defined functions for * |
| 1231 |
* exact solution, diffusion, advection and reaction terms * |
| 1232 |
* * |
| 1233 |
**************************************************************************************************/ |
| 1234 |
|
| 1235 |
template<typename Scalar> |
| 1236 |
void exactSolutionGrad(Scalar gradExact[3], const Scalar& x, const Scalar& y, const Scalar& z) { |
| 1237 |
|
| 1238 |
// To enable derivatives of the gradient (i.e., 2nd derivatives of the exact solution) need 2 levels of fad types |
| 1239 |
Sacado::Fad::SFad<Scalar,3> fad_x = x; |
| 1240 |
Sacado::Fad::SFad<Scalar,3> fad_y = y; |
| 1241 |
Sacado::Fad::SFad<Scalar,3> fad_z = z; |
| 1242 |
Sacado::Fad::SFad<Scalar,3> u; |
| 1243 |
|
| 1244 |
// Indicate the independent variables |
| 1245 |
fad_x.diff(0,3); |
| 1246 |
fad_y.diff(1,3); |
| 1247 |
fad_z.diff(2,3); |
| 1248 |
|
| 1249 |
u = exactSolution(fad_x, fad_y, fad_z); |
| 1250 |
|
| 1251 |
gradExact[0] = u.dx(0); |
| 1252 |
gradExact[1] = u.dx(1); |
| 1253 |
gradExact[2] = u.dx(2); |
| 1254 |
} |
| 1255 |
|
| 1256 |
|
| 1257 |
|
| 1258 |
template<typename Scalar> |
| 1259 |
const Scalar sourceTerm(Scalar& x, Scalar& y, Scalar& z){ |
| 1260 |
|
| 1261 |
Scalar u; |
| 1262 |
Scalar grad_u[3]; |
| 1263 |
Scalar flux[3] = {0.0, 0.0, 0.0}; |
| 1264 |
Scalar diffusion[3][3]; |
| 1265 |
Scalar advection[3]; |
| 1266 |
Scalar f = 0.; |
| 1267 |
|
| 1268 |
// Indicate the independent variables |
| 1269 |
x.diff(0,3); |
| 1270 |
y.diff(1,3); |
| 1271 |
z.diff(2,3); |
| 1272 |
|
| 1273 |
// Get exact solution and its gradient |
| 1274 |
u = exactSolution(x, y, z); |
| 1275 |
exactSolutionGrad(grad_u, x, y, z); |
| 1276 |
|
| 1277 |
// Get diffusion tensor and advective vector |
| 1278 |
diffusionTensor<Scalar>(diffusion, x, y, z); |
| 1279 |
advectiveVector<Scalar>(advection, x, y, z); |
| 1280 |
|
| 1281 |
// Compute total flux = (K.grad u - b.u) |
| 1282 |
for(int i = 0; i < 3; i++){ |
| 1283 |
|
| 1284 |
// Initialize by the advective flux |
| 1285 |
flux[i] = -advection[i]*u; |
| 1286 |
//flux[i] = 0.; |
| 1287 |
|
| 1288 |
// Add diffusive flux |
| 1289 |
for(int j = 0; j < 3; j++){ |
| 1290 |
flux[i] += diffusion[i][j]*grad_u[j]; |
| 1291 |
} |
| 1292 |
} |
| 1293 |
|
| 1294 |
// Compute source term (right hand side): f = -div(flux) + reactionCoeff*u |
| 1295 |
f = -(flux[0].dx(0) + flux[1].dx(1) + flux[2].dx(2)) + reactionTerm<Scalar>(x, y, z)*u; |
| 1296 |
|
| 1297 |
return f; |
| 1298 |
} |
| 1299 |
|
| 1300 |
|
| 1301 |
|
| 1302 |
/************************************************************************************************** |
| 1303 |
* * |
| 1304 |
* Evaluation methods accepting multidimensional arrays of points * |
| 1305 |
* * |
| 1306 |
**************************************************************************************************/ |
| 1307 |
|
| 1308 |
template<class ArrayOut, class ArrayIn> |
| 1309 |
void evaluateDiffusionTensor(ArrayOut & diffTensorValues, |
| 1310 |
const ArrayIn & evaluationPoints){ |
| 1311 |
|
| 1312 |
int numWorksetCells = evaluationPoints.dimension(0); |
| 1313 |
int numPoints = evaluationPoints.dimension(1); |
| 1314 |
int spaceDim = evaluationPoints.dimension(2); |
| 1315 |
|
| 1316 |
double diffusion[3][3]; |
| 1317 |
|
| 1318 |
for(int cell = 0; cell < numWorksetCells; cell++){ |
| 1319 |
for(int pt = 0; pt < numPoints; pt++){ |
| 1320 |
|
| 1321 |
double x = evaluationPoints(cell, pt, 0); |
| 1322 |
double y = evaluationPoints(cell, pt, 1); |
| 1323 |
double z = evaluationPoints(cell, pt, 2); |
| 1324 |
|
| 1325 |
diffusionTensor<double>(diffusion, x, y, z); |
| 1326 |
|
| 1327 |
for(int row = 0; row < spaceDim; row++){ |
| 1328 |
for(int col = 0; col < spaceDim; col++){ |
| 1329 |
diffTensorValues(cell, pt, row, col) = diffusion[row][col]; |
| 1330 |
} |
| 1331 |
} |
| 1332 |
} |
| 1333 |
} |
| 1334 |
} |
| 1335 |
|
| 1336 |
|
| 1337 |
|
| 1338 |
template<class ArrayOut, class ArrayIn> |
| 1339 |
void evaluateAdvectiveVector(ArrayOut & worksetAdvectionValues, |
| 1340 |
const ArrayIn & evaluationPoints){ |
| 1341 |
|
| 1342 |
int numWorksetCells = evaluationPoints.dimension(0); |
| 1343 |
int numPoints = evaluationPoints.dimension(1); |
| 1344 |
int spaceDim = evaluationPoints.dimension(2); |
| 1345 |
|
| 1346 |
double advection[3]; |
| 1347 |
|
| 1348 |
for(int cell = 0; cell < numWorksetCells; cell++){ |
| 1349 |
for(int pt = 0; pt < numPoints; pt++){ |
| 1350 |
|
| 1351 |
double x = evaluationPoints(cell, pt, 0); |
| 1352 |
double y = evaluationPoints(cell, pt, 1); |
| 1353 |
double z = evaluationPoints(cell, pt, 2); |
| 1354 |
|
| 1355 |
advectiveVector<double>(advection, x, y, z); |
| 1356 |
|
| 1357 |
for(int row = 0; row < spaceDim; row++){ |
| 1358 |
worksetAdvectionValues(cell, pt, row) = advection[row]; |
| 1359 |
} |
| 1360 |
} |
| 1361 |
} |
| 1362 |
} |
| 1363 |
|
| 1364 |
|
| 1365 |
|
| 1366 |
template<class ArrayOut, class ArrayIn> |
| 1367 |
void evaluateReactionCoefficient(ArrayOut & worksetReactionValues, |
| 1368 |
const ArrayIn & evaluationPoints){ |
| 1369 |
|
| 1370 |
int numWorksetCells = evaluationPoints.dimension(0); |
| 1371 |
int numPoints = evaluationPoints.dimension(1); |
| 1372 |
|
| 1373 |
for(int cell = 0; cell < numWorksetCells; cell++){ |
| 1374 |
for(int pt = 0; pt < numPoints; pt++){ |
| 1375 |
|
| 1376 |
double x = evaluationPoints(cell, pt, 0); |
| 1377 |
double y = evaluationPoints(cell, pt, 1); |
| 1378 |
double z = evaluationPoints(cell, pt, 2); |
| 1379 |
|
| 1380 |
worksetReactionValues(cell, pt) = reactionTerm<double>(x, y, z); |
| 1381 |
} |
| 1382 |
} |
| 1383 |
} |
| 1384 |
|
| 1385 |
|
| 1386 |
|
| 1387 |
template<class ArrayOut, class ArrayIn> |
| 1388 |
void evaluateSourceTerm(ArrayOut & sourceTermValues, |
| 1389 |
const ArrayIn & evaluationPoints){ |
| 1390 |
|
| 1391 |
int numWorksetCells = evaluationPoints.dimension(0); |
| 1392 |
int numPoints = evaluationPoints.dimension(1); |
| 1393 |
|
| 1394 |
for(int cell = 0; cell < numWorksetCells; cell++){ |
| 1395 |
for(int pt = 0; pt < numPoints; pt++){ |
| 1396 |
|
| 1397 |
Sacado::Fad::SFad<double,3> x = evaluationPoints(cell, pt, 0); |
| 1398 |
Sacado::Fad::SFad<double,3> y = evaluationPoints(cell, pt, 1); |
| 1399 |
Sacado::Fad::SFad<double,3> z = evaluationPoints(cell, pt, 2); |
| 1400 |
|
| 1401 |
sourceTermValues(cell, pt) = sourceTerm<Sacado::Fad::SFad<double,3> >(x, y, z).val(); |
| 1402 |
} |
| 1403 |
} |
| 1404 |
} |
| 1405 |
|
| 1406 |
|
| 1407 |
|
| 1408 |
template<class ArrayOut, class ArrayIn> |
| 1409 |
void evaluateExactSolution(ArrayOut & exactSolutionValues, |
| 1410 |
const ArrayIn & evaluationPoints){ |
| 1411 |
|
| 1412 |
int numWorksetCells = evaluationPoints.dimension(0); |
| 1413 |
int numPoints = evaluationPoints.dimension(1); |
| 1414 |
|
| 1415 |
for(int cell = 0; cell < numWorksetCells; cell++){ |
| 1416 |
for(int pt = 0; pt < numPoints; pt++){ |
| 1417 |
|
| 1418 |
double x = evaluationPoints(cell, pt, 0); |
| 1419 |
double y = evaluationPoints(cell, pt, 1); |
| 1420 |
double z = evaluationPoints(cell, pt, 2); |
| 1421 |
|
| 1422 |
exactSolutionValues(cell, pt) = exactSolution<double>(x, y, z); |
| 1423 |
} |
| 1424 |
} |
| 1425 |
} |
| 1426 |
|
| 1427 |
|
| 1428 |
|
| 1429 |
template<class ArrayOut, class ArrayIn> |
| 1430 |
void evaluateExactSolutionGrad(ArrayOut & exactSolutionGradValues, |
| 1431 |
const ArrayIn & evaluationPoints){ |
| 1432 |
|
| 1433 |
int numWorksetCells = evaluationPoints.dimension(0); |
| 1434 |
int numPoints = evaluationPoints.dimension(1); |
| 1435 |
int spaceDim = evaluationPoints.dimension(2); |
| 1436 |
|
| 1437 |
double gradient[3]; |
| 1438 |
|
| 1439 |
for(int cell = 0; cell < numWorksetCells; cell++){ |
| 1440 |
for(int pt = 0; pt < numPoints; pt++){ |
| 1441 |
|
| 1442 |
double x = evaluationPoints(cell, pt, 0); |
| 1443 |
double y = evaluationPoints(cell, pt, 1); |
| 1444 |
double z = evaluationPoints(cell, pt, 2); |
| 1445 |
|
| 1446 |
exactSolutionGrad<double>(gradient, x, y, z); |
| 1447 |
|
| 1448 |
for(int row = 0; row < spaceDim; row++){ |
| 1449 |
exactSolutionGradValues(cell, pt, row) = gradient[row]; |
| 1450 |
} |
| 1451 |
} |
| 1452 |
} |
| 1453 |
} |
| 1454 |
|
| 1455 |
|
| 1456 |
/************************************************************************************************** |
| 1457 |
* * |
| 1458 |
* Solver part * |
| 1459 |
* * |
| 1460 |
**************************************************************************************************/ |
| 1461 |
|
| 1462 |
// Test ML |
| 1463 |
int TestMultiLevelPreconditioner(char ProblemType[], |
| 1464 |
Teuchos::ParameterList & MLList, |
| 1465 |
Epetra_CrsMatrix & A, |
| 1466 |
const Epetra_MultiVector & xexact, |
| 1467 |
Epetra_MultiVector & b, |
| 1468 |
Epetra_MultiVector & uh, |
| 1469 |
double & TotalErrorResidual, |
| 1470 |
double & TotalErrorExactSol) |
| 1471 |
{ |
| 1472 |
Epetra_MultiVector x(xexact); |
| 1473 |
x.PutScalar(0.0); |
| 1474 |
|
| 1475 |
Epetra_LinearProblem Problem(&A,&x,&b); |
| 1476 |
Epetra_MultiVector* lhs = Problem.GetLHS(); |
| 1477 |
Epetra_MultiVector* rhs = Problem.GetRHS(); |
| 1478 |
|
| 1479 |
Epetra_Time Time(A.Comm()); |
| 1480 |
|
| 1481 |
// =================== // |
| 1482 |
// call ML and AztecOO // |
| 1483 |
// =================== // |
| 1484 |
|
| 1485 |
AztecOO solver(Problem); |
| 1486 |
ML_Epetra::MultiLevelPreconditioner *MLPrec = new ML_Epetra::MultiLevelPreconditioner(A, MLList, true); |
| 1487 |
|
| 1488 |
// tell AztecOO to use this preconditioner, then solve |
| 1489 |
solver.SetPrecOperator(MLPrec); |
| 1490 |
solver.SetAztecOption(AZ_solver, AZ_gmres); |
| 1491 |
solver.SetAztecOption(AZ_output, 10); |
| 1492 |
|
| 1493 |
solver.Iterate(500, 1e-10); |
| 1494 |
|
| 1495 |
delete MLPrec; |
| 1496 |
|
| 1497 |
uh = *lhs; |
| 1498 |
|
| 1499 |
// ==================================================== // |
| 1500 |
// compute difference between exact solution and ML one // |
| 1501 |
// ==================================================== // |
| 1502 |
double d = 0.0, d_tot = 0.0; |
| 1503 |
for( int i=0 ; i<lhs->Map().NumMyElements() ; ++i ) |
| 1504 |
d += ((*lhs)[0][i] - xexact[0][i]) * ((*lhs)[0][i] - xexact[0][i]); |
| 1505 |
|
| 1506 |
A.Comm().SumAll(&d,&d_tot,1); |
| 1507 |
|
| 1508 |
// ================== // |
| 1509 |
// compute ||Ax - b|| // |
| 1510 |
// ================== // |
| 1511 |
double Norm; |
| 1512 |
Epetra_Vector Ax(rhs->Map()); |
| 1513 |
A.Multiply(false, *lhs, Ax); |
| 1514 |
Ax.Update(1.0, *rhs, -1.0); |
| 1515 |
Ax.Norm2(&Norm); |
| 1516 |
|
| 1517 |
string msg = ProblemType; |
| 1518 |
|
| 1519 |
if (A.Comm().MyPID() == 0) { |
| 1520 |
cout << msg << endl << "......Using " << A.Comm().NumProc() << " processes" << endl; |
| 1521 |
cout << msg << "......||A x - b||_2 = " << Norm << endl; |
| 1522 |
cout << msg << "......||x_exact - x||_2 = " << sqrt(d_tot) << endl; |
| 1523 |
cout << msg << "......Total Time = " << Time.ElapsedTime() << endl; |
| 1524 |
} |
| 1525 |
|
| 1526 |
TotalErrorExactSol += sqrt(d_tot); |
| 1527 |
TotalErrorResidual += Norm; |
| 1528 |
|
| 1529 |
return( solver.NumIters() ); |
| 1530 |
|
| 1531 |
} |
| 1532 |
|
| 1533 |
|
| 1534 |
/*************************************************************************************************** |
| 1535 |
* * |
| 1536 |
* Pamgen mesh * |
| 1537 |
* * |
| 1538 |
**************************************************************************************************/ |
| 1539 |
|
| 1540 |
template<class Scalar> |
| 1541 |
void getPamgenMesh(FieldContainer<Scalar> & localNodeCoordsFC, |
| 1542 |
FieldContainer<long long> & localCellToNodeFC, |
| 1543 |
FieldContainer<int> & nodeOnBoundaryFC, |
| 1544 |
FieldContainer<bool> & nodeIsOwnedFC, |
| 1545 |
FieldContainer<long long> & globalNodeIdsFC, |
| 1546 |
const std::string & meshInput, |
| 1547 |
const int & procRank, |
| 1548 |
const int & numProcs, |
| 1549 |
const Epetra_Comm & Comm, |
| 1550 |
Epetra_Time & Time, |
| 1551 |
const string & message, |
| 1552 |
const int verbose) { |
| 1553 |
|
| 1554 |
typedef long long int128; |
| 1555 |
|
| 1556 |
// All cells in a Pamgen grid have Hexahedron<8> type. |
| 1557 |
ShardsCellTopology hex_8(shards::getCellTopologyData<shards::Hexahedron<8> >() ); |
| 1558 |
int spaceDim = hex_8.getDimension(); |
| 1559 |
|
| 1560 |
if (!Comm.MyPID() && verbose) { |
| 1561 |
std::cout << message << "Generating Pamgen mesh ... \n\n"; Time.ResetStartTime(); |
| 1562 |
} |
| 1563 |
|
| 1564 |
// Error flag |
| 1565 |
int pamgenError = 0; |
| 1566 |
|
| 1567 |
// Generate mesh with Pamgen |
| 1568 |
int128 maxInt = 9223372036854775807LL; |
| 1569 |
int128 * node_comm_proc_ids = NULL; |
| 1570 |
int128 * node_cmap_node_cnts = NULL; |
| 1571 |
int128 * node_cmap_ids = NULL; |
| 1572 |
int128 ** comm_node_ids = NULL; |
| 1573 |
int128 ** comm_node_proc_ids = NULL; |
| 1574 |
|
| 1575 |
|
| 1576 |
long long cr_result = Create_Pamgen_Mesh(meshInput.c_str(), spaceDim, procRank, numProcs, maxInt); |
| 1577 |
TrilinosCouplings::pamgen_error_check(std::cout,cr_result); |
| 1578 |
|
| 1579 |
if(!Comm.MyPID() && verbose ) { |
| 1580 |
std::cout << message << " Timing of Pamgen tasks: \n\n" ; |
| 1581 |
std::cout << " Pamgen Setup: " << Time.ElapsedTime() << " sec.\n"; |
| 1582 |
Time.ResetStartTime(); |
| 1583 |
} |
| 1584 |
|
| 1585 |
|
| 1586 |
/*************************************************************************************************** |
| 1587 |
* * |
| 1588 |
* Process local element blocks: local to the rank processor for which mesh was created * |
| 1589 |
* * |
| 1590 |
**************************************************************************************************/ |
| 1591 |
|
| 1592 |
// Get local mesh data: limited to entities local to the rank processor |
| 1593 |
char title[100]; |
| 1594 |
int128 numDim; |
| 1595 |
int128 numNodesLocal; |
| 1596 |
int128 numGridCellsLocal; |
| 1597 |
int128 numElemBlkLocal; |
| 1598 |
int128 numNodeSetsLocal; |
| 1599 |
int128 numSideSetsLocal; |
| 1600 |
int id = 0; |
| 1601 |
|
| 1602 |
pamgenError += im_ex_get_init_l(id, title, |
| 1603 |
&numDim, &numNodesLocal, &numGridCellsLocal, |
| 1604 |
&numElemBlkLocal, &numNodeSetsLocal, &numSideSetsLocal); |
| 1605 |
|
| 1606 |
// Get local element block data: retrieve element node count, connectivity, etc on this processor |
| 1607 |
int128 * block_ids = new int128 [numElemBlkLocal]; |
| 1608 |
int128 * nodes_per_element = new int128 [numElemBlkLocal]; |
| 1609 |
int128 * element_attributes = new int128 [numElemBlkLocal]; |
| 1610 |
int128 * elements = new int128 [numElemBlkLocal]; |
| 1611 |
char ** element_types = new char * [numElemBlkLocal]; |
| 1612 |
int128 ** elmt_node_linkage = new int128 * [numElemBlkLocal]; |
| 1613 |
|
| 1614 |
// First get the ids of the element blocks on this processor |
| 1615 |
pamgenError += im_ex_get_elem_blk_ids_l(id, block_ids); |
| 1616 |
|
| 1617 |
// Then get the mesh data for each one of the blocks on this processor |
| 1618 |
for(int128 i = 0; i < numElemBlkLocal; i ++){ |
| 1619 |
element_types[i] = new char [MAX_STR_LENGTH + 1]; |
| 1620 |
pamgenError += im_ex_get_elem_block_l(id, |
| 1621 |
block_ids[i], |
| 1622 |
element_types[i], |
| 1623 |
(int128*) & (elements[i]), |
| 1624 |
(int128*) & (nodes_per_element[i]), |
| 1625 |
(int128*) & (element_attributes[i])); |
| 1626 |
} |
| 1627 |
|
| 1628 |
// Get connectivity of the elements in each block |
| 1629 |
for(int128 b = 0; b < numElemBlkLocal; b++){ |
| 1630 |
elmt_node_linkage[b] = new int128 [nodes_per_element[b]*elements[b]]; |
| 1631 |
pamgenError += im_ex_get_elem_conn_l(id, |
| 1632 |
block_ids[b], |
| 1633 |
elmt_node_linkage[b]); |
| 1634 |
} |
| 1635 |
|
| 1636 |
// Copy element-to-node connectivity to multi-dimensional array: collect connectivity from all element |
| 1637 |
// blocks. This requires all blocks to have the same number of nodes per element! |
| 1638 |
int telct = 0; |
| 1639 |
int numNodesPerElem = nodes_per_element[0]; // This will not work if blocks have elements with diff. node counts! |
| 1640 |
localCellToNodeFC.resize(numGridCellsLocal,numNodesPerElem); |
| 1641 |
|
| 1642 |
for(int128 b = 0; b < numElemBlkLocal; b++){ |
| 1643 |
for(int128 el = 0; el < elements[b]; el++){ |
| 1644 |
for (int j = 0; j < numNodesPerElem; j++) { |
| 1645 |
localCellToNodeFC(telct,j) = elmt_node_linkage[b][el*numNodesPerElem + j]-1; |
| 1646 |
} |
| 1647 |
telct ++; |
| 1648 |
} |
| 1649 |
} |
| 1650 |
|
| 1651 |
// Read node coordinates for this processor and place in field container |
| 1652 |
localNodeCoordsFC.resize(numNodesLocal,spaceDim); |
| 1653 |
|
| 1654 |
double * nodeCoordx = new double [numNodesLocal]; |
| 1655 |
double * nodeCoordy = new double [numNodesLocal]; |
| 1656 |
double * nodeCoordz = new double [numNodesLocal]; |
| 1657 |
|
| 1658 |
pamgenError += im_ex_get_coord_l(id,nodeCoordx,nodeCoordy,nodeCoordz); |
| 1659 |
|
| 1660 |
for (int i=0; i<numNodesLocal; i++) { |
| 1661 |
localNodeCoordsFC(i,0) = nodeCoordx[i]; |
| 1662 |
localNodeCoordsFC(i,1) = nodeCoordy[i]; |
| 1663 |
localNodeCoordsFC(i,2) = nodeCoordz[i]; |
| 1664 |
} |
| 1665 |
delete [] nodeCoordx; |
| 1666 |
delete [] nodeCoordy; |
| 1667 |
delete [] nodeCoordz; |
| 1668 |
|
| 1669 |
|
| 1670 |
/*************************************************************************************************** |
| 1671 |
* * |
| 1672 |
* Parallel info: get global mesh data * |
| 1673 |
* * |
| 1674 |
**************************************************************************************************/ |
| 1675 |
|
| 1676 |
// Get global mesh data: retrieve mesh sizing information for the complete (global) mesh data base |
| 1677 |
int128 numNodesGlobal; |
| 1678 |
int128 numGridCellsGlobal; |
| 1679 |
int128 numElemBlkGlobal; |
| 1680 |
int128 numNodeSetsGlobal; |
| 1681 |
int128 numSideSetsGlobal; |
| 1682 |
|
| 1683 |
pamgenError += im_ne_get_init_global_l(id, |
| 1684 |
&numNodesGlobal, &numGridCellsGlobal, &numElemBlkGlobal, |
| 1685 |
&numNodeSetsGlobal, &numSideSetsGlobal); |
| 1686 |
|
| 1687 |
int128 num_internal_nodes; |
| 1688 |
int128 num_border_nodes; |
| 1689 |
int128 num_external_nodes; |
| 1690 |
int128 num_internal_elems; |
| 1691 |
int128 num_border_elems; |
| 1692 |
int128 num_node_comm_maps; |
| 1693 |
int128 num_elem_comm_maps; |
| 1694 |
|
| 1695 |
// Get sizing information for processor communication data. This is the first step in gathering |
| 1696 |
// all the information required to construct communication protocols between adjacent regions of decomposed mesh. |
| 1697 |
pamgenError += im_ne_get_loadbal_param_l( id, |
| 1698 |
&num_internal_nodes, |
| 1699 |
&num_border_nodes, |
| 1700 |
&num_external_nodes, |
| 1701 |
&num_internal_elems, |
| 1702 |
&num_border_elems, |
| 1703 |
&num_node_comm_maps, |
| 1704 |
&num_elem_comm_maps, |
| 1705 |
0/*unused*/ ); |
| 1706 |
|
| 1707 |
if(num_node_comm_maps > 0){ |
| 1708 |
node_comm_proc_ids = new int128 [num_node_comm_maps]; |
| 1709 |
node_cmap_node_cnts = new int128 [num_node_comm_maps]; |
| 1710 |
node_cmap_ids = new int128 [num_node_comm_maps]; |
| 1711 |
comm_node_ids = new int128* [num_node_comm_maps]; |
| 1712 |
comm_node_proc_ids = new int128* [num_node_comm_maps]; |
| 1713 |
|
| 1714 |
int128 * elem_cmap_ids = new int128 [num_elem_comm_maps]; |
| 1715 |
int128 * elem_cmap_elem_cnts = new int128 [num_elem_comm_maps]; |
| 1716 |
|
| 1717 |
// Get communication maps and ids |
| 1718 |
if( im_ne_get_cmap_params_l(id, |
| 1719 |
node_cmap_ids, |
| 1720 |
(int128*)node_cmap_node_cnts, |
| 1721 |
elem_cmap_ids, |
| 1722 |
(int128*)elem_cmap_elem_cnts, |
| 1723 |
0/*not used proc_id*/ ) < 0 ) ++pamgenError; |
| 1724 |
|
| 1725 |
for(int128 j = 0; j < num_node_comm_maps; j++) { |
| 1726 |
comm_node_ids[j] = new int128 [node_cmap_node_cnts[j]]; |
| 1727 |
comm_node_proc_ids[j] = new int128 [node_cmap_node_cnts[j]]; |
| 1728 |
|
| 1729 |
// Get node communication map |
| 1730 |
if( im_ne_get_node_cmap_l(id, |
| 1731 |
node_cmap_ids[j], |
| 1732 |
comm_node_ids[j], |
| 1733 |
comm_node_proc_ids[j], |
| 1734 |
0/*not used proc_id*/ ) < 0 ) ++pamgenError; |
| 1735 |
node_comm_proc_ids[j] = comm_node_proc_ids[j][0]; |
| 1736 |
} |
| 1737 |
delete [] elem_cmap_ids; |
| 1738 |
delete [] elem_cmap_elem_cnts; |
| 1739 |
} |
| 1740 |
|
| 1741 |
if(!Comm.MyPID() && verbose) { |
| 1742 |
std::cout << " Mesh Queries: " << Time.ElapsedTime() << " sec.\n"; |
| 1743 |
Time.ResetStartTime(); |
| 1744 |
} |
| 1745 |
|
| 1746 |
|
| 1747 |
//Calculate global node ids |
| 1748 |
int128 * globalNodeIds = new int128[numNodesLocal]; |
| 1749 |
bool * nodeIsOwned = new bool[numNodesLocal]; |
| 1750 |
|
| 1751 |
calc_global_node_ids(globalNodeIds, |
| 1752 |
nodeIsOwned, |
| 1753 |
numNodesLocal, |
| 1754 |
num_node_comm_maps, |
| 1755 |
node_cmap_node_cnts, |
| 1756 |
node_comm_proc_ids, |
| 1757 |
comm_node_ids, |
| 1758 |
procRank); |
| 1759 |
|
| 1760 |
if(!Comm.MyPID() && verbose) { |
| 1761 |
std::cout << " Calculating Global Node Nums: " << Time.ElapsedTime() << " sec.\n"; |
| 1762 |
Time.ResetStartTime(); |
| 1763 |
} |
| 1764 |
|
| 1765 |
|
| 1766 |
// Container indicating whether a node is owned or ghost (1-yes 0-no) |
| 1767 |
nodeIsOwnedFC.resize(numNodesLocal); |
| 1768 |
globalNodeIdsFC.resize(numNodesLocal); |
| 1769 |
|
| 1770 |
for(int128 i = 0; i < numNodesLocal; i++){ |
| 1771 |
nodeIsOwnedFC(i) = nodeIsOwned[i]; |
| 1772 |
globalNodeIdsFC(i) = globalNodeIds[i]; |
| 1773 |
} |
| 1774 |
|
| 1775 |
if(!Comm.MyPID() && verbose) { |
| 1776 |
std::cout << " Processing Owned Nodes: " << Time.ElapsedTime() << " sec.\n"; |
| 1777 |
Time.ResetStartTime(); |
| 1778 |
} |
| 1779 |
|
| 1780 |
|
| 1781 |
// Get boundary (side set) information |
| 1782 |
int128 * sideSetIds = new int128 [numSideSetsLocal]; |
| 1783 |
int128 numSidesInSet; |
| 1784 |
int128 numDFinSet; |
| 1785 |
|
| 1786 |
pamgenError += im_ex_get_side_set_ids_l(id,sideSetIds); |
| 1787 |
|
| 1788 |
|
| 1789 |
// Container indicating whether a node is on the boundary (1-yes 0-no). |
| 1790 |
nodeOnBoundaryFC.resize(numNodesLocal); |
| 1791 |
|
| 1792 |
for (int i = 0; i < numSideSetsLocal; i++) { |
| 1793 |
pamgenError += im_ex_get_side_set_param_l(id, sideSetIds[i], &numSidesInSet, &numDFinSet); |
| 1794 |
if (numSidesInSet > 0){ |
| 1795 |
int128 * sideSetElemList = new int128 [numSidesInSet]; |
| 1796 |
int128 * sideSetSideList = new int128 [numSidesInSet]; |
| 1797 |
im_ex_get_side_set_l(id,sideSetIds[i],sideSetElemList,sideSetSideList); |
| 1798 |
for (int j=0; j<numSidesInSet; j++) { |
| 1799 |
|
| 1800 |
int sideNode0 = hex_8.getNodeMap(2, sideSetSideList[j]-1, 0); |
| 1801 |
int sideNode1 = hex_8.getNodeMap(2, sideSetSideList[j]-1, 1); |
| 1802 |
int sideNode2 = hex_8.getNodeMap(2, sideSetSideList[j]-1, 2); |
| 1803 |
int sideNode3 = hex_8.getNodeMap(2, sideSetSideList[j]-1, 3); |
| 1804 |
|
| 1805 |
nodeOnBoundaryFC(localCellToNodeFC(sideSetElemList[j]-1,sideNode0))=1; |
| 1806 |
nodeOnBoundaryFC(localCellToNodeFC(sideSetElemList[j]-1,sideNode1))=1; |
| 1807 |
nodeOnBoundaryFC(localCellToNodeFC(sideSetElemList[j]-1,sideNode2))=1; |
| 1808 |
nodeOnBoundaryFC(localCellToNodeFC(sideSetElemList[j]-1,sideNode3))=1; |
| 1809 |
} |
| 1810 |
delete [] sideSetElemList; |
| 1811 |
delete [] sideSetSideList; |
| 1812 |
} |
| 1813 |
} |
| 1814 |
delete [] sideSetIds; |
| 1815 |
|
| 1816 |
if(!Comm.MyPID() && verbose) { |
| 1817 |
std::cout << "Processing Boundary Conditions: " << Time.ElapsedTime() << " sec.\n"; |
| 1818 |
Time.ResetStartTime(); |
| 1819 |
} |
| 1820 |
|
| 1821 |
// Print mesh information |
| 1822 |
if (!Comm.MyPID()){ |
| 1823 |
std::cout << " Number of Global Elements: " << numGridCellsGlobal << " \n"; |
| 1824 |
std::cout << " Number of Global Nodes: " << numNodesGlobal << " \n\n"; |
| 1825 |
} |
| 1826 |
|
| 1827 |
|
| 1828 |
#ifdef DUMP_DATA |
| 1829 |
// Print coords |
| 1830 |
|
| 1831 |
std::stringstream fname; |
| 1832 |
fname << "nodeCoords"; |
| 1833 |
fname << Comm.MyPID() << ".dat"; |
| 1834 |
FILE *f=fopen(fname.str().c_str(),"w"); |
| 1835 |
for (int i=0; i<numNodesLocal; i++) { |
| 1836 |
if (nodeIsOwned[i]) { |
| 1837 |
fprintf(f,"%22.16e %22.16e %22.16e\n", localNodeCoordsFC(i,0),localNodeCoordsFC(i,1),localNodeCoordsFC(i,2)); |
| 1838 |
} |
| 1839 |
} |
| 1840 |
fclose(f); |
| 1841 |
|
| 1842 |
// Output element to node connectivity |
| 1843 |
std::stringstream efname; |
| 1844 |
efname << "elem2node"; |
| 1845 |
efname << Comm.MyPID() << ".dat"; |
| 1846 |
ofstream el2nout(efname.str().c_str()); |
| 1847 |
for (int i=0; i<numGridCellsLocal; i++) { |
| 1848 |
for (int m=0; m<numNodesPerElem; m++) { |
| 1849 |
el2nout << globalNodeIds[localCellToNodeFC(i,m)] << " "; |
| 1850 |
} |
| 1851 |
el2nout << "\n"; |
| 1852 |
} |
| 1853 |
el2nout.close(); |
| 1854 |
#endif |
| 1855 |
|
| 1856 |
|
| 1857 |
// Delete mesh & clean up |
| 1858 |
for(int128 b = 0; b < numElemBlkLocal; b++){ |
| 1859 |
delete [] elmt_node_linkage[b]; |
| 1860 |
delete [] element_types[b]; |
| 1861 |
} |
| 1862 |
delete [] nodeIsOwned; |
| 1863 |
delete [] block_ids; |
| 1864 |
delete [] nodes_per_element; |
| 1865 |
delete [] element_attributes; |
| 1866 |
delete [] element_types; |
| 1867 |
delete [] elmt_node_linkage; |
| 1868 |
delete [] elements; |
| 1869 |
delete [] globalNodeIds; |
| 1870 |
|
| 1871 |
if(num_node_comm_maps > 0){ |
| 1872 |
delete [] node_comm_proc_ids; |
| 1873 |
delete [] node_cmap_node_cnts; |
| 1874 |
delete [] node_cmap_ids; |
| 1875 |
for(int128 i=0;i<num_node_comm_maps;i++){ |
| 1876 |
delete [] comm_node_ids[i]; |
| 1877 |
delete [] comm_node_proc_ids[i]; |
| 1878 |
} |
| 1879 |
delete [] comm_node_ids; |
| 1880 |
delete [] comm_node_proc_ids; |
| 1881 |
} |
| 1882 |
|
| 1883 |
Delete_Pamgen_Mesh(); |
| 1884 |
|
| 1885 |
TEUCHOS_TEST_FOR_EXCEPTION( !(pamgenError == 0), std::runtime_error, " Pamgen error... Exiting!"); |
| 1886 |
}// *** PAMGEN wrapper *** |
| 1887 |
|
| 1888 |
/************************************************************************************************** |
| 1889 |
* * |
| 1890 |
* Argument input * |
| 1891 |
* * |
| 1892 |
**************************************************************************************************/ |
| 1893 |
void getInputArguments(Teuchos::ParameterList & inputMeshList, |
| 1894 |
std::string & meshInput, |
| 1895 |
Teuchos::ParameterList & inputSolverList, |
| 1896 |
int & argc, |
| 1897 |
char * argv[], |
| 1898 |
const Epetra_Comm & Comm, |
| 1899 |
const std::string & inputMeshFile, |
| 1900 |
const std::string & inputSolverFile){ |
| 1901 |
|
| 1902 |
// Command line for xml file, otherwise use default |
| 1903 |
std::string xmlMeshInFileName, xmlSolverInFileName; |
| 1904 |
|
| 1905 |
//Check number of arguments |
| 1906 |
if (argc > 3) { |
| 1907 |
std::cout << "\n>>> ERROR: Invalid number of arguments.\n\n"; |
| 1908 |
std::cout << "Usage:\n\n"; |
| 1909 |
std::cout << " ./TrilinosCouplings_examples_scaling_Example_StabilizedADR.exe [meshfile.xml] [solver.xml]\n\n"; |
| 1910 |
std::cout << " meshfile.xml(optional) - xml file with description of Pamgen mesh\n\n"; |
| 1911 |
std::cout << " solver.xml(optional) - xml file with ML solver options\n\n"; |
| 1912 |
TEUCHOS_TEST_FOR_EXCEPTION( argc == 3, std::invalid_argument, " ...exiting!"); |
| 1913 |
} |
| 1914 |
|
| 1915 |
// Solver is specified |
| 1916 |
if(argc >= 3) xmlSolverInFileName = string(argv[2]); |
| 1917 |
else xmlSolverInFileName = inputSolverFile; |
| 1918 |
|
| 1919 |
// Custom mesh file is specified |
| 1920 |
if(argc >= 2) xmlMeshInFileName = string(argv[1]); |
| 1921 |
else xmlMeshInFileName = inputMeshFile; |
| 1922 |
|
| 1923 |
if(xmlMeshInFileName.length()) { |
| 1924 |
if (!Comm.MyPID()) { |
| 1925 |
std::cout << "\nReading parameter list from the XML file \""<< xmlMeshInFileName << "\" ...\n\n"; |
| 1926 |
} |
| 1927 |
Teuchos::updateParametersFromXmlFile (xmlMeshInFileName, Teuchos::ptr (&inputMeshList)); |
| 1928 |
|
| 1929 |
if (!Comm.MyPID()) { |
| 1930 |
inputMeshList.print(std::cout, 2, true, true); |
| 1931 |
std::cout << "\n"; |
| 1932 |
} |
| 1933 |
} |
| 1934 |
else{ |
| 1935 |
std::cout << "Cannot read input file: " << xmlMeshInFileName << "\n"; |
| 1936 |
TEUCHOS_TEST_FOR_EXCEPTION( true, std::invalid_argument, " ...exiting!"); |
| 1937 |
} |
| 1938 |
|
| 1939 |
if(xmlSolverInFileName.length()) { |
| 1940 |
if (!Comm.MyPID()){ |
| 1941 |
std::cout << "\nReading parameter list from the XML file \""<<xmlSolverInFileName<<"\" ...\n\n"; |
| 1942 |
} |
| 1943 |
Teuchos::updateParametersFromXmlFile (xmlSolverInFileName, Teuchos::ptr (&inputSolverList)); |
| 1944 |
} |
| 1945 |
else if (!Comm.MyPID()) { |
| 1946 |
std::cout << "Using default solver values ..." << std::endl; |
| 1947 |
} |
| 1948 |
|
| 1949 |
// Get pamgen mesh definition |
| 1950 |
meshInput = Teuchos::getParameter<std::string>(inputMeshList,"meshInput"); |
| 1951 |
|
| 1952 |
} |
| 1953 |
|
| 1954 |
|
| 1955 |
|
| 1956 |
|
| 1957 |
|
| 1958 |
|
| 1959 |
|
| 1960 |
|
| 1961 |
|
| 1962 |
|
| 1963 |
|
| 1964 |
|
| 1965 |
|
| 1966 |
|
| 1967 |
|