rheolef  7.0
field.h
Go to the documentation of this file.
1 # ifndef _RHEOLEF_FIELD_H
2 # define _RHEOLEF_FIELD_H
3 
4 #include "rheolef/skit.h"
5 #include "rheolef/space.h"
6 #include "rheolef/undeterminated.h"
7 #include "rheolef/misc_algo.h" // copy_n
8 #include "rheolef/quadrature.h"
9 
10 namespace rheolef {
11 
12 template <class T, class M> class field_indirect;
13 template <class T, class M> class field_indirect_const;
14 template <class T, class M> class field_component;
15 template <class T, class M> class field_component_const;
16 template <class T, class M> class field_concat_value;
17 template <class T, class M> class band_basic;
18 
19 namespace details {
20 template <class Expr> struct is_field_expr_v2_linear_arg;
21 template <class Expr> struct is_field;
22 } // namespace details
23 
24 //<field:
230 template <class T, class M = rheo_default_memory_model>
231 class field_basic : public std::unary_function<point_basic<typename scalar_traits<T>::type>,T> {
232 public :
233 
234  typedef typename std::size_t size_type;
235  typedef M memory_type;
236  typedef T scalar_type;
238 // typedef undeterminated_basic<T> value_type; // TODO
239  typedef T value_type; // TO_CLEAN
244  class iterator;
245  class const_iterator;
246 
247 // allocator/deallocator:
248 
249  field_basic();
250 
251  explicit field_basic (
252  const space_type& V,
253  const T& init_value = std::numeric_limits<T>::max());
254 
255  void resize (
256  const space_type& V,
257  const T& init_value = std::numeric_limits<T>::max());
258 
259  field_basic<T,M>& operator= (const T&);
260  field_basic<T,M>& operator= (const field_basic<T,M>&);
261 
262  template <class Expr, class Sfinae
263  = typename std::enable_if<
266  >::type>
267  field_basic (const Expr& expr);
268 
269  template <class Expr, class Sfinae
270  = typename std::enable_if<
273  >::type>
274  field_basic<T, M>& operator= (const Expr&);
275 
276 
277 #ifdef _RHEOLEF_HAVE_STD_INITIALIZER_LIST
278  field_basic (const std::initializer_list<field_concat_value<T,M> >& init_list);
279  field_basic<T,M>& operator= (const std::initializer_list<field_concat_value<T,M> >& init_list);
280 #endif // _RHEOLEF_HAVE_STD_INITIALIZER_LIST
281 
282 
283  const space_type& get_space() const { return _V; }
284  const geo_type& get_geo() const { return _V.get_geo(); }
285  std::string stamp() const { return _V.stamp(); }
286  std::string get_approx() const { return _V.get_approx(); }
287  valued_type valued_tag() const { return _V.valued_tag(); }
288  const std::string& valued() const { return _V.valued(); }
289 
290 
291  const vec<T,M>& u() const { return _u; }
292  const vec<T,M>& b() const { return _b; }
293  vec<T,M>& set_u() { dis_dof_indexes_requires_update(); return _u; }
294  vec<T,M>& set_b() { dis_dof_indexes_requires_update(); return _b; }
295 
296 
297  T min() const;
298  T max() const;
299  T max_abs() const;
300  T min_abs() const;
301 
302 
303  field_indirect<T,M> operator[] (const geo_basic<T,M>& dom);
304  field_indirect_const<T,M> operator[] (const geo_basic<T,M>& dom) const;
305  field_indirect<T,M> operator[] (std::string dom_name);
306  field_indirect_const<T,M> operator[] (std::string dom_name) const;
307 
308 
309  size_type size() const { return _V.size(); }
310  field_component<T,M> operator[] (size_type i_comp);
311  field_component_const<T,M> operator[] (size_type i_comp) const;
312  field_component<T,M> operator() (size_type i_comp, size_type j_comp);
313  field_component_const<T,M> operator() (size_type i_comp, size_type j_comp) const;
314 
315 
316  const distributor& ownership() const { return get_space().ownership(); }
317  const communicator& comm() const { return ownership().comm(); }
318  size_type ndof() const { return ownership().size(); }
319  size_type dis_ndof() const { return ownership().dis_size(); }
320  T& dof (size_type idof);
321  const T& dof (size_type idof) const;
322  const T& dis_dof (size_type dis_idof) const;
323  dis_reference dis_dof_entry (size_type dis_idof);
324 
325  iterator begin_dof();
326  iterator end_dof();
327  const_iterator begin_dof() const;
328  const_iterator end_dof() const;
329 
330 // input/output:
331 
332  idiststream& get (idiststream& ips);
333  odiststream& put (odiststream& ops) const;
334  odiststream& put_field (odiststream& ops) const;
335 
336 
337  T dis_evaluate (const point_basic<T>& x, size_type i_comp = 0) const;
338  T operator() (const point_basic<T>& x) const { return dis_evaluate (x,0); }
339  point_basic<T> dis_vector_evaluate (const point_basic<T>& x) const;
340 
341 public:
342 
343  T evaluate (const geo_element& K, const point_basic<T>& hat_xq, size_type i_comp = 0) const;
344 
345  void dis_dof_update() const;
346 
347  template <class Expr>
348  void assembly_internal (
349  const geo_basic<T,M>& dom,
350  const geo_basic<T,M>& band,
351  const band_basic<T,M>& gh,
352  const Expr& expr,
353  const quadrature_option& qopt,
354  bool is_on_band);
355  template <class Expr>
356  void assembly (
357  const geo_basic<T,M>& domain,
358  const Expr& expr,
359  const quadrature_option& qopt);
360  template <class Expr>
361  void assembly (
362  const band_basic<T,M>& gh,
363  const Expr& expr,
364  const quadrature_option& qopt);
365 
366 protected:
367  void dis_dof_indexes_requires_update() const;
368  void dis_dof_assembly_requires_update() const;
369 
370  space_type _V;
371  mutable vec<T,M> _u;
372  mutable vec<T,M> _b;
375 };
376 template <class T, class M>
377 idiststream& operator >> (odiststream& ips, field_basic<T,M>& u);
378 
379 template <class T, class M>
380 odiststream& operator << (odiststream& ops, const field_basic<T,M>& uh);
381 
384 @endcode
385 
386 template <class T, class M>
387 class field_basic<T,M>::iterator {
388 protected:
389  typedef typename vec<T,M>::iterator data_t; // random acess
390  typedef typename disarray<space_pair_type,M>::const_iterator iter_t; // forward access
391 public:
392 
393 
394  typedef std::forward_iterator_tag iterator_category; // TODO: not fully random yet
395  typedef typename vec<T,M>::size_type size_type;
396  typedef T value_type;
397  typedef T& reference;
398  typedef T* pointer;
399  typedef std::ptrdiff_t difference_type;
400 
401 
403  : _blk_iub_iter(), _u(), _b()
404  {}
405  iterator (iter_t blk_iub_iter, data_t u, data_t b)
406  : _blk_iub_iter(blk_iub_iter), _u(u), _b(b)
407  {}
408 
409 
410  reference operator* () const {
411  size_type iub = (*_blk_iub_iter).iub();
412  size_type blk = (*_blk_iub_iter).is_blocked();
413  if (!blk) return _u[iub]; else return _b[iub];
414  }
415  iterator& operator++ () { _blk_iub_iter++; return *this; }
416  iterator operator++ (int) { iterator tmp = *this; operator++(); return *this; }
417  iterator& operator+= (difference_type n) { _blk_iub_iter += n; return *this; }
418  iterator operator+ (difference_type n) const { iterator tmp = *this; return tmp += n; }
419  reference operator[] (size_type n) const { return *(*this + n); }
420 
421 
422  bool operator== (const iterator& j) const { return _blk_iub_iter == j._blk_iub_iter; }
423  bool operator!= (const iterator& j) const { return ! operator== (j); }
424 protected:
425  friend class const_iterator;
427  data_t _u;
428  data_t _b;
429 };
430 template <class T, class M>
431 inline
434 {
435  dis_dof_indexes_requires_update();
436  return iterator (_V.data()._idof2blk_iub.begin(), _u.begin(), _b.begin());
437 }
438 template <class T, class M>
439 inline
442 {
443  dis_dof_indexes_requires_update();
444  return iterator (_V.data()._idof2blk_iub.end(), _u.begin(), _b.begin());
445 }
446 template <class T, class M>
448 protected:
451 public:
452 
453 
454  typedef std::forward_iterator_tag iterator_category;
455  typedef typename vec<T,M>::size_type size_type;
456  typedef T value_type;
457  typedef const T& reference;
458  typedef const T* pointer;
459  typedef std::ptrdiff_t difference_type;
460 
461 
463  : _blk_iub_iter(), _u(), _b()
464  {}
465  const_iterator (iter_t blk_iub_iter, data_t u, data_t b)
466  : _blk_iub_iter(blk_iub_iter), _u(u), _b(b)
467  {}
469  : _blk_iub_iter(i._blk_iub_iter), _u(i._u), _b(i._b)
470  {}
471 
472 
473  reference operator* () const {
474  size_type iub = (*_blk_iub_iter).iub();
475  size_type blk = (*_blk_iub_iter).is_blocked();
476  if (!blk) return _u[iub]; else return _b[iub];
477  }
478  const_iterator& operator++ () { _blk_iub_iter++; return *this; }
479  const_iterator operator++ (int) { const_iterator tmp = *this; operator++(); return *this; }
480  const_iterator& operator+= (difference_type n) { _blk_iub_iter += n; return *this; }
481  const_iterator operator+ (difference_type n) const { const_iterator tmp = *this; return tmp += n; }
482  reference operator[] (size_type n) const { return *(*this + n); }
483 
484 
485  bool operator== (const const_iterator& j) const { return _blk_iub_iter == j._blk_iub_iter; }
486  bool operator!= (const const_iterator& j) const { return ! operator== (j); }
487 protected:
489  data_t _u;
490  data_t _b;
491 };
492 template <class T, class M>
493 inline
496 {
497  return const_iterator (_V.data()._idof2blk_iub.begin(), _u.begin(), _b.begin());
498 }
499 template <class T, class M>
500 inline
503 {
504  return const_iterator (_V.data()._idof2blk_iub.end(), _u.begin(), _b.begin());
505 }
506 template <class T, class M>
507 inline
509  : _V(),
510  _u(),
511  _b(),
512  _dis_dof_indexes_requires_update(true),
513  _dis_dof_assembly_requires_update(false)
514 {
515 }
516 template <class T, class M>
517 inline
520 {
521  _V.operator= (x._V);
522  _u.operator= (x._u);
523  _b.operator= (x._b);
526  return *this;
527 }
528 template <class T, class M>
529 void
531 {
533 }
534 template <class T, class M>
535 void
537 {
539 }
540 template<class T, class M>
541 inline
544 {
545  check_macro (stamp() != "", "field=constant : uninitialized field in affectation");
546  std::fill (begin_dof(), end_dof(), value);
548  return *this;
549 }
550 template <class T, class M>
551 inline
552 T&
553 field_basic<T,M>::dof (size_type idof)
554 {
556  if (! _V.is_blocked(idof)) {
557  return _u [_V.iub(idof)];
558  } else {
559  return _b [_V.iub(idof)];
560  }
561 }
562 template <class T, class M>
563 inline
564 const T&
565 field_basic<T,M>::dof (size_type idof) const
566 {
567  if (! _V.is_blocked(idof)) {
568  return _u [_V.iub(idof)];
569  } else {
570  return _b [_V.iub(idof)];
571  }
572 }
573 template <class T, class M>
574 inline
575 T
577 {
578  T val = std::numeric_limits<T>::max();
579  for (const_iterator iter = begin_dof(), last = end_dof(); iter != last; iter++) {
580  val = std::min(val, *iter);
581  }
582 #ifdef _RHEOLEF_HAVE_MPI
584  val = mpi::all_reduce (comm(), val, mpi::minimum<T>());
585  }
586 #endif // _RHEOLEF_HAVE_MPI
587  return val;
588 }
589 template <class T, class M>
590 inline
591 T
593 {
594  T val = std::numeric_limits<T>::min();
595  for (const_iterator iter = begin_dof(), last = end_dof(); iter != last; iter++) {
596  val = std::max(val, *iter);
597  }
598 #ifdef _RHEOLEF_HAVE_MPI
600  val = mpi::all_reduce (comm(), val, mpi::maximum<T>());
601  }
602 #endif // _RHEOLEF_HAVE_MPI
603  return val;
604 }
605 template <class T, class M>
606 inline
607 T
609 {
610  T val = std::numeric_limits<T>::max();
611  for (const_iterator iter = begin_dof(), last = end_dof(); iter != last; iter++) {
612  val = std::min(val, abs(*iter));
613  }
614 #ifdef _RHEOLEF_HAVE_MPI
616  val = mpi::all_reduce (comm(), val, mpi::minimum<T>());
617  }
618 #endif // _RHEOLEF_HAVE_MPI
619  return val;
620 }
621 template <class T, class M>
622 inline
623 T
625 {
626  T val = 0;
627  for (const_iterator iter = begin_dof(), last = end_dof(); iter != last; iter++) {
628  val = std::max(val, abs(*iter));
629  }
630 #ifdef _RHEOLEF_HAVE_MPI
632  val = mpi::all_reduce (comm(), val, mpi::maximum<T>());
633  }
634 #endif // _RHEOLEF_HAVE_MPI
635  return val;
636 }
637 template <class T, class M>
638 inline
639 idiststream&
640 operator >> (idiststream& ips, field_basic<T,M>& uh)
641 {
642  return uh.get (ips);
643 }
644 template <class T, class M>
645 inline
647 operator << (odiststream& ops, const field_basic<T,M>& uh)
648 {
649  return uh.put (ops);
650 }
651 
652 }// namespace rheolef
653 # endif /* _RHEOLEF_FIELD_H */
vec< T, M >::dis_reference dis_reference
Definition: field.h:243
size_type ndof() const
Definition: field.h:318
distributor - data distribution table
Definition: distributor.h:19
disarray< space_pair_type, M >::const_iterator iter_t
Definition: field.h:450
const communicator & comm() const
Definition: field.h:317
T max_abs() const
Definition: field.h:624
std::size_t size_type
Definition: field.h:234
band - compute the band around a level set
Definition: band.h:45
std::string stamp() const
Definition: field.h:285
field - piecewise polynomial finite element field
iterator(iter_t blk_iub_iter, data_t u, data_t b)
Definition: field.h:405
field_basic< Float, sequential > field_sequential
Definition: field.h:383
vec< T, M > & set_b()
Definition: field.h:294
pair_with_linear_algebra< T1, T2 > operator*(const T0 &k, const pair_with_linear_algebra< T1, T2 > &x)
idiststream, odiststream - distributed interface for large data streams
Definition: diststream.h:68
size_type size() const
Definition: field.h:309
const_iterator(iter_t blk_iub_iter, data_t u, data_t b)
Definition: field.h:465
point - vertex of a mesh
Definition: point.h:22
void put(std::ostream &out, std::string name, const tiny_matrix< T > &a)
Definition: tiny_lu.h:106
std::string get_approx() const
Definition: field.h:286
T max() const
Definition: field.h:592
quadrature_option - send options to the integrate function
disarray - container in distributed environment
Definition: disarray.h:350
vec< T, M > & set_u()
Definition: field.h:293
irheostream, orheostream - large data streams
Definition: compiler.h:7
T & dof(size_type idof)
Definition: field.h:553
const std::string & valued() const
Definition: field.h:288
vec< T, M > _u
Definition: field.h:371
geo_basic< float_type, M > geo_type
Definition: field.h:241
T min_abs() const
Definition: field.h:608
field_basic< Float > field
Definition: field.h:382
vec< T, M >::const_iterator data_t
Definition: field.h:449
const geo_type & get_geo() const
Definition: field.h:284
bool operator==(const stack_allocator< T1 > &lhs, const stack_allocator< T1 > &rhs)
space_constant::valued_type valued_type
Definition: field.h:240
T min() const
Definition: field.h:576
float_traits< T >::type float_type
Definition: field.h:237
base::const_iterator const_iterator
Definition: vec.h:60
#define check_macro(ok_condition, message)
Definition: compiler.h:104
vec< T, M > _b
Definition: field.h:372
valued_type valued_tag() const
Definition: field.h:287
T max_abs(const T &x)
vec< T, M >::size_type size_type
Definition: field.h:455
std::forward_iterator_tag iterator_category
Definition: field.h:394
pair_with_linear_algebra< T1, T2 > operator+(const pair_with_linear_algebra< T1, T2 > &x, const pair_with_linear_algebra< T1, T2 > &y)
vec< T, M >::size_type size_type
Definition: field.h:395
const vec< T, M > & b() const
Definition: field.h:292
rheolef::std value
Definition: rotating-hill.h:1
std::ptrdiff_t difference_type
Definition: field.h:399
iterator operator++(int)
Definition: field.h:416
std::forward_iterator_tag iterator_category
Definition: field.h:454
space_basic< float_type, M > space_type
Definition: field.h:242
size_type dis_ndof() const
Definition: field.h:319
base::iterator iterator
Definition: vec.h:59
iterator begin_dof()
Definition: field.h:433
const distributor & ownership() const
Definition: field.h:316
const space_type & get_space() const
Definition: field.h:283
vec< T, M >::iterator data_t
Definition: field.h:389
void dis_dof_assembly_requires_update() const
Definition: field.h:536
disarray< space_pair_type, M >::const_iterator iter_t
Definition: field.h:390
std::istream & operator>>(std::istream &is, const catchmark &m)
Definition: catchmark.h:48
rheolef::std type
geo_element - element of a mesh
Expr1::memory_type M
Definition: vec_expr_v2.h:310
iterator end_dof()
Definition: field.h:441
vec - vector in distributed environment
Definition: vec.h:48
bool operator!=(const stack_allocator< T1 > &lhs, const stack_allocator< T1 > &rhs)
space_type _V
Definition: field.h:370
field_basic< T, M > & operator=(const T &)
Definition: field.h:543
void dis_dof_indexes_requires_update() const
Definition: field.h:530
bool _dis_dof_assembly_requires_update
Definition: field.h:374
idiststream & get(idiststream &ips)
Definition: field.cc:83
base::size_type size_type
Definition: vec.h:54
bool _dis_dof_indexes_requires_update
Definition: field.h:373
const vec< T, M > & u() const
Definition: field.h:291
bool evaluate(const geo_element &K, std::vector< Result > &value) const
const_iterator operator++(int)
Definition: field.h:479