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 -------------------------------------------------------------------------------
11 License
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 
34 namespace 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.
112  decomposition().distributePoints(points);
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  {
182  insidePoints = geometryToConformTo().wellInside
183  (
184  points,
185  minimumSurfaceDistanceCoeffSqr_
186  *sqr(cellShapeControls().cellSize(points))
187  );
188  }
189 
190  DynamicList<Vb::Point> initialPoints(insidePoints.size()/10);
191 
192  forAll(insidePoints, i)
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 // ************************************************************************* //
List< ReturnType > get(const UPtrList< T > &list, const AccessOp &aop)
List of values generated by applying the access operation to each list item.
virtual List< Vb::Point > initialPoints() const
Return the initial points for the conformalVoronoiMesh.
void size(const label n)
Older name for setAddressableSize.
Definition: UList.H:116
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:125
error FatalError
Error stream (stdout output on all processes), with additional &#39;FOAM FATAL ERROR&#39; header text and sta...
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:578
vectorIOField pointIOField
pointIOField is a vectorIOField.
Definition: pointIOField.H:38
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: BitOps.H:56
dimensionedSymmTensor sqr(const dimensionedVector &dv)
bool empty() const noexcept
True if List is empty (ie, size() is zero)
Definition: UList.H:632
Random rndGen
Definition: createFields.H:23
engineTime & runTime
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:487
static bool & parRun() noexcept
Test if this a parallel run.
Definition: UPstream.H:1004
Ignore writing from objectRegistry::writeObject()
static int myProcNo(const label communicator=worldComm)
Rank of this process in the communicator (starting from masterNo()). Can be negative if the process i...
Definition: UPstream.H:1029
void inplaceSubset(const BoolListType &select, ListType &input, const bool invert=false)
Inplace extract elements of the input list when select is true.
Macros for easy insertion into run-time selection tables.
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:414
static void allGatherList(List< T > &values, const int tag=UPstream::msgType(), const label comm=UPstream::worldComm)
Gather data, but keep individual values separate. Uses linear/tree communication. ...
pointFile(const dictionary &initialPointsDict, const Time &runTime, Random &rndGen, const conformationSurfaces &geometryToConformTo, const cellShapeControl &cellShapeControls, const autoPtr< backgroundMeshDecomposition > &decomposition)
Construct from components.
static label nProcs(const label communicator=worldComm)
Number of ranks in parallel run (for given communicator). It is 1 for serial run. ...
Definition: UPstream.H:1020
vectorField pointField
pointField is a vectorField.
Definition: pointFieldFwd.H:38
Type sample01()
Return a sample whose components lie in the range [0,1].
const pointField & points
defineTypeNameAndDebug(combustionModel, 0)
addToRunTimeSelectionTable(decompositionMethod, kahipDecomp, dictionary)
vector point
Point is a vector.
Definition: point.H:37
void reduce(const List< UPstream::commsStruct > &comms, T &value, const BinaryOp &bop, const int tag, const label comm)
Reduce inplace (cf. MPI Allreduce) using specified communication schedule.
messageStream Info
Information stream (stdout output on master, null elsewhere)
volScalarField & p
insidePoints((1 2 3))
List< bool > boolList
A List of bools.
Definition: List.H:60
Namespace for OpenFOAM.
string expand(const std::string &s, const HashTable< string > &mapping, const char sigil='$')
Expand occurrences of variables according to the mapping and return the expanded string.
Definition: stringOps.C:704