convertAreaFields.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) 2018-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 finite-area - included by foamToVTK.
15 
16  Typedef vtkWriterType_areaMesh is declared in writeAreaFields.H
17 
18 \*---------------------------------------------------------------------------*/
19 
20 //
21 // Finite-area mesh and fields - need not exist
22 //
23 
24 // No subsetting!
25 if (doFiniteArea)
26 {
27  using reportFields = foamToVtkReportFields;
28 
29  autoPtr<faMesh> faMeshPtr;
30 
31  const label nAreaFields =
32  objects.count(stringListOps::foundOp<word>(fieldTypes::area));
33 
34  if (nAreaFields || withMeshIds)
35  {
36  faMeshPtr = faMesh::TryNew(meshProxy.baseMesh());
37  }
38 
39  if (faMeshPtr && (nAreaFields || withMeshIds))
40  {
41  const faMesh& areaMesh = faMeshPtr();
42 
43  reportFields::area(Info, objects);
44 
45  const auto& pp = faMeshPtr->patch();
46 
48  (
49  pp,
50  writeOpts,
51  (
52  outputDir/regionDir/"finite-area"
53  / "finiteArea" + timeDesc
54  ),
55  UPstream::parRun()
56  );
57  Info<< " Area : "
58  << args.relativePath(writer.output()) << nl;
59 
60  writer.beginFile(areaMesh.name());
61 
62  writer.writeTimeValue(timeValue);
63  writer.writeGeometry();
64 
65  // Optionally with (cellID, patchID, faceLabels, procID) fields
66  writer.beginCellData
67  (
68  (withMeshIds ? 3 + (writer.parallel() ? 1 : 0) : 0)
69  + nAreaFields
70  );
71 
72  if (withMeshIds)
73  {
74  const globalIndex procAddr(areaMesh.nFaces());
75 
76  // Use global indexed values for the 'cell' ids
77  writer.writeCellData("cellID", identity(procAddr.range()));
78 
79  // The patch ids can also be quite useful
80  const polyBoundaryMesh& pbm = areaMesh.mesh().boundaryMesh();
81 
83  (
84  pbm.patchID(areaMesh.faceLabels())
85  );
86 
87  writer.writeCellData("patchID", patchIds);
88 
89  // Use proc-local data for faceLabels
90  // (confusing enough already without renumbering)
91  writer.writeCellData("faceLabels", areaMesh.faceLabels());
92 
93  writer.writeProcIDs(); // parallel only
94  }
95 
97  (
98  writer,
99  areaMesh,
100  objects,
101  true // syncPar
102  );
103 
104  fileName outputName(writer.output());
105 
106  writer.close();
107 
108  if (UPstream::master())
109  {
110  // Add to file-series and emit as JSON
111 
112  fileName seriesName(vtk::seriesWriter::base(outputName));
113 
114  vtk::seriesWriter& series = vtkSeries(seriesName);
115 
116  // First time?
117  // Load from file, verify against filesystem,
118  // prune time >= currentTime
119  if (series.empty())
120  {
121  series.load(seriesName, true, timeValue);
122  }
123 
124  series.append(timeValue, outputName);
125  series.write(seriesName);
126  }
127  }
128 }
129 
130 
131 // ************************************************************************* //
labelList patchIds
const polyBoundaryMesh & pbm
vtk::lineWriter writer(edgeCentres, edgeList::null(), fileName(aMesh.time().globalPath()/"finiteArea-edgesCentres"))
constexpr char nl
The newline &#39;\n&#39; character (0x0a)
Definition: Ostream.H:50
label writeAllAreaFields(ensightCase &ensCase, const ensightFaMesh &ensMesh, const IOobjectList &objects)
word outputName("finiteArea-edges.obj")
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
const wordList area
Standard area field types (scalar, vector, tensor, etc)
fileName relativePath(const fileName &input, const bool caseTag=false) const
Return the input relative to the globalPath by stripping off a leading value of the globalPath...
Definition: argListI.H:87
globalIndex procAddr(aMesh.nFaces())
const word & regionDir
messageStream Info
Information stream (stdout output on master, null elsewhere)
List< label > labelList
A List of labels.
Definition: List.H:62
Foam::argList args(argc, argv)
vtk::uindirectPatchGeoFieldsWriter vtkWriterType_areaMesh
uindirectPrimitivePatch pp(UIndirectList< face >(mesh.faces(), faceLabels), mesh.points())