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/>.
25 newDirectionMixedFvPatchField
28 Doubly mixed fixed value-fixed gradient boundary condition
29 separated into a normal and a tangential component given a
30 direction vector. The mixture is controlled by two separate
31 valueFraction coefficients in the normal and tangential direction.
33 \*---------------------------------------------------------------------------*/
35 #include "newDirectionMixedFvPatchField.H"
36 #include "transformField.H"
38 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
43 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
46 void newDirectionMixedFvPatchField<Type>::checkNHat()
48 scalarField magNHat(Foam::mag(nHat_));
50 if (min(magNHat) < SMALL)
52 FatalErrorIn("void newDirectionMixedFvPatchField<Type>::checkNHat()")
53 << "Incorrectly defined normal direction. mag = "
58 magNHat /= mag(magNHat);
61 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
64 newDirectionMixedFvPatchField<Type>::newDirectionMixedFvPatchField
67 const DimensionedField<Type, volMesh>& iF
70 fvPatchField<Type>(p, iF),
74 normalValueFraction_(p.size()),
75 tangentialValueFraction_(p.size())
80 newDirectionMixedFvPatchField<Type>::newDirectionMixedFvPatchField
82 const newDirectionMixedFvPatchField<Type>& ptf,
84 const DimensionedField<Type, volMesh>& iF,
85 const fvPatchFieldMapper& mapper
88 fvPatchField<Type>(ptf, p, iF, mapper),
89 refValue_(ptf.refValue_, mapper),
90 refGrad_(ptf.refGrad_, mapper),
91 nHat_(ptf.nHat_, mapper),
92 normalValueFraction_(ptf.normalValueFraction_, mapper),
93 tangentialValueFraction_(ptf.tangentialValueFraction_, mapper)
100 newDirectionMixedFvPatchField<Type>::newDirectionMixedFvPatchField
103 const DimensionedField<Type, volMesh>& iF,
104 const dictionary& dict
107 fvPatchField<Type>(p, iF, dict),
108 refValue_("refValue", dict, p.size()),
109 refGrad_("refGradient", dict, p.size()),
110 nHat_("nHat", dict, p.size()),
111 normalValueFraction_("normalValueFraction", dict, p.size()),
112 tangentialValueFraction_("tangentialValueFraction", dict, p.size())
120 newDirectionMixedFvPatchField<Type>::newDirectionMixedFvPatchField
122 const newDirectionMixedFvPatchField<Type>& ptf,
123 const DimensionedField<Type, volMesh>& iF
126 fvPatchField<Type>(ptf, iF),
127 refValue_(ptf.refValue_),
128 refGrad_(ptf.refGrad_),
130 normalValueFraction_(ptf.normalValueFraction_),
131 tangentialValueFraction_(ptf.tangentialValueFraction_)
137 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
141 void newDirectionMixedFvPatchField<Type>::autoMap
143 const fvPatchFieldMapper& m
146 Field<Type>::autoMap(m);
147 refValue_.autoMap(m);
150 normalValueFraction_.autoMap(m);
151 tangentialValueFraction_.autoMap(m);
155 // Reverse-map the given fvPatchField onto this fvPatchField
157 void newDirectionMixedFvPatchField<Type>::rmap
159 const fvPatchField<Type>& ptf,
160 const labelList& addr
163 fvPatchField<Type>::rmap(ptf, addr);
165 const newDirectionMixedFvPatchField<Type>& dmptf =
166 refCast<const newDirectionMixedFvPatchField<Type> >(ptf);
168 refValue_.rmap(dmptf.refValue_, addr);
169 refGrad_.rmap(dmptf.refGrad_, addr);
170 nHat_.rmap(dmptf.nHat_, addr);
171 normalValueFraction_.rmap(dmptf.normalValueFraction_, addr);
172 tangentialValueFraction_.rmap(dmptf.tangentialValueFraction_, addr);
176 // Return gradient at boundary
178 tmp<Field<Type> > newDirectionMixedFvPatchField<Type>::snGrad() const
180 Field<Type> pif = this->patchInternalField();
182 const scalarField& deltaCoeffs = this->patch().deltaCoeffs();
183 const tensorField nn= nHat_*nHat_;
185 Field<Type> normalValue =
186 normalValueFraction_*transform(nn, refValue_)
187 + (1.0 - normalValueFraction_)*transform(nn, pif + refGrad_/deltaCoeffs);
189 Field<Type> tangentialValue =
190 tangentialValueFraction_*transform(I - nn, refValue_)
191 + (1.0 - tangentialValueFraction_)*
192 transform(I - nn, pif + refGrad_/deltaCoeffs);
194 return (normalValue + tangentialValue - pif)*deltaCoeffs;
198 // Evaluate the field on the patch
200 void newDirectionMixedFvPatchField<Type>::evaluate()
202 if (!this->updated())
204 this->updateCoeffs();
207 Field<Type> pif = this->patchInternalField();
209 const scalarField& deltaCoeffs = this->patch().deltaCoeffs();
210 const tensorField nn = nHat_*nHat_;
212 Field<Type> normalValue =
213 normalValueFraction_*transform(nn, refValue_)
214 + (1.0 - normalValueFraction_)*transform(nn, pif + refGrad_/deltaCoeffs);
216 Field<Type> tangentialValue =
217 tangentialValueFraction_*transform(I - nn, refValue_)
218 + (1.0 - tangentialValueFraction_)*
219 transform(I - nn, pif + refGrad_/deltaCoeffs);
221 Field<Type>::operator=(normalValue + tangentialValue);
223 fvPatchField<Type>::evaluate();
227 //- Return the matrix diagonal coefficients corresponding to the
228 // evaluation of the value of this patchField
230 tmp<Field<Type> > newDirectionMixedFvPatchField<Type>::valueInternalCoeffs
232 const tmp<scalarField>&
235 const Field<Type> one(this->size(), pTraits<Type>::one);
236 const tensorField nn= nHat_*nHat_;
239 transform(nn, one)*(1.0 - normalValueFraction_)
240 + transform(I - nn, one)*(1.0 - tangentialValueFraction_);
244 //- Return the matrix source coefficients corresponding to the
245 // evaluation of the value of this patchField
247 tmp<Field<Type> > newDirectionMixedFvPatchField<Type>::valueBoundaryCoeffs
249 const tmp<scalarField>&
252 const scalarField& deltaCoeffs = this->patch().deltaCoeffs();
253 const tensorField nn= nHat_*nHat_;
256 normalValueFraction_*transform(nn, refValue_)
257 + (1.0 - normalValueFraction_)*transform(nn, refGrad_)/deltaCoeffs
258 + tangentialValueFraction_*transform(I - nn, refValue_)
259 + (1.0 - tangentialValueFraction_)*
260 transform(I - nn, refGrad_)/deltaCoeffs;
262 // Alternative; allows fiddling internal/boundary split for value coeffs
267 // valueInternalCoeffs(this->patch().weights()),
268 // this->patchInternalField()
272 //- Return the matrix diagonal coefficients corresponding to the
273 // evaluation of the gradient of this patchField
276 newDirectionMixedFvPatchField<Type>::gradientInternalCoeffs() const
278 const scalarField& deltaCoeffs = this->patch().deltaCoeffs();
279 const Field<Type> one(this->size(), pTraits<Type>::one);
280 const tensorField nn= nHat_*nHat_;
283 -transform(nn, one)*normalValueFraction_*deltaCoeffs
284 - transform(I - nn, one)*tangentialValueFraction_*deltaCoeffs;
287 //- Return the matrix source coefficients corresponding to the
288 // evaluation of the gradient of this patchField
291 newDirectionMixedFvPatchField<Type>::gradientBoundaryCoeffs() const
293 const scalarField& deltaCoeffs = this->patch().deltaCoeffs();
294 const tensorField nn= nHat_*nHat_;
297 normalValueFraction_*deltaCoeffs*transform(nn, refValue_)
298 + (1.0 - normalValueFraction_)*transform(nn, refGrad_)
299 + tangentialValueFraction_*deltaCoeffs*transform(I - nn, refValue_)
300 + (1.0 - tangentialValueFraction_)*transform(I - nn, refGrad_);
302 // Alternative; allows fiddling internal/boundary split for grad coeffs
305 // - scale(gradientInternalCoeffs(), this->patchInternalField());
311 void newDirectionMixedFvPatchField<Type>::write(Ostream& os) const
313 fvPatchField<Type>::write(os);
314 refValue_.writeEntry("refValue", os);
315 refGrad_.writeEntry("refGradient", os);
316 nHat_.writeEntry("nHat", os);
317 normalValueFraction_.writeEntry("normalValueFraction", os);
318 tangentialValueFraction_.writeEntry("tangentialValueFraction", os);
319 this->writeEntry("value", os);
323 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
325 } // End namespace Foam
327 // ************************************************************************* //