pointFile.C
Go to the documentation of this file.
1/*---------------------------------------------------------------------------*\
2 ========= |
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4 \\ / O peration |
5 \\ / A nd | www.openfoam.com
6 \\/ M anipulation |
7-------------------------------------------------------------------------------
8 Copyright (C) 2012-2016 OpenFOAM Foundation
9 Copyright (C) 2018-2022 OpenCFD Ltd.
10-------------------------------------------------------------------------------
11License
12 This file is part of OpenFOAM.
13
14 OpenFOAM is free software: you can redistribute it and/or modify it
15 under the terms of the GNU General Public License as published by
16 the Free Software Foundation, either version 3 of the License, or
17 (at your option) any later version.
18
19 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22 for more details.
23
24 You should have received a copy of the GNU General Public License
25 along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26
27\*---------------------------------------------------------------------------*/
28
29#include "pointFile.H"
31
32// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
33
34namespace Foam
35{
36 defineTypeNameAndDebug(pointFile, 0);
37 addToRunTimeSelectionTable(initialPointsMethod, pointFile, dictionary);
38}
39
40
41// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
42
44(
45 const dictionary& initialPointsDict,
46 const Time& runTime,
47 Random& rndGen,
48 const conformationSurfaces& geometryToConformTo,
49 const cellShapeControl& cellShapeControls,
50 const autoPtr<backgroundMeshDecomposition>& decomposition
51)
52:
53 initialPointsMethod
54 (
55 typeName,
56 initialPointsDict,
57 runTime,
58 rndGen,
59 geometryToConformTo,
60 cellShapeControls,
61 decomposition
62 ),
63 pointFileName_(detailsDict().get<fileName>("pointFile").expand()),
64 insideOutsideCheck_(detailsDict().get<Switch>("insideOutsideCheck")),
65 randomiseInitialGrid_(detailsDict().get<Switch>("randomiseInitialGrid")),
66 randomPerturbationCoeff_
67 (
68 detailsDict().get<scalar>("randomPerturbationCoeff")
69 )
70{
71 Info<< " Inside/Outside check is " << insideOutsideCheck_.c_str()
72 << endl;
73}
74
75
76// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
77
79{
81 {
82 // Look for points
83 IOobject pointsIO
84 (
85 pointFileName_.name(),
86 time().timeName(),
87 time(),
90 );
91
92 Info<< " Inserting points from file " << pointFileName_ << endl;
93
94 // See if processor local file
95 if (pointsIO.typeHeaderOk<pointIOField>(true))
96 {
97 // Found it (processor local)
98 points = pointIOField(pointsIO);
99
100 if (points.empty())
101 {
103 << "Point file contain no points"
104 << exit(FatalError) << endl;
105 }
106
107 if (Pstream::parRun())
108 {
109 // assume that the points in each processor file
110 // are unique. They are unlikely to belong on the current
111 // processor as the background mesh is unlikely to be the same.
113 }
114 }
115 else if (Pstream::parRun())
116 {
117 // See if points can be found in parent directory
118 // (only if timeName = constant)
120 (
121 IOobject
122 (
123 pointFileName_.name(),
124 time().caseConstant(),
125 time(),
128 )
129 );
130
131 if (points.empty())
132 {
134 << "Point file contain no points"
135 << exit(FatalError) << endl;
136 }
137
138 // Points are assumed to be covering the whole
139 // domain, so filter the points to be only those on this processor
140 boolList procPt(decomposition().positionOnThisProcessor(points));
141
142 List<boolList> allProcPt(Pstream::nProcs());
143
144 allProcPt[Pstream::myProcNo()] = procPt;
145 Pstream::allGatherList(allProcPt);
146
147 forAll(procPt, ptI)
148 {
149 bool foundAlready = false;
150
151 forAll(allProcPt, proci)
152 {
153 // If a processor with a lower index has found this point
154 // to insert already, defer to it and don't insert.
155 if (foundAlready)
156 {
157 allProcPt[proci][ptI] = false;
158 }
159 else if (allProcPt[proci][ptI])
160 {
161 foundAlready = true;
162 }
163 }
164 }
165
166 procPt = allProcPt[Pstream::myProcNo()];
167
168 inplaceSubset(procPt, points);
169 }
170 else
171 {
173 << "Cannot find points file " << pointsIO.objectPath()
174 << exit(FatalError) << endl;
175 }
176 }
177
178 Field<bool> insidePoints(points.size(), true);
179
180 if (insideOutsideCheck_)
181 {
183 (
184 points,
186 *sqr(cellShapeControls().cellSize(points))
187 );
188 }
189
190 DynamicList<Vb::Point> initialPoints(insidePoints.size()/10);
191
193 {
194 if (insidePoints[i])
195 {
196 point& p = points[i];
197
198 if (randomiseInitialGrid_)
199 {
200 p.x() +=
201 randomPerturbationCoeff_
202 *(rndGen().sample01<scalar>() - 0.5);
203 p.y() +=
204 randomPerturbationCoeff_
205 *(rndGen().sample01<scalar>() - 0.5);
206 p.z() +=
207 randomPerturbationCoeff_
208 *(rndGen().sample01<scalar>() - 0.5);
209 }
210
211 initialPoints.append(Vb::Point(p.x(), p.y(), p.z()));
212 }
213 }
214
215 initialPoints.shrink();
216
217 label nPointsRejected = points.size() - initialPoints.size();
218
219 if (Pstream::parRun())
220 {
221 reduce(nPointsRejected, sumOp<label>());
222 }
223
224 if (nPointsRejected)
225 {
226 Info<< " " << nPointsRejected << " points rejected from "
227 << pointFileName_.name() << endl;
228 }
229
230 return initialPoints;
231}
232
233
234// ************************************************************************* //
Macros for easy insertion into run-time selection tables.
#define addToRunTimeSelectionTable(baseType, thisType, argNames)
Add to construction table with typeName as the key.
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: List.H:77
label nProcs() const noexcept
Number of ranks associated with PstreamBuffers.
static void allGatherList(const List< commsStruct > &comms, List< T > &values, const int tag, const label comm)
Type sample01()
Return a sample whose components lie in the range [0,1].
bool empty() const noexcept
True if the UList is empty (ie, size() is zero)
Definition: UListI.H:427
void size(const label n)
Older name for setAddressableSize.
Definition: UList.H:114
static bool & parRun() noexcept
Test if this a parallel run.
Definition: UPstream.H:433
autoPtr< mapDistribute > distributePoints(List< PointType > &points) const
Distribute supplied the points to the appropriate processor.
Field< bool > wellInside(const pointField &samplePts, const scalarField &testDistSqr) const
Check if point is inside surfaces to conform to by at least.
static std::string name(const std::string &str)
Return basename (part beyond last /), including its extension.
Definition: fileNameI.H:199
scalar minimumSurfaceDistanceCoeffSqr_
Only allow the placement of initial points that are within the.
const conformationSurfaces & geometryToConformTo() const
const cellShapeControl & cellShapeControls() const
const backgroundMeshDecomposition & decomposition() const
Inserts points at locations specified in a pointFile into the surfaces to be conformed to of the conf...
Definition: pointFile.H:58
virtual List< Vb::Point > initialPoints() const
Return the initial points for the conformalVoronoiMesh.
int myProcNo() const noexcept
Return processor number.
#define defineTypeNameAndDebug(Type, DebugSwitch)
Define the typeName and debug information.
Definition: className.H:121
volScalarField & p
engineTime & runTime
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:453
const pointField & points
word timeName
Definition: getTimeIndex.H:3
List< ReturnType > get(const UPtrList< T > &list, const AccessOp &aop)
string expand(const std::string &s, const HashTable< string > &mapping, const char sigil='$')
Definition: stringOps.C:718
Namespace for OpenFOAM.
void inplaceSubset(const BoolListType &select, ListType &input, const bool invert=false)
Inplace extract elements of the input list when select is true.
dimensionedSymmTensor sqr(const dimensionedVector &dv)
messageStream Info
Information stream (stdout output on master, null elsewhere)
vectorField pointField
pointField is a vectorField.
Definition: pointFieldFwd.H:44
vector point
Point is a vector.
Definition: point.H:43
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:372
void reduce(const List< UPstream::commsStruct > &comms, T &value, const BinaryOp &bop, const int tag, const label comm)
vectorIOField pointIOField
pointIOField is a vectorIOField.
Definition: pointIOField.H:44
List< bool > boolList
A List of bools.
Definition: List.H:64
error FatalError
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:130
insidePoints((1 2 3))
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:333
Random rndGen
Definition: createFields.H:23