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 | Copyright (C) 2015 OpenCFD Ltd.
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 "ensightPartFaces.H"
29 
30 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
31 
32 namespace Foam
33 {
34  makeSurfaceWriterType(ensightSurfaceWriter);
35  addToRunTimeSelectionTable(surfaceWriter, ensightSurfaceWriter, wordDict);
36 }
37 
38 
39 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
40 
42 :
43  surfaceWriter(),
44  writeFormat_(IOstream::ASCII),
45  collateTimes_(false)
46 {}
47 
48 
50 :
51  surfaceWriter(),
52  writeFormat_(IOstream::ASCII)
53 {
54  // choose ascii or binary format
55  if (options.found("format"))
56  {
57  writeFormat_ = IOstream::formatEnum(options.lookup("format"));
58  }
59  options.readIfPresent("collateTimes", collateTimes_);
60 }
61 
62 
63 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
64 
66 {}
67 
68 
69 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
70 
72 (
73  const fileName& outputDir,
74  const fileName& surfaceName,
75  const pointField& points,
76  const faceList& faces,
77  const bool verbose
78 ) const
79 {
80  if (!isDir(outputDir))
81  {
82  mkDir(outputDir);
83  }
84 
85  // const scalar timeValue = Foam::name(this->mesh().time().timeValue());
86  const scalar timeValue = 0.0;
87 
88  OFstream osCase(outputDir/surfaceName + ".case");
89  ensightGeoFile osGeom
90  (
91  outputDir/surfaceName + ".0000.mesh",
92  writeFormat_
93  );
94 
95  if (verbose)
96  {
97  Info<< "Writing case file to " << osCase.name() << endl;
98  }
99 
100  osCase
101  << "FORMAT" << nl
102  << "type: ensight gold" << nl
103  << nl
104  << "GEOMETRY" << nl
105  << "model: 1 " << osGeom.name().name() << nl
106  << nl
107  << "TIME" << nl
108  << "time set: 1" << nl
109  << "number of steps: 1" << nl
110  << "filename start number: 0" << nl
111  << "filename increment: 1" << nl
112  << "time values:" << nl
113  << timeValue << nl
114  << nl;
115 
116  ensightPartFaces ensPart(0, osGeom.name().name(), points, faces, true);
117  osGeom << ensPart;
118 
119  return osCase.name();
120 }
121 
122 
123 // create write methods
125 
126 
127 // ************************************************************************* //
Foam::ensightSurfaceWriter::~ensightSurfaceWriter
virtual ~ensightSurfaceWriter()
Destructor.
Definition: ensightSurfaceWriter.C:65
Foam::surfaceWriter
Base class for surface writers.
Definition: surfaceWriter.H:54
Foam::fileName
A class for handling file names.
Definition: fileName.H:69
Foam::ensightSurfaceWriter::collateTimes_
bool collateTimes_
Definition: ensightSurfaceWriter.H:57
ensightPartFaces.H
Foam::dictionary::readIfPresent
bool readIfPresent(const word &, T &, bool recursive=false, bool patternMatch=true) const
Find an entry if present, and assign to T.
Definition: dictionaryTemplates.C:94
Foam::addToRunTimeSelectionTable
addToRunTimeSelectionTable(ensightPart, ensightPartCells, istream)
Foam::dictionary::lookup
ITstream & lookup(const word &, bool recursive=false, bool patternMatch=true) const
Find and return an entry data stream.
Definition: dictionary.C:449
Foam::IOstream
An IOstream is an abstract base class for all input/output systems; be they streams,...
Definition: IOstream.H:71
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
Foam::ensightSurfaceWriter
A surfaceWriter for Ensight format.
Definition: ensightSurfaceWriter.H:48
Foam::fileName::name
word name() const
Return file name (part beyond last /)
Definition: fileName.C:212
makeSurfaceWriterMethods.H
Convenience macros for instantiating writer methods for surfaceWriter classes.
Foam::ensightGeoFile
Specialized Ensight output with extra geometry file header.
Definition: ensightGeoFile.H:45
Foam::dictionary::found
bool found(const word &, bool recursive=false, bool patternMatch=true) const
Search dictionary for given keyword.
Definition: dictionary.C:304
Foam::Field
Pre-declare SubField and related Field type.
Definition: Field.H:57
Foam::nl
static const char nl
Definition: Ostream.H:260
Foam::Info
messageStream Info
Foam::defineSurfaceWriterWriteFields
defineSurfaceWriterWriteFields(nastranSurfaceWriter)
Foam::ensightSurfaceWriter::write
virtual fileName write(const fileName &outputDir, const fileName &surfaceName, const pointField &points, const faceList &faces, const bool verbose=false) const
Write single surface geometry to file.
Definition: ensightSurfaceWriter.C:72
Foam::IOstream::formatEnum
static streamFormat formatEnum(const word &)
Return stream format of given format name.
Definition: IOstream.C:39
Foam::dictionary
A list of keyword definitions, which are a keyword followed by any number of values (e....
Definition: dictionary.H:137
Foam
Namespace for OpenFOAM.
Definition: combustionModel.C:30
ensightSurfaceWriter.H
Foam::isDir
bool isDir(const fileName &)
Does the name exist as a DIRECTORY in the file system?
Definition: POSIX.C:615
Foam::OFstream
Output to file stream.
Definition: OFstream.H:81
Foam::List
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: HashTable.H:59
points
const pointField & points
Definition: gmvOutputHeader.H:1
Foam::ensightPartFaces
An implementation of ensightPart to hold volume mesh faces.
Definition: ensightPartFaces.H:48
Foam::OFstream::name
const fileName & name() const
Return the name of the stream.
Definition: OFstream.H:118
Foam::makeSurfaceWriterType
makeSurfaceWriterType(boundaryDataSurfaceWriter)
Foam::mkDir
bool mkDir(const fileName &, mode_t=0777)
Make a directory and return an error if it could not be created.
Definition: POSIX.C:419
Foam::ensightSurfaceWriter::writeFormat_
IOstream::streamFormat writeFormat_
Write option (default is IOstream::ASCII.
Definition: ensightSurfaceWriter.H:55
Foam::ensightSurfaceWriter::ensightSurfaceWriter
ensightSurfaceWriter()
Construct null.
Definition: ensightSurfaceWriter.C:41