FreeFOAM The Cross-Platform CFD Toolkit
resErrorDiv.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 "resErrorDiv.H"
27 #include <finiteVolume/fvc.H>
28 
29 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
30 
31 namespace Foam
32 {
33 
34 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
35 
36 namespace resError
37 {
38 
39 template<class Type>
40 tmp<errorEstimate<Type> >
41 div
42 (
43  const surfaceScalarField& flux,
45 )
46 {
47  const fvMesh& mesh = vf.mesh();
48 
49  const scalarField& vols = mesh.V();
50  const surfaceVectorField& faceCentres = mesh.Cf();
51  const volVectorField& cellCentres = mesh.C();
52  const fvPatchList& patches = mesh.boundary();
53  const unallocLabelList& owner = mesh.owner();
54  const unallocLabelList& neighbour = mesh.neighbour();
55 
57  scalarField aNorm(vols.size(), 0.0);
58 
59  // Get sign of flux
60  const surfaceScalarField signF = pos(flux);
61 
62  // Calculate gradient of the solution
64  <
66  > gradVf = fvc::grad(vf);
67 
68  // Internal faces
69  forAll (owner, faceI)
70  {
71  // Calculate the centre of the face
72  const vector& curFaceCentre = faceCentres[faceI];
73 
74  // Owner
75  vector ownD = curFaceCentre - cellCentres[owner[faceI]];
76 
77  // Subtract convection
78  res[owner[faceI]] -=
79  (
80  vf[owner[faceI]]
81  + (ownD & gradVf[owner[faceI]])
82  )*flux[faceI];
83 
84  aNorm[owner[faceI]] += signF[faceI]*flux[faceI];
85 
86  // Neighbour
87  vector neiD = curFaceCentre - cellCentres[neighbour[faceI]];
88 
89  // Subtract convection
90  res[neighbour[faceI]] +=
91  (
92  vf[neighbour[faceI]]
93  + (neiD & gradVf[neighbour[faceI]])
94  )*flux[faceI];
95 
96  aNorm[neighbour[faceI]] -= (1.0 - signF[faceI])*flux[faceI];
97  }
98 
99  forAll (patches, patchI)
100  {
101  const vectorField& patchFaceCentres =
102  faceCentres.boundaryField()[patchI];
103 
104  const scalarField& patchFlux = flux.boundaryField()[patchI];
105  const scalarField& patchSignFlux = signF.boundaryField()[patchI];
106 
107  const labelList& fCells = patches[patchI].faceCells();
108 
109  forAll (fCells, faceI)
110  {
111  vector d =
112  patchFaceCentres[faceI] - cellCentres[fCells[faceI]];
113 
114  // Subtract convection
115  res[fCells[faceI]] -=
116  (
117  vf[fCells[faceI]]
118  + (d & gradVf[fCells[faceI]])
119  )*patchFlux[faceI];
120 
121  aNorm[fCells[faceI]] += patchSignFlux[faceI]*patchFlux[faceI];
122  }
123  }
124 
125  res /= vols;
126  aNorm /= vols;
127 
128  return tmp<errorEstimate<Type> >
129  (
131  (
132  vf,
133  flux.dimensions()*vf.dimensions(),
134  res,
135  aNorm
136  )
137  );
138 }
139 
140 
141 template<class Type>
143 div
144 (
145  const tmp<surfaceScalarField>& tflux,
147 )
148 {
149  tmp<errorEstimate<Type> > Div(resError::div(tflux(), vf));
150  tflux.clear();
151  return Div;
152 }
153 
154 
155 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
156 
157 } // End namespace resError
158 
159 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
160 
161 } // End namespace Foam
162 
163 // ************************************************************************* //
164 
165 
166 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
167