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-2020 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::Write
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
56 {
57  if (!isDir(outputDir/fieldName))
58  {
59  mkDir(outputDir/fieldName);
60  }
61 
62  // const scalar timeValue = Foam::name(this->mesh().time().timeValue());
63  const scalar timeValue = 0.0;
64 
65  OFstream osCase(outputDir/fieldName/surfaceName + ".case");
66  ensightGeoFile osGeom
67  (
68  outputDir/fieldName/surfaceName + ".000.mesh",
69  writeFormat_
70  );
71  ensightFile osField
72  (
73  outputDir/fieldName/surfaceName + ".000." + fieldName,
74  writeFormat_
75  );
76 
77  if (debug)
78  {
79  Info<< "Writing case file to " << osCase.name() << endl;
80  }
81 
82  osCase
83  << "FORMAT" << nl
84  << "type: ensight gold" << nl
85  << nl
86  << "GEOMETRY" << nl
87  << "model: 1 " << osGeom.name().name() << nl
88  << nl
89  << "VARIABLE" << nl
90  << ensightPTraits<Type>::typeName << " per "
91  << word(isNodeValues ? "node:" : "element:") << setw(10) << 1
92  << " " << fieldName
93  << " " << surfaceName.c_str() << ".***." << fieldName << nl
94  << nl
95  << "TIME" << nl
96  << "time set: 1" << nl
97  << "number of steps: 1" << nl
98  << "filename start number: 0" << nl
99  << "filename increment: 1" << nl
100  << "time values:" << nl
101  << timeValue << nl
102  << nl;
103 
104  ensightPartFaces ensPart(0, osGeom.name().name(), points, faces, true);
105  osGeom << ensPart;
106 
107  // Write field
108  osField.writeKeyword(ensightPTraits<Type>::typeName);
109  ensPart.writeField(osField, values, isNodeValues);
110 }
111 
112 
113 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
114 
116 (
117  const IOstream::streamFormat writeFormat
118 )
119 :
120  surfaceWriter(writeFormat)
121 {}
122 
123 
125 :
126  surfaceWriter(optDict)
127 {}
128 
129 
130 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
131 
133 {}
134 
135 
136 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
137 
139 (
140  const fileName& outputDir,
141  const fileName& surfaceName,
142  const pointField& points,
143  const faceList& faces
144 ) const
145 {
146  if (!isDir(outputDir))
147  {
148  mkDir(outputDir);
149  }
150 
151  // const scalar timeValue = Foam::name(this->mesh().time().timeValue());
152  const scalar timeValue = 0.0;
153 
154  OFstream osCase(outputDir/surfaceName + ".case");
155  ensightGeoFile osGeom
156  (
157  outputDir/surfaceName + ".000.mesh",
159  );
160 
161  if (debug)
162  {
163  Info<< "Writing case file to " << osCase.name() << endl;
164  }
165 
166  osCase
167  << "FORMAT" << nl
168  << "type: ensight gold" << nl
169  << nl
170  << "GEOMETRY" << nl
171  << "model: 1 " << osGeom.name().name() << nl
172  << nl
173  << "TIME" << nl
174  << "time set: 1" << nl
175  << "number of steps: 1" << nl
176  << "filename start number: 0" << nl
177  << "filename increment: 1" << nl
178  << "time values:" << nl
179  << timeValue << nl
180  << nl;
181 
182  ensightPartFaces ensPart(0, osGeom.name().name(), points, faces, true);
183  osGeom << ensPart;
184 }
185 
186 
187 // create write methods
189 
190 
191 // ************************************************************************* //
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:156
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:251
Specialised Ensight output with extra geometry file header.
const fileName & name() const
Return the name of the stream.
Definition: OFstream.H:120
virtual ~ensightSurfaceWriter()
Destructor.
IOstream::streamFormat writeFormat_
Write format.
Definition: surfaceWriter.H:62
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:294
Convenience macros for instantiating writer methods for surfaceWriter classes.
word name() const
Return file name (part beyond last /)
Definition: fileName.C:195
streamFormat
Enumeration for the format of data in the stream.
Definition: IOstream.H:86
defineSurfaceWriterWriteFields(nastranSurfaceWriter)
Istream and Ostream manipulators taking arguments.
addToRunTimeSelectionTable(ensightPart, ensightPartCells, istream)
static const char nl
Definition: Ostream.H:260
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.
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
virtual void write(const fileName &outputDir, const fileName &surfaceName, const pointField &points, const faceList &faces) const
Write single surface geometry to file.
Namespace for OpenFOAM.
ensightSurfaceWriter(const IOstream::streamFormat writeFormat)
Construct given write format.