foamVtkAppendRawFormatter.C
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) 2016-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 \*---------------------------------------------------------------------------*/
27 
29 #include "foamVtkOutputOptions.H"
30 #include <limits>
31 
32 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
33 
34 const char* Foam::vtk::appendRawFormatter::name_ = "append";
35 const char* Foam::vtk::appendRawFormatter::encoding_ = "raw";
36 
38 Foam::vtk::appendRawFormatter::opts_(formatType::APPEND_BINARY);
39 
40 
41 // * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
42 
44 (
45  const char* s,
46  std::streamsize n
47 )
48 {
49  os().write(s, n);
50 }
51 
52 
53 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
54 
55 Foam::vtk::appendRawFormatter::appendRawFormatter(std::ostream& os)
56 :
57  formatter(os),
58  offset_(0)
59 {}
60 
61 
62 // * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
63 
66 {
67  return opts_;
68 }
69 
70 
72 {
73  return name_;
74 }
75 
76 
78 {
79  return encoding_;
80 }
81 
82 
83 uint64_t Foam::vtk::appendRawFormatter::offset(const uint64_t numbytes)
84 {
85  uint64_t prev = offset_;
86 
87  if (formatter::npos != numbytes)
88  {
89  offset_ += this->encodedLength(sizeof(uint64_t) + numbytes);
90  }
91  return prev;
92 }
93 
94 
95 bool Foam::vtk::appendRawFormatter::writeSize(const uint64_t numbytes)
96 {
97  write(reinterpret_cast<const char*>(&numbytes), sizeof(uint64_t));
98  return true;
99 }
100 
101 
103 {
104  write(reinterpret_cast<const char*>(&val), sizeof(uint8_t));
105 }
106 
107 
109 {
110  // std::cerr<<"label:" << sizeof(val) << "=" << val << '\n';
111  write(reinterpret_cast<const char*>(&val), sizeof(label));
112 }
113 
114 
116 {
117  // std::cerr<<"float:" << sizeof(val) << "=" << val << '\n';
118  write(reinterpret_cast<const char*>(&val), sizeof(float));
119 }
120 
121 
123 {
124  // std::cerr<<"double as float=" << val << '\n';
125 
126  // Limit range of double to float conversion
127  if (val >= std::numeric_limits<float>::max())
128  {
130  }
131  else if (val <= std::numeric_limits<float>::lowest())
132  {
133  write(std::numeric_limits<float>::lowest());
134  }
135  else
136  {
137  float copy(val);
138  write(copy);
139  }
140 }
141 
142 
144 {/*nop*/}
145 
146 
147 // ************************************************************************* //
Foam::vtk::outputOptions
Encapsulated combinations of output format options. This is primarily useful when defining the output...
Definition: foamVtkOutputOptions.H:59
s
gmvFile<< "tracers "<< particles.size()<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().x()<< " ";}gmvFile<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().y()<< " ";}gmvFile<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().z()<< " ";}gmvFile<< nl;forAll(lagrangianScalarNames, i){ word name=lagrangianScalarNames[i];IOField< scalar > s(IOobject(name, runTime.timeName(), cloud::prefix, mesh, IOobject::MUST_READ, IOobject::NO_WRITE))
Definition: gmvOutputSpray.H:25
Foam::vtk::appendRawFormatter::writeSize
virtual bool writeSize(const uint64_t numbytes)
Write leading size for binary output.
Definition: foamVtkAppendRawFormatter.C:95
Foam::vtk::appendRawFormatter::encoding
virtual const char * encoding() const
Output name for append encoding type ("raw")
Definition: foamVtkAppendRawFormatter.C:77
foamVtkAppendRawFormatter.H
n
label n
Definition: TABSMDCalcMethod2.H:31
Foam::vtk::appendRawFormatter::offset
virtual uint64_t offset(const uint64_t numbytes)
Increase the append data offset by numbytes and sizeof(uint64_t).
Definition: foamVtkAppendRawFormatter.C:83
Foam::max
label max(const labelHashSet &set, label maxValue=labelMin)
Find the max value in labelHashSet, optionally limited by second argument.
Definition: hashSets.C:47
Foam::vtk::appendRawFormatter::name
virtual const char * name() const
Output name for XML type ("append")
Definition: foamVtkAppendRawFormatter.C:71
os
OBJstream os(runTime.globalPath()/outputName)
Foam::vtk::appendRawFormatter::opts
virtual const outputOptions & opts() const
The output is APPEND_BINARY.
Definition: foamVtkAppendRawFormatter.C:65
foamVtkOutputOptions.H
Foam::vtk::appendRawFormatter::flush
virtual void flush()
A no-op for this format.
Definition: foamVtkAppendRawFormatter.C:143
Foam::vtk::appendRawFormatter::write
void write(const char *s, std::streamsize n)
Write.
Definition: foamVtkAppendRawFormatter.C:44
Foam::vtk::write
void write(vtk::formatter &fmt, const Type &val, const label n=1)
Component-wise write of a value (N times)
Definition: foamVtkOutputTemplates.C:36
Foam::vtk::formatter::npos
static constexpr uint64_t npos
Out of range position or size.
Definition: foamVtkFormatter.H:145
Foam::vtk::formatter
Abstract class for a VTK output stream formatter.
Definition: foamVtkFormatter.H:68