Merge branch 'master' of ssh://git.code.sf.net/p/foam-extend/foam-extend-3.2
[foam-extend-3.2.git] / src / dynamicMesh / dynamicTopoFvMesh / eMesh / eMeshDemandDrivenData.C
blob96595cd43daf08a1a4edb58cf00e65670ea2dfa4
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 Description
26     Demand-driven edge mesh data
28 \*---------------------------------------------------------------------------*/
30 #include "eMesh.H"
32 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
34 namespace Foam
37 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
39 //- Calculate ordered edges
40 void eMesh::calcOrderedEdgeList()
42     if (debug)
43     {
44         Info<< "void eMesh::calcOrderedEdges() const : "
45             << "Calculating ordered edges" << endl;
46     }
48     if (edges_.size() || boundary_.size())
49     {
50         FatalErrorIn
51         (
52             "void eMesh::calcOrderedEdges() const"
53         )   << "Ordered edges already allocated."
54             << abort(FatalError);
55     }
57     // Set size first.
58     nEdges_ = mesh_.nEdges();
59     nInternalEdges_ = 0;
60     boundary_.setSize(mesh_.boundaryMesh().size());
62     // Allocate lists for re-ordering
63     labelList edgePatch(nEdges_, -1);
64     labelList edgePatchStarts(mesh_.boundaryMesh().size(), -1);
65     labelList edgePatchSizes(mesh_.boundaryMesh().size(), 0);
67     reverseEdgeMap_.setSize(nEdges_);
69     // Obtain connectivity from primitive mesh
70     const edgeList& edges = mesh_.edges();
71     const labelListList& fEdges = mesh_.faceEdges();
73     // Edge-patches are the same as faces
74     for (label i = mesh_.nInternalFaces(); i < mesh_.nFaces(); i++)
75     {
76         const labelList& fEdge = fEdges[i];
78         forAll(fEdge, edgeI)
79         {
80             edgePatch[fEdge[edgeI]] = mesh_.boundaryMesh().whichPatch(i);
81         }
82     }
84     // Loop through edgePatch and renumber internal edges
85     forAll(edgePatch, edgeI)
86     {
87         if (edgePatch[edgeI] == -1)
88         {
89             reverseEdgeMap_[edgeI] = nInternalEdges_++;
90         }
91         else
92         {
93             edgePatchSizes[edgePatch[edgeI]]++;
94         }
95     }
97     // Calculate patch-starts
98     label startCount = nInternalEdges_;
100     forAll(edgePatchStarts, patchI)
101     {
102         edgePatchStarts[patchI] = startCount;
103         startCount += edgePatchSizes[patchI];
104     }
106     // Now renumber boundary edges
107     labelList patchCount(edgePatchStarts);
109     forAll(edgePatch, edgeI)
110     {
111         if (edgePatch[edgeI] > -1)
112         {
113             reverseEdgeMap_[edgeI] = patchCount[edgePatch[edgeI]]++;
114         }
115     }
117     // Renumber and fill in edges
118     edges_.setSize(nEdges_, edge(-1,-1));
120     forAll(edges, edgeI)
121     {
122         edges_[reverseEdgeMap_[edgeI]] = edges[edgeI];
123     }
125     // Now set the boundary, copy name. (type is default)
126     forAll(boundary_, patchI)
127     {
128         boundary_.set
129         (
130             patchI,
131             ePatch::New
132             (
133                 ePatch::typeName_(),
134                 mesh_.boundaryMesh()[patchI].name(),
135                 edgePatchSizes[patchI],
136                 edgePatchStarts[patchI],
137                 patchI,
138                 boundary_
139             )
140         );
141     }
143     // Force calculation of other data...
144     calcEdgeFaces();
145     calcFaceEdges();
149 void eMesh::calcFaceEdges() const
151     if (debug)
152     {
153         Info<< "void eMesh::calcFaceEdges() const : "
154             << "Calculating FaceEdges" << endl;
155     }
157     if (fePtr_)
158     {
159         FatalErrorIn
160         (
161             "void eMesh::calcFaceEdges() const"
162         )   << "fePtr_ already allocated"
163             << abort(FatalError);
164     }
166     fePtr_ =
167     (
168         new labelListIOList
169         (
170             IOobject
171             (
172                 "faceEdges",
173                 mesh_.facesInstance(),
174                 meshSubDir,
175                 mesh_,
176                 IOobject::READ_IF_PRESENT,
177                 IOobject::NO_WRITE
178             ),
179             mesh_.nFaces()
180         )
181     );
183     labelListIOList& faceEdges = *fePtr_;
185     // If the read was successful, return.
186     if (faceEdges.headerOk())
187     {
188         return;
189     }
191     // If edgeFaces exists, use that.
192     if (efPtr_)
193     {
194         invertManyToMany(mesh_.nFaces(), edgeFaces(), faceEdges);
195     }
196     else
197     {
198         FatalErrorIn
199         (
200             "void eMesh::calcFaceEdges() const"
201         )   << "Cannot calculate faceEdges."
202             << abort(FatalError);
203     }
206 void eMesh::calcEdgeFaces() const
208     if (debug)
209     {
210         Info<< "void eMesh::calcEdgeFaces() const : "
211             << "Calculating EdgeFaces" << endl;
212     }
214     if (efPtr_)
215     {
216         FatalErrorIn
217         (
218             "void eMesh::calcEdgeFaces() const"
219         )   << "efPtr_ already allocated."
220             << abort(FatalError);
221     }
223     efPtr_ =
224     (
225         new labelListIOList
226         (
227             IOobject
228             (
229                 "edgeFaces",
230                 mesh_.facesInstance(),
231                 meshSubDir,
232                 mesh_,
233                 IOobject::READ_IF_PRESENT,
234                 IOobject::NO_WRITE
235             ),
236             nEdges_
237         )
238     );
240     labelListIOList& edgeFaces = *efPtr_;
242     // If the read was successful, return.
243     if (edgeFaces.headerOk())
244     {
245         return;
246     }
248     if (fePtr_)
249     {
250         // If faceEdges exists, use that.
251         invertManyToMany(nEdges_, faceEdges(), edgeFaces);
252     }
253     else
254     {
255         // Obtain connectivity from primitive mesh.
256         if (!reverseEdgeMap_.size())
257         {
258             FatalErrorIn
259             (
260                 "void eMesh::calcEdgeFaces() const"
261             )   << "reverseEdgeMap has not been allocated."
262                 << abort(FatalError);
263         }
265         const labelListList& eFaces = mesh_.edgeFaces();
267         forAll(eFaces, edgeI)
268         {
269             edgeFaces[reverseEdgeMap_[edgeI]] = eFaces[edgeI];
270         }
271     }
275 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
277 } // End namespace Foam
279 // ************************************************************************* //