ensightFile.H 6.28 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 40 41
#ifndef ensightFile_H
#define ensightFile_H

#include "OFstream.H"
#include "IOstream.H"

42 43
#include "ensightFileName.H"
#include "ensightVarName.H"
44
#include "UList.H"
45

46 47
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

48 49 50 51
namespace Foam
{

/*---------------------------------------------------------------------------*\
52
                         Class ensightFile Declaration
53 54 55 56 57 58
\*---------------------------------------------------------------------------*/

class ensightFile
:
    public OFstream
{
Mark Olesen's avatar
Mark Olesen committed
59
    // Private Data
60

61
        //- Allow undef in results
62
        static bool allowUndef_;
63

64
        //- Value to represent undef in results
65
        static scalar undefValue_;
66

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

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

73

74
    // Private Member Functions
75

76 77 78
        //- Initialize by setting the ASCII output formatting
        void initialize();

79 80 81 82
        //- No copy construct
        ensightFile(const ensightFile&) = delete;

        //- No copy assignment
83
        void operator=(const ensightFile&) = delete;
84

85 86

public:
87

Mark Olesen's avatar
Mark Olesen committed
88
    // Static Functions
89 90 91 92 93 94

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


97 98
    // Constructors

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

107 108 109 110 111 112 113 114 115
        //- 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
        );

116

117
    //- Destructor
118
    ~ensightFile() = default;
119

120 121

    // Access
122

123 124 125
        //- Return setting for whether 'undef' values are allowed in results
        static bool allowUndef();

126
        //- The '*' mask appropriate for subDir
127 128
        static string mask();

129
        //- Consistent zero-padded numbers for subdirectories
130 131
        static string subDir(const label);

132 133 134 135 136 137 138
        //- 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();

139

140
    // Edit
141

142 143
        //- Enable/disable use of \c undef keyword and value
        static bool allowUndef(bool enabled);
144 145 146 147

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

150

151 152
    // Output

153 154 155
        //- Inherit write from Ostream
        using Ostream::write;

156
        //- Binary write
157
        virtual Ostream& write(const char* buf, std::streamsize count);
158

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

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

165
        //- Write undef value
166 167
        Ostream& writeUndef();

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

171
        //- Write string as "%79s" or as binary (max 80 chars)
172
        Ostream& write(const string&);
173

174
        //- Write integer as "%10d" or as binary
175
        Ostream& write(const label);
176

177
        //- Write integer with specified width or as binary
178
        Ostream& write(const label, const label fieldWidth);
179

180
        //- Write float as "%12.5e" or as binary
181
        Ostream& write(const scalar);
182 183 184

        //- Add carriage return to ascii stream
        void newline();
185 186 187 188


    // Convenience Output Methods

189
        //- Begin a part (0-based index internally).
190 191 192 193 194
        void beginPart(const label index);

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

195 196 197
        //- Write a list of integers as float values
        void writeList(const UList<label>& field);

198 199 200 201 202 203
        //- 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)
204
        void writeList(const UList<scalar>& field, const labelUList& addr);
205 206 207 208 209 210 211
};


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

} // End namespace Foam

212 213
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

214 215 216
#endif

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