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  Copyright (C) 2020 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 \*---------------------------------------------------------------------------*/
28 
29 #include "surfaceLocation.H"
30 #include "triSurface.H"
31 
32 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
33 
35 {
36  const vectorField& n = s.faceNormals();
37 
38  if (elementType_ == triPointRef::NONE)
39  {
40  return n[index()];
41  }
42  else if (elementType_ == triPointRef::EDGE)
43  {
44  const labelList& eFaces = s.edgeFaces()[index()];
45 
46  if (eFaces.size() == 1)
47  {
48  return n[eFaces[0]];
49  }
50  else
51  {
52  // Average edge normal
53  vector edgeNormal(Zero);
54 
55  for (const label facei : eFaces)
56  {
57  edgeNormal += n[facei];
58  }
59 
60  return edgeNormal/(mag(edgeNormal) + VSMALL);
61  }
62  }
63  else // triPointRef::POINT
64  {
65  return s.pointNormals()[index()];
66  }
67 }
68 
69 
70 // * * * * * * * * * * * * * * * Friend Operators * * * * * * * * * * * * * //
71 
73 {
74  if (elementType_ == triPointRef::NONE)
75  {
76  os << "trianglecoords:" << s[index()].tri(s.points());
77  }
78  else if (elementType() == triPointRef::EDGE)
79  {
80  const edge& e = s.edges()[index()];
81 
82  os << "edgecoords:" << e.line(s.localPoints());
83  }
84  else // triPointRef::POINT
85  {
86  os << "pointcoord:" << s.localPoints()[index()];
87  }
88 }
89 
90 
92 {
93  label elType;
94  is >> static_cast<pointIndexHit&>(sl)
95  >> elType >> sl.triangle_;
96 
97  sl.elementType_ = triPointRef::proxType(elType);
98  return is;
99 }
100 
101 
103 {
104  return os
105  << static_cast<const pointIndexHit&>(sl)
106  << token::SPACE << label(sl.elementType_)
107  << token::SPACE << sl.triangle_;
108 }
109 
110 
111 Foam::Ostream& Foam::operator<<
112 (
113  Ostream& os,
115 )
116 {
117  const surfaceLocation& sl = ip.t_;
118 
119  os << "coord:" << sl.point();
120 
121  if (sl.elementType() == triPointRef::NONE)
122  {
123  os << " inside triangle:";
124  }
125  else if (sl.elementType() == triPointRef::EDGE)
126  {
127  os << " on edge:";
128  }
129  else // triPointRef::POINT
130  {
131  os << " on point:";
132  }
133 
134  os << sl.index()
135  << " excludeTriangle:" << sl.triangle();
136 
137  if (sl.hit())
138  {
139  os << " (hit)";
140  }
141  else
142  {
143  os << " (miss)";
144  }
145 
146  return os;
147 }
148 
149 
150 // ************************************************************************* //
Foam::surfaceLocation::write
void write(Ostream &os, const triSurface &s) const
Write info about selected face index to a stream.
Definition: surfaceLocation.C:72
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 (0)
Definition: zero.H:131
Foam::surfaceLocation
Contains information about location on a triSurface.
Definition: surfaceLocation.H:71
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::operator>>
Istream & operator>>(Istream &, directionInfo &)
Definition: directionInfo.C:230
triSurface.H
Foam::operator<<
Ostream & operator<<(Ostream &, const boundaryPatch &p)
Write boundaryPatch as dictionary entries (without surrounding braces)
Definition: boundaryPatch.C:83
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:52
Foam::PointIndexHit::hit
bool hit() const noexcept
Is there a hit?
Definition: PointIndexHit.H:130
Foam::Field< vector >
Foam::triSurface
Triangulated surface description with patch information.
Definition: triSurface.H:76
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
Unknown proximity.
Definition: triangle.H:95
Foam::surfaceLocation::normal
vector normal(const triSurface &s) const
Normal. Approximate for points.
Definition: surfaceLocation.C:34
os
OBJstream os(runTime.globalPath()/outputName)
Foam::triangle::EDGE
Close to edge.
Definition: triangle.H:97
Foam::surfaceLocation::triangle
label & triangle() noexcept
Definition: surfaceLocation.H:128
Foam::triangle::proxType
proxType
The proximity classifications.
Definition: triangle.H:93
Foam::Vector< scalar >
Foam::List< label >
Foam::PointIndexHit::index
label index() const noexcept
Return the hit index.
Definition: PointIndexHit.H:136
Foam::surfaceLocation::elementType
triPointRef::proxType & elementType() noexcept
Definition: surfaceLocation.H:118
Foam::mag
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)
Foam::token::SPACE
Space [isspace].
Definition: token.H:125
Foam::constant::electromagnetic::e
const dimensionedScalar e
Elementary charge.
Definition: createFields.H:11
Foam::PointIndexHit::point
const point_type & point() const noexcept
Return point, no checks.
Definition: PointIndexHit.H:142
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:56
surfaceLocation.H