33 const char* Foam::meshWriters::STARCD::defaultBoundaryName =
34 "Default_Boundary_Region";
39 { 0, 1, 4, 5, 2, -1 },
40 { 5, 4, 2, 0, -1, -1 },
47 Foam::label Foam::meshWriters::STARCD::findDefaultBoundary()
const
66 void Foam::meshWriters::STARCD::getCellTable()
74 mesh_.time().constant(),
83 bool useCellZones =
false;
84 cellTableId_.setSize(mesh_.nCells(), -1);
87 if (ioList.headerOk())
89 if (ioList.size() == mesh_.nCells())
91 cellTableId_.transfer(ioList);
93 if (cellTable_.empty())
95 Info<<
"no cellTable information available" <<
endl;
101 << ioList.objectPath() <<
" has incorrect number of cells "
102 <<
" - use cellZone information"
117 if (cellTable_.empty())
119 Info<<
"created cellTable from cellZones" <<
endl;
124 label nUnzoned = mesh_.nCells();
127 Info<<
"matching cellZones to cellTable" <<
endl;
129 forAll(mesh_.cellZones(), zoneI)
131 const cellZone& cZone = mesh_.cellZones()[zoneI];
134 nUnzoned -= cZone.size();
136 label tableId = cellTable_.findIndex(cZone.name());
141 dict.add(
"Label", cZone.name());
142 dict.add(
"MaterialType",
"fluid");
143 tableId = cellTable_.append(
dict);
148 cellTableId_[cZone[i]] = tableId;
157 dict.add(
"Label",
"__unZonedCells__");
158 dict.add(
"MaterialType",
"fluid");
163 if (cellTableId_[i] < 0)
165 cellTableId_[i] = tableId;
173 void Foam::meshWriters::STARCD::writeHeader(Ostream& os,
const char* filetype)
175 os <<
"PROSTAR_" << filetype <<
nl
188 void Foam::meshWriters::STARCD::writePoints(
const fileName& prefix)
const
190 OFstream os(prefix +
".vrt");
197 os.setf(std::ios::showpoint);
201 Info<<
"Writing " << os.name() <<
" : "
209 << scaleFactor_ *
points[ptI].x() <<
" "
210 << scaleFactor_ *
points[ptI].y() <<
" "
211 << scaleFactor_ *
points[ptI].z() <<
nl;
218 void Foam::meshWriters::STARCD::writeCells(
const fileName& prefix)
const
220 OFstream os(prefix +
".cel");
225 Map<label> shapeLookupIndex;
226 shapeLookupIndex.insert(hexModel->index(), 11);
227 shapeLookupIndex.insert(prismModel->index(), 12);
228 shapeLookupIndex.insert(tetModel->index(), 13);
229 shapeLookupIndex.insert(pyrModel->index(), 14);
233 const faceList& faces = mesh_.faces();
234 const labelList& owner = mesh_.faceOwner();
236 Info<<
"Writing " << os.name() <<
" : "
242 label materialType = 1;
243 if (cellTable_.found(tableId))
245 const dictionary&
dict = cellTable_[tableId];
246 if (
dict.found(
"MaterialType"))
249 dict.lookup(
"MaterialType") >> matType;
250 if (matType ==
"solid")
258 const cellShape& shape = shapes[
cellId];
259 label mapIndex = shape.model().index();
262 if (shapeLookupIndex.found(mapIndex))
264 label shapeId = shapeLookupIndex[mapIndex];
269 <<
" " << vrtList.size()
271 <<
" " << materialType;
278 if ((
count % 8) == 0)
283 os <<
" " << vrtList[i] + 1;
295 List<label> indices(cFaces.size() + 1);
296 indices[0] = indices.size();
302 count += faces[cFaces[facei]].size();
303 indices[facei+1] =
count;
310 <<
" " << materialType;
317 if ((
count % 8) == 0)
322 os <<
" " << indices[i];
329 label meshFace = cFaces[facei];
332 if (owner[meshFace] ==
cellId)
338 f = faces[meshFace].reverseFace();
343 if ((
count % 8) == 0)
349 os <<
" " <<
f[i] + 1;
360 void Foam::meshWriters::STARCD::writeBoundary(
const fileName& prefix)
const
362 OFstream os(prefix +
".bnd");
367 const faceList& faces = mesh_.faces();
368 const labelList& owner = mesh_.faceOwner();
369 const polyBoundaryMesh&
patches = mesh_.boundaryMesh();
374 Map<label> faceLookupIndex;
375 faceLookupIndex.insert(hexModel->index(), 0);
376 faceLookupIndex.insert(prismModel->index(), 1);
377 faceLookupIndex.insert(tetModel->index(), 2);
378 faceLookupIndex.insert(pyrModel->index(), 3);
380 Info<<
"Writing " << os.name() <<
" : "
381 << (mesh_.nFaces() -
patches[0].start()) <<
" boundaries" <<
endl;
384 label defaultId = findDefaultBoundary();
393 if (regionId == defaultId)
397 else if (defaultId == -1 || regionId < defaultId)
408 label facei = patchStart;
409 facei < (patchStart + patchSize);
415 const cellShape& shape = shapes[
cellId];
429 label mapIndex = shape.model().index();
432 if (faceLookupIndex.found(mapIndex))
434 const faceList sFaces = shape.faces();
437 if (faces[facei] == sFaces[sFacei])
444 mapIndex = faceLookupIndex[mapIndex];
445 cellFaceId = foamToStarFaceAddr[mapIndex][cellFaceId];
454 <<
" " << cellFaceId + 1
457 <<
" " << bndType.c_str()
469 const scalar scaleFactor
490 rm(baseName +
".vrt");
491 rm(baseName +
".cel");
492 rm(baseName +
".bnd");
493 rm(baseName +
".inp");
501 if (baseName.empty())
507 mesh_.time().name() !=
"0"
508 && mesh_.time().name() != mesh_.time().constant()
511 baseName +=
"_" + mesh_.time().
name();
516 writePoints(baseName);
517 writeCells(baseName);
521 writeBoundary(baseName);
Functions used by OpenFOAM that are specific to POSIX compliant operating systems and need to be repl...
#define forAll(list, i)
Loop across all elements in list.
void readDict(const objectRegistry &, const word &name="boundaryRegion", const fileName &instance="constant")
Read constant/boundaryRegion.
void readDict(const objectRegistry &, const word &name="cellTable", const fileName &instance="constant")
Read constant/cellTable.
A class for handling file names.
word name() const
Return file name (part beyond last /)
write OpenFOAM meshes and/or results to another CFD format
boundaryRegion boundaryRegion_
boundaryRegion persistent data saved as a dictionary
cellTable cellTable_
cellTable persistent data saved as a dictionary
static string defaultMeshName
Specify a default mesh name.
const polyMesh & mesh_
Mesh reference.
virtual ~STARCD()
Destructor.
STARCD(const polyMesh &, const scalar scaleFactor=1.0)
Open a file for writing.
void rmFiles(const fileName &baseName) const
Remove STAR-CD files for the baseName.
virtual bool write(const fileName &meshName=fileName::null) const
Write volume mesh.
static const label foamToStarFaceAddr[4][6]
Face addressing from OpenFOAM faces -> pro-STAR faces.
Mesh consisting of general polyhedral cells.
const polyBoundaryMesh & boundaryMesh() const
Return boundary mesh.
static word meshSubDir
Return the mesh sub-directory name (usually "polyMesh")
const fvPatchList & patches
#define WarningInFunction
Report a warning using Foam::Warning.
void writeHeader(std::ostream &, const bool isBinary, const std::string &title)
Write header.
List< cellShape > cellShapeList
List of cellShapes and PtrList of List of cellShape.
List< label > labelList
A List of labels.
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
bool rm(const fileName &)
Remove a file, returning true if successful otherwise false.
List< cell > cellList
list of cells
Ostream & endl(Ostream &os)
Add newline and flush stream.
word name(const bool)
Return a word representation of a bool.
vectorField pointField
pointField is a vectorField.
label findIndex(const ListType &, typename ListType::const_reference, const label start=0)
Find first occurrence of given element and return index,.
label count(const ListType &l, typename ListType::const_reference x)
Count the number of occurrences of a value in a list.