initial commit for version 1.6.x patch release
[OpenFOAM-1.6.x.git] / src / finiteVolume / fields / fvPatchFields / constraint / cyclic / cyclicFvPatchField.C
blobb4955d750cf0f6de9e4085e991fb6e981b03a72d
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 1991-2009 OpenCFD Ltd.
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 \*---------------------------------------------------------------------------*/
27 #include "cyclicFvPatchField.H"
29 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
31 namespace Foam
34 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
36 template<class Type>
37 cyclicFvPatchField<Type>::cyclicFvPatchField
39     const fvPatch& p,
40     const DimensionedField<Type, volMesh>& iF
43     coupledFvPatchField<Type>(p, iF),
44     cyclicPatch_(refCast<const cyclicFvPatch>(p))
48 template<class Type>
49 cyclicFvPatchField<Type>::cyclicFvPatchField
51     const cyclicFvPatchField<Type>& ptf,
52     const fvPatch& p,
53     const DimensionedField<Type, volMesh>& iF,
54     const fvPatchFieldMapper& mapper
57     coupledFvPatchField<Type>(ptf, p, iF, mapper),
58     cyclicPatch_(refCast<const cyclicFvPatch>(p))
60     if (!isType<cyclicFvPatch>(this->patch()))
61     {
62         FatalErrorIn
63         (
64             "cyclicFvPatchField<Type>::cyclicFvPatchField\n"
65             "(\n"
66             "    const cyclicFvPatchField<Type>& ptf,\n"
67             "    const fvPatch& p,\n"
68             "    const DimensionedField<Type, volMesh>& iF,\n"
69             "    const fvPatchFieldMapper& mapper\n"
70             ")\n"
71         )   << "\n    patch type '" << p.type()
72             << "' not constraint type '" << typeName << "'"
73             << "\n    for patch " << p.name()
74             << " of field " << this->dimensionedInternalField().name()
75             << " in file " << this->dimensionedInternalField().objectPath()
76             << exit(FatalIOError);
77     }
81 template<class Type>
82 cyclicFvPatchField<Type>::cyclicFvPatchField
84     const fvPatch& p,
85     const DimensionedField<Type, volMesh>& iF,
86     const dictionary& dict
89     coupledFvPatchField<Type>(p, iF, dict),
90     cyclicPatch_(refCast<const cyclicFvPatch>(p))
92     if (!isType<cyclicFvPatch>(p))
93     {
94         FatalIOErrorIn
95         (
96             "cyclicFvPatchField<Type>::cyclicFvPatchField\n"
97             "(\n"
98             "    const fvPatch& p,\n"
99             "    const Field<Type>& field,\n"
100             "    const dictionary& dict\n"
101             ")\n",
102             dict
103         )   << "\n    patch type '" << p.type()
104             << "' not constraint type '" << typeName << "'"
105             << "\n    for patch " << p.name()
106             << " of field " << this->dimensionedInternalField().name()
107             << " in file " << this->dimensionedInternalField().objectPath()
108             << exit(FatalIOError);
109     }
111     this->evaluate(Pstream::blocking);
115 template<class Type>
116 cyclicFvPatchField<Type>::cyclicFvPatchField
118     const cyclicFvPatchField<Type>& ptf
121     cyclicLduInterfaceField(),
122     coupledFvPatchField<Type>(ptf),
123     cyclicPatch_(ptf.cyclicPatch_)
127 template<class Type>
128 cyclicFvPatchField<Type>::cyclicFvPatchField
130     const cyclicFvPatchField<Type>& ptf,
131     const DimensionedField<Type, volMesh>& iF
134     coupledFvPatchField<Type>(ptf, iF),
135     cyclicPatch_(ptf.cyclicPatch_)
139 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
141 template<class Type>
142 tmp<Field<Type> > cyclicFvPatchField<Type>::patchNeighbourField() const
144     const Field<Type>& iField = this->internalField();
145     const unallocLabelList& faceCells = cyclicPatch_.faceCells();
147     tmp<Field<Type> > tpnf(new Field<Type>(this->size()));
148     Field<Type>& pnf = tpnf();
150     label sizeby2 = this->size()/2;
152     if (doTransform())
153     {
154         for (label facei=0; facei<sizeby2; facei++)
155         {
156             pnf[facei] = transform
157             (
158                 forwardT()[0], iField[faceCells[facei + sizeby2]]
159             );
161             pnf[facei + sizeby2] = transform
162             (
163                 reverseT()[0], iField[faceCells[facei]]
164             );
165         }
166     }
167     else
168     {
169         for (label facei=0; facei<sizeby2; facei++)
170         {
171             pnf[facei] = iField[faceCells[facei + sizeby2]];
172             pnf[facei + sizeby2] = iField[faceCells[facei]];
173         }
174     }
176     return tpnf;
180 template<class Type>
181 void cyclicFvPatchField<Type>::updateInterfaceMatrix
183     const scalarField& psiInternal,
184     scalarField& result,
185     const lduMatrix&,
186     const scalarField& coeffs,
187     const direction cmpt,
188     const Pstream::commsTypes
189 ) const
191     scalarField pnf(this->size());
193     label sizeby2 = this->size()/2;
194     const unallocLabelList& faceCells = cyclicPatch_.faceCells();
196     for (label facei=0; facei<sizeby2; facei++)
197     {
198         pnf[facei] = psiInternal[faceCells[facei + sizeby2]];
199         pnf[facei + sizeby2] = psiInternal[faceCells[facei]];
200     }
202     // Transform according to the transformation tensors
203     transformCoupleField(pnf, cmpt);
205     // Multiply the field by coefficients and add into the result
206     forAll(faceCells, elemI)
207     {
208         result[faceCells[elemI]] -= coeffs[elemI]*pnf[elemI];
209     }
213 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
215 } // End namespace Foam
217 // ************************************************************************* //