~ubuntu-branches/ubuntu/trusty/rheolef/trusty

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
#ifndef _RHEOLEF_SPACE_H
#define _RHEOLEF_SPACE_H
///
/// This file is part of Rheolef.
///
/// Copyright (C) 2000-2009 Pierre Saramito <Pierre.Saramito@imag.fr>
///
/// Rheolef is free software; you can redistribute it and/or modify
/// it under the terms of the GNU General Public License as published by
/// the Free Software Foundation; either version 2 of the License, or
/// (at your option) any later version.
///
/// Rheolef is distributed in the hope that it will be useful,
/// but WITHOUT ANY WARRANTY; without even the implied warranty of
/// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
/// GNU General Public License for more details.
///
/// You should have received a copy of the GNU General Public License
/// along with Rheolef; if not, write to the Free Software
/// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
///
/// =========================================================================

#include "rheolef/geo.h"
#include "rheolef/geo_domain.h"
#include "rheolef/numbering.h"
#include "rheolef/space_constitution.h"

namespace rheolef {

// forward declarations:
template <class T, class M> class field_basic;
template <class T, class M> class space_mult_list;
template <class T, class M> class space_component;
template <class T, class M> class space_component_const;

// =====================================================================
// a dof = a degree-of-freedom 
//       = space_pair
//       = pair (bool is_blocked ; size_t iub)
// =====================================================================
// TODO: compact the bool as an extra bit in size_type ?
struct space_pair_type {
    typedef array<size_t>::size_type size_type;
    space_pair_type () : _blk(false), _iub (std::numeric_limits<size_type>::max()) {}
    space_pair_type (bool blk, size_type iub) : _blk(blk), _iub(iub) {}
    bool is_blocked() const { return _blk; }
    size_type iub()   const { return _iub; }
    void set_iub (size_type iub) { _iub = iub; }
    void set_blocked (bool blk)  { _blk = blk; }
    friend std::ostream&  operator<< (std::ostream& os, const space_pair_type& x) {
	return os << "{" << x.is_blocked() << "," << x.iub() << "}"; }
    template<class Archive>
    void serialize (Archive& ar, const unsigned int version) { ar & _blk; ar & _iub; }
protected:
    bool      _blk;
    size_type _iub;
};

} // namespace rheolef

#ifdef _RHEOLEF_HAVE_MPI
// =====================================================================
// Some serializable types, like geo_element, have a fixed amount of data stored at fixed field positions.
// When this is the case, boost::mpi can optimize their serialization and transmission to avoid extraneous 
// copy operations.
// To enable this optimization, we specialize the type trait is_mpi_datatype, e.g.:
namespace boost {
 namespace mpi {
  template <> struct is_mpi_datatype<rheolef::space_pair_type> : mpl::true_ { };
 } // namespace mpi
} // namespace boost
#endif // _RHEOLEF_HAVE_MPI

namespace rheolef {

// =====================================================================
// 1) representation: space_base_rep and space_rep
// =====================================================================
template <class T, class M>
class space_base_rep {
public:

// typedefs:

    typedef typename space_pair_type::size_type  size_type;
    typedef typename space_constant::valued_type valued_type;

// allocators:

    space_base_rep ();
    space_base_rep (const space_constitution<T,M>& constit);
    space_base_rep (const geo_basic<T,M>& omega, std::string approx, std::string valued);
    space_base_rep (const space_mult_list<T,M>&);

// accessors:

    const distributor&  ownership() const { return _idof2blk_iub.ownership(); }
    size_type                ndof() const { return ownership().size(); }
    size_type            dis_ndof() const { return ownership().dis_size(); }
    const communicator&      comm() const { return ownership().comm(); }

    const space_constitution<T,M>& get_constitution() const { return _constit; }
    const geo_basic<T,M>& get_geo()       const { return _constit.get_geo(); }
    const numbering<T,M>& get_numbering() const { return _constit.get_numbering(); }
    valued_type           valued_tag()   const { return _constit.valued_tag(); }
    const std::string&    valued()       const { return _constit.valued(); }
    size_type             size()   const { return _constit.size(); }
    space_component<T,M>       operator[] (size_type i_comp);
    space_component_const<T,M> operator[] (size_type i_comp) const;

    std::string stamp() const; /// e.g. "P1(square)", for field_expr<Expr> checks

