offsetSurface.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 | Copyright (C) 2014 OpenFOAM Foundation
6  \\/ M anipulation | Copyright (C) 2015 OpenCFD Ltd.
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 "offsetSurface.H"
28 #include "triSurface.H"
29 #include "triSurfaceSearch.H"
30 
31 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
32 
33 namespace Foam
34 {
35 namespace extrudeModels
36 {
37 
38 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
39 
40 defineTypeNameAndDebug(offsetSurface, 0);
41 
42 addToRunTimeSelectionTable(extrudeModel, offsetSurface, dictionary);
43 
44 
45 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
46 
48 :
49  extrudeModel(typeName, dict),
50  project_(coeffDict_.lookupOrDefault("project", false))
51 {
52  // Read surface
53  fileName baseName(coeffDict_.lookup("baseSurface"));
54  baseName.expand();
55  baseSurfPtr_.reset(new triSurface(baseName));
56 
57  // Construct search engine
59 
60  // Read offsetted surface
61  fileName offsetName(coeffDict_.lookup("offsetSurface"));
62  offsetName.expand();
63  offsetSurfPtr_.reset(new triSurface(offsetName));
64 
65  // Construct search engine
67 
68 
69  const triSurface& b = baseSurfPtr_();
70  const triSurface& o = offsetSurfPtr_();
71 
72  if
73  (
74  b.size() != o.size()
75  || b.nPoints() != o.nPoints()
76  || b.nEdges() != o.nEdges()
77  )
78  {
80  << "offsetSurface " << offsetName
81  << " should have exactly the same topology as the baseSurface "
82  << baseName << exit(FatalIOError);
83  }
84 }
85 
86 
87 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
88 
90 {}
91 
92 
93 // * * * * * * * * * * * * * * * * Operators * * * * * * * * * * * * * * * * //
94 
95 point offsetSurface::operator()
96 (
97  const point& surfacePoint,
98  const vector& surfaceNormal,
99  const label layer
100 ) const
101 {
102  if (layer == 0)
103  {
104  return surfacePoint;
105  }
106  else
107  {
108  pointField samples(1, surfacePoint);
109  scalarField nearestDistSqr(1, GREAT);
110  List<pointIndexHit> info;
111  baseSearchPtr_().findNearest(samples, nearestDistSqr, info);
112 
113  label triI = info[0].index();
114 
115 
116  const triSurface& base = baseSurfPtr_();
117  const triPointRef baseTri(base[triI].tri(base.points()));
118 
119  List<scalar> bary;
120  baseTri.barycentric(surfacePoint, bary);
121 
122  const triSurface& offset = offsetSurfPtr_();
123  const triPointRef offsetTri(offset[triI].tri(offset.points()));
124 
125  const point offsetPoint
126  (
127  bary[0]*offsetTri.a()
128  +bary[1]*offsetTri.b()
129  +bary[2]*offsetTri.c()
130  );
131 
132  point interpolatedPoint
133  (
134  surfacePoint + sumThickness(layer)*(offsetPoint-surfacePoint)
135  );
136 
137 
138  //- Either return interpolatedPoint or re-project onto surface (since
139  // snapping might not have do so exactly)
140 
141  if (project_)
142  {
143  // Re-project onto surface
144  offsetSearchPtr_().findNearest
145  (
146  pointField(1, interpolatedPoint),
147  scalarField(1, GREAT),
148  info
149  );
150  return info[0].hitPoint();
151  }
152  else
153  {
154  return interpolatedPoint;
155  }
156  }
157 }
158 
159 
160 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
161 
162 } // End namespace extrudeModels
163 } // End namespace Foam
164 
165 // ************************************************************************* //
Foam::pointField
vectorField pointField
pointField is a vectorField.
Definition: pointFieldFwd.H:42
Foam::extrudeModels::offsetSurface::baseSearchPtr_
autoPtr< triSurfaceSearch > baseSearchPtr_
search engine
Definition: offsetSurface.H:66
Foam::scalarField
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
Definition: primitiveFieldsFwd.H:48
Foam::PrimitivePatch::points
const Field< PointType > & points() const
Return reference to global points.
Definition: PrimitivePatchTemplate.H:282
Foam::fileName
A class for handling file names.
Definition: fileName.H:69
Foam::extrudeModels::defineTypeNameAndDebug
defineTypeNameAndDebug(cyclicSector, 0)
Foam::extrudeModel
Top level extrusion model class.
Definition: extrudeModel.H:51
Foam::PrimitivePatch::nEdges
label nEdges() const
Return number of edges in patch.
Definition: PrimitivePatchTemplate.H:299
Foam::dictionary::lookup
ITstream & lookup(const word &, bool recursive=false, bool patternMatch=true) const
Find and return an entry data stream.
Definition: dictionary.C:449
Foam::extrudeModels::offsetSurface::baseSurfPtr_
autoPtr< triSurface > baseSurfPtr_
surface
Definition: offsetSurface.H:63
Foam::FatalIOError
IOerror FatalIOError
Foam::triSurfaceSearch
Helper class to search on triSurface.
Definition: triSurfaceSearch.H:55
Foam::triangle::barycentric
scalar barycentric(const point &pt, List< scalar > &bary) const
Calculate the barycentric coordinates of the given.
Definition: triangleI.H:281
Foam::triangle
A triangle primitive used to calculate face normals and swept volumes.
Definition: triangle.H:59
samples
scalarField samples(nIntervals, 0)
Foam::triangle::c
const Point & c() const
Return third vertex.
Definition: triangleI.H:95
Foam::label
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
Foam::constant::physicoChemical::b
const dimensionedScalar b
Wien displacement law constant: default SI units: [m.K].
Definition: createFields.H:28
Foam::Field
Pre-declare SubField and related Field type.
Definition: Field.H:57
Foam::triSurface
Triangulated surface description with patch information.
Definition: triSurface.H:57
Foam::triangle::a
const Point & a() const
Return first vertex.
Definition: triangleI.H:83
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::PrimitivePatch::nPoints
label nPoints() const
Return number of points supporting patch faces.
Definition: PrimitivePatchTemplate.H:293
Foam::dictionary
A list of keyword definitions, which are a keyword followed by any number of values (e....
Definition: dictionary.H:137
Foam::extrudeModels::addToRunTimeSelectionTable
addToRunTimeSelectionTable(extrudeModel, cyclicSector, dictionary)
Foam::triangle::b
const Point & b() const
Return second vertex.
Definition: triangleI.H:89
offsetSurface.H
addToRunTimeSelectionTable.H
Macros for easy insertion into run-time selection tables.
Foam
Namespace for OpenFOAM.
Definition: combustionModel.C:30
Foam::exit
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
Foam::extrudeModels::offsetSurface::~offsetSurface
virtual ~offsetSurface()
Destructor.
Definition: offsetSurface.C:89
Foam::extrudeModels::offsetSurface::offsetSearchPtr_
autoPtr< triSurfaceSearch > offsetSearchPtr_
search engine
Definition: offsetSurface.H:72
Foam::Vector< scalar >
Foam::List
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: HashTable.H:59
Foam::string::expand
string & expand(const bool allowEmpty=false)
Expand initial tildes and all occurences of environment variables.
Definition: string.C:98
triSurfaceSearch.H
Foam::extrudeModels::offsetSurface::offsetSurfPtr_
autoPtr< triSurface > offsetSurfPtr_
offsets
Definition: offsetSurface.H:69
Foam::extrudeModels::offsetSurface::offsetSurface
offsetSurface(const dictionary &dict)
Construct from dictionary.
Definition: offsetSurface.C:47
Foam::extrudeModel::coeffDict_
const dictionary & coeffDict_
Definition: extrudeModel.H:63
FatalIOErrorInFunction
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Definition: error.H:330
Foam::List::size
void size(const label)
Override size to be inconsistent with allocated storage.