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-2024 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"
29 #include "pointConstraint.H"
30 
31 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
32 
33 namespace Foam
34 {
35 namespace blockVertices
36 {
39 }
40 }
41 
42 
43 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
44 
46 (
47  const dictionary& dict,
48  const label index,
49  const searchableSurfaces& geometry,
50  Istream& is
51 )
52 :
53  pointVertex(dict, index, geometry, is),
54  geometry_(geometry)
55 {
56  wordList names(is);
57  surfaces_.setSize(names.size());
58  forAll(names, i)
59  {
60  surfaces_[i] = geometry_.findSurfaceID(names[i]);
61 
62  if (surfaces_[i] == -1)
63  {
65  << "Cannot find surface " << names[i] << " in geometry"
66  << exit(FatalIOError);
67  }
68  }
69 }
70 
71 
72 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
73 
74 Foam::blockVertices::projectVertex::operator point() const
75 {
76  pointField start(1, pointVertex::operator point());
77 
78  pointField boundaryNear(start);
79  List<pointConstraint> boundaryConstraint;
80 
81 
82  // Note: how far do we need to search? Probably not further than
83  // span of surfaces themselves. Make sure to limit in case
84  // of e.g. searchablePlane which has infinite bb.
85  boundBox bb(searchableSurfacesQueries::bounds(geometry_, surfaces_));
86  bb.min() = max(bb.min(), point(-great, -great, -great));
87  bb.max() = min(bb.max(), point(great, great, great));
88 
90  (
91  geometry_,
92  surfaces_,
93  start,
94  scalarField(start.size(), magSqr(bb.span())),
95  boundaryNear,
96  boundaryConstraint
97  );
98 
99  return boundaryNear[0];
100 }
101 
102 
103 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
Macros for easy insertion into run-time selection tables.
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:60
void size(const label)
Override size to be inconsistent with allocated storage.
Definition: ListI.H:164
void setSize(const label)
Reset size of List.
Definition: List.C:281
Define a block vertex.
Definition: blockVertex.H:49
Projects the vertex onto the selected surfaces of the geometry provided as a searchableSurfaces objec...
Definition: projectVertex.H:54
projectVertex(const dictionary &, const label index, const searchableSurfaces &geometry, Istream &)
Construct from Istream setting pointsList.
Definition: projectVertex.C:46
A bounding box defined in terms of the points at its extremities.
Definition: boundBox.H:59
const point & min() const
Minimum point defining the bounding box.
Definition: boundBoxI.H:60
const point & max() const
Maximum point defining the bounding box.
Definition: boundBoxI.H:66
vector span() const
The bounding box span (from minimum to maximum)
Definition: boundBoxI.H:90
A list of keyword definitions, which are a keyword followed by any number of values (e....
Definition: dictionary.H:162
static boundBox bounds(const PtrList< searchableSurface > &allSurfaces, const labelList &surfacesToTest)
Find the boundBox of the selected surfaces.
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.
Container for searchableSurfaces.
label findSurfaceID(const word &name) const
Find index of surface. Return -1 if not found.
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Definition: error.H:346
defineTypeNameAndDebug(namedVertex, 0)
addToRunTimeSelectionTable(blockVertex, namedVertex, Istream)
Namespace for OpenFOAM.
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
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
vector point
Point is a vector.
Definition: point.H:41
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
layerAndWeight min(const layerAndWeight &a, const layerAndWeight &b)
layerAndWeight max(const layerAndWeight &a, const layerAndWeight &b)
IOerror FatalIOError
dimensioned< scalar > magSqr(const dimensioned< Type > &)
dictionary dict