Rheolef  7.1
an efficient C++ finite element environment
branch.h
Go to the documentation of this file.
1 #ifndef _RHEO_BRANCH_H
2 #define _RHEO_BRANCH_H
3 //
4 // This file is part of Rheolef.
5 //
6 // Copyright (C) 2000-2009 Pierre Saramito <Pierre.Saramito@imag.fr>
7 //
8 // Rheolef is free software; you can redistribute it and/or modify
9 // it under the terms of the GNU General Public License as published by
10 // the Free Software Foundation; either version 2 of the License, or
11 // (at your option) any later version.
12 //
13 // Rheolef is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 // GNU General Public License for more details.
17 //
18 // You should have received a copy of the GNU General Public License
19 // along with Rheolef; if not, write to the Free Software
20 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 //
22 // =========================================================================
23 // AUTHOR: Pierre.Saramito@imag.fr
24 
25 namespace rheolef {
65 } // namespace rheolef
66 
67 #include "rheolef/field.h"
68 
69 namespace rheolef {
70 
71 template <class T, class M> class __obranch;
72 template <class T, class M> class __iobranch;
73 template <class T, class M> class __branch_header;
74 template <class T, class M> class __const_branch_header;
75 template <class T, class M> class __const_branch_finalize;
76 
77 // =============================================================================
78 // class definition
79 // =============================================================================
80 
81 // [verbatim_branch_basic]
82 template <class T, class M = rheo_default_memory_model>
83 class branch_basic : public std::vector<std::pair<std::string,field_basic<T,M> > > {
84 public :
85 // typedefs:
86 
87  typedef std::vector<std::pair<std::string,field_basic<T,M> > > base;
88  typedef typename base::size_type size_type;
89 
90 // allocators:
91 
93  ~branch_basic();
96 
97  template <typename... Args>
98  branch_basic(const std::string& parameter, Args... names);
99 
100 // accessors:
101 
102  const T& parameter () const;
103  const std::string& parameter_name () const;
104  size_type n_value () const;
105  size_type n_field () const;
106 
107 // modifiers:
108 
109  void set_parameter_name (const std::string& name);
110  void set_parameter (const T& value);
111  void set_range (const std::pair<T,T>& u_range);
112 // [verbatim_branch_basic]
113 
114 // input/output:
115 
116  // get/set current value
117  template <typename... Args>
118  __obranch<T,M> operator() (const T& t, const field_basic<T,M>& u0, Args... uk);
119  template <typename... Args>
121 
125 
126 // implementation
127 
128 public:
129  template <class T1, class M1> friend class __obranch;
130  template <class T1, class M1> friend class __iobranch;
131 
132 // inputs (internals):
133 
134  template <class T1> friend void get_header (idiststream&, branch_basic<T1,sequential>&);
135  template <class T1> friend void get_event (idiststream&, branch_basic<T1,sequential>&);
136 
137 #ifdef _RHEOLEF_HAVE_MPI
138  template <class T1> friend void get_header (idiststream&, branch_basic<T1,distributed>&);
139  template <class T1> friend void get_event (idiststream&, branch_basic<T1,distributed>&);
140 #endif // _RHEOLEF_HAVE_MPI
141 
142  void get_header_rheolef (idiststream&);
143  void get_event_rheolef (idiststream&);
144 
145  template <class T1> friend void get_header_vtk (idiststream&, branch_basic<T1,sequential>&);
146  template <class T1> friend void get_event_vtk (idiststream&, branch_basic<T1,sequential>&);
147 
148 // outputs (internals):
149 
150  void put_header (odiststream&) const;
151  void put_finalize (odiststream&) const;
152 
153 // file formats
154  template <class T1> friend void put_header (odiststream&, const branch_basic<T1,sequential>&);
155  template <class T1> friend void put_event (odiststream&, const branch_basic<T1,sequential>&);
156  template <class T1> friend void put_finalize(odiststream&, const branch_basic<T1,sequential>&);
157 
158 #ifdef _RHEOLEF_HAVE_MPI
159  template <class T1> friend void put_header (odiststream&, const branch_basic<T1,distributed>&);
160  template <class T1> friend void put_event (odiststream&, const branch_basic<T1,distributed>&);
161  template <class T1> friend void put_finalize(odiststream&, const branch_basic<T1,distributed>&);
162 #endif // _RHEOLEF_HAVE_MPI
163 
164  void put_header_rheolef (odiststream&) const;
165  void put_event_rheolef (odiststream&) const;
166  void put_finalize_rheolef (odiststream&) const;
167 
168  template <class T1> friend void put_header_gnuplot (odiststream&, const branch_basic<T1,sequential>&);
169  template <class T1> friend void put_event_gnuplot (odiststream&, const branch_basic<T1,sequential>&);
170 
171 // file formats
172  template <class T1> friend void put_header (odiststream&, const branch_basic<T1,sequential>&);
173  template <class T1> friend void put_event (odiststream&, const branch_basic<T1,sequential>&);
174  template <class T1> friend void put_finalize(odiststream&, const branch_basic<T1,sequential>&);
175 
176 #ifdef _RHEOLEF_HAVE_MPI
177  template <class T1> friend void put_header (odiststream&, const branch_basic<T1,distributed>&);
178  template <class T1> friend void put_event (odiststream&, const branch_basic<T1,distributed>&);
179  template <class T1> friend void put_finalize(odiststream&, const branch_basic<T1,distributed>&);
180 #endif // _RHEOLEF_HAVE_MPI
181 
182  template <class T1> friend void put_header_gnuplot (odiststream&, const branch_basic<T1,sequential>&);
183  template <class T1> friend void put_event_gnuplot (odiststream&, const branch_basic<T1,sequential>&);
184  template <class T1> friend void put_finalize_gnuplot (odiststream&, const branch_basic<T1,sequential>&);
185 
186  template <class T1> friend void put_header_paraview (odiststream&, const branch_basic<T1,sequential>&);
187  template <class T1> friend void put_event_paraview (odiststream&, const branch_basic<T1,sequential>&);
188  template <class T1> friend void put_finalize_paraview(odiststream&, const branch_basic<T1,sequential>&);
189 
190  template <class T1> friend void put_header_vtk (odiststream&, const branch_basic<T1,sequential>&);
191  template <class T1> friend void put_event_vtk (odiststream&, const branch_basic<T1,sequential>&);
192  template <class T1> friend void put_event_vtk_stream (odiststream&, const branch_basic<T1,sequential>&);
193  template <class T1> friend void put_finalize_vtk (odiststream&, const branch_basic<T1,sequential>&);
194 
195 private:
196  template <typename... Args>
197  void fill_field_names (const std::string &field_name, Args... others);
198  void fill_field_names () {}
199  template <typename... Args>
200  void fill_field_values (std::size_t i, const field_basic<T,M>& ui, Args... uk);
201  void fill_field_values (std::size_t i) {}
202 // data:
203 protected:
204  std::string _parameter_name;
208  mutable std::ostream* _p_data_out;
209  mutable std::ostream* _p_ctrl_out;
210  mutable bool _header_in_done;
211  mutable bool _header_out_done;
212  mutable bool _finalize_out_done;
213  mutable std::string _to_clean;
214  mutable std::pair<T,T> _u_range;
215  mutable std::pair<bool,bool> _have_u_range;
216 // [verbatim_branch_basic_cont]
217 };
218 template <class T, class M> idiststream& operator>> (idiststream&, branch_basic<T,M>&);
219 template <class T, class M> odiststream& operator<< (odiststream&, const branch_basic<T,M>&);
220 // [verbatim_branch_basic_cont]
221 
222 template <class T, class M>
223 idiststream& operator>> (idiststream&, branch_basic<T,M>&);
224 
225 template <class T, class M>
227 
228 // [verbatim_branch]
230 // [verbatim_branch]
231 
232 // =============================================================================
233 // inlined
234 // =============================================================================
235 template <class T, class M>
236 inline
238  : std::vector<std::pair<std::string,field_basic<T,M> > >(0),
239  _parameter_name ("*unnamed*"),
240  _parameter_value(std::numeric_limits<T>::max()),
241  _n_value (std::numeric_limits<size_type>::max()),
242  _count_value (std::numeric_limits<size_type>::max()),
243  _p_data_out (0),
244  _p_ctrl_out (0),
245  _header_in_done (false),
246  _header_out_done (false),
247  _finalize_out_done (false),
248  _to_clean(),
249  _u_range(std::pair<T,T>( std::numeric_limits<T>::max(),
250  -std::numeric_limits<T>::max())),
251  _have_u_range(std::pair<bool,bool>(false,false))
252 {
253 }
254 template <class T, class M>
255 inline
257  : std::vector<std::pair<std::string,field_basic<T,M> > >(x),
258  _parameter_name (x._parameter_name),
259  _parameter_value(x._parameter_value),
260  _n_value (x._n_value),
261  _count_value (x._count_value),
262  _p_data_out (x._p_data_out),
263  _p_ctrl_out (x._p_ctrl_out),
264  _header_in_done (x._header_in_done),
265  _header_out_done (x._header_out_done),
266  _finalize_out_done (x._finalize_out_done),
267  _to_clean (x._to_clean),
268  _u_range (x._u_range),
269  _have_u_range (x._have_u_range)
270 {
271 }
272 template <class T, class M>
273 inline
276 {
277  std::vector<std::pair<std::string,field_basic<T,M> > >::operator= (x);
278  _parameter_name = x._parameter_name;
279  _parameter_value = x._parameter_value;
280  _n_value = x._n_value;
281  _count_value = x._count_value;
282  _p_data_out = x._p_data_out;
283  _p_ctrl_out = x._p_ctrl_out;
284  _header_in_done = x._header_in_done;
285  _header_out_done = x._header_out_done;
286  _finalize_out_done = x._finalize_out_done;
287  _to_clean = x._to_clean;
288  _u_range = x._u_range;
289  _have_u_range = x._have_u_range;
290  return *this;
291 }
292 template <class T, class M>
293  template <typename... Args>
294 inline branch_basic<T,M>::branch_basic(const std::string& parameter_name, Args... field_names)
295  : std::vector<std::pair<std::string,field_basic<T,M> > >(0),
296  _parameter_name (parameter_name),
297  _parameter_value(std::numeric_limits<Float>::max()),
298  _n_value (std::numeric_limits<size_type>::max()),
299  _count_value (std::numeric_limits<size_type>::max()),
300  _p_data_out (0),
301  _p_ctrl_out (0),
302  _header_in_done (false),
303  _header_out_done (false),
304  _finalize_out_done (false),
305  _to_clean(),
306  _u_range(std::pair<T,T>( std::numeric_limits<T>::max(),
307  -std::numeric_limits<T>::max())),
308  _have_u_range(std::pair<bool,bool>(false,false))
309 {
310  check_macro (parameter_name.length() != 0, "empty parameter name not allowed");
311  fill_field_names (field_names...);
312 }
313 template <class T, class M>
314 template <typename... Args>
315 inline void branch_basic<T,M>::fill_field_names (const std::string& field_name, Args... others) {
316  check_macro (field_name.length() != 0, "empty field name not allowed");
317  base::push_back (std::make_pair(field_name, field_basic<T,M>()));
318  fill_field_names (others...);
319 }
320 // -----------------------------------------------------------------------------
321 // accessors
322 // -----------------------------------------------------------------------------
323 template <class T, class M>
324 inline
325 const T&
327 {
328  return _parameter_value;
329 }
330 template <class T, class M>
331 inline
332 const std::string&
334 {
335  return _parameter_name;
336 }
337 template <class T, class M>
338 inline
341 {
342  return _n_value;
343 }
344 template <class T, class M>
345 inline
348 {
349  return base::size();
350 }
351 // -----------------------------------------------------------------------------
352 // modifiers
353 // -----------------------------------------------------------------------------
354 template <class T, class M>
355 inline
356 void
358 {
359  _parameter_name = name;
360 }
361 template <class T, class M>
362 inline
363 void
365 {
366  _parameter_value = x;
367 }
368 template <class T, class M>
369 inline
370 void
371 branch_basic<T,M>::set_range (const std::pair<T,T>& u_range)
372 {
373  _u_range = u_range;
374  _have_u_range = std::pair<bool,bool>(false,false);
375 }
376 // -----------------------------------------------------------------------------
377 // io header wrapper
378 // -----------------------------------------------------------------------------
379 template <class T, class M>
381  public:
383  friend idiststream& operator>> (idiststream& in, __branch_header<T,M> h) {
384  get_header(in, h._b); return in; }
386  h._b.put_header(out); return out; }
387  protected:
389  template <class T1, class M1> friend class __const_branch_header;
390 };
391 template <class T, class M>
393  public:
397  h._b.put_header(out); return out; }
398  protected:
400 };
401 template <class T, class M>
402 inline
405 {
406  return *this;
407 }
408 template <class T, class M>
409 inline
412 {
413  return *this;
414 }
415 // -----------------------------------------------------------------------------
416 // o finalize wrapper
417 // -----------------------------------------------------------------------------
418 template <class T, class M>
420  public:
423  h._b.put_finalize(out); return out; }
424  protected:
426 };
427 template <class T, class M>
428 inline
431 {
432  return *this;
433 }
434 // -----------------------------------------------------------------------------
435 // io value wrapper
436 // -----------------------------------------------------------------------------
437 template <class T, class M>
438 class __obranch {
439  public:
441  : _put(put), _x(x) {}
443  { m._put (os, m._x); return os; }
444  private:
445  odiststream& (*_put) (odiststream&, const branch_basic<T,M>&);
446  const branch_basic<T,M>& _x;
447 };
448 template <class T, class M>
449 class __iobranch {
450  public:
451  template <typename... Args>
453  idiststream& (*get)(idiststream&, branch_basic<T,M>&),
455  T& t,
456  field_basic<T,M>& u0,
457  Args&... uk)
458  : _put(put), _get(get), _px(&x), _pt(&t), _pu()
459  {
460  std::size_t n = sizeof...(Args)+1;
461  _pu.resize(n);
462  _pu[0] = &u0;
463  fill_field_references (1, uk...);
464  }
466  : _put(x._put), _get(x._get), _px(x._px), _pt(x._pt), _pu(x._pu) {}
467  template <typename... Args>
468  void fill_field_references (std::size_t i, field_basic<T,M>& ui, Args&... uk) {
469  _pu [i] = &ui;
470  fill_field_references (i+1, uk...);
471  }
472  void fill_field_references (std::size_t i) {}
473 
474  template <class T1, class M1>
476  template <class T1, class M1>
477  friend idiststream& operator>> (idiststream& is, __iobranch<T1,M1> m);
478  private:
479  odiststream& (*_put) (odiststream&, const branch_basic<T,M>&);
480  idiststream& (*_get) (idiststream&, branch_basic<T,M>&);
481  branch_basic<T,M> *_px;
482  T *_pt;
483 
484  std::vector<field_basic<T,M>*> _pu;
485 
486 private:
487  __iobranch<T,M>& operator= (const __iobranch<T,M>&);
488 };
489 template <class T, class M>
490 inline
492  m._put (os, *m._px);
493  return os;
494 }
495 template <class T, class M>
496 inline
497 idiststream& operator>> (idiststream& is, __iobranch<T,M> m) {
498  m._get (is, *m._px);
499  if (m._pt) { *m._pt = (*m._px).parameter(); }
500  for (std::size_t i = 0, n = (*m._px).size(); i < n; ++i) {
501  *(m._pu[i]) = (*m._px)[i].second;
502  }
503  return is;
504 }
505 template <class T, class M>
506 template <typename... Args>
507 inline
508 __obranch<T,M>
509 branch_basic<T,M>::operator() (const T& t, const field_basic<T,M>& u0, Args... uk) {
510  check_macro (base::size() >= sizeof...(Args)+1, "attempt to output a " << (sizeof...(Args)+1) <<"-field branch when a "
511  << base::size() << "-field one was supplied");
512  _parameter_value = t;
513  base::operator[](0).second = u0;
514  fill_field_values (1, uk...);
515  return __obranch<T,M> (operator<<, *this);
516 }
517 template <class T, class M>
518 template <typename... Args>
519 inline
522  check_macro (base::size() >= sizeof...(Args)+1, "attempt to output a " << (sizeof...(Args)+1) <<"-field branch when a "
523  << base::size() << "-field one was supplied");
524  _parameter_value = t;
525  base::operator[](0).second = u0;
526  fill_field_values (1, uk...);
527  return __iobranch<T,M> (operator<<, operator>>, *this, t, u0, uk...);
528 }
529 template <class T, class M>
530 template <typename... Args>
531 inline
532 void branch_basic<T,M>::fill_field_values(std::size_t id, const field_basic<T,M>& u_id, Args... uk) {
533  base::operator[](id++).second = u_id;
534  fill_field_values(id, uk...);
535 }
536 
537 }// namespace rheolef
538 #endif // define_RHEO_BRANCH_H
void put(idiststream &in, odiststream &out, bool do_proj, bool do_lumped_mass, bool def_fill_opt, size_type extract_id, const Float &scale_value, const std::pair< Float, Float > &u_range, render_type render)
Definition: branch.cc:500
field::size_type size_type
Definition: branch.cc:425
see the Float page for the full documentation
branch_basic< T, M > & _b
Definition: branch.h:388
__branch_header(branch_basic< T, M > &b)
Definition: branch.h:382
const branch_basic< T, M > & _b
Definition: branch.h:425
__const_branch_finalize(const branch_basic< T, M > &b)
Definition: branch.h:421
const branch_basic< T, M > & _b
Definition: branch.h:399
__const_branch_header(const branch_basic< T, M > &b)
Definition: branch.h:394
__const_branch_header(__branch_header< T, M > h)
Definition: branch.h:395
__iobranch(const __iobranch< T, M > &x)
Definition: branch.h:465
void fill_field_references(std::size_t i)
Definition: branch.h:472
void fill_field_references(std::size_t i, field_basic< T, M > &ui, Args &... uk)
Definition: branch.h:468
__iobranch(odiststream &(*put)(odiststream &, const branch_basic< T, M > &), idiststream &(*get)(idiststream &, branch_basic< T, M > &), branch_basic< T, M > &x, T &t, field_basic< T, M > &u0, Args &... uk)
Definition: branch.h:452
__obranch(odiststream &(*put)(odiststream &, const branch_basic< T, M > &), const branch_basic< T, M > &x)
Definition: branch.h:440
std::ostream * _p_ctrl_out
Definition: branch.h:209
branch_basic(const branch_basic< T, M > &)
Definition: branch.h:256
void set_range(const std::pair< T, T > &u_range)
Definition: branch.h:371
friend void put_event(odiststream &, const branch_basic< T1, sequential > &)
void put_header_rheolef(odiststream &) const
Definition: branch.cc:124
friend void put_event_paraview(odiststream &, const branch_basic< T1, sequential > &)
friend void put_finalize_gnuplot(odiststream &, const branch_basic< T1, sequential > &)
friend void get_header(idiststream &, branch_basic< T1, sequential > &)
std::string _parameter_name
Definition: branch.h:204
size_type _count_value
Definition: branch.h:207
friend void put_finalize_vtk(odiststream &, const branch_basic< T1, sequential > &)
void put_finalize_rheolef(odiststream &) const
Definition: branch.cc:210
friend void get_event(idiststream &, branch_basic< T1, sequential > &)
friend void get_event_vtk(idiststream &, branch_basic< T1, sequential > &)
friend void put_header_gnuplot(odiststream &, const branch_basic< T1, sequential > &)
const T & parameter() const
Definition: branch.h:326
void put_finalize(odiststream &) const
Definition: branch.cc:235
__const_branch_header< T, M > header() const
Definition: branch.h:411
void get_header_rheolef(idiststream &)
Definition: branch.cc:39
base::size_type size_type
Definition: branch.h:88
friend void put_header_vtk(odiststream &, const branch_basic< T1, sequential > &)
std::ostream * _p_data_out
Definition: branch.h:208
friend void put_finalize(odiststream &, const branch_basic< T1, sequential > &)
friend void put_finalize_paraview(odiststream &, const branch_basic< T1, sequential > &)
friend void get_header_vtk(idiststream &, branch_basic< T1, sequential > &)
void get_event_rheolef(idiststream &)
Definition: branch.cc:56
__obranch< T, M > operator()(const T &t, const field_basic< T, M > &u0, Args... uk)
Definition: branch.h:509
const std::string & parameter_name() const
Definition: branch.h:333
std::vector< std::pair< std::string, field_basic< T, M > > > base
Definition: branch.h:87
size_type n_value() const
Definition: branch.h:340
friend void put_header(odiststream &, const branch_basic< T1, sequential > &)
friend void put_event_gnuplot(odiststream &, const branch_basic< T1, sequential > &)
std::string _to_clean
Definition: branch.h:213
std::pair< T, T > _u_range
Definition: branch.h:214
friend void put_event_vtk_stream(odiststream &, const branch_basic< T1, sequential > &)
std::pair< bool, bool > _have_u_range
Definition: branch.h:215
__const_branch_finalize< T, M > finalize() const
Definition: branch.h:430
friend void put_header_paraview(odiststream &, const branch_basic< T1, sequential > &)
__branch_header< T, M > header()
Definition: branch.h:404
void put_event_rheolef(odiststream &) const
Definition: branch.cc:168
void set_parameter_name(const std::string &name)
Definition: branch.h:357
branch_basic(const std::string &parameter, Args... names)
Definition: branch.h:294
void put_header(odiststream &) const
Definition: branch.cc:160
size_type _n_value
Definition: branch.h:206
void set_parameter(const T &value)
Definition: branch.h:364
size_type n_field() const
Definition: branch.h:347
branch_basic< T, M > & operator=(const branch_basic< T, M > &)
Definition: branch.h:275
friend void put_event_vtk(odiststream &, const branch_basic< T1, sequential > &)
odiststream: see the diststream page for the full documentation
Definition: diststream.h:126
branch_basic< Float > branch
Definition: branch.h:229
rheolef::std value
Expr1::float_type T
Definition: field_expr.h:261
check_macro(expr1.have_homogeneous_space(Xh1), "dual(expr1,expr2); expr1 should have homogeneous space. HINT: use dual(interpolate(Xh, expr1),expr2)")
This file is part of Rheolef.
std::istream & operator>>(std::istream &is, const catchmark &m)
Definition: catchmark.h:88
void get_header(idiststream &in, branch_basic< T, sequential > &b)
Definition: branch.cc:82
std::ostream & operator<<(std::ostream &os, const catchmark &m)
Definition: catchmark.h:99
idiststream & operator>>(idiststream &is, __iobranch< T, M > m)
Definition: branch.h:497
ostream & operator<<(ostream &os, const tiny_element &K)
Definition: tiny_element.cc:27
Expr1::memory_type M
Definition: vec_expr_v2.h:416