    void block  (const domain_indirect_basic<M>& dom) { no_freeze_guard(); _constit.block  (dom); }
    void unblock(const domain_indirect_basic<M>& dom) { no_freeze_guard(); _constit.unblock(dom);}

    bool                 is_blocked (size_type     idof) const { freeze_guard(); return _idof2blk_iub [idof].is_blocked(); }
    size_type                   iub (size_type     idof) const { freeze_guard(); return _idof2blk_iub [idof].iub(); }
    const point_basic<T>& xdof (size_type idof) const { return _xdof [idof]; }
    const array<point_basic<T>,M >& get_xdofs() const { return _xdof; }

    const distributor& iu_ownership() const { freeze_guard(); return _iu_ownership; }
    const distributor& ib_ownership() const { freeze_guard(); return _ib_ownership; }

    void dis_idof (const geo_element& K, std::vector<size_type>& dis_idof) const;

    template <class Function>
    T momentum (Function f, size_type idof) const { return f (xdof(idof)); }

    template <class Function>
    point_basic<T> vector_momentum (Function f, size_type idof) const { return f (xdof(idof)); }

    array<size_type, M> build_indirect_array (
    	const space_base_rep<T,M>& Wh, const std::string& dom_name) const;

// comparator:

    bool operator== (const space_base_rep<T,M>& V2) const { 
	return _constit.operator==(V2._constit); } // TODO: compare also blocked/unknown sizes:

    friend bool are_compatible (const space_base_rep<T,M>& V1, const space_base_rep<T,M>& V2) {
    	return V1._constit.operator==(V2._constit); }

protected:
    template <class T1, class M1> friend class field_basic;
// internal:
    void init_xdof();
    void freeze_guard() const {
    	if (_have_freezed) return;
    	_have_freezed = true;
    	freeze_body();
    }
    void no_freeze_guard() const {
    	check_macro (!_have_freezed, "freezed space cannot accept new (un)blocked domains");
    }
    void base_freeze_body() const;
    virtual void freeze_body() const { return base_freeze_body(); }
// data: lazy initialization (on demand only), thus most are mutable
    space_constitution<T,M>   _constit;
    array<point_basic<T>,M >               _xdof;          // nodal approx only
    mutable bool                           _have_freezed;
    mutable array<space_pair_type,M>       _idof2blk_iub;  // pair (is_blocked ; iu_or_ib); use ownership
    mutable distributor                    _iu_ownership;  // unknown values distribution
    mutable distributor                    _ib_ownership;  // blocked values distribution
};
// ---------------------------------------------------------------------
template <class T, class M> class space_rep {};

template <class T>
class space_rep<T,sequential> : public space_base_rep<T,sequential> {
public:

// typedefs:

    typedef space_base_rep<T,sequential> base;
    typedef typename base::size_type size_type;

// allocators:

    space_rep (const space_constitution<T,sequential>& constit);
    space_rep (const geo_basic<T,sequential>& omega, std::string approx, std::string valued);
    space_rep (const space_mult_list<T,sequential>&);

// compatibility with the distributed interface:

    bool             dis_is_blocked (size_type dis_idof) const { return is_blocked(dis_idof); }
    size_type               dis_iub (size_type dis_idof) const { return iub(dis_idof); }

    const distributor& ios_ownership() const { return base::ownership(); }
    size_type     idof2ios_dis_idof (size_type     idof) const { return idof; }
    size_type     ios_idof2dis_idof (size_type ios_idof) const { return ios_idof; }

    // for compatibility with the distributed case:
    const std::set<size_type>& ext_iu_set() const;
    const std::set<size_type>& ext_ib_set() const;
};
// ---------------------------------------------------------------------
#ifdef _RHEOLEF_HAVE_MPI
template <class T>
class space_rep<T,distributed> : public space_base_rep<T,distributed> {
public:

// typedefs:

    typedef space_base_rep<T,distributed> base;
    typedef typename base::size_type size_type;

// allocators:

    space_rep (const space_constitution<T,distributed>& constit);
    space_rep (const geo_basic<T,distributed>& omega, std::string approx, std::string valued);
    space_rep (const space_mult_list<T,distributed>&);

// accessors:

    const communicator&      comm() const { return base::comm(); }

    bool             dis_is_blocked (size_type dis_idof) const;
    size_type               dis_iub (size_type dis_idof) const;

    const distributor& ios_ownership() const { return _ios_idof2dis_idof.ownership(); }
    size_type     idof2ios_dis_idof (size_type     idof) const { base::freeze_guard(); return _idof2ios_dis_idof [idof]; }
    size_type     ios_idof2dis_idof (size_type ios_idof) const { base::freeze_guard(); return _ios_idof2dis_idof [ios_idof]; }
#ifdef TO_CLEAN
    void get_ios_dis_idof (const geo_element& K, std::vector<size_type>& ios_dis_idof) const;
#endif // TO_CLEAN
    const std::set<size_type>& ext_iu_set() const { return _ext_iu_set; }
    const std::set<size_type>& ext_ib_set() const { return _ext_ib_set; }

protected:
    template <class T1, class M1> friend class field_basic;
    typedef std::map <size_type, size_type, std::less<size_type>,
            heap_allocator<std::pair<size_type,size_type> > >           map_type;
    typedef std::map <size_type, space_pair_type, std::less<size_type>,
            heap_allocator<std::pair<size_type,space_pair_type> > >     map_pair_type;
// internal procedures:
    void freeze_body() const;
    void append_external_dof (const geo_basic<T,distributed>& dom, std::set<size_type>& ext_dof_set) const;
// data:
    array<size_type,distributed>   _idof2ios_dis_idof;   // permut to/from ios dof numbering (before geo part), for i/o
    array<size_type,distributed>   _ios_idof2dis_idof;
// mutable data, affected by freeze_*()const:
    mutable std::set<size_type>    _ext_iu_set;    // external dofs used by field::dis_dof
    mutable std::set<size_type>    _ext_ib_set;
};
#endif // _RHEOLEF_HAVE_MPI
// ====================================================================
// 2) wrapper class: seq & mpi specializations
// ====================================================================
/*Class:space
NAME: @code{space} -- piecewise polynomial finite element space
@clindex space
DESCRIPTION:
@noindent
The @code{space} class contains some numbering 
for unknowns and blocked degrees of freedoms
related to a given mesh and polynomial approximation.
SYNOPSIS:
@example
    space Q (omega, "P1");
    space V (omega, "P2", "vector");
    space T (omega, "P1d", "tensor");
@end example
PRODUCT:
@example
    space X = T*V*Q;
    space Q2 = pow(Q,2);
@end example
SEE ALSO: "geo"(3)
AUTHORS: Pierre.Saramito@imag.fr
DATE:   14 december 2010
End:
*/
/// @brief the finite element space
template <class T, class M = rheo_default_memory_model>
class space_basic {
public:
};
typedef space_basic<Float> space;
// ---------------------------------------------------------------------
//<verbatim:
template <class T>
class space_basic<T,sequential> : public smart_pointer<space_rep<T,sequential> > {
public:

// typedefs:

    typedef space_rep<T,sequential>   rep;
    typedef smart_pointer<rep>        base;
    typedef typename rep::size_type   size_type;
    typedef typename rep::valued_type valued_type;

// allocators:

    space_basic (const geo_basic<T,sequential>& omega = (geo_basic<T,sequential>()),
		  std::string approx = "", std::string valued = "scalar");
    space_basic (const space_mult_list<T,sequential>& expr);
    space_basic (const space_constitution<T,sequential>& constit);

// accessors:

    void block  (std::string dom_name);
    void unblock(std::string dom_name);
    void block  (const domain_indirect_basic<sequential>& dom);
    void unblock(const domain_indirect_basic<sequential>& dom);

    const distributor&  ownership() const;
    const communicator& comm() const;
    size_type           ndof() const;
    size_type           dis_ndof() const;

    const geo_basic<T,sequential>& get_geo() const;
    const numbering<T,sequential>& get_numbering() const;
    size_type size() const;
    valued_type           valued_tag()   const;
    const std::string&    valued()       const;
    space_component<T,sequential>       operator[] (size_type i_comp);
    space_component_const<T,sequential> operator[] (size_type i_comp) const;
    const space_constitution<T,sequential>& get_constitution() const;
    size_type degree() const;
    std::string get_approx() const;
    std::string stamp() const;

