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 ensightMesh
31 
32 SourceFiles
33  writeVolFields.H
34 
35 \*---------------------------------------------------------------------------*/
36 
37 #ifndef writeVolFields_H
38 #define writeVolFields_H
39 
40 #include "readFields.H"
41 #include "fvMeshSubsetProxy.H"
42 
43 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
44 
45 namespace Foam
46 {
47 
48 template<class Type>
49 bool writeVolField
50 (
51  ensightCase& ensCase,
52  const ensightMesh& ensMesh,
53  const fvMeshSubsetProxy& proxy,
55  const bool nodeValues
56 )
57 {
58  if (!tfield.valid())
59  {
60  return false;
61  }
62 
63  const auto& field = tfield();
64 
65  autoPtr<ensightFile> os = ensCase.newData<Type>(field.name());
66 
67  bool wrote = ensightOutput::writeVolField<Type>
68  (
69  field,
70  ensMesh,
71  os.ref(),
72  nodeValues
73  );
74 
75  tfield.clear();
76  return wrote;
77 }
78 
79 
80 template<class Type>
82 (
83  ensightCase& ensCase,
84  const ensightMesh& ensMesh,
85  const fvMeshSubsetProxy& proxy,
86  const IOobjectList& objects,
87  const bool nodeValues
88 )
89 {
91 
92  label count = 0;
93 
94  for (const word& fieldName : objects.sortedNames<GeoField>())
95  {
96  if
97  (
98  writeVolField<Type>
99  (
100  ensCase,
101  ensMesh,
102  proxy,
103  getField<GeoField>(objects.findObject(fieldName), proxy),
104  nodeValues
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 fvMeshSubsetProxy& proxy,
122  const IOobjectList& objects,
123  const bool nodeValues
124 )
125 {
126  #undef foamToEnsight_WRITE_FIELD
127  #define foamToEnsight_WRITE_FIELD(PrimitiveType) \
128  writeVolFields<PrimitiveType> \
129  ( \
130  ensCase, ensMesh, \
131  proxy, \
132  objects, \
133  nodeValues \
134  )
135 
136  label count = 0;
137  count += foamToEnsight_WRITE_FIELD(scalar);
142 
143  #undef foamToEnsight_WRITE_FIELD
144  return count;
145 }
146 
147 } // End namespace Foam
148 
149 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
150 
151 #endif
152 
153 // ************************************************************************* //
Foam::Tensor< scalar >
Foam::ensightMesh
Encapsulation of volume meshes for writing in ensight format.
Definition: ensightMesh.H:68
Foam::SymmTensor< scalar >
readFields.H
Read fields from disk for foamToEnsight.
foamToEnsight_WRITE_FIELD
#define foamToEnsight_WRITE_FIELD(PrimitiveType)
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()
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
fvMeshSubsetProxy.H
Foam::SphericalTensor< scalar >
Foam::IOobjectList
List of IOobjects with searching and retrieving facilities.
Definition: IOobjectList.H:55
Foam::fvMeshSubsetProxy
Simple proxy for holding a mesh, or mesh-subset. The subMeshes are currently limited to cellSet or ce...
Definition: fvMeshSubsetProxy.H:58
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
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