fixed writing out entries in advective bc
[OpenFOAM-1.6-ext.git] / src / finiteVolume / fvMesh / fvMeshMapper / fvPatchMapper.C
blobd05b82c196be5207efed800f1b24f5f660ec7cea
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright held by original author
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 "fvPatchMapper.H"
28 #include "fvPatch.H"
29 #include "fvBoundaryMesh.H"
30 #include "fvMesh.H"
31 #include "mapPolyMesh.H"
32 #include "faceMapper.H"
34 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
36 void Foam::fvPatchMapper::calcAddressing() const
38     if
39     (
40         directAddrPtr_
41      || interpolationAddrPtr_
42      || weightsPtr_
43     )
44     {
45         FatalErrorIn
46         (
47             "void fvPatchMapper::calcAddressing() const)"
48         )   << "Addressing already calculated"
49             << abort(FatalError);
50     }
52     // Mapping
53     const label oldPatchStart =
54         faceMap_.oldPatchStarts()[patch_.index()];
56     const label oldPatchEnd =
57         oldPatchStart + faceMap_.oldPatchSizes()[patch_.index()];
59     // Assemble the maps: slice to patch
60     if (direct())
61     {
62         // Direct mapping - slice to size
63         directAddrPtr_ = new labelList
64         (
65             patch_.patchSlice
66             (
67                 static_cast<const labelList&>(faceMap_.directAddressing())
68             )
69         );
70         labelList& addr = *directAddrPtr_;
72         // Adjust mapping to manage hits into other patches and into
73         // internal
74         forAll (addr, faceI)
75         {
76             if
77             (
78                 addr[faceI] >= oldPatchStart
79              && addr[faceI] < oldPatchEnd
80             )
81             {
82                 addr[faceI] -= oldPatchStart;
83             }
84             else
85             {
86                 addr[faceI] = 0;
87             }
88         }
90         if (fvMesh::debug)
91         {
92             if (addr.size() > 0 && min(addr) < 0)
93             {
94                 FatalErrorIn
95                 (
96                     "void fvPatchMapper::calcAddressing() const"
97                 )   << "Error in patch mapping for patch "
98                     << patch_.index() << " named " << patch_.name()
99                     << abort(FatalError);
100             }
101         }
102     }
103     else
104     {
105         // Interpolative mapping
106         interpolationAddrPtr_ =
107             new labelListList
108             (
109                 patch_.patchSlice(faceMap_.addressing())
110             );
111         labelListList& addr = *interpolationAddrPtr_;
113         weightsPtr_ =
114             new scalarListList
115             (
116                 patch_.patchSlice(faceMap_.weights())
117             );
118         scalarListList& w = *weightsPtr_;
120         // Adjust mapping to manage hits into other patches and into
121         // internal
122         forAll (addr, faceI)
123         {
124             labelList& curAddr = addr[faceI];
125             scalarList& curW = w[faceI];
127             if
128             (
129                 min(curAddr) >= oldPatchStart
130              && max(curAddr) < oldPatchEnd
131             )
132             {
133                 // No adjustment of weights, just subtract patch start
134                 forAll (curAddr, i)
135                 {
136                     curAddr[i] -= oldPatchStart;
137                 }
138             }
139             else
140             {
141                 // Need to recalculate weights to exclude hits into internal
142                 labelList newAddr(curAddr.size(), false);
143                 scalarField newWeights(curAddr.size());
144                 label nActive = 0;
146                 forAll (curAddr, lfI)
147                 {
148                     if
149                     (
150                         curAddr[lfI] >= oldPatchStart
151                      && curAddr[lfI] < oldPatchEnd
152                     )
153                     {
154                         newAddr[nActive] = curAddr[lfI] - oldPatchStart;
155                         newWeights[nActive] = curW[lfI];
156                         nActive++;
157                     }
158                 }
160                 // Cater for bad mapping
161                 if (nActive == 0)
162                 {
163                     newAddr[nActive] = 0;
164                     newWeights[nActive] = 1;
165                     nActive++;
166                 }
168                 newAddr.setSize(nActive);
169                 newWeights.setSize(nActive);
171                 // Re-scale the weights
172                 newWeights /= sum(newWeights);
174                 // Reset addressing and weights
175                 curAddr = newAddr;
176                 curW = newWeights;
177             }
178         }
180         if (fvMesh::debug)
181         {
182             forAll (addr, faceI)
183             {
184                 if (min(addr[faceI]) < 0)
185                 {
186                     FatalErrorIn
187                     (
188                         "void fvPatchMapper::calcAddressing() const"
189                     )   << "Error in patch mapping for patch "
190                         << patch_.index() << " named " << patch_.name()
191                         << " face " << faceI
192                         << abort(FatalError);
193                 }
194             }
195         }
196     }
200 void Foam::fvPatchMapper::clearOut()
202     deleteDemandDrivenData(directAddrPtr_);
203     deleteDemandDrivenData(interpolationAddrPtr_);
204     deleteDemandDrivenData(weightsPtr_);
208 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
210 // Construct from components
211 Foam::fvPatchMapper::fvPatchMapper
213     const fvPatch& patch,
214     const faceMapper& faceMap
217     patch_(patch),
218     faceMap_(faceMap),
219     sizeBeforeMapping_(faceMap.oldPatchSizes()[patch_.index()]),
220     directPtr_(NULL),
221     directAddrPtr_(NULL),
222     interpolationAddrPtr_(NULL),
223     weightsPtr_(NULL)
227 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
229 Foam::fvPatchMapper::~fvPatchMapper()
231     clearOut();
235 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
237 const Foam::unallocLabelList& Foam::fvPatchMapper::directAddressing() const
239     if (!direct())
240     {
241         FatalErrorIn
242         (
243             "const unallocLabelList& fvPatchMapper::directAddressing() const"
244         )   << "Requested direct addressing for an interpolative mapper."
245             << abort(FatalError);
246     }
248     if (!directAddrPtr_)
249     {
250         calcAddressing();
251     }
253     return *directAddrPtr_;
257 const Foam::labelListList& Foam::fvPatchMapper::addressing() const
259     if (direct())
260     {
261         FatalErrorIn
262         (
263             "const labelListList& fvPatchMapper::addressing() const"
264         )   << "Requested interpolative addressing for a direct mapper."
265             << abort(FatalError);
266     }
268     if (!interpolationAddrPtr_)
269     {
270         calcAddressing();
271     }
273     return *interpolationAddrPtr_;
277 const Foam::scalarListList& Foam::fvPatchMapper::weights() const
279     if (direct())
280     {
281         FatalErrorIn
282         (
283             "const scalarListList& fvPatchMapper::weights() const"
284         )   << "Requested interpolative weights for a direct mapper."
285             << abort(FatalError);
286     }
288     if (!weightsPtr_)
289     {
290         calcAddressing();
291     }
293     return *weightsPtr_;
297 // * * * * * * * * * * * * * * * Member Operators  * * * * * * * * * * * * * //
300 // * * * * * * * * * * * * * * * Friend Functions  * * * * * * * * * * * * * //
303 // * * * * * * * * * * * * * * * Friend Operators  * * * * * * * * * * * * * //
306 // ************************************************************************* //