Remove trailing whitespace systematically
[foam-extend-3.2.git] / applications / solvers / solidMechanics / deprecatedSolvers / materialModels / fvPatchFields / newDirectionMixed / newDirectionMixedFvPatchField.C
blobdb4396239b73bb4ab45d13a9ff823f0586cee66c
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | foam-extend: Open Source CFD
4    \\    /   O peration     |
5     \\  /    A nd           | For copyright notice see file Copyright
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
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 Class
25     newDirectionMixedFvPatchField
27 Description
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 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
40 namespace Foam
43 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
45 template<class Type>
46 void newDirectionMixedFvPatchField<Type>::checkNHat()
48     scalarField magNHat(Foam::mag(nHat_));
50     if (min(magNHat) < SMALL)
51     {
52         FatalErrorIn("void newDirectionMixedFvPatchField<Type>::checkNHat()")
53             << "Incorrectly defined normal direction.  mag = "
54             << min(magNHat)
55             << abort(FatalError);
56     }
58     magNHat /= mag(magNHat);
61 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
63 template<class Type>
64 newDirectionMixedFvPatchField<Type>::newDirectionMixedFvPatchField
66     const fvPatch& p,
67     const DimensionedField<Type, volMesh>& iF
70     fvPatchField<Type>(p, iF),
71     refValue_(p.size()),
72     refGrad_(p.size()),
73     nHat_(p.size()),
74     normalValueFraction_(p.size()),
75     tangentialValueFraction_(p.size())
79 template<class Type>
80 newDirectionMixedFvPatchField<Type>::newDirectionMixedFvPatchField
82     const newDirectionMixedFvPatchField<Type>& ptf,
83     const fvPatch& p,
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)
95     this->checkNHat();
99 template<class Type>
100 newDirectionMixedFvPatchField<Type>::newDirectionMixedFvPatchField
102     const fvPatch& p,
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())
114     this->checkNHat();
115     evaluate();
119 template<class Type>
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_),
129     nHat_(ptf.nHat_),
130     normalValueFraction_(ptf.normalValueFraction_),
131     tangentialValueFraction_(ptf.tangentialValueFraction_)
133     this->checkNHat();
137 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
139 // Map from self
140 template<class Type>
141 void newDirectionMixedFvPatchField<Type>::autoMap
143     const fvPatchFieldMapper& m
146     Field<Type>::autoMap(m);
147     refValue_.autoMap(m);
148     refGrad_.autoMap(m);
149     nHat_.autoMap(m);
150     normalValueFraction_.autoMap(m);
151     tangentialValueFraction_.autoMap(m);
155 // Reverse-map the given fvPatchField onto this fvPatchField
156 template<class Type>
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
177 template<class Type>
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
199 template<class Type>
200 void newDirectionMixedFvPatchField<Type>::evaluate()
202     if (!this->updated())
203     {
204         this->updateCoeffs();
205     }
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
229 template<class Type>
230 tmp<Field<Type> > newDirectionMixedFvPatchField<Type>::valueInternalCoeffs
232     const tmp<scalarField>&
233 ) const
235     const Field<Type> one(this->size(), pTraits<Type>::one);
236     const tensorField nn= nHat_*nHat_;
238     return
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
246 template<class Type>
247 tmp<Field<Type> > newDirectionMixedFvPatchField<Type>::valueBoundaryCoeffs
249     const tmp<scalarField>&
250 ) const
252     const scalarField& deltaCoeffs = this->patch().deltaCoeffs();
253     const tensorField nn= nHat_*nHat_;
255     return
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
263 //     return
264 //         *this
265 //       - scale
266 //         (
267 //             valueInternalCoeffs(this->patch().weights()),
268 //             this->patchInternalField()
269 //         );
272 //- Return the matrix diagonal coefficients corresponding to the
273 //  evaluation of the gradient of this patchField
274 template<class Type>
275 tmp<Field<Type> >
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_;
282     return
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
289 template<class Type>
290 tmp<Field<Type> >
291 newDirectionMixedFvPatchField<Type>::gradientBoundaryCoeffs() const
293     const scalarField& deltaCoeffs = this->patch().deltaCoeffs();
294     const tensorField nn= nHat_*nHat_;
296     return
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
303 //     return
304 //         snGrad()
305 //       - scale(gradientInternalCoeffs(), this->patchInternalField());
309 // Write
310 template<class Type>
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 // ************************************************************************* //