Fix tutorials: coupled/conjugateHeatFoam/conjugateCavity: fix Allrun file
[OpenFOAM-1.6-ext.git] / src / finiteVolume / fields / fvPatchFields / constraint / cyclicGgi / cyclicGgiFvPatchField.C
blob1b64c7c64ae1b24a11814ffec9a2f894b7f9fea3
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright held by original author
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
9     This file is part of OpenFOAM.
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 the
13     Free Software Foundation; either version 2 of the License, or (at your
14     option) any later version.
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.
21     You should have received a copy of the GNU General Public License
22     along with OpenFOAM; if not, write to the Free Software Foundation,
23     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 Author
26     Martin Beaudoin, Hydro-Quebec, (2008)
28 Contributor:
29     Hrvoje Jasak, Wikki Ltd.
31 \*---------------------------------------------------------------------------*/
33 #include "cyclicGgiFvPatchField.H"
34 #include "symmTransformField.H"
36 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
38 namespace Foam
41 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
43 template<class Type>
44 cyclicGgiFvPatchField<Type>::cyclicGgiFvPatchField
46     const fvPatch& p,
47     const DimensionedField<Type, volMesh>& iF
50     coupledFvPatchField<Type>(p, iF),
51     cyclicGgiPatch_(refCast<const cyclicGgiFvPatch>(p))
55 template<class Type>
56 cyclicGgiFvPatchField<Type>::cyclicGgiFvPatchField
58     const fvPatch& p,
59     const DimensionedField<Type, volMesh>& iF,
60     const dictionary& dict
63     coupledFvPatchField<Type>(p, iF, dict, false),
64     cyclicGgiPatch_(refCast<const cyclicGgiFvPatch>(p))
66     if (!isType<cyclicGgiFvPatch>(p))
67     {
68         FatalIOErrorIn
69         (
70             "cyclicGgiFvPatchField<Type>::cyclicGgiFvPatchField\n"
71             "(\n"
72             "    const fvPatch& p,\n"
73             "    const DimensionedField<Type, volMesh>& iF,\n"
74             "    const dictionary& dict\n"
75             ")\n",
76             dict
77         )   << "patch " << this->patch().index() << " not cyclicGgi type. "
78             << "Patch type = " << p.type()
79             << exit(FatalIOError);
80     }
82     if (!dict.found("value"))
83     {
84         // Grab the internal value for initialisation. (?) HJ, 27/Feb/2009
85         fvPatchField<Type>::operator=(this->patchInternalField()());
86     }
90 template<class Type>
91 cyclicGgiFvPatchField<Type>::cyclicGgiFvPatchField
93     const cyclicGgiFvPatchField<Type>& ptf,
94     const fvPatch& p,
95     const DimensionedField<Type, volMesh>& iF,
96     const fvPatchFieldMapper& mapper
99     coupledFvPatchField<Type>(ptf, p, iF, mapper),
100     cyclicGgiPatch_(refCast<const cyclicGgiFvPatch>(p))
102     if (!isType<cyclicGgiFvPatch>(this->patch()))
103     {
104         FatalErrorIn
105         (
106             "cyclicGgiFvPatchField<Type>::cyclicGgiFvPatchField\n"
107             "(\n"
108             "    const cyclicGgiFvPatchField<Type>& ptf,\n"
109             "    const fvPatch& p,\n"
110             "    const DimensionedField<Type, volMesh>& iF,\n"
111             "    const fvPatchFieldMapper& mapper\n"
112             ")\n"
113         )   << "Field type does not correspond to patch type for patch "
114             << this->patch().index() << "." << endl
115             << "Field type: " << typeName << endl
116             << "Patch type: " << this->patch().type()
117             << exit(FatalError);
118     }
122 template<class Type>
123 cyclicGgiFvPatchField<Type>::cyclicGgiFvPatchField
125     const cyclicGgiFvPatchField<Type>& ptf,
126     const DimensionedField<Type, volMesh>& iF
129     ggiLduInterfaceField(),
130     coupledFvPatchField<Type>(ptf, iF),
131     cyclicGgiPatch_(refCast<const cyclicGgiFvPatch>(ptf.patch()))
136 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
138 // Return neighbour field
139 template<class Type>
140 tmp<Field<Type> > cyclicGgiFvPatchField<Type>::patchNeighbourField() const
142     const Field<Type>& iField = this->internalField();
144     // Get shadow face-cells and assemble shadow field
145     const unallocLabelList& sfc = cyclicGgiPatch_.shadow().faceCells();
147     Field<Type> sField(sfc.size());
149     forAll (sField, i)
150     {
151         sField[i] = iField[sfc[i]];
152     }
154     // Transformation is handled in interpolation.  HJ, 7/Jan/2009
155     tmp<Field<Type> > tpnf(cyclicGgiPatch_.interpolate(sField));
156     Field<Type>& pnf = tpnf();
158     if (cyclicGgiPatch_.bridgeOverlap())
159     {
160         // Symmetry treatment used for overlap
161         vectorField nHat = this->patch().nf();
163         // Use mirrored internal field for neighbour
164         // HJ, 27/Jan/2009
165         Field<Type> bridgeField =
166             transform(I - 2.0*sqr(nHat), this->patchInternalField());
168         cyclicGgiPatch_.bridge(bridgeField, pnf);
169     }
171     return tpnf;
175 template<class Type>
176 void cyclicGgiFvPatchField<Type>::initEvaluate
178     const Pstream::commsTypes commsType
181     if (!this->updated())
182     {
183         this->updateCoeffs();
184     }
186     Field<Type> pf
187     (
188         this->patch().weights()*this->patchInternalField()
189       + (1.0 - this->patch().weights())*this->patchNeighbourField()
190     );
192     if (cyclicGgiPatch_.bridgeOverlap())
193     {
194         // Symmetry treatment used for overlap
195         vectorField nHat = this->patch().nf();
197         Field<Type> bridgeField =
198         (
199             this->patchInternalField()
200           + transform(I - 2.0*sqr(nHat), this->patchInternalField())
201         )/2.0;
203         cyclicGgiPatch_.bridge(bridgeField, pf);
204     }
206     Field<Type>::operator=(pf);
210 template<class Type>
211 void cyclicGgiFvPatchField<Type>::evaluate
213     const Pstream::commsTypes
216     if (!this->updated())
217     {
218         this->updateCoeffs();
219     }
223 template<class Type>
224 void cyclicGgiFvPatchField<Type>::initInterfaceMatrixUpdate
226     const scalarField& psiInternal,
227     scalarField& result,
228     const lduMatrix&,
229     const scalarField& coeffs,
230     const direction cmpt,
231     const Pstream::commsTypes commsType
232 ) const
234     // Get shadow face-cells and assemble shadow field
235     const unallocLabelList& sfc = cyclicGgiPatch_.shadow().faceCells();
237     scalarField sField(sfc.size());
239     forAll (sField, i)
240     {
241         sField[i] = psiInternal[sfc[i]];
242     }
244     // Transform according to the transformation tensor, using the slave
245     // side transform.  Warning: forwardT() corresponds to the slave
246     // patch.  HJ, 12/Jan/2009
247     transformCoupleField(sField, cmpt);
249     // Note: scalar interpolate does not get a transform, so this is safe
250     // HJ, 12/Jan/2009
251     scalarField pnf = cyclicGgiPatch_.interpolate(sField);
253     // Multiply the field by coefficients and add into the result
254     const unallocLabelList& fc = cyclicGgiPatch_.faceCells();
256     forAll(fc, elemI)
257     {
258         result[fc[elemI]] -= coeffs[elemI]*pnf[elemI];
259     }
263 // Return matrix product for coupled boundary
264 template<class Type>
265 void cyclicGgiFvPatchField<Type>::updateInterfaceMatrix
267     const scalarField& psiInternal,
268     scalarField& result,
269     const lduMatrix&,
270     const scalarField& coeffs,
271     const direction cmpt,
272     const Pstream::commsTypes
273 ) const
277 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
279 } // End namespace Foam
281 // ************************************************************************* //