1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
7 -------------------------------------------------------------------------------
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
13 the Free Software Foundation, either version 3 of the License, or
14 (at your 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
21 You should have received a copy of the GNU General Public License
22 along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
24 \*---------------------------------------------------------------------------*/
26 #include "cyclicPointPatchField.H"
28 #include "transformField.H"
29 #include "pointFields.H"
31 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
34 Foam::cyclicPointPatchField<Type>::cyclicPointPatchField
37 const DimensionedField<Type, pointMesh>& iF
40 coupledPointPatchField<Type>(p, iF),
41 cyclicPatch_(refCast<const cyclicPointPatch>(p))
46 Foam::cyclicPointPatchField<Type>::cyclicPointPatchField
49 const DimensionedField<Type, pointMesh>& iF,
50 const dictionary& dict
53 coupledPointPatchField<Type>(p, iF, dict),
54 cyclicPatch_(refCast<const cyclicPointPatch>(p))
56 if (!isType<cyclicPointPatch>(p))
60 "cyclicPointPatchField<Type>::cyclicPointPatchField\n"
62 " const pointPatch& p,\n"
63 " const Field<Type>& field,\n"
64 " const dictionary& dict\n"
67 ) << "patch " << this->patch().index() << " not cyclic type. "
68 << "Patch type = " << p.type()
69 << exit(FatalIOError);
75 Foam::cyclicPointPatchField<Type>::cyclicPointPatchField
77 const cyclicPointPatchField<Type>& ptf,
79 const DimensionedField<Type, pointMesh>& iF,
80 const pointPatchFieldMapper& mapper
83 coupledPointPatchField<Type>(ptf, p, iF, mapper),
84 cyclicPatch_(refCast<const cyclicPointPatch>(p))
86 if (!isType<cyclicPointPatch>(this->patch()))
90 "cyclicPointPatchField<Type>::cyclicPointPatchField\n"
92 " const cyclicPointPatchField<Type>& ptf,\n"
93 " const pointPatch& p,\n"
94 " const DimensionedField<Type, pointMesh>& iF,\n"
95 " const pointPatchFieldMapper& mapper\n"
97 ) << "Field type does not correspond to patch type for patch "
98 << this->patch().index() << "." << endl
99 << "Field type: " << typeName << endl
100 << "Patch type: " << this->patch().type()
107 Foam::cyclicPointPatchField<Type>::cyclicPointPatchField
109 const cyclicPointPatchField<Type>& ptf,
110 const DimensionedField<Type, pointMesh>& iF
113 coupledPointPatchField<Type>(ptf, iF),
114 cyclicPatch_(ptf.cyclicPatch_)
118 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
121 void Foam::cyclicPointPatchField<Type>::swapAddSeparated
123 const Pstream::commsTypes,
127 // Get neighbouring pointPatch
128 const cyclicPointPatch& nbrPatch = cyclicPatch_.neighbPatch();
130 if (cyclicPatch_.cyclicPatch().owner())
132 // We inplace modify pField. To prevent the other side (which gets
133 // evaluated at a later date) using already changed values we do
134 // all swaps on the side that gets evaluated first.
136 // Get neighbouring pointPatchField
137 const GeometricField<Type, pointPatchField, pointMesh>& fld =
138 refCast<const GeometricField<Type, pointPatchField, pointMesh> >
140 this->dimensionedInternalField()
143 const cyclicPointPatchField<Type>& nbr =
144 refCast<const cyclicPointPatchField<Type> >
146 fld.boundaryField()[nbrPatch.index()]
150 Field<Type> pf(this->patchInternalField(pField));
151 Field<Type> nbrPf(nbr.patchInternalField(pField));
153 const edgeList& pairs = cyclicPatch_.transformPairs();
157 // Transform both sides.
160 label pointi = pairs[pairi][0];
161 label nbrPointi = pairs[pairi][1];
163 Type tmp = pf[pointi];
164 pf[pointi] = transform(forwardT()[0], nbrPf[nbrPointi]);
165 nbrPf[nbrPointi] = transform(reverseT()[0], tmp);
172 Swap(pf[pairs[pairi][0]], nbrPf[pairs[pairi][1]]);
175 this->addToInternalField(pField, pf);
176 nbr.addToInternalField(pField, nbrPf);
181 // ************************************************************************* //