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 
72 void Foam::surfaceLocation::write(Ostream& os, const triSurface& s) const
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 
91 Foam::Istream& Foam::operator>>(Istream& is, surfaceLocation& sl)
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 
102 Foam::Ostream& Foam::operator<<(Ostream& os, const surfaceLocation& sl)
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,
114  const InfoProxy<surfaceLocation>& iproxy
115 )
116 {
117  const auto& sl = *iproxy;
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 // ************************************************************************* //
void size(const label n)
Older name for setAddressableSize.
Definition: UList.H:116
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)
Unknown proximity.
Definition: triangle.H:239
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
PointIndexHit< point > pointIndexHit
A PointIndexHit with a 3D point.
Definition: pointIndexHit.H:58
This class describes the interaction of an object (often a face) and a point. It carries the info of ...
Definition: pointIndexHit.H:44
const dimensionedScalar e
Elementary charge.
Definition: createFields.H:11
proxType
Proximity classifications.
Definition: triangle.H:237
Close to edge.
Definition: triangle.H:241
Istream & operator>>(Istream &, directionInfo &)
Space [isspace].
Definition: token.H:131
label index() const noexcept
Return the hit index.
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:56
A Vector of values with scalar precision, where scalar is float/double depending on the compilation f...
OBJstream os(runTime.globalPath()/outputName)
Ostream & operator<<(Ostream &, const boundaryPatch &p)
Write boundaryPatch as dictionary entries (without surrounding braces)
Definition: boundaryPatch.C:77
void write(Ostream &os, const triSurface &s) const
Write info about selected face index to a stream.
label n
vector normal(const triSurface &s) const
Normal. Approximate for points.
Triangulated surface description with patch information.
Definition: triSurface.H:71
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))
static constexpr const zero Zero
Global zero (0)
Definition: zero.H:127