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-2023 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 {
40  (
43  fvMesh
44  );
45 }
46 }
47 
48 
49 // * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
50 
52 {
53  const dictionary& distributorDict(dict());
54 
56  distributorDict.lookupOrDefault("redistributionInterval", 10);
57 
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  (
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 // ************************************************************************* //
Macros for easy insertion into run-time selection tables.
label timeIndex() const
Return current time index.
Definition: TimeStateI.H:28
static label nProcs(const label communicator=0)
Number of processes in parallel run.
Definition: UPstream.H:411
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
Definition: autoPtr.H:51
Abstract base class for decomposition.
A list of keyword definitions, which are a keyword followed by any number of values (e....
Definition: dictionary.H:162
T lookupOrDefault(const word &, const T &, bool recursive=false, bool patternMatch=true) const
Find and return a T, if not found return the given default.
Base class for statistical distributions.
Definition: distribution.H:76
Sends/receives parts of mesh+fvfields to neighbouring processors. Used in load balancing.
Abstract base class for fvMesh movers.
const dictionary & dict() const
Return the dynamicMeshDict/distributor sub-dict.
Dynamic mesh redistribution using the distributor specified in decomposeParDict.
scalar maxImbalance_
Maximum imbalance between the ideal number of cells per processor.
void readDict()
Read the projection parameters from dictionary.
void distribute(const labelList &distribution)
Distribute the mesh and mesh data.
virtual void topoChange(const polyTopoChangeMap &)
Update corresponding to the given map.
label redistributionInterval_
Time-step interval between redistribution calls.
virtual void mapMesh(const polyMeshMap &)
Update from another mesh using the given map.
virtual bool write(const bool write=true) const
Write using given format, version and compression.
distributor(fvMesh &mesh)
Construct from fvMesh.
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:99
const Time & time() const
Return the top-level database.
Definition: fvMesh.H:418
virtual void distribute(const polyDistributionMap &map)
Redistribute or update using the given distribution map.
Definition: fvMesh.C:1343
label nTotalCells() const
Return total number of cells in decomposed mesh.
Class containing mesh-to-mesh mapping information after a mesh distribution where we send parts of me...
Class containing mesh-to-mesh mapping information.
Definition: polyMeshMap.H:51
const globalMeshData & globalData() const
Return parallel info.
Definition: polyMesh.C:1515
Class containing mesh-to-mesh mapping information after a change in polyMesh topology.
label nCells() const
addToRunTimeSelectionTable(fvMeshDistributor, none, fvMesh)
void write(std::ostream &os, const bool binary, List< floatScalar > &fField)
Write floats ascii or binary.
Namespace for OpenFOAM.
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:257
messageStream Info
T returnReduce(const T &Value, const BinaryOp &bop, const int tag=Pstream::msgType(), const label comm=UPstream::worldComm)
dimensioned< scalar > mag(const dimensioned< Type > &)