fvMeshDistributorsDistributor.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) 2021-2022 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 
27 #include "decompositionMethod.H"
28 #include "fvMeshDistribute.H"
29 #include "polyDistributionMap.H"
31 
32 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
33 
34 namespace Foam
35 {
36 namespace fvMeshDistributors
37 {
38  defineTypeNameAndDebug(distributor, 0);
40  (
41  fvMeshDistributor,
42  distributor,
43  fvMesh
44  );
45 }
46 }
47 
48 
49 // * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
50 
52 {
53  const dictionary& distributorDict(dict());
54 
55  redistributionInterval_ =
56  distributorDict.lookupOrDefault("redistributionInterval", 10);
57 
58  maxImbalance_ =
59  distributorDict.lookupOrDefault<scalar>("maxImbalance", 0.1);
60 }
61 
62 
64 (
65  const labelList& distribution
66 )
67 {
68  fvMesh& mesh = this->mesh();
69 
70  // Mesh distribution engine
72 
73  // Do actual sending/receiving of mesh
75  (
76  distributor.distribute(distribution)
77  );
78 
79  // Distribute the mesh data
80  mesh.distribute(map);
81 }
82 
83 
84 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
85 
87 :
88  fvMeshDistributor(mesh),
89  distributor_
90  (
91  decompositionMethod::NewDistributor
92  (
93  decompositionMethod::decomposeParDict(mesh.time())
94  )
95  ),
96  redistributionInterval_(1),
97  maxImbalance_(0.1),
98  timeIndex_(-1)
99 {
100  readDict();
101 }
102 
103 
104 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
105 
107 {}
108 
109 
110 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
111 
113 {
114  const fvMesh& mesh = this->mesh();
115 
116  bool redistributed = false;
117 
118  if
119  (
120  Pstream::nProcs() > 1
121  && mesh.time().timeIndex() > 1
122  && timeIndex_ != mesh.time().timeIndex()
123  && mesh.time().timeIndex() % redistributionInterval_ == 0
124  )
125  {
126  timeIndex_ = mesh.time().timeIndex();
127 
128  const scalar idealNCells =
130 
131  const scalar imbalance = returnReduce
132  (
133  mag(1 - mesh.nCells()/idealNCells),
134  maxOp<scalar>()
135  );
136 
137  if (imbalance > maxImbalance_)
138  {
139  Info<< "Redistributing mesh with imbalance " << imbalance << endl;
140 
141  // Create new decomposition distribution
142  const labelList distribution
143  (
144  distributor_->decompose(mesh, scalarField())
145  );
146 
147  distribute(distribution);
148 
149  redistributed = true;
150  }
151  }
152 
153  return redistributed;
154 }
155 
156 
158 {}
159 
160 
162 {}
163 
164 
166 (
167  const polyDistributionMap&
168 )
169 {}
170 
171 
173 {
174  return true;
175 }
176 
177 
178 // ************************************************************************* //
scalar maxImbalance_
Maximum imbalance between the ideal number of cells per processor.
label redistributionInterval_
Time-step interval between redistribution calls.
dictionary dict
Class containing mesh-to-mesh mapping information after a mesh distribution where we send parts of me...
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:156
label nCells() const
void readDict()
Read the projection parameters from dictionary.
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
void distribute(const labelList &distribution)
Distribute the mesh and mesh data.
label nTotalCells() const
Return total number of cells in decomposed mesh.
const Time & time() const
Return the top-level database.
Definition: fvMesh.H:372
fvMesh & mesh
Macros for easy insertion into run-time selection tables.
Sends/receives parts of mesh+fvfields to neighbouring processors. Used in load balancing.
addToRunTimeSelectionTable(fvMeshDistributor, none, fvMesh)
autoPtr< polyDistributionMap > distribute(const labelList &dist)
Send cells to neighbours according to distribution.
virtual bool write(const bool write=true) const
Write using given format, version and compression.
Class containing mesh-to-mesh mapping information after a change in polyMesh topology.
fvMesh & mesh()
Return the fvMesh.
const globalMeshData & globalData() const
Return parallel info.
Definition: polyMesh.C:1435
Abstract base class for decomposition.
virtual void distribute(const polyDistributionMap &map)
Redistribute or update using the given distribution map.
Definition: fvMesh.C:1289
Dynamic mesh redistribution using the distributor specified in decomposeParDict.
virtual void mapMesh(const polyMeshMap &)
Update from another mesh using the given map.
Abstract base class for fvMesh movers.
static label nProcs(const label communicator=0)
Number of processes in parallel run.
Definition: UPstream.H:411
label timeIndex() const
Return current time index.
Definition: TimeStateI.H:28
T lookupOrDefault(const word &, const T &, bool recursive=false, bool patternMatch=true) const
Find and return a T,.
label timeIndex_
The time index used for updating.
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:95
messageStream Info
dimensioned< scalar > mag(const dimensioned< Type > &)
autoPtr< decompositionMethod > distributor_
Cache the decomposer/distributor.
T returnReduce(const T &Value, const BinaryOp &bop, const int tag=Pstream::msgType(), const label comm=UPstream::worldComm)
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
Definition: PtrList.H:52
Class containing mesh-to-mesh mapping information.
Definition: polyMeshMap.H:50
distributor(fvMesh &mesh)
Construct from fvMesh.
virtual void topoChange(const polyTopoChangeMap &)
Update corresponding to the given map.
Namespace for OpenFOAM.