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  // Clear sliced and other non-distributable mesh data
75 
76  // Do actual sending/receiving of mesh
78  (
80  );
81 
82  // Distribute the mesh data
83  mesh.distribute(map);
84 }
85 
86 
87 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
88 
90 :
91  fvMeshDistributor(mesh),
92  distributor_
93  (
94  decompositionMethod::NewDistributor
95  (
96  decompositionMethod::decomposeParDict(mesh.time())
97  )
98  ),
99  redistributionInterval_(1),
100  maxImbalance_(0.1),
101  timeIndex_(-1)
102 {
103  readDict();
104 }
105 
106 
107 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
108 
110 {}
111 
112 
113 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
114 
116 {
117  const fvMesh& mesh = this->mesh();
118 
119  bool redistributed = false;
120 
121  if
122  (
123  Pstream::nProcs() > 1
124  && mesh.time().timeIndex() > 1
125  && timeIndex_ != mesh.time().timeIndex()
126  && mesh.time().timeIndex() % redistributionInterval_ == 0
127  )
128  {
129  timeIndex_ = mesh.time().timeIndex();
130 
131  const scalar idealNCells =
133 
134  const scalar imbalance = returnReduce
135  (
136  mag(1 - mesh.nCells()/idealNCells),
137  maxOp<scalar>()
138  );
139 
140  if (imbalance > maxImbalance_)
141  {
142  Info<< "Redistributing mesh with imbalance " << imbalance << endl;
143 
144  // Create new decomposition distribution
145  const labelList distribution
146  (
147  distributor_->decompose(mesh, scalarField())
148  );
149 
150  distribute(distribution);
151 
152  redistributed = true;
153  }
154  }
155 
156  return redistributed;
157 }
158 
159 
161 {}
162 
163 
165 {}
166 
167 
169 (
170  const polyDistributionMap&
171 )
172 {}
173 
174 
176 {
177  return true;
178 }
179 
180 
181 // ************************************************************************* //
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:160
T lookupOrDefault(const word &, const T &, bool recursive=false, bool patternMatch=true) const
Find and return a T,.
Accumulating histogram of values. Specified bin resolution automatic generation of bins.
Definition: distribution.H:61
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.
virtual bool update()=0
Update the mesh.
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:101
const Time & time() const
Return the top-level database.
Definition: fvMesh.H:406
virtual void distribute(const polyDistributionMap &map)
Redistribute or update using the given distribution map.
Definition: fvMesh.C:1372
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:1563
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:251
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 > &)