symmetryPlaneOptimisation.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 "polyMeshGenAddressing.H"
31 #include "helperFunctions.H"
32 #include "polyMeshGenChecks.H"
33 #include "meshOptimizer.H"
34 
35 // #define DEBUGSearch
36 
37 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
38 
39 namespace Foam
40 {
41 
42 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
43 
45 {
46  const PtrList<boundaryPatch>& boundaries = mesh_.boundaries();
47  const pointFieldPMG& points = mesh_.points();
48  const faceListPMG& faces = mesh_.faces();
49 
50  symmetryPlanes_.clear();
51 
52  typedef std::map<label, std::pair<vector, label> > mapType;
53  mapType centreSum, normalSum;
54 
55  forAll(boundaries, patchI)
56  {
57  if( boundaries[patchI].patchType() == "symmetryPlane" )
58  {
59  std::pair<vector, label>& cs = centreSum[patchI];
60  cs = std::pair<vector, label>(vector::zero, 0);
61 
62  std::pair<vector, label>& ns = normalSum[patchI];
63  ns = std::pair<vector, label>(vector::zero, 0);
64 
65  const label start = boundaries[patchI].patchStart();
66  const label end = start + boundaries[patchI].patchSize();
67  for(label faceI=start;faceI<end;++faceI)
68  {
69  cs.first += faces[faceI].centre(points);
70  ns.first += faces[faceI].normal(points);
71  }
72 
73  cs.second = ns.second = boundaries[patchI].patchSize();
74  }
75  }
76 
77  if( Pstream::parRun() )
78  {
79  //- sum up all normals and centres of all processors
80  //- every symmetry plane patch must be present on all processors
81  forAllIter(mapType, centreSum, pIter)
82  {
83  std::pair<vector, label>& cs = pIter->second;
84  reduce(cs.second, sumOp<label>());
85  reduce(cs.first, sumOp<vector>());
86 
87  std::pair<vector, label>& ns = normalSum[pIter->first];
88  reduce(ns.first, sumOp<vector>());
89  ns.second = cs.second;
90  }
91  }
92 
93  //- create planes corresponding to each symmetry plane
94  forAllConstIter(mapType, centreSum, it)
95  {
96  const point c = it->second.first / it->second.second;
97 
98  const std::pair<vector, label>& ns = normalSum[it->first];
99  const point n = ns.first / ns.second;
100 
101  symmetryPlanes_.insert(std::make_pair(it->first, plane(c, n)));
102  }
103 }
104 
106 {
107  const PtrList<boundaryPatch>& boundaries = mesh_.boundaries();
108  const pointFieldPMG& points = mesh_.points();
109  const faceListPMG& faces = mesh_.faces();
110 
111  pointInPlanes.clear();
112  pointInPlanes.setSize(points.size());
113 
114  forAll(boundaries, patchI)
115  {
116  if( boundaries[patchI].patchType() == "symmetryPlane" )
117  {
118  const label start = boundaries[patchI].patchStart();
119  const label end = start + boundaries[patchI].patchSize();
120  for(label faceI=start;faceI<end;++faceI)
121  {
122  const face& f = faces[faceI];
123 
124  forAll(f, pI)
125  pointInPlanes.appendIfNotIn(f[pI], patchI);
126  }
127  }
128  }
129 
130  if( Pstream::parRun() )
131  {
132  const Map<label>& globalToLocal =
134  const VRWGraph& pointAtProcs = mesh_.addressingData().pointAtProcs();
135  const DynList<label>& neiProcs =
137 
138  std::map<label, labelLongList> exchangeData;
139  forAll(neiProcs, i)
140  exchangeData[neiProcs[i]].clear();
141 
142  forAllConstIter(Map<label>, globalToLocal, it)
143  {
144  const label pointI = it();
145 
146  if( pointInPlanes.sizeOfRow(pointI) == 0 )
147  continue;
148 
149  forAllRow(pointAtProcs, pointI, i)
150  {
151  const label neiProc = pointAtProcs(pointI, i);
152 
153  if( neiProc == Pstream::myProcNo() )
154  continue;
155 
156  labelLongList& dataToSend = exchangeData[neiProc];
157 
158  dataToSend.append(it.key());
159  dataToSend.append(pointInPlanes.sizeOfRow(pointI));
160  forAllRow(pointInPlanes, pointI, pipI)
161  dataToSend.append(pointInPlanes(pointI, pipI));
162  }
163  }
164 
165  labelLongList receivedData;
166  help::exchangeMap(exchangeData, receivedData);
167 
168  for(label counter=0;counter<receivedData.size();)
169  {
170  const label pointI = globalToLocal[receivedData[counter++]];
171 
172  const label size = receivedData[counter++];
173  for(label i=0;i<size;++i)
174  pointInPlanes.appendIfNotIn(pointI, receivedData[counter++]);
175  }
176  }
177 }
178 
179 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
180 
181 // Construct from mesh
183 :
184  mesh_(mesh)
185 {
187 }
188 
189 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
190 
192 {}
193 
194 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
195 
197 {
199 
200  VRWGraph pointInPlane;
201  pointInPlanes(pointInPlane);
202 
203  forAll(pointInPlane, pointI)
204  {
205  const label nPlanes = pointInPlane.sizeOfRow(pointI);
206 
207  if( nPlanes > 3 )
208  {
209  WarningIn
210  (
211  "void symmetryPlaneOptimisation::optimizeSymmetryPlanes()"
212  ) << "Point " << pointI << " is in more than three symmetry"
213  << " planes. Cannot move it" << endl;
214  }
215 
216  point& p = points[pointI];
217  vector disp(vector::zero);
218  for(label plI=0;plI<nPlanes;++plI)
219  {
220  //- point is in a plane
221  std::map<label, plane>::const_iterator it =
222  symmetryPlanes_.find(pointInPlane(pointI, 0));
223 
224  const point newP = it->second.nearestPoint(points[pointI]);
225  disp += newP - p;
226  }
227 
228  p += disp;
229  }
230 
231  labelHashSet badFaces;
232  polyMeshGenChecks::checkFacePyramids(mesh_, false, VSMALL, &badFaces);
233 
234  if( badFaces.size() )
235  {
236  WarningIn
237  (
238  "void symmetryPlaneOptimisation::optimizeSymmetryPlanes()"
239  ) << "Bad quality or inverted faces found in the mesh" << endl;
240 
241  const label badFacesId = mesh_.addFaceSubset("invalidFaces");
242  forAllConstIter(labelHashSet, badFaces, it)
243  mesh_.addFaceToSubset(badFacesId, it.key());
244  }
245 }
246 
247 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
248 
249 } // End namespace Foam
250 
251 // ************************************************************************* //
Foam::polyMeshGenCells::addressingData
const polyMeshGenAddressing & addressingData() const
addressing which may be needed
Definition: polyMeshGenCells.C:327
Foam::LongList::append
void append(const T &e)
Append an element at the end of the list.
Definition: LongListI.H:265
Foam::Vector< scalar >::zero
static const Vector zero
Definition: Vector.H:80
p
p
Definition: pEqn.H:62
forAllIter
#define forAllIter(Container, container, iter)
Iterate across all elements in the container object of type.
Definition: UList.H:431
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:406
Foam::polyMeshGenAddressing::globalToLocalPointAddressing
const Map< label > & globalToLocalPointAddressing() const
Definition: polyMeshGenAddressingParallelAddressing.C:814
demandDrivenData.H
Template functions to aid in the implementation of demand driven data.
Foam::symmetryPlaneOptimisation::symmetryPlanes_
std::map< label, plane > symmetryPlanes_
symmetry planes in the mesh
Definition: symmetryPlaneOptimisation.H:63
Foam::UPstream::parRun
static bool & parRun()
Is this a parallel run?
Definition: UPstream.H:377
Foam::polyMeshGenFaces::addFaceSubset
label addFaceSubset(const word &)
Definition: polyMeshGenFaces.C:262
Foam::Map< label >
Foam::symmetryPlaneOptimisation::~symmetryPlaneOptimisation
~symmetryPlaneOptimisation()
Definition: symmetryPlaneOptimisation.C:191
Foam::polyMeshGen
Definition: polyMeshGen.H:46
Foam::symmetryPlaneOptimisation::pointInPlanes
void pointInPlanes(VRWGraph &) const
point-planes addressing
Definition: symmetryPlaneOptimisation.C:105
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
Foam::polyMeshGenPoints::points
const pointFieldPMG & points() const
access to points
Definition: polyMeshGenPointsI.H:44
Foam::LongList::size
label size() const
Size of the active part of the list.
Definition: LongListI.H:203
Foam::HashSet< label, Hash< label > >
polyMeshGenChecks.H
Foam::polyMeshGenFaces::faces
const faceListPMG & faces() const
access to faces
Definition: polyMeshGenFacesI.H:43
Foam::polyMeshGenAddressing::pointAtProcs
const VRWGraph & pointAtProcs() const
Definition: polyMeshGenAddressingParallelAddressing.C:775
forAllConstIter
forAllConstIter(PtrDictionary< phaseModel >, mixture.phases(), phase)
Definition: pEqn.H:39
Foam::plane
Geometric class that creates a 2D plane and can return the intersection point between a line and the ...
Definition: plane.H:60
Foam::LongList< label >
n
label n
Definition: TABSMDCalcMethod2.H:31
Foam::reduce
void reduce(const List< UPstream::commsStruct > &comms, T &Value, const BinaryOp &bop, const int tag, const label comm)
Definition: PstreamReduceOps.H:43
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::polyMeshGenAddressing::pointNeiProcs
const DynList< label > & pointNeiProcs() const
Definition: polyMeshGenAddressingParallelAddressing.C:794
Foam::symmetryPlaneOptimisation::optimizeSymmetryPlanes
void optimizeSymmetryPlanes()
move vertices to the symmetry planes
Definition: symmetryPlaneOptimisation.C:196
Foam::PtrList
A templated 1D list of pointers to objects of type <T>, where the size of the array is known and used...
Definition: List.H:61
forAllRow
#define forAllRow(graph, rowI, index)
Definition: VRWGraph.H:277
Foam::VRWGraph::sizeOfRow
label sizeOfRow(const label rowI) const
Returns the number of elements in the given row.
Definition: VRWGraphI.H:127
Foam::HashTable::size
label size() const
Return number of elements in table.
Definition: HashTableI.H:65
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:18
Foam
Namespace for OpenFOAM.
Definition: combustionModel.C:30
Foam::symmetryPlaneOptimisation::symmetryPlaneOptimisation
symmetryPlaneOptimisation(polyMeshGen &mesh)
Construct from mesh.
Definition: symmetryPlaneOptimisation.C:182
Foam::symmetryPlaneOptimisation::mesh_
polyMeshGen & mesh_
reference to the mesh
Definition: symmetryPlaneOptimisation.H:60
Foam::DynList< label >
Foam::UPstream::myProcNo
static int myProcNo(const label communicator=0)
Number of this process (starting from masterNo() = 0)
Definition: UPstream.H:405
Foam::polyMeshGenChecks::checkFacePyramids
bool checkFacePyramids(const polyMeshGen &, const bool report=false, const scalar minPyrVol=-SMALL, labelHashSet *setPtr=NULL, const boolList *changedFacePtr=NULL)
Check face pyramid volume.
Definition: polyMeshGenChecksGeometry.C:962
Foam::symmetryPlaneOptimisation::detectSymmetryPlanes
void detectSymmetryPlanes()
detect symmetry planes
Definition: symmetryPlaneOptimisation.C:44
Foam::PtrList::first
T & first()
Return reference to the first element of the list.
Definition: PtrListI.H:46
Foam::sumOp
Definition: ops.H:162
helperFunctions.H
f
labelList f(nPoints)
Foam::Vector< scalar >
Foam::polyMeshGenFaces::boundaries
const PtrList< boundaryPatch > & boundaries() const
ordinary boundaries
Definition: polyMeshGenFacesI.H:111
points
const pointField & points
Definition: gmvOutputHeader.H:1
meshOptimizer.H
Foam::help::exchangeMap
void exchangeMap(const std::map< label, ListType > &m, LongList< T > &data, const Pstream::commsTypes commsType)
Definition: helperFunctionsPar.C:129
Foam::constant::universal::c
const dimensionedScalar c
Speed of light in a vacuum.
symmetryPlaneOptimisation.H
Foam::polyMeshGenFaces::addFaceToSubset
void addFaceToSubset(const label, const label)
Definition: polyMeshGenFacesI.H:117
Foam::face
A face is a list of labels corresponding to mesh vertices.
Definition: face.H:75
WarningIn
#define WarningIn(functionName)
Report a warning using Foam::Warning.
Definition: messageStream.H:254
Foam::faceListPMG
Definition: faceListPMG.H:50
Foam::pointFieldPMG
Definition: pointFieldPMG.H:50
Foam::VRWGraph
Definition: VRWGraph.H:101
polyMeshGenAddressing.H