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 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 ensightParts
31 
32 SourceFiles
33  writeVolFields.H
34 
35 \*---------------------------------------------------------------------------*/
36 
37 #ifndef writeVolFields_H
38 #define writeVolFields_H
39 
40 #include "readFields.H"
41 #include "fvMesh.H"
42 
43 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
44 
45 namespace Foam
46 {
47 
48 template<class Type>
49 bool writeVolField
50 (
51  ensightCase& ensCase,
52  const ensightParts& ensParts,
53  const fvMesh& mesh,
55 )
56 {
57  if (!tfield.valid())
58  {
59  return false;
60  }
61 
62  const auto& field = tfield();
63 
64  autoPtr<ensightFile> os = ensCase.newData<Type>(field.name());
65 
66  // Currently serial only
67  bool wrote = ensightOutput::Serial::writeVolField<Type>
68  (
69  field,
70  ensParts,
71  os.ref()
72  );
73 
74  tfield.clear();
75  return wrote;
76 }
77 
78 
79 template<class Type>
81 (
82  ensightCase& ensCase,
83  const ensightParts& ensParts,
84  const fvMesh& mesh,
85  const IOobjectList& objects
86 )
87 {
89 
90  label count = 0;
91 
92  for (const word& fieldName : objects.sortedNames<GeoField>())
93  {
94  if
95  (
96  writeVolField<Type>
97  (
98  ensCase,
99  ensParts,
100  mesh,
101  getField<GeoField>(objects.findObject(fieldName), mesh)
102  )
103  )
104  {
105  Info<< ' ' << fieldName;
106  ++count;
107  }
108  }
109 
110  return count;
111 }
112 
113 
115 (
116  ensightCase& ensCase,
117  const ensightParts& ensParts,
118  const fvMesh& mesh,
119  const IOobjectList& objects
120 )
121 {
122  #undef foamToEnsight_WRITE_FIELD
123  #define foamToEnsight_WRITE_FIELD(PrimitiveType) \
124  writeVolFields<PrimitiveType> \
125  ( \
126  ensCase, ensParts, \
127  mesh, \
128  objects \
129  )
130 
131  label count = 0;
132  count += foamToEnsight_WRITE_FIELD(scalar);
137 
138  #undef foamToEnsight_WRITE_FIELD
139  return count;
140 }
141 
142 } // End namespace Foam
143 
144 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
145 
146 #endif
147 
148 // ************************************************************************* //
Foam::ensightParts
A collection of several ensightPart elements.
Definition: ensightParts.H:54
Foam::Tensor< scalar >
Foam::SymmTensor< scalar >
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:62
Foam::ensightCase::newData
autoPtr< ensightFile > newData(const word &varName) const
Open stream for new data file (on master), with current index.
Foam::tmp
A class for managing temporary objects.
Definition: PtrList.H:59
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::label
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:62
Foam::writeVolField
bool writeVolField(ensightCase &ensCase, const ensightMesh &ensMesh, const fvMeshSubsetProxy &proxy, const tmp< GeometricField< Type, fvPatchField, volMesh >> &tfield, const bool nodeValues)
Definition: writeVolFields.H:50
Foam::Info
messageStream Info
Information stream (uses stdout - output is on the master only)
Foam::writeAllVolFields
label writeAllVolFields(ensightCase &ensCase, const ensightMesh &ensMesh, const fvMeshSubsetProxy &proxy, const IOobjectList &objects, const bool nodeValues)
Definition: writeVolFields.H:118
field
rDeltaTY field()
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:6
Foam::fvMesh
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:84
fvMesh.H
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
readFields.H
Read fields from disk for foamToEnsight.
Foam::SphericalTensor< scalar >
Foam::IOobjectList
List of IOobjects with searching and retrieving facilities.
Definition: IOobjectList.H:55
Foam::ensightCase
Supports writing of ensight cases as well as providing common factory methods to open new files.
Definition: ensightCase.H:63
Foam::writeVolFields
label writeVolFields(ensightCase &ensCase, const ensightMesh &ensMesh, const fvMeshSubsetProxy &proxy, const IOobjectList &objects, const bool nodeValues)
Definition: writeVolFields.H:82
Foam::autoPtr
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition: HashPtrTable.H:53
foamToEnsight_WRITE_FIELD
#define foamToEnsight_WRITE_FIELD(PrimitiveType)
Foam::BitOps::count
unsigned int count(const UList< bool > &bools, const bool val=true)
Count number of 'true' entries.
Definition: BitOps.H:74
Foam::Vector< scalar >
Foam::GeometricField< Type, fvPatchField, volMesh >
Foam::autoPtr::ref
T & ref()
Return reference to the managed object without nullptr checking.
Definition: autoPtrI.H:128