// @HEADER // ***************************************************************************** // Trilinos: An Object-Oriented Solver Framework // // Copyright 2001-2024 NTESS and the Trilinos contributors. // SPDX-License-Identifier: BSD-3-Clause // ***************************************************************************** // @HEADER /** \file example_CurlLSFEM.cpp \brief Example solution of a div-curl system on a hexahedral mesh using curl-conforming (edge) 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 x n = 0 on Gamma Corresponding discrete linear system for edge element coeficients (x): (Kc + Mc*Dg*MgInv*Dg'*Mc)x = b Kc - Hcurl stiffness matrix Mc - Hcurl mass matrix Dg - Node to edge incidence matrix MgInv - 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_CurlLSFEM.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 CurlLSFEMin.xml. \endverbatim Input files available in Trilinos for use with the CurlLSFEM driver: \li CurlLSFEMin.xml - basic input file with box mesh and one mesh block \li Ninja.xml - input file with distorted mesh (shaped like Ninja star) and one mesh block \li CurlLSFEMblock_in_block.xml - input file with box mesh with a center block with different material values. **/ /**************************************************************/ /* Includes */ /**************************************************************/ // 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_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_Import.h" #include "Epetra_Export.h" #include "Epetra_FECrsMatrix.h" #include "Epetra_FEVector.h" #include "Epetra_LinearProblem.h" // Teuchos includes #include "Teuchos_oblackholestream.hpp" #include "Teuchos_RCP.hpp" #include "Teuchos_ArrayRCP.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" // AztecOO includes #include "AztecOO.h" // ML Includes #include "ml_MultiLevelPreconditioner.h" #include "ml_RefMaxwell_11_Operator.h" #include "ml_RefMaxwell.h" #include "ml_EdgeMatrixFreePreconditioner.h" #include "ml_epetra_utils.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" #define ABS(x) ((x)>0?(x):-(x)) using Teuchos::rcp; using Teuchos::ArrayRCP; /*** Uncomment if you would like output data for plotting ***/ //#define DUMP_DATA using namespace std; using namespace Intrepid; /*********************************************************/ /* 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 DECLARATION FOR ML PRECONDITIONER *********************/ /**********************************************************************************/ /** \brief ML Preconditioner \param ProblemType [in] problem type \param MLList [in] ML parameter list \param CurlCurl [in] H(curl) stiffness matrix \param D0clean [in] Edge to node stiffness matrix \param M0inv [in] H(grad) mass matrix inverse \param M1 [in] H(curl) 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_CurlLSFEM(char ProblemType[], Teuchos::ParameterList & MLList, Epetra_CrsMatrix & CurlCurl, Epetra_CrsMatrix & D0clean, Epetra_CrsMatrix & M0inv, Epetra_CrsMatrix & M1, 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 \param mu [in] material parameter \return Value of the divergence of exact solution at (x,y,z) */ double evalDivu(double & x, double & y, double & z, double & mu); /** \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 Gradient of Divergence of exact solution \param gradDivu0 [out] first (x) component of grad div of exact solution \param gradDivu1 [out] second (y) component of grad div of exact solution \param gradDivu2 [out] third (z) component of grad div of exact solution \param x [in] x coordinate \param y [in] y coordinate \param z [in] z coordinate \param mu [in] material parameter */ int evalGradDivu(double & gradDivu0, double & gradDivu1, double & gradDivu2, 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_CurlLSFEM.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: Solve Div-Curl System on Hexahedral Mesh |\n" \ << "| with Curl-conforming Elements |\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; /**********************************************************************************/ /********************************** GET XML INPUTS ********************************/ /**********************************************************************************/ // Command line for xml file, otherwise use default std::string xmlInFileName; if(argc>=2) xmlInFileName=string(argv[1]); else xmlInFileName="CurlLSFEMin.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 shards::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)=3; refFaceToEdge(3,1)=8; refFaceToEdge(3,2)=7; refFaceToEdge(3,3)=11; refFaceToEdge(4,0)=0; refFaceToEdge(4,1)=1; refFaceToEdge(4,2)=2; refFaceToEdge(4,3)=3; refFaceToEdge(5,0)=4; refFaceToEdge(5,1)=5; refFaceToEdge(5,2)=6; refFaceToEdge(5,3)=7; /**********************************************************************************/ /******************************* GENERATE MESH ************************************/ /**********************************************************************************/ if (MyPID == 0) { std::cout << "Generating mesh ... \n\n"; } // Generate mesh with Pamgen int dim=3; 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; 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); int numEdgeOnBndy=0; 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] shards::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); /**********************************************************************************/ /* Get numerical integration points and weights for hexahedron edge */ /* (needed for inhomogeneous boundary terms) */ /**********************************************************************************/ // Define topology of the edge parametrization domain as [-1,1] shards::CellTopology paramEdge(shards::getCellTopologyData >() ); // Define cubature DefaultCubatureFactory cubFactoryEdge; Teuchos::RCP > hexEdgeCubature = cubFactoryEdge.create(paramEdge, 3); int cubEdgeDim = hexEdgeCubature -> getDimension(); int numEdgePoints = hexEdgeCubature -> getNumPoints(); // Define storage for cubature points and weights on [-1,1] FieldContainer paramEdgeWeights(numEdgePoints); FieldContainer paramEdgePoints(numEdgePoints,cubEdgeDim); // Define storage for cubature points on workset faces hexEdgeCubature -> getCubature(paramEdgePoints, paramEdgeWeights); if(MyPID==0) {std::cout << "Getting cubature " << Time.ElapsedTime() << " sec \n" ; Time.ResetStartTime();} /**********************************************************************************/ /*********************************** GET BASIS ************************************/ /**********************************************************************************/ // Define basis Basis_HCURL_HEX_I1_FEM > hexHCurlBasis; Basis_HGRAD_HEX_C1_FEM > hexHGradBasis; int numFieldsC = hexHCurlBasis.getCardinality(); int numFieldsG = hexHGradBasis.getCardinality(); // Evaluate basis at cubature points FieldContainer HGVals(numFieldsG, numCubPoints); FieldContainer HCVals(numFieldsC, numCubPoints, spaceDim); FieldContainer HCurls(numFieldsC, numCubPoints, spaceDim); FieldContainer worksetCVals(numFieldsC, numFacePoints, spaceDim); hexHCurlBasis.getValues(HCVals, cubPoints, OPERATOR_VALUE); hexHCurlBasis.getValues(HCurls, cubPoints, OPERATOR_CURL); hexHGradBasis.getValues(HGVals, cubPoints, OPERATOR_VALUE); if(MyPID==0) {std::cout << "Getting basis " << Time.ElapsedTime() << " sec \n" ; Time.ResetStartTime();} /**********************************************************************************/ /********************* 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_FECrsMatrix StiffMatrixC(Copy, globalMapC, numFieldsC); Epetra_FECrsMatrix MassMatrixC (Copy, globalMapC, numFieldsC); Epetra_FECrsMatrix MassMatrixG (Copy, globalMapG, numFieldsG); Epetra_FEVector rhsVector (globalMapC); 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 bndyEdgeVal(numEdgeOnBndy); FieldContainer bndyEdgeToEdge(numEdges); FieldContainer bndyEdgeDone(numEdges); FieldContainer refEdgePoints(numEdgePoints,spaceDim); FieldContainer bndyEdgePoints(1,numEdgePoints,spaceDim); FieldContainer bndyEdgeJacobians(1,numEdgePoints,spaceDim,spaceDim); FieldContainer edgeTan(1,numEdgePoints,spaceDim); FieldContainer uDotTangent(numEdgePoints); FieldContainer uEdge(numEdgePoints,spaceDim); FieldContainer nodes(1, numNodesPerElem, spaceDim); int ibedge=0; // Evaluate tangent at edge quadrature points for (int ielem=0; ielem cellWorkset(worksetSize, numNodesPerElem, spaceDim); FieldContainer worksetEdgeSigns(worksetSize, numEdgesPerElem); // Copy coordinates into cell workset int cellCounter = 0; for(int cell = worksetBegin; cell < worksetEnd; cell++){ // Physical cell coordinates for (int inode=0; inode 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 HGRAD mass matrix FieldContainer massMatrixHGrad (worksetSize, numFieldsG, numFieldsG); FieldContainer weightedMeasure (worksetSize, numCubPoints); FieldContainer weightedMeasureMuInv (worksetSize, numCubPoints); FieldContainer HGValsTransformed (worksetSize, numFieldsG, numCubPoints); FieldContainer HGValsTransformedWeighted (worksetSize, numFieldsG, numCubPoints); // Containers for element HCURL mass matrix FieldContainer massMatrixHCurl (worksetSize, numFieldsC, numFieldsC); FieldContainer HCValsTransformed (worksetSize, numFieldsC, numCubPoints, spaceDim); FieldContainer HCValsTransformedWeighted (worksetSize, numFieldsC, numCubPoints, spaceDim); // Containers for element HCURL stiffness matrix FieldContainer stiffMatrixHCurl (worksetSize, numFieldsC, numFieldsC); FieldContainer weightedMeasureMu (worksetSize, numCubPoints); FieldContainer HCurlsTransformed (worksetSize, numFieldsC, numCubPoints, spaceDim); FieldContainer HCurlsTransformedWeighted (worksetSize, numFieldsC, numCubPoints, spaceDim); // Containers for right hand side vectors FieldContainer rhsDatag (worksetSize, numCubPoints, cubDim); FieldContainer rhsDatah (worksetSize, numCubPoints, cubDim); FieldContainer gC (worksetSize, numFieldsC); FieldContainer hC (worksetSize, numFieldsC); // Containers for right hand side boundary term FieldContainer hCBoundary (1, numFieldsC); 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 faceNormal (1, numFacePoints, spaceDim); FieldContainer bcFaceCVals (numFieldsC, numFacePoints, spaceDim); FieldContainer faceVFieldVals (1, numFacePoints, spaceDim); FieldContainer bcCValsTransformed (1, numFieldsC, numFacePoints, spaceDim); FieldContainer divuFace (1, numFacePoints); FieldContainer bcFieldDotNormal (1, numFieldsC, numFacePoints); FieldContainer bcEdgeSigns (1, numFieldsC); /**********************************************************************************/ /* 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 HGRAD Mass Matrix */ /**********************************************************************************/ // transform to physical coordinates IntrepidFSTools::HGRADtransformVALUE(HGValsTransformed, HGVals); // 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++){ weightedMeasureMuInv(cellCounter,nPt) = weightedMeasure(cellCounter,nPt) / muVal(cell); } cellCounter++; } // multiply values with weighted measure IntrepidFSTools::multiplyMeasure(HGValsTransformedWeighted, weightedMeasureMuInv, 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();} /**********************************************************************************/ /* Compute HCURL Mass Matrix */ /**********************************************************************************/ // transform to physical coordinates IntrepidFSTools::HCURLtransformVALUE(HCValsTransformed, worksetJacobInv, HCVals); // multiply by weighted measure IntrepidFSTools::multiplyMeasure(HCValsTransformedWeighted, weightedMeasure, 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 HCURL Stiffness Matrix */ /**********************************************************************************/ // transform to physical coordinates IntrepidFSTools::HCURLtransformCURL(HCurlsTransformed, worksetJacobian, worksetJacobDet, HCurls); // 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(HCurlsTransformedWeighted, weightedMeasure, HCurlsTransformed); // integrate to compute element stiffness matrix IntrepidFSTools::integrate(stiffMatrixHCurl, HCurlsTransformed, HCurlsTransformedWeighted, COMP_BLAS); // apply edge signs IntrepidFSTools::applyLeftFieldSigns (stiffMatrixHCurl, worksetEdgeSigns); IntrepidFSTools::applyRightFieldSigns(stiffMatrixHCurl, worksetEdgeSigns); if(MyPID==0) {std::cout << "Compute HCURL Stiffness 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; evalCurlu(du1, du2, du3, x, y, z, muVal(cell)); rhsDatag(worksetCellOrdinal,nPt,0) = du1; rhsDatag(worksetCellOrdinal,nPt,1) = du2; rhsDatag(worksetCellOrdinal,nPt,2) = du3; evalGradDivu(du1, du2, du3, x, y, z, muVal(cell)); rhsDatah(worksetCellOrdinal,nPt,0) = du1; rhsDatah(worksetCellOrdinal,nPt,1) = du2; rhsDatah(worksetCellOrdinal,nPt,2) = du3; } } // integrate (g,curl w) term IntrepidFSTools::integrate(gC, rhsDatag, HCurlsTransformedWeighted, COMP_BLAS); // integrate (h,div w) term IntrepidFSTools::integrate(hC, rhsDatah, HCValsTransformedWeighted, COMP_BLAS); // apply signs IntrepidFSTools::applyFieldSigns(gC, worksetEdgeSigns); IntrepidFSTools::applyFieldSigns(hC, worksetEdgeSigns); // evaluate 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 edge signs for (int iedge =0; iedge < numEdgesPerElem; iedge++){ bcEdgeSigns(0,iedge) = worksetEdgeSigns(worksetCellOrdinal,iedge); } // 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 hexHCurlBasis.getValues(bcFaceCVals, refFacePoints, OPERATOR_VALUE); // compute Jacobians at Gauss pts. on reference face for all parent cells IntrepidCTools::setJacobian(faceJacobians, refFacePoints, cellNodes, cellType); IntrepidCTools::setJacobianInv(faceJacobInv, faceJacobians ); // transform to physical coordinates IntrepidFSTools::HCURLtransformVALUE(bcCValsTransformed, faceJacobInv, bcFaceCVals); // 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 div 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); divuFace(0,nPt)=evalDivu(x, y, z, muVal(cell)); } // compute the dot product and multiply by Gauss weights for (int nF = 0; nF < numFieldsC; nF++){ for(int nPt = 0; nPt < numFacePoints; nPt++){ bcFieldDotNormal(0,nF,nPt)=0.0; for (int dim = 0; dim < spaceDim; dim++){ bcFieldDotNormal(0,nF,nPt) += bcCValsTransformed(0,nF,nPt,dim) * faceNormal(0,nPt,dim) * paramFaceWeights(nPt); } //dim } //nPt } //nF // integrate IntrepidFSTools::integrate(hCBoundary, divuFace, bcFieldDotNormal, COMP_CPP); // apply signs IntrepidFSTools::applyFieldSigns(hCBoundary, bcEdgeSigns); // add into hC term for (int nF = 0; nF < numFieldsC; nF++){ hC(worksetCellOrdinal,nF) = hC(worksetCellOrdinal,nF) - hCBoundary(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, stiffness matrix and right-hand side ***/ // loop over edges for matrix row for (int cellEdgeRow = 0; cellEdgeRow < numFieldsC; cellEdgeRow++){ int localEdgeRow = elemToEdge(cell, cellEdgeRow); int globalEdgeRow = globalEdgeIds[localEdgeRow]; double rhsContribution = gC(worksetCellOrdinal, cellEdgeRow) - hC(worksetCellOrdinal, cellEdgeRow); rhsVector.SumIntoGlobalValues(1, &globalEdgeRow, &rhsContribution); // 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); double stiffCContribution = stiffMatrixHCurl(worksetCellOrdinal, cellEdgeRow, cellEdgeCol); MassMatrixC.InsertGlobalValues (1, &globalEdgeRow, 1, &globalEdgeCol, &massCContribution); StiffMatrixC.InsertGlobalValues(1, &globalEdgeRow, 1, &globalEdgeCol, &stiffCContribution); }// *** cell edge col loop *** }// *** cell edge 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(); StiffMatrixC.GlobalAssemble(); StiffMatrixC.FillComplete(); MassMatrixC.GlobalAssemble(); MassMatrixC.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 Coordinates EpetraExt::VectorToMatrixMarketFile("ecoordx.dat",EDGE_X); EpetraExt::VectorToMatrixMarketFile("ecoordy.dat",EDGE_Y); EpetraExt::VectorToMatrixMarketFile("ecoordz.dat",EDGE_Z); // Edge signs EpetraExt::MultiVectorToMatrixMarketFile("edge_signs.dat",edgeSign,0,0,false); #endif /**********************************************************************************/ /*********************** ADJUST MATRICES AND RHS FOR BCs **************************/ /**********************************************************************************/ // Build the inverse diagonal for MassMatrixG Epetra_Vector DiagG(MassMatrixG.RowMap()); DiagG.PutScalar(1.0); MassMatrixG.Multiply(false,DiagG,DiagG); for(int i=0;i hexEdgeSigns(numCells, numFieldsC); 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 uhCVals(numFieldsC, numCubPointsErr, spaceDim); FieldContainer uhCValsTrans(numCells,numFieldsC, numCubPointsErr, spaceDim); FieldContainer uhCurls(numFieldsC, numCubPointsErr, spaceDim); FieldContainer uhCurlsTrans(numCells, numFieldsC, numCubPointsErr, spaceDim); hexHCurlBasis.getValues(uhCVals, cubPointsErr, OPERATOR_VALUE); hexHCurlBasis.getValues(uhCurls, cubPointsErr, OPERATOR_CURL); // Loop over elements for (int k=0; k(uhCValsTrans, hexJacobInvE, uhCVals); IntrepidFSTools::HCURLtransformCURL(uhCurlsTrans, hexJacobianE, hexJacobDetE, uhCurls); // compute weighted measure IntrepidFSTools::computeCellMeasure(weightedMeasureE, hexJacobDetE, cubWeightsErr); // loop over cubature points for (int nPt = 0; nPt < numCubPointsErr; nPt++){ // get exact solution and curls 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); double mu = 1.0; // use mu=1 to get the curl without material parameter evalCurlu(curluExact1, curluExact2, curluExact3, x, y, z, mu); // calculate approximate solution and curls double uApprox1 = 0.0; double uApprox2 = 0.0; double uApprox3 = 0.0; double curluApprox1 = 0.0; double curluApprox2= 0.0; double curluApprox3 = 0.0; for (int i = 0; i < numFieldsC; i++){ int rowIndex = globalEdgeIds[elemToEdge(k,i)]; #ifdef HAVE_MPI double uh1 = uCoeff.Values()[rowIndex]; #else double uh1 = xh.Values()[rowIndex]; #endif uApprox1 += uh1*uhCValsTrans(0,i,nPt,0)*hexEdgeSigns(0,i); uApprox2 += uh1*uhCValsTrans(0,i,nPt,1)*hexEdgeSigns(0,i); uApprox3 += uh1*uhCValsTrans(0,i,nPt,2)*hexEdgeSigns(0,i); curluApprox1 += uh1*uhCurlsTrans(0,i,nPt,0)*hexEdgeSigns(0,i); curluApprox2 += uh1*uhCurlsTrans(0,i,nPt,1)*hexEdgeSigns(0,i); curluApprox3 += uh1*uhCurlsTrans(0,i,nPt,2)*hexEdgeSigns(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); HCurlerrElem+=((curluExact1 - curluApprox1)*(curluExact1 - curluApprox1)) *weightedMeasureE(0,nPt); HCurlerrElem+=((curluExact2 - curluApprox2)*(curluExact2 - curluApprox2)) *weightedMeasureE(0,nPt); HCurlerrElem+=((curluExact3 - curluApprox3)*(curluExact3 - curluApprox3)) *weightedMeasureE(0,nPt); } L2err+=L2errElem; HCurlerr+=HCurlerrElem; } #ifdef HAVE_MPI // sum over all processors Comm.SumAll(&L2err,&L2errTot,1); Comm.SumAll(&HCurlerr,&HCurlerrTot,1); Comm.MaxAll(&Linferr,&LinferrTot,1); #else L2errTot = L2err; HCurlerrTot = HCurlerr; LinferrTot = Linferr; #endif if (MyPID == 0) { std::cout << "\n" << "L2 Error: " << sqrt(L2errTot) <<"\n"; std::cout << "HCurl Error: " << sqrt(HCurlerrTot) <<"\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); } /*************************************************************************************/ /**************************** 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(curl) 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 BCedges_arcp(BCedges,0,numBCedges,false); if(!CurlCurl.Comm().MyPID()) cout<<"Total number of rows = "<