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-2021 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  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!
38 if (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)
48  {
49  const bool oldThrowingError = FatalError.throwing(true);
50  try
51  {
52  faMeshPtr.reset(new faMesh(meshProxy.baseMesh()));
53  }
54  catch (const Foam::error& err)
55  {
56  faMeshPtr.clear();
57  }
58  FatalError.throwing(oldThrowingError);
59  }
60 
61  if (faMeshPtr && nAreaFields)
62  {
63  reportFields::area(Info, objects);
64 
65  const auto& pp = faMeshPtr->patch();
66 
68  (
69  pp,
70  writeOpts,
71  (
72  outputDir/regionDir/"finite-area"
73  / "finiteArea" + timeDesc
74  ),
75  Pstream::parRun()
76  );
77 
78  writer.beginFile(faMeshPtr->name());
79 
80  writer.writeTimeValue(timeValue);
81  writer.writeGeometry();
82 
83  writer.beginCellData(nAreaFields);
84 
86  (
87  writer,
88  *faMeshPtr,
89  objects,
90  true // syncPar
91  );
92 
93  fileName outputName(writer.output());
94 
95  writer.close();
96 
97  if (Pstream::master())
98  {
99  // Add to file-series and emit as JSON
100 
101  fileName seriesName(vtk::seriesWriter::base(outputName));
102 
103  vtk::seriesWriter& series = vtkSeries(seriesName);
104 
105  // First time?
106  // Load from file, verify against filesystem,
107  // prune time >= currentTime
108  if (series.empty())
109  {
110  series.load(seriesName, true, timeValue);
111  }
112 
113  series.append(timeValue, outputName);
114  series.write(seriesName);
115  }
116  }
117 }
118 
119 
120 // ************************************************************************* //
Foam::error::throwing
bool throwing() const noexcept
Return the current exception throwing state (on or off)
Definition: error.H:169
outputName
word outputName("finiteArea-edges.obj")
Foam::Info
messageStream Info
Information stream (stdout output on master, null elsewhere)
Foam::FatalError
error FatalError
Foam::vtkWriterType_areaMesh
vtk::uindirectPatchGeoFieldsWriter vtkWriterType_areaMesh
Definition: writeAreaFields.H:50
Foam::fieldTypes::area
const wordList area
Standard area field types (scalar, vector, tensor, etc)
Foam::writeAllAreaFields
label writeAllAreaFields(ensightCase &ensCase, const ensightFaMesh &ensMesh, const IOobjectList &objects)
Definition: writeAreaFields.H:105
regionDir
const word & regionDir
Definition: findMeshDefinitionDict.H:34
writer
vtk::internalMeshWriter writer(topoMesh, topoCells, vtk::formatType::INLINE_ASCII, runTime.path()/"blockTopology")
Foam::error
Class to handle errors and exceptions in a simple, consistent stream-based manner.
Definition: error.H:73