writePointFields.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) 2020 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 point fields from disk
31  and write as ensight data
32 
33 SourceFiles
34 
35 \*---------------------------------------------------------------------------*/
36 
37 #ifndef ensight_writePointFields_H
38 #define ensight_writePointFields_H
39 
40 #include "readFields.H"
41 #include "ensightMesh.H"
42 #include "fvMesh.H"
43 
44 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
45 
46 namespace Foam
47 {
48 
49 template<class Type>
50 bool writePointField
51 (
52  ensightCase& ensCase,
53  const ensightMesh& ensMesh,
55 )
56 {
57  if (!tfield.valid())
58  {
59  return false;
60  }
61 
62  const auto& field = tfield();
63 
64  // PointData = true
65  autoPtr<ensightFile> os = ensCase.newData<Type>(field.name(), true);
66 
67  bool wrote = ensightOutput::writePointField<Type>
68  (
69  os.ref(),
70  field,
71  ensMesh
72  );
73 
74  tfield.clear();
75  return wrote;
76 }
77 
78 
79 template<class Type>
80 label writePointFields
81 (
82  ensightCase& ensCase,
83  const ensightMesh& ensMesh,
84  const IOobjectList& objects
85 )
86 {
88 
89  const pointMesh& ptMesh = pointMesh::New(ensMesh.mesh());
90 
91  label count = 0;
92 
93  for (const word& fieldName : objects.sortedNames<GeoField>())
94  {
95  if
96  (
97  writePointField<Type>
98  (
99  ensCase,
100  ensMesh,
101  getField<GeoField>(ptMesh, objects, fieldName)
102  )
103  )
104  {
105  Info<< ' ' << fieldName;
106  ++count;
107  }
108  }
109 
110  return count;
111 }
112 
113 
115 (
116  ensightCase& ensCase,
117  const ensightMesh& ensMesh,
118  const IOobjectList& objects
119 )
120 {
121  #undef ensight_WRITE_FIELD
122  #define ensight_WRITE_FIELD(PrimitiveType) \
123  writePointFields<PrimitiveType> \
124  ( \
125  ensCase, \
126  ensMesh, \
127  objects \
128  )
129 
130  label count = 0;
131  count += ensight_WRITE_FIELD(scalar);
136 
137  #undef ensight_WRITE_FIELD
138  return count;
139 }
140 
141 } // End namespace Foam
142 
143 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
144 
145 #endif
146 
147 // ************************************************************************* //
Foam::Tensor< scalar >
Foam::ensightCase::newData
autoPtr< ensightFile > newData(const word &varName, const bool isPointData=false) const
Open stream for new data file (on master), with current index.
Foam::ensightMesh
Encapsulation of volume meshes for writing in ensight format. It manages cellZones,...
Definition: ensightMesh.H:82
Foam::SymmTensor< scalar >
Foam::writePointFields
label writePointFields(ensightCase &ensCase, const ensightMesh &ensMesh, const IOobjectList &objects)
Definition: writePointFields.H:81
readFields.H
Helper routines for reading a field or fields, for foamToEnsight.
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:62
Foam::tmp
A class for managing temporary objects.
Definition: PtrList.H:61
Foam::MeshObject< polyMesh, UpdateableMeshObject, pointMesh >::New
static const pointMesh & New(const polyMesh &mesh, Args &&... args)
Get existing or create a new MeshObject.
Definition: MeshObject.C:48
Foam::IOobjectList::sortedNames
wordList sortedNames() const
The sorted names of the IOobjects.
Definition: IOobjectList.C:345
ensightMesh.H
ensight_WRITE_FIELD
#define ensight_WRITE_FIELD(PrimitiveType)
Foam::Info
messageStream Info
Information stream (uses stdout - output is on the master only)
field
rDeltaTY field()
Foam::writePointField
bool writePointField(ensightCase &ensCase, const ensightMesh &ensMesh, const tmp< GeometricField< Type, pointPatchField, pointMesh >> &tfield)
Definition: writePointFields.H:51
fvMesh.H
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::pointMesh
Mesh representing a set of points created from polyMesh.
Definition: pointMesh.H:50
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:67
Foam::autoPtr
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition: HashPtrTable.H:53
Foam::autoPtr::ref
T & ref()
Return reference to the managed object without nullptr checking.
Definition: autoPtr.H:167
Foam::BitOps::count
unsigned int count(const UList< bool > &bools, const bool val=true)
Count number of 'true' entries.
Definition: BitOps.H:77
Foam::Vector< scalar >
Foam::GeometricField
Generic GeometricField class.
Definition: areaFieldsFwd.H:53
Foam::ensightMesh::mesh
const polyMesh & mesh() const
Reference to the underlying polyMesh.
Definition: ensightMeshI.H:30
Foam::writeAllPointFields
label writeAllPointFields(ensightCase &ensCase, const ensightMesh &ensMesh, const IOobjectList &objects)
Definition: writePointFields.H:115