File size: 6,569 Bytes
5a600cf | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 | /*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2011-2026 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
\*---------------------------------------------------------------------------*/
#include "boundaryPoints.H"
#include "polyMesh.H"
#include "addToRunTimeSelectionTable.H"
#include "treeBoundBox.H"
#include "treeDataFace.H"
#include "Time.H"
#include "OBJstream.H"
#include "RemoteData.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
namespace Foam
{
namespace sampledSets
{
defineTypeNameAndDebug(boundaryPoints, 0);
addToRunTimeSelectionTable(sampledSet, boundaryPoints, word);
}
}
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
bool Foam::sampledSets::boundaryPoints::calcSamples
(
DynamicList<point>& samplingPositions,
DynamicList<scalar>&,
DynamicList<label>& samplingSegments,
DynamicList<label>& samplingCells,
DynamicList<label>& samplingFaces
) const
{
// Get the patch IDs
const labelHashSet patchIDs(mesh().boundary().patchSet(patches_));
// Construct a single list of all patch faces
label nPatchFaces = 0;
forAllConstIter(labelHashSet, patchIDs, iter)
{
const polyPatch& pp = mesh().boundary()[iter.key()];
nPatchFaces += pp.size();
}
labelList patchFaces(nPatchFaces);
nPatchFaces = 0;
forAllConstIter(labelHashSet, patchIDs, iter)
{
const polyPatch& pp = mesh().boundary()[iter.key()];
forAll(pp, i)
{
patchFaces[nPatchFaces++] = pp.start()+i;
}
}
// Construct a processor-local bound box
treeBoundBox patchBB(point::max, point::min);
forAllConstIter(labelHashSet, patchIDs, iter)
{
const polyPatch& pp = mesh().boundary()[iter.key()];
const boundBox patchBb(pp.points(), pp.meshPoints(), false);
patchBB.min() = min(patchBB.min(), patchBb.min());
patchBB.max() = max(patchBB.max(), patchBb.max());
}
patchBB = patchBB.extend(1e-4);
// Create a search tree
indexedOctree<treeDataFace> patchTree
(
treeDataFace // all information needed to search faces
(
false, // do not cache the bound box
mesh(),
patchFaces
),
patchBB, // overall search box
8, // maximum number of levels
10, // how many elements per leaf
3.0 // in how many leaves is a shape on average
);
// Force calculation of face-diagonal decomposition
(void)mesh().tetBasePtIs();
// Generate the nearest patch information for each sampling point
List<RemoteData<Tuple2<scalar, point>>> nearest(points_.size());
forAll(points_, sampleI)
{
const point& sample = points_[sampleI];
const pointIndexHit pih =
patchFaces.size()
? patchTree.findNearest(sample, sqr(maxDistance_))
: pointIndexHit();
if (pih.hit())
{
nearest[sampleI].proci = Pstream::myProcNo();
nearest[sampleI].elementi = patchFaces[pih.index()];
nearest[sampleI].data.first() = magSqr(pih.hitPoint() - sample);
nearest[sampleI].data.second() = pih.hitPoint();
}
}
// Reduce to get the nearest patch locations globally
Pstream::listCombineGather
(
nearest,
RemoteData<Tuple2<scalar, point>>::smallestFirstEqOp()
);
Pstream::listCombineScatter(nearest);
// Dump connecting lines from the sampling points to the hit locations
if (debug && Pstream::master())
{
OBJstream str(mesh().time().path()/(name() + "_nearest.obj"));
forAll(nearest, sampleI)
{
if (nearest[sampleI].proci != -1)
{
str.write
(
linePointRef
(
points_[sampleI],
nearest[sampleI].data.second()
)
);
}
}
}
// Store the sampling locations on the nearest processor
forAll(nearest, sampleI)
{
if (nearest[sampleI].proci != -1)
{
if (nearest[sampleI].proci == Pstream::myProcNo())
{
const label facei = nearest[sampleI].elementi;
samplingPositions.append(nearest[sampleI].data.second());
samplingSegments.append(sampleI);
samplingCells.append(mesh().faceOwner()[facei]);
samplingFaces.append(facei);
}
}
else
{
WarningInFunction
<< "Unable to find location on patches " << patches_
<< " for the point " << points_[sampleI]
<< " within a distance of " << maxDistance_ << endl;
}
}
// This set is unordered. Distances have not been created.
return false;
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::sampledSets::boundaryPoints::boundaryPoints
(
const word& name,
const polyMesh& mesh,
const dictionary& dict
)
:
sampledSet(name, mesh, dict),
points_(dict.lookup("points")),
patches_(dict.lookup("patches")),
maxDistance_(dict.lookup<scalar>("maxDistance"))
{}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::sampledSets::boundaryPoints::~boundaryPoints()
{}
// ************************************************************************* //
|