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-2022 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 ensight_writeVolFields_H
22#define ensight_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
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
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 fvMesh& mesh = dynamicCast<const fvMesh>(ensMesh.mesh());
92
93 label count = 0;
94
95 for (const word& fieldName : objects.sortedNames<FieldType>())
96 {
97 if
98 (
99 writeVolField<Type>
100 (
101 ensCase,
102 ensMesh,
103 getField<FieldType>(objects.findObject(fieldName), mesh),
104 nearCellValue
105 )
106 )
107 {
108 Info<< ' ' << fieldName;
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 #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);
137 count += ensight_WRITE_FIELD(vector);
140 count += ensight_WRITE_FIELD(tensor);
141
142 #undef ensight_WRITE_FIELD
143 return count;
144}
145
146} // End namespace Foam
147
148// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
149
150#endif
151
152// ************************************************************************* //
Generic GeometricField class.
List of IOobjects with searching and retrieving facilities.
Definition: IOobjectList.H:59
const IOobject * findObject(const word &objName) const
Return const pointer to the object found by name.
Definition: IOobjectList.C:293
wordList sortedNames() const
The sorted names of the IOobjects.
Definition: IOobjectList.C:383
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition: autoPtr.H:66
Supports writing of ensight cases as well as providing common factory methods to open new files.
Definition: ensightCase.H:69
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.
Definition: ensightCaseI.H:60
Encapsulation of volume meshes for writing in ensight format. It manages cellZones,...
Definition: ensightMesh.H:83
const polyMesh & mesh() const noexcept
Reference to the underlying polyMesh.
Definition: ensightMesh.H:159
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:91
A class for managing temporary objects.
Definition: tmp.H:65
A class for handling words, derived from Foam::string.
Definition: word.H:68
rDeltaTY field()
dynamicFvMesh & mesh
OBJstream os(runTime.globalPath()/outputName)
#define ensight_WRITE_FIELD(PrimitiveType)
unsigned int count(const UList< bool > &bools, const bool val=true)
Count number of 'true' entries.
Definition: BitOps.H:78
Namespace for OpenFOAM.
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)
bool writeVolField(ensightCase &ensCase, const ensightMesh &ensMesh, const tmp< VolumeField< Type > > &tfield, const bool nearCellValue=false)