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-2020 OpenCFD Ltd.
9 -------------------------------------------------------------------------------
10 License
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 Description
27  Code chunk for converting finite-area - included by foamToVTK.
28 
29 \*---------------------------------------------------------------------------*/
30 
31 //
32 // Finite-area mesh and fields - need not exist
33 //
34 
35 // No subsetting!
36 if (doFiniteArea)
37 {
38  using reportFields = foamToVtkReportFields;
39 
40  autoPtr<faMesh> faMeshPtr;
41 
42  const label nAreaFields =
43  objects.count(stringListOps::foundOp<word>(fieldTypes::area));
44 
45  if (nAreaFields)
46  {
47  const bool throwing = FatalError.throwExceptions();
48  try
49  {
50  faMeshPtr.reset(new faMesh(meshProxy.baseMesh()));
51  }
52  catch (const Foam::error& err)
53  {
54  faMeshPtr.clear();
55  }
56  FatalError.throwExceptions(throwing);
57  }
58 
59  if (faMeshPtr && nAreaFields)
60  {
61  reportFields::area(Info, objects);
62 
63  const auto& pp = faMeshPtr->patch();
64 
65  vtk::surfaceMeshWriter writer
66  (
67  pp,
68  writeOpts,
69  (
70  outputDir/regionPrefix/"finite-area"
71  / "finiteArea" + timeDesc
72  ),
73  Pstream::parRun()
74  );
75 
76  writer.beginFile(faMeshPtr->name());
77 
78  writer.writeTimeValue(timeValue);
79  writer.writeGeometry();
80 
81  writer.beginCellData(nAreaFields);
82 
84  (
85  writer,
86  *faMeshPtr,
87  objects,
88  true // syncPar
89  );
90 
91  fileName outputName(writer.output());
92 
93  writer.close();
94 
95  if (Pstream::master())
96  {
97  // Add to file-series and emit as JSON
98 
99  fileName seriesName(vtk::seriesWriter::base(outputName));
100 
101  vtk::seriesWriter& series = vtkSeries(seriesName);
102 
103  // First time?
104  // Load from file, verify against filesystem,
105  // prune time >= currentTime
106  if (series.empty())
107  {
108  series.load(seriesName, true, timeValue);
109  }
110 
111  series.append(timeValue, outputName);
112  series.write(seriesName);
113  }
114  }
115 }
116 
117 
118 // ************************************************************************* //
Foam::writeAllAreaFields
label writeAllAreaFields(vtk::surfaceMeshWriter &writer, const faMesh &mesh, const IOobjectList &objects, const bool syncPar)
Definition: writeAreaFields.H:99
writer
vtk::internalMeshWriter writer(topoMesh, topoCells, writeOpts, runTime.path()/"blockTopology")
Foam::Info
messageStream Info
Information stream (uses stdout - output is on the master only)
Foam::FatalError
error FatalError
Foam::fieldTypes::area
const wordList area
Standard area field types (scalar, vector, tensor, etc)
Foam::error::throwExceptions
bool throwExceptions(bool doThrow)
Activate/deactivate exception throwing.
Definition: error.H:151
Foam::error
Class to handle errors and exceptions in a simple, consistent stream-based manner.
Definition: error.H:70