ensightFile.H 8.15 KB
Newer Older
1 2 3 4
/*---------------------------------------------------------------------------*\
  =========                 |
  \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
   \\    /   O peration     |
OpenFOAM bot's avatar
OpenFOAM bot committed
5
    \\  /    A nd           | www.openfoam.com
OpenFOAM bot's avatar
OpenFOAM bot committed
6 7
     \\/     M anipulation  |
-------------------------------------------------------------------------------
OpenFOAM bot's avatar
OpenFOAM bot committed
8
    Copyright (C) 2011-2015 OpenFOAM Foundation
Mark Olesen's avatar
Mark Olesen committed
9
    Copyright (C) 2016-2020 OpenCFD Ltd.
10 11 12 13
-------------------------------------------------------------------------------
License
    This file is part of OpenFOAM.

14 15 16 17
    OpenFOAM is free software: you can redistribute it and/or modify it
    under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.
18 19 20 21 22 23 24

    OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    for more details.

    You should have received a copy of the GNU General Public License
25
    along with OpenFOAM.  If not, see <http://www.gnu.org/licenses/>.
26 27 28 29 30 31 32 33 34

Class
    Foam::ensightFile

Description
    Ensight output with specialized write() for strings, integers and floats.
    Correctly handles binary write as well.

\*---------------------------------------------------------------------------*/
35

36 37 38 39
#ifndef ensightFile_H
#define ensightFile_H

#include "OFstream.H"
40 41
#include "ensightFileName.H"
#include "ensightVarName.H"
42
#include "IndirectListBase.H"
43

44 45
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

