conformalVoronoiMeshTemplates.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM 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 OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
26 #include "conformalVoronoiMesh.H"
27 
28 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
29 
30 template<class Triangulation>
31 bool Foam::conformalVoronoiMesh::distributeBackground(const Triangulation& mesh)
32 {
33  if (!Pstream::parRun())
34  {
35  return false;
36  }
37 
38  Info<< nl << "Redistributing points" << endl;
39 
40  timeCheck("Before distribute");
41 
42  label iteration = 0;
43 
44  scalar previousLoadUnbalance = 0;
45 
46  while (true)
47  {
48  scalar maxLoadUnbalance = mesh.calculateLoadUnbalance();
49 
50  if
51  (
52  maxLoadUnbalance <= foamyHexMeshControls().maxLoadUnbalance()
53  || maxLoadUnbalance <= previousLoadUnbalance
54  )
55  {
56  // If this is the first iteration, return false, if it was a
57  // subsequent one, return true;
58  return iteration != 0;
59  }
60 
61  previousLoadUnbalance = maxLoadUnbalance;
62 
63  Info<< " Total number of vertices before redistribution "
64  << returnReduce(label(mesh.number_of_vertices()), sumOp<label>())
65  << endl;
66 
67  const fvMesh& bMesh = decomposition_().mesh();
68 
69  volScalarField cellWeights
70  (
71  IOobject
72  (
73  "cellWeights",
74  bMesh.time().timeName(),
75  bMesh,
78  ),
79  bMesh,
80  dimensionedScalar("weight", dimless, 1e-2),
81  zeroGradientFvPatchScalarField::typeName
82  );
83 
84  meshSearch cellSearch(bMesh, polyMesh::FACE_PLANES);
85 
86  labelList cellVertices(bMesh.nCells(), label(0));
87 
88  for
89  (
90  typename Triangulation::Finite_vertices_iterator vit
91  = mesh.finite_vertices_begin();
92  vit != mesh.finite_vertices_end();
93  ++vit
94  )
95  {
96  // Only store real vertices that are not feature vertices
97  if (vit->real() && !vit->featurePoint())
98  {
99  pointFromPoint v = topoint(vit->point());
100 
101  label celli = cellSearch.findCell(v);
102 
103  if (celli == -1)
104  {
105 // Pout<< "findCell conformalVoronoiMesh::distribute "
106 // << "findCell "
107 // << vit->type() << " "
108 // << vit->index() << " "
109 // << v << " "
110 // << celli
111 // << " find nearest celli ";
112 
113  celli = cellSearch.findNearestCell(v);
114  }
115 
116  cellVertices[celli]++;
117  }
118  }
119 
120  scalarField& cwi = cellWeights.primitiveFieldRef();
121 
122  forAll(cellVertices, cI)
123  {
124  // Give a small but finite weight for empty cells. Some
125  // decomposition methods have difficulty with integer overflows in
126  // the sum of the normalised weight field.
127  cwi[cI] = max(cellVertices[cI], 1e-2);
128  }
129 
130  autoPtr<mapDistributePolyMesh> mapDist = decomposition_().distribute
131  (
132  cellWeights
133  );
134 
135  cellShapeControl_.shapeControlMesh().distribute(decomposition_);
136 
137  distribute();
138 
139  timeCheck("After distribute");
140 
141  iteration++;
142  }
143 
144  return true;
145 }
146 
147 
148 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:428
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
pointFromPoint topoint(const Point &P)
dimensioned< Type > max(const dimensioned< Type > &, const dimensioned< Type > &)
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:256
static void timeCheck(const Time &runTime, const string &description=string::null, const bool check=true)
Write the elapsedCpuTime and memory usage, with an optional.
GeometricField< scalar, fvPatchField, volMesh > volScalarField
Definition: volFieldsFwd.H:52
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
List< label > labelList
A List of labels.
Definition: labelList.H:56
void distribute(const backgroundMeshDecomposition &decomposition)
static const char nl
Definition: Ostream.H:265
static bool & parRun()
Is this a parallel run?
Definition: UPstream.H:397
const dimensionSet dimless(0, 0, 0, 0, 0, 0, 0)
Definition: dimensionSets.H:47
dimensioned< scalar > dimensionedScalar
Dimensioned scalar obtained from generic dimensioned type.
messageStream Info
cellShapeControlMesh & shapeControlMesh()
T returnReduce(const T &Value, const BinaryOp &bop, const int tag=Pstream::msgType(), const label comm=UPstream::worldComm)
const doubleScalar e
Elementary charge.
Definition: doubleScalar.H:98
const cvControls & foamyHexMeshControls() const
Return the foamyHexMeshControls object.
PrimitivePatch< face, List, const pointField > bMesh
Holder of faceList and points. (v.s. e.g. primitivePatch which references points) ...
Definition: bMesh.H:45