FreeFOAM The Cross-Platform CFD Toolkit
evaluateError.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | Copyright (C) 1991-2010 OpenCFD Ltd.
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
26 #include "evaluateError.H"
27 #include <finiteVolume/volFields.H>
29 #include <dynamicMesh/refineCell.H>
30 
31 
32 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
33 
34 // Construct null
36 :
37  unsplitFaces_(),
38  refCells_()
39 {}
40 
41 
42 // Construct from components
44 (
45  const volScalarField& cellError,
46  const volVectorField& gradTheta,
47  const surfaceScalarField& faceError,
48  const labelList& candidateFaces
49 )
50 :
51  unsplitFaces_(candidateFaces.size()),
52  refCells_()
53 {
54  const polyMesh& mesh = cellError.mesh();
55 
56  // picks up the error field and the gradient of the variable
57  // and appends lists of cells to refine/unrefine based on the width of
58  // standard deviation of the error distribution
59 
60  // calculate the average error
61  scalar avgError = cellError.average().value();
62 
63  scalar squareError = sqr(cellError)().average().value();
64  scalar deviation = sqrt(squareError - sqr(avgError));
65 
66  Info<< "avgError:" << avgError
67  << " squareError:" << squareError
68  << " deviation:" << deviation
69  << endl;
70 
71  scalar ref = avgError + deviation;
72  scalar unref = avgError - deviation;
73 
74  Info<< "evaluateError : refinement criterion : " << ref << endl
75  << " unrefinement criterion : " << unref << endl;
76 
77  // Coarsen mesh first.
78  // Find out set of candidateFaces where error is above crit.
79 
80  // Construct to filter unrefinement pattern
81 // removeFaces faceRemover(mesh);
82 
83  // Keep track of unrefinement pattern.
84  boolList markedFace(mesh.nFaces(), false);
85 
86  label unsplitFaceI = 0;
87 
88  // Subset candidate faces and update refinement pattern interference pattern
89  forAll(candidateFaces, candidateFaceI)
90  {
91  label faceI = candidateFaces[candidateFaceI];
92 
93  if (markedFace[faceI])
94  {
95  Info<< "evaluateError : protected candidate face:" << faceI
96  << endl;
97  }
98  else
99  {
100 // if (faceError[faceI] < unref)
101  if (unsplitFaceI < (candidateFaces.size()/2 + 1))
102  {
103  unsplitFaces_[unsplitFaceI++] = faceI;
104 
105 // faceRemover.markAffectedFaces(faceI, markedFace);
106  }
107  }
108  }
109 
110  unsplitFaces_.setSize(unsplitFaceI);
111 
112  // Now we have:
113  // -unsplitFaces_: all the faces that will be removed
114  // -markedFace : all the faces affected by this removal.
115  // From markedFace protect the cells using them.
116 
117  boolList markedCells(mesh.nCells(), false);
118 
119 // forAll(markedFace, faceI)
120 // {
121 // if (markedFace[faceI])
122 // {
123 // markedCells[mesh.faceOwner()[faceI]] = true;
124 //
125 // if (mesh.isInternalFace(faceI))
126 // {
127 // markedCells[mesh.faceNeighbour()[faceI]] = true;
128 // }
129 // }
130 // }
131 
132  // Select the cells that need to be split.
133  // Two pass: count first, select later.
134 
135  label refCellI = 0;
136 
137  forAll(cellError, cellI)
138  {
139  if ((cellError[cellI] > ref) && !markedCells[cellI])
140  {
141  refCellI++;
142  }
143  }
144 
145  refCells_.setSize(refCellI);
146 
147  refCellI = 0;
148 
149  forAll(cellError, cellI)
150  {
151  if ((cellError[cellI] > ref) && !markedCells[cellI])
152  {
153  refCells_[refCellI++] = refineCell(cellI, gradTheta[cellI]);
154  }
155  }
156 
157  Info<< "evaluateError : selected " << unsplitFaces_.size()
158  << " faces out of " << candidateFaces.size() << " for removal" << endl;
159  Info<< "evaluateError : selected " << refCells_.size()
160  << " cells out of " << cellError.size() << " for refinement" << endl;
161 }
162 
163 
164 // ************************ vim: set sw=4 sts=4 et: ************************ //