FreeFOAM The Cross-Platform CFD Toolkit
cyclicFvPatchField.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | Copyright (C) 1991-2010 OpenCFD Ltd.
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
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.
15 
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.
20 
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/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
27 
28 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
29 
30 namespace Foam
31 {
32 
33 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
34 
35 template<class Type>
37 (
38  const fvPatch& p,
40 )
41 :
43  cyclicPatch_(refCast<const cyclicFvPatch>(p))
44 {}
45 
46 
47 template<class Type>
49 (
50  const cyclicFvPatchField<Type>& ptf,
51  const fvPatch& p,
53  const fvPatchFieldMapper& mapper
54 )
55 :
56  coupledFvPatchField<Type>(ptf, p, iF, mapper),
57  cyclicPatch_(refCast<const cyclicFvPatch>(p))
58 {
59  if (!isType<cyclicFvPatch>(this->patch()))
60  {
62  (
63  "cyclicFvPatchField<Type>::cyclicFvPatchField\n"
64  "(\n"
65  " const cyclicFvPatchField<Type>& ptf,\n"
66  " const fvPatch& p,\n"
67  " const DimensionedField<Type, volMesh>& iF,\n"
68  " const fvPatchFieldMapper& mapper\n"
69  ")\n"
70  ) << "\n patch type '" << p.type()
71  << "' not constraint type '" << typeName << "'"
72  << "\n for patch " << p.name()
73  << " of field " << this->dimensionedInternalField().name()
74  << " in file " << this->dimensionedInternalField().objectPath()
75  << exit(FatalIOError);
76  }
77 }
78 
79 
80 template<class Type>
82 (
83  const fvPatch& p,
85  const dictionary& dict
86 )
87 :
88  coupledFvPatchField<Type>(p, iF, dict),
89  cyclicPatch_(refCast<const cyclicFvPatch>(p))
90 {
91  if (!isType<cyclicFvPatch>(p))
92  {
94  (
95  "cyclicFvPatchField<Type>::cyclicFvPatchField\n"
96  "(\n"
97  " const fvPatch& p,\n"
98  " const Field<Type>& field,\n"
99  " const dictionary& dict\n"
100  ")\n",
101  dict
102  ) << "\n patch type '" << p.type()
103  << "' not constraint type '" << typeName << "'"
104  << "\n for patch " << p.name()
105  << " of field " << this->dimensionedInternalField().name()
106  << " in file " << this->dimensionedInternalField().objectPath()
107  << exit(FatalIOError);
108  }
109 
110  this->evaluate(Pstream::blocking);
111 }
112 
113 
114 template<class Type>
116 (
117  const cyclicFvPatchField<Type>& ptf
118 )
119 :
122  cyclicPatch_(ptf.cyclicPatch_)
123 {}
124 
125 
126 template<class Type>
128 (
129  const cyclicFvPatchField<Type>& ptf,
131 )
132 :
133  coupledFvPatchField<Type>(ptf, iF),
134  cyclicPatch_(ptf.cyclicPatch_)
135 {}
136 
137 
138 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
139 
140 template<class Type>
142 {
143  const Field<Type>& iField = this->internalField();
144  const unallocLabelList& faceCells = cyclicPatch_.faceCells();
145 
146  tmp<Field<Type> > tpnf(new Field<Type>(this->size()));
147  Field<Type>& pnf = tpnf();
148 
149  label sizeby2 = this->size()/2;
150 
151  if (doTransform())
152  {
153  for (label facei=0; facei<sizeby2; facei++)
154  {
155  pnf[facei] = transform
156  (
157  forwardT()[0], iField[faceCells[facei + sizeby2]]
158  );
159 
160  pnf[facei + sizeby2] = transform
161  (
162  reverseT()[0], iField[faceCells[facei]]
163  );
164  }
165  }
166  else
167  {
168  for (label facei=0; facei<sizeby2; facei++)
169  {
170  pnf[facei] = iField[faceCells[facei + sizeby2]];
171  pnf[facei + sizeby2] = iField[faceCells[facei]];
172  }
173  }
174 
175  return tpnf;
176 }
177 
178 
179 template<class Type>
181 (
182  const scalarField& psiInternal,
183  scalarField& result,
184  const lduMatrix&,
185  const scalarField& coeffs,
186  const direction cmpt,
187  const Pstream::commsTypes
188 ) const
189 {
190  scalarField pnf(this->size());
191 
192  label sizeby2 = this->size()/2;
193  const unallocLabelList& faceCells = cyclicPatch_.faceCells();
194 
195  for (label facei=0; facei<sizeby2; facei++)
196  {
197  pnf[facei] = psiInternal[faceCells[facei + sizeby2]];
198  pnf[facei + sizeby2] = psiInternal[faceCells[facei]];
199  }
200 
201  // Transform according to the transformation tensors
202  transformCoupleField(pnf, cmpt);
203 
204  // Multiply the field by coefficients and add into the result
205  forAll(faceCells, elemI)
206  {
207  result[faceCells[elemI]] -= coeffs[elemI]*pnf[elemI];
208  }
209 }
210 
211 
212 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
213 
214 } // End namespace Foam
215 
216 // ************************ vim: set sw=4 sts=4 et: ************************ //