34 const char* Foam::meshWriters::STARCD::defaultBoundaryName =
35 "Default_Boundary_Region";
40 { 0, 1, 4, 5, 2, -1 },
41 { 5, 4, 2, 0, -1, -1 },
48 Foam::label Foam::meshWriters::STARCD::findDefaultBoundary()
const
57 if (defaultBoundaryName == patches[patchI].
name())
67 void Foam::meshWriters::STARCD::getCellTable()
84 bool useCellZones =
false;
85 cellTableId_.setSize(mesh_.nCells(), -1);
88 if (ioList.headerOk())
90 if (ioList.size() == mesh_.nCells())
92 cellTableId_.transfer(ioList);
94 if (cellTable_.empty())
96 Info<<
"no cellTable information available" <<
endl;
102 << ioList.objectPath() <<
" has incorrect number of cells "
103 <<
" - use cellZone information"
118 if (cellTable_.empty())
120 Info<<
"created cellTable from cellZones" <<
endl;
125 label nUnzoned = mesh_.nCells();
128 Info<<
"matching cellZones to cellTable" <<
endl;
130 forAll (mesh_.cellZones(), zoneI)
132 const cellZone& cZone = mesh_.cellZones()[zoneI];
135 nUnzoned -= cZone.size();
137 label tableId = cellTable_.findIndex(cZone.name());
142 dict.add(
"Label", cZone.name());
143 dict.add(
"MaterialType",
"fluid");
144 tableId = cellTable_.append(dict);
149 cellTableId_[cZone[i]] = tableId;
158 dict.add(
"Label",
"__unZonedCells__");
159 dict.add(
"MaterialType",
"fluid");
160 label tableId = cellTable_.append(dict);
164 if (cellTableId_[i] < 0)
166 cellTableId_[i] = tableId;
174 void Foam::meshWriters::STARCD::writeHeader(Ostream& os,
const char* filetype)
176 os <<
"PROSTAR_" << filetype <<
nl
189 void Foam::meshWriters::STARCD::writePoints(
const fileName& prefix)
const
191 OFstream os(prefix +
".vrt");
192 writeHeader(os,
"VERTEX");
198 os.setf(std::ios::showpoint);
202 Info<<
"Writing " << os.name() <<
" : "
203 << points.size() <<
" points" <<
endl;
210 << scaleFactor_ * points[ptI].x() <<
" "
211 << scaleFactor_ * points[ptI].y() <<
" "
212 << scaleFactor_ * points[ptI].z() <<
nl;
219 void Foam::meshWriters::STARCD::writeCells(
const fileName& prefix)
const
221 OFstream os(prefix +
".cel");
222 writeHeader(os,
"CELL");
226 Map<label> shapeLookupIndex;
227 shapeLookupIndex.insert(hexModel->index(), 11);
228 shapeLookupIndex.insert(prismModel->index(), 12);
229 shapeLookupIndex.insert(tetModel->index(), 13);
230 shapeLookupIndex.insert(pyrModel->index(), 14);
234 const faceList& faces = mesh_.faces();
235 const labelList& owner = mesh_.faceOwner();
237 Info<<
"Writing " << os.name() <<
" : "
238 << cells.size() <<
" cells" <<
endl;
242 label tableId = cellTableId_[cellId];
243 label materialType = 1;
244 if (cellTable_.found(tableId))
246 const dictionary& dict = cellTable_[tableId];
247 if (dict.found(
"MaterialType"))
250 dict.lookup(
"MaterialType") >> matType;
251 if (matType ==
"solid")
259 const cellShape& shape = shapes[cellId];
260 label mapIndex = shape.model().index();
263 if (shapeLookupIndex.found(mapIndex))
265 label shapeId = shapeLookupIndex[mapIndex];
266 const labelList& vrtList = shapes[cellId];
270 <<
" " << vrtList.
size()
272 <<
" " << materialType;
279 if ((count % 8) == 0)
282 <<
" " << cellId + 1;
284 os <<
" " << vrtList[i] + 1;
296 List<label> indices(cFaces.size() + 1);
297 indices[0] = indices.
size();
299 label count = indices.size();
303 count += faces[cFaces[faceI]].size();
304 indices[faceI+1] = count;
311 <<
" " << materialType;
318 if ((count % 8) == 0)
321 <<
" " << cellId + 1;
323 os <<
" " << indices[i];
330 label meshFace = cFaces[faceI];
333 if (owner[meshFace] == cellId)
339 f = faces[meshFace].reverseFace();
344 if ((count % 8) == 0)
347 <<
" " << cellId + 1;
350 os <<
" " << f[i] + 1;
361 void Foam::meshWriters::STARCD::writeBoundary(
const fileName& prefix)
const
363 OFstream os(prefix +
".bnd");
364 writeHeader(os,
"BOUNDARY");
367 const cellList& cells = mesh_.cells();
368 const faceList& faces = mesh_.faces();
369 const labelList& owner = mesh_.faceOwner();
370 const polyBoundaryMesh& patches = mesh_.boundaryMesh();
375 Map<label> faceLookupIndex;
376 faceLookupIndex.insert(hexModel->index(), 0);
377 faceLookupIndex.insert(prismModel->index(), 1);
378 faceLookupIndex.insert(tetModel->index(), 2);
379 faceLookupIndex.insert(pyrModel->index(), 3);
381 Info<<
"Writing " << os.name() <<
" : "
382 << (mesh_.nFaces() - patches[0].start()) <<
" boundaries" << endl;
385 label defaultId = findDefaultBoundary();
393 label regionId = patchI;
394 if (regionId == defaultId)
398 else if (defaultId == -1 || regionId < defaultId)
403 label patchStart = patches[patchI].start();
404 label patchSize = patches[patchI].size();
405 word bndType = boundaryRegion_.boundaryType(patches[patchI].
name());
409 label faceI = patchStart;
410 faceI < (patchStart + patchSize);
414 label cellId = owner[faceI];
416 const cellShape& shape = shapes[cellId];
417 label cellFaceId =
findIndex(cFaces, faceI);
430 label mapIndex = shape.model().index();
433 if (faceLookupIndex.found(mapIndex))
435 const faceList sFaces = shape.faces();
438 if (faces[faceI] == sFaces[sFaceI])
445 mapIndex = faceLookupIndex[mapIndex];
446 cellFaceId = foamToStarFaceAddr[mapIndex][cellFaceId];
455 <<
" " << cellFaceId + 1
458 <<
" " << bndType.c_str()
467 Foam::meshWriters::STARCD::STARCD
470 const scalar scaleFactor
475 boundaryRegion_.readDict(mesh_);
476 cellTable_.readDict(mesh_);
491 rm(baseName +
".vrt");
492 rm(baseName +
".cel");
493 rm(baseName +
".bnd");
494 rm(baseName +
".inp");
502 if (baseName.empty())
508 mesh_.time().timeName() !=
"0"
509 && mesh_.time().timeName() !=
"constant"
512 baseName +=
"_" + mesh_.time().timeName();
517 writePoints(baseName);
518 writeCells(baseName);
522 writeBoundary(baseName);
532 const bool& triangulate
537 if (baseName.empty())
543 mesh_.time().timeName() !=
"0"
544 && mesh_.time().timeName() !=
"constant"
547 baseName +=
"_" + mesh_.time().timeName();
553 OFstream celFile(baseName +
".cel");
554 writeHeader(celFile,
"CELL");
560 const labelList& owner = mesh_.faceOwner();
561 const faceList& meshFaces = mesh_.faces();
579 label patchStart = patches[patchI].start();
580 label patchSize = patches[patchI].
size();
582 label ctableId = patchI + 1;
586 label faceI = patchStart;
587 faceI < (patchStart + patchSize);
591 const face& f = meshFaces[faceI];
611 const labelList& vrtList = triFaces[faceI];
616 << vrtList.
size() <<
" "
624 if ((count % 8) == 0)
628 <<
" " << cellId + 1;
631 pointHash.
insert(vrtList[i]);
632 celFile <<
" " << vrtList[i] + 1;
649 label patchStart = patches[patchI].start();
650 label patchSize = patches[patchI].
size();
654 label faceI = patchStart;
655 faceI < (patchStart + patchSize);
659 const labelList& vrtList = meshFaces[faceI];
660 label cellId = faceI;
665 << vrtList.
size() <<
" "
666 << cellTableId_[owner[faceI]] <<
" "
673 if ((count % 8) == 0)
677 <<
" " << cellId + 1;
680 pointHash.
insert(vrtList[i]);
681 celFile <<
" " << vrtList[i] + 1;
689 OFstream vrtFile(baseName +
".vrt");
690 writeHeader(vrtFile,
"VERTEX");
693 vrtFile.
setf(std::ios::showpoint);
703 toc[i++] = iter.key();
713 label vrtId = toc[i];
716 <<
" " << scaleFactor_ * points[vrtId].x()
717 <<
" " << scaleFactor_ * points[vrtId].y()
718 <<
" " << scaleFactor_ * points[vrtId].z()