projectVertex.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) 2016 OpenFOAM Foundation
9 -------------------------------------------------------------------------------
10 License
11  This file is part of OpenFOAM.
12 
13  OpenFOAM is free software: you can redistribute it and/or modify it
14  under the terms of the GNU General Public License as published by
15  the Free Software Foundation, either version 3 of the License, or
16  (at your option) any later version.
17 
18  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21  for more details.
22 
23  You should have received a copy of the GNU General Public License
24  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25 
26 \*---------------------------------------------------------------------------*/
27 
28 #include "projectVertex.H"
29 #include "unitConversion.H"
32 #include "pointConstraint.H"
33 
34 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
35 
36 namespace Foam
37 {
38 namespace blockVertices
39 {
40  defineTypeNameAndDebug(projectVertex, 0);
41  addToRunTimeSelectionTable(blockVertex, projectVertex, Istream);
42 }
43 }
44 
45 
46 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
47 
48 Foam::blockVertices::projectVertex::projectVertex
49 (
50  const dictionary& dict,
51  const label index,
52  const searchableSurfaces& geometry,
53  Istream& is
54 )
55 :
56  pointVertex(dict, index, geometry, is),
57  geometry_(geometry)
58 {
59  wordList names(is);
60  surfaces_.setSize(names.size());
61  forAll(names, i)
62  {
63  surfaces_[i] = geometry_.findSurfaceID(names[i]);
64 
65  if (surfaces_[i] == -1)
66  {
68  << "Cannot find surface " << names[i] << " in geometry"
69  << exit(FatalIOError);
70  }
71  }
72 }
73 
74 
75 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
76 
77 Foam::blockVertices::projectVertex::operator point() const
78 {
79  pointField start(1, pointVertex::operator point());
80 
81  pointField boundaryNear(start);
82  List<pointConstraint> boundaryConstraint;
83 
84 
85  // Note: how far do we need to search? Probably not further than
86  // span of surfaces themselves. Make sure to limit in case
87  // of e.g. searchablePlane which has infinite bb.
88  boundBox bb(searchableSurfacesQueries::bounds(geometry_, surfaces_));
89  bb.min() = max(bb.min(), point(-GREAT, -GREAT, -GREAT));
90  bb.max() = min(bb.max(), point(GREAT, GREAT, GREAT));
91 
92  searchableSurfacesQueries::findNearest
93  (
94  geometry_,
95  surfaces_,
96  start,
97  scalarField(start.size(), magSqr(bb.span())),
98  boundaryNear,
99  boundaryConstraint
100  );
101 
102  return boundaryNear[0];
103 }
104 
105 
106 // ************************************************************************* //
Foam::blockVertices::addToRunTimeSelectionTable
addToRunTimeSelectionTable(blockVertex, namedVertex, Istream)
pointConstraint.H
Foam::scalarField
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
Definition: primitiveFieldsFwd.H:52
projectVertex.H
unitConversion.H
Unit conversion functions.
Foam::FatalIOError
IOerror FatalIOError
Foam::boundBox::max
const point & max() const
Maximum describing the bounding box.
Definition: boundBoxI.H:97
searchableSurfacesQueries.H
Foam::min
label min(const labelHashSet &set, label minValue=labelMax)
Find the min value in labelHashSet, optionally limited by second argument.
Definition: hashSets.C:33
Foam::boundBox::min
const point & min() const
Minimum describing the bounding box.
Definition: boundBoxI.H:91
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:296
Foam::magSqr
dimensioned< typename typeOfMag< Type >::type > magSqr(const dimensioned< Type > &dt)
Foam::boundBox::span
vector span() const
The bounding box span (from minimum to maximum)
Definition: boundBoxI.H:127
Foam::Field< vector >
Foam::Istream
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:61
Foam::max
label max(const labelHashSet &set, label maxValue=labelMin)
Find the max value in labelHashSet, optionally limited by second argument.
Definition: hashSets.C:47
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:123
addToRunTimeSelectionTable.H
Macros for easy insertion into run-time selection tables.
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::exit
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:130
Foam::List< word >
Foam::blockVertices::defineTypeNameAndDebug
defineTypeNameAndDebug(namedVertex, 0)
Foam::searchableSurfaces
Container for searchableSurfaces. The collection is specified as a dictionary. For example,...
Definition: searchableSurfaces.H:92
Foam::boundBox
A bounding box defined in terms of min/max extrema points.
Definition: boundBox.H:63
FatalIOErrorInFunction
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Definition: error.H:473
Foam::point
vector point
Point is a vector.
Definition: point.H:43
Foam::PtrListOps::names
List< word > names(const UPtrList< T > &list, const UnaryMatchPredicate &matcher)
Foam::blockVertices::pointVertex
Definition: pointVertex.H:52