initial commit for version 1.6.x patch release
[OpenFOAM-1.6.x.git] / src / dynamicMesh / slidingInterface / enrichedPatch / enrichedPatch.C
blobeb191b3f0f124bfd971fa91d9e6e3bcb5fb6bf4a
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 1991-2009 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 Description
27 \*---------------------------------------------------------------------------*/
29 #include "enrichedPatch.H"
30 #include "demandDrivenData.H"
31 #include "OFstream.H"
32 #include "meshTools.H"
34 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
36 namespace Foam
38     defineTypeNameAndDebug(enrichedPatch, 0);
42 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
44 void Foam::enrichedPatch::calcMeshPoints() const
46     if (meshPointsPtr_)
47     {
48         FatalErrorIn("void enrichedPatch::calcMeshPoints() const")
49             << "Mesh points already calculated."
50             << abort(FatalError);
51     }
53     meshPointsPtr_ = new labelList(pointMap().toc());
54     labelList& mp = *meshPointsPtr_;
56     sort(mp);
60 void Foam::enrichedPatch::calcLocalFaces() const
62     if (localFacesPtr_)
63     {
64         FatalErrorIn("void enrichedPatch::calcLocalFaces() const")
65             << "Local faces already calculated."
66             << abort(FatalError);
67     }
69     // Invert mesh points and renumber faces using it
70     const labelList& mp = meshPoints();
72     Map<label> mpLookup(2*mp.size());
74     forAll (mp, mpI)
75     {
76         mpLookup.insert(mp[mpI], mpI);
77     }
79     const faceList& faces = enrichedFaces();
81     localFacesPtr_ = new faceList(faces.size());
82     faceList& lf = *localFacesPtr_;
84     forAll (faces, faceI)
85     {
86         const face& f = faces[faceI];
88         face& curlf = lf[faceI];
90         curlf.setSize(f.size());
92         forAll (f, pointI)
93         {
94             curlf[pointI] = mpLookup.find(f[pointI])();
95         }
96     }
100 void Foam::enrichedPatch::calcLocalPoints() const
102     if (localPointsPtr_)
103     {
104         FatalErrorIn("void enrichedPatch::calcLocalPoints() const")
105             << "Local points already calculated."
106             << abort(FatalError);
107     }
109     const labelList& mp = meshPoints();
111     localPointsPtr_ = new pointField(mp.size());
112     pointField& lp = *localPointsPtr_;
114     forAll (lp, i)
115     {
116         lp[i] = pointMap().find(mp[i])();
117     }
121 void Foam::enrichedPatch::clearOut()
123     deleteDemandDrivenData(enrichedFacesPtr_);
125     deleteDemandDrivenData(meshPointsPtr_);
126     deleteDemandDrivenData(localFacesPtr_);
127     deleteDemandDrivenData(localPointsPtr_);
128     deleteDemandDrivenData(pointPointsPtr_);
129     deleteDemandDrivenData(masterPointFacesPtr_);
131     clearCutFaces();
135 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
137 // Construct from components
138 Foam::enrichedPatch::enrichedPatch
140     const primitiveFacePatch& masterPatch,
141     const primitiveFacePatch& slavePatch,
142     const labelList& slavePointPointHits,
143     const labelList& slavePointEdgeHits,
144     const List<objectHit>& slavePointFaceHits
147     masterPatch_(masterPatch),
148     slavePatch_(slavePatch),
149     pointMap_
150     (
151         masterPatch_.meshPoints().size()
152       + slavePatch_.meshPoints().size()
153     ),
154     pointMapComplete_(false),
155     pointMergeMap_(2*slavePatch_.meshPoints().size()),
156     slavePointPointHits_(slavePointPointHits),
157     slavePointEdgeHits_(slavePointEdgeHits),
158     slavePointFaceHits_(slavePointFaceHits),
159     enrichedFacesPtr_(NULL),
160     meshPointsPtr_(NULL),
161     localFacesPtr_(NULL),
162     localPointsPtr_(NULL),
163     pointPointsPtr_(NULL),
164     masterPointFacesPtr_(NULL),
165     cutFacesPtr_(NULL),
166     cutFaceMasterPtr_(NULL),
167     cutFaceSlavePtr_(NULL)
171 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
173 Foam::enrichedPatch::~enrichedPatch()
175     clearOut();
179 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
181 const Foam::labelList& Foam::enrichedPatch::meshPoints() const
183     if (!meshPointsPtr_)
184     {
185         calcMeshPoints();
186     }
188     return *meshPointsPtr_;
192 const Foam::faceList& Foam::enrichedPatch::localFaces() const
194     if (!localFacesPtr_)
195     {
196         calcLocalFaces();
197     }
199     return *localFacesPtr_;
203 const Foam::pointField& Foam::enrichedPatch::localPoints() const
205     if (!localPointsPtr_)
206     {
207         calcLocalPoints();
208     }
210     return *localPointsPtr_;
214 const Foam::labelListList& Foam::enrichedPatch::pointPoints() const
216     if (!pointPointsPtr_)
217     {
218         calcPointPoints();
219     }
221     return *pointPointsPtr_;
225 bool Foam::enrichedPatch::checkSupport() const
227     const faceList& faces = enrichedFaces();
229     bool error = false;
231     forAll (faces, faceI)
232     {
233         const face& curFace = faces[faceI];
235         forAll (curFace, pointI)
236         {
237             if (!pointMap().found(curFace[pointI]))
238             {
239                 WarningIn("void enrichedPatch::checkSupport()")
240                     << "Point " << pointI << " of face " << faceI
241                     << " global point index: " << curFace[pointI]
242                     << " not supported in point map.  This is not allowed."
243                     << endl;
245                 error = true;
246             }
247         }
248     }
250     return error;
254 void Foam::enrichedPatch::writeOBJ(const fileName& fName) const
256     OFstream str(fName);
258     const pointField& lp = localPoints();
260     forAll(lp, pointI)
261     {
262         meshTools::writeOBJ(str, lp[pointI]);
263     }
265     const faceList& faces = localFaces();
267     forAll(faces, faceI)
268     {
269         const face& f = faces[faceI];
271         str << 'f';
272         forAll(f, fp)
273         {
274             str << ' ' << f[fp]+1;
275         }
276         str << nl;
277     }
281 // * * * * * * * * * * * * * * * Member Operators  * * * * * * * * * * * * * //
284 // * * * * * * * * * * * * * * * Friend Functions  * * * * * * * * * * * * * //
287 // * * * * * * * * * * * * * * * Friend Operators  * * * * * * * * * * * * * //
290 // ************************************************************************* //