anisotropicFilter.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2025 OpenFOAM Foundation
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"
27 #include "fvcSurfaceIntegrate.H"
28 #include "fvcSnGrad.H"
30 
31 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
32 
33 namespace Foam
34 {
37 }
38 
39 
40 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
41 
42 template<class Type>
43 inline Foam::tmp<Foam::VolField<Type>> Foam::anisotropicFilter::filter
44 (
45  const tmp<VolField<Type>>& unFilteredField
46 ) const
47 {
48  correctBoundaryConditions(unFilteredField);
49 
50  tmp<VolField<Type>> tmpFilteredField
51  (
53  (
54  "anisotropicFilteredField",
55  mesh(),
56  unFilteredField().dimensions()
57  )
58  );
59 
60  for (direction d=0; d<pTraits<Type>::nComponents; d++)
61  {
62  tmpFilteredField.ref().replace
63  (
64  d, anisotropicFilter::operator()(unFilteredField().component(d))
65  );
66  }
67 
68  unFilteredField.clear();
69 
70  return tmpFilteredField;
71 }
72 
73 
74 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
75 
77 (
78  const fvMesh& mesh,
79  scalar widthCoeff
80 )
81 :
82  LESfilter(mesh),
83  widthCoeff_(widthCoeff),
84  coeff_
85  (
86  IOobject
87  (
88  "anisotropicFilterCoeff",
89  mesh.time().name(),
90  mesh
91  ),
92  mesh,
94  calculatedFvPatchVectorField::typeName
95  )
96 {
97  for (direction d=0; d<vector::nComponents; d++)
98  {
99  coeff_.primitiveFieldRef().replace
100  (
101  d,
102  (1/widthCoeff_)*
103  sqr
104  (
105  2.0*mesh.V()
106  /fvc::surfaceSum(mag(mesh.Sf().component(d)))().primitiveField()
107  )
108  );
109  }
110 }
111 
112 
114 (
115  const fvMesh& mesh,
116  const dictionary& bd
117 )
118 :
119  LESfilter(mesh),
120  widthCoeff_
121  (
122  bd.optionalSubDict(type() + "Coeffs").lookup<scalar>("widthCoeff")
123  ),
124  coeff_
125  (
126  IOobject
127  (
128  "anisotropicFilterCoeff",
129  mesh.time().name(),
130  mesh
131  ),
132  mesh,
134  calculatedFvPatchScalarField::typeName
135  )
136 {
137  for (direction d=0; d<vector::nComponents; d++)
138  {
139  coeff_.primitiveFieldRef().replace
140  (
141  d,
142  (1/widthCoeff_)*
143  sqr
144  (
145  2.0*mesh.V()
146  /fvc::surfaceSum(mag(mesh.Sf().component(d)))().primitiveField()
147  )
148  );
149  }
150 }
151 
152 
153 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
154 
156 {
157  bd.optionalSubDict(type() + "Coeffs").lookup("widthCoeff") >> widthCoeff_;
158 }
159 
160 
161 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
162 
163 Foam::tmp<Foam::volScalarField> Foam::anisotropicFilter::operator()
164 (
165  const tmp<volScalarField>& unFilteredField
166 ) const
167 {
168  correctBoundaryConditions(unFilteredField);
169 
170  tmp<volScalarField> tmpFilteredField =
171  unFilteredField
172  + (
173  coeff_
175  (
176  mesh().Sf()
177  *fvc::snGrad(unFilteredField())
178  )
179  );
180 
181  unFilteredField.clear();
182 
183  return tmpFilteredField;
184 }
185 
186 
187 Foam::tmp<Foam::volVectorField> Foam::anisotropicFilter::operator()
188 (
189  const tmp<volVectorField>& unFilteredField
190 ) const
191 {
192  return filter(unFilteredField);
193 }
194 
195 
196 Foam::tmp<Foam::volSymmTensorField> Foam::anisotropicFilter::operator()
197 (
198  const tmp<volSymmTensorField>& unFilteredField
199 ) const
200 {
201  return filter(unFilteredField);
202 }
203 
204 
205 Foam::tmp<Foam::volTensorField> Foam::anisotropicFilter::operator()
206 (
207  const tmp<volTensorField>& unFilteredField
208 ) const
209 {
210  return filter(unFilteredField);
211 }
212 
213 
214 // ************************************************************************* //
Macros for easy insertion into run-time selection tables.
Generic GeometricField class.
Internal::FieldType & primitiveFieldRef()
Return a reference to the primitive field.
tmp< GeometricField< cmptType, GeoMesh, Field > > component(const direction) const
Return a component of the field.
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
Definition: IOobject.H:99
Abstract class for LES filters.
Definition: LESfilter.H:55
void correctBoundaryConditions(const tmp< GeoFieldType > &tgf) const
Temporary function to ensure the coupled boundary conditions of the.
Definition: LESfilter.H:72
const fvMesh & mesh() const
Return mesh reference.
Definition: LESfilter.H:130
static const direction nComponents
Number of components in this vector space.
Definition: VectorSpace.H:105
anisotropic filter
anisotropicFilter(const fvMesh &mesh, scalar widthCoeff)
Construct from components.
virtual void read(const dictionary &)
Read the LESfilter dictionary.
A list of keywords followed by any number of values (e.g. words and numbers) or sub-dictionaries.
Definition: dictionary.H:162
ITstream & lookup(const word &, bool recursive=false, bool patternMatch=true) const
Find and return an entry data stream.
Definition: dictionary.C:740
const dictionary & optionalSubDict(const word &) const
Find and return a sub-dictionary if found.
Definition: dictionary.C:927
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:96
const DimensionedField< scalar, volMesh > & V() const
Return cell volumes.
const surfaceVectorField & Sf() const
Return cell face area vectors.
A class for managing temporary objects.
Definition: tmp.H:55
void clear() const
If object pointer points to valid object:
Definition: tmpI.H:253
T & ref() const
Return non-const reference or generate a fatal error.
Definition: tmpI.H:197
Foam::fvMesh mesh(Foam::IOobject(regionName, runTime.name(), runTime, Foam::IOobject::MUST_READ), false)
Calculate the snGrad of the given volField.
Surface integrate surfaceField creating a volField. Surface sum a surfaceField creating a volField.
U correctBoundaryConditions()
tmp< VolField< Type > > surfaceIntegrateExtrapolate(const SurfaceField< Type > &ssf)
tmp< VolInternalField< Type > > surfaceSum(const SurfaceField< Type > &ssf)
tmp< SurfaceField< Type > > snGrad(const VolField< Type > &vf, const word &name)
Definition: fvcSnGrad.C:45
Namespace for OpenFOAM.
static const zero Zero
Definition: zero.H:97
addToRunTimeSelectionTable(polyPatch, mergedCyclicPolyPatch, word)
const HashTable< dimensionSet > & dimensions()
Get the table of dimension sets.
Definition: dimensionSets.C:96
const dimensionSet dimLength
void mag(LagrangianPatchField< scalar > &f, const LagrangianPatchField< Type > &f1)
void component(LagrangianPatchField< typename LagrangianPatchField< Type >::cmptType > &sf, const LagrangianPatchField< Type > &f, const direction d)
defineTypeNameAndDebug(combustionModel, 0)
void sqr(LagrangianPatchField< typename outerProduct< Type, Type >::type > &f, const LagrangianPatchField< Type > &f1)
word name(const LagrangianState state)
Return a string representation of a Lagrangian state enumeration.
uint8_t direction
Definition: direction.H:45
fileType type(const fileName &, const bool checkVariants=true, const bool followLink=true)
Return the file type: directory or file.
Definition: POSIX.C:488