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-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
26Description
27 Code chunk for converting finite-area - included by foamToVTK.
28
29 Typedef vtkWriterType_areaMesh is declared in writeAreaFields.H
30
31\*---------------------------------------------------------------------------*/
32
33//
34// Finite-area mesh and fields - need not exist
35//
36
37// No subsetting!
38if (doFiniteArea)
39{
40 using reportFields = foamToVtkReportFields;
41
42 autoPtr<faMesh> faMeshPtr;
43
44 const label nAreaFields =
45 objects.count(stringListOps::foundOp<word>(fieldTypes::area));
46
47 if (nAreaFields || withMeshIds)
48 {
49 faMeshPtr = faMesh::TryNew(meshProxy.baseMesh());
50 }
51
52 if (faMeshPtr && (nAreaFields || withMeshIds))
53 {
54 const faMesh& areaMesh = faMeshPtr();
55
56 reportFields::area(Info, objects);
57
58 const auto& pp = faMeshPtr->patch();
59
60 vtkWriterType_areaMesh writer
61 (
62 pp,
63 writeOpts,
64 (
65 outputDir/regionDir/"finite-area"
66 / "finiteArea" + timeDesc
67 ),
68 Pstream::parRun()
69 );
70 Info<< " Area : "
71 << args.relativePath(writer.output()) << nl;
72
73 writer.beginFile(areaMesh.name());
74
75 writer.writeTimeValue(timeValue);
76 writer.writeGeometry();
77
78 // Optionally with (cellID, faceLabels, procID) fields
79 writer.beginCellData
80 (
81 (withMeshIds ? 2 + (writer.parallel() ? 1 : 0) : 0)
82 + nAreaFields
83 );
84
85 if (withMeshIds)
86 {
87 const globalIndex procAddr(areaMesh.nFaces());
88
89 // Use global indexed values for the 'cell' ids
90 writer.writeCellData("cellID", identity(procAddr.range()));
91
92 // Use proc-local data for faceLabels
93 // (confusing enough already without renumbering)
94 writer.writeCellData("faceLabels", areaMesh.faceLabels());
95
96 writer.writeProcIDs(); // parallel only
97 }
98
99 writeAllAreaFields
100 (
101 writer,
102 areaMesh,
103 objects,
104 true // syncPar
105 );
106
107 fileName outputName(writer.output());
108
109 writer.close();
110
111 if (Pstream::master())
112 {
113 // Add to file-series and emit as JSON
114
115 fileName seriesName(vtk::seriesWriter::base(outputName));
116
117 vtk::seriesWriter& series = vtkSeries(seriesName);
118
119 // First time?
120 // Load from file, verify against filesystem,
121 // prune time >= currentTime
122 if (series.empty())
123 {
124 series.load(seriesName, true, timeValue);
125 }
126
127 series.append(timeValue, outputName);
128 series.write(seriesName);
129 }
130 }
131}
132
133
134// ************************************************************************* //
vtk::internalMeshWriter writer(topoMesh, topoCells, vtk::formatType::INLINE_ASCII, runTime.path()/"blockTopology")
globalIndex procAddr(aMesh.nFaces())
fileName relativePath(const fileName &input, const bool caseTag=false) const
Definition: argListI.H:94
word outputName("finiteArea-edges.obj")
const word & regionDir
Foam::argList args(argc, argv)