FreeFOAM The Cross-Platform CFD Toolkit
Hosted by SourceForge:
Get FreeFOAM at SourceForge.net.
            Fast, secure and Free Open Source software downloads

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