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-2023 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 && UPstream::parRun())
20 do
21 {
22  faMeshReconstructor reconstructor(aMesh, IOobjectOption::LAZY_READ);
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  refPtr<fileOperation> newHandler(fileOperation::NewUncollated());
61 
62  const bool oldDistributed = fileHandler().distributed();
63  auto oldHandler = fileOperation::fileHandler(newHandler);
64  fileHandler().distributed(true);
65 
66  if (UPstream::master())
67  {
68  haveMeshOnProc.set(UPstream::myProcNo());
69  subsetter.reset(new faMeshSubset(serialMesh));
70 
71  const bool oldParRun = UPstream::parRun(false);
72 
73  objects = IOobjectList(serialMesh.time(), runTime.timeName());
74 
75  UPstream::parRun(oldParRun);
76  }
77 
78  // Restore settings
79  (void) fileOperation::fileHandler(oldHandler);
80  fileHandler().distributed(oldDistributed);
81 
82  areaFieldsCache.readAllFields
83  (
84  haveMeshOnProc,
85  subsetter.get(),
86  serialMesh,
87  objects
88  );
89  }
90 
91  const label nAreaFields = areaFieldsCache.size();
92 
93  if (nAreaFields)
94  {
95  Info<< "Decomposing " << nAreaFields << " area fields" << nl;
96 
97  faFieldDecomposer fieldDecomposer
98  (
99  serialMesh,
100  aMesh,
101  reconstructor.edgeProcAddressing(),
102  reconstructor.faceProcAddressing(),
103  reconstructor.boundaryProcAddressing()
104  );
105 
106  // Report
107  areaFieldsCache.decomposeAllFields(fieldDecomposer, true);
108  Info<< endl;
109  }
110 } while (false);
111 
112 
113 // ************************************************************************* //
constexpr char nl
The newline &#39;\n&#39; character (0x0a)
Definition: Ostream.H:50
engineTime & runTime
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:531
refPtr< fileOperation > fileHandler(std::nullptr_t)
Delete current file handler - forwards to fileOperation::handler()
messageStream Info
Information stream (stdout output on master, null elsewhere)