FreeFOAM The Cross-Platform CFD Toolkit
cyclicFvPatch.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 
26 #include "cyclicFvPatch.H"
28 #include <finiteVolume/fvMesh.H>
29 
30 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
31 
32 namespace Foam
33 {
34 
35 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
36 
37 defineTypeNameAndDebug(cyclicFvPatch, 0);
38 addToRunTimeSelectionTable(fvPatch, cyclicFvPatch, polyPatch);
39 
40 
41 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
42 
43 // Make patch weighting factors
45 {
46  const scalarField& magFa = magSf();
47 
48  scalarField deltas = nf() & fvPatch::delta();
49  label sizeby2 = deltas.size()/2;
50 
51  for (label facei = 0; facei < sizeby2; facei++)
52  {
53  scalar avFa = (magFa[facei] + magFa[facei + sizeby2])/2.0;
54 
55  if (mag(magFa[facei] - magFa[facei + sizeby2])/avFa > 1e-4)
56  {
57  FatalErrorIn("cyclicFvPatch::makeWeights(scalarField& w) const")
58  << "face " << facei << " and " << facei + sizeby2
59  << " areas do not match by "
60  << 100*mag(magFa[facei] - magFa[facei + sizeby2])/avFa
61  << "% -- possible face ordering problem"
62  << abort(FatalError);
63  }
64 
65  scalar di = deltas[facei];
66  scalar dni = deltas[facei + sizeby2];
67 
68  w[facei] = dni/(di + dni);
69  w[facei + sizeby2] = 1 - w[facei];
70  }
71 }
72 
73 
74 // Make patch face - neighbour cell distances
76 {
77  scalarField deltas = nf() & fvPatch::delta();
78  label sizeby2 = deltas.size()/2;
79 
80  for (label facei = 0; facei < sizeby2; facei++)
81  {
82  scalar di = deltas[facei];
83  scalar dni = deltas[facei + sizeby2];
84 
85  dc[facei] = 1.0/(di + dni);
86  dc[facei + sizeby2] = dc[facei];
87  }
88 }
89 
90 
91 // Return delta (P to N) vectors across coupled patch
93 {
94  vectorField patchD = fvPatch::delta();
95  label sizeby2 = patchD.size()/2;
96 
97  tmp<vectorField> tpdv(new vectorField(patchD.size()));
98  vectorField& pdv = tpdv();
99 
100  // To the transformation if necessary
101  if (parallel())
102  {
103  for (label facei = 0; facei < sizeby2; facei++)
104  {
105  vector ddi = patchD[facei];
106  vector dni = patchD[facei + sizeby2];
107 
108  pdv[facei] = ddi - dni;
109  pdv[facei + sizeby2] = -pdv[facei];
110  }
111  }
112  else
113  {
114  for (label facei = 0; facei < sizeby2; facei++)
115  {
116  vector ddi = patchD[facei];
117  vector dni = patchD[facei + sizeby2];
118 
119  pdv[facei] = ddi - transform(forwardT()[0], dni);
120  pdv[facei + sizeby2] = -transform(reverseT()[0], pdv[facei]);
121  }
122  }
123 
124  return tpdv;
125 }
126 
127 
129 (
130  const unallocLabelList& internalData
131 ) const
132 {
133  return patchInternalField(internalData);
134 }
135 
136 
138 (
139  const Pstream::commsTypes,
140  const unallocLabelList& interfaceData
141 ) const
142 {
143  tmp<labelField> tpnf(new labelField(this->size()));
144  labelField& pnf = tpnf();
145 
146  label sizeby2 = this->size()/2;
147 
148  for (label facei=0; facei<sizeby2; facei++)
149  {
150  pnf[facei] = interfaceData[facei + sizeby2];
151  pnf[facei + sizeby2] = interfaceData[facei];
152  }
153 
154  return tpnf;
155 }
156 
157 
159 (
160  const Pstream::commsTypes commsType,
161  const unallocLabelList& iF
162 ) const
163 {
164  const unallocLabelList& faceCells = this->patch().faceCells();
165 
166  tmp<labelField> tpnf(new labelField(this->size()));
167  labelField& pnf = tpnf();
168 
169  label sizeby2 = this->size()/2;
170 
171  for (label facei=0; facei<sizeby2; facei++)
172  {
173  pnf[facei] = iF[faceCells[facei + sizeby2]];
174  pnf[facei + sizeby2] = iF[faceCells[facei]];
175  }
176 
177  return tpnf;
178 }
179 
180 
181 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
182 
183 } // End namespace Foam
184 
185 // ************************ vim: set sw=4 sts=4 et: ************************ //