All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
starcdSurfaceWriter.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 "starcdSurfaceWriter.H"
27 #include "MeshedSurfaceProxy.H"
29 
30 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
31 
32 namespace Foam
33 {
34  makeSurfaceWriterType(starcdSurfaceWriter);
35 }
36 
37 
38 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
39 
40 namespace Foam
41 {
42  template<>
43  inline void Foam::starcdSurfaceWriter::writeData
44  (
45  Ostream& os,
46  const scalar& v
47  )
48  {
49  os << v << nl;
50  }
51 
52 
53  template<>
54  inline void Foam::starcdSurfaceWriter::writeData
55  (
56  Ostream& os,
57  const vector& v
58  )
59  {
60  os << v[0] << ' ' << v[1] << ' ' << v[2] << nl;
61  }
62 
63 
64  template<>
65  inline void Foam::starcdSurfaceWriter::writeData
66  (
67  Ostream& os,
68  const sphericalTensor& v
69  )
70  {
71  os << v[0] << nl;
72  }
73 
74 }
75 
76 
77 template<class Type>
78 inline void Foam::starcdSurfaceWriter::writeData
79 (
80  Ostream& os,
81  const Type& v
82 )
83 {}
84 
85 
86 template<class Type>
87 void Foam::starcdSurfaceWriter::Write
88 (
89  const fileName& outputDir,
90  const fileName& surfaceName,
91  const pointField& points,
92  const faceList& faces,
93  const word& fieldName,
94  const Field<Type>& values,
95  const bool isNodeValues
96 ) const
97 {
98  if (!isDir(outputDir))
99  {
100  mkDir(outputDir);
101  }
102 
103  OFstream os(outputDir/fieldName + '_' + surfaceName + ".usr");
104 
105  if (debug)
106  {
107  Info<< "Writing field " << fieldName << " to " << os.name() << endl;
108  }
109 
110  // no header, just write values
111  forAll(values, elemI)
112  {
113  os << elemI+1 << ' ';
114  writeData(os, values[elemI]);
115  }
116 }
117 
118 
119 
120 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
121 
123 (
124  const IOstream::streamFormat writeFormat
125 )
126 :
127  surfaceWriter(writeFormat)
128 {}
129 
130 
131 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
132 
134 {}
135 
136 
137 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
138 
140 (
141  const fileName& outputDir,
142  const fileName& surfaceName,
143  const pointField& points,
144  const faceList& faces
145 ) const
146 {
147  if (!isDir(outputDir))
148  {
149  mkDir(outputDir);
150  }
151 
152  fileName outName(outputDir/surfaceName + ".inp");
153 
154  if (debug)
155  {
156  Info<< "Writing geometry to " << outName << endl;
157  }
158 
159  MeshedSurfaceProxy<face>(points, faces).write(outName);
160 }
161 
162 
163 // create write methods
167 
168 
169 // ************************************************************************* //
starcdSurfaceWriter(const IOstream::streamFormat writeFormat)
Construct given write format.
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
A class for handling file names.
Definition: fileName.H:79
Output to file stream.
Definition: OFstream.H:82
virtual ~starcdSurfaceWriter()
Destructor.
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
const fileName & name() const
Return the name of the stream.
Definition: OFstream.H:120
Templated 3D SphericalTensor derived from VectorSpace adding construction from 1 component, element access using th ii() member function and the inner-product (dot-product) and outer-product operators.
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
A class for handling words, derived from string.
Definition: word.H:59
Convenience macros for instantiating writer methods for surfaceWriter classes.
streamFormat
Enumeration for the format of data in the stream.
Definition: IOstream.H:86
void write(std::ostream &os, const bool binary, List< floatScalar > &fField)
Write floats ascii or binary.
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:54
static const char nl
Definition: Ostream.H:260
A proxy for writing MeshedSurface, UnsortedMeshedSurface and surfMesh to various file formats...
Definition: MeshedSurface.H:73
const bool writeData(readBool(pdfDictionary.lookup("writeData")))
bool mkDir(const fileName &, mode_t=0777)
Make a directory and return an error if it could not be created.
Definition: POSIX.C:290
virtual void write(const fileName &outputDir, const fileName &surfaceName, const pointField &points, const faceList &faces) const
Write single surface geometry to file.
defineSurfaceWriterWriteField(Foam::starcdSurfaceWriter, scalar)
makeSurfaceWriterType(ensightSurfaceWriter)
A surfaceWriter for STARCD files.
messageStream Info
Base class for surface writers.
Definition: surfaceWriter.H:54
Namespace for OpenFOAM.