diff --git a/packages/trilinoscouplings/examples/scaling/TrilinosCouplings_Statistics.hpp b/packages/trilinoscouplings/examples/scaling/TrilinosCouplings_Statistics.hpp index ba570d4f7c56..1fea0b302a10 100644 --- a/packages/trilinoscouplings/examples/scaling/TrilinosCouplings_Statistics.hpp +++ b/packages/trilinoscouplings/examples/scaling/TrilinosCouplings_Statistics.hpp @@ -144,7 +144,7 @@ class MachineLearningStatistics_Hex3D { int node3 = edgeToNode(edge, 0); int node4 = edgeToNode(edge, 1); - int numElems = elemToEdge.dimension(0); + int numElems = elemToNode.dimension(0); for(int i=0; i +#include +#include #include "TrilinosCouplings_config.h" @@ -167,6 +169,10 @@ #include "stk_mesh/base/FieldBase.hpp" // for field_data, etc #include "stk_mesh/base/Types.hpp" // for BucketVector, EntityId +#ifdef HAVE_TRILINOSCOUPLINGS_MUELU +#include "TrilinosCouplings_Statistics.hpp" +#endif + /*********************************************************/ /* Typedefs */ /*********************************************************/ @@ -481,16 +487,20 @@ int main(int argc, char *argv[]) { for (int i=0; i CoordFieldType; // get coordinates field @@ -537,6 +547,19 @@ int main(int argc, char *argv[]) { } // end loop over mesh parts int numNodesPerElem = cellType.getNodeCount(); +#if defined(HAVE_TRILINOSCOUPLINGS_MUELU) && defined(HAVE_MUELU_EPETRA) + int numEdgesPerElem = cellType.getEdgeCount(); +#endif + + if(MyPID==0) { + std::cout<<"Cell Topology: "< MLStatistics(numGlobalElements); + bool do_statistics = !strcmp(cellType.getName(),"Hexahedron_8"); + std::cout<<"do_statistics = "< elemToNode(numLocalElems,numNodesPerElem); + Intrepid::FieldContainer elemToEdge(numLocalElems,numEdgesPerElem); + Intrepid::FieldContainer nodeCoord (numLocalNodes, spaceDim); + Intrepid::FieldContainer sigmaVal(numLocalElems); + + int elem_ct=0; + std::map,int> local_edge_hash; + std::vector > edge_vector; + + for (size_t bucketIndex = 0; bucketIndex < localElementBuckets.size(); ++bucketIndex) { + stk::mesh::Bucket &elemBucket = *localElementBuckets[bucketIndex]; + for (size_t elemIndex = 0; elemIndex < elemBucket.size(); ++elemIndex) { + stk::mesh::Entity elem = elemBucket[elemIndex]; + //TODO (Optimization) It's assumed all elements are the same type, so this is constant. + //TODO Therefore there's no need to do this everytime. + unsigned numNodes = bulkData.num_nodes(elem); + stk::mesh::Entity const* nodes = bulkData.begin_nodes(elem); + for (unsigned inode = 0; inode < numNodes; ++inode) { + double *coord = stk::mesh::field_data(*coords, nodes[inode]); + int lid = globalMapG.LID((int)bulkData.identifier(nodes[inode]) -1); + elemToNode(elem_ct,inode) = lid; + if(lid != -1) { + nodeCoord(lid,0) = coord[0]; + nodeCoord(lid,1) = coord[1]; + if(spaceDim==3) + nodeCoord(lid,2) = coord[2]; + } + }//end node loop + + auto data = cellType.getCellTopologyData(); + for(unsigned iedge=0; iedgeedge[iedge].node[0]; + int n1 = data->edge[iedge].node[1]; + int lid0 = globalMapG.LID((int)bulkData.identifier(nodes[n0]) -1); + int lid1 = globalMapG.LID((int)bulkData.identifier(nodes[n1]) -1); + if(lid0 != -1 && lid1 != -1) { + int lo = std::min(lid0,lid1); + int hi = std::max(lid0,lid1); + std::pair key(lo,hi); + if (local_edge_hash.find(key) == local_edge_hash.end()) { + int new_edge_id = edge_vector.size(); + local_edge_hash[key] = new_edge_id; + edge_vector.push_back(key); + elemToEdge(elem_ct,iedge) = new_edge_id; + } + else { + elemToEdge(elem_ct,iedge) = local_edge_hash[key]; + } + } + }//end edge loop + + sigmaVal(elem_ct) = 1;// Not doing sigma here + + elem_ct++; + }//end element loop + }//end bucket loop + + Intrepid::FieldContainer edgeToNode(edge_vector.size(), 2); + for(int i=0; i<(int)edge_vector.size(); i++) { + edgeToNode(i,0) = edge_vector[i].first; + edgeToNode(i,1) = edge_vector[i].second; + } + + + MLStatistics.Phase1(elemToNode,elemToEdge,edgeToNode,nodeCoord,sigmaVal); + + } +#endif + /**********************************************************************************/ /******************** DEFINE WORKSETS AND LOOP OVER THEM **************************/ /**********************************************************************************/ @@ -873,6 +970,17 @@ int main(int argc, char *argv[]) { Time.ResetStartTime(); } + + + + /**********************************************************************************/ + /***************************** STATISTICS (Part II) ******************************/ + /**********************************************************************************/ +#if defined(HAVE_TRILINOSCOUPLINGS_MUELU) && defined(HAVE_MUELU_EPETRA) + if(do_statistics) + MLStatistics.Phase2a(worksetJacobDet,worksetCubWeights); +#endif + /**********************************************************************************/ /* Assemble into Global Matrix */ /**********************************************************************************/ @@ -880,6 +988,7 @@ int main(int argc, char *argv[]) { //"WORKSET CELL" loop: local cell ordinal is relative to numLocalElems //JJH runs from 0 to (#local cells - 1) int worksetCellOrdinal = 0; + for (size_t bucketIndex = 0; bucketIndex < localElementBuckets.size(); ++bucketIndex) { stk::mesh::Bucket &elemBucket = *localElementBuckets[bucketIndex]; @@ -910,13 +1019,15 @@ int main(int argc, char *argv[]) { }// end cell row loop + worksetCellOrdinal++; }// end workset cell loop - worksetCellOrdinal++; + } //for (size_t bucketIndex = 0; ... }// end workset loop + StiffMatrix.GlobalAssemble(); StiffMatrix.FillComplete(); rhsVector.GlobalAssemble(); @@ -926,6 +1037,26 @@ int main(int argc, char *argv[]) { << Time.ElapsedTime() << " seconds" << std::endl; Time.ResetStartTime(); } +/**********************************************************************************/ +/***************************** STATISTICS (Part IIb) ******************************/ +/**********************************************************************************/ +#if defined(HAVE_TRILINOSCOUPLINGS_MUELU) && defined(HAVE_MUELU_EPETRA) + if(do_statistics){ + MLStatistics.Phase2b(Teuchos::rcp(&StiffMatrix.Graph(),false),Teuchos::rcp(&nCoord,false)); + } +#endif +/**********************************************************************************/ +/***************************** STATISTICS (Part III) ******************************/ +/**********************************************************************************/ +#if defined(HAVE_TRILINOSCOUPLINGS_MUELU) && defined(HAVE_MUELU_EPETRA) + if(do_statistics){ + MLStatistics.Phase3(); + Teuchos::ParameterList problemStatistics = MLStatistics.GetStatistics(); + if(MyPID==0) std::cout<<"*** Problem Statistics ***"< const Scalar exactSolution(const Scalar& x, const Scalar& y, const Scalar& z) { + // Patch test: tri-linear function is in the FE space and should be recovered + return 1. + x + y + z + x*y + x*z + y*z + x*y*z; + + // Patch test - tet: function is in the FE space and should be recovered - return 1. + x + y + z ; + // return 1. + x + y + z ; // Patch test - hex: tri-linear function is in the FE space and should be recovered // return 1. + x + y + z + x*y + x*z + y*z + x*y*z;