    void dis_idof (const geo_element& K, std::vector<size_type>& dis_idof) const;

    const distributor& iu_ownership() const;
    const distributor& ib_ownership() const;

    bool      is_blocked (size_type     idof) const;
    size_type        iub (size_type     idof) const;
    bool  dis_is_blocked (size_type dis_idof) const;
    size_type    dis_iub (size_type dis_idof) const;

    const distributor& ios_ownership() const;
    size_type idof2ios_dis_idof (size_type idof) const;
    size_type ios_idof2dis_idof (size_type ios_idof) const;

    const point_basic<T>& xdof (size_type idof) const;
    const array<point_basic<T>,sequential>& get_xdofs() const;

    template <class Function>
    T momentum (Function f, size_type idof) const;

    template <class Function>
    point_basic<T> vector_momentum (Function f, size_type idof) const;

    array<size_type, sequential> build_indirect_array (
    	const space_basic<T,sequential>& Wh, const std::string& dom_name) const;

    const std::set<size_type>& ext_iu_set() const { return base::data().ext_iu_set(); }
    const std::set<size_type>& ext_ib_set() const { return base::data().ext_ib_set(); }

// comparator:

    bool operator== (const space_basic<T,sequential>& V2) const { return base::data().operator==(V2.data()); }
    bool operator!= (const space_basic<T,sequential>& V2) const { return ! operator== (V2); }
    friend bool are_compatible (const space_basic<T,sequential>& V1, const space_basic<T,sequential>& V2) {
	return are_compatible (V1.data(), V2.data()); }
};
//>verbatim:
template<class T>
inline
space_basic<T,sequential>::space_basic (
    const space_constitution<T,sequential>& constit)
 : base (new_macro(rep(constit)))
{
}
template<class T>
inline
space_basic<T,sequential>::space_basic (
    const geo_basic<T,sequential>& omega,
    std::string approx,
    std::string valued)
 : base (new_macro(rep(omega, approx, valued)))
{
}
template<class T>
inline
space_basic<T,sequential>::space_basic (const space_mult_list<T,sequential>& expr)
 : base (new_macro(rep(expr)))
{
}
template<class T>
inline
const distributor&
space_basic<T,sequential>::ownership() const
{
    return base::data().ownership();
}
template<class T>
inline
const distributor&
space_basic<T,sequential>::ios_ownership() const
{
    return base::data().ios_ownership();
}
template<class T>
inline
const communicator&
space_basic<T,sequential>::comm() const
{
    return base::data().comm();
}
template<class T>
inline
typename space_basic<T,sequential>::size_type
space_basic<T,sequential>::ndof() const
{
    return base::data().ndof();
}
template<class T>
inline
typename space_basic<T,sequential>::size_type
space_basic<T,sequential>::dis_ndof() const
{
    return base::data().dis_ndof();
}
template<class T>
inline
const geo_basic<T,sequential>&
space_basic<T,sequential>::get_geo() const
{
    return base::data().get_geo();
}
template<class T>
inline
const numbering<T,sequential>&
space_basic<T,sequential>::get_numbering() const
{
    return base::data().get_numbering();
}
template<class T>
inline
const space_constitution<T,sequential>&
space_basic<T,sequential>::get_constitution() const
{
    return base::data().get_constitution();
}
template<class T>
inline
typename space_basic<T,sequential>::size_type
space_basic<T,sequential>::size() const
{
    return base::data().size();
}
template<class T>
inline
const std::string&
space_basic<T,sequential>::valued() const
{
    return base::data().valued();
}
template<class T>
inline
typename space_basic<T,sequential>::valued_type
space_basic<T,sequential>::valued_tag() const
{
    return base::data().valued_tag();
}
template<class T>
inline
space_component<T,sequential>
space_basic<T,sequential>::operator[] (size_type i_comp)
{
    return base::data().operator[] (i_comp);
}
template<class T>
inline
space_component_const<T,sequential>
space_basic<T,sequential>::operator[] (size_type i_comp) const
{
    return base::data().operator[] (i_comp);
}
template<class T>
inline
typename space_basic<T,sequential>::size_type
space_basic<T,sequential>::degree() const
{
    return get_numbering().degree();
}
template<class T>
inline
std::string
space_basic<T,sequential>::get_approx() const
{
    return get_numbering().name();
}
template<class T>
inline
std::string
space_basic<T,sequential>::stamp() const
{
    return base::data().stamp();
}
template<class T>
inline
void
space_basic<T,sequential>::dis_idof (const geo_element& K, std::vector<size_type>& dis_idof) const
{
    return base::data().dis_idof (K, dis_idof);
}
template<class T>
inline
typename space_basic<T,sequential>::size_type
space_basic<T,sequential>::idof2ios_dis_idof (size_type idof) const
{
    return base::data().idof2ios_dis_idof (idof);
}
template<class T>
inline
typename space_basic<T,sequential>::size_type
space_basic<T,sequential>::ios_idof2dis_idof (size_type ios_idof) const
{
    return base::data().ios_idof2dis_idof (ios_idof);
}
template<class T>
inline
const distributor&
space_basic<T,sequential>::iu_ownership() const
{
    return base::data().iu_ownership();
}
template<class T>
inline
const distributor&
space_basic<T,sequential>::ib_ownership() const
{
    return base::data().ib_ownership();
}
template<class T>
inline
bool
space_basic<T,sequential>::is_blocked (size_type idof) const
{
    return base::data().is_blocked (idof);
}
template<class T>
inline
typename space_basic<T,sequential>::size_type
space_basic<T,sequential>::iub (size_type idof) const
{
    return base::data().iub (idof);
}
template<class T>
inline
bool
space_basic<T,sequential>::dis_is_blocked (size_type dis_idof) const
{
    return base::data().dis_is_blocked (dis_idof);
}
template<class T>
inline
typename space_basic<T,sequential>::size_type
space_basic<T,sequential>::dis_iub (size_type dis_idof) const
{
    return base::data().dis_iub (dis_idof);
}
template<class T>
inline
void
space_basic<T,sequential>::block (std::string dom_name)
{
    return base::data().block (get_geo().get_domain_indirect(dom_name));
}
template<class T>
inline
void
space_basic<T,sequential>::unblock (std::string dom_name)
{
    return base::data().unblock (get_geo().get_domain_indirect(dom_name));
}
template<class T>
inline
void
space_basic<T,sequential>::block (const domain_indirect_basic<sequential>& dom)
{
    return base::data().block (dom);
}
template<class T>
inline
void
space_basic<T,sequential>::unblock (const domain_indirect_basic<sequential>& dom)
{
    return base::data().unblock (dom);
}
template<class T>
inline
const point_basic<T>&
space_basic<T,sequential>::xdof (size_type idof) const
{
    return base::data().xdof (idof);
}
template<class T>
inline
const array<point_basic<T>,sequential>&
space_basic<T,sequential>::get_xdofs() const
{
    return base::data().get_xdofs();
}
template<class T>
template <class Function>
inline
T
space_basic<T,sequential>::momentum (Function f, size_type idof) const
{
    return base::data().momentum (f, idof);
}
template<class T>
template <class Function>
inline
point_basic<T>
space_basic<T,sequential>::vector_momentum (Function f, size_type idof) const
{
    return base::data().vector_momentum (f, idof);
}
// ---------------------------------------------------------------------
#ifdef _RHEOLEF_HAVE_MPI
//<verbatim:
template <class T>
class space_basic<T,distributed> : public smart_pointer<space_rep<T,distributed> > {
public:

// typedefs:

