34 #include <vtkCellData.h> 35 #include <vtkCellTypes.h> 36 #include <vtkThreshold.h> 37 #include <vtkGeometryFilter.h> 38 #include <vtkGenericCell.h> 39 #include <vtkPoints.h> 40 #include <vtkUnstructuredGrid.h> 44 using nemAux::operator-;
54 std::cout <<
"writing packet 25..." << std::endl;
57 std::string defaultHeader =
"25 0 0 1 0 0 0 0 0";
58 outputStream << defaultHeader;
59 outputStream << std::endl;
63 outputStream << std::endl;
69 std::cout <<
"writing packet 26..." << std::endl;
73 for (
int i = 0; i < 8; i++)
78 outputStream << std::setw(8) << std::right <<
"1";
81 outputStream << std::setw(8) << std::right
85 outputStream << std::setw(8) << std::right
89 outputStream << std::setw(8) << std::right <<
"0";
93 outputStream << std::endl;
96 std::time_t t = std::time(
nullptr);
97 std::tm *now = std::localtime(&t);
98 outputStream << std::setw(12) << std::left << (now->tm_year + 1900) <<
'-' 99 << (now->tm_mon + 1) <<
'-' << now->tm_mday;
100 outputStream << std::endl;
106 std::cout <<
"writing packet 1..." << std::endl;
109 iNode <
volMeshBase->getDataSet()->GetNumberOfPoints(); iNode++)
113 outputStream <<
" 1";
115 outputStream << std::setw(8) << std::right << iNode + 1;
117 outputStream << std::setw(8) << std::right <<
"0";
119 outputStream << std::setw(8) << std::right <<
"2";
121 for (
int i = 0; i < 5; i++)
123 outputStream << std::setw(8) << std::right <<
"0";
125 outputStream << std::endl;
130 volMeshBase->getDataSet()->GetPoint(iNode, coords);
131 for (
double coord : coords)
134 snprintf(buffer, 17,
"%16.9E", coord);
135 outputStream << buffer;
137 outputStream << std::endl;
141 outputStream <<
"1G";
143 outputStream << std::setw(8) << std::right <<
"6";
145 outputStream << std::setw(8) << std::right <<
"0";
147 outputStream << std::setw(8) << std::right <<
"0";
149 outputStream << std::setw(2) << std::right <<
"";
151 outputStream << std::setw(6) << std::right <<
"000000";
152 outputStream << std::endl;
159 std::cout <<
"writing packet 2..." << std::endl;
162 iCell <
volMeshBase->getDataSet()->GetNumberOfCells(); iCell++)
168 volMeshBase->getDataSet()->GetCellData()->GetArray(
"elemType")
169 ->GetTuple(iCell, elemType);
170 if (elemType[0] == VTK_TETRA)
174 std::string defaultHeader =
" 2";
175 outputStream << defaultHeader;
177 outputStream << std::setw(8) << std::right << iCell + 1;
179 outputStream << std::setw(8) << std::right <<
"5";
181 outputStream << std::setw(8) << std::right <<
"2";
183 for (
int i = 0; i < 5; i++)
185 outputStream << std::setw(8) << std::right <<
"0";
187 outputStream << std::endl;
191 outputStream << std::setw(8) << std::right <<
"4";
193 outputStream << std::setw(8) << std::right <<
"0";
195 outputStream << std::setw(8) << std::right <<
"0";
197 outputStream << std::setw(8) << std::right <<
"0";
199 for (
int i = 0; i < 3; i++)
202 snprintf(buffer, 17,
"%16.9E", 0.0);
203 outputStream << buffer;
205 outputStream << std::endl;
211 volMeshBase->getDataSet()->GetCellPoints(iCell, cellPtIds);
212 for (
int iPt = 0; iPt < cellPtIds->GetNumberOfIds(); iPt++)
214 outputStream << std::setw(8) << std::right << cellPtIds->GetId(iPt) + 1;
216 outputStream << std::endl;
226 std::cout <<
"writing packet 6..." << std::endl;
228 vtkSmartPointer<vtkIdList> facePtIds;
234 vtkSmartPointer<vtkStaticCellLocator> surfCellLocator =
surfMeshBase->buildStaticCellLocator();
236 vtkIdType nVerticesPerFaceMax = 0;
238 int nFacesPerCellMax = 0;
246 int numFaces = genCell1->GetNumberOfFaces();
247 nFacesPerCellMax = (nFacesPerCellMax < numFaces
250 auto surfPatchNoArr =
251 surfMeshBase->getDataSet()->GetCellData()->GetArray(
"patchNo");
252 if (!surfPatchNoArr) {
254 surfMeshBase->getDataSet()->GetCellData()->GetArray(
"PhysGrpId");
256 for (
int j = 0; j < numFaces; ++j)
258 vtkCell *faceObj = genCell1->GetFace(j);
260 vtkIdType numVerts = faceObj->GetNumberOfPoints();
261 nVerticesPerFaceMax = (nVerticesPerFaceMax < numVerts
263 : nVerticesPerFaceMax);
264 facePtIds = faceObj->GetPointIds();
266 volMeshBase->getDataSet()->GetCellNeighbors(i, facePtIds,
268 std::vector<nemId_t> facePntIds(numVerts);
269 for (vtkIdType k = 0; k < numVerts; ++k)
271 facePntIds[k] = faceObj->GetPointId(k) + 1;
273 if (sharedCellPtIds->GetNumberOfIds() == 0)
276 faceObj->GetBounds(bounds);
278 surfCellLocator->FindCellsWithinBounds(bounds, cellIds);
279 vtkIdType closestCellId;
280 if (cellIds->GetNumberOfIds() == 0) {
281 std::cerr <<
"No surface cell found." << std::endl;
284 closestCellId = cellIds->GetId(0);
285 if (cellIds->GetNumberOfIds() > 1) {
286 double p1[3], p2[3], p3[3];
287 faceObj->GetPoints()->GetPoint(0, p1);
288 faceObj->GetPoints()->GetPoint(1, p2);
289 faceObj->GetPoints()->GetPoint(2, p3);
290 std::vector<double> faceCenter(3);
291 for (vtkIdType k = 0; k < numVerts; ++k) {
292 faceCenter[k] = (p1[k] + p2[k] + p3[k]) / 3.0;
295 faceCenter -
surfMeshBase->getCellCenter(cellIds->GetId(0)));
296 for (vtkIdType k = 1; k < cellIds->GetNumberOfIds(); ++k) {
297 auto candidateCellCenter =
300 if (dist < minDist) {
302 closestCellId = cellIds->GetId(k);
307 double patchNo = surfPatchNoArr->GetComponent(closestCellId, 0);
310 for (vtkIdType iFaceNode = 0;
311 iFaceNode < facePtIds->GetNumberOfIds(); iFaceNode++)
314 static_cast<int>(patchNo));
319 outputStream << std::setw(2) << std::right <<
"6";
321 outputStream << std::setw(8) << std::right << i + 1;
323 outputStream << std::setw(8) << std::right <<
"1";
325 outputStream << std::setw(8) << std::right <<
"2";
327 for (
int i = 0; i < 5; i++)
329 outputStream << std::setw(8) << std::right <<
"0";
331 outputStream << std::endl;
335 outputStream << std::setw(3) << std::right
339 outputStream << std::setw(6) << std::right
343 outputStream << std::setw(8) << std::right <<
face2nodes[j];
346 outputStream << std::setw(2) << std::right
348 outputStream << std::endl;
353 snprintf(buffer, 17,
"%16.9E", (
double)
faceTypeMap[static_cast<int>(patchNo)]);
354 outputStream << buffer;
356 outputStream << std::endl;
373 std::cout <<
"writing packet 8..." << std::endl;
380 volMeshBase->getDataSet()->GetPointCells(iNode, pointCellIds);
384 outputStream << std::setw(2) << std::right <<
"8";
386 outputStream << std::setw(8) << std::right << iNode + 1;
388 outputStream << std::setw(8) << std::right <<
"1";
390 outputStream << std::setw(8) << std::right <<
"2";
392 for (
int i = 0; i < 5; i++)
394 outputStream << std::setw(8) << std::right <<
"0";
396 outputStream << std::endl;
399 std::vector<int> patchNoVec;
400 for (
int &patchItr : boundaryNodeId2PatchNo[iNode])
401 patchNoVec.push_back(patchItr);
406 for (
auto patchItr = patchNoVec.begin();
407 patchItr != patchNoVec.end() - 1; ++patchItr)
411 patchVal = *patchItr;
414 patchVal = *patchItr;
416 int patchNo[1] = {patchVal};
420 outputStream << std::setw(8) << std::right
422 std::string structuralFlag, thermalFlag, meshMotionFlag;
426 structuralFlag =
"1";
431 structuralFlag =
"0";
444 meshMotionFlag =
"1";
449 meshMotionFlag =
"0";
452 outputStream << std::setw(6) << std::right
453 << structuralFlag + thermalFlag + meshMotionFlag +
"000";
454 outputStream << std::endl;
458 for (
int i = 0; i < nFlags; i++)
461 snprintf(buffer, 17,
"%16.9E", (
double)
nodeTypeMap[patchNo[0]]);
462 outputStream << buffer;
464 outputStream << std::endl;
472 <<
"99 0 0 1 0 0 0 0 0";
473 outputStream << std::endl;
478 const std::string &_inFnameVtk,
479 const std::string &_outFnameNeu,
480 const std::map<int, int> &_faceTypeMap,
481 const std::map<int, int> &_nodeTypeMap,
482 const std::map<int, bool> &_nodeStructuralMap,
483 const std::map<int, bool> &_nodeMeshMotionMap,
484 const std::map<int, bool> &_nodeThermalMap,
485 const std::vector<int> &_nppVec)
487 std::cout <<
"Writing Patran file in Rocfrac input format..." << std::endl;
518 if (!outputStream.good())
520 std::cout <<
"Cannot open file " <<
outFnameNeu << std::endl;
526 elementTypeArray->SetNumberOfComponents(1);
527 elementTypeArray->SetName(
"elemType");
531 for (vtkIdType iCell = 0;
532 iCell <
fullMesh->getDataSet()->GetNumberOfCells(); iCell++)
534 if (
fullMesh->getDataSet()->GetCellType(iCell) != VTK_TETRA
535 &&
fullMesh->getDataSet()->GetCellType(iCell) != VTK_TRIANGLE)
537 std::cout <<
"Error: only triangle and tetrahedral elements supported." 541 tmp[0] =
fullMesh->getDataSet()->GetCellType(iCell);
542 elementTypeArray->InsertNextTuple(tmp);
544 fullMesh->getDataSet()->GetCellData()->AddArray(elementTypeArray);
548 volThreshold->SetInputData(
fullMesh->getDataSet());
549 volThreshold->SetInputArrayToProcess(0, 0, 0,
550 vtkDataObject::FIELD_ASSOCIATION_CELLS,
552 volThreshold->ThresholdBetween(VTK_TETRA, VTK_TETRA);
553 volThreshold->Update();
555 vtkSmartPointer<vtkUnstructuredGrid> volUG = volThreshold->GetOutput();
562 surfThreshold->SetInputData(
fullMesh->getDataSet());
563 surfThreshold->SetInputArrayToProcess(0, 0, 0,
564 vtkDataObject::FIELD_ASSOCIATION_CELLS,
566 surfThreshold->ThresholdBetween(VTK_TRIANGLE, VTK_TRIANGLE);
567 surfThreshold->Update();
569 vtkSmartPointer<vtkUnstructuredGrid> surfUG = surfThreshold->GetOutput();
572 geomFilter->SetInputData(surfUG);
573 geomFilter->Update();
574 vtkSmartPointer<vtkPolyData> surfPD = geomFilter->GetOutput();
580 std::cout <<
"Writing Patran file..." << std::endl;
std::shared_ptr< meshBase > surfMeshBase
std::map< int, std::string > face2nodes
void write2(std::ofstream &outputStream) const
std::vector< int > nppVec
geoMeshBase * New(MeshType meshType)
Create a new mesh object.
std::map< int, int > faceTypeMap
void write8(std::ofstream &outputStream)
void write25(std::ofstream &outputStream) const
std::map< int, bool > nodeStructuralMap
patran(std::shared_ptr< meshBase > fullMesh, const std::string &inFnameVtk, const std::string &outFnameNeu, const std::map< int, int > &faceTypeMap, const std::map< int, int > &nodeTypeMap, const std::map< int, bool > &nodeStructuralMap, const std::map< int, bool > &nodeMeshMotionMap, const std::map< int, bool > &nodeThermalMap, const std::vector< int > &nppItr)
std::map< int, bool > nodeMeshMotionMap
static std::shared_ptr< meshBase > CreateShared(const std::string &fname)
Create shared ptr from fname.
bool comparePatch(int i, int j)
void write1(std::ofstream &outputStream) const
std::map< int, int > nodeTypeMap
void write26(std::ofstream &outputStream) const
void write99(std::ofstream &outputStream) const
std::map< nemId_t, std::vector< int > > boundaryNodeId2PatchNo
void write6(std::ofstream &outputStream)
std::map< int, bool > nodeThermalMap
std::shared_ptr< meshBase > volMeshBase
std::shared_ptr< meshBase > fullMesh
T l2_Norm(const std::vector< T > &x)