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-2021 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 
42 template<class Type>
44 :
45  writer<Type>(dict)
46 {}
47 
48 
49 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
50 
51 template<class Type>
53 (
54  const coordSet& points,
55  const wordList& valueSetNames
56 ) const
57 {
58  return this->getBaseName(points, valueSetNames) + ".nas";
59 }
60 
61 
62 template<class Type>
64 (
65  const coordSet& points,
66  const wordList& valueSetNames,
67  const List<const Field<Type>*>& valueSets,
68  Ostream& os
69 ) const
70 {
71  os << "TITLE=OpenFOAM "
72  << this->getBaseName(points, valueSetNames).c_str()
73  << nl
74  << "$" << nl
75  << "BEGIN BULK" << nl;
76 
77  forAll(points, pointi)
78  {
79  fileFormats::NASCore::writeKeyword(os, "GRID", fieldFormat::FREE);
80 
81  const point& pt = points[pointi];
82 
83  //os.setf(std::ios_base::right);
84  //os << setw(8) << pointi+1
85  // << setw(8) << ' '
86  // << setw(8) << float(pt.x())
87  // << setw(8) << float(pt.y())
88  // << setw(8) << float(pt.z())
89  // << nl;
90  //os.unsetf(std::ios_base::right);
91  os << ',' << pointi+1
92  << ','
93  << ',' << float(pt.x())
94  << ',' << float(pt.y())
95  << ',' << float(pt.z())
96  << nl;
97  }
98 
99  if (false)
100  {
101  // Single track with multiple segments
102  const label nEdges = points.size()-1;
103  for (label edgei = 0; edgei < nEdges; ++edgei)
104  {
106  (
107  os,
108  "PLOTEL",
109  fieldFormat::FREE
110  );
111 
112  //os.setf(std::ios_base::right);
113  //os << setw(8) << edgei+1
114  // << setw(8) << edgei+1
115  // << setw(8) << edgei+2
116  // << nl;
117  //os.unsetf(std::ios_base::right);
118  os << ',' << edgei+1
119  << ',' << edgei+1
120  << ',' << edgei+2
121  << nl;
122  }
123  }
124 
125  os << "ENDDATA" << nl;
126 }
127 
128 
129 template<class Type>
131 (
132  const bool writeTracks,
133  const List<scalarField>& times,
134  const PtrList<coordSet>& tracks,
135  const wordList& valueSetNames,
136  const List<List<Field<Type>>>& valueSets,
137  Ostream& os
138 ) const
139 {
140  if (valueSets.size() != valueSetNames.size())
141  {
143  << "Number of variables:" << valueSetNames.size() << endl
144  << "Number of valueSets:" << valueSets.size()
145  << exit(FatalError);
146  }
147  if (tracks.empty())
148  {
149  return;
150  }
151 
152  os << "TITLE=OpenFOAM "
153  << this->getBaseName(tracks[0], valueSetNames).c_str()
154  << nl
155  << "$" << nl
156  << "BEGIN BULK" << nl;
157 
158 // label nTracks = tracks.size();
159 // label nPoints = 0;
160 // forAll(tracks, i)
161 // {
162 // nPoints += tracks[i].size();
163 // }
164 
165  label globalPti = 0;
166  for (const coordSet& points : tracks)
167  {
168  for (const point& pt : points)
169  {
170  fileFormats::NASCore::writeKeyword(os, "GRID", fieldFormat::FREE);
171 
172  //os.setf(std::ios_base::right);
173  //os << setw(8) << globalPti++
174  // << setw(8) << ' '
175  // << setw(8) << float(pt.x())
176  // << setw(8) << float(pt.y())
177  // << setw(8) << float(pt.z())
178  // << nl;
179  //os.unsetf(std::ios_base::right);
180  os << ',' << globalPti++
181  << ','
182  << ',' << float(pt.x())
183  << ',' << float(pt.y())
184  << ',' << float(pt.z())
185  << nl;
186  }
187  }
188 
189  if (writeTracks)
190  {
191  // Write ids of track points to file
192  label globalEdgei = 0;
193  label globalPointi = 0;
194  for (const coordSet& points : tracks)
195  {
196  const label nEdges = points.size()-1;
197  for (label edgei = 0; edgei < nEdges; ++edgei)
198  {
200  (
201  os,
202  "PLOTEL",
203  fieldFormat::FREE
204  );
205 
206  //os.setf(std::ios_base::right);
207  //os << setw(8) << globalEdgei+1
208  // << setw(8) << globalPointi+1
209  // << setw(8) << globalPointi+2
210  // << nl;
211  //os.unsetf(std::ios_base::right);
212 
213  os << ',' << globalEdgei+1
214  << ',' << globalPointi+1
215  << ',' << globalPointi+2
216  << nl;
217  globalEdgei++;
218  globalPointi++;
219  }
220  }
221  }
222 
223  os << "ENDDATA" << nl;
224 }
225 
226 
227 // ************************************************************************* //
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:73
coordSet.H
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:369
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:64
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:59
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::nastranSetWriter::getFileName
virtual fileName getFileName(const coordSet &, const wordList &) const
Generate file name with correct extension.
Definition: nastranSetWriter.C:53
Foam::FatalError
error FatalError
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:123
Foam::nastranSetWriter::nastranSetWriter
nastranSetWriter()
Default construct.
Definition: nastranSetWriter.C:36
os
OBJstream os(runTime.globalPath()/outputName)
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:81
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:453
Foam::nl
constexpr char nl
Definition: Ostream.H:404
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