1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | cfMesh: A library for mesh generation
5 \\ / A nd | Author: Franjo Juretic (franjo.juretic@c-fields.com)
6 \\/ M anipulation | Copyright (C) Creative Fields, Ltd.
7 -------------------------------------------------------------------------------
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
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/>.
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"
40 //#define DEBUGMapping
42 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
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)
63 labelLongList parBndEdges;
65 //- use the shrinking laplace first
67 # pragma omp parallel for schedule(dynamic, 40)
69 forAll(activeBoundaryEdges_, eI)
71 const label beI = activeBoundaryEdges_[eI];
73 labelledPoint lp(0, vector::zero);
75 if( edgeFaces.sizeOfRow(beI) == 2 )
77 forAllRow(edgeFaces, beI, efI)
80 lp.coordinates() += faceCentres[edgeFaces(beI, efI)];
84 else if( edgeFaces.sizeOfRow(beI) == 1 )
87 lp.coordinates() += faceCentres[edgeFaces(beI, 0)];
92 parBndEdges.append(eI);
95 //- store the information
96 preMapPositions[eI] = lp;
99 if( Pstream::parRun() )
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)
114 surfaceEngine_.beNeiProcs()[i],
115 LongList<refLabelledPoint>()
119 Map<label> edgeToActiveAddressing;
120 forAll(parBndEdges, i)
122 const label beI = activeBoundaryEdges_[parBndEdges[i]];
123 edgeToActiveAddressing.insert(beI, parBndEdges[i]);
125 forAllRow(beAtProcs, beI, procI)
127 const label neiProc = beAtProcs(beI, procI);
129 if( neiProc == Pstream::myProcNo() )
132 exchangeData[neiProc].append
136 globalEdgeLabel[beI],
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)
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();
162 //- calculate coordinates of points for searching
164 # pragma omp parallel for schedule(dynamic, 50)
166 forAll(activeBoundaryEdges_, eI)
168 labelledPoint& lp = preMapPositions[eI];
170 if( lp.pointLabel() == 0 )
172 Warning << "Surface edge " << activeBoundaryEdges_[eI]
173 << " has no active faces" << endl;
177 lp.coordinates() /= lp.pointLabel();
180 //- create the surface modifier and move the surface points
181 meshSurfaceEngineModifier surfaceModifier(surfaceEngine_);
184 # pragma omp parallel for schedule(dynamic, 50)
186 forAll(activeBoundaryEdges_, eI)
188 const label beI = activeBoundaryEdges_[eI];
189 const edge& e = edges[beI];
191 const point& p = points[e.start()];
197 meshOctree_.findNearestSurfacePoint
203 preMapPositions[eI].coordinates()
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);
214 surfaceModifier.updateGeometry();
215 surfaceModifier.syncVerticesAtParallelBoundaries();
217 Info << "." << flush;
223 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
225 } // End namespace Foam
227 // ************************************************************************* //