BUG: UListIO: byteSize overflowing on really big faceLists
[OpenFOAM-2.0.x.git] / src / sampling / sampledSurface / writers / ensight / ensightSurfaceWriter.C
blob9d4a65381976543e14b423442c9e8a177d72417a
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 2011 OpenFOAM Foundation
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
9     This file is part of OpenFOAM.
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.
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.
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/>.
24 \*---------------------------------------------------------------------------*/
26 #include "ensightSurfaceWriter.H"
28 #include "OFstream.H"
29 #include "OSspecific.H"
30 #include "IOmanip.H"
31 #include "ensightPartFaces.H"
33 #include "makeSurfaceWriterMethods.H"
35 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
37 namespace Foam
39     makeSurfaceWriterType(ensightSurfaceWriter);
40     addToRunTimeSelectionTable(surfaceWriter, ensightSurfaceWriter, wordDict);
44 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
46 template<class Type>
47 void Foam::ensightSurfaceWriter::writeTemplate
49     const fileName& outputDir,
50     const fileName& surfaceName,
51     const pointField& points,
52     const faceList& faces,
53     const word& fieldName,
54     const Field<Type>& values,
55     const bool isNodeValues,
56     const bool verbose
57 ) const
59     if (!isDir(outputDir/fieldName))
60     {
61         mkDir(outputDir/fieldName);
62     }
64     // const scalar timeValue = Foam::name(this->mesh().time().timeValue());
65     const scalar timeValue = 0.0;
67     OFstream osCase(outputDir/fieldName/surfaceName + ".case");
68     ensightGeoFile osGeom
69     (
70         outputDir/fieldName/surfaceName + ".000.mesh",
71         writeFormat_
72     );
73     ensightFile osField
74     (
75         outputDir/fieldName/surfaceName + ".000." + fieldName,
76         writeFormat_
77     );
79     if (verbose)
80     {
81         Info<< "Writing case file to " << osCase.name() << endl;
82     }
84     osCase
85         << "FORMAT" << nl
86         << "type: ensight gold" << nl
87         << nl
88         << "GEOMETRY" << nl
89         << "model:        1     " << osGeom.name().name() << nl
90         << nl
91         << "VARIABLE" << nl
92         << pTraits<Type>::typeName << " per "
93         << word(isNodeValues ? "node:" : "element:") << setw(10) << 1
94         << "       " << fieldName
95         << "       " << surfaceName.c_str() << ".***." << fieldName << nl
96         << nl
97         << "TIME" << nl
98         << "time set:                      1" << nl
99         << "number of steps:               1" << nl
100         << "filename start number:         0" << nl
101         << "filename increment:            1" << nl
102         << "time values:" << nl
103         << timeValue << nl
104         << nl;
106     ensightPartFaces ensPart(0, osGeom.name().name(), points, faces, true);
107     osGeom << ensPart;
109     // Write field
110     osField.writeKeyword(pTraits<Type>::typeName);
111     ensPart.writeField(osField, values, isNodeValues);
115 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
117 Foam::ensightSurfaceWriter::ensightSurfaceWriter()
119     surfaceWriter(),
120     writeFormat_(IOstream::ASCII)
124 Foam::ensightSurfaceWriter::ensightSurfaceWriter(const dictionary& options)
126     surfaceWriter(),
127     writeFormat_(IOstream::ASCII)
129     // choose ascii or binary format
130     if (options.found("format"))
131     {
132         writeFormat_ = IOstream::formatEnum(options.lookup("format"));
133     }
137 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
139 Foam::ensightSurfaceWriter::~ensightSurfaceWriter()
143 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
145 void Foam::ensightSurfaceWriter::write
147     const fileName& outputDir,
148     const fileName& surfaceName,
149     const pointField& points,
150     const faceList& faces,
151     const bool verbose
152 ) const
154     if (!isDir(outputDir))
155     {
156         mkDir(outputDir);
157     }
159     // const scalar timeValue = Foam::name(this->mesh().time().timeValue());
160     const scalar timeValue = 0.0;
162     OFstream osCase(outputDir/surfaceName + ".case");
163     ensightGeoFile osGeom
164     (
165         outputDir/surfaceName + ".000.mesh",
166         writeFormat_
167     );
169     if (verbose)
170     {
171         Info<< "Writing case file to " << osCase.name() << endl;
172     }
174     osCase
175         << "FORMAT" << nl
176         << "type: ensight gold" << nl
177         << nl
178         << "GEOMETRY" << nl
179         << "model:        1     " << osGeom.name().name() << nl
180         << nl
181         << "TIME" << nl
182         << "time set:                      1" << nl
183         << "number of steps:               1" << nl
184         << "filename start number:         0" << nl
185         << "filename increment:            1" << nl
186         << "time values:" << nl
187         << timeValue << nl
188         << nl;
190     ensightPartFaces ensPart(0, osGeom.name().name(), points, faces, true);
191     osGeom << ensPart;
195 // create write methods
196 defineSurfaceWriterWriteFields(Foam::ensightSurfaceWriter);
199 // ************************************************************************* //