61 for (i=ts.
size()-1; i>=0; i--)
74 for (
label j=i; j>=0; j--)
76 if (
isFile(d.
path()/ts[j].name()/typeName/foamName))
80 Pout<<
" triSurface::triSurfInstance(const Time& d)"
81 <<
"reading " << foamName
82 <<
" from " << ts[j].name()/typeName
93 Pout<<
" triSurface::triSurfInstance(const Time& d)"
94 <<
"reading " << foamName
95 <<
" from constant/" <<
endl;
104 const label defaultRegion
111 const face&
f = faces[facei];
116 <<
"Face at position " << facei
117 <<
" does not have three vertices:" <<
f
121 labelledTri& tri = triFaces[facei];
126 tri.region() = defaultRegion;
136 const label defaultRegion
139 List<labelledTri> triFaces(faces.size());
145 labelledTri& tri = triFaces[facei];
150 tri.region() = defaultRegion;
159 void Foam::triSurface::printTriangle
163 const labelledTri&
f,
168 << pre.c_str() <<
"vertex numbers:"
169 <<
f[0] <<
' ' <<
f[1] <<
' ' <<
f[2] <<
endl
170 << pre.c_str() <<
"vertex coords :"
172 << pre.c_str() <<
"region :" <<
f.region() <<
endl
177 Foam::string Foam::triSurface::getLineNoComment(IFstream& is)
184 while ((line.empty() || line[0] ==
'#') && is.good());
190 Foam::scalar Foam::triSurface::pointNormalWeight
218 tmp<vectorField> tpointNormals
226 const labelList& meshPoints = this->meshPoints();
235 const triFace&
f = operator[](facei);
238 const scalar weight =
239 pointNormalWeight(
f, meshPoints[
pi], fa,
points);
241 pointNormals[
pi] += weight*fa;
244 pointNormals[
pi] /=
mag(pointNormals[
pi]) + vSmall;
247 return tpointNormals;
257 triadField& pointCoordSys = tpointCoordSys.ref();
260 const labelList& meshPoints = this->meshPoints();
265 const vector& normal = pointNormals[
pi];
267 if (
mag(normal) < small)
279 vector dir2 = dir1 ^ normal;
282 pointCoordSys[
pi] = triad(dir1, dir2, normal);
285 return pointCoordSys;
289 bool Foam::triSurface::read(Istream& is)
291 is >> patches_ >> storedPoints() >> storedFaces();
297 bool Foam::triSurface::read
299 const fileName&
name,
312 fileName unzipName =
name.lessExt();
315 return read(unzipName, unzipName.ext(),
false);
317 else if (ext ==
"ftr")
321 else if (ext ==
"stl")
323 return readSTL(
name);
325 else if (ext ==
"stlb")
327 return readSTLBINARY(
name);
329 else if (ext ==
"gts")
331 return readGTS(
name);
333 else if (ext ==
"obj")
335 return readOBJ(
name);
337 else if (ext ==
"off")
339 return readOFF(
name);
341 else if (ext ==
"tri")
343 return readTRI(
name);
345 else if (ext ==
"ac")
349 else if (ext ==
"nas")
351 return readNAS(
name);
353 else if (ext ==
"vtk")
355 return readVTK(
name);
360 <<
"unknown file extension " << ext
361 <<
". Supported extensions are '.ftr', '.stl', '.stlb', '.gts'"
362 <<
", '.obj', '.ac', '.off', '.nas', '.tri' and '.vtk'"
370 void Foam::triSurface::write
372 const fileName&
name,
381 else if (ext ==
"stl")
383 return writeSTLASCII(
sort, OFstream(
name)());
385 else if (ext ==
"stlb")
387 ofstream outFile(
name.c_str(), std::ios::binary);
389 writeSTLBINARY(outFile);
391 else if (ext ==
"gts")
393 return writeGTS(
sort, OFstream(
name)());
395 else if (ext ==
"obj")
399 else if (ext ==
"off")
403 else if (ext ==
"vtk")
407 else if (ext ==
"tri")
411 else if (ext ==
"ac")
413 writeAC(OFstream(
name)());
415 else if (ext ==
"smesh")
422 <<
"unknown file extension " << ext
423 <<
" for file " <<
name
424 <<
". Supported extensions are '.ftr', '.stl', '.stlb', "
425 <<
"'.gts', '.obj', '.vtk'"
426 <<
", '.off', '.dx', '.smesh', '.ac' and '.tri'"
435 SortableList<label> sortedRegion(size());
437 forAll(sortedRegion, facei)
439 sortedRegion[facei] = operator[](facei).region();
443 faceMap = sortedRegion.indices();
446 label maxRegion = patches_.size()-1;
453 operator[](
faceMap.last()).region()
463 label region = operator[](facei).region();
465 newPatches[region].size()++;
471 label startFacei = 0;
472 forAll(newPatches, newPatchi)
474 surfacePatch& newPatch = newPatches[newPatchi];
476 newPatch.index() = newPatchi;
478 label oldPatchi = newPatchi;
481 newPatch.start() = startFacei;
485 if ((oldPatchi < patches_.size()) && (patches_[oldPatchi].name() !=
""))
487 newPatch.name() = patches_[oldPatchi].name();
491 newPatch.name() = word(
"patch") +
name(newPatchi);
496 (oldPatchi < patches_.size())
497 && (patches_[oldPatchi].geometricType() !=
"")
500 newPatch.geometricType() = patches_[oldPatchi].geometricType();
504 newPatch.geometricType() =
"empty";
507 startFacei += newPatch.size();
514 void Foam::triSurface::setDefaultPatches()
522 patches_.setSize(newPatches.size());
528 patches_[
patchi].geometricType() = newPatches[
patchi].geometricType();
539 sortedEdgeFacesPtr_(nullptr),
540 edgeOwnerPtr_(nullptr)
553 sortedEdgeFacesPtr_(nullptr),
554 edgeOwnerPtr_(nullptr)
568 sortedEdgeFacesPtr_(nullptr),
569 edgeOwnerPtr_(nullptr)
582 sortedEdgeFacesPtr_(nullptr),
583 edgeOwnerPtr_(nullptr)
595 sortedEdgeFacesPtr_(nullptr),
596 edgeOwnerPtr_(nullptr)
610 sortedEdgeFacesPtr_(nullptr),
611 edgeOwnerPtr_(nullptr)
621 sortedEdgeFacesPtr_(nullptr),
622 edgeOwnerPtr_(nullptr)
636 sortedEdgeFacesPtr_(nullptr),
637 edgeOwnerPtr_(nullptr)
649 sortedEdgeFacesPtr_(nullptr),
650 edgeOwnerPtr_(nullptr)
668 sortedEdgeFacesPtr_(nullptr),
669 edgeOwnerPtr_(nullptr)
677 sortedEdgeFacesPtr_(nullptr),
678 edgeOwnerPtr_(nullptr)
694 ParentType::clearTopology();
702 ParentType::clearPatchMeshAddr();
708 ParentType::clearOut();
711 clearPatchMeshAddr();
717 if (!sortedEdgeFacesPtr_)
719 calcSortedEdgeFaces();
722 return *sortedEdgeFacesPtr_;
733 return *edgeOwnerPtr_;
743 ParentType::clearGeom();
746 storedPoints() = newPoints;
753 if (scaleFactor > 0 && scaleFactor != 1.0)
759 ParentType::clearGeom();
761 storedPoints() *= scaleFactor;
777 if (
f[fp] < 0 ||
f[fp] > maxPointi)
781 <<
" uses point indices outside point range 0.."
795 bool hasInvalid =
false;
801 if ((
f[0] ==
f[1]) || (
f[0] ==
f[2]) || (
f[1] ==
f[2]))
804 valid[facei] =
false;
810 <<
"triangle " << facei
811 <<
" does not have three unique vertices:\n";
818 const labelList& fEdges = faceEdges()[facei];
825 const labelList& eFaces = edgeFaces()[fEdges[fp]];
829 label neighbour = eFaces[i];
831 if (neighbour > facei)
838 ((
f[0] ==
n[0]) || (
f[0] ==
n[1]) || (
f[0] ==
n[2]))
839 && ((
f[1] ==
n[0]) || (
f[1] ==
n[1]) || (
f[1] ==
n[2]))
840 && ((
f[2] ==
n[0]) || (
f[2] ==
n[1]) || (
f[2] ==
n[2]))
843 valid[facei] =
false;
849 <<
"triangles share the same vertices:\n"
850 <<
" face 1 :" << facei <<
endl;
856 << neighbour <<
endl;
877 (*this)[newFacei++] =
f;
884 <<
"Removing " << size() - newFacei
885 <<
" illegal faces." <<
endl;
887 (*this).setSize(newFacei);
901 const labelList& myFaces = eFaces[edgeI];
906 <<
"Edge " << edgeI <<
" with vertices " << edges()[edgeI]
907 <<
" has no edgeFaces"
910 else if (myFaces.
size() > 2 && verbose)
913 <<
"Edge " << edgeI <<
" with vertices " << edges()[edgeI]
914 <<
" has more than 2 faces connected to it : " << myFaces
924 stitchTriangles(small, verbose);
929 checkTriangles(verbose);
939 const label currentZone,
953 label facei = changedFaces[i];
955 const labelList& fEdges = faceEdges()[facei];
959 label edgeI = fEdges[i];
961 if (!borderEdge[edgeI])
963 const labelList& eFaces = edgeFaces()[edgeI];
967 label nbrFacei = eFaces[j];
972 newChangedFaces.
append(nbrFacei);
974 else if (
faceZone[nbrFacei] != currentZone)
978 <<
" at face " << nbrFacei
979 <<
" connects to zone " << currentZone
980 <<
" at face " << facei
988 if (newChangedFaces.
empty())
993 changedFaces.
transfer(newChangedFaces);
1007 if (borderEdge.
size() != nEdges())
1010 <<
"borderEdge boolList not same size as number of edges" <<
endl
1011 <<
"borderEdge:" << borderEdge.
size() <<
endl
1012 <<
"nEdges :" << nEdges()
1018 for (
label startFacei = 0;; zoneI++)
1021 for (; startFacei < size(); startFacei++)
1029 if (startFacei >= size())
1036 markZone(borderEdge, startFacei, zoneI,
faceZone);
1061 forAll(include, oldFacei)
1063 if (include[oldFacei])
1074 if (!pointHad[labI])
1076 pointHad[labI] =
true;
1077 pointMap[pointi++] = labI;
1100 subsetMeshMap(include, pointMap,
faceMap);
1108 newPoints[pointi] = locPoints[pointMap[pointi]];
1109 oldToNew[pointMap[pointi]] = pointi;
1120 newTriangles[facei][0] = oldToNew[tri[0]];
1121 newTriangles[facei][1] = oldToNew[tri[1]];
1122 newTriangles[facei][2] = oldToNew[tri[2]];
1123 newTriangles[facei].region() = tri.
region();
1137 faces[facei] = operator[](facei).triFaceFace();
1151 const labelList& meshPoints = this->meshPoints();
1152 const Map<label>& meshPointMap = this->meshPointMap();
1156 this->weightedPointNormals()
1161 this->pointCoordSys(pointNormals)
1181 const edge&
e = fEdges[feI];
1183 edgeVectors[feI] =
e.vec(
points);
1184 normalDifferences[feI] =
1185 pointNormals[meshPointMap[
e[0]]]
1186 - pointNormals[meshPointMap[
e[1]]];
1190 const vector& e0 = edgeVectors[0];
1192 const vector e1 = (e0 ^ eN);
1194 if (
magSqr(eN) < rootVSmall)
1199 triad faceCoordSys(e0, e1, eN);
1207 for (
label i = 0; i < 3; ++i)
1209 const scalar
x = edgeVectors[i] & faceCoordSys[0];
1210 const scalar
y = edgeVectors[i] & faceCoordSys[1];
1218 const scalar dndx = normalDifferences[i] & faceCoordSys[0];
1219 const scalar dndy = normalDifferences[i] & faceCoordSys[1];
1222 Z[1] += dndx*
y + dndy*
x;
1229 const symmTensor2D secondFundamentalTensor(Z[0], Z[1], Z[2]);
1235 const label patchPointIndex = meshPointMap[
f[fpi]];
1237 const triad& ptCoordSys = pointCoordSys[patchPointIndex];
1239 if (!ptCoordSys.
set())
1250 const triad rotatedFaceCoordSys = rotTensor &
tensor(faceCoordSys);
1256 ptCoordSys[0] & rotatedFaceCoordSys[0],
1257 ptCoordSys[0] & rotatedFaceCoordSys[1]
1261 ptCoordSys[1] & rotatedFaceCoordSys[0],
1262 ptCoordSys[1] & rotatedFaceCoordSys[1]
1273 projTensor.
x() & (secondFundamentalTensor & projTensor.
x()),
1274 projTensor.
x() & (secondFundamentalTensor & projTensor.
y()),
1275 projTensor.
y() & (secondFundamentalTensor & projTensor.
y())
1279 const scalar weight = pointNormalWeight
1282 meshPoints[patchPointIndex],
1288 pointFundamentalTensors[patchPointIndex] +=
1289 weight*projectedFundamentalTensor;
1291 accumulatedWeights[patchPointIndex] += weight;
1297 pointFundamentalTensors[
pi] /= (accumulatedWeights[
pi] + small);
1299 const vector2D principalCurvatures =
1304 const scalar curvature =
max
1306 mag(principalCurvatures[0]),
1307 mag(principalCurvatures[1])
1311 curvaturePointField[meshPoints[
pi]] = curvature;
1314 return tcurvaturePointField;
1318 void Foam::triSurface::write
1321 const bool sortByRegion
1337 os.
check(
"triSurface::write(Ostream&)");
1341 void Foam::triSurface::write(
const Time& d)
const
1345 fileName foamPath(d.
path()/triSurfInstance(d)/typeName/foamFile);
1369 if (pointIsUsed.
set(pointi, 1))
1378 os <<
"Triangles : " << size() <<
endl
1380 <<
"Bounding Box : " << bb <<
endl;
1390 storedPoints() = ts.
points();
1399 storedPoints() = move(ts.points());
1400 patches_ = move(ts.patches());
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.
DynamicList< T, SizeInc, SizeMult, SizeDiv > & append(const T &)
Append an element at the end of the list.
virtual bool check(const char *operation) const
Check IOstream status for given operation.
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
void transfer(List< T > &)
Transfer the contents of the argument List into this list.
void size(const label)
Override size to be inconsistent with allocated storage.
void operator=(const UList< T > &)
Assignment to UList operator. Takes linear time.
void setSize(const label)
Reset size of List.
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
void set(const PackedList< 1 > &)
Set specified bits.
const Field< PointType > & points() const
Return reference to global points.
std::remove_reference< ::Foam::List< labelledTri > >::type::value_type FaceType
Templated 2D symmetric tensor derived from VectorSpace adding construction from 4 components,...
A templated 2D square symmetric matrix of objects of <T>, where the n x n matrix dimension is known a...
Templated 2D tensor derived from VectorSpace adding construction from 4 components,...
Vector2D< Cmpt > y() const
Vector2D< Cmpt > x() const
static const word & constant()
Return constant name.
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
instantList times() const
Search the case for valid time directories.
fileName path() const
Explicitly inherit path from TimePaths to disambiguate from.
scalar userTimeValue() const
Return current user time value.
const fileName & caseName() const
Explicitly inherit caseName from TimePaths to disambiguate from.
label rcIndex(const label i) const
Return the reverse circular index, i.e. the previous index.
label fcIndex(const label i) const
Return the forward circular index, i.e. the next index.
bool empty() const
Return true if the UList is empty (ie, size() is zero)
A bounding box defined in terms of the points at its extremities.
const point & min() const
Minimum point defining the bounding box.
const point & max() const
Maximum point defining the bounding box.
static const boundBox invertedBox
A very large inverted boundBox: min/max == +/- vGreat.
An edge is a list of two point labels. The functionality it provides supports the discretisation on a...
A subset of mesh faces organised as a primitive patch.
A face is a list of labels corresponding to mesh vertices.
A class for handling file names.
Triangle with additional region number.
label region() const
Return region label.
A class for handling character strings derived from std::string.
A class for managing temporary objects.
T & ref() const
Return non-const reference or generate a fatal error.
A triangular face using a FixedList of labels corresponding to mesh vertices.
Triangulated surface description with patch information.
virtual void scalePoints(const scalar)
Scale points. A non-positive factor is ignored.
static fileName triSurfInstance(const Time &)
Name of triSurface directory to use.
triSurface()
Construct null.
triSurface subsetMesh(const boolList &include, labelList &pointMap, labelList &faceMap) const
Return new surface. Returns pointMap, faceMap from.
label markZones(const boolList &borderEdge, labelList &faceZone) const
(size and) fills faceZone with zone of face. Zone is area
tmp< scalarField > curvature() const
Return the curvature of surface at the points.
void operator=(const triSurface &)
void cleanup(const bool verbose)
Remove non-valid triangles.
const geometricSurfacePatchList & patches() const
void checkTriangles(const bool verbose)
Check/remove duplicate/degenerate triangles.
void checkEdges(const bool verbose)
Check triply (or more) connected edges.
void markZone(const boolList &borderEdge, const label facei, const label currentZone, labelList &faceZone) const
Fill faceZone with currentZone for every face reachable.
void writeStats(Ostream &) const
Write some statistics.
faceList faces() const
Return the list of triangles as a faceList.
const labelList & edgeOwner() const
If 2 face neighbours: label of face where ordering of edge.
void subsetMeshMap(const boolList &include, labelList &pointMap, labelList &faceMap) const
'Create' sub mesh, including only faces for which
void clearPatchMeshAddr()
const labelListList & sortedEdgeFaces() const
Return edge-face addressing sorted (for edges with more than.
virtual ~triSurface()
Destructor.
virtual void setPoints(const pointField &)
Move points.
Representation of a 3D Cartesian coordinate system as a Vector of vectors.
bool set(const direction d) const
Is the vector in the direction d set.
void normalise()
Normalise each set axis vector to have a unit magnitude.
A class for handling words, derived from string.
Template functions to aid in the implementation of demand driven data.
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
const fvPatchList & patches
#define WarningInFunction
Report a warning using Foam::Warning.
bool valid(const PtrList< ModelType > &l)
void write(std::ostream &os, const bool binary, List< floatScalar > &fField)
Write floats ascii or binary.
bool isFile(const fileName &, const bool checkVariants=true, const bool followLink=true)
Does the name exist as a file in the file system?
errorManipArg< error, int > exit(error &err, const int errNo=1)
bool read(const char *, int32_t &)
tensor rotationTensor(const vector &n1, const vector &n2)
Rotational transformation tensor from unit vector n1 to n2.
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.
dimensionedSymmTensor sqr(const dimensionedVector &dv)
Tensor< scalar > tensor
Tensor of scalars.
Ostream & endl(Ostream &os)
Add newline and flush stream.
word name(const bool)
Return a word representation of a bool.
void deleteDemandDrivenData(DataType *&dataPtr)
errorManip< error > abort(error &err)
bool exists(const fileName &, const bool checkVariants=true, const bool followLink=true)
Does the name exist (as directory or file) in the file system?
vectorField pointField
pointField is a vectorField.
vector point
Point is a vector.
Field< triad > triadField
Specialisation of Field<T> for triad.
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
layerAndWeight min(const layerAndWeight &a, const layerAndWeight &b)
List< triFace > triFaceList
list of triFaces
Vector< scalar > vector
A scalar version of the templated Vector.
List< labelList > labelListList
A List of labelList.
dimensioned< scalar > mag(const dimensioned< Type > &)
defineTypeNameAndDebug(combustionModel, 0)
dimensionedVector eigenValues(const dimensionedTensor &dt)
layerAndWeight max(const layerAndWeight &a, const layerAndWeight &b)
Field< vector > vectorField
Specialisation of Field<T> for vector.
Pair< int > faceMap(const label facePi, const face &faceP, const label faceNi, const face &faceN)
void writeVTK(OFstream &os, const Type &value)
prefixOSstream Pout(cout, "Pout")
label findIndex(const ListType &, typename ListType::const_reference, const label start=0)
Find first occurrence of given element and return index,.
Ostream & operator<<(Ostream &os, const fvConstraints &constraints)
void LUsolve(scalarSquareMatrix &matrix, List< Type > &source)
Solve the matrix using LU decomposition with pivoting.
void T(FieldField< Field, Type > &f1, const FieldField< Field, Type > &f2)
dimensioned< scalar > magSqr(const dimensioned< Type > &)
List< surfacePatch > surfacePatchList
Info<< "Finished reading KIVA file"<< endl;cellShapeList cellShapes(nPoints);labelList cellZoning(nPoints, -1);const cellModel &hex=*(cellModeller::lookup("hex"));labelList hexLabels(8);label activeCells=0;labelList pointMap(nPoints);forAll(pointMap, i){ pointMap[i]=i;}for(label i=0;i< nPoints;i++){ if(f[i] > 0.0) { hexLabels[0]=i;hexLabels[1]=i1tab[i];hexLabels[2]=i3tab[i1tab[i]];hexLabels[3]=i3tab[i];hexLabels[4]=i8tab[i];hexLabels[5]=i1tab[i8tab[i]];hexLabels[6]=i3tab[i1tab[i8tab[i]]];hexLabels[7]=i3tab[i8tab[i]];cellShapes[activeCells]=cellShape(hex, hexLabels);edgeList edges=cellShapes[activeCells].edges();forAll(edges, ei) { if(edges[ei].mag(points)< small) { label start=pointMap[edges[ei].start()];while(start !=pointMap[start]) { start=pointMap[start];} label end=pointMap[edges[ei].end()];while(end !=pointMap[end]) { end=pointMap[end];} label minLabel=min(start, end);pointMap[start]=pointMap[end]=minLabel;} } cellZoning[activeCells]=idreg[i];activeCells++;}}cellShapes.setSize(activeCells);cellZoning.setSize(activeCells);forAll(cellShapes, celli){ cellShape &cs=cellShapes[celli];forAll(cs, i) { cs[i]=pointMap[cs[i]];} cs.collapse();}label bcIDs[11]={-1, 0, 2, 4, -1, 5, -1, 6, 7, 8, 9};const label nBCs=12;const word *kivaPatchTypes[nBCs]={ &wallPolyPatch::typeName, &wallPolyPatch::typeName, &wallPolyPatch::typeName, &wallPolyPatch::typeName, &symmetryPolyPatch::typeName, &wedgePolyPatch::typeName, &polyPatch::typeName, &polyPatch::typeName, &polyPatch::typeName, &polyPatch::typeName, &symmetryPolyPatch::typeName, &mergedCyclicPolyPatch::typeName};enum patchTypeNames{ PISTON, VALVE, LINER, CYLINDERHEAD, AXIS, WEDGE, INFLOW, OUTFLOW, PRESIN, PRESOUT, SYMMETRYPLANE, CYCLIC};const char *kivaPatchNames[nBCs]={ "piston", "valve", "liner", "cylinderHead", "axis", "wedge", "inflow", "outflow", "presin", "presout", "symmetryPlane", "cyclic"};List< SLList< face > > pFaces[nBCs]