46 47 48 49
namespace Foam
{

/*---------------------------------------------------------------------------*\
50
                         Class ensightFile Declaration
51 52 53 54 55 56
\*---------------------------------------------------------------------------*/

class ensightFile
:
    public OFstream
{
Mark Olesen's avatar
Mark Olesen committed
57
    // Private Data
58

59
        //- Allow undef in results
60
        static bool allowUndef_;
61

62
        //- Value to represent undef in results (default: 1e+37, floatVGREAT)
63
        static scalar undefValue_;
64

65 66 67 68 69 70
        //- The '*' mask appropriate for subDir
        static string mask_;

        //- The printf format for zero-padded subdirectory numbers
        static string dirFmt_;

71

72
    // Private Member Functions
73

74 75 76
        //- Initialize by setting the ASCII output formatting
        void initialize();

77 78 79 80
        //- No copy construct
        ensightFile(const ensightFile&) = delete;

        //- No copy assignment
81
        void operator=(const ensightFile&) = delete;
82

83 84

public:
85

86 87 88 89 90 91
    // Static Data Members

        //- The keyword "coordinates"
        static const char* const coordinates;


Mark Olesen's avatar
Mark Olesen committed
92
    // Static Functions
93 94 95 96 97 98

        //- Return a null ensightFile
        inline static const ensightFile& null()
        {
            return NullObjectRef<ensightFile>();
        }
99 100


101 102
    // Constructors

Mark Olesen's avatar
Mark Olesen committed
103 104 105
        //- Construct from pathName.
        //  The entire pathName is checked for valid ensight naming.
        explicit ensightFile
106 107 108 109 110
        (
            const fileName& pathname,
            IOstream::streamFormat format=IOstream::BINARY
        );

111 112 113 114 115 116 117 118 119
        //- Construct from path and name.
        //  Only the name portion is checked for valid ensight naming.
        ensightFile
        (
            const fileName& path,
            const fileName& name,
            IOstream::streamFormat format=IOstream::BINARY
        );

120

121
    //- Destructor
122
    ~ensightFile() = default;
123

124

125 126
    // Member Functions

127
    // Access
128

129 130 131
        //- Return setting for whether 'undef' values are allowed in results
        static bool allowUndef();

132
        //- The '*' mask appropriate for subDir
133 134
        static string mask();

135
        //- Consistent zero-padded numbers for subdirectories
136 137
        static string subDir(const label);

138 139 140 141 142 143 144
        //- Set width of subDir and mask. Default width is 8 digits.
        //  Max width is 31 digits.
        static void subDirWidth(const label);

        //- Return current width of subDir and mask.
        static label subDirWidth();

145

146
    // Edit
147

148 149
        //- Enable/disable use of \c undef keyword and value
        static bool allowUndef(bool enabled);
150 151 152 153

        //- Assign the value to represent undef in the results
        //  Returns the previous value
        //  NB: do not use values larger than floatScalarVGREAT
154
        static scalar undefValue(const scalar value);
155

156

157 158
    // Output

159 160
        //- Write element keyword with trailing newline,
        //- optionally with undef and the value for undefined
161
        virtual Ostream& writeKeyword(const keyType& key);
162

163
        //- Write "C Binary" string for binary files (eg, geometry/measured)
164 165
        Ostream& writeBinaryHeader();

166 167 168 169 170 171
        //- Write C-string as "%79s" or as binary (max 80 chars)
        Ostream& writeString(const char* str);

        //- Write string as "%79s" or as binary (max 80 chars)
        Ostream& writeString(const std::string& str);

172
        //- Write undef value
173 174
        Ostream& writeUndef();

175 176 177 178 179 180 181 182 183 184 185 186 187 188 189

        //- Writing token does not make sense
        virtual bool write(const token&)
        {
            NotImplemented;
            return false;
        }

        //- Writing single character does not make sense
        virtual Ostream& write(const char)
        {
            NotImplemented;
            return *this;
        }

190 191
        //- Binary write
        virtual Ostream& write(const char* buf, std::streamsize count);
192

193 194 195 196 197 198 199 200
        //- Write C-string, uses writeString()
        virtual Ostream& write(const char* str);

        //- Write word, uses writeString()
        virtual Ostream& write(const word& str);

        //- Write string, uses writeString()
        virtual Ostream& write(const string& str);
201

202
        //- Write integer as "%10d" or as binary
203 204 205 206
        virtual Ostream& write(const int32_t val);

        //- Write integer as "%10d" or as binary
        virtual Ostream& write(const int64_t val);
207

208
        //- Write integer with specified width or as binary
209
        Ostream& write(const label value, const label fieldWidth);
210

211 212 213 214 215
        //- Write floating-point as "%12.5e" or as binary
        virtual Ostream& write(const floatScalar val);

        //- Write floating-point as "%12.5e" or as binary
        virtual Ostream& write(const doubleScalar val);
216 217 218

        //- Add carriage return to ascii stream
        void newline();
219 220 221 222


    // Convenience Output Methods

223
        //- Begin a part (0-based index internally).
224 225 226 227 228
        void beginPart(const label index);

        //- Begin a "particle coordinates" block (measured data)
        void beginParticleCoordinates(const label nparticles);

229 230 231 232 233 234 235 236 237
        //- Write a list of integers
        //  With carriage return after each value (ascii stream)
        void writeLabels(const UList<label>& list);

        //- Write a list of integers
        //  With carriage return after each value (ascii stream)
        template<class Addr>
        void writeLabels(const IndirectListBase<label, Addr>& list);

238
        //- Write a list of integers as float values
239
        //  With carriage return after each value (ascii stream)
240 241
        void writeList(const UList<label>& field);

242 243 244 245 246 247
        //- Write a list of floats as "%12.5e" or as binary
        //  With carriage return after each value (ascii stream)
        void writeList(const UList<scalar>& field);

        //- Write an indirect list of scalars as "%12.5e" or as binary
        //  With carriage return after each value (ascii stream)
248 249 250 251 252 253 254 255 256 257 258 259
        template<class Addr>
        void writeList(const IndirectListBase<scalar, Addr>& field);


    // Other Methods

        //- Check for any NaN in the field
        static bool isUndef(const UList<scalar>& field);

        //- Check for any NaN in the field
        template<class Addr>
        static bool isUndef(const IndirectListBase<scalar, Addr>& field);
260 261 262 263 264 265 266
};


// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

} // End namespace Foam

267 268
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

269 270 271 272 273 274
#ifdef NoRepository
    #include "ensightFileTemplates.C"
#endif

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

275 276 277
#endif

// ************************************************************************* //