distributor_fvMeshDistributor.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-2025 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 labelList& distribution
54 )
55 {
56  fvMesh& mesh = this->mesh();
57 
58  mesh.preChange();
59 
60  // Mesh distribution engine
62 
63  // Do actual sending/receiving of mesh
65  (
67  );
68 
69  // Distribute the mesh data
70  mesh.distribute(map);
71 }
72 
73 
74 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
75 
77 (
78  fvMesh& mesh,
79  const dictionary& dict
80 )
81 :
83  distributor_
84  (
85  decompositionMethod::NewDistributor
86  (
87  decompositionMethod::decomposeParDict(mesh.time())
88  )
89  ),
90  redistributionInterval_(dict.lookupOrDefault("redistributionInterval", 10)),
91  maxImbalance_(dict.lookupOrDefault<scalar>("maxImbalance", 0.1)),
92  timeIndex_(-1)
93 {}
94 
95 
96 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
97 
99 {}
100 
101 
102 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
103 
105 {
106  const fvMesh& mesh = this->mesh();
107 
108  bool redistributed = false;
109 
110  if
111  (
112  Pstream::nProcs() > 1
113  && mesh.time().timeIndex() > 1
114  && timeIndex_ != mesh.time().timeIndex()
115  && mesh.time().timeIndex() % redistributionInterval_ == 0
116  )
117  {
118  timeIndex_ = mesh.time().timeIndex();
119 
120  const scalar idealNCells =
122 
123  const scalar imbalance = returnReduce
124  (
125  mag(1 - mesh.nCells()/idealNCells),
126  maxOp<scalar>()
127  );
128 
129  if (imbalance > maxImbalance_)
130  {
131  Info<< "Redistributing mesh with imbalance " << imbalance << endl;
132 
133  // Create new decomposition distribution
134  const labelList distribution
135  (
136  distributor_->decompose(mesh, scalarField())
137  );
138 
139  distribute(distribution);
140 
141  redistributed = true;
142  }
143  }
144 
145  return redistributed;
146 }
147 
148 
150 {}
151 
152 
154 {}
155 
156 
158 (
159  const polyDistributionMap&
160 )
161 {}
162 
163 
165 {
166  return true;
167 }
168 
169 
170 // ************************************************************************* //
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 keywords followed by any number of values (e.g. words and numbers) or sub-dictionaries.
Definition: dictionary.H:162
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.
fvMesh & mesh()
Return the fvMesh.
Dynamic mesh redistribution using the distributor specified in decomposeParDict.
distributor(fvMesh &mesh, const dictionary &dict)
Construct from fvMesh and dictionary.
void distribute(const labelList &distribution)
Distribute the mesh and mesh data.
virtual void topoChange(const polyTopoChangeMap &)
Update corresponding to the given map.
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.
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:96
const Time & time() const
Return the top-level database.
Definition: fvMesh.H:420
void preChange()
Prepare for a mesh change.
Definition: fvMesh.C:1222
virtual void distribute(const polyDistributionMap &map)
Redistribute or update using the given distribution map.
Definition: fvMesh.C:1462
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:1521
Class containing mesh-to-mesh mapping information after a change in polyMesh topology.
label nCells() const
Foam::fvMesh mesh(Foam::IOobject(regionName, runTime.name(), runTime, Foam::IOobject::MUST_READ), false)
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:258
messageStream Info
void mag(LagrangianPatchField< scalar > &f, const LagrangianPatchField< Type > &f1)
T returnReduce(const T &Value, const BinaryOp &bop, const int tag=Pstream::msgType(), const label comm=UPstream::worldComm)
dictionary dict