1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | foam-extend: Open Source CFD
4 \\ / O peration | Version: 3.2
5 \\ / A nd | Web: http://www.foam-extend.org
6 \\/ M anipulation | For copyright notice see file Copyright
7 -------------------------------------------------------------------------------
9 This file is part of foam-extend.
11 foam-extend 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 foam-extend is distributed in the hope that it will be useful, but
17 WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with foam-extend. If not, see <http://www.gnu.org/licenses/>.
28 Base class for convexSetAlgorithms
32 University of Massachusetts Amherst
35 \*---------------------------------------------------------------------------*/
37 #include "objectRegistry.H"
42 #include "objectMap.H"
43 #include "edgeIOList.H"
44 #include "cellIOList.H"
46 #include "convexSetAlgorithm.H"
48 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
53 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
55 // Construct from components
56 convexSetAlgorithm::convexSetAlgorithm
59 const pointField& newPoints,
60 const UList<edge>& newEdges,
61 const UList<face>& newFaces,
62 const UList<cell>& newCells,
63 const UList<label>& newOwner,
64 const UList<label>& newNeighbour
67 nOldPoints_(mesh.nPoints()),
69 newPoints_(newPoints),
74 newNeighbour_(newNeighbour)
78 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
80 // Obtain map weighting factors
81 void convexSetAlgorithm::computeWeights
85 const labelList& mapCandidates,
86 const labelListList& oldNeighbourList,
93 if (parents.size() || weights.size() || centres.size())
98 "void convexSetAlgorithm::computeWeights\n"
100 " const label index,\n"
101 " const label offset,\n"
102 " const labelList& mapCandidates,\n"
103 " const labelListList& oldNeighbourList,\n"
104 " labelList& parents,\n"
105 " scalarField& weights,\n"
106 " vectorField& centres,\n"
110 << " Addressing has already been calculated." << nl
111 << " Index: " << index << nl
112 << " Offset: " << offset << nl
113 << " Type: " << (dimension() == 2 ? "Face" : "Cell") << nl
114 << " mapCandidates: " << mapCandidates << nl
115 << " Parents: " << parents << nl
116 << " Weights: " << weights << nl
117 << " Centres: " << centres << nl
118 << abort(FatalError);
121 // Do nothing for empty lists
122 if (mapCandidates.empty() || oldNeighbourList.empty())
128 label nAttempts = 0, nIntersects = 0;
130 // Calculate the algorithm normFactor
131 computeNormFactor(index);
133 // Maintain a check-list
134 labelHashSet checked, skipped;
136 // Loop and add intersections until nothing changes
142 // Fetch the set of candidates
147 checkList = mapCandidates;
151 checkList = checked.toc();
154 forAll(checkList, indexI)
156 labelList checkEntities;
160 checkEntities = labelList(1, checkList[indexI] - offset);
164 checkEntities = oldNeighbourList[checkList[indexI]];
167 forAll(checkEntities, entityI)
169 label checkEntity = checkEntities[entityI];
171 // Skip if this is already
172 // on the checked / skipped list
175 (checked.found(checkEntity)) ||
176 (skipped.found(checkEntity))
187 checkEntity + offset,
197 if (!checked.found(checkEntity))
199 checked.insert(checkEntity);
206 // Add to the skipped list
207 if (!skipped.found(checkEntity))
209 skipped.insert(checkEntity);
215 if (nAttempts == 0 && !changed)
217 // Need to setup a rescue mechanism.
220 forAll(mapCandidates, cI)
222 if (!rescue.found(mapCandidates[cI] - offset))
224 rescue.insert(mapCandidates[cI] - offset);
228 for (label level = 0; level < 10; level++)
230 labelList initList = rescue.toc();
234 const labelList& ff = oldNeighbourList[initList[fI]];
238 if (!rescue.found(ff[entityI]))
240 rescue.insert(ff[entityI]);
246 labelList finalList = rescue.toc();
248 forAll(finalList, entityI)
250 label checkEntity = finalList[entityI];
257 checkEntity + offset,
267 if (!checked.found(checkEntity))
269 checked.insert(checkEntity);
279 // No point in continuing further...
286 // Break out if we're taking too long
298 populateLists(parents, centres, weights);
302 // Output an entity as a VTK file
303 void convexSetAlgorithm::writeVTK
307 const label primitiveType,
308 const bool useOldConnectivity
314 labelList(1, entity),
321 // Output a list of entities as a VTK file
322 void convexSetAlgorithm::writeVTK
325 const labelList& cList,
326 const label primitiveType,
327 const bool useOldConnectivity
330 if (useOldConnectivity)
332 const polyMesh& mesh = this->mesh_;
365 bool convexSetAlgorithm::consistent(const scalar tolerance) const
369 scalar normError = mag(1.0 - (sum(weights_)/normFactor_));
371 if (normError < tolerance)
385 // Return the normFactor
386 scalar convexSetAlgorithm::normFactor() const
392 // Normalize stored weights
393 void convexSetAlgorithm::normalize(bool normSum) const
399 weights_ /= sum(weights_);
406 weights_ /= normFactor_;
412 // Extract weights and centres to lists
413 void convexSetAlgorithm::populateLists
416 vectorField& centres,
434 // Write out connectivity information to disk
435 bool convexSetAlgorithm::write() const
442 mesh_.time().timeName(),
443 "convexSetAlgorithm",
453 IOstream::currentVersion,
462 mesh_.time().timeName(),
463 "convexSetAlgorithm",
473 IOstream::currentVersion,
482 mesh_.time().timeName(),
483 "convexSetAlgorithm",
493 IOstream::currentVersion,
502 mesh_.time().timeName(),
503 "convexSetAlgorithm",
513 IOstream::currentVersion,
522 mesh_.time().timeName(),
523 "convexSetAlgorithm",
533 IOstream::currentVersion,
542 mesh_.time().timeName(),
543 "convexSetAlgorithm",
553 IOstream::currentVersion,
561 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
563 } // End namespace Foam
565 // ************************************************************************* //