Debian Codegraph @

packages/trilinoscouplings/examples/scaling/TrilinosCouplings_TpetraIntrepidPoissonExample.cpp

raw
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 #include <limits>
11 #include <set>
12
13 // TrilinosCouplings includes
14 #include <TrilinosCouplings_config.h>
15
16 // Intrepid includes
17 #include <Intrepid_FunctionSpaceTools.hpp>
18 #include <Intrepid_CellTools.hpp>
19 #include <Intrepid_ArrayTools.hpp>
20 #include <Intrepid_HGRAD_HEX_C1_FEM.hpp>
21 #include <Intrepid_RealSpaceTools.hpp>
22 #include <Intrepid_DefaultCubatureFactory.hpp>
23 #include <Intrepid_Utils.hpp>
24
25 // Teuchos includes
26 //#include <Teuchos_TimeMonitor.hpp>
27
28 // Shards includes
29 #include <Shards_CellTopology.hpp>
30
31 // Pamgen includes
32 #include <create_inline_mesh.h>
33 #include <pamgen_im_exodusII_l.h>
34 #include <pamgen_im_ne_nemesisI_l.h>
35 #include <pamgen_extras.h>
36 #include "RTC_FunctionRTC.hh"
37
38 #ifdef HAVE_INTREPID_KOKKOS
39 #include "Sacado.hpp"
40 #else
41 // Sacado includes
42 #include <Sacado_No_Kokkos.hpp>
43 #endif
44
45 // My includes
46 #include "TrilinosCouplings_TpetraIntrepidPoissonExample.hpp"
47 #include "TrilinosCouplings_Pamgen_Utils.hpp"
48 #include "TrilinosCouplings_IntrepidPoissonExampleHelpers.hpp"
49 #include "TrilinosCouplings_Statistics.hpp"
50
51 // Disable the full set of problem statistics
52 //const bool use_new_problem_stats = true;
53
54
55 /*********************************************************/
56 /* Typedefs */
57 /*********************************************************/
58
59 struct fecomp{
60 bool operator () ( topo_entity* x, topo_entity* y )const
61 {
62 if(x->sorted_local_node_ids < y->sorted_local_node_ids)return true;
63 return false;
64 }
65 };
66
67 template<class FC>
68 double distance2(const FC & coord, int n1, int n2) {
69 double dist = 0.0;
70 for(int i=0; i<coord.dimension(1); i++)
71 dist += (coord(n2,i) -coord(n1,i)) * (coord(n2,i) -coord(n1,i));
72 return sqrt(dist);
73 }
74
75 namespace TrilinosCouplings {
76 namespace TpetraIntrepidPoissonExample {
77
78 /**********************************************************************************/
79 /******** FUNCTION DECLARATIONS FOR EXACT SOLUTION AND SOURCE TERMS ***************/
80 /**********************************************************************************/
81
82 /** \brief User-defined exact solution.
83
84 \param x [in] x-coordinate of the evaluation point
85 \param y [in] y-coordinate of the evaluation point
86 \param z [in] z-coordinate of the evaluation point
87
88 \return Value of the exact solution at (x,y,z)
89 */
90 template<typename Scalar>
91 const Scalar
92 exactSolution (const Scalar& x, const Scalar& y, const Scalar& z);
93
94 /** \brief Computes gradient of the exact solution. Requires user-defined exact solution.
95
96 \param gradExact [out] gradient of the exact solution evaluated at (x,y,z)
97 \param x [in] x-coordinate of the evaluation point
98 \param y [in] y-coordinate of the evaluation point
99 \param z [in] z-coordinate of the evaluation point
100 */
101 template<typename Scalar>
102 void
103 exactSolutionGrad (Scalar gradExact[3],
104 const Scalar& x,
105 const Scalar& y,
106 const Scalar& z);
107
108 /** \brief Computes source term: f = -div(A.grad u). Requires user-defined exact solution
109 and material tensor.
110
111 \param x [in] x-coordinate of the evaluation point
112 \param y [in] y-coordinate of the evaluation point
113 \param z [in] z-coordinate of the evaluation point
114
115 \return Source term corresponding to the user-defined exact solution evaluated at (x,y,z)
116 */
117 template<typename Scalar>
118 const Scalar
119 sourceTerm (Scalar& x, Scalar& y, Scalar& z);
120
121 /** \brief Compute the material tensor at array of points in physical space.
122
123 \param worksetMaterialValues [out] Rank-2, 3 or 4 array with dimensions (C,P), (C,P,D) or (C,P,D,D)
124 with the values of the material tensor
125 \param evaluationPoints [in] Rank-3 (C,P,D) array with the evaluation points in physical frame
126 */
127 template<class ArrayOut, class ArrayIn>
128 void
129 evaluateMaterialTensor (ArrayOut& worksetMaterialValues,
130 const ArrayIn& evaluationPoints);
131
132 /** \brief Compute the source term at array of points in physical space.
133
134 \param sourceTermValues [out] Rank-2 (C,P) array with the values of the source term
135 \param evaluationPoints [in] Rank-3 (C,P,D) array with the evaluation points in physical frame
136 */
137 template<class ArrayOut, class ArrayIn>
138 void
139 evaluateSourceTerm (ArrayOut& sourceTermValues,
140 const ArrayIn& evaluationPoints);
141
142 /** \brief Compute the exact solution at array of points in physical space.
143
144 \param exactSolutionValues [out] Rank-2 (C,P) array with the values of the exact solution
145 \param evaluationPoints [in] Rank-3 (C,P,D) array with the evaluation points in physical frame
146 */
147 template<class ArrayOut, class ArrayIn>
148 void
149 evaluateExactSolution (ArrayOut& exactSolutionValues,
150 const ArrayIn& evaluationPoints);
151
152 /** \brief Computation of the gradient of the exact solution at array of points in physical space.
153
154 \param exactSolutionGradValues [out] Rank-3 (C,P,D) array with the values of the gradient of the exact solution
155 \param evaluationPoints [in] Rank-3 (C,P,D) array with the evaluation points in physical frame
156 */
157 template<class ArrayOut, class ArrayIn>
158 void
159 evaluateExactSolutionGrad (ArrayOut& exactSolutionGradValues,
160 const ArrayIn& evaluationPoints);
161
162 void
163 makeMatrixAndRightHandSide (Teuchos::RCP<sparse_matrix_type>& A,
164 Teuchos::RCP<multivector_type>& B,
165 Teuchos::RCP<multivector_type>& X_exact,
166 Teuchos::RCP<multivector_type>& X,
167 Teuchos::RCP<multivector_type> & coords,
168 Teuchos::RCP<vector_type>& node_sigma,
169 const Teuchos::RCP<const Teuchos::Comm<int> >& comm,
170 const std::string& meshInput,
171 Teuchos::ParameterList & inputList,
172 Teuchos::ParameterList & problemStatistics,
173 const Teuchos::RCP<Teuchos::FancyOStream>& out,
174 const Teuchos::RCP<Teuchos::FancyOStream>& err,
175 const bool verbose,
176 const bool debug)
177 {
178 using Teuchos::RCP;
179 using Teuchos::rcp_implicit_cast;
180
181 RCP<vector_type> b, x_exact, x;
182 makeMatrixAndRightHandSide (A, b, x_exact, x, coords, node_sigma, comm, meshInput, inputList, problemStatistics,
183 out, err, verbose, debug);
184
185 B = rcp_implicit_cast<multivector_type> (b);
186 X_exact = rcp_implicit_cast<multivector_type> (x_exact);
187 X = rcp_implicit_cast<multivector_type> (x);
188 }
189
190 double myDistance2(const Tpetra::MultiVector<ST, LO, GO, Node> &v, int i0, int i1) {
191 const size_t numVectors = v.getNumVectors();
192 double distance = 0.0;
193 for (size_t j=0; j<numVectors; j++) {
194 distance += (v.getData(j)[i0]-v.getData(j)[i1])*(v.getData(j)[i0]-v.getData(j)[i1]);
195 }
196 return distance;
197 }
198
199 void
200 makeMatrixAndRightHandSide (Teuchos::RCP<sparse_matrix_type>& A,
201 Teuchos::RCP<vector_type>& B,
202 Teuchos::RCP<vector_type>& X_exact,
203 Teuchos::RCP<vector_type>& X,
204 Teuchos::RCP<multivector_type> & coords,
205 Teuchos::RCP<vector_type>& node_sigma,
206 const Teuchos::RCP<const Teuchos::Comm<int> >& comm,
207 const std::string& meshInput,
208 Teuchos::ParameterList & inputList,
209 Teuchos::ParameterList & problemStatistics,
210 const Teuchos::RCP<Teuchos::FancyOStream>& out,
211 const Teuchos::RCP<Teuchos::FancyOStream>& err,
212 const bool verbose,
213 const bool debug)
214 {
215 using namespace Intrepid;
216 using Tpetra::global_size_t;
217 using Teuchos::Array;
218 using Teuchos::ArrayRCP;
219 using Teuchos::ArrayView;
220 using Teuchos::arrayView;
221 using Teuchos::as;
222 using Teuchos::outArg;
223 using Teuchos::ParameterList;
224 using Teuchos::RCP;
225 using Teuchos::rcp;
226 using Teuchos::TimeMonitor;
227 using std::endl;
228 //typedef Teuchos::ArrayView<LO>::size_type size_type; // unused
229 typedef Teuchos::ScalarTraits<ST> STS;
230
231 (void) verbose;
232 (void) debug;
233
234 //
235 // mfh 19 Apr 2012: If you want to change the template parameters of
236 // these typedefs, modify the typedefs (ST, LO, GO, Node) near the
237 // top of this file.
238 //
239 typedef Tpetra::Map<LO, GO, Node> map_type;
240 typedef Tpetra::Export<LO, GO, Node> export_type;
241 //typedef Tpetra::Import<LO, GO, Node> import_type; // unused
242 typedef Tpetra::CrsGraph<LO, GO, Node> sparse_graph_type;
243
244 // Number of independent variables fixed at 3
245 //typedef Sacado::Fad::SFad<ST, 3> Fad3; // unused
246 typedef Intrepid::FunctionSpaceTools IntrepidFSTools;
247 //typedef Intrepid::RealSpaceTools<ST> IntrepidRSTools; // unused
248 typedef Intrepid::CellTools<ST> IntrepidCTools;
249
250 const int numProcs = comm->getSize ();
251 const int myRank = comm->getRank ();
252
253 *out << "makeMatrixAndRightHandSide:" << endl;
254 Teuchos::OSTab tab (out);
255
256
257 /***************************** GET CELL TOPOLOGY **********************************/
258 /**********************************************************************************/
259
260 *out << "Getting cell topology" << endl;
261 // Get cell topology for base hexahedron
262 shards::CellTopology cellType (shards::getCellTopologyData<shards::Hexahedron<8> > ());
263 // Get dimensions
264 int numNodesPerElem = cellType.getNodeCount();
265 int numEdgesPerElem = cellType.getEdgeCount();
266 int numFacesPerElem = cellType.getSideCount();
267 int numNodesPerEdge = 2; // for any rational universe
268 int numNodesPerFace = 4; // hardwired for hexes
269 int spaceDim = cellType.getDimension();
270 int dim = 3;
271
272
273 // Build reference element edge to node map
274 FieldContainer<int> refEdgeToNode(numEdgesPerElem,numNodesPerEdge);
275 for (int i=0; i<numEdgesPerElem; i++){
276 refEdgeToNode(i,0)=cellType.getNodeMap(1, i, 0);
277 refEdgeToNode(i,1)=cellType.getNodeMap(1, i, 1);
278 }
279
280 // Build reference element face to node map
281 FieldContainer<int> refFaceToNode(numFacesPerElem,numNodesPerFace);
282 for (int i=0; i<numFacesPerElem; i++){
283 refFaceToNode(i,0)=cellType.getNodeMap(2, i, 0);
284 refFaceToNode(i,1)=cellType.getNodeMap(2, i, 1);
285 refFaceToNode(i,2)=cellType.getNodeMap(2, i, 2);
286 refFaceToNode(i,3)=cellType.getNodeMap(2, i, 3);
287 }
288
289 /**********************************************************************************/
290 /******************************* GENERATE MESH ************************************/
291 /**********************************************************************************/
292
293 *out << "Generating mesh (tpetra)" << endl;
294
295 int error = 0; // Number of errors in generating the mesh
296
297 long long * node_comm_proc_ids = NULL;
298 long long * node_cmap_node_cnts = NULL;
299 long long * node_cmap_ids = NULL;
300 long long ** comm_node_ids = NULL;
301 long long ** comm_node_proc_ids = NULL;
302
303 std::set < topo_entity * , fecomp > edge_set;
304 std::set < topo_entity * , fecomp > face_set;
305 std::vector < topo_entity * > edge_vector;
306 std::vector < topo_entity * > face_vector;
307
308 // Generate mesh with Pamgen
309 long long maxInt = 9223372036854775807LL;
310 long long cr_result = Create_Pamgen_Mesh (meshInput.c_str (), dim, myRank, numProcs, maxInt);
311 TrilinosCouplings::pamgen_error_check(*out,cr_result);
312
313 std::string msg ("Poisson: ");
314
315 // Get mesh size info
316 char title[100];
317 long long numDim;
318 long long numNodes;
319 long long numElems;
320 long long numElemBlk;
321 long long numNodeSets;
322 long long numSideSets;
323 int id = 0;
324
325 im_ex_get_init_l (id, title, &numDim, &numNodes, &numElems, &numElemBlk,
326 &numNodeSets, &numSideSets);
327
328 TEUCHOS_TEST_FOR_EXCEPTION(numElems == 0, std::runtime_error,
329 "The number of elements in the mesh is zero.");
330
331 long long numNodesGlobal;
332 long long numElemsGlobal;
333 long long numElemBlkGlobal;
334 long long numNodeSetsGlobal;
335 long long numSideSetsGlobal;
336
337 im_ne_get_init_global_l (id, &numNodesGlobal, &numElemsGlobal,
338 &numElemBlkGlobal, &numNodeSetsGlobal,
339 &numSideSetsGlobal);
340 MachineLearningStatistics_Hex3D<ST, LO, GO, Node> MLStatistics(numElemsGlobal);
341
342 // Print mesh information
343 {
344 Teuchos::OSTab tab2 (out);
345 *out << "Global number of elements: "
346 << numElemsGlobal << endl
347 << "Global number of nodes (incl. boundary nodes): "
348 << numNodesGlobal << endl;
349 }
350
351 long long * block_ids = new long long [numElemBlk];
352 error += im_ex_get_elem_blk_ids_l(id, block_ids);
353
354 long long *nodes_per_element = new long long [numElemBlk];
355 long long *element_attributes = new long long [numElemBlk];
356 long long *elements = new long long [numElemBlk];
357 char **element_types = new char * [numElemBlk];
358 long long **elmt_node_linkage = new long long * [numElemBlk];
359
360 for (long long i = 0; i < numElemBlk; ++i) {
361 element_types[i] = new char [MAX_STR_LENGTH + 1];
362 error += im_ex_get_elem_block_l (id,
363 block_ids[i],
364 element_types[i],
365 (long long*)&(elements[i]),
366 (long long*)&(nodes_per_element[i]),
367 (long long*)&(element_attributes[i]));
368 }
369
370 // connectivity
371 for (long long b = 0; b < numElemBlk; ++b) {
372 elmt_node_linkage[b] = new long long [nodes_per_element[b]*elements[b]];
373 error += im_ex_get_elem_conn_l (id,block_ids[b], elmt_node_linkage[b]);
374 }
375
376 // Get node-element connectivity
377 int telct = 0;
378 FieldContainer<int> elemToNode(numElems,numNodesPerElem);
379 for (long long b = 0; b < numElemBlk; b++) {
380 for (long long el = 0; el < elements[b]; el++) {
381 for (int j = 0; j < numNodesPerElem; ++j) {
382 elemToNode(telct,j) = elmt_node_linkage[b][el*numNodesPerElem + j]-1;
383 }
384 ++telct;
385 }
386 }
387
388 // Read node coordinates and place in field container
389 FieldContainer<ST> nodeCoord (numNodes, dim);
390 ST * nodeCoordx = new ST [numNodes];
391 ST * nodeCoordy = new ST [numNodes];
392 ST * nodeCoordz = new ST [numNodes];
393 im_ex_get_coord_l (id, nodeCoordx, nodeCoordy, nodeCoordz);
394 for (int i=0; i<numNodes; i++) {
395 nodeCoord(i,0)=nodeCoordx[i];
396 nodeCoord(i,1)=nodeCoordy[i];
397 nodeCoord(i,2)=nodeCoordz[i];
398 }
399 delete [] nodeCoordx; delete[] nodeCoordy; delete [] nodeCoordz;
400
401 // Get the "time" value for the RTC
402 double time = 0.0;
403 if(inputList.isParameter("time"))
404 time = inputList.get("time",time);
405
406 // Get sigma value for each block of elements from parameter list
407 std::vector<double> sigma(numElemBlk);
408 std::vector<PG_RuntimeCompiler::Function> sigmaRTC(numElemBlk);
409 std::vector<bool> useSigmaRTC(numElemBlk,false);
410
411 for(int b = 0; b < numElemBlk; b++){
412 std::stringstream sigmaBlock, mysigmaRTC;
413 sigmaBlock << "sigma" << b;
414 mysigmaRTC << "sigma RTC " << b;
415 if(inputList.isParameter(sigmaBlock.str()))
416 sigma[b] = inputList.get(sigmaBlock.str(),1.0);
417 else if(inputList.isParameter(mysigmaRTC.str())) {
418 std::string mystr;
419 mystr = inputList.get(mysigmaRTC.str(),mystr);
420 if(!sigmaRTC[b].addVar("double","x")) {printf("ERROR: sigmaRTC.addVar(x) failed\n");exit(-1);}
421 if(!sigmaRTC[b].addVar("double","y")) {printf("ERROR: sigmaRTC.addVar(y) failed\n");exit(-1);}
422 if(!sigmaRTC[b].addVar("double","z")) {printf("ERROR: sigmaRTC.addVar(z) failed\n");exit(-1);}
423 if(!sigmaRTC[b].addVar("double","time")) {printf("ERROR: sigmaRTC.addVar(time) failed\n");exit(-1);}
424 if(!sigmaRTC[b].addVar("double","sigma")) {printf("ERROR: sigmaRTC.addVar(sigma) failed\n");exit(-1);}
425 if(!sigmaRTC[b].addBody(mystr)) {printf("ERROR: sigmaRTC[%d].addBody failed\n",b);exit(-1);}
426 useSigmaRTC[b]=true;
427 }
428 else
429 sigma[b]=1.0;
430 }
431
432 // Get node-element connectivity and set element mu/sigma value
433 telct = 0;
434 FieldContainer<double> sigmaVal(numElems);
435 for(long long b = 0; b < numElemBlk; b++){
436 for(long long el = 0; el < elements[b]; el++){
437 std::vector<double> centercoord(3,0);
438 for (int j=0; j<numNodesPerElem; j++) {
439 centercoord[0] += nodeCoord(elemToNode(telct,j),0) / numNodesPerElem;
440 centercoord[1] += nodeCoord(elemToNode(telct,j),1) / numNodesPerElem;
441 centercoord[2] += nodeCoord(elemToNode(telct,j),2) / numNodesPerElem;
442 }
443 if(useSigmaRTC[b]) {
444 sigmaRTC[b].varAddrFill(0,&centercoord[0]);
445 sigmaRTC[b].varAddrFill(1,&centercoord[1]);
446 sigmaRTC[b].varAddrFill(2,&centercoord[2]);
447 sigmaRTC[b].varAddrFill(3,&time);
448 sigmaRTC[b].varAddrFill(4,&sigmaVal(telct));
449 sigmaRTC[b].execute();
450 }
451 else
452 sigmaVal(telct) = sigma[b];
453 telct ++;
454 }
455 }
456
457
458
459 // parallel info
460 long long num_internal_nodes;
461 long long num_border_nodes;
462 long long num_external_nodes;
463 long long num_internal_elems;
464 long long num_border_elems;
465 long long num_node_comm_maps;
466 long long num_elem_comm_maps;
467 im_ne_get_loadbal_param_l( id,
468 &num_internal_nodes,
469 &num_border_nodes,
470 &num_external_nodes,
471 &num_internal_elems,
472 &num_border_elems,
473 &num_node_comm_maps,
474 &num_elem_comm_maps,
475 0/*unused*/ );
476
477 if (num_node_comm_maps > 0) {
478 node_comm_proc_ids = new long long [num_node_comm_maps];
479 node_cmap_node_cnts = new long long [num_node_comm_maps];
480 node_cmap_ids = new long long [num_node_comm_maps];
481 comm_node_ids = new long long* [num_node_comm_maps];
482 comm_node_proc_ids = new long long* [num_node_comm_maps];
483
484 long long * elem_cmap_ids = new long long [num_elem_comm_maps];
485 long long * elem_cmap_elem_cnts = new long long [num_elem_comm_maps];
486
487 if (im_ne_get_cmap_params_l (id,
488 node_cmap_ids,
489 (long long*)node_cmap_node_cnts,
490 elem_cmap_ids,
491 (long long*)elem_cmap_elem_cnts,
492 0/*not used proc_id*/ ) < 0) {
493 ++error;
494 }
495
496 for (long long j = 0; j < num_node_comm_maps; ++j) {
497 comm_node_ids[j] = new long long [node_cmap_node_cnts[j]];
498 comm_node_proc_ids[j] = new long long [node_cmap_node_cnts[j]];
499 if (im_ne_get_node_cmap_l (id,
500 node_cmap_ids[j],
501 comm_node_ids[j],
502 comm_node_proc_ids[j],
503 0/*not used proc_id*/ ) < 0) {
504 ++error;
505 }
506 node_comm_proc_ids[j] = comm_node_proc_ids[j][0];
507 }
508
509 delete [] elem_cmap_ids;
510 delete [] elem_cmap_elem_cnts;
511 }
512
513 //
514 // Calculate global node ids
515 //
516 Array<long long> globalNodeIds (numNodes);
517 // nodeIsOwned must be a raw array, because std::vector<T> (and
518 // therefore Teuchos::Array<T>) has a specialization for T = bool
519 // that messes up the pointer type.
520 bool* nodeIsOwned = new bool [numNodes];
521 calc_global_node_ids (globalNodeIds.getRawPtr (),
522 nodeIsOwned,
523 numNodes,
524 num_node_comm_maps,
525 node_cmap_node_cnts,
526 node_comm_proc_ids,
527 comm_node_ids,
528 myRank);
529
530
531 // Container indicating whether a node is on the boundary (1-yes 0-no)
532 FieldContainer<int> nodeOnBoundary (numNodes);
533
534 // Get boundary (side set) information
535 long long * sideSetIds = new long long [numSideSets];
536 long long numSidesInSet;
537 long long numDFinSet;
538 im_ex_get_side_set_ids_l(id,sideSetIds);
539 for (int i=0; i < numSideSets; ++i) {
540 im_ex_get_side_set_param_l (id,sideSetIds[i], &numSidesInSet, &numDFinSet);
541 if (numSidesInSet > 0){
542 long long * sideSetElemList = new long long [numSidesInSet];
543 long long * sideSetSideList = new long long [numSidesInSet];
544 im_ex_get_side_set_l (id, sideSetIds[i], sideSetElemList, sideSetSideList);
545 for (int j = 0; j < numSidesInSet; ++j) {
546 int sideNode0 = cellType.getNodeMap(2,sideSetSideList[j]-1,0);
547 int sideNode1 = cellType.getNodeMap(2,sideSetSideList[j]-1,1);
548 int sideNode2 = cellType.getNodeMap(2,sideSetSideList[j]-1,2);
549 int sideNode3 = cellType.getNodeMap(2,sideSetSideList[j]-1,3);
550
551 nodeOnBoundary(elemToNode(sideSetElemList[j]-1,sideNode0))=1;
552 nodeOnBoundary(elemToNode(sideSetElemList[j]-1,sideNode1))=1;
553 nodeOnBoundary(elemToNode(sideSetElemList[j]-1,sideNode2))=1;
554 nodeOnBoundary(elemToNode(sideSetElemList[j]-1,sideNode3))=1;
555 }
556 delete [] sideSetElemList;
557 delete [] sideSetSideList;
558 }
559 }
560 delete [] sideSetIds;
561
562
563
564 FieldContainer<int> elemToEdge(numElems,numEdgesPerElem);
565 FieldContainer<int> elemToFace(numElems,numFacesPerElem);
566
567 // Calculate edge and face ids
568 int elct = 0;
569 for(long long b = 0; b < numElemBlk; b++){
570 if(nodes_per_element[b] == 4){
571 }
572 else if (nodes_per_element[b] == 8){
573 //loop over all elements and push their edges onto a set if they are not there already
574 for(long long el = 0; el < elements[b]; el++){
575 std::set< topo_entity *, fecomp > ::iterator fit;
576 for (int i=0; i < numEdgesPerElem; i++){
577 topo_entity * teof = new topo_entity;
578 for(int j = 0; j < numNodesPerEdge;j++){
579 teof->add_node(elmt_node_linkage[b][el*numNodesPerElem + refEdgeToNode(i,j)],globalNodeIds.getRawPtr());
580 }
581 teof->sort();
582 fit = edge_set.find(teof);
583 if(fit == edge_set.end()){
584 teof->local_id = edge_vector.size();
585 edge_set.insert(teof);
586 elemToEdge(elct,i)= edge_vector.size();
587 edge_vector.push_back(teof);
588 }
589 else{
590 elemToEdge(elct,i) = (*fit)->local_id;
591 delete teof;
592 }
593 }
594 for (int i=0; i < numFacesPerElem; i++){
595 topo_entity * teof = new topo_entity;
596 for(int j = 0; j < numNodesPerFace;j++){
597 teof->add_node(elmt_node_linkage[b][el*numNodesPerElem + refFaceToNode(i,j)],globalNodeIds.getRawPtr());
598 }
599 teof->sort();
600 fit = face_set.find(teof);
601 if(fit == face_set.end()){
602 teof->local_id = face_vector.size();
603 face_set.insert(teof);
604 elemToFace(elct,i)= face_vector.size();
605 face_vector.push_back(teof);
606 }
607 else{
608 elemToFace(elct,i) = (*fit)->local_id;
609 delete teof;
610 }
611 }
612 elct ++;
613 }
614 }
615 }
616
617 // Edge to Node connectivity
618 FieldContainer<int> edgeToNode(edge_vector.size(), numNodesPerEdge);
619 for(unsigned ect = 0; ect != edge_vector.size(); ect++){
620 std::list<long long>::iterator elit;
621 int nct = 0;
622 for(elit = edge_vector[ect]->local_node_ids.begin();
623 elit != edge_vector[ect]->local_node_ids.end();
624 elit ++){
625 edgeToNode(ect,nct) = *elit-1;
626 nct++;
627 }
628 }
629
630
631 //
632 // Mesh cleanup
633 //
634 delete [] block_ids;
635 block_ids = NULL;
636 delete [] nodes_per_element;
637 nodes_per_element = NULL;
638 delete [] element_attributes;
639 element_attributes = NULL;
640 for (long long b = 0; b < numElemBlk; ++b) {
641 delete [] elmt_node_linkage[b];
642 delete [] element_types[b];
643 }
644 delete [] element_types;
645 element_types = NULL;
646 delete [] elmt_node_linkage;
647 elmt_node_linkage = NULL;
648 if (num_node_comm_maps > 0) {
649 delete [] node_comm_proc_ids;
650 node_comm_proc_ids = NULL;
651 delete [] node_cmap_node_cnts;
652 node_cmap_node_cnts = NULL;
653 delete [] node_cmap_ids;
654 node_cmap_ids = NULL;
655 for (long long i = 0; i < num_node_comm_maps; ++i) {
656 delete [] comm_node_ids[i];
657 delete [] comm_node_proc_ids[i];
658 }
659 delete [] comm_node_ids;
660 comm_node_ids = NULL;
661 delete [] comm_node_proc_ids;
662 comm_node_proc_ids = NULL;
663 }
664 delete [] elements;
665 elements = NULL;
666
667 for(int i=0;i< (int)edge_vector.size(); i++) delete edge_vector[i];
668 edge_vector.resize(0);
669 for(int i=0;i< (int)face_vector.size(); i++) delete face_vector[i];
670 face_vector.resize(0);
671
672
673 /**********************************************************************************/
674 /****************************** STATISTICS (Part I) *******************************/
675 /**********************************************************************************/
676 MLStatistics.Phase1(elemToNode,elemToEdge,edgeToNode,nodeCoord,sigmaVal);
677
678 /**********************************************************************************/
679 /********************************* GET CUBATURE ***********************************/
680 /**********************************************************************************/
681
682 *out << "Getting cubature" << endl;
683
684 // Get numerical integration points and weights
685 DefaultCubatureFactory<ST> cubFactory;
686 int cubDegree = 2;
687 RCP<Cubature<ST> > hexCub = cubFactory.create (cellType, cubDegree);
688
689 int cubDim = hexCub->getDimension ();
690 int numCubPoints = hexCub->getNumPoints ();
691
692 FieldContainer<ST> cubPoints (numCubPoints, cubDim);
693 FieldContainer<ST> cubWeights (numCubPoints);
694
695 hexCub->getCubature (cubPoints, cubWeights);
696
697 /**********************************************************************************/
698 /*********************************** GET BASIS ************************************/
699 /**********************************************************************************/
700
701 *out << "Getting basis" << endl;
702
703 // Define basis
704 Basis_HGRAD_HEX_C1_FEM<ST, FieldContainer<ST> > hexHGradBasis;
705 int numFieldsG = hexHGradBasis.getCardinality ();
706 FieldContainer<ST> HGBValues (numFieldsG, numCubPoints);
707 FieldContainer<ST> HGBGrads (numFieldsG, numCubPoints, spaceDim);
708
709 // Evaluate basis values and gradients at cubature points
710 hexHGradBasis.getValues (HGBValues, cubPoints, OPERATOR_VALUE);
711 hexHGradBasis.getValues (HGBGrads, cubPoints, OPERATOR_GRAD);
712
713 /**********************************************************************************/
714 /********************* BUILD MAPS FOR GLOBAL SOLUTION *****************************/
715 /**********************************************************************************/
716
717 Tpetra::global_size_t GST_INVALID = Teuchos::OrdinalTraits<Tpetra::global_size_t>::invalid();
718
719 *out << "Building Maps" << endl;
720
721 Array<GO> ownedGIDs;
722 RCP<const map_type> globalMapG;
723 {
724 TEUCHOS_FUNC_TIME_MONITOR_DIFF("Build global maps", build_maps);
725
726 // Count owned nodes
727 int ownedNodes = 0;
728 for (int i = 0; i < numNodes; ++i) {
729 if (nodeIsOwned[i]) {
730 ++ownedNodes;
731 }
732 }
733
734 // Build a list of the OWNED global ids...
735 // NTS: will need to switch back to long long
736 ownedGIDs.resize(ownedNodes);
737 int oidx = 0;
738 for (int i = 0; i < numNodes; ++i) {
739 if (nodeIsOwned[i]) {
740 ownedGIDs[oidx] = as<int> (globalNodeIds[i]);
741 ++oidx;
742 }
743 }
744 globalMapG = rcp (new map_type (GST_INVALID, ownedGIDs (), 0, comm));
745 }
746
747 /**********************************************************************************/
748 /********************* BUILD MAPS FOR OVERLAPPED SOLUTION *************************/
749 /**********************************************************************************/
750
751 Array<GO> overlappedGIDs;
752 RCP<const map_type> overlappedMapG;
753 RCP<const export_type> exporter;
754 {
755 // Count owned nodes
756 int overlappedNodes = numNodes;
757
758 // Build a list of the OVERLAPPED global ids...
759 overlappedGIDs.resize (overlappedNodes);
760 for (int i = 0; i < numNodes; ++i) {
761 overlappedGIDs[i] = as<int> (globalNodeIds[i]);
762 }
763
764 //Generate overlapped Map for nodes.
765 overlappedMapG = rcp (new map_type (GST_INVALID, overlappedGIDs (), 0, comm));
766
767 // Build Tpetra Export from overlapped to owned Map.
768 exporter = rcp (new export_type (overlappedMapG, globalMapG));
769 }
770
771 /**********************************************************************************/
772 /****************************** STASH COORDINATES *********************************/
773 /**********************************************************************************/
774
775 coords = rcp(new multivector_type(globalMapG,dim));
776 for(int j=0; j<dim; j++) {
777 auto cdata = coords->getDataNonConst(j);
778 int lid=0;
779 for(int i=0; i<numNodes; i++) {
780 if (nodeIsOwned[i]) {
781 cdata[lid] = nodeCoord(i,j);
782 lid++;
783 }
784 }
785 }
786
787 /**********************************************************************************/
788 /********************* BUILD GRAPH FOR OVERLAPPED SOLUTION ************************/
789 /**********************************************************************************/
790
791 *out << "Building Graph" << endl;
792
793 RCP<sparse_graph_type> overlappedGraph;
794 RCP<sparse_graph_type> ownedGraph;
795 {
796 TEUCHOS_FUNC_TIME_MONITOR_DIFF("Build matrix graph: 0-Total", graph_total);
797
798 // Construct Tpetra::CrsGraph objects.
799 overlappedGraph = rcp (new sparse_graph_type (overlappedMapG, 200));
800 ownedGraph = rcp (new sparse_graph_type (globalMapG, 0));
801
802 // Define desired workset size and count how many worksets
803 // there are on this process's mesh block.
804 //int desiredWorksetSize = numElems; // change to desired workset size!
805 int desiredWorksetSize = 100; // change to desired workset size!
806 int numWorksets = (numElems+desiredWorksetSize-1)/desiredWorksetSize;
807
808 for (int workset = 0; workset < numWorksets; ++workset) {
809 // Compute cell numbers where the workset starts and ends
810 int worksetBegin = (workset + 0)*desiredWorksetSize;
811 int worksetEnd = (workset + 1)*desiredWorksetSize;
812
813 // When numElems is not divisible by desiredWorksetSize, the
814 // last workset ends at numElems.
815 worksetEnd = (worksetEnd <= numElems) ? worksetEnd : numElems;
816
817 // Now we know the actual workset size and can allocate the
818 // array for the cell nodes.
819 //int worksetSize = worksetEnd - worksetBegin;
820
821 //"WORKSET CELL" loop: local cell ordinal is relative to numElems
822 for (int cell = worksetBegin; cell < worksetEnd; ++cell) {
823 TEUCHOS_FUNC_TIME_MONITOR_DIFF(
824 "Build matrix graph: 1-Insert global indices", graph_insert);
825
826 // Compute cell ordinal relative to the current workset
827 //int worksetCellOrdinal = cell - worksetBegin;
828
829 // "CELL EQUATION" loop for the workset cell: cellRow is
830 // relative to the cell DoF numbering
831 for (int cellRow = 0; cellRow < numFieldsG; cellRow++){
832
833 int localRow = elemToNode(cell, cellRow);
834 //globalRow for Tpetra Graph
835 global_size_t globalRowT = as<global_size_t> (globalNodeIds[localRow]);
836
837 // "CELL VARIABLE" loop for the workset cell: cellCol is
838 // relative to the cell DoF numbering
839 for (int cellCol = 0; cellCol < numFieldsG; ++cellCol) {
840 int localCol = elemToNode (cell, cellCol);
841 GO globalCol = (globalNodeIds[localCol]);
842 //create ArrayView globalCol object for Tpetra
843 ArrayView<GO> globalColAV = arrayView (&globalCol, 1);
844
845 //Update Tpetra overlap Graph
846 overlappedGraph->insertGlobalIndices (globalRowT, globalColAV);
847 }// *** cell col loop ***
848 }// *** cell row loop ***
849 }// *** workset cell loop **
850 }// *** workset loop ***
851
852 // Fill-complete overlapping distribution Graph.
853 {
854 TEUCHOS_FUNC_TIME_MONITOR_DIFF(
855 "Build matrix graph: 2-Overlapped fill complete",
856 overlapped_fill_complete);
857 overlappedGraph->fillComplete ();
858 }
859
860 // Export to owned distribution Graph, and fill-complete the latter.
861 {
862 TEUCHOS_FUNC_TIME_MONITOR_DIFF(
863 "Build matrix graph: 3-Owned graph export", graph_export);
864 ownedGraph->doExport (*overlappedGraph, *exporter, Tpetra::INSERT);
865 }
866 {
867 TEUCHOS_FUNC_TIME_MONITOR_DIFF(
868 "Build matrix graph: 4-Owned fill complete", owned_fill_complete);
869 ownedGraph->fillComplete ();
870 }
871 }
872
873 *out << "Constructing stiffness matrix and vectors" << endl;
874
875 //
876 // Construct stiffness matrix, right-hand side vector, and exact
877 // solution vector. The linear algebra objects starting with gl_
878 // are for the nonoverlapped ("owned") distribution; the ones not
879 // starting with gl_ are for the overlapped distribution. Once
880 // we've constructed the overlapped distribution objects, we'll
881 // Export to the owned distribution objects.
882 //
883 // Owned distribution objects: their names start with gl_.
884 //
885 RCP<sparse_matrix_type> gl_StiffMatrix =
886 rcp (new sparse_matrix_type (ownedGraph.getConst ()));
887 RCP<vector_type> gl_rhsVector = rcp (new vector_type (globalMapG));
888 // We compute the exact solution vector when we make v, and v has
889 // the owned distribution, so we only need an owned distribution
890 // version of the exact solution vector.
891 RCP<vector_type> gl_exactSolVector = rcp (new vector_type (globalMapG));
892
893 RCP<vector_type> gl_nodalSigma(new vector_type(globalMapG));
894 RCP<vector_type> gl_nodalVolume(new vector_type(globalMapG));
895 RCP<vector_type> gl_inverseNodalVolume(new vector_type(globalMapG));
896
897 //
898 // Overlapped distribution objects: their names don't start with gl_.
899 //
900 RCP<sparse_matrix_type> StiffMatrix =
901 rcp (new sparse_matrix_type (overlappedGraph.getConst ()));
902 StiffMatrix->setAllToScalar (STS::zero ());
903 RCP<vector_type> rhsVector = rcp (new vector_type (overlappedMapG));
904 RCP<vector_type> nodalSigma(new vector_type(overlappedMapG));
905 RCP<vector_type> nodalVolume(new vector_type(overlappedMapG));
906
907 rhsVector->putScalar (STS::zero ());
908 nodalSigma->putScalar (STS::zero ());
909 nodalVolume->putScalar (STS::zero ());
910
911
912
913
914 /**********************************************************************************/
915 /************************** DIRICHLET BC SETUP ************************************/
916 /**********************************************************************************/
917
918 *out << "Setting up Dirichlet boundary conditions" << endl;
919
920 int numBCNodes = 0;
921 RCP<vector_type> v;
922 Array<int> BCNodes;
923 {
924 TEUCHOS_FUNC_TIME_MONITOR_DIFF("Dirichlet BC setup", bc_setup);
925 for (int inode = 0; inode < numNodes; ++inode) {
926 if (nodeOnBoundary(inode) && nodeIsOwned[inode]) {
927 ++numBCNodes;
928 }
929 }
930 // v: Vector for use in applying Dirichlet BCs.
931 // v uses the owned (nonoverlapped) distribution.
932 v = rcp (new vector_type (globalMapG, true));
933 v->putScalar (STS::zero ());
934
935 // Set v to boundary values on Dirichlet nodes. While we're
936 // iterating through all the nodes that this process can see
937 // (which includes the nodes which my process owns, as well as
938 // nodes on the interface between my process and another process),
939 // also set the exact solution values.
940 BCNodes.resize (numBCNodes);
941 int indbc = 0;
942 int iOwned = 0;
943 for (int inode = 0; inode < numNodes; ++inode) {
944 if (nodeIsOwned[inode]) {
945 const ST x = nodeCoord(inode, 0);
946 const ST y = nodeCoord(inode, 1);
947 const ST z = nodeCoord(inode, 2);
948
949 if (nodeOnBoundary (inode)) {
950 BCNodes[indbc]=iOwned;
951 ++indbc;
952 // We assume that the exact solution is defined on the
953 // boundary, and evaluate the exact solution function to get
954 // boundary values.
955 v->replaceLocalValue (iOwned, exactSolution (x,y,z));
956 } // if node inode is on the boundary
957
958 gl_exactSolVector->replaceLocalValue (iOwned, exactSolution (x,y,z));
959 ++iOwned;
960 } // if node inode is owned by my process
961 } // for each node inode that my process can see
962 } // Done setting up v (for Dirichlet BCs) and gl_exactSolVector
963
964 /**********************************************************************************/
965 /******************** DEFINE WORKSETS AND LOOP OVER THEM **************************/
966 /**********************************************************************************/
967
968 *out << "Building discretization matrix and right hand side" << endl;
969
970 {
971 TEUCHOS_FUNC_TIME_MONITOR_DIFF(
972 "Matrix/RHS fill: 0-Total", fill_total);
973
974 // Define desired workset size and count how many worksets there are
975 // on this processor's mesh block
976 //int desiredWorksetSize = numElems; // change to desired workset size!
977 int desiredWorksetSize = 100; // change to desired workset size!
978 int numWorksets = (numElems+desiredWorksetSize-1)/desiredWorksetSize;
979
980 {
981 Teuchos::OSTab tab2 (out);
982 *out << "Desired workset size: " << desiredWorksetSize << endl
983 << "Number of worksets (per process): " << numWorksets << endl;
984 }
985
986
987 for (int workset = 0; workset < numWorksets; ++workset) {
988
989 // Compute cell numbers where the workset starts and ends
990 int worksetBegin = (workset + 0)*desiredWorksetSize;
991 int worksetEnd = (workset + 1)*desiredWorksetSize;
992
993 // When numElems is not divisible by desiredWorksetSize, the last
994 // workset ends at numElems.
995 worksetEnd = (worksetEnd <= numElems) ? worksetEnd : numElems;
996
997 // Now we know the actual workset size and can allocate the array
998 // for the cell nodes.
999 int worksetSize = worksetEnd - worksetBegin;
1000 FieldContainer<ST> cellWorkset (worksetSize, numNodesPerElem, spaceDim);
1001
1002 // Copy coordinates into cell workset
1003 int cellCounter = 0;
1004 for (int cell = worksetBegin; cell < worksetEnd; ++cell) {
1005 for (int node = 0; node < numNodesPerElem; ++node) {
1006 cellWorkset(cellCounter, node, 0) = nodeCoord( elemToNode(cell, node), 0);
1007 cellWorkset(cellCounter, node, 1) = nodeCoord( elemToNode(cell, node), 1);
1008 cellWorkset(cellCounter, node, 2) = nodeCoord( elemToNode(cell, node), 2);
1009 }
1010 ++cellCounter;
1011 }
1012
1013 /**********************************************************************************/
1014 /* Allocate arrays */
1015 /**********************************************************************************/
1016
1017 // Containers for Jacobians, integration measure & cubature points in workset cells
1018 FieldContainer<ST> worksetJacobian (worksetSize, numCubPoints, spaceDim, spaceDim);
1019 FieldContainer<ST> worksetJacobInv (worksetSize, numCubPoints, spaceDim, spaceDim);
1020 FieldContainer<ST> worksetJacobDet (worksetSize, numCubPoints);
1021 FieldContainer<ST> worksetCubWeights(worksetSize, numCubPoints);
1022 FieldContainer<ST> worksetCubPoints (worksetSize, numCubPoints, cubDim);
1023
1024 // Containers for basis values transformed to workset cells and
1025 // them multiplied by cubature weights
1026 FieldContainer<ST> worksetHGBValues (worksetSize, numFieldsG, numCubPoints);
1027 FieldContainer<ST> worksetHGBValuesWeighted(worksetSize, numFieldsG, numCubPoints);
1028 FieldContainer<ST> worksetHGBGrads (worksetSize, numFieldsG, numCubPoints, spaceDim);
1029 FieldContainer<ST> worksetHGBGradsWeighted (worksetSize, numFieldsG, numCubPoints, spaceDim);
1030
1031 // Containers for diffusive & advective fluxes & non-conservative
1032 // adv. term and reactive terms
1033 FieldContainer<ST> worksetDiffusiveFlux(worksetSize, numFieldsG, numCubPoints, spaceDim);
1034
1035 // Containers for material values and source term. Require
1036 // user-defined functions
1037 FieldContainer<ST> worksetMaterialVals (worksetSize, numCubPoints, spaceDim, spaceDim);
1038 FieldContainer<ST> worksetSourceTerm (worksetSize, numCubPoints);
1039
1040 // Containers for workset contributions to the discretization
1041 // matrix and the right hand side
1042 FieldContainer<ST> worksetStiffMatrix (worksetSize, numFieldsG, numFieldsG);
1043 FieldContainer<ST> worksetRHS (worksetSize, numFieldsG);
1044
1045 // Weighted measure for material parameters
1046 FieldContainer<ST> weightedMeasureSigma (worksetSize, numCubPoints);
1047
1048 // Containers for the volume-weighted nodal mass
1049 FieldContainer<ST> worksetHGBValuesWeightedSigma(worksetSize, numFieldsG, numCubPoints);
1050 FieldContainer<double> massMatrixG(worksetSize, numFieldsG, numFieldsG);
1051 FieldContainer<double> sigmaMassMatrixG(worksetSize, numFieldsG, numFieldsG);
1052
1053 {
1054 TEUCHOS_FUNC_TIME_MONITOR_DIFF(
1055 "Matrix/RHS fill: 1-Element discretization", elem_discretization);
1056
1057 /**********************************************************************************/
1058 /* Calculate Jacobians */
1059 /**********************************************************************************/
1060
1061 IntrepidCTools::setJacobian(worksetJacobian, cubPoints, cellWorkset, cellType);
1062 IntrepidCTools::setJacobianInv(worksetJacobInv, worksetJacobian );
1063 IntrepidCTools::setJacobianDet(worksetJacobDet, worksetJacobian );
1064
1065 /**********************************************************************************/
1066 /* Cubature Points to Physical Frame and Compute Data */
1067 /**********************************************************************************/
1068
1069 // Map cubature points to physical frame.
1070 IntrepidCTools::mapToPhysicalFrame (worksetCubPoints, cubPoints, cellWorkset, cellType);
1071
1072 // Evaluate the material tensor A at cubature points.
1073 evaluateMaterialTensor (worksetMaterialVals, worksetCubPoints);
1074
1075 // Evaluate the source term at cubature points.
1076 evaluateSourceTerm (worksetSourceTerm, worksetCubPoints);
1077
1078 /**********************************************************************************/
1079 /* Compute Stiffness Matrix */
1080 /**********************************************************************************/
1081
1082 // Transform basis gradients to physical frame:
1083 IntrepidFSTools::HGRADtransformGRAD<ST> (worksetHGBGrads, // DF^{-T}(grad u)
1084 worksetJacobInv,
1085 HGBGrads);
1086 // Compute integration measure for workset cells:
1087 IntrepidFSTools::computeCellMeasure<ST> (worksetCubWeights, // Det(DF)*w = J*w
1088 worksetJacobDet,
1089 cubWeights);
1090
1091 // Combine sigma value with weighted measure
1092 cellCounter = 0;
1093 for(int cell = worksetBegin; cell < worksetEnd; cell++){
1094 for (int nPt = 0; nPt < numCubPoints; nPt++){
1095 weightedMeasureSigma(cellCounter,nPt) = worksetCubWeights(cellCounter,nPt) * sigmaVal(cell);
1096 }
1097 cellCounter++;
1098 }
1099
1100 // Multiply transformed (workset) gradients with weighted measure
1101 IntrepidFSTools::multiplyMeasure<ST> (worksetHGBGradsWeighted, // DF^{-T}(grad u)*J*w
1102 weightedMeasureSigma,
1103 worksetHGBGrads);
1104 // Compute the diffusive flux:
1105 IntrepidFSTools::tensorMultiplyDataField<ST> (worksetDiffusiveFlux, // A*(DF^{-T}(grad u)
1106 worksetMaterialVals,
1107 worksetHGBGrads);
1108 // Integrate to compute workset diffusion contribution to global matrix:
1109 IntrepidFSTools::integrate<ST> (worksetStiffMatrix, // (DF^{-T}(grad u)*J*w)*(A*DF^{-T}(grad u))
1110 worksetHGBGradsWeighted,
1111 worksetDiffusiveFlux,
1112 COMP_BLAS);
1113
1114 /**********************************************************************************/
1115 /* Compute RHS */
1116 /**********************************************************************************/
1117
1118 // Transform basis values to physical frame:
1119 IntrepidFSTools::HGRADtransformVALUE<ST> (worksetHGBValues, // clones basis values (u)
1120 HGBValues);
1121 // Multiply transformed (workset) values with weighted measure
1122 IntrepidFSTools::multiplyMeasure<ST> (worksetHGBValuesWeighted, // (u)*J*w
1123 worksetCubWeights,
1124 worksetHGBValues);
1125 // Integrate worksetSourceTerm against weighted basis function set
1126 IntrepidFSTools::integrate<ST> (worksetRHS, // f.(u)*J*w
1127 worksetSourceTerm,
1128 worksetHGBValuesWeighted,
1129 COMP_BLAS);
1130
1131
1132 /**********************************************************************************/
1133 /* Compute Mass Matrix */
1134 /**********************************************************************************/
1135 // Get the non-sigma mass matrix
1136 IntrepidFSTools::integrate<ST>(massMatrixG, worksetHGBValues,worksetHGBValuesWeighted,COMP_BLAS);
1137
1138 // Get the sigma mass matrix
1139 IntrepidFSTools::multiplyMeasure<ST> (worksetHGBValuesWeightedSigma, // (u)*J*w
1140 weightedMeasureSigma,
1141 worksetHGBValues);
1142 IntrepidFSTools::integrate<ST>(sigmaMassMatrixG, worksetHGBValues,worksetHGBValuesWeightedSigma,COMP_BLAS);
1143
1144 } // Element discretization timer
1145
1146
1147
1148 /**********************************************************************************/
1149 /***************************** STATISTICS (Part II) ******************************/
1150 /**********************************************************************************/
1151 MLStatistics.Phase2a(worksetJacobDet,worksetCubWeights);
1152
1153 /**********************************************************************************/
1154 /* Assemble into Global Matrix */
1155 /**********************************************************************************/
1156
1157 {
1158 TEUCHOS_FUNC_TIME_MONITOR_DIFF(
1159 "Matrix/RHS fill: 2-Element assembly", elem_assembly_total);
1160
1161 // "WORKSET CELL" loop: local cell ordinal is relative to numElems
1162 for (int cell = worksetBegin; cell < worksetEnd; ++cell) {
1163
1164 // Compute cell ordinal relative to the current workset
1165 const int worksetCellOrdinal = cell - worksetBegin;
1166
1167 // "CELL EQUATION" loop for the workset cell: cellRow is
1168 // relative to the cell DoF numbering.
1169 for (int cellRow = 0; cellRow < numFieldsG; ++cellRow) {
1170 int localRow = elemToNode (cell, cellRow);
1171 ST sourceTermContribution = worksetRHS (worksetCellOrdinal, cellRow);
1172
1173 {
1174 // TEUCHOS_FUNC_TIME_MONITOR_DIFF(
1175 // "Matrix/RHS fill: 2a-RHS sum into local values",
1176 // elem_rhs);
1177 rhsVector->sumIntoLocalValue (localRow, sourceTermContribution);
1178
1179
1180 }
1181
1182 // "CELL VARIABLE" loop for the workset cell: sum entire element
1183 // stiff matrix contribution in one function call
1184 ArrayView<int> localColAV =
1185 arrayView<int> (&elemToNode(cell,0), numFieldsG);
1186 ArrayView<ST> operatorMatrixContributionAV =
1187 arrayView<ST> (&worksetStiffMatrix(worksetCellOrdinal,cellRow,0),
1188 numFieldsG);
1189 {
1190 // TEUCHOS_FUNC_TIME_MONITOR_DIFF(
1191 // "Matrix/RHS fill: 2b-Matrix sum into local values",
1192 // elem_matrix);
1193 StiffMatrix->sumIntoLocalValues (localRow, localColAV,
1194 operatorMatrixContributionAV);
1195 }
1196
1197 // Sigma vector goodness
1198 ArrayView<ST> mass_m = arrayView<ST> (&massMatrixG(worksetCellOrdinal,cellRow,0),numFieldsG);
1199 ArrayView<ST> sigma_m = arrayView<ST> (&sigmaMassMatrixG(worksetCellOrdinal,cellRow,0),numFieldsG);
1200 ST sigma_sum = Teuchos::ScalarTraits<ST>::zero();
1201 ST volume_sum = Teuchos::ScalarTraits<ST>::zero();
1202 for(size_t i=0; i<(size_t)mass_m.size(); i++) {
1203 sigma_sum+= sigma_m[i];
1204 volume_sum+= mass_m[i];
1205 }
1206 nodalSigma->sumIntoLocalValue(localRow,sigma_sum);
1207 nodalVolume->sumIntoLocalValue(localRow,volume_sum);
1208
1209
1210 }// *** cell row loop ***
1211 }// *** workset cell loop **
1212 } // *** stop timer ***
1213 }// *** workset loop ***
1214
1215 /**********************************************************************************/
1216 /***************************** STATISTICS (Part IIb) ******************************/
1217 /**********************************************************************************/
1218 MLStatistics.Phase2b(gl_StiffMatrix->getCrsGraph(),coords);
1219
1220 /**********************************************************************************/
1221 /***************************** STATISTICS (Part III) ******************************/
1222 /**********************************************************************************/
1223 MLStatistics.Phase3();
1224 problemStatistics = MLStatistics.GetStatistics();
1225
1226 //////////////////////////////////////////////////////////////////////////////
1227 // Export sparse matrix and right-hand side from overlapping row Map
1228 // to owned (nonoverlapping) row Map.
1229 //////////////////////////////////////////////////////////////////////////////
1230
1231 *out << "Exporting matrix and right-hand side from overlapped to owned Map" << endl;
1232
1233 gl_StiffMatrix->setAllToScalar (STS::zero ());
1234 {
1235 TEUCHOS_FUNC_TIME_MONITOR_DIFF(
1236 "Matrix/RHS fill: 3-Matrix export", matrix_export);
1237 gl_StiffMatrix->doExport (*StiffMatrix, *exporter, Tpetra::ADD);
1238 }
1239 // If target of export has static graph, no need to do
1240 // setAllToScalar(0.0); export will clobber values.
1241 {
1242 TEUCHOS_FUNC_TIME_MONITOR_DIFF(
1243 "Matrix/RHS fill: 4-Matrix fill complete", matrix_fill_complete);
1244 gl_StiffMatrix->fillComplete ();
1245 }
1246
1247 gl_rhsVector->putScalar (STS::zero ());
1248 {
1249 TEUCHOS_FUNC_TIME_MONITOR_DIFF(
1250 "Matrix/RHS fill: 5-RHS export", rhs_export);
1251 gl_rhsVector->doExport (*rhsVector, *exporter, Tpetra::ADD);
1252 }
1253
1254 gl_nodalSigma->putScalar (STS::zero ());
1255 gl_nodalSigma->doExport (*nodalSigma, *exporter, Tpetra::ADD);
1256
1257 gl_nodalVolume->putScalar (STS::zero ());
1258 gl_nodalVolume->doExport (*nodalVolume, *exporter, Tpetra::ADD);
1259
1260 // Get the volume-weighted sigma
1261 gl_inverseNodalVolume->reciprocal(*gl_nodalVolume);
1262 gl_nodalSigma->elementWiseMultiply(STS::one(), *gl_nodalSigma,*gl_inverseNodalVolume,STS::zero());
1263
1264 //////////////////////////////////////////////////////////////////////////////
1265 // Adjust matrix for boundary conditions
1266 //////////////////////////////////////////////////////////////////////////////
1267
1268 *out << "Adjusting matrix and right-hand side for BCs" << endl;
1269
1270 {
1271 TEUCHOS_FUNC_TIME_MONITOR_DIFF(
1272 "Matrix/RHS fill: 6-Dirichlet BC assembly", bc_assembly);
1273
1274 // Apply owned stiffness matrix to v: rhs := A*v
1275 RCP<multivector_type> rhsDir =
1276 rcp (new multivector_type (globalMapG, true));
1277 gl_StiffMatrix->apply (*v.getConst (), *rhsDir);
1278 // Update right-hand side
1279 gl_rhsVector->update (as<ST> (-STS::one ()), *rhsDir, STS::one ());
1280
1281 // Get a const view of the vector's local data.
1282 ArrayRCP<const ST> vArrayRCP = v->getData (0);
1283
1284 // Adjust rhs due to Dirichlet boundary conditions.
1285 for (int inode = 0; inode < numNodes; ++inode) {
1286 if (nodeIsOwned[inode]) {
1287 if (nodeOnBoundary (inode)) {
1288 // Get global node ID
1289 const GO gni = as<GO> (globalNodeIds[inode]);
1290 const LO lidT = globalMapG->getLocalElement (gni);
1291 ST v_valT = vArrayRCP[lidT];
1292 gl_rhsVector->replaceGlobalValue (gni, v_valT);
1293 }
1294 }
1295 }
1296
1297 // Zero out rows and columns of stiffness matrix corresponding to
1298 // Dirichlet edges and add one to diagonal. The following is the
1299 // Tpetra analog of Apply_OAZToMatrix().
1300 //
1301 // Reenable changes to the values and structure of the global
1302 // stiffness matrix.
1303 gl_StiffMatrix->resumeFill ();
1304
1305 // Find the local column numbers to nuke
1306 RCP<const map_type> ColMap = gl_StiffMatrix->getColMap ();
1307 RCP<const map_type> globalMap =
1308 rcp (new map_type (gl_StiffMatrix->getGlobalNumCols (), 0, comm,
1309 Tpetra::GloballyDistributed));
1310
1311 // Create the exporter from this process' column Map to the global
1312 // 1-1 column map. (???)
1313 RCP<const export_type> bdyExporter =
1314 rcp (new export_type (ColMap, globalMap));
1315 // Create a vector of global column indices to which we will export
1316 RCP<Tpetra::Vector<int, LO, GO, Node> > globColsToZeroT =
1317 rcp (new Tpetra::Vector<int, LO, GO, Node> (globalMap));
1318 // Create a vector of local column indices from which we will export
1319 RCP<Tpetra::Vector<int, LO, GO, Node> > myColsToZeroT =
1320 rcp (new Tpetra::Vector<int, LO, GO, Node> (ColMap));
1321 myColsToZeroT->putScalar (0);
1322
1323 // Flag (set to 1) all local columns corresponding to the local
1324 // rows specified.
1325 for (int i = 0; i < numBCNodes; ++i) {
1326 const GO globalRow = gl_StiffMatrix->getRowMap ()->getGlobalElement (BCNodes[i]);
1327 const LO localCol = gl_StiffMatrix->getColMap ()->getLocalElement (globalRow);
1328 // Tpetra::Vector<int, ...> works just like
1329 // Tpetra::Vector<double, ...>. Epetra has a separate
1330 // Epetra_IntVector class for ints.
1331 myColsToZeroT->replaceLocalValue (localCol, 1);
1332 }
1333
1334 // Export to the global column map.
1335 globColsToZeroT->doExport (*myColsToZeroT, *bdyExporter, Tpetra::ADD);
1336 // Import from the global column map to the local column map.
1337 myColsToZeroT->doImport (*globColsToZeroT, *bdyExporter, Tpetra::INSERT);
1338
1339 ArrayRCP<const int> myColsToZeroArrayRCP = myColsToZeroT->getData(0);
1340 size_t NumEntries = 0;
1341
1342 // Zero the columns corresponding to Dirichlet BCs.
1343 typename sparse_matrix_type::nonconst_local_inds_host_view_type indices("indices", 1);
1344 typename sparse_matrix_type::nonconst_values_host_view_type values("values", 1);
1345 for (LO i = 0; i < as<int> (gl_StiffMatrix->getLocalNumRows ()); ++i) {
1346 NumEntries = gl_StiffMatrix->getNumEntriesInLocalRow (i);
1347 Kokkos::resize(indices, NumEntries);
1348 Kokkos::resize(values, NumEntries);
1349 gl_StiffMatrix->getLocalRowCopy (i, indices, values, NumEntries);
1350 for (int j = 0; j < as<int> (NumEntries); ++j) {
1351 if (myColsToZeroArrayRCP[indices(j)] == 1)
1352 values(j) = STS::zero ();
1353 }
1354 gl_StiffMatrix->replaceLocalValues (i, indices, values);
1355 } // for each (local) row of the global stiffness matrix
1356
1357 // Zero the rows and add ones to diagonal.
1358 for (int i = 0; i < numBCNodes; ++i) {
1359 NumEntries = gl_StiffMatrix->getNumEntriesInLocalRow (BCNodes[i]);
1360 Kokkos::resize(indices, NumEntries);
1361 Kokkos::resize(values, NumEntries);
1362 gl_StiffMatrix->getLocalRowCopy (BCNodes[i], indices, values, NumEntries);
1363 const GO globalRow = gl_StiffMatrix->getRowMap ()->getGlobalElement (BCNodes[i]);
1364 const LO localCol = gl_StiffMatrix->getColMap ()->getLocalElement (globalRow);
1365 for (int j = 0; j < as<int> (NumEntries); ++j) {
1366 values(j) = STS::zero ();
1367 if (indices(j) == localCol) {
1368 values(j) = STS::one ();
1369 }
1370 } // for each entry in the current row
1371 gl_StiffMatrix->replaceLocalValues (BCNodes[i], indices, values);
1372 } // for each BC node
1373 }
1374
1375 *out << "Calling fillComplete() on owned-Map stiffness matrix" << endl;
1376
1377 // We're done modifying the owned stiffness matrix.
1378 gl_StiffMatrix->fillComplete ();
1379
1380 } // Matrix/RHS fill timing
1381
1382 //
1383 // We're done with assembly, so we can delete the mesh.
1384 //
1385 delete [] nodeIsOwned;
1386 nodeIsOwned = NULL;
1387 Delete_Pamgen_Mesh ();
1388
1389 // Create vector to store approximate solution, and set initial guess.
1390 RCP<vector_type> gl_approxSolVector = rcp (new vector_type (globalMapG));
1391 gl_approxSolVector->putScalar (STS::zero ());
1392
1393 // Store the output pointers.
1394 A = gl_StiffMatrix;
1395 B = gl_rhsVector;
1396 X_exact = gl_exactSolVector;
1397 X = gl_approxSolVector;
1398 node_sigma = gl_nodalSigma;
1399 }
1400
1401 std::vector<Teuchos::ScalarTraits<ST>::magnitudeType>
1402 exactResidualNorm (const Teuchos::RCP<const sparse_matrix_type>& A,
1403 const Teuchos::RCP<const vector_type>& B,
1404 const Teuchos::RCP<const vector_type>& X_exact)
1405 {
1406 using Teuchos::RCP;
1407 using Teuchos::rcp;
1408 typedef Teuchos::ScalarTraits<ST> STS;
1409 typedef STS::magnitudeType MT;
1410
1411 RCP<vector_type> R = rcp (new vector_type (*B)); // R := B
1412 // R := 1.0*R - 1.0*A*X_exact.
1413 A->apply (*X_exact, *R, Teuchos::NO_TRANS, -STS::one(), STS::one());
1414
1415 std::vector<MT> results (3);
1416 results[0] = R->norm2 ();
1417 results[1] = B->norm2 ();
1418 results[2] = A->getFrobeniusNorm ();
1419 return results;
1420 }
1421
1422 /**********************************************************************************/
1423 /************ USER DEFINED FUNCTIONS FOR EXACT SOLUTION ***************************/
1424 /**********************************************************************************/
1425
1426 template<typename Scalar>
1427 const Scalar
1428 exactSolution (const Scalar& x, const Scalar& y, const Scalar& z)
1429 {
1430 // Patch test: tri-linear function is in the FE space and should be recovered
1431 return 1. + x + y + z + x*y + x*z + y*z + x*y*z;
1432
1433 // Analytic solution with homogeneous Dirichlet boundary data
1434 // return sin(M_PI*x)*sin(M_PI*y)*sin(M_PI*z)*exp(x+y+z);
1435
1436 // Analytic solution with inhomogeneous Dirichlet boundary data
1437 // return exp(x + y + z)/(1. + x*y + y*z + x*y*z);
1438 }
1439
1440
1441 /** \brief User-defined material tensor.
1442
1443 Evaluate the tensor using operator(). Its arguments are:
1444
1445 \param material [out] 3 x 3 material tensor evaluated at (x,y,z)
1446 \param x [in] x-coordinate of the evaluation point
1447 \param y [in] y-coordinate of the evaluation point
1448 \param z [in] z-coordinate of the evaluation point
1449
1450 \warning Symmetric and positive definite tensor is required for every (x,y,z).
1451 */
1452 template<typename Scalar>
1453 class MaterialTensor {
1454 public:
1455 // Default Construction
1456 MaterialTensor():offDiagVal_(Scalar(0.0)),v_() {
1457
1458 if(::TrilinosCouplings::IntrepidPoissonExample::useDiffusionMatrix()) {
1459 v_ = ::TrilinosCouplings::IntrepidPoissonExample::getDiffusionMatrix();
1460 }
1461 else {
1462 offDiagVal_ = Scalar (::TrilinosCouplings::IntrepidPoissonExample::getMaterialTensorOffDiagonalValue());
1463 }
1464 }
1465
1466 void
1467 operator () (Scalar material[][3],
1468 const Scalar& x,
1469 const Scalar& y,
1470 const Scalar& z) const
1471 {
1472 typedef Teuchos::ScalarTraits<Scalar> STS;
1473
1474 if(v_.size() == 0) {
1475 // We go through this trouble to make numbers, because Scalar
1476 // isn't necessarily double. It could be some automatic
1477 // differentiation type.
1478 const Scalar zero = STS::zero ();
1479 const Scalar one = STS::one ();
1480
1481 // You can use the value of offDiagVal_ to control the iteration
1482 // count. The iteration counts below are for Belos' GMRES with no
1483 // preconditioning, using the default problem size.
1484 // setMaterialTensorOffDiagonalValue() sets the value of this
1485 // parameter.
1486 //
1487 // Classical elasticity assumes a symmetric material tensor. I
1488 // suppose one could solve Poisson's equation with an unsymmetric
1489 // material tensor, but I'm not sure what that would mean.
1490
1491 // offDiagVal_ = -5/4: 209 iterations (CG breaks!)
1492 // offDiagVal_ = -1/2: 47 iterations
1493 // offDiagVal_ = 0: 40 iterations (CG works)
1494 // offDiagVal_ = 1/2: 46 iterations
1495 // offDiagVal_ = 3/4: 47 iterations
1496 // offDiagVal_ = 1: 59 iterations
1497 // offDiagVal_ = 5/4: 183 iterations
1498 // offDiagVal_ = 3/2: 491 iterations
1499 // offDiagVal_ = 2: 939 iterations (CG breaks!)
1500 material[0][0] = one;
1501 material[0][1] = zero;
1502 material[0][2] = offDiagVal_;
1503
1504 material[1][0] = zero;
1505 material[1][1] = one;
1506 material[1][2] = zero;
1507
1508 material[2][0] = offDiagVal_;
1509 material[2][1] = zero;
1510 material[2][2] = one;
1511 }
1512 else {
1513 // Use the user tensor
1514 for(int i=0; i<3; i++)
1515 for(int j=0; j<3; j++)
1516 material[i][j] = v_[i*3+j];
1517 }
1518 }
1519
1520 private:
1521 Scalar offDiagVal_;
1522 std::vector<double> v_;
1523 };
1524
1525 /**********************************************************************************/
1526 /************** AUXILIARY FUNCTIONS FROM EXACT SOLUTION ***************************/
1527 /**********************************************************************************/
1528
1529 /// \brief Compute gradient of exact solution at (x,y,z).
1530 ///
1531 /// \param gradExact [out] The gradient at (x,y,z).
1532 /// \param x [in]
1533 /// \param y [in]
1534 /// \param z [in]
1535 template<typename Scalar>
1536 void
1537 exactSolutionGrad (Scalar gradExact[3],
1538 const Scalar& x,
1539 const Scalar& y,
1540 const Scalar& z)
1541 {
1542 // To enable taking derivatives of the gradient (that is, second
1543 // derivatives of the exact solution), we need 2 levels of fad
1544 // types.
1545 Sacado::Fad::SFad<Scalar,3> fad_x = x;
1546 Sacado::Fad::SFad<Scalar,3> fad_y = y;
1547 Sacado::Fad::SFad<Scalar,3> fad_z = z;
1548 Sacado::Fad::SFad<Scalar,3> u;
1549
1550 // Indicate the independent variables
1551 fad_x.diff(0,3);
1552 fad_y.diff(1,3);
1553 fad_z.diff(2,3);
1554
1555 u = exactSolution(fad_x, fad_y, fad_z);
1556
1557 gradExact[0] = u.dx(0);
1558 gradExact[1] = u.dx(1);
1559 gradExact[2] = u.dx(2);
1560 }
1561
1562 /// \brief Compute the source term (right-hand side) at (x,y,z).
1563 ///
1564 /// We compute the source term from the exact solution, its gradient,
1565 /// and the material tensor at (x,y,z).
1566 template<typename Scalar>
1567 const Scalar
1568 sourceTerm (Scalar& x, Scalar& y, Scalar& z)
1569 {
1570 Scalar u;
1571 Scalar grad_u[3];
1572 Scalar flux[3] = {0.0, 0.0, 0.0};
1573 Scalar material[3][3];
1574 Scalar f = 0.;
1575
1576 // Indicate the independent variables
1577 x.diff(0,3);
1578 y.diff(1,3);
1579 z.diff(2,3);
1580
1581 // Get exact solution and its gradient
1582 u = exactSolution (x, y, z);
1583 exactSolutionGrad (grad_u, x, y, z);
1584
1585 // Get material tensor
1586 MaterialTensor<Scalar> matTens;
1587 matTens (material, x, y, z);
1588
1589 // Compute total flux = (A.grad u)
1590 for (int i = 0; i < 3; ++i) {
1591 // Add diffusive flux
1592 for (int j = 0; j < 3; ++j) {
1593 flux[i] += material[i][j]*grad_u[j];
1594 }
1595 }
1596
1597 // Compute source term (right hand side): f = -div(A.grad u)
1598 f = -(flux[0].dx(0) + flux[1].dx(1) + flux[2].dx(2));
1599
1600 return f;
1601 }
1602
1603 /**********************************************************************************/
1604 /*************************** EVALUATION METHODS ***********************************/
1605 /**********************************************************************************/
1606
1607 //! Compute the material tensor over a workset.
1608 template<class ArrayOut, class ArrayIn>
1609 void
1610 evaluateMaterialTensor (ArrayOut& matTensorValues,
1611 const ArrayIn& evaluationPoints)
1612 {
1613 typedef typename ArrayOut::scalar_type scalar_type;
1614
1615 const int numWorksetCells = evaluationPoints.dimension(0);
1616 const int numPoints = evaluationPoints.dimension(1);
1617 const int spaceDim = evaluationPoints.dimension(2);
1618
1619 scalar_type material[3][3];
1620
1621 MaterialTensor<scalar_type> matTens;
1622 for (int cell = 0; cell < numWorksetCells; ++cell) {
1623 for (int pt = 0; pt < numPoints; ++pt) {
1624 scalar_type x = evaluationPoints(cell, pt, 0);
1625 scalar_type y = evaluationPoints(cell, pt, 1);
1626 scalar_type z = evaluationPoints(cell, pt, 2);
1627
1628 matTens (material, x, y, z);
1629
1630 for (int row = 0; row < spaceDim; ++row) {
1631 for(int col = 0; col < spaceDim; ++col) {
1632 matTensorValues(cell, pt, row, col) = material[row][col];
1633 }
1634 }
1635 }
1636 }
1637 }
1638
1639 /************ Source Term (RHS) ****************/
1640 template<class ArrayOut, class ArrayIn>
1641 void
1642 evaluateSourceTerm (ArrayOut& sourceTermValues,
1643 const ArrayIn& evaluationPoints)
1644 {
1645 typedef typename ArrayOut::scalar_type scalar_type;
1646
1647 const int numWorksetCells = evaluationPoints.dimension(0);
1648 const int numPoints = evaluationPoints.dimension(1);
1649
1650 for (int cell = 0; cell < numWorksetCells; ++cell) {
1651 for (int pt = 0; pt < numPoints; ++pt) {
1652 Sacado::Fad::SFad<scalar_type,3> x = evaluationPoints(cell, pt, 0);
1653 Sacado::Fad::SFad<scalar_type,3> y = evaluationPoints(cell, pt, 1);
1654 Sacado::Fad::SFad<scalar_type,3> z = evaluationPoints(cell, pt, 2);
1655
1656 sourceTermValues(cell, pt) =
1657 sourceTerm<Sacado::Fad::SFad<scalar_type,3> > (x, y, z).val ();
1658 }
1659 }
1660 }
1661
1662 /************ Exact Solution ****************/
1663 template<class ArrayOut, class ArrayIn>
1664 void
1665 evaluateExactSolution (ArrayOut& exactSolutionValues,
1666 const ArrayIn& evaluationPoints)
1667 {
1668 typedef typename ArrayOut::scalar_type scalar_type;
1669
1670 const int numWorksetCells = evaluationPoints.dimension(0);
1671 const int numPoints = evaluationPoints.dimension(1);
1672
1673 for (int cell = 0; cell < numWorksetCells; ++cell) {
1674 for (int pt = 0; pt < numPoints; ++pt) {
1675 const scalar_type x = evaluationPoints(cell, pt, 0);
1676 const scalar_type y = evaluationPoints(cell, pt, 1);
1677 const scalar_type z = evaluationPoints(cell, pt, 2);
1678 exactSolutionValues(cell, pt) = exactSolution<scalar_type> (x, y, z);
1679 }
1680 }
1681 }
1682
1683 /************ Grad of Exact Solution ****************/
1684 template<class ArrayOut, class ArrayIn>
1685 void
1686 evaluateExactSolutionGrad (ArrayOut& exactSolutionGradValues,
1687 const ArrayIn& evaluationPoints)
1688 {
1689 typedef typename ArrayOut::scalar_type scalar_type;
1690
1691 const int numWorksetCells = evaluationPoints.dimension(0);
1692 const int numPoints = evaluationPoints.dimension(1);
1693 const int spaceDim = evaluationPoints.dimension(2);
1694
1695 scalar_type gradient[3];
1696
1697 for (int cell = 0; cell < numWorksetCells; ++cell) {
1698 for (int pt = 0; pt < numPoints; ++pt) {
1699 const scalar_type x = evaluationPoints(cell, pt, 0);
1700 const scalar_type y = evaluationPoints(cell, pt, 1);
1701 const scalar_type z = evaluationPoints(cell, pt, 2);
1702
1703 exactSolutionGrad<scalar_type> (gradient, x, y, z);
1704
1705 for (int row = 0; row < spaceDim; ++row) {
1706 exactSolutionGradValues(cell, pt, row) = gradient[row];
1707 }
1708 }
1709 }
1710 }
1711
1712 } // namespace TpetraIntrepidPoissonExample
1713 } // namespace TrilinosCouplings