Forward compatibility: flex
[foam-extend-3.2.git] / src / dynamicMesh / dynamicTopoFvMesh / eMesh / eMesh.C
blob94fa41223212582f5d7e369921939c9c461fcf9b
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     Mesh needed to do edge-based addressing.
28 \*---------------------------------------------------------------------------*/
30 #include "eMesh.H"
31 #include "demandDrivenData.H"
33 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
35 namespace Foam
38 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
40 defineTypeNameAndDebug(eMesh, 0);
42 word eMesh::meshSubDir = "eMesh";
44 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
46 void eMesh::clearGeom() const
48     if (debug)
49     {
50         Info<< "void eMesh::clearGeom() const : "
51             << "Clearing geometry" << endl;
52     }
56 void eMesh::clearAddressing() const
58     if (debug)
59     {
60         Info<< "void eMesh::clearAddressing() const : "
61             << "Clearing addressing" << endl;
62     }
64     edges_.clear();
66     deleteDemandDrivenData(fePtr_);
67     deleteDemandDrivenData(efPtr_);
71 // Helper function to isolate points on triangular faces
72 label eMesh::findIsolatedPoint(const face& f, const edge& e) const
74     // Check the first point
75     if ( f[0] != e.start() && f[0] != e.end() )
76     {
77         return f[0];
78     }
80     // Check the second point
81     if ( f[1] != e.start() && f[1] != e.end() )
82     {
83         return f[1];
84     }
86     // Check the third point
87     if ( f[2] != e.start() && f[2] != e.end() )
88     {
89         return f[2];
90     }
92     return -1;
96 //- Helper function to determine the orientation of a triangular face
97 label eMesh::edgeDirection(const face& f, const edge& e) const
99     if
100     (
101         (f[0] == e.start() && f[1] == e.end())
102      || (f[1] == e.start() && f[2] == e.end())
103      || (f[2] == e.start() && f[0] == e.end())
104     )
105     {
106         // Return counter-clockwise
107         return 1;
108     }
109     else
110     {
111         // Return clockwise
112         return -1;
113     }
117 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
119 eMesh::eMesh(const polyMesh& pMesh, const word& subDir)
121     objectRegistry(pMesh.time()),
122     mesh_(pMesh),
123     edges_
124     (
125         IOobject
126         (
127             "edges",
128             mesh_.facesInstance(),
129             subDir,
130             mesh_,
131             IOobject::READ_IF_PRESENT,
132             IOobject::NO_WRITE
133         )
134     ),
135     boundary_
136     (
137         IOobject
138         (
139             "edgeBoundary",
140             mesh_.facesInstance(),
141             subDir,
142             mesh_,
143             IOobject::READ_IF_PRESENT,
144             IOobject::NO_WRITE
145         ),
146         *this
147     ),
148     fePtr_(NULL),
149     efPtr_(NULL)
151     if (debug)
152     {
153         Info << "eMesh::eMesh(const polyMesh&, const word&) : "
154              << "Creating eMesh from polyMesh"
155              << endl;
156     }
158     // Re-initialize / override meshSubDir
159     meshSubDir = subDir;
161     // Try to read from disk.
162     if (edges_.headerOk() && boundary_.headerOk())
163     {
164         // Set sizes
165         nEdges_ = edges_.size();
166         nInternalEdges_ = boundary_[0].start();
167     }
168     else
169     {
170         // Could not read ordered edges, so calculate it instead.
171         calcOrderedEdgeList();
172     }
176 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
178 eMesh::~eMesh()
180     clearOut();
183 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
185 fileName eMesh::meshDir() const
187     return mesh_.dbDir();
191 fileName eMesh::meshSubDirectory() const
193     return mesh_.dbDir()/meshSubDir;
197 const Time& eMesh::time() const
199     return mesh_.time();
203 label eMesh::nEdges() const
205     return nEdges_;
209 label eMesh::nInternalEdges() const
211     return nInternalEdges_;
215 const edgeList& eMesh::edges() const
217     return edges_;
221 void eMesh::addEdgePatches(const List<ePatch*>& p)
223     if (debug)
224     {
225         Info << "void eMesh::addEdgePatches(const List<ePatch*>& p) : "
226              << "Adding patches to eMesh" << endl;
227     }
229     if (boundary().size() > 0)
230     {
231         FatalErrorIn
232         (
233             "void eMesh::addEdgePatches(const List<ePatch*>& p)"
234         )
235             << "Boundary already exists"
236             << abort(FatalError);
237     }
239     boundary_.setSize(p.size());
241     forAll(p, patchI)
242     {
243         boundary_.set(patchI, p[patchI]);
244     }
248 const objectRegistry& eMesh::db() const
250     return mesh_.db();
254 const eBoundaryMesh& eMesh::boundary() const
256     return boundary_;
260 void eMesh::resetPrimitives
262     edgeList& edges,
263     labelListList& faceEdges,
264     labelListList& edgeFaces,
265     const labelList& patchSizes,
266     const labelList& patchStarts,
267     const bool reUse,
268     const bool storePrimitives
271     // Clear out geometry and addressing
272     clearOut();
274     // Initialize pointers for storage
275     if (storePrimitives)
276     {
277         fePtr_ =
278         (
279             new labelListIOList
280             (
281                 IOobject
282                 (
283                     "faceEdges",
284                     mesh_.facesInstance(),
285                     meshSubDir,
286                     mesh_,
287                     IOobject::NO_READ,
288                     IOobject::NO_WRITE
289                 )
290             )
291         );
293         efPtr_ =
294         (
295             new labelListIOList
296             (
297                 IOobject
298                 (
299                     "edgeFaces",
300                     mesh_.facesInstance(),
301                     meshSubDir,
302                     mesh_,
303                     IOobject::NO_READ,
304                     IOobject::NO_WRITE
305                 )
306             )
307         );
309         if (reUse)
310         {
311             edges_.transfer(edges);
312             fePtr_->transfer(faceEdges);
313             efPtr_->transfer(edgeFaces);
314         }
315         else
316         {
317             edges_ = edges;
318             fePtr_->operator=(faceEdges);
319             efPtr_->operator=(edgeFaces);
320         }
321     }
323     // Reset patch sizes and starts
324     forAll(boundary_, patchI)
325     {
326         boundary_[patchI] = ePatch
327         (
328             boundary_[patchI].name(),
329             patchSizes[patchI],
330             patchStarts[patchI],
331             patchI,
332             boundary_
333         );
334     }
336     // Reset size information
337     nEdges_ = edges.size();
338     nInternalEdges_ = boundary_[0].start();
340     // Set mesh files as changed
341     setInstance(time().timeName());
345 //- Clear demand-driven data
346 void eMesh::clearOut() const
348     clearGeom();
349     clearAddressing();
353 //- Set the instance for mesh files
354 void eMesh::setInstance(const fileName& inst)
356     if (debug)
357     {
358         Info<< "void eMesh::setInstance(const fileName& inst) : "
359             << "Resetting file instance to " << inst << endl;
360     }
362     if (edges_.size())
363     {
364         edges_.writeOpt() = IOobject::AUTO_WRITE;
365         edges_.instance() = inst;
366     }
368     if (efPtr_)
369     {
370         efPtr_->writeOpt() = IOobject::AUTO_WRITE;
371         efPtr_->instance() = inst;
372     }
374     if (fePtr_)
375     {
376         fePtr_->writeOpt() = IOobject::AUTO_WRITE;
377         fePtr_->instance() = inst;
378     }
380     // Write out boundary information only
381     // if all others are being written out
382     if (edges_.size() && efPtr_ && fePtr_)
383     {
384         boundary_.writeOpt() = IOobject::AUTO_WRITE;
385         boundary_.instance() = inst;
386     }
390 const labelListList& eMesh::faceEdges() const
392     if (!fePtr_)
393     {
394         calcFaceEdges();
395     }
397     return *fePtr_;
401 const labelListList& eMesh::edgeFaces() const
403     if (!efPtr_)
404     {
405         calcEdgeFaces();
406     }
408     return *efPtr_;
412 bool eMesh::write() const
414     if (edges_.size())
415     {
416         edges_.write();
417     }
419     if (efPtr_)
420     {
421         efPtr_->write();
422     }
424     if (fePtr_)
425     {
426         fePtr_->write();
427     }
429     if (edges_.size() && efPtr_ && fePtr_)
430     {
431         boundary_.write();
432     }
434     return false;
438 // * * * * * * * * * * * * * * * Member Operators  * * * * * * * * * * * * * //
440 bool eMesh::operator!=(const eMesh& m) const
442     return &m != this;
445 bool eMesh::operator==(const eMesh& m) const
447     return &m == this;
451 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
453 } // End namespace Foam
455 // ************************************************************************* //