Changeset 931
- Timestamp:
- 09/20/16 16:48:07 (8 years ago)
- Location:
- XIOS/trunk/src
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
XIOS/trunk/src/io/nc4_data_output.cpp
r929 r931 450 450 StdString domainName = domain->name; 451 451 domain->assignMesh(domainName, domain->nvertex); 452 //domain->mesh->createMesh(domain->lonvalue_srv, domain->latvalue_srv, domain->bounds_lon_srv, domain->bounds_lat_srv);453 452 domain->mesh->createMeshEpsilon(server->intraComm, domain->lonvalue_srv, domain->latvalue_srv, domain->bounds_lon_srv, domain->bounds_lat_srv); 454 453 -
XIOS/trunk/src/node/mesh.cpp
r929 r931 1523 1523 ///---------------------------------------------------------------- 1524 1524 /*! 1525 * \fn void CMesh::get NghbFacesNodeType(const MPI_Comm& comm,1526 const CArray<double, 2>& bounds_lon, const CArray<double, 2>& bounds_lat,1527 CArray<int, 2>& nghbFaces)1525 * \fn void CMesh::getGloNghbFacesNodeType(const MPI_Comm& comm, const CArray<int, 1>& face_idx, 1526 const CArray<double, 2>& bounds_lon, const CArray<double, 2>& bounds_lat, 1527 CArray<int, 2>& nghbFaces) 1528 1528 * Finds neighboring cells of a local domain for node-type of neighbors. 1529 1529 * \param [in] comm 1530 * \param [in] face_idx Array with global indexes. 1530 1531 * \param [in] bounds_lon Array of boundary longitudes. 1531 1532 * \param [in] bounds_lat Array of boundary latitudes. … … 1533 1534 */ 1534 1535 1535 void CMesh::get NghbFacesNodeType(const MPI_Comm& comm,1536 void CMesh::getGloNghbFacesNodeType(const MPI_Comm& comm, const CArray<int, 1>& face_idx, 1536 1537 const CArray<double, 2>& bounds_lon, const CArray<double, 2>& bounds_lat, 1537 1538 CArray<int, 2>& nghbFaces) 1538 1539 { 1539 int nvertex = (bounds_lon.numElements() == 0) ? 1 :bounds_lon.rows();1540 int nvertex = bounds_lon.rows(); 1540 1541 int nbFaces = bounds_lon.shape()[1]; 1541 1542 nghbFaces.resize(2, nbFaces*10); // some estimate on max number of neighbouring cells … … 1544 1545 MPI_Comm_rank(comm, &mpiRank); 1545 1546 MPI_Comm_size(comm, &mpiSize); 1546 1547 // For determining the global face index1548 size_t nbFacesOnProc = nbFaces;1549 size_t nbFacesAccum;1550 MPI_Scan(&nbFacesOnProc, &nbFacesAccum, 1, MPI_UNSIGNED_LONG, MPI_SUM, comm);1551 nbFacesAccum -= nbFaces;1552 1547 1553 1548 // (1) Generating unique node indexes … … 1630 1625 it = nodeIdx2IdxMin.find(myNodeIdx); 1631 1626 size_t nodeIdxMin = (it->second)[0]; 1632 size_t faceIdx = nbFacesAccum + nf;1627 size_t faceIdx = face_idx(nf); 1633 1628 if (nodeIdxMin2Face.count(nodeIdxMin) == 0) 1634 1629 { … … 1680 1675 } 1681 1676 nghbFaces.resizeAndPreserve(2, nbNghb); 1682 } // get NghbFacesNodeType1677 } // getGloNghbFacesNodeType 1683 1678 1684 1679 ///---------------------------------------------------------------- 1685 1680 /*! 1686 * \fn void CMesh::get NghbFacesEdgeType(const MPI_Comm& comm,1681 * \fn void CMesh::getGloNghbFacesEdgeType(const MPI_Comm& comm, const CArray<int, 1>& face_idx, 1687 1682 const CArray<double, 2>& bounds_lon, const CArray<double, 2>& bounds_lat, 1688 1683 CArray<int, 2>& nghbFaces) 1689 1684 * Finds neighboring cells of a local domain for edge-type of neighbors. 1690 1685 * \param [in] comm 1686 * \param [in] face_idx Array with global indexes. 1691 1687 * \param [in] bounds_lon Array of boundary longitudes. 1692 1688 * \param [in] bounds_lat Array of boundary latitudes. … … 1694 1690 */ 1695 1691 1696 void CMesh::get NghbFacesEdgeType(const MPI_Comm& comm,1692 void CMesh::getGloNghbFacesEdgeType(const MPI_Comm& comm, const CArray<int, 1>& face_idx, 1697 1693 const CArray<double, 2>& bounds_lon, const CArray<double, 2>& bounds_lat, 1698 1694 CArray<int, 2>& nghbFaces) 1699 1695 { 1700 int nvertex = (bounds_lon.numElements() == 0) ? 1 :bounds_lon.rows();1696 int nvertex = bounds_lon.rows(); 1701 1697 int nbFaces = bounds_lon.shape()[1]; 1702 1698 nghbFaces.resize(2, nbFaces*10); // estimate of max number of neighbouring cells … … 1705 1701 MPI_Comm_rank(comm, &mpiRank); 1706 1702 MPI_Comm_size(comm, &mpiSize); 1707 1708 // For determining the global face index1709 size_t nbFacesOnProc = nbFaces;1710 size_t nbFacesAccum;1711 MPI_Scan(&nbFacesOnProc, &nbFacesAccum, 1, MPI_UNSIGNED_LONG, MPI_SUM, comm);1712 nbFacesAccum -= nbFaces;1713 1703 1714 1704 // (1) Generating unique node indexes … … 1798 1788 size_t nodeIdxMin1 = (it1->second)[0]; 1799 1789 size_t nodeIdxMin2 = (it2->second)[0]; 1800 size_t faceIdx = nbFacesAccum + nf;1790 size_t faceIdx = face_idx(nf); 1801 1791 1802 1792 if (nodeIdxMin1 != nodeIdxMin2) … … 1828 1818 for (int nf = 0; nf < nbFaces; ++nf) 1829 1819 { 1830 nbNghb = 0;1831 1820 for (int nv1 = 0; nv1 < nvertex; ++nv1) 1832 1821 { … … 1866 1855 } 1867 1856 nghbFaces.resizeAndPreserve(2, nbNghb); 1868 } // get NghbFacesEdgeType1857 } // getGloNghbFacesEdgeType 1869 1858 1870 1859 ///---------------------------------------------------------------- 1871 1860 /*! 1872 * \fn void getDomainExtended(const int nghbType, const MPI_Comm& comm, 1873 const CArray<double, 2>& bounds_lon, const CArray<double, 2>& bounds_lat, 1874 CArray<size_t, 1>& nghbFaces) 1861 * \fn void getGlobalNghbFaces (const int nghbType, const MPI_Comm& comm, const CArray<int, 1>& face_idx, 1862 const CArray<double, 2>& bounds_lon, const CArray<double, 2>& bounds_lat, 1863 CArray<size_t, 1>& nghbFaces) 1864 * Finds neighboring faces owned by other procs. 1875 1865 * \param [in] nghbType 0 for faces sharing nodes, otherwise for faces sharing edges. 1876 1866 * \param [in] comm 1867 * \param [in] face_idx Array with global indexes. 1877 1868 * \param [in] bounds_lon Array of boundary longitudes. 1878 1869 * \param [in] bounds_lat Array of boundary latitudes. 1879 * \param [out] nghbFaces Array containing neighboring faces and their ranks. The ordering is face1, rank1,....1870 * \param [out] nghbFaces 2D array containing neighboring faces and owner ranks. 1880 1871 */ 1881 1872 1882 void CMesh::getDomainExtended(const int nghbType, const MPI_Comm& comm, 1883 const CArray<double, 2>& bounds_lon, const CArray<double, 2>& bounds_lat, 1884 CArray<int, 2>& nghbFaces) 1873 void CMesh::getGlobalNghbFaces(const int nghbType, const MPI_Comm& comm, 1874 const CArray<int, 1>& face_idx, 1875 const CArray<double, 2>& bounds_lon, const CArray<double, 2>& bounds_lat, 1876 CArray<int, 2>& nghbFaces) 1885 1877 { 1886 1878 if (nghbType == 0) 1887 get NghbFacesNodeType(comm, bounds_lon, bounds_lat, nghbFaces);1879 getGloNghbFacesNodeType(comm, face_idx, bounds_lon, bounds_lat, nghbFaces); 1888 1880 else 1889 getNghbFacesEdgeType(comm, bounds_lon, bounds_lat, nghbFaces); 1890 } // getDomainExtended 1881 getGloNghbFacesEdgeType(comm, face_idx, bounds_lon, bounds_lat, nghbFaces); 1882 } // getGlobalNghbFaces 1883 1884 ///---------------------------------------------------------------- 1885 /*! 1886 * \fn void getLocalNghbFaces (const int nghbType, 1887 const CArray<double, 2>& bounds_lon, const CArray<double, 2>& bounds_lat, 1888 CArray<size_t, 1>& nghbFaces) 1889 * \param [in] nghbType 0 for faces sharing nodes, otherwise for faces sharing edges. 1890 * \param [in] bounds_lon Array of boundary longitudes. 1891 * \param [in] bounds_lat Array of boundary latitudes. 1892 * \param [out] nghbFaces 1D array containing neighboring faces. 1893 */ 1894 1895 void CMesh::getLocalNghbFaces(const int nghbType, const CArray<int, 1>& face_idx, 1896 const CArray<double, 2>& bounds_lon, const CArray<double, 2>& bounds_lat, 1897 CArray<int, 2>& nghbFaces, CArray<int, 1>& nbNghbFaces) 1898 { 1899 if (nghbType == 0) 1900 getLocNghbFacesNodeType(face_idx, bounds_lon, bounds_lat, nghbFaces, nbNghbFaces); 1901 else 1902 getLocNghbFacesEdgeType(face_idx, bounds_lon, bounds_lat, nghbFaces, nbNghbFaces); 1903 } // getLocalNghbFaces 1904 1905 ///---------------------------------------------------------------- 1906 /*! 1907 * \fn void getLocNghbFacesNodeType (const CArray<double, 2>& bounds_lon, const CArray<double, 2>& bounds_lat, 1908 CArray<int, 2>& nghbFaces) 1909 * \param [in] face_idx Array with global face indexing. 1910 * \param [in] bounds_lon Array of boundary longitudes. 1911 * \param [in] bounds_lat Array of boundary latitudes. 1912 * \param [out] nghbFaces 2D array containing neighboring faces. 1913 * \param [out] nbNghbFaces Array containing number of neighboring faces. 1914 */ 1915 1916 void CMesh::getLocNghbFacesNodeType (const CArray<int, 1>& face_idx, 1917 const CArray<double, 2>& bounds_lon, const CArray<double, 2>& bounds_lat, 1918 CArray<int, 2>& faceToFaces, CArray<int, 1>& nbNghbFaces) 1919 { 1920 int nvertex = bounds_lon.rows(); 1921 int nbFaces = bounds_lon.shape()[1]; 1922 int nbNodes = 0; 1923 nbNghbFaces.resize(nbFaces); 1924 nbNghbFaces = 0; 1925 1926 // nodeToFaces connectivity 1927 CClientClientDHTSizet::Index2VectorInfoTypeMap nodeToFaces; 1928 for (int nf = 0; nf < nbFaces; ++nf) 1929 for (int nv = 0; nv < nvertex; ++nv) 1930 { 1931 size_t nodeHash = (CMesh::createHashes(bounds_lon(nv, nf), bounds_lat(nv ,nf)))[0]; 1932 nodeToFaces[nodeHash].push_back(face_idx(nf)); 1933 } 1934 1935 // faceToFaces connectivity 1936 boost::unordered_map <int, int> mapFaces; // mapFaces = < hash(face1, face2), hash> (the mapped value is irrelevant) 1937 int maxNb = 20; // some assumption on the max possible number of neighboring cells 1938 faceToFaces.resize(maxNb, nbFaces); 1939 CClientClientDHTSizet::Index2VectorInfoTypeMap::iterator it; 1940 for (it = nodeToFaces.begin(); it != nodeToFaces.end(); ++it) 1941 { 1942 int size = it->second.size(); 1943 for (int i = 0; i < (size-1); ++i) 1944 { 1945 int face1 = it->second[i]; 1946 for (int j = i+1; j < size; ++j) 1947 { 1948 int face2 = it->second[j]; 1949 if (face2 != face1) 1950 { 1951 int hashFace = hashPairOrdered(face1, face2); 1952 if (mapFaces.count(hashFace) == 0) 1953 { 1954 faceToFaces(nbNghbFaces(face1), face1) = face2; 1955 faceToFaces(nbNghbFaces(face2), face2) = face1; 1956 ++nbNghbFaces(face1); 1957 ++nbNghbFaces(face2); 1958 mapFaces[hashFace] = hashFace; 1959 } 1960 } 1961 } 1962 } 1963 } 1964 } //getLocNghbFacesEdgeType 1965 1966 1967 ///---------------------------------------------------------------- 1968 /*! 1969 * \fn void getLocNghbFacesEdgeType (const CArray<int, 1>& face_idx, 1970 * const CArray<double, 2>& bounds_lon, const CArray<double, 2>& bounds_lat, 1971 * CArray<int, 2>& nghbFaces, CArray<int, 1>& nbNghbFaces) 1972 * \param [in] face_idx Array with global face indexing. 1973 * \param [in] bounds_lon Array of boundary longitudes. 1974 * \param [in] bounds_lat Array of boundary latitudes. 1975 * \param [out] nghbFaces 2D array containing neighboring faces. 1976 * \param [out] nbNghbFaces Array containing number of neighboring faces. 1977 */ 1978 1979 void CMesh::getLocNghbFacesEdgeType (const CArray<int, 1>& face_idx, 1980 const CArray<double, 2>& bounds_lon, const CArray<double, 2>& bounds_lat, 1981 CArray<int, 2>& faceToFaces, CArray<int, 1>& nbNghbFaces) 1982 { 1983 int nvertex = bounds_lon.rows(); 1984 int nbFaces = bounds_lon.shape()[1]; 1985 int nbNodes = 0; 1986 int nbEdges = 0; 1987 nbNghbFaces.resize(nbFaces); 1988 nbNghbFaces = 0; 1989 1990 // faceToNodes connectivity 1991 CArray<double, 2> faceToNodes (nvertex, nbFaces); 1992 1993 boost::unordered_map <pair<double,double>, int> mapNodes; 1994 1995 for (int nf = 0; nf < nbFaces; ++nf) 1996 for (int nv = 0; nv < nvertex; ++nv) 1997 { 1998 if (mapNodes.find(make_pair (bounds_lon(nv, nf), bounds_lat(nv ,nf))) == mapNodes.end()) 1999 { 2000 mapNodes[make_pair (bounds_lon(nv, nf), bounds_lat(nv, nf))] = nbNodes; 2001 faceToNodes(nv,nf) = nbNodes ; 2002 ++nbNodes ; 2003 } 2004 else 2005 faceToNodes(nv,nf) = mapNodes[make_pair (bounds_lon(nv, nf), bounds_lat(nv ,nf))]; 2006 } 2007 2008 // faceToFaces connectivity 2009 boost::unordered_map <pair<int,int>, int> mapEdges; 2010 faceToFaces.resize(nvertex, nbFaces); 2011 CArray<int, 2> edgeToFaces(2, nbFaces*nvertex); // max possible 2012 2013 for (int nf = 0; nf < nbFaces; ++nf) 2014 { 2015 for (int nv1 = 0; nv1 < nvertex; ++nv1) 2016 { 2017 int nv2 = (nv1 < nvertex -1 ) ? (nv1 + 1) : (nv1 + 1 - nvertex); // cyclic rotation 2018 int face = face_idx(nf); 2019 int node1 = faceToNodes(nv1,face); 2020 int node2 = faceToNodes(nv2,face); 2021 if (node1 != node2) 2022 { 2023 if (mapEdges.find(make_ordered_pair (node1, node2)) == mapEdges.end()) 2024 { 2025 mapEdges[make_ordered_pair (node1, node2)] = nbEdges; 2026 edgeToFaces(0,nbEdges) = face; 2027 ++nbEdges; 2028 } 2029 else 2030 { 2031 int edge = mapEdges[make_ordered_pair (node1, node2)]; 2032 edgeToFaces(1, edge) = face; 2033 int face1 = face; 2034 int face2 = edgeToFaces(0,edge); 2035 faceToFaces(nbNghbFaces(face1), face1) = face2; 2036 faceToFaces(nbNghbFaces(face2), face2) = face1; 2037 ++nbNghbFaces(face1); 2038 ++nbNghbFaces(face2); 2039 } 2040 } // node1 != node2 2041 } // nv 2042 } // nf 2043 2044 } //getLocNghbFacesEdgeType 2045 1891 2046 1892 2047 } // namespace xios -
XIOS/trunk/src/node/mesh.hpp
r929 r931 64 64 const CArray<double, 2>&, const CArray<double, 2>& ); 65 65 66 void get DomainExtended(const int, const MPI_Comm&,66 void getGlobalNghbFaces(const int, const MPI_Comm&, const CArray<int, 1>&, 67 67 const CArray<double, 2>&, const CArray<double, 2>&, 68 68 CArray<int, 2>&); 69 70 void getLocalNghbFaces(const int, const CArray<int, 1>&, 71 const CArray<double, 2>&, const CArray<double, 2>&, 72 CArray<int, 2>&, CArray<int, 1>&); 69 73 70 74 static CMesh* getMesh(StdString, int); … … 80 84 CClientClientDHTSizet* pNodeGlobalIndex; // pointer to a map <nodeHash, nodeIdxGlo> 81 85 CClientClientDHTSizet* pEdgeGlobalIndex; // pointer to a map <edgeHash, edgeIdxGlo> 82 void getNghbFacesNodeType(const MPI_Comm&, const CArray<double, 2>&, const CArray<double, 2>&, CArray<int, 2>&); 83 void getNghbFacesEdgeType(const MPI_Comm&, const CArray<double, 2>&, const CArray<double, 2>&, CArray<int, 2>&); 86 void getGloNghbFacesNodeType(const MPI_Comm&, const CArray<int, 1>&, const CArray<double, 2>&, const CArray<double, 2>&, CArray<int, 2>&); 87 void getGloNghbFacesEdgeType(const MPI_Comm&, const CArray<int, 1>&, const CArray<double, 2>&, const CArray<double, 2>&, CArray<int, 2>&); 88 void getLocNghbFacesNodeType(const CArray<int, 1>&, const CArray<double, 2>&, const CArray<double, 2>&, CArray<int, 2>&, CArray<int, 1>&); 89 void getLocNghbFacesEdgeType(const CArray<int, 1>&, const CArray<double, 2>&, const CArray<double, 2>&, CArray<int, 2>&, CArray<int, 1>&); 84 90 85 91 vector<size_t> createHashes (const double, const double);
Note: See TracChangeset
for help on using the changeset viewer.