ensightBinaryStream.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2019 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 Class
25  Foam::ensightBinaryStream
26 
27 Description
28 
29 SourceFiles
30  ensightBinaryStream.C
31 
32 \*---------------------------------------------------------------------------*/
33 
34 #ifndef ensightBinaryStream_H
35 #define ensightBinaryStream_H
36 
37 #include "ensightStream.H"
38 
39 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
40 
41 namespace Foam
42 {
43 
44 /*---------------------------------------------------------------------------*\
45  Class ensightBinaryStream Declaration
46 \*---------------------------------------------------------------------------*/
47 
49 :
50  public ensightStream
51 {
52  // Private Data
53 
54  //- Description of data_
56 
57 
58 public:
59 
60  // Constructors
61 
62  //- Construct from components
63  ensightBinaryStream(const fileName& f, const Time&)
64  :
65  ensightStream(f),
66  str_
67  (
68  new std::ofstream
69  (
70  f.c_str(),
71  ios_base::out | ios_base::binary | ios_base::trunc
72  )
73  )
74  {}
75 
76  //- Disallow default bitwise copy construction
78 
79 
80  //- Destructor
81  virtual ~ensightBinaryStream()
82  {}
83 
84 
85  // Member Functions
86 
87  virtual bool ascii() const
88  {
89  return false;
90  }
91 
92  virtual void write(const char* val)
93  {
94  char buffer[80] = {0};
95  strcpy(buffer, val);
96  str_().write(buffer, 80*sizeof(char));
97  }
98 
99  virtual void write(const int val)
100  {
101  str_().write(reinterpret_cast<const char*>(&val), sizeof(int));
102  }
104  virtual void write(const scalarField& sf)
105  {
106  if (sf.size())
107  {
108  List<float> temp(sf.size());
109 
110  forAll(sf, i)
111  {
112  temp[i] = float(sf[i]);
113  }
114 
115  str_().write
116  (
117  reinterpret_cast<const char*>(temp.begin()),
118  sf.size()*sizeof(float)
119  );
120  }
121  }
123  virtual void write(const List<int>& sf)
124  {
125  str_().write
126  (
127  reinterpret_cast<const char*>(sf.begin()),
128  sf.size()*sizeof(int)
129  );
130  }
132  virtual void writePartHeader(const label partI)
133  {
134  write("part");
135  write(partI);
136  }
137 
138 
139  // Member Operators
140 
141  //- Disallow default bitwise assignment
142  void operator=(const ensightBinaryStream&) = delete;
143 };
144 
145 
146 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
147 
148 } // End namespace Foam
149 
150 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
151 
152 #endif
153 
154 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
ensightBinaryStream(const fileName &f, const Time &)
Construct from components.
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:59
A class for handling file names.
Definition: fileName.H:79
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: HashTable.H:59
void size(const label)
Override size to be inconsistent with allocated storage.
Definition: ListI.H:163
virtual void writePartHeader(const label partI)
Abstract base class for writing Ensight data.
Definition: ensightStream.H:50
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:68
iterator begin()
Return an iterator to begin traversing the UList.
Definition: UListI.H:216
virtual void write(const char *val)
labelList f(nPoints)
virtual bool ascii() const
volScalarField sf(fieldObject, mesh)
void operator=(const ensightBinaryStream &)=delete
Disallow default bitwise assignment.
virtual ~ensightBinaryStream()
Destructor.
Namespace for OpenFOAM.