    typedef space_rep<T,distributed>  rep;
    typedef smart_pointer<rep>        base;
    typedef typename rep::size_type   size_type;
    typedef typename rep::valued_type valued_type;

// allocators:

    space_basic (const geo_basic<T,distributed>& omega = (geo_basic<T,distributed>()),
		  std::string approx = "", std::string valued = "scalar");
    space_basic (const space_mult_list<T,distributed>&);
    space_basic (const space_constitution<T,distributed>& constit);

// accessors:

    void block  (std::string dom_name);
    void unblock(std::string dom_name);
    void block  (const domain_indirect_basic<distributed>& dom);
    void unblock(const domain_indirect_basic<distributed>& dom);

    const distributor&  ownership() const;
    const communicator& comm() const;
    size_type           ndof() const;
    size_type           dis_ndof() const;

    const geo_basic<T,distributed>& get_geo() const;
    const numbering<T,distributed>& get_numbering() const;
    size_type size() const;
    valued_type           valued_tag()   const;
    const std::string&    valued()       const;
    space_component<T,distributed>       operator[] (size_type i_comp);
    space_component_const<T,distributed> operator[] (size_type i_comp) const;
    const space_constitution<T,distributed>& get_constitution() const;
    size_type degree() const;
    std::string get_approx() const;
    std::string stamp() const;

