matlab.hh

Go to the documentation of this file.
1 
6 #ifndef graphMatlab_hh
7 #define graphMatlab_hh
8 
9 #include "basis.hh"
10 #include "basics/outputMatlab.hh"
13 
14 #define MatlabGraphConstr_D 0
15 #define MatlabMeshWriteFormula_D 0
16 
17 namespace concepts {
18  // forward declaration
19  template<class F>
20  class Formula;
21 }
22 
23 
24 namespace graphics {
25 
26  using concepts::Real;
27  using concepts::Real2d;
28 
29  // ********************************************************** matlabEnding **
30 
32  std::string matlabEnding(const std::string& filename);
33 
34  // ******************************************************** MatlabGraphics **
35 
114  class MatlabGraphics : public OutputBase {
115  public:
121  template<class G>
122  MatlabGraphics(const concepts::Space<G>& spc, const std::string filename,
123  const uint dim = 2);
129  MatlabGraphics(concepts::Mesh& msh, const std::string filename,
130  const uint dim = 2, const uint points = noPoints);
131 
139  template<class F, class G>
140  MatlabGraphics(const concepts::Space<G>& spc, const std::string filename,
141  const concepts::Vector<F>& sol, const uint dim = 2,
142  const concepts::ElementFunction<F,G>* fun = 0);
143 
150  template<class F, class G>
151  MatlabGraphics(const concepts::Space<G>& spc, const std::string filename,
153  const uint dim = 2);
161  template<class F>
162  MatlabGraphics(concepts::Mesh& msh, const std::string filename,
164  const uint dim = 2, const uint points = noPoints);
165 
166  virtual ~MatlabGraphics() {}
167 
174  template<class F, class G>
175  void operator()(const concepts::Space<G>& spc,
176  const concepts::Vector<F>& sol,
177  const concepts::ElementFunction<F,G>* fun = 0);
178 
184  template<class F, class G>
185  void operator()(const concepts::Space<G>& spc,
186  const concepts::Formula<F>& frm);
192  template<class F, class G>
193  void operator()(concepts::Mesh& msh, const concepts::Formula<F>& frm,
194  const uint points = 5);
195 
196  static uint noPoints;
197  protected:
198  virtual std::ostream& info(std::ostream& os) const;
199  private:
203  template<class F>
204  void write_(concepts::GlobalPostprocess<F>& postProcess,
205  BaseOutputCell<F>& matlab, bool data = false);
207  void createStreams_(bool data);
209  void closeStreams_(const uint& n);
210 
212  std::map<std::string, std::ostream*> s_ptr_;
214  uint dim_;
216  uint cnt_;
217  };
218 
219  template<class G>
221  const std::string filename, const uint dim)
222  : OutputBase(matlabEnding(filename)), dim_(dim), cnt_(0)
223  {
224  // Post processor (global)
225  concepts::GlobalPostprocess<G> postProcess(spc);
226  // Post processor on cell
228  // Creates streams, writes to streams, writes to file and clear
229  // and delete all streams.
230  write_(postProcess, matlab);
231  }
232 
233  template<class F, class G>
235  const std::string filename,
236  const concepts::Vector<F>& sol,
237  const uint dim,
239  : OutputBase(matlabEnding(filename)), dim_(dim), cnt_(0) {
240  // Post processor (global)
241  concepts::GlobalPostprocess<G> postProcess(spc);
242  // Post processor on cell
243  BaseDataCell<F,G> matlab(s_ptr_, dim,
245  // Creates streams, writes to streams, writes to file and clear
246  // and delete all streams.
247  write_(postProcess, matlab, true);
248  }
249 
250  template<class F, class G>
252  const std::string filename,
254  const uint dim)
255  : OutputBase(matlabEnding(filename)), dim_(dim), cnt_(0) {
256  // Post processor (global)
257  concepts::GlobalPostprocess<G> postProcess(spc);
258  // Post processor on cell
261  // Creates streams, writes to streams, writes to file and clear
262  // and delete all streams.
263  write_(postProcess, matlab, true);
264  }
265 
266  template<class F>
267  MatlabGraphics::MatlabGraphics(concepts::Mesh& msh, const std::string filename,
269  const uint dim, const uint points)
270  : OutputBase(matlabEnding(filename)), dim_(dim), cnt_(0) {
271  // Post processor (global)
272  concepts::GlobalPostprocess<Real> postProcess(msh);
273  // Post processor on cell
274  BaseFormulaCell<F,Real> matlab(s_ptr_, dim,
276  points);
277  // Creates streams, writes to streams, writes to file and clear
278  // and delete all streams.
279  write_(postProcess, matlab, true);
280  }
281 
282  template<class F, class G>
284  const concepts::Vector<F>& sol,
285  const concepts::ElementFunction<F,G>* fun) {
286 
287  }
288 
289  template<class F, class G>
291  const concepts::Formula<F>& frm) {
292 
293  }
294 
295  template<class F, class G>
297  const concepts::Formula<F>& frm,
298  const uint points) {
299 
300  }
301 
302  template<class F>
304  BaseOutputCell<F>& matlab, bool data)
305  {
306  // Create the streams
307  createStreams_(data);
308  // set counter to zero
309  matlab.count().assign(1, 0);
310  // Post processor on cell
311  DEBUGL(MatlabGraphConstr_D, matlab);
312  // loop over cells or elements and write into streams
313  postProcess(matlab);
314  // write to file, clear and delete streams
315  closeStreams_(matlab.n());
316  }
317 
318  // ************************************************************* MatlabMesh **
319 
326  public:
337  static void writeMesh(const concepts::Cell& cell,
338  std::map<std::string, std::ostream*>& os,
339  const concepts::Array<uint>& np, uint& cnt,
340  bool boundary = false, bool coord = true);
350  template<class F>
351  static void writeFormula(const concepts::Cell& cell,
352  std::map<std::string, std::ostream*>& os,
353  const concepts::Array<uint>& np, uint& cnt,
362  static void writeAttributes(const concepts::Connector& cntr,
363  std::map<std::string, std::ostream*>& os);
369  template<uint dim>
370  static void writeCoord(typename concepts::Point<Real, dim> x,
371  std::map<std::string, std::ostream*>& os);
373  std::map<std::string, std::ostream*>& os);
374  static void writeCoord(const concepts::Point<Real, 3> x,
375  std::map<std::string, std::ostream*>& os,
376  const uint dim);
377  protected:
378  virtual std::ostream& info(std::ostream& os) const;
379  private:
380  static void writeMesh_(const concepts::Quad2d& quad,
381  std::map<std::string, std::ostream*>& os,
382  const concepts::Array<uint>& np, uint& cnt,
383  bool boundary = false, bool coord = true);
384  static void writeMesh_(const concepts::InfiniteQuad2d& quad,
385  std::map<std::string, std::ostream*>& os,
386  const concepts::Array<uint>& np, uint& cnt,
387  bool boundary = false, bool coord = true);
388  static void writeMesh_(const concepts::Edge2d& quad,
389  std::map<std::string, std::ostream*>& os,
390  const concepts::Array<uint>& np, uint& cnt,
391  bool boundary = false, bool coord = true);
392  };
393 
394 
395  template<uint dim>
397  std::map<std::string, std::ostream*>& os) {
399  *os["x"] << x[0] << " ";
400  if (dim > 1) {
402  *os["y"] << x[1] << " ";
403  if (dim > 2) {
405  *os["z"] << x[2] << " ";
406  }
407  }
408  }
409 
410  template<class F>
412  std::map<std::string, std::ostream*>& os,
413  const concepts::Array<uint>& np, uint& cnt,
415  DEBUGL(MatlabMeshWriteFormula_D, "cell = " << cell);
416 
417  // writes mesh, but not the coordinates
418  writeMesh(cell, os, np, cnt, false, false);
419 
420  F f; // formula value
421 
422  // 2D quadrilaterial
423  const concepts::Quad2d* cellQ =
424  dynamic_cast<const concepts::Quad2d*>(&cell);
425  if (cellQ) {
426  Real2d x; // coordinates
427  for (uint j = 0; j < np[1]; ++j) {
428  Real py = (Real)j / (np[1]-1);
429  for (uint i = 0; i < np[0]; ++i) {
430  x = cellQ->chi((Real)i/(np[0]-1), py);
431  // write coordinates
432  writeCoord(x, os);
433  // write value (particularly components)
434  f = (*frm)(cell.connector(), x);
435  DEBUGL(MatlabMeshWriteFormula_D, "f = " << f);
436  *os["u"] << concepts::OutputMatlab<F>(f) << ' ';
437  } // for i
438  } // for j
439  } // cellQ
440  }
441 
442 } // namespace graphics
443 
444 #endif // graphMatlab_hh
445 
Draws a picture of data in Matlab format and stores the result in a single file.
Definition: matlab.hh:114
#define MatlabMeshWriteFormula_D
Definition: matlab.hh:15
virtual Connector & connector() const =0
Returns the connector.
A 2D cell: quadrilateral.
Definition: cell2D.hh:378
Real2d chi(Real xi, Real eta) const
Evaluates the element map.
An abstract class for a function in a FE space.
static void writeMesh_(const concepts::InfiniteQuad2d &quad, std::map< std::string, std::ostream * > &os, const concepts::Array< uint > &np, uint &cnt, bool boundary=false, bool coord=true)
Piecewise defined function on a number of cells.
virtual uint n() const =0
Number of components.
static void writeCoord(const concepts::Point< Real, 3 > x, std::map< std::string, std::ostream * > &os, const uint dim)
std::string matlabEnding(const std::string &filename)
Returns a string with ".m" ending.
Routines for writing mesh and formula for a single cell for different cell types.
Definition: matlab.hh:325
static void writeFormula(const concepts::Cell &cell, std::map< std::string, std::ostream * > &os, const concepts::Array< uint > &np, uint &cnt, const concepts::PiecewiseFormulaBase< F > *frm)
Writes for a cell a formula on the mesh, with coordinates, to output streams.
Definition: matlab.hh:411
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
static void writeAttributes(const concepts::Connector &cntr, std::map< std::string, std::ostream * > &os)
Writes for a cell the attributes to output streams.
virtual ~MatlabGraphics()
Definition: matlab.hh:166
Base class for graphical output to a file.
Definition: basis.hh:74
Interface for a formula.
Definition: lform.hh:18
#define conceptsAssert(cond, exc)
Assert that a certain condition is fulfilled.
Definition: exceptions.hh:394
Class for output of objects to matlab.
Definition: outputMatlab.hh:88
A 1D cell: edge in 2D.
Definition: cell1D.hh:189
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.
virtual std::ostream & info(std::ostream &os) const
Returns information in an output stream.
#define DEBUGL(doit, msg)
Writes the mesh to the given streams (for a cell).
Definition: basis.hh:263
static void writeMesh(const concepts::Cell &cell, std::map< std::string, std::ostream * > &os, const concepts::Array< uint > &np, uint &cnt, bool boundary=false, bool coord=true)
Writes for a cell the mesh, eventually with coordinates, to output streams.
Class for writing the graphical output of a FE solution represented by a coefficient vector (and poss...
Definition: basis.hh:140
uint cnt_
Number of vectors written to the files.
Definition: matlab.hh:216
std::map< std::string, std::ostream * > s_ptr_
Pointer to the streams, i.e. *(s_ptr_["vtxmsh"]) for FE mesh.
Definition: matlab.hh:212
void operator()(const concepts::Space< G > &spc, const concepts::Vector< F > &sol, const concepts::ElementFunction< F, G > *fun=0)
Application operator for output of solutions and functions of it.
Definition: matlab.hh:283
Exception class for assertions.
Definition: exceptions.hh:258
Graphics.
Definition: basis.hh:33
static void writeCoord(concepts::Point< Real, 2 > x, std::map< std::string, std::ostream * > &os)
void createStreams_(bool data)
Create the streams.
void write_(concepts::GlobalPostprocess< F > &postProcess, BaseOutputCell< F > &matlab, bool data=false)
Creates standard streams, writes to streams, writes to file and clear and delete all streams.
Definition: matlab.hh:303
Interface for a formula defined element by element.
MatlabGraphics(const concepts::Space< G > &spc, const std::string filename, const uint dim=2)
Constructor for output of mesh only.
Definition: matlab.hh:220
static void writeCoord(typename concepts::Point< Real, dim > x, std::map< std::string, std::ostream * > &os)
Writes the coordinates of one point to output streams.
Definition: matlab.hh:396
Writes element formula for a cell to the given streams.
Definition: basis.hh:186
std::vector< uint > & count()
Number of points written to the files, used for mesh representation.
Definition: basis.hh:108
#define MatlabGraphConstr_D
Definition: matlab.hh:14
static uint noPoints
Definition: matlab.hh:196
MatlabGraphics(concepts::Mesh &msh, const std::string filename, const uint dim=2, const uint points=noPoints)
Constructor for output of mesh only.
A 2D cell: infinite quadrilateral.
Definition: cell2D.hh:610
static void writeMesh_(const concepts::Quad2d &quad, std::map< std::string, std::ostream * > &os, const concepts::Array< uint > &np, uint &cnt, bool boundary=false, bool coord=true)
uint dim_
Spatial dimension of the space.
Definition: matlab.hh:214
An abstract class for meshes.
Definition: mesh.hh:76
static void writeMesh_(const concepts::Edge2d &quad, std::map< std::string, std::ostream * > &os, const concepts::Array< uint > &np, uint &cnt, bool boundary=false, bool coord=true)
void closeStreams_(const uint &n)
Closes the streams.
Class providing an output operator.
An abstract class for elements of the topology.
Definition: connector.hh:85
double Real
Type normally used for a floating point number.
Definition: typedefs.hh:36
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