surfaceLocation.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-2018 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 "surfaceLocation.H"
27 #include "triSurface.H"
28 
29 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
30 
32 {
33  const vectorField& n = s.faceNormals();
34 
35  if (elementType_ == triPointRef::NONE)
36  {
37  return n[index()];
38  }
39  else if (elementType_ == triPointRef::EDGE)
40  {
41  const labelList& eFaces = s.edgeFaces()[index()];
42 
43  if (eFaces.size() == 1)
44  {
45  return n[eFaces[0]];
46  }
47  else
48  {
49  vector edgeNormal(Zero);
50 
51  forAll(eFaces, i)
52  {
53  edgeNormal += n[eFaces[i]];
54  }
55  return edgeNormal/(mag(edgeNormal) + vSmall);
56  }
57  }
58  else
59  {
60  return s.pointNormals()[index()];
61  }
62 }
63 
64 
65 // * * * * * * * * * * * * * * * Friend Operators * * * * * * * * * * * * * //
66 
68 {
69  if (elementType_ == triPointRef::NONE)
70  {
71  os << "trianglecoords:" << s[index()].tri(s.points());
72  }
73  else if (elementType() == triPointRef::EDGE)
74  {
75  const edge& e = s.edges()[index()];
76 
77  os << "edgecoords:" << e.line(s.localPoints());
78  }
79  else
80  {
81  os << "pointcoord:" << s.localPoints()[index()];
82  }
83 }
84 
85 
87 {
88  label elType;
89  is >> static_cast<pointIndexHit&>(sl)
90  >> elType >> sl.triangle_;
91  sl.elementType_ = triPointRef::proxType(elType);
92  return is;
93 }
94 
95 
97 {
98  return os
99  << static_cast<const pointIndexHit&>(sl)
100  << token::SPACE << label(sl.elementType_)
101  << token::SPACE << sl.triangle_;
102 }
103 
104 
105 Foam::Ostream& Foam::operator<<
106 (
107  Ostream& os,
109 )
110 {
111  const surfaceLocation& sl = ip.t_;
112 
113  if (sl.elementType() == triPointRef::NONE)
114  {
115  os << "coord:" << sl.rawPoint()
116  << " inside triangle:" << sl.index()
117  << " excludeTriangle:" << sl.triangle();
118  }
119  else if (sl.elementType() == triPointRef::EDGE)
120  {
121  os << "coord:" << sl.rawPoint()
122  << " on edge:" << sl.index()
123  << " excludeTriangle:" << sl.triangle();
124  }
125  else
126  {
127  os << "coord:" << sl.rawPoint()
128  << " on point:" << sl.index()
129  << " excludeTriangle:" << sl.triangle();
130  }
131 
132  if (sl.hit())
133  {
134  os << " (hit)";
135  }
136  else
137  {
138  os << " (miss)";
139  }
140 
141  return os;
142 }
143 
144 
145 // ************************************************************************* //
label n
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
A helper class for outputting values to Ostream.
Definition: InfoProxy.H:50
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
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:57
This class describes the interaction of (usually) a face and a point. It carries the info of a succes...
Definition: PointIndexHit.H:54
const Point & rawPoint() const
Return point with no checking.
label index() const
Return index.
bool hit() const
Is there a hit.
An edge is a list of two point labels. The functionality it provides supports the discretisation on a...
Definition: edge.H:61
Contains information about location on a triSurface.
vector normal(const triSurface &s) const
Normal. Approximate for points.
triPointRef::proxType & elementType()
void write(Ostream &os, const triSurface &s) const
Write info to os.
Triangulated surface description with patch information.
Definition: triSurface.H:69
proxType
Return types for classify.
Definition: triangle.H:90
gmvFile<< "tracers "<< particles.size()<< nl;forAllConstIter(Cloud< passiveParticle >, particles, iter){ gmvFile<< iter().position().x()<< " ";}gmvFile<< nl;forAllConstIter(Cloud< passiveParticle >, particles, iter){ gmvFile<< iter().position().y()<< " ";}gmvFile<< nl;forAllConstIter(Cloud< passiveParticle >, particles, iter){ gmvFile<< iter().position().z()<< " ";}gmvFile<< nl;forAll(lagrangianScalarNames, i){ word name=lagrangianScalarNames[i];IOField< scalar > s(IOobject(name, runTime.name(), cloud::prefix, mesh, IOobject::MUST_READ, IOobject::NO_WRITE))
static const zero Zero
Definition: zero.H:97
const doubleScalar e
Definition: doubleScalar.H:106
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
Istream & operator>>(Istream &, pistonPointEdgeData &)
dimensioned< scalar > mag(const dimensioned< Type > &)
Ostream & operator<<(Ostream &os, const fvConstraints &constraints)