Merge branch 'master' of ssh://git.code.sf.net/p/foam-extend/foam-extend-3.2
[foam-extend-3.2.git] / src / foam / meshes / polyMesh / polyPatches / basic / coupled / coupledPolyPatch.C
blob132867f62f198f4db9f98913100453ef44c0365f
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | foam-extend: Open Source CFD
4    \\    /   O peration     | Version:     3.2
5     \\  /    A nd           | Web:         http://www.foam-extend.org
6      \\/     M anipulation  | For copyright notice see file Copyright
7 -------------------------------------------------------------------------------
8 License
9     This file is part of foam-extend.
11     foam-extend 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 3 of the License, or (at your
14     option) any later version.
16     foam-extend is distributed in the hope that it will be useful, but
17     WITHOUT ANY WARRANTY; without even the implied warranty of
18     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
19     General Public License for more details.
21     You should have received a copy of the GNU General Public License
22     along with foam-extend.  If not, see <http://www.gnu.org/licenses/>.
24 \*---------------------------------------------------------------------------*/
26 #include "coupledPolyPatch.H"
27 #include "ListOps.H"
28 #include "transform.H"
29 #include "OFstream.H"
31 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
33 defineTypeNameAndDebug(Foam::coupledPolyPatch, 0);
36 // * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * * //
38 void Foam::coupledPolyPatch::calcTransformTensors
40     const vectorField& Cf,
41     const vectorField& Cr,
42     const vectorField& nf,
43     const vectorField& nr,
44     const scalarField& smallDist,
45     const scalar absTol
46 ) const
48     if (debug)
49     {
50         Pout<< "coupledPolyPatch::calcTransformTensors : " << name() << endl
51             << "    (half)size:" << Cf.size() << nl
52             << "    absTol:" << absTol << nl
53             << "    sum(mag(nf & nr)):" << sum(mag(nf & nr)) << endl;
54     }
56     // Tolerance calculation.
57     // - normal calculation: assume absTol is the absolute error in a
58     // single normal/transformation calculation. Consists both of numerical
59     // precision (on the order of SMALL and of writing precision
60     // (from e.g. decomposition)
61     // Then the overall error of summing the normals is sqrt(size())*absTol
62     // - separation calculation: pass in from the outside an allowable error.
64     if (size() == 0)
65     {
66         // Dummy geometry.
67         separation_.setSize(0);
68         forwardT_ = I;
69         reverseT_ = I;
70     }
71     else
72     {
73         scalar error = absTol*Foam::sqrt(1.0*Cf.size());
75         if (debug)
76         {
77             Pout<< "    error:" << error << endl;
78         }
80         if (sum(mag(nf & nr)) < Cf.size() - error)
81         {
82             // Rotation, no separation
84             separation_.setSize(0);
86             forwardT_.setSize(Cf.size());
87             reverseT_.setSize(Cf.size());
89             forAll (forwardT_, facei)
90             {
91                 forwardT_[facei] = rotationTensor(-nr[facei], nf[facei]);
92                 reverseT_[facei] = rotationTensor(nf[facei], -nr[facei]);
93             }
95             if (debug)
96             {
97                 Pout<< "    sum(mag(forwardT_ - forwardT_[0])):"
98                     << sum(mag(forwardT_ - forwardT_[0]))
99                     << endl;
100             }
102             if (sum(mag(forwardT_ - forwardT_[0])) < error)
103             {
104                 forwardT_.setSize(1);
105                 reverseT_.setSize(1);
107                 if (debug)
108                 {
109                     Pout<< "    difference in rotation less than"
110                         << " local tolerance "
111                         << error << ". Assuming uniform rotation." << endl;
112                 }
113             }
114         }
115         else
116         {
117             forwardT_.setSize(0);
118             reverseT_.setSize(0);
120             separation_ = (nf & (Cr - Cf))*nf;
122             // Three situations:
123             // - separation is zero. No separation.
124             // - separation is same. Single separation vector.
125             // - separation differs per face. Separation vectorField.
127             // Check for different separation per face
128             bool sameSeparation = true;
130             forAll(separation_, facei)
131             {
132                 scalar smallSqr = sqr(smallDist[facei]);
134                 if (magSqr(separation_[facei] - separation_[0]) > smallSqr)
135                 {
136                     if (debug)
137                     {
138                         Pout<< "    separation " << separation_[facei]
139                             << " at " << facei
140                             << " differs from separation[0] " << separation_[0]
141                             << " by more than local tolerance "
142                             << smallDist[facei]
143                             << ". Assuming non-uniform separation." << endl;
144                     }
145                     sameSeparation = false;
146                     break;
147                 }
148             }
150             if (sameSeparation)
151             {
152                 // Check for zero separation (at 0 so everywhere)
153                 if (magSqr(separation_[0]) < sqr(smallDist[0]))
154                 {
155                     if (debug)
156                     {
157                         Pout<< "    separation " << mag(separation_[0])
158                             << " less than local tolerance " << smallDist[0]
159                             << ". Assuming zero separation." << endl;
160                     }
162                     separation_.setSize(0);
163                 }
164                 else
165                 {
166                     if (debug)
167                     {
168                         Pout<< "    separation " << mag(separation_[0])
169                             << " more than local tolerance " << smallDist[0]
170                             << ". Assuming uniform separation." << endl;
171                     }
173                     separation_.setSize(1);
174                 }
175             }
176         }
177     }
179     if (debug)
180     {
181         Pout<< "    separation_:" << separation_.size() << nl
182             << "    forwardT size:" << forwardT_.size() << endl;
183     }
187 // * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * * * * * //
189 Foam::coupledPolyPatch::coupledPolyPatch
191     const word& name,
192     const label size,
193     const label start,
194     const label index,
195     const polyBoundaryMesh& bm
198     polyPatch(name, size, start, index, bm)
202 Foam::coupledPolyPatch::coupledPolyPatch
204     const word& name,
205     const dictionary& dict,
206     const label index,
207     const polyBoundaryMesh& bm
210     polyPatch(name, dict, index, bm)
214 Foam::coupledPolyPatch::coupledPolyPatch
216     const coupledPolyPatch& pp,
217     const polyBoundaryMesh& bm
220     polyPatch(pp, bm)
224 Foam::coupledPolyPatch::coupledPolyPatch
226     const coupledPolyPatch& pp,
227     const polyBoundaryMesh& bm,
228     const label index,
229     const label newSize,
230     const label newStart
233     polyPatch(pp, bm, index, newSize, newStart)
237 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
239 Foam::coupledPolyPatch::~coupledPolyPatch()
243 // ************************************************************************* //