parFaFieldDistributorCache.C
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) 2022 OpenCFD Ltd.
9-------------------------------------------------------------------------------
10License
11 This file is part of OpenFOAM.
12
13 OpenFOAM is free software: you can redistribute it and/or modify it
14 under the terms of the GNU General Public License as published by
15 the Free Software Foundation, either version 3 of the License, or
16 (at your option) any later version.
17
18 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 for more details.
22
23 You should have received a copy of the GNU General Public License
24 along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25
26\*---------------------------------------------------------------------------*/
27
29
30#include "areaFields.H"
31#include "edgeFields.H"
32#include "fieldsDistributor.H"
33#include "faMeshDistributor.H"
34#include "faMeshSubset.H"
35
36// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
37
38template<class GeoField>
39void Foam::parFaFieldDistributorCache::redistributeAndWrite
40(
41 const faMeshDistributor& distributor,
42 PtrList<GeoField>& fields,
43 const bool isWriteProc
44)
45{
46 for (GeoField& fld : fields)
47 {
48 tmp<GeoField> tfld = distributor.distributeField(fld);
49
50 if (isWriteProc)
51 {
52 tfld().write();
53 }
54 }
55}
56
57
58// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
59
61(
62 const Time& baseRunTime,
63 const fileName& proc0CaseName,
64 const bool decompose, // i.e. read from undecomposed case
65
66 const boolList& areaMeshOnProc,
67 const fileName& areaMeshInstance,
68 faMesh& mesh
69)
70{
71 Time& runTime = const_cast<Time&>(mesh.time());
72 const bool oldProcCase = runTime.processorCase();
73
74 autoPtr<faMeshSubset> subsetterPtr;
75
76 // Missing an area mesh somewhere?
77 if (areaMeshOnProc.found(false))
78 {
79 // A zero-sized mesh with boundaries.
80 // This is used to create zero-sized fields.
81 subsetterPtr.reset(new faMeshSubset(mesh, zero{}));
82
83 // Deregister from polyMesh ...
84 auto& obr = const_cast<objectRegistry&>
85 (
86 subsetterPtr->subMesh().thisDb()
87 );
88
89 obr.checkOut(faMesh::typeName);
90 obr.checkOut("faBoundaryMesh");
91 obr.checkOut("faSchemes");
92 obr.checkOut("faSolution");
93 }
94
95
96 // Get original objects (before incrementing time!)
97 if (Pstream::master() && decompose)
98 {
99 runTime.caseName() = baseRunTime.caseName();
100 runTime.processorCase(false);
101 }
102 IOobjectList objects(mesh.mesh(), runTime.timeName());
103 if (Pstream::master() && decompose)
104 {
105 runTime.caseName() = proc0CaseName;
106 runTime.processorCase(oldProcCase);
107 }
108
109 Info<< "From time " << runTime.timeName()
110 << " mesh:" << mesh.mesh().objectRegistry::objectRelPath()
111 << " have objects:" << objects.names() << endl;
112
113 if (Pstream::master() && decompose)
114 {
115 runTime.caseName() = baseRunTime.caseName();
116 runTime.processorCase(false);
117 }
118
119 #undef doFieldReading
120 #define doFieldReading(Storage) \
121 fieldsDistributor::readFields \
122 ( \
123 areaMeshOnProc, mesh, subsetterPtr, objects, Storage, \
124 true /* (deregister field) */ \
125 );
126
127 // areaFields
128 doFieldReading(scalarAreaFields_);
129 doFieldReading(vectorAreaFields_);
130 doFieldReading(sphericalTensorAreaFields_);
131 doFieldReading(symmTensorAreaFields_);
132 doFieldReading(tensorAreaFields_);
133
134 // edgeFields
135 doFieldReading(scalarEdgeFields_);
136 doFieldReading(vectorEdgeFields_);
137 doFieldReading(tensorEdgeFields_);
138 doFieldReading(sphericalTensorEdgeFields_);
139 doFieldReading(symmTensorEdgeFields_);
140 #undef doFieldReading
141}
142
143
144void Foam::parFaFieldDistributorCache::redistributeAndWrite
145(
146 const faMeshDistributor& distributor,
147 const bool isWriteProc
148)
149{
150 redistributeAndWrite(distributor, scalarAreaFields_, isWriteProc);
151 redistributeAndWrite(distributor, vectorAreaFields_, isWriteProc);
152 redistributeAndWrite(distributor, sphericalTensorAreaFields_, isWriteProc);
153 redistributeAndWrite(distributor, symmTensorAreaFields_, isWriteProc);
154 redistributeAndWrite(distributor, tensorAreaFields_, isWriteProc);
155
156 redistributeAndWrite(distributor, scalarEdgeFields_, isWriteProc);
157 redistributeAndWrite(distributor, vectorEdgeFields_, isWriteProc);
158 redistributeAndWrite(distributor, sphericalTensorEdgeFields_, isWriteProc);
159 redistributeAndWrite(distributor, symmTensorEdgeFields_, isWriteProc);
160 redistributeAndWrite(distributor, tensorEdgeFields_, isWriteProc);
161}
162
163
164// ************************************************************************* //
Info<< nl<< "Wrote faMesh in vtk format: "<< writer.output().name()<< nl;}{ vtk::lineWriter writer(aMesh.points(), aMesh.edges(), fileName(aMesh.mesh().time().globalPath()/"finiteArea-edges"));writer.writeGeometry();writer.beginCellData(4);writer.writeProcIDs();{ Field< scalar > fld(faMeshTools::flattenEdgeField(aMesh.magLe(), true))
virtual bool read()
Re-read model coefficients if they have changed.
bool processorCase() const noexcept
Return true if this is a processor case.
Definition: TimePathsI.H:36
const fileName & caseName() const
Return case name.
Definition: TimePathsI.H:62
static word timeName(const scalar t, const int precision=precision_)
Definition: Time.C:780
const Time & time() const
Return the top-level database.
Definition: fvMesh.H:290
wordList names() const
The unsorted names of all objects.
splitCell * master() const
Definition: splitCell.H:113
dynamicFvMesh & mesh
engineTime & runTime
messageStream Info
Information stream (stdout output on master, null elsewhere)
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:372
List< bool > boolList
A List of bools.
Definition: List.H:64
multivariateSurfaceInterpolationScheme< scalar >::fieldTable fields
Definition: createFields.H:97
static const char *const typeName
The type name used in ensight case files.