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-------------------------------------------------------------------------------
10License
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
30#include <limits>
31
32// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
33
34const char* Foam::vtk::appendRawFormatter::name_ = "append";
35const char* Foam::vtk::appendRawFormatter::encoding_ = "raw";
36
38Foam::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
56:
57 vtk::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
83uint64_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
95bool 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 {
129 write(std::numeric_limits<float>::max());
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// ************************************************************************* //
label n
virtual bool write()
Write the output fields.
const vector & offset() const noexcept
Offset vector (from patch faces to destination mesh objects)
virtual bool writeSize(const uint64_t numbytes)
Write leading size for binary output.
virtual const vtk::outputOptions & opts() const
The output is APPEND_BINARY.
virtual const char * name() const
Output name for XML type ("append")
virtual void flush()
A no-op for this format.
virtual const char * encoding() const
Output name for append encoding type ("raw")
Abstract class for a VTK output stream formatter.
std::ostream & os() noexcept
Access to the underlying output stream.
static constexpr uint64_t npos
Out of range position or size.
Encapsulated combinations of output format options. This is primarily useful when defining the output...
OBJstream os(runTime.globalPath()/outputName)
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))
runTime write()