FreeFOAM The Cross-Platform CFD Toolkit
anisotropicFilter.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 "anisotropicFilter.H"
30 #include <finiteVolume/fvc.H>
31 
32 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
33 
34 namespace Foam
35 {
36  defineTypeNameAndDebug(anisotropicFilter, 0);
37  addToRunTimeSelectionTable(LESfilter, anisotropicFilter, dictionary);
38 }
39 
40 
41 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
42 
43 Foam::anisotropicFilter::anisotropicFilter
44 (
45  const fvMesh& mesh,
46  scalar widthCoeff
47 )
48 :
49  LESfilter(mesh),
50  widthCoeff_(widthCoeff),
51  coeff_
52  (
53  IOobject
54  (
55  "anisotropicFilterCoeff",
56  mesh.time().timeName(),
57  mesh
58  ),
59  mesh,
60  dimensionedVector("zero", dimLength*dimLength, vector::zero),
61  calculatedFvPatchVectorField::typeName
62  )
63 {
64  for (direction d=0; d<vector::nComponents; d++)
65  {
66  coeff_.internalField().replace
67  (
68  d,
69  (2.0/widthCoeff_)*mesh.V()
70  /fvc::surfaceSum(mag(mesh.Sf().component(d)))().internalField()
71  );
72  }
73 }
74 
75 
76 Foam::anisotropicFilter::anisotropicFilter
77 (
78  const fvMesh& mesh,
79  const dictionary& bd
80 )
81 :
82  LESfilter(mesh),
83  widthCoeff_(readScalar(bd.subDict(type() + "Coeffs").lookup("widthCoeff"))),
84  coeff_
85  (
86  IOobject
87  (
88  "anisotropicFilterCoeff",
89  mesh.time().timeName(),
90  mesh
91  ),
92  mesh,
93  dimensionedVector("zero", dimLength*dimLength, vector::zero),
94  calculatedFvPatchScalarField::typeName
95  )
96 {
97  for (direction d=0; d<vector::nComponents; d++)
98  {
99  coeff_.internalField().replace
100  (
101  d,
102  (2.0/widthCoeff_)*mesh.V()
103  /fvc::surfaceSum(mag(mesh.Sf().component(d)))().internalField()
104  );
105  }
106 }
107 
108 
109 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
110 
112 {
113  bd.subDict(type() + "Coeffs").lookup("widthCoeff") >> widthCoeff_;
114 }
115 
116 
117 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
118 
119 Foam::tmp<Foam::volScalarField> Foam::anisotropicFilter::operator()
120 (
121  const tmp<volScalarField>& unFilteredField
122 ) const
123 {
124  tmp<volScalarField> tmpFilteredField =
125  unFilteredField
126  + (
127  coeff_
129  (
130  mesh().Sf()
131  *fvc::snGrad(unFilteredField())
132  )
133  );
134 
135  unFilteredField.clear();
136 
137  return tmpFilteredField;
138 }
139 
140 
141 Foam::tmp<Foam::volVectorField> Foam::anisotropicFilter::operator()
142 (
143  const tmp<volVectorField>& unFilteredField
144 ) const
145 {
146  tmp<volVectorField> tmpFilteredField =
147  unFilteredField
148  + (
149  coeff_
151  (
152  mesh().Sf()
153  *fvc::snGrad(unFilteredField())
154  )
155  );
156 
157  unFilteredField.clear();
158 
159  return tmpFilteredField;
160 }
161 
162 
163 Foam::tmp<Foam::volSymmTensorField> Foam::anisotropicFilter::operator()
164 (
165  const tmp<volSymmTensorField>& unFilteredField
166 ) const
167 {
168  tmp<volSymmTensorField> tmpFilteredField
169  (
171  (
172  IOobject
173  (
174  "anisotropicFilteredSymmTensorField",
175  mesh().time().timeName(),
176  mesh(),
179  ),
180  mesh(),
181  unFilteredField().dimensions()
182  )
183  );
184 
186  {
187  tmpFilteredField().replace
188  (
189  d, anisotropicFilter::operator()(unFilteredField().component(d))
190  );
191  }
192 
193  unFilteredField.clear();
194 
195  return tmpFilteredField;
196 }
197 
198 
199 Foam::tmp<Foam::volTensorField> Foam::anisotropicFilter::operator()
200 (
201  const tmp<volTensorField>& unFilteredField
202 ) const
203 {
204  tmp<volTensorField> tmpFilteredField
205  (
206  new volTensorField
207  (
208  IOobject
209  (
210  "anisotropicFilteredTensorField",
211  mesh().time().timeName(),
212  mesh(),
215  ),
216  mesh(),
217  unFilteredField().dimensions()
218  )
219  );
220 
221  for (direction d=0; d<tensor::nComponents; d++)
222  {
223  tmpFilteredField().replace
224  (
225  d, anisotropicFilter::operator()(unFilteredField().component(d))
226  );
227  }
228 
229  unFilteredField.clear();
230 
231  return tmpFilteredField;
232 }
233 
234 
235 // ************************ vim: set sw=4 sts=4 et: ************************ //