File size: 5,440 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 | /*---------------------------------------------------------------------------*\
========= |
\\ / 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 "refinementParameters.H"
#include "units.H"
#include "polyMesh.H"
#include "globalIndex.H"
#include "meshSearch.H"
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::refinementParameters::refinementParameters(const dictionary& dict)
:
maxGlobalCells_(dict.lookup<label>("maxGlobalCells")),
maxLocalCells_(dict.lookup<label>("maxLocalCells")),
minRefineCells_(dict.lookup<label>("minRefinementCells")),
planarAngle_
(
dict.lookupOrDefault
(
"planarAngle",
units::degrees,
dict.lookup<scalar>("resolveFeatureAngle", units::degrees)
)
),
nBufferLayers_(dict.lookup<label>("nCellsBetweenLevels")),
selectionPoints_(dict),
allowFreeStandingZoneFaces_(dict.lookup("allowFreeStandingZoneFaces")),
useTopologicalSnapDetection_
(
dict.lookupOrDefault<bool>("useTopologicalSnapDetection", true)
),
maxLoadUnbalance_(dict.lookupOrDefault<scalar>("maxLoadUnbalance", 0)),
handleSnapProblems_
(
dict.lookupOrDefault<Switch>("handleSnapProblems", true)
)
{
const scalar featAngle
(
dict.lookup<scalar>("resolveFeatureAngle", units::degrees)
);
if (featAngle < 0 || featAngle > degToRad(180))
{
curvature_ = -great;
}
else
{
curvature_ = Foam::cos(featAngle);
}
}
Foam::refinementParameters::cellSelectionPoints::cellSelectionPoints
(
const dictionary& dict
)
:
inside_
(
dict.found("insidePoints")
? dict.lookup<List<point>>("insidePoints", dimensions::length)
: dict.found("insidePoint")
? List<point>(1, dict.lookup<point>("insidePoint", dimensions::length))
: dict.found("locationInMesh")
? List<point>(1, dict.lookup<point>("locationInMesh", dimensions::length))
: List<point>::null()
),
outside_
(
dict.found("outsidePoints")
? dict.lookup<List<point>>("outsidePoints", dimensions::length)
: dict.found("outsidePoint")
? List<point>(1, dict.lookup<point>("outsidePoint", dimensions::length))
: List<point>::null()
)
{
if (inside_.size())
{
Info << "Cell selection insidePoints: " << inside_ << endl;
}
if (outside_.size())
{
Info << "Cell selection outsidePoints: " << outside_ << endl;
}
if (!inside_.size() && !outside_.size())
{
FatalErrorInFunction
<< "Neither insidePoint/insidePoints nor "
"outsidePoint/outsidePoints specified: "
<< "cannot select any cells."
<< exit(FatalError);
}
}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
Foam::labelList Foam::refinementParameters::findCells
(
const polyMesh& mesh
) const
{
const meshSearch& searchEngine = meshSearch::New(mesh);
// Global calculation engine
globalIndex globalCells(mesh.nCells());
// Cell label per point
labelList cellLabels(selectionPoints_.inside().size());
forAll(selectionPoints_.inside(), i)
{
const point& insidePoint = selectionPoints_.inside()[i];
label localCelli = searchEngine.findCell(insidePoint);
label globalCelli = -1;
if (localCelli != -1)
{
globalCelli = globalCells.toGlobal(localCelli);
}
reduce(globalCelli, maxOp());
if (globalCelli == -1)
{
FatalErrorInFunction
<< "Point " << insidePoint
<< " is not inside the mesh or on a face or edge." << nl
<< "Bounding box of the mesh:" << mesh.bounds()
<< exit(FatalError);
}
label proci = globalCells.whichProcID(globalCelli);
label procCelli = globalCells.toLocal(proci, globalCelli);
Info<< "Found point " << insidePoint << " in cell " << procCelli
<< " on processor " << proci << endl;
if (globalCells.isLocal(globalCelli))
{
cellLabels[i] = localCelli;
}
else
{
cellLabels[i] = -1;
}
}
return cellLabels;
}
// ************************************************************************* //
|