surfaceLocation.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 | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2011-2016 OpenFOAM Foundation
9 -------------------------------------------------------------------------------
10 License
11  This file is part of OpenFOAM.
12 
13  OpenFOAM is free software: you can redistribute it and/or modify it
14  under the terms of the GNU General Public License as published by
15  the Free Software Foundation, either version 3 of the License, or
16  (at your option) any later version.
17 
18  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21  for more details.
22 
23  You should have received a copy of the GNU General Public License
24  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25 
26 \*---------------------------------------------------------------------------*/
27 
28 #include "surfaceLocation.H"
29 #include "triSurface.H"
30 
31 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
32 
34 {
35  const vectorField& n = s.faceNormals();
36 
37  if (elementType_ == triPointRef::NONE)
38  {
39  return n[index()];
40  }
41  else if (elementType_ == triPointRef::EDGE)
42  {
43  const labelList& eFaces = s.edgeFaces()[index()];
44 
45  if (eFaces.size() == 1)
46  {
47  return n[eFaces[0]];
48  }
49  else
50  {
51  vector edgeNormal(Zero);
52 
53  forAll(eFaces, i)
54  {
55  edgeNormal += n[eFaces[i]];
56  }
57  return edgeNormal/(mag(edgeNormal) + VSMALL);
58  }
59  }
60  else
61  {
62  return s.pointNormals()[index()];
63  }
64 }
65 
66 
67 // * * * * * * * * * * * * * * * Friend Operators * * * * * * * * * * * * * //
68 
70 {
71  if (elementType_ == triPointRef::NONE)
72  {
73  os << "trianglecoords:" << s[index()].tri(s.points());
74  }
75  else if (elementType() == triPointRef::EDGE)
76  {
77  const edge& e = s.edges()[index()];
78 
79  os << "edgecoords:" << e.line(s.localPoints());
80  }
81  else
82  {
83  os << "pointcoord:" << s.localPoints()[index()];
84  }
85 }
86 
87 
89 {
90  label elType;
91  is >> static_cast<pointIndexHit&>(sl)
92  >> elType >> sl.triangle_;
93  sl.elementType_ = triPointRef::proxType(elType);
94  return is;
95 }
96 
97 
99 {
100  return os
101  << static_cast<const pointIndexHit&>(sl)
102  << token::SPACE << label(sl.elementType_)
103  << token::SPACE << sl.triangle_;
104 }
105 
106 
107 Foam::Ostream& Foam::operator<<
108 (
109  Ostream& os,
111 )
112 {
113  const surfaceLocation& sl = ip.t_;
114 
115  if (sl.elementType() == triPointRef::NONE)
116  {
117  os << "coord:" << sl.rawPoint()
118  << " inside triangle:" << sl.index()
119  << " excludeTriangle:" << sl.triangle();
120  }
121  else if (sl.elementType() == triPointRef::EDGE)
122  {
123  os << "coord:" << sl.rawPoint()
124  << " on edge:" << sl.index()
125  << " excludeTriangle:" << sl.triangle();
126  }
127  else
128  {
129  os << "coord:" << sl.rawPoint()
130  << " on point:" << sl.index()
131  << " excludeTriangle:" << sl.triangle();
132  }
133 
134  if (sl.hit())
135  {
136  os << " (hit)";
137  }
138  else
139  {
140  os << " (miss)";
141  }
142 
143  return os;
144 }
145 
146 
147 // ************************************************************************* //
Foam::surfaceLocation::write
void write(Ostream &os, const triSurface &s) const
Write info to os.
Definition: surfaceLocation.C:69
Foam::PointIndexHit::index
label index() const
Return index.
Definition: PointIndexHit.H:113
Foam::InfoProxy
A helper class for outputting values to Ostream.
Definition: InfoProxy.H:47
s
gmvFile<< "tracers "<< particles.size()<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().x()<< " ";}gmvFile<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().y()<< " ";}gmvFile<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().z()<< " ";}gmvFile<< nl;forAll(lagrangianScalarNames, i){ word name=lagrangianScalarNames[i];IOField< scalar > s(IOobject(name, runTime.timeName(), cloud::prefix, mesh, IOobject::MUST_READ, IOobject::NO_WRITE))
Definition: gmvOutputSpray.H:25
Foam::Zero
static constexpr const zero Zero
Global zero.
Definition: zero.H:128
Foam::surfaceLocation
Contains information about location on a triSurface.
Definition: surfaceLocation.H:75
Foam::edge
An edge is a list of two point labels. The functionality it provides supports the discretisation on a...
Definition: edge.H:63
Foam::PointIndexHit::hit
bool hit() const
Is there a hit.
Definition: PointIndexHit.H:107
Foam::operator>>
Istream & operator>>(Istream &, directionInfo &)
Definition: directionInfo.C:228
triSurface.H
Foam::surfaceLocation::elementType
triPointRef::proxType & elementType()
Definition: surfaceLocation.H:122
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:290
n
label n
Definition: TABSMDCalcMethod2.H:31
Foam::PointIndexHit
This class describes the interaction of (usually) a face and a point. It carries the info of a succes...
Definition: PointIndexHit.H:55
Foam::PointIndexHit::rawPoint
const Point & rawPoint() const
Return point with no checking.
Definition: PointIndexHit.H:145
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:62
Foam::Field< vector >
Foam::triSurface
Triangulated surface description with patch information.
Definition: triSurface.H:70
Foam::Istream
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:61
Foam::triangle::NONE
Definition: triangle.H:99
Foam::surfaceLocation::normal
vector normal(const triSurface &s) const
Normal. Approximate for points.
Definition: surfaceLocation.C:33
Foam::triangle::EDGE
Definition: triangle.H:101
Foam::triangle::proxType
proxType
Return types for classify.
Definition: triangle.H:97
Foam::Vector< scalar >
Foam::List< label >
Foam::mag
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)
Foam::token::SPACE
Space [isspace].
Definition: token.H:112
Foam::constant::electromagnetic::e
const dimensionedScalar e
Elementary charge.
Definition: createFields.H:11
Foam::surfaceLocation::triangle
label & triangle()
Definition: surfaceLocation.H:132
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:56
Foam::operator<<
Ostream & operator<<(Ostream &, const boundaryPatch &)
Definition: boundaryPatch.C:102
surfaceLocation.H