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-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 InNamespace
27  Foam
28 
29 Description
30  Read volume fields from disk and write with ensightMesh
31 
32 SourceFiles
33 
34 \*---------------------------------------------------------------------------*/
35 
36 #ifndef ensight_writeVolFields_H
37 #define ensight_writeVolFields_H
38 
39 #include "readFields.H"
40 #include "fvMesh.H"
41 
42 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
43 
44 namespace Foam
45 {
46 
47 template<class Type>
48 bool writeVolField
49 (
50  ensightCase& ensCase,
51  const ensightMesh& ensMesh,
53  const bool nearCellValue = false
54 )
55 {
56  if (!tfield.valid())
57  {
58  return false;
59  }
60  else if (nearCellValue)
61  {
62  auto tzgrad = makeZeroGradientField<Type>(tfield);
63 
64  // Recursive call
65  return writeVolField
66  (
67  ensCase,
68  ensMesh,
69  tzgrad,
70  false // No nearCellValue, we already have zero-gradient
71  );
72  }
73 
74  const auto& field = tfield();
75 
76  // Forced use of node values?
77  const bool nodeValues = ensCase.nodeValues();
78 
80  ensCase.newData<Type>(field.name(), nodeValues);
81 
82  bool wrote = ensightOutput::writeVolField<Type>
83  (
84  os.ref(),
85  field,
86  ensMesh,
87  nodeValues
88  );
89 
90  tfield.clear();
91  return wrote;
92 }
93 
94 
95 template<class Type>
96 label writeVolFields
97 (
98  ensightCase& ensCase,
99  const ensightMesh& ensMesh,
100  const IOobjectList& objects,
101  const bool nearCellValue = false
102 )
103 {
105 
106  const fvMesh& mesh = dynamicCast<const fvMesh>(ensMesh.mesh());
107 
108  label count = 0;
109 
110  for (const word& fieldName : objects.sortedNames<GeoField>())
111  {
112  if
113  (
114  writeVolField<Type>
115  (
116  ensCase,
117  ensMesh,
118  getField<GeoField>(objects.findObject(fieldName), mesh),
119  nearCellValue
120  )
121  )
122  {
123  Info<< ' ' << fieldName;
124  ++count;
125  }
126  }
127 
128  return count;
129 }
130 
131 
132 label writeAllVolFields
133 (
134  ensightCase& ensCase,
135  const ensightMesh& ensMesh,
136  const IOobjectList& objects,
137  const bool nearCellValue = false
138 )
139 {
140  #undef ensight_WRITE_FIELD
141  #define ensight_WRITE_FIELD(PrimitiveType) \
142  writeVolFields<PrimitiveType> \
143  ( \
144  ensCase, \
145  ensMesh, \
146  objects, \
147  nearCellValue \
148  )
149 
150  label count = 0;
151  count += ensight_WRITE_FIELD(scalar);
156 
157  #undef ensight_WRITE_FIELD
158  return count;
159 }
160 
161 } // End namespace Foam
162 
163 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
164 
165 #endif
166 
167 // ************************************************************************* //
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:62
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::writeVolField
bool writeVolField(ensightCase &ensCase, const ensightMesh &ensMesh, const tmp< GeometricField< Type, fvPatchField, volMesh >> &tfield, const bool nearCellValue=false)
Definition: writeVolFields.H:49
Foam::Info
messageStream Info
Information stream (uses stdout - output is on the master only)
Foam::writeAllVolFields
label writeAllVolFields(ensightCase &ensCase, const ensightMesh &ensMesh, const IOobjectList &objects, const bool nearCellValue=false)
Definition: writeVolFields.H:133
field
rDeltaTY field()
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:6
Foam::fvMesh
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:83
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:97
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::autoPtr::ref
T & ref()
Return reference to the managed object without nullptr checking.
Definition: autoPtr.H:167
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 >
Foam::ensightMesh::mesh
const polyMesh & mesh() const
Reference to the underlying polyMesh.
Definition: ensightMeshI.H:30