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-2026 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 sampledIsoSurfaceSurface::calcIsoSurf(pointDistance, distance_);
92 }
93 
94 
95 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
96 
98 (
99  const word& name,
100  const polyMesh& mesh,
101  const dictionary& dict
102 )
103 :
105  surfPtr_
106  (
108  (
109  dict.lookup("surfaceType"),
110  IOobject
111  (
112  dict.lookupOrDefault("surfaceName", name),
113  mesh.time().constant(),
114  searchableSurface::geometryDir(mesh.time()),
115  mesh.time(),
116  IOobject::MUST_READ,
117  IOobject::NO_WRITE
118  ),
119  dict
120  )
121  ),
122  distance_(dict.lookup<scalar>("distance")),
123  signed_(readBool(dict.lookup("signed")))
124 {}
125 
126 
127 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
128 
130 {}
131 
132 
133 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
134 
136 {
137  return timeIndex() == -1;
138 }
139 
140 
142 {
143  os << "distanceSurface: " << name() << " :"
144  << " surface:" << surfPtr_().name()
145  << " distance:" << distance_
146  << " faces:" << faces().size()
147  << " points:" << points().size();
148 }
149 
150 
151 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:449
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 keywords followed by any number of values (e.g. words and numbers) or sub-dictionaries.
Definition: dictionary.H:162
Motion of the mesh specified as a list of pointMeshMovers.
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:78
virtual const pointField & points() const
Return raw points.
Definition: polyMesh.C:1295
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
Write.
A base class for sampled surfaces constructed from iso-surfaces.
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:63
Foam::fvMesh mesh(Foam::IOobject(regionName, runTime.name(), runTime, Foam::IOobject::MUST_READ), false)
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:334
const pointField & points
label nPoints
const dimensionSet time
defineTypeNameAndDebug(cutPlane, 0)
addToRunTimeSelectionTable(sampledSurface, cutPlane, word)
const unitSet & lookup(const word &unitName)
Lookup and return the named unit from the table.
Definition: units.C:346
Namespace for OpenFOAM.
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
bool readBool(Istream &)
Definition: boolIO.C:63
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
word name(const LagrangianState state)
Return a string representation of a Lagrangian state enumeration.
tmp< DimensionedField< scalar, GeoMesh, Field > > mag(const DimensionedField< Type, GeoMesh, PrimitiveField > &df)
error FatalError
tmp< DimensionedField< TypeR, GeoMesh, Field > > New(const tmp< DimensionedField< TypeR, GeoMesh, Field >> &tdf1, const word &name, const dimensionSet &dimensions)
label timeIndex
Definition: getTimeIndex.H:4
dictionary dict