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 
93  (
94  geometry_,
95  surfaces_,
96  start,
97  scalarField(start.size(), bb.magSqr()),
98  boundaryNear,
99  boundaryConstraint
100  );
101 
102  return boundaryNear[0];
103 }
104 
105 
106 // ************************************************************************* //
dictionary dict
void size(const label n)
Older name for setAddressableSize.
Definition: UList.H:116
List< word > names(const UPtrList< T > &list, const UnaryMatchPredicate &matcher)
List of names generated by calling name() for each list item and filtered for matches.
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:125
A list of keyword definitions, which are a keyword followed by a number of values (eg...
Definition: dictionary.H:129
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.
label max(const labelHashSet &set, label maxValue=labelMin)
Find the max value in labelHashSet, optionally limited by second argument.
Definition: hashSets.C:40
Unit conversion functions.
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
label findSurfaceID(const word &name) const
Find index of surface. Return -1 if not found.
defineTypeNameAndDebug(namedVertex, 0)
Macros for easy insertion into run-time selection tables.
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:421
vectorField pointField
pointField is a vectorField.
Definition: pointFieldFwd.H:38
void setSize(const label n)
Alias for resize()
Definition: List.H:316
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
Container for searchableSurfaces. The collection is specified as a dictionary. For example...
addToRunTimeSelectionTable(blockVertex, namedVertex, Istream)
label min(const labelHashSet &set, label minValue=labelMax)
Find the min value in labelHashSet, optionally limited by second argument.
Definition: hashSets.C:26
vector point
Point is a vector.
Definition: point.H:37
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Definition: error.H:627
Namespace for OpenFOAM.
static boundBox bounds(const PtrList< searchableSurface > &allSurfaces, const labelUList &surfacesToTest)
Find the boundBox of the selected surfaces.
IOerror FatalIOError
Error stream (stdout output on all processes), with additional &#39;FOAM FATAL IO ERROR&#39; header text and ...