Go to the documentation of this file.
59 const string SEPARATOR(
" -1");
61 bool isSeparator(
const std::string&
line)
63 return line.substr(0, 6) == SEPARATOR;
87 tag =
line.substr(0, 6);
89 }
while (tag == SEPARATOR);
104 if (isSeparator(
line))
127 if (isSeparator(
line))
135 scalar readUnvScalar(
const std::string& unvString)
139 s.replaceAll(
"d",
"E");
140 s.replaceAll(
"D",
"E");
142 return readScalar(
s);
164 string units(
line.substr(10, 20));
168 Info<<
"unitType:" << unitType <<
endl;
173 lengthScale = readUnvScalar(
line.substr(0, 25));
174 forceScale = readUnvScalar(
line.substr(25, 25));
175 tempScale = readUnvScalar(
line.substr(50, 25));
178 tempOffset = readUnvScalar(
line.substr(0, 25));
180 Info<<
"Unit factors:" <<
nl
181 <<
" Length scale : " << lengthScale <<
nl
182 <<
" Force scale : " << forceScale <<
nl
183 <<
" Temperature scale : " << tempScale <<
nl
184 <<
" Temperature offset : " << tempOffset <<
nl
199 static bool hasWarned =
false;
212 else if (pointi !=
points.size()+1 && !hasWarned)
217 <<
"Points not in order starting at point " << pointi
223 pt[0] = readUnvScalar(
line.substr(0, 25));
224 pt[1] = readUnvScalar(
line.substr(25, 25));
225 pt[2] = readUnvScalar(
line.substr(50, 25));
227 unvPointID.
append(pointi);
244 if (indizes.size() < (celli+1))
248 indizes[celli] = val;
268 label maxUnvPoint = 0;
269 forAll(unvPointID, pointi)
271 maxUnvPoint =
max(maxUnvPoint, unvPointID[pointi]);
289 if (isSeparator(
line))
294 label celli, feID, physProp, matProp, colour, nNodes;
298 >> celli >> feID >> physProp >> matProp >> colour >> nNodes;
300 if (foundFeType.
insert(feID))
302 Info<<
"First occurrence of element type " << feID
303 <<
" for cell " << celli <<
" at line "
313 else if (feID == 171)
318 else if (feID == 41 || feID == 91)
326 >> cVerts[0] >> cVerts[1] >> cVerts[2];
327 boundaryFaces.
append(cVerts);
328 boundaryFaceIndices.
append(celli);
330 else if (feID == 44 || feID == 94)
338 >> cVerts[0] >> cVerts[1] >> cVerts[2] >> cVerts[3];
339 boundaryFaces.
append(cVerts);
340 boundaryFaceIndices.
append(celli);
342 else if (feID == 111)
350 >> cVerts[0] >> cVerts[1] >> cVerts[2] >> cVerts[3];
353 cellMaterial.
append(physProp);
354 addAndExtend(cellCorrespondence,celli,cellMaterial.size()-1);
356 if (cellVerts.last().size() != cVerts.size())
359 <<
" element:" << celli
361 <<
" collapsed from " << cVerts <<
nl
362 <<
" to:" << cellVerts.last()
366 else if (feID == 112)
374 >> cVerts[0] >> cVerts[1] >> cVerts[2]
375 >> cVerts[3] >> cVerts[4] >> cVerts[5];
378 cellMaterial.
append(physProp);
379 addAndExtend(cellCorrespondence,celli,cellMaterial.size()-1);
381 if (cellVerts.last().size() != cVerts.size())
384 <<
" element:" << celli
386 <<
" collapsed from " << cVerts <<
nl
387 <<
" to:" << cellVerts.last()
391 else if (feID == 115)
399 >> cVerts[0] >> cVerts[1] >> cVerts[2] >> cVerts[3]
400 >> cVerts[4] >> cVerts[5] >> cVerts[6] >> cVerts[7];
403 cellMaterial.
append(physProp);
404 addAndExtend(cellCorrespondence,celli,cellMaterial.size()-1);
406 if (cellVerts.last().size() != cVerts.size())
409 <<
" element:" << celli
411 <<
" collapsed from " << cVerts <<
nl
412 <<
" to:" << cellVerts.last()
416 else if (feID == 118)
426 >> cVerts[0] >> dummy >> cVerts[1] >> dummy >> cVerts[2];
431 lineStr >> dummy>> cVerts[3];
435 cellMaterial.
append(physProp);
436 addAndExtend(cellCorrespondence,celli,cellMaterial.size()-1);
438 if (cellVerts.last().size() != cVerts.size())
441 <<
" element:" << celli
443 <<
" collapsed from " << cVerts <<
nl
444 <<
" to:" << cellVerts.last()
450 if (skippedElements.
insert(feID))
453 <<
"Cell type " << feID <<
" not supported" <<
endl;
463 boundaryFaceIndices.
shrink();
464 cellCorrespondence.
shrink();
466 Info<<
"Read " << cellVerts.size() <<
" cells"
467 <<
" and " << boundaryFaces.size() <<
" boundary faces." <<
endl;
469 if (!cellVerts.size())
472 <<
"There are no cells in the mesh." <<
endl
473 <<
" Note: 2D meshes are not supported."<<
endl;
485 Info<<
"Starting reading patches at line " << is.
lineNumber() <<
'.'
493 if (isSeparator(
line))
499 label
group, constraintSet, restraintSet, loadSet, dofSet,
500 tempSet, contactSet, nFaces;
502 >>
group >> constraintSet >> restraintSet >> loadSet
503 >> dofSet >> tempSet >> contactSet >> nFaces;
509 <<
" named " << groupName
510 <<
" trying to read " << nFaces <<
" patch face indices."
514 label groupType = -1;
517 while (nFaces < groupIndices.size())
524 if (nFaces == groupIndices.size()-1)
529 for (label i = 0; i < nRead; i++)
533 lineStr >> groupType >> tag >> nodeLeaf >>
component;
535 groupIndices[nFaces++] = tag;
544 patchFaceIndices.
append(groupIndices);
549 <<
"When reading patches expect entity type code 8"
550 <<
nl <<
" Skipping group code " << groupType
556 patchFaceIndices.
shrink();
569 Info<<
"Starting reading constraints at line " << is.
lineNumber() <<
'.'
589 <<
" trying to read vertex indices."
598 if (isSeparator(
line))
612 <<
" read " <<
vertices.size() <<
" vertex indices." <<
endl;
626 if (dofGroups[patchi].
found(
f[0]))
628 bool allInGroup =
true;
631 for (label fp = 1; fp <
f.size(); fp++)
633 if (!dofGroups[patchi].
found(
f[fp]))
651 int main(
int argc,
char *argv[])
655 "Convert I-Deas unv format to OpenFOAM"
662 "Dump boundary faces as boundaryFaces.obj (for debugging)"
674 <<
"Cannot open file " << ideasName
680 const bool verbose =
false;
683 scalar lengthScale = 1;
684 scalar forceScale = 1;
685 scalar tempScale = 1;
686 scalar tempOffset = 0;
708 while (inFile.good())
710 label tag = readTag(inFile);
717 Info<<
"Processing tag:" << tag <<
endl;
737 readPoints(inFile,
points, unvPointID);
773 Info<<
"Skipping tag " << tag <<
" on line "
774 << inFile.lineNumber() <<
endl;
783 label maxUnvPoint = 0;
784 forAll(unvPointID, pointi)
786 maxUnvPoint =
max(maxUnvPoint, unvPointID[pointi]);
800 static_cast<labelList&
>(cellVerts[celli])
804 if (foamVerts.found(-1))
808 <<
" unv vertices " << cellVerts[celli]
809 <<
" has some undefined vertices " << foamVerts
814 cellVerts[celli].
transfer(foamVerts);
819 forAll(boundaryFaces, bFacei)
823 if (foamVerts.found(-1))
826 <<
"Boundary face " << bFacei
827 <<
" unv vertices " << boundaryFaces[bFacei]
828 <<
" has some undefined vertices " << foamVerts
833 boundaryFaces[bFacei].
transfer(foamVerts);
853 forAll(boundaryFaces, facei)
856 faceToFaceID.insert(
face(sortedVerts), facei);
861 faceList faces = cellVerts[celli].faces();
865 const auto fnd = faceToFaceID.find(
face(sortedVerts));
889 if (own[facei] == -1 && nei[facei] != -1)
892 boundaryFaces[facei] = boundaryFaces[facei].reverseFace();
893 Swap(own[facei], nei[facei]);
899 Info <<
"Found " << nReverse <<
" reversed boundary faces out of "
900 << boundaryFaces.size() <<
endl;
907 if (own[facei] != -1 && nei[facei] != -1)
909 faceToCell[1].insert(facei, own[facei]);
910 faceToCell[0].insert(facei, nei[facei]);
917 Info <<
"Of " << boundaryFaces.size() <<
" so-called"
918 <<
" boundary faces " << cnt <<
" belong to two cells "
919 <<
"and are therefore internal" <<
endl;
927 if (dofVertIndices.size())
935 Info<<
"Using " << dofVertIndices.size()
936 <<
" DOF sets to detect boundary faces."<<
endl;
939 forAll(dofVertIndices, patchi)
948 forAll(dofVertIndices, patchi)
950 const labelList& foamVerts = dofVertIndices[patchi];
951 dofGroups[patchi].insert(foamVerts);
958 const cellShape& shape = cellVerts[celli];
964 label patchi = findPatch(dofGroups, shapeFaces[i]);
968 dynPatchFaces[patchi].append(shapeFaces[i]);
974 patchFaceVerts.
setSize(dynPatchFaces.size());
976 forAll(dynPatchFaces, patchi)
978 patchFaceVerts[patchi].
transfer(dynPatchFaces[patchi]);
987 patchFaceVerts.
setSize(patchFaceIndices.size());
989 Info<<
"Sorting boundary faces according to group (patch)" <<
endl;
996 Map<label> boundaryFaceToIndex(boundaryFaceIndices.size());
998 forAll(boundaryFaceIndices, i)
1000 boundaryFaceToIndex.insert(boundaryFaceIndices[i], i);
1003 forAll(patchFaceVerts, patchi)
1007 faceList& patchFaces = patchFaceVerts[patchi];
1008 const labelList& faceIndices = patchFaceIndices[patchi];
1010 patchFaces.
setSize(faceIndices.size());
1012 bool duplicateFaces =
false;
1017 if (boundaryFaceToIndex.found(faceIndices[i]))
1019 label bFacei = boundaryFaceToIndex[faceIndices[i]];
1021 if (own[bFacei] != -1 && nei[bFacei] == -1)
1023 patchFaces[cnt] = boundaryFaces[bFacei];
1025 if (alreadyOnBoundary.
found(bFacei))
1027 duplicateFaces =
true;
1033 if (cnt != patchFaces.size() || duplicateFaces)
1035 isAPatch[patchi] =
false;
1039 if (cnt != patchFaces.size())
1042 <<
"For patch " << patchi <<
" there were "
1043 << patchFaces.size()-cnt
1044 <<
" faces not used because they seem"
1045 <<
" to be internal. "
1046 <<
"This seems to be a face or a cell-zone"
1053 << patchi <<
" has faces that are already "
1054 <<
" in use on other boundary-patches,"
1055 <<
" Assuming faceZoneset." <<
endl;
1061 if (cellCorrespondence[faceIndices[0]] >= 0)
1067 if (cellCorrespondence[faceIndices[0]] < 0)
1070 <<
"The face index " << faceIndices[i]
1071 <<
" was not found amongst the cells."
1072 <<
" This kills the theory that "
1077 theCells[i] = cellCorrespondence[faceIndices[i]];
1087 theFaces[i] = boundaryFaceToIndex[faceIndices[i]];
1098 label bFacei = boundaryFaceToIndex[faceIndices[i]];
1099 alreadyOnBoundary.
insert(bFacei);
1106 polyPoints.transfer(
points);
1109 polyPoints /= lengthScale;
1115 Info<<
"Writing boundary faces to OBJ file boundaryFaces.obj"
1124 rawSurface.localPoints(),
1125 rawSurface.localFaces()
1130 Info<<
"\nConstructing mesh with non-default patches of size:" <<
nl;
1136 if (isAPatch[patchi])
1139 << patchFaceVerts[patchi].size() <<
nl;
1141 usedPatchFaceVerts.
append(patchFaceVerts[patchi]);
1145 usedPatchFaceVerts.
shrink();
1158 std::move(polyPoints),
1164 polyPatch::typeName,
1171 if (faceZones.
size() || cellZones.
size())
1173 Info <<
"Adding cell and face zones" <<
endl;
1179 if (cellZones.
size())
1196 if (faceZones.
size())
1210 << oldIndizes.size() <<
endl;
1214 const label old = oldIndizes[i];
1216 label
c1 = -1,
c2 = -1;
1217 if (faceToCell[0].
found(old))
1219 c1 = faceToCell[0][old];
1221 if (faceToCell[1].
found(old))
1223 c2 = faceToCell[1][old];
1238 const face&
f = boundaryFaces[old];
1239 if (
mag(centers[j]-
f.centre(
points)) < SMALL)
1253 (
c1 == own[j] &&
c2 == nei[j])
1254 || (
c2 == own[j] &&
c1 == nei[j])
1262 assert(noveau > -1);
1263 indizes[i] = noveau;
1267 faceZones.
toc()[cnt],
label size() const noexcept
The number of elements in table.
virtual const pointField & points() const
Return raw points.
Defines the attributes of an object for which implicit objectRegistry management is supported,...
void component(FieldField< Field, typename FieldField< Field, Type >::cmptType > &sf, const FieldField< Field, Type > &f, const direction d)
A class for handling words, derived from Foam::string.
ISstream & getLine(std::string &str, char delim='\n')
Raw, low-level getline (until delimiter) into a string.
A class for handling file names.
virtual bool write(const bool valid=true) const
Write mesh using IO settings from time.
gmvFile<< "tracers "<< particles.size()<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().x()<< " ";}gmvFile<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().y()<< " ";}gmvFile<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.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))
constexpr const char *const group
Group name for atomic constants.
List< Key > toc() const
The table of contents (the keys) in unsorted order.
static word defaultRegion
Return the default region name.
A class for managing temporary objects.
Input from file stream, using an ISstream.
static void addNote(const string ¬e)
Add extra notes for the usage information.
bool insert(const Key &key, const T &obj)
Copy insert a new entry, not overwriting existing entries.
const cellZoneMesh & cellZones() const
Return cell zone mesh.
static word validate(const std::string &s, const bool prefix=false)
Construct validated word (no invalid characters).
void append(const T &val)
Append an element at the end of the list.
Ostream & endl(Ostream &os)
Add newline and flush stream.
faceList faces() const
Faces of this cell.
DynamicList< T, SizeMin > & shrink()
Shrink the allocated space to the number of elements used.
void Swap(DynamicList< T, SizeMin1 > &a, DynamicList< T, SizeMin2 > &b)
labelList invert(const label len, const labelUList &map)
Create an inverse one-to-one mapping.
void inplaceRenumber(const labelUList &oldToNew, IntListType &input)
Inplace renumber the values (not the indices) of a list.
Mesh consisting of general polyhedral cells.
#define forAll(list, i)
Loop across all elements in list.
const faceZoneMesh & faceZones() const
Return face zone mesh.
static int compare(const face &a, const face &b)
Compare faces.
IOporosityModelList pZones(mesh)
List< word > wordList
A List of words.
static void addArgument(const string &argName, const string &usage="")
Append a (mandatory) argument to validArgs.
Ostream & flush(Ostream &os)
Flush stream.
const dimensionedScalar c1
First radiation constant: default SI units: [W/m2].
A subset of mesh faces organised as a primitive patch.
messageStream Info
Information stream (uses stdout - output is on the master only)
word name(const complex &c)
Return string representation of complex.
void removeFiles(const fileName &instanceDir) const
Remove all files from mesh instance.
DynamicList< T, SizeMin > & append(const T &val)
Append an element to the end of this list.
virtual const labelList & faceOwner() const
Return face owner.
void transfer(List< T > &list)
wordList patchNames(nPatches)
static const cellModel & ref(const modelType model)
Look up reference to cellModel by enumeration. Fatal on failure.
label max(const labelHashSet &set, label maxValue=labelMin)
Find the max value in labelHashSet, optionally limited by second argument.
pointField vertices(const blockVertexList &bvl)
A list that is sorted upon construction or when explicitly requested with the sort() method.
An analytical geometric cellShape.
Input from string buffer, using a ISstream.
errorManip< error > abort(error &err)
const dimensionedScalar c2
Second radiation constant: default SI units: [m.K].
void setSize(const label nElem)
Alter addressable list size.
errorManipArg< error, int > exit(error &err, const int errNo=1)
IOstream & hex(IOstream &io)
A HashTable similar to std::unordered_map.
static void addBoolOption(const word &optName, const string &usage="", bool advanced=false)
Add a bool option to validOptions with usage information.
IntListType renumber(const labelUList &oldToNew, const IntListType &input)
Renumber the values (not the indices) of a list.
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
fileName path() const
Return path.
static unsigned int defaultPrecision()
Return the default precision.
MeshedSurface< face > meshedSurface
label readLabel(const char *buf)
Parse entire buffer as a label, skipping leading/trailing whitespace.
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)
const vectorField & faceCentres() const
void transfer(List< T > &lst)
Transfer contents of the argument List into this.
bool insert(const Key &key)
Insert a new entry, not overwriting existing entries.
void write(vtk::formatter &fmt, const Type &val, const label n=1)
Component-wise write of a value (N times)
label lineNumber() const
Const access to the current stream line number.
A face is a list of labels corresponding to mesh vertices.
Maps a geometry to a set of cell primitives.
#define IOWarningInFunction(ios)
Report an IO warning using Foam::Warning.
static void noParallel()
Remove the parallel options.
bool good() const
Return true if next operation might succeed.
bool found(const Key &key) const
Return true if hashed entry is found in table.
void setSize(const label newSize)
Alias for resize(const label)
const word & constant() const
Return constant name.
Foam::argList args(argc, argv)
#define WarningInFunction
Report a warning using Foam::Warning.
void addZones(const List< pointZone * > &pz, const List< faceZone * > &fz, const List< cellZone * > &cz)
Add mesh zones.
virtual const labelList & faceNeighbour() const
Return face neighbour.
bool found(const word &optName) const
Return true if the named option is found.