This file is indexed.

/usr/include/rheolef/geo.h is in librheolef-dev 6.6-1build2.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

   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
 978
 979
 980
 981
 982
 983
 984
 985
 986
 987
 988
 989
 990
 991
 992
 993
 994
 995
 996
 997
 998
 999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
#ifndef _RHEOLEF_GEO_H
#define _RHEOLEF_GEO_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
///
/// =========================================================================
/*
  geo: mesh data structure
  author: Pierre.Saramito@imag.fr
  date: 20 april 2013

  geo is an alias to geo_basic<T,M>
 	T: the current Float represetation (e.g. double)
	M: the memory model (sequential or distributed)
           the default memory model has been choosen by the configure script

  geo_basic<T,M> is a smart_pointer_clone<geo_abstract_rep<T,M> >
	i.e. a pointer with shalow copy semantic on a pure virtual base class geo_abstract_rep<T,M>
        used by polymorphic hierarchy of classes.

  there are three concrete variants for this base class:
    geo_rep<T,M> 		 : for usual meshes, as omega
    geo_domain_indirect_rep<T,M> : for usual boundary domains, as gamma=omega["boundary"]
    geo_domain_rep<T,M> 	 : for compacted boundary domains, as gamma=omega["boundary"]
				   used when defining a space on a boundary domain, as
					space W (omega["boundary"], "P1");
				   => elments and vertex are renumbered in a compact form
				      for easy P1 dofs numbering.

   Most code is shared by these three classes and by the sequential/distributed variants.
   This leads to the following hierarchy of classes:

        geo_abstract_base_rep<T>             : virtual methods for M=seq
          geo_abstract_rep<T,M>              : M=seq,dis have separated impl; add methods for M=dis
            geo_domain_indirect_base_rep<T,M>: data + methods for domains
              geo_domain_indirect_rep<T,M>   : M=seq,dis have separated impl; add methods for M=dis
            geo_base_rep<T,M>                : data + methods for geometry
              geo_rep<T,M>                   : M=seq,dis have separated impl: add methods for M=dis
                geo_domain_rep<T,M>          : data + methods for compacted geometry on domain
*/
#include "rheolef/geo_element.h"
#include "rheolef/array.h"
#include "rheolef/hack_array.h"
#include "rheolef/geo_size.h"
#include "rheolef/point.h"
#include "rheolef/domain_indirect.h"
#include "rheolef/geo_header.h"
#include "rheolef/numbering.h"
#include "rheolef/space_constant.h"
#include "rheolef/geo_locate.h"
#include "rheolef/geo_trace_ray_boundary.h"
#include "rheolef/geo_nearest.h"

namespace rheolef {

// =========================================================================
// point io helpers
// =========================================================================
/// @brief point input helper
template <class T>
struct _point_get {
  typedef typename point_basic<T>::size_type size_type;
  _point_get (size_type d1) : d(d1) {}
  size_type d;
  std::istream& operator() (std::istream& is, point_basic<T>& x) { return x.get (is, d); }
}; 
/// @brief point output helper
template <class T>
struct _point_put {
  typedef typename point_basic<T>::size_type size_type;
  _point_put (size_type d1) : d(d1) {}
  size_type d;
  std::ostream& operator() (std::ostream& os, const point_basic<T>& x) { return x.put (os, d); }
};

// forward declaration:
template <class T, class M> class geo_basic;
template <class T, class M> class geo_domain_indirect_rep;

// =========================================================================
/// @brief geo iterator
// =========================================================================
template <class T> class geo_abstract_base_rep;

template<class T, class Ref, class Ptr, class IteratorByVariant>
struct geo_iterator {
  typedef geo_iterator<T,Ref,Ptr,IteratorByVariant>                  _self;
  typedef geo_iterator<T,T&,T*,typename hack_array<T>::iterator>  _nonconst_iterator;

// typedefs

  // see std::deque<T>::iterator : TODO: complete to a full random iterator
  typedef std::random_access_iterator_tag iterator_category;
  typedef T                               value_type;
  typedef Ptr                             pointer;
  typedef Ref                             reference;
  typedef typename T::size_type           size_type;
  typedef ptrdiff_t                       difference_type;

// allocators:

  template<class Geo>
  geo_iterator (size_type dim, size_type variant, IteratorByVariant iter, Geo& omega);
  geo_iterator (const _nonconst_iterator& y); // conversion from iter to const_iter

// accessors & modifiers:

  reference operator* () const { return *_iter_by_var; }
  pointer   operator->() const { return _iter_by_var.operator->(); }

  _self& operator++ () { 
    ++_iter_by_var;
    _reset_to_next_or_last();
    return *this;
  }
  void _reset_to_next_or_last () {
    while (_variant < _variant_max && _iter_by_var == _last_by_var [_variant]) {
      ++_variant; // then variant <= variant_max
      if (_variant < _variant_max) {
        _iter_by_var = _first_by_var [_variant];
      }
    }
  }
  _self operator++ (int) { _self tmp = *this; operator++(); return tmp; }

  bool operator== (const _self& y) const { return _variant == y._variant && _iter_by_var == y._iter_by_var; }
  bool operator!= (const _self& y) const { return ! operator== (y); }

// data:

  size_type                       _variant;
  size_type                       _variant_max;
  IteratorByVariant               _iter_by_var;
  IteratorByVariant               _first_by_var [reference_element::max_variant];
  IteratorByVariant                _last_by_var [reference_element::max_variant];
};
// =========================================================================
/// @brief abstract base interface class
// =========================================================================
template <class T>
class geo_abstract_base_rep {
public:

// typedefs

    typedef enum { 
	geo                 = 0, 
	geo_domain          = 1, 
	geo_domain_indirect = 2, 
	max_variant         = 3 
    } geo_rep_variant_type; 

    typedef geo_element_hack::size_type                    size_type;
    typedef point_basic<T>                                 node_type;
    typedef reference_element::variant_type             variant_type;
    typedef geo_element&                                   reference;
    typedef const geo_element&                             const_reference;
    typedef typename hack_array<geo_element_hack>::iterator
	    iterator_by_variant;
    typedef typename hack_array<geo_element_hack>::const_iterator
	    const_iterator_by_variant;
    typedef geo_iterator<geo_element, geo_element&, geo_element*, iterator_by_variant>
            iterator;
    typedef geo_iterator<geo_element, const geo_element&, const geo_element*, const_iterator_by_variant>
            const_iterator;
    typedef space_constant::coordinate_type coordinate_type;

// allocators:

    geo_abstract_base_rep () {}
    virtual ~geo_abstract_base_rep () {}

// abstract accessors:

    virtual size_type variant() const = 0;
    virtual std::string name() const = 0;
    virtual std::string familyname() const = 0;
    virtual size_type dimension() const = 0;
    virtual size_type serial_number() const = 0;
    virtual size_type map_dimension() const = 0;
    virtual coordinate_type coordinate_system() const = 0;
    virtual const basis_basic<T>& get_piola_basis() const = 0;
    virtual const node_type& xmin() const = 0;
    virtual const node_type& xmax() const = 0;
    virtual const T&         hmin() const = 0;
    virtual const T&         hmax() const = 0;
    virtual const geo_size&  sizes() const = 0;
    virtual const geo_size&  ios_sizes() const = 0;

    virtual const distributor&  geo_element_ownership (size_type dim) const = 0;
    virtual const_reference get_geo_element           (size_type dim, size_type ige) const = 0;
    virtual const geo_element& bgd2dom_geo_element (const geo_element& bgd_K) const { return bgd_K; }
    virtual const geo_element& dom2bgd_geo_element (const geo_element& dom_K) const { return dom_K; }
    virtual size_type neighbour (size_type ie, size_type loc_isid) const = 0;
    virtual void neighbour_guard() const = 0;

    virtual const_iterator_by_variant begin_by_variant (variant_type variant) const = 0;
    virtual const_iterator_by_variant   end_by_variant (variant_type variant) const = 0;

    const_iterator begin (size_type dim) const;
    const_iterator end   (size_type dim) const;

    virtual size_type n_node() const = 0;
    virtual const node_type& node   (size_type inod) const = 0;
    virtual const node_type& dis_node (size_type dis_inod) const = 0;
    virtual node_type piola (const geo_element& K, const node_type& hat_x) const = 0;
    virtual void dis_inod (const geo_element& K, std::vector<size_type>& dis_inod) const = 0;
    virtual size_type dis_inod2dis_iv (size_type dis_inod) const = 0;

    virtual size_type n_domain_indirect () const = 0;
    virtual bool have_domain_indirect (const std::string& name) const = 0;
    virtual void reset_order (size_type order) = 0;

