ensightSurfaceWriter.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 | Copyright (C) 2011-2013 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
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.
15 
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.
20 
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/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
26 #include "ensightSurfaceWriter.H"
27 
28 #include "OFstream.H"
29 #include "OSspecific.H"
30 #include "IOmanip.H"
31 #include "ensightPartFaces.H"
32 #include "ensightPTraits.H"
33 
35 
36 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
37 
38 namespace Foam
39 {
40  makeSurfaceWriterType(ensightSurfaceWriter);
41  addToRunTimeSelectionTable(surfaceWriter, ensightSurfaceWriter, wordDict);
42 }
43 
44 
45 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
46 
47 template<class Type>
48 void Foam::ensightSurfaceWriter::writeTemplate
49 (
50  const fileName& outputDir,
51  const fileName& surfaceName,
52  const pointField& points,
53  const faceList& faces,
54  const word& fieldName,
55  const Field<Type>& values,
56  const bool isNodeValues,
57  const bool verbose
58 ) const
59 {
60  if (!isDir(outputDir/fieldName))
61  {
62  mkDir(outputDir/fieldName);
63  }
64 
65  // const scalar timeValue = Foam::name(this->mesh().time().timeValue());
66  const scalar timeValue = 0.0;
67 
68  OFstream osCase(outputDir/fieldName/surfaceName + ".case");
69  ensightGeoFile osGeom
70  (
71  outputDir/fieldName/surfaceName + ".000.mesh",
72  writeFormat_
73  );
74  ensightFile osField
75  (
76  outputDir/fieldName/surfaceName + ".000." + fieldName,
77  writeFormat_
78  );
79 
80  if (verbose)
81  {
82  Info<< "Writing case file to " << osCase.name() << endl;
83  }
84 
85  osCase
86  << "FORMAT" << nl
87  << "type: ensight gold" << nl
88  << nl
89  << "GEOMETRY" << nl
90  << "model: 1 " << osGeom.name().name() << nl
91  << nl
92  << "VARIABLE" << nl
93  << ensightPTraits<Type>::typeName << " per "
94  << word(isNodeValues ? "node:" : "element:") << setw(10) << 1
95  << " " << fieldName
96  << " " << surfaceName.c_str() << ".***." << fieldName << nl
97  << nl
98  << "TIME" << nl
99  << "time set: 1" << nl
100  << "number of steps: 1" << nl
101  << "filename start number: 0" << nl
102  << "filename increment: 1" << nl
103  << "time values:" << nl
104  << timeValue << nl
105  << nl;
106 
107  ensightPartFaces ensPart(0, osGeom.name().name(), points, faces, true);
108  osGeom << ensPart;
109 
110  // Write field
111  osField.writeKeyword(ensightPTraits<Type>::typeName);
112  ensPart.writeField(osField, values, isNodeValues);
113 }
114 
115 
116 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
117 
119 :
120  surfaceWriter(),
121  writeFormat_(IOstream::ASCII)
122 {}
123 
124 
126 :
127  surfaceWriter(),
128  writeFormat_(IOstream::ASCII)
129 {
130  // choose ascii or binary format
131  if (options.found("format"))
132  {
133  writeFormat_ = IOstream::formatEnum(options.lookup("format"));
134  }
135 }
136 
137 
138 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
139 
141 {}
142 
143 
144 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
145 
147 (
148  const fileName& outputDir,
149  const fileName& surfaceName,
150  const pointField& points,
151  const faceList& faces,
152  const bool verbose
153 ) const
154 {
155  if (!isDir(outputDir))
156  {
157  mkDir(outputDir);
158  }
159 
160  // const scalar timeValue = Foam::name(this->mesh().time().timeValue());
161  const scalar timeValue = 0.0;
162 
163  OFstream osCase(outputDir/surfaceName + ".case");
164  ensightGeoFile osGeom
165  (
166  outputDir/surfaceName + ".000.mesh",
167  writeFormat_
168  );
169 
170  if (verbose)
171  {
172  Info<< "Writing case file to " << osCase.name() << endl;
173  }
174 
175  osCase
176  << "FORMAT" << nl
177  << "type: ensight gold" << nl
178  << nl
179  << "GEOMETRY" << nl
180  << "model: 1 " << osGeom.name().name() << nl
181  << nl
182  << "TIME" << nl
183  << "time set: 1" << nl
184  << "number of steps: 1" << nl
185  << "filename start number: 0" << nl
186  << "filename increment: 1" << nl
187  << "time values:" << nl
188  << timeValue << nl
189  << nl;
190 
191  ensightPartFaces ensPart(0, osGeom.name().name(), points, faces, true);
192  osGeom << ensPart;
193 }
194 
195 
196 // create write methods
198 
199 
200 // ************************************************************************* //
Output to file stream.
Definition: OFstream.H:81
bool found(const word &, bool recursive=false, bool patternMatch=true) const
Search dictionary for given keyword.
Definition: dictionary.C:306
const pointField & points
word name() const
Return file name (part beyond last /)
Definition: fileName.C:206
Specialized Ensight output with extra geometry file header.
Convenience macros for instantiating writer methods for surfaceWriter classes.
Functions used by OpenFOAM that are specific to POSIX compliant operating systems and need to be repl...
defineSurfaceWriterWriteFields(nastranSurfaceWriter)
messageStream Info
List< face > faceList
Definition: faceListFwd.H:43
An implementation of ensightPart to hold volume mesh faces.
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:137
vectorField pointField
pointField is a vectorField.
Definition: pointFieldFwd.H:42
Namespace for OpenFOAM.
ensightSurfaceWriter()
Construct null.
static const char nl
Definition: Ostream.H:260
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
static const char *const typeName
const fileName & name() const
Return the name of the stream.
Definition: OFstream.H:118
Base class for surface writers.
Definition: surfaceWriter.H:54
virtual void write(const fileName &outputDir, const fileName &surfaceName, const pointField &points, const faceList &faces, const bool verbose=false) const
Write single surface geometry to file.
virtual ~ensightSurfaceWriter()
Destructor.
Omanip< int > setw(const int i)
Definition: IOmanip.H:199
Istream and Ostream manipulators taking arguments.
static streamFormat formatEnum(const word &)
Return stream format of given format name.
Definition: IOstream.C:39
bool isDir(const fileName &)
Does the name exist as a DIRECTORY in the file system?
Definition: POSIX.C:616
virtual const fileName & name() const
Return the name of the stream.
Definition: IOstream.H:297
ITstream & lookup(const word &, bool recursive=false, bool patternMatch=true) const
Find and return an entry data stream.
Definition: dictionary.C:452
A class for handling file names.
Definition: fileName.H:69
makeSurfaceWriterType(dxSurfaceWriter)
bool mkDir(const fileName &, mode_t=0777)
Make a directory and return an error if it could not be created.
Definition: POSIX.C:420
A surfaceWriter for Ensight format.
addToRunTimeSelectionTable(ensightPart, ensightPartCells, istream)
An IOstream is an abstract base class for all input/output systems; be they streams, files, token lists etc.
Definition: IOstream.H:71