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 #include "isoSurfaceCell.H"
00027 #include <OpenFOAM/polyMesh.H>
00028 #include <OpenFOAM/tetMatcher.H>
00029
00030
00031
00032 template<class Type>
00033 Type Foam::isoSurfaceCell::generatePoint
00034 (
00035 const DynamicList<Type>& snappedPoints,
00036
00037 const scalar s0,
00038 const Type& p0,
00039 const label p0Index,
00040
00041 const scalar s1,
00042 const Type& p1,
00043 const label p1Index
00044 ) const
00045 {
00046 scalar d = s1-s0;
00047
00048 if (mag(d) > VSMALL)
00049 {
00050 scalar s = (iso_-s0)/d;
00051
00052 if (s >= 0.5 && s <= 1 && p1Index != -1)
00053 {
00054 return snappedPoints[p1Index];
00055 }
00056 else if (s >= 0.0 && s <= 0.5 && p0Index != -1)
00057 {
00058 return snappedPoints[p0Index];
00059 }
00060 else
00061 {
00062 return s*p1 + (1.0-s)*p0;
00063 }
00064 }
00065 else
00066 {
00067 scalar s = 0.4999;
00068
00069 return s*p1 + (1.0-s)*p0;
00070 }
00071 }
00072
00073
00074 template<class Type>
00075 void Foam::isoSurfaceCell::generateTriPoints
00076 (
00077 const DynamicList<Type>& snapped,
00078
00079 const scalar s0,
00080 const Type& p0,
00081 const label p0Index,
00082
00083 const scalar s1,
00084 const Type& p1,
00085 const label p1Index,
00086
00087 const scalar s2,
00088 const Type& p2,
00089 const label p2Index,
00090
00091 const scalar s3,
00092 const Type& p3,
00093 const label p3Index,
00094
00095 DynamicList<Type>& points
00096 ) const
00097 {
00098 int triIndex = 0;
00099 if (s0 < iso_)
00100 {
00101 triIndex |= 1;
00102 }
00103 if (s1 < iso_)
00104 {
00105 triIndex |= 2;
00106 }
00107 if (s2 < iso_)
00108 {
00109 triIndex |= 4;
00110 }
00111 if (s3 < iso_)
00112 {
00113 triIndex |= 8;
00114 }
00115
00116
00117 switch (triIndex)
00118 {
00119 case 0x00:
00120 case 0x0F:
00121 break;
00122
00123 case 0x0E:
00124 case 0x01:
00125 points.append(generatePoint(snapped,s0,p0,p0Index,s1,p1,p1Index));
00126 points.append(generatePoint(snapped,s0,p0,p0Index,s2,p2,p2Index));
00127 points.append(generatePoint(snapped,s0,p0,p0Index,s3,p3,p3Index));
00128 break;
00129
00130 case 0x0D:
00131 case 0x02:
00132 points.append(generatePoint(snapped,s1,p1,p1Index,s0,p0,p0Index));
00133 points.append(generatePoint(snapped,s1,p1,p1Index,s3,p3,p3Index));
00134 points.append(generatePoint(snapped,s1,p1,p1Index,s2,p2,p2Index));
00135 break;
00136
00137 case 0x0C:
00138 case 0x03:
00139 {
00140 Type tp1 = generatePoint(snapped,s0,p0,p0Index,s2,p2,p2Index);
00141 Type tp2 = generatePoint(snapped,s1,p1,p1Index,s3,p3,p3Index);
00142
00143 points.append(generatePoint(snapped,s0,p0,p0Index,s3,p3,p3Index));
00144 points.append(tp1);
00145 points.append(tp2);
00146 points.append(tp2);
00147 points.append(generatePoint(snapped,s1,p1,p1Index,s2,p2,p2Index));
00148 points.append(tp1);
00149 }
00150 break;
00151
00152 case 0x0B:
00153 case 0x04:
00154 {
00155 points.append(generatePoint(snapped,s2,p2,p2Index,s0,p0,p0Index));
00156 points.append(generatePoint(snapped,s2,p2,p2Index,s1,p1,p1Index));
00157 points.append(generatePoint(snapped,s2,p2,p2Index,s3,p3,p3Index));
00158 }
00159 break;
00160
00161 case 0x0A:
00162 case 0x05:
00163 {
00164 Type tp0 = generatePoint(snapped,s0,p0,p0Index,s1,p1,p1Index);
00165 Type tp1 = generatePoint(snapped,s2,p2,p2Index,s3,p3,p3Index);
00166
00167 points.append(tp0);
00168 points.append(tp1);
00169 points.append(generatePoint(snapped,s0,p0,p0Index,s3,p3,p3Index));
00170 points.append(tp0);
00171 points.append(generatePoint(snapped,s1,p1,p1Index,s2,p2,p2Index));
00172 points.append(tp1);
00173 }
00174 break;
00175
00176 case 0x09:
00177 case 0x06:
00178 {
00179 Type tp0 = generatePoint(snapped,s0,p0,p0Index,s1,p1,p1Index);
00180 Type tp1 = generatePoint(snapped,s2,p2,p2Index,s3,p3,p3Index);
00181
00182 points.append(tp0);
00183 points.append(generatePoint(snapped,s1,p1,p1Index,s3,p3,p3Index));
00184 points.append(tp1);
00185 points.append(tp0);
00186 points.append(generatePoint(snapped,s0,p0,p0Index,s2,p2,p2Index));
00187 points.append(tp1);
00188 }
00189 break;
00190
00191 case 0x07:
00192 case 0x08:
00193 points.append(generatePoint(snapped,s3,p3,p3Index,s0,p0,p0Index));
00194 points.append(generatePoint(snapped,s3,p3,p3Index,s2,p2,p2Index));
00195 points.append(generatePoint(snapped,s3,p3,p3Index,s1,p1,p1Index));
00196 break;
00197 }
00198 }
00199
00200
00201 template<class Type>
00202 void Foam::isoSurfaceCell::generateTriPoints
00203 (
00204 const scalarField& cVals,
00205 const scalarField& pVals,
00206
00207 const Field<Type>& cCoords,
00208 const Field<Type>& pCoords,
00209
00210 const DynamicList<Type>& snappedPoints,
00211 const labelList& snappedCc,
00212 const labelList& snappedPoint,
00213
00214 DynamicList<Type>& triPoints,
00215 DynamicList<label>& triMeshCells
00216 ) const
00217 {
00218 tetMatcher tet;
00219
00220 forAll(mesh_.cells(), cellI)
00221 {
00222 if (cellCutType_[cellI] != NOTCUT)
00223 {
00224 label oldNPoints = triPoints.size();
00225
00226 const cell& cFaces = mesh_.cells()[cellI];
00227
00228 if (tet.isA(mesh_, cellI))
00229 {
00230
00231
00232
00233 const face& f0 = mesh_.faces()[cFaces[0]];
00234
00235
00236 const face& f1 = mesh_.faces()[cFaces[1]];
00237 label oppositeI = -1;
00238 forAll(f1, fp)
00239 {
00240 oppositeI = f1[fp];
00241
00242 if (findIndex(f0, oppositeI) == -1)
00243 {
00244 break;
00245 }
00246 }
00247
00248 generateTriPoints
00249 (
00250 snappedPoints,
00251 pVals[f0[0]],
00252 pCoords[f0[0]],
00253 snappedPoint[f0[0]],
00254
00255 pVals[f0[1]],
00256 pCoords[f0[1]],
00257 snappedPoint[f0[1]],
00258
00259 pVals[f0[2]],
00260 pCoords[f0[2]],
00261 snappedPoint[f0[2]],
00262
00263 pVals[oppositeI],
00264 pCoords[oppositeI],
00265 snappedPoint[oppositeI],
00266
00267 triPoints
00268 );
00269 }
00270 else
00271 {
00272 const cell& cFaces = mesh_.cells()[cellI];
00273
00274 forAll(cFaces, cFaceI)
00275 {
00276 label faceI = cFaces[cFaceI];
00277 const face& f = mesh_.faces()[faceI];
00278
00279 for (label fp = 1; fp < f.size() - 1; fp++)
00280 {
00281 triFace tri(f[0], f[fp], f[f.fcIndex(fp)]);
00282
00283
00284
00285
00286
00287
00288 generateTriPoints
00289 (
00290 snappedPoints,
00291
00292 pVals[tri[0]],
00293 pCoords[tri[0]],
00294 snappedPoint[tri[0]],
00295
00296 pVals[tri[1]],
00297 pCoords[tri[1]],
00298 snappedPoint[tri[1]],
00299
00300 pVals[tri[2]],
00301 pCoords[tri[2]],
00302 snappedPoint[tri[2]],
00303
00304 cVals[cellI],
00305 cCoords[cellI],
00306 snappedCc[cellI],
00307
00308 triPoints
00309 );
00310 }
00311 }
00312 }
00313
00314
00315
00316 label nCells = (triPoints.size()-oldNPoints)/3;
00317 for (label i = 0; i < nCells; i++)
00318 {
00319 triMeshCells.append(cellI);
00320 }
00321 }
00322 }
00323
00324 triPoints.shrink();
00325 triMeshCells.shrink();
00326 }
00327
00328
00329 template <class Type>
00330 Foam::tmp<Foam::Field<Type> >
00331 Foam::isoSurfaceCell::interpolate
00332 (
00333 const scalarField& cVals,
00334 const scalarField& pVals,
00335 const Field<Type>& cCoords,
00336 const Field<Type>& pCoords
00337 ) const
00338 {
00339 DynamicList<Type> triPoints(nCutCells_);
00340 DynamicList<label> triMeshCells(nCutCells_);
00341
00342
00343 DynamicList<Type> snappedPoints;
00344 labelList snappedCc(mesh_.nCells(), -1);
00345 labelList snappedPoint(mesh_.nPoints(), -1);
00346
00347
00348 generateTriPoints
00349 (
00350 cVals,
00351 pVals,
00352
00353 cCoords,
00354 pCoords,
00355
00356 snappedPoints,
00357 snappedCc,
00358 snappedPoint,
00359
00360 triPoints,
00361 triMeshCells
00362 );
00363
00364
00365
00366 tmp<Field<Type> > tvalues(new Field<Type>(points().size()));
00367 Field<Type>& values = tvalues();
00368
00369 forAll(triPoints, i)
00370 {
00371 label mergedPointI = triPointMergeMap_[i];
00372
00373 if (mergedPointI >= 0)
00374 {
00375 values[mergedPointI] = triPoints[i];
00376 }
00377 }
00378
00379 return tvalues;
00380 }
00381
00382
00383