| 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_CurlLSFEM.cpp |
| 11 |
\brief Example solution of a div-curl system on a hexahedral mesh 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 |
For more details on the formulation see |
| 23 |
|
| 24 |
\li P. Bochev, K. Peterson, C. Siefert, "Analysis and Computation |
| 25 |
of Compatible Least-Squares Methods for Div-Curl Equations", |
| 26 |
SIAM J. Numerical Analysis, vol 49, pp 159-191, 2011. |
| 27 |
|
| 28 |
|
| 29 |
\verbatim |
| 30 |
|
| 31 |
Div-Curl System: |
| 32 |
|
| 33 |
curl u = g in Omega |
| 34 |
div u = h in Omega |
| 35 |
u x n = 0 on Gamma |
| 36 |
|
| 37 |
Corresponding discrete linear system for edge element coeficients (x): |
| 38 |
|
| 39 |
(Kc + Mc*Dg*MgInv*Dg'*Mc)x = b |
| 40 |
|
| 41 |
Kc - Hcurl stiffness matrix |
| 42 |
Mc - Hcurl mass matrix |
| 43 |
Dg - Node to edge incidence matrix |
| 44 |
MgInv - Hgrad mass matrix inverse |
| 45 |
b - right hand side vector |
| 46 |
|
| 47 |
\endverbatim |
| 48 |
|
| 49 |
\author Created by P. Bochev, D. Ridzal, K. Peterson, D. Hensinger, C. Siefert. |
| 50 |
|
| 51 |
\remark Usage |
| 52 |
\verbatim |
| 53 |
|
| 54 |
./TrilinosCouplings_examples_scaling_Example_CurlLSFEM.exe inputfile.xml |
| 55 |
|
| 56 |
|
| 57 |
inputfile.xml (optional) - xml input file containing Pamgen mesh description |
| 58 |
and material parameters for each Pamgen block, |
| 59 |
if not present code attempts to read CurlLSFEMin.xml. |
| 60 |
|
| 61 |
\endverbatim |
| 62 |
|
| 63 |
Input files available in Trilinos for use with the CurlLSFEM driver: |
| 64 |
|
| 65 |
\li CurlLSFEMin.xml - basic input file with box mesh and one mesh block |
| 66 |
\li Ninja.xml - input file with distorted mesh (shaped like Ninja star) and one mesh block |
| 67 |
\li CurlLSFEMblock_in_block.xml - input file with box mesh with a center block with different material values. |
| 68 |
|
| 69 |
**/ |
| 70 |
|
| 71 |
/**************************************************************/ |
| 72 |
/* Includes */ |
| 73 |
/**************************************************************/ |
| 74 |
// TrilinosCouplings includes |
| 75 |
#include "TrilinosCouplings_config.h" |
| 76 |
#include "TrilinosCouplings_Pamgen_Utils.hpp" |
| 77 |
|
| 78 |
// Intrepid includes |
| 79 |
#include "Intrepid_FunctionSpaceTools.hpp" |
| 80 |
#include "Intrepid_FieldContainer.hpp" |
| 81 |
#include "Intrepid_CellTools.hpp" |
| 82 |
#include "Intrepid_ArrayTools.hpp" |
| 83 |
#include "Intrepid_HCURL_HEX_I1_FEM.hpp" |
| 84 |
#include "Intrepid_HGRAD_HEX_C1_FEM.hpp" |
| 85 |
#include "Intrepid_RealSpaceTools.hpp" |
| 86 |
#include "Intrepid_DefaultCubatureFactory.hpp" |
| 87 |
#include "Intrepid_Utils.hpp" |
| 88 |
|
| 89 |
// Epetra includes |
| 90 |
#include "Epetra_Time.h" |
| 91 |
#include "Epetra_Map.h" |
| 92 |
#ifdef HAVE_MPI |
| 93 |
#include "Epetra_MpiComm.h" |
| 94 |
#else |
| 95 |
#include "Epetra_SerialComm.h" |
| 96 |
#endif |
| 97 |
#include "Epetra_Import.h" |
| 98 |
#include "Epetra_Export.h" |
| 99 |
#include "Epetra_FECrsMatrix.h" |
| 100 |
#include "Epetra_FEVector.h" |
| 101 |
#include "Epetra_LinearProblem.h" |
| 102 |
|
| 103 |
// Teuchos includes |
| 104 |
#include "Teuchos_oblackholestream.hpp" |
| 105 |
#include "Teuchos_RCP.hpp" |
| 106 |
#include "Teuchos_ArrayRCP.hpp" |
| 107 |
#include "Teuchos_BLAS.hpp" |
| 108 |
#include "Teuchos_GlobalMPISession.hpp" |
| 109 |
#include "Teuchos_ParameterList.hpp" |
| 110 |
#include "Teuchos_XMLParameterListHelpers.hpp" |
| 111 |
|
| 112 |
|
| 113 |
// Shards includes |
| 114 |
#include "Shards_CellTopology.hpp" |
| 115 |
|
| 116 |
// EpetraExt includes |
| 117 |
#include "EpetraExt_RowMatrixOut.h" |
| 118 |
#include "EpetraExt_MultiVectorOut.h" |
| 119 |
#include "EpetraExt_VectorOut.h" |
| 120 |
|
| 121 |
// AztecOO includes |
| 122 |
#include "AztecOO.h" |
| 123 |
|
| 124 |
// ML Includes |
| 125 |
#include "ml_MultiLevelPreconditioner.h" |
| 126 |
#include "ml_RefMaxwell_11_Operator.h" |
| 127 |
#include "ml_RefMaxwell.h" |
| 128 |
#include "ml_EdgeMatrixFreePreconditioner.h" |
| 129 |
#include "ml_epetra_utils.h" |
| 130 |
|
| 131 |
// Pamgen includes |
| 132 |
#include "create_inline_mesh.h" |
| 133 |
#include "pamgen_im_exodusII_l.h" |
| 134 |
#include "pamgen_im_ne_nemesisI_l.h" |
| 135 |
#include "pamgen_extras.h" |
| 136 |
|
| 137 |
|
| 138 |
#define ABS(x) ((x)>0?(x):-(x)) |
| 139 |
|
| 140 |
using Teuchos::rcp; |
| 141 |
using Teuchos::ArrayRCP; |
| 142 |
|
| 143 |
|
| 144 |
/*** Uncomment if you would like output data for plotting ***/ |
| 145 |
//#define DUMP_DATA |
| 146 |
|
| 147 |
using namespace std; |
| 148 |
using namespace Intrepid; |
| 149 |
|
| 150 |
|
| 151 |
/*********************************************************/ |
| 152 |
/* Typedefs */ |
| 153 |
/*********************************************************/ |
| 154 |
typedef Intrepid::FunctionSpaceTools IntrepidFSTools; |
| 155 |
typedef Intrepid::RealSpaceTools<double> IntrepidRSTools; |
| 156 |
typedef Intrepid::CellTools<double> IntrepidCTools; |
| 157 |
|
| 158 |
|
| 159 |
struct fecomp{ |
| 160 |
bool operator () ( topo_entity* x, topo_entity* y )const |
| 161 |
{ |
| 162 |
if(x->sorted_local_node_ids < y->sorted_local_node_ids)return true; |
| 163 |
return false; |
| 164 |
} |
| 165 |
}; |
| 166 |
|
| 167 |
/**********************************************************************************/ |
| 168 |
/***************** FUNCTION DECLARATION FOR ML PRECONDITIONER *********************/ |
| 169 |
/**********************************************************************************/ |
| 170 |
|
| 171 |
/** \brief ML Preconditioner |
| 172 |
|
| 173 |
\param ProblemType [in] problem type |
| 174 |
\param MLList [in] ML parameter list |
| 175 |
\param CurlCurl [in] H(curl) stiffness matrix |
| 176 |
\param D0clean [in] Edge to node stiffness matrix |
| 177 |
\param M0inv [in] H(grad) mass matrix inverse |
| 178 |
\param M1 [in] H(curl) mass matrix |
| 179 |
\param xh [out] solution vector |
| 180 |
\param b [in] right-hand-side vector |
| 181 |
\param TotalErrorResidual [out] error residual |
| 182 |
\param TotalErrorExactSol [out] error in xh |
| 183 |
|
| 184 |
*/ |
| 185 |
void TestMultiLevelPreconditioner_CurlLSFEM(char ProblemType[], |
| 186 |
Teuchos::ParameterList & MLList, |
| 187 |
Epetra_CrsMatrix & CurlCurl, |
| 188 |
Epetra_CrsMatrix & D0clean, |
| 189 |
Epetra_CrsMatrix & M0inv, |
| 190 |
Epetra_CrsMatrix & M1, |
| 191 |
Epetra_MultiVector & xh, |
| 192 |
Epetra_MultiVector & b, |
| 193 |
double & TotalErrorResidual, |
| 194 |
double & TotalErrorExactSol); |
| 195 |
|
| 196 |
|
| 197 |
/**********************************************************************************/ |
| 198 |
/******** FUNCTION DECLARATIONS FOR EXACT SOLUTION AND SOURCE TERMS ***************/ |
| 199 |
/**********************************************************************************/ |
| 200 |
|
| 201 |
/** \brief Exact solution evaluation. |
| 202 |
|
| 203 |
\param uExact0 [out] first component of exact solution at (x,y,z) |
| 204 |
\param uExact1 [out] second component of exact solution at (x,y,z) |
| 205 |
\param uExact2 [out] third component of exact solution at (x,y,z) |
| 206 |
\param x [in] x coordinate |
| 207 |
\param y [in] y coordinate |
| 208 |
\param z [in] z coordinate |
| 209 |
*/ |
| 210 |
int evalu(double & uExact0, |
| 211 |
double & uExact1, |
| 212 |
double & uExact2, |
| 213 |
double & x, |
| 214 |
double & y, |
| 215 |
double & z); |
| 216 |
|
| 217 |
/** \brief Divergence of exact solution. |
| 218 |
|
| 219 |
\param x [in] x coordinate |
| 220 |
\param y [in] y coordinate |
| 221 |
\param z [in] z coordinate |
| 222 |
\param mu [in] material parameter |
| 223 |
|
| 224 |
\return Value of the divergence of exact solution at (x,y,z) |
| 225 |
*/ |
| 226 |
double evalDivu(double & x, |
| 227 |
double & y, |
| 228 |
double & z, |
| 229 |
double & mu); |
| 230 |
|
| 231 |
/** \brief Curl of exact solution. |
| 232 |
|
| 233 |
\param curlu0 [out] first component of curl of exact solution |
| 234 |
\param curlu1 [out] second component of curl of exact solution |
| 235 |
\param curlu2 [out] third component of curl of exact solution |
| 236 |
\param x [in] x coordinate |
| 237 |
\param y [in] y coordinate |
| 238 |
\param z [in] z coordinate |
| 239 |
\param mu [in] material parameter |
| 240 |
*/ |
| 241 |
int evalCurlu(double & curlu0, |
| 242 |
double & curlu1, |
| 243 |
double & curlu2, |
| 244 |
double & x, |
| 245 |
double & y, |
| 246 |
double & z, |
| 247 |
double & mu); |
| 248 |
|
| 249 |
/** \brief Gradient of Divergence of exact solution |
| 250 |
|
| 251 |
\param gradDivu0 [out] first (x) component of grad div of exact solution |
| 252 |
\param gradDivu1 [out] second (y) component of grad div of exact solution |
| 253 |
\param gradDivu2 [out] third (z) component of grad div of exact solution |
| 254 |
\param x [in] x coordinate |
| 255 |
\param y [in] y coordinate |
| 256 |
\param z [in] z coordinate |
| 257 |
\param mu [in] material parameter |
| 258 |
*/ |
| 259 |
int evalGradDivu(double & gradDivu0, |
| 260 |
double & gradDivu1, |
| 261 |
double & gradDivu2, |
| 262 |
double & x, double & y, |
| 263 |
double & z, double & mu); |
| 264 |
|
| 265 |
/**********************************************************************************/ |
| 266 |
/**********************************************************************************/ |
| 267 |
/**********************************************************************************/ |
| 268 |
|
| 269 |
|
| 270 |
|
| 271 |
/**********************************************************************************/ |
| 272 |
/******************************** MAIN ********************************************/ |
| 273 |
/**********************************************************************************/ |
| 274 |
int main(int argc, char *argv[]) { |
| 275 |
|
| 276 |
int error = 0; |
| 277 |
#ifdef HAVE_MPI |
| 278 |
Teuchos::GlobalMPISession mpiSession(&argc, &argv,0); |
| 279 |
int rank=mpiSession.getRank(); |
| 280 |
int numProcs=mpiSession.getNProc(); |
| 281 |
Epetra_MpiComm Comm(MPI_COMM_WORLD); |
| 282 |
int MyPID = Comm.MyPID(); |
| 283 |
#else |
| 284 |
int rank=0; |
| 285 |
int numProcs=1; |
| 286 |
int MyPID = 0; |
| 287 |
Epetra_SerialComm Comm; |
| 288 |
#endif |
| 289 |
Epetra_Time Time(Comm); |
| 290 |
|
| 291 |
//Check number of arguments |
| 292 |
if (argc > 2) { |
| 293 |
std::cout <<"\n>>> ERROR: Invalid number of arguments.\n\n"; |
| 294 |
std::cout <<"Usage:\n\n"; |
| 295 |
std::cout <<" ./TrilinosCouplings_examples_scaling_Example_CurlLSFEM.exe [inputfile.xml] \n\n"; |
| 296 |
std::cout <<" inputfile.xml(optional) - xml file with description of Pamgen mesh \n"; |
| 297 |
std::cout <<" and material parameters for each block \nn"; |
| 298 |
exit(1); |
| 299 |
} |
| 300 |
|
| 301 |
if (MyPID == 0) { |
| 302 |
std::cout \ |
| 303 |
<< "===============================================================================\n" \ |
| 304 |
<< "| |\n" \ |
| 305 |
<< "| Example: Solve Div-Curl System on Hexahedral Mesh |\n" \ |
| 306 |
<< "| with Curl-conforming Elements |\n" \ |
| 307 |
<< "| |\n" \ |
| 308 |
<< "| Questions? Contact Pavel Bochev ([email protected]), |\n" \ |
| 309 |
<< "| Denis Ridzal ([email protected]), |\n" \ |
| 310 |
<< "| Kara Peterson ([email protected]). |\n" \ |
| 311 |
<< "| |\n" \ |
| 312 |
<< "| Intrepid's website: http://trilinos.sandia.gov/packages/intrepid |\n" \ |
| 313 |
<< "| Pamgen's website: http://trilinos.sandia.gov/packages/pamgen |\n" \ |
| 314 |
<< "| ML's website: http://trilinos.sandia.gov/packages/ml |\n" \ |
| 315 |
<< "| Trilinos website: http://trilinos.sandia.gov |\n" \ |
| 316 |
<< "| |\n" \ |
| 317 |
<< "===============================================================================\n"; |
| 318 |
} |
| 319 |
|
| 320 |
long long * node_comm_proc_ids = NULL; |
| 321 |
long long * node_cmap_node_cnts = NULL; |
| 322 |
long long * node_cmap_ids = NULL; |
| 323 |
long long ** comm_node_ids = NULL; |
| 324 |
long long ** comm_node_proc_ids = NULL; |
| 325 |
|
| 326 |
std::set < topo_entity * , fecomp > edge_set; |
| 327 |
std::set < topo_entity * , fecomp > face_set; |
| 328 |
|
| 329 |
std::vector < topo_entity * > edge_vector; |
| 330 |
std::vector < topo_entity * > face_vector; |
| 331 |
|
| 332 |
std::vector < int > edge_comm_procs; |
| 333 |
|
| 334 |
|
| 335 |
/**********************************************************************************/ |
| 336 |
/********************************** GET XML INPUTS ********************************/ |
| 337 |
/**********************************************************************************/ |
| 338 |
|
| 339 |
// Command line for xml file, otherwise use default |
| 340 |
std::string xmlInFileName; |
| 341 |
if(argc>=2) xmlInFileName=string(argv[1]); |
| 342 |
else xmlInFileName="CurlLSFEMin.xml"; |
| 343 |
|
| 344 |
|
| 345 |
// Read xml file into parameter list |
| 346 |
Teuchos::ParameterList inputList; |
| 347 |
|
| 348 |
if(xmlInFileName.length()) { |
| 349 |
if (MyPID == 0) { |
| 350 |
std::cout << "\nReading parameter list from the XML file \""<<xmlInFileName<<"\" ...\n\n"; |
| 351 |
} |
| 352 |
Teuchos::updateParametersFromXmlFile(xmlInFileName, Teuchos::ptr (&inputList)); |
| 353 |
if (MyPID == 0) { |
| 354 |
inputList.print(std::cout,2,true,true); |
| 355 |
std::cout << "\n"; |
| 356 |
} |
| 357 |
} |
| 358 |
else |
| 359 |
{ |
| 360 |
std::cout << "Cannot read input file: " << xmlInFileName << "\n"; |
| 361 |
return 0; |
| 362 |
} |
| 363 |
|
| 364 |
// Get pamgen mesh definition |
| 365 |
std::string meshInput = Teuchos::getParameter<std::string>(inputList,"meshInput"); |
| 366 |
|
| 367 |
|
| 368 |
/**********************************************************************************/ |
| 369 |
/***************************** GET CELL TOPOLOGY **********************************/ |
| 370 |
/**********************************************************************************/ |
| 371 |
|
| 372 |
// Get cell topology for base hexahedron |
| 373 |
shards::CellTopology cellType(shards::getCellTopologyData<shards::Hexahedron<8> >() ); |
| 374 |
|
| 375 |
// Get dimensions |
| 376 |
int numNodesPerElem = cellType.getNodeCount(); |
| 377 |
int numEdgesPerElem = cellType.getEdgeCount(); |
| 378 |
int numFacesPerElem = cellType.getSideCount(); |
| 379 |
int numNodesPerEdge = 2; |
| 380 |
int numNodesPerFace = 4; |
| 381 |
int numEdgesPerFace = 4; |
| 382 |
int spaceDim = cellType.getDimension(); |
| 383 |
|
| 384 |
// Build reference element edge to node map |
| 385 |
FieldContainer<int> refEdgeToNode(numEdgesPerElem,numNodesPerEdge); |
| 386 |
for (int i=0; i<numEdgesPerElem; i++){ |
| 387 |
refEdgeToNode(i,0)=cellType.getNodeMap(1, i, 0); |
| 388 |
refEdgeToNode(i,1)=cellType.getNodeMap(1, i, 1); |
| 389 |
} |
| 390 |
|
| 391 |
// Build reference element face to node map |
| 392 |
FieldContainer<int> refFaceToNode(numFacesPerElem,numNodesPerFace); |
| 393 |
for (int i=0; i<numFacesPerElem; i++){ |
| 394 |
refFaceToNode(i,0)=cellType.getNodeMap(2, i, 0); |
| 395 |
refFaceToNode(i,1)=cellType.getNodeMap(2, i, 1); |
| 396 |
refFaceToNode(i,2)=cellType.getNodeMap(2, i, 2); |
| 397 |
refFaceToNode(i,3)=cellType.getNodeMap(2, i, 3); |
| 398 |
} |
| 399 |
|
| 400 |
// Build reference element face to edge map (Hardcoded for now) |
| 401 |
FieldContainer<int> refFaceToEdge(numFacesPerElem,numEdgesPerFace); |
| 402 |
refFaceToEdge(0,0)=0; refFaceToEdge(0,1)=9; |
| 403 |
refFaceToEdge(0,2)=4; refFaceToEdge(0,3)=8; |
| 404 |
refFaceToEdge(1,0)=1; refFaceToEdge(1,1)=10; |
| 405 |
refFaceToEdge(1,2)=5; refFaceToEdge(1,3)=9; |
| 406 |
refFaceToEdge(2,0)=2; refFaceToEdge(2,1)=11; |
| 407 |
refFaceToEdge(2,2)=6; refFaceToEdge(2,3)=10; |
| 408 |
refFaceToEdge(3,0)=3; refFaceToEdge(3,1)=8; |
| 409 |
refFaceToEdge(3,2)=7; refFaceToEdge(3,3)=11; |
| 410 |
refFaceToEdge(4,0)=0; refFaceToEdge(4,1)=1; |
| 411 |
refFaceToEdge(4,2)=2; refFaceToEdge(4,3)=3; |
| 412 |
refFaceToEdge(5,0)=4; refFaceToEdge(5,1)=5; |
| 413 |
refFaceToEdge(5,2)=6; refFaceToEdge(5,3)=7; |
| 414 |
|
| 415 |
|
| 416 |
/**********************************************************************************/ |
| 417 |
/******************************* GENERATE MESH ************************************/ |
| 418 |
/**********************************************************************************/ |
| 419 |
|
| 420 |
|
| 421 |
if (MyPID == 0) { |
| 422 |
std::cout << "Generating mesh ... \n\n"; |
| 423 |
} |
| 424 |
|
| 425 |
// Generate mesh with Pamgen |
| 426 |
int dim=3; |
| 427 |
long long maxInt = 9223372036854775807LL; |
| 428 |
long long cr_result = Create_Pamgen_Mesh(meshInput.c_str(), dim, rank, numProcs, maxInt); |
| 429 |
TrilinosCouplings::pamgen_error_check(std::cout,cr_result); |
| 430 |
|
| 431 |
// Get local mesh size info |
| 432 |
char title[100]; |
| 433 |
long long numDim; |
| 434 |
long long numNodes; |
| 435 |
long long numElems; |
| 436 |
long long numElemBlk; |
| 437 |
long long numNodeSets; |
| 438 |
long long numSideSets; |
| 439 |
int id = 0; |
| 440 |
|
| 441 |
im_ex_get_init_l(id, title, &numDim, &numNodes, |
| 442 |
&numElems, &numElemBlk, &numNodeSets, |
| 443 |
&numSideSets); |
| 444 |
|
| 445 |
// Get global mesh size info |
| 446 |
long long numNodesGlobal; |
| 447 |
long long numElemsGlobal; |
| 448 |
long long numElemBlkGlobal; |
| 449 |
long long numNodeSetsGlobal; |
| 450 |
long long numSideSetsGlobal; |
| 451 |
|
| 452 |
im_ne_get_init_global_l(id, &numNodesGlobal, &numElemsGlobal, |
| 453 |
&numElemBlkGlobal, &numNodeSetsGlobal, |
| 454 |
&numSideSetsGlobal); |
| 455 |
|
| 456 |
long long * block_ids = new long long [numElemBlk]; |
| 457 |
error += im_ex_get_elem_blk_ids_l(id, block_ids); |
| 458 |
|
| 459 |
|
| 460 |
long long *nodes_per_element = new long long [numElemBlk]; |
| 461 |
long long *element_attributes = new long long [numElemBlk]; |
| 462 |
long long *elements = new long long [numElemBlk]; |
| 463 |
char **element_types = new char * [numElemBlk]; |
| 464 |
long long **elmt_node_linkage = new long long * [numElemBlk]; |
| 465 |
|
| 466 |
|
| 467 |
for(long long i = 0; i < numElemBlk; i ++){ |
| 468 |
element_types[i] = new char [MAX_STR_LENGTH + 1]; |
| 469 |
error += im_ex_get_elem_block_l(id, |
| 470 |
block_ids[i], |
| 471 |
element_types[i], |
| 472 |
(long long*)&(elements[i]), |
| 473 |
(long long*)&(nodes_per_element[i]), |
| 474 |
(long long*)&(element_attributes[i])); |
| 475 |
} |
| 476 |
|
| 477 |
/*connectivity*/ |
| 478 |
for(long long b = 0; b < numElemBlk; b++){ |
| 479 |
elmt_node_linkage[b] = new long long [nodes_per_element[b]*elements[b]]; |
| 480 |
error += im_ex_get_elem_conn_l(id,block_ids[b],elmt_node_linkage[b]); |
| 481 |
} |
| 482 |
|
| 483 |
// Get mu value for each block of elements from parameter list |
| 484 |
double *mu = new double [numElemBlk]; |
| 485 |
for(int b = 0; b < numElemBlk; b++){ |
| 486 |
stringstream muBlock; |
| 487 |
muBlock.clear(); |
| 488 |
muBlock << "mu" << b; |
| 489 |
mu[b] = inputList.get(muBlock.str(),1.0); |
| 490 |
} |
| 491 |
|
| 492 |
// Get node-element connectivity and set element mu value |
| 493 |
int telct = 0; |
| 494 |
FieldContainer<int> elemToNode(numElems,numNodesPerElem); |
| 495 |
FieldContainer<double> muVal(numElems); |
| 496 |
for(long long b = 0; b < numElemBlk; b++){ |
| 497 |
for(long long el = 0; el < elements[b]; el++){ |
| 498 |
for (int j=0; j<numNodesPerElem; j++) { |
| 499 |
elemToNode(telct,j) = elmt_node_linkage[b][el*numNodesPerElem + j]-1; |
| 500 |
} |
| 501 |
muVal(telct) = mu[b]; |
| 502 |
telct ++; |
| 503 |
} |
| 504 |
} |
| 505 |
|
| 506 |
// Read node coordinates and place in field container |
| 507 |
FieldContainer<double> nodeCoord(numNodes,dim); |
| 508 |
double * nodeCoordx = new double [numNodes]; |
| 509 |
double * nodeCoordy = new double [numNodes]; |
| 510 |
double * nodeCoordz = new double [numNodes]; |
| 511 |
im_ex_get_coord_l(id,nodeCoordx,nodeCoordy,nodeCoordz); |
| 512 |
for (int i=0; i<numNodes; i++) { |
| 513 |
nodeCoord(i,0)=nodeCoordx[i]; |
| 514 |
nodeCoord(i,1)=nodeCoordy[i]; |
| 515 |
nodeCoord(i,2)=nodeCoordz[i]; |
| 516 |
} |
| 517 |
|
| 518 |
/*parallel info*/ |
| 519 |
long long num_internal_nodes; |
| 520 |
long long num_border_nodes; |
| 521 |
long long num_external_nodes; |
| 522 |
long long num_internal_elems; |
| 523 |
long long num_border_elems; |
| 524 |
long long num_node_comm_maps; |
| 525 |
long long num_elem_comm_maps; |
| 526 |
im_ne_get_loadbal_param_l( id, |
| 527 |
&num_internal_nodes, |
| 528 |
&num_border_nodes, |
| 529 |
&num_external_nodes, |
| 530 |
&num_internal_elems, |
| 531 |
&num_border_elems, |
| 532 |
&num_node_comm_maps, |
| 533 |
&num_elem_comm_maps, |
| 534 |
0/*unused*/ ); |
| 535 |
|
| 536 |
if(num_node_comm_maps > 0){ |
| 537 |
node_comm_proc_ids = new long long [num_node_comm_maps]; |
| 538 |
node_cmap_node_cnts = new long long [num_node_comm_maps]; |
| 539 |
node_cmap_ids = new long long [num_node_comm_maps]; |
| 540 |
comm_node_ids = new long long* [num_node_comm_maps]; |
| 541 |
comm_node_proc_ids = new long long* [num_node_comm_maps]; |
| 542 |
|
| 543 |
long long * elem_cmap_ids = new long long [num_elem_comm_maps]; |
| 544 |
long long * elem_cmap_elem_cnts = new long long [num_elem_comm_maps]; |
| 545 |
if ( im_ne_get_cmap_params_l( id, |
| 546 |
node_cmap_ids, |
| 547 |
(long long*)node_cmap_node_cnts, |
| 548 |
elem_cmap_ids, |
| 549 |
(long long*)elem_cmap_elem_cnts, |
| 550 |
0/*not used proc_id*/ ) < 0 )++error; |
| 551 |
|
| 552 |
for(long long j = 0; j < num_node_comm_maps; j++) { |
| 553 |
comm_node_ids[j] = new long long [node_cmap_node_cnts[j]]; |
| 554 |
comm_node_proc_ids[j] = new long long [node_cmap_node_cnts[j]]; |
| 555 |
if ( im_ne_get_node_cmap_l( id, |
| 556 |
node_cmap_ids[j], |
| 557 |
comm_node_ids[j], |
| 558 |
comm_node_proc_ids[j], |
| 559 |
0/*not used proc_id*/ ) < 0 )++error; |
| 560 |
node_comm_proc_ids[j] = comm_node_proc_ids[j][0]; |
| 561 |
} |
| 562 |
} |
| 563 |
|
| 564 |
|
| 565 |
|
| 566 |
//Calculate global node ids |
| 567 |
long long * globalNodeIds = new long long[numNodes]; |
| 568 |
bool * nodeIsOwned = new bool[numNodes]; |
| 569 |
|
| 570 |
calc_global_node_ids(globalNodeIds, |
| 571 |
nodeIsOwned, |
| 572 |
numNodes, |
| 573 |
num_node_comm_maps, |
| 574 |
node_cmap_node_cnts, |
| 575 |
node_comm_proc_ids, |
| 576 |
comm_node_ids, |
| 577 |
rank); |
| 578 |
|
| 579 |
// Count owned nodes |
| 580 |
int ownedNodes=0; |
| 581 |
for(int i=0;i<numNodes;i++) |
| 582 |
if(nodeIsOwned[i]) ownedNodes++; |
| 583 |
|
| 584 |
// Build a list of the OWNED global ids... |
| 585 |
int *ownedGIDs=new int [ownedNodes]; |
| 586 |
int oidx=0; |
| 587 |
for(int i=0;i<numNodes;i++) |
| 588 |
if(nodeIsOwned[i]){ |
| 589 |
ownedGIDs[oidx]=(int)globalNodeIds[i]; |
| 590 |
oidx++; |
| 591 |
} |
| 592 |
|
| 593 |
FieldContainer<int> elemToEdge(numElems,numEdgesPerElem); |
| 594 |
FieldContainer<int> elemToFace(numElems,numFacesPerElem); |
| 595 |
|
| 596 |
// Calculate edge and face ids |
| 597 |
int elct = 0; |
| 598 |
for(long long b = 0; b < numElemBlk; b++){ |
| 599 |
if(nodes_per_element[b] == 4){ |
| 600 |
} |
| 601 |
else if (nodes_per_element[b] == 8){ |
| 602 |
//loop over all elements and push their edges onto a set if they are not there already |
| 603 |
for(long long el = 0; el < elements[b]; el++){ |
| 604 |
std::set< topo_entity *, fecomp > ::iterator fit; |
| 605 |
for (int i=0; i < numEdgesPerElem; i++){ |
| 606 |
topo_entity * teof = new topo_entity; |
| 607 |
for(int j = 0; j < numNodesPerEdge;j++){ |
| 608 |
teof->add_node(elmt_node_linkage[b][el*numNodesPerElem + refEdgeToNode(i,j)],globalNodeIds); |
| 609 |
} |
| 610 |
teof->sort(); |
| 611 |
fit = edge_set.find(teof); |
| 612 |
if(fit == edge_set.end()){ |
| 613 |
teof->local_id = edge_vector.size(); |
| 614 |
edge_set.insert(teof); |
| 615 |
elemToEdge(elct,i)= edge_vector.size(); |
| 616 |
edge_vector.push_back(teof); |
| 617 |
} |
| 618 |
else{ |
| 619 |
elemToEdge(elct,i) = (*fit)->local_id; |
| 620 |
delete teof; |
| 621 |
} |
| 622 |
} |
| 623 |
for (int i=0; i < numFacesPerElem; i++){ |
| 624 |
topo_entity * teof = new topo_entity; |
| 625 |
for(int j = 0; j < numNodesPerFace;j++){ |
| 626 |
teof->add_node(elmt_node_linkage[b][el*numNodesPerElem + refFaceToNode(i,j)],globalNodeIds); |
| 627 |
} |
| 628 |
teof->sort(); |
| 629 |
fit = face_set.find(teof); |
| 630 |
if(fit == face_set.end()){ |
| 631 |
teof->local_id = face_vector.size(); |
| 632 |
face_set.insert(teof); |
| 633 |
elemToFace(elct,i)= face_vector.size(); |
| 634 |
face_vector.push_back(teof); |
| 635 |
} |
| 636 |
else{ |
| 637 |
elemToFace(elct,i) = (*fit)->local_id; |
| 638 |
delete teof; |
| 639 |
} |
| 640 |
} |
| 641 |
elct ++; |
| 642 |
} |
| 643 |
} |
| 644 |
} |
| 645 |
|
| 646 |
// Edge to Node connectivity |
| 647 |
FieldContainer<int> edgeToNode(edge_vector.size(), numNodesPerEdge); |
| 648 |
for(unsigned ect = 0; ect != edge_vector.size(); ect++){ |
| 649 |
std::list<long long>::iterator elit; |
| 650 |
int nct = 0; |
| 651 |
for(elit = edge_vector[ect]->local_node_ids.begin(); |
| 652 |
elit != edge_vector[ect]->local_node_ids.end(); |
| 653 |
elit ++){ |
| 654 |
edgeToNode(ect,nct) = *elit-1; |
| 655 |
nct++; |
| 656 |
} |
| 657 |
} |
| 658 |
|
| 659 |
// Face to Node connectivity |
| 660 |
FieldContainer<int> faceToNode(face_vector.size(), numNodesPerFace); |
| 661 |
for(unsigned fct = 0; fct != face_vector.size(); fct++){ |
| 662 |
std::list<long long>::iterator flit; |
| 663 |
int nct = 0; |
| 664 |
for(flit = face_vector[fct]->local_node_ids.begin(); |
| 665 |
flit != face_vector[fct]->local_node_ids.end(); |
| 666 |
flit ++){ |
| 667 |
faceToNode(fct,nct) = *flit-1; |
| 668 |
nct++; |
| 669 |
} |
| 670 |
} |
| 671 |
|
| 672 |
// Face to Edge connectivity |
| 673 |
FieldContainer<int> faceToEdge(face_vector.size(), numEdgesPerFace); |
| 674 |
FieldContainer<bool> faceDone(face_vector.size()); |
| 675 |
for (int ielem = 0; ielem < numElems; ielem++){ |
| 676 |
for (int iface = 0; iface < numFacesPerElem; iface++){ |
| 677 |
if (!faceDone(elemToFace(ielem,iface))){ |
| 678 |
for (int iedge = 0; iedge < numEdgesPerFace; iedge++){ |
| 679 |
faceToEdge(elemToFace(ielem,iface),iedge) = |
| 680 |
elemToEdge(ielem,refFaceToEdge(iface,iedge)); |
| 681 |
faceDone(elemToFace(ielem,iface))=1; |
| 682 |
} |
| 683 |
} |
| 684 |
} |
| 685 |
} |
| 686 |
|
| 687 |
int numEdges = edge_vector.size(); |
| 688 |
int numFaces = face_vector.size(); |
| 689 |
|
| 690 |
// Calculate global edge and face numbering |
| 691 |
std::string doing_type; |
| 692 |
doing_type = "EDGES"; |
| 693 |
calc_global_ids(edge_vector, |
| 694 |
comm_node_ids, |
| 695 |
node_comm_proc_ids, |
| 696 |
node_cmap_node_cnts, |
| 697 |
num_node_comm_maps, |
| 698 |
rank, |
| 699 |
doing_type); |
| 700 |
|
| 701 |
|
| 702 |
doing_type = "FACES"; |
| 703 |
calc_global_ids(face_vector, |
| 704 |
comm_node_ids, |
| 705 |
node_comm_proc_ids, |
| 706 |
node_cmap_node_cnts, |
| 707 |
num_node_comm_maps, |
| 708 |
rank, |
| 709 |
doing_type); |
| 710 |
|
| 711 |
// Build list of owned global edge ids |
| 712 |
long long * globalEdgeIds = new long long[numEdges]; |
| 713 |
bool * edgeIsOwned = new bool[numEdges]; |
| 714 |
int numOwnedEdges=0; |
| 715 |
for (int i=0; i<numEdges; i++) { |
| 716 |
edgeIsOwned[i] = edge_vector[i]->owned; |
| 717 |
globalEdgeIds[i] = edge_vector[i]->global_id; |
| 718 |
if (edgeIsOwned[i]){ |
| 719 |
numOwnedEdges++; |
| 720 |
} |
| 721 |
} |
| 722 |
int * ownedEdgeIds = new int[numOwnedEdges]; |
| 723 |
int nedge=0; |
| 724 |
for (int i=0; i<numEdges; i++) { |
| 725 |
if (edgeIsOwned[i]){ |
| 726 |
ownedEdgeIds[nedge]=(int)globalEdgeIds[i]; |
| 727 |
nedge++; |
| 728 |
} |
| 729 |
} |
| 730 |
|
| 731 |
// Build list of owned global face ids |
| 732 |
long long * globalFaceIds = new long long[numFaces]; |
| 733 |
bool * faceIsOwned = new bool[numFaces]; |
| 734 |
int numOwnedFaces=0; |
| 735 |
for (int i=0; i<numFaces; i++) { |
| 736 |
faceIsOwned[i] = face_vector[i]->owned; |
| 737 |
globalFaceIds[i] = face_vector[i]->global_id; |
| 738 |
if (faceIsOwned[i]){ |
| 739 |
numOwnedFaces++; |
| 740 |
} |
| 741 |
} |
| 742 |
int * ownedFaceIds = new int[numOwnedFaces]; |
| 743 |
int nface=0; |
| 744 |
for (int i=0; i<numFaces; i++) { |
| 745 |
if (faceIsOwned[i]){ |
| 746 |
ownedFaceIds[nface]=(int)globalFaceIds[i]; |
| 747 |
nface++; |
| 748 |
} |
| 749 |
} |
| 750 |
|
| 751 |
// Calculate number of global edges and faces |
| 752 |
int numEdgesGlobal; |
| 753 |
int numFacesGlobal; |
| 754 |
#ifdef HAVE_MPI |
| 755 |
Comm.SumAll(&numOwnedEdges,&numEdgesGlobal,1); |
| 756 |
Comm.SumAll(&numOwnedFaces,&numFacesGlobal,1); |
| 757 |
#else |
| 758 |
numEdgesGlobal = numEdges; |
| 759 |
numFacesGlobal = numFaces; |
| 760 |
#endif |
| 761 |
|
| 762 |
|
| 763 |
// Print mesh size information |
| 764 |
if (MyPID == 0) { |
| 765 |
std::cout << " Number of Elements: " << numElemsGlobal << " \n"; |
| 766 |
std::cout << " Number of Nodes: " << numNodesGlobal << " \n"; |
| 767 |
std::cout << " Number of Edges: " << numEdgesGlobal << " \n"; |
| 768 |
std::cout << " Number of Faces: " << numFacesGlobal << " \n\n"; |
| 769 |
} |
| 770 |
|
| 771 |
|
| 772 |
|
| 773 |
// Container indicating whether a face is on the boundary (1-yes 0-no) |
| 774 |
FieldContainer<int> edgeOnBoundary(numEdges); |
| 775 |
FieldContainer<int> faceOnBoundary(numFaces); |
| 776 |
|
| 777 |
// Get boundary (side set) information |
| 778 |
long long * sideSetIds = new long long [numSideSets]; |
| 779 |
long long numSidesInSet; |
| 780 |
long long numDFinSet; |
| 781 |
im_ex_get_side_set_ids_l(id,sideSetIds); |
| 782 |
for (int i=0; i<numSideSets; i++) { |
| 783 |
im_ex_get_side_set_param_l(id,sideSetIds[i],&numSidesInSet,&numDFinSet); |
| 784 |
if (numSidesInSet > 0){ |
| 785 |
long long * sideSetElemList = new long long [numSidesInSet]; |
| 786 |
long long * sideSetSideList = new long long [numSidesInSet]; |
| 787 |
im_ex_get_side_set_l(id,sideSetIds[i],sideSetElemList,sideSetSideList); |
| 788 |
for (int j=0; j<numSidesInSet; j++) { |
| 789 |
int iface = sideSetSideList[j]-1; |
| 790 |
faceOnBoundary(elemToFace(sideSetElemList[j]-1,iface))=1; |
| 791 |
edgeOnBoundary(faceToEdge(elemToFace(sideSetElemList[j]-1,iface),0))=1; |
| 792 |
edgeOnBoundary(faceToEdge(elemToFace(sideSetElemList[j]-1,iface),1))=1; |
| 793 |
edgeOnBoundary(faceToEdge(elemToFace(sideSetElemList[j]-1,iface),2))=1; |
| 794 |
edgeOnBoundary(faceToEdge(elemToFace(sideSetElemList[j]-1,iface),3))=1; |
| 795 |
} |
| 796 |
delete [] sideSetElemList; |
| 797 |
delete [] sideSetSideList; |
| 798 |
} |
| 799 |
} |
| 800 |
|
| 801 |
delete [] sideSetIds; |
| 802 |
|
| 803 |
|
| 804 |
// Container indicating whether a node is on the boundary (1-yes 0-no) |
| 805 |
FieldContainer<int> nodeOnBoundary(numNodes); |
| 806 |
int numEdgeOnBndy=0; |
| 807 |
for (int i=0; i<numEdges; i++) { |
| 808 |
if (edgeOnBoundary(i)){ |
| 809 |
nodeOnBoundary(edgeToNode(i,0))=1; |
| 810 |
nodeOnBoundary(edgeToNode(i,1))=1; |
| 811 |
numEdgeOnBndy++; |
| 812 |
} |
| 813 |
} |
| 814 |
|
| 815 |
|
| 816 |
#ifdef RANDOM_GRID |
| 817 |
/***********************************************************************************/ |
| 818 |
/* This block of code will create a randomly perturbed mesh by jiggling the node |
| 819 |
coordinates up to 1/4 of an edge length away from their initial location. |
| 820 |
!!!NOTE: THIS WILL ONLY WORK CORRECTLY ON A SINGLE PROCESSOR!!! */ |
| 821 |
/***********************************************************************************/ |
| 822 |
// Side length assuming an initially regular grid |
| 823 |
double hx = nodeCoord(elemToNode(0,1),0)-nodeCoord(elemToNode(0,0),0); |
| 824 |
double hy = nodeCoord(elemToNode(0,3),1)-nodeCoord(elemToNode(0,0),1); |
| 825 |
double hz = nodeCoord(elemToNode(0,4),2)-nodeCoord(elemToNode(0,0),2); |
| 826 |
|
| 827 |
// Loop over nodes |
| 828 |
for (int inode = 0; inode < numNodes; inode++){ |
| 829 |
if (!nodeOnBoundary(inode) & nodeIsOwned[inode]) { |
| 830 |
// random numbers between -1.0 and 1.0 |
| 831 |
double rx = 2.0 * (double)rand()/RAND_MAX - 1.0; |
| 832 |
double ry = 2.0 * (double)rand()/RAND_MAX - 1.0; |
| 833 |
double rz = 2.0 * (double)rand()/RAND_MAX - 1.0; |
| 834 |
// limit variation to 1/4 edge length |
| 835 |
nodeCoord(inode,0) = nodeCoord(inode,0) + 0.125 * hx * rx; |
| 836 |
nodeCoord(inode,1) = nodeCoord(inode,1) + 0.125 * hy * ry; |
| 837 |
nodeCoord(inode,2) = nodeCoord(inode,2) + 0.125 * hz * rz; |
| 838 |
nodeCoordx[inode] = nodeCoord(inode,0); |
| 839 |
nodeCoordy[inode] = nodeCoord(inode,1); |
| 840 |
nodeCoordz[inode] = nodeCoord(inode,2); |
| 841 |
} |
| 842 |
} |
| 843 |
#endif |
| 844 |
|
| 845 |
/**********************************************************************************/ |
| 846 |
/********************************* GET CUBATURE ***********************************/ |
| 847 |
/**********************************************************************************/ |
| 848 |
|
| 849 |
// Get numerical integration points and weights for cell |
| 850 |
DefaultCubatureFactory<double> cubFactory; |
| 851 |
int cubDegree = 2; |
| 852 |
Teuchos::RCP<Cubature<double> > hexCub = cubFactory.create(cellType, cubDegree); |
| 853 |
|
| 854 |
int cubDim = hexCub->getDimension(); |
| 855 |
int numCubPoints = hexCub->getNumPoints(); |
| 856 |
|
| 857 |
FieldContainer<double> cubPoints(numCubPoints, cubDim); |
| 858 |
FieldContainer<double> cubWeights(numCubPoints); |
| 859 |
|
| 860 |
hexCub->getCubature(cubPoints, cubWeights); |
| 861 |
|
| 862 |
/**********************************************************************************/ |
| 863 |
/* Get numerical integration points and weights for hexahedron face */ |
| 864 |
/* (needed for rhs boundary term) */ |
| 865 |
/**********************************************************************************/ |
| 866 |
|
| 867 |
// Define topology of the face parametrization domain as [-1,1]x[-1,1] |
| 868 |
shards::CellTopology paramQuadFace(shards::getCellTopologyData<shards::Quadrilateral<4> >() ); |
| 869 |
|
| 870 |
// Define cubature |
| 871 |
DefaultCubatureFactory<double> cubFactoryFace; |
| 872 |
Teuchos::RCP<Cubature<double> > hexFaceCubature = cubFactoryFace.create(paramQuadFace, 3); |
| 873 |
int cubFaceDim = hexFaceCubature -> getDimension(); |
| 874 |
int numFacePoints = hexFaceCubature -> getNumPoints(); |
| 875 |
|
| 876 |
// Define storage for cubature points and weights on [-1,1]x[-1,1] |
| 877 |
FieldContainer<double> paramFaceWeights(numFacePoints); |
| 878 |
FieldContainer<double> paramFacePoints(numFacePoints,cubFaceDim); |
| 879 |
|
| 880 |
// Define storage for cubature points on workset faces |
| 881 |
hexFaceCubature -> getCubature(paramFacePoints, paramFaceWeights); |
| 882 |
|
| 883 |
/**********************************************************************************/ |
| 884 |
/* Get numerical integration points and weights for hexahedron edge */ |
| 885 |
/* (needed for inhomogeneous boundary terms) */ |
| 886 |
/**********************************************************************************/ |
| 887 |
|
| 888 |
// Define topology of the edge parametrization domain as [-1,1] |
| 889 |
shards::CellTopology paramEdge(shards::getCellTopologyData<shards::Line<2> >() ); |
| 890 |
|
| 891 |
// Define cubature |
| 892 |
DefaultCubatureFactory<double> cubFactoryEdge; |
| 893 |
Teuchos::RCP<Cubature<double> > hexEdgeCubature = cubFactoryEdge.create(paramEdge, 3); |
| 894 |
int cubEdgeDim = hexEdgeCubature -> getDimension(); |
| 895 |
int numEdgePoints = hexEdgeCubature -> getNumPoints(); |
| 896 |
|
| 897 |
// Define storage for cubature points and weights on [-1,1] |
| 898 |
FieldContainer<double> paramEdgeWeights(numEdgePoints); |
| 899 |
FieldContainer<double> paramEdgePoints(numEdgePoints,cubEdgeDim); |
| 900 |
|
| 901 |
// Define storage for cubature points on workset faces |
| 902 |
hexEdgeCubature -> getCubature(paramEdgePoints, paramEdgeWeights); |
| 903 |
|
| 904 |
if(MyPID==0) {std::cout << "Getting cubature " |
| 905 |
<< Time.ElapsedTime() << " sec \n" ; Time.ResetStartTime();} |
| 906 |
|
| 907 |
|
| 908 |
/**********************************************************************************/ |
| 909 |
/*********************************** GET BASIS ************************************/ |
| 910 |
/**********************************************************************************/ |
| 911 |
|
| 912 |
// Define basis |
| 913 |
Basis_HCURL_HEX_I1_FEM<double, FieldContainer<double> > hexHCurlBasis; |
| 914 |
Basis_HGRAD_HEX_C1_FEM<double, FieldContainer<double> > hexHGradBasis; |
| 915 |
|
| 916 |
int numFieldsC = hexHCurlBasis.getCardinality(); |
| 917 |
int numFieldsG = hexHGradBasis.getCardinality(); |
| 918 |
|
| 919 |
// Evaluate basis at cubature points |
| 920 |
FieldContainer<double> HGVals(numFieldsG, numCubPoints); |
| 921 |
FieldContainer<double> HCVals(numFieldsC, numCubPoints, spaceDim); |
| 922 |
FieldContainer<double> HCurls(numFieldsC, numCubPoints, spaceDim); |
| 923 |
FieldContainer<double> worksetCVals(numFieldsC, numFacePoints, spaceDim); |
| 924 |
|
| 925 |
hexHCurlBasis.getValues(HCVals, cubPoints, OPERATOR_VALUE); |
| 926 |
hexHCurlBasis.getValues(HCurls, cubPoints, OPERATOR_CURL); |
| 927 |
hexHGradBasis.getValues(HGVals, cubPoints, OPERATOR_VALUE); |
| 928 |
|
| 929 |
if(MyPID==0) {std::cout << "Getting basis " |
| 930 |
<< Time.ElapsedTime() << " sec \n" ; Time.ResetStartTime();} |
| 931 |
|
| 932 |
|
| 933 |
/**********************************************************************************/ |
| 934 |
/********************* BUILD MAPS FOR GLOBAL SOLUTION *****************************/ |
| 935 |
/**********************************************************************************/ |
| 936 |
|
| 937 |
// Define global epetra maps |
| 938 |
Epetra_Map globalMapG(-1,ownedNodes,ownedGIDs,0,Comm); |
| 939 |
Epetra_Map globalMapC(-1,numOwnedEdges,ownedEdgeIds,0,Comm); |
| 940 |
|
| 941 |
Epetra_FECrsMatrix StiffMatrixC(Copy, globalMapC, numFieldsC); |
| 942 |
Epetra_FECrsMatrix MassMatrixC (Copy, globalMapC, numFieldsC); |
| 943 |
Epetra_FECrsMatrix MassMatrixG (Copy, globalMapG, numFieldsG); |
| 944 |
Epetra_FEVector rhsVector (globalMapC); |
| 945 |
|
| 946 |
if(MyPID==0) {std::cout << "Build global maps " |
| 947 |
<< Time.ElapsedTime() << " sec \n"; Time.ResetStartTime();} |
| 948 |
|
| 949 |
|
| 950 |
/**********************************************************************************/ |
| 951 |
/************************** OUTPUT CONNECTIVITY (FOR PLOTTING) ********************/ |
| 952 |
/**********************************************************************************/ |
| 953 |
|
| 954 |
|
| 955 |
// Build the coordinate vectors for ML solver (including owned nodes only) |
| 956 |
Epetra_Vector Nx(globalMapG), Ny(globalMapG),Nz(globalMapG); |
| 957 |
for(int i=0,nlid=0;i<numNodes;i++) |
| 958 |
if(nodeIsOwned[i]) { |
| 959 |
Nx[nlid]=nodeCoordx[i]; |
| 960 |
Ny[nlid]=nodeCoordy[i]; |
| 961 |
Nz[nlid]=nodeCoordz[i]; |
| 962 |
nlid++; |
| 963 |
} |
| 964 |
|
| 965 |
|
| 966 |
#ifdef DUMP_DATA |
| 967 |
// Put coordinates in multivector for output |
| 968 |
Epetra_MultiVector nCoord(globalMapG,3); |
| 969 |
|
| 970 |
int ownedNode = 0; |
| 971 |
for (int inode=0; inode<numNodes; inode++) { |
| 972 |
if (nodeIsOwned[inode]) { |
| 973 |
nCoord[0][ownedNode]=nodeCoord(inode,0); |
| 974 |
nCoord[1][ownedNode]=nodeCoord(inode,1); |
| 975 |
nCoord[2][ownedNode]=nodeCoord(inode,2); |
| 976 |
ownedNode++; |
| 977 |
} |
| 978 |
} |
| 979 |
EpetraExt::MultiVectorToMatrixMarketFile("coords.dat",nCoord,0,0,false); |
| 980 |
|
| 981 |
// Put element to node mapping in multivector for output |
| 982 |
Epetra_Map globalMapElem(numElemsGlobal, numElems, 0, Comm); |
| 983 |
Epetra_MultiVector elem2node(globalMapElem, numNodesPerElem); |
| 984 |
for (int ielem=0; ielem<numElems; ielem++) { |
| 985 |
for (int inode=0; inode<numNodesPerElem; inode++) { |
| 986 |
elem2node[inode][ielem]=globalNodeIds[elemToNode(ielem,inode)]; |
| 987 |
} |
| 988 |
} |
| 989 |
EpetraExt::MultiVectorToMatrixMarketFile("elem2node.dat",elem2node,0,0,false); |
| 990 |
|
| 991 |
// Put element to edge mapping in multivector for output |
| 992 |
Epetra_MultiVector elem2edge(globalMapElem, numEdgesPerElem); |
| 993 |
for (int ielem=0; ielem<numElems; ielem++) { |
| 994 |
for (int iedge=0; iedge<numEdgesPerElem; iedge++) { |
| 995 |
elem2edge[iedge][ielem]=globalEdgeIds[elemToEdge(ielem,iedge)]; |
| 996 |
} |
| 997 |
} |
| 998 |
EpetraExt::MultiVectorToMatrixMarketFile("elem2edge.dat",elem2edge,0,0,false); |
| 999 |
|
| 1000 |
// Put edge to node mapping in multivector for output |
| 1001 |
Epetra_MultiVector edge2node(globalMapC, numNodesPerEdge); |
| 1002 |
int ownedEdge = 0; |
| 1003 |
for (int iedge=0; iedge<numEdges; iedge++) { |
| 1004 |
if (edgeIsOwned[iedge]) { |
| 1005 |
for (int inode=0; inode<numNodesPerEdge; inode++) { |
| 1006 |
edge2node[inode][ownedEdge]=globalNodeIds[edgeToNode(iedge,inode)]; |
| 1007 |
} |
| 1008 |
ownedEdge++; |
| 1009 |
} |
| 1010 |
} |
| 1011 |
EpetraExt::MultiVectorToMatrixMarketFile("edge2node.dat",edge2node,0,0,false); |
| 1012 |
|
| 1013 |
// Define multi-vector for cell edge sign (fill during cell loop) |
| 1014 |
Epetra_MultiVector edgeSign(globalMapElem, numEdgesPerElem); |
| 1015 |
|
| 1016 |
if(MyPID==0) {Time.ResetStartTime();} |
| 1017 |
#endif |
| 1018 |
|
| 1019 |
|
| 1020 |
/**********************************************************************************/ |
| 1021 |
/*************************BUILD INCIDENCE MATRIX***********************************/ |
| 1022 |
/**********************************************************************************/ |
| 1023 |
|
| 1024 |
// Edge to node incidence matrix |
| 1025 |
Epetra_FECrsMatrix DGrad(Copy, globalMapC, 2); |
| 1026 |
|
| 1027 |
// Grab edge coordinates (for dumping to disk) |
| 1028 |
Epetra_Vector EDGE_X(globalMapC); |
| 1029 |
Epetra_Vector EDGE_Y(globalMapC); |
| 1030 |
Epetra_Vector EDGE_Z(globalMapC); |
| 1031 |
|
| 1032 |
double vals[2]; |
| 1033 |
vals[0]=-1.0; vals[1]=1.0; |
| 1034 |
for (int j=0, elid=0; j<numEdges; j++){ |
| 1035 |
if (edgeIsOwned[j]){ |
| 1036 |
int rowNum = globalEdgeIds[j]; |
| 1037 |
int colNum[2]; |
| 1038 |
colNum[0] = globalNodeIds[edgeToNode(j,0)]; |
| 1039 |
colNum[1] = globalNodeIds[edgeToNode(j,1)]; |
| 1040 |
DGrad.InsertGlobalValues(1, &rowNum, 2, colNum, vals); |
| 1041 |
EDGE_X[elid] = (nodeCoordx[edgeToNode(j,0)] + nodeCoordx[edgeToNode(j,1)])/2.0; |
| 1042 |
EDGE_Y[elid] = (nodeCoordy[edgeToNode(j,0)] + nodeCoordy[edgeToNode(j,1)])/2.0; |
| 1043 |
EDGE_Z[elid] = (nodeCoordz[edgeToNode(j,0)] + nodeCoordz[edgeToNode(j,1)])/2.0; |
| 1044 |
elid++; |
| 1045 |
} |
| 1046 |
} |
| 1047 |
|
| 1048 |
DGrad.GlobalAssemble(globalMapG,globalMapC); |
| 1049 |
DGrad.FillComplete(MassMatrixG.RowMap(),MassMatrixC.RowMap()); |
| 1050 |
|
| 1051 |
if(MyPID==0) {std::cout << "Building incidence matrix " |
| 1052 |
<< Time.ElapsedTime() << " sec \n" ; Time.ResetStartTime();} |
| 1053 |
|
| 1054 |
|
| 1055 |
/**********************************************************************************/ |
| 1056 |
/******************** INHOMOGENEOUS BOUNDARY CONDITIONS ***************************/ |
| 1057 |
/**********************************************************************************/ |
| 1058 |
|
| 1059 |
FieldContainer<double> bndyEdgeVal(numEdgeOnBndy); |
| 1060 |
FieldContainer<int> bndyEdgeToEdge(numEdges); |
| 1061 |
FieldContainer<bool> bndyEdgeDone(numEdges); |
| 1062 |
FieldContainer<double> refEdgePoints(numEdgePoints,spaceDim); |
| 1063 |
FieldContainer<double> bndyEdgePoints(1,numEdgePoints,spaceDim); |
| 1064 |
FieldContainer<double> bndyEdgeJacobians(1,numEdgePoints,spaceDim,spaceDim); |
| 1065 |
FieldContainer<double> edgeTan(1,numEdgePoints,spaceDim); |
| 1066 |
FieldContainer<double> uDotTangent(numEdgePoints); |
| 1067 |
FieldContainer<double> uEdge(numEdgePoints,spaceDim); |
| 1068 |
FieldContainer<double> nodes(1, numNodesPerElem, spaceDim); |
| 1069 |
|
| 1070 |
int ibedge=0; |
| 1071 |
// Evaluate tangent at edge quadrature points |
| 1072 |
for (int ielem=0; ielem<numElems; ielem++) { |
| 1073 |
for (int inode=0; inode<numNodesPerElem; inode++) { |
| 1074 |
nodes(0,inode,0) = nodeCoord(elemToNode(ielem,inode),0); |
| 1075 |
nodes(0,inode,1) = nodeCoord(elemToNode(ielem,inode),1); |
| 1076 |
nodes(0,inode,2) = nodeCoord(elemToNode(ielem,inode),2); |
| 1077 |
} |
| 1078 |
for (int iedge=0; iedge<numEdgesPerElem; iedge++){ |
| 1079 |
if(edgeOnBoundary(elemToEdge(ielem,iedge)) && !bndyEdgeDone(elemToEdge(ielem,iedge))){ |
| 1080 |
|
| 1081 |
// map evaluation points from reference edge to reference cell |
| 1082 |
IntrepidCTools::mapToReferenceSubcell(refEdgePoints, |
| 1083 |
paramEdgePoints, |
| 1084 |
1, iedge, cellType); |
| 1085 |
|
| 1086 |
// calculate Jacobian |
| 1087 |
IntrepidCTools::setJacobian(bndyEdgeJacobians, refEdgePoints, |
| 1088 |
nodes, cellType); |
| 1089 |
|
| 1090 |
// map evaluation points from reference cell to physical cell |
| 1091 |
IntrepidCTools::mapToPhysicalFrame(bndyEdgePoints, |
| 1092 |
refEdgePoints, |
| 1093 |
nodes, cellType); |
| 1094 |
|
| 1095 |
// Compute edge tangents |
| 1096 |
IntrepidCTools::getPhysicalEdgeTangents(edgeTan, |
| 1097 |
bndyEdgeJacobians, |
| 1098 |
iedge, cellType); |
| 1099 |
|
| 1100 |
// evaluate exact solution at edge center and dot with normal |
| 1101 |
for(int nPt = 0; nPt < numEdgePoints; nPt++){ |
| 1102 |
|
| 1103 |
double x = bndyEdgePoints(0, nPt, 0); |
| 1104 |
double y = bndyEdgePoints(0, nPt, 1); |
| 1105 |
double z = bndyEdgePoints(0, nPt, 2); |
| 1106 |
|
| 1107 |
evalu(uEdge(nPt,0), uEdge(nPt,1), uEdge(nPt,2), x, y, z); |
| 1108 |
uDotTangent(nPt)=(uEdge(nPt,0)*edgeTan(0,nPt,0)+uEdge(nPt,1)*edgeTan(0,nPt,1)+uEdge(nPt,2)*edgeTan(0,nPt,2)); |
| 1109 |
} |
| 1110 |
|
| 1111 |
// integrate |
| 1112 |
for(int nPt = 0; nPt < numEdgePoints; nPt++){ |
| 1113 |
bndyEdgeVal(ibedge)=bndyEdgeVal(ibedge)+uDotTangent(nPt)*paramEdgeWeights(nPt); |
| 1114 |
} |
| 1115 |
|
| 1116 |
bndyEdgeToEdge(elemToEdge(ielem,iedge))=ibedge; |
| 1117 |
ibedge++; |
| 1118 |
bndyEdgeDone(elemToEdge(ielem,iedge))=1; |
| 1119 |
} |
| 1120 |
} |
| 1121 |
} |
| 1122 |
|
| 1123 |
// Count of boundary edges |
| 1124 |
int numBCEdges=0; |
| 1125 |
for (int i=0; i<numEdges; i++){ |
| 1126 |
if (edgeOnBoundary(i) && edgeIsOwned[i]){ |
| 1127 |
numBCEdges++; |
| 1128 |
} |
| 1129 |
} |
| 1130 |
|
| 1131 |
// Vector for use in applying BCs |
| 1132 |
Epetra_MultiVector v(globalMapC,true); |
| 1133 |
v.PutScalar(0.0); |
| 1134 |
|
| 1135 |
// Set v to boundary values on Dirichlet edges |
| 1136 |
int * BCEdges = new int [numBCEdges]; |
| 1137 |
int indbc=0; |
| 1138 |
int iOwned=0; |
| 1139 |
for (int i=0; i<numEdges; i++){ |
| 1140 |
if (edgeIsOwned[i]){ |
| 1141 |
if (edgeOnBoundary(i)){ |
| 1142 |
BCEdges[indbc]=iOwned; |
| 1143 |
indbc++; |
| 1144 |
v[0][iOwned]=bndyEdgeVal(bndyEdgeToEdge(i)); |
| 1145 |
} |
| 1146 |
iOwned++; |
| 1147 |
} |
| 1148 |
} |
| 1149 |
|
| 1150 |
if(MyPID==0) {std::cout << "Boundary Condition Setup " |
| 1151 |
<< Time.ElapsedTime() << " sec \n\n"; Time.ResetStartTime();} |
| 1152 |
|
| 1153 |
/**********************************************************************************/ |
| 1154 |
/******************** DEFINE WORKSETS AND LOOP OVER THEM **************************/ |
| 1155 |
/**********************************************************************************/ |
| 1156 |
|
| 1157 |
// Define desired workset size and count how many worksets there are on this processor's mesh block |
| 1158 |
int desiredWorksetSize = numElems; // change to desired workset size! |
| 1159 |
//int desiredWorksetSize = 100; // change to desired workset size! |
| 1160 |
int numWorksets = numElems/desiredWorksetSize; |
| 1161 |
|
| 1162 |
// When numElems is not divisible by desiredWorksetSize, increase workset count by 1 |
| 1163 |
if(numWorksets*desiredWorksetSize < numElems) numWorksets += 1; |
| 1164 |
|
| 1165 |
if (MyPID == 0) { |
| 1166 |
std::cout << "Building discretization matrix and right hand side... \n\n"; |
| 1167 |
std::cout << "\tDesired workset size: " << desiredWorksetSize <<"\n"; |
| 1168 |
std::cout << "\tNumber of worksets (per processor): " << numWorksets <<"\n\n"; |
| 1169 |
Time.ResetStartTime(); |
| 1170 |
} |
| 1171 |
|
| 1172 |
for(int workset = 0; workset < numWorksets; workset++){ |
| 1173 |
|
| 1174 |
// Compute cell numbers where the workset starts and ends |
| 1175 |
int worksetSize = 0; |
| 1176 |
int worksetBegin = (workset + 0)*desiredWorksetSize; |
| 1177 |
int worksetEnd = (workset + 1)*desiredWorksetSize; |
| 1178 |
|
| 1179 |
// When numElems is not divisible by desiredWorksetSize, the last workset ends at numElems |
| 1180 |
worksetEnd = (worksetEnd <= numElems) ? worksetEnd : numElems; |
| 1181 |
|
| 1182 |
// Now we know the actual workset size and can allocate the array for the cell nodes |
| 1183 |
worksetSize = worksetEnd - worksetBegin; |
| 1184 |
FieldContainer<double> cellWorkset(worksetSize, numNodesPerElem, spaceDim); |
| 1185 |
FieldContainer<double> worksetEdgeSigns(worksetSize, numEdgesPerElem); |
| 1186 |
|
| 1187 |
// Copy coordinates into cell workset |
| 1188 |
int cellCounter = 0; |
| 1189 |
for(int cell = worksetBegin; cell < worksetEnd; cell++){ |
| 1190 |
|
| 1191 |
// Physical cell coordinates |
| 1192 |
for (int inode=0; inode<numNodesPerElem; inode++) { |
| 1193 |
cellWorkset(cellCounter,inode,0) = nodeCoord(elemToNode(cell,inode),0); |
| 1194 |
cellWorkset(cellCounter,inode,1) = nodeCoord(elemToNode(cell,inode),1); |
| 1195 |
cellWorkset(cellCounter,inode,2) = nodeCoord(elemToNode(cell,inode),2); |
| 1196 |
} |
| 1197 |
|
| 1198 |
// Edge signs |
| 1199 |
for (int iedge=0; iedge<numEdgesPerElem; iedge++) { |
| 1200 |
if (elemToNode(cell,refEdgeToNode(iedge,0))==edgeToNode(elemToEdge(cell,iedge),0) && |
| 1201 |
elemToNode(cell,refEdgeToNode(iedge,1))==edgeToNode(elemToEdge(cell,iedge),1)) |
| 1202 |
worksetEdgeSigns(cellCounter,iedge) = 1.0; |
| 1203 |
else |
| 1204 |
worksetEdgeSigns(cellCounter,iedge) = -1.0; |
| 1205 |
} |
| 1206 |
|
| 1207 |
// modify signs for edges that are owned by another processor |
| 1208 |
// (Note: this is particular to the numbering of edges used in Pamgen!!) |
| 1209 |
if (!faceIsOwned[elemToFace(cell,0)]) { |
| 1210 |
worksetEdgeSigns(cellCounter,0)=-1.0*worksetEdgeSigns(cellCounter,0); |
| 1211 |
worksetEdgeSigns(cellCounter,4)=-1.0*worksetEdgeSigns(cellCounter,4); |
| 1212 |
} |
| 1213 |
if (!faceIsOwned[elemToFace(cell,1)]) { |
| 1214 |
worksetEdgeSigns(cellCounter,1)=-1.0*worksetEdgeSigns(cellCounter,1); |
| 1215 |
worksetEdgeSigns(cellCounter,5)=-1.0*worksetEdgeSigns(cellCounter,5); |
| 1216 |
} |
| 1217 |
if (!faceIsOwned[elemToFace(cell,2)]) { |
| 1218 |
worksetEdgeSigns(cellCounter,2)=-1.0*worksetEdgeSigns(cellCounter,2); |
| 1219 |
worksetEdgeSigns(cellCounter,6)=-1.0*worksetEdgeSigns(cellCounter,6); |
| 1220 |
} |
| 1221 |
if (!faceIsOwned[elemToFace(cell,3)]) { |
| 1222 |
worksetEdgeSigns(cellCounter,3)=-1.0*worksetEdgeSigns(cellCounter,3); |
| 1223 |
worksetEdgeSigns(cellCounter,7)=-1.0*worksetEdgeSigns(cellCounter,7); |
| 1224 |
} |
| 1225 |
|
| 1226 |
#ifdef DUMP_DATA |
| 1227 |
for (int iedge=0; iedge<numEdgesPerElem; iedge++) { |
| 1228 |
edgeSign[iedge][cell] = worksetEdgeSigns(cellCounter,iedge); |
| 1229 |
} |
| 1230 |
#endif |
| 1231 |
|
| 1232 |
cellCounter++; |
| 1233 |
|
| 1234 |
} // end loop over workset cells |
| 1235 |
|
| 1236 |
/**********************************************************************************/ |
| 1237 |
/* Allocate arrays */ |
| 1238 |
/**********************************************************************************/ |
| 1239 |
|
| 1240 |
// Containers for Jacobian |
| 1241 |
FieldContainer<double> worksetJacobian (worksetSize, numCubPoints, spaceDim, spaceDim); |
| 1242 |
FieldContainer<double> worksetJacobInv (worksetSize, numCubPoints, spaceDim, spaceDim); |
| 1243 |
FieldContainer<double> worksetJacobDet (worksetSize, numCubPoints); |
| 1244 |
|
| 1245 |
// Container for cubature points in physical space |
| 1246 |
FieldContainer<double> worksetCubPoints (worksetSize,numCubPoints, cubDim); |
| 1247 |
|
| 1248 |
// Containers for element HGRAD mass matrix |
| 1249 |
FieldContainer<double> massMatrixHGrad (worksetSize, numFieldsG, numFieldsG); |
| 1250 |
FieldContainer<double> weightedMeasure (worksetSize, numCubPoints); |
| 1251 |
FieldContainer<double> weightedMeasureMuInv (worksetSize, numCubPoints); |
| 1252 |
FieldContainer<double> HGValsTransformed (worksetSize, numFieldsG, numCubPoints); |
| 1253 |
FieldContainer<double> HGValsTransformedWeighted (worksetSize, numFieldsG, numCubPoints); |
| 1254 |
|
| 1255 |
// Containers for element HCURL mass matrix |
| 1256 |
FieldContainer<double> massMatrixHCurl (worksetSize, numFieldsC, numFieldsC); |
| 1257 |
FieldContainer<double> HCValsTransformed (worksetSize, numFieldsC, numCubPoints, spaceDim); |
| 1258 |
FieldContainer<double> HCValsTransformedWeighted (worksetSize, numFieldsC, numCubPoints, spaceDim); |
| 1259 |
|
| 1260 |
// Containers for element HCURL stiffness matrix |
| 1261 |
FieldContainer<double> stiffMatrixHCurl (worksetSize, numFieldsC, numFieldsC); |
| 1262 |
FieldContainer<double> weightedMeasureMu (worksetSize, numCubPoints); |
| 1263 |
FieldContainer<double> HCurlsTransformed (worksetSize, numFieldsC, numCubPoints, spaceDim); |
| 1264 |
FieldContainer<double> HCurlsTransformedWeighted (worksetSize, numFieldsC, numCubPoints, spaceDim); |
| 1265 |
|
| 1266 |
// Containers for right hand side vectors |
| 1267 |
FieldContainer<double> rhsDatag (worksetSize, numCubPoints, cubDim); |
| 1268 |
FieldContainer<double> rhsDatah (worksetSize, numCubPoints, cubDim); |
| 1269 |
FieldContainer<double> gC (worksetSize, numFieldsC); |
| 1270 |
FieldContainer<double> hC (worksetSize, numFieldsC); |
| 1271 |
|
| 1272 |
// Containers for right hand side boundary term |
| 1273 |
FieldContainer<double> hCBoundary (1, numFieldsC); |
| 1274 |
FieldContainer<double> refFacePoints (numFacePoints,spaceDim); |
| 1275 |
FieldContainer<double> cellNodes (1, numNodesPerElem, spaceDim); |
| 1276 |
FieldContainer<double> worksetFacePoints (1, numFacePoints, spaceDim); |
| 1277 |
FieldContainer<double> faceJacobians (1, numFacePoints, spaceDim, spaceDim); |
| 1278 |
FieldContainer<double> faceJacobInv (1, numFacePoints, spaceDim, spaceDim); |
| 1279 |
FieldContainer<double> faceNormal (1, numFacePoints, spaceDim); |
| 1280 |
FieldContainer<double> bcFaceCVals (numFieldsC, numFacePoints, spaceDim); |
| 1281 |
FieldContainer<double> faceVFieldVals (1, numFacePoints, spaceDim); |
| 1282 |
FieldContainer<double> bcCValsTransformed (1, numFieldsC, numFacePoints, spaceDim); |
| 1283 |
FieldContainer<double> divuFace (1, numFacePoints); |
| 1284 |
FieldContainer<double> bcFieldDotNormal (1, numFieldsC, numFacePoints); |
| 1285 |
FieldContainer<double> bcEdgeSigns (1, numFieldsC); |
| 1286 |
|
| 1287 |
|
| 1288 |
/**********************************************************************************/ |
| 1289 |
/* Calculate Jacobians */ |
| 1290 |
/**********************************************************************************/ |
| 1291 |
|
| 1292 |
IntrepidCTools::setJacobian (worksetJacobian, cubPoints, cellWorkset, cellType); |
| 1293 |
IntrepidCTools::setJacobianInv(worksetJacobInv, worksetJacobian ); |
| 1294 |
IntrepidCTools::setJacobianDet(worksetJacobDet, worksetJacobian ); |
| 1295 |
|
| 1296 |
if(MyPID==0) {std::cout << "Calculate Jacobians " |
| 1297 |
<< Time.ElapsedTime() << " sec \n"; Time.ResetStartTime();} |
| 1298 |
|
| 1299 |
|
| 1300 |
/**********************************************************************************/ |
| 1301 |
/* Compute HGRAD Mass Matrix */ |
| 1302 |
/**********************************************************************************/ |
| 1303 |
|
| 1304 |
// transform to physical coordinates |
| 1305 |
IntrepidFSTools::HGRADtransformVALUE<double>(HGValsTransformed, HGVals); |
| 1306 |
|
| 1307 |
// compute weighted measure |
| 1308 |
IntrepidFSTools::computeCellMeasure<double>(weightedMeasure, worksetJacobDet, cubWeights); |
| 1309 |
|
| 1310 |
// combine mu value with weighted measure |
| 1311 |
cellCounter = 0; |
| 1312 |
for(int cell = worksetBegin; cell < worksetEnd; cell++){ |
| 1313 |
for (int nPt = 0; nPt < numCubPoints; nPt++){ |
| 1314 |
weightedMeasureMuInv(cellCounter,nPt) = weightedMeasure(cellCounter,nPt) / muVal(cell); |
| 1315 |
} |
| 1316 |
cellCounter++; |
| 1317 |
} |
| 1318 |
|
| 1319 |
// multiply values with weighted measure |
| 1320 |
IntrepidFSTools::multiplyMeasure<double>(HGValsTransformedWeighted, |
| 1321 |
weightedMeasureMuInv, HGValsTransformed); |
| 1322 |
|
| 1323 |
// integrate to compute element mass matrix |
| 1324 |
IntrepidFSTools::integrate<double>(massMatrixHGrad, |
| 1325 |
HGValsTransformed, HGValsTransformedWeighted, COMP_BLAS); |
| 1326 |
|
| 1327 |
if(MyPID==0) {std::cout << "Compute HGRAD Mass Matrix " |
| 1328 |
<< Time.ElapsedTime() << " sec \n"; Time.ResetStartTime();} |
| 1329 |
|
| 1330 |
|
| 1331 |
/**********************************************************************************/ |
| 1332 |
/* Compute HCURL Mass Matrix */ |
| 1333 |
/**********************************************************************************/ |
| 1334 |
|
| 1335 |
// transform to physical coordinates |
| 1336 |
IntrepidFSTools::HCURLtransformVALUE<double>(HCValsTransformed, worksetJacobInv, |
| 1337 |
HCVals); |
| 1338 |
|
| 1339 |
// multiply by weighted measure |
| 1340 |
IntrepidFSTools::multiplyMeasure<double>(HCValsTransformedWeighted, |
| 1341 |
weightedMeasure, HCValsTransformed); |
| 1342 |
|
| 1343 |
// integrate to compute element mass matrix |
| 1344 |
IntrepidFSTools::integrate<double>(massMatrixHCurl, |
| 1345 |
HCValsTransformed, HCValsTransformedWeighted, |
| 1346 |
COMP_BLAS); |
| 1347 |
|
| 1348 |
// apply edge signs |
| 1349 |
IntrepidFSTools::applyLeftFieldSigns<double> (massMatrixHCurl, worksetEdgeSigns); |
| 1350 |
IntrepidFSTools::applyRightFieldSigns<double>(massMatrixHCurl, worksetEdgeSigns); |
| 1351 |
|
| 1352 |
if(MyPID==0) {std::cout << "Compute HCURL Mass Matrix " |
| 1353 |
<< Time.ElapsedTime() << " sec \n"; Time.ResetStartTime();} |
| 1354 |
|
| 1355 |
|
| 1356 |
/**********************************************************************************/ |
| 1357 |
/* Compute HCURL Stiffness Matrix */ |
| 1358 |
/**********************************************************************************/ |
| 1359 |
|
| 1360 |
// transform to physical coordinates |
| 1361 |
IntrepidFSTools::HCURLtransformCURL<double>(HCurlsTransformed, worksetJacobian, worksetJacobDet, |
| 1362 |
HCurls); |
| 1363 |
|
| 1364 |
// combine mu value with weighted measure |
| 1365 |
cellCounter = 0; |
| 1366 |
for(int cell = worksetBegin; cell < worksetEnd; cell++){ |
| 1367 |
for (int nPt = 0; nPt < numCubPoints; nPt++){ |
| 1368 |
weightedMeasureMu(cellCounter,nPt) = weightedMeasure(cellCounter,nPt) * muVal(cell); |
| 1369 |
} |
| 1370 |
cellCounter++; |
| 1371 |
} |
| 1372 |
|
| 1373 |
// multiply by weighted measure |
| 1374 |
IntrepidFSTools::multiplyMeasure<double>(HCurlsTransformedWeighted, |
| 1375 |
weightedMeasure, HCurlsTransformed); |
| 1376 |
|
| 1377 |
// integrate to compute element stiffness matrix |
| 1378 |
IntrepidFSTools::integrate<double>(stiffMatrixHCurl, |
| 1379 |
HCurlsTransformed, HCurlsTransformedWeighted, |
| 1380 |
COMP_BLAS); |
| 1381 |
|
| 1382 |
// apply edge signs |
| 1383 |
IntrepidFSTools::applyLeftFieldSigns<double> (stiffMatrixHCurl, worksetEdgeSigns); |
| 1384 |
IntrepidFSTools::applyRightFieldSigns<double>(stiffMatrixHCurl, worksetEdgeSigns); |
| 1385 |
|
| 1386 |
if(MyPID==0) {std::cout << "Compute HCURL Stiffness Matrix " |
| 1387 |
<< Time.ElapsedTime() << " sec \n"; Time.ResetStartTime();} |
| 1388 |
|
| 1389 |
|
| 1390 |
/**********************************************************************************/ |
| 1391 |
/* Build Right Hand Side */ |
| 1392 |
/**********************************************************************************/ |
| 1393 |
|
| 1394 |
// transform integration points to physical points |
| 1395 |
IntrepidCTools::mapToPhysicalFrame(worksetCubPoints, cubPoints, cellWorkset, cellType); |
| 1396 |
|
| 1397 |
// evaluate right hand side functions at physical points |
| 1398 |
for(int cell = worksetBegin; cell < worksetEnd; cell++){ |
| 1399 |
|
| 1400 |
// Compute cell ordinal relative to the current workset |
| 1401 |
int worksetCellOrdinal = cell - worksetBegin; |
| 1402 |
|
| 1403 |
for (int nPt = 0; nPt < numCubPoints; nPt++){ |
| 1404 |
double x = worksetCubPoints(worksetCellOrdinal,nPt,0); |
| 1405 |
double y = worksetCubPoints(worksetCellOrdinal,nPt,1); |
| 1406 |
double z = worksetCubPoints(worksetCellOrdinal,nPt,2); |
| 1407 |
double du1, du2, du3; |
| 1408 |
|
| 1409 |
evalCurlu(du1, du2, du3, x, y, z, muVal(cell)); |
| 1410 |
rhsDatag(worksetCellOrdinal,nPt,0) = du1; |
| 1411 |
rhsDatag(worksetCellOrdinal,nPt,1) = du2; |
| 1412 |
rhsDatag(worksetCellOrdinal,nPt,2) = du3; |
| 1413 |
|
| 1414 |
evalGradDivu(du1, du2, du3, x, y, z, muVal(cell)); |
| 1415 |
rhsDatah(worksetCellOrdinal,nPt,0) = du1; |
| 1416 |
rhsDatah(worksetCellOrdinal,nPt,1) = du2; |
| 1417 |
rhsDatah(worksetCellOrdinal,nPt,2) = du3; |
| 1418 |
} |
| 1419 |
} |
| 1420 |
|
| 1421 |
// integrate (g,curl w) term |
| 1422 |
IntrepidFSTools::integrate<double>(gC, rhsDatag, HCurlsTransformedWeighted, |
| 1423 |
COMP_BLAS); |
| 1424 |
|
| 1425 |
// integrate (h,div w) term |
| 1426 |
IntrepidFSTools::integrate<double>(hC, rhsDatah, HCValsTransformedWeighted, |
| 1427 |
COMP_BLAS); |
| 1428 |
// apply signs |
| 1429 |
IntrepidFSTools::applyFieldSigns<double>(gC, worksetEdgeSigns); |
| 1430 |
IntrepidFSTools::applyFieldSigns<double>(hC, worksetEdgeSigns); |
| 1431 |
|
| 1432 |
|
| 1433 |
// evaluate RHS boundary term |
| 1434 |
for(int cell = worksetBegin; cell < worksetEnd; cell++){ |
| 1435 |
|
| 1436 |
// Compute cell ordinal relative to the current workset |
| 1437 |
int worksetCellOrdinal = cell - worksetBegin; |
| 1438 |
|
| 1439 |
// evaluate boundary term |
| 1440 |
for (int iface = 0; iface < numFacesPerElem; iface++){ |
| 1441 |
if (faceOnBoundary(elemToFace(cell,iface))){ |
| 1442 |
|
| 1443 |
// cell nodal coordinates |
| 1444 |
for (int inode =0; inode < numNodesPerElem; inode++){ |
| 1445 |
cellNodes(0,inode,0) = cellWorkset(worksetCellOrdinal,inode,0); |
| 1446 |
cellNodes(0,inode,1) = cellWorkset(worksetCellOrdinal,inode,1); |
| 1447 |
cellNodes(0,inode,2) = cellWorkset(worksetCellOrdinal,inode,2); |
| 1448 |
} |
| 1449 |
|
| 1450 |
// cell edge signs |
| 1451 |
for (int iedge =0; iedge < numEdgesPerElem; iedge++){ |
| 1452 |
bcEdgeSigns(0,iedge) = worksetEdgeSigns(worksetCellOrdinal,iedge); |
| 1453 |
} |
| 1454 |
|
| 1455 |
// map Gauss points on quad to reference face: paramFacePoints -> refFacePoints |
| 1456 |
IntrepidCTools::mapToReferenceSubcell(refFacePoints, |
| 1457 |
paramFacePoints, |
| 1458 |
2, iface, cellType); |
| 1459 |
|
| 1460 |
// get basis values at points on reference cell |
| 1461 |
hexHCurlBasis.getValues(bcFaceCVals, refFacePoints, OPERATOR_VALUE); |
| 1462 |
|
| 1463 |
// compute Jacobians at Gauss pts. on reference face for all parent cells |
| 1464 |
IntrepidCTools::setJacobian(faceJacobians, |
| 1465 |
refFacePoints, |
| 1466 |
cellNodes, cellType); |
| 1467 |
IntrepidCTools::setJacobianInv(faceJacobInv, faceJacobians ); |
| 1468 |
|
| 1469 |
// transform to physical coordinates |
| 1470 |
IntrepidFSTools::HCURLtransformVALUE<double>(bcCValsTransformed, faceJacobInv, |
| 1471 |
bcFaceCVals); |
| 1472 |
|
| 1473 |
// map Gauss points on quad from ref. face to face workset: refFacePoints -> worksetFacePoints |
| 1474 |
IntrepidCTools::mapToPhysicalFrame(worksetFacePoints, |
| 1475 |
refFacePoints, |
| 1476 |
cellNodes, cellType); |
| 1477 |
|
| 1478 |
// Compute face normals |
| 1479 |
IntrepidCTools::getPhysicalFaceNormals(faceNormal, |
| 1480 |
faceJacobians, |
| 1481 |
iface, cellType); |
| 1482 |
|
| 1483 |
// evaluate div u at face points |
| 1484 |
for(int nPt = 0; nPt < numFacePoints; nPt++){ |
| 1485 |
|
| 1486 |
double x = worksetFacePoints(0, nPt, 0); |
| 1487 |
double y = worksetFacePoints(0, nPt, 1); |
| 1488 |
double z = worksetFacePoints(0, nPt, 2); |
| 1489 |
|
| 1490 |
divuFace(0,nPt)=evalDivu(x, y, z, muVal(cell)); |
| 1491 |
} |
| 1492 |
|
| 1493 |
// compute the dot product and multiply by Gauss weights |
| 1494 |
for (int nF = 0; nF < numFieldsC; nF++){ |
| 1495 |
for(int nPt = 0; nPt < numFacePoints; nPt++){ |
| 1496 |
bcFieldDotNormal(0,nF,nPt)=0.0; |
| 1497 |
for (int dim = 0; dim < spaceDim; dim++){ |
| 1498 |
bcFieldDotNormal(0,nF,nPt) += bcCValsTransformed(0,nF,nPt,dim) |
| 1499 |
* faceNormal(0,nPt,dim) * paramFaceWeights(nPt); |
| 1500 |
} //dim |
| 1501 |
} //nPt |
| 1502 |
} //nF |
| 1503 |
|
| 1504 |
// integrate |
| 1505 |
IntrepidFSTools::integrate<double>(hCBoundary, divuFace, bcFieldDotNormal, |
| 1506 |
COMP_CPP); |
| 1507 |
|
| 1508 |
// apply signs |
| 1509 |
IntrepidFSTools::applyFieldSigns<double>(hCBoundary, bcEdgeSigns); |
| 1510 |
|
| 1511 |
// add into hC term |
| 1512 |
for (int nF = 0; nF < numFieldsC; nF++){ |
| 1513 |
hC(worksetCellOrdinal,nF) = hC(worksetCellOrdinal,nF) - hCBoundary(0,nF); |
| 1514 |
} |
| 1515 |
|
| 1516 |
} // if faceOnBoundary |
| 1517 |
|
| 1518 |
} // numFaces |
| 1519 |
|
| 1520 |
}// *** workset cell loop ** |
| 1521 |
|
| 1522 |
|
| 1523 |
if(MyPID==0) {std::cout << "Compute right-hand side " |
| 1524 |
<< Time.ElapsedTime() << " sec \n"; Time.ResetStartTime();} |
| 1525 |
|
| 1526 |
|
| 1527 |
/**********************************************************************************/ |
| 1528 |
/* Assemble into Global Matrix */ |
| 1529 |
/**********************************************************************************/ |
| 1530 |
|
| 1531 |
// Loop over workset cells |
| 1532 |
for(int cell = worksetBegin; cell < worksetEnd; cell++){ |
| 1533 |
|
| 1534 |
// Compute cell ordinal relative to the current workset |
| 1535 |
int worksetCellOrdinal = cell - worksetBegin; |
| 1536 |
|
| 1537 |
|
| 1538 |
/*** Assemble H(grad) mass matrix ***/ |
| 1539 |
|
| 1540 |
// loop over nodes for matrix row |
| 1541 |
for (int cellNodeRow = 0; cellNodeRow < numFieldsG; cellNodeRow++){ |
| 1542 |
|
| 1543 |
int localNodeRow = elemToNode(cell, cellNodeRow); |
| 1544 |
int globalNodeRow = globalNodeIds[localNodeRow]; |
| 1545 |
|
| 1546 |
// loop over nodes for matrix column |
| 1547 |
for (int cellNodeCol = 0; cellNodeCol < numFieldsG; cellNodeCol++){ |
| 1548 |
|
| 1549 |
int localNodeCol = elemToNode(cell, cellNodeCol); |
| 1550 |
int globalNodeCol = globalNodeIds[localNodeCol]; |
| 1551 |
double massGContribution = massMatrixHGrad(worksetCellOrdinal, cellNodeRow, cellNodeCol); |
| 1552 |
|
| 1553 |
MassMatrixG.InsertGlobalValues(1, &globalNodeRow, 1, &globalNodeCol, &massGContribution); |
| 1554 |
|
| 1555 |
}// *** cell node col loop *** |
| 1556 |
}// *** cell node row loop *** |
| 1557 |
|
| 1558 |
|
| 1559 |
/*** Assemble H(curl) mass matrix, stiffness matrix and right-hand side ***/ |
| 1560 |
|
| 1561 |
// loop over edges for matrix row |
| 1562 |
for (int cellEdgeRow = 0; cellEdgeRow < numFieldsC; cellEdgeRow++){ |
| 1563 |
|
| 1564 |
int localEdgeRow = elemToEdge(cell, cellEdgeRow); |
| 1565 |
int globalEdgeRow = globalEdgeIds[localEdgeRow]; |
| 1566 |
double rhsContribution = gC(worksetCellOrdinal, cellEdgeRow) - hC(worksetCellOrdinal, cellEdgeRow); |
| 1567 |
|
| 1568 |
rhsVector.SumIntoGlobalValues(1, &globalEdgeRow, &rhsContribution); |
| 1569 |
|
| 1570 |
// loop over edges for matrix column |
| 1571 |
for (int cellEdgeCol = 0; cellEdgeCol < numFieldsC; cellEdgeCol++){ |
| 1572 |
|
| 1573 |
int localEdgeCol = elemToEdge(cell, cellEdgeCol); |
| 1574 |
int globalEdgeCol = globalEdgeIds[localEdgeCol]; |
| 1575 |
|
| 1576 |
double massCContribution = massMatrixHCurl (worksetCellOrdinal, cellEdgeRow, cellEdgeCol); |
| 1577 |
double stiffCContribution = stiffMatrixHCurl(worksetCellOrdinal, cellEdgeRow, cellEdgeCol); |
| 1578 |
|
| 1579 |
MassMatrixC.InsertGlobalValues (1, &globalEdgeRow, 1, &globalEdgeCol, &massCContribution); |
| 1580 |
StiffMatrixC.InsertGlobalValues(1, &globalEdgeRow, 1, &globalEdgeCol, &stiffCContribution); |
| 1581 |
|
| 1582 |
|
| 1583 |
}// *** cell edge col loop *** |
| 1584 |
}// *** cell edge row loop *** |
| 1585 |
|
| 1586 |
}// *** workset cell loop ** |
| 1587 |
}// *** workset loop *** |
| 1588 |
|
| 1589 |
if(MyPID==0) {std::cout << "Assemble Matrices " |
| 1590 |
<< Time.ElapsedTime() << " sec \n"; Time.ResetStartTime();} |
| 1591 |
|
| 1592 |
|
| 1593 |
/**********************************************************************************/ |
| 1594 |
/********************* ASSEMBLE OVER MULTIPLE PROCESSORS **************************/ |
| 1595 |
/**********************************************************************************/ |
| 1596 |
|
| 1597 |
// Assemble over multiple processors, if necessary |
| 1598 |
MassMatrixG.GlobalAssemble(); MassMatrixG.FillComplete(); |
| 1599 |
StiffMatrixC.GlobalAssemble(); StiffMatrixC.FillComplete(); |
| 1600 |
MassMatrixC.GlobalAssemble(); MassMatrixC.FillComplete(); |
| 1601 |
rhsVector.GlobalAssemble(); |
| 1602 |
|
| 1603 |
|
| 1604 |
if(MyPID==0) {std::cout << "Global assembly " |
| 1605 |
<< Time.ElapsedTime() << " sec \n"; Time.ResetStartTime();} |
| 1606 |
|
| 1607 |
|
| 1608 |
#ifdef DUMP_DATA |
| 1609 |
// Node Coordinates |
| 1610 |
EpetraExt::VectorToMatrixMarketFile("coordx.dat",Nx,0,0,false); |
| 1611 |
EpetraExt::VectorToMatrixMarketFile("coordy.dat",Ny,0,0,false); |
| 1612 |
EpetraExt::VectorToMatrixMarketFile("coordz.dat",Nz,0,0,false); |
| 1613 |
|
| 1614 |
// Edge Coordinates |
| 1615 |
EpetraExt::VectorToMatrixMarketFile("ecoordx.dat",EDGE_X); |
| 1616 |
EpetraExt::VectorToMatrixMarketFile("ecoordy.dat",EDGE_Y); |
| 1617 |
EpetraExt::VectorToMatrixMarketFile("ecoordz.dat",EDGE_Z); |
| 1618 |
|
| 1619 |
// Edge signs |
| 1620 |
EpetraExt::MultiVectorToMatrixMarketFile("edge_signs.dat",edgeSign,0,0,false); |
| 1621 |
#endif |
| 1622 |
|
| 1623 |
|
| 1624 |
/**********************************************************************************/ |
| 1625 |
/*********************** ADJUST MATRICES AND RHS FOR BCs **************************/ |
| 1626 |
/**********************************************************************************/ |
| 1627 |
|
| 1628 |
// Build the inverse diagonal for MassMatrixG |
| 1629 |
Epetra_Vector DiagG(MassMatrixG.RowMap()); |
| 1630 |
DiagG.PutScalar(1.0); |
| 1631 |
MassMatrixG.Multiply(false,DiagG,DiagG); |
| 1632 |
for(int i=0;i<DiagG.MyLength();i++) { |
| 1633 |
DiagG[i]=1.0/DiagG[i]; |
| 1634 |
} |
| 1635 |
Epetra_CrsMatrix MassMatrixGinv(Copy,MassMatrixG.RowMap(),MassMatrixG.RowMap(),1); |
| 1636 |
for(int i=0;i<DiagG.MyLength();i++) { |
| 1637 |
int CID=MassMatrixG.GCID(i); |
| 1638 |
MassMatrixGinv.InsertGlobalValues(MassMatrixG.GRID(i),1,&(DiagG[i]),&CID); |
| 1639 |
} |
| 1640 |
MassMatrixGinv.FillComplete(); |
| 1641 |
|
| 1642 |
// Zero out entries that correspond to boundary nodes |
| 1643 |
for(int i=0;i<numNodes;i++) { |
| 1644 |
if (nodeOnBoundary(i)){ |
| 1645 |
double val=0.0; |
| 1646 |
int index = globalNodeIds[i]; |
| 1647 |
MassMatrixGinv.ReplaceGlobalValues(index,1,&val,&index); |
| 1648 |
} |
| 1649 |
} |
| 1650 |
|
| 1651 |
// Get the full matrix operator |
| 1652 |
ML_Epetra::ML_RefMaxwell_11_Operator MatrixC(StiffMatrixC,DGrad,MassMatrixGinv,MassMatrixC); |
| 1653 |
|
| 1654 |
// Apply it to v |
| 1655 |
Epetra_MultiVector rhsDir(globalMapC,true); |
| 1656 |
MatrixC.Apply(v,rhsDir); |
| 1657 |
|
| 1658 |
// Update right-hand side |
| 1659 |
rhsVector.Update(-1.0,rhsDir,1.0); |
| 1660 |
|
| 1661 |
// Adjust rhs due to Dirichlet boundary conditions |
| 1662 |
indbc=0; |
| 1663 |
int indOwned=0; |
| 1664 |
for (int i=0; i<numEdges; i++){ |
| 1665 |
if (edgeIsOwned[i]){ |
| 1666 |
if (edgeOnBoundary(i)){ |
| 1667 |
indbc++; |
| 1668 |
rhsVector[0][indOwned]=bndyEdgeVal(bndyEdgeToEdge(i)); |
| 1669 |
rhsDir[0][indOwned]=0.0; |
| 1670 |
} |
| 1671 |
indOwned++; |
| 1672 |
} |
| 1673 |
} |
| 1674 |
|
| 1675 |
// Zero out rows and columns of stiffness matrix corresponding to Dirichlet edges |
| 1676 |
// and add one to diagonal. |
| 1677 |
ML_Epetra::Apply_OAZToMatrix(BCEdges, numBCEdges, StiffMatrixC); |
| 1678 |
|
| 1679 |
delete [] BCEdges; |
| 1680 |
|
| 1681 |
if(MyPID==0) {std::cout << "Adjust global matrix and rhs due to BCs " << Time.ElapsedTime() |
| 1682 |
<< " sec \n"; Time.ResetStartTime();} |
| 1683 |
|
| 1684 |
|
| 1685 |
/**********************************************************************************/ |
| 1686 |
/*********************************** SOLVE ****************************************/ |
| 1687 |
/**********************************************************************************/ |
| 1688 |
|
| 1689 |
// Parameter list for ML |
| 1690 |
Teuchos::ParameterList MLList,dummy; |
| 1691 |
double TotalErrorResidual=0, TotalErrorExactSol=0; |
| 1692 |
ML_Epetra::SetDefaultsRefMaxwell(MLList); |
| 1693 |
Teuchos::ParameterList MLList2=MLList.get("refmaxwell: 11list",MLList); |
| 1694 |
MLList2.set("aggregation: type","Uncoupled-MIS"); |
| 1695 |
MLList2.set("x-coordinates",&Nx[0]); |
| 1696 |
MLList2.set("y-coordinates",&Ny[0]); |
| 1697 |
MLList2.set("z-coordinates",&Nz[0]); |
| 1698 |
MLList2.set("ML output",10); |
| 1699 |
MLList2.set("smoother: sweeps (level 0)",3); |
| 1700 |
MLList2.set("smoother: sweeps",3); |
| 1701 |
MLList2.set("smoother: type","Chebyshev"); |
| 1702 |
// MLList2.set("eigen-analysis: max iters", 20); |
| 1703 |
MLList2.set("eigen-analysis: type", "power-method"); |
| 1704 |
MLList2.get("edge matrix free: coarse",dummy); |
| 1705 |
ML_Epetra::SetDefaults("SA",dummy,0,0,false); |
| 1706 |
dummy.set("PDE equations",3); |
| 1707 |
dummy.set("ML output",10); |
| 1708 |
dummy.set("smoother: sweeps",3); |
| 1709 |
dummy.set("smoother: type","Chebyshev"); |
| 1710 |
dummy.set("aggregation: type","Uncoupled"); |
| 1711 |
dummy.set("smoother: pre or post","both"); |
| 1712 |
dummy.set("max levels",10); |
| 1713 |
dummy.set("coarse: type","Amesos-KLU"); |
| 1714 |
dummy.set("repartition: enable",1); |
| 1715 |
dummy.set("repartition: min per proc",1000); |
| 1716 |
dummy.set("repartition: max min ratio",1.4); |
| 1717 |
dummy.set("repartition: Zoltan dimensions",3); |
| 1718 |
dummy.set("x-coordinates",&Nx[0]); |
| 1719 |
dummy.set("y-coordinates",&Ny[0]); |
| 1720 |
dummy.set("z-coordinates",&Nz[0]); |
| 1721 |
MLList2.set("edge matrix free: coarse",dummy); |
| 1722 |
|
| 1723 |
if (MyPID == 0) { |
| 1724 |
cout<<MLList2<<endl; |
| 1725 |
} |
| 1726 |
|
| 1727 |
Epetra_FEVector xh(rhsVector); |
| 1728 |
|
| 1729 |
MassMatrixC.SetLabel("M1"); |
| 1730 |
StiffMatrixC.SetLabel("K1"); |
| 1731 |
DGrad.SetLabel("D0"); |
| 1732 |
MassMatrixGinv.SetLabel("M0^{-1}"); |
| 1733 |
|
| 1734 |
char probType[12] = "curl_lsfem"; |
| 1735 |
|
| 1736 |
TestMultiLevelPreconditioner_CurlLSFEM(probType,MLList2,StiffMatrixC, |
| 1737 |
DGrad,MassMatrixGinv,MassMatrixC, |
| 1738 |
xh,rhsVector, |
| 1739 |
TotalErrorResidual, TotalErrorExactSol); |
| 1740 |
|
| 1741 |
/**********************************************************************************/ |
| 1742 |
/**************************** CALCULATE ERROR *************************************/ |
| 1743 |
/**********************************************************************************/ |
| 1744 |
|
| 1745 |
if (MyPID == 0) {Time.ResetStartTime();} |
| 1746 |
|
| 1747 |
double L2err = 0.0; |
| 1748 |
double HCurlerr = 0.0; |
| 1749 |
double Linferr = 0.0; |
| 1750 |
double L2errTot = 0.0; |
| 1751 |
double HCurlerrTot = 0.0; |
| 1752 |
double LinferrTot = 0.0; |
| 1753 |
|
| 1754 |
#ifdef HAVE_MPI |
| 1755 |
// Import solution onto current processor |
| 1756 |
Epetra_Map solnMap(numEdgesGlobal, numEdgesGlobal, 0, Comm); |
| 1757 |
Epetra_Import solnImporter(solnMap, globalMapC); |
| 1758 |
Epetra_FEVector uCoeff(solnMap); |
| 1759 |
uCoeff.Import(xh, solnImporter, Insert); |
| 1760 |
#endif |
| 1761 |
|
| 1762 |
int numCells = 1; |
| 1763 |
FieldContainer<double> hexEdgeSigns(numCells, numFieldsC); |
| 1764 |
FieldContainer<double> hexNodes(numCells, numFieldsG, spaceDim); |
| 1765 |
|
| 1766 |
// Get cubature points and weights for error calc (may be different from previous) |
| 1767 |
DefaultCubatureFactory<double> cubFactoryErr; |
| 1768 |
int cubDegErr = 3; |
| 1769 |
Teuchos::RCP<Cubature<double> > hexCubErr = cubFactoryErr.create(cellType, cubDegErr); |
| 1770 |
int cubDimErr = hexCubErr->getDimension(); |
| 1771 |
int numCubPointsErr = hexCubErr->getNumPoints(); |
| 1772 |
FieldContainer<double> cubPointsErr(numCubPointsErr, cubDimErr); |
| 1773 |
FieldContainer<double> cubWeightsErr(numCubPointsErr); |
| 1774 |
hexCubErr->getCubature(cubPointsErr, cubWeightsErr); |
| 1775 |
FieldContainer<double> physCubPointsE(numCells,numCubPointsErr, cubDimErr); |
| 1776 |
|
| 1777 |
// Containers for Jacobian |
| 1778 |
FieldContainer<double> hexJacobianE(numCells, numCubPointsErr, spaceDim, spaceDim); |
| 1779 |
FieldContainer<double> hexJacobInvE(numCells, numCubPointsErr, spaceDim, spaceDim); |
| 1780 |
FieldContainer<double> hexJacobDetE(numCells, numCubPointsErr); |
| 1781 |
FieldContainer<double> weightedMeasureE(numCells, numCubPointsErr); |
| 1782 |
|
| 1783 |
// Evaluate basis values and curls at cubature points |
| 1784 |
FieldContainer<double> uhCVals(numFieldsC, numCubPointsErr, spaceDim); |
| 1785 |
FieldContainer<double> uhCValsTrans(numCells,numFieldsC, numCubPointsErr, spaceDim); |
| 1786 |
FieldContainer<double> uhCurls(numFieldsC, numCubPointsErr, spaceDim); |
| 1787 |
FieldContainer<double> uhCurlsTrans(numCells, numFieldsC, numCubPointsErr, spaceDim); |
| 1788 |
hexHCurlBasis.getValues(uhCVals, cubPointsErr, OPERATOR_VALUE); |
| 1789 |
hexHCurlBasis.getValues(uhCurls, cubPointsErr, OPERATOR_CURL); |
| 1790 |
|
| 1791 |
// Loop over elements |
| 1792 |
for (int k=0; k<numElems; k++){ |
| 1793 |
|
| 1794 |
double L2errElem = 0.0; |
| 1795 |
double HCurlerrElem = 0.0; |
| 1796 |
double uExact1, uExact2, uExact3; |
| 1797 |
double curluExact1, curluExact2, curluExact3; |
| 1798 |
|
| 1799 |
// physical cell coordinates |
| 1800 |
for (int i=0; i<numNodesPerElem; i++) { |
| 1801 |
hexNodes(0,i,0) = nodeCoord(elemToNode(k,i),0); |
| 1802 |
hexNodes(0,i,1) = nodeCoord(elemToNode(k,i),1); |
| 1803 |
hexNodes(0,i,2) = nodeCoord(elemToNode(k,i),2); |
| 1804 |
} |
| 1805 |
// Edge signs |
| 1806 |
for (int j=0; j<numEdgesPerElem; j++) { |
| 1807 |
if (elemToNode(k,refEdgeToNode(j,0))==edgeToNode(elemToEdge(k,j),0) && |
| 1808 |
elemToNode(k,refEdgeToNode(j,1))==edgeToNode(elemToEdge(k,j),1)) |
| 1809 |
hexEdgeSigns(0,j) = 1.0; |
| 1810 |
else |
| 1811 |
hexEdgeSigns(0,j) = -1.0; |
| 1812 |
} |
| 1813 |
|
| 1814 |
// modify signs for edges whose signs were defined on another processor |
| 1815 |
if (!faceIsOwned[elemToFace(k,0)]) { |
| 1816 |
hexEdgeSigns(0,0)=-1.0*hexEdgeSigns(0,0); |
| 1817 |
hexEdgeSigns(0,4)=-1.0*hexEdgeSigns(0,4); |
| 1818 |
} |
| 1819 |
if (!faceIsOwned[elemToFace(k,1)]) { |
| 1820 |
hexEdgeSigns(0,1)=-1.0*hexEdgeSigns(0,1); |
| 1821 |
hexEdgeSigns(0,5)=-1.0*hexEdgeSigns(0,5); |
| 1822 |
} |
| 1823 |
if (!faceIsOwned[elemToFace(k,2)]) { |
| 1824 |
hexEdgeSigns(0,2)=-1.0*hexEdgeSigns(0,2); |
| 1825 |
hexEdgeSigns(0,6)=-1.0*hexEdgeSigns(0,6); |
| 1826 |
} |
| 1827 |
if (!faceIsOwned[elemToFace(k,3)]) { |
| 1828 |
hexEdgeSigns(0,3)=-1.0*hexEdgeSigns(0,3); |
| 1829 |
hexEdgeSigns(0,7)=-1.0*hexEdgeSigns(0,7); |
| 1830 |
} |
| 1831 |
|
| 1832 |
// compute cell Jacobians, their inverses and their determinants |
| 1833 |
IntrepidCTools::setJacobian(hexJacobianE, cubPointsErr, hexNodes, cellType); |
| 1834 |
IntrepidCTools::setJacobianInv(hexJacobInvE, hexJacobianE ); |
| 1835 |
IntrepidCTools::setJacobianDet(hexJacobDetE, hexJacobianE ); |
| 1836 |
|
| 1837 |
// transform integration points to physical points |
| 1838 |
IntrepidCTools::mapToPhysicalFrame(physCubPointsE, cubPointsErr, hexNodes, cellType); |
| 1839 |
|
| 1840 |
// transform basis values to physical coordinates |
| 1841 |
IntrepidFSTools::HCURLtransformVALUE<double>(uhCValsTrans, hexJacobInvE, uhCVals); |
| 1842 |
IntrepidFSTools::HCURLtransformCURL<double>(uhCurlsTrans, hexJacobianE, hexJacobDetE, uhCurls); |
| 1843 |
|
| 1844 |
// compute weighted measure |
| 1845 |
IntrepidFSTools::computeCellMeasure<double>(weightedMeasureE, hexJacobDetE, cubWeightsErr); |
| 1846 |
|
| 1847 |
// loop over cubature points |
| 1848 |
for (int nPt = 0; nPt < numCubPointsErr; nPt++){ |
| 1849 |
|
| 1850 |
// get exact solution and curls |
| 1851 |
double x = physCubPointsE(0,nPt,0); |
| 1852 |
double y = physCubPointsE(0,nPt,1); |
| 1853 |
double z = physCubPointsE(0,nPt,2); |
| 1854 |
evalu(uExact1, uExact2, uExact3, x, y, z); |
| 1855 |
double mu = 1.0; // use mu=1 to get the curl without material parameter |
| 1856 |
evalCurlu(curluExact1, curluExact2, curluExact3, x, y, z, mu); |
| 1857 |
|
| 1858 |
// calculate approximate solution and curls |
| 1859 |
double uApprox1 = 0.0; |
| 1860 |
double uApprox2 = 0.0; |
| 1861 |
double uApprox3 = 0.0; |
| 1862 |
double curluApprox1 = 0.0; |
| 1863 |
double curluApprox2= 0.0; |
| 1864 |
double curluApprox3 = 0.0; |
| 1865 |
for (int i = 0; i < numFieldsC; i++){ |
| 1866 |
int rowIndex = globalEdgeIds[elemToEdge(k,i)]; |
| 1867 |
#ifdef HAVE_MPI |
| 1868 |
double uh1 = uCoeff.Values()[rowIndex]; |
| 1869 |
#else |
| 1870 |
double uh1 = xh.Values()[rowIndex]; |
| 1871 |
#endif |
| 1872 |
uApprox1 += uh1*uhCValsTrans(0,i,nPt,0)*hexEdgeSigns(0,i); |
| 1873 |
uApprox2 += uh1*uhCValsTrans(0,i,nPt,1)*hexEdgeSigns(0,i); |
| 1874 |
uApprox3 += uh1*uhCValsTrans(0,i,nPt,2)*hexEdgeSigns(0,i); |
| 1875 |
curluApprox1 += uh1*uhCurlsTrans(0,i,nPt,0)*hexEdgeSigns(0,i); |
| 1876 |
curluApprox2 += uh1*uhCurlsTrans(0,i,nPt,1)*hexEdgeSigns(0,i); |
| 1877 |
curluApprox3 += uh1*uhCurlsTrans(0,i,nPt,2)*hexEdgeSigns(0,i); |
| 1878 |
} |
| 1879 |
|
| 1880 |
// evaluate the error at cubature points |
| 1881 |
Linferr = max(Linferr, abs(uExact1 - uApprox1)); |
| 1882 |
Linferr = max(Linferr, abs(uExact2 - uApprox2)); |
| 1883 |
Linferr = max(Linferr, abs(uExact3 - uApprox3)); |
| 1884 |
L2errElem+=(uExact1 - uApprox1)*(uExact1 - uApprox1)*weightedMeasureE(0,nPt); |
| 1885 |
L2errElem+=(uExact2 - uApprox2)*(uExact2 - uApprox2)*weightedMeasureE(0,nPt); |
| 1886 |
L2errElem+=(uExact3 - uApprox3)*(uExact3 - uApprox3)*weightedMeasureE(0,nPt); |
| 1887 |
HCurlerrElem+=((curluExact1 - curluApprox1)*(curluExact1 - curluApprox1)) |
| 1888 |
*weightedMeasureE(0,nPt); |
| 1889 |
HCurlerrElem+=((curluExact2 - curluApprox2)*(curluExact2 - curluApprox2)) |
| 1890 |
*weightedMeasureE(0,nPt); |
| 1891 |
HCurlerrElem+=((curluExact3 - curluApprox3)*(curluExact3 - curluApprox3)) |
| 1892 |
*weightedMeasureE(0,nPt); |
| 1893 |
} |
| 1894 |
|
| 1895 |
L2err+=L2errElem; |
| 1896 |
HCurlerr+=HCurlerrElem; |
| 1897 |
} |
| 1898 |
|
| 1899 |
|
| 1900 |
#ifdef HAVE_MPI |
| 1901 |
// sum over all processors |
| 1902 |
Comm.SumAll(&L2err,&L2errTot,1); |
| 1903 |
Comm.SumAll(&HCurlerr,&HCurlerrTot,1); |
| 1904 |
Comm.MaxAll(&Linferr,&LinferrTot,1); |
| 1905 |
#else |
| 1906 |
L2errTot = L2err; |
| 1907 |
HCurlerrTot = HCurlerr; |
| 1908 |
LinferrTot = Linferr; |
| 1909 |
#endif |
| 1910 |
|
| 1911 |
if (MyPID == 0) { |
| 1912 |
std::cout << "\n" << "L2 Error: " << sqrt(L2errTot) <<"\n"; |
| 1913 |
std::cout << "HCurl Error: " << sqrt(HCurlerrTot) <<"\n"; |
| 1914 |
std::cout << "LInf Error: " << LinferrTot <<"\n\n"; |
| 1915 |
} |
| 1916 |
|
| 1917 |
|
| 1918 |
// delete mesh |
| 1919 |
Delete_Pamgen_Mesh(); |
| 1920 |
|
| 1921 |
//clean up |
| 1922 |
for(long long b = 0; b < numElemBlk; b++){ |
| 1923 |
delete [] elmt_node_linkage[b]; |
| 1924 |
delete [] element_types[b]; |
| 1925 |
} |
| 1926 |
delete [] block_ids; |
| 1927 |
delete [] nodes_per_element; |
| 1928 |
delete [] element_attributes; |
| 1929 |
delete [] element_types; |
| 1930 |
delete [] elmt_node_linkage; |
| 1931 |
delete [] elements; |
| 1932 |
delete [] nodeCoordx; |
| 1933 |
delete [] nodeCoordy; |
| 1934 |
delete [] nodeCoordz; |
| 1935 |
|
| 1936 |
delete [] globalNodeIds; |
| 1937 |
delete [] nodeIsOwned; |
| 1938 |
delete [] globalEdgeIds; |
| 1939 |
delete [] edgeIsOwned; |
| 1940 |
delete [] globalFaceIds; |
| 1941 |
delete [] faceIsOwned; |
| 1942 |
if(num_node_comm_maps > 0){ |
| 1943 |
delete [] node_comm_proc_ids; |
| 1944 |
delete [] node_cmap_node_cnts; |
| 1945 |
delete [] node_cmap_ids; |
| 1946 |
for(long long i=0;i<num_node_comm_maps;i++){ |
| 1947 |
delete [] comm_node_ids[i]; |
| 1948 |
delete [] comm_node_proc_ids[i]; |
| 1949 |
} |
| 1950 |
|
| 1951 |
delete [] comm_node_ids; |
| 1952 |
delete [] comm_node_proc_ids; |
| 1953 |
} |
| 1954 |
|
| 1955 |
return 0; |
| 1956 |
} |
| 1957 |
/**********************************************************************************/ |
| 1958 |
/********************************* END MAIN ***************************************/ |
| 1959 |
/**********************************************************************************/ |
| 1960 |
|
| 1961 |
|
| 1962 |
/*************************************************************************************/ |
| 1963 |
/****************************** Multiply Ones ****************************************/ |
| 1964 |
/*************************************************************************************/ |
| 1965 |
/** \brief Multiplies Ax = y, where all non-zero entries of A are replaced with the value 1.0 |
| 1966 |
|
| 1967 |
\param A [in] matrix |
| 1968 |
\param x [in] vector |
| 1969 |
\param y [in] vector |
| 1970 |
*/ |
| 1971 |
int Multiply_Ones(const Epetra_CrsMatrix &A,const Epetra_Vector &x,Epetra_Vector &y){ |
| 1972 |
if(!A.Filled()) |
| 1973 |
EPETRA_CHK_ERR(-1); // Matrix must be filled. |
| 1974 |
|
| 1975 |
double* xp = (double*) x.Values(); |
| 1976 |
double* yp = (double*) y.Values(); |
| 1977 |
const Epetra_Import* Importer_=A.Importer(); |
| 1978 |
const Epetra_Export* Exporter_=A.Exporter(); |
| 1979 |
Epetra_Vector *xcopy=0, *ImportVector_=0, *ExportVector_=0; |
| 1980 |
|
| 1981 |
if (&x==&y && Importer_==0 && Exporter_==0) { |
| 1982 |
xcopy = new Epetra_Vector(x); |
| 1983 |
xp = (double *) xcopy->Values(); |
| 1984 |
} |
| 1985 |
else if (Importer_) |
| 1986 |
ImportVector_ = new Epetra_Vector(Importer_->TargetMap()); |
| 1987 |
else if (Exporter_) |
| 1988 |
ExportVector_ = new Epetra_Vector(Exporter_->SourceMap()); |
| 1989 |
|
| 1990 |
|
| 1991 |
// If we have a non-trivial importer, we must import elements that are permuted or are on other processors |
| 1992 |
if(Importer_ != 0) { |
| 1993 |
EPETRA_CHK_ERR(ImportVector_->Import(x, *Importer_, Insert)); |
| 1994 |
xp = (double*) ImportVector_->Values(); |
| 1995 |
} |
| 1996 |
|
| 1997 |
// If we have a non-trivial exporter, we must export elements that are permuted or belong to other processors |
| 1998 |
if(Exporter_ != 0) yp = (double*) ExportVector_->Values(); |
| 1999 |
|
| 2000 |
// Do actual computation |
| 2001 |
for(int i = 0; i < A.NumMyRows(); i++) { |
| 2002 |
int NumEntries,*RowIndices; |
| 2003 |
A.Graph().ExtractMyRowView(i,NumEntries,RowIndices); |
| 2004 |
double sum = 0.0; |
| 2005 |
for(int j = 0; j < NumEntries; j++) |
| 2006 |
sum += xp[*RowIndices++]; |
| 2007 |
yp[i] = sum; |
| 2008 |
} |
| 2009 |
|
| 2010 |
if(Exporter_ != 0) { |
| 2011 |
y.PutScalar(0.0); // Make sure target is zero |
| 2012 |
EPETRA_CHK_ERR(y.Export(*ExportVector_, *Exporter_, Add)); // Fill y with Values from export vector |
| 2013 |
} |
| 2014 |
// Handle case of rangemap being a local replicated map |
| 2015 |
if (!A.Graph().RangeMap().DistributedGlobal() && A.Comm().NumProc()>1) EPETRA_CHK_ERR(y.Reduce()); |
| 2016 |
|
| 2017 |
delete xcopy; |
| 2018 |
delete ImportVector_; |
| 2019 |
delete ExportVector_; |
| 2020 |
|
| 2021 |
|
| 2022 |
return(0); |
| 2023 |
} |
| 2024 |
|
| 2025 |
/*************************************************************************************/ |
| 2026 |
/**************************** GET ML RESIDUAL ****************************************/ |
| 2027 |
/*************************************************************************************/ |
| 2028 |
/** \brief Compute ML solution residual |
| 2029 |
|
| 2030 |
\param A [in] discrete operator |
| 2031 |
\param lhs [in] solution vector |
| 2032 |
\param rhs [in] right hand side vector |
| 2033 |
\param Time [in] elapsed time for output |
| 2034 |
\param TotalErrorResidual [out] error residual |
| 2035 |
\param TotalErrorExactSol [out] error in xh (not an appropriate measure |
| 2036 |
for H(curl) basis functions) |
| 2037 |
*/ |
| 2038 |
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){ |
| 2039 |
// ==================================================== // |
| 2040 |
// compute difference between exact solution and ML one // |
| 2041 |
// ==================================================== // |
| 2042 |
double d = 0.0, d_tot = 0.0; |
| 2043 |
for( int i=0 ; i<lhs.Map().NumMyElements() ; ++i ) |
| 2044 |
d += (lhs[0][i] - xexact[0][i]) * (lhs[0][i] - xexact[0][i]); |
| 2045 |
|
| 2046 |
A.Comm().SumAll(&d,&d_tot,1); |
| 2047 |
|
| 2048 |
// ================== // |
| 2049 |
// compute ||Ax - b|| // |
| 2050 |
// ================== // |
| 2051 |
double Norm; |
| 2052 |
Epetra_Vector Ax(rhs.Map()); |
| 2053 |
A.Apply(lhs, Ax); |
| 2054 |
Ax.Update(1.0, rhs, -1.0); |
| 2055 |
Ax.Norm2(&Norm); |
| 2056 |
|
| 2057 |
// NOTE: (x_exact - x) does not make sense for H(curl) or H(grad) basis functions |
| 2058 |
if (A.Comm().MyPID() == 0) { |
| 2059 |
cout << msg << "......Using " << A.Comm().NumProc() << " processes" << endl; |
| 2060 |
cout << msg << "......||A x - b||_2 = " << Norm << endl; |
| 2061 |
// cout << msg << "......||x_exact - x||_2 = " << sqrt(d_tot) << endl; |
| 2062 |
cout << msg << "......Total Time = " << Time.ElapsedTime() << endl; |
| 2063 |
} |
| 2064 |
|
| 2065 |
TotalErrorExactSol += sqrt(d_tot); |
| 2066 |
TotalErrorResidual += Norm; |
| 2067 |
} |
| 2068 |
|
| 2069 |
/*************************************************************************************/ |
| 2070 |
/*************************** ML PRECONDITIONER****************************************/ |
| 2071 |
/*************************************************************************************/ |
| 2072 |
void TestMultiLevelPreconditioner_CurlLSFEM(char ProblemType[], |
| 2073 |
Teuchos::ParameterList & MLList, |
| 2074 |
Epetra_CrsMatrix & CurlCurl, |
| 2075 |
Epetra_CrsMatrix & D0clean, |
| 2076 |
Epetra_CrsMatrix & M0inv, |
| 2077 |
Epetra_CrsMatrix & M1, |
| 2078 |
Epetra_MultiVector & xh, |
| 2079 |
Epetra_MultiVector & b, |
| 2080 |
double & TotalErrorResidual, |
| 2081 |
double & TotalErrorExactSol){ |
| 2082 |
|
| 2083 |
/* Nuke M1 for D0, OAZ*/ |
| 2084 |
Epetra_CrsMatrix D0(D0clean); |
| 2085 |
ML_Epetra::Apply_BCsToGradient(CurlCurl,D0); |
| 2086 |
|
| 2087 |
/* Get the BC edges*/ |
| 2088 |
int numBCedges; |
| 2089 |
int* BCedges=ML_Epetra::FindLocalDiricheltRowsFromOnesAndZeros(CurlCurl,numBCedges); |
| 2090 |
// printf("# BC edges = %d\n",numBCedges); |
| 2091 |
ML_Epetra::Apply_OAZToMatrix(BCedges,numBCedges,M1); |
| 2092 |
ArrayRCP<int> BCedges_arcp(BCedges,0,numBCedges,false); |
| 2093 |
|
| 2094 |
if(!CurlCurl.Comm().MyPID()) |
| 2095 |
cout<<"Total number of rows = "<<CurlCurl.NumGlobalRows()<<endl; |
| 2096 |
|
| 2097 |
/* Build the (1,1) Block Operator */ |
| 2098 |
ML_Epetra::ML_RefMaxwell_11_Operator Operator11(CurlCurl,D0,M0inv,M1); |
| 2099 |
|
| 2100 |
/* Build the AztecOO stuff */ |
| 2101 |
Epetra_MultiVector x(xh); |
| 2102 |
x.PutScalar(0.0); |
| 2103 |
|
| 2104 |
Epetra_LinearProblem Problem(&Operator11,&x,&b); |
| 2105 |
Epetra_MultiVector* lhs = Problem.GetLHS(); |
| 2106 |
Epetra_MultiVector* rhs = Problem.GetRHS(); |
| 2107 |
|
| 2108 |
Epetra_Time Time(CurlCurl.Comm()); |
| 2109 |
|
| 2110 |
/* Build the aggregation guide matrix */ |
| 2111 |
Epetra_CrsMatrix *TMT_Agg_Matrix; |
| 2112 |
ML_Epetra::ML_Epetra_PtAP(M1,D0clean,TMT_Agg_Matrix,false); |
| 2113 |
|
| 2114 |
/* Approximate the diagonal for EMFP: 2a^2 b guy */ |
| 2115 |
Epetra_Vector Diagonal(CurlCurl.DomainMap()); |
| 2116 |
Epetra_Vector NodeDiagonal(D0.DomainMap()); |
| 2117 |
Epetra_Vector EdgeDiagonal(M1.DomainMap()); |
| 2118 |
Epetra_Vector CurlDiagonal(CurlCurl.DomainMap()); |
| 2119 |
|
| 2120 |
M0inv.ExtractDiagonalCopy(NodeDiagonal); |
| 2121 |
M1.ExtractDiagonalCopy(EdgeDiagonal); |
| 2122 |
CurlCurl.ExtractDiagonalCopy(CurlDiagonal); |
| 2123 |
|
| 2124 |
Multiply_Ones(D0,NodeDiagonal,Diagonal); |
| 2125 |
|
| 2126 |
for(int i=0;i<CurlCurl.NumMyRows();i++) { |
| 2127 |
Diagonal[i]=Diagonal[i]*(EdgeDiagonal[i]*EdgeDiagonal[i]) + CurlDiagonal[i]; |
| 2128 |
if(ABS(Diagonal[i])<1e-12) Diagonal[i]=1.0; |
| 2129 |
} |
| 2130 |
|
| 2131 |
/* Build the EMFP Preconditioner */ |
| 2132 |
ML_Epetra::EdgeMatrixFreePreconditioner EMFP(rcp(&Operator11,false),rcp(&Diagonal,false),rcp(&D0,false),rcp(&D0clean,false),rcp(TMT_Agg_Matrix,false),BCedges_arcp,MLList); |
| 2133 |
|
| 2134 |
/* Solve! */ |
| 2135 |
AztecOO solver(Problem); |
| 2136 |
solver.SetPrecOperator(&EMFP); |
| 2137 |
solver.SetAztecOption(AZ_solver, AZ_cg); |
| 2138 |
solver.SetAztecOption(AZ_output, 32); |
| 2139 |
solver.Iterate(500, 1e-10); |
| 2140 |
// solver.Iterate(1, 1e-10); |
| 2141 |
|
| 2142 |
Epetra_MultiVector xexact(xh); |
| 2143 |
xexact.PutScalar(0.0); |
| 2144 |
|
| 2145 |
// accuracy check |
| 2146 |
string msg = ProblemType; |
| 2147 |
solution_test(msg,Operator11,*lhs,*rhs,xexact,Time,TotalErrorExactSol,TotalErrorResidual); |
| 2148 |
|
| 2149 |
|
| 2150 |
#ifdef DUMP_DATA |
| 2151 |
EpetraExt::RowMatrixToMatlabFile("mag_m0inv_matrix.dat",M0inv); |
| 2152 |
EpetraExt::RowMatrixToMatlabFile("mag_m1_matrix.dat",M1); |
| 2153 |
EpetraExt::RowMatrixToMatlabFile("mag_k1_matrix.dat",CurlCurl); |
| 2154 |
EpetraExt::RowMatrixToMatlabFile("mag_t0_matrix.dat",D0); |
| 2155 |
EpetraExt::RowMatrixToMatlabFile("mag_t0_clean_matrix.dat",D0clean); |
| 2156 |
EpetraExt::MultiVectorToMatrixMarketFile("mag_rhs1.dat",*rhs,0,0,false); |
| 2157 |
EpetraExt::MultiVectorToMatrixMarketFile("mag_lhs1.dat",*lhs,0,0,false); |
| 2158 |
#endif |
| 2159 |
|
| 2160 |
xh = *lhs; |
| 2161 |
|
| 2162 |
// Cleanup |
| 2163 |
delete TMT_Agg_Matrix; |
| 2164 |
delete [] BCedges; |
| 2165 |
} |
| 2166 |
|
| 2167 |
/**********************************************************************************/ |
| 2168 |
/************ USER DEFINED FUNCTIONS FOR EXACT SOLUTION ***************************/ |
| 2169 |
/**********************************************************************************/ |
| 2170 |
|
| 2171 |
// Calculates value of exact solution u |
| 2172 |
int evalu(double & uExact0, double & uExact1, double & uExact2, double & x, double & y, double & z) |
| 2173 |
{ |
| 2174 |
|
| 2175 |
/* |
| 2176 |
// Exact solution 1 - homogeneous boundary conditions, nonzero divergence |
| 2177 |
uExact0 = exp(x+y+z)*(y+1.0)*(y-1.0)*(z+1.0)*(z-1.0); |
| 2178 |
uExact1 = exp(x+y+z)*(x+1.0)*(x-1.0)*(z+1.0)*(z-1.0); |
| 2179 |
uExact2 = exp(x+y+z)*(x+1.0)*(x-1.0)*(y+1.0)*(y-1.0); |
| 2180 |
*/ |
| 2181 |
|
| 2182 |
|
| 2183 |
/* |
| 2184 |
// Exact solution 2 - homogeneous boundary conditions, nonzero divergence |
| 2185 |
uExact0 = cos(M_PI*x)*sin(M_PI*y)*sin(M_PI*z); |
| 2186 |
uExact1 = sin(M_PI*x)*cos(M_PI*y)*sin(M_PI*z); |
| 2187 |
uExact2 = sin(M_PI*x)*sin(M_PI*y)*cos(M_PI*z); |
| 2188 |
*/ |
| 2189 |
|
| 2190 |
/* |
| 2191 |
// Exact solution 3 - homogeneous boundary conditions, zero divergence |
| 2192 |
uExact0 = (y*y - 1.0)*(z*z-1.0); |
| 2193 |
uExact1 = (x*x - 1.0)*(z*z-1.0); |
| 2194 |
uExact2 = (x*x - 1.0)*(y*y-1.0); |
| 2195 |
|
| 2196 |
*/ |
| 2197 |
|
| 2198 |
// Exact solution 4 - patch test with inhomogeneous boundary conditions, |
| 2199 |
// zero divergence, linear field should be recovered |
| 2200 |
uExact0 = 1.0 + 2.0*y + 3.0*z; |
| 2201 |
uExact1 = 1.0 + x + 3.0*z; |
| 2202 |
uExact2 = 1.0 + x + 2.0*y; |
| 2203 |
|
| 2204 |
|
| 2205 |
return 0; |
| 2206 |
} |
| 2207 |
|
| 2208 |
// Calculates divergence of exact solution u |
| 2209 |
double evalDivu(double & x, double & y, double & z, double & mu) |
| 2210 |
{ |
| 2211 |
|
| 2212 |
|
| 2213 |
/* |
| 2214 |
// Exact solution 1 - homogeneous boundary conditions, nonzero divergence |
| 2215 |
double divu = exp(x+y+z)*(y+1.0)*(y-1.0)*(z+1.0)*(z-1.0) |
| 2216 |
+ exp(x+y+z)*(x+1.0)*(x-1.0)*(z+1.0)*(z-1.0) |
| 2217 |
+ exp(x+y+z)*(x+1.0)*(x-1.0)*(y+1.0)*(y-1.0); |
| 2218 |
*/ |
| 2219 |
|
| 2220 |
/* |
| 2221 |
// Exact solution 2 - homogeneous boundary conditions, nonzero divergence |
| 2222 |
double divu = -3.0*M_PI*sin(M_PI*x)*sin(M_PI*y)*sin(M_PI*z); |
| 2223 |
*/ |
| 2224 |
|
| 2225 |
|
| 2226 |
/* |
| 2227 |
// Exact solution 3 - homogeneous boundary conditions, zero divergence |
| 2228 |
double divu = 0.0; |
| 2229 |
*/ |
| 2230 |
|
| 2231 |
|
| 2232 |
// Exact solution 4 - patch test with inhomogeneous boundary conditions, |
| 2233 |
// zero divergence, linear field should be recovered |
| 2234 |
double divu = 0.0; |
| 2235 |
|
| 2236 |
|
| 2237 |
return mu*divu; |
| 2238 |
} |
| 2239 |
|
| 2240 |
|
| 2241 |
// Calculates curl of exact solution u |
| 2242 |
int evalCurlu(double & curlu0, double & curlu1, double & curlu2, double & x, double & y, double & z, double &mu) |
| 2243 |
{ |
| 2244 |
|
| 2245 |
/* |
| 2246 |
// Exact solution 1 - homogeneous boundary conditions, nonzero divergence |
| 2247 |
double duxdy = exp(x+y+z)*(z*z-1.0)*(y*y+2.0*y-1.0); |
| 2248 |
double duxdz = exp(x+y+z)*(y*y-1.0)*(z*z+2.0*z-1.0); |
| 2249 |
double duydx = exp(x+y+z)*(z*z-1.0)*(x*x+2.0*x-1.0); |
| 2250 |
double duydz = exp(x+y+z)*(x*x-1.0)*(z*z+2.0*z-1.0); |
| 2251 |
double duzdx = exp(x+y+z)*(y*y-1.0)*(x*x+2.0*x-1.0); |
| 2252 |
double duzdy = exp(x+y+z)*(x*x-1.0)*(y*y+2.0*y-1.0); |
| 2253 |
*/ |
| 2254 |
|
| 2255 |
/* |
| 2256 |
// Exact solution 2 - homogeneous boundary conditions, nonzero divergence |
| 2257 |
double duxdy = M_PI*cos(M_PI*x)*cos(M_PI*y)*sin(M_PI*z); |
| 2258 |
double duxdz = M_PI*cos(M_PI*x)*sin(M_PI*y)*cos(M_PI*z); |
| 2259 |
double duydx = M_PI*cos(M_PI*x)*cos(M_PI*y)*sin(M_PI*z); |
| 2260 |
double duydz = M_PI*sin(M_PI*x)*cos(M_PI*y)*cos(M_PI*z); |
| 2261 |
double duzdx = M_PI*cos(M_PI*x)*sin(M_PI*y)*cos(M_PI*z); |
| 2262 |
double duzdy = M_PI*sin(M_PI*x)*cos(M_PI*y)*cos(M_PI*z); |
| 2263 |
*/ |
| 2264 |
|
| 2265 |
/* |
| 2266 |
// Exact solution 3 - homogeneous boundary conditions, zero divergence |
| 2267 |
double duxdy = 2.0*y*(z*z-1); |
| 2268 |
double duxdz = 2.0*z*(y*y-1); |
| 2269 |
double duydx = 2.0*x*(z*z-1); |
| 2270 |
double duydz = 2.0*z*(x*x-1); |
| 2271 |
double duzdx = 2.0*x*(y*y-1); |
| 2272 |
double duzdy = 2.0*y*(x*x-1); |
| 2273 |
*/ |
| 2274 |
|
| 2275 |
// Exact solution 4 - patch test with inhomogeneous boundary conditions, |
| 2276 |
// zero divergence, linear field should be recovered |
| 2277 |
double duxdy = 2.0; |
| 2278 |
double duxdz = 3.0; |
| 2279 |
double duydx = 1.0; |
| 2280 |
double duydz = 3.0; |
| 2281 |
double duzdx = 1.0; |
| 2282 |
double duzdy = 2.0; |
| 2283 |
|
| 2284 |
curlu0 = mu*(duzdy - duydz); |
| 2285 |
curlu1 = mu*(duxdz - duzdx); |
| 2286 |
curlu2 = mu*(duydx - duxdy); |
| 2287 |
|
| 2288 |
return 0; |
| 2289 |
} |
| 2290 |
|
| 2291 |
// Calculates gradient of the divergence of exact solution u |
| 2292 |
int evalGradDivu(double & gradDivu0, double & gradDivu1, double & gradDivu2, double & x, double & y, double & z, double & mu) |
| 2293 |
{ |
| 2294 |
|
| 2295 |
/* |
| 2296 |
// Exact solution 1 - homogeneous boundary conditions, nonzero divergence |
| 2297 |
gradDivu0 = exp(x+y+z)*((y*y-1.0)*(z*z-1.0)+(x*x+2.0*x-1.0)*(z*z-1.0)+(x*x+2.0*x-1.0)*(y*y-1.0)); |
| 2298 |
gradDivu1 = exp(x+y+z)*((y*y+2.0*y-1.0)*(z*z-1.0)+(x*x-1.0)*(z*z-1.0)+(x*x-1.0)*(y*y+2.0*y-1.0)); |
| 2299 |
gradDivu2 = exp(x+y+z)*((y*y-1.0)*(z*z+2.0*z-1.0)+(x*x-1.0)*(z*z+2.0*z-1.0)+(x*x-1.0)*(y*y-1.0)); |
| 2300 |
*/ |
| 2301 |
|
| 2302 |
/* |
| 2303 |
// Exact solution 2 - homogeneous boundary conditions, nonzero divergence |
| 2304 |
gradDivu0 = -3.0*M_PI*M_PI*cos(M_PI*x)*sin(M_PI*y)*sin(M_PI*z); |
| 2305 |
gradDivu1 = -3.0*M_PI*M_PI*sin(M_PI*x)*cos(M_PI*y)*sin(M_PI*z); |
| 2306 |
gradDivu2 = -3.0*M_PI*M_PI*sin(M_PI*x)*sin(M_PI*y)*cos(M_PI*z); |
| 2307 |
*/ |
| 2308 |
|
| 2309 |
/* |
| 2310 |
// Exact solution 3 - homogeneous boundary conditions, zero divergence |
| 2311 |
gradDivu0 = 0; |
| 2312 |
gradDivu1 = 0; |
| 2313 |
gradDivu2 = 0; |
| 2314 |
*/ |
| 2315 |
|
| 2316 |
// Exact solution 4 - patch test with inhomogeneous boundary conditions, |
| 2317 |
// zero divergence, linear field should be recovered |
| 2318 |
gradDivu0 = 0; |
| 2319 |
gradDivu1 = 0; |
| 2320 |
gradDivu2 = 0; |
| 2321 |
|
| 2322 |
gradDivu0 = gradDivu0 * mu; |
| 2323 |
gradDivu1 = gradDivu1 * mu; |
| 2324 |
gradDivu2 = gradDivu2 * mu; |
| 2325 |
|
| 2326 |
return 0; |
| 2327 |
} |
| 2328 |
|
| 2329 |
|