decomposeFaFields.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2021-2022 OpenCFD Ltd.
9 -------------------------------------------------------------------------------
10 License
11  This file is part of OpenFOAM, distributed under GPL-3.0-or-later.
12 
13 Description
14  Write proc addressing and decompose area fields (parallel only).
15 
16 \*---------------------------------------------------------------------------*/
17 
18 // Embed do-while to support early termination
19 if (doDecompose && Pstream::parRun())
20 do
21 {
22  faMeshReconstructor reconstructor(aMesh, IOobjectOption::READ_IF_PRESENT);
23 
24  if (!reconstructor.good())
25  {
26  Info<< "Missing volume proc-addressing, "
27  "cannot generate area proc-addressing." << nl
28  << "Also skip decomposing area fields...."
29  << endl;
30  break;
31  }
32 
33  reconstructor.writeMesh(); // Writes on master only
34  reconstructor.writeAddressing(); // Writes per-proc
35 
36  Info<< "Wrote proc-addressing and serial mesh" << nl << endl;
37 
38  // Handle area fields
39  // ------------------
40 
41  faFieldDecomposer::fieldsCache areaFieldsCache;
42 
43  const faMesh& serialMesh = reconstructor.mesh();
44 
45  if (doDecompFields)
46  {
47  // The serial finite-area mesh exists and is identical on all
48  // processors, but its fields can only reliably be read on the
49  // master (eg, running with distributed roots).
50  //
51  // - mark mesh fields as readable on master only (haveMeshOnProc)
52  // - 'subset' entire serial mesh so that a full copy will be
53  // broadcast to other ranks (subsetterPtr)
54  // - scan available IOobjects on the master only
55 
56  bitSet haveMeshOnProc;
57  std::unique_ptr<faMeshSubset> subsetter;
58  IOobjectList objects(0);
59 
60  const bool oldDistributed = fileHandler().distributed();
61  auto oldHandler = fileHandler(fileOperation::NewUncollated());
62  fileHandler().distributed(true);
63 
64  if (Pstream::master())
65  {
66  haveMeshOnProc.set(Pstream::myProcNo());
67  subsetter.reset(new faMeshSubset(serialMesh));
68 
69  const bool oldParRun = Pstream::parRun(false);
70 
71  objects = IOobjectList(serialMesh.time(), runTime.timeName());
72 
73  Pstream::parRun(oldParRun);
74  }
75 
76  // Restore old settings
77  if (oldHandler)
78  {
79  fileHandler(std::move(oldHandler));
80  }
81  fileHandler().distributed(oldDistributed);
82 
83  areaFieldsCache.readAllFields
84  (
85  haveMeshOnProc,
86  subsetter.get(),
87  serialMesh,
88  objects
89  );
90  }
91 
92  const label nAreaFields = areaFieldsCache.size();
93 
94  if (nAreaFields)
95  {
96  Info<< "Decomposing " << nAreaFields << " area fields" << nl;
97 
98  faFieldDecomposer fieldDecomposer
99  (
100  serialMesh,
101  aMesh,
102  reconstructor.edgeProcAddressing(),
103  reconstructor.faceProcAddressing(),
104  reconstructor.boundaryProcAddressing()
105  );
106 
107  // Report
108  areaFieldsCache.decomposeAllFields(fieldDecomposer, true);
109  Info<< endl;
110  }
111 } while (false);
112 
113 
114 // ************************************************************************* //
constexpr char nl
The newline &#39;\n&#39; character (0x0a)
Definition: Ostream.H:49
engineTime & runTime
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:487
autoPtr< fileOperation > fileHandler(std::nullptr_t)
Delete current file handler.
messageStream Info
Information stream (stdout output on master, null elsewhere)
faMesh aMesh(mesh)