    virtual size_type seq_locate (
	const point_basic<T>& x,
	size_type dis_ie_guest = std::numeric_limits<size_type>::max()) const = 0;
    virtual size_type dis_locate (
	const point_basic<T>& x,
	size_type dis_ie_guest = std::numeric_limits<size_type>::max()) const = 0;

    virtual size_type seq_trace_move (
        const point_basic<T>&     x,
        const point_basic<T>&     v,
              point_basic<T>&     y) const = 0;
    virtual size_type dis_trace_move (
        const point_basic<T>&     x,
        const point_basic<T>&     v,
              point_basic<T>&     y) const = 0;

    virtual size_type seq_nearest (
        const point_basic<T>&    x,
              point_basic<T>&    x_nearest) const = 0;
    virtual size_type dis_nearest (
        const point_basic<T>&    x,
              point_basic<T>&    x_nearest) const = 0;

// virtual i/o:

    virtual odiststream& put         (odiststream& ops) const = 0;
    virtual bool check(bool verbose) const = 0;

// deduced comparator:

    bool operator== (const geo_abstract_base_rep<T>& omega2) const {
	return name() == omega2.name(); }
};
template<class T, class Ref, class Ptr, class IteratorByVariant>
template<class Geo>
geo_iterator<T,Ref,Ptr,IteratorByVariant>::geo_iterator (
  size_type                       dim,
  size_type                       variant,
  IteratorByVariant               iter,
  Geo&                            omega)
 : _variant     (variant),
   _variant_max (reference_element::last_variant_by_dimension(dim)),
   _iter_by_var (iter),
   _first_by_var(),
    _last_by_var()
{
   for (size_type variant = reference_element::first_variant_by_dimension(dim);
                  variant < reference_element::last_variant_by_dimension(dim); variant++) {
     _first_by_var [variant] = omega.begin_by_variant (variant);
      _last_by_var [variant] = omega.  end_by_variant (variant);
   }
   _reset_to_next_or_last();
}
template<class T, class Ref, class Ptr, class IteratorByVariant>
geo_iterator<T,Ref,Ptr,IteratorByVariant>::geo_iterator (const _nonconst_iterator& y)
 : _variant     (y._variant),
   _variant_max (y._variant_max),
   _iter_by_var (y._iter_by_var),
   _first_by_var(),
    _last_by_var()
{
   std::copy (y._first_by_var, y._first_by_var + reference_element::max_variant, _first_by_var);
   std::copy (y. _last_by_var, y. _last_by_var + reference_element::max_variant,  _last_by_var);
}
// =========================================================================
/// @brief abstract interface class
// =========================================================================
template <class T, class M>
class geo_abstract_rep {};

template <class T>
class geo_abstract_rep<T,sequential> : public geo_abstract_base_rep<T> {
public:

// typedefs

    typedef geo_abstract_base_rep<T>                  base;
    typedef typename base::size_type                  size_type;
    typedef typename base::node_type                  node_type;
    typedef typename base::variant_type               variant_type;
    typedef typename base::iterator                   iterator;
    typedef typename base::const_iterator             const_iterator;
    typedef typename base::iterator_by_variant        iterator_by_variant;
    typedef typename base::const_iterator_by_variant  const_iterator_by_variant;
    typedef typename base::reference                  reference;
    typedef typename base::const_reference            const_reference;

// allocators:

    geo_abstract_rep () {}
    virtual geo_abstract_rep<T,sequential>* clone() const = 0;
    virtual ~geo_abstract_rep () {}

// abstract accessors:

    virtual const domain_indirect_basic<sequential>& get_domain_indirect (size_type i) const = 0;
    virtual const domain_indirect_basic<sequential>& get_domain_indirect (const std::string& name) const = 0;
    virtual void  insert_domain_indirect (const domain_indirect_basic<sequential>& dom) const = 0;

    virtual const array<node_type,sequential>& get_nodes() const = 0;
    virtual void set_nodes (const array<node_type,sequential>&) = 0;

    virtual void locate (
                const array<point_basic<T>, sequential>&    x,
                      array<size_type, sequential>&         dis_ie,
                bool  do_check = false) const = 0;
    virtual void trace_ray_boundary (
                const array<point_basic<T>,sequential>&     x,
                const array<point_basic<T>,sequential>&     v,
                      array<size_type, sequential>&         dis_ie,
                      array<point_basic<T>,sequential>&     y,
                bool  do_check = false) const = 0;
    virtual void trace_move (
                const array<point_basic<T>,sequential>&     x,
                const array<point_basic<T>,sequential>&     v,
                      array<size_type, sequential>&         dis_ie,
                      array<point_basic<T>,sequential>&     y) const = 0;
    virtual void nearest (
                const array<point_basic<T>,sequential>&     x,
                      array<point_basic<T>,sequential>&     x_nearest,
                      array<size_type, sequential>&         dis_ie) const = 0;
};
#ifdef _RHEOLEF_HAVE_MPI
template <class T>
class geo_abstract_rep<T,distributed> : public geo_abstract_base_rep<T> {
public:

// typedefs

    typedef geo_abstract_base_rep<T>       base;
    typedef typename base::size_type       size_type;
    typedef typename base::node_type       node_type;
    typedef typename base::const_reference const_reference;
    typedef std::map <size_type, node_type, std::less<size_type>,
            heap_allocator<std::pair<size_type,node_type> > >    node_map_type;

// allocators:

    geo_abstract_rep () {}
    virtual geo_abstract_rep<T,distributed>* clone() const = 0;
    virtual ~geo_abstract_rep () {}

// abstract accessors:

    virtual distributor geo_element_ios_ownership (size_type dim) const = 0;
    virtual const_reference   dis_get_geo_element (size_type dim, size_type dis_ige) const = 0;
    virtual size_type             ige2ios_dis_ige (size_type dim, size_type     ige) const = 0;
    virtual size_type         dis_ige2ios_dis_ige (size_type dim, size_type dis_ige) const = 0;
    virtual size_type             ios_ige2dis_ige (size_type dim, size_type ios_ige) const = 0;

    virtual const domain_indirect_basic<distributed>& get_domain_indirect (size_type i) const = 0;
    virtual const domain_indirect_basic<distributed>& get_domain_indirect (const std::string& name) const = 0;
    virtual void insert_domain_indirect (const domain_indirect_basic<distributed>& dom) const = 0;

    virtual const array<node_type,distributed>& get_nodes() const = 0;
    virtual void set_nodes (const array<node_type,distributed>&) = 0;

    virtual void locate (
                const array<point_basic<T>,distributed>&     x,
                      array<size_type, distributed>&         dis_ie,
                bool  do_check = true) const = 0;
    virtual void trace_ray_boundary (
                const array<point_basic<T>,distributed>&     x,
                const array<point_basic<T>,distributed>&     v,
                      array<size_type, distributed>&         dis_ie,
                      array<point_basic<T>,distributed>&     y,
                bool  do_check = false) const = 0;
    virtual void trace_move (
                const array<point_basic<T>,distributed>&     x,
                const array<point_basic<T>,distributed>&     v,
                      array<size_type, distributed>&         dis_ie,
                      array<point_basic<T>,distributed>&     y) const = 0;
    virtual void nearest (
                const array<point_basic<T>,distributed>&     x,
                      array<point_basic<T>,distributed>&     x_nearest,
                      array<size_type, distributed>&         dis_ie) const = 0;

// utility:

    virtual void set_ios_permutation (
    	boost::array<size_type,reference_element::max_variant>& loc_ndof_by_variant,
    	array<size_type,distributed>&                           idof2ios_dis_idof) const = 0;
};
#endif // _RHEOLEF_HAVE_MPI
// =========================================================================
/// @brief base class for M=sequential or distributed meshes representations
// =========================================================================
// NOTE: since geo_rep<seq> contains sequential arrays for vertices and elts,
//  the geo_rep<mpi> cannot derive from geo_rep<seq>. The solution is to
//  derive both geo_rep<seq> and geo_rep<mpi> classes from a generic base class
//  named geo_base_rep that takes the memory model (seq or mpi) as template argument.
template <class T, class M>
class geo_base_rep : public geo_abstract_rep<T,M> {
public:
// typedefs:

    typedef geo_abstract_rep<T,M>                     base;
    typedef typename base::size_type                  size_type;
    typedef typename base::node_type                  node_type;
    typedef typename base::variant_type               variant_type;
    typedef typename base::iterator                   iterator;
    typedef typename base::const_iterator             const_iterator;
    typedef typename base::iterator_by_variant        iterator_by_variant;
    typedef typename base::const_iterator_by_variant  const_iterator_by_variant;
    typedef typename base::reference                  reference;
    typedef typename base::const_reference            const_reference;
    typedef typename base::coordinate_type            coordinate_type;

// allocators:

