initial commit for version 1.6.x patch release
[OpenFOAM-1.6.x.git] / src / finiteVolume / fvMesh / fvPatches / constraint / cyclic / cyclicFvPatch.C
blobbc9c9fb85008f484763e4a77b41a7751e376c7aa
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 "cyclicFvPatch.H"
28 #include "addToRunTimeSelectionTable.H"
29 #include "fvMesh.H"
31 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
33 namespace Foam
36 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
38 defineTypeNameAndDebug(cyclicFvPatch, 0);
39 addToRunTimeSelectionTable(fvPatch, cyclicFvPatch, polyPatch);
42 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
44 // Make patch weighting factors
45 void cyclicFvPatch::makeWeights(scalarField& w) const
47     const scalarField& magFa = magSf();
49     scalarField deltas = nf() & fvPatch::delta();
50     label sizeby2 = deltas.size()/2;
52     for (label facei = 0; facei < sizeby2; facei++)
53     {
54         scalar avFa = (magFa[facei] + magFa[facei + sizeby2])/2.0;
56         if (mag(magFa[facei] - magFa[facei + sizeby2])/avFa > 1e-4)
57         {
58             FatalErrorIn("cyclicFvPatch::makeWeights(scalarField& w) const")
59                 << "face " << facei << " and " << facei + sizeby2
60                 <<  " areas do not match by "
61                 << 100*mag(magFa[facei] - magFa[facei + sizeby2])/avFa
62                 << "% -- possible face ordering problem"
63                 << abort(FatalError);
64         }
66         scalar di = deltas[facei];
67         scalar dni = deltas[facei + sizeby2];
69         w[facei] = dni/(di + dni);
70         w[facei + sizeby2] = 1 - w[facei];
71     }
75 // Make patch face - neighbour cell distances
76 void cyclicFvPatch::makeDeltaCoeffs(scalarField& dc) const
78     scalarField deltas = nf() & fvPatch::delta();
79     label sizeby2 = deltas.size()/2;
81     for (label facei = 0; facei < sizeby2; facei++)
82     {
83         scalar di = deltas[facei];
84         scalar dni = deltas[facei + sizeby2];
86         dc[facei] = 1.0/(di + dni);
87         dc[facei + sizeby2] = dc[facei];
88     }
92 // Return delta (P to N) vectors across coupled patch
93 tmp<vectorField> cyclicFvPatch::delta() const
95     vectorField patchD = fvPatch::delta();
96     label sizeby2 = patchD.size()/2;
98     tmp<vectorField> tpdv(new vectorField(patchD.size()));
99     vectorField& pdv = tpdv();
101     // To the transformation if necessary
102     if (parallel())
103     {
104         for (label facei = 0; facei < sizeby2; facei++)
105         {
106             vector ddi = patchD[facei];
107             vector dni = patchD[facei + sizeby2];
109             pdv[facei] = ddi - dni;
110             pdv[facei + sizeby2] = -pdv[facei];
111         }
112     }
113     else
114     {
115         for (label facei = 0; facei < sizeby2; facei++)
116         {
117             vector ddi = patchD[facei];
118             vector dni = patchD[facei + sizeby2];
120             pdv[facei] = ddi - transform(forwardT()[0], dni);
121             pdv[facei + sizeby2] = -transform(reverseT()[0], pdv[facei]);
122         }
123     }
125     return tpdv;
129 tmp<labelField> cyclicFvPatch::interfaceInternalField
131     const unallocLabelList& internalData
132 ) const
134     return patchInternalField(internalData);
138 tmp<labelField> cyclicFvPatch::transfer
140     const Pstream::commsTypes,
141     const unallocLabelList& interfaceData
142 ) const
144     tmp<labelField> tpnf(new labelField(this->size()));
145     labelField& pnf = tpnf();
147     label sizeby2 = this->size()/2;
149     for (label facei=0; facei<sizeby2; facei++)
150     {
151         pnf[facei] = interfaceData[facei + sizeby2];
152         pnf[facei + sizeby2] = interfaceData[facei];
153     }
155     return tpnf;
159 tmp<labelField> cyclicFvPatch::internalFieldTransfer
161     const Pstream::commsTypes commsType,
162     const unallocLabelList& iF
163 ) const
165     const unallocLabelList& faceCells = this->patch().faceCells();
167     tmp<labelField> tpnf(new labelField(this->size()));
168     labelField& pnf = tpnf();
170     label sizeby2 = this->size()/2;
172     for (label facei=0; facei<sizeby2; facei++)
173     {
174         pnf[facei] = iF[faceCells[facei + sizeby2]];
175         pnf[facei + sizeby2] = iF[faceCells[facei]];
176     }
178     return tpnf;
182 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
184 } // End namespace Foam
186 // ************************************************************************* //