Loading...
Searching...
No Matches
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-------------------------------------------------------------------------------
10License
11 This file is part of OpenFOAM, distributed under GPL-3.0-or-later.
12
13Description
14 Write proc addressing and decompose area fields (parallel only).
15
16\*---------------------------------------------------------------------------*/
17
18// Embed do-while to support early termination
19if (doDecompose && UPstream::parRun())
20do
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;
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
74 (
75 serialMesh.time(),
76 runTime.timeName(),
77 serialMesh.dbDir(),
78 IOobjectOption::NO_REGISTER
79 );
80
81 UPstream::parRun(oldParRun);
82 }
83
84 // Restore settings
85 (void) fileOperation::fileHandler(oldHandler);
86 fileHandler().distributed(oldDistributed);
87
88 areaFieldsCache.readAllFields
89 (
90 haveMeshOnProc,
91 subsetter.get(),
92 serialMesh,
93 objects
94 );
95 }
96
97 const label nAreaFields = areaFieldsCache.size();
98
99 if (nAreaFields)
100 {
101 Info<< "Decomposing " << nAreaFields << " area fields" << nl;
102
103 faFieldDecomposer fieldDecomposer
104 (
105 serialMesh,
106 aMesh,
107 reconstructor.edgeProcAddressing(),
108 reconstructor.faceProcAddressing(),
109 reconstructor.boundaryProcAddressing()
110 );
111
112 // Report
113 areaFieldsCache.decomposeAllFields(fieldDecomposer, true);
114 Info<< endl;
115 }
116} while (false);
117
118
119// ************************************************************************* //
engineTime & runTime
refPtr< fileOperation > fileHandler(std::nullptr_t)
Delete current file handler - forwards to fileOperation::handler().
messageStream Info
Information stream (stdout output on master, null elsewhere).
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition Ostream.H:519
constexpr char nl
The newline '\n' character (0x0a).
Definition Ostream.H:50