starcdSurfaceWriter.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 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 
28 #include "MeshedSurfaceProxy.H"
29 #include "OFstream.H"
30 #include "OSspecific.H"
31 
33 
34 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
35 
36 namespace Foam
37 {
38  makeSurfaceWriterType(starcdSurfaceWriter);
39 }
40 
41 
42 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
43 
44 namespace Foam
45 {
46  template<>
47  inline void Foam::starcdSurfaceWriter::writeData
48  (
49  Ostream& os,
50  const scalar& v
51  )
52  {
53  os << v << nl;
54  }
55 
56 
57  template<>
58  inline void Foam::starcdSurfaceWriter::writeData
59  (
60  Ostream& os,
61  const vector& v
62  )
63  {
64  os << v[0] << ' ' << v[1] << ' ' << v[2] << nl;
65  }
66 
67 
68  template<>
69  inline void Foam::starcdSurfaceWriter::writeData
70  (
71  Ostream& os,
72  const sphericalTensor& v
73  )
74  {
75  os << v[0] << nl;
76  }
77 
78 }
79 
80 
81 template<class Type>
82 inline void Foam::starcdSurfaceWriter::writeData
83 (
84  Ostream& os,
85  const Type& v
86 )
87 {}
88 
89 
90 template<class Type>
91 void Foam::starcdSurfaceWriter::writeTemplate
92 (
93  const fileName& outputDir,
94  const fileName& surfaceName,
95  const pointField& points,
96  const faceList& faces,
97  const word& fieldName,
98  const Field<Type>& values,
99  const bool isNodeValues,
100  const bool verbose
101 ) const
102 {
103  if (!isDir(outputDir))
104  {
105  mkDir(outputDir);
106  }
107 
108  OFstream os(outputDir/fieldName + '_' + surfaceName + ".usr");
109 
110  if (verbose)
111  {
112  Info<< "Writing field " << fieldName << " to " << os.name() << endl;
113  }
114 
115  // no header, just write values
116  forAll(values, elemI)
117  {
118  os << elemI+1 << ' ';
119  writeData(os, values[elemI]);
120  }
121 }
122 
123 
124 
125 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
126 
128 :
129  surfaceWriter()
130 {}
131 
132 
133 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
134 
136 {}
137 
138 
139 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
140 
142 (
143  const fileName& outputDir,
144  const fileName& surfaceName,
145  const pointField& points,
146  const faceList& faces,
147  const bool verbose
148 ) const
149 {
150  if (!isDir(outputDir))
151  {
152  mkDir(outputDir);
153  }
154 
155  fileName outName(outputDir/surfaceName + ".inp");
156 
157  if (verbose)
158  {
159  Info<< "Writing geometry to " << outName << endl;
160  }
161 
162  MeshedSurfaceProxy<face>(points, faces).write(outName);
163 }
164 
165 
166 // create write methods
170 
171 
172 // ************************************************************************* //
Output to file stream.
Definition: OFstream.H:81
const pointField & points
virtual ~starcdSurfaceWriter()
Destructor.
defineSurfaceWriterWriteField(Foam::starcdSurfaceWriter, scalar)
A proxy for writing MeshedSurface, UnsortedMeshedSurface and surfMesh to various file formats...
Definition: MeshedSurface.H:73
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...
A class for handling words, derived from string.
Definition: word.H:59
messageStream Info
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.
Namespace for OpenFOAM.
A surfaceWriter for STARCD files.
starcdSurfaceWriter()
Construct null.
static const char nl
Definition: Ostream.H:260
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:118
Base class for surface writers.
Definition: surfaceWriter.H:54
#define forAll(list, i)
Definition: UList.H:421
const bool writeData(readBool(pdfDictionary.lookup("writeData")))
bool isDir(const fileName &)
Does the name exist as a DIRECTORY in the file system?
Definition: POSIX.C:616
A class for handling file names.
Definition: fileName.H:69
makeSurfaceWriterType(dxSurfaceWriter)
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:53
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.
bool mkDir(const fileName &, mode_t=0777)
Make a directory and return an error if it could not be created.
Definition: POSIX.C:420