Merge branch 'master' of ssh://git.code.sf.net/p/foam-extend/foam-extend-3.2
[foam-extend-3.2.git] / src / mesh / cfMesh / utilities / smoothers / geometry / meshSurfaceOptimizer / meshSurfaceOptimizer.C
blobf8b16b20f57a612b1730dc62bca6cbdc3443da9b
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | cfMesh: A library for mesh generation
4    \\    /   O peration     |
5     \\  /    A nd           | Author: Franjo Juretic (franjo.juretic@c-fields.com)
6      \\/     M anipulation  | Copyright (C) Creative Fields, Ltd.
7 -------------------------------------------------------------------------------
8 License
9     This file is part of cfMesh.
11     cfMesh 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     cfMesh 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 cfMesh.  If not, see <http://www.gnu.org/licenses/>.
24 Description
26 \*---------------------------------------------------------------------------*/
28 #include "demandDrivenData.H"
29 #include "meshSurfaceOptimizer.H"
30 #include "meshSurfaceEngine.H"
31 #include "meshSurfacePartitioner.H"
32 #include "meshSurfaceMapper.H"
33 #include "polyMeshGenChecks.H"
35 #include <map>
37 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
39 namespace Foam
42 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
44 void meshSurfaceOptimizer::classifySurfaceVertices()
46     const labelHashSet& corners = partitionerPtr_->corners();
47     const labelHashSet& edgePoints = partitionerPtr_->edgePoints();
49     //- set all vertices to partition
50     vertexType_ = PARTITION;
52     //- set corners
53     forAllConstIter(labelHashSet, corners, it)
54         vertexType_[it.key()] = CORNER;
56     //- set edges
57     forAllConstIter(labelHashSet, edgePoints, it)
58         vertexType_[it.key()] = EDGE;
60     if( Pstream::parRun() )
61     {
62         //- mark nodes at parallel boundaries
63         const Map<label>& globalToLocal =
64             surfaceEngine_.globalToLocalBndPointAddressing();
66         forAllConstIter(Map<label>, globalToLocal, iter)
67         {
68             const label bpI = iter();
70             vertexType_[bpI] |= PROCBND;
71         }
72     }
75 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
77 meshSurfaceOptimizer::meshSurfaceOptimizer(const meshSurfaceEngine& surface)
79     surfaceEngine_(surface),
80     vertexType_(surface.boundaryPoints().size()),
81     partitionerPtr_(new meshSurfacePartitioner(surface)),
82     deletePartitioner_(true),
83     octreePtr_(NULL),
84     triMeshPtr_(NULL),
85     enforceConstraints_(false),
86     badPointsSubsetName_("invertedBoundaryPoints")
88     classifySurfaceVertices();
91 meshSurfaceOptimizer::meshSurfaceOptimizer(const meshSurfacePartitioner& mPart)
93     surfaceEngine_(mPart.surfaceEngine()),
94     vertexType_(surfaceEngine_.boundaryPoints().size()),
95     partitionerPtr_(&mPart),
96     deletePartitioner_(true),
97     octreePtr_(NULL),
98     triMeshPtr_(NULL),
99     enforceConstraints_(false),
100     badPointsSubsetName_("invertedBoundaryPoints")
102     classifySurfaceVertices();
105 meshSurfaceOptimizer::meshSurfaceOptimizer
107     const meshSurfaceEngine& surface,
108     const meshOctree& octree
111     surfaceEngine_(surface),
112     vertexType_(surface.boundaryPoints().size()),
113     partitionerPtr_(new meshSurfacePartitioner(surface)),
114     deletePartitioner_(true),
115     octreePtr_(&octree),
116     triMeshPtr_(NULL),
117     enforceConstraints_(false),
118     badPointsSubsetName_("invertedBoundaryPoints")
120     classifySurfaceVertices();
123 meshSurfaceOptimizer::meshSurfaceOptimizer
125     const meshSurfacePartitioner& partitioner,
126     const meshOctree& octree
129     surfaceEngine_(partitioner.surfaceEngine()),
130     vertexType_(surfaceEngine_.boundaryPoints().size()),
131     partitionerPtr_(&partitioner),
132     deletePartitioner_(false),
133     octreePtr_(&octree),
134     triMeshPtr_(NULL),
135     enforceConstraints_(false),
136     badPointsSubsetName_("invertedBoundaryPoints")
138     classifySurfaceVertices();
141 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
143 meshSurfaceOptimizer::~meshSurfaceOptimizer()
145     deleteDemandDrivenData(triMeshPtr_);
147     if( deletePartitioner_ )
148         deleteDemandDrivenData(partitionerPtr_);
151 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
153 void meshSurfaceOptimizer::removeUserConstraints()
155     # ifdef USE_OMP
156     # pragma omp parallel for schedule(dynamic, 100)
157     # endif
158     forAll(vertexType_, bpI)
159         if( vertexType_[bpI] & LOCKED )
160             vertexType_[bpI] ^= LOCKED;
163 void meshSurfaceOptimizer::enforceConstraints(const word subsetName)
165     enforceConstraints_ = true;
167     badPointsSubsetName_ = subsetName;
170 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
172 } // End namespace Foam
174 // ************************************************************************* //