Moving cfMesh into place. Updated contibutors list
[foam-extend-3.2.git] / src / mesh / cfMesh / meshLibrary / utilities / surfaceTools / meshSurfaceMapper2D / meshSurfaceMapper2DPremapVertices.C
blobf86500c9d529e1d1cfe9d75993bd285fc150bb91
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 "meshSurfaceEngineModifier.H"
30 #include "meshSurfaceMapper2D.H"
31 #include "polyMeshGen2DEngine.H"
32 #include "meshOctree.H"
33 #include "refLabelledPoint.H"
34 #include "helperFunctionsPar.H"
36 # ifdef USE_OMP
37 #include <omp.h>
38 # endif
40 //#define DEBUGMapping
42 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
44 namespace Foam
47 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
49 void meshSurfaceMapper2D::preMapVertices(const label nIterations)
51     Info << "Smoothing mesh surface before mapping. Iteration:" << flush;
53     const pointFieldPMG& points = surfaceEngine_.points();
54     const labelList& bp = surfaceEngine_.bp();
55     const vectorField& faceCentres = surfaceEngine_.faceCentres();
56     const VRWGraph& edgeFaces = surfaceEngine_.edgeFaces();
57     const edgeList& edges = surfaceEngine_.edges();
59     List<labelledPoint> preMapPositions(activeBoundaryEdges_.size());
61     for(label iterI=0;iterI<nIterations;++iterI)
62     {
63         labelLongList parBndEdges;
65         //- use the shrinking laplace first
66         # ifdef USE_OMP
67         # pragma omp parallel for schedule(dynamic, 40)
68         # endif
69         forAll(activeBoundaryEdges_, eI)
70         {
71             const label beI = activeBoundaryEdges_[eI];
73             labelledPoint lp(0, vector::zero);
75             if( edgeFaces.sizeOfRow(beI) == 2 )
76             {
77                 forAllRow(edgeFaces, beI, efI)
78                 {
79                     ++lp.pointLabel();
80                     lp.coordinates() += faceCentres[edgeFaces(beI, efI)];
81                 }
83             }
84             else if( edgeFaces.sizeOfRow(beI) == 1 )
85             {
86                 ++lp.pointLabel();
87                 lp.coordinates() += faceCentres[edgeFaces(beI, 0)];
89                 #ifdef USE_OMP
90                 # pragma omp critical
91                 # endif
92                 parBndEdges.append(eI);
93             }
95             //- store the information
96             preMapPositions[eI] = lp;
97         }
99         if( Pstream::parRun() )
100         {
101             const VRWGraph& beAtProcs = surfaceEngine_.beAtProcs();
102             const labelList& globalEdgeLabel =
103                 surfaceEngine_.globalBoundaryEdgeLabel();
104             const Map<label>& globalToLocal =
105                 surfaceEngine_.globalToLocalBndEdgeAddressing();
107             //- collect data to be sent to other processors
108             std::map<label, LongList<refLabelledPoint> > exchangeData;
109             forAll(surfaceEngine_.beNeiProcs(), i)
110                 exchangeData.insert
111                 (
112                     std::make_pair
113                     (
114                         surfaceEngine_.beNeiProcs()[i],
115                         LongList<refLabelledPoint>()
116                     )
117                 );
119             Map<label> edgeToActiveAddressing;
120             forAll(parBndEdges, i)
121             {
122                 const label beI = activeBoundaryEdges_[parBndEdges[i]];
123                 edgeToActiveAddressing.insert(beI, parBndEdges[i]);
125                 forAllRow(beAtProcs, beI, procI)
126                 {
127                     const label neiProc = beAtProcs(beI, procI);
129                     if( neiProc == Pstream::myProcNo() )
130                         continue;
132                     exchangeData[neiProc].append
133                     (
134                         refLabelledPoint
135                         (
136                             globalEdgeLabel[beI],
137                             preMapPositions[beI]
138                         )
139                     );
140                 }
141             }
143             //- exchange data with other processors
144             LongList<refLabelledPoint> receivedData;
145             help::exchangeMap(exchangeData, receivedData);
147             //- combine collected data with the available data
148             forAll(receivedData, i)
149             {
150                 const refLabelledPoint& rlp = receivedData[i];
151                 const labelledPoint& lps = rlp.lPoint();
153                 const label beI = globalToLocal[rlp.objectLabel()];
154                 const label eI = edgeToActiveAddressing[beI];
156                 labelledPoint& lp = preMapPositions[eI];
157                 lp.pointLabel() += lps.pointLabel();
158                 lp.coordinates() += lps.coordinates();
159             }
160         }
162         //- calculate coordinates of points for searching
163         # ifdef USE_OMP
164         # pragma omp parallel for schedule(dynamic, 50)
165         # endif
166         forAll(activeBoundaryEdges_, eI)
167         {
168             labelledPoint& lp = preMapPositions[eI];
170             if( lp.pointLabel() == 0 )
171             {
172                 Warning << "Surface edge " << activeBoundaryEdges_[eI]
173                     << " has no active faces" << endl;
174                 continue;
175             }
177             lp.coordinates() /= lp.pointLabel();
178         }
180         //- create the surface modifier and move the surface points
181         meshSurfaceEngineModifier surfaceModifier(surfaceEngine_);
183         # ifdef USE_OMP
184         # pragma omp parallel for schedule(dynamic, 50)
185         # endif
186         forAll(activeBoundaryEdges_, eI)
187         {
188             const label beI = activeBoundaryEdges_[eI];
189             const edge& e = edges[beI];
191             const point& p = points[e.start()];
193             label patch, nt;
194             point pMap = p;
195             scalar dSq;
197             meshOctree_.findNearestSurfacePoint
198             (
199                 pMap,
200                 dSq,
201                 nt,
202                 patch,
203                 preMapPositions[eI].coordinates()
204             );
206             pMap.z() = p.z();
207             point newP = 0.5 * (pMap + p);
209             surfaceModifier.moveBoundaryVertexNoUpdate(bp[e.start()], newP);
210             newP.z() = points[e.end()].z();
211             surfaceModifier.moveBoundaryVertexNoUpdate(bp[e.end()], newP);
212         }
214         surfaceModifier.updateGeometry();
215         surfaceModifier.syncVerticesAtParallelBoundaries();
217         Info << "." << flush;
218     }
220     Info << endl;
223 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
225 } // End namespace Foam
227 // ************************************************************************* //