OpenFOAM logo
The Open Source CFD Toolbox
  Source Guide OpenCFD Solutions Contact OpenFOAM

FaceCellWave.C

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------------*\
00002   =========                 |
00003   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
00004    \\    /   O peration     |
00005     \\  /    A nd           | Copyright (C) 1991-2009 OpenCFD Ltd.
00006      \\/     M anipulation  |
00007 -------------------------------------------------------------------------------
00008 License
00009     This file is part of OpenFOAM.
00010 
00011     OpenFOAM is free software; you can redistribute it and/or modify it
00012     under the terms of the GNU General Public License as published by the
00013     Free Software Foundation; either version 2 of the License, or (at your
00014     option) any later version.
00015 
00016     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
00017     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00018     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00019     for more details.
00020 
00021     You should have received a copy of the GNU General Public License
00022     along with OpenFOAM; if not, write to the Free Software Foundation,
00023     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
00024 
00025 \*---------------------------------------------------------------------------*/
00026 
00027 #include "FaceCellWave.H"
00028 #include "polyMesh.H"
00029 #include "processorPolyPatch.H"
00030 #include "cyclicPolyPatch.H"
00031 #include "OPstream.H"
00032 #include "IPstream.H"
00033 #include "PstreamReduceOps.H"
00034 #include "debug.H"
00035 #include "typeInfo.H"
00036 
00037 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
00038 
00039 template <class Type>
00040 const Foam::scalar Foam::FaceCellWave<Type>::geomTol_ = 1e-6;
00041 
00042 template <class Type>
00043 const Foam::scalar Foam::FaceCellWave<Type>::propagationTol_ = 0.01;
00044 
00045 // Write to ostream
00046 template <class Type>
00047 Foam::Ostream& Foam::FaceCellWave<Type>::writeFaces
00048 (
00049     const label nFaces,
00050     const labelList& faceLabels,
00051     const List<Type>& faceInfo,
00052     Ostream& os
00053 )
00054 {
00055     // Write list contents depending on data format
00056     if (os.format() == IOstream::ASCII)
00057     {
00058         os << nFaces;
00059 
00060         for(label i = 0; i < nFaces; i++)
00061         {
00062             os << ' ' << faceLabels[i];
00063         }
00064         for(label i = 0; i < nFaces; i++)
00065         {
00066             os << ' ' << faceInfo[i];
00067         }
00068     }
00069     else
00070     {
00071         os << nFaces;
00072 
00073         for(label i = 0; i < nFaces; i++)
00074         {
00075             os << faceLabels[i];
00076         }
00077         for(label i = 0; i < nFaces; i++)
00078         {
00079             os << faceInfo[i];
00080         }
00081     }
00082     return os;
00083 }
00084 
00085 
00086 // Read from istream
00087 template <class Type>
00088 Foam::Istream& Foam::FaceCellWave<Type>::readFaces
00089 (
00090     label& nFaces,
00091     labelList& faceLabels,
00092     List<Type>& faceInfo,
00093     Istream& is
00094 )
00095 {
00096     is >> nFaces;
00097 
00098     for(label i = 0; i < nFaces; i++)
00099     {
00100         is >> faceLabels[i];
00101     }
00102     for(label i = 0; i < nFaces; i++)
00103     {
00104         is >> faceInfo[i];
00105     }
00106     return is;
00107 }
00108 
00109 
00110 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
00111 
00112 // Update info for cellI, at position pt, with information from
00113 // neighbouring face/cell.
00114 // Updates:
00115 //      - changedCell_, changedCells_, nChangedCells_,
00116 //      - statistics: nEvals_, nUnvisitedCells_
00117 template <class Type>
00118 bool Foam::FaceCellWave<Type>::updateCell
00119 (
00120     const label cellI,
00121     const label neighbourFaceI,
00122     const Type& neighbourInfo,
00123     const scalar tol,
00124     Type& cellInfo
00125 )
00126 {
00127     nEvals_++;
00128 
00129     bool wasValid = cellInfo.valid();
00130 
00131     bool propagate =
00132         cellInfo.updateCell
00133         (
00134             mesh_,
00135             cellI,
00136             neighbourFaceI,
00137             neighbourInfo,
00138             tol
00139         );
00140 
00141     if (propagate)
00142     {
00143         if (!changedCell_[cellI])
00144         {
00145             changedCell_[cellI] = true;
00146             changedCells_[nChangedCells_++] = cellI;
00147         }
00148     }
00149 
00150     if (!wasValid && cellInfo.valid())
00151     {
00152         --nUnvisitedCells_;
00153     }
00154 
00155     return propagate;
00156 }
00157 
00158 
00159 // Update info for faceI, at position pt, with information from
00160 // neighbouring face/cell.
00161 // Updates:
00162 //      - changedFace_, changedFaces_, nChangedFaces_,
00163 //      - statistics: nEvals_, nUnvisitedFaces_
00164 template <class Type>
00165 bool Foam::FaceCellWave<Type>::updateFace
00166 (
00167     const label faceI,
00168     const label neighbourCellI,
00169     const Type& neighbourInfo,
00170     const scalar tol,
00171     Type& faceInfo
00172 )
00173 {
00174     nEvals_++;
00175 
00176     bool wasValid = faceInfo.valid();
00177 
00178     bool propagate =
00179         faceInfo.updateFace
00180         (
00181             mesh_,
00182             faceI,
00183             neighbourCellI,
00184             neighbourInfo,
00185             tol
00186         );
00187 
00188     if (propagate)
00189     {
00190         if (!changedFace_[faceI])
00191         {
00192             changedFace_[faceI] = true;
00193             changedFaces_[nChangedFaces_++] = faceI;
00194         }
00195     }
00196 
00197     if (!wasValid && faceInfo.valid())
00198     {
00199         --nUnvisitedFaces_;
00200     }
00201 
00202     return propagate;
00203 }
00204 
00205 
00206 // Update info for faceI, at position pt, with information from
00207 // same face.
00208 // Updates:
00209 //      - changedFace_, changedFaces_, nChangedFaces_,
00210 //      - statistics: nEvals_, nUnvisitedFaces_
00211 template <class Type>
00212 bool Foam::FaceCellWave<Type>::updateFace
00213 (
00214     const label faceI,
00215     const Type& neighbourInfo,
00216     const scalar tol,
00217     Type& faceInfo
00218 )
00219 {
00220     nEvals_++;
00221 
00222     bool wasValid = faceInfo.valid();
00223 
00224     bool propagate =
00225         faceInfo.updateFace
00226         (
00227             mesh_,
00228             faceI,
00229             neighbourInfo,
00230             tol
00231         );
00232 
00233     if (propagate)
00234     {
00235         if (!changedFace_[faceI])
00236         {
00237             changedFace_[faceI] = true;
00238             changedFaces_[nChangedFaces_++] = faceI;
00239         }
00240     }
00241 
00242     if (!wasValid && faceInfo.valid())
00243     {
00244         --nUnvisitedFaces_;
00245     }
00246 
00247     return propagate;
00248 }
00249 
00250 
00251 // For debugging: check status on both sides of cyclic
00252 template <class Type>
00253 void Foam::FaceCellWave<Type>::checkCyclic(const polyPatch& patch) const
00254 {
00255     label cycOffset = patch.size()/2;
00256 
00257     for(label patchFaceI = 0; patchFaceI < cycOffset; patchFaceI++)
00258     {
00259         label i1 = patch.start() + patchFaceI;
00260         label i2 = i1 + cycOffset;
00261 
00262         if (!allFaceInfo_[i1].sameGeometry(mesh_, allFaceInfo_[i2], geomTol_))
00263         {
00264             FatalErrorIn("FaceCellWave<Type>::checkCyclic(const polyPatch&)")
00265                 << "problem: i:" << i1 << "  otheri:" << i2
00266                 << "   faceInfo:" << allFaceInfo_[i1]
00267                 << "   otherfaceInfo:" << allFaceInfo_[i2]
00268                 << abort(FatalError);
00269         }
00270 
00271         if (changedFace_[i1] != changedFace_[i2])
00272         {
00273             FatalErrorIn("FaceCellWave<Type>::checkCyclic(const polyPatch&)")
00274                 << " problem: i:" << i1 << "  otheri:" << i2
00275                 << "   faceInfo:" << allFaceInfo_[i1]
00276                 << "   otherfaceInfo:" << allFaceInfo_[i2]
00277                 << "   changedFace:" << changedFace_[i1]
00278                 << "   otherchangedFace:" << changedFace_[i2]
00279                 << abort(FatalError);
00280         }
00281     }
00282 }
00283 
00284 
00285 // Check if patches of given type name are present
00286 template <class Type>
00287 bool Foam::FaceCellWave<Type>::hasPatchType(const word& nameOfType)
00288 {
00289     forAll(mesh_.boundaryMesh(), patchI)
00290     {
00291         if (mesh_.boundaryMesh()[patchI].type() == nameOfType)
00292         {
00293             return true;
00294         }
00295     }
00296     return false;
00297 }
00298 
00299 
00300 // Copy face information into member data
00301 template <class Type>
00302 void Foam::FaceCellWave<Type>::setFaceInfo
00303 (
00304     const labelList& changedFaces,
00305     const List<Type>& changedFacesInfo
00306 )
00307 {
00308     forAll(changedFaces, changedFaceI)
00309     {
00310         label faceI = changedFaces[changedFaceI];
00311 
00312         bool wasValid = allFaceInfo_[faceI].valid();
00313 
00314         // Copy info for faceI
00315         allFaceInfo_[faceI] = changedFacesInfo[changedFaceI];
00316 
00317         // Maintain count of unset faces
00318         if (!wasValid && allFaceInfo_[faceI].valid())
00319         {
00320             --nUnvisitedFaces_;
00321         }
00322 
00323         // Mark faceI as changed, both on list and on face itself.
00324 
00325         changedFace_[faceI] = true;
00326         changedFaces_[nChangedFaces_++] = faceI;
00327     }
00328 }
00329 
00330 
00331 // Merge face information into member data
00332 template <class Type>
00333 void Foam::FaceCellWave<Type>::mergeFaceInfo
00334 (
00335     const polyPatch& patch,
00336     const label nFaces,
00337     const labelList& changedFaces,
00338     const List<Type>& changedFacesInfo,
00339     const bool
00340 )
00341 {
00342     for(label changedFaceI = 0; changedFaceI < nFaces; changedFaceI++)
00343     {
00344         const Type& neighbourWallInfo = changedFacesInfo[changedFaceI];
00345         label patchFaceI = changedFaces[changedFaceI];
00346 
00347         label meshFaceI = patch.start() + patchFaceI;
00348 
00349         Type& currentWallInfo = allFaceInfo_[meshFaceI];
00350 
00351         if (currentWallInfo != neighbourWallInfo)
00352         {
00353             updateFace
00354             (
00355                 meshFaceI,
00356                 neighbourWallInfo,
00357                 propagationTol_,
00358                 currentWallInfo
00359             );
00360         }
00361     }
00362 }
00363 
00364 
00365 // Construct compact patchFace change arrays for a (slice of a) single patch.
00366 // changedPatchFaces in local patch numbering.
00367 // Return length of arrays.
00368 template <class Type>
00369 Foam::label Foam::FaceCellWave<Type>::getChangedPatchFaces
00370 (
00371     const polyPatch& patch,
00372     const label startFaceI,
00373     const label nFaces,
00374     labelList& changedPatchFaces,
00375     List<Type>& changedPatchFacesInfo
00376 ) const
00377 {
00378     label nChangedPatchFaces = 0;
00379 
00380     for(label i = 0; i < nFaces; i++)
00381     {
00382         label patchFaceI = i + startFaceI;
00383 
00384         label meshFaceI = patch.start() + patchFaceI;
00385 
00386         if (changedFace_[meshFaceI])
00387         {
00388             changedPatchFaces[nChangedPatchFaces] = patchFaceI;
00389             changedPatchFacesInfo[nChangedPatchFaces] = allFaceInfo_[meshFaceI];
00390             nChangedPatchFaces++;
00391         }
00392     }
00393     return nChangedPatchFaces;
00394 }
00395 
00396 
00397 // Handle leaving domain. Implementation referred to Type
00398 template <class Type>
00399 void Foam::FaceCellWave<Type>::leaveDomain
00400 (
00401     const polyPatch& patch,
00402     const label nFaces,
00403     const labelList& faceLabels,
00404     List<Type>& faceInfo
00405 ) const
00406 {
00407     const vectorField& fc = mesh_.faceCentres();
00408     
00409     for(label i = 0; i < nFaces; i++)
00410     {
00411         label patchFaceI = faceLabels[i];
00412 
00413         label meshFaceI = patch.start() + patchFaceI;
00414         faceInfo[i].leaveDomain(mesh_, patch, patchFaceI, fc[meshFaceI]);
00415     }
00416 }
00417 
00418 
00419 // Handle entering domain. Implementation referred to Type
00420 template <class Type>
00421 void Foam::FaceCellWave<Type>::enterDomain
00422 (
00423     const polyPatch& patch,
00424     const label nFaces,
00425     const labelList& faceLabels,
00426     List<Type>& faceInfo
00427 ) const
00428 {
00429     const vectorField& fc = mesh_.faceCentres();
00430     
00431     for(label i = 0; i < nFaces; i++)
00432     {
00433         label patchFaceI = faceLabels[i];
00434 
00435         label meshFaceI = patch.start() + patchFaceI;
00436         faceInfo[i].enterDomain(mesh_, patch, patchFaceI, fc[meshFaceI]);
00437     }
00438 }
00439 
00440 
00441 // Transform. Implementation referred to Type
00442 template <class Type>
00443 void Foam::FaceCellWave<Type>::transform
00444 (
00445     const tensorField& rotTensor,
00446     const label nFaces,
00447     List<Type>& faceInfo
00448 )
00449 {
00450     if (rotTensor.size() == 1)
00451     {
00452         const tensor& T = rotTensor[0];
00453 
00454         for(label faceI = 0; faceI < nFaces; faceI++)
00455         {
00456             faceInfo[faceI].transform(mesh_, T);
00457         }
00458     }
00459     else
00460     {
00461         for(label faceI = 0; faceI < nFaces; faceI++)
00462         {
00463             faceInfo[faceI].transform(mesh_, rotTensor[faceI]);
00464         }
00465     }
00466 }
00467 
00468 
00469 // Send face info to neighbour.
00470 template <class Type>
00471 void Foam::FaceCellWave<Type>::sendPatchInfo
00472 (
00473     const label neighbour,
00474     const label nFaces,
00475     const labelList& faceLabels,
00476     const List<Type>& faceInfo
00477 ) const
00478 {
00479     OPstream toNeighbour(Pstream::blocking, neighbour);
00480 
00481     writeFaces(nFaces, faceLabels, faceInfo, toNeighbour);
00482 }
00483 
00484 
00485 // Receive face info from neighbour
00486 template <class Type>
00487 Foam::label Foam::FaceCellWave<Type>::receivePatchInfo
00488 (
00489     const label neighbour,
00490     labelList& faceLabels,
00491     List<Type>& faceInfo
00492 ) const
00493 {
00494     IPstream fromNeighbour(Pstream::blocking, neighbour);
00495 
00496     label nFaces = 0;
00497     readFaces(nFaces, faceLabels, faceInfo, fromNeighbour);
00498 
00499     return nFaces;
00500 }
00501 
00502 
00503 // Offset mesh face. Used for transferring from one cyclic half to the other.
00504 template <class Type>
00505 void Foam::FaceCellWave<Type>::offset
00506 (
00507     const polyPatch&,
00508     const label cycOffset,
00509     const label nFaces,
00510     labelList& faces
00511 )
00512 {
00513     for(label faceI = 0; faceI < nFaces; faceI++)
00514     {
00515         faces[faceI] += cycOffset;
00516     }
00517 }
00518 
00519 
00520 // Tranfer all the information to/from neighbouring processors
00521 template <class Type>
00522 void Foam::FaceCellWave<Type>::handleProcPatches()
00523 {
00524     // Send all
00525 
00526     forAll(mesh_.boundaryMesh(), patchI)
00527     {
00528         const polyPatch& patch = mesh_.boundaryMesh()[patchI];
00529 
00530         if (isA<processorPolyPatch>(patch))
00531         {
00532             // Allocate buffers
00533             label nSendFaces;
00534             labelList sendFaces(patch.size());
00535             List<Type> sendFacesInfo(patch.size());
00536 
00537             // Determine which faces changed on current patch
00538             nSendFaces = getChangedPatchFaces
00539             (
00540                 patch,
00541                 0,
00542                 patch.size(),
00543                 sendFaces,
00544                 sendFacesInfo
00545             );
00546 
00547             // Adapt wallInfo for leaving domain
00548             leaveDomain
00549             (
00550                 patch,
00551                 nSendFaces,
00552                 sendFaces,
00553                 sendFacesInfo
00554             );
00555 
00556             const processorPolyPatch& procPatch =
00557                 refCast<const processorPolyPatch>(patch);
00558 
00559             if (debug)
00560             {
00561                 Pout<< " Processor patch " << patchI << ' ' << patch.name()
00562                     << " communicating with " << procPatch.neighbProcNo()
00563                     << "  Sending:" << nSendFaces
00564                     << endl;
00565             }
00566 
00567             sendPatchInfo
00568             (
00569                 procPatch.neighbProcNo(),
00570                 nSendFaces,
00571                 sendFaces,
00572                 sendFacesInfo
00573             );
00574         }
00575     }
00576 
00577     // Receive all
00578 
00579     forAll(mesh_.boundaryMesh(), patchI)
00580     {
00581         const polyPatch& patch = mesh_.boundaryMesh()[patchI];
00582 
00583         if (isA<processorPolyPatch>(patch))
00584         {
00585             const processorPolyPatch& procPatch =
00586                 refCast<const processorPolyPatch>(patch);
00587 
00588             // Allocate buffers
00589             label nReceiveFaces;
00590             labelList receiveFaces(patch.size());
00591             List<Type> receiveFacesInfo(patch.size());
00592 
00593             nReceiveFaces = receivePatchInfo
00594             (
00595                 procPatch.neighbProcNo(),
00596                 receiveFaces,
00597                 receiveFacesInfo
00598             );
00599 
00600             if (debug)
00601             {
00602                 Pout<< " Processor patch " << patchI << ' ' << patch.name()
00603                     << " communicating with " << procPatch.neighbProcNo()
00604                     << "  Receiving:" << nReceiveFaces
00605                     << endl;
00606             }
00607 
00608             // Apply transform to received data for non-parallel planes
00609             if (!procPatch.parallel())
00610             {
00611                 transform
00612                 (
00613                     procPatch.reverseT(),
00614                     nReceiveFaces,
00615                     receiveFacesInfo
00616                 );
00617             }
00618 
00619             // Adapt wallInfo for entering domain
00620             enterDomain
00621             (
00622                 patch,
00623                 nReceiveFaces,
00624                 receiveFaces,
00625                 receiveFacesInfo
00626             );
00627 
00628             // Merge received info
00629             mergeFaceInfo
00630             (
00631                 patch,
00632                 nReceiveFaces,
00633                 receiveFaces,
00634                 receiveFacesInfo,
00635                 procPatch.parallel()
00636             );
00637         }
00638     }
00639 }
00640 
00641 
00642 // Transfer information across cyclic halves.
00643 // Note: Cyclic is two patches in one: one side from 0..size/2 and other
00644 // side from size/2 .. size.
00645 template <class Type>
00646 void Foam::FaceCellWave<Type>::handleCyclicPatches()
00647 {
00648     forAll(mesh_.boundaryMesh(), patchI)
00649     {
00650         const polyPatch& patch = mesh_.boundaryMesh()[patchI];
00651 
00652         if (isA<cyclicPolyPatch>(patch))
00653         {
00654             label halfSize = patch.size()/2;
00655 
00656             // Allocate buffers
00657             label nSendFaces;
00658             labelList sendFaces(halfSize);
00659             List<Type> sendFacesInfo(halfSize);
00660 
00661             label nReceiveFaces;
00662             labelList receiveFaces(halfSize);
00663             List<Type> receiveFacesInfo(halfSize);
00664 
00665             // Half1: Determine which faces changed. Use sendFaces for storage
00666             nSendFaces = getChangedPatchFaces
00667             (
00668                 patch,
00669                 0,
00670                 halfSize,
00671                 sendFaces,
00672                 sendFacesInfo
00673             );
00674 
00675             // Half2: Determine which faces changed. Use receiveFaces_  ,,
00676             nReceiveFaces = getChangedPatchFaces
00677             (
00678                 patch,
00679                 halfSize,
00680                 halfSize,
00681                 receiveFaces,
00682                 receiveFacesInfo
00683             );
00684 
00685             //Info<< "Half1:" << endl;
00686             //writeFaces(nSendFaces, sendFaces, sendFacesInfo, Info);
00687             //Info<< endl;
00688             //
00689             //Info<< "Half2:" << endl;
00690             //writeFaces(nReceiveFaces, receiveFaces, receiveFacesInfo, Info);
00691             //Info<< endl;
00692 
00693 
00694             // Half1: Adapt wallInfo for leaving domain
00695             leaveDomain
00696             (
00697                 patch,
00698                 nSendFaces,
00699                 sendFaces,
00700                 sendFacesInfo
00701             );
00702             // Half2: Adapt wallInfo for leaving domain
00703             leaveDomain
00704             (
00705                 patch,
00706                 nReceiveFaces,
00707                 receiveFaces,
00708                 receiveFacesInfo
00709             );
00710 
00711             // Half1: 'transfer' to other side by offsetting patchFaceI
00712             offset(patch, halfSize, nSendFaces, sendFaces);
00713 
00714             // Half2: 'transfer' to other side
00715             offset(patch, -halfSize, nReceiveFaces, receiveFaces);
00716 
00717             // Apply rotation for non-parallel planes
00718             const cyclicPolyPatch& cycPatch =
00719                 refCast<const cyclicPolyPatch>(patch);
00720 
00721             if (!cycPatch.parallel())
00722             {
00723                 // sendFaces = received data from half1
00724                 transform
00725                 (
00726                     cycPatch.forwardT(),
00727                     nSendFaces,
00728                     sendFacesInfo
00729                 );
00730 
00731                 // receiveFaces = received data from half2
00732                 transform
00733                 (
00734                     cycPatch.reverseT(),
00735                     nReceiveFaces,
00736                     receiveFacesInfo
00737                 );
00738             }
00739 
00740             if (debug)
00741             {
00742                 Pout<< " Cyclic patch " << patchI << ' ' << patch.name() 
00743                     << "  Changed on first half : " << nSendFaces
00744                     << "  Changed on second half : " << nReceiveFaces
00745                     << endl;
00746             }
00747 
00748             // Half1: Adapt wallInfo for entering domain
00749             enterDomain
00750             (
00751                 patch,
00752                 nSendFaces,
00753                 sendFaces,
00754                 sendFacesInfo
00755             );
00756 
00757             // Half2: Adapt wallInfo for entering domain
00758             enterDomain
00759             (
00760                 patch,
00761                 nReceiveFaces,
00762                 receiveFaces,
00763                 receiveFacesInfo
00764             );
00765 
00766             // Merge into global storage
00767             mergeFaceInfo
00768             (
00769                 patch,
00770                 nSendFaces,
00771                 sendFaces,
00772                 sendFacesInfo,
00773                 cycPatch.parallel()
00774             );
00775             // Merge into global storage
00776             mergeFaceInfo
00777             (
00778                 patch,
00779                 nReceiveFaces,
00780                 receiveFaces,
00781                 receiveFacesInfo,
00782                 cycPatch.parallel()
00783             );
00784 
00785             if (debug)
00786             {
00787                 checkCyclic(patch);
00788             }
00789         }
00790     }
00791 }
00792 
00793 
00794 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
00795 
00796 // Set up only. Use setFaceInfo and iterate() to do actual calculation.
00797 template <class Type>
00798 Foam::FaceCellWave<Type>::FaceCellWave
00799 (
00800     const polyMesh& mesh,
00801     UList<Type>& allFaceInfo,
00802     UList<Type>& allCellInfo
00803 )
00804 :
00805     mesh_(mesh),
00806     allFaceInfo_(allFaceInfo),
00807     allCellInfo_(allCellInfo),
00808     changedFace_(mesh_.nFaces(), false),
00809     changedFaces_(mesh_.nFaces()),
00810     nChangedFaces_(0),
00811     changedCell_(mesh_.nCells(), false),
00812     changedCells_(mesh_.nCells()),
00813     nChangedCells_(0),
00814     hasCyclicPatches_(hasPatchType(cyclicPolyPatch::typeName)),
00815     nEvals_(0),
00816     nUnvisitedCells_(mesh_.nCells()),
00817     nUnvisitedFaces_(mesh_.nFaces()),
00818     iter_(0)
00819 {}
00820 
00821 
00822 // Iterate, propagating changedFacesInfo across mesh, until no change (or 
00823 // maxIter reached). Initial cell values specified.
00824 template <class Type>
00825 Foam::FaceCellWave<Type>::FaceCellWave
00826 (
00827     const polyMesh& mesh,
00828     const labelList& changedFaces,
00829     const List<Type>& changedFacesInfo,
00830     UList<Type>& allFaceInfo,
00831     UList<Type>& allCellInfo,
00832     const label maxIter
00833 )
00834 :
00835     mesh_(mesh),
00836     allFaceInfo_(allFaceInfo),
00837     allCellInfo_(allCellInfo),
00838     changedFace_(mesh_.nFaces(), false),
00839     changedFaces_(mesh_.nFaces()),
00840     nChangedFaces_(0),
00841     changedCell_(mesh_.nCells(), false),
00842     changedCells_(mesh_.nCells()),
00843     nChangedCells_(0),
00844     hasCyclicPatches_(hasPatchType(cyclicPolyPatch::typeName)),
00845     nEvals_(0),
00846     nUnvisitedCells_(mesh_.nCells()),
00847     nUnvisitedFaces_(mesh_.nFaces()),
00848     iter_(0)
00849 {
00850     // Copy initial changed faces data
00851     setFaceInfo(changedFaces, changedFacesInfo);
00852 
00853     // Iterate until nothing changes
00854     iterate(maxIter);
00855 
00856     if ((maxIter > 0) && (iter_ >= maxIter))
00857     {
00858         FatalErrorIn
00859         (
00860             "FaceCellWave<Type>::FaceCellWave"
00861             "(const polyMesh&, const labelList&, const List<Type>,"
00862             " UList<Type>&, UList<Type>&, const label maxIter)"
00863         )
00864             << "Maximum number of iterations reached. Increase maxIter." << endl
00865             << "    maxIter:" << maxIter << endl
00866             << "    nChangedCells:" << nChangedCells_ << endl
00867             << "    nChangedFaces:" << nChangedFaces_ << endl
00868             << exit(FatalError);
00869     }
00870 }
00871 
00872 
00873 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00874 
00875 
00876 template <class Type>
00877 Foam::label Foam::FaceCellWave<Type>::getUnsetCells() const
00878 {
00879     return nUnvisitedCells_;
00880 }
00881 
00882 
00883 template <class Type>
00884 Foam::label Foam::FaceCellWave<Type>::getUnsetFaces() const
00885 {
00886     return nUnvisitedFaces_;
00887 }
00888 
00889 
00890 
00891 // Propagate cell to face
00892 template <class Type>
00893 Foam::label Foam::FaceCellWave<Type>::faceToCell()
00894 {
00895     const labelList& owner = mesh_.faceOwner();
00896     const labelList& neighbour = mesh_.faceNeighbour();
00897     label nInternalFaces = mesh_.nInternalFaces();
00898 
00899     for
00900     (
00901         label changedFaceI = 0;
00902         changedFaceI < nChangedFaces_;
00903         changedFaceI++
00904     )
00905     {
00906         label faceI = changedFaces_[changedFaceI];
00907         if (!changedFace_[faceI])
00908         {
00909             FatalErrorIn("FaceCellWave<Type>::faceToCell()")
00910                 << "Face " << faceI
00911                 << " not marked as having been changed"
00912                 << abort(FatalError);
00913         }
00914 
00915 
00916         const Type& neighbourWallInfo = allFaceInfo_[faceI];
00917 
00918         // Evaluate all connected cells
00919 
00920         // Owner
00921         label cellI = owner[faceI];
00922         Type& currentWallInfo = allCellInfo_[cellI];
00923 
00924         if (currentWallInfo != neighbourWallInfo)
00925         {
00926             updateCell
00927             (
00928                 cellI,
00929                 faceI,
00930                 neighbourWallInfo,
00931                 propagationTol_,
00932                 currentWallInfo
00933             );
00934         }
00935 
00936         // Neighbour. Hack for check if face has neighbour.
00937         if (faceI < nInternalFaces)
00938         {
00939             cellI = neighbour[faceI];
00940             Type& currentWallInfo2 = allCellInfo_[cellI];
00941 
00942             if (currentWallInfo2 != neighbourWallInfo)
00943             {
00944                 updateCell
00945                 (
00946                     cellI,
00947                     faceI,
00948                     neighbourWallInfo,
00949                     propagationTol_,
00950                     currentWallInfo2
00951                 );
00952             }
00953         }
00954 
00955         // Reset status of face
00956         changedFace_[faceI] = false;
00957     }
00958 
00959     // Handled all changed faces by now
00960     nChangedFaces_ = 0;
00961 
00962     if (debug)
00963     {
00964         Pout<< " Changed cells            : " << nChangedCells_ << endl;
00965     }
00966 
00967     // Sum nChangedCells over all procs
00968     label totNChanged = nChangedCells_;
00969 
00970     reduce(totNChanged, sumOp<label>());
00971 
00972     return totNChanged;
00973 }
00974 
00975 
00976 // Propagate cell to face
00977 template <class Type>
00978 Foam::label Foam::FaceCellWave<Type>::cellToFace()
00979 {
00980     const cellList& cells = mesh_.cells();
00981 
00982     for
00983     (
00984         label changedCellI = 0;
00985         changedCellI < nChangedCells_;
00986         changedCellI++
00987     )
00988     {
00989         label cellI = changedCells_[changedCellI];
00990         if (!changedCell_[cellI])
00991         {
00992             FatalErrorIn("FaceCellWave<Type>::cellToFace()") << "Cell " << cellI
00993                 << " not marked as having been changed"
00994                 << abort(FatalError);
00995         }
00996 
00997         const Type& neighbourWallInfo = allCellInfo_[cellI];
00998 
00999         // Evaluate all connected faces
01000 
01001         const labelList& faceLabels = cells[cellI];
01002         forAll(faceLabels, faceLabelI)
01003         {
01004             label faceI = faceLabels[faceLabelI];
01005             Type& currentWallInfo = allFaceInfo_[faceI];
01006 
01007             if (currentWallInfo != neighbourWallInfo)
01008             {
01009                 updateFace
01010                 (
01011                     faceI,
01012                     cellI,
01013                     neighbourWallInfo,
01014                     propagationTol_,
01015                     currentWallInfo
01016                 );
01017             }
01018         }
01019 
01020         // Reset status of cell
01021         changedCell_[cellI] = false;
01022     }
01023 
01024     // Handled all changed cells by now
01025     nChangedCells_ = 0;
01026 
01027     if (hasCyclicPatches_)
01028     {
01029         // Transfer changed faces across cyclic halves
01030         handleCyclicPatches();
01031     }
01032     if (Pstream::parRun())
01033     {
01034         // Transfer changed faces from neighbouring processors.
01035         handleProcPatches();
01036     }
01037 
01038     if (debug)
01039     {
01040         Pout<< " Changed faces            : " << nChangedFaces_ << endl;
01041     }
01042 
01043     // Sum nChangedFaces over all procs
01044     label totNChanged = nChangedFaces_;
01045 
01046     reduce(totNChanged, sumOp<label>());
01047 
01048     return totNChanged;
01049 }
01050 
01051 
01052 // Iterate
01053 template <class Type>
01054 Foam::label Foam::FaceCellWave<Type>::iterate(const label maxIter)
01055 {
01056     if (hasCyclicPatches_)
01057     {
01058         // Transfer changed faces across cyclic halves
01059         handleCyclicPatches();
01060     }
01061     if (Pstream::parRun())
01062     {
01063         // Transfer changed faces from neighbouring processors.
01064         handleProcPatches();
01065     }
01066 
01067     while(iter_ < maxIter)
01068     {
01069         if (debug)
01070         {
01071             Pout<< " Iteration " << iter_ << endl;
01072         }
01073 
01074         nEvals_ = 0;
01075 
01076         label nCells = faceToCell();
01077 
01078         if (debug)
01079         {
01080             Pout<< " Total changed cells      : " << nCells << endl;
01081         }
01082 
01083         if (nCells == 0)
01084         {
01085             break;
01086         }
01087 
01088         label nFaces = cellToFace();
01089 
01090         if (debug)
01091         {
01092             Pout<< " Total changed faces      : " << nFaces << nl
01093                 << " Total evaluations        : " << nEvals_ << nl
01094                 << " Remaining unvisited cells: " << nUnvisitedCells_ << nl
01095                 << " Remaining unvisited faces: " << nUnvisitedFaces_ << endl;
01096         }
01097 
01098         if (nFaces == 0)
01099         {
01100             break;
01101         }
01102 
01103         ++iter_;
01104     }
01105 
01106     return nUnvisitedCells_;
01107 }
01108 
01109 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd