Class documentation of Concepts

Loading...
Searching...
No Matches
tecplot.hh
Go to the documentation of this file.
1
6#ifndef graphTecplot_hh
7#define graphTecplot_hh
8
9#include <vector>
10#include "basis.hh"
12#include "basics/output.hh"
14#include "geometry/arrays.hh"
15
16#define TecplotGraphConstr_D 0
17#define TecplotMeshWriteFormula_D 0
18
19namespace concepts {
20
21 // forward declaration
22 template<class F>
23 class Formula;
24}
25
26namespace graphics {
27
28 using concepts::Real;
29 using concepts::Real2d;
30
31 // ********************************************************* tecplotEnding **
32
34 std::string tecplotEnding(const std::string& filename);
35
36 // ******************************************************* TecplotGraphics **
37
42 class TecplotGraphics : public OutputBase {
43 public:
44 enum elementTypes {TRIANGLE, QUADRILATERAL, TETRAHEDRON , BRICK,
45 MAX_TYPE };
52 template<class G>
53 TecplotGraphics(const concepts::Space<G>& spc, const std::string filename,
54 const std::string title,
55 const enum elementTypes type = QUADRILATERAL);
62 TecplotGraphics(concepts::Mesh& msh, const std::string filename,
63 const std::string title,
64 const enum elementTypes type = QUADRILATERAL,
65 const uint points = noPoints);
66
75 template<class F, class G>
76 TecplotGraphics(const concepts::Space<G>& spc, const std::string filename,
77 const std::string title,
78 const concepts::Vector<F>& sol,
79 const enum elementTypes type = QUADRILATERAL,
80 const concepts::ElementFunction<F,G>* fun = 0,
81 const bool append = false);
82
90 template<class F, class G>
91 TecplotGraphics(const concepts::Space<G>& spc, const std::string filename,
92 const std::string title,
93 const concepts::Formula<F>& frm,
94 const enum elementTypes type = QUADRILATERAL);
101 template<class F, class G>
102 TecplotGraphics(const concepts::Space<G>& spc, const std::string filename,
103 const std::string title,
105 const enum elementTypes type = QUADRILATERAL);
113 template<class F>
114 TecplotGraphics(concepts::Mesh& msh, const std::string filename,
115 const std::string title,
116 const concepts::Formula<F>& frm,
117 const enum elementTypes type = QUADRILATERAL,
118 const uint points = noPoints);
119
120 virtual ~TecplotGraphics() {}
121
122 static uint noPoints;
123 protected:
124 virtual std::ostream& info(std::ostream& os) const;
125 private:
129 template<class F, class G>
130 void write_(concepts::GlobalPostprocess<G>& postProcess,
131 BaseOutputCell<G>& tecplot, const F v);
133 void createStreams_();
135 void closeStreams_(const std::vector<uint>& cnt);
137 const uint dim_() const;
139 const std::string typeStr_() const;
140
142 std::map<std::string, std::ostream*> s_ptr_;
144 const std::string title_;
146 const enum elementTypes type_;
147 };
148
149 template<class G>
151 const std::string filename,
152 const std::string title,
153 const enum elementTypes type)
154 : OutputBase(tecplotEnding(filename)), title_(title), type_(type)
155 {
156 // Post processor (global)
157 concepts::GlobalPostprocess<G> postProcess(spc);
158 // Post processor on cell
159 BaseMeshCell tecplot(s_ptr_, dim_(),
160 concepts::ElementGraphicsBase::TECPLOT, noPoints);
161 // Creates streams, writes to streams, writes to file and clear
162 // and delete all streams.
163 write_(postProcess, tecplot, 0);
164 }
165
166 template<class F, class G>
168 const std::string filename,
169 const std::string title,
170 const concepts::Vector<F>& sol,
171 const enum elementTypes type,
173 const bool append)
174 : OutputBase(tecplotEnding(filename), append), title_(title), type_(type)
175 {
176 // Post processor (global)
177 concepts::GlobalPostprocess<G> postProcess(spc);
178 // Post processor on cell
179 BaseDataCell<F,G> tecplot(s_ptr_, dim_(),
180 concepts::ElementGraphicsBase::TECPLOT,
181 sol, fun);
182 // Creates streams, writes to streams, writes to file and clear
183 // and delete all streams. Header has to be written during the output
184 // inside stream "header".
185 write_(postProcess, tecplot, (F)0);
186 }
187
188 template<class F, class G>
190 const std::string filename,
191 const std::string title,
192 const concepts::Formula<F>& frm,
193 const enum elementTypes type)
194 : OutputBase(tecplotEnding(filename)),
195 title_(title), type_(type) {
196 // Post processor (global)
197 concepts::GlobalPostprocess<G> postProcess(spc);
198 // Post processor on cell
199 BaseFormulaCell<F,G> tecplot(s_ptr_, dim_(),
200 concepts::ElementGraphicsBase::TECPLOT, frm,
201 noPoints);
202 // Creates streams, writes to streams, writes to file and clear
203 // and delete all streams.
204 write_(postProcess, tecplot, true);
205 }
206
207 template<class F, class G>
209 const std::string filename,
210 const std::string title,
212 const enum elementTypes type)
213 : OutputBase(tecplotEnding(filename)), title_(title), type_(type)
214 {
215 // Post processor (global)
216 concepts::GlobalPostprocess<G> postProcess(spc);
217 // Post processor on cell
219 (s_ptr_, dim_(), concepts::ElementGraphicsBase::TECPLOT, frm);
220 // Creates streams, writes to streams, writes to file and clear
221 // and delete all streams.
222 write_(postProcess, tecplot, (F)0);
223 }
224
225 template<class F>
227 const std::string filename,
228 const std::string title,
229 const concepts::Formula<F>& frm,
230 const enum elementTypes type,
231 const uint points)
232 : OutputBase(tecplotEnding(filename)), title_(title ), type_(type)
233 {
234 // Post processor (global)
235 concepts::GlobalPostprocess<Real> postProcess(msh);
236 // Post processor on cell
237 BaseFormulaCell<F,Real> tecplot(s_ptr_, dim_(),
238 concepts::ElementGraphicsBase::TECPLOT,
239 frm, points);
240 // Creates streams, writes to streams, writes to file and clear
241 // and delete all streams.
242 write_(postProcess, tecplot, F(1));
243 }
244
245 template<class F, class G>
246 void TecplotGraphics::write_(concepts::GlobalPostprocess<G>& postProcess,
247 BaseOutputCell<G>& tecplot, const F v) {
248 // Create the streams
249 createStreams_();
250 if (v != F(0)) {
251 concepts::OutputTecplot<F>(v).header(*ofs_ << ", ", "v");
252 *ofs_ << std::endl;
253 }
254 // set counter to zero
255 tecplot.count().assign(2, 0);
256 // Post processor on cell
257 DEBUGL(TecplotGraphConstr_D, tecplot);
258 // loop over cells or elements and write into streams
259 postProcess(tecplot);
260 // write to file, clear and delete streams
261 closeStreams_(tecplot.count());
262 }
263
264 // ************************************************************ TecplotMesh **
265
272 public:
283 static void writeMesh(const concepts::Cell& cell,
284 std::map<std::string, std::ostream*>& os,
285 const concepts::Array<uint>& np,
286 std::vector<uint>& cnt);
296 template<class F>
297 static void writeFormula(const concepts::Cell& cell,
298 std::map<std::string, std::ostream*>& os,
299 const concepts::Array<uint>& np,
300 std::vector<uint>& cnt,
308 template<uint dim, class F>
309 static void writeData
311 std::ostream& os, const F* values = 0);
317 static void writeConnect(const concepts::Quad2d& quad, std::ostream& os,
318 const concepts::Array<uint>& np,
319 std::vector<uint>& cnt);
320 protected:
321 virtual std::ostream& info(std::ostream& os) const;
322 private:
323
329 template<uint dim>
330 static void writeCoord_(concepts::Point<Real, dim> x, std::ostream& os);
331
332 };
333
334 template<class F>
336 std::map<std::string, std::ostream*>& os,
337 const concepts::Array<uint>& np,
338 std::vector<uint>& cnt,
340 {
341 DEBUGL(TecplotMeshWriteFormula_D, "cell = " << cell);
342
343 // 2D quadrilaterial
344 const concepts::Quad2d* cellQ =
345 dynamic_cast<const concepts::Quad2d*>(&cell);
346 if (cellQ) {
347 // coordinates in the cell
349 (*cellQ,
350 concepts::Array<Real>(np[0], 0, 1./(np[0]-1)),
351 concepts::Array<Real>(np[1], 0, 1./(np[1]-1)));
352 const concepts::Real2d* x = (const concepts::Real2d*)X;
353 // array for the formula values
354 concepts::Array<F> V(X.size()); F* v = (F*)V;
355 for (uint i = X.size(); i--; )
356 *v++ = (*frm)(cell.connector(), *x++);
357 writeData(X, *os["data"], (const F*)V);
358 writeConnect(*cellQ, *os["connect"], np, cnt);
359 } // cellQ
360 }
361
362 template<uint dim, class F>
365 std::ostream& os, const F* v) {
367 (const concepts::Point<Real, dim>*)coord;
368 bool values = v != 0;
369 for(uint i = coord.size(); i--; ) {
370 writeCoord_(*x++, os);
371 if (values) os << " " << concepts::OutputTecplot<F>(*v++);
372 os << std::endl;
373 }
374 }
375
376 template<uint dim>
377 void TecplotMesh::writeCoord_(concepts::Point<Real, dim> x, std::ostream& os)
378 {
379 os << x[0] << " ";
380 if (dim > 1) {
381 os << x[1] << " ";
382 if (dim > 2)
383 os << x[2] << " ";
384 }
385 }
386
387} // namespace graphics
388
389#endif // graphTecplot_hh
390
virtual Connector & connector() const =0
Returns the connector.
std::vector< uint > & count()
Number of points written to the files, used for mesh representation.
Definition basis.hh:108
std::unique_ptr< std::ofstream > ofs_
Stream for output file.
Definition basis.hh:83
TecplotGraphics(concepts::Mesh &msh, const std::string filename, const std::string title, const enum elementTypes type=QUADRILATERAL, const uint points=noPoints)
virtual std::ostream & info(std::ostream &os) const
Returns information in an output stream.
TecplotGraphics(const concepts::Space< G > &spc, const std::string filename, const std::string title, const enum elementTypes type=QUADRILATERAL)
Definition tecplot.hh:150
static void writeMesh(const concepts::Cell &cell, std::map< std::string, std::ostream * > &os, const concepts::Array< uint > &np, std::vector< uint > &cnt)
static void writeData(const concepts::Array< concepts::Point< Real, dim > > &coord, std::ostream &os, const F *values=0)
Definition tecplot.hh:364
static void writeFormula(const concepts::Cell &cell, std::map< std::string, std::ostream * > &os, const concepts::Array< uint > &np, std::vector< uint > &cnt, const concepts::PiecewiseFormulaBase< F > *frm)
Definition tecplot.hh:335
static void writeConnect(const concepts::Quad2d &quad, std::ostream &os, const concepts::Array< uint > &np, std::vector< uint > &cnt)
virtual std::ostream & info(std::ostream &os) const
Returns information in an output stream.
#define DEBUGL(doit, msg)
Definition debug.hh:40
double Real
Definition typedefs.hh:39
Set< F > makeSet(uint n, const F &first,...)
Definition set.hh:320
std::string tecplotEnding(const std::string &filename)
Returns a string with ".dat" ending.