initial commit for version 1.5.x patch release
[OpenFOAM-1.5.x.git] / src / OpenFOAM / meshes / pointMesh / pointMeshMapper / pointPatchMapper.C
blob288bd4de4f9b34ca1302335a4a1d630d5cedf56e
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 1991-2008 OpenCFD Ltd.
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 "pointPatchMapper.H"
28 #include "pointPatch.H"
29 #include "mapPolyMesh.H"
30 #include "faceMapper.H"
31 #include "demandDrivenData.H"
33 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
35 void Foam::pointPatchMapper::calcAddressing() const
37     if
38     (
39         directAddrPtr_
40      || interpolationAddrPtr_
41      || weightsPtr_
42     )
43     {
44         FatalErrorIn
45         (
46             "void pointPatchMapper::calcAddressing() const"
47         )   << "Addressing already calculated"
48             << abort(FatalError);
49     }
51     if (direct())
52     {
53         // Direct mapping.
54         directAddrPtr_ = new labelList(mpm_.patchPointMap()[patch_.index()]);
55         labelList& addr = *directAddrPtr_;
57         forAll(addr, i)
58         {
59             if (addr[i] < 0)
60             {
61                 addr[i] = 0;
62             }
63         }
64     }
65     else
66     {
67         // Interpolative mapping.
69         // NOTE: Incorrect:
70         // FOR NOW only takes first patch point instead of averaging all
71         // patch points. Problem is we don't know what points were in the patch
72         // for points that were merged.
74         interpolationAddrPtr_ = new labelListList(size());
75         labelListList& addr = *interpolationAddrPtr_;
77         weightsPtr_ = new scalarListList(addr.size());
78         scalarListList& w = *weightsPtr_;
80         const labelList& ppm = mpm_.patchPointMap()[patch_.index()];
82         forAll(ppm, i)
83         {
84             if (ppm[i] >= 0)
85             {
86                 addr[i] = labelList(1, ppm[i]);
87                 w[i] = scalarList(1, 1.0);
88             }
89             else
90             {
91                 // Inserted point. Map from point0 (arbitrary choice)
92                 addr[i] = labelList(1, 0);
93                 w[i] = scalarList(1, 1.0);
94             }
95         }
96     }
100 void Foam::pointPatchMapper::clearOut()
102     deleteDemandDrivenData(directAddrPtr_);
103     deleteDemandDrivenData(interpolationAddrPtr_);
104     deleteDemandDrivenData(weightsPtr_);
108 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
110 // Construct from components
111 Foam::pointPatchMapper::pointPatchMapper
113     const pointPatch& patch,
114     const pointMapper& pointMap,
115     const mapPolyMesh& mpm
118     pointPatchFieldMapper(),
119     patch_(patch),
120     pointMapper_(pointMap),
121     mpm_(mpm),
122     sizeBeforeMapping_
123     (
124         patch_.index() < mpm_.oldPatchNMeshPoints().size()
125       ? mpm_.oldPatchNMeshPoints()[patch_.index()]
126       : 0
127     ),
128     directAddrPtr_(NULL),
129     interpolationAddrPtr_(NULL),
130     weightsPtr_(NULL)
134 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
136 Foam::pointPatchMapper::~pointPatchMapper()
138     clearOut();
142 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
144 const Foam::unallocLabelList& Foam::pointPatchMapper::directAddressing() const
146     if (!direct())
147     {
148         FatalErrorIn
149         (
150             "const unallocLabelList& pointPatchMapper::directAddressing() const"
151         )   << "Requested direct addressing for an interpolative mapper."
152             << abort(FatalError);
153     }
155     if (!directAddrPtr_)
156     {
157         calcAddressing();
158     }
160     return *directAddrPtr_;
164 const Foam::labelListList& Foam::pointPatchMapper::addressing() const
166     if (direct())
167     {
168         FatalErrorIn
169         (
170             "const labelListList& pointPatchMapper::addressing() const"
171         )   << "Requested interpolative addressing for a direct mapper."
172             << abort(FatalError);
173     }
175     if (!interpolationAddrPtr_)
176     {
177         calcAddressing();
178     }
180     return *interpolationAddrPtr_;
184 const Foam::scalarListList& Foam::pointPatchMapper::weights() const
186     if (direct())
187     {
188         FatalErrorIn
189         (
190             "const scalarListList& pointPatchMapper::weights() const"
191         )   << "Requested interpolative weights for a direct mapper."
192             << abort(FatalError);
193     }
195     if (!weightsPtr_)
196     {
197         calcAddressing();
198     }
200     return *weightsPtr_;
204 // * * * * * * * * * * * * * * * Member Operators  * * * * * * * * * * * * * //
207 // * * * * * * * * * * * * * * * Friend Functions  * * * * * * * * * * * * * //
210 // * * * * * * * * * * * * * * * Friend Operators  * * * * * * * * * * * * * //
213 // ************************************************************************* //