68 const string SEPARATOR(
" -1");
70 bool isSeparator(
const string& line)
72 return line.substr(0, 6) == SEPARATOR;
96 tag = line.substr(0, 6);
98 }
while (tag == SEPARATOR);
113 if (isSeparator(line))
136 if (isSeparator(line))
144 scalar readUnvScalar(
const string& unvString)
148 s.replaceAll(
"d",
"E");
149 s.replaceAll(
"D",
"E");
173 string units(line.substr(10, 20));
177 Info<<
"unitType:" << unitType <<
endl;
182 lengthScale = readUnvScalar(line.substr(0, 25));
183 forceScale = readUnvScalar(line.substr(25, 25));
184 tempScale = readUnvScalar(line.substr(50, 25));
187 tempOffset = readUnvScalar(line.substr(0, 25));
189 Info<<
"Unit factors:" << nl
190 <<
" Length scale : " << lengthScale << nl
191 <<
" Force scale : " << forceScale << nl
192 <<
" Temperature scale : " << tempScale << nl
193 <<
" Temperature offset : " << tempOffset << nl
208 static bool hasWarned =
false;
221 else if (pointi != points.
size()+1 && !hasWarned)
228 ) <<
"Points not in order starting at point " << pointi
234 pt[0] = readUnvScalar(line.substr(0, 25));
235 pt[1] = readUnvScalar(line.substr(25, 25));
236 pt[2] = readUnvScalar(line.substr(50, 25));
238 unvPointID.
append(pointi);
255 if (indices.
size() < (celli+1))
259 indices[celli] = val;
279 label maxUnvPoint = 0;
280 forAll(unvPointID, pointi)
282 maxUnvPoint =
max(maxUnvPoint, unvPointID[pointi]);
300 if (isSeparator(line))
305 label celli, feID, physProp, matProp, colour, nNodes;
309 >> celli >> feID >> physProp >> matProp >> colour >> nNodes;
311 if (foundFeType.
insert(feID))
313 Info<<
"First occurrence of element type " << feID
314 <<
" for cell " << celli <<
" at line " 324 else if (feID == 171)
329 else if (feID == 41 || feID == 91)
337 >> cVerts[0] >> cVerts[1] >> cVerts[2];
338 boundaryFaces.
append(cVerts);
339 boundaryFaceIndices.
append(celli);
341 else if (feID == 44 || feID == 94)
349 >> cVerts[0] >> cVerts[1] >> cVerts[2] >> cVerts[3];
350 boundaryFaces.
append(cVerts);
351 boundaryFaceIndices.
append(celli);
353 else if (feID == 111)
361 >> cVerts[0] >> cVerts[1] >> cVerts[2] >> cVerts[3];
364 cellMaterial.
append(physProp);
365 addAndExtend(cellCorrespondence,celli,cellMaterial.
size()-1);
367 if (cellVerts.
last().
size() != cVerts.size())
370 <<
" element:" << celli
372 <<
" collapsed from " << cVerts << nl
373 <<
" to:" << cellVerts.
last()
377 else if (feID == 112)
385 >> cVerts[0] >> cVerts[1] >> cVerts[2]
386 >> cVerts[3] >> cVerts[4] >> cVerts[5];
389 cellMaterial.
append(physProp);
390 addAndExtend(cellCorrespondence,celli,cellMaterial.
size()-1);
392 if (cellVerts.
last().
size() != cVerts.size())
395 <<
" element:" << celli
397 <<
" collapsed from " << cVerts << nl
398 <<
" to:" << cellVerts.
last()
402 else if (feID == 115)
410 >> cVerts[0] >> cVerts[1] >> cVerts[2] >> cVerts[3]
411 >> cVerts[4] >> cVerts[5] >> cVerts[6] >> cVerts[7];
414 cellMaterial.
append(physProp);
415 addAndExtend(cellCorrespondence,celli,cellMaterial.
size()-1);
417 if (cellVerts.
last().
size() != cVerts.size())
420 <<
" element:" << celli
422 <<
" collapsed from " << cVerts << nl
423 <<
" to:" << cellVerts.
last()
427 else if (feID == 118)
437 >> cVerts[0] >> dummy >> cVerts[1] >> dummy >> cVerts[2];
442 lineStr >> dummy>> cVerts[3];
446 cellMaterial.
append(physProp);
447 addAndExtend(cellCorrespondence,celli,cellMaterial.
size()-1);
449 if (cellVerts.
last().
size() != cVerts.size())
452 <<
" element:" << celli
454 <<
" collapsed from " << cVerts << nl
455 <<
" to:" << cellVerts.
last()
461 if (skippedElements.
insert(feID))
464 <<
"Cell type " << feID <<
" not supported" <<
endl;
474 boundaryFaceIndices.
shrink();
475 cellCorrespondence.
shrink();
477 Info<<
"Read " << cellVerts.
size() <<
" cells" 478 <<
" and " << boundaryFaces.
size() <<
" boundary faces." <<
endl;
480 if (!cellVerts.
size())
483 <<
"There are no cells in the mesh." << endl
484 <<
" Note: 2D meshes are not supported."<<
endl;
496 Info<<
"Starting reading patches at line " << is.
lineNumber() <<
'.' 504 if (isSeparator(line))
510 label group, constraintSet, restraintSet, loadSet, dofSet,
511 tempSet, contactSet, nFaces;
513 >> group >> constraintSet >> restraintSet >> loadSet
514 >> dofSet >> tempSet >> contactSet >> nFaces;
517 word groupName = string::validate<word>(line);
519 Info<<
"For group " << group
520 <<
" named " << groupName
521 <<
" trying to read " << nFaces <<
" patch face indices." 525 label groupType = -1;
528 while (nFaces < groupIndices.size())
535 if (nFaces == groupIndices.size()-1)
540 for (
label i = 0; i < nRead; i++)
544 lineStr >> groupType >> tag >> nodeLeaf >>
component;
546 groupIndices[nFaces++] = tag;
554 patchNames.
append(groupName);
555 patchFaceIndices.
append(groupIndices);
560 <<
"When reading patches expect entity type code 8" 561 << nl <<
" Skipping group code " << groupType
567 patchFaceIndices.
shrink();
580 Info<<
"Starting reading constraints at line " << is.
lineNumber() <<
'.' 594 patchNames.
append(lineStr);
597 Info<<
"For DOF set " << group
598 <<
" named " << patchNames.
last()
599 <<
" trying to read vertex indices." 608 if (isSeparator(line))
620 Info<<
"For DOF set " << group
621 <<
" named " << patchNames.
last()
622 <<
" read " << vertices.
size() <<
" vertex indices." <<
endl;
636 if (dofGroups[patchi].
found(f[0]))
638 bool allInGroup =
true;
643 if (!dofGroups[patchi].
found(f[fp]))
661 int main(
int argc,
char *argv[])
668 "dump boundary faces as boundaryFaces.obj (for debugging)" 673 "specify the mesh region" 685 <<
"Cannot open file " << ideasName
690 const bool verbose =
false;
693 scalar lengthScale = 1;
694 scalar forceScale = 1;
695 scalar tempScale = 1;
696 scalar tempOffset = 0;
718 while (inFile.good())
720 label tag = readTag(inFile);
727 Info<<
"Processing tag:" << tag <<
endl;
747 readPoints(inFile, points, unvPointID);
783 Info<<
"Skipping tag " << tag <<
" on line " 784 << inFile.lineNumber() <<
endl;
793 label maxUnvPoint = 0;
794 forAll(unvPointID, pointi)
796 maxUnvPoint =
max(maxUnvPoint, unvPointID[pointi]);
810 static_cast<labelList&>(cellVerts[celli])
818 <<
" unv vertices " << cellVerts[celli]
819 <<
" has some undefined vertices " << foamVerts
824 cellVerts[celli].
transfer(foamVerts);
829 forAll(boundaryFaces, bFacei)
836 <<
"Boundary face " << bFacei
837 <<
" unv vertices " << boundaryFaces[bFacei]
838 <<
" has some undefined vertices " << foamVerts
843 boundaryFaces[bFacei].
transfer(foamVerts);
863 forAll(boundaryFaces, facei)
866 faceToFaceID.insert(
face(sortedVerts), facei);
871 faceList faces = cellVerts[celli].faces();
876 faceToFaceID.
find(
face(sortedVerts));
878 if (fnd != faceToFaceID.
end())
900 if (own[facei] == -1 && nei[facei] != -1)
903 boundaryFaces[facei] = boundaryFaces[facei].reverseFace();
904 Swap(own[facei], nei[facei]);
910 Info <<
"Found " << nReverse <<
" reversed boundary faces out of " 918 if (own[facei] != -1 && nei[facei] != -1)
920 faceToCell[1].insert(facei, own[facei]);
921 faceToCell[0].insert(facei, nei[facei]);
928 Info <<
"Of " << boundaryFaces.
size() <<
" so-called" 929 <<
" boundary faces " << cnt <<
" belong to two cells " 930 <<
"and are therefore internal" <<
endl;
938 if (dofVertIndices.
size())
946 Info<<
"Using " << dofVertIndices.
size()
947 <<
" DOF sets to detect boundary faces."<<
endl;
950 forAll(dofVertIndices, patchi)
959 forAll(dofVertIndices, patchi)
965 dofGroups[
patchi].insert(foamVerts[i]);
973 const cellShape& shape = cellVerts[celli];
979 label patchi = findPatch(dofGroups, shapeFaces[i]);
983 dynPatchFaces[
patchi].append(shapeFaces[i]);
989 patchFaceVerts.
setSize(dynPatchFaces.size());
991 forAll(dynPatchFaces, patchi)
1004 Info<<
"Sorting boundary faces according to group (patch)" <<
endl;
1013 forAll(boundaryFaceIndices, i)
1015 boundaryFaceToIndex.insert(boundaryFaceIndices[i], i);
1018 forAll(patchFaceVerts, patchi)
1027 bool duplicateFaces =
false;
1032 if (boundaryFaceToIndex.found(faceIndices[i]))
1034 label bFacei = boundaryFaceToIndex[faceIndices[i]];
1036 if (own[bFacei] != -1 && nei[bFacei] == -1)
1038 patchFaces[cnt] = boundaryFaces[bFacei];
1040 if (alreadyOnBoundary.
found(bFacei))
1042 duplicateFaces =
true;
1048 if (cnt != patchFaces.
size() || duplicateFaces)
1050 isAPatch[
patchi] =
false;
1054 if (cnt != patchFaces.
size())
1057 <<
"For patch " << patchi <<
" there were " 1058 << patchFaces.
size()-cnt
1059 <<
" faces not used because they seem" 1060 <<
" to be internal. " 1061 <<
"This seems to be a face or a cell-zone" 1068 << patchi <<
" has faces that are already " 1069 <<
" in use on other boundary-patches," 1070 <<
" Assuming faceZoneset." <<
endl;
1076 if (cellCorrespondence[faceIndices[0]] >= 0)
1082 if (cellCorrespondence[faceIndices[0]] < 0)
1085 <<
"The face index " << faceIndices[i]
1086 <<
" was not found amongst the cells." 1087 <<
" This kills the theory that " 1088 << patchNames[
patchi] <<
" is a cell zone" 1092 theCells[i] = cellCorrespondence[faceIndices[i]];
1094 cellZones.
insert(patchNames[patchi], theCells);
1102 theFaces[i] = boundaryFaceToIndex[faceIndices[i]];
1104 faceZones.
insert(patchNames[patchi],theFaces);
1113 label bFacei = boundaryFaceToIndex[faceIndices[i]];
1114 alreadyOnBoundary.
insert(bFacei);
1124 polyPoints /= lengthScale;
1130 Info<<
"Writing boundary faces to OBJ file boundaryFaces.obj" 1137 clone(boundaryFaces)
1143 clone(rawSurface.localPoints()),
1144 clone(rawSurface.localFaces())
1145 ).
write(runTime.path()/
"boundaryFaces.obj");
1149 Info<<
"\nConstructing mesh with non-default patches of size:" <<
nl;
1153 forAll(patchNames, patchi)
1155 if (isAPatch[patchi])
1159 usedPatchNames.
append(patchNames[patchi]);
1160 usedPatchFaceVerts.
append(patchFaceVerts[patchi]);
1164 usedPatchFaceVerts.
shrink();
1191 polyPatch::typeName,
1196 if (faceZones.
size() > 0 || cellZones.
size() > 0)
1198 Info <<
"Adding cell and face zones" <<
endl;
1204 if (cellZones.
size() > 0)
1208 word name = cellZones.
toc()[cnt];
1209 Info<<
" Cell Zone " << name <<
" " <<
tab 1221 if (faceZones.
size() > 0)
1230 word name = faceZones.
toc()[cnt];
1234 Info<<
" Face Zone " << name <<
" " <<
tab 1239 const label old = oldindices[i];
1242 if (faceToCell[0].
found(old))
1244 c1 = faceToCell[0][old];
1246 if (faceToCell[1].
found(old))
1248 c2 = faceToCell[1][old];
1263 const face& f = boundaryFaces[old];
1264 if (
mag(centers[j]- f.
centre(points)) < small)
1278 (c1 == own[j] &&
c2 == nei[j])
1279 || (
c2 == own[j] && c1 == nei[j])
1287 assert(nouveau > -1);
1288 indices[i] = nouveau;
1292 faceZones.
toc()[cnt],
ListType renumber(const labelUList &oldToNew, const ListType &)
Renumber the values (not the indices) of a list.
const char *const group
Group name for atomic constants.
#define forAll(list, i)
Loop across all elements in list.
layerAndWeight max(const layerAndWeight &a, const layerAndWeight &b)
FvWallInfoData< WallInfo, label > label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
static const cellModel * lookup(const word &)
Look up a model by name and return a pointer to the model or nullptr.
A class for handling file names.
void inplaceRenumber(const labelUList &oldToNew, ListType &)
Inplace renumber the values of a list.
errorManipArg< error, int > exit(error &err, const int errNo=1)
static iteratorEnd end()
iteratorEnd set to beyond the end of any HashTable
A face is a list of labels corresponding to mesh vertices.
const meshCellZones & cellZones() const
Return cell zones.
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
virtual const labelList & faceNeighbour() const
Return face neighbour.
A list that is sorted upon construction or when explicitly requested with the sort() method...
const T * cdata() const
Return a const pointer to the first data element,.
An analytical geometric cellShape.
void size(const label)
Override size to be inconsistent with allocated storage.
static word defaultRegion
Return the default region name.
Ostream & endl(Ostream &os)
Add newline and flush stream.
bool optionFound(const word &opt) const
Return true if the named option is found.
static void noParallel()
Remove the parallel options.
static SLList< string > validArgs
A list of valid (mandatory) arguments.
label lineNumber() const
Return current stream line number.
unsigned operator()(const PrimitiveType &p, unsigned seed) const
virtual bool write(const bool write=true) const
Write mesh using IO settings from time.
bool insert(const Key &key)
Insert a new entry.
bool good() const
Return true if next operation might succeed.
label size() const
Return number of elements in table.
const dimensionedScalar c2
Second radiation constant: default SI units: [m K].
virtual const pointField & points() const
Return raw points.
List< bool > boolList
Bool container classes.
bool insert(const Key &, const T &newElmt)
Insert a new hashedEntry.
iterator find(const Key &)
Find and return an iterator set at the hashedEntry.
const dimensionedScalar c1
First radiation constant: default SI units: [W/m^2].
pointField vertices(const blockVertexList &bvl)
gmvFile<< "tracers "<< particles.size()<< nl;forAllConstIter(Cloud< passiveParticle >, particles, iter){ gmvFile<< iter().position().x()<< " ";}gmvFile<< nl;forAllConstIter(Cloud< passiveParticle >, particles, iter){ gmvFile<< iter().position().y()<< " ";}gmvFile<< nl;forAllConstIter(Cloud< passiveParticle >, particles, iter){ gmvFile<< iter().position().z()<< " ";}gmvFile<< nl;forAll(lagrangianScalarNames, i){ word name=lagrangianScalarNames[i];IOField< scalar > s(IOobject(name, runTime.timeName(), cloud::prefix, mesh, IOobject::MUST_READ, IOobject::NO_WRITE))
faceList faces() const
Faces of this cell.
labelList invert(const label len, const labelUList &)
Invert one-to-one map. Unmapped elements will be -1.
void setSize(const label)
Alter the addressed list size.
A 1D vector of objects of type <T> that resizes itself as necessary to accept the new objects...
bool found(const Key &) const
Return true if hashedEntry is found in table.
A class for handling words, derived from string.
MeshedSurface< face > meshedSurface
static int compare(const face &, const face &)
Compare faces.
wordList patchNames(nPatches)
static void addOption(const word &opt, const string ¶m="", const string &usage="")
Add to an option to validOptions with usage information.
virtual const labelList & faceOwner() const
Return face owner.
DynamicList< T, SizeInc, SizeMult, SizeDiv > & append(const T &)
Append an element at the end of the list.
bool readScalar(const char *buf, doubleScalar &s)
Read whole of buf as a scalar. Return true if successful.
An STL-conforming hash table.
void addZones(const List< pointZone *> &pz, const List< faceZone *> &fz, const List< cellZone *> &cz)
Add mesh zones.
errorManip< error > abort(error &err)
label readLabel(Istream &is)
static void write(const fileName &, const MeshedSurface< Face > &)
Write to file.
DynamicList< T, SizeInc, SizeMult, SizeDiv > & shrink()
Shrink the allocated space to the number of elements used.
static vector centre(const PointField &ps)
Return centre point given face points.
label findIndex(const ListType &, typename ListType::const_reference, const label start=0)
Find first occurrence of given element and return index,.
word name(const complex &)
Return a string representation of a complex.
const vectorField & faceCentres() const
List< word > wordList
A List of words.
void setSize(const label)
Reset size of List.
unsigned Hasher(const void *data, size_t len, unsigned seed=0)
Bob Jenkins's 96-bit mixer hashing function (lookup3)
ISstream & getLine(string &, const bool continuation=true)
Read line into a string.
Ostream & flush(Ostream &os)
Flush stream.
#define WarningInFunction
Report a warning using Foam::Warning.
Input from memory buffer stream.
const meshFaceZones & faceZones() const
Return face zones.
Maps a geometry to a set of cell primitives, which enables geometric cell data to be calculated witho...
dimensioned< scalar > mag(const dimensioned< Type > &)
#define IOWarningInFunction(ios)
Report an IO warning using Foam::Warning.
Mesh consisting of general polyhedral cells.
static void addBoolOption(const word &opt, const string &usage="")
Add to a bool option to validOptions with usage information.
A subset of mesh faces organised as a primitive patch.
List< Key > toc() const
Return the table of contents.
A class for managing temporary objects.
T & last()
Return the last element of the list.
Foam::argList args(argc, argv)
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
void transfer(List< T > &)
Transfer contents of the argument List into this.
void component(FieldField< Field, typename FieldField< Field, Type >::cmptType > &sf, const FieldField< Field, Type > &f, const direction d)
void transfer(List< T > &)
Transfer the contents of the argument List into this list.
const string & option(const word &opt) const
Return the argument string associated with the named option.
IOporosityModelList pZones(mesh)