FreeFOAM The Cross-Platform CFD Toolkit
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 | Copyright (C) 1991-2010 OpenCFD Ltd.
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/triSurface.H>
28 
29 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
30 
31 
32 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
33 
34 
35 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
36 
37 
38 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
39 
41 {
42  const vectorField& n = s.faceNormals();
43 
44  if (elementType_ == triPointRef::NONE)
45  {
46  return n[index()];
47  }
48  else if (elementType_ == triPointRef::EDGE)
49  {
50  const labelList& eFaces = s.edgeFaces()[index()];
51 
52  if (eFaces.size() == 1)
53  {
54  return n[eFaces[0]];
55  }
56  else
57  {
58  vector edgeNormal(vector::zero);
59 
60  forAll(eFaces, i)
61  {
62  edgeNormal += n[eFaces[i]];
63  }
64  return edgeNormal/(mag(edgeNormal) + VSMALL);
65  }
66  }
67  else
68  {
69  return s.pointNormals()[index()];
70  }
71 }
72 
73 
74 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
75 
76 
77 // * * * * * * * * * * * * * * * Friend Functions * * * * * * * * * * * * * //
78 
79 
80 // * * * * * * * * * * * * * * * Friend Operators * * * * * * * * * * * * * //
81 
83 {
84  if (elementType_ == triPointRef::NONE)
85  {
86  os << "trianglecoords:" << s[index()].tri(s.points());
87  }
88  else if (elementType() == triPointRef::EDGE)
89  {
90  const edge& e = s.edges()[index()];
91 
92  os << "edgecoords:" << e.line(s.localPoints());
93  }
94  else
95  {
96  os << "pointcoord:" << s.localPoints()[index()];
97  }
98 }
99 
100 
102 {
103  label elType;
104  is >> static_cast<pointIndexHit&>(sl)
105  >> elType >> sl.triangle_;
106  sl.elementType_ = triPointRef::proxType(elType);
107  return is;
108 }
109 
110 
111 Foam::Ostream& Foam::operator<<(Ostream& os, const surfaceLocation& sl)
112 {
113  return os
114  << static_cast<const pointIndexHit&>(sl)
115  << token::SPACE << label(sl.elementType_)
116  << token::SPACE << sl.triangle_;
117 }
118 
119 
120 Foam::Ostream& Foam::operator<<
121 (
122  Ostream& os,
123  const InfoProxy<surfaceLocation>& ip
124 )
125 {
126  const surfaceLocation& sl = ip.t_;
127 
128  if (sl.elementType() == triPointRef::NONE)
129  {
130  os << "coord:" << sl.rawPoint()
131  << " inside triangle:" << sl.index()
132  << " excludeTriangle:" << sl.triangle();
133  }
134  else if (sl.elementType() == triPointRef::EDGE)
135  {
136  os << "coord:" << sl.rawPoint()
137  << " on edge:" << sl.index()
138  << " excludeTriangle:" << sl.triangle();
139  }
140  else
141  {
142  os << "coord:" << sl.rawPoint()
143  << " on point:" << sl.index()
144  << " excludeTriangle:" << sl.triangle();
145  }
146 
147  if (sl.hit())
148  {
149  os << " (hit)";
150  }
151  else
152  {
153  os << " (miss)";
154  }
155 
156  return os;
157 }
158 
159 
160 // ************************ vim: set sw=4 sts=4 et: ************************ //