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"
11 #include "basics/outputTecplot.hh"
12 #include "basics/output.hh"
14 #include "geometry/arrays.hh"
15 
16 #define TecplotGraphConstr_D 0
17 #define TecplotMeshWriteFormula_D 0
18 
19 namespace concepts {
20 
21  // forward declaration
22  template<class F>
23  class Formula;
24 }
25 
26 namespace 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:
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,
104  const concepts::ElementFormula<F,G>& frm,
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);
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_(),
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_(),
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_(),
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
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
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>
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) {
366  const concepts::Point<Real, dim>* x =
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>
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 
static void writeData(const concepts::Array< concepts::Point< Real, dim > > &coord, std::ostream &os, const F *values=0)
Writes coordinates and data.
Definition: tecplot.hh:364
uint size() const
Returns the requested size of the array.
Definition: array.hh:259
virtual Connector & connector() const =0
Returns the connector.
A 2D cell: quadrilateral.
Definition: cell2D.hh:378
An abstract class for a function in a FE space.
Piecewise defined function on a number of cells.
virtual std::ostream & info(std::ostream &os) const
Returns information in an output stream.
std::unique_ptr< std::ofstream > ofs_
Stream for output file.
Definition: basis.hh:83
Point< Real, 2 > Real2d
Global Postprocessing.
Definition: postProcess.hh:70
Writes formula for a cell to the given streams.
Definition: basis.hh:223
A cell in a mesh consist of topological information (neighbours, connectivity, orientation) and geome...
Definition: cell.hh:39
Base class for graphical output to a file.
Definition: basis.hh:74
Interface for a formula.
Definition: lform.hh:18
static void writeMesh(const concepts::Cell &cell, std::map< std::string, std::ostream * > &os, const concepts::Array< uint > &np, std::vector< uint > &cnt)
Writes for a cell the mesh, eventually with coordinates, to output streams.
enum elementTypes type_
Element type.
Definition: tecplot.hh:146
Writes the mesh to the given streams.
Definition: basis.hh:95
virtual std::ostream & info(std::ostream &os) const
Returns information in an output stream.
Routines for writing mesh and formula for a single cell for different cell types.
Definition: tecplot.hh:271
#define DEBUGL(doit, msg)
Writes the mesh to the given streams (for a cell).
Definition: basis.hh:263
Class for writing the graphical output of a FE solution represented by a coefficient vector (and poss...
Definition: basis.hh:140
#define TecplotMeshWriteFormula_D
Definition: tecplot.hh:17
virtual ~TecplotGraphics()
Definition: tecplot.hh:120
void createStreams_()
Create the streams.
Graphics.
Definition: basis.hh:33
static void writeCoord_(concepts::Point< Real, dim > x, std::ostream &os)
Writes the coordinates of one point to output streams.
Definition: tecplot.hh:377
std::map< std::string, std::ostream * > s_ptr_
Pointer to the streams, i.e. *(s_ptr_["vtxmsh"]) for FE mesh.
Definition: tecplot.hh:142
Class for output of objects to tecplot.
Interface for a formula defined element by element.
Output to Tecplot.
Definition: tecplot.hh:42
#define TecplotGraphConstr_D
Definition: tecplot.hh:16
TecplotGraphics(concepts::Mesh &msh, const std::string filename, const std::string title, const enum elementTypes type=QUADRILATERAL, const uint points=noPoints)
Constructor for output of mesh only.
Writes element formula for a cell to the given streams.
Definition: basis.hh:186
const uint dim_() const
Spatial dimension of the space.
std::vector< uint > & count()
Number of points written to the files, used for mesh representation.
Definition: basis.hh:108
void write_(concepts::GlobalPostprocess< G > &postProcess, BaseOutputCell< G > &tecplot, const F v)
Creates standard streams, writes to streams, writes to file and clear and delete all streams.
Definition: tecplot.hh:246
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)
Writes for a cell a formula on the mesh, with coordinates, to output streams.
Definition: tecplot.hh:335
const std::string typeStr_() const
Returns a string for the element type.
static void writeConnect(const concepts::Quad2d &quad, std::ostream &os, const concepts::Array< uint > &np, std::vector< uint > &cnt)
Writes the connectivity data.
std::string tecplotEnding(const std::string &filename)
Returns a string with ".dat" ending.
An abstract class for meshes.
Definition: mesh.hh:76
void closeStreams_(const std::vector< uint > &cnt)
Closes the streams.
Array with coordinates in 2D.
Definition: arrays.hh:150
Class providing an output operator.
void header(std::ostream &os, std::string name, uint cnt=0)
Output of a header.
const std::string title_
File name.
Definition: tecplot.hh:144
double Real
Type normally used for a floating point number.
Definition: typedefs.hh:36
Basic namespace for Concepts-2.
Definition: pml_formula.h:16
TecplotGraphics(const concepts::Space< G > &spc, const std::string filename, const std::string title, const enum elementTypes type=QUADRILATERAL)
Constructor for output of mesh only.
Definition: tecplot.hh:150
Page URL: http://wiki.math.ethz.ch/bin/view/Concepts/WebHome
21 August 2020
© 2020 Eidgenössische Technische Hochschule Zürich