Rheolef  7.1
an efficient C++ finite element environment
field_indirect.h
Go to the documentation of this file.
1 # ifndef _RHEOLEF_FIELD_INDIRECT_H
2 # define _RHEOLEF_FIELD_INDIRECT_H
23 
24 #include "rheolef/field.h"
25 
26 namespace rheolef {
27 
28 // forward:
29 template <class T, class M>
30 class field_indirect_const;
31 
32 // =================================================================================
33 // field_indirect
34 // as for:
35 // uh["left"] = value
36 // uh["left"] = gh
37 // =================================================================================
38 template <class T, class M = rheo_default_memory_model>
40 public:
41 // typedefs
42 
44  typedef T value_type;
45  typedef M memory_type;
48  class iterator;
49  class const_iterator;
50 
51 // allocators:
52 
54  : _V(uh.get_space()),
55  _W(),
56  _dom(dom),
57  _indirect(),
58  _val(uh.begin_dof())
59  {
60  if (! (_V.get_basis().option().is_restricted_to_sides()
61  && _V.get_geo().map_dimension() == _dom.map_dimension() + 1)) {
62  _W = space_basic<T,M> (dom, _V.get_basis().name());
63  } else {
64  // restricted on a subdomain: e.g. Pkd[sides](square) => Pkd(square[interface])
65  // i.e. the basis should remove the "sides" option
66  size_type k = _V.get_basis().degree();
67  _W = space_basic<T,M> (dom, "P"+itos(k)+"d", _V.valued());
68 #ifdef TODO
69  // TODO: more general, by skipping "sides" in option basis: how to do that?
70  // something as: basis b2 = b; bopt=b.opt(); bopt.set_restr(false); b2.reset(bopt);
71  // space (omega,b2.name());
72  basis b = _V.get_basis();
73  basis_option bopt = b.option();
74  bopt.set_restricted_to_sides (false);
75  b.reset (bopt);
76  _W = space_basic<T,M> (dom, b.name()); // TODO: a cstor space(dom,basis) ?
77  // => fatal(../../include/rheolef/smart_pointer.h,330): no_copy functor called (illegal copy)
78 #endif // TODO
79  }
80  _indirect = disarray<size_type,M> (_V.build_indirect_array (_W, dom));
81  }
82 
84 
86 
87  template <class Expr,
88  class Sfinae
89  = typename std::enable_if<
92  >::type>
93  field_indirect<T,M>& operator= (const Expr&);
94 
95  // explicit copy cstor (avoid simple copy of the proxy; see nfem/ptst/field_comp_assign_tst.cc )
97  return this -> template operator=<field_indirect<T,M> > (expr);
98  }
99 
100 // accessors:
101 
102  const distributor& ownership() const { return _indirect.ownership(); }
103  const communicator& comm() const { return ownership().comm(); }
104  size_type ndof() const { return ownership().size(); }
105  size_type dis_ndof() const { return ownership().dis_size(); }
106  std::string name() const;
107  const space_basic<T,M>& get_space() const { return _W; }
108  bool have_homogeneous_space (space_basic<T,M>& Xh) const { Xh = get_space(); return true; }
109  T& dof (size_type idof) { return _val [_indirect [idof]]; }
110  const T& dof (size_type idof) const { return _val [_indirect [idof]]; }
111 
112  iterator begin_dof();
113  iterator end_dof();
114  const_iterator begin_dof() const;
116 protected:
117  friend class field_basic<T,M>;
118  friend class field_indirect_const<T,M>;
119  static std::string _name_internal (const space_basic<T,M>& V, const geo_basic<T,M>& dom);
120 // data:
125  typename field_basic<T,M>::iterator _val; // iterator = reference on an external variable uh
126  // => cstor is protected : prevent copy outside the field class
127 };
128 template<class T, class M>
129 inline
132 {
133  std::fill (begin_dof(), end_dof(), alpha);
134  return *this;
135 }
136 template<class T, class M>
137 inline
138 std::string
140 {
141  return _name_internal (_V, _dom);
142 }
143 template<class T, class M>
144 std::string
146  const space_basic<T,M>& V,
147  const geo_basic<T,M>& dom)
148 {
149  // e.g. "P1(square[left]", an unique signature for field_expr<Expr> size-like checks
150  std::string dom_name = (dom.variant() != geo_abstract_base_rep<T>::geo_domain) ?
151  V.get_geo().name() + "[" + dom.name() + "]" :
152  dom.name();
153  return V.get_basis().name() + "{" + dom_name + "}";
154 }
155 template<class T, class M>
156 inline
159 {
160  dis_dof_indexes_requires_update();
161  return field_indirect<T,M> (*this, dom);
162 }
163 template<class T, class M>
164 inline
166 field_basic<T,M>::operator[] (std::string dom_name)
167 {
168  dis_dof_indexes_requires_update();
169  return operator[] (get_space().get_geo().operator[] (dom_name));
170 }
171 // =================================================================================
172 // field_indirect::iterator
173 // =================================================================================
174 template <class T, class M>
176 public:
177 // typedef:
178  typedef std::forward_iterator_tag iterator_category; // TODO: not fully random yet
179  typedef typename vec<T,M>::size_type size_type;
180  typedef T value_type;
181  typedef T& reference;
182  typedef T* pointer;
183  typedef std::ptrdiff_t difference_type;
184 // allocator:
186  : _idof_iter(idof_iter), _val(val) {}
187 
188 // accessors & modifiers:
189  T& operator* () { return _val [*_idof_iter]; }
190  const T& operator* () const { return _val [*_idof_iter]; }
191  iterator& operator++() { ++_idof_iter; return *this; }
192 
193 // comparators:
194 
195  bool operator== (const iterator& j) const { return _idof_iter == j._idof_iter; }
196  bool operator!= (const iterator& j) const { return ! operator== (j); }
197 protected:
198 // data:
201 };
202 template<class T, class M>
203 inline
206 {
207  return iterator (_indirect.begin(), _val);
208 }
209 template<class T, class M>
210 inline
213 {
214  return iterator (_indirect.end(), _val);
215 }
216 // =================================================================================
217 // field_indirect::const_iterator
218 // =================================================================================
219 template <class T, class M>
221 public:
222 // typedef:
223  typedef std::forward_iterator_tag iterator_category; // TODO: not fully random yet
224  typedef typename vec<T,M>::size_type size_type;
225  typedef T value_type;
226  typedef const T& reference;
227  typedef const T* pointer;
228  typedef std::ptrdiff_t difference_type;
229 // allocator:
231  : _idof_iter(idof_iter), _val(val) {}
232 
233 // accessors & modifiers:
234  const T& operator* () const { return _val [*_idof_iter]; }
235  const_iterator& operator++() { ++_idof_iter; return *this; }
236 
237 // comparators:
238 
239  bool operator== (const const_iterator& j) const { return _idof_iter == j._idof_iter; }
240  bool operator!= (const const_iterator& j) const { return ! operator== (j); }
241 protected:
242 // data:
245 };
246 template<class T, class M>
247 inline
250 {
251  return const_iterator (_indirect.begin(), _val);
252 }
253 template<class T, class M>
254 inline
257 {
258  return const_iterator (_indirect.end(), _val);
259 }
260 // =================================================================================
261 // field_indirect_const
262 // as for:
263 // gh = uh["left"]
264 // =================================================================================
265 template <class T, class M = rheo_default_memory_model>
267 public:
268 //protected:
269 
270 // typedefs:
271 
273  typedef T scalar_type;
274  typedef T value_type; // TODO: run-time dependent
275  typedef M memory_type;
276  class const_iterator;
277 
278 // allocators:
279 
281  : _V(uh.get_space()),
282  _W(dom, _V.get_basis().name()),
283  _dom(dom),
284  _indirect(_V.build_indirect_array (_W, dom)),
285  _val(uh.begin_dof())
286  {}
287 
289  : _V(gh._V),
290  _W(gh._W),
291  _dom(gh._dom),
292  _indirect(gh._indirect),
293  _val(gh._val)
294  {}
295 
296 // accessors:
297 //protected:
298 
299  const distributor& ownership() const { return _indirect.ownership(); }
300  const communicator& comm() const { return ownership().comm(); }
301  size_type ndof() const { return ownership().size(); }
302  size_type dis_ndof() const { return ownership().dis_size(); }
303  std::string name() const;
304  space_basic<T,M> get_space() const { return _W; }
305  bool have_homogeneous_space (space_basic<T,M>& Xh) const { Xh = get_space(); return true; }
306 
307  const T& dof(size_type idof) const { return _val [_indirect [idof]]; }
308 
309  const_iterator begin_dof() const;
310  const_iterator end_dof() const;
311  friend class field_basic<T,M>;
312 protected:
317  typename field_basic<T,M>::const_iterator _val; // iterator = reference on an external variable uh
318  // thus cstor is protected to prevent copy outside the field class
319 };
320 template<class T, class M>
321 inline
322 std::string
324 {
326 }
327 template<class T, class M>
328 inline
331 {
332  return field_indirect_const<T,M> (*this, dom);
333 }
334 template<class T, class M>
335 inline
337 field_basic<T,M>::operator[] (std::string dom_name) const
338 {
339  return operator[] (get_space().get_geo().operator[] (dom_name));
340 }
341 // =================================================================================
342 // field_indirect_const::const_iterator
343 // =================================================================================
344 template <class T, class M>
346 public:
347 // typedefs:
348 
349  typedef std::forward_iterator_tag iterator_category; // TODO: not fully random yet
350  typedef typename vec<T,M>::size_type size_type;
351  typedef T value_type;
352  typedef const T& reference;
353  typedef const T* pointer;
354  typedef std::ptrdiff_t difference_type;
355 
356 // allocator:
358  : _idof_iter(idof_iter), _val(val) {}
359 
360 // accessors & modifiers:
361  const T& operator* () const { return _val [*_idof_iter]; }
362  const_iterator& operator++() { ++_idof_iter; return *this; }
363 
364 // comparators:
365 
366  bool operator== (const const_iterator& j) const { return _idof_iter == j._idof_iter; }
367  bool operator!= (const const_iterator& j) const { return ! operator== (j); }
368 protected:
369 // data:
372 };
373 template<class T, class M>
374 inline
377 {
378  return const_iterator (_indirect.begin(), _val);
379 }
380 template<class T, class M>
381 inline
384 {
385  return const_iterator (_indirect.end(), _val);
386 }
387 // =================================================================================
388 // io
389 // =================================================================================
390 template <class T, class M>
391 inline
394 {
395  field_basic<T,M> tmp = uh;
396  return tmp.put (ops);
397 }
398 template <class T, class M>
399 inline
402 {
403  field_basic<T,M> tmp = uh;
404  return tmp.put (ops);
405 }
406 
407 }// namespace rheolef
408 # endif /* _RHEOLEF_FIELD_INDIRECT_H */
field gh(Float epsilon, Float t, const field &uh, const test &v)
see the basis page for the full documentation
see the basis_option page for the full documentation
Definition: basis_option.h:93
void set_restricted_to_sides(bool r=true)
Definition: basis_option.h:281
see the distributor page for the full documentation
Definition: distributor.h:62
size_type dis_size() const
global and local sizes
Definition: distributor.h:207
size_type size(size_type iproc) const
Definition: distributor.h:163
const communicator_type & comm() const
Definition: distributor.h:145
field_indirect< T, M > operator[](const geo_basic< T, M > &dom)
field_basic< T, M >::const_iterator _val
std::forward_iterator_tag iterator_category
disarray< size_type, M >::const_iterator _idof_iter
const_iterator(typename disarray< size_type, M >::const_iterator idof_iter, typename field_basic< T, M >::const_iterator val)
field_basic< T, M >::iterator _val
std::forward_iterator_tag iterator_category
vec< T, M >::size_type size_type
iterator(typename disarray< size_type, M >::const_iterator idof_iter, typename field_basic< T, M >::iterator val)
disarray< size_type, M >::const_iterator _idof_iter
field_basic< T, M >::const_iterator _val
disarray< size_type, M >::const_iterator _idof_iter
const_iterator(typename disarray< size_type, M >::const_iterator idof_iter, typename field_basic< T, M >::const_iterator val)
field_basic< T, M >::const_iterator _val
disarray< size_type, M > _indirect
space_basic< T, M > get_space() const
field_basic< T, M >::size_type size_type
const T & dof(size_type idof) const
const distributor & ownership() const
field_indirect_const(const field_basic< T, M > &uh, const geo_basic< T, M > &dom)
const communicator & comm() const
bool have_homogeneous_space(space_basic< T, M > &Xh) const
field_indirect_const(field_indirect< T, M > gh)
field_basic< T, M >::iterator _val
field_indirect< T, M > & operator=(const T &alpha)
std::string name() const
static std::string _name_internal(const space_basic< T, M > &V, const geo_basic< T, M > &dom)
size_type dis_ndof() const
disarray< size_type, M > _indirect
const space_basic< T, M > & get_space() const
T & dof(size_type idof)
field_basic< T, M >::size_type size_type
const T & dof(size_type idof) const
const distributor & ownership() const
scalar_traits< value_type >::type scalar_type
float_traits< scalar_type >::type float_type
geo_basic< T, M > _dom
const communicator & comm() const
size_type ndof() const
bool have_homogeneous_space(space_basic< T, M > &Xh) const
space_basic< T, M > _V
space_basic< T, M > _W
field_indirect(field_basic< T, M > &uh, const geo_basic< T, M > &dom)
abstract base interface class
Definition: geo.h:248
odiststream: see the diststream page for the full documentation
Definition: diststream.h:126
see the vec page for the full documentation
Definition: vec.h:79
rheolef::std type
void get_geo(istream &in, my_geo &omega)
Expr1::float_type T
Definition: field_expr.h:261
return a operator*(eh)
Float alpha[pmax+1][pmax+1]
Definition: bdf.icc:28
This file is part of Rheolef.
bool operator==(const heap_allocator< T1 > &lhs, const heap_allocator< T1 > &rhs)
std::string itos(std::string::size_type i)
itos: see the rheostream page for the full documentation
bool operator!=(const heap_allocator< T1 > &lhs, const heap_allocator< T1 > &rhs)
const_iterator begin_dof() const
ostream & operator<<(ostream &os, const tiny_element &K)
Definition: tiny_element.cc:27
Expr1::memory_type M
Definition: vec_expr_v2.h:416