surfaceLocation.C
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #include "surfaceLocation.H"
00028 #include "triSurface.H"
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041 Foam::vector Foam::surfaceLocation::normal(const triSurface& s) const
00042 {
00043 const vectorField& n = s.faceNormals();
00044
00045 if (elementType_ == triPointRef::NONE)
00046 {
00047 return n[index()];
00048 }
00049 else if (elementType_ == triPointRef::EDGE)
00050 {
00051 const labelList& eFaces = s.edgeFaces()[index()];
00052
00053 if (eFaces.size() == 1)
00054 {
00055 return n[eFaces[0]];
00056 }
00057 else
00058 {
00059 vector edgeNormal(vector::zero);
00060
00061 forAll(eFaces, i)
00062 {
00063 edgeNormal += n[eFaces[i]];
00064 }
00065 return edgeNormal/(mag(edgeNormal) + VSMALL);
00066 }
00067 }
00068 else
00069 {
00070 return s.pointNormals()[index()];
00071 }
00072 }
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083 void Foam::surfaceLocation::write(Ostream& os, const triSurface& s) const
00084 {
00085 if (elementType_ == triPointRef::NONE)
00086 {
00087 os << "trianglecoords:" << s[index()].tri(s.points());
00088 }
00089 else if (elementType() == triPointRef::EDGE)
00090 {
00091 const edge& e = s.edges()[index()];
00092
00093 os << "edgecoords:" << e.line(s.localPoints());
00094 }
00095 else
00096 {
00097 os << "pointcoord:" << s.localPoints()[index()];
00098 }
00099 }
00100
00101
00102 Foam::Istream& Foam::operator>>(Istream& is, surfaceLocation& sl)
00103 {
00104 label elType;
00105 is >> static_cast<pointIndexHit&>(sl)
00106 >> elType >> sl.triangle_;
00107 sl.elementType_ = triPointRef::proxType(elType);
00108 return is;
00109 }
00110
00111
00112 Foam::Ostream& Foam::operator<<(Ostream& os, const surfaceLocation& sl)
00113 {
00114 return os
00115 << static_cast<const pointIndexHit&>(sl)
00116 << token::SPACE << label(sl.elementType_)
00117 << token::SPACE << sl.triangle_;
00118 }
00119
00120
00121 Foam::Ostream& Foam::operator<<
00122 (
00123 Ostream& os,
00124 const InfoProxy<surfaceLocation>& ip
00125 )
00126 {
00127 const surfaceLocation& sl = ip.t_;
00128
00129 if (sl.elementType() == triPointRef::NONE)
00130 {
00131 os << "coord:" << sl.rawPoint()
00132 << " inside triangle:" << sl.index()
00133 << " excludeTriangle:" << sl.triangle();
00134 }
00135 else if (sl.elementType() == triPointRef::EDGE)
00136 {
00137 os << "coord:" << sl.rawPoint()
00138 << " on edge:" << sl.index()
00139 << " excludeTriangle:" << sl.triangle();
00140 }
00141 else
00142 {
00143 os << "coord:" << sl.rawPoint()
00144 << " on point:" << sl.index()
00145 << " excludeTriangle:" << sl.triangle();
00146 }
00147
00148 if (sl.hit())
00149 {
00150 os << " (hit)";
00151 }
00152 else
00153 {
00154 os << " (miss)";
00155 }
00156
00157 return os;
00158 }
00159
00160
00161
Copyright © 2000-2009 OpenCFD Ltd