// @HEADER // ***************************************************************************** // Trilinos: An Object-Oriented Solver Framework // // Copyright 2001-2024 NTESS and the Trilinos contributors. // SPDX-License-Identifier: BSD-3-Clause // ***************************************************************************** // @HEADER /** \file example_DivLSFEM.cpp \brief Example solution of a div-curl system on a hexahedral mesh using div-conforming (face) elements. This example uses the following Trilinos packages: \li Pamgen to generate a Hexahedral mesh. \li Intrepid to build the discretization matrices and right-hand side. \li Epetra to handle the global matrix and vector. \li ML to solve the linear system. For more details on the formulation see \li P. Bochev, K. Peterson, C. Siefert, "Analysis and Computation of Compatible Least-Squares Methods for Div-Curl Equations", SIAM J. Numerical Analysis, vol 49, pp 159-191, 2011. \verbatim Div-Curl System: curl u = g in Omega div u = h in Omega u.n = 0 on Gamma Corresponding discrete linear system for face element coeficients (x): (Kd + Md*Dc*McInv*Dc'*Md)x = b Kd - Hdiv stiffness matrix Md - Hdiv mass matrix Dc - Edge to Face incidence matrix McInv - Hgrad mass matrix inverse b - right hand side vector \endverbatim \author Created by P. Bochev, D. Ridzal, K. Peterson, D. Hensinger, C. Siefert. \remark Usage \verbatim ./TrilinosCouplings_examples_scaling_Example_DivLSFEM.exe inputfile.xml inputfile.xml (optional) - xml input file containing Pamgen mesh description and material parameters for each Pamgen block, if not present code attempts to read DivLSFEMin.xml. \endverbatim **/ // TrilinosCouplings includes #include "TrilinosCouplings_config.h" #include "TrilinosCouplings_Pamgen_Utils.hpp" // Intrepid includes #include "Intrepid_FunctionSpaceTools.hpp" #include "Intrepid_FieldContainer.hpp" #include "Intrepid_CellTools.hpp" #include "Intrepid_ArrayTools.hpp" #include "Intrepid_HCURL_HEX_I1_FEM.hpp" #include "Intrepid_HGRAD_HEX_C1_FEM.hpp" #include "Intrepid_HDIV_HEX_I1_FEM.hpp" #include "Intrepid_RealSpaceTools.hpp" #include "Intrepid_DefaultCubatureFactory.hpp" #include "Intrepid_Utils.hpp" // Epetra includes #include "Epetra_Time.h" #include "Epetra_Map.h" #ifdef HAVE_MPI #include "Epetra_MpiComm.h" #else #include "Epetra_SerialComm.h" #endif #include "Epetra_FECrsMatrix.h" #include "Epetra_FEVector.h" #include "Epetra_Vector.h" #include "Epetra_LinearProblem.h" #include "Epetra_Import.h" #include "Epetra_Export.h" // Teuchos includes #include "Teuchos_oblackholestream.hpp" #include "Teuchos_RCP.hpp" #include "Teuchos_BLAS.hpp" #include "Teuchos_GlobalMPISession.hpp" #include "Teuchos_ParameterList.hpp" #include "Teuchos_XMLParameterListHelpers.hpp" // Shards includes #include "Shards_CellTopology.hpp" // EpetraExt includes #include "EpetraExt_RowMatrixOut.h" #include "EpetraExt_MultiVectorOut.h" #include "EpetraExt_VectorOut.h" #include "EpetraExt_MatrixMatrix.h" // Pamgen includes #include "create_inline_mesh.h" #include "pamgen_im_exodusII_l.h" #include "pamgen_im_ne_nemesisI_l.h" #include "pamgen_extras.h" // AztecOO includes #include "AztecOO.h" // ML Includes #include "ml_epetra_utils.h" #include "ml_RefMaxwell_11_Operator.h" #include "ml_FaceMatrixFreePreconditioner.h" #include "ml_RefMaxwell.h" #define ABS(x) ((x)>0?(x):-(x)) /*** Uncomment if you would like output data for plotting ***/ //#define DUMP_DATA using namespace std; using namespace Intrepid; using namespace Teuchos; /*********************************************************/ /* Typedefs */ /*********************************************************/ typedef Intrepid::FunctionSpaceTools IntrepidFSTools; typedef Intrepid::RealSpaceTools IntrepidRSTools; typedef Intrepid::CellTools IntrepidCTools; struct fecomp{ bool operator () ( topo_entity* x, topo_entity* y )const { if(x->sorted_local_node_ids < y->sorted_local_node_ids)return true; return false; } }; /**********************************************************************************/ /***************** FUNCTION DECLARATIONS FOR ML PRECONDITIONER ********************/ /**********************************************************************************/ /** \brief Multiplies abs(A)x = y, where all non-zero entries of A are replaced with their absolute values value \param A [in] matrix \param x [in] vector \param y [out] vector */ int Multiply_Abs(const Epetra_CrsMatrix &A,const Epetra_Vector &x,Epetra_Vector &y); /** \brief ML Preconditioner \param ProblemType [in] problem type \param MLList [in] ML parameter list \param GradDiv [in] H(curl) stiffness matrix \param D0clean [in] Edge to node incidence matrix \param D1clean [in] Face to edge incidence matrix \param FaceNode [in] Face to node incidence matrix \param M1inv [in] H(curl) mass matrix inverse \param M2 [in] H(div) mass matrix \param xh [out] solution vector \param b [in] right-hand-side vector \param TotalErrorResidual [out] error residual \param TotalErrorExactSol [out] error in xh */ void TestMultiLevelPreconditioner_DivLSFEM(char ProblemType[], Teuchos::ParameterList & MLList, Epetra_CrsMatrix & GradDiv, Epetra_CrsMatrix & D0clean, Epetra_CrsMatrix & D1clean, Epetra_CrsMatrix & FaceNode, Epetra_CrsMatrix & M1, Epetra_CrsMatrix & M1inv, Epetra_CrsMatrix & M2, Epetra_MultiVector & xh, Epetra_MultiVector & b, double & TotalErrorResidual, double & TotalErrorExactSol); /**********************************************************************************/ /******** FUNCTION DECLARATIONS FOR EXACT SOLUTION AND SOURCE TERMS ***************/ /**********************************************************************************/ /** \brief Exact solution evaluation. \param uExact0 [out] first component of exact solution at (x,y,z) \param uExact1 [out] second component of exact solution at (x,y,z) \param uExact2 [out] third component of exact solution at (x,y,z) \param x [in] x coordinate \param y [in] y coordinate \param z [in] z coordinate */ int evalu(double & uExact0, double & uExact1, double & uExact2, double & x, double & y, double & z); /** \brief Divergence of exact solution. \param x [in] x coordinate \param y [in] y coordinate \param z [in] z coordinate \return Value of the divergence of exact solution at (x,y,z) */ double evalDivu(double & x, double & y, double & z); /** \brief Curl of exact solution. \param curlu0 [out] first component of curl of exact solution \param curlu1 [out] second component of curl of exact solution \param curlu2 [out] third component of curl of exact solution \param x [in] x coordinate \param y [in] y coordinate \param z [in] z coordinate \param mu [in] material parameter */ int evalCurlu(double & curlu0, double & curlu1, double & curlu2, double & x, double & y, double & z, double & mu); /** \brief Curl of curl of exact solution. \param curlCurlu0 [out] first component of curl curl of exact solution \param curlCurlu1 [out] second component of curl curl of exact solution \param curlCurlu2 [out] third component of curl curl of exact solution \param x [in] x coordinate \param y [in] y coordinate \param z [in] z coordinate \param mu [in] material parameter */ int evalCurlCurlu(double & curlCurlu0, double & curlCurlu1, double & curlCurlu2, double & x, double & y, double & z, double & mu); /**********************************************************************************/ /**********************************************************************************/ /**********************************************************************************/ /**********************************************************************************/ /******************************** MAIN ********************************************/ /**********************************************************************************/ int main(int argc, char *argv[]) { int error = 0; #ifdef HAVE_MPI Teuchos::GlobalMPISession mpiSession(&argc, &argv,0); int rank=mpiSession.getRank(); int numProcs=mpiSession.getNProc(); Epetra_MpiComm Comm(MPI_COMM_WORLD); int MyPID = Comm.MyPID(); #else int rank=0; int numProcs=1; int MyPID = 0; Epetra_SerialComm Comm; #endif Epetra_Time Time(Comm); //Check number of arguments if (argc > 2) { std::cout <<"\n>>> ERROR: Invalid number of arguments.\n\n"; std::cout <<"Usage:\n\n"; std::cout <<" ./TrilinosCouplings_examples_scaling_Example_DivLSFEM.exe [inputfile.xml] \n\n"; std::cout <<" inputfile.xml(optional) - xml file with description of Pamgen mesh \n"; std::cout <<" and material parameters for each block \nn"; exit(1); } if (MyPID == 0) { std::cout \ << "===============================================================================\n" \ << "| |\n" \ << "| Example: Div-Curl System on Hexahedral Mesh |\n" \ << "| |\n" \ << "| Questions? Contact Pavel Bochev (pbboche@sandia.gov), |\n" \ << "| Denis Ridzal (dridzal@sandia.gov), |\n" \ << "| Kara Peterson (kjpeter@sandia.gov). |\n" \ << "| |\n" \ << "| Intrepid's website: http://trilinos.sandia.gov/packages/intrepid |\n" \ << "| Pamgen's website: http://trilinos.sandia.gov/packages/pamgen |\n" \ << "| ML's website: http://trilinos.sandia.gov/packages/ml |\n" \ << "| Trilinos website: http://trilinos.sandia.gov |\n" \ << "| |\n" \ << "===============================================================================\n"; } long long * node_comm_proc_ids = NULL; long long * node_cmap_node_cnts = NULL; long long * node_cmap_ids = NULL; long long ** comm_node_ids = NULL; long long ** comm_node_proc_ids = NULL; std::set < topo_entity * , fecomp > edge_set; std::set < topo_entity * , fecomp > face_set; std::vector < topo_entity * > edge_vector; std::vector < topo_entity * > face_vector; std::vector < int > edge_comm_procs; int dim = 3; /**********************************************************************************/ /********************************** GET XML INPUTS ********************************/ /**********************************************************************************/ // Command line for xml file, otherwise use default std::string xmlInFileName; if(argc>=2) xmlInFileName=string(argv[1]); else xmlInFileName="DivLSFEMin.xml"; // Read xml file into parameter list Teuchos::ParameterList inputList; if(xmlInFileName.length()) { if (MyPID == 0) { std::cout << "\nReading parameter list from the XML file \""<(inputList,"meshInput"); /**********************************************************************************/ /***************************** GET CELL TOPOLOGY **********************************/ /**********************************************************************************/ // Get cell topology for base hexahedron typedef shards::CellTopology CellTopology; CellTopology cellType(shards::getCellTopologyData >() ); // Get dimensions int numNodesPerElem = cellType.getNodeCount(); int numEdgesPerElem = cellType.getEdgeCount(); int numFacesPerElem = cellType.getSideCount(); int numNodesPerEdge = 2; int numNodesPerFace = 4; int numEdgesPerFace = 4; int spaceDim = cellType.getDimension(); // Build reference element edge to node map FieldContainer refEdgeToNode(numEdgesPerElem,numNodesPerEdge); for (int i=0; i refFaceToNode(numFacesPerElem,numNodesPerFace); for (int i=0; i refFaceToEdge(numFacesPerElem,numEdgesPerFace); refFaceToEdge(0,0)=0; refFaceToEdge(0,1)=9; refFaceToEdge(0,2)=4; refFaceToEdge(0,3)=8; refFaceToEdge(1,0)=1; refFaceToEdge(1,1)=10; refFaceToEdge(1,2)=5; refFaceToEdge(1,3)=9; refFaceToEdge(2,0)=2; refFaceToEdge(2,1)=11; refFaceToEdge(2,2)=6; refFaceToEdge(2,3)=10; refFaceToEdge(3,0)=8; refFaceToEdge(3,1)=7; refFaceToEdge(3,2)=11; refFaceToEdge(3,3)=3; refFaceToEdge(4,0)=3; refFaceToEdge(4,1)=2; refFaceToEdge(4,2)=1; refFaceToEdge(4,3)=0; refFaceToEdge(5,0)=4; refFaceToEdge(5,1)=5; refFaceToEdge(5,2)=6; refFaceToEdge(5,3)=7; /**********************************************************************************/ /******************************* GENERATE MESH ************************************/ /**********************************************************************************/ // Generate mesh with Pamgen long long maxInt = 9223372036854775807LL; long long cr_result = Create_Pamgen_Mesh(meshInput.c_str(), dim, rank, numProcs, maxInt); TrilinosCouplings::pamgen_error_check(std::cout,cr_result); // Get local mesh size info char title[100]; long long numDim; long long numNodes; long long numElems; long long numElemBlk; long long numNodeSets; long long numSideSets; int id = 0; im_ex_get_init_l(id, title, &numDim, &numNodes, &numElems, &numElemBlk, &numNodeSets, &numSideSets); // Get global mesh size info long long numNodesGlobal; long long numElemsGlobal; long long numElemBlkGlobal; long long numNodeSetsGlobal; long long numSideSetsGlobal; im_ne_get_init_global_l(id, &numNodesGlobal, &numElemsGlobal, &numElemBlkGlobal, &numNodeSetsGlobal, &numSideSetsGlobal); long long * block_ids = new long long [numElemBlk]; error += im_ex_get_elem_blk_ids_l(id, block_ids); long long *nodes_per_element = new long long [numElemBlk]; long long *element_attributes = new long long [numElemBlk]; long long *elements = new long long [numElemBlk]; char **element_types = new char * [numElemBlk]; long long **elmt_node_linkage = new long long * [numElemBlk]; for(long long i = 0; i < numElemBlk; i ++){ element_types[i] = new char [MAX_STR_LENGTH + 1]; error += im_ex_get_elem_block_l(id, block_ids[i], element_types[i], (long long*)&(elements[i]), (long long*)&(nodes_per_element[i]), (long long*)&(element_attributes[i])); } /*connectivity*/ for(long long b = 0; b < numElemBlk; b++){ elmt_node_linkage[b] = new long long [nodes_per_element[b]*elements[b]]; error += im_ex_get_elem_conn_l(id,block_ids[b],elmt_node_linkage[b]); } // Get mu value for each block of elements from parameter list double *mu = new double [numElemBlk]; for(int b = 0; b < numElemBlk; b++){ stringstream muBlock; muBlock.clear(); muBlock << "mu" << b; mu[b] = inputList.get(muBlock.str(),1.0); } // Get node-element connectivity and set element mu value int telct = 0; FieldContainer elemToNode(numElems,numNodesPerElem); FieldContainer muVal(numElems); for(long long b = 0; b < numElemBlk; b++){ for(long long el = 0; el < elements[b]; el++){ for (int j=0; j nodeCoord(numNodes,dim); double * nodeCoordx = new double [numNodes]; double * nodeCoordy = new double [numNodes]; double * nodeCoordz = new double [numNodes]; im_ex_get_coord_l(id,nodeCoordx,nodeCoordy,nodeCoordz); for (int i=0; i 0){ node_comm_proc_ids = new long long [num_node_comm_maps]; node_cmap_node_cnts = new long long [num_node_comm_maps]; node_cmap_ids = new long long [num_node_comm_maps]; comm_node_ids = new long long* [num_node_comm_maps]; comm_node_proc_ids = new long long* [num_node_comm_maps]; long long * elem_cmap_ids = new long long [num_elem_comm_maps]; long long * elem_cmap_elem_cnts = new long long [num_elem_comm_maps]; if ( im_ne_get_cmap_params_l( id, node_cmap_ids, (long long*)node_cmap_node_cnts, elem_cmap_ids, (long long*)elem_cmap_elem_cnts, 0/*not used proc_id*/ ) < 0 )++error; for(long long j = 0; j < num_node_comm_maps; j++) { comm_node_ids[j] = new long long [node_cmap_node_cnts[j]]; comm_node_proc_ids[j] = new long long [node_cmap_node_cnts[j]]; if ( im_ne_get_node_cmap_l( id, node_cmap_ids[j], comm_node_ids[j], comm_node_proc_ids[j], 0/*not used proc_id*/ ) < 0 )++error; node_comm_proc_ids[j] = comm_node_proc_ids[j][0]; } } //Calculate global node ids long long * globalNodeIds = new long long[numNodes]; bool * nodeIsOwned = new bool[numNodes]; calc_global_node_ids(globalNodeIds, nodeIsOwned, numNodes, num_node_comm_maps, node_cmap_node_cnts, node_comm_proc_ids, comm_node_ids, rank); // Count owned nodes int ownedNodes=0; for(int i=0;i elemToEdge(numElems,numEdgesPerElem); FieldContainer elemToFace(numElems,numFacesPerElem); // calculate edge and face ids int elct = 0; for(long long b = 0; b < numElemBlk; b++){ if(nodes_per_element[b] == 4){ } else if (nodes_per_element[b] == 8){ //loop over all elements and push their edges onto a set if they are not there already for(long long el = 0; el < elements[b]; el++){ std::set< topo_entity *, fecomp > ::iterator fit; for (int i=0; i < numEdgesPerElem; i++){ topo_entity * teof = new topo_entity; for(int j = 0; j < numNodesPerEdge;j++){ teof->add_node(elmt_node_linkage[b][el*numNodesPerElem + refEdgeToNode(i,j)],globalNodeIds); } teof->sort(); fit = edge_set.find(teof); if(fit == edge_set.end()){ teof->local_id = edge_vector.size(); edge_set.insert(teof); elemToEdge(elct,i)= edge_vector.size(); edge_vector.push_back(teof); } else{ elemToEdge(elct,i) = (*fit)->local_id; delete teof; } } for (int i=0; i < numFacesPerElem; i++){ topo_entity * teof = new topo_entity; for(int j = 0; j < numNodesPerFace;j++){ teof->add_node(elmt_node_linkage[b][el*numNodesPerElem + refFaceToNode(i,j)],globalNodeIds); } teof->sort(); fit = face_set.find(teof); if(fit == face_set.end()){ teof->local_id = face_vector.size(); face_set.insert(teof); elemToFace(elct,i)= face_vector.size(); face_vector.push_back(teof); } else{ elemToFace(elct,i) = (*fit)->local_id; delete teof; } } elct ++; } } } // Edge to Node connectivity FieldContainer edgeToNode(edge_vector.size(), numNodesPerEdge); for(unsigned ect = 0; ect != edge_vector.size(); ect++){ std::list::iterator elit; int nct = 0; for(elit = edge_vector[ect]->local_node_ids.begin(); elit != edge_vector[ect]->local_node_ids.end(); elit ++){ edgeToNode(ect,nct) = *elit-1; nct++; } } // Face to Node connectivity FieldContainer faceToNode(face_vector.size(), numNodesPerFace); for(unsigned fct = 0; fct != face_vector.size(); fct++){ std::list::iterator flit; int nct = 0; for(flit = face_vector[fct]->local_node_ids.begin(); flit != face_vector[fct]->local_node_ids.end(); flit ++){ faceToNode(fct,nct) = *flit-1; nct++; } } // Face to Edge connectivity FieldContainer faceToEdge(face_vector.size(), numEdgesPerFace); FieldContainer faceDone(face_vector.size()); for (int ielem = 0; ielem < numElems; ielem++){ for (int iface = 0; iface < numFacesPerElem; iface++){ if (!faceDone(elemToFace(ielem,iface))){ for (int iedge = 0; iedge < numEdgesPerFace; iedge++){ faceToEdge(elemToFace(ielem,iface),iedge) = elemToEdge(ielem,refFaceToEdge(iface,iedge)); faceDone(elemToFace(ielem,iface))=1; } } } } int numEdges = edge_vector.size(); int numFaces = face_vector.size(); // Calculate global edge and face numbering std::string doing_type; doing_type = "EDGES"; calc_global_ids(edge_vector, comm_node_ids, node_comm_proc_ids, node_cmap_node_cnts, num_node_comm_maps, rank, doing_type); doing_type = "FACES"; calc_global_ids(face_vector, comm_node_ids, node_comm_proc_ids, node_cmap_node_cnts, num_node_comm_maps, rank, doing_type); // Build list of owned global edge ids long long * globalEdgeIds = new long long[numEdges]; bool * edgeIsOwned = new bool[numEdges]; int numOwnedEdges=0; for (int i=0; iowned; globalEdgeIds[i] = edge_vector[i]->global_id; if (edgeIsOwned[i]){ numOwnedEdges++; } } int * ownedEdgeIds = new int[numOwnedEdges]; int nedge=0; for (int i=0; iowned; globalFaceIds[i] = face_vector[i]->global_id; if (faceIsOwned[i]){ numOwnedFaces++; } } int * ownedFaceIds = new int[numOwnedFaces]; int nface=0; for (int i=0; i edgeOnBoundary(numEdges); FieldContainer faceOnBoundary(numFaces); // Get boundary (side set) information long long * sideSetIds = new long long [numSideSets]; long long numSidesInSet; long long numDFinSet; int numBndyFaces=0; im_ex_get_side_set_ids_l(id,sideSetIds); for (int i=0; i 0){ long long * sideSetElemList = new long long [numSidesInSet]; long long * sideSetSideList = new long long [numSidesInSet]; im_ex_get_side_set_l(id,sideSetIds[i],sideSetElemList,sideSetSideList); for (int j=0; j nodeOnBoundary(numNodes); for (int i=0; i cubFactory; int cubDegree = 2; Teuchos::RCP > hexCub = cubFactory.create(cellType, cubDegree); int cubDim = hexCub->getDimension(); int numCubPoints = hexCub->getNumPoints(); FieldContainer cubPoints(numCubPoints, cubDim); FieldContainer cubWeights(numCubPoints); hexCub->getCubature(cubPoints, cubWeights); /**********************************************************************************/ /* Get numerical integration points and weights for hexahedron face */ /* (needed for rhs boundary term) */ /**********************************************************************************/ // Define topology of the face parametrization domain as [-1,1]x[-1,1] CellTopology paramQuadFace(shards::getCellTopologyData >() ); // Define cubature DefaultCubatureFactory cubFactoryFace; Teuchos::RCP > hexFaceCubature = cubFactoryFace.create(paramQuadFace, 3); int cubFaceDim = hexFaceCubature -> getDimension(); int numFacePoints = hexFaceCubature -> getNumPoints(); // Define storage for cubature points and weights on [-1,1]x[-1,1] FieldContainer paramFaceWeights(numFacePoints); FieldContainer paramFacePoints(numFacePoints,cubFaceDim); // Define storage for cubature points on workset faces hexFaceCubature -> getCubature(paramFacePoints, paramFaceWeights); if(MyPID==0) {std::cout << "Getting cubature " << Time.ElapsedTime() << " sec \n" ; Time.ResetStartTime();} /**********************************************************************************/ /*********************************** GET BASIS ************************************/ /**********************************************************************************/ // Define basis Basis_HCURL_HEX_I1_FEM > hexHCurlBasis; Basis_HDIV_HEX_I1_FEM > hexHDivBasis; Basis_HGRAD_HEX_C1_FEM > hexHGradBasis; int numFieldsC = hexHCurlBasis.getCardinality(); int numFieldsD = hexHDivBasis.getCardinality(); int numFieldsG = hexHGradBasis.getCardinality(); // Evaluate basis at cubature points FieldContainer HCVals(numFieldsC, numCubPoints, spaceDim); FieldContainer HDVals(numFieldsD, numCubPoints, spaceDim); FieldContainer HDivs(numFieldsD, numCubPoints); FieldContainer HGVals(numFieldsG, numCubPoints); hexHCurlBasis.getValues(HCVals, cubPoints, OPERATOR_VALUE); hexHDivBasis.getValues(HDVals, cubPoints, OPERATOR_VALUE); hexHDivBasis.getValues(HDivs, cubPoints, OPERATOR_DIV); hexHGradBasis.getValues(HGVals, cubPoints, OPERATOR_VALUE); /**********************************************************************************/ /********************* BUILD MAPS FOR GLOBAL SOLUTION *****************************/ /**********************************************************************************/ // Define global epetra maps Epetra_Map globalMapG(-1,ownedNodes,ownedGIDs,0,Comm); Epetra_Map globalMapC(-1,numOwnedEdges,ownedEdgeIds,0,Comm); Epetra_Map globalMapD(-1,numOwnedFaces,ownedFaceIds,0,Comm); // Global arrays in Epetra format Epetra_FECrsMatrix MassMatrixC(Copy, globalMapC, numFieldsC); Epetra_FECrsMatrix MassMatrixD(Copy, globalMapD, numFieldsD); Epetra_FECrsMatrix MassMatrixG(Copy, globalMapG, numFieldsG); Epetra_FECrsMatrix StiffMatrixD(Copy, globalMapD, numFieldsD); Epetra_FEVector rhsVector(globalMapD); if(MyPID==0) {std::cout << "Build global maps " << Time.ElapsedTime() << " sec \n"; Time.ResetStartTime();} /**********************************************************************************/ /************************** OUTPUT CONNECTIVITY (FOR PLOTTING) ********************/ /**********************************************************************************/ // Build the coordinate vectors for ML solver (including owned nodes only) Epetra_Vector Nx(globalMapG), Ny(globalMapG),Nz(globalMapG); for(int i=0,nlid=0;i faceDone2(numFaces); for (int i=0; i= numEdgesPerFace) indm=0; if (edgeToNode(faceToEdge(iface,m),1) == edgeToNode(faceToEdge(iface,indm),0) || edgeToNode(faceToEdge(iface,m),1) == edgeToNode(faceToEdge(iface,indm),1)){ vals[m]=1.0;} else vals[m]=-1.0; // This is a convoluted way to account for edge orientations that // may be incorrect on the local processor because the edge is // not owned by the local processor. int edgeIndex = -1; if (!edgeIsOwned[faceToEdge(iface,m)]){ for (int l=0; l 3 && faceIsOwned[elemToFace(i,5)]){ vals[m]=-1.0*vals[m]; } } } // end loop over face edges DCurl.InsertGlobalValues(1, &rowNum, 4, colNum, vals); faceDone2(iface)=1; } // end if face is owned and face not done } // end loop over element faces } // end loop over elements DGrad.GlobalAssemble(globalMapG,globalMapC); DGrad.FillComplete(MassMatrixG.RowMap(),MassMatrixC.RowMap()); DCurl.GlobalAssemble(globalMapC,globalMapD); DCurl.FillComplete(MassMatrixC.RowMap(),MassMatrixD.RowMap()); if(MyPID==0) {std::cout << "Building incidence matrices " << Time.ElapsedTime() << " sec \n" ; Time.ResetStartTime();} /**********************************************************************************/ /******************** INHOMOGENEOUS BOUNDARY CONDITIONS ***************************/ /**********************************************************************************/ FieldContainer bndyFaceVal(numBndyFaces); FieldContainer bndyFaceToFace(numFaces); FieldContainer refFacePoints(numFacePoints,spaceDim); FieldContainer bndyFacePoints(1,numFacePoints,spaceDim); FieldContainer bndyFaceJacobians(1,numFacePoints,spaceDim,spaceDim); FieldContainer faceNorm(1,numFacePoints,spaceDim); FieldContainer uDotNormal(1,numFacePoints); FieldContainer uFace(numFacePoints,spaceDim); FieldContainer nodes(1, numNodesPerElem, spaceDim); int ibface=0; // Evaluate normal at face quadrature points for (int ielem=0; ielem cellWorkset(worksetSize, numNodesPerElem, spaceDim); FieldContainer worksetEdgeSigns(worksetSize, numEdgesPerElem); FieldContainer worksetFaceSigns(worksetSize, numFacesPerElem); // Copy coordinates into cell workset int cellCounter = 0; for(int cell = worksetBegin; cell < worksetEnd; cell++){ // Physical cell coordinates for (int inode=0; inode= numNodesPerFace) indf=0; if (elemToNode(cell,refFaceToNode(iface,0))==faceToNode(elemToFace(cell,iface),i) && elemToNode(cell,refFaceToNode(iface,1))==faceToNode(elemToFace(cell,iface),indf)) worksetFaceSigns(cellCounter,iface) = 1.0; } if (!faceIsOwned[elemToFace(cell,iface)]){ worksetFaceSigns(cellCounter,iface)=-1.0*worksetFaceSigns(cellCounter,iface); } } #ifdef DUMP_DATA for (int iface=0; iface worksetJacobian (worksetSize, numCubPoints, spaceDim, spaceDim); FieldContainer worksetJacobInv (worksetSize, numCubPoints, spaceDim, spaceDim); FieldContainer worksetJacobDet (worksetSize, numCubPoints); // Container for cubature points in physical space FieldContainer worksetCubPoints (worksetSize,numCubPoints, cubDim); // Containers for element HCURL mass matrix FieldContainer massMatrixHCurl (worksetSize, numFieldsC, numFieldsC); FieldContainer weightedMeasure (worksetSize, numCubPoints); FieldContainer weightedMeasureMu (worksetSize, numCubPoints); FieldContainer HCValsTransformed (worksetSize, numFieldsC, numCubPoints, spaceDim); FieldContainer HCValsTransformedWeighted (worksetSize, numFieldsC, numCubPoints, spaceDim); // Containers for element HDIV mass matrix FieldContainer massMatrixHDiv (worksetSize, numFieldsD, numFieldsD); FieldContainer HDValsTransformed (worksetSize, numFieldsD, numCubPoints, spaceDim); FieldContainer HDValsTransformedWeighted (worksetSize, numFieldsD, numCubPoints, spaceDim); // Containers for element HDIV stiffness matrix FieldContainer stiffMatrixHDiv (worksetSize, numFieldsD, numFieldsD); FieldContainer HDivsTransformed (worksetSize, numFieldsD, numCubPoints); FieldContainer HDivsTransformedWeighted (worksetSize, numFieldsD, numCubPoints); // Containers for element HGRAD mass matrix FieldContainer massMatrixHGrad (worksetSize, numFieldsG, numFieldsG); FieldContainer HGValsTransformed (worksetSize, numFieldsG, numCubPoints); FieldContainer HGValsTransformedWeighted (worksetSize, numFieldsG, numCubPoints); // Containers for right hand side vectors FieldContainer rhsDatag (worksetSize, numCubPoints, cubDim); FieldContainer rhsDatah (worksetSize, numCubPoints); FieldContainer gD (worksetSize, numFieldsD); FieldContainer hD (worksetSize, numFieldsD); // Containers for right hand side boundary term FieldContainer gDBoundary (1, numFieldsD); FieldContainer refFacePoints (numFacePoints,spaceDim); FieldContainer cellNodes (1, numNodesPerElem, spaceDim); FieldContainer worksetFacePoints (1, numFacePoints, spaceDim); FieldContainer faceJacobians (1, numFacePoints, spaceDim, spaceDim); FieldContainer faceJacobInv (1, numFacePoints, spaceDim, spaceDim); FieldContainer faceJacobDet (1, numFacePoints); FieldContainer faceNormal (1, numFacePoints, spaceDim); FieldContainer bcFaceDVals (numFieldsD, numFacePoints, spaceDim); FieldContainer bcDValsTransformed (1, numFieldsD, numFacePoints, spaceDim); FieldContainer curluFace (1, numFacePoints, spaceDim); FieldContainer bcDataCrossField (1, numFieldsD, numFacePoints, spaceDim); FieldContainer bcFaceSigns (1, numFieldsD); /**********************************************************************************/ /* Calculate Jacobians */ /**********************************************************************************/ IntrepidCTools::setJacobian (worksetJacobian, cubPoints, cellWorkset, cellType); IntrepidCTools::setJacobianInv(worksetJacobInv, worksetJacobian ); IntrepidCTools::setJacobianDet(worksetJacobDet, worksetJacobian ); if(MyPID==0) {std::cout << "Calculate Jacobians " << Time.ElapsedTime() << " sec \n"; Time.ResetStartTime();} /**********************************************************************************/ /* Compute HCURL Mass Matrix */ /**********************************************************************************/ // transform to physical coordinates IntrepidFSTools::HCURLtransformVALUE(HCValsTransformed, worksetJacobInv, HCVals); // compute weighted measure IntrepidFSTools::computeCellMeasure(weightedMeasure, worksetJacobDet, cubWeights); // combine mu value with weighted measure cellCounter = 0; for(int cell = worksetBegin; cell < worksetEnd; cell++){ for (int nPt = 0; nPt < numCubPoints; nPt++){ weightedMeasureMu(cellCounter,nPt) = weightedMeasure(cellCounter,nPt) * muVal(cell); } cellCounter++; } // multiply by weighted measure IntrepidFSTools::multiplyMeasure(HCValsTransformedWeighted, weightedMeasureMu, HCValsTransformed); // integrate to compute element mass matrix IntrepidFSTools::integrate(massMatrixHCurl, HCValsTransformed, HCValsTransformedWeighted, COMP_BLAS); // apply edge signs IntrepidFSTools::applyLeftFieldSigns(massMatrixHCurl, worksetEdgeSigns); IntrepidFSTools::applyRightFieldSigns(massMatrixHCurl, worksetEdgeSigns); if(MyPID==0) {std::cout << "Compute HCURL Mass Matrix " << Time.ElapsedTime() << " sec \n"; Time.ResetStartTime();} /**********************************************************************************/ /* Compute HDiv Mass Matrix */ /**********************************************************************************/ // transform to physical coordinates IntrepidFSTools::HDIVtransformVALUE(HDValsTransformed, worksetJacobian, worksetJacobDet, HDVals); // multiply by weighted measure IntrepidFSTools::multiplyMeasure(HDValsTransformedWeighted, weightedMeasure, HDValsTransformed); // integrate to compute element mass matrix IntrepidFSTools::integrate(massMatrixHDiv, HDValsTransformed, HDValsTransformedWeighted, COMP_BLAS); // apply face signs IntrepidFSTools::applyLeftFieldSigns(massMatrixHDiv, worksetFaceSigns); IntrepidFSTools::applyRightFieldSigns(massMatrixHDiv, worksetFaceSigns); if(MyPID==0) {std::cout << "Compute HDIV Mass Matrix " << Time.ElapsedTime() << " sec \n"; Time.ResetStartTime();} /**********************************************************************************/ /* Compute HDiv Stiffness Matrix */ /**********************************************************************************/ // transform to physical coordinates IntrepidFSTools::HDIVtransformDIV(HDivsTransformed, worksetJacobDet, HDivs); // multiply by weighted measure IntrepidFSTools::multiplyMeasure(HDivsTransformedWeighted, weightedMeasure, HDivsTransformed); // integrate to compute element stiffness matrix IntrepidFSTools::integrate(stiffMatrixHDiv, HDivsTransformed, HDivsTransformedWeighted, COMP_BLAS); // apply face signs IntrepidFSTools::applyLeftFieldSigns(stiffMatrixHDiv, worksetFaceSigns); IntrepidFSTools::applyRightFieldSigns(stiffMatrixHDiv, worksetFaceSigns); if(MyPID==0) {std::cout << "Compute HDiv Stiffness Matrix " << Time.ElapsedTime() << " sec \n"; Time.ResetStartTime();} /**********************************************************************************/ /* Compute HGrad Mass Matrix */ /**********************************************************************************/ // transform to physical coordinates IntrepidFSTools::HGRADtransformVALUE(HGValsTransformed, HGVals); // multiply values with weighted measure IntrepidFSTools::multiplyMeasure(HGValsTransformedWeighted, weightedMeasure, HGValsTransformed); // integrate to compute element mass matrix IntrepidFSTools::integrate(massMatrixHGrad, HGValsTransformed, HGValsTransformedWeighted, COMP_BLAS); if(MyPID==0) {std::cout << "Compute HGRAD Mass Matrix " << Time.ElapsedTime() << " sec \n"; Time.ResetStartTime();} /**********************************************************************************/ /* Build Right Hand Side */ /**********************************************************************************/ // transform integration points to physical points IntrepidCTools::mapToPhysicalFrame(worksetCubPoints, cubPoints, cellWorkset, cellType); // evaluate right hand side functions at physical points for(int cell = worksetBegin; cell < worksetEnd; cell++){ // Compute cell ordinal relative to the current workset int worksetCellOrdinal = cell - worksetBegin; for (int nPt = 0; nPt < numCubPoints; nPt++){ double x = worksetCubPoints(worksetCellOrdinal,nPt,0); double y = worksetCubPoints(worksetCellOrdinal,nPt,1); double z = worksetCubPoints(worksetCellOrdinal,nPt,2); double du1, du2, du3; evalCurlCurlu(du1, du2, du3, x, y, z, muVal(cell)); rhsDatag(worksetCellOrdinal,nPt,0) = du1; rhsDatag(worksetCellOrdinal,nPt,1) = du2; rhsDatag(worksetCellOrdinal,nPt,2) = du3; rhsDatah(worksetCellOrdinal,nPt) = evalDivu(x, y, z); } } // end workset cell loop // integrate (g,curl w) term IntrepidFSTools::integrate(gD, rhsDatag, HDValsTransformedWeighted, COMP_BLAS); // integrate (h,div w) term IntrepidFSTools::integrate(hD, rhsDatah, HDivsTransformedWeighted, COMP_BLAS); // apply signs IntrepidFSTools::applyFieldSigns(gD, worksetFaceSigns); IntrepidFSTools::applyFieldSigns(hD, worksetFaceSigns); // calculate RHS boundary term for(int cell = worksetBegin; cell < worksetEnd; cell++){ // Compute cell ordinal relative to the current workset int worksetCellOrdinal = cell - worksetBegin; // evaluate boundary term for (int iface = 0; iface < numFacesPerElem; iface++){ if (faceOnBoundary(elemToFace(cell,iface))){ // cell nodal coordinates for (int inode =0; inode < numNodesPerElem; inode++){ cellNodes(0,inode,0) = cellWorkset(worksetCellOrdinal,inode,0); cellNodes(0,inode,1) = cellWorkset(worksetCellOrdinal,inode,1); cellNodes(0,inode,2) = cellWorkset(worksetCellOrdinal,inode,2); } // cell face signs for (int jface =0; jface < numFacesPerElem; jface++){ bcFaceSigns(0,jface) = worksetFaceSigns(worksetCellOrdinal,jface); } // map Gauss points on quad to reference face: paramFacePoints -> refFacePoints IntrepidCTools::mapToReferenceSubcell(refFacePoints, paramFacePoints, 2, iface, cellType); // get basis values at points on reference cell hexHDivBasis.getValues(bcFaceDVals, refFacePoints, OPERATOR_VALUE); // compute Jacobians at Gauss pts. on reference face for all parent cells IntrepidCTools::setJacobian(faceJacobians, refFacePoints, cellNodes, cellType); IntrepidCTools::setJacobianDet(faceJacobDet, faceJacobians); // transform to physical coordinates IntrepidFSTools::HDIVtransformVALUE(bcDValsTransformed, faceJacobians, faceJacobDet, bcFaceDVals); // map Gauss points on quad from ref. face to face workset: refFacePoints -> worksetFacePoints IntrepidCTools::mapToPhysicalFrame(worksetFacePoints, refFacePoints, cellNodes, cellType); // Compute face normals IntrepidCTools::getPhysicalFaceNormals(faceNormal, faceJacobians, iface, cellType); // evaluate curl u at face points for(int nPt = 0; nPt < numFacePoints; nPt++){ double x = worksetFacePoints(0, nPt, 0); double y = worksetFacePoints(0, nPt, 1); double z = worksetFacePoints(0, nPt, 2); evalCurlu(curluFace(0,nPt,0), curluFace(0,nPt,1), curluFace(0,nPt,2), x, y, z, muVal(cell)); } // compute the cross product of curluFace with basis and multiply by weights for (int nF = 0; nF < numFieldsD; nF++){ for(int nPt = 0; nPt < numFacePoints; nPt++){ bcDataCrossField(0,nF,nPt,0) = (curluFace(0,nPt,1)*bcDValsTransformed(0,nF,nPt,2) - curluFace(0,nPt,2)*bcDValsTransformed(0,nF,nPt,1)) * paramFaceWeights(nPt); bcDataCrossField(0,nF,nPt,1) = (curluFace(0,nPt,2)*bcDValsTransformed(0,nF,nPt,0) - curluFace(0,nPt,0)*bcDValsTransformed(0,nF,nPt,2)) * paramFaceWeights(nPt); bcDataCrossField(0,nF,nPt,2) = (curluFace(0,nPt,0)*bcDValsTransformed(0,nF,nPt,1) - curluFace(0,nPt,1)*bcDValsTransformed(0,nF,nPt,0)) *paramFaceWeights(nPt); } //nPt } //nF // integrate IntrepidFSTools::integrate(gDBoundary, faceNormal, bcDataCrossField, COMP_CPP); // apply signs IntrepidFSTools::applyFieldSigns(gDBoundary, bcFaceSigns); // add into gD term for (int nF = 0; nF < numFieldsD; nF++){ gD(worksetCellOrdinal,nF) = gD(worksetCellOrdinal,nF) - gDBoundary(0,nF); } } // if faceOnBoundary } // numFaces }// *** workset cell loop ** if(MyPID==0) {std::cout << "Compute right-hand side " << Time.ElapsedTime() << " sec \n"; Time.ResetStartTime();} /**********************************************************************************/ /* Assemble into Global Matrix */ /**********************************************************************************/ // Loop over workset cells for(int cell = worksetBegin; cell < worksetEnd; cell++){ // Compute cell ordinal relative to the current workset int worksetCellOrdinal = cell - worksetBegin; /*** Assemble H(grad) mass matrix ***/ // loop over nodes for matrix row for (int cellNodeRow = 0; cellNodeRow < numFieldsG; cellNodeRow++){ int localNodeRow = elemToNode(cell, cellNodeRow); int globalNodeRow = globalNodeIds[localNodeRow]; // loop over nodes for matrix column for (int cellNodeCol = 0; cellNodeCol < numFieldsG; cellNodeCol++){ int localNodeCol = elemToNode(cell, cellNodeCol); int globalNodeCol = globalNodeIds[localNodeCol]; double massGContribution = massMatrixHGrad(worksetCellOrdinal, cellNodeRow, cellNodeCol); MassMatrixG.InsertGlobalValues(1, &globalNodeRow, 1, &globalNodeCol, &massGContribution); }// *** cell node col loop *** }// *** cell node row loop *** /*** Assemble H(curl) mass matrix ***/ // loop over edges for matrix row for (int cellEdgeRow = 0; cellEdgeRow < numFieldsC; cellEdgeRow++){ int localEdgeRow = elemToEdge(cell, cellEdgeRow); int globalEdgeRow = globalEdgeIds[localEdgeRow]; // loop over edges for matrix column for (int cellEdgeCol = 0; cellEdgeCol < numFieldsC; cellEdgeCol++){ int localEdgeCol = elemToEdge(cell, cellEdgeCol); int globalEdgeCol = globalEdgeIds[localEdgeCol]; double massCContribution = massMatrixHCurl (worksetCellOrdinal, cellEdgeRow, cellEdgeCol); MassMatrixC.InsertGlobalValues (1, &globalEdgeRow, 1, &globalEdgeCol, &massCContribution); }// *** cell edge col loop *** }// *** cell edge row loop *** /*** Assemble H(div) mass matrix, stiffness matrix and right-hand side ***/ // loop over faces for matrix row for (int cellFaceRow = 0; cellFaceRow < numFieldsD; cellFaceRow++){ int localFaceRow = elemToFace(cell, cellFaceRow); int globalFaceRow = globalFaceIds[localFaceRow]; double rhsContribution = gD(worksetCellOrdinal, cellFaceRow) + hD(worksetCellOrdinal, cellFaceRow); rhsVector.SumIntoGlobalValues(1, &globalFaceRow, &rhsContribution); // loop over faces for matrix column for (int cellFaceCol = 0; cellFaceCol < numFieldsD; cellFaceCol++){ int localFaceCol = elemToFace(cell, cellFaceCol); int globalFaceCol = globalFaceIds[localFaceCol]; double massDContribution = massMatrixHDiv (worksetCellOrdinal, cellFaceRow, cellFaceCol); double stiffDContribution = stiffMatrixHDiv(worksetCellOrdinal, cellFaceRow, cellFaceCol); MassMatrixD.InsertGlobalValues (1, &globalFaceRow, 1, &globalFaceCol, &massDContribution); StiffMatrixD.InsertGlobalValues(1, &globalFaceRow, 1, &globalFaceCol, &stiffDContribution); }// *** cell face col loop *** }// *** cell face row loop *** }// *** workset cell loop ** }// *** workset loop *** if(MyPID==0) {std::cout << "Assemble Matrices " << Time.ElapsedTime() << " sec \n"; Time.ResetStartTime();} /**********************************************************************************/ /********************* ASSEMBLE OVER MULTIPLE PROCESSORS **************************/ /**********************************************************************************/ // Assemble over multiple processors, if necessary MassMatrixG.GlobalAssemble(); MassMatrixG.FillComplete(); MassMatrixC.GlobalAssemble(); MassMatrixC.FillComplete(); MassMatrixD.GlobalAssemble(); MassMatrixD.FillComplete(); StiffMatrixD.GlobalAssemble(); StiffMatrixD.FillComplete(); rhsVector.GlobalAssemble(); if(MyPID==0) {std::cout << "Global assembly " << Time.ElapsedTime() << " sec \n"; Time.ResetStartTime();} #ifdef DUMP_DATA // Node Coordinates EpetraExt::VectorToMatrixMarketFile("coordx.dat",Nx,0,0,false); EpetraExt::VectorToMatrixMarketFile("coordy.dat",Ny,0,0,false); EpetraExt::VectorToMatrixMarketFile("coordz.dat",Nz,0,0,false); // Edge signs EpetraExt::MultiVectorToMatrixMarketFile("edge_signs.dat",edgeSign,0,0,false); // Face signs EpetraExt::MultiVectorToMatrixMarketFile("face_signs.dat",faceSign,0,0,false); #endif /**********************************************************************************/ /*********************** ADJUST MATRICES AND RHS FOR BCs **************************/ /**********************************************************************************/ // Build the inverse diagonal for MassMatrixC // We do this by computing the absolute rowsum and inverting that. Epetra_CrsMatrix MassMatrixCinv(Copy,MassMatrixC.RowMap(),MassMatrixC.RowMap(),1); Epetra_Vector DiagC(MassMatrixC.RowMap()); Epetra_Vector temp(MassMatrixC.RowMap()); temp.PutScalar(1.0); Multiply_Abs(MassMatrixC,temp,DiagC); for(int i=0; i hexFaceSigns(numCells, numFieldsD); FieldContainer hexNodes(numCells, numFieldsG, spaceDim); // Get cubature points and weights for error calc (may be different from previous) DefaultCubatureFactory cubFactoryErr; int cubDegErr = 3; Teuchos::RCP > hexCubErr = cubFactoryErr.create(cellType, cubDegErr); int cubDimErr = hexCubErr->getDimension(); int numCubPointsErr = hexCubErr->getNumPoints(); FieldContainer cubPointsErr(numCubPointsErr, cubDimErr); FieldContainer cubWeightsErr(numCubPointsErr); hexCubErr->getCubature(cubPointsErr, cubWeightsErr); FieldContainer physCubPointsE(numCells,numCubPointsErr, cubDimErr); // Containers for Jacobian FieldContainer hexJacobianE(numCells, numCubPointsErr, spaceDim, spaceDim); FieldContainer hexJacobInvE(numCells, numCubPointsErr, spaceDim, spaceDim); FieldContainer hexJacobDetE(numCells, numCubPointsErr); FieldContainer weightedMeasureE(numCells, numCubPointsErr); // Evaluate basis values and curls at cubature points FieldContainer uhDVals(numFieldsD, numCubPointsErr, spaceDim); FieldContainer uhDValsTrans(numCells,numFieldsD, numCubPointsErr, spaceDim); FieldContainer uhDivs(numFieldsD, numCubPointsErr); FieldContainer uhDivsTrans(numCells, numFieldsD, numCubPointsErr); hexHDivBasis.getValues(uhDVals, cubPointsErr, OPERATOR_VALUE); hexHDivBasis.getValues(uhDivs, cubPointsErr, OPERATOR_DIV); // Loop over elements for (int k=0; k numNodesPerFace) indf=0; if (elemToNode(k,refFaceToNode(j,0))==faceToNode(elemToFace(k,j),i) && elemToNode(k,refFaceToNode(j,1))==faceToNode(elemToFace(k,j),indf)) hexFaceSigns(0,j) = 1.0; } if (!faceIsOwned[elemToFace(k,j)]){ hexFaceSigns(0,j)=-1.0*hexFaceSigns(0,j); } } // compute cell Jacobians, their inverses and their determinants IntrepidCTools::setJacobian(hexJacobianE, cubPointsErr, hexNodes, cellType); IntrepidCTools::setJacobianInv(hexJacobInvE, hexJacobianE ); IntrepidCTools::setJacobianDet(hexJacobDetE, hexJacobianE ); // transform integration points to physical points IntrepidCTools::mapToPhysicalFrame(physCubPointsE, cubPointsErr, hexNodes, cellType); // transform basis values to physical coordinates IntrepidFSTools::HDIVtransformVALUE(uhDValsTrans, hexJacobianE, hexJacobDetE, uhDVals); IntrepidFSTools::HDIVtransformDIV(uhDivsTrans, hexJacobDetE, uhDivs); // compute weighted measure IntrepidFSTools::computeCellMeasure(weightedMeasureE, hexJacobDetE, cubWeightsErr); // loop over cubature points for (int nPt = 0; nPt < numCubPointsErr; nPt++){ // get exact solution and divs double x = physCubPointsE(0,nPt,0); double y = physCubPointsE(0,nPt,1); double z = physCubPointsE(0,nPt,2); evalu(uExact1, uExact2, uExact3, x, y, z); divuExact = evalDivu(x, y, z); // calculate approximate solution and divs double uApprox1 = 0.0; double uApprox2 = 0.0; double uApprox3 = 0.0; double divuApprox = 0.0; for (int i = 0; i < numFieldsD; i++){ int rowIndex = globalFaceIds[elemToFace(k,i)]; #ifdef HAVE_MPI double uh1 = uCoeff.Values()[rowIndex]; #else double uh1 = xh.Values()[rowIndex]; #endif uApprox1 += uh1*uhDValsTrans(0,i,nPt,0)*hexFaceSigns(0,i); uApprox2 += uh1*uhDValsTrans(0,i,nPt,1)*hexFaceSigns(0,i); uApprox3 += uh1*uhDValsTrans(0,i,nPt,2)*hexFaceSigns(0,i); divuApprox += uh1*uhDivsTrans(0,i,nPt)*hexFaceSigns(0,i); } // evaluate the error at cubature points Linferr = max(Linferr, abs(uExact1 - uApprox1)); Linferr = max(Linferr, abs(uExact2 - uApprox2)); Linferr = max(Linferr, abs(uExact3 - uApprox3)); L2errElem+=(uExact1 - uApprox1)*(uExact1 - uApprox1)*weightedMeasureE(0,nPt); L2errElem+=(uExact2 - uApprox2)*(uExact2 - uApprox2)*weightedMeasureE(0,nPt); L2errElem+=(uExact3 - uApprox3)*(uExact3 - uApprox3)*weightedMeasureE(0,nPt); HDiverrElem+=((divuExact - divuApprox)*(divuExact - divuApprox)) *weightedMeasureE(0,nPt); } L2err+=L2errElem; HDiverr+=HDiverrElem; } #ifdef HAVE_MPI // sum over all processors Comm.SumAll(&L2err,&L2errTot,1); Comm.SumAll(&HDiverr,&HDiverrTot,1); Comm.MaxAll(&Linferr,&LinferrTot,1); #else L2errTot = L2err; HDiverrTot = HDiverr; LinferrTot = Linferr; #endif if (MyPID == 0) { std::cout << "\n" << "L2 Error: " << sqrt(L2errTot) <<"\n"; std::cout << "HDiv Error: " << sqrt(HDiverrTot) <<"\n"; std::cout << "LInf Error: " << LinferrTot <<"\n\n"; } // delete mesh Delete_Pamgen_Mesh(); //clean up for(long long b = 0; b < numElemBlk; b++){ delete [] elmt_node_linkage[b]; delete [] element_types[b]; } delete [] block_ids; delete [] nodes_per_element; delete [] element_attributes; delete [] element_types; delete [] elmt_node_linkage; delete [] elements; delete [] nodeCoordx; delete [] nodeCoordy; delete [] nodeCoordz; delete [] globalNodeIds; delete [] nodeIsOwned; delete [] globalEdgeIds; delete [] edgeIsOwned; delete [] globalFaceIds; delete [] faceIsOwned; if(num_node_comm_maps > 0){ delete [] node_comm_proc_ids; delete [] node_cmap_node_cnts; delete [] node_cmap_ids; for(long long i=0;iValues(); } else if (Importer_) ImportVector_ = new Epetra_Vector(Importer_->TargetMap()); else if (Exporter_) ExportVector_ = new Epetra_Vector(Exporter_->SourceMap()); // If we have a non-trivial importer, we must import elements that are permuted or are on other processors if(Importer_ != 0) { EPETRA_CHK_ERR(ImportVector_->Import(x, *Importer_, Insert)); xp = (double*) ImportVector_->Values(); } // If we have a non-trivial exporter, we must export elements that are permuted or belong to other processors if(Exporter_ != 0) yp = (double*) ExportVector_->Values(); // Do actual computation for(int i = 0; i < A.NumMyRows(); i++) { int NumEntries,*RowIndices; A.Graph().ExtractMyRowView(i,NumEntries,RowIndices); double sum = 0.0; for(int j = 0; j < NumEntries; j++) sum += xp[*RowIndices++]; yp[i] = sum; } if(Exporter_ != 0) { y.PutScalar(0.0); // Make sure target is zero EPETRA_CHK_ERR(y.Export(*ExportVector_, *Exporter_, Add)); // Fill y with Values from export vector } // Handle case of rangemap being a local replicated map if (!A.Graph().RangeMap().DistributedGlobal() && A.Comm().NumProc()>1) EPETRA_CHK_ERR(y.Reduce()); delete xcopy; delete ImportVector_; delete ExportVector_; return(0); } /*************************************************************************************/ /****************************** Multiply Abs *****************************************/ /*************************************************************************************/ // Multiplies abs(A)x = y, where all non-zero entries of A are replaced with their absolute values value int Multiply_Abs(const Epetra_CrsMatrix &A,const Epetra_Vector &x,Epetra_Vector &y){ if(!A.Filled()) EPETRA_CHK_ERR(-1); // Matrix must be filled. double* xp = (double*) x.Values(); double* yp = (double*) y.Values(); const Epetra_Import* Importer_=A.Importer(); const Epetra_Export* Exporter_=A.Exporter(); Epetra_Vector *xcopy=0, *ImportVector_=0, *ExportVector_=0; if (&x==&y && Importer_==0 && Exporter_==0) { xcopy = new Epetra_Vector(x); xp = (double *) xcopy->Values(); } else if (Importer_) ImportVector_ = new Epetra_Vector(Importer_->TargetMap()); else if (Exporter_) ExportVector_ = new Epetra_Vector(Exporter_->SourceMap()); // If we have a non-trivial importer, we must import elements that are permuted or are on other processors if(Importer_ != 0) { EPETRA_CHK_ERR(ImportVector_->Import(x, *Importer_, Insert)); xp = (double*) ImportVector_->Values(); } // If we have a non-trivial exporter, we must export elements that are permuted or belong to other processors if(Exporter_ != 0) yp = (double*) ExportVector_->Values(); // Do actual computation for(int i = 0; i < A.NumMyRows(); i++) { int NumEntries,*RowIndices; double *RowValues; A.ExtractMyRowView(i,NumEntries,RowValues,RowIndices); double sum = 0.0; for(int j = 0; j < NumEntries; j++){ double v=*RowValues++; sum += ABS(v) * xp[*RowIndices++]; } yp[i] = sum; } if(Exporter_ != 0) { y.PutScalar(0.0); // Make sure target is zero EPETRA_CHK_ERR(y.Export(*ExportVector_, *Exporter_, Add)); // Fill y with Values from export vector } // Handle case of rangemap being a local replicated map if (!A.Graph().RangeMap().DistributedGlobal() && A.Comm().NumProc()>1) EPETRA_CHK_ERR(y.Reduce()); delete xcopy; delete ImportVector_; delete ExportVector_; return(0); } /*************************************************************************************/ /**************************** GET ML RESIDUAL ****************************************/ /*************************************************************************************/ /** \brief Compute ML solution residual \param A [in] discrete operator \param lhs [in] solution vector \param rhs [in] right hand side vector \param Time [in] elapsed time for output \param TotalErrorResidual [out] error residual \param TotalErrorExactSol [out] error in xh (not an appropriate measure for H(div) basis functions) */ 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){ // ==================================================== // // compute difference between exact solution and ML one // // ==================================================== // double d = 0.0, d_tot = 0.0; for( int i=0 ; i