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

evaluateError.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 "evaluateError.H"
00028 #include "volFields.H"
00029 #include "surfaceFields.H"
00030 #include "refineCell.H"
00031 
00032 
00033 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
00034 
00035 // Construct null
00036 Foam::evaluateError::evaluateError()
00037 :
00038     unsplitFaces_(),
00039     refCells_()
00040 {}
00041 
00042 
00043 // Construct from components
00044 Foam::evaluateError::evaluateError
00045 (
00046     const volScalarField& cellError,
00047     const volVectorField& gradTheta,
00048     const surfaceScalarField& faceError,
00049     const labelList& candidateFaces
00050 )
00051 :
00052     unsplitFaces_(candidateFaces.size()),
00053     refCells_()
00054 {
00055     const polyMesh& mesh = cellError.mesh();
00056 
00057     // picks up the error field and the gradient of the variable
00058     // and appends lists of cells to refine/unrefine based on the width of
00059     // standard deviation of the error distribution
00060 
00061     // calculate the average error
00062     scalar avgError = cellError.average().value();
00063 
00064     scalar squareError = sqr(cellError)().average().value();
00065     scalar deviation = sqrt(squareError - sqr(avgError));
00066 
00067     Info<< "avgError:" << avgError
00068         << "  squareError:" << squareError
00069         << "  deviation:" << deviation
00070         << endl;
00071 
00072     scalar ref = avgError + deviation;
00073     scalar unref = avgError - deviation;
00074 
00075     Info<< "evaluateError : refinement criterion : " << ref << endl
00076         << "                unrefinement criterion : " << unref << endl;
00077 
00078     // Coarsen mesh first.
00079     // Find out set of candidateFaces where error is above crit.
00080 
00081     // Construct to filter unrefinement pattern
00082 //    removeFaces faceRemover(mesh);
00083 
00084     // Keep track of unrefinement pattern.
00085     boolList markedFace(mesh.nFaces(), false);
00086 
00087     label unsplitFaceI = 0;
00088 
00089     // Subset candidate faces and update refinement pattern interference pattern
00090     forAll(candidateFaces, candidateFaceI)
00091     {
00092         label faceI = candidateFaces[candidateFaceI];
00093 
00094         if (markedFace[faceI])
00095         {
00096             Info<< "evaluateError : protected candidate face:" << faceI
00097                 << endl;
00098         }
00099         else
00100         {
00101 //            if (faceError[faceI] < unref)
00102             if (unsplitFaceI < (candidateFaces.size()/2 + 1))
00103             {
00104                 unsplitFaces_[unsplitFaceI++] = faceI;
00105 
00106 //                faceRemover.markAffectedFaces(faceI, markedFace);
00107             }
00108         }
00109     }
00110 
00111     unsplitFaces_.setSize(unsplitFaceI);
00112 
00113     // Now we have:
00114     // -unsplitFaces_: all the faces that will be removed 
00115     // -markedFace   : all the faces affected by this removal.
00116     // From markedFace protect the cells using them.
00117 
00118     boolList markedCells(mesh.nCells(), false);
00119 
00120 //    forAll(markedFace, faceI)
00121 //    {
00122 //        if (markedFace[faceI])
00123 //        {
00124 //            markedCells[mesh.faceOwner()[faceI]] = true;
00125 //
00126 //            if (mesh.isInternalFace(faceI))
00127 //            {
00128 //                markedCells[mesh.faceNeighbour()[faceI]] = true;
00129 //            }
00130 //        }
00131 //    }
00132 
00133     // Select the cells that need to be split.
00134     // Two pass: count first, select later.
00135 
00136     label refCellI = 0;
00137 
00138     forAll(cellError, cellI)
00139     {
00140         if ((cellError[cellI] > ref) && !markedCells[cellI])
00141         {
00142             refCellI++;
00143         }
00144     }
00145 
00146     refCells_.setSize(refCellI);
00147 
00148     refCellI = 0;
00149 
00150     forAll(cellError, cellI)
00151     {
00152         if ((cellError[cellI] > ref) && !markedCells[cellI])
00153         {
00154             refCells_[refCellI++] = refineCell(cellI, gradTheta[cellI]);
00155         }
00156     }
00157 
00158     Info<< "evaluateError : selected " << unsplitFaces_.size()
00159         << " faces out of " << candidateFaces.size() << " for removal" << endl;
00160     Info<< "evaluateError : selected " << refCells_.size()
00161         << " cells out of " << cellError.size() << " for refinement" << endl;
00162 }
00163 
00164 
00165 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd