Class documentation of Concepts

Loading...
Searching...
No Matches
matlab.hh
Go to the documentation of this file.
1
6#ifndef graphMatlab_hh
7#define graphMatlab_hh
8
9#include "basis.hh"
13
14#define MatlabGraphConstr_D 0
15#define MatlabMeshWriteFormula_D 0
16
17namespace concepts {
18 // forward declaration
19 template<class F>
20 class Formula;
21}
22
23
24namespace 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
227 BaseMeshCell matlab(s_ptr_, dim, concepts::ElementGraphicsBase::MATLAB);
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,
244 concepts::ElementGraphicsBase::MATLAB, sol, fun);
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
260 (s_ptr_, dim, concepts::ElementGraphicsBase::MATLAB, frm);
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,
275 concepts::ElementGraphicsBase::MATLAB, frm,
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,
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>
303 void MatlabGraphics::write_(concepts::GlobalPostprocess<F>& postProcess,
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
virtual Connector & connector() const =0
Returns the connector.
Real2d chi(Real xi, Real eta) const
std::vector< uint > & count()
Number of points written to the files, used for mesh representation.
Definition basis.hh:108
virtual uint n() const =0
Number of components.
virtual std::ostream & info(std::ostream &os) const
Returns information in an output stream.
MatlabGraphics(const concepts::Space< G > &spc, const std::string filename, const uint dim=2)
Definition matlab.hh:220
MatlabGraphics(concepts::Mesh &msh, const std::string filename, const uint dim=2, const uint points=noPoints)
void operator()(const concepts::Space< G > &spc, const concepts::Vector< F > &sol, const concepts::ElementFunction< F, G > *fun=0)
Definition matlab.hh:283
static void writeCoord(typename concepts::Point< Real, dim > x, std::map< std::string, std::ostream * > &os)
Definition matlab.hh:396
static void writeAttributes(const concepts::Connector &cntr, std::map< std::string, std::ostream * > &os)
virtual std::ostream & info(std::ostream &os) const
Returns information in an output stream.
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)
Definition matlab.hh:411
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)
#define conceptsAssert(cond, exc)
#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 matlabEnding(const std::string &filename)
Returns a string with ".m" ending.