nastranSetWriter.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 | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2018-2019 OpenCFD Ltd.
9 -------------------------------------------------------------------------------
10 License
11  This file is part of OpenFOAM.
12 
13  OpenFOAM is free software: you can redistribute it and/or modify it
14  under the terms of the GNU General Public License as published by
15  the Free Software Foundation, either version 3 of the License, or
16  (at your option) any later version.
17 
18  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21  for more details.
22 
23  You should have received a copy of the GNU General Public License
24  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25 
26 \*---------------------------------------------------------------------------*/
27 
28 #include "nastranSetWriter.H"
29 #include "coordSet.H"
30 #include "IOmanip.H"
32 
33 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
34 
35 template<class Type>
37 :
38  writer<Type>()
39 {}
40 
41 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
42 
43 template<class Type>
45 {}
46 
47 
48 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
49 
50 template<class Type>
52 (
53  const coordSet& points,
54  const wordList& valueSetNames
55 ) const
56 {
57  return this->getBaseName(points, valueSetNames) + ".nas";
58 }
59 
60 
61 template<class Type>
63 (
64  const coordSet& points,
65  const wordList& valueSetNames,
66  const List<const Field<Type>*>& valueSets,
67  Ostream& os
68 ) const
69 {
70  os << "TITLE=OpenFOAM "
71  << this->getBaseName(points, valueSetNames).c_str()
72  << nl
73  << "$" << nl
74  << "BEGIN BULK" << nl;
75 
76  forAll(points, pointi)
77  {
78  fileFormats::NASCore::writeKeyword(os, "GRID", fieldFormat::FREE);
79 
80  const point& pt = points[pointi];
81 
82  //os.setf(std::ios_base::right);
83  //os << setw(8) << pointi+1
84  // << setw(8) << ' '
85  // << setw(8) << float(pt.x())
86  // << setw(8) << float(pt.y())
87  // << setw(8) << float(pt.z())
88  // << nl;
89  //os.unsetf(std::ios_base::right);
90  os << ',' << pointi+1
91  << ','
92  << ',' << float(pt.x())
93  << ',' << float(pt.y())
94  << ',' << float(pt.z())
95  << nl;
96  }
97 
98  if (false)
99  {
100  // Single track with multiple segments
101  const label nEdges = points.size()-1;
102  for (label edgei = 0; edgei < nEdges; ++edgei)
103  {
105  (
106  os,
107  "PLOTEL",
108  fieldFormat::FREE
109  );
110 
111  //os.setf(std::ios_base::right);
112  //os << setw(8) << edgei+1
113  // << setw(8) << edgei+1
114  // << setw(8) << edgei+2
115  // << nl;
116  //os.unsetf(std::ios_base::right);
117  os << ',' << edgei+1
118  << ',' << edgei+1
119  << ',' << edgei+2
120  << nl;
121  }
122  }
123 
124  os << "ENDDATA" << nl;
125 }
126 
127 
128 template<class Type>
130 (
131  const bool writeTracks,
132  const PtrList<coordSet>& tracks,
133  const wordList& valueSetNames,
134  const List<List<Field<Type>>>& valueSets,
135  Ostream& os
136 ) const
137 {
138  if (valueSets.size() != valueSetNames.size())
139  {
141  << "Number of variables:" << valueSetNames.size() << endl
142  << "Number of valueSets:" << valueSets.size()
143  << exit(FatalError);
144  }
145  if (tracks.empty())
146  {
147  return;
148  }
149 
150  os << "TITLE=OpenFOAM "
151  << this->getBaseName(tracks[0], valueSetNames).c_str()
152  << nl
153  << "$" << nl
154  << "BEGIN BULK" << nl;
155 
156 // label nTracks = tracks.size();
157 // label nPoints = 0;
158 // forAll(tracks, i)
159 // {
160 // nPoints += tracks[i].size();
161 // }
162 
163  label globalPti = 0;
164  for (const coordSet& points : tracks)
165  {
166  for (const point& pt : points)
167  {
168  fileFormats::NASCore::writeKeyword(os, "GRID", fieldFormat::FREE);
169 
170  //os.setf(std::ios_base::right);
171  //os << setw(8) << globalPti++
172  // << setw(8) << ' '
173  // << setw(8) << float(pt.x())
174  // << setw(8) << float(pt.y())
175  // << setw(8) << float(pt.z())
176  // << nl;
177  //os.unsetf(std::ios_base::right);
178  os << ',' << globalPti++
179  << ','
180  << ',' << float(pt.x())
181  << ',' << float(pt.y())
182  << ',' << float(pt.z())
183  << nl;
184  }
185  }
186 
187  if (writeTracks)
188  {
189  // Write ids of track points to file
190  label globalEdgei = 0;
191  label globalPointi = 0;
192  for (const coordSet& points : tracks)
193  {
194  const label nEdges = points.size()-1;
195  for (label edgei = 0; edgei < nEdges; ++edgei)
196  {
198  (
199  os,
200  "PLOTEL",
201  fieldFormat::FREE
202  );
203 
204  //os.setf(std::ios_base::right);
205  //os << setw(8) << globalEdgei+1
206  // << setw(8) << globalPointi+1
207  // << setw(8) << globalPointi+2
208  // << nl;
209  //os.unsetf(std::ios_base::right);
210 
211  os << ',' << globalEdgei+1
212  << ',' << globalPointi+1
213  << ',' << globalPointi+2
214  << nl;
215  globalEdgei++;
216  globalPointi++;
217  }
218  }
219  }
220 
221  os << "ENDDATA" << nl;
222 }
223 
224 
225 // ************************************************************************* //
Foam::Vector::x
const Cmpt & x() const
Access to the vector x component.
Definition: VectorI.H:73
Foam::fileName
A class for handling file names.
Definition: fileName.H:69
coordSet.H
Foam::nastranSetWriter::~nastranSetWriter
virtual ~nastranSetWriter()
Destructor.
Definition: nastranSetWriter.C:44
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:350
Foam::Vector::z
const Cmpt & z() const
Access to the vector z component.
Definition: VectorI.H:85
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:296
Foam::nastranSetWriter::write
virtual void write(const coordSet &, const wordList &, const List< const Field< Type > * > &, Ostream &) const
General entry point for writing.
Definition: nastranSetWriter.C:63
Foam::fileFormats::NASCore::writeKeyword
static Ostream & writeKeyword(Ostream &os, const word &keyword, const fieldFormat format)
Definition: NASCore.C:165
Foam::Field
Generic templated field type.
Definition: Field.H:63
nastranSetWriter.H
IOmanip.H
Istream and Ostream manipulators taking arguments.
Foam::PtrList
A list of pointers to objects of type <T>, with allocation/deallocation management of the pointers....
Definition: List.H:62
Foam::nastranSetWriter::getFileName
virtual fileName getFileName(const coordSet &, const wordList &) const
Generate file name with correct extension.
Definition: nastranSetWriter.C:52
Foam::FatalError
error FatalError
Foam::nastranSetWriter::nastranSetWriter
nastranSetWriter()
Construct null.
Definition: nastranSetWriter.C:36
addToRunTimeSelectionTable.H
Macros for easy insertion into run-time selection tables.
Foam::writer
Base class for graphics format writing. Entry points are.
Definition: writer.H:80
Foam::coordSet
Holds list of sampling positions.
Definition: coordSet.H:53
Foam::exit
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:130
Foam::Vector::y
const Cmpt & y() const
Access to the vector y component.
Definition: VectorI.H:79
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:381
Foam::nl
constexpr char nl
Definition: Ostream.H:385
Foam::Vector< scalar >
Foam::List< word >
points
const pointField & points
Definition: gmvOutputHeader.H:1
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:56