    geo_base_rep ();
    geo_base_rep (const geo_base_rep<T,M>&);

    void build_from_list (
      const geo_basic<T,M>&                               lambda,
      const array<point_basic<T>,M>&                      node_list,
      const boost::array<array<geo_element_auto<heap_allocator<size_type> >,M>,
                         reference_element::max_variant>& elt_list);

    ~geo_base_rep ();

// abstract accessors defined:
  
    size_type          variant() const { return geo_abstract_base_rep<T>::geo; }
    std::string     familyname() const { return _name; }
    std::string           name() const;
    size_type    serial_number() const { return _serial_number; }
    size_type        dimension() const { return _dimension; }
    size_type    map_dimension() const { return _map_dimension; }
    coordinate_type coordinate_system() const { return _sys_coord; }
    void set_coordinate_system (coordinate_type sys_coord) { _sys_coord = sys_coord; }
    void set_name (std::string name) { _name = name; }
    void set_dimension (size_type dim) { _dimension = dim; }
    void set_serial_number(size_type i) { _serial_number = i; }
    const basis_basic<T>& get_piola_basis() const { return _numbering.get_basis(); }
    const node_type&      xmin() const { return _xmin; }
    const node_type&      xmax() const { return _xmax; }
    const T&              hmin() const { return _hmin; }
    const T&              hmax() const { return _hmax; }
    const geo_size&      sizes() const { return _gs; }
    const geo_size&  ios_sizes() const { return _gs; }

    const distributor& geo_element_ownership (size_type dim) const { return _gs.ownership_by_dimension[dim]; }
    const_reference     get_geo_element (size_type dim, size_type ige) const;
    const_reference dis_get_geo_element (size_type dim, size_type dis_ige) const;

    const_iterator_by_variant begin_by_variant (variant_type variant) const;
          iterator_by_variant begin_by_variant (variant_type variant);
    const_iterator_by_variant   end_by_variant (variant_type variant) const;
          iterator_by_variant   end_by_variant (variant_type variant);

    const node_type&     node (size_type     inod) const { return _node [inod]; }
    const node_type& dis_node (size_type dis_inod) const { return _node.dis_at (dis_inod); }
    const node_type&     node (const geo_element& K, size_type loc_inod) const;
    void             dis_inod (const geo_element& K, std::vector<size_type>& dis_inod) const
	{ _numbering.dis_idof (_gs, K, dis_inod); }
    node_type piola (const geo_element& K, const node_type& hat_x) const;
    const array<node_type,M>& get_nodes() const { return _node; }

    void set_nodes (const array<node_type,M>& x) { _node = x; _node.reset_dis_indexes(); compute_bbox(); }
    size_type n_domain_indirect () const { return _domains.size(); }
    bool have_domain_indirect (const std::string& name) const;
    const domain_indirect_basic<M>& get_domain_indirect (size_type i) const { return _domains[i]; }
    const domain_indirect_basic<M>& get_domain_indirect (const std::string& name) const;
    void  insert_domain_indirect (const domain_indirect_basic<M>& dom) const;

    size_type seq_locate (
                const point_basic<T>& x,
	        size_type dis_ie_guest = std::numeric_limits<size_type>::max()) const;
    size_type dis_locate (
		const point_basic<T>& x,
		size_type dis_ie_guest = std::numeric_limits<size_type>::max()) const;
    size_type seq_trace_move (
                const point_basic<T>&     x,
                const point_basic<T>&     v,
                      point_basic<T>&     y) const;
    size_type dis_trace_move (
                const point_basic<T>&     x,
                const point_basic<T>&     v,
                      point_basic<T>&     y) const;
    size_type seq_nearest (
                const point_basic<T>&    x,
                      point_basic<T>&    x_nearest) const;
    size_type dis_nearest (
                const point_basic<T>&    x,
                      point_basic<T>&    x_nearest) const;

    size_type neighbour (size_type ie, size_type loc_isid) const;
    void neighbour_guard() const;

// additional accessors & modifier:

    reference get_geo_element (size_type dim, size_type ige);
    iterator begin (size_type dim);
    iterator end   (size_type dim);

// deduced accessors:

    size_type     size(size_type dim) const;
    size_type dis_size(size_type dim) const;
    const distributor&        ownership() const { return geo_element_ownership (map_dimension()); }
    const distributor& vertex_ownership() const { return geo_element_ownership (0); }
    const communicator&            comm() const { return ownership().comm(); }
    size_type            order() const { return get_piola_basis().degree(); }

    size_type        n_node() const { return _node.    size(); }
    size_type    dis_n_node() const { return _node.dis_size(); }
    size_type      n_vertex() const { return     size (0); }
    size_type          size() const { return     size (map_dimension()); }
    size_type  dis_n_vertex() const { return dis_size (0); }
    size_type      dis_size() const { return dis_size (map_dimension()); }
    size_type    dis_n_edge() const { return dis_size (1); }
    size_type    dis_n_face() const { return dis_size (2); }
    size_type dis_inod2dis_iv (size_type dis_inod) const;
    size_type dis_iv2dis_inod (size_type dis_iv)   const;

    const_reference operator[] (size_type ie) const { return get_geo_element (map_dimension(), ie); }
    reference  	    operator[] (size_type ie)	    { return get_geo_element (map_dimension(), ie); }

    const_iterator begin (size_type dim) const { return base::begin (dim); }
    const_iterator end   (size_type dim) const { return base::end   (dim); }

    const_iterator begin()               const { return base::begin (map_dimension()); }
    const_iterator end()                 const { return base::end   (map_dimension()); }

    const_iterator begin_edge()          const { return base::begin (1); }
    const_iterator end_edge()            const { return base::end   (1); }
    const_iterator begin_face()          const { return base::begin (2); }
    const_iterator end_face()            const { return base::end   (2); }

protected:
    void compute_bbox();
    void init_neighbour() const;
    template<class U> friend void add_ball_externals (const geo_base_rep<U,M>&, const array<index_set,M>&);

// data:
// 0) header:
    std::string                              _name;
    size_type                                _version;
    size_type                                _serial_number;
// 1) connectivity:
    hack_array<geo_element_hack,M>           _geo_element [reference_element::max_variant];
    size_type                                _map_dimension;
    geo_size                                 _gs; // counters by geo_element dimension: 0,1,2,3
    mutable std::vector<domain_indirect_basic<M> > _domains;
    bool				     _have_connectivity; // e.g.list of  edges in a 2d triangular mesh
    mutable bool			     _have_neighbour; // inter-element connectivity
// 2) coordinates:
    array<node_type, M>                      _node;
    size_type                                _dimension;
    coordinate_type                          _sys_coord;
    node_type				     _xmin; // bounding box
    node_type				     _xmax;
    T					     _hmin;
    T					     _hmax;
    numbering<T,M>                           _numbering;
    geo_locate<T,M>                          _locator;
    geo_trace_ray_boundary<T,M>              _tracer_ray_boundary;
    geo_nearest<T,M>                         _nearestor;
};
template <class T, class M>
inline
void
geo_base_rep<T,M>::neighbour_guard() const
{
  if (_have_neighbour) return;
  _have_neighbour = true;
  init_neighbour();
}
template <class T, class M>
typename geo_base_rep<T,M>::iterator_by_variant
geo_base_rep<T,M>::begin_by_variant (variant_type variant)
{
  return _geo_element [variant].begin(); 
}
template <class T, class M>
typename geo_base_rep<T,M>::const_iterator_by_variant
geo_base_rep<T,M>::begin_by_variant (variant_type variant) const
{
  return _geo_element [variant].begin(); 
}
template <class T, class M>
typename geo_base_rep<T,M>::iterator_by_variant
geo_base_rep<T,M>::end_by_variant (variant_type variant)
{
  return _geo_element [variant].end(); 
}
template <class T, class M>
typename geo_base_rep<T,M>::const_iterator_by_variant
geo_base_rep<T,M>::end_by_variant (variant_type variant) const
{
  return _geo_element [variant].end(); 
}
/// @brief iterator by dimension: wraps iterator by geo_element variant
template <class T, class M>
inline
typename geo_base_rep<T,M>::iterator
geo_base_rep<T,M>::begin (size_type dim)
{
  variant_type variant = reference_element::first_variant_by_dimension(dim);
  iterator_by_variant iter = begin_by_variant (variant);
  iterator res = iterator (dim, variant, iter, *this);
  return res;
}
template <class T, class M>
inline
typename geo_base_rep<T,M>::iterator
geo_base_rep<T,M>::end (size_type dim) 
{
  variant_type variant = reference_element::last_variant_by_dimension(dim);
  iterator_by_variant iter = end_by_variant (variant - 1);
  iterator res = iterator (dim, variant, iter, *this);
  return res;
}
template <class T>
inline
typename geo_abstract_base_rep<T>::const_iterator
geo_abstract_base_rep<T>::begin (size_type dim) const
{
  variant_type variant = reference_element::first_variant_by_dimension(dim);
  const_iterator_by_variant iter = begin_by_variant (variant);
  return const_iterator (dim, variant, iter, *this);
}
template <class T>
inline
typename geo_abstract_base_rep<T>::const_iterator
geo_abstract_base_rep<T>::end (size_type dim) const
{
  variant_type variant = reference_element::last_variant_by_dimension(dim);
  const_iterator_by_variant iter = end_by_variant (variant - 1);
  return const_iterator (dim, variant, iter, *this);
}
// =========================================================================
/// @brief sequential mesh representation
// =========================================================================
template <class T, class M> class geo_rep {};

template <class T>
class geo_rep<T,sequential> : public geo_base_rep<T,sequential> {
public:
// typedefs:

    typedef geo_base_rep<T,sequential>               base;
    typedef typename base::size_type                 size_type;
    typedef typename base::node_type                 node_type;
    typedef typename base::variant_type              variant_type;
    typedef typename base::reference                 reference;
    typedef typename base::const_reference           const_reference;
    typedef typename base::iterator                  iterator;
    typedef typename base::const_iterator            const_iterator;
    typedef typename base::iterator_by_variant       iterator_by_variant;
    typedef typename base::const_iterator_by_variant const_iterator_by_variant;
    typedef typename base::coordinate_type           coordinate_type;

// allocators:

    geo_rep();
    geo_rep (const geo_rep<T,sequential>&);
    geo_abstract_rep<T,sequential>* clone() const;

    // build from_list (for level set)
    geo_rep (
      const geo_basic<T,sequential>&                      lambda,
      const array<point_basic<T>,sequential>&             node_list,
      const boost::array<array<geo_element_auto<heap_allocator<size_type> >,sequential>,
                         reference_element::max_variant>& elt_list);

    void build_from_domain (
	const domain_indirect_rep<sequential>&              indirect,
	const geo_abstract_rep<T,sequential>&               omega,
              std::map<size_type,size_type>&                bgd_ie2dom_ie);

// abstract accessors redefined:

    void locate (
                const array<point_basic<T>, sequential>&    x,
                      array<size_type, sequential>&         dis_ie,
                bool do_check = false) const;
    void trace_ray_boundary (
                const array<point_basic<T>,sequential>&     x,
                const array<point_basic<T>,sequential>&     v,
                      array<size_type, sequential>&         dis_ie,
                      array<point_basic<T>,sequential>&     y,
                bool  do_check = false) const;
    void trace_move (
                const array<point_basic<T>,sequential>&     x,
                const array<point_basic<T>,sequential>&     v,
                      array<size_type, sequential>&         dis_ie,
                      array<point_basic<T>,sequential>&     y) const;
    void nearest (
                const array<point_basic<T>,sequential>&     x,
                      array<point_basic<T>,sequential>&     x_nearest,
                      array<size_type, sequential>&         dis_ie) const;

// herited accessors:

    size_type map_dimension ()     const { return base::map_dimension(); }
    const distributor& geo_element_ownership(size_type dim) const { return base::geo_element_ownership (dim); }
    const_reference get_geo_element (size_type dim, size_type ige) const { return base::get_geo_element (dim, ige); }
    reference       get_geo_element (size_type dim, size_type ige)       { return base::get_geo_element (dim, ige); }
    iterator       begin (size_type dim)       { return base::begin(dim); }
    iterator       end   (size_type dim)       { return base::end  (dim); }
    const_iterator begin (size_type dim) const { return base::begin(dim); }
    const_iterator end   (size_type dim) const { return base::end  (dim); }

    const domain_indirect_basic<sequential>& get_domain_indirect (size_type idom) const { return base::get_domain_indirect (idom); }
    const domain_indirect_basic<sequential>& get_domain_indirect (const std::string& name) const { return base::get_domain_indirect (name); }

// deduced accessors:

    const distributor& vertex_ownership()        const { return geo_element_ownership(0); }
    const_reference operator[] (size_type ie) const { return get_geo_element (map_dimension(), ie); }
    reference       operator[] (size_type ie)       { return get_geo_element (map_dimension(), ie); }
#ifdef TO_CLEAN
    size_type             dis_inod2dis_iv (size_type dis_inod) const { return dis_inod; }
    size_type             dis_iv2dis_inod (size_type dis_iv)   const { return dis_iv; }
#endif // TO_CLEAN

// i/o:

    idiststream& get         (idiststream&);
    odiststream& put_geo     (odiststream&) const;
    odiststream& put         (odiststream& ops) const { return put_geo(ops); }

    void dump (std::string name) const;
    void load (std::string name, const communicator& = communicator());
    bool check(bool verbose) const;

// modifier:

    void reset_order (size_type order);
    void build_from_data (
        const geo_header&                                               hdr,
        const array<node_type, sequential>&                             node,
              boost::array<array<geo_element_auto<heap_allocator<size_type> >,sequential, heap_allocator<size_type> >, reference_element::max_variant>&
									tmp_geo_element,
        bool do_upgrade);

// internal:
protected:
    idiststream& get_standard (idiststream&, const geo_header&);
    idiststream& get_upgrade  (idiststream&, const geo_header&);
    void build_connectivity (
  	boost::array<array<geo_element_auto<heap_allocator<size_type> >,sequential, heap_allocator<size_type> >, reference_element::max_variant>& tmp_geo_element);

    void build_connectivity_sides (
		size_type side_dim, 
  		boost::array<array<geo_element_auto<heap_allocator<size_type> >,sequential, heap_allocator<size_type> >, reference_element::max_variant>& tmp_geo_element);
    void set_element_side_index (size_type side_dim);
    void domain_set_side_part1 (
                const domain_indirect_rep<sequential>&    indirect,
                const geo_abstract_rep<T,sequential>&     bgd_omega,
                size_type                                 sid_dim,
                array<size_type,sequential>&              bgd_isid2dom_dis_isid,
                array<size_type,sequential>&              dom_isid2bgd_isid,
                array<size_type,sequential>&              dom_isid2dom_ios_dis_isid,
    		size_type                                 size_by_variant [reference_element::max_variant]);
    void domain_set_side_part2 (
                const domain_indirect_rep<sequential>&    indirect,
                const geo_abstract_rep<T,sequential>&     bgd_omega,
                array<size_type,sequential>&              bgd_iv2dom_dis_iv,
                size_type                                 sid_dim,
                array<size_type,sequential>&              bgd_isid2dom_dis_isid,
                array<size_type,sequential>&              dom_isid2bgd_isid,
                array<size_type,sequential>&              dom_isid2dom_ios_dis_isid,
    		size_type                                 size_by_variant [reference_element::max_variant]);
    void build_external_entities () {} // for distributed compat
};
#ifdef _RHEOLEF_HAVE_MPI
// =========================================================================
/// @brief distributed mesh representation
// =========================================================================
template <class T>
class geo_rep<T,distributed> : public geo_base_rep<T,distributed> {
public:
// typedefs:

    typedef geo_base_rep<T,distributed>              base;
    typedef typename base::size_type                 size_type;
    typedef typename base::node_type                 node_type;
    typedef typename base::variant_type              variant_type;
    typedef typename base::node_map_type             node_map_type;
    typedef typename base::reference                 reference;
    typedef typename base::const_reference           const_reference;
    typedef typename base::iterator                  iterator;
    typedef typename base::const_iterator            const_iterator;
    typedef typename base::iterator_by_variant       iterator_by_variant;
    typedef typename base::const_iterator_by_variant const_iterator_by_variant;
    typedef typename base::coordinate_type           coordinate_type;

// allocators:

    geo_rep ();
    geo_rep (const geo_rep<T,distributed>&);
    geo_abstract_rep<T,distributed>* clone() const;

    void build_from_domain (
        const domain_indirect_rep<distributed>&              indirect,
        const geo_abstract_rep<T,distributed>&               omega,
              std::map<size_type,size_type>&                 bgd_ie2dom_ie);

    // build from_list (for level set)
    geo_rep (
      const geo_basic<T,distributed>&                     lambda,
      const array<point_basic<T>,distributed>&            node_list,
      const boost::array<array<geo_element_auto<heap_allocator<size_type> >,distributed>,
                         reference_element::max_variant>& elt_list);

// abstract accessors defined:

    distributor geo_element_ios_ownership (size_type dim) const;

    size_type             ige2ios_dis_ige (size_type dim, size_type ige) const;
    size_type         dis_ige2ios_dis_ige (size_type dim, size_type dis_ige) const;
    size_type             ios_ige2dis_ige (size_type dim, size_type ios_ige) const;
    const geo_size&  ios_sizes() const { return _ios_gs; }
    void locate (
                const array<point_basic<T>,distributed>&     x,
                      array<size_type, distributed>&         dis_ie,
                      bool do_check = false) const;
    void trace_ray_boundary (
                const array<point_basic<T>,distributed>&     x,
                const array<point_basic<T>,distributed>&     v,
                      array<size_type, distributed>&         dis_ie,
                      array<point_basic<T>,distributed>&     y,
                bool  do_check = false) const;
    void trace_move (
                const array<point_basic<T>,distributed>&     x,
                const array<point_basic<T>,distributed>&     v,
                      array<size_type, distributed>&         dis_ie,
                      array<point_basic<T>,distributed>&     y) const;
    void nearest (
                const array<point_basic<T>,distributed>&     x,
                      array<point_basic<T>,distributed>&     x_nearest,
                      array<size_type, distributed>&         dis_ie) const;

// herited accessors:

    size_type map_dimension ()     const { return base::map_dimension(); }
    size_type size (size_type dim) const { return base::size(dim); }
    const distributor& geo_element_ownership(size_type dim) const { return base::geo_element_ownership (dim); }
    const_reference get_geo_element (size_type dim, size_type ige) const { return base::get_geo_element (dim, ige); }
    reference       get_geo_element (size_type dim, size_type ige)       { return base::get_geo_element (dim, ige); }

    const_iterator begin (size_type dim) const { return base::begin(dim); }
    const_iterator end   (size_type dim) const { return base::end  (dim); }
    iterator       begin (size_type dim)       { return base::begin(dim); }
    iterator       end   (size_type dim)       { return base::end  (dim); }

    const domain_indirect_basic<distributed>& get_domain_indirect (size_type idom) const { return base::get_domain_indirect (idom); }
    const domain_indirect_basic<distributed>& get_domain_indirect (const std::string& name) const { return base::get_domain_indirect (name); }

// deduced accessors:

    size_type          size ()                   const { return size (map_dimension()); }
    const distributor& vertex_ownership()        const { return geo_element_ownership(0); }
    const_reference operator[] (size_type ie) const { return get_geo_element (map_dimension(), ie); }
#ifdef TODO
	  reference operator[] (size_type ie)       { return get_geo_element (map_dimension(), ie); }
#endif // TODO

// modifier:

    void reset_order (size_type order);

// i/o:

    idiststream& get (idiststream&);
    odiststream& put (odiststream&) const;
    void dump (std::string name) const;
    void load (std::string name, const communicator& comm);
    bool check(bool verbose) const;

// utilities:

    void set_ios_permutation (
    	boost::array<size_type,reference_element::max_variant>& loc_ndof_by_variant,
    	array<size_type,distributed>&                           idof2ios_dis_idof) const;

protected:
// internal:
    void build_external_entities ();
    void set_element_side_index (size_type side_dim);
    void domain_set_side_part1 (
                const domain_indirect_rep<distributed>&    indirect,
                const geo_abstract_rep<T,distributed>&     bgd_omega,
                size_type                                  sid_dim,
                array<size_type>&                          bgd_isid2dom_dis_isid,
                array<size_type>&                          dom_isid2bgd_isid,
                array<size_type>&                          dom_isid2dom_ios_dis_isid,
    		size_type                                  size_by_variant [reference_element::max_variant]);
    void domain_set_side_part2 (
                const domain_indirect_rep<distributed>&    indirect,
                const geo_abstract_rep<T,distributed>&     bgd_omega,
                array<size_type>&                          bgd_iv2dom_dis_iv,
                size_type                                  sid_dim,
                array<size_type>&                          bgd_isid2dom_dis_isid,
                array<size_type>&                          dom_isid2bgd_isid,
                array<size_type>&                          dom_isid2dom_ios_dis_isid,
    		size_type                                  size_by_variant [reference_element::max_variant]);

    void node_renumbering (const distributor& ios_node_ownership);

// data:
    array<size_type>             _inod2ios_dis_inod;  // permutation for node
    array<size_type>             _ios_inod2dis_inod;  // reverse permutation for node
    array<size_type>             _ios_ige2dis_ige[4]; // reverse permutation for geo_element[dim]
    geo_size                     _ios_gs;
    array<size_type>             _igev2ios_dis_igev [reference_element::max_variant];
    array<size_type>             _ios_igev2dis_igev [reference_element::max_variant];
};
#endif // _RHEOLEF_HAVE_MPI

// =========================================================================
/// @brief generic mesh with rerefence counting
// =========================================================================
template <class T, class M = rheo_default_memory_model>
class geo_basic {
public:
    typedef M memory_type;
};
/*Class:geo
NAME:  @code{geo} - finite element mesh (@PACKAGE@-@VERSION@)
SYNOPSYS:       
 Distributed finite element mesh.
SEE ALSO: "geo_element"(3)
AUTHORS: Pierre.Saramito@imag.fr
DATE:   10 december 2010
End:
*/
// =========================================================================
/// @brief sequential mesh with reference counting
// =========================================================================
// handler for complex geo names as "square[boundary]"
template<class T, class M> geo_basic<T,M> geo_load (const std::string& name);

// guards for omega.boundary(), omega.internal_sides() and omega.sides()
template<class T, class M> void boundary_guard       (const geo_basic<T,M>&);
template<class T, class M> void internal_sides_guard (const geo_basic<T,M>&);
template<class T, class M> void sides_guard          (const geo_basic<T,M>&);

//<verbatim:
template <class T>
class geo_basic<T,sequential> : public smart_pointer_clone<geo_abstract_rep<T,sequential> > {
public:

// typedefs:

    typedef sequential                              memory_type;
    typedef geo_abstract_rep<T,sequential>          rep;
    typedef geo_rep<T,sequential>                   rep_geo_rep;
    typedef smart_pointer_clone<rep>                base;
    typedef typename rep::size_type                 size_type;
    typedef typename rep::node_type                 node_type;
    typedef typename rep::variant_type              variant_type;
    typedef typename rep::reference                 reference;
    typedef typename rep::const_reference           const_reference;
    typedef typename rep::iterator                  iterator;
    typedef typename rep::const_iterator            const_iterator;
    typedef typename rep::iterator_by_variant       iterator_by_variant;
    typedef typename rep::const_iterator_by_variant const_iterator_by_variant;
    typedef typename rep::coordinate_type           coordinate_type;

// allocators:

    geo_basic ();
    geo_basic (std::string name, const communicator& comm = communicator());
    void load (std::string name, const communicator& comm = communicator());
    geo_basic (const domain_indirect_basic<sequential>& dom, const geo_basic<T,sequential>& omega);

    // build from_list (for level set)
    geo_basic (
      const geo_basic<T,sequential>&                      lambda,
      const array<point_basic<T>,sequential>&             node_list,
      const boost::array<array<geo_element_auto<heap_allocator<size_type> >,sequential>,
                         reference_element::max_variant>& elt_list)
    : base (new_macro(rep_geo_rep(lambda,node_list,elt_list))) {}

// accessors:

    std::string                    name() const { return base::data().name(); }
    std::string              familyname() const { return base::data().familyname(); }
    size_type                 dimension() const { return base::data().dimension(); }
    size_type             map_dimension() const { return base::data().map_dimension(); }
    size_type             serial_number() const { return base::data().serial_number(); }
    size_type                   variant() const { return base::data().variant(); }
    coordinate_type   coordinate_system() const { return base::data().coordinate_system(); }
    std::string  coordinate_system_name() const { return space_constant::coordinate_system_name(coordinate_system()); }
    const basis_basic<T>& get_piola_basis() const { return base::data().get_piola_basis(); }
    size_type                     order() const { return base::data().get_piola_basis().degree(); }
    const node_type&               xmin() const { return base::data().xmin(); }
    const node_type&               xmax() const { return base::data().xmax(); }
    const T&           		   hmin() const { return base::data().hmin(); }
    const T&	                   hmax() const { return base::data().hmax(); }
    const distributor& geo_element_ownership(size_type dim) const { return base::data().geo_element_ownership(dim); }
    const geo_size&      sizes()             const { return base::data().sizes(); }
    const geo_size&  ios_sizes()             const { return base::data().ios_sizes(); }
    const_reference get_geo_element (size_type dim, size_type ige) const { return base::data().get_geo_element (dim, ige); }
          reference get_geo_element (size_type dim, size_type ige)       { return base::data().get_geo_element (dim, ige); }
    const_reference dis_get_geo_element (size_type dim, size_type dis_ige) const
		{ return get_geo_element (dim, dis_ige); }
    const geo_element& bgd2dom_geo_element (const geo_element& bgd_K) const { return base::data().bgd2dom_geo_element (bgd_K); }
    const geo_element& dom2bgd_geo_element (const geo_element& dom_K) const { return base::data().dom2bgd_geo_element (dom_K); }
    size_type neighbour (size_type ie, size_type loc_isid) const {
			  return base::data().neighbour (ie, loc_isid); }
    void neighbour_guard() const { base::data().neighbour_guard(); }
    size_type        n_node()   const { return base::data().n_node(); }
    const node_type&     node(size_type     inod) const { return base::data().node(inod); }
    const node_type& dis_node(size_type dis_inod) const { return base::data().dis_node(dis_inod); }
    void dis_inod (const geo_element& K, std::vector<size_type>& dis_inod) const {
    		return base::data().dis_inod(K,dis_inod); }
    node_type piola (const geo_element& K, const node_type& hat_x) const { return base::data().piola (K, hat_x); }
    const array<node_type,sequential>& get_nodes() const { return base::data().get_nodes(); }
    size_type dis_inod2dis_iv (size_type dis_inod) const { return base::data().dis_inod2dis_iv(dis_inod); }

    size_type n_domain_indirect () const { return base::data().n_domain_indirect (); }
    bool have_domain_indirect (const std::string& name) const { return base::data().have_domain_indirect (name); }
    const domain_indirect_basic<sequential>& get_domain_indirect (size_type i) const {
	  return base::data().get_domain_indirect (i); }
    const domain_indirect_basic<sequential>& get_domain_indirect (const std::string& name) const {
	  return base::data().get_domain_indirect (name); }
    void  insert_domain_indirect (const domain_indirect_basic<sequential>& dom) const {
	  base::data().insert_domain_indirect (dom); }

    size_type n_domain () const { return base::data().n_domain_indirect (); }
    geo_basic<T,sequential> get_domain (size_type i) const;
    geo_basic<T,sequential> operator[] (const std::string& name) const;
    geo_basic<T,sequential> boundary() const;
    geo_basic<T,sequential> internal_sides() const;
    geo_basic<T,sequential> sides() const;

    size_type seq_locate (
		const point_basic<T>& x,
		size_type dis_ie_guest = std::numeric_limits<size_type>::max()) const
		{ return base::data().seq_locate (x, dis_ie_guest); }
    size_type dis_locate (
		const point_basic<T>& x,
		size_type dis_ie_guest = std::numeric_limits<size_type>::max()) const
		{ return base::data().dis_locate (x, dis_ie_guest); }
    void locate (	
		const array<point_basic<T>, sequential>& x,
		array<size_type, sequential>& dis_ie) const
    		{ return base::data().locate (x, dis_ie); }
    size_type seq_trace_move (
                const point_basic<T>&     x,
                const point_basic<T>&     v,
                      point_basic<T>&     y) const
    					{ return base::data().seq_trace_move (x,v,y); }
    size_type dis_trace_move (
                const point_basic<T>&     x,
                const point_basic<T>&     v,
                      point_basic<T>&     y) const
    					{ return base::data().dis_trace_move (x,v,y); }
    void trace_ray_boundary (
                const array<point_basic<T>,sequential>&     x,
                const array<point_basic<T>,sequential>&     v,
                      array<size_type, sequential>&         dis_ie,
                      array<point_basic<T>,sequential>&     y) const
    					{ return base::data().trace_ray_boundary (x,v,dis_ie,y); }
    void trace_move (
                const array<point_basic<T>,sequential>&     x,
                const array<point_basic<T>,sequential>&     v,
                      array<size_type, sequential>&         dis_ie,
                      array<point_basic<T>,sequential>&     y) const
    					{ return base::data().trace_move (x,v,dis_ie,y); }
    size_type seq_nearest (
                const point_basic<T>&    x,
                      point_basic<T>&    x_nearest) const
    					{ return base::data().seq_nearest (x, x_nearest); }
    size_type dis_nearest (
                const point_basic<T>&    x,
                      point_basic<T>&    x_nearest) const
    					{ return base::data().dis_nearest (x, x_nearest); }
    void nearest (
                const array<point_basic<T>,sequential>&     x,
                      array<point_basic<T>,sequential>&     x_nearest,
                      array<size_type, sequential>&         dis_ie) const
    					{ base::data().nearest (x, x_nearest, dis_ie); }

// modifiers:

    void set_name (std::string name);
    void set_dimension (size_type dim);
    void set_serial_number (size_type i);
    void reset_order (size_type order);
    void set_coordinate_system (coordinate_type sys_coord);
    void set_coordinate_system (std::string sys_coord_name) { set_coordinate_system (space_constant::coordinate_system(sys_coord_name)); }
    void set_nodes (const array<node_type,sequential>& x);
    void build_from_data (
        const geo_header&                                               hdr,
        const array<node_type, sequential>&                             node,
              boost::array<array<geo_element_auto<heap_allocator<size_type> >,sequential, heap_allocator<size_type> >, reference_element::max_variant>&
									tmp_geo_element,
        bool do_upgrade);

// extended accessors:

    const communicator& comm()        const { return geo_element_ownership (0).comm(); }
    size_type     size(size_type dim) const { return base::data().geo_element_ownership(dim).size(); }
    size_type dis_size(size_type dim) const { return base::data().geo_element_ownership(dim).dis_size(); }
    size_type     size()              const { return size     (map_dimension()); }
    size_type dis_size()              const { return dis_size (map_dimension()); }
    size_type     n_vertex()          const { return size     (0); }
    size_type dis_n_vertex()          const { return dis_size (0); }
    const_reference operator[] (size_type ie) const { return get_geo_element (map_dimension(), ie); }
	  reference operator[] (size_type ie)       { return get_geo_element (map_dimension(), ie); }
    const_iterator begin (size_type dim) const { return base::data().begin(dim); }
    const_iterator end   (size_type dim) const { return base::data().end  (dim); }
    const_iterator begin ()              const { return begin(map_dimension()); }
    const_iterator end   ()              const { return end  (map_dimension()); }

    const_iterator_by_variant begin_by_variant (variant_type variant) const 
	{ return base::data().begin_by_variant (variant); }
    const_iterator_by_variant   end_by_variant (variant_type variant) const
	{ return base::data().  end_by_variant (variant); }

    const geo_basic<T,sequential>& get_background_geo() const; // code in geo_domain.h
          geo_basic<T,sequential>  get_background_domain() const;

// for compatibility with distributed interface:

    size_type ige2ios_dis_ige (size_type dim, size_type ige) const { return ige; }
    size_type dis_ige2ios_dis_ige (size_type dim, size_type dis_ige) const { return dis_ige; }
    size_type ios_ige2dis_ige (size_type dim, size_type ios_ige) const { return ios_ige; }

// comparator:

    bool operator== (const geo_basic<T,sequential>& omega2) const { return base::data().operator== (omega2.data()); }

// i/o:

    idiststream& get (idiststream& ips);
    odiststream& put (odiststream& ops) const;
    void save (std::string filename = "") const;
    void dump (std::string name) const {        base::data().dump (name); }
    bool check (bool verbose = true) const { return base::data().check(verbose); }
};
//>verbatim:
template <class T>
inline
geo_basic<T,sequential>::geo_basic()
  : base (new_macro((geo_rep<T,sequential>)))
{
}
template <class T>
inline
geo_basic<T,sequential>::geo_basic (std::string name, const communicator& comm)
  : base (0)
{
    base::operator= (geo_load<T,sequential>(name));
}
template <class T>
inline
void
geo_basic<T,sequential>::load (std::string name, const communicator& comm)
{
    base::operator= (geo_load<T,sequential>(name));
}
template <class T>
inline
geo_basic<T,sequential>
geo_basic<T,sequential>::boundary() const
{
   boundary_guard (*this);
   return operator[] ("boundary");
}
template <class T>
inline
geo_basic<T,sequential>
geo_basic<T,sequential>::internal_sides() const
{
   internal_sides_guard (*this);
   return operator[] ("internal_sides");
}
template <class T>
inline
geo_basic<T,sequential>
geo_basic<T,sequential>::sides() const
{
   sides_guard (*this);
   return operator[] ("sides");
}
#ifdef _RHEOLEF_HAVE_MPI
// =========================================================================
/// @brief distributed mesh with rerefence counting
// =========================================================================
//<verbatim:
template <class T>
class geo_basic<T,distributed> : public smart_pointer_clone<geo_abstract_rep<T,distributed> > {
public:

// typedefs:

    typedef distributed                             memory_type;
    typedef geo_abstract_rep<T,distributed>         rep;
    typedef geo_rep<T,distributed>                  rep_geo_rep;
    typedef smart_pointer_clone<rep>                base;
    typedef typename rep::size_type                 size_type;
    typedef typename rep::node_type                 node_type;
    typedef typename rep::variant_type              variant_type;
    typedef typename rep::node_map_type             node_map_type;
    typedef typename rep::reference                 reference;
    typedef typename rep::const_reference           const_reference;
    typedef typename rep::iterator                  iterator;
    typedef typename rep::const_iterator            const_iterator;
    typedef typename rep::iterator_by_variant       iterator_by_variant;
    typedef typename rep::const_iterator_by_variant const_iterator_by_variant;
    typedef typename rep::coordinate_type           coordinate_type;

// allocators:

    geo_basic ();
    geo_basic (std::string name, const communicator& comm = communicator());
    void load (std::string name, const communicator& comm = communicator());
    geo_basic (const domain_indirect_basic<distributed>& dom, const geo_basic<T,distributed>& omega);

    // build from_list (for level set)
    geo_basic (
      const geo_basic<T,distributed>&                     lambda,
      const array<point_basic<T>,distributed>&                   node_list,
      const boost::array<array<geo_element_auto<heap_allocator<size_type> >,distributed>,
                         reference_element::max_variant>& elt_list)
    : base (new_macro(rep_geo_rep(lambda,node_list,elt_list))) {}

// accessors:

    std::string                    name() const { return base::data().name(); }
    std::string              familyname() const { return base::data().familyname(); }
    size_type                 dimension() const { return base::data().dimension(); }
    size_type             map_dimension() const { return base::data().map_dimension(); }
    size_type             serial_number() const { return base::data().serial_number(); }
    size_type                   variant() const { return base::data().variant(); }
    coordinate_type   coordinate_system() const { return base::data().coordinate_system(); }
    std::string  coordinate_system_name() const { return space_constant::coordinate_system_name(coordinate_system()); }
    const basis_basic<T>& get_piola_basis() const { return base::data().get_piola_basis(); }
    size_type                     order() const { return base::data().get_piola_basis().degree(); }
    const node_type&               xmin() const { return base::data().xmin(); }
    const node_type&               xmax() const { return base::data().xmax(); }
    const T&           		   hmin() const { return base::data().hmin(); }
    const T&	                   hmax() const { return base::data().hmax(); }
    const distributor& geo_element_ownership(size_type dim) const
			{ return base::data().geo_element_ownership (dim); }
    const geo_size&      sizes()             const { return base::data().sizes(); }
    const geo_size&  ios_sizes()             const { return base::data().ios_sizes(); }
    const_reference get_geo_element (size_type dim, size_type ige) const
		{ return base::data().get_geo_element (dim, ige); }
    const_reference dis_get_geo_element (size_type dim, size_type dis_ige) const
		{ return base::data().dis_get_geo_element (dim, dis_ige); }
    const geo_element& bgd2dom_geo_element (const geo_element& bgd_K) const
		{ return base::data().bgd2dom_geo_element (bgd_K); }
    const geo_element& dom2bgd_geo_element (const geo_element& dom_K) const
		{ return base::data().dom2bgd_geo_element (dom_K); }
    size_type neighbour (size_type ie, size_type loc_isid) const {
			  return base::data().neighbour (ie, loc_isid); }
    void neighbour_guard() const { base::data().neighbour_guard(); }
    distributor geo_element_ios_ownership (size_type dim) const {
	return base::data().geo_element_ios_ownership (dim); }
    size_type ige2ios_dis_ige (size_type dim, size_type ige) const {
	return base::data().ige2ios_dis_ige (dim,ige); }
    size_type dis_ige2ios_dis_ige (size_type dim, size_type dis_ige) const {
	return base::data().dis_ige2ios_dis_ige (dim,dis_ige); }
    size_type ios_ige2dis_ige (size_type dim, size_type ios_ige) const {
    	return base::data().ios_ige2dis_ige (dim, ios_ige); }
    size_type        n_node() const { return base::data().n_node(); }
    const node_type&     node(size_type     inod) const { return base::data().node(inod); }
    const node_type& dis_node(size_type dis_inod) const { return base::data().dis_node(dis_inod); }
    void dis_inod (const geo_element& K, std::vector<size_type>& dis_inod) const {
    		return base::data().dis_inod(K,dis_inod); }
    node_type piola (const geo_element& K, const node_type& hat_x) const { return base::data().piola (K, hat_x); }
    const array<node_type,distributed>& get_nodes() const { return base::data().get_nodes(); }
    void set_nodes (const array<node_type,distributed>& x);
    void reset_order (size_type order);
    size_type dis_inod2dis_iv (size_type dis_inod) const { return base::data().dis_inod2dis_iv(dis_inod); }
    void set_coordinate_system (coordinate_type sys_coord);
    void set_coordinate_system (std::string sys_coord_name) { set_coordinate_system (space_constant::coordinate_system(sys_coord_name)); }
    void set_dimension (size_type dim);
    void set_serial_number (size_type i);
    void set_name (std::string name);

    size_type n_domain_indirect () const { return base::data().n_domain_indirect (); }
    bool have_domain_indirect (const std::string& name) const { return base::data().have_domain_indirect (name); }
    const domain_indirect_basic<distributed>& get_domain_indirect (size_type i) const {
	  return base::data().get_domain_indirect (i); }
    const domain_indirect_basic<distributed>& get_domain_indirect (const std::string& name) const {
	  return base::data().get_domain_indirect (name); }
    void  insert_domain_indirect (const domain_indirect_basic<distributed>& dom) const {
	  base::data().insert_domain_indirect (dom); }

    size_type n_domain () const { return base::data().n_domain_indirect (); }
    geo_basic<T,distributed> get_domain (size_type i) const;
    geo_basic<T,distributed> operator[] (const std::string& name) const;
    geo_basic<T,distributed> boundary() const;
    geo_basic<T,distributed> internal_sides() const;
    geo_basic<T,distributed> sides() const;

    size_type seq_locate (
		const point_basic<T>& x,
		size_type dis_ie_guest = std::numeric_limits<size_type>::max()) const
		{ return base::data().seq_locate (x, dis_ie_guest); }
    size_type dis_locate (
		const point_basic<T>& x,
		size_type dis_ie_guest = std::numeric_limits<size_type>::max()) const
		{ return base::data().dis_locate (x, dis_ie_guest); }
    void locate (const array<point_basic<T>, distributed>& x, array<size_type, distributed>& dis_ie) const
    		{ return base::data().locate (x, dis_ie); }
    size_type seq_trace_move (
                const point_basic<T>&     x,
                const point_basic<T>&     v,
                      point_basic<T>&     y) const
    					{ return base::data().seq_trace_move (x,v,y); }
    size_type dis_trace_move (
                const point_basic<T>&     x,
                const point_basic<T>&     v,
                      point_basic<T>&     y) const
    					{ return base::data().dis_trace_move (x,v,y); }
    void trace_ray_boundary (
                const array<point_basic<T>,distributed>&     x,
                const array<point_basic<T>,distributed>&     v,
                      array<size_type, distributed>&         dis_ie,
                      array<point_basic<T>,distributed>&     y) const
    					{ return base::data().trace_ray_boundary (x,v,dis_ie,y); }
    void trace_move (
                const array<point_basic<T>,distributed>&     x,
                const array<point_basic<T>,distributed>&     v,
                      array<size_type, distributed>&         dis_ie,
                      array<point_basic<T>,distributed>&     y) const
    					{ return base::data().trace_move (x,v,dis_ie,y); }
    size_type seq_nearest (
                const point_basic<T>&    x,
                      point_basic<T>&    x_nearest) const
    					{ return base::data().seq_nearest (x, x_nearest); }
    size_type dis_nearest (
                const point_basic<T>&    x,
                      point_basic<T>&    x_nearest) const
    					{ return base::data().dis_nearest (x, x_nearest); }
    void nearest (
                const array<point_basic<T>,distributed>&     x,
                      array<point_basic<T>,distributed>&     x_nearest,
                      array<size_type, distributed>&         dis_ie) const
    					{ base::data().nearest (x, x_nearest, dis_ie); }

// extended accessors:

    size_type     size(size_type dim) const { return base::data().geo_element_ownership(dim).size(); }
    size_type dis_size(size_type dim) const { return base::data().geo_element_ownership(dim).dis_size(); }
    const communicator& comm()        const { return geo_element_ownership (0).comm(); }
    size_type     size()              const { return size     (map_dimension()); }
    size_type dis_size()              const { return dis_size (map_dimension()); }
    size_type     n_vertex()          const { return size     (0); }
    const_reference operator[] (size_type ie) const	
		{ return get_geo_element (map_dimension(), ie); }

    const_iterator begin (size_type dim) const { return base::data().begin(dim); }
    const_iterator end   (size_type dim) const { return base::data().end  (dim); }
    const_iterator begin ()              const { return begin(map_dimension()); }
    const_iterator end   ()              const { return end  (map_dimension()); }

    const_iterator_by_variant begin_by_variant (variant_type variant) const 
	{ return base::data().begin_by_variant (variant); }
    const_iterator_by_variant   end_by_variant (variant_type variant) const
	{ return base::data().  end_by_variant (variant); }

    const geo_basic<T,distributed>& get_background_geo() const; // code in geo_domain.h
          geo_basic<T,distributed>  get_background_domain() const;

// comparator:

    bool operator== (const geo_basic<T,distributed>& omega2) const { return base::data().operator== (omega2.data()); }

// i/o:

    odiststream& put (odiststream& ops) const { return base::data().put (ops); }
    idiststream& get (idiststream& ips);
    void save (std::string filename = "") const;
    bool check (bool verbose = true) const { return base::data().check(verbose); }

// utilities:

    void set_ios_permutation (
    	boost::array<size_type,reference_element::max_variant>& loc_ndof_by_variant,
    	array<size_type,distributed>&                           idof2ios_dis_idof) const
     { base::data().set_ios_permutation (loc_ndof_by_variant, idof2ios_dis_idof); }
};
//>verbatim:
#endif // _RHEOLEF_HAVE_MPI

/// @brief geo - the default mesh class
typedef geo_basic<Float,rheo_default_memory_model> geo;

// ==============================================================================
// inlined: geo<T,distributed>
// ==============================================================================
#ifdef _RHEOLEF_HAVE_MPI
template <class T>
inline
geo_basic<T,distributed>::geo_basic()
  : base (new_macro((geo_rep<T,distributed>)))
{
}
template <class T>
inline
geo_basic<T,distributed>::geo_basic (std::string name, const communicator& comm)
  : base (0)
{
    base::operator= (geo_load<T,distributed>(name));
}
template <class T>
inline
void
geo_basic<T,distributed>::load (std::string name, const communicator& comm)
{
    base::operator= (geo_load<T,distributed>(name));
}
template <class T>
inline
idiststream&
geo_basic<T,distributed>::get (idiststream& ips)
{
    // allocate a new geo_rep object (TODO: do a dynamic_cast ?)
    geo_rep<T,distributed>* ptr = new_macro((geo_rep<T,distributed>));
    ptr->get (ips);
    base::operator= (ptr);
    return ips;
}
template <class T>
inline
geo_basic<T,distributed>
geo_basic<T,distributed>::boundary() const
{
   boundary_guard (*this);
   return operator[] ("boundary");
}
template <class T>
inline
geo_basic<T,distributed>
geo_basic<T,distributed>::internal_sides() const
{
   internal_sides_guard (*this);
   return operator[] ("internal_sides");
}
template <class T>
inline
geo_basic<T,distributed>
geo_basic<T,distributed>::sides() const
{
   sides_guard (*this);
   return operator[] ("sides");
}
#endif // _RHEOLEF_HAVE_MPI

// ==============================================================================
// geo fat interface: members are specific to geo_rep
// => check that pointer to geo_abstract_rep points to a geo_rep
// ==============================================================================

#define _RHEOLEF_save(M)	                                              	\
template <class T>								\
void										\
geo_basic<T,M>::save (std::string filename) const				\
{										\
  if (filename == "") filename = name();					\
  odiststream out (filename, "geo");						\
  put (out);									\
}
#define _RHEOLEF_set_nodes(M)                                              	\
template <class T>								\
void										\
geo_basic<T,M>::set_nodes (const array<node_type,M>& x)				\
{										\
  geo_rep<T,M>* ptr = dynamic_cast<geo_rep<T,M>*>(base::pointer());		\
  check_macro (ptr != 0, "cannot set_name on geo_domains");			\
  ptr->set_nodes(x);								\
}
#define _RHEOLEF_reset_order(M)                                              	\
template <class T>								\
void										\
geo_basic<T,M>::reset_order (size_type order)					\
{										\
  geo_rep<T,M>* ptr = dynamic_cast<geo_rep<T,M>*>(base::pointer());		\
  check_macro (ptr != 0, "cannot set_name on geo_domains");			\
  ptr->reset_order(order);							\
}
#define _RHEOLEF_set_coordinate_system(M)                                    	\
template <class T>								\
void										\
geo_basic<T,M>::set_coordinate_system (coordinate_type sys_coord)		\
{										\
  geo_rep<T,M>* ptr = dynamic_cast<geo_rep<T,M>*>(base::pointer());		\
  check_macro (ptr != 0, "cannot set_name on geo_domains");			\
  ptr->set_coordinate_system(sys_coord);					\
}
#define _RHEOLEF_set_dimension(M)	                                    	\
template <class T>								\
void										\
geo_basic<T,M>::set_dimension (size_type dim)					\
{										\
  geo_rep<T,M>* ptr = dynamic_cast<geo_rep<T,M>*>(base::pointer());		\
  check_macro (ptr != 0, "cannot set_name on geo_domains");			\
  ptr->set_dimension(dim);							\
}
#define _RHEOLEF_set_serial_number(M)	                                    	\
template <class T>								\
void										\
geo_basic<T,M>::set_serial_number (size_type i)					\
{										\
  geo_rep<T,M>* ptr = dynamic_cast<geo_rep<T,M>*>(base::pointer());		\
  check_macro (ptr != 0, "cannot set_name on geo_domains");			\
  ptr->set_serial_number(i);							\
}
#define _RHEOLEF_set_name(M)		                                    	\
template <class T>								\
void										\
geo_basic<T,M>::set_name (std::string name)					\
{										\
  geo_rep<T,M>* ptr = dynamic_cast<geo_rep<T,M>*>(base::pointer());		\
  check_macro (ptr != 0, "cannot set_name on geo_domains");			\
  ptr->set_name(name);								\
}
#define _RHEOLEF_build_from_data(M)		                                \
template <class T>								\
void										\
geo_basic<T,M>::build_from_data (						\
  const geo_header&                     hdr,					\
  const array<node_type, sequential>&   node,					\
        boost::array<array<geo_element_auto<heap_allocator<size_type> >,sequential, heap_allocator<size_type> >, reference_element::max_variant>& tmp_geo_element, \
  bool do_upgrade)								\
{										\
  geo_rep<T,M>* ptr = dynamic_cast<geo_rep<T,M>*>(base::pointer());		\
  check_macro (ptr != 0, "cannot set_name on geo_domains");			\
  ptr->build_from_data (hdr, node, tmp_geo_element, do_upgrade);		\
}

_RHEOLEF_save(sequential)
_RHEOLEF_set_nodes(sequential)
_RHEOLEF_reset_order(sequential)
_RHEOLEF_set_coordinate_system(sequential)
_RHEOLEF_set_dimension(sequential)
_RHEOLEF_set_serial_number(sequential)
_RHEOLEF_set_name(sequential)
_RHEOLEF_build_from_data(sequential)
#ifdef _RHEOLEF_HAVE_MPI
_RHEOLEF_save(distributed)
_RHEOLEF_set_nodes(distributed)
_RHEOLEF_reset_order(distributed)
_RHEOLEF_set_coordinate_system(distributed)
_RHEOLEF_set_dimension(distributed)
_RHEOLEF_set_serial_number(distributed)
_RHEOLEF_set_name(distributed)
#endif // _RHEOLEF_HAVE_MPI
#undef _RHEOLEF_set_nodes
#undef _RHEOLEF_reset_order
#undef _RHEOLEF_set_coordinate_system
#undef _RHEOLEF_set_dimension
#undef _RHEOLEF_set_name
#undef _RHEOLEF_build_from_data
// ==============================================================================
// inlined: geo<T,M>
// ==============================================================================
template <class T, class M>
inline 
idiststream&
operator>> (idiststream& ips, geo_basic<T,M>& omega)
{
    return omega.get (ips);
}
template <class T, class M>
inline 
odiststream&
operator<< (odiststream& ops, const geo_basic<T,M>& omega)
{
    return omega.put (ops);
}

} // namespace rheolef
#endif // _RHEOLEF_GEO_H