    void dis_idof (const geo_element& K, std::vector<size_type>& dis_idof) const;

    const distributor& iu_ownership() const;
    const distributor& ib_ownership() const;

    bool      is_blocked (size_type     idof) const;
    size_type        iub (size_type     idof) const;

    bool  dis_is_blocked (size_type dis_idof) const;
    size_type    dis_iub (size_type dis_idof) const;

    const distributor& ios_ownership() const;
    size_type idof2ios_dis_idof (size_type idof) const;
    size_type ios_idof2dis_idof (size_type ios_idof) const;

    const point_basic<T>& xdof (size_type idof) const;
    const array<point_basic<T>,distributed>& get_xdofs() const;

    template <class Function>
    T momentum (Function f, size_type idof) const;

    template <class Function>
    point_basic<T> vector_momentum (Function f, size_type idof) const;

    array<size_type, distributed> build_indirect_array (
    	const space_basic<T,distributed>& Wh, const std::string& dom_name) const;

    const std::set<size_type>& ext_iu_set() const { return base::data().ext_iu_set(); }
    const std::set<size_type>& ext_ib_set() const { return base::data().ext_ib_set(); }

// comparator:

    bool operator== (const space_basic<T,distributed>& V2) const { return base::data().operator==(V2.data()); }
    bool operator!= (const space_basic<T,distributed>& V2) const { return ! operator== (V2); }
    friend bool are_compatible (const space_basic<T,distributed>& V1, const space_basic<T,distributed>& V2) {
	return are_compatible (V1.data(), V2.data()); }
};
//>verbatim:

template<class T>
inline
space_basic<T,distributed>::space_basic (
    const space_constitution<T,distributed>& constit)
 : base (new_macro(rep(constit)))
{
}
template<class T>
inline
space_basic<T,distributed>::space_basic (
    const geo_basic<T,distributed>& omega,
    std::string approx,
    std::string valued)
 : base (new_macro(rep(omega, approx, valued)))
{
}
template<class T>
inline
space_basic<T,distributed>::space_basic (const space_mult_list<T,distributed>& expr)
 : base (new_macro(rep(expr)))
{
}
template<class T>
inline
const distributor&
space_basic<T,distributed>::ownership() const
{
    return base::data().ownership();
}
template<class T>
inline
const distributor&
space_basic<T,distributed>::ios_ownership() const
{
    return base::data().ios_ownership();
}
template<class T>
inline
const communicator&
space_basic<T,distributed>::comm() const
{
    return base::data().comm();
}
template<class T>
inline
typename space_basic<T,distributed>::size_type
space_basic<T,distributed>::ndof() const
{
    return base::data().ndof();
}
template<class T>
inline
typename space_basic<T,distributed>::size_type
space_basic<T,distributed>::dis_ndof() const
{
    return base::data().dis_ndof();
}
template<class T>
inline
const geo_basic<T,distributed>&
space_basic<T,distributed>::get_geo() const
{
    return base::data().get_geo();
}
template<class T>
inline
const numbering<T,distributed>&
space_basic<T,distributed>::get_numbering() const
{
    return base::data().get_numbering();
}
template<class T>
inline
const space_constitution<T,distributed>&
space_basic<T,distributed>::get_constitution() const
{
    return base::data().get_constitution();
}
template<class T>
inline
typename space_basic<T,distributed>::size_type
space_basic<T,distributed>::size() const
{
    return base::data().size();
}
template<class T>
inline
const std::string&
space_basic<T,distributed>::valued() const
{
    return base::data().valued();
}
template<class T>
inline
typename space_basic<T,distributed>::valued_type
space_basic<T,distributed>::valued_tag() const
{
    return base::data().valued_tag();
}
template<class T>
inline
space_component<T,distributed>
space_basic<T,distributed>::operator[] (size_type i_comp)
{
    return base::data().operator[] (i_comp);
}
template<class T>
inline
space_component_const<T,distributed>
space_basic<T,distributed>::operator[] (size_type i_comp) const
{
    return base::data().operator[] (i_comp);
}
template<class T>
inline
typename space_basic<T,distributed>::size_type
space_basic<T,distributed>::degree() const
{
    return get_numbering().degree();
}
template<class T>
inline
std::string
space_basic<T,distributed>::get_approx() const
{
    return get_numbering().name();
}
template<class T>
inline
std::string
space_basic<T,distributed>::stamp() const
{
    return base::data().stamp();
}
template<class T>
inline
void
space_basic<T,distributed>::dis_idof (const geo_element& K, std::vector<size_type>& dis_idof) const
{
    return base::data().dis_idof (K, dis_idof);
}
template<class T>
inline
typename space_basic<T,distributed>::size_type
space_basic<T,distributed>::idof2ios_dis_idof (size_type idof) const
{
    return base::data().idof2ios_dis_idof (idof);
}
template<class T>
inline
typename space_basic<T,distributed>::size_type
space_basic<T,distributed>::ios_idof2dis_idof (size_type ios_idof) const
{
    return base::data().ios_idof2dis_idof (ios_idof);
}
template<class T>
inline
const distributor&
space_basic<T,distributed>::iu_ownership() const
{
    return base::data().iu_ownership();
}
template<class T>
inline
const distributor&
space_basic<T,distributed>::ib_ownership() const
{
    return base::data().ib_ownership();
}
template<class T>
inline
bool
space_basic<T,distributed>::is_blocked (size_type idof) const
{
    return base::data().is_blocked (idof);
}
template<class T>
inline
typename space_basic<T,distributed>::size_type
space_basic<T,distributed>::iub (size_type idof) const
{
    return base::data().iub (idof);
}
template<class T>
inline
bool
space_basic<T,distributed>::dis_is_blocked (size_type dis_idof) const
{
    return base::data().dis_is_blocked (dis_idof);
}
template<class T>
inline
typename space_basic<T,distributed>::size_type
space_basic<T,distributed>::dis_iub (size_type dis_idof) const
{
    return base::data().dis_iub (dis_idof);
}
template<class T>
inline
void
space_basic<T,distributed>::block (std::string dom_name)
{
    return base::data().block (get_geo().get_domain_indirect(dom_name));
}
template<class T>
inline
void
space_basic<T,distributed>::unblock (std::string dom_name)
{
    return base::data().unblock (get_geo().get_domain_indirect(dom_name));
}
template<class T>
inline
void
space_basic<T,distributed>::block (const domain_indirect_basic<distributed>& dom)
{
    base::data().block (dom);
}
template<class T>
inline
void
space_basic<T,distributed>::unblock (const domain_indirect_basic<distributed>& dom)
{
    base::data().unblock (dom);
}
template<class T>
inline
const point_basic<T>&
space_basic<T,distributed>::xdof (size_type idof) const
{
    return base::data().xdof (idof);
}
template<class T>
inline
const array<point_basic<T>,distributed>&
space_basic<T,distributed>::get_xdofs() const
{
    return base::data().get_xdofs();
}
template<class T>
template <class Function>
inline
T
space_basic<T,distributed>::momentum (Function f, size_type idof) const
{
    return base::data().momentum (f, idof);
}
template<class T>
template <class Function>
inline
point_basic<T>
space_basic<T,distributed>::vector_momentum (Function f, size_type idof) const
{
    return base::data().vector_momentum (f, idof);
}
#endif // _RHEOLEF_HAVE_MPI

// only valid when M=sequential or M=distributed => use a macro
#define _RHEOLEF_space_build_indirect_array(M)						\
template<class T>									\
inline											\
array<typename space_basic<T,M>::size_type, M>						\
space_basic<T,M>::build_indirect_array (						\
	const space_basic<T,M>& Wh,							\
	const std::string& dom_name) const						\
{											\
    return base::data().build_indirect_array (Wh.data(), dom_name);			\
}
_RHEOLEF_space_build_indirect_array(sequential)

#ifdef _RHEOLEF_HAVE_MPI
_RHEOLEF_space_build_indirect_array(distributed)
#endif // _RHEOLEF_HAVE_MPI

#undef _RHEOLEF_space_build_indirect_array

} // namespace rheolef
#endif // _RHEOLEF_SPACE_H