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