118 if (!outputStream.good())
120 std::cout <<
"Cannot open file " <<
outFnameCgr << std::endl;
126 std::cout <<
"surface mesh is empty!" << std::endl;
129 auto surfPatchNoArr =
130 surfMeshBase->getDataSet()->GetCellData()->GetArray(
"patchNo");
131 if (!surfPatchNoArr) {
133 surfMeshBase->getDataSet()->GetCellData()->GetArray(
"PhysGrpId");
134 if (!surfPatchNoArr) {
135 std::cout <<
"surface mesh must have cell array with name \"patchNo\" or " 136 "\"PhysGrpId\" denoting patch number." 142 vtkSmartPointer<vtkIdList> facePtIds;
147 std::map<std::vector<nemId_t>,
148 std::pair<nemId_t, long long int>,
151 vtkSmartPointer<vtkStaticCellLocator> surfCellLocator =
surfMeshBase->buildStaticCellLocator();
153 vtkIdType nVerticesPerFaceMax = 0;
155 int nFacesPerCellMax = 0;
157 for (vtkIdType i = 0; i <
volMeshBase->getNumberOfCells(); ++i)
163 int numFaces = genCell1->GetNumberOfFaces();
164 nFacesPerCellMax = (nFacesPerCellMax < numFaces
167 for (
int j = 0; j < numFaces; ++j)
169 vtkCell *face = genCell1->GetFace(j);
171 vtkIdType numVerts = face->GetNumberOfPoints();
172 nVerticesPerFaceMax = (nVerticesPerFaceMax < numVerts
174 : nVerticesPerFaceMax);
175 facePtIds = face->GetPointIds();
176 volMeshBase->getDataSet()->GetCellNeighbors(i, facePtIds,
178 std::vector<nemId_t> facePntIds(numVerts);
179 for (vtkIdType k = 0; k < numVerts; ++k)
181 facePntIds[k] = face->GetPointId(k) + 1;
183 if (sharedCellPtIds->GetNumberOfIds())
185 faceMap.emplace(facePntIds, std::pair<nemId_t, long long int>(
186 i + 1, sharedCellPtIds->GetId(0) + 1));
191 face->GetBounds(bounds);
193 surfCellLocator->FindCellsWithinBounds(bounds, cellIds);
194 vtkIdType closestCellId;
195 if (cellIds->GetNumberOfIds() == 0) {
196 std::cerr <<
"No surface cell found." << std::endl;
199 closestCellId = cellIds->GetId(0);
200 if (cellIds->GetNumberOfIds() > 1) {
201 double p1[3], p2[3], p3[3];
202 face->GetPoints()->GetPoint(0, p1);
203 face->GetPoints()->GetPoint(1, p2);
204 face->GetPoints()->GetPoint(2, p3);
205 std::vector<double> faceCenter(3);
206 for (vtkIdType k = 0; k < numVerts; ++k) {
207 faceCenter[k] = (p1[k] + p2[k] + p3[k]) / 3.0;
210 faceCenter -
surfMeshBase->getCellCenter(cellIds->GetId(0)));
211 for (vtkIdType k = 1; k < cellIds->GetNumberOfIds(); ++k) {
212 auto candidateCellCenter =
215 if (dist < minDist) {
217 closestCellId = cellIds->GetId(k);
222 double patchNo = surfPatchNoArr->GetComponent(closestCellId, 0);
223 faceMap.emplace(facePntIds,
224 std::pair<nemId_t, long long int>(i + 1, -1 * patchNo));
229 std::map<nemId_t, nemId_t> patchMap;
233 surfPatchNoArr->GetTuple(i, patchNo);
234 patchMap.insert(std::pair<nemId_t, nemId_t>(patchNo[0], i));
240 outputStream << 3 <<
" " << 1 <<
" " << patchMap.size() << std::endl;
241 outputStream <<
volMeshBase->getNumberOfPoints() <<
" " << faceMap.size()
243 << nVerticesPerFaceMax <<
" " << nFacesPerCellMax << std::endl;
247 outputStream << std::setw(21) << std::fixed << std::setprecision(15)
248 << pnt[0] <<
" " << pnt[1] <<
" " << pnt[2] << std::endl;
251 auto it = faceMap.begin();
252 while (it != faceMap.end())
254 outputStream << it->first.size() <<
" ";
255 auto faceIdIter = it->first.begin();
256 while (faceIdIter != it->first.end())
258 outputStream << *faceIdIter <<
" ";
261 outputStream << it->second.first <<
" " << it->second.second << std::endl;
std::shared_ptr< meshBase > volMeshBase
void writePatchMap(const std::string &mapFile, const std::map< nemId_t, nemId_t > &patchMap) const
geoMeshBase * New(MeshType meshType)
Create a new mesh object.
sum comparison for vectors representing faces inserted into map
std::shared_ptr< meshBase > surfMeshBase
T l2_Norm(const std::vector< T > &x)