convertProcessorPatches.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) 2019-2023 OpenCFD Ltd.
9 -------------------------------------------------------------------------------
10 License
11  This file is part of OpenFOAM, distributed under GPL-3.0-or-later.
12 
13 Description
14  Code chunk for converting volume fields on processor boundaries,
15  included by foamToVTK.
16 
17 \*---------------------------------------------------------------------------*/
18 
19 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
20 
21 // Generate processor/processorN/procBoundary
22 
23 {
24  using reportFields = foamToVtkReportFields;
25 
26  const label nVolFields =
27  (
28  objects.count(stringListOps::foundOp<word>(fieldTypes::volume))
29  );
30 
31  reportFields::volume(Info, objects);
32 
33  // Setup for the vtm writer.
34 
35  fileName vtmOutputBase
36  (
37  outputDir/regionDir/vtkName + timeDesc
38  );
39 
40  // Naming
41  const auto subDirNaming =
42  [](const label i) -> fileName
43  { return "processor" / ("processor" + Foam::name(i)); };
44 
45 
46  // Dummy writer.
47  autoPtr<vtk::internalWriter> internalWriter;
48 
49  // Setup the patch writers
50  PtrList<vtk::patchWriter> patchWriters;
51 
52  const polyBoundaryMesh& patches = mesh.boundaryMesh();
53 
55  identity
56  (
57  patches.size()-patches.nNonProcessor(),
58  patches.nNonProcessor()
59  );
60 
61  forAll(patchIds, i)
62  {
63  if (!isA<processorPolyPatch>(patches[patchIds[i]]))
64  {
65  patchIds.resize(i);
66  break;
67  }
68  }
69 
70  patchWriters.resize(patchIds.size());
71 
72  label nPatchWriters = 0;
73 
74  List<wordList> procPatchNames(UPstream::nProcs());
75  procPatchNames[UPstream::myProcNo()].resize(patchIds.size());
76 
77  for (const label patchId : patchIds)
78  {
79  const polyPatch& pp = patches[patchId];
80 
82  (
83  meshProxy.mesh(),
84  labelList(one{}, pp.index()),
85  writeOpts,
86  nearCellValue,
87  (
89  / subDirNaming(UPstream::myProcNo())
90  / pp.name()
91  ),
92  false // This MUST be non-parallel (serial only)
93  );
94 
95  procPatchNames[UPstream::myProcNo()][nPatchWriters] = pp.name();
96 
97  writer->writeTimeValue(timeValue);
98  writer->writeGeometry();
99 
100  // Transfer writer to list for later use
102  }
103  patchWriters.resize(nPatchWriters);
104 
105 
106  Pstream::gatherList(procPatchNames);
107 
108  // CellData
109  {
110  for (vtk::patchWriter& writer : patchWriters)
111  {
112  // Optionally with patchID, procID, neighID fields
113  // - use UPstream::parRun() not writer.parallel() !!
114  writer.beginCellData
115  (
116  (withMeshIds ? 1 + (UPstream::parRun() ? 2 : 0) : 0)
117  + nVolFields
118  );
119 
120  if (withMeshIds)
121  {
122  writer.writePatchIDs();
123  writer.writeProcIDs(); // parallel only
124  writer.writeNeighIDs(); // parallel only
125  }
126  }
127 
129  (
131  patchWriters,
132  meshProxy,
133  objects,
134  true, // syncPar
135  nullptr // no field cache (object registry)
136  );
137 
138  // End CellData is implicit
139  }
140 
141 
142  // Finish writers
143  if (internalWriter)
144  {
145  internalWriter->close();
146  }
147 
148  for (vtk::patchWriter& writer : patchWriters)
149  {
150  writer.close();
151  }
152 
153  patchWriters.clear();
154 
155 
156  // Collective output
157 
158  const label nProcPatches = returnReduce(nPatchWriters, sumOp<label>());
159 
160  if (UPstream::master() && nProcPatches)
161  {
162  Info<< "Wrote " << nProcPatches << " processor boundaries from "
163  << UPstream::nProcs() << " processes" << nl;
164 
165 
166  // Collect individual boundaries into a vtm file
168 
169  // Naming for vtm
170  fileName outputName(vtmOutputBase / "processor");
171  outputName.ext(vtmBoundaries.ext());
172 
173  vtmBoundaries.setTime(timeValue);
174 
175  forAll(procPatchNames, proci)
176  {
177  label n = 0;
178 
179  const word blockName("proc" + Foam::name(proci));
180  const fileName dirName = subDirNaming(proci);
181 
182  for (const word& patchName : procPatchNames[proci])
183  {
184  if (!n)
185  {
186  vtmBoundaries.beginBlock(blockName);
187  ++n;
188  }
189 
190  vtmBoundaries.append_vtp
191  (
192  patchName,
193  dirName/patchName
194  );
195  }
196 
197  if (n)
198  {
199  vtmBoundaries.endBlock();
200  }
201  }
202 
203 
204  // Emit "processor.vtm" with collection of processor boundaries
205  vtmBoundaries.write(outputName);
206  }
207 }
208 
209 
210 // ************************************************************************* //
label patchId(-1)
labelList patchIds
const auto subDirNaming
forAll(patchIds, i)
vtk::lineWriter writer(edgeCentres, edgeList::null(), fileName(aMesh.time().globalPath()/"finiteArea-edgesCentres"))
label writeAllVolFields(ensightCase &ensCase, const ensightMesh &ensMesh, const IOobjectList &objects, const bool nearCellValue=false)
constexpr char nl
The newline &#39;\n&#39; character (0x0a)
Definition: Ostream.H:50
tmp< DimensionedField< TypeR, GeoMesh > > New(const tmp< DimensionedField< TypeR, GeoMesh >> &tf1, const word &name, const dimensionSet &dimensions, const bool initCopy=false)
Global function forwards to reuseTmpDimensionedField::New.
fileName vtmOutputBase(outputDir/regionDir/vtkName+timeDesc)
T returnReduce(const T &value, const BinaryOp &bop, const int tag=UPstream::msgType(), const label comm=UPstream::worldComm)
Perform reduction on a copy, using specified binary operation.
List< wordList > procPatchNames(UPstream::nProcs())
word outputName("finiteArea-edges.obj")
dynamicFvMesh & mesh
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for expressions::valueTypeCode::INVALID.
Definition: exprTraits.C:127
labelList identity(const label len, label start=0)
Return an identity map of the given length with (map[i] == i), works like std::iota() but returning a...
Definition: labelLists.C:44
label nPatchWriters
const label nVolFields
autoPtr< vtk::internalWriter > internalWriter
const wordList volume
Standard volume field types (scalar, vector, tensor, etc)
const label nProcPatches
vtk::vtmWriter vtmBoundaries
const word & regionDir
const polyBoundaryMesh & patches
vtk::vtmWriter vtmWriter
messageStream Info
Information stream (stdout output on master, null elsewhere)
label n
List< label > labelList
A List of labels.
Definition: List.H:62
PtrList< vtk::patchWriter > patchWriters
uindirectPrimitivePatch pp(UIndirectList< face >(mesh.faces(), faceLabels), mesh.points())