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 "PrimitivePatch.H"
00028 #include "Map.H"
00029
00030
00031
00032
00033
00034 template
00035 <
00036 class Face,
00037 template<class> class FaceList,
00038 class PointField,
00039 class PointType
00040 >
00041
00042 void
00043 Foam::PrimitivePatch<Face, FaceList, PointField, PointType>::
00044 calcMeshData() const
00045 {
00046 if (debug)
00047 {
00048 Pout<< "PrimitivePatch<Face, FaceList, PointField, PointType>::"
00049 "calcMeshData() : "
00050 "calculating mesh data in PrimitivePatch"
00051 << endl;
00052 }
00053
00054
00055
00056 if (meshPointsPtr_ || localFacesPtr_)
00057 {
00058 FatalErrorIn
00059 (
00060 "PrimitivePatch<Face, FaceList, PointField, PointType>::"
00061 "calcMeshData()"
00062 ) << "meshPointsPtr_ or localFacesPtr_already allocated"
00063 << abort(FatalError);
00064 }
00065
00066
00067
00068 Map<label> markedPoints(4*this->size());
00069
00070
00071
00072
00073
00074
00075
00076
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00091
00092
00093
00095
00096
00098
00099
00100
00101
00102
00103
00104 DynamicList<label> meshPoints(2*this->size());
00105 forAll (*this, faceI)
00106 {
00107 const Face& curPoints = this->operator[](faceI);
00108
00109 forAll (curPoints, pointI)
00110 {
00111 if (markedPoints.insert(curPoints[pointI], meshPoints.size()))
00112 {
00113 meshPoints.append(curPoints[pointI]);
00114 }
00115 }
00116 }
00117
00118 meshPointsPtr_ = new labelList(meshPoints, true);
00119
00120
00121
00122
00123
00124 localFacesPtr_ = new List<Face>(*this);
00125 List<Face>& lf = *localFacesPtr_;
00126
00127 forAll (*this, faceI)
00128 {
00129 const Face& curFace = this->operator[](faceI);
00130 lf[faceI].setSize(curFace.size());
00131
00132 forAll (curFace, labelI)
00133 {
00134 lf[faceI][labelI] = markedPoints.find(curFace[labelI])();
00135 }
00136 }
00137
00138 if (debug)
00139 {
00140 Pout<< "PrimitivePatch<Face, FaceList, PointField, PointType>::"
00141 "calcMeshData() : "
00142 "finished calculating mesh data in PrimitivePatch"
00143 << endl;
00144 }
00145 }
00146
00147
00148 template
00149 <
00150 class Face,
00151 template<class> class FaceList,
00152 class PointField,
00153 class PointType
00154 >
00155
00156 void
00157 Foam::PrimitivePatch<Face, FaceList, PointField, PointType>::
00158 calcMeshPointMap() const
00159 {
00160 if (debug)
00161 {
00162 Pout<< "PrimitivePatch<Face, FaceList, PointField, PointType>::"
00163 "calcMeshPointMap() : "
00164 "calculating mesh point map in PrimitivePatch"
00165 << endl;
00166 }
00167
00168
00169
00170 if (meshPointMapPtr_)
00171 {
00172 FatalErrorIn
00173 (
00174 "PrimitivePatch<Face, FaceList, PointField, PointType>::"
00175 "calcMeshPointMap()"
00176 ) << "meshPointMapPtr_ already allocated"
00177 << abort(FatalError);
00178 }
00179
00180 const labelList& mp = meshPoints();
00181
00182 meshPointMapPtr_ = new Map<label>(2*mp.size());
00183 Map<label>& mpMap = *meshPointMapPtr_;
00184
00185 forAll (mp, i)
00186 {
00187 mpMap.insert(mp[i], i);
00188 }
00189
00190 if (debug)
00191 {
00192 Pout<< "PrimitivePatch<Face, FaceList, PointField, PointType>::"
00193 "calcMeshPointMap() : "
00194 "finished calculating mesh point map in PrimitivePatch"
00195 << endl;
00196 }
00197 }
00198
00199
00200 template
00201 <
00202 class Face,
00203 template<class> class FaceList,
00204 class PointField,
00205 class PointType
00206 >
00207
00208 void
00209 Foam::PrimitivePatch<Face, FaceList, PointField, PointType>::
00210 calcLocalPoints() const
00211 {
00212 if (debug)
00213 {
00214 Pout<< "PrimitivePatch<Face, FaceList, PointField, PointType>::"
00215 "calcLocalPoints() : "
00216 "calculating localPoints in PrimitivePatch"
00217 << endl;
00218 }
00219
00220
00221
00222 if (localPointsPtr_)
00223 {
00224 FatalErrorIn
00225 (
00226 "PrimitivePatch<Face, FaceList, PointField, PointType>::"
00227 "calcLocalPoints()"
00228 ) << "localPointsPtr_already allocated"
00229 << abort(FatalError);
00230 }
00231
00232 const labelList& meshPts = meshPoints();
00233
00234 localPointsPtr_ = new Field<PointType>(meshPts.size());
00235
00236 Field<PointType>& locPts = *localPointsPtr_;
00237
00238 forAll (meshPts, pointI)
00239 {
00240 locPts[pointI] = points_[meshPts[pointI]];
00241 }
00242
00243 if (debug)
00244 {
00245 Pout<< "PrimitivePatch<Face, FaceList, PointField, PointType>::"
00246 << "calcLocalPoints() : "
00247 << "finished calculating localPoints in PrimitivePatch"
00248 << endl;
00249 }
00250 }
00251
00252
00253 template
00254 <
00255 class Face,
00256 template<class> class FaceList,
00257 class PointField,
00258 class PointType
00259 >
00260
00261 void
00262 Foam::PrimitivePatch<Face, FaceList, PointField, PointType>::
00263 calcPointNormals() const
00264 {
00265 if (debug)
00266 {
00267 Pout<< "PrimitivePatch<Face, FaceList, PointField, PointType>::"
00268 "calcPointNormals() : "
00269 "calculating pointNormals in PrimitivePatch"
00270 << endl;
00271 }
00272
00273
00274
00275 if (pointNormalsPtr_)
00276 {
00277 FatalErrorIn
00278 (
00279 "PrimitivePatch<Face, FaceList, PointField, PointType>::"
00280 "calcPointNormals()"
00281 ) << "pointNormalsPtr_already allocated"
00282 << abort(FatalError);
00283 }
00284
00285 const Field<PointType>& faceUnitNormals = faceNormals();
00286
00287 const labelListList& pf = pointFaces();
00288
00289 pointNormalsPtr_ = new Field<PointType>
00290 (
00291 meshPoints().size(),
00292 PointType::zero
00293 );
00294
00295 Field<PointType>& n = *pointNormalsPtr_;
00296
00297 forAll (pf, pointI)
00298 {
00299 PointType& curNormal = n[pointI];
00300
00301 const labelList& curFaces = pf[pointI];
00302
00303 forAll (curFaces, faceI)
00304 {
00305 curNormal += faceUnitNormals[curFaces[faceI]];
00306 }
00307
00308 curNormal /= mag(curNormal) + VSMALL;
00309 }
00310
00311 if (debug)
00312 {
00313 Pout<< "PrimitivePatch<Face, FaceList, PointField, PointType>::"
00314 "calcPointNormals() : "
00315 "finished calculating pointNormals in PrimitivePatch"
00316 << endl;
00317 }
00318 }
00319
00320
00321 template
00322 <
00323 class Face,
00324 template<class> class FaceList,
00325 class PointField,
00326 class PointType
00327 >
00328
00329 void
00330 Foam::PrimitivePatch<Face, FaceList, PointField, PointType>::
00331 calcFaceNormals() const
00332 {
00333 if (debug)
00334 {
00335 Pout<< "PrimitivePatch<Face, FaceList, PointField, PointType>::"
00336 "calcFaceNormals() : "
00337 "calculating faceNormals in PrimitivePatch"
00338 << endl;
00339 }
00340
00341
00342
00343 if (faceNormalsPtr_)
00344 {
00345 FatalErrorIn
00346 (
00347 "PrimitivePatch<Face, FaceList, PointField, PointType>::"
00348 "calcFaceNormals()"
00349 ) << "faceNormalsPtr_already allocated"
00350 << abort(FatalError);
00351 }
00352
00353 faceNormalsPtr_ = new Field<PointType>(this->size());
00354
00355 Field<PointType>& n = *faceNormalsPtr_;
00356
00357 forAll (n, faceI)
00358 {
00359 n[faceI] = this->operator[](faceI).normal(points_);
00360 n[faceI] /= mag(n[faceI]) + VSMALL;
00361 }
00362
00363 if (debug)
00364 {
00365 Pout<< "PrimitivePatch<Face, FaceList, PointField, PointType>::"
00366 "calcFaceNormals() : "
00367 "finished calculating faceNormals in PrimitivePatch"
00368 << endl;
00369 }
00370 }
00371
00372
00373