32 #include <vtkCellTypes.h> 33 #include <vtkCellData.h> 34 #include <vtkThreshold.h> 35 #include <vtkGeometryFilter.h> 36 #include <vtkGenericCell.h> 37 #include <vtkUnstructuredGrid.h> 41 using nemAux::operator-;
49 const std::string &_inFnameVtk,
50 const std::string &_outFnameCgr,
51 const std::string &_outFnameCgi)
58 vtkSmartPointer<vtkDataArray> elementTypeArray
60 elementTypeArray->SetNumberOfComponents(1);
61 elementTypeArray->SetName(
"elemType");
66 iCell < fullMesh->getDataSet()->GetNumberOfCells(); iCell++)
68 if (fullMesh->getDataSet()->GetCellType(iCell) != VTK_TETRA
69 && fullMesh->getDataSet()->GetCellType(iCell) != VTK_TRIANGLE)
71 std::cout <<
"Error: only triangle and tetrahedral elements supported." 75 tmp[0] = fullMesh->getDataSet()->GetCellType(iCell);
76 elementTypeArray->InsertNextTuple(tmp);
78 fullMesh->getDataSet()->GetCellData()->AddArray(elementTypeArray);
82 volThreshold->SetInputData(fullMesh->getDataSet());
83 volThreshold->SetInputArrayToProcess(0, 0, 0,
84 vtkDataObject::FIELD_ASSOCIATION_CELLS,
86 volThreshold->ThresholdBetween(VTK_TETRA, VTK_TETRA);
87 volThreshold->Update();
89 vtkSmartPointer<vtkUnstructuredGrid> volUG = volThreshold->GetOutput();
96 surfThreshold->SetInputData(fullMesh->getDataSet());
97 surfThreshold->SetInputArrayToProcess(0, 0, 0,
98 vtkDataObject::FIELD_ASSOCIATION_CELLS,
100 surfThreshold->ThresholdBetween(VTK_TRIANGLE, VTK_TRIANGLE);
101 surfThreshold->Update();
103 vtkSmartPointer<vtkUnstructuredGrid> surfUG = surfThreshold->GetOutput();
106 geomFilter->SetInputData(surfUG);
107 geomFilter->Update();
108 vtkSmartPointer<vtkPolyData> surfPD = geomFilter->GetOutput();
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;
268 const std::map<nemId_t, nemId_t> &patchMap)
const 270 std::ofstream outputStream(mapFile);
271 if (!outputStream.good())
273 std::cout <<
"Error opening file " << mapFile << std::endl;
281 const std::map<nemId_t, nemId_t> &patchMap)
const 283 outputStream << patchMap.size() << std::endl;
284 outputStream << patchMap.size() << std::endl;
285 auto it = patchMap.begin();
286 size_t normPatchNo = 1;
287 while (it != patchMap.end())
289 for (
int i = 0; i < 2; ++i)
291 outputStream << std::setw(2) << std::left << it->first <<
" ";
293 outputStream << std::setw(2) << std::left << normPatchNo <<
" ";
294 outputStream << 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
static std::shared_ptr< meshBase > CreateShared(const std::string &fname)
Create shared ptr from fname.
cobalt(std::shared_ptr< meshBase > fullMesh, const std::string &inFnameVtk, const std::string &outFnameCgr, const std::string &outFnameCgi)
std::shared_ptr< meshBase > surfMeshBase
T l2_Norm(const std::vector< T > &x)