1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | foam-extend: Open Source CFD
4 \\ / O peration | Version: 3.2
5 \\ / A nd | Web: http://www.foam-extend.org
6 \\/ M anipulation | For copyright notice see file Copyright
7 -------------------------------------------------------------------------------
9 This file is part of foam-extend.
11 foam-extend is free software: you can redistribute it and/or modify it
12 under the terms of the GNU General Public License as published by the
13 Free Software Foundation, either version 3 of the License, or (at your
14 option) any later version.
16 foam-extend is distributed in the hope that it will be useful, but
17 WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with foam-extend. If not, see <http://www.gnu.org/licenses/>.
24 \*---------------------------------------------------------------------------*/
26 #include "basicSymmetryFvPatchField.H"
27 #include "volFields.H"
29 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
34 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
37 tmp<scalarField > basicSymmetryFvPatchField<scalar>::snGrad() const
39 return tmp<scalarField>(new scalarField(size(), scalar(0)));
44 // Skew correction and second order is currently handled in template
45 // specialisations because
46 // Note 2: Currently repeated code in evaluate after typedefs.
47 // Refactor. HJ, 18/Mar/2015
49 void basicSymmetryFvPatchField<scalar>::evaluate(const Pstream::commsTypes)
53 typedef outerProduct<vector, Type>::type gradType;
54 typedef GeometricField<gradType, fvPatchField, volMesh> gradFieldType;
61 vectorField nHat = this->patch().nf();
63 // Get patch internal field
64 Field<Type> pif = this->patchInternalField();
66 // Skew corrected treatment
69 // Access the gradient
70 const word DName = this->dimensionedInternalField().name();
71 const word gradDName("grad(" + DName + ")");
73 if (!this->db().foundObject<gradFieldType>(gradDName))
77 "void basicSymmetryFvPatchField<Type>::"
78 "evaluate(const Pstream::commsTypes)"
79 ) << "Cannot access " << gradDName << " field for field "
80 << DName << " for patch "<< this->patch().name()
81 << ". Evaluating without skew correction"
86 // Calculate skew correction vector k
87 vectorField delta = patch().delta();
88 vectorField k = delta - nHat*(nHat&delta);
91 const fvPatchField<gradType>& gradD =
92 patch().lookupPatchField<gradFieldType, gradType>(gradDName);
94 // Correct cell value for k
95 pif += (k & gradD.patchInternalField());
99 Field<Type> nGradD = (nHat & gradD.patchInternalField());
101 Field<Type>::operator=
106 pif + 0.5*nGradD/this->patch().deltaCoeffs()
110 // Return, skew corrected, second order
111 transformFvPatchField<Type>::evaluate();
116 Field<Type>::operator=
118 0.5*(pif + transform(I - 2.0*sqr(nHat), pif))
121 // Return, skew corrected without second order correction
122 transformFvPatchField<Type>::evaluate();
128 // Without skew correction
129 Field<Type>::operator=
131 0.5*(pif + transform(I - 2.0*sqr(nHat), pif))
134 transformFvPatchField<Type>::evaluate();
139 tmp<vectorField> basicSymmetryFvPatchField<vector>::snGrad() const
143 typedef outerProduct<vector, Type>::type gradType;
144 typedef GeometricField<gradType, fvPatchField, volMesh> gradFieldType;
146 vectorField nHat = this->patch().nf();
148 // Get patch internal field
149 Field<Type> pif = this->patchInternalField();
151 // Skew corrected treatment
154 // Access the gradient
155 const word DName = this->dimensionedInternalField().name();
156 const word gradDName("grad(" + DName + ")");
158 if (!this->db().foundObject<gradFieldType>(gradDName))
162 "void basicSymmetryFvPatchField<Type>::snGrad() const"
163 ) << "Cannot access " << gradDName << " field for field "
164 << DName << " for patch "<< this->patch().name()
165 << ". Evaluating without skew correction"
170 // Calculate skew correction vector k
171 vectorField delta = patch().delta();
172 vectorField k = delta - nHat*(nHat&delta);
175 const fvPatchField<gradType>& gradD =
176 patch().lookupPatchField<gradFieldType, gradType>(gradDName);
178 // Correct cell value for k
179 pif += (k & gradD.patchInternalField());
183 Field<Type> nGradD = (nHat & gradD.patchInternalField());
185 // Return, skew corrected, second order
188 transform(I - 2.0*sqr(nHat), pif) - pif
189 )*(this->patch().deltaCoeffs()/2.0)
190 - transform(sqr(nHat), nGradD);
194 // Return, skew corrected, without second order correction
197 transform(I - 2.0*sqr(nHat), pif) - pif
198 )*(this->patch().deltaCoeffs()/2.0);
203 // Without skew correction
206 transform(I - 2.0*sqr(nHat), pif) - pif
207 )*(this->patch().deltaCoeffs()/2.0);
212 void basicSymmetryFvPatchField<vector>::evaluate(const Pstream::commsTypes)
216 typedef outerProduct<vector, Type>::type gradType;
217 typedef GeometricField<gradType, fvPatchField, volMesh> gradFieldType;
229 vectorField nHat = this->patch().nf();
231 // Get patch internal field
232 Field<Type> pif = this->patchInternalField();
234 // Skew corrected treatment
237 // Access the gradient
238 const word DName = this->dimensionedInternalField().name();
239 const word gradDName("grad(" + DName + ")");
241 if (!this->db().foundObject<gradFieldType>(gradDName))
245 "void basicSymmetryFvPatchField<Type>::"
246 "evaluate(const Pstream::commsTypes)"
247 ) << "Cannot access " << gradDName << " field for field "
248 << DName << " for patch "<< this->patch().name()
249 << ". Evaluating without skew correction"
254 // Calculate skew correction vector k
255 vectorField delta = patch().delta();
256 vectorField k = delta - nHat*(nHat&delta);
259 const fvPatchField<gradType>& gradD =
260 patch().lookupPatchField<gradFieldType, gradType>(gradDName);
262 // Correct cell value for k
263 pif += (k & gradD.patchInternalField());
267 Field<Type> nGradD = (nHat & gradD.patchInternalField());
269 Field<Type>::operator=
274 pif + 0.5*nGradD/this->patch().deltaCoeffs()
278 // Return, skew corrected, second order
279 transformFvPatchField<Type>::evaluate();
284 Field<Type>::operator=
286 0.5*(pif + transform(I - 2.0*sqr(nHat), pif))
289 // Return, skew corrected without second order correction
290 transformFvPatchField<Type>::evaluate();
296 // Without skew correction
297 Field<Type>::operator=
299 0.5*(pif + transform(I - 2.0*sqr(nHat), pif))
302 transformFvPatchField<Type>::evaluate();
306 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
308 } // End namespace Foam
310 // ************************************************************************* //