writeVolFields.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, distributed under GPL-3.0-or-later.
12 
13 InNamespace
14  Foam
15 
16 Description
17  Read volume fields from disk and write with ensightMesh
18 
19 \*---------------------------------------------------------------------------*/
20 
21 #ifndef ensight_writeVolFields_H
22 #define ensight_writeVolFields_H
23 
24 #include "readFields.H"
25 #include "fvMesh.H"
26 
27 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
28 
29 namespace Foam
30 {
31 
32 template<class Type>
33 bool writeVolField
34 (
35  ensightCase& ensCase,
36  const ensightMesh& ensMesh,
37  const tmp<GeometricField<Type, fvPatchField, volMesh>>& tfield,
38  const bool nearCellValue = false
39 )
40 {
41  if (!tfield.valid())
42  {
43  return false;
44  }
45  else if (nearCellValue)
46  {
47  auto tzgrad = makeZeroGradientField<Type>(tfield);
48 
49  // Recursive call
50  return writeVolField
51  (
52  ensCase,
53  ensMesh,
54  tzgrad,
55  false // No nearCellValue, we already have zero-gradient
56  );
57  }
58 
59  const auto& field = tfield();
60 
61  // Forced use of node values?
62  const bool nodeValues = ensCase.nodeValues();
63 
64  autoPtr<ensightFile> os =
65  ensCase.newData<Type>(field.name(), nodeValues);
66 
67  bool wrote = ensightOutput::writeVolField<Type>
68  (
69  os.ref(),
70  field,
71  ensMesh,
72  nodeValues
73  );
74 
75  tfield.clear();
76  return wrote;
77 }
78 
79 
80 template<class Type>
81 label writeVolFields
82 (
83  ensightCase& ensCase,
84  const ensightMesh& ensMesh,
85  const IOobjectList& objects,
86  const bool nearCellValue = false
87 )
88 {
89  typedef GeometricField<Type, fvPatchField, volMesh> GeoField;
90 
91  const fvMesh& mesh = dynamicCast<const fvMesh>(ensMesh.mesh());
92 
93  label count = 0;
94 
95  for (const word& fieldName : objects.sortedNames<GeoField>())
96  {
97  if
98  (
99  writeVolField<Type>
100  (
101  ensCase,
102  ensMesh,
103  getField<GeoField>(objects.findObject(fieldName), mesh),
104  nearCellValue
105  )
106  )
107  {
108  Info<< ' ' << fieldName;
109  ++count;
110  }
111  }
112 
113  return count;
114 }
115 
116 
117 label writeAllVolFields
118 (
119  ensightCase& ensCase,
120  const ensightMesh& ensMesh,
121  const IOobjectList& objects,
122  const bool nearCellValue = false
123 )
124 {
125  #undef ensight_WRITE_FIELD
126  #define ensight_WRITE_FIELD(PrimitiveType) \
127  writeVolFields<PrimitiveType> \
128  ( \
129  ensCase, \
130  ensMesh, \
131  objects, \
132  nearCellValue \
133  )
134 
135  label count = 0;
136  count += ensight_WRITE_FIELD(scalar);
141 
142  #undef ensight_WRITE_FIELD
143  return count;
144 }
145 
146 } // End namespace Foam
147 
148 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
149 
150 #endif
151 
152 // ************************************************************************* //
Foam::Tensor< scalar >
Foam::ensightCase::newData
autoPtr< ensightFile > newData(const word &varName, const bool isPointData=false) const
Open stream for new data file (on master), with current index.
Foam::ensightMesh
Encapsulation of volume meshes for writing in ensight format. It manages cellZones,...
Definition: ensightMesh.H:82
Foam::SymmTensor< scalar >
readFields.H
Helper routines for reading a field or fields, for foamToEnsight.
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:65
Foam::tmp
A class for managing temporary objects.
Definition: PtrList.H:61
ensight_WRITE_FIELD
#define ensight_WRITE_FIELD(PrimitiveType)
Foam::IOobjectList::findObject
const IOobject * findObject(const word &objName) const
Return const pointer to the object found by name.
Definition: IOobjectList.C:270
Foam::IOobjectList::sortedNames
wordList sortedNames() const
The sorted names of the IOobjects.
Definition: IOobjectList.C:345
Foam::ensightMesh::mesh
const polyMesh & mesh() const noexcept
Reference to the underlying polyMesh.
Definition: ensightMesh.H:148
Foam::writeVolField
bool writeVolField(ensightCase &ensCase, const ensightMesh &ensMesh, const tmp< GeometricField< Type, fvPatchField, volMesh >> &tfield, const bool nearCellValue=false)
Definition: writeVolFields.H:42
Foam::Info
messageStream Info
Information stream (stdout output on master, null elsewhere)
Foam::writeAllVolFields
label writeAllVolFields(ensightCase &ensCase, const ensightMesh &ensMesh, const IOobjectList &objects, const bool nearCellValue=false)
Definition: writeVolFields.H:126
field
rDeltaTY field()
os
OBJstream os(runTime.globalPath()/outputName)
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:6
Foam::fvMesh
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:85
fvMesh.H
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::SphericalTensor< scalar >
Foam::IOobjectList
List of IOobjects with searching and retrieving facilities.
Definition: IOobjectList.H:55
Foam::writeVolFields
label writeVolFields(ensightCase &ensCase, const ensightMesh &ensMesh, const IOobjectList &objects, const bool nearCellValue=false)
Definition: writeVolFields.H:90
Foam::ensightCase
Supports writing of ensight cases as well as providing common factory methods to open new files.
Definition: ensightCase.H:67
Foam::autoPtr
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition: HashPtrTable.H:53
Foam::BitOps::count
unsigned int count(const UList< bool > &bools, const bool val=true)
Count number of 'true' entries.
Definition: BitOps.H:77
Foam::Vector< scalar >
Foam::ensightCase::nodeValues
bool nodeValues() const
Force use of values per node instead of per element.
Definition: ensightCaseI.H:60
Foam::GeometricField< Type, fvPatchField, volMesh >