24
24
#include "rheolef/geo.h"
25
25
#include "rheolef/geo_domain.h"
26
#include "rheolef/element.h"
26
#include "rheolef/numbering.h"
27
#include "rheolef/space_constitution.h"
28
29
namespace rheolef {
30
// =====================================================================
31
// space_act = a domain + an act (block, unblock)
32
// =====================================================================
47
space_act() : _dom(), _act() {}
48
space_act(const domain_indirect_basic<M>& dom, act_type act)
49
: _dom(dom), _act(act) {}
50
space_act(const space_act<M>& sp)
51
: _dom(sp._dom), _act(sp._act) {}
55
const domain_indirect_basic<M>& get_domain_indirect() const { return _dom; }
56
act_type get_act() const { return _act; }
60
domain_indirect_basic<M> _dom;
63
// =====================================================================
64
// space_constitution = a table of acts
65
// =====================================================================
67
template <class T, class M>
68
class space_constitution_rep : public std::vector<space_act<M> > {
70
typedef std::vector<space_act<M> > base;
71
typedef typename base::size_type size_type;
72
typedef typename base::const_iterator const_iterator;
76
space_constitution_rep()
77
: base(), _omega(), _element() {}
78
space_constitution_rep(const geo_basic<T,M>& omega, std::string approx)
79
: base(), _omega(compact(omega)), _element(approx) {}
80
space_constitution_rep (const space_constitution_rep<T,M>& scr)
81
: base(scr), _omega(scr._omega), _element(scr._element)
83
error_macro ("physical copy of space_constitution_rep: size="<< base::size());
88
const geo_basic<T,M>& get_geo() const { return _omega; }
89
const element<T>& get_element() const { return _element; }
91
size_type size() const { return base::size(); }
92
const_iterator begin() const { return base::begin(); }
93
const_iterator end() const { return base::end(); }
97
void set_geo (const geo_basic<T,M>& omega) { _omega = omega; }
98
void set_element (const element<T>& elt) { _element = elt; }
100
void block (const domain_indirect_basic<M>& dom) {
101
base::push_back (space_act<M> (dom, space_act<M>::block));
103
void unblock(const domain_indirect_basic<M>& dom) {
104
base::push_back (space_act<M> (dom, space_act<M>::unblock));
109
bool operator== (const space_constitution_rep<T,M>& V2) const { return _omega == V2._omega && _element == V2._element; }
113
geo_basic<T,M> _omega;
116
template <class T, class M>
117
class space_constitution : public smart_pointer<space_constitution_rep<T,M> > {
120
typedef space_constitution_rep<T,M> rep;
121
typedef smart_pointer<rep> base;
122
typedef typename rep::size_type size_type;
123
typedef typename rep::const_iterator const_iterator;
128
: smart_pointer<rep>(new_macro(rep)) {}
130
space_constitution(const geo_basic<T,M>& omega, std::string approx)
131
: smart_pointer<rep>(new_macro(rep (omega,approx))) {}
135
const geo_basic<T,M>& get_geo() const { return base::data().get_geo(); }
136
const element<T>& get_element() const { return base::data().get_element(); }
138
size_type size() const { return base::data().size(); }
139
const_iterator begin() const { return base::data().begin(); }
140
const_iterator end() const { return base::data().end(); }
144
bool operator== (const space_constitution<T,M>& V2) const { return base::data().operator==(V2.data()); }
148
void set_geo (const geo_basic<T,M>& omega) { base::data().set_geo (omega); }
149
void set_element (const element<T>& elt) { base::data().set_element (elt); }
151
void block (const domain_indirect_basic<M>& dom) {
152
base::data().block(dom);
154
void unblock(const domain_indirect_basic<M>& dom) { base::data().unblock(dom); }
31
// forward declarations:
32
template <class T, class M> class field_basic;
33
template <class T, class M> class space_mult_list;
34
template <class T, class M> class space_component;
35
template <class T, class M> class space_component_const;
156
37
// =====================================================================
157
38
// a dof = a degree-of-freedom
208
typedef typename space_pair_type::size_type size_type;
86
typedef typename space_pair_type::size_type size_type;
87
typedef typename space_constant::valued_type valued_type;
212
91
space_base_rep ();
213
space_base_rep (const geo_basic<T,M>& omega, std::string approx);
92
space_base_rep (const space_constitution<T,M>& constit);
93
space_base_rep (const geo_basic<T,M>& omega, std::string approx, std::string valued);
94
space_base_rep (const space_mult_list<T,M>&);
217
98
const distributor& ownership() const { return _idof2blk_iub.ownership(); }
218
size_type size() const { return ownership().size(); }
219
size_type dis_size() const { return ownership().dis_size(); }
99
size_type ndof() const { return ownership().size(); }
100
size_type dis_ndof() const { return ownership().dis_size(); }
220
101
const communicator& comm() const { return ownership().comm(); }
222
const geo_basic<T,M>& get_geo() const { return _constit.get_geo(); }
223
const element<T>& get_element() const { return _constit.get_element(); }
103
const space_constitution<T,M>& get_constitution() const { return _constit; }
104
const geo_basic<T,M>& get_geo() const { return _constit.get_geo(); }
105
const numbering<T,M>& get_numbering() const { return _constit.get_numbering(); }
106
valued_type valued_tag() const { return _constit.valued_tag(); }
107
const std::string& valued() const { return _constit.valued(); }
108
size_type size() const { return _constit.size(); }
109
space_component<T,M> operator[] (size_type i_comp);
110
space_component_const<T,M> operator[] (size_type i_comp) const;
225
std::string get_stamp() const; /// e.g. "P1(square)", for field_expr<Expr> checks
112
std::string stamp() const; /// e.g. "P1(square)", for field_expr<Expr> checks
227
114
void block (const domain_indirect_basic<M>& dom) { no_freeze_guard(); _constit.block (dom); }
228
void unblock(const domain_indirect_basic<M>& dom) {no_freeze_guard(); _constit.unblock(dom);}
115
void unblock(const domain_indirect_basic<M>& dom) { no_freeze_guard(); _constit.unblock(dom);}
230
117
bool is_blocked (size_type idof) const { freeze_guard(); return _idof2blk_iub [idof].is_blocked(); }
231
118
size_type iub (size_type idof) const { freeze_guard(); return _idof2blk_iub [idof].iub(); }
119
const point_basic<T>& xdof (size_type idof) const { return _xdof [idof]; }
120
const array<point_basic<T>,M >& get_xdofs() const { return _xdof; }
233
122
const distributor& iu_ownership() const { freeze_guard(); return _iu_ownership; }
234
123
const distributor& ib_ownership() const { freeze_guard(); return _ib_ownership; }
236
void get_dis_idof (const geo_element& K, std::vector<size_type>& dis_idof) const;
238
template <class Function>
239
T momentum (Function f, size_type idof) const;
125
void dis_idof (const geo_element& K, std::vector<size_type>& dis_idof) const;
127
template <class Function>
128
T momentum (Function f, size_type idof) const { return f (xdof(idof)); }
130
template <class Function>
131
point_basic<T> vector_momentum (Function f, size_type idof) const { return f (xdof(idof)); }
241
133
array<size_type, M> build_indirect_array (
242
const domain_indirect_basic<M>& indirect) const;
134
const space_base_rep<T,M>& Wh, const std::string& dom_name) const;
253
145
template <class T1, class M1> friend class field_basic;
255
148
void freeze_guard() const {
256
if (_is_freezed) return;
149
if (_have_freezed) return;
150
_have_freezed = true;
260
153
void no_freeze_guard() const {
261
check_macro (!_is_freezed, "freezed space cannot accept new (un)blocked domains");
154
check_macro (!_have_freezed, "freezed space cannot accept new (un)blocked domains");
263
156
void base_freeze_body() const;
264
157
virtual void freeze_body() const { return base_freeze_body(); }
266
space_constitution<T,M> _constit;
267
mutable bool _is_freezed;
268
mutable array<space_pair_type,M> _idof2blk_iub; // pair (is_blocked ; iu_or_ib); use ownership
269
mutable distributor _iu_ownership; // unknown values distribution
270
mutable distributor _ib_ownership; // blocked values distribution
158
// data: lazy initialization (on demand only), thus most are mutable
159
space_constitution<T,M> _constit;
160
array<point_basic<T>,M > _xdof; // nodal approx only
161
mutable bool _have_freezed;
162
mutable array<space_pair_type,M> _idof2blk_iub; // pair (is_blocked ; iu_or_ib); use ownership
163
mutable distributor _iu_ownership; // unknown values distribution
164
mutable distributor _ib_ownership; // blocked values distribution
272
166
// ---------------------------------------------------------------------
273
// momentum/interpolation implementation
274
// ---------------------------------------------------------------------
275
template <class T, class M>
276
template <class Function>
277
/* TODO: typename function_traits<Function>::result_type */
280
space_base_rep<T,M>::momentum (
282
size_type idof) const
285
// P1 Lagrange only ; TODO: extend
286
const basic_point<T>& x = get_geo().vertex (idof);
289
basic_point<T> x = get_element().x_dof (idof, get_geo());
292
// ---------------------------------------------------------------------
293
167
template <class T, class M> class space_rep {};
295
169
template <class T>
353
237
void freeze_body() const;
354
238
void append_external_dof (const geo_basic<T,distributed>& dom, std::set<size_type>& ext_dof_set) const;
356
array<size_type> _idof2ios_dis_idof; // permut to/from ios dof numbering (before geo part), for i/o
357
array<size_type> _ios_idof2dis_idof;
240
array<size_type,distributed> _idof2ios_dis_idof; // permut to/from ios dof numbering (before geo part), for i/o
241
array<size_type,distributed> _ios_idof2dis_idof;
358
242
// mutable data, affected by freeze_*()const:
359
mutable map_pair_type _ext_dis_idof2blk_dis_iub; // same for partition bdry dofs
243
mutable std::set<size_type> _ext_iu_set; // external dofs used by field::dis_dof
244
mutable std::set<size_type> _ext_ib_set;
361
246
#endif // _RHEOLEF_HAVE_MPI
362
247
// ====================================================================
392
typedef space_rep<T,sequential> rep;
393
typedef smart_pointer<rep> base;
394
typedef typename rep::size_type size_type;
288
typedef space_rep<T,sequential> rep;
289
typedef smart_pointer<rep> base;
290
typedef typename rep::size_type size_type;
291
typedef typename rep::valued_type valued_type;
398
space_basic (const geo_basic<T,sequential>& omega = (geo_basic<T,sequential>()), std::string approx = "");
295
space_basic (const geo_basic<T,sequential>& omega = (geo_basic<T,sequential>()),
296
std::string approx = "", std::string valued = "scalar");
297
space_basic (const space_mult_list<T,sequential>& expr);
298
space_basic (const space_constitution<T,sequential>& constit);
407
307
const distributor& ownership() const;
408
308
const communicator& comm() const;
409
size_type size() const;
410
size_type dis_size() const;
309
size_type ndof() const;
310
size_type dis_ndof() const;
412
312
const geo_basic<T,sequential>& get_geo() const;
413
const element<T>& get_element() const;
414
std::string get_stamp() const;
313
const numbering<T,sequential>& get_numbering() const;
314
size_type size() const;
315
valued_type valued_tag() const;
316
const std::string& valued() const;
317
space_component<T,sequential> operator[] (size_type i_comp);
318
space_component_const<T,sequential> operator[] (size_type i_comp) const;
319
const space_constitution<T,sequential>& get_constitution() const;
320
size_type degree() const;
321
std::string get_approx() const;
322
std::string stamp() const;
416
void get_dis_idof (const geo_element& K, std::vector<size_type>& dis_idof) const;
324
void dis_idof (const geo_element& K, std::vector<size_type>& dis_idof) const;
418
326
const distributor& iu_ownership() const;
419
327
const distributor& ib_ownership() const;
427
335
size_type idof2ios_dis_idof (size_type idof) const;
428
336
size_type ios_idof2dis_idof (size_type ios_idof) const;
338
const point_basic<T>& xdof (size_type idof) const;
339
const array<point_basic<T>,sequential>& get_xdofs() const;
430
341
template <class Function>
431
342
T momentum (Function f, size_type idof) const;
433
array<size_type, sequential>
434
build_indirect_array (const geo_basic<T,sequential>& dom) const;
344
template <class Function>
345
point_basic<T> vector_momentum (Function f, size_type idof) const;
347
array<size_type, sequential> build_indirect_array (
348
const space_basic<T,sequential>& Wh, const std::string& dom_name) const;
350
const std::set<size_type>& ext_iu_set() const { return base::data().ext_iu_set(); }
351
const std::set<size_type>& ext_ib_set() const { return base::data().ext_ib_set(); }
444
361
template<class T>
446
space_basic<T,sequential>::space_basic (const geo_basic<T,sequential>& omega, std::string approx)
447
: base (new_macro(rep(omega, approx)))
363
space_basic<T,sequential>::space_basic (
364
const space_constitution<T,sequential>& constit)
365
: base (new_macro(rep(constit)))
370
space_basic<T,sequential>::space_basic (
371
const geo_basic<T,sequential>& omega,
374
: base (new_macro(rep(omega, approx, valued)))
379
space_basic<T,sequential>::space_basic (const space_mult_list<T,sequential>& expr)
380
: base (new_macro(rep(expr)))
450
383
template<class T>
492
425
template<class T>
495
space_basic<T,sequential>::get_element() const
497
return base::data().get_element();
502
space_basic<T,sequential>::get_stamp() const
504
return base::data().get_stamp();
427
const numbering<T,sequential>&
428
space_basic<T,sequential>::get_numbering() const
430
return base::data().get_numbering();
434
const space_constitution<T,sequential>&
435
space_basic<T,sequential>::get_constitution() const
437
return base::data().get_constitution();
441
typename space_basic<T,sequential>::size_type
442
space_basic<T,sequential>::size() const
444
return base::data().size();
449
space_basic<T,sequential>::valued() const
451
return base::data().valued();
455
typename space_basic<T,sequential>::valued_type
456
space_basic<T,sequential>::valued_tag() const
458
return base::data().valued_tag();
462
space_component<T,sequential>
463
space_basic<T,sequential>::operator[] (size_type i_comp)
465
return base::data().operator[] (i_comp);
469
space_component_const<T,sequential>
470
space_basic<T,sequential>::operator[] (size_type i_comp) const
472
return base::data().operator[] (i_comp);
476
typename space_basic<T,sequential>::size_type
477
space_basic<T,sequential>::degree() const
479
return get_numbering().degree();
484
space_basic<T,sequential>::get_approx() const
486
return get_numbering().name();
491
space_basic<T,sequential>::stamp() const
493
return base::data().stamp();
506
495
template<class T>
509
space_basic<T,sequential>::get_dis_idof (const geo_element& K, std::vector<size_type>& dis_idof) const
498
space_basic<T,sequential>::dis_idof (const geo_element& K, std::vector<size_type>& dis_idof) const
511
return base::data().get_dis_idof (K, dis_idof);
500
return base::data().dis_idof (K, dis_idof);
513
502
template<class T>
614
typedef space_rep<T,distributed> rep;
615
typedef smart_pointer<rep> base;
616
typedef typename rep::size_type size_type;
625
typedef space_rep<T,distributed> rep;
626
typedef smart_pointer<rep> base;
627
typedef typename rep::size_type size_type;
628
typedef typename rep::valued_type valued_type;
620
space_basic (const geo_basic<T,distributed>& omega = (geo_basic<T,distributed>()), std::string approx = "");
632
space_basic (const geo_basic<T,distributed>& omega = (geo_basic<T,distributed>()),
633
std::string approx = "", std::string valued = "scalar");
634
space_basic (const space_mult_list<T,distributed>&);
635
space_basic (const space_constitution<T,distributed>& constit);
629
644
const distributor& ownership() const;
630
645
const communicator& comm() const;
631
size_type size() const;
632
size_type dis_size() const;
646
size_type ndof() const;
647
size_type dis_ndof() const;
634
649
const geo_basic<T,distributed>& get_geo() const;
635
const element<T>& get_element() const;
636
std::string get_stamp() const;
650
const numbering<T,distributed>& get_numbering() const;
651
size_type size() const;
652
valued_type valued_tag() const;
653
const std::string& valued() const;
654
space_component<T,distributed> operator[] (size_type i_comp);
655
space_component_const<T,distributed> operator[] (size_type i_comp) const;
656
const space_constitution<T,distributed>& get_constitution() const;
657
size_type degree() const;
658
std::string get_approx() const;
659
std::string stamp() const;
638
void get_dis_idof (const geo_element& K, std::vector<size_type>& dis_idof) const;
661
void dis_idof (const geo_element& K, std::vector<size_type>& dis_idof) const;
640
663
const distributor& iu_ownership() const;
641
664
const distributor& ib_ownership() const;
650
673
size_type idof2ios_dis_idof (size_type idof) const;
651
674
size_type ios_idof2dis_idof (size_type ios_idof) const;
676
const point_basic<T>& xdof (size_type idof) const;
677
const array<point_basic<T>,distributed>& get_xdofs() const;
653
679
template <class Function>
654
680
T momentum (Function f, size_type idof) const;
656
array<size_type, distributed>
657
build_indirect_array (const geo_basic<T,distributed>& dom) const;
682
template <class Function>
683
point_basic<T> vector_momentum (Function f, size_type idof) const;
685
array<size_type, distributed> build_indirect_array (
686
const space_basic<T,distributed>& Wh, const std::string& dom_name) const;
688
const std::set<size_type>& ext_iu_set() const { return base::data().ext_iu_set(); }
689
const std::set<size_type>& ext_ib_set() const { return base::data().ext_ib_set(); }
668
700
template<class T>
670
space_basic<T,distributed>::space_basic (const geo_basic<T,distributed>& omega, std::string approx)
671
: base (new_macro(rep(omega, approx)))
702
space_basic<T,distributed>::space_basic (
703
const space_constitution<T,distributed>& constit)
704
: base (new_macro(rep(constit)))
709
space_basic<T,distributed>::space_basic (
710
const geo_basic<T,distributed>& omega,
713
: base (new_macro(rep(omega, approx, valued)))
718
space_basic<T,distributed>::space_basic (const space_mult_list<T,distributed>& expr)
719
: base (new_macro(rep(expr)))
674
722
template<class T>
716
764
template<class T>
719
space_basic<T,distributed>::get_element() const
721
return base::data().get_element();
726
space_basic<T,distributed>::get_stamp() const
728
return base::data().get_stamp();
766
const numbering<T,distributed>&
767
space_basic<T,distributed>::get_numbering() const
769
return base::data().get_numbering();
773
const space_constitution<T,distributed>&
774
space_basic<T,distributed>::get_constitution() const
776
return base::data().get_constitution();
780
typename space_basic<T,distributed>::size_type
781
space_basic<T,distributed>::size() const
783
return base::data().size();
788
space_basic<T,distributed>::valued() const
790
return base::data().valued();
794
typename space_basic<T,distributed>::valued_type
795
space_basic<T,distributed>::valued_tag() const
797
return base::data().valued_tag();
801
space_component<T,distributed>
802
space_basic<T,distributed>::operator[] (size_type i_comp)
804
return base::data().operator[] (i_comp);
808
space_component_const<T,distributed>
809
space_basic<T,distributed>::operator[] (size_type i_comp) const
811
return base::data().operator[] (i_comp);
815
typename space_basic<T,distributed>::size_type
816
space_basic<T,distributed>::degree() const
818
return get_numbering().degree();
823
space_basic<T,distributed>::get_approx() const
825
return get_numbering().name();
830
space_basic<T,distributed>::stamp() const
832
return base::data().stamp();
730
834
template<class T>
733
space_basic<T,distributed>::get_dis_idof (const geo_element& K, std::vector<size_type>& dis_idof) const
837
space_basic<T,distributed>::dis_idof (const geo_element& K, std::vector<size_type>& dis_idof) const
735
return base::data().get_dis_idof (K, dis_idof);
839
return base::data().dis_idof (K, dis_idof);
737
841
template<class T>
833
959
template<class T> \
835
961
array<typename space_basic<T,M>::size_type, M> \
836
space_basic<T,M>::build_indirect_array (const geo_basic<T,M>& dom) const \
962
space_basic<T,M>::build_indirect_array ( \
963
const space_basic<T,M>& Wh, \
964
const std::string& dom_name) const \
838
if (dom.data().variant() == geo_abstract_base_rep<T>::geo_domain_indirect) { \
839
const geo_domain_indirect_rep<T,M>& dom_rep \
840
= dynamic_cast<const geo_domain_indirect_rep<T,M>&>(dom.data()); \
841
return base::data().build_indirect_array (dom_rep.get_indirect()); \
843
error_macro ("build_indirect_array: unsupported non domain_indirect geo variant"); \
844
return array<size_type, M>(); /* not reached */ \
966
return base::data().build_indirect_array (Wh.data(), dom_name); \
846
968
_RHEOLEF_space_build_indirect_array(sequential)