basis.hh

Go to the documentation of this file.
1 
6 #ifndef graphicsbasis_hh
7 #define graphicsbasis_hh
8 
9 #include <fstream>
10 #include "basics/debug.hh"
11 #include "basics/exceptions.hh"
12 #include "basics/outputOperator.hh"
13 #include "basics/typedefs.hh"
14 #include "toolbox/array.hh"
16 #include "toolbox/sequence.hh"
17 #include "geometry/cell2D.hh"
18 #include "space/function.hh"
19 #include "space/postProcess.hh"
20 #include "space/space.hh"
21 
22 namespace concepts {
23  template<class F>
24  class Vector;
25 
26  template<class F, class G>
27  class ElementFormula;
28 
29  template<class F>
30  class PiecewiseFormulaBase;
31 }
32 
33 namespace graphics {
34 
35  using concepts::Real;
36 
37  // ****************************************************************** Size **
38 
43  template<class F>
44  struct Size {
45  const uint n() = 0;
46  };
47 
48  template<>
49  struct Size<Real> {
50  static const uint n() { return 1; }
51  };
52 
53  template<>
54  struct Size<concepts::Cmplx> {
55  static const uint n() { return 1; }
56  };
57 
58  template<class F, uint dim>
59  struct Size<concepts::Point<F, dim> > {
60  static const uint n() { return Size<F>::n() * dim; }
61  };
62 
63  template<class F, uint dim>
64  struct Size<concepts::Mapping<F, dim> > {
65  static const uint n() { return Size<F>::n() * dim * dim; }
66  };
67 
68  // ************************************************************ OutputBase **
69 
75  public:
78  OutputBase(const std::string filename, const bool append = false);
79  virtual ~OutputBase() { ofs_.reset(0); }
80  protected:
81  virtual std::ostream& info(std::ostream& os) const;
83  std::unique_ptr<std::ofstream> ofs_;
84  };
85 
86  // ******************************************************** BaseOutputCell **
87 
94  template<class F = Real>
96  public:
97  BaseOutputCell(std::map<std::string, std::ostream*>& os, const uint dim,
99  : type_(type), dim_(dim), os_(os) {}
100  virtual void operator()(const concepts::Element<F>& elm) = 0;
101  virtual void operator()(const concepts::Cell& cell) = 0;
103  std::map<std::string, std::ostream*>& write() { return os_; }
105  uint streams() const { return os_.size(); }
107 // uint& count() { return cnt_; }
108  std::vector<uint>& count() { return cnt_; }
110 // uint& elm() { return elm_; }
112  uint dim() const { return dim_; }
114  virtual uint n() const = 0;
115  protected:
116  virtual std::ostream& info(std::ostream& os) const;
122 // uint elm_;
124  const uint dim_;
126  std::map<std::string, std::ostream*>& os_;
127  };
128 
129  // ********************************************************** BaseDataCell **
130 
139  template<class F, class G = typename concepts::Realtype<F>::type>
140  class BaseDataCell : public BaseOutputCell<G> {
141  public:
148  BaseDataCell(std::map<std::string, std::ostream*>& os,
149  const uint dim,
151  const concepts::Vector<F>& sol,
152  const concepts::ElementFunction<F,G>* fun = 0);
155  virtual void operator()(const concepts::Element<G>& elm);
157  virtual void operator()(const concepts::Cell& cell)
160  const concepts::Array<F>& coeff() const { return coeff_; }
163  { return fun_; }
164  const concepts::Vector<F>& sol() const { return sol_; }
165  virtual uint n() const;
166  protected:
167  virtual std::ostream& info(std::ostream& os) const;
168  private:
175  };
176 
177  // ************************************************ BaseElementFormulaCell **
178 
185  template<class F, class G = typename concepts::Realtype<F>::type>
187  public:
195  (std::map<std::string, std::ostream*>& os, const uint dim,
197  const concepts::ElementFormula<F,G>& fun);
200  virtual void operator()(const concepts::Element<G>& elm);
202  virtual void operator()(const concepts::Cell& cell)
206  { return fun_; }
207  virtual uint n() const { return Size<F>::n(); }
208  protected:
209  virtual std::ostream& info(std::ostream& os) const;
212  };
213 
214  // ******************************************************* BaseFormulaCell **
215 
222  template<class F, class G = typename concepts::Realtype<F>::type>
223  class BaseFormulaCell : public BaseOutputCell<G> {
224  public:
232  BaseFormulaCell(std::map<std::string, std::ostream*>& os,
233  const uint dim,
236  const uint points = 5);
239  virtual void operator()(const concepts::Element<G>& elm);
241  virtual void operator()(const concepts::Cell& cell)
244  const concepts::PiecewiseFormulaBase<F>* formula() const { return &frm_; }
245  virtual uint n() const { return Size<F>::n(); }
246  protected:
247  virtual std::ostream& info(std::ostream& os) const;
248  private:
253  };
254 
255  // ********************************************************** BaseMeshCell **
256 
263  class BaseMeshCell : public BaseOutputCell<Real> {
264  public:
271  BaseMeshCell(std::map<std::string, std::ostream*>& os, const uint dim,
273  const uint points = 5);
276  virtual void operator()(const concepts::Element<Real>& elm);
279  virtual void operator()(const concepts::Cell& cell)
282  virtual uint n() const { return 0; }
283  protected:
284  virtual std::ostream& info(std::ostream& os) const;
285  private:
288  };
289 
290 } // namespace concepts
291 
292 #endif // graphicsbasis_hh
virtual void operator()(const concepts::Cell &cell)
Not operational.
const concepts::ElementFormula< F, G > & elementFormula()
Returns the coefficients of the elements shape functions.
Definition: basis.hh:205
virtual ~OutputBase()
Definition: basis.hh:79
const concepts::Vector< F > & sol() const
Definition: basis.hh:164
An abstract class for an element of a space.
Definition: exceptions.hh:15
virtual uint n() const
Definition: basis.hh:245
virtual std::ostream & info(std::ostream &os) const
Returns information in an output stream.
virtual void operator()(const concepts::Cell &cell)
Not operational.
An abstract class for a function in a FE space.
static const uint n()
Definition: basis.hh:55
enum concepts::ElementGraphicsBase::graphicsType type_
Type of Output, like Matlab, Gnuplot.
Definition: basis.hh:118
const concepts::Array< uint > Points_
Number of points in one direction.
Definition: basis.hh:287
Piecewise defined function on a number of cells.
const concepts::Array< F > & coeff() const
Returns the coefficients of the elements shape functions.
Definition: basis.hh:160
virtual uint n() const =0
Number of components.
Basic class for a Point or a vector.
virtual void operator()(const concepts::Element< G > &elm)
Output of the mesh and formula on the element.
std::unique_ptr< std::ofstream > ofs_
Stream for output file.
Definition: basis.hh:83
BaseDataCell(std::map< std::string, std::ostream * > &os, const uint dim, const concepts::ElementGraphicsBase::graphicsType type, const concepts::Vector< F > &sol, const concepts::ElementFunction< F, G > *fun=0)
Constructor (for single and repeated output)
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
const concepts::PiecewiseFormulaBase< F > & frm_
Formula.
Definition: basis.hh:250
virtual uint n() const
virtual std::ostream & info(std::ostream &os) const
Returns information in an output stream.
Base class for graphical output to a file.
Definition: basis.hh:74
virtual void operator()(const concepts::Cell &cell)
Not operational.
Writes the mesh to the given streams.
Definition: basis.hh:95
const concepts::Array< uint > Points_
Number of points in one direction.
Definition: basis.hh:252
virtual std::ostream & info(std::ostream &os) const
Returns information in an output stream.
const concepts::PiecewiseFormulaBase< F > * formula() const
Returns the formula.
Definition: basis.hh:244
const uint dim_
Number of drawn elements.
Definition: basis.hh:124
Writes the mesh to the given streams (for a cell).
Definition: basis.hh:263
const concepts::Vector< F > & sol_
Vector of the variable to plot.
Definition: basis.hh:172
Class for writing the graphical output of a FE solution represented by a coefficient vector (and poss...
Definition: basis.hh:140
const concepts::ElementFunction< F, G > *& elementFunction()
Returns the function of the solution.
Definition: basis.hh:162
An array of objects.
Definition: bilinearForm.hh:23
Graphics.
Definition: basis.hh:33
BaseMeshCell(std::map< std::string, std::ostream * > &os, const uint dim, const concepts::ElementGraphicsBase::graphicsType type, const uint points=5)
Constructor (for single and repeated output)
virtual void operator()(const concepts::Element< G > &elm)
Output of the mesh and vector data of the element.
virtual void operator()(const concepts::Element< F > &elm)=0
uint dim() const
Number of the elements, used for drawing mesh representation.
Definition: basis.hh:112
concepts::Sequence< uint > cnt_
Some counters.
Definition: basis.hh:120
virtual std::ostream & info(std::ostream &os) const
Returns information in an output stream.
Interface for a formula defined element by element.
virtual void operator()(const concepts::Cell &cell)=0
Application operator.
Writes element formula for a cell to the given streams.
Definition: basis.hh:186
virtual void operator()(const concepts::Element< G > &elm)
Output of the mesh and vector data of the element.
std::vector< uint > & count()
Number of points written to the files, used for mesh representation.
Definition: basis.hh:108
std::map< std::string, std::ostream * > & os_
Streams to write the data to.
Definition: basis.hh:126
std::complex< Real > Cmplx
Type for a complex number. It also depends on the setting of Real.
Definition: typedefs.hh:39
virtual std::ostream & info(std::ostream &os) const
Returns information in an output stream.
Number of components of data types.
Definition: basis.hh:44
concepts::Array< F > coeff_
Elementwise coefficients of the shape functions.
Definition: basis.hh:170
OutputBase(const std::string filename, const bool append=false)
Constructor.
virtual uint n() const
Number of components.
Definition: basis.hh:282
static const uint n()
Definition: basis.hh:50
uint streams() const
Number of streams.
Definition: basis.hh:105
BaseFormulaCell(std::map< std::string, std::ostream * > &os, const uint dim, const concepts::ElementGraphicsBase::graphicsType type, const concepts::PiecewiseFormulaBase< F > &frm, const uint points=5)
Constructor (for single and repeated output)
virtual uint n() const
Definition: basis.hh:207
virtual std::ostream & info(std::ostream &os) const
Returns information in an output stream.
Exception class to express a missing feature.
Definition: exceptions.hh:206
const concepts::ElementFunction< F, G > * fun_
Function of the solution.
Definition: basis.hh:174
virtual void operator()(const concepts::Element< Real > &elm)
Output of the mesh of the element.
virtual void operator()(const concepts::Cell &cell)
Output of the mesh for this cell.
BaseOutputCell(std::map< std::string, std::ostream * > &os, const uint dim, const concepts::ElementGraphicsBase::graphicsType type)
Definition: basis.hh:97
const uint n()=0
const concepts::ElementFormula< F, G > & fun_
Element Formula.
Definition: basis.hh:211
Class providing an output operator.
BaseElementFormulaCell(std::map< std::string, std::ostream * > &os, const uint dim, const concepts::ElementGraphicsBase::graphicsType type, const concepts::ElementFormula< F, G > &fun)
Constructor (for single and repeated output)
Abstract class for per cell postprocessing.
Definition: postProcess.hh:38
double Real
Type normally used for a floating point number.
Definition: typedefs.hh:36
std::map< std::string, std::ostream * > & write()
Returns the streams to write the data to.
Definition: basis.hh:103
Basic namespace for Concepts-2.
Definition: pml_formula.h:16
Page URL: http://wiki.math.ethz.ch/bin/view/Concepts/WebHome
21 August 2020
© 2020 Eidgenössische Technische Hochschule Zürich