Loading...
Searching...
No Matches
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-2025 OpenCFD Ltd.
9-------------------------------------------------------------------------------
10License
11 This file is part of OpenFOAM, distributed under GPL-3.0-or-later.
12
13InNamespace
14 Foam
15
16Description
17 Read volume fields from disk and write with ensightMesh
18
19\*---------------------------------------------------------------------------*/
20
21#ifndef FoamToEnsight_writeVolFields_H
22#define FoamToEnsight_writeVolFields_H
23
24#include "readFields.H"
25#include "fvMesh.H"
26
27// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
28
29namespace Foam
30{
31
32template<class Type>
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
68 (
69 os.ref(),
70 field,
71 ensMesh,
72 nodeValues
73 );
74
75 tfield.clear();
76 return wrote;
77}
78
79
80template<class Type>
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 (
100 (
101 ensCase,
102 ensMesh,
104 nearCellValue
105 )
106 )
107 {
108 Info<< ' ' << io.name();
109 ++count;
110 }
111 }
112
113 return count;
114}
115
116
118(
119 ensightCase& ensCase,
120 const ensightMesh& ensMesh,
121 const IOobjectList& objects,
122 const bool nearCellValue = false
123)
124{
125 label count = 0;
126 const label total = objects.size();
127 do
128 {
129 #undef doLocalWriteCode
130 #define doLocalWriteCode(Type) \
131 { \
132 count += writeVolFields<Type> \
133 ( \
134 ensCase, \
135 ensMesh, \
136 objects, \
137 nearCellValue \
138 ); \
139 if (count >= total) break; /* early exit */ \
140 }
141
142 doLocalWriteCode(scalar);
147
148 #undef doLocalWriteCode
149 }
150 while (false);
151
152 return count;
153}
154
155} // End namespace Foam
156
157// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
158
159#endif
160
161// ************************************************************************* //
Helper routines for reading a field or fields, for foamToEnsight.
label size() const noexcept
The number of elements in table.
Definition HashTable.H:358
List of IOobjects with searching and retrieving facilities. Implemented as a HashTable,...
UPtrList< const IOobject > csorted() const
The sorted list of IOobjects with headerClassName == Type::typeName.
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition IOobject.H:191
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition autoPtr.H:65
Supports writing of ensight cases as well as providing common factory methods to open new files.
Definition ensightCase.H:64
autoPtr< ensightFile > newData(const word &varName, const bool isPointData=false) const
Open stream for new data file (on master), with current index.
bool nodeValues() const
Force use of values per node instead of per element.
Encapsulation of volume meshes for writing in ensight format. It manages cellZones,...
Definition ensightMesh.H:79
const polyMesh & mesh() const noexcept
Reference to the underlying polyMesh.
A class for managing temporary objects.
Definition tmp.H:75
rDeltaTY field()
dynamicFvMesh & mesh
OBJstream os(runTime.globalPath()/outputName)
const auto & io
#define doLocalWriteCode(Type)
bool writeVolField(ensightOutput::floatBufferType &scratch, ensightFile &os, const GeometricField< Type, fvPatchField, volMesh > &vf, const ensightMesh &ensMesh)
Write volume field component-wise.
Namespace for OpenFOAM.
Type & refCast(U &obj)
A dynamic_cast (for references) to Type reference.
Definition typeInfo.H:172
GeometricField< Type, fvPatchField, volMesh > VolumeField
A volume field for a given type.
label writeAllVolFields(ensightCase &ensCase, const ensightMesh &ensMesh, const IOobjectList &objects, const bool nearCellValue=false)
label writeVolFields(ensightCase &ensCase, const ensightMesh &ensMesh, const IOobjectList &objects, const bool nearCellValue=false)
messageStream Info
Information stream (stdout output on master, null elsewhere).
Tensor< scalar > tensor
Definition symmTensor.H:57
bool writeVolField(ensightCase &ensCase, const ensightMesh &ensMesh, const tmp< VolumeField< Type > > &tfield, const bool nearCellValue=false)
tmp< VolumeField< Type > > makeZeroGradientField(const tmp< VolumeInternalField< Type > > &tdf)
Convert an internal field to zero-gradient volume field.
Definition readFields.H:101
Vector< scalar > vector
Definition vector.H:57
SphericalTensor< scalar > sphericalTensor
SphericalTensor of scalars, i.e. SphericalTensor<scalar>.
tmp< GeoField > getField(const IOobject &io, const typename GeoField::Mesh &mesh)
Get the field or FatalError.
Definition readFields.H:51
SymmTensor< scalar > symmTensor
SymmTensor of scalars, i.e. SymmTensor<scalar>.
Definition symmTensor.H:55