1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | cfMesh: A library for mesh generation
5 \\ / A nd | Author: Franjo Juretic (franjo.juretic@c-fields.com)
6 \\/ M anipulation | Copyright (C) Creative Fields, Ltd.
7 -------------------------------------------------------------------------------
9 This file is part of cfMesh.
11 cfMesh is free software; you can redistribute it and/or modify it
12 under the terms of the GNU General Public License as published by the
13 Free Software Foundation; either version 3 of the License, or (at your
14 option) any later version.
16 cfMesh is distributed in the hope that it will be useful, but WITHOUT
17 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 You should have received a copy of the GNU General Public License
22 along with cfMesh. If not, see <http://www.gnu.org/licenses/>.
26 \*---------------------------------------------------------------------------*/
29 #include "demandDrivenData.H"
33 #include "triSurface.H"
35 #include "helperFunctions.H"
37 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
42 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
44 void triSurf::readFromFTR(const fileName& fName)
46 IFstream fStream(fName);
48 fStream >> triSurfFacets::patches_;
50 fStream >> triSurfPoints::points_;
52 fStream >> triSurfFacets::triangles_;
55 void triSurf::writeToFTR(const fileName& fName) const
57 OFstream fStream(fName);
59 fStream << triSurfFacets::patches_;
63 fStream << triSurfPoints::points_;
67 fStream << triSurfFacets::triangles_;
70 void triSurf::readFromFMS(const fileName& fName)
72 IFstream fStream(fName);
74 //- read the list of patches defined on the surface mesh
75 fStream >> triSurfFacets::patches_;
78 fStream >> triSurfPoints::points_;
80 //- read surface triangles
81 fStream >> triSurfFacets::triangles_;
83 //- read feature edges
84 fStream >> triSurfFeatureEdges::featureEdges_;
86 List<meshSubset> subsets;
88 //- read point subsets
90 forAll(subsets, subsetI)
91 triSurfPoints::pointSubsets_.insert(subsetI, subsets[subsetI]);
95 //- read facet subsets
97 forAll(subsets, subsetI)
98 triSurfFacets::facetSubsets_.insert(subsetI, subsets[subsetI]);
102 //- read subsets on feature edges
104 forAll(subsets, subsetI)
105 triSurfFeatureEdges::featureEdgeSubsets_.insert
112 void triSurf::writeToFMS(const fileName& fName) const
114 OFstream fStream(fName);
117 fStream << triSurfFacets::patches_;
122 fStream << triSurfPoints::points_;
127 fStream << triSurfFacets::triangles_;
131 //- write feature edges
132 fStream << triSurfFeatureEdges::featureEdges_;
136 //- write point subsets
137 List<meshSubset> subsets;
139 subsets.setSize(pointSubsets_.size());
140 forAllConstIter(Map<meshSubset>, pointSubsets_, it)
146 //- write subsets of facets
147 subsets.setSize(triSurfFacets::facetSubsets_.size());
149 forAllConstIter(Map<meshSubset>, triSurfFacets::facetSubsets_, it)
155 //- write subets of feature edges
156 subsets.setSize(triSurfFeatureEdges::featureEdgeSubsets_.size());
161 triSurfFeatureEdges::featureEdgeSubsets_,
168 void triSurf::topologyCheck()
170 const pointField& pts = this->points();
171 const LongList<labelledTri>& trias = this->facets();
173 //- check for inf and nan points
175 # pragma omp parallel for schedule(dynamic, 100)
179 const point& p = pts[pointI];
181 if( help::isnan(p) || help::isinf(p) )
184 # pragma omp critical
189 "void triSurf::topologyCheck()"
190 ) << "Point " << pointI << " has invalid coordinates "
191 << p << exit(FatalError);
196 //- check whether the nodes are within the scope
197 //- report duplicate nodes in the same triangle
199 # pragma omp parallel for schedule(dynamic, 100)
203 const labelledTri& ltri = trias[triI];
207 if( ltri[pI] < 0 || (ltri[pI] >= pts.size()) )
210 # pragma omp critical
214 "void triSurf::topologyCheck()"
215 ) << "Point " << ltri[pI] << " in triangle " << ltri
216 << " is out of scope 0 " << pts.size() << exit(FatalError);
219 if( ltri[pI] == ltri[(pI+1)%3] || ltri[pI] == ltri[(pI+2)%3] )
222 # pragma omp critical
226 "void triSurf::topologyCheck()"
227 ) << "Triangle " << ltri << " has duplicated points. "
228 << "This may cause problems in the meshing process!" << endl;
233 //- check feature edges
234 const edgeLongList& featureEdges = this->featureEdges();
237 # pragma omp parallel for schedule(dynamic, 100)
239 forAll(featureEdges, eI)
241 const edge& fe = featureEdges[eI];
245 if( fe[pI] < 0 || (fe[pI] >= pts.size()) )
248 # pragma omp critical
252 "void triSurf::topologyCheck()"
253 ) << "Feature edge " << fe << " point " << fe[pI]
254 << " is out of scope 0 " << pts.size() << exit(FatalError);
258 if( fe.start() == fe.end() )
261 # pragma omp critical
265 "void triSurf::topologyCheck()"
266 ) << "Feature edge " << fe << " has duplicated points. "
267 << "This may cause problems in the meshing process!" << endl;
271 //- check point subsets
272 DynList<label> subsetIds;
273 this->pointSubsetIndices(subsetIds);
277 this->pointsInSubset(subsetIds[i], elmts);
281 const label elI = elmts[elmtI];
283 if( elI < 0 || elI >= pts.size() )
286 # pragma omp critical
290 "void triSurf::topologyCheck()"
291 ) << "Point " << elI << " in point subset "
292 << this->pointSubsetName(subsetIds[i])
293 << " is out of scope 0 " << pts.size() << exit(FatalError);
298 //- check face subsets
300 this->facetSubsetIndices(subsetIds);
304 this->facetsInSubset(subsetIds[i], elmts);
308 const label elI = elmts[elmtI];
310 if( elI < 0 || elI >= trias.size() )
313 # pragma omp critical
317 "void triSurf::topologyCheck()"
318 ) << "Triangle " << elI << " in facet subset "
319 << this->facetSubsetName(subsetIds[i])
320 << " is out of scope 0 " << trias.size() << exit(FatalError);
325 //- check feature edge subsets
327 this->edgeSubsetIndices(subsetIds);
331 this->edgesInSubset(subsetIds[i], elmts);
335 const label elI = elmts[elmtI];
337 if( elI < 0 || elI >= featureEdges.size() )
340 # pragma omp critical
344 "void triSurf::topologyCheck()"
345 ) << "Feature edge " << elI << " in edge subset "
346 << this->edgeSubsetName(subsetIds[i])
347 << " is out of scope 0 " << featureEdges.size()
354 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
360 triSurfFeatureEdges(),
361 triSurfAddressing(triSurfPoints::points_, triSurfFacets::triangles_)
364 //- Construct from parts
367 const LongList<labelledTri>& triangles,
368 const geometricSurfacePatchList& patches,
369 const edgeLongList& featureEdges,
370 const pointField& points
373 triSurfPoints(points),
374 triSurfFacets(triangles, patches),
375 triSurfFeatureEdges(featureEdges),
376 triSurfAddressing(triSurfPoints::points_, triSurfFacets::triangles_)
382 triSurf::triSurf(const fileName& fName)
386 triSurfFeatureEdges(),
387 triSurfAddressing(triSurfPoints::points_, triSurfFacets::triangles_)
394 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
399 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
401 void triSurf::readSurface(const fileName& fName)
403 if( fName.ext() == "fms" || fName.ext() == "FMS" )
407 else if( fName.ext() == "ftr" || fName.ext() == "FTR" )
413 triSurface copySurface(fName);
416 triSurfPoints::points_.setSize(copySurface.points().size());
417 forAll(copySurface.points(), pI)
418 triSurfPoints::points_[pI] = copySurface.points()[pI];
420 //- copy the triangles
421 triSurfFacets::triangles_.setSize(copySurface.size());
422 forAll(copySurface, tI)
423 triSurfFacets::triangles_[tI] = copySurface[tI];
426 triSurfFacets::patches_ = copySurface.patches();
430 void triSurf::writeSurface(const fileName& fName) const
432 if( fName.ext() == "fms" || fName.ext() == "FMS" )
436 else if( fName.ext() == "ftr" || fName.ext() == "FTR" )
442 const pointField& pts = this->points();
443 const LongList<labelledTri>& facets = this->facets();
444 const geometricSurfacePatchList& patches = this->patches();
446 List<labelledTri> newTrias(facets.size());
448 newTrias[tI] = facets[tI];
450 triSurface newSurf(newTrias, patches, pts);
451 newSurf.write(fName);
455 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
457 } // End namespace Foam
459 // ************************************************************************* //