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-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 "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::writeTemplate
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 bool verbose
97 ) const
98 {
99  if (!isDir(outputDir))
100  {
101  mkDir(outputDir);
102  }
103 
104  OFstream os(outputDir/fieldName + '_' + surfaceName + ".usr");
105 
106  if (verbose)
107  {
108  Info<< "Writing field " << fieldName << " to " << os.name() << endl;
109  }
110 
111  // no header, just write values
112  forAll(values, elemI)
113  {
114  os << elemI+1 << ' ';
115  writeData(os, values[elemI]);
116  }
117 }
118 
119 
120 
121 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
122 
124 :
125  surfaceWriter()
126 {}
127 
128 
129 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
130 
132 {}
133 
134 
135 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
136 
138 (
139  const fileName& outputDir,
140  const fileName& surfaceName,
141  const pointField& points,
142  const faceList& faces,
143  const bool verbose
144 ) const
145 {
146  if (!isDir(outputDir))
147  {
148  mkDir(outputDir);
149  }
150 
151  fileName outName(outputDir/surfaceName + ".inp");
152 
153  if (verbose)
154  {
155  Info<< "Writing geometry to " << outName << endl;
156  }
157 
158  MeshedSurfaceProxy<face>(points, faces).write(outName);
159 }
160 
161 
162 // create write methods
166 
167 
168 // ************************************************************************* //
starcdSurfaceWriter()
Construct null.
#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:256
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.
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.
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:53
static const char nl
Definition: Ostream.H:265
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
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.