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-2023 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<VolumeField<Type>>& tfield,
38  const bool nearCellValue = false
39 )
40 {
41  if (!tfield)
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 
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 VolumeField<Type> FieldType;
90 
91  const auto& mesh = refCast<const fvMesh>(ensMesh.mesh());
92 
93  label count = 0;
94 
95  for (const IOobject& io : objects.csorted<FieldType>())
96  {
97  if
98  (
99  writeVolField<Type>
100  (
101  ensCase,
102  ensMesh,
103  getField<FieldType>(io, mesh),
104  nearCellValue
105  )
106  )
107  {
108  Info<< ' ' << io.name();
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 // ************************************************************************* //
#define ensight_WRITE_FIELD(PrimitiveType)
rDeltaTY field()
List of IOobjects with searching and retrieving facilities. Implemented as a HashTable, so the various sorted methods should be used if traversing in parallel.
Definition: IOobjectList.H:55
const word & name() const noexcept
Return the object name.
Definition: IOobjectI.H:195
label writeAllVolFields(ensightCase &ensCase, const ensightMesh &ensMesh, const IOobjectList &objects, const bool nearCellValue=false)
Generic GeometricField class.
Definition: areaFieldsFwd.H:50
const polyMesh & mesh() const noexcept
Reference to the underlying polyMesh.
Definition: ensightMesh.H:191
unsigned int count(const UList< bool > &bools, const bool val=true)
Count number of &#39;true&#39; entries.
Definition: BitOps.H:73
dynamicFvMesh & mesh
A Vector of values with scalar precision, where scalar is float/double depending on the compilation f...
Encapsulation of volume meshes for writing in ensight format. It manages cellZones, facesZone, patches.
Definition: ensightMesh.H:78
OBJstream os(runTime.globalPath()/outputName)
bool writeVolField(ensightCase &ensCase, const ensightMesh &ensMesh, const tmp< VolumeField< Type >> &tfield, const bool nearCellValue=false)
Helper routines for reading a field or fields, for foamToEnsight.
messageStream Info
Information stream (stdout output on master, null elsewhere)
Pointer management similar to std::unique_ptr, with some additional methods and type checking...
Definition: HashPtrTable.H:48
IOobject io("surfaceFilmProperties", mesh.time().constant(), mesh, IOobject::READ_IF_PRESENT, IOobject::NO_WRITE, IOobject::NO_REGISTER)
A class for managing temporary objects.
Definition: HashPtrTable.H:50
Tensor of scalars, i.e. Tensor<scalar>.
Defines the attributes of an object for which implicit objectRegistry management is supported...
Definition: IOobject.H:172
UPtrList< const IOobject > csorted() const
The sorted list of IOobjects with headerClassName == Type::typeName.
Namespace for OpenFOAM.
label writeVolFields(ensightCase &ensCase, const ensightMesh &ensMesh, const IOobjectList &objects, const bool nearCellValue=false)