sampledDistanceSurface.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) 2011-2023 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 "sampledDistanceSurface.H"
28 
29 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
30 
31 namespace Foam
32 {
33 namespace sampledSurfaces
34 {
37 }
38 }
39 
40 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
41 
43 Foam::sampledSurfaces::distanceSurface::calcIsoSurf() const
44 {
45  // Compute the distance from the mesh points to the surface
46  scalarField pointDistance(mesh().nPoints());
47  {
48  List<pointIndexHit> nearest;
49  surfPtr_().findNearest
50  (
51  mesh().points(),
52  scalarField(mesh().points().size(), great),
53  nearest
54  );
55 
56  if (signed_)
57  {
58  List<volumeType> volType;
59  surfPtr_().getVolumeType(mesh().points(), volType);
60 
61  forAll(nearest, i)
62  {
63  if
64  (
65  volType[i] != volumeType::outside
66  && volType[i] != volumeType::inside
67  )
68  {
70  << "Point " << mesh().points()[i] << " could not be "
71  << "classified as either inside or outside the surface "
72  << surfPtr_->name() << exit(FatalError);
73  }
74 
75  pointDistance[i] =
76  (volType[i] == volumeType::outside ? +1 : -1)
77  *mag(mesh().points()[i] - nearest[i].hitPoint());
78  }
79  }
80  else
81  {
82  forAll(nearest, i)
83  {
84  pointDistance[i] =
85  mag(mesh().points()[i] - nearest[i].hitPoint());
86  }
87  }
88  }
89 
90  // Construct an iso-surface at the given distance
91  return autoPtr<cutPolyIsoSurface>
92  (
93  new cutPolyIsoSurface(mesh(), pointDistance, distance_, zoneName())
94  );
95 }
96 
97 
98 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
99 
101 (
102  const word& name,
103  const polyMesh& mesh,
104  const dictionary& dict
105 )
106 :
108  surfPtr_
109  (
111  (
112  dict.lookup("surfaceType"),
113  IOobject
114  (
115  dict.lookupOrDefault("surfaceName", name),
116  mesh.time().constant(),
117  searchableSurface::geometryDir(mesh.time()),
118  mesh.time(),
119  IOobject::MUST_READ,
120  IOobject::NO_WRITE
121  ),
122  dict
123  )
124  ),
125  distance_(dict.lookup<scalar>("distance")),
126  signed_(readBool(dict.lookup("signed")))
127 {}
128 
129 
130 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
131 
133 {}
134 
135 
136 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
137 
139 {
140  return timeIndex() == -1;
141 }
142 
143 
145 {
146  os << "distanceSurface: " << name() << " :"
147  << " surface:" << surfPtr_().name()
148  << " distance:" << distance_
149  << " faces:" << faces().size()
150  << " points:" << points().size();
151 }
152 
153 
154 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
Macros for easy insertion into run-time selection tables.
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
Definition: IOobject.H:99
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:57
A list of keyword definitions, which are a keyword followed by any number of values (e....
Definition: dictionary.H:162
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:80
virtual const pointField & points() const
Return raw points.
Definition: polyMesh.C:1313
An abstract class for surfaces with sampling.
const polyMesh & mesh() const
Access to the underlying mesh.
A sampledSurface defined by a distance to a surface.
distanceSurface(const word &name, const polyMesh &mesh, const dictionary &dict)
Construct from dictionary.
virtual bool needsUpdate() const
Does the surface need an update?
virtual void print(Ostream &) const
Print.
A base class for sampled surfaces constructed from iso-surfaces.
const word & zoneName() const
Access the zoneName.
virtual const pointField & points() const
Points of surface.
Base class of (analytical or triangulated) surface. Encapsulates all the search routines....
A class for handling words, derived from string.
Definition: word.H:62
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:334
const pointField & points
label nPoints
defineTypeNameAndDebug(cutPlane, 0)
addToRunTimeSelectionTable(sampledSurface, cutPlane, word)
Namespace for OpenFOAM.
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
bool readBool(Istream &)
Definition: boolIO.C:66
word name(const bool)
Return a word representation of a bool.
Definition: boolIO.C:39
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
dimensioned< scalar > mag(const dimensioned< Type > &)
tmp< DimensionedField< TypeR, GeoMesh > > New(const tmp< DimensionedField< TypeR, GeoMesh >> &tdf1, const word &name, const dimensionSet &dimensions)
error FatalError
label timeIndex
Definition: getTimeIndex.H:4
dictionary dict