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 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")),
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 
146  Pstream::gatherList(allProcPt);
147 
148  Pstream::scatterList(allProcPt);
149 
150  forAll(procPt, ptI)
151  {
152  bool foundAlready = false;
153 
154  forAll(allProcPt, proci)
155  {
156  // If a processor with a lower index has found this point
157  // to insert already, defer to it and don't insert.
158  if (foundAlready)
159  {
160  allProcPt[proci][ptI] = false;
161  }
162  else if (allProcPt[proci][ptI])
163  {
164  foundAlready = true;
165  }
166  }
167  }
168 
169  procPt = allProcPt[Pstream::myProcNo()];
170 
171  inplaceSubset(procPt, points);
172  }
173  else
174  {
176  << "Cannot find points file " << pointsIO.objectPath()
177  << exit(FatalError) << endl;
178  }
179  }
180 
181  Field<bool> insidePoints(points.size(), true);
182 
183  if (insideOutsideCheck_)
184  {
185  insidePoints = geometryToConformTo().wellInside
186  (
187  points,
188  minimumSurfaceDistanceCoeffSqr_
189  *sqr(cellShapeControls().cellSize(points))
190  );
191  }
192 
193  DynamicList<Vb::Point> initialPoints(insidePoints.size()/10);
194 
195  forAll(insidePoints, i)
196  {
197  if (insidePoints[i])
198  {
199  point& p = points[i];
200 
201  if (randomiseInitialGrid_)
202  {
203  p.x() +=
204  randomPerturbationCoeff_
205  *(rndGen().sample01<scalar>() - 0.5);
206  p.y() +=
207  randomPerturbationCoeff_
208  *(rndGen().sample01<scalar>() - 0.5);
209  p.z() +=
210  randomPerturbationCoeff_
211  *(rndGen().sample01<scalar>() - 0.5);
212  }
213 
214  initialPoints.append(Vb::Point(p.x(), p.y(), p.z()));
215  }
216  }
217 
218  initialPoints.shrink();
219 
220  label nPointsRejected = points.size() - initialPoints.size();
221 
222  if (Pstream::parRun())
223  {
224  reduce(nPointsRejected, sumOp<label>());
225  }
226 
227  if (nPointsRejected)
228  {
229  Info<< " " << nPointsRejected << " points rejected from "
230  << pointFileName_.name() << endl;
231  }
232 
233  return initialPoints;
234 }
235 
236 
237 // ************************************************************************* //
Foam::addToRunTimeSelectionTable
addToRunTimeSelectionTable(decompositionMethod, kahipDecomp, dictionary)
Foam::IOobject::NO_WRITE
Definition: IOobject.H:130
Foam::pointField
vectorField pointField
pointField is a vectorField.
Definition: pointFieldFwd.H:44
runTime
engineTime & runTime
Definition: createEngineTime.H:13
p
volScalarField & p
Definition: createFieldRefs.H:8
pointFile.H
Foam::pointFile::pointFile
pointFile(const dictionary &initialPointsDict, const Time &runTime, Random &rndGen, const conformationSurfaces &geometryToConformTo, const cellShapeControl &cellShapeControls, const autoPtr< backgroundMeshDecomposition > &decomposition)
Construct from components.
CGAL::indexedVertex::Point
Vb::Point Point
Definition: indexedVertex.H:135
Foam::Pstream::scatterList
static void scatterList(const List< commsStruct > &comms, List< T > &Values, const int tag, const label comm)
Scatter data. Reverse of gatherList.
Definition: gatherScatterList.C:215
Foam::Random::sample01
Type sample01()
Return a sample whose components lie in the range [0,1].
Definition: RandomTemplates.C:36
Foam::UPstream::nProcs
static label nProcs(const label communicator=0)
Number of processes in parallel run.
Definition: UPstream.H:427
Foam::UPstream::parRun
static bool & parRun()
Is this a parallel run?
Definition: UPstream.H:415
Foam::boolList
List< bool > boolList
A List of bools.
Definition: List.H:69
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:350
Foam::pointFile::initialPoints
virtual List< Vb::Point > initialPoints() const
Return the initial points for the conformalVoronoiMesh.
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:296
Foam::reduce
void reduce(const List< UPstream::commsStruct > &comms, T &Value, const BinaryOp &bop, const int tag, const label comm)
Definition: PstreamReduceOps.H:51
Foam::pointIOField
vectorIOField pointIOField
pointIOField is a vectorIOField.
Definition: pointIOField.H:44
Foam::Info
messageStream Info
Information stream (uses stdout - output is on the master only)
Foam::FatalError
error FatalError
addToRunTimeSelectionTable.H
Macros for easy insertion into run-time selection tables.
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::inplaceSubset
void inplaceSubset(const BoolListType &select, ListType &input, const bool invert=false)
Inplace extract elements of the input list when select is true.
Definition: ListOpsTemplates.C:590
Foam::exit
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:130
Foam::UPstream::myProcNo
static int myProcNo(const label communicator=0)
Number of this process (starting from masterNo() = 0)
Definition: UPstream.H:445
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:372
Foam::Pstream::gatherList
static void gatherList(const List< commsStruct > &comms, List< T > &Values, const int tag, const label comm)
Gather data but keep individual values separate.
Definition: gatherScatterList.C:52
Foam::sqr
dimensionedSymmTensor sqr(const dimensionedVector &dv)
Definition: dimensionedSymmTensor.C:51
Foam::List
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: HashTable.H:102
points
const pointField & points
Definition: gmvOutputHeader.H:1
insidePoints
insidePoints((1 2 3))
rndGen
Random rndGen
Definition: createFields.H:23
Foam::point
vector point
Point is a vector.
Definition: point.H:43
Foam::defineTypeNameAndDebug
defineTypeNameAndDebug(combustionModel, 0)
Foam::IOobject::MUST_READ
Definition: IOobject.H:120