meshSurfaceMapper2DPremapVertices.C
Go to the documentation of this file.
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.
10 
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.
15 
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.
20 
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/>.
23 
24 Description
25 
26 \*---------------------------------------------------------------------------*/
27 
28 #include "demandDrivenData.H"
30 #include "meshSurfaceMapper2D.H"
31 #include "polyMeshGen2DEngine.H"
32 #include "meshOctree.H"
33 #include "refLabelledPoint.H"
34 #include "helperFunctionsPar.H"
35 
36 # ifdef USE_OMP
37 #include <omp.h>
38 # endif
39 
40 //#define DEBUGMapping
41 
42 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
43 
44 namespace Foam
45 {
46 
47 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
48 
50 {
51  Info << "Smoothing mesh surface before mapping. Iteration:" << flush;
52 
54  const labelList& bp = surfaceEngine_.bp();
55  const vectorField& faceCentres = surfaceEngine_.faceCentres();
56  const VRWGraph& edgeFaces = surfaceEngine_.edgeFaces();
57  const edgeList& edges = surfaceEngine_.edges();
58 
60 
61  for(label iterI=0;iterI<nIterations;++iterI)
62  {
63  labelLongList parBndEdges;
64 
65  //- use the shrinking laplace first
66  # ifdef USE_OMP
67  # pragma omp parallel for schedule(dynamic, 40)
68  # endif
70  {
71  const label beI = activeBoundaryEdges_[eI];
72 
74 
75  if( edgeFaces.sizeOfRow(beI) == 2 )
76  {
77  forAllRow(edgeFaces, beI, efI)
78  {
79  ++lp.pointLabel();
80  lp.coordinates() += faceCentres[edgeFaces(beI, efI)];
81  }
82 
83  }
84  else if( edgeFaces.sizeOfRow(beI) == 1 )
85  {
86  ++lp.pointLabel();
87  lp.coordinates() += faceCentres[edgeFaces(beI, 0)];
88 
89  #ifdef USE_OMP
90  # pragma omp critical
91  # endif
92  parBndEdges.append(eI);
93  }
94 
95  //- store the information
96  preMapPositions[eI] = lp;
97  }
98 
99  if( Pstream::parRun() )
100  {
101  const VRWGraph& beAtProcs = surfaceEngine_.beAtProcs();
102  const labelList& globalEdgeLabel =
104  const Map<label>& globalToLocal =
106 
107  //- collect data to be sent to other processors
108  std::map<label, LongList<refLabelledPoint> > exchangeData;
110  exchangeData.insert
111  (
112  std::make_pair
113  (
116  )
117  );
118 
119  Map<label> edgeToActiveAddressing;
120  forAll(parBndEdges, i)
121  {
122  const label beI = activeBoundaryEdges_[parBndEdges[i]];
123  edgeToActiveAddressing.insert(beI, parBndEdges[i]);
124 
125  forAllRow(beAtProcs, beI, procI)
126  {
127  const label neiProc = beAtProcs(beI, procI);
128 
129  if( neiProc == Pstream::myProcNo() )
130  continue;
131 
132  exchangeData[neiProc].append
133  (
135  (
136  globalEdgeLabel[beI],
137  preMapPositions[beI]
138  )
139  );
140  }
141  }
142 
143  //- exchange data with other processors
144  LongList<refLabelledPoint> receivedData;
145  help::exchangeMap(exchangeData, receivedData);
146 
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();
152 
153  const label beI = globalToLocal[rlp.objectLabel()];
154  const label eI = edgeToActiveAddressing[beI];
155 
156  labelledPoint& lp = preMapPositions[eI];
157  lp.pointLabel() += lps.pointLabel();
158  lp.coordinates() += lps.coordinates();
159  }
160  }
161 
162  //- calculate coordinates of points for searching
163  # ifdef USE_OMP
164  # pragma omp parallel for schedule(dynamic, 50)
165  # endif
167  {
168  labelledPoint& lp = preMapPositions[eI];
169 
170  if( lp.pointLabel() == 0 )
171  {
172  Warning << "Surface edge " << activeBoundaryEdges_[eI]
173  << " has no active faces" << endl;
174  continue;
175  }
176 
177  lp.coordinates() /= lp.pointLabel();
178  }
179 
180  //- create the surface modifier and move the surface points
181  meshSurfaceEngineModifier surfaceModifier(surfaceEngine_);
182 
183  # ifdef USE_OMP
184  # pragma omp parallel for schedule(dynamic, 50)
185  # endif
187  {
188  const label beI = activeBoundaryEdges_[eI];
189  const edge& e = edges[beI];
190 
191  const point& p = points[e.start()];
192 
193  label patch, nt;
194  point pMap = p;
195  scalar dSq;
196 
198  (
199  pMap,
200  dSq,
201  nt,
202  patch,
203  preMapPositions[eI].coordinates()
204  );
205 
206  pMap.z() = p.z();
207  point newP = 0.5 * (pMap + p);
208 
209  surfaceModifier.moveBoundaryVertexNoUpdate(bp[e.start()], newP);
210  newP.z() = points[e.end()].z();
211  surfaceModifier.moveBoundaryVertexNoUpdate(bp[e.end()], newP);
212  }
213 
214  surfaceModifier.updateGeometry();
215  surfaceModifier.syncVerticesAtParallelBoundaries();
216 
217  Info << "." << flush;
218  }
219 
220  Info << endl;
221 }
222 
223 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
224 
225 } // End namespace Foam
226 
227 // ************************************************************************* //
Foam::meshSurfaceEngine::faceCentres
const vectorField & faceCentres() const
Definition: meshSurfaceEngineI.H:277
Foam::meshSurfaceEngine::beAtProcs
const VRWGraph & beAtProcs() const
processors which contain the edges
Definition: meshSurfaceEngineI.H:530
Foam::meshSurfaceEngine::bp
const labelList & bp() const
Definition: meshSurfaceEngineI.H:64
Foam::LongList::append
void append(const T &e)
Append an element at the end of the list.
Definition: LongListI.H:265
Foam::labelledPoint::coordinates
const point & coordinates() const
return point coordinates
Definition: labelledPoint.H:93
Foam::Vector< scalar >::zero
static const Vector zero
Definition: Vector.H:80
p
p
Definition: pEqn.H:62
Foam::meshSurfaceEngine::globalToLocalBndEdgeAddressing
const Map< label > & globalToLocalBndEdgeAddressing() const
global boundary edge label to local label. Only for processor edges
Definition: meshSurfaceEngineI.H:510
Foam::meshSurfaceEngine::globalBoundaryEdgeLabel
const labelList & globalBoundaryEdgeLabel() const
global boundary edge label
Definition: meshSurfaceEngineI.H:489
helperFunctionsPar.H
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:406
demandDrivenData.H
Template functions to aid in the implementation of demand driven data.
Foam::meshOctree::findNearestSurfacePoint
void findNearestSurfacePoint(point &nearest, scalar &distSq, label &nearestTriangle, label &region, const point &p) const
find nearest surface point for vertex and its region
Definition: meshOctreeFindNearestSurfacePoint.C:44
Foam::Warning
messageStream Warning
Foam::UPstream::parRun
static bool & parRun()
Is this a parallel run?
Definition: UPstream.H:377
Foam::edge
An edge is a list of two point labels. The functionality it provides supports the discretisation on a...
Definition: edge.H:58
Foam::Map< label >
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
Foam::LongList::size
label size() const
Size of the active part of the list.
Definition: LongListI.H:203
Foam::refLabelledPoint
Definition: refLabelledPoint.H:49
meshOctree.H
Foam::LongList< label >
Foam::flush
Ostream & flush(Ostream &os)
Flush stream.
Definition: Ostream.H:243
Foam::meshSurfaceEngineModifier
Definition: meshSurfaceEngineModifier.H:48
refLabelledPoint.H
Foam::label
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
Foam::Field
Pre-declare SubField and related Field type.
Definition: Field.H:57
Foam::Info
messageStream Info
Foam::meshSurfaceEngineModifier::moveBoundaryVertexNoUpdate
void moveBoundaryVertexNoUpdate(const label bpI, const point &newP)
relocate the selected boundary vertex
Definition: meshSurfaceEngineModifier.C:68
Foam::meshSurfaceEngine::beNeiProcs
const DynList< label > & beNeiProcs() const
communication matrix for sending edge data
Definition: meshSurfaceEngineI.H:549
Foam::meshSurfaceMapper2D::activeBoundaryEdges_
labelLongList activeBoundaryEdges_
Definition: meshSurfaceMapper2D.H:82
forAllRow
#define forAllRow(graph, rowI, index)
Definition: VRWGraph.H:277
Foam::meshSurfaceEngine::points
const pointFieldPMG & points() const
Definition: meshSurfaceEngineI.H:49
coordinates
PtrList< coordinateSystem > coordinates(solidRegions.size())
Foam::VRWGraph::sizeOfRow
label sizeOfRow(const label rowI) const
Returns the number of elements in the given row.
Definition: VRWGraphI.H:127
Foam::meshSurfaceMapper2D::preMapVertices
void preMapVertices(const label nIterations=2)
Definition: meshSurfaceMapper2DPremapVertices.C:49
polyMeshGen2DEngine.H
Foam::meshSurfaceEngine::edgeFaces
const VRWGraph & edgeFaces() const
Definition: meshSurfaceEngineI.H:334
Foam
Namespace for OpenFOAM.
Definition: combustionModel.C:30
Foam::meshSurfaceEngineModifier::updateGeometry
void updateGeometry(const labelLongList &)
Definition: meshSurfaceEngineModifier.C:234
Foam::Vector::z
const Cmpt & z() const
Definition: VectorI.H:77
Foam::e
const double e
Elementary charge.
Definition: doubleFloat.H:94
Foam::meshSurfaceMapper2D::meshOctree_
const meshOctree & meshOctree_
reference to the octree
Definition: meshSurfaceMapper2D.H:69
Foam::meshSurfaceEngine::edges
const edgeList & edges() const
Definition: meshSurfaceEngineI.H:296
Foam::refLabelledPoint::objectLabel
label objectLabel() const
return label of the object it is associated to
Definition: refLabelledPoint.H:81
Foam::meshSurfaceMapper2D::surfaceEngine_
const meshSurfaceEngine & surfaceEngine_
reference to mesh surface
Definition: meshSurfaceMapper2D.H:66
Foam::UPstream::myProcNo
static int myProcNo(const label communicator=0)
Number of this process (starting from masterNo() = 0)
Definition: UPstream.H:405
Foam::labelledPoint
Definition: labelledPoint.H:50
Foam::Vector< scalar >
Foam::List
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: HashTable.H:59
points
const pointField & points
Definition: gmvOutputHeader.H:1
Foam::help::exchangeMap
void exchangeMap(const std::map< label, ListType > &m, LongList< T > &data, const Pstream::commsTypes commsType)
Definition: helperFunctionsPar.C:129
meshSurfaceEngineModifier.H
Foam::pointFieldPMG
Definition: pointFieldPMG.H:50
Foam::VRWGraph
Definition: VRWGraph.H:101
Foam::refLabelledPoint::lPoint
const labelledPoint & lPoint() const
return labelledPoint
Definition: refLabelledPoint.H:87
Foam::labelledPoint::pointLabel
label pointLabel() const
return point label
Definition: labelledPoint.H:82
meshSurfaceMapper2D.H
Foam::meshSurfaceEngineModifier::syncVerticesAtParallelBoundaries
void syncVerticesAtParallelBoundaries()
Definition: meshSurfaceEngineModifier.C:160