projectVertex.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2016-2018 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
26 #include "projectVertex.H"
27 #include "unitConversion.H"
30 #include "pointConstraint.H"
31 
32 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
33 
34 namespace Foam
35 {
36 namespace blockVertices
37 {
38  defineTypeNameAndDebug(projectVertex, 0);
39  addToRunTimeSelectionTable(blockVertex, projectVertex, Istream);
40 }
41 }
42 
43 
44 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
45 
46 Foam::blockVertices::projectVertex::projectVertex
47 (
48  const dictionary& dict,
49  const label index,
50  const searchableSurfaces& geometry,
51  Istream& is
52 )
53 :
54  pointVertex(dict, index, geometry, is),
55  geometry_(geometry)
56 {
57  wordList names(is);
58  surfaces_.setSize(names.size());
59  forAll(names, i)
60  {
61  surfaces_[i] = geometry_.findSurfaceID(names[i]);
62 
63  if (surfaces_[i] == -1)
64  {
66  << "Cannot find surface " << names[i] << " in geometry"
67  << exit(FatalIOError);
68  }
69  }
70 }
71 
72 
73 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
74 
75 Foam::blockVertices::projectVertex::operator point() const
76 {
77  pointField start(1, pointVertex::operator point());
78 
79  pointField boundaryNear(start);
80  List<pointConstraint> boundaryConstraint;
81 
82 
83  // Note: how far do we need to search? Probably not further than
84  // span of surfaces themselves. Make sure to limit in case
85  // of e.g. searchablePlane which has infinite bb.
86  boundBox bb(searchableSurfacesQueries::bounds(geometry_, surfaces_));
87  bb.min() = max(bb.min(), point(-great, -great, -great));
88  bb.max() = min(bb.max(), point(great, great, great));
89 
91  (
92  geometry_,
93  surfaces_,
94  start,
95  scalarField(start.size(), magSqr(bb.span())),
96  boundaryNear,
97  boundaryConstraint
98  );
99 
100  return boundaryNear[0];
101 }
102 
103 
104 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:428
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:137
dimensioned< Type > max(const dimensioned< Type > &, const dimensioned< Type > &)
static void findNearest(const PtrList< searchableSurface > &, const labelList &surfacesToTest, const pointField &, const scalarField &nearestDistSqr, labelList &surfaces, List< pointIndexHit > &)
Find nearest. Return -1 (and a miss()) or surface and nearest.
Unit conversion functions.
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
void size(const label)
Override size to be inconsistent with allocated storage.
Definition: ListI.H:163
A bounding box defined in terms of the points at its extremities.
Definition: boundBox.H:58
defineTypeNameAndDebug(namedVertex, 0)
Macros for easy insertion into run-time selection tables.
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
Container for searchableSurfaces.
addToRunTimeSelectionTable(blockVertex, namedVertex, Istream)
dimensioned< scalar > magSqr(const dimensioned< Type > &)
dimensioned< Type > min(const dimensioned< Type > &, const dimensioned< Type > &)
const point & max() const
Maximum describing the bounding box.
Definition: boundBoxI.H:60
vector point
Point is a vector.
Definition: point.H:41
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Definition: error.H:331
vector span() const
The bounding box span (from minimum to maximum)
Definition: boundBoxI.H:84
const point & min() const
Minimum describing the bounding box.
Definition: boundBoxI.H:54
static boundBox bounds(const PtrList< searchableSurface > &allSurfaces, const labelList &surfacesToTest)
Find the boundBox of the selected surfaces.
Namespace for OpenFOAM.
IOerror FatalIOError