39     typedef vector<Class_Octant<3> >        OctantsType;
 
   40     typedef vector<Class_Intersection<3> >  IntersectionsType;
 
   41     typedef vector<uint32_t>                u32vector;
 
   42     typedef vector<uint64_t>                u64vector;
 
   43     typedef vector<vector<uint32_t> >       u32vector2D;
 
   44     typedef vector<vector<uint64_t> >       u64vector2D;
 
   53     IntersectionsType           intersections;      
 
   54     u64vector                   globalidx_ghosts;   
 
   58     uint8_t                     local_max_depth;    
 
   59     uint8_t                     balance_codim;      
 
   62     u32vector                   last_ghost_bros;    
 
   66     u32vector2D                 connectivity;       
 
   68     u32vector2D                 ghostsnodes;        
 
   69     u32vector2D                 ghostsconnectivity; 
 
  103     uint32_t getSizeGhost()
 const{
 
  106     uint32_t getNumOctants()
 const{
 
  107         return octants.size();
 
  109     uint8_t getLocalMaxDepth()
 const{                           
 
  110         return local_max_depth;
 
  112     int8_t getMarker(int32_t idx){                              
 
  115     uint8_t getLevel(int32_t idx){                              
 
  116         return octants[idx].getLevel();
 
  118     uint8_t getGhostLevel(int32_t idx){                             
 
  119         return ghosts[idx].getLevel();
 
  121     bool getBalance(int32_t idx){                               
 
  122         return octants[idx].getNotBalance();
 
  128     uint8_t getBalanceCodim()
 const{
 
  129         return balance_codim;
 
  132     void setMarker(int32_t idx, int8_t marker){                 
 
  133         octants[idx].setMarker(marker);
 
  135     void setBalance(int32_t idx, 
bool balance){                 
 
  136         octants[idx].setBalance(balance);
 
  142     void setBalanceCodim(uint8_t b21codim){
 
  143         balance_codim = b21codim;
 
  147         OctantsType::const_iterator firstOctant = octants.begin();
 
  148         first_desc = 
Class_Octant<3>(MAX_LEVEL_3D,firstOctant->x,firstOctant->y,firstOctant->z);
 
  151         OctantsType::const_iterator lastOctant = octants.end() - 1;
 
  152         uint32_t x,y,z,delta;
 
  153         delta = (uint32_t)pow(2.0,(
double)((uint8_t)MAX_LEVEL_3D - lastOctant->level)) - 1;
 
  154         x = lastOctant->x + delta;
 
  155         y = lastOctant->y + delta;
 
  156         z = lastOctant->z + delta;
 
  185         vector<uint32_t> last_child_index;
 
  186         vector< Class_Octant<3> > children;
 
  187         uint32_t idx, nocts, ilastch;
 
  188         uint32_t offset = 0, blockidx;
 
  189         uint8_t nchm1 = global3D.
nchildren-1, ich;
 
  190         bool dorefine = 
false;
 
  192         nocts = octants.size();
 
  193         for (idx=0; idx<nocts; idx++){
 
  194             if(octants[idx].getMarker() > 0 && octants[idx].getLevel() < MAX_LEVEL_3D){
 
  195                 last_child_index.push_back(idx+nchm1+offset);
 
  200                 if (octants[idx].marker > 0)
 
  201                     octants[idx].marker = 0;
 
  202                 octants[idx].info[15] = 
true;
 
  206             octants.resize(octants.size()+offset);
 
  207             blockidx = last_child_index[0]-nchm1;
 
  208             idx = octants.size();
 
  209             ilastch = last_child_index.size()-1;
 
  210             while (idx>blockidx){
 
  212                 if(idx == last_child_index[ilastch]){
 
  214                     children = octants[idx-offset].buildChildren();
 
  215                     for (ich=0; ich<global3D.
nchildren; ich++){
 
  216                         octants[idx-ich] = (children[nchm1-ich]);
 
  221                     if (children[0].getLevel() > local_max_depth){
 
  222                         local_max_depth = children[0].getLevel();
 
  224                     if (children[0].getMarker() > 0){
 
  234                     octants[idx] = octants[idx-offset];
 
  238 #if defined(__INTEL_COMPILER) || defined(__ICC) 
  240         octants.shrink_to_fit();
 
  242         nocts = octants.size();
 
  255         vector<uint32_t> first_child_index;
 
  262         int8_t markerfather, marker;
 
  265         bool docoarse = 
false;
 
  276         nocts   = octants.size();
 
  277         size_ghosts = ghosts.size();
 
  279         first_child_index.clear();
 
  289             while(idx2_gh < size_ghosts && ghosts[idx2_gh].computeMorton() <= last_desc.
computeMorton()){
 
  292             idx2_gh = min((size_ghosts-1), idx2_gh);
 
  296         for (idx=0; idx<nocts; idx++){
 
  297             if(octants[idx].getMarker() < 0 && octants[idx].getLevel() > 0){
 
  299                 father = octants[idx].buildFather();
 
  301                 for (idx2=idx; idx2<idx+global3D.
nchildren; idx2++){
 
  303                         if(octants[idx2].getMarker() < 0 && octants[idx2].buildFather() == father){
 
  310                     first_child_index.push_back(idx);
 
  324         uint32_t nblock = nocts;
 
  325         uint32_t nfchild = first_child_index.size();
 
  327             nblock = nocts - nidx*nchm1;
 
  329             for (idx=0; idx<nblock; idx++){
 
  331                     if (idx+offset == first_child_index[nidx]){
 
  332                         markerfather = -MAX_LEVEL_3D;
 
  333                         father = octants[idx+offset].buildFather();
 
  334                         for(idx2=0; idx2<global3D.
nchildren; idx2++){
 
  335                             if (markerfather < octants[idx+offset+idx2].getMarker()+1){
 
  336                                 markerfather = octants[idx+offset+idx2].
getMarker()+1;
 
  338                             for (
int iii=0; iii<16; iii++){
 
  339                                 father.info[iii] = father.info[iii] || octants[idx+offset+idx2].info[iii];
 
  342                         father.info[13] = 
true;
 
  343                         father.info[15] = 
true;
 
  344                         if (markerfather < 0){
 
  348                         octants[idx] = father;
 
  353                         octants[idx] = octants[idx+offset];
 
  357                     octants[idx] = octants[idx+offset];
 
  362         octants.resize(nblock);
 
  363 #if defined(__INTEL_COMPILER) || defined(__ICC) 
  365         octants.shrink_to_fit();
 
  367         nocts = octants.size();
 
  370         if (ghosts.size() && nocts > 0){
 
  372             if (ghosts[idx2_gh].buildFather() == octants[nocts-1].buildFather()){
 
  373                 father = ghosts[idx2_gh].buildFather();
 
  374                 for (uint32_t iii=0; iii<16; iii++){
 
  375                     father.info[iii] = 
false;
 
  377                 markerfather = ghosts[idx2_gh].getMarker()+1;
 
  380                 marker = ghosts[idx].getMarker();
 
  381                 while(marker < 0 && ghosts[idx].buildFather() == father){
 
  383                     if (markerfather < ghosts[idx].getMarker()+1){
 
  384                         markerfather = ghosts[idx].getMarker()+1;
 
  386                     for (uint32_t iii=0; iii<global3D.
nfaces; iii++){
 
  387                         father.info[iii] = father.info[iii] || ghosts[idx].info[iii];
 
  389                     father.info[14] = father.info[14] || ghosts[idx].info[14];
 
  391                     if(idx == size_ghosts){
 
  394                     marker = ghosts[idx].getMarker();
 
  401                 marker = octants[idx].getMarker();
 
  402                 while(marker < 0 && octants[idx].buildFather() == father && idx >= 0){
 
  405                     if (markerfather < octants[idx].getMarker()+1){
 
  406                         markerfather = octants[idx].getMarker()+1;
 
  409                     marker = octants[idx].getMarker();
 
  429                 for (idx=0; idx < nend; idx++){
 
  434                 father.info[13] = 
true;
 
  435                 father.info[15] = 
true;
 
  436                 if (markerfather < 0){
 
  440                 octants.resize(nocts-offset);
 
  441                 octants.push_back(father);
 
  442 #if defined(__INTEL_COMPILER) || defined(__ICC) 
  444                 octants.shrink_to_fit();
 
  446                 nocts = octants.size();
 
  462     bool refine(u32vector & mapidx){                            
 
  465         vector<uint32_t> last_child_index;
 
  466         vector< Class_Octant<3> > children;
 
  467         uint32_t idx, nocts, ilastch;
 
  468         uint32_t offset = 0, blockidx;
 
  469         uint8_t nchm1 = global3D.
nchildren-1, ich;
 
  470         bool dorefine = 
false;
 
  472         nocts = octants.size();
 
  473         for (idx=0; idx<nocts; idx++){
 
  474             if(octants[idx].getMarker() > 0 && octants[idx].getLevel() < MAX_LEVEL_3D){
 
  475                 last_child_index.push_back(idx+nchm1+offset);
 
  480                 if (octants[idx].marker > 0){
 
  481                     octants[idx].marker = 0;
 
  482                     octants[idx].info[15] = 
false;
 
  487             mapidx.resize(octants.size()+offset);
 
  488 #if defined(__INTEL_COMPILER) || defined(__ICC) 
  490             mapidx.shrink_to_fit();
 
  492             octants.resize(octants.size()+offset);
 
  493             blockidx = last_child_index[0]-nchm1;
 
  494             idx = octants.size();
 
  495             ilastch = last_child_index.size()-1;
 
  496             while (idx>blockidx){
 
  500                 if(idx == last_child_index[ilastch]){
 
  501                     children = octants[idx-offset].buildChildren();
 
  502                     for (ich=0; ich<global3D.
nchildren; ich++){
 
  503                         octants[idx-ich] = (children[nchm1-ich]);
 
  504                         mapidx[idx-ich]  = mapidx[idx-offset];
 
  509                     if (children[0].getLevel() > local_max_depth){
 
  510                         local_max_depth = children[0].getLevel();
 
  512                     if (children[0].getMarker() > 0){
 
  522                     octants[idx] = octants[idx-offset];
 
  523                     mapidx[idx]  = mapidx[idx-offset];
 
  527 #if defined(__INTEL_COMPILER) || defined(__ICC) 
  529         octants.shrink_to_fit();
 
  531         nocts = octants.size();
 
  542     bool coarse(u32vector & mapidx){                            
 
  546         vector<uint32_t> first_child_index;
 
  548         uint32_t nocts, nocts0;
 
  553         int8_t markerfather, marker;
 
  556         bool docoarse = 
false;
 
  567         nocts = nocts0 = octants.size();
 
  568         size_ghosts = ghosts.size();
 
  579             while(idx2_gh < size_ghosts && ghosts[idx2_gh].computeMorton() < last_desc.
computeMorton()){
 
  582             idx2_gh = min((size_ghosts-1), idx2_gh);
 
  586         for (idx=0; idx<nocts; idx++){
 
  587             if(octants[idx].getMarker() < 0 && octants[idx].getLevel() > 0){
 
  589                 father = octants[idx].buildFather();
 
  591                 for (idx2=idx; idx2<idx+global3D.
nchildren; idx2++){
 
  593                         if(octants[idx2].getMarker() < 0 && octants[idx2].buildFather() == father){
 
  600                     first_child_index.push_back(idx);
 
  614         uint32_t nblock = nocts;
 
  615         uint32_t nfchild = first_child_index.size();
 
  617             nblock = nocts - nidx*nchm1;
 
  620             for (idx=0; idx<nblock; idx++){
 
  622                     if (idx+offset == first_child_index[nidx]){
 
  623                         markerfather = -MAX_LEVEL_3D;
 
  624                         father = octants[idx+offset].buildFather();
 
  625                         for (uint32_t iii=0; iii<16; iii++){
 
  626                             father.info[iii] = 
false;
 
  628                         for(idx2=0; idx2<global3D.
nchildren; idx2++){
 
  629                             if (markerfather < octants[idx+offset+idx2].getMarker()+1){
 
  630                                 markerfather = octants[idx+offset+idx2].getMarker()+1;
 
  632                             for (uint32_t iii=0; iii<16; iii++){
 
  633                                 father.info[iii] = father.info[iii] || octants[idx+offset+idx2].info[iii];
 
  636                         father.info[13] = 
true;
 
  637                         father.info[15] = 
true;
 
  639                         if (markerfather < 0){
 
  642                         octants[idx] = father;
 
  643                         mapidx[idx] = mapidx[idx+offset];
 
  648                         octants[idx] = octants[idx+offset];
 
  649                         mapidx[idx] = mapidx[idx+offset];
 
  653                     octants[idx] = octants[idx+offset];
 
  654                     mapidx[idx] = mapidx[idx+offset];
 
  658         octants.resize(nblock);
 
  659 #if defined(__INTEL_COMPILER) || defined(__ICC) 
  661         octants.shrink_to_fit();
 
  663         nocts = octants.size();
 
  664         mapidx.resize(nocts);
 
  665 #if defined(__INTEL_COMPILER) || defined(__ICC) 
  667         mapidx.shrink_to_fit();
 
  670         if (ghosts.size() && nocts > 0){
 
  672             if (ghosts[idx2_gh].buildFather() == octants[nocts-1].buildFather()){
 
  673                 father = ghosts[idx2_gh].buildFather();
 
  674                 for (uint32_t iii=0; iii<16; iii++){
 
  675                     father.info[iii] = 
false;
 
  677                 markerfather = ghosts[idx2_gh].getMarker()+1;
 
  680                 marker = ghosts[idx].getMarker();
 
  681                 while(marker < 0 && ghosts[idx].buildFather() == father){
 
  683                     if (markerfather < ghosts[idx].getMarker()+1){
 
  684                         markerfather = ghosts[idx].getMarker()+1;
 
  686                     for (uint32_t iii=0; iii<global3D.
nfaces; iii++){
 
  687                         father.info[iii] = father.info[iii] || ghosts[idx].info[iii];
 
  689                     father.info[14] = father.info[14] || ghosts[idx].info[14];
 
  691                     if(idx == size_ghosts){
 
  694                     marker = ghosts[idx].getMarker();
 
  701                 marker = octants[idx].getMarker();
 
  702                 while(marker < 0 && octants[idx].buildFather() == father && idx >= 0){
 
  705                     if (markerfather < octants[idx].getMarker()+1){
 
  706                         markerfather = octants[idx].getMarker()+1;
 
  709                     marker = octants[idx].getMarker();
 
  729                 for (idx=0; idx < nend; idx++){
 
  730                     for (uint32_t iii=0; iii<16; iii++){
 
  731                         father.info[iii] = father.info[iii] || octants[nocts-idx-1].info[iii];
 
  734                 father.info[13] = 
true;
 
  735                 father.info[15] = 
true;
 
  736                 if (markerfather < 0){
 
  740                 octants.resize(nocts-offset);
 
  741                 octants.push_back(father);
 
  742 #if defined(__INTEL_COMPILER) || defined(__ICC) 
  744                 octants.shrink_to_fit();
 
  746                 nocts = octants.size();
 
  747                 mapidx.resize(nocts);
 
  748 #if defined(__INTEL_COMPILER) || defined(__ICC) 
  750                 mapidx.shrink_to_fit();
 
  771         vector<uint32_t> last_child_index;
 
  772         vector< Class_Octant<3> > children;
 
  773         uint32_t idx, nocts, ilastch;
 
  774         uint32_t offset = 0, blockidx;
 
  775         uint8_t nchm1 = global3D.
nchildren-1, ich;
 
  776         bool dorefine = 
false;
 
  778         nocts = octants.size();
 
  779         for (idx=0; idx<nocts; idx++){
 
  780             octants[idx].setMarker(1);
 
  781             if(octants[idx].getMarker() > 0 && octants[idx].getLevel() < MAX_LEVEL_3D){
 
  782                 last_child_index.push_back(idx+nchm1+offset);
 
  786                 if (octants[idx].marker > 0)
 
  787                     octants[idx].marker = 0;
 
  788                 octants[idx].info[15] = 
true;
 
  792             octants.resize(octants.size()+offset);
 
  793             blockidx = last_child_index[0]-nchm1;
 
  794             idx = octants.size();
 
  795             ilastch = last_child_index.size()-1;
 
  796             while (idx>blockidx){
 
  798                 if(idx == last_child_index[ilastch]){
 
  800                     children = octants[idx-offset].buildChildren();
 
  801                     for (ich=0; ich<global3D.
nchildren; ich++){
 
  802                         octants[idx-ich] = (children[nchm1-ich]);
 
  807                     if (children[0].getLevel() > local_max_depth){
 
  808                         local_max_depth = children[0].getLevel();
 
  810                     if (children[0].getMarker() > 0){
 
  819                     octants[idx] = octants[idx-offset];
 
  823 #if defined(__INTEL_COMPILER) || defined(__ICC) 
  825         octants.shrink_to_fit();
 
  827         nocts = octants.size();
 
  841         vector<uint32_t> first_child_index;
 
  848         int8_t markerfather, marker;
 
  851         bool docoarse = 
false;
 
  862         nocts   = octants.size();
 
  863         size_ghosts = ghosts.size();
 
  873             while(idx2_gh < size_ghosts && ghosts[idx2_gh].computeMorton() <= last_desc.
computeMorton()){
 
  876             idx2_gh = min((size_ghosts-1), idx2_gh);
 
  880         for (idx=0; idx<nocts; idx++){
 
  881             octants[idx].setMarker(-1);
 
  882             if(octants[idx].getMarker() < 0 && octants[idx].getLevel() > 0){
 
  884                 father = octants[idx].buildFather();
 
  886                 for (idx2=idx; idx2<idx+global3D.
nchildren; idx2++){
 
  889                         if(octants[idx2].getMarker() < 0 && octants[idx2].buildFather() == father){
 
  896                     first_child_index.push_back(idx);
 
  901                         octants[idx].setMarker(0);
 
  902                         octants[idx].info[15] = 
true;
 
  910         uint32_t nblock = nocts;
 
  911         uint32_t nfchild = first_child_index.size();
 
  913             nblock = nocts - nidx*nchm1;
 
  915             for (idx=0; idx<nblock; idx++){
 
  917                     if (idx+offset == first_child_index[nidx]){
 
  918                         markerfather = -MAX_LEVEL_3D;
 
  919                         father = octants[idx+offset].buildFather();
 
  920                         for(idx2=0; idx2<global3D.
nchildren; idx2++){
 
  921                             if (markerfather < octants[idx+offset+idx2].getMarker()+1){
 
  922                                 markerfather = octants[idx+offset+idx2].
getMarker()+1;
 
  924                             for (uint32_t iii=0; iii<16; iii++){
 
  925                                 father.info[iii] = father.info[iii] || octants[idx+offset+idx2].info[iii];
 
  928                         father.info[13] = 
true;
 
  929                         if (markerfather < 0){
 
  933                         octants[idx] = father;
 
  938                         octants[idx] = octants[idx+offset];
 
  942                     octants[idx] = octants[idx+offset];
 
  946         octants.resize(nblock);
 
  947 #if defined(__INTEL_COMPILER) || defined(__ICC) 
  949         octants.shrink_to_fit();
 
  951         nocts = octants.size();
 
  954         if (ghosts.size() && nocts > 0){
 
  956             if ((ghosts[idx2_gh].getMarker() < 0) && (octants[nocts-1].getMarker() < 0)){
 
  957                 father = ghosts[idx2_gh].buildFather();
 
  958                 for (uint32_t iii=0; iii<16; iii++){
 
  959                     father.info[iii] = 
false;
 
  961                 markerfather = ghosts[idx2_gh].getMarker()+1;
 
  964                 ghosts[idx].setMarker(-1);
 
  965                 marker = ghosts[idx].getMarker();
 
  966                 while(marker < 0 && ghosts[idx].buildFather() == father){
 
  968                     if (markerfather < ghosts[idx].getMarker()+1){
 
  969                         markerfather = ghosts[idx].getMarker()+1;
 
  972                     if(idx == size_ghosts){
 
  975                     ghosts[idx].setMarker(-1);
 
  976                     marker = ghosts[idx].getMarker();
 
  977                     for (uint32_t iii=0; iii<16; iii++){
 
  978                         father.info[iii] = father.info[iii] || ghosts[idx].info[iii];
 
  983                 octants[idx].setMarker(-1);
 
  984                 marker = octants[idx].getMarker();
 
  985                 while(marker < 0 && octants[idx].buildFather() == father && idx >= 0){
 
  988                     if (markerfather < octants[idx].getMarker()+1){
 
  989                         markerfather = octants[idx].getMarker()+1;
 
  992                     octants[idx].setMarker(-1);
 
  993                     marker = octants[idx].getMarker();
 
 1006                     for(uint32_t ii=nocts-global3D.
nchildren; ii<nocts; ii++){
 
 1007                         octants[ii].setMarker(0);
 
 1008                         octants[ii].info[15] = 
true;
 
 1013                 for (idx=0; idx < nend; idx++){
 
 1014                     for (
int iii=0; iii<16; iii++){
 
 1015                         father.info[iii] = father.info[iii] || octants[nocts-idx-1].info[iii];
 
 1018                 father.info[13] = 
true;
 
 1019                 if (markerfather < 0){
 
 1023                 octants.resize(nocts-offset);
 
 1024                 octants.push_back(father);
 
 1025 #if defined(__INTEL_COMPILER) || defined(__ICC) 
 1027                 octants.shrink_to_fit();
 
 1029                 nocts = octants.size();
 
 1046     bool globalRefine(u32vector & mapidx){
 
 1048         vector<uint32_t> last_child_index;
 
 1049         vector< Class_Octant<3> > children;
 
 1050         uint32_t idx, nocts, ilastch;
 
 1051         uint32_t offset = 0, blockidx;
 
 1052         uint8_t nchm1 = global3D.
nchildren-1, ich;
 
 1053         bool dorefine = 
false;
 
 1055         nocts = octants.size();
 
 1056         for (idx=0; idx<nocts; idx++){
 
 1057             octants[idx].setMarker(1);
 
 1058             if(octants[idx].getMarker() > 0 && octants[idx].getLevel() < MAX_LEVEL_3D){
 
 1059                 last_child_index.push_back(idx+nchm1+offset);
 
 1064                 if (octants[idx].marker > 0){
 
 1065                     octants[idx].marker = 0;
 
 1066                     octants[idx].info[15] = 
false;
 
 1071             mapidx.resize(octants.size()+offset);
 
 1072 #if defined(__INTEL_COMPILER) || defined(__ICC) 
 1074             mapidx.shrink_to_fit();
 
 1076             octants.resize(octants.size()+offset);
 
 1077             blockidx = last_child_index[0]-nchm1;
 
 1078             idx = octants.size();
 
 1079             ilastch = last_child_index.size()-1;
 
 1080             while (idx>blockidx){
 
 1084                 if(idx == last_child_index[ilastch]){
 
 1085                     children = octants[idx-offset].buildChildren();
 
 1086                     for (ich=0; ich<global3D.
nchildren; ich++){
 
 1087                         octants[idx-ich] = (children[nchm1-ich]);
 
 1088                         mapidx[idx-ich]  = mapidx[idx-offset];
 
 1093                     if (children[0].getLevel() > local_max_depth){
 
 1094                         local_max_depth = children[0].getLevel();
 
 1096                     if (children[0].getMarker() > 0){
 
 1106                     octants[idx] = octants[idx-offset];
 
 1107                     mapidx[idx]  = mapidx[idx-offset];
 
 1111 #if defined(__INTEL_COMPILER) || defined(__ICC) 
 1113         octants.shrink_to_fit();
 
 1115         nocts = octants.size();
 
 1126     bool globalCoarse(u32vector & mapidx){                          
 
 1130         vector<uint32_t> first_child_index;
 
 1132         uint32_t nocts, nocts0;
 
 1137         int8_t markerfather, marker;
 
 1138         uint8_t nbro, nstart, nend;
 
 1140         bool docoarse = 
false;
 
 1146         nbro = nstart = nend = 0;
 
 1151         nocts = nocts0 = octants.size();
 
 1152         size_ghosts = ghosts.size();
 
 1163             while(idx2_gh < size_ghosts && ghosts[idx2_gh].computeMorton() < last_desc.
computeMorton()){
 
 1166             idx2_gh = min((size_ghosts-1), idx2_gh);
 
 1170         for (idx=0; idx<nocts; idx++){
 
 1171             octants[idx].setMarker(-1);
 
 1172             if(octants[idx].getMarker() < 0 && octants[idx].getLevel() > 0){
 
 1174                 father = octants[idx].buildFather();
 
 1176                 for (idx2=idx; idx2<idx+global3D.
nchildren; idx2++){
 
 1179                         if(octants[idx2].getMarker() < 0 && octants[idx2].buildFather() == father){
 
 1186                     first_child_index.push_back(idx);
 
 1191                         octants[idx].setMarker(0);
 
 1192                         octants[idx].info[15] = 
true;
 
 1201             uint32_t nblock = nocts - nidx*nchm1 - nstart;
 
 1202             uint32_t nfchild = first_child_index.size();
 
 1205             for (idx=0; idx<nocts-offset; idx++){
 
 1206                 if (nidx < nfchild){
 
 1207                     if (idx+offset == first_child_index[nidx]){
 
 1208                         markerfather = -MAX_LEVEL_3D;
 
 1209                         father = octants[idx+offset].buildFather();
 
 1210                         for (uint32_t iii=0; iii<16; iii++){
 
 1211                             father.info[iii] = 
false;
 
 1213                         for(idx2=0; idx2<global3D.
nchildren; idx2++){
 
 1214                             if (markerfather < octants[idx+offset+idx2].getMarker()+1){
 
 1215                                 markerfather = octants[idx+offset+idx2].getMarker()+1;
 
 1217                             for (uint32_t iii=0; iii<16; iii++){
 
 1218                                 father.info[iii] = father.info[iii] || octants[idx+offset+idx2].info[iii];
 
 1221                         father.info[13] = 
true;
 
 1223                         if (markerfather < 0){
 
 1226                         octants[idx] = father;
 
 1227                         mapidx[idx] = mapidx[idx+offset];
 
 1232                         octants[idx] = octants[idx+offset];
 
 1233                         mapidx[idx] = mapidx[idx+offset];
 
 1237                     octants[idx] = octants[idx+offset];
 
 1238                     mapidx[idx] = mapidx[idx+offset];
 
 1242         octants.resize(nocts-offset);
 
 1243 #if defined(__INTEL_COMPILER) || defined(__ICC) 
 1245         octants.shrink_to_fit();
 
 1247         nocts = octants.size();
 
 1248         mapidx.resize(nocts);
 
 1249 #if defined(__INTEL_COMPILER) || defined(__ICC) 
 1251         mapidx.shrink_to_fit();
 
 1254         if (ghosts.size() && nocts > 0){
 
 1256             if ((ghosts[idx2_gh].getMarker() < 0) && (octants[nocts-1].getMarker() < 0)){
 
 1257                 father = ghosts[idx2_gh].buildFather();
 
 1258                 markerfather = ghosts[idx2_gh].
getMarker()+1;
 
 1261                 ghosts[idx].setMarker(-1);
 
 1262                 marker = ghosts[idx].getMarker();
 
 1263                 while(marker < 0 && ghosts[idx].buildFather() == father){
 
 1265                     if (markerfather < ghosts[idx].getMarker()+1){
 
 1266                         markerfather = ghosts[idx].getMarker()+1;
 
 1269                     if(idx == size_ghosts){
 
 1272                     ghosts[idx].setMarker(-1);
 
 1273                     marker = ghosts[idx].getMarker();
 
 1277                 octants[idx].setMarker(-1);
 
 1278                 marker = octants[idx].getMarker();
 
 1279                 while(marker < 0 && octants[idx].buildFather() == father && idx >= 0){
 
 1282                     if (markerfather < octants[idx].getMarker()+1){
 
 1283                         markerfather = octants[idx].getMarker()+1;
 
 1286                     octants[idx].setMarker(-1);
 
 1287                     marker = octants[idx].getMarker();
 
 1300                     for(uint32_t ii=nocts-global3D.
nchildren; ii<nocts; ii++){
 
 1301                         octants[ii].setMarker(0);
 
 1302                         octants[ii].info[15] = 
true;
 
 1307                 for (uint32_t iii=0; iii<16; iii++){
 
 1308                     father.info[iii] = 
false;
 
 1310                 for (idx=0; idx < nend; idx++){
 
 1311                     for (uint32_t iii=0; iii<16; iii++){
 
 1312                         father.info[iii] = father.info[iii] || octants[nocts-idx-1].info[iii];
 
 1315                 father.info[13] = 
true;
 
 1316                 if (markerfather < 0){
 
 1320                 octants.resize(nocts-offset);
 
 1321                 octants.push_back(father);
 
 1322 #if defined(__INTEL_COMPILER) || defined(__ICC) 
 1324                 octants.shrink_to_fit();
 
 1326                 nocts = octants.size();
 
 1327                 mapidx.resize(nocts);
 
 1328 #if defined(__INTEL_COMPILER) || defined(__ICC) 
 1330                 mapidx.shrink_to_fit();
 
 1346     void checkCoarse(uint64_t lastDescPre,                      
 
 1347             uint64_t firstDescPost){        
 
 1351         uint8_t toDelete = 0;
 
 1353         nocts = getNumOctants();
 
 1355         Morton = octants[idx].computeMorton();
 
 1356         while(Morton <= lastDescPre && idx < nocts && Morton != 0){
 
 1360             Morton = octants[idx].computeMorton();
 
 1362         for(idx=0; idx<nocts-toDelete; idx++){
 
 1363             octants[idx] = octants[idx+toDelete];
 
 1365         octants.resize(nocts-toDelete);
 
 1366 #if defined(__INTEL_COMPILER) || defined(__ICC) 
 1368         octants.shrink_to_fit();
 
 1370         nocts = getNumOctants();
 
 1379     void checkCoarse(uint64_t lastDescPre,                      
 
 1380             uint64_t firstDescPost,
 
 1381             u32vector & mapidx){                    
 
 1385         uint8_t toDelete = 0;
 
 1387         nocts = getNumOctants();
 
 1389         Morton = octants[idx].computeMorton();
 
 1390         while(Morton <= lastDescPre && idx < nocts && Morton != 0){
 
 1394             Morton = octants[idx].computeMorton();
 
 1396         for(idx=0; idx<nocts-toDelete; idx++){
 
 1397             octants[idx] = octants[idx+toDelete];
 
 1398             mapidx[idx] = mapidx[idx+toDelete];
 
 1400         octants.resize(nocts-toDelete);
 
 1401 #if defined(__INTEL_COMPILER) || defined(__ICC) 
 1403         octants.shrink_to_fit();
 
 1405         mapidx.resize(nocts-toDelete);
 
 1406 #if defined(__INTEL_COMPILER) || defined(__ICC) 
 1408         mapidx.shrink_to_fit();
 
 1410         nocts = getNumOctants();
 
 1419     void updateLocalMaxDepth(){                     
 
 1420         uint32_t noctants = getNumOctants();
 
 1423         local_max_depth = 0;
 
 1424         for(i = 0; i < noctants; i++){
 
 1425             if(octants[i].getLevel() > local_max_depth){
 
 1426                 local_max_depth = octants[i].getLevel();
 
 1434     void findNeighbours(uint32_t idx,                           
 
 1436             u32vector & neighbours,         
 
 1437             vector<bool> & isghost){        
 
 1439         uint64_t  Morton, Mortontry;
 
 1440         uint32_t  noctants = getNumOctants();
 
 1443         uint32_t size = oct->
getSize();
 
 1449         int8_t cx = global3D.
normals[iface][0];
 
 1450         int8_t cy = global3D.
normals[iface][1];
 
 1451         int8_t cz = global3D.
normals[iface][2];
 
 1457         if (iface < 0 || iface > global3D.
nfaces){
 
 1462         if (oct->info[global3D.
nfaces+iface] == 
false){
 
 1465             if (oct->info[iface] == 
false){
 
 1468                 Class_Octant<3> samesizeoct(oct->level, int32_t(oct->x)+int32_t(cx*size), int32_t(oct->y)+int32_t(cy*size), int32_t(oct->z)+int32_t(cz*size));
 
 1473                 int32_t jump = (oct->
computeMorton() > Morton) ? int32_t(idx/2+1) : int32_t((noctants -idx)/2+1);
 
 1475                 if (idxtry > noctants-1) idxtry = noctants-1;
 
 1477                 while(abs(jump) > 0){
 
 1478                     Mortontry = octants[idxtry].computeMorton();
 
 1479                     jump = ((Mortontry<Morton)-(Mortontry>Morton))*abs(jump)/2;
 
 1481                     if (idxtry > noctants-1){
 
 1483                             idxtry = noctants - 1;
 
 1492                 if(octants[idxtry].computeMorton() == Morton && octants[idxtry].level == oct->level){
 
 1494                     isghost.push_back(
false);
 
 1495                     neighbours.push_back(idxtry);
 
 1501                         while(octants[idxtry].computeMorton() < Morton){
 
 1503                             if(idxtry > noctants-1){
 
 1504                                 idxtry = noctants-1;
 
 1508                         while(octants[idxtry].computeMorton() > Morton){
 
 1510                             if(idxtry > noctants-1){
 
 1516                     if(octants[idxtry].computeMorton() == Morton && octants[idxtry].level == oct->level){
 
 1518                         isghost.push_back(
false);
 
 1519                         neighbours.push_back(idxtry);
 
 1525                     Mortontry = octants[idxtry].computeMorton();
 
 1527                     int32_t Dxstar, Dystar, Dzstar;
 
 1528                     while(Mortontry < Mortonlast && idxtry < noctants){
 
 1529                         Dx = int32_t(abs(cx))*(-int32_t(oct->x) + int32_t(octants[idxtry].x));
 
 1530                         Dy = int32_t(abs(cy))*(-int32_t(oct->y) + int32_t(octants[idxtry].y));
 
 1531                         Dz = int32_t(abs(cz))*(-int32_t(oct->z) + int32_t(octants[idxtry].z));
 
 1532                         Dxstar = int32_t((cx-1)/2)*(octants[idxtry].getSize()) + int32_t((cx+1)/2)*size;
 
 1533                         Dystar = int32_t((cy-1)/2)*(octants[idxtry].getSize()) + int32_t((cy+1)/2)*size;
 
 1534                         Dzstar = int32_t((cz-1)/2)*(octants[idxtry].getSize()) + int32_t((cz+1)/2)*size;
 
 1536                         uint32_t x0 = oct->x;
 
 1537                         uint32_t x1 = x0 + size;
 
 1538                         uint32_t y0 = oct->y;
 
 1539                         uint32_t y1 = y0 + size;
 
 1540                         uint32_t z0 = oct->z;
 
 1541                         uint32_t z1 = z0 + size;
 
 1542                         uint32_t x0try = octants[idxtry].x;
 
 1543                         uint32_t x1try = x0try + octants[idxtry].getSize();
 
 1544                         uint32_t y0try = octants[idxtry].y;
 
 1545                         uint32_t y1try = y0try + octants[idxtry].getSize();
 
 1546                         uint32_t z0try = octants[idxtry].z;
 
 1547                         uint32_t z1try = z0try + octants[idxtry].getSize();
 
 1548                         uint8_t level = oct->level;
 
 1549                         uint8_t leveltry = octants[idxtry].getLevel();
 
 1551                         if (Dx == Dxstar && Dy == Dystar && Dz == Dzstar){
 
 1552                             if (leveltry > level){
 
 1553                                 if((abs(cx)*((y0try>=y0)*(y0try<y1))*((z0try>=z0)*(z0try<z1))) + (abs(cy)*((x0try>=x0)*(x0try<x1))*((z0try>=z0)*(z0try<z1))) + (abs(cz)*((x0try>=x0)*(x0try<x1))*((y0try>=y0)*(y0try<y1)))){
 
 1554                                     neighbours.push_back(idxtry);
 
 1555                                     isghost.push_back(
false);
 
 1558                             if (leveltry < level){
 
 1559                                 if((abs(cx)*((y0>=y0try)*(y0<y1try))*((z0>=z0try)*(z0<z1try))) + (abs(cy)*((x0>=x0try)*(x0<x1try))*((z0>=z0try)*(z0<z1try))) + (abs(cz)*((x0>=x0try)*(x0<x1try))*((y0>=y0try)*(y0<y1try)))){
 
 1560                                     neighbours.push_back(idxtry);
 
 1561                                     isghost.push_back(
false);
 
 1567                         if(idxtry>noctants-1){
 
 1570                         Mortontry = octants[idxtry].computeMorton();
 
 1584             if (oct->info[iface] == 
false){
 
 1587                 if (ghosts.size()>0){
 
 1590                     uint32_t idxghost = uint32_t(size_ghosts/2);
 
 1594                     Class_Octant<3> samesizeoct(oct->level, oct->x+cx*size, oct->y+cy*size, oct->z+cz*size);
 
 1599                     int32_t jump = (octghost->
computeMorton() > Morton) ? int32_t(idxghost/2+1) : int32_t((size_ghosts -idxghost)/2+1);
 
 1601                     if (idxtry > ghosts.size()-1) idxtry = ghosts.size()-1;
 
 1602                     while(abs(jump) > 0){
 
 1603                         Mortontry = ghosts[idxtry].computeMorton();
 
 1604                         jump = ((Mortontry<Morton)-(Mortontry>Morton))*abs(jump)/2;
 
 1606                         if (idxtry > ghosts.size()-1){
 
 1608                                 idxtry = ghosts.size() - 1;
 
 1617                     if(ghosts[idxtry].computeMorton() == Morton && ghosts[idxtry].level == oct->level){
 
 1619                         isghost.push_back(
true);
 
 1620                         neighbours.push_back(idxtry);
 
 1626                             while(ghosts[idxtry].computeMorton() < Morton){
 
 1628                                 if(idxtry > ghosts.size()-1){
 
 1629                                     idxtry = ghosts.size()-1;
 
 1633                             while(ghosts[idxtry].computeMorton() > Morton){
 
 1635                                 if(idxtry > ghosts.size()-1){
 
 1641                         if(idxtry < size_ghosts){
 
 1642                             if(ghosts[idxtry].computeMorton() == Morton && ghosts[idxtry].level == oct->level){
 
 1644                                 isghost.push_back(
true);
 
 1645                                 neighbours.push_back(idxtry);
 
 1651                             Mortontry = ghosts[idxtry].computeMorton();
 
 1653                             int32_t Dxstar, Dystar, Dzstar;
 
 1654                             while(Mortontry < Mortonlast && idxtry < size_ghosts){
 
 1655                                 Dx = int32_t(abs(cx))*(-int32_t(oct->x) + int32_t(ghosts[idxtry].x));
 
 1656                                 Dy = int32_t(abs(cy))*(-int32_t(oct->y) + int32_t(ghosts[idxtry].y));
 
 1657                                 Dz = int32_t(abs(cz))*(-int32_t(oct->z) + int32_t(ghosts[idxtry].z));
 
 1658                                 Dxstar = int32_t((cx-1)/2)*(ghosts[idxtry].getSize()) + int32_t((cx+1)/2)*size;
 
 1659                                 Dystar = int32_t((cy-1)/2)*(ghosts[idxtry].getSize()) + int32_t((cy+1)/2)*size;
 
 1660                                 Dzstar = int32_t((cz-1)/2)*(ghosts[idxtry].getSize()) + int32_t((cz+1)/2)*size;
 
 1662                                 uint32_t x0 = oct->x;
 
 1663                                 uint32_t x1 = x0 + size;
 
 1664                                 uint32_t y0 = oct->y;
 
 1665                                 uint32_t y1 = y0 + size;
 
 1666                                 uint32_t z0 = oct->z;
 
 1667                                 uint32_t z1 = z0 + size;
 
 1668                                 uint32_t x0try = ghosts[idxtry].x;
 
 1669                                 uint32_t x1try = x0try + ghosts[idxtry].getSize();
 
 1670                                 uint32_t y0try = ghosts[idxtry].y;
 
 1671                                 uint32_t y1try = y0try + ghosts[idxtry].getSize();
 
 1672                                 uint32_t z0try = ghosts[idxtry].z;
 
 1673                                 uint32_t z1try = z0try + ghosts[idxtry].getSize();
 
 1674                                 uint8_t level = oct->level;
 
 1675                                 uint8_t leveltry = ghosts[idxtry].getLevel();
 
 1677                                 if (Dx == Dxstar && Dy == Dystar && Dz == Dzstar){
 
 1678                                     if (leveltry > level){
 
 1679                                         if((abs(cx)*((y0try>=y0)*(y0try<y1))*((z0try>=z0)*(z0try<z1))) + (abs(cy)*((x0try>=x0)*(x0try<x1))*((z0try>=z0)*(z0try<z1))) + (abs(cz)*((x0try>=x0)*(x0try<x1))*((y0try>=y0)*(y0try<y1)))){
 
 1680                                             neighbours.push_back(idxtry);
 
 1681                                             isghost.push_back(
true);
 
 1684                                     if (leveltry < level){
 
 1685                                         if((abs(cx)*((y0>=y0try)*(y0<y1try))*((z0>=z0try)*(z0<z1try))) + (abs(cy)*((x0>=x0try)*(x0<x1try))*((z0>=z0try)*(z0<z1try))) + (abs(cz)*((x0>=x0try)*(x0<x1try))*((y0>=y0try)*(y0<y1try)))){
 
 1686                                             neighbours.push_back(idxtry);
 
 1687                                             isghost.push_back(
true);
 
 1693                                 if(idxtry>size_ghosts-1){
 
 1696                                 Mortontry = ghosts[idxtry].computeMorton();
 
 1701                     uint32_t lengthneigh = 0;
 
 1702                     uint32_t sizeneigh = neighbours.size();
 
 1703                     for (idxtry=0; idxtry<sizeneigh; idxtry++){
 
 1704                         lengthneigh += ghosts[neighbours[idxtry]].getArea();
 
 1706                     if (lengthneigh < oct->getArea()){
 
 1710                         if (oct->info[iface] == 
false){
 
 1713                             Class_Octant<3> samesizeoct(oct->level, oct->x+cx*size, oct->y+cy*size, oct->z+cz*size);
 
 1718                             int32_t jump = (oct->
computeMorton() > Morton) ? int32_t(idx/2+1) : int32_t((noctants -idx)/2+1);
 
 1720                             if (idxtry > noctants-1) idxtry = noctants-1;
 
 1721                             while(abs(jump) > 0){
 
 1722                                 Mortontry = octants[idxtry].computeMorton();
 
 1723                                 jump = ((Mortontry<Morton)-(Mortontry>Morton))*abs(jump)/2;
 
 1725                                 if (idxtry > noctants-1){
 
 1727                                         idxtry = noctants - 1;
 
 1736                             if(octants[idxtry].computeMorton() == Morton && octants[idxtry].level == oct->level){
 
 1738                                 isghost.push_back(
false);
 
 1739                                 neighbours.push_back(idxtry);
 
 1745                                     while(octants[idxtry].computeMorton() < Morton){
 
 1747                                         if(idxtry > noctants-1){
 
 1748                                             idxtry = noctants-1;
 
 1752                                     while(octants[idxtry].computeMorton() > Morton){
 
 1754                                         if(idxtry > noctants-1){
 
 1760                                 if (idxtry < noctants){
 
 1761                                     if(octants[idxtry].computeMorton() == Morton && octants[idxtry].level == oct->level){
 
 1763                                         isghost.push_back(
false);
 
 1764                                         neighbours.push_back(idxtry);
 
 1770                                     Mortontry = octants[idxtry].computeMorton();
 
 1772                                     int32_t Dxstar, Dystar, Dzstar;
 
 1773                                     while(Mortontry < Mortonlast && idxtry <= noctants-1){
 
 1774                                         Dx = int32_t(abs(cx))*(-int32_t(oct->x) + int32_t(octants[idxtry].x));
 
 1775                                         Dy = int32_t(abs(cy))*(-int32_t(oct->y) + int32_t(octants[idxtry].y));
 
 1776                                         Dz = int32_t(abs(cz))*(-int32_t(oct->z) + int32_t(octants[idxtry].z));
 
 1777                                         Dxstar = int32_t((cx-1)/2)*(octants[idxtry].getSize()) + int32_t((cx+1)/2)*size;
 
 1778                                         Dystar = int32_t((cy-1)/2)*(octants[idxtry].getSize()) + int32_t((cy+1)/2)*size;
 
 1779                                         Dzstar = int32_t((cz-1)/2)*(octants[idxtry].getSize()) + int32_t((cz+1)/2)*size;
 
 1781                                         uint32_t x0 = oct->x;
 
 1782                                         uint32_t x1 = x0 + size;
 
 1783                                         uint32_t y0 = oct->y;
 
 1784                                         uint32_t y1 = y0 + size;
 
 1785                                         uint32_t z0 = oct->z;
 
 1786                                         uint32_t z1 = z0 + size;
 
 1787                                         uint32_t x0try = octants[idxtry].x;
 
 1788                                         uint32_t x1try = x0try + octants[idxtry].getSize();
 
 1789                                         uint32_t y0try = octants[idxtry].y;
 
 1790                                         uint32_t y1try = y0try + octants[idxtry].getSize();
 
 1791                                         uint32_t z0try = octants[idxtry].z;
 
 1792                                         uint32_t z1try = z0try + octants[idxtry].getSize();
 
 1793                                         uint8_t level = oct->level;
 
 1794                                         uint8_t leveltry = octants[idxtry].getLevel();
 
 1796                                         if (Dx == Dxstar && Dy == Dystar && Dz == Dzstar){
 
 1797                                             if (leveltry > level){
 
 1798                                                 if((abs(cx)*((y0try>=y0)*(y0try<y1))*((z0try>=z0)*(z0try<z1))) + (abs(cy)*((x0try>=x0)*(x0try<x1))*((z0try>=z0)*(z0try<z1))) + (abs(cz)*((x0try>=x0)*(x0try<x1))*((y0try>=y0)*(y0try<y1)))){
 
 1799                                                     neighbours.push_back(idxtry);
 
 1800                                                     isghost.push_back(
false);
 
 1803                                             if (leveltry < level){
 
 1804                                                 if((abs(cx)*((y0>=y0try)*(y0<y1try))*((z0>=z0try)*(z0<z1try))) + (abs(cy)*((x0>=x0try)*(x0<x1try))*((z0>=z0try)*(z0<z1try))) + (abs(cz)*((x0>=x0try)*(x0<x1try))*((y0>=y0try)*(y0<y1try)))){
 
 1805                                                     neighbours.push_back(idxtry);
 
 1806                                                     isghost.push_back(
false);
 
 1812                                         if(idxtry>noctants-1){
 
 1815                                         Mortontry = octants[idxtry].computeMorton();
 
 1835             u32vector & neighbours,         
 
 1836             vector<bool> & isghost){        
 
 1838         uint64_t  Morton, Mortontry;
 
 1839         uint32_t  noctants = getNumOctants();
 
 1841         uint32_t size = oct->
getSize();
 
 1845         int8_t cx = int8_t((iface<2)*(int8_t(2*iface-1)));
 
 1846         int8_t cy = int8_t((iface<4)*(int8_t(iface/2))*(int8_t(2*iface-5)));
 
 1847         int8_t cz = int8_t((int8_t(iface/4))*(int8_t(2*iface-9)));
 
 1853         if (iface < 0 || iface > global3D.
nfaces){
 
 1858         if (oct->info[global3D.
nfaces+iface] == 
false){
 
 1861             if (oct->info[iface] == 
false){
 
 1864                 Class_Octant<3> samesizeoct(oct->level, int32_t(oct->x)+int32_t(cx*size), int32_t(oct->y)+int32_t(cy*size), int32_t(oct->z)+int32_t(cz*size));
 
 1869                 int32_t jump = int32_t((noctants)/2+1);
 
 1870                 idxtry = uint32_t(jump);
 
 1872                 while(abs(jump) > 0){
 
 1873                     Mortontry = octants[idxtry].computeMorton();
 
 1874                     jump = ((Mortontry<Morton)-(Mortontry>Morton))*abs(jump)/2;
 
 1876                     if (idxtry > noctants-1){
 
 1878                             idxtry = noctants - 1;
 
 1887                 if(octants[idxtry].computeMorton() == Morton && octants[idxtry].level == oct->level){
 
 1889                     isghost.push_back(
false);
 
 1890                     neighbours.push_back(idxtry);
 
 1896                         while(octants[idxtry].computeMorton() < Morton){
 
 1898                             if(idxtry > noctants-1){
 
 1899                                 idxtry = noctants-1;
 
 1903                         while(octants[idxtry].computeMorton() > Morton){
 
 1905                             if(idxtry > noctants-1){
 
 1911                     if(octants[idxtry].computeMorton() == Morton && octants[idxtry].level == oct->level){
 
 1913                         isghost.push_back(
false);
 
 1914                         neighbours.push_back(idxtry);
 
 1920                     Mortontry = octants[idxtry].computeMorton();
 
 1922                     int32_t Dxstar, Dystar, Dzstar;
 
 1923                     while(Mortontry < Mortonlast && idxtry < noctants){
 
 1924                         Dx = int32_t(abs(cx))*(-int32_t(oct->x) + int32_t(octants[idxtry].x));
 
 1925                         Dy = int32_t(abs(cy))*(-int32_t(oct->y) + int32_t(octants[idxtry].y));
 
 1926                         Dz = int32_t(abs(cz))*(-int32_t(oct->z) + int32_t(octants[idxtry].z));
 
 1927                         Dxstar = int32_t((cx-1)/2)*(octants[idxtry].getSize()) + int32_t((cx+1)/2)*size;
 
 1928                         Dystar = int32_t((cy-1)/2)*(octants[idxtry].getSize()) + int32_t((cy+1)/2)*size;
 
 1929                         Dzstar = int32_t((cz-1)/2)*(octants[idxtry].getSize()) + int32_t((cz+1)/2)*size;
 
 1931                         uint32_t x0 = oct->x;
 
 1932                         uint32_t x1 = x0 + size;
 
 1933                         uint32_t y0 = oct->y;
 
 1934                         uint32_t y1 = y0 + size;
 
 1935                         uint32_t z0 = oct->z;
 
 1936                         uint32_t z1 = z0 + size;
 
 1937                         uint32_t x0try = octants[idxtry].x;
 
 1938                         uint32_t x1try = x0try + octants[idxtry].getSize();
 
 1939                         uint32_t y0try = octants[idxtry].y;
 
 1940                         uint32_t y1try = y0try + octants[idxtry].getSize();
 
 1941                         uint32_t z0try = octants[idxtry].z;
 
 1942                         uint32_t z1try = z0try + octants[idxtry].getSize();
 
 1943                         uint8_t level = oct->level;
 
 1944                         uint8_t leveltry = octants[idxtry].getLevel();
 
 1946                         if (Dx == Dxstar && Dy == Dystar && Dz == Dzstar){
 
 1947                             if (leveltry > level){
 
 1948                                 if((abs(cx)*((y0try>=y0)*(y0try<y1))*((z0try>=z0)*(z0try<z1))) + (abs(cy)*((x0try>=x0)*(x0try<x1))*((z0try>=z0)*(z0try<z1))) + (abs(cz)*((x0try>=x0)*(x0try<x1))*((y0try>=y0)*(y0try<y1)))){
 
 1949                                     neighbours.push_back(idxtry);
 
 1950                                     isghost.push_back(
false);
 
 1953                             if (leveltry < level){
 
 1954                                 if((abs(cx)*((y0>=y0try)*(y0<y1try))*((z0>=z0try)*(z0<z1try))) + (abs(cy)*((x0>=x0try)*(x0<x1try))*((z0>=z0try)*(z0<z1try))) + (abs(cz)*((x0>=x0try)*(x0<x1try))*((y0>=y0try)*(y0<y1try)))){
 
 1955                                     neighbours.push_back(idxtry);
 
 1956                                     isghost.push_back(
false);
 
 1962                         if(idxtry>noctants-1){
 
 1965                         Mortontry = octants[idxtry].computeMorton();
 
 1979             if (oct->info[iface] == 
false){
 
 1982                 if (ghosts.size()>0){
 
 1985                     uint32_t idxghost = uint32_t(size_ghosts/2);
 
 1989                     Class_Octant<3> samesizeoct(oct->level, oct->x+cx*size, oct->y+cy*size, oct->z+cz*size);
 
 1994                     int32_t jump = (octghost->
computeMorton() > Morton) ? int32_t(idxghost/2+1) : int32_t((size_ghosts -idxghost)/2+1);
 
 1996                     if (idxtry > ghosts.size()-1) idxtry = ghosts.size()-1;
 
 1997                     while(abs(jump) > 0){
 
 1998                         Mortontry = ghosts[idxtry].computeMorton();
 
 1999                         jump = ((Mortontry<Morton)-(Mortontry>Morton))*abs(jump)/2;
 
 2001                         if (idxtry > ghosts.size()-1){
 
 2003                                 idxtry = ghosts.size() - 1;
 
 2012                     if(ghosts[idxtry].computeMorton() == Morton && ghosts[idxtry].level == oct->level){
 
 2014                         isghost.push_back(
true);
 
 2015                         neighbours.push_back(idxtry);
 
 2021                             while(ghosts[idxtry].computeMorton() < Morton){
 
 2023                                 if(idxtry > ghosts.size()-1){
 
 2024                                     idxtry = ghosts.size()-1;
 
 2028                             while(ghosts[idxtry].computeMorton() > Morton){
 
 2030                                 if(idxtry > ghosts.size()-1){
 
 2036                         if(idxtry < size_ghosts){
 
 2037                             if(ghosts[idxtry].computeMorton() == Morton && ghosts[idxtry].level == oct->level){
 
 2039                                 isghost.push_back(
true);
 
 2040                                 neighbours.push_back(idxtry);
 
 2046                             Mortontry = ghosts[idxtry].computeMorton();
 
 2048                             int32_t Dxstar, Dystar, Dzstar;
 
 2049                             while(Mortontry < Mortonlast && idxtry < size_ghosts){
 
 2050                                 Dx = int32_t(abs(cx))*(-int32_t(oct->x) + int32_t(ghosts[idxtry].x));
 
 2051                                 Dy = int32_t(abs(cy))*(-int32_t(oct->y) + int32_t(ghosts[idxtry].y));
 
 2052                                 Dz = int32_t(abs(cz))*(-int32_t(oct->z) + int32_t(ghosts[idxtry].z));
 
 2053                                 Dxstar = int32_t((cx-1)/2)*(ghosts[idxtry].getSize()) + int32_t((cx+1)/2)*size;
 
 2054                                 Dystar = int32_t((cy-1)/2)*(ghosts[idxtry].getSize()) + int32_t((cy+1)/2)*size;
 
 2055                                 Dzstar = int32_t((cz-1)/2)*(ghosts[idxtry].getSize()) + int32_t((cz+1)/2)*size;
 
 2057                                 uint32_t x0 = oct->x;
 
 2058                                 uint32_t x1 = x0 + size;
 
 2059                                 uint32_t y0 = oct->y;
 
 2060                                 uint32_t y1 = y0 + size;
 
 2061                                 uint32_t z0 = oct->z;
 
 2062                                 uint32_t z1 = z0 + size;
 
 2063                                 uint32_t x0try = ghosts[idxtry].x;
 
 2064                                 uint32_t x1try = x0try + ghosts[idxtry].getSize();
 
 2065                                 uint32_t y0try = ghosts[idxtry].y;
 
 2066                                 uint32_t y1try = y0try + ghosts[idxtry].getSize();
 
 2067                                 uint32_t z0try = ghosts[idxtry].z;
 
 2068                                 uint32_t z1try = z0try + ghosts[idxtry].getSize();
 
 2069                                 uint8_t level = oct->level;
 
 2070                                 uint8_t leveltry = ghosts[idxtry].getLevel();
 
 2072                                 if (Dx == Dxstar && Dy == Dystar && Dz == Dzstar){
 
 2073                                     if (leveltry > level){
 
 2074                                         if((abs(cx)*((y0try>=y0)*(y0try<y1))*((z0try>=z0)*(z0try<z1))) + (abs(cy)*((x0try>=x0)*(x0try<x1))*((z0try>=z0)*(z0try<z1))) + (abs(cz)*((x0try>=x0)*(x0try<x1))*((y0try>=y0)*(y0try<y1)))){
 
 2075                                             neighbours.push_back(idxtry);
 
 2076                                             isghost.push_back(
true);
 
 2079                                     if (leveltry < level){
 
 2080                                         if((abs(cx)*((y0>=y0try)*(y0<y1try))*((z0>=z0try)*(z0<z1try))) + (abs(cy)*((x0>=x0try)*(x0<x1try))*((z0>=z0try)*(z0<z1try))) + (abs(cz)*((x0>=x0try)*(x0<x1try))*((y0>=y0try)*(y0<y1try)))){
 
 2081                                             neighbours.push_back(idxtry);
 
 2082                                             isghost.push_back(
true);
 
 2088                                 if(idxtry>size_ghosts-1){
 
 2091                                 Mortontry = ghosts[idxtry].computeMorton();
 
 2096                     uint32_t lengthneigh = 0;
 
 2097                     uint32_t sizeneigh = neighbours.size();
 
 2098                     for (idxtry=0; idxtry<sizeneigh; idxtry++){
 
 2099                         lengthneigh += ghosts[neighbours[idxtry]].getArea();
 
 2101                     if (lengthneigh < oct->getArea()){
 
 2105                         if (oct->info[iface] == 
false){
 
 2108                             Class_Octant<3> samesizeoct(oct->level, oct->x+cx*size, oct->y+cy*size, oct->z+cz*size);
 
 2113                             int32_t jump = (int32_t((noctants)/2+1));
 
 2114                             idxtry = uint32_t(jump);
 
 2115                             while(abs(jump) > 0){
 
 2116                                 Mortontry = octants[idxtry].computeMorton();
 
 2117                                 jump = ((Mortontry<Morton)-(Mortontry>Morton))*abs(jump)/2;
 
 2119                                 if (idxtry > noctants-1){
 
 2121                                         idxtry = noctants - 1;
 
 2130                             if(octants[idxtry].computeMorton() == Morton && octants[idxtry].level == oct->level){
 
 2132                                 isghost.push_back(
false);
 
 2133                                 neighbours.push_back(idxtry);
 
 2139                                     while(octants[idxtry].computeMorton() < Morton){
 
 2141                                         if(idxtry > noctants-1){
 
 2142                                             idxtry = noctants-1;
 
 2146                                     while(octants[idxtry].computeMorton() > Morton){
 
 2148                                         if(idxtry > noctants-1){
 
 2154                                 if (idxtry < noctants){
 
 2155                                     if(octants[idxtry].computeMorton() == Morton && octants[idxtry].level == oct->level){
 
 2157                                         isghost.push_back(
false);
 
 2158                                         neighbours.push_back(idxtry);
 
 2164                                     Mortontry = octants[idxtry].computeMorton();
 
 2166                                     int32_t Dxstar, Dystar, Dzstar;
 
 2167                                     while(Mortontry < Mortonlast && idxtry <= noctants-1){
 
 2168                                         Dx = int32_t(abs(cx))*(-int32_t(oct->x) + int32_t(octants[idxtry].x));
 
 2169                                         Dy = int32_t(abs(cy))*(-int32_t(oct->y) + int32_t(octants[idxtry].y));
 
 2170                                         Dz = int32_t(abs(cz))*(-int32_t(oct->z) + int32_t(octants[idxtry].z));
 
 2171                                         Dxstar = int32_t((cx-1)/2)*(octants[idxtry].getSize()) + int32_t((cx+1)/2)*size;
 
 2172                                         Dystar = int32_t((cy-1)/2)*(octants[idxtry].getSize()) + int32_t((cy+1)/2)*size;
 
 2173                                         Dzstar = int32_t((cz-1)/2)*(octants[idxtry].getSize()) + int32_t((cz+1)/2)*size;
 
 2175                                         uint32_t x0 = oct->x;
 
 2176                                         uint32_t x1 = x0 + size;
 
 2177                                         uint32_t y0 = oct->y;
 
 2178                                         uint32_t y1 = y0 + size;
 
 2179                                         uint32_t z0 = oct->z;
 
 2180                                         uint32_t z1 = z0 + size;
 
 2181                                         uint32_t x0try = octants[idxtry].x;
 
 2182                                         uint32_t x1try = x0try + octants[idxtry].getSize();
 
 2183                                         uint32_t y0try = octants[idxtry].y;
 
 2184                                         uint32_t y1try = y0try + octants[idxtry].getSize();
 
 2185                                         uint32_t z0try = octants[idxtry].z;
 
 2186                                         uint32_t z1try = z0try + octants[idxtry].getSize();
 
 2187                                         uint8_t level = oct->level;
 
 2188                                         uint8_t leveltry = octants[idxtry].getLevel();
 
 2190                                         if (Dx == Dxstar && Dy == Dystar && Dz == Dzstar){
 
 2191                                             if (leveltry > level){
 
 2192                                                 if((abs(cx)*((y0try>=y0)*(y0try<y1))*((z0try>=z0)*(z0try<z1))) + (abs(cy)*((x0try>=x0)*(x0try<x1))*((z0try>=z0)*(z0try<z1))) + (abs(cz)*((x0try>=x0)*(x0try<x1))*((y0try>=y0)*(y0try<y1)))){
 
 2193                                                     neighbours.push_back(idxtry);
 
 2194                                                     isghost.push_back(
false);
 
 2197                                             if (leveltry < level){
 
 2198                                                 if((abs(cx)*((y0>=y0try)*(y0<y1try))*((z0>=z0try)*(z0<z1try))) + (abs(cy)*((x0>=x0try)*(x0<x1try))*((z0>=z0try)*(z0<z1try))) + (abs(cz)*((x0>=x0try)*(x0<x1try))*((y0>=y0try)*(y0<y1try)))){
 
 2199                                                     neighbours.push_back(idxtry);
 
 2200                                                     isghost.push_back(
false);
 
 2206                                         Mortontry = octants[idxtry].computeMorton();
 
 2224     void findGhostNeighbours(uint32_t 
const idx,        
 
 2226             u32vector & neighbours){        
 
 2228         uint64_t  Morton, Mortontry;
 
 2229         uint32_t  noctants = getNumOctants();
 
 2232         uint32_t size = oct->
getSize();
 
 2235         int8_t cx = int8_t((iface<2)*(int8_t(2*iface-1)));
 
 2236         int8_t cy = int8_t((iface<4)*(int8_t(iface/2))*(int8_t(2*iface-5)));
 
 2237         int8_t cz = int8_t((int8_t(iface/4))*(int8_t(2*iface-9)));
 
 2242         if (iface < 0 || iface > global3D.
nfaces){
 
 2247         if (oct->info[global3D.
nfaces+iface] == 
true){
 
 2250             Class_Octant<3> samesizeoct(oct->level, int32_t(oct->x)+int32_t(cx*size), int32_t(oct->y)+int32_t(cy*size), int32_t(oct->z)+int32_t(cz*size));
 
 2255             int32_t jump = getNumOctants()/2;
 
 2256             idxtry = uint32_t(getNumOctants()/2);
 
 2257             Mortontry = octants[idxtry].computeMorton();
 
 2258             jump = ((Mortontry<Morton)-(Mortontry>Morton))*abs(jump)/2;
 
 2259             while(abs(jump) > 0){
 
 2260                 Mortontry = octants[idxtry].computeMorton();
 
 2261                 jump = ((Mortontry<Morton)-(Mortontry>Morton))*abs(jump)/2;
 
 2263                 if (idxtry > noctants-1){
 
 2265                         idxtry = noctants - 1;
 
 2274             if(octants[idxtry].computeMorton() == Morton && octants[idxtry].level == oct->level){
 
 2276                 neighbours.push_back(idxtry);
 
 2282                     while(octants[idxtry].computeMorton() < Morton){
 
 2284                         if(idxtry > noctants-1){
 
 2285                             idxtry = noctants-1;
 
 2289                     while(octants[idxtry].computeMorton() > Morton){
 
 2291                         if(idxtry > noctants-1){
 
 2297                 if(octants[idxtry].computeMorton() == Morton && octants[idxtry].level == oct->level){
 
 2299                     neighbours.push_back(idxtry);
 
 2305                 Mortontry = octants[idxtry].computeMorton();
 
 2307                 int32_t Dxstar, Dystar, Dzstar;
 
 2308                 while(Mortontry < Mortonlast && idxtry < noctants){
 
 2309                     Dx = int32_t(abs(cx))*(-int32_t(oct->x) + int32_t(octants[idxtry].x));
 
 2310                     Dy = int32_t(abs(cy))*(-int32_t(oct->y) + int32_t(octants[idxtry].y));
 
 2311                     Dz = int32_t(abs(cz))*(-int32_t(oct->z) + int32_t(octants[idxtry].z));
 
 2312                     Dxstar = int32_t((cx-1)/2)*(octants[idxtry].getSize()) + int32_t((cx+1)/2)*size;
 
 2313                     Dystar = int32_t((cy-1)/2)*(octants[idxtry].getSize()) + int32_t((cy+1)/2)*size;
 
 2314                     Dzstar = int32_t((cz-1)/2)*(octants[idxtry].getSize()) + int32_t((cz+1)/2)*size;
 
 2316                     uint32_t x0 = oct->x;
 
 2317                     uint32_t x1 = x0 + size;
 
 2318                     uint32_t y0 = oct->y;
 
 2319                     uint32_t y1 = y0 + size;
 
 2320                     uint32_t z0 = oct->z;
 
 2321                     uint32_t z1 = z0 + size;
 
 2322                     uint32_t x0try = octants[idxtry].x;
 
 2323                     uint32_t x1try = x0try + octants[idxtry].getSize();
 
 2324                     uint32_t y0try = octants[idxtry].y;
 
 2325                     uint32_t y1try = y0try + octants[idxtry].getSize();
 
 2326                     uint32_t z0try = octants[idxtry].z;
 
 2327                     uint32_t z1try = z0try + octants[idxtry].getSize();
 
 2328                     uint8_t level = oct->level;
 
 2329                     uint8_t leveltry = octants[idxtry].getLevel();
 
 2331                     if (Dx == Dxstar && Dy == Dystar && Dz == Dzstar){
 
 2332                         if (leveltry > level){
 
 2333                             if((abs(cx)*((y0try>=y0)*(y0try<y1))*((z0try>=z0)*(z0try<z1))) + (abs(cy)*((x0try>=x0)*(x0try<x1))*((z0try>=z0)*(z0try<z1))) + (abs(cz)*((x0try>=x0)*(x0try<x1))*((y0try>=y0)*(y0try<y1)))){
 
 2334                                 neighbours.push_back(idxtry);
 
 2337                         if (leveltry < level){
 
 2338                             if((abs(cx)*((y0>=y0try)*(y0<y1try))*((z0>=z0try)*(z0<z1try))) + (abs(cy)*((x0>=x0try)*(x0<x1try))*((z0>=z0try)*(z0<z1try))) + (abs(cz)*((x0>=x0try)*(x0<x1try))*((y0>=y0try)*(y0<y1try)))){
 
 2339                                 neighbours.push_back(idxtry);
 
 2345                     if(idxtry>noctants-1){
 
 2348                     Mortontry = octants[idxtry].computeMorton();
 
 2363     void preBalance21(
bool internal){
 
 2368         uint32_t idx, idx2, idx0, last_idx;
 
 2369         uint32_t idx1_gh, idx2_gh;
 
 2370         int8_t markerfather, marker;
 
 2382         nocts   = octants.size();
 
 2383         size_ghosts = ghosts.size();
 
 2387         last_ghost_bros.clear();
 
 2392             while(idx2_gh < size_ghosts && ghosts[idx2_gh].computeMorton() <= last_desc.
computeMorton()){
 
 2395             idx2_gh = min((size_ghosts-1), idx2_gh);
 
 2397             while(idx1_gh < size_ghosts && ghosts[idx1_gh].computeMorton() <= octants[0].computeMorton()){
 
 2401             if (idx1_gh==-1) idx1_gh=0;
 
 2405         if (ghosts.size() && nocts > 0){
 
 2406             if (ghosts[idx1_gh].buildFather()==octants[0].buildFather()){
 
 2407                 father = ghosts[idx1_gh].buildFather();
 
 2411                 while(marker < 0 && ghosts[idx].buildFather() == father){
 
 2416                     marker = ghosts[idx].getMarker();
 
 2421                 while(idx<nocts && octants[idx].buildFather() == father){
 
 2422                     if(octants[idx].getMarker()<0)
 
 2429                 if (nbro != global3D.
nchildren && idx!=nocts-1){
 
 2430                     for(uint32_t ii=0; ii<idx; ii++){
 
 2431                         if (octants[ii].getMarker()<0){
 
 2432                             octants[ii].setMarker(0);
 
 2433                             octants[ii].info[15]=
true;
 
 2441             if (ghosts[idx2_gh].buildFather()==octants[nocts-1].buildFather()){
 
 2442                 father = ghosts[idx2_gh].buildFather();
 
 2446                 while(marker < 0 && ghosts[idx].buildFather() == father){
 
 2449                     last_ghost_bros.push_back(idx);
 
 2453                     if(idx == size_ghosts){
 
 2456                     marker = ghosts[idx].getMarker();
 
 2461                 while(octants[idx].buildFather() == father ){
 
 2462                     if (octants[idx].getMarker()<0)
 
 2470                 if (nbro != global3D.
nchildren && idx!=nocts-1){
 
 2471                     for(uint32_t ii=idx+1; ii<nocts; ii++){
 
 2472                         if (octants[ii].getMarker()<0){
 
 2473                             octants[ii].setMarker(0);
 
 2474                             octants[ii].info[15]=
true;
 
 2479                     last_ghost_bros.clear();
 
 2486             father = octants[0].buildFather();
 
 2487             lastdesc = father.buildLastDesc();
 
 2490             for (idx=0; idx<global3D.
nchildren; idx++){
 
 2492                 if (octants[idx].computeMorton() <= mortonld){
 
 2500             for (idx=idx0; idx<nocts; idx++){
 
 2501                 if(octants[idx].getMarker() < 0 && octants[idx].getLevel() > 0){
 
 2503                     father = octants[idx].buildFather();
 
 2505                     for (idx2=idx; idx2<idx+global3D.
nchildren; idx2++){
 
 2507                             if(octants[idx2].getMarker() < 0 && octants[idx2].buildFather() == father){
 
 2518                             octants[idx].info[15]=
true;
 
 2529     void preBalance21(u32vector& newmodified){
 
 2534         uint32_t idx, idx2, idx0, last_idx;
 
 2535         uint32_t idx1_gh, idx2_gh;
 
 2536         int8_t markerfather, marker;
 
 2548         nocts   = octants.size();
 
 2549         size_ghosts = ghosts.size();
 
 2553         last_ghost_bros.clear();
 
 2557             while(idx2_gh < size_ghosts && ghosts[idx2_gh].computeMorton() <= last_desc.
computeMorton()){
 
 2560             idx2_gh = min((size_ghosts-1), idx2_gh);
 
 2562             while(idx1_gh < size_ghosts && ghosts[idx1_gh].computeMorton() <= octants[0].computeMorton()){
 
 2566             if (idx1_gh==-1) idx1_gh=0;
 
 2570         if (ghosts.size() && nocts > 0){
 
 2571             if (ghosts[idx1_gh].buildFather()==octants[0].buildFather()){
 
 2572                 father = ghosts[idx1_gh].buildFather();
 
 2576                 while(marker < 0 && ghosts[idx].buildFather() == father){
 
 2579                     last_ghost_bros.push_back(idx);
 
 2585                     marker = ghosts[idx].getMarker();
 
 2590                 while(idx<nocts && octants[idx].buildFather() == father){
 
 2591                     if (octants[idx].getMarker()<0)
 
 2597                 if (nbro != global3D.
nchildren && idx!=nocts-1){
 
 2598                     for(uint32_t ii=0; ii<idx; ii++){
 
 2599                         if (octants[ii].getMarker()<0){
 
 2600                             octants[ii].setMarker(0);
 
 2601                             octants[ii].info[15]=
true;
 
 2603                             newmodified.push_back(ii);
 
 2607                     last_ghost_bros.clear();
 
 2612             if (ghosts[idx2_gh].buildFather()==octants[nocts-1].buildFather()){
 
 2613                 father = ghosts[idx2_gh].buildFather();
 
 2617                 while(marker < 0 && ghosts[idx].buildFather() == father){
 
 2620                     if(idx == size_ghosts){
 
 2623                     marker = ghosts[idx].getMarker();
 
 2628                 while(octants[idx].buildFather() == father){
 
 2629                     if (octants[idx].getMarker()<0)
 
 2636                 if (nbro != global3D.
nchildren && idx!=nocts-1){
 
 2637                     for(uint32_t ii=idx+1; ii<nocts; ii++){
 
 2638                         if (octants[ii].getMarker()<0){
 
 2639                             octants[ii].setMarker(0);
 
 2640                             octants[ii].info[15]=
true;
 
 2642                             newmodified.push_back(ii);
 
 2650         father = octants[0].buildFather();
 
 2651         lastdesc = father.buildLastDesc();
 
 2654         for (idx=0; idx<global3D.
nchildren; idx++){
 
 2656             if (octants[idx].computeMorton() <= mortonld){
 
 2664         for (idx=idx0; idx<nocts; idx++){
 
 2665             if(octants[idx].getMarker() < 0 && octants[idx].getLevel() > 0){
 
 2667                 father = octants[idx].buildFather();
 
 2669                 for (idx2=idx; idx2<idx+global3D.
nchildren; idx2++){
 
 2671                         if(octants[idx2].getMarker() < 0 && octants[idx2].buildFather() == father){
 
 2682                         octants[idx].info[15]=
true;
 
 2684                         newmodified.push_back(idx);
 
 2693     bool localBalance(
bool doInterior){             
 
 2697         uint32_t            sizeneigh, modsize;
 
 2699         u32vector           modified, newmodified;
 
 2701         uint8_t             iface, iedge, inode;
 
 2702         int8_t              targetmarker;
 
 2703         vector<bool>        isghost;
 
 2706         OctantsType::iterator   obegin, oend, it;
 
 2707         u32vector::iterator     ibegin, iend, iit;
 
 2712             obegin = octants.begin();
 
 2713             oend = octants.end();
 
 2715             for (it=obegin; it!=oend; it++){
 
 2716                 if (!it->getNotBalance() && it->getMarker() != 0){
 
 2717                     targetmarker = min(MAX_LEVEL_3D, (octants[idx].getLevel() + octants[idx].getMarker()));
 
 2720                     for (iface=0; iface<global3D.
nfaces; iface++){
 
 2721                         if(!it->getBound(iface)){
 
 2722                             findNeighbours(idx, iface, neigh, isghost);
 
 2723                             sizeneigh = neigh.size();
 
 2724                             for(i=0; i<sizeneigh; i++){
 
 2727                                         if((octants[neigh[i]].getLevel() + octants[neigh[i]].getMarker()) > (targetmarker + 1) ){
 
 2728                                             octants[idx].setMarker(octants[neigh[i]].getLevel()+octants[neigh[i]].getMarker()-1-octants[idx].getLevel());
 
 2729                                             octants[idx].info[15] = 
true;
 
 2730                                             modified.push_back(idx);
 
 2733                                         else if((octants[neigh[i]].getLevel() + octants[neigh[i]].getMarker()) < (targetmarker - 1)){
 
 2734                                             octants[neigh[i]].setMarker(targetmarker-octants[neigh[i]].getLevel()-1);
 
 2735                                             octants[neigh[i]].info[15] = 
true;
 
 2736                                             modified.push_back(neigh[i]);
 
 2743                                         if((ghosts[neigh[i]].getLevel() + ghosts[neigh[i]].getMarker()) > (targetmarker + 1) ){
 
 2744                                             octants[idx].setMarker(ghosts[neigh[i]].getLevel()+ghosts[neigh[i]].getMarker()-1-octants[idx].getLevel());
 
 2745                                             octants[idx].info[15] = 
true;
 
 2746                                             modified.push_back(idx);
 
 2755                     if (balance_codim>1){
 
 2757                         for (iedge=0; iedge<global3D.
nedges; iedge++){
 
 2758                             if(!it->getBound(global3D.
edgeface[iedge][0]) && !it->getBound(global3D.
edgeface[iedge][1])){
 
 2759                                 findEdgeNeighbours(idx, iedge, neigh, isghost);
 
 2760                                 sizeneigh = neigh.size();
 
 2761                                 for(i=0; i<sizeneigh; i++){
 
 2764                                             if((octants[neigh[i]].getLevel() + octants[neigh[i]].getMarker()) > (targetmarker + 1) ){
 
 2765                                                 octants[idx].setMarker(octants[neigh[i]].getLevel()+octants[neigh[i]].getMarker()-1-octants[idx].getLevel());
 
 2766                                                 octants[idx].info[15] = 
true;
 
 2767                                                 modified.push_back(idx);
 
 2770                                             else if((octants[neigh[i]].getLevel() + octants[neigh[i]].getMarker()) < (targetmarker - 1)){
 
 2771                                                 octants[neigh[i]].setMarker(targetmarker-octants[neigh[i]].getLevel()-1);
 
 2772                                                 octants[neigh[i]].info[15] = 
true;
 
 2773                                                 modified.push_back(neigh[i]);
 
 2779                                         if((ghosts[neigh[i]].getLevel() + ghosts[neigh[i]].getMarker()) > (targetmarker + 1) ){
 
 2780                                             octants[idx].setMarker(ghosts[neigh[i]].getLevel()+ghosts[neigh[i]].getMarker()-1-octants[idx].getLevel());
 
 2781                                             octants[idx].info[15] = 
true;
 
 2782                                             modified.push_back(idx);
 
 2791                     if (balance_codim>2){
 
 2793                         for (inode=0; inode<global3D.
nnodes; inode++){
 
 2794                             if(!it->getBound(global3D.
nodeface[inode][0]) && !it->getBound(global3D.
nodeface[inode][1]) && !it->getBound(global3D.
nodeface[inode][2])){
 
 2795                                 findNodeNeighbours(idx, inode, neigh, isghost);
 
 2796                                 sizeneigh = neigh.size();
 
 2797                                 for(i=0; i<sizeneigh; i++){
 
 2800                                             if((octants[neigh[i]].getLevel() + octants[neigh[i]].getMarker()) > (targetmarker + 1) ){
 
 2801                                                 octants[idx].setMarker(octants[neigh[i]].getLevel()+octants[neigh[i]].getMarker()-1-octants[idx].getLevel());
 
 2802                                                 octants[idx].info[15] = 
true;
 
 2803                                                 modified.push_back(idx);
 
 2806                                             else if((octants[neigh[i]].getLevel() + octants[neigh[i]].getMarker()) < (targetmarker - 1)){
 
 2807                                                 octants[neigh[i]].setMarker(targetmarker-octants[neigh[i]].getLevel()-1);
 
 2808                                                 octants[neigh[i]].info[15] = 
true;
 
 2809                                                 modified.push_back(neigh[i]);
 
 2815                                         if((ghosts[neigh[i]].getLevel() + ghosts[neigh[i]].getMarker()) > (targetmarker + 1) ){
 
 2816                                             octants[idx].setMarker(ghosts[neigh[i]].getLevel()+ghosts[neigh[i]].getMarker()-1-octants[idx].getLevel());
 
 2817                                             octants[idx].info[15] = 
true;
 
 2818                                             modified.push_back(idx);
 
 2831             obegin = ghosts.begin();
 
 2832             oend = ghosts.end();
 
 2834             for (it=obegin; it!=oend; it++){
 
 2835                 if (!it->getNotBalance() && it->getMarker() != 0){
 
 2836                     targetmarker = min(MAX_LEVEL_3D, (it->getLevel()+it->getMarker()));
 
 2839                     for (iface=0; iface<global3D.
nfaces; iface++){
 
 2840                         if(it->getPbound(iface) == 
true){
 
 2842                             findGhostNeighbours(idx, iface, neigh);
 
 2843                             sizeneigh = neigh.size();
 
 2844                             for(i=0; i<sizeneigh; i++){
 
 2845                                 if((octants[neigh[i]].getLevel() + octants[neigh[i]].getMarker()) < (targetmarker - 1)){
 
 2846                                     octants[neigh[i]].setMarker(targetmarker-octants[neigh[i]].getLevel()-1);
 
 2847                                     octants[neigh[i]].info[15] = 
true;
 
 2848                                     modified.push_back(neigh[i]);
 
 2855                     if (balance_codim>1){
 
 2857                         for (iedge=0; iedge<global3D.
nedges; iedge++){
 
 2858                             if(it->getPbound(global3D.
nodeface[iedge][0]) == 
true || it->getPbound(global3D.
nodeface[iedge][1]) == 
true){
 
 2860                                 findGhostEdgeNeighbours(idx, iedge, neigh);
 
 2861                                 sizeneigh = neigh.size();
 
 2862                                 for(i=0; i<sizeneigh; i++){
 
 2863                                     if((octants[neigh[i]].getLevel() + octants[neigh[i]].getMarker()) < (targetmarker - 1)){
 
 2864                                         octants[neigh[i]].setMarker(targetmarker-octants[neigh[i]].getLevel()-1);
 
 2865                                         octants[neigh[i]].info[15] = 
true;
 
 2866                                         modified.push_back(neigh[i]);
 
 2874                     if (balance_codim>2){
 
 2876                         for (inode=0; inode<global3D.
nnodes; inode++){
 
 2877                             if(it->getPbound(global3D.
nodeface[inode][0]) == 
true || it->getPbound(global3D.
nodeface[inode][1]) == 
true || it->getPbound(global3D.
nodeface[inode][2]) == 
true){
 
 2879                                 findGhostNodeNeighbours(idx, inode, neigh);
 
 2880                                 sizeneigh = neigh.size();
 
 2881                                 for(i=0; i<sizeneigh; i++){
 
 2882                                     if((octants[neigh[i]].getLevel() + octants[neigh[i]].getMarker()) < (targetmarker - 1)){
 
 2883                                         octants[neigh[i]].setMarker(targetmarker-octants[neigh[i]].getLevel()-1);
 
 2884                                         octants[neigh[i]].info[15] = 
true;
 
 2885                                         modified.push_back(neigh[i]);
 
 2898             u32vector().swap(newmodified);
 
 2899             modsize = modified.size();
 
 2901                 ibegin = modified.begin();
 
 2902                 iend = modified.end();
 
 2903                 for (iit=ibegin; iit!=iend; iit++){
 
 2905                     if (!octants[idx].getNotBalance()){
 
 2906                         targetmarker = min(MAX_LEVEL_3D, (octants[idx].getLevel()+octants[idx].getMarker()));
 
 2909                         for (iface=0; iface<global3D.
nfaces; iface++){
 
 2910                             if(!octants[idx].getPbound(iface)){
 
 2911                                 findNeighbours(idx, iface, neigh, isghost);
 
 2912                                 sizeneigh = neigh.size();
 
 2913                                 for(i=0; i<sizeneigh; i++){
 
 2916                                             if((octants[neigh[i]].getLevel() + octants[neigh[i]].getMarker()) >  (targetmarker + 1)){
 
 2917                                                 octants[idx].setMarker(octants[neigh[i]].getLevel()+octants[neigh[i]].getMarker()-octants[idx].getLevel()-1);
 
 2918                                                 octants[idx].info[15] = 
true;
 
 2919                                                 newmodified.push_back(idx);
 
 2922                                             else if((octants[neigh[i]].getLevel() + octants[neigh[i]].getMarker()) < (targetmarker - 1)){
 
 2923                                                 octants[neigh[i]].setMarker(targetmarker-octants[neigh[i]].getLevel()-1);
 
 2924                                                 octants[neigh[i]].info[15] = 
true;
 
 2925                                                 newmodified.push_back(neigh[i]);
 
 2934                         if (balance_codim>1){
 
 2936                             for (iedge=0; iedge<global3D.
nedges; iedge++){
 
 2937                                 if(!octants[idx].getPbound(global3D.
edgeface[iedge][0]) || !octants[idx].getPbound(global3D.
edgeface[iedge][1])){
 
 2938                                     findEdgeNeighbours(idx, iedge, neigh, isghost);
 
 2939                                     sizeneigh = neigh.size();
 
 2940                                     for(i=0; i<sizeneigh; i++){
 
 2943                                                 if((octants[neigh[i]].getLevel() + octants[neigh[i]].getMarker()) >  (targetmarker + 1)){
 
 2944                                                     octants[idx].setMarker(octants[neigh[i]].getLevel()+octants[neigh[i]].getMarker()-octants[idx].getLevel()-1);
 
 2945                                                     octants[idx].info[15] = 
true;
 
 2946                                                     newmodified.push_back(idx);
 
 2949                                                 else if((octants[neigh[i]].getLevel() + octants[neigh[i]].getMarker()) < (targetmarker - 1)){
 
 2950                                                     octants[neigh[i]].setMarker(targetmarker-octants[neigh[i]].getLevel()-1);
 
 2951                                                     octants[neigh[i]].info[15] = 
true;
 
 2952                                                     newmodified.push_back(neigh[i]);
 
 2962                         if (balance_codim>2){
 
 2964                             for (inode=0; inode<global3D.
nnodes; inode++){
 
 2965                                 if(!octants[idx].getPbound(global3D.
nodeface[inode][0]) || !octants[idx].getPbound(global3D.
nodeface[inode][1]) || !octants[idx].getPbound(global3D.
nodeface[inode][2])){
 
 2966                                     findNodeNeighbours(idx, inode, neigh, isghost);
 
 2967                                     sizeneigh = neigh.size();
 
 2968                                     for(i=0; i<sizeneigh; i++){
 
 2971                                                 if((octants[neigh[i]].getLevel() + octants[neigh[i]].getMarker()) >  (targetmarker + 1)){
 
 2972                                                     octants[idx].setMarker(octants[neigh[i]].getLevel()+octants[neigh[i]].getMarker()-octants[idx].getLevel()-1);
 
 2973                                                     octants[idx].info[15] = 
true;
 
 2974                                                     newmodified.push_back(idx);
 
 2977                                                 else if((octants[neigh[i]].getLevel() + octants[neigh[i]].getMarker()) < (targetmarker - 1)){
 
 2978                                                     octants[neigh[i]].setMarker(targetmarker-octants[neigh[i]].getLevel()-1);
 
 2979                                                     octants[neigh[i]].info[15] = 
true;
 
 2980                                                     newmodified.push_back(neigh[i]);
 
 2992                 preBalance21(newmodified);
 
 2993                 u32vector().swap(modified);
 
 2994                 swap(modified,newmodified);
 
 2995                 modsize = modified.size();
 
 2996                 u32vector().swap(newmodified);
 
 3003             obegin = ghosts.begin();
 
 3004             oend = ghosts.end();
 
 3006             for (it=obegin; it!=oend; it++){
 
 3007                 if (!it->getNotBalance() && it->info[15]){
 
 3008                     targetmarker = min(MAX_LEVEL_3D, (it->getLevel()+it->getMarker()));
 
 3011                     for (iface=0; iface<global3D.
nfaces; iface++){
 
 3012                         if(it->getPbound(iface) == 
true){
 
 3014                             findGhostNeighbours(idx, iface, neigh);
 
 3015                             sizeneigh = neigh.size();
 
 3016                             for(i=0; i<sizeneigh; i++){
 
 3017                                 if((octants[neigh[i]].getLevel() + octants[neigh[i]].getMarker()) < (targetmarker - 1)){
 
 3018                                     octants[neigh[i]].setMarker(targetmarker-octants[neigh[i]].getLevel()-1);
 
 3019                                     octants[neigh[i]].info[15] = 
true;
 
 3020                                     modified.push_back(neigh[i]);
 
 3027                     if (balance_codim>1){
 
 3029                         for (iedge=0; iedge<global3D.
nedges; iedge++){
 
 3030                             if(it->getPbound(global3D.
nodeface[iedge][0]) == 
true || it->getPbound(global3D.
nodeface[iedge][1]) == 
true){
 
 3032                                 findGhostEdgeNeighbours(idx, iedge, neigh);
 
 3033                                 sizeneigh = neigh.size();
 
 3034                                 for(i=0; i<sizeneigh; i++){
 
 3035                                     if((octants[neigh[i]].getLevel() + octants[neigh[i]].getMarker()) < (targetmarker - 1)){
 
 3036                                         octants[neigh[i]].setMarker(targetmarker-octants[neigh[i]].getLevel()-1);
 
 3037                                         octants[neigh[i]].info[15] = 
true;
 
 3038                                         modified.push_back(neigh[i]);
 
 3046                     if (balance_codim>2){
 
 3048                         for (inode=0; inode<global3D.
nnodes; inode++){
 
 3049                             if(it->getPbound(global3D.
nodeface[inode][0]) == 
true || it->getPbound(global3D.
nodeface[inode][1]) == 
true || it->getPbound(global3D.
nodeface[inode][2]) == 
true){
 
 3051                                 findGhostNodeNeighbours(idx, inode, neigh);
 
 3052                                 sizeneigh = neigh.size();
 
 3053                                 for(i=0; i<sizeneigh; i++){
 
 3054                                     if((octants[neigh[i]].getLevel() + octants[neigh[i]].getMarker()) < (targetmarker - 1)){
 
 3055                                         octants[neigh[i]].setMarker(targetmarker-octants[neigh[i]].getLevel()-1);
 
 3056                                         octants[neigh[i]].info[15] = 
true;
 
 3057                                         modified.push_back(neigh[i]);
 
 3070             u32vector().swap(newmodified);
 
 3071             modsize = modified.size();
 
 3073                 ibegin = modified.begin();
 
 3074                 iend = modified.end();
 
 3075                 for (iit=ibegin; iit!=iend; iit++){
 
 3077                     if (!octants[idx].getNotBalance()){
 
 3078                         targetmarker = min(MAX_LEVEL_3D, (octants[idx].getLevel()+octants[idx].getMarker()));
 
 3081                         for (iface=0; iface<global3D.
nfaces; iface++){
 
 3082                             if(!octants[idx].getPbound(iface)){
 
 3083                                 findNeighbours(idx, iface, neigh, isghost);
 
 3084                                 sizeneigh = neigh.size();
 
 3085                                 for(i=0; i<sizeneigh; i++){
 
 3088                                             if((octants[neigh[i]].getLevel() + octants[neigh[i]].getMarker()) >  (targetmarker + 1)){
 
 3089                                                 octants[idx].setMarker(octants[neigh[i]].getLevel()+octants[neigh[i]].getMarker()-octants[idx].getLevel()-1);
 
 3090                                                 octants[idx].info[15] = 
true;
 
 3091                                                 newmodified.push_back(idx);
 
 3094                                             else if((octants[neigh[i]].getLevel() + octants[neigh[i]].getMarker()) < (targetmarker - 1)){
 
 3095                                                 octants[neigh[i]].setMarker(targetmarker-octants[neigh[i]].getLevel()-1);
 
 3096                                                 octants[neigh[i]].info[15] = 
true;
 
 3097                                                 newmodified.push_back(neigh[i]);
 
 3106                         if (balance_codim>1){
 
 3108                             for (iedge=0; iedge<global3D.
nedges; iedge++){
 
 3109                                 if(!octants[idx].getPbound(global3D.
edgeface[iedge][0]) || !octants[idx].getPbound(global3D.
edgeface[iedge][1])){
 
 3110                                     findEdgeNeighbours(idx, iedge, neigh, isghost);
 
 3111                                     sizeneigh = neigh.size();
 
 3112                                     for(i=0; i<sizeneigh; i++){
 
 3115                                                 if((octants[neigh[i]].getLevel() + octants[neigh[i]].getMarker()) >  (targetmarker + 1)){
 
 3116                                                     octants[idx].setMarker(octants[neigh[i]].getLevel()+octants[neigh[i]].getMarker()-octants[idx].getLevel()-1);
 
 3117                                                     octants[idx].info[15] = 
true;
 
 3118                                                     newmodified.push_back(idx);
 
 3121                                                 else if((octants[neigh[i]].getLevel() + octants[neigh[i]].getMarker()) < (targetmarker - 1)){
 
 3122                                                     octants[neigh[i]].setMarker(targetmarker-octants[neigh[i]].getLevel()-1);
 
 3123                                                     octants[neigh[i]].info[15] = 
true;
 
 3124                                                     newmodified.push_back(neigh[i]);
 
 3134                         if (balance_codim>2){
 
 3136                             for (inode=0; inode<global3D.
nnodes; inode++){
 
 3137                                 if(!octants[idx].getPbound(global3D.
nodeface[inode][0]) || !octants[idx].getPbound(global3D.
nodeface[inode][1]) || !octants[idx].getPbound(global3D.
nodeface[inode][2])){
 
 3138                                     findNodeNeighbours(idx, inode, neigh, isghost);
 
 3139                                     sizeneigh = neigh.size();
 
 3140                                     for(i=0; i<sizeneigh; i++){
 
 3143                                                 if((octants[neigh[i]].getLevel() + octants[neigh[i]].getMarker()) >  (targetmarker + 1)){
 
 3144                                                     octants[idx].setMarker(octants[neigh[i]].getLevel()+octants[neigh[i]].getMarker()-octants[idx].getLevel()-1);
 
 3145                                                     octants[idx].info[15] = 
true;
 
 3146                                                     newmodified.push_back(idx);
 
 3149                                                 else if((octants[neigh[i]].getLevel() + octants[neigh[i]].getMarker()) < (targetmarker - 1)){
 
 3150                                                     octants[neigh[i]].setMarker(targetmarker-octants[neigh[i]].getLevel()-1);
 
 3151                                                     octants[neigh[i]].info[15] = 
true;
 
 3152                                                     newmodified.push_back(neigh[i]);
 
 3164                 preBalance21(newmodified);
 
 3165                 u32vector().swap(modified);
 
 3166                 swap(modified,newmodified);
 
 3167                 modsize = modified.size();
 
 3168                 u32vector().swap(newmodified);
 
 3170             obegin = oend = octants.end();
 
 3171             ibegin = iend = modified.end();
 
 3179     bool localBalanceAll(
bool doInterior){              
 
 3183         uint32_t            sizeneigh, modsize;
 
 3185         u32vector           modified, newmodified;
 
 3187         uint8_t             iface, iedge, inode;
 
 3188         int8_t              targetmarker;
 
 3189         vector<bool>        isghost;
 
 3192         OctantsType::iterator   obegin, oend, it;
 
 3193         u32vector::iterator     ibegin, iend, iit;
 
 3199             obegin = octants.begin();
 
 3200             oend = octants.end();
 
 3202             for (it=obegin; it!=oend; it++){
 
 3203                 if ((!it->getNotBalance()) && ((it->info[15]) || (it->getMarker()!=0) || ((it->getIsNewC()) || (it->getIsNewR())))){
 
 3204                     targetmarker = min(MAX_LEVEL_3D, 
int(octants[idx].getLevel()) + 
int(octants[idx].getMarker()));
 
 3207                     for (iface=0; iface<global3D.
nfaces; iface++){
 
 3208                         if(!it->getBound(iface)){
 
 3209                             findNeighbours(idx, iface, neigh, isghost);
 
 3210                             sizeneigh = neigh.size();
 
 3211                             for(i=0; i<sizeneigh; i++){
 
 3214                                         if((octants[neigh[i]].getLevel() + octants[neigh[i]].getMarker()) > (targetmarker + 1) ){
 
 3215                                             octants[idx].setMarker(octants[neigh[i]].getLevel()+octants[neigh[i]].getMarker()-1-octants[idx].getLevel());
 
 3216                                             octants[idx].info[15] = 
true;
 
 3217                                             modified.push_back(idx);
 
 3220                                         else if((octants[neigh[i]].getLevel() + octants[neigh[i]].getMarker()) < (targetmarker - 1)){
 
 3221                                             octants[neigh[i]].setMarker(targetmarker-octants[neigh[i]].getLevel()-1);
 
 3222                                             octants[neigh[i]].info[15] = 
true;
 
 3223                                             modified.push_back(neigh[i]);
 
 3230                                         if((ghosts[neigh[i]].getLevel() + ghosts[neigh[i]].getMarker()) > (targetmarker + 1) ){
 
 3231                                             octants[idx].setMarker(ghosts[neigh[i]].getLevel()+ghosts[neigh[i]].getMarker()-1-octants[idx].getLevel());
 
 3232                                             octants[idx].info[15] = 
true;
 
 3233                                             modified.push_back(idx);
 
 3243                     if (balance_codim>1){
 
 3245                         for (iedge=0; iedge<global3D.
nedges; iedge++){
 
 3246                             if(!it->getBound(global3D.
edgeface[iedge][0]) && !it->getBound(global3D.
edgeface[iedge][1])){
 
 3247                                 findEdgeNeighbours(idx, iedge, neigh, isghost);
 
 3248                                 sizeneigh = neigh.size();
 
 3249                                 for(i=0; i<sizeneigh; i++){
 
 3252                                             if((octants[neigh[i]].getLevel() + octants[neigh[i]].getMarker()) > (targetmarker + 1) ){
 
 3253                                                 octants[idx].setMarker(octants[neigh[i]].getLevel()+octants[neigh[i]].getMarker()-1-octants[idx].getLevel());
 
 3254                                                 octants[idx].info[15] = 
true;
 
 3255                                                 modified.push_back(idx);
 
 3258                                             else if((octants[neigh[i]].getLevel() + octants[neigh[i]].getMarker()) < (targetmarker - 1)){
 
 3259                                                 octants[neigh[i]].setMarker(targetmarker-octants[neigh[i]].getLevel()-1);
 
 3260                                                 octants[neigh[i]].info[15] = 
true;
 
 3261                                                 modified.push_back(neigh[i]);
 
 3267                                         if((ghosts[neigh[i]].getLevel() + ghosts[neigh[i]].getMarker()) > (targetmarker + 1) ){
 
 3268                                             octants[idx].setMarker(ghosts[neigh[i]].getLevel()+ghosts[neigh[i]].getMarker()-1-octants[idx].getLevel());
 
 3269                                             octants[idx].info[15] = 
true;
 
 3270                                             modified.push_back(idx);
 
 3279                     if (balance_codim>2){
 
 3281                         for (inode=0; inode<global3D.
nnodes; inode++){
 
 3282                             if(!it->getBound(global3D.
nodeface[inode][0]) && !it->getBound(global3D.
nodeface[inode][1]) && !it->getBound(global3D.
nodeface[inode][2])){
 
 3283                                 findNodeNeighbours(idx, inode, neigh, isghost);
 
 3284                                 sizeneigh = neigh.size();
 
 3285                                 for(i=0; i<sizeneigh; i++){
 
 3288                                             if((octants[neigh[i]].getLevel() + octants[neigh[i]].getMarker()) > (targetmarker + 1) ){
 
 3289                                                 octants[idx].setMarker(octants[neigh[i]].getLevel()+octants[neigh[i]].getMarker()-1-octants[idx].getLevel());
 
 3290                                                 octants[idx].info[15] = 
true;
 
 3291                                                 modified.push_back(idx);
 
 3294                                             else if((octants[neigh[i]].getLevel() + octants[neigh[i]].getMarker()) < (targetmarker - 1)){
 
 3295                                                 octants[neigh[i]].setMarker(targetmarker-octants[neigh[i]].getLevel()-1);
 
 3296                                                 octants[neigh[i]].info[15] = 
true;
 
 3297                                                 modified.push_back(neigh[i]);
 
 3303                                         if((ghosts[neigh[i]].getLevel() + ghosts[neigh[i]].getMarker()) > (targetmarker + 1) ){
 
 3304                                             octants[idx].setMarker(ghosts[neigh[i]].getLevel()+ghosts[neigh[i]].getMarker()-1-octants[idx].getLevel());
 
 3305                                             octants[idx].info[15] = 
true;
 
 3306                                             modified.push_back(idx);
 
 3319             obegin = ghosts.begin();
 
 3320             oend = ghosts.end();
 
 3322             for (it=obegin; it!=oend; it++){
 
 3323                 if (!it->getNotBalance() && (it->info[15] || (it->getIsNewC() || it->getIsNewR()))){
 
 3324                     targetmarker = min(MAX_LEVEL_3D, (it->getLevel()+it->getMarker()));
 
 3327                     for (iface=0; iface<global3D.
nfaces; iface++){
 
 3328                         if(it->getPbound(iface) == 
true){
 
 3330                             findGhostNeighbours(idx, iface, neigh);
 
 3331                             sizeneigh = neigh.size();
 
 3332                             for(i=0; i<sizeneigh; i++){
 
 3333                                 if((octants[neigh[i]].getLevel() + octants[neigh[i]].getMarker()) < (targetmarker - 1)){
 
 3334                                     octants[neigh[i]].setMarker(targetmarker-octants[neigh[i]].getLevel()-1);
 
 3335                                     octants[neigh[i]].info[15] = 
true;
 
 3336                                     modified.push_back(neigh[i]);
 
 3343                     if (balance_codim>1){
 
 3345                         for (iedge=0; iedge<global3D.
nedges; iedge++){
 
 3346                             if(it->getPbound(global3D.
nodeface[iedge][0]) == 
true || it->getPbound(global3D.
nodeface[iedge][1]) == 
true){
 
 3348                                 findGhostEdgeNeighbours(idx, iedge, neigh);
 
 3349                                 sizeneigh = neigh.size();
 
 3350                                 for(i=0; i<sizeneigh; i++){
 
 3351                                     if((octants[neigh[i]].getLevel() + octants[neigh[i]].getMarker()) < (targetmarker - 1)){
 
 3352                                         octants[neigh[i]].setMarker(targetmarker-octants[neigh[i]].getLevel()-1);
 
 3353                                         octants[neigh[i]].info[15] = 
true;
 
 3354                                         modified.push_back(neigh[i]);
 
 3362                     if (balance_codim>2){
 
 3364                         for (inode=0; inode<global3D.
nnodes; inode++){
 
 3365                             if(it->getPbound(global3D.
nodeface[inode][0]) == 
true || it->getPbound(global3D.
nodeface[inode][1]) == 
true || it->getPbound(global3D.
nodeface[inode][2]) == 
true){
 
 3367                                 findGhostNodeNeighbours(idx, inode, neigh);
 
 3368                                 sizeneigh = neigh.size();
 
 3369                                 for(i=0; i<sizeneigh; i++){
 
 3370                                     if((octants[neigh[i]].getLevel() + octants[neigh[i]].getMarker()) < (targetmarker - 1)){
 
 3371                                         octants[neigh[i]].setMarker(targetmarker-octants[neigh[i]].getLevel()-1);
 
 3372                                         octants[neigh[i]].info[15] = 
true;
 
 3373                                         modified.push_back(neigh[i]);
 
 3386             u32vector().swap(newmodified);
 
 3387             modsize = modified.size();
 
 3389                 ibegin = modified.begin();
 
 3390                 iend = modified.end();
 
 3391                 for (iit=ibegin; iit!=iend; iit++){
 
 3393                     if (!octants[idx].getNotBalance()){
 
 3394                         targetmarker = min(MAX_LEVEL_3D, (octants[idx].getLevel()+octants[idx].getMarker()));
 
 3397                         for (iface=0; iface<global3D.
nfaces; iface++){
 
 3398                             if(!octants[idx].getPbound(iface)){
 
 3399                                 findNeighbours(idx, iface, neigh, isghost);
 
 3400                                 sizeneigh = neigh.size();
 
 3401                                 for(i=0; i<sizeneigh; i++){
 
 3404                                             if((octants[neigh[i]].getLevel() + octants[neigh[i]].getMarker()) >  (targetmarker + 1)){
 
 3405                                                 octants[idx].setMarker(octants[neigh[i]].getLevel()+octants[neigh[i]].getMarker()-octants[idx].getLevel()-1);
 
 3406                                                 octants[idx].info[15] = 
true;
 
 3407                                                 newmodified.push_back(idx);
 
 3410                                             else if((octants[neigh[i]].getLevel() + octants[neigh[i]].getMarker()) < (targetmarker - 1)){
 
 3411                                                 octants[neigh[i]].setMarker(targetmarker-octants[neigh[i]].getLevel()-1);
 
 3412                                                 octants[neigh[i]].info[15] = 
true;
 
 3413                                                 newmodified.push_back(neigh[i]);
 
 3422                         if (balance_codim>1){
 
 3424                             for (iedge=0; iedge<global3D.
nedges; iedge++){
 
 3425                                 if(!octants[idx].getPbound(global3D.
edgeface[iedge][0]) || !octants[idx].getPbound(global3D.
edgeface[iedge][1])){
 
 3426                                     findEdgeNeighbours(idx, iedge, neigh, isghost);
 
 3427                                     sizeneigh = neigh.size();
 
 3428                                     for(i=0; i<sizeneigh; i++){
 
 3431                                                 if((octants[neigh[i]].getLevel() + octants[neigh[i]].getMarker()) >  (targetmarker + 1)){
 
 3432                                                     octants[idx].setMarker(octants[neigh[i]].getLevel()+octants[neigh[i]].getMarker()-octants[idx].getLevel()-1);
 
 3433                                                     octants[idx].info[15] = 
true;
 
 3434                                                     newmodified.push_back(idx);
 
 3437                                                 else if((octants[neigh[i]].getLevel() + octants[neigh[i]].getMarker()) < (targetmarker - 1)){
 
 3438                                                     octants[neigh[i]].setMarker(targetmarker-octants[neigh[i]].getLevel()-1);
 
 3439                                                     octants[neigh[i]].info[15] = 
true;
 
 3440                                                     newmodified.push_back(neigh[i]);
 
 3450                         if (balance_codim>2){
 
 3452                             for (inode=0; inode<global3D.
nnodes; inode++){
 
 3453                                 if(!octants[idx].getPbound(global3D.
nodeface[inode][0]) || !octants[idx].getPbound(global3D.
nodeface[inode][1]) || !octants[idx].getPbound(global3D.
nodeface[inode][2])){
 
 3454                                     findNodeNeighbours(idx, inode, neigh, isghost);
 
 3455                                     sizeneigh = neigh.size();
 
 3456                                     for(i=0; i<sizeneigh; i++){
 
 3459                                                 if((octants[neigh[i]].getLevel() + octants[neigh[i]].getMarker()) >  (targetmarker + 1)){
 
 3460                                                     octants[idx].setMarker(octants[neigh[i]].getLevel()+octants[neigh[i]].getMarker()-octants[idx].getLevel()-1);
 
 3461                                                     octants[idx].info[15] = 
true;
 
 3462                                                     newmodified.push_back(idx);
 
 3465                                                 else if((octants[neigh[i]].getLevel() + octants[neigh[i]].getMarker()) < (targetmarker - 1)){
 
 3466                                                     octants[neigh[i]].setMarker(targetmarker-octants[neigh[i]].getLevel()-1);
 
 3467                                                     octants[neigh[i]].info[15] = 
true;
 
 3468                                                     newmodified.push_back(neigh[i]);
 
 3480                 preBalance21(newmodified);
 
 3481                 u32vector().swap(modified);
 
 3482                 swap(modified,newmodified);
 
 3483                 modsize = modified.size();
 
 3484                 u32vector().swap(newmodified);
 
 3491             obegin = ghosts.begin();
 
 3492             oend = ghosts.end();
 
 3494             for (it=obegin; it!=oend; it++){
 
 3495                 if (!it->getNotBalance() && (it->info[15] || (it->getIsNewC() || it->getIsNewR()))){
 
 3496                     targetmarker = min(MAX_LEVEL_3D, (it->getLevel()+it->getMarker()));
 
 3499                     for (iface=0; iface<global3D.
nfaces; iface++){
 
 3500                         if(it->getPbound(iface) == 
true){
 
 3502                             findGhostNeighbours(idx, iface, neigh);
 
 3503                             sizeneigh = neigh.size();
 
 3504                             for(i=0; i<sizeneigh; i++){
 
 3505                                 if((octants[neigh[i]].getLevel() + octants[neigh[i]].getMarker()) < (targetmarker - 1)){
 
 3506                                     octants[neigh[i]].setMarker(targetmarker-octants[neigh[i]].getLevel()-1);
 
 3507                                     octants[neigh[i]].info[15] = 
true;
 
 3508                                     modified.push_back(neigh[i]);
 
 3515                     if (balance_codim>1){
 
 3517                         for (iedge=0; iedge<global3D.
nedges; iedge++){
 
 3518                             if(it->getPbound(global3D.
nodeface[iedge][0]) == 
true || it->getPbound(global3D.
nodeface[iedge][1]) == 
true){
 
 3520                                 findGhostEdgeNeighbours(idx, iedge, neigh);
 
 3521                                 sizeneigh = neigh.size();
 
 3522                                 for(i=0; i<sizeneigh; i++){
 
 3523                                     if((octants[neigh[i]].getLevel() + octants[neigh[i]].getMarker()) < (targetmarker - 1)){
 
 3524                                         octants[neigh[i]].setMarker(targetmarker-octants[neigh[i]].getLevel()-1);
 
 3525                                         octants[neigh[i]].info[15] = 
true;
 
 3526                                         modified.push_back(neigh[i]);
 
 3534                     if (balance_codim>2){
 
 3536                         for (inode=0; inode<global3D.
nnodes; inode++){
 
 3537                             if(it->getPbound(global3D.
nodeface[inode][0]) == 
true || it->getPbound(global3D.
nodeface[inode][1]) == 
true || it->getPbound(global3D.
nodeface[inode][2]) == 
true){
 
 3539                                 findGhostNodeNeighbours(idx, inode, neigh);
 
 3540                                 sizeneigh = neigh.size();
 
 3541                                 for(i=0; i<sizeneigh; i++){
 
 3542                                     if((octants[neigh[i]].getLevel() + octants[neigh[i]].getMarker()) < (targetmarker - 1)){
 
 3543                                         octants[neigh[i]].setMarker(targetmarker-octants[neigh[i]].getLevel()-1);
 
 3544                                         octants[neigh[i]].info[15] = 
true;
 
 3545                                         modified.push_back(neigh[i]);
 
 3558             u32vector().swap(newmodified);
 
 3559             modsize = modified.size();
 
 3561                 ibegin = modified.begin();
 
 3562                 iend = modified.end();
 
 3563                 for (iit=ibegin; iit!=iend; iit++){
 
 3565                     if (!octants[idx].getNotBalance()){
 
 3566                         targetmarker = min(MAX_LEVEL_3D, (octants[idx].getLevel()+octants[idx].getMarker()));
 
 3569                         for (iface=0; iface<global3D.
nfaces; iface++){
 
 3570                             if(!octants[idx].getPbound(iface)){
 
 3571                                 findNeighbours(idx, iface, neigh, isghost);
 
 3572                                 sizeneigh = neigh.size();
 
 3573                                 for(i=0; i<sizeneigh; i++){
 
 3576                                             if((octants[neigh[i]].getLevel() + octants[neigh[i]].getMarker()) >  (targetmarker + 1)){
 
 3577                                                 octants[idx].setMarker(octants[neigh[i]].getLevel()+octants[neigh[i]].getMarker()-octants[idx].getLevel()-1);
 
 3578                                                 octants[idx].info[15] = 
true;
 
 3579                                                 newmodified.push_back(idx);
 
 3582                                             else if((octants[neigh[i]].getLevel() + octants[neigh[i]].getMarker()) < (targetmarker - 1)){
 
 3583                                                 octants[neigh[i]].setMarker(targetmarker-octants[neigh[i]].getLevel()-1);
 
 3584                                                 octants[neigh[i]].info[15] = 
true;
 
 3585                                                 newmodified.push_back(neigh[i]);
 
 3594                         if (balance_codim>1){
 
 3596                             for (iedge=0; iedge<global3D.
nedges; iedge++){
 
 3597                                 if(!octants[idx].getPbound(global3D.
edgeface[iedge][0]) || !octants[idx].getPbound(global3D.
edgeface[iedge][1])){
 
 3598                                     findEdgeNeighbours(idx, iedge, neigh, isghost);
 
 3599                                     sizeneigh = neigh.size();
 
 3600                                     for(i=0; i<sizeneigh; i++){
 
 3603                                                 if((octants[neigh[i]].getLevel() + octants[neigh[i]].getMarker()) >  (targetmarker + 1)){
 
 3604                                                     octants[idx].setMarker(octants[neigh[i]].getLevel()+octants[neigh[i]].getMarker()-octants[idx].getLevel()-1);
 
 3605                                                     octants[idx].info[15] = 
true;
 
 3606                                                     newmodified.push_back(idx);
 
 3609                                                 else if((octants[neigh[i]].getLevel() + octants[neigh[i]].getMarker()) < (targetmarker - 1)){
 
 3610                                                     octants[neigh[i]].setMarker(targetmarker-octants[neigh[i]].getLevel()-1);
 
 3611                                                     octants[neigh[i]].info[15] = 
true;
 
 3612                                                     newmodified.push_back(neigh[i]);
 
 3622                         if (balance_codim>2){
 
 3624                             for (inode=0; inode<global3D.
nnodes; inode++){
 
 3625                                 if(!octants[idx].getPbound(global3D.
nodeface[inode][0]) || !octants[idx].getPbound(global3D.
nodeface[inode][1]) || !octants[idx].getPbound(global3D.
nodeface[inode][2])){
 
 3626                                     findNodeNeighbours(idx, inode, neigh, isghost);
 
 3627                                     sizeneigh = neigh.size();
 
 3628                                     for(i=0; i<sizeneigh; i++){
 
 3631                                                 if((octants[neigh[i]].getLevel() + octants[neigh[i]].getMarker()) >  (targetmarker + 1)){
 
 3632                                                     octants[idx].setMarker(octants[neigh[i]].getLevel()+octants[neigh[i]].getMarker()-octants[idx].getLevel()-1);
 
 3633                                                     octants[idx].info[15] = 
true;
 
 3634                                                     newmodified.push_back(idx);
 
 3637                                                 else if((octants[neigh[i]].getLevel() + octants[neigh[i]].getMarker()) < (targetmarker - 1)){
 
 3638                                                     octants[neigh[i]].setMarker(targetmarker-octants[neigh[i]].getLevel()-1);
 
 3639                                                     octants[neigh[i]].info[15] = 
true;
 
 3640                                                     newmodified.push_back(neigh[i]);
 
 3652                 preBalance21(newmodified);
 
 3653                 u32vector().swap(modified);
 
 3654                 swap(modified,newmodified);
 
 3655                 modsize = modified.size();
 
 3656                 u32vector().swap(newmodified);
 
 3658             obegin = oend = octants.end();
 
 3659             ibegin = iend = modified.end();
 
 3667     void findEdgeNeighbours(uint32_t idx,           
 
 3669             u32vector & neighbours,     
 
 3670             vector<bool> & isghost){    
 
 3672         uint64_t  Morton, Mortontry;
 
 3673         uint32_t  noctants = getNumOctants();
 
 3676         uint32_t size = oct->
getSize();
 
 3677         uint8_t iface1, iface2;
 
 3679         int32_t Dxstar,Dystar,Dzstar;
 
 3693         if (iedge < 0 || iedge > global3D.
nfaces*2){
 
 3698         iface1 = global3D.
edgeface[iedge][0];
 
 3699         iface2 = global3D.
edgeface[iedge][1];
 
 3702         if (oct->info[iface1] == 
false && oct->info[iface2] == 
false){
 
 3705             Class_Octant<3> samesizeoct(oct->level, oct->x+cx*size, oct->y+cy*size, oct->z+cz*size);
 
 3710             if (ghosts.size()>0){
 
 3712                 uint32_t idxghost = uint32_t(size_ghosts/2);
 
 3718                 int32_t jump = int32_t(idxghost/2);
 
 3720                 if (idxtry > ghosts.size()-1) idxtry = ghosts.size()-1;
 
 3721                 while(abs(jump) > 0){
 
 3722                     Mortontry = ghosts[idxtry].computeMorton();
 
 3723                     jump = ((Mortontry<Morton)-(Mortontry>Morton))*abs(jump)/2;
 
 3725                     if (idxtry > ghosts.size()-1){
 
 3727                             idxtry = ghosts.size() - 1;
 
 3736                 if(ghosts[idxtry].computeMorton() == Morton && ghosts[idxtry].level == oct->level){
 
 3738                     isghost.push_back(
true);
 
 3739                     neighbours.push_back(idxtry);
 
 3745                         while(ghosts[idxtry].computeMorton() < Morton){
 
 3747                             if(idxtry > ghosts.size()-1){
 
 3748                                 idxtry = ghosts.size()-1;
 
 3752                         while(ghosts[idxtry].computeMorton() > Morton){
 
 3754                             if(idxtry > ghosts.size()-1){
 
 3760                     if(idxtry < size_ghosts){
 
 3761                         if(ghosts[idxtry].computeMorton() == Morton && ghosts[idxtry].level == oct->level){
 
 3763                             isghost.push_back(
true);
 
 3764                             neighbours.push_back(idxtry);
 
 3770                         Mortontry = ghosts[idxtry].computeMorton();
 
 3771                         while(Mortontry < Mortonlast && idxtry < ghosts.size()){
 
 3772                             Dx = int32_t(abs(cx))*(-int32_t(oct->x) + int32_t(ghosts[idxtry].x));
 
 3773                             Dy = int32_t(abs(cy))*(-int32_t(oct->y) + int32_t(ghosts[idxtry].y));
 
 3774                             Dz = int32_t(abs(cz))*(-int32_t(oct->z) + int32_t(ghosts[idxtry].z));
 
 3775                             Dxstar = int32_t((cx-1)/2)*(ghosts[idxtry].getSize()) + int32_t((cx+1)/2)*size;
 
 3776                             Dystar = int32_t((cy-1)/2)*(ghosts[idxtry].getSize()) + int32_t((cy+1)/2)*size;
 
 3777                             Dzstar = int32_t((cz-1)/2)*(ghosts[idxtry].getSize()) + int32_t((cz+1)/2)*size;
 
 3779                             uint32_t x0 = oct->x;
 
 3780                             uint32_t x1 = x0 + size;
 
 3781                             uint32_t y0 = oct->y;
 
 3782                             uint32_t y1 = y0 + size;
 
 3783                             uint32_t z0 = oct->z;
 
 3784                             uint32_t z1 = z0 + size;
 
 3785                             uint32_t x0try = ghosts[idxtry].x;
 
 3786                             uint32_t x1try = x0try + ghosts[idxtry].getSize();
 
 3787                             uint32_t y0try = ghosts[idxtry].y;
 
 3788                             uint32_t y1try = y0try + ghosts[idxtry].getSize();
 
 3789                             uint32_t z0try = ghosts[idxtry].z;
 
 3790                             uint32_t z1try = z0try + ghosts[idxtry].getSize();
 
 3791                             uint8_t level = oct->level;
 
 3792                             uint8_t leveltry = ghosts[idxtry].getLevel();
 
 3794                             if (Dx == Dxstar && Dy == Dystar && Dz == Dzstar){
 
 3795                                 if (leveltry > level){
 
 3796                                     if((abs(cx)*abs(cz)*((y0try>=y0)*(y0try<y1))) + (abs(cy)*abs(cz)*((x0try>=x0)*(x0try<x1))) + (abs(cx)*abs(cy)*((z0try>=z0)*(z0try<z1)))){
 
 3797                                         neighbours.push_back(idxtry);
 
 3798                                         isghost.push_back(
true);
 
 3801                                 if (leveltry < level){
 
 3802                                     if((abs(cx)*abs(cz)*((y0>=y0try)*(y0<y1try))) + (abs(cy)*abs(cz)*((x0>=x0try)*(x0<x1try))) + (abs(cx)*abs(cy)*((z0>=z0try)*(z0<z1try)))){
 
 3803                                         neighbours.push_back(idxtry);
 
 3804                                         isghost.push_back(
true);
 
 3810                             if(idxtry>size_ghosts-1){
 
 3813                             Mortontry = ghosts[idxtry].computeMorton();
 
 3827             int32_t jump = (oct->
computeMorton() > Morton) ? int32_t(idx/2+1) : int32_t((noctants -idx)/2+1);
 
 3829             if (idxtry > noctants-1)
 
 3830                 idxtry = noctants-1;
 
 3831             while(abs(jump) > 0){
 
 3832                 Mortontry = octants[idxtry].computeMorton();
 
 3833                 jump = ((Mortontry<Morton)-(Mortontry>Morton))*abs(jump)/2;
 
 3835                 if (idxtry > octants.size()-1){
 
 3837                         idxtry = octants.size() - 1;
 
 3846             if(octants[idxtry].computeMorton() == Morton && octants[idxtry].level == oct->level){
 
 3848                 isghost.push_back(
false);
 
 3849                 neighbours.push_back(idxtry);
 
 3855                     while(octants[idxtry].computeMorton() < Morton){
 
 3857                         if(idxtry > noctants-1){
 
 3858                             idxtry = noctants-1;
 
 3862                     while(octants[idxtry].computeMorton() > Morton){
 
 3864                         if(idxtry > noctants-1){
 
 3870                 if (idxtry < noctants){
 
 3871                     if(octants[idxtry].computeMorton() == Morton && octants[idxtry].level == oct->level){
 
 3873                         isghost.push_back(
false);
 
 3874                         neighbours.push_back(idxtry);
 
 3880                     Mortontry = octants[idxtry].computeMorton();
 
 3881                     while(Mortontry < Mortonlast && idxtry <= noctants-1){
 
 3882                         Dx = int32_t(abs(cx))*(-int32_t(oct->x) + int32_t(octants[idxtry].x));
 
 3883                         Dy = int32_t(abs(cy))*(-int32_t(oct->y) + int32_t(octants[idxtry].y));
 
 3884                         Dz = int32_t(abs(cz))*(-int32_t(oct->z) + int32_t(octants[idxtry].z));
 
 3885                         Dxstar = int32_t((cx-1)/2)*(octants[idxtry].getSize()) + int32_t((cx+1)/2)*size;
 
 3886                         Dystar = int32_t((cy-1)/2)*(octants[idxtry].getSize()) + int32_t((cy+1)/2)*size;
 
 3887                         Dzstar = int32_t((cz-1)/2)*(octants[idxtry].getSize()) + int32_t((cz+1)/2)*size;
 
 3889                         uint32_t x0 = oct->x;
 
 3890                         uint32_t x1 = x0 + size;
 
 3891                         uint32_t y0 = oct->y;
 
 3892                         uint32_t y1 = y0 + size;
 
 3893                         uint32_t z0 = oct->z;
 
 3894                         uint32_t z1 = z0 + size;
 
 3895                         uint32_t x0try = octants[idxtry].x;
 
 3896                         uint32_t x1try = x0try + octants[idxtry].getSize();
 
 3897                         uint32_t y0try = octants[idxtry].y;
 
 3898                         uint32_t y1try = y0try + octants[idxtry].getSize();
 
 3899                         uint32_t z0try = octants[idxtry].z;
 
 3900                         uint32_t z1try = z0try + octants[idxtry].getSize();
 
 3901                         uint8_t level = oct->level;
 
 3902                         uint8_t leveltry = octants[idxtry].getLevel();
 
 3904                         if (Dx == Dxstar && Dy == Dystar && Dz == Dzstar){
 
 3905                             if (leveltry > level){
 
 3906                                 if((abs(cx)*abs(cz)*((y0try>=y0)*(y0try<y1))) + (abs(cy)*abs(cz)*((x0try>=x0)*(x0try<x1))) + (abs(cx)*abs(cy)*((z0try>=z0)*(z0try<z1)))){
 
 3907                                     neighbours.push_back(idxtry);
 
 3908                                     isghost.push_back(
false);
 
 3911                             if (leveltry < level){
 
 3912                                 if((abs(cx)*abs(cz)*((y0>=y0try)*(y0<y1try))) + (abs(cy)*abs(cz)*((x0>=x0try)*(x0<x1try))) + (abs(cx)*abs(cy)*((z0>=z0try)*(z0<z1try)))){
 
 3913                                     neighbours.push_back(idxtry);
 
 3914                                     isghost.push_back(
false);
 
 3920                         if(idxtry>noctants-1){
 
 3923                         Mortontry = octants[idxtry].computeMorton();
 
 3939             u32vector & neighbours,     
 
 3940             vector<bool> & isghost){    
 
 3942         uint64_t  Morton, Mortontry;
 
 3943         uint32_t  noctants = getNumOctants();
 
 3945         uint32_t size = oct->
getSize();
 
 3946         uint8_t iface1, iface2;
 
 3948         int32_t Dxstar,Dystar,Dzstar;
 
 3962         if (iedge < 0 || iedge > global3D.
nfaces*2){
 
 3967         iface1 = global3D.
edgeface[iedge][0];
 
 3968         iface2 = global3D.
edgeface[iedge][1];
 
 3971         if (oct->info[iface1] == 
false && oct->info[iface2] == 
false){
 
 3974             Class_Octant<3> samesizeoct(oct->level, oct->x+cx*size, oct->y+cy*size, oct->z+cz*size);
 
 3979             if (ghosts.size()>0){
 
 3981                 uint32_t idxghost = uint32_t(size_ghosts/2);
 
 3987                 int32_t jump = int32_t(idxghost/2+1);
 
 3989                 while(abs(jump) > 0){
 
 3990                     Mortontry = ghosts[idxtry].computeMorton();
 
 3991                     jump = ((Mortontry<Morton)-(Mortontry>Morton))*abs(jump)/2;
 
 3993                     if (idxtry > ghosts.size()-1){
 
 3995                             idxtry = ghosts.size() - 1;
 
 4004                 if(ghosts[idxtry].computeMorton() == Morton && ghosts[idxtry].level == oct->level){
 
 4006                     isghost.push_back(
true);
 
 4007                     neighbours.push_back(idxtry);
 
 4013                         while(ghosts[idxtry].computeMorton() < Morton){
 
 4015                             if(idxtry > ghosts.size()-1){
 
 4016                                 idxtry = ghosts.size()-1;
 
 4020                         while(ghosts[idxtry].computeMorton() > Morton){
 
 4022                             if(idxtry > ghosts.size()-1){
 
 4028                     if(idxtry < size_ghosts){
 
 4029                         if(ghosts[idxtry].computeMorton() == Morton && ghosts[idxtry].level == oct->level){
 
 4031                             isghost.push_back(
true);
 
 4032                             neighbours.push_back(idxtry);
 
 4038                         Mortontry = ghosts[idxtry].computeMorton();
 
 4039                         while(Mortontry < Mortonlast && idxtry < ghosts.size()){
 
 4040                             Dx = int32_t(abs(cx))*(-int32_t(oct->x) + int32_t(ghosts[idxtry].x));
 
 4041                             Dy = int32_t(abs(cy))*(-int32_t(oct->y) + int32_t(ghosts[idxtry].y));
 
 4042                             Dz = int32_t(abs(cz))*(-int32_t(oct->z) + int32_t(ghosts[idxtry].z));
 
 4043                             Dxstar = int32_t((cx-1)/2)*(ghosts[idxtry].getSize()) + int32_t((cx+1)/2)*size;
 
 4044                             Dystar = int32_t((cy-1)/2)*(ghosts[idxtry].getSize()) + int32_t((cy+1)/2)*size;
 
 4045                             Dzstar = int32_t((cz-1)/2)*(ghosts[idxtry].getSize()) + int32_t((cz+1)/2)*size;
 
 4047                             uint32_t x0 = oct->x;
 
 4048                             uint32_t x1 = x0 + size;
 
 4049                             uint32_t y0 = oct->y;
 
 4050                             uint32_t y1 = y0 + size;
 
 4051                             uint32_t z0 = oct->z;
 
 4052                             uint32_t z1 = z0 + size;
 
 4053                             uint32_t x0try = ghosts[idxtry].x;
 
 4054                             uint32_t x1try = x0try + ghosts[idxtry].getSize();
 
 4055                             uint32_t y0try = ghosts[idxtry].y;
 
 4056                             uint32_t y1try = y0try + ghosts[idxtry].getSize();
 
 4057                             uint32_t z0try = ghosts[idxtry].z;
 
 4058                             uint32_t z1try = z0try + ghosts[idxtry].getSize();
 
 4059                             uint8_t level = oct->level;
 
 4060                             uint8_t leveltry = ghosts[idxtry].getLevel();
 
 4062                             if (Dx == Dxstar && Dy == Dystar && Dz == Dzstar){
 
 4063                                 if (leveltry > level){
 
 4064                                     if((abs(cx)*abs(cz)*((y0try>=y0)*(y0try<y1))) + (abs(cy)*abs(cz)*((x0try>=x0)*(x0try<x1))) + (abs(cx)*abs(cy)*((z0try>=z0)*(z0try<z1)))){
 
 4065                                         neighbours.push_back(idxtry);
 
 4066                                         isghost.push_back(
true);
 
 4069                                 if (leveltry < level){
 
 4070                                     if((abs(cx)*abs(cz)*((y0>=y0try)*(y0<y1try))) + (abs(cy)*abs(cz)*((x0>=x0try)*(x0<x1try))) + (abs(cx)*abs(cy)*((z0>=z0try)*(z0<z1try)))){
 
 4071                                         neighbours.push_back(idxtry);
 
 4072                                         isghost.push_back(
true);
 
 4078                             if(idxtry>size_ghosts-1){
 
 4081                             Mortontry = ghosts[idxtry].computeMorton();
 
 4093                 int32_t jump = int32_t((noctants)/2+1);
 
 4094                 idxtry = uint32_t(jump);
 
 4095                 if (idxtry > noctants-1)
 
 4096                     idxtry = noctants-1;
 
 4097                 while(abs(jump) > 0){
 
 4098                     Mortontry = octants[idxtry].computeMorton();
 
 4099                     jump = ((Mortontry<Morton)-(Mortontry>Morton))*abs(jump)/2;
 
 4101                     if (idxtry > octants.size()-1){
 
 4103                             idxtry = octants.size() - 1;
 
 4112                 if(octants[idxtry].computeMorton() == Morton && octants[idxtry].level == oct->level){
 
 4114                     isghost.push_back(
false);
 
 4115                     neighbours.push_back(idxtry);
 
 4121                         while(octants[idxtry].computeMorton() < Morton){
 
 4123                             if(idxtry > noctants-1){
 
 4124                                 idxtry = noctants-1;
 
 4128                         while(octants[idxtry].computeMorton() > Morton){
 
 4130                             if(idxtry > noctants-1){
 
 4136                     if (idxtry < noctants){
 
 4137                         if(octants[idxtry].computeMorton() == Morton && octants[idxtry].level == oct->level){
 
 4139                             isghost.push_back(
false);
 
 4140                             neighbours.push_back(idxtry);
 
 4146                         Mortontry = octants[idxtry].computeMorton();
 
 4147                         while(Mortontry < Mortonlast && idxtry <= noctants-1){
 
 4148                             Dx = int32_t(abs(cx))*(-int32_t(oct->x) + int32_t(octants[idxtry].x));
 
 4149                             Dy = int32_t(abs(cy))*(-int32_t(oct->y) + int32_t(octants[idxtry].y));
 
 4150                             Dz = int32_t(abs(cz))*(-int32_t(oct->z) + int32_t(octants[idxtry].z));
 
 4151                             Dxstar = int32_t((cx-1)/2)*(octants[idxtry].getSize()) + int32_t((cx+1)/2)*size;
 
 4152                             Dystar = int32_t((cy-1)/2)*(octants[idxtry].getSize()) + int32_t((cy+1)/2)*size;
 
 4153                             Dzstar = int32_t((cz-1)/2)*(octants[idxtry].getSize()) + int32_t((cz+1)/2)*size;
 
 4155                             uint32_t x0 = oct->x;
 
 4156                             uint32_t x1 = x0 + size;
 
 4157                             uint32_t y0 = oct->y;
 
 4158                             uint32_t y1 = y0 + size;
 
 4159                             uint32_t z0 = oct->z;
 
 4160                             uint32_t z1 = z0 + size;
 
 4161                             uint32_t x0try = octants[idxtry].x;
 
 4162                             uint32_t x1try = x0try + octants[idxtry].getSize();
 
 4163                             uint32_t y0try = octants[idxtry].y;
 
 4164                             uint32_t y1try = y0try + octants[idxtry].getSize();
 
 4165                             uint32_t z0try = octants[idxtry].z;
 
 4166                             uint32_t z1try = z0try + octants[idxtry].getSize();
 
 4167                             uint8_t level = oct->level;
 
 4168                             uint8_t leveltry = octants[idxtry].getLevel();
 
 4170                             if (Dx == Dxstar && Dy == Dystar && Dz == Dzstar){
 
 4171                                 if (leveltry > level){
 
 4172                                     if((abs(cx)*abs(cz)*((y0try>=y0)*(y0try<y1))) + (abs(cy)*abs(cz)*((x0try>=x0)*(x0try<x1))) + (abs(cx)*abs(cy)*((z0try>=z0)*(z0try<z1)))){
 
 4173                                         neighbours.push_back(idxtry);
 
 4174                                         isghost.push_back(
false);
 
 4177                                 if (leveltry < level){
 
 4178                                     if((abs(cx)*abs(cz)*((y0>=y0try)*(y0<y1try))) + (abs(cy)*abs(cz)*((x0>=x0try)*(x0<x1try))) + (abs(cx)*abs(cy)*((z0>=z0try)*(z0<z1try)))){
 
 4179                                         neighbours.push_back(idxtry);
 
 4180                                         isghost.push_back(
false);
 
 4186                             if(idxtry>noctants-1){
 
 4189                             Mortontry = octants[idxtry].computeMorton();
 
 4204     void findGhostEdgeNeighbours(uint32_t idx,      
 
 4206             u32vector & neighbours){                
 
 4208         uint64_t  Morton, Mortontry;
 
 4209         uint32_t  noctants = getNumOctants();
 
 4212         uint32_t size = oct->
getSize();
 
 4213         uint8_t iface1, iface2;
 
 4215         int32_t Dxstar,Dystar,Dzstar;
 
 4225         if (iedge < 0 || iedge > global3D.
nfaces*2){
 
 4230         iface1 = global3D.
edgeface[iedge][0];
 
 4231         iface2 = global3D.
edgeface[iedge][1];
 
 4234         if (oct->info[iface1+global3D.
nfaces] == 
true || oct->info[iface2+global3D.
nfaces] == 
true){
 
 4237             Class_Octant<3> samesizeoct(oct->level, oct->x+cx*size, oct->y+cy*size, oct->z+cz*size);
 
 4244             int32_t jump = getNumOctants()/2;
 
 4245             idxtry = uint32_t(getNumOctants()/2);
 
 4246             while(abs(jump) > 0){
 
 4247                 Mortontry = octants[idxtry].computeMorton();
 
 4248                 jump = ((Mortontry<Morton)-(Mortontry>Morton))*abs(jump)/2;
 
 4250                 if (idxtry > octants.size()-1){
 
 4252                         idxtry = octants.size() - 1;
 
 4261             if(octants[idxtry].computeMorton() == Morton && octants[idxtry].level == oct->level){
 
 4263                 neighbours.push_back(idxtry);
 
 4269                     while(octants[idxtry].computeMorton() < Morton){
 
 4271                         if(idxtry > noctants-1){
 
 4272                             idxtry = noctants-1;
 
 4276                     while(octants[idxtry].computeMorton() > Morton){
 
 4278                         if(idxtry > noctants-1){
 
 4284                 if (idxtry < noctants){
 
 4285                     if(octants[idxtry].computeMorton() == Morton && octants[idxtry].level == oct->level){
 
 4287                         neighbours.push_back(idxtry);
 
 4293                     Mortontry = octants[idxtry].computeMorton();
 
 4294                     while(Mortontry < Mortonlast && idxtry <= noctants-1){
 
 4295                         Dx = int32_t(abs(cx))*(-int32_t(oct->x) + int32_t(octants[idxtry].x));
 
 4296                         Dy = int32_t(abs(cy))*(-int32_t(oct->y) + int32_t(octants[idxtry].y));
 
 4297                         Dz = int32_t(abs(cz))*(-int32_t(oct->z) + int32_t(octants[idxtry].z));
 
 4298                         Dxstar = int32_t((cx-1)/2)*(octants[idxtry].getSize()) + int32_t((cx+1)/2)*size;
 
 4299                         Dystar = int32_t((cy-1)/2)*(octants[idxtry].getSize()) + int32_t((cy+1)/2)*size;
 
 4300                         Dzstar = int32_t((cz-1)/2)*(octants[idxtry].getSize()) + int32_t((cz+1)/2)*size;
 
 4302                         uint32_t x0 = oct->x;
 
 4303                         uint32_t x1 = x0 + size;
 
 4304                         uint32_t y0 = oct->y;
 
 4305                         uint32_t y1 = y0 + size;
 
 4306                         uint32_t z0 = oct->z;
 
 4307                         uint32_t z1 = z0 + size;
 
 4308                         uint32_t x0try = octants[idxtry].x;
 
 4309                         uint32_t x1try = x0try + octants[idxtry].getSize();
 
 4310                         uint32_t y0try = octants[idxtry].y;
 
 4311                         uint32_t y1try = y0try + octants[idxtry].getSize();
 
 4312                         uint32_t z0try = octants[idxtry].z;
 
 4313                         uint32_t z1try = z0try + octants[idxtry].getSize();
 
 4314                         uint8_t level = oct->level;
 
 4315                         uint8_t leveltry = octants[idxtry].getLevel();
 
 4317                         if (Dx == Dxstar && Dy == Dystar && Dz == Dzstar){
 
 4318                             if (leveltry > level){
 
 4319                                 if((abs(cx)*abs(cz)*((y0try>=y0)*(y0try<y1))) + (abs(cy)*abs(cz)*((x0try>=x0)*(x0try<x1))) + (abs(cx)*abs(cy)*((z0try>=z0)*(z0try<z1)))){
 
 4320                                     neighbours.push_back(idxtry);
 
 4323                             if (leveltry < level){
 
 4324                                 if((abs(cx)*abs(cz)*((y0>=y0try)*(y0<y1try))) + (abs(cy)*abs(cz)*((x0>=x0try)*(x0<x1try))) + (abs(cx)*abs(cy)*((z0>=z0try)*(z0<z1try)))){
 
 4325                                     neighbours.push_back(idxtry);
 
 4330                         if(idxtry>noctants-1){
 
 4333                         Mortontry = octants[idxtry].computeMorton();
 
 4595             u32vector & neighbours,     
 
 4596             vector<bool> & isghost){    
 
 4598         uint64_t  Morton, Mortontry;
 
 4599         uint32_t  noctants = getNumOctants();
 
 4601         uint32_t size = oct->
getSize();
 
 4602         uint8_t iface1, iface2, iface3;
 
 4603         int32_t Dhx, Dhy, Dhz;
 
 4604         int32_t Dhxref, Dhyref, Dhzref;
 
 4607         int8_t Cx[8] = {-1,1,-1,1,-1,1,-1,1};
 
 4608         int8_t Cy[8] = {-1,-1,1,1,-1,-1,1,1};
 
 4609         int8_t Cz[8] = {-1,-1,-1,-1,1,1,1,1};
 
 4610         int8_t cx = Cx[inode];
 
 4611         int8_t cy = Cy[inode];
 
 4612         int8_t cz = Cz[inode];
 
 4618         if (inode < 0 || inode > global3D.
nnodes){
 
 4623         iface1 = global3D.
nodeface[inode][0];
 
 4624         iface2 = global3D.
nodeface[inode][1];
 
 4625         iface3 = global3D.
nodeface[inode][2];
 
 4628         if (oct->info[iface1] == 
false && oct->info[iface2] == 
false && oct->info[iface3] == 
false){
 
 4631             Class_Octant<3> samesizeoct(oct->level, oct->x+cx*size, oct->y+cy*size, oct->z+cz*size);
 
 4636             if (ghosts.size()>0){
 
 4638                 uint32_t idxghost = uint32_t(size_ghosts/2);
 
 4644                 int32_t jump = (octghost->
computeMorton() > Morton) ? int32_t(idxghost/2+1) : int32_t((size_ghosts -idxghost)/2+1);
 
 4646                 if (idxtry > size_ghosts-1)
 
 4647                     idxtry = size_ghosts-1;
 
 4648                 while(abs(jump) > 0){
 
 4649                     Mortontry = ghosts[idxtry].computeMorton();
 
 4650                     jump = ((Mortontry<Morton)-(Mortontry>Morton))*abs(jump)/2;
 
 4652                     if (idxtry > ghosts.size()-1){
 
 4654                             idxtry = ghosts.size() - 1;
 
 4663                 if(ghosts[idxtry].computeMorton() == Morton && ghosts[idxtry].level == oct->level){
 
 4665                     isghost.push_back(
true);
 
 4666                     neighbours.push_back(idxtry);
 
 4672                         while(ghosts[idxtry].computeMorton() < Morton){
 
 4674                             if(idxtry > ghosts.size()-1){
 
 4675                                 idxtry = ghosts.size()-1;
 
 4679                         while(ghosts[idxtry].computeMorton() > Morton){
 
 4681                             if(idxtry > ghosts.size()-1){
 
 4687                     if(idxtry < size_ghosts){
 
 4688                         if(ghosts[idxtry].computeMorton() == Morton && ghosts[idxtry].level == oct->level){
 
 4690                             isghost.push_back(
true);
 
 4691                             neighbours.push_back(idxtry);
 
 4697                         Mortontry = ghosts[idxtry].computeMorton();
 
 4698                         while(Mortontry < Mortonlast && idxtry < size_ghosts){
 
 4699                             Dhx = int32_t(cx)*(int32_t(oct->x) - int32_t(ghosts[idxtry].x));
 
 4700                             Dhy = int32_t(cy)*(int32_t(oct->y) - int32_t(ghosts[idxtry].y));
 
 4701                             Dhz = int32_t(cz)*(int32_t(oct->z) - int32_t(ghosts[idxtry].z));
 
 4702                             Dhxref = int32_t(cx<0)*ghosts[idxtry].getSize() + int32_t(cx>0)*size;
 
 4703                             Dhyref = int32_t(cy<0)*ghosts[idxtry].getSize() + int32_t(cy>0)*size;
 
 4704                             Dhzref = int32_t(cz<0)*ghosts[idxtry].getSize() + int32_t(cz>0)*size;
 
 4705                             if ((abs(Dhx) == Dhxref) && (abs(Dhy) == Dhyref) && (abs(Dhz) == Dhzref)){
 
 4706                                 neighbours.push_back(idxtry);
 
 4707                                 isghost.push_back(
true);
 
 4711                             if(idxtry>size_ghosts-1){
 
 4714                             Mortontry = ghosts[idxtry].computeMorton();
 
 4726             int32_t jump = (int32_t((noctants)/2+1));
 
 4727             idxtry = uint32_t(jump);
 
 4728             if (idxtry > noctants-1)
 
 4729                 idxtry = noctants-1;
 
 4730             while(abs(jump) > 0){
 
 4731                 Mortontry = octants[idxtry].computeMorton();
 
 4732                 jump = ((Mortontry<Morton)-(Mortontry>Morton))*abs(jump)/2;
 
 4734                 if (idxtry > octants.size()-1){
 
 4736                         idxtry = octants.size() - 1;
 
 4745             if(octants[idxtry].computeMorton() == Morton && octants[idxtry].level == oct->level){
 
 4747                 isghost.push_back(
false);
 
 4748                 neighbours.push_back(idxtry);
 
 4754                     while(octants[idxtry].computeMorton() < Morton){
 
 4756                         if(idxtry > noctants-1){
 
 4757                             idxtry = noctants-1;
 
 4761                     while(octants[idxtry].computeMorton() > Morton){
 
 4763                         if(idxtry > noctants-1){
 
 4769                 if (idxtry < noctants){
 
 4770                     if(octants[idxtry].computeMorton() == Morton && octants[idxtry].level == oct->level){
 
 4772                         isghost.push_back(
false);
 
 4773                         neighbours.push_back(idxtry);
 
 4779                     Mortontry = octants[idxtry].computeMorton();
 
 4780                     while(Mortontry < Mortonlast && idxtry <= noctants-1){
 
 4781                         Dhx = int32_t(cx)*(int32_t(oct->x) - int32_t(octants[idxtry].x));
 
 4782                         Dhy = int32_t(cy)*(int32_t(oct->y) - int32_t(octants[idxtry].y));
 
 4783                         Dhz = int32_t(cz)*(int32_t(oct->z) - int32_t(octants[idxtry].z));
 
 4784                         Dhxref = int32_t(cx<0)*octants[idxtry].getSize() + int32_t(cx>0)*size;
 
 4785                         Dhyref = int32_t(cy<0)*octants[idxtry].getSize() + int32_t(cy>0)*size;
 
 4786                         Dhzref = int32_t(cz<0)*octants[idxtry].getSize() + int32_t(cz>0)*size;
 
 4787                         if ((abs(Dhx) == Dhxref) && (abs(Dhy) == Dhyref) && (abs(Dhz) == Dhzref)){
 
 4788                             neighbours.push_back(idxtry);
 
 4789                             isghost.push_back(
false);
 
 4793                         if(idxtry>noctants-1){
 
 4796                         Mortontry = octants[idxtry].computeMorton();
 
 4810     void findNodeNeighbours(uint32_t idx,           
 
 4812             u32vector & neighbours,     
 
 4813             vector<bool> & isghost){    
 
 4815         uint64_t  Morton, Mortontry;
 
 4816         uint32_t  noctants = getNumOctants();
 
 4819         uint32_t size = oct->
getSize();
 
 4820         uint8_t iface1, iface2, iface3;
 
 4821         int32_t Dhx, Dhy, Dhz;
 
 4822         int32_t Dhxref, Dhyref, Dhzref;
 
 4825         int8_t Cx[8] = {-1,1,-1,1,-1,1,-1,1};
 
 4826         int8_t Cy[8] = {-1,-1,1,1,-1,-1,1,1};
 
 4827         int8_t Cz[8] = {-1,-1,-1,-1,1,1,1,1};
 
 4828         int8_t cx = Cx[inode];
 
 4829         int8_t cy = Cy[inode];
 
 4830         int8_t cz = Cz[inode];
 
 4836         if (inode < 0 || inode > global3D.
nnodes){
 
 4841         iface1 = global3D.
nodeface[inode][0];
 
 4842         iface2 = global3D.
nodeface[inode][1];
 
 4843         iface3 = global3D.
nodeface[inode][2];
 
 4846         if (oct->info[iface1] == 
false && oct->info[iface2] == 
false && oct->info[iface3] == 
false){
 
 4849             Class_Octant<3> samesizeoct(oct->level, oct->x+cx*size, oct->y+cy*size, oct->z+cz*size);
 
 4854             if (ghosts.size()>0){
 
 4856                 uint32_t idxghost = uint32_t(size_ghosts/2);
 
 4862                 int32_t jump = (octghost->
computeMorton() > Morton) ? int32_t(idxghost/2+1) : int32_t((size_ghosts -idxghost)/2+1);
 
 4864                 if (idxtry > size_ghosts-1)
 
 4865                     idxtry = size_ghosts-1;
 
 4866                 while(abs(jump) > 0){
 
 4867                     Mortontry = ghosts[idxtry].computeMorton();
 
 4868                     jump = ((Mortontry<Morton)-(Mortontry>Morton))*abs(jump)/2;
 
 4870                     if (idxtry > ghosts.size()-1){
 
 4872                             idxtry = ghosts.size() - 1;
 
 4881                 if(ghosts[idxtry].computeMorton() == Morton && ghosts[idxtry].level == oct->level){
 
 4883                     isghost.push_back(
true);
 
 4884                     neighbours.push_back(idxtry);
 
 4890                         while(ghosts[idxtry].computeMorton() < Morton){
 
 4892                             if(idxtry > ghosts.size()-1){
 
 4893                                 idxtry = ghosts.size()-1;
 
 4897                         while(ghosts[idxtry].computeMorton() > Morton){
 
 4899                             if(idxtry > ghosts.size()-1){
 
 4905                     if(idxtry < size_ghosts){
 
 4906                         if(ghosts[idxtry].computeMorton() == Morton && ghosts[idxtry].level == oct->level){
 
 4908                             isghost.push_back(
true);
 
 4909                             neighbours.push_back(idxtry);
 
 4915                         Mortontry = ghosts[idxtry].computeMorton();
 
 4916                         while(Mortontry < Mortonlast && idxtry < size_ghosts){
 
 4917                             Dhx = int32_t(cx)*(int32_t(oct->x) - int32_t(ghosts[idxtry].x));
 
 4918                             Dhy = int32_t(cy)*(int32_t(oct->y) - int32_t(ghosts[idxtry].y));
 
 4919                             Dhz = int32_t(cz)*(int32_t(oct->z) - int32_t(ghosts[idxtry].z));
 
 4920                             Dhxref = int32_t(cx<0)*ghosts[idxtry].getSize() + int32_t(cx>0)*size;
 
 4921                             Dhyref = int32_t(cy<0)*ghosts[idxtry].getSize() + int32_t(cy>0)*size;
 
 4922                             Dhzref = int32_t(cz<0)*ghosts[idxtry].getSize() + int32_t(cz>0)*size;
 
 4923                             if ((abs(Dhx) == Dhxref) && (abs(Dhy) == Dhyref) && (abs(Dhz) == Dhzref)){
 
 4924                                 neighbours.push_back(idxtry);
 
 4925                                 isghost.push_back(
true);
 
 4929                             if(idxtry>size_ghosts-1){
 
 4932                             Mortontry = ghosts[idxtry].computeMorton();
 
 4944             int32_t jump = (int32_t((noctants)/2+1));
 
 4945             idxtry = uint32_t(jump);
 
 4946             if (idxtry > noctants-1)
 
 4947                 idxtry = noctants-1;
 
 4948             while(abs(jump) > 0){
 
 4949                 Mortontry = octants[idxtry].computeMorton();
 
 4950                 jump = ((Mortontry<Morton)-(Mortontry>Morton))*abs(jump)/2;
 
 4952                 if (idxtry > octants.size()-1){
 
 4954                         idxtry = octants.size() - 1;
 
 4963             if(octants[idxtry].computeMorton() == Morton && octants[idxtry].level == oct->level){
 
 4965                 isghost.push_back(
false);
 
 4966                 neighbours.push_back(idxtry);
 
 4972                     while(octants[idxtry].computeMorton() < Morton){
 
 4974                         if(idxtry > noctants-1){
 
 4975                             idxtry = noctants-1;
 
 4979                     while(octants[idxtry].computeMorton() > Morton){
 
 4981                         if(idxtry > noctants-1){
 
 4987                 if (idxtry < noctants){
 
 4988                     if(octants[idxtry].computeMorton() == Morton && octants[idxtry].level == oct->level){
 
 4990                         isghost.push_back(
false);
 
 4991                         neighbours.push_back(idxtry);
 
 4997                     Mortontry = octants[idxtry].computeMorton();
 
 4998                     while(Mortontry < Mortonlast && idxtry <= noctants-1){
 
 4999                         Dhx = int32_t(cx)*(int32_t(oct->x) - int32_t(octants[idxtry].x));
 
 5000                         Dhy = int32_t(cy)*(int32_t(oct->y) - int32_t(octants[idxtry].y));
 
 5001                         Dhz = int32_t(cz)*(int32_t(oct->z) - int32_t(octants[idxtry].z));
 
 5002                         Dhxref = int32_t(cx<0)*octants[idxtry].getSize() + int32_t(cx>0)*size;
 
 5003                         Dhyref = int32_t(cy<0)*octants[idxtry].getSize() + int32_t(cy>0)*size;
 
 5004                         Dhzref = int32_t(cz<0)*octants[idxtry].getSize() + int32_t(cz>0)*size;
 
 5005                         if ((abs(Dhx) == Dhxref) && (abs(Dhy) == Dhyref) && (abs(Dhz) == Dhzref)){
 
 5006                             neighbours.push_back(idxtry);
 
 5007                             isghost.push_back(
false);
 
 5011                         if(idxtry>noctants-1){
 
 5014                         Mortontry = octants[idxtry].computeMorton();
 
 5028 void findGhostNodeNeighbours(uint32_t idx,      
 
 5030         u32vector & neighbours){                
 
 5032     uint64_t  Morton, Mortontry;
 
 5033     uint32_t  noctants = getNumOctants();
 
 5036     uint32_t size = oct->
getSize();
 
 5037     uint8_t iface1, iface2, iface3;
 
 5038     int32_t Dhx, Dhy, Dhz;
 
 5039     int32_t Dhxref, Dhyref, Dhzref;
 
 5042     int8_t Cx[8] = {-1,1,-1,1,-1,1,-1,1};
 
 5043     int8_t Cy[8] = {-1,-1,1,1,-1,-1,1,1};
 
 5044     int8_t Cz[8] = {-1,-1,-1,-1,1,1,1,1};
 
 5045     int8_t cx = Cx[inode];
 
 5046     int8_t cy = Cy[inode];
 
 5047     int8_t cz = Cz[inode];
 
 5052     if (inode < 0 || inode > global3D.
nnodes){
 
 5057     iface1 = global3D.
nodeface[inode][0];
 
 5058     iface2 = global3D.
nodeface[inode][1];
 
 5059     iface3 = global3D.
nodeface[inode][2];
 
 5064     if (oct->info[iface1+global3D.
nfaces] == 
true || oct->info[iface2+global3D.
nfaces] == 
true || oct->info[iface3+global3D.
nfaces] == 
true){
 
 5067         Class_Octant<3> samesizeoct(oct->level, oct->x+cx*size, oct->y+cy*size, oct->z+cz*size);
 
 5069         int32_t jump = noctants/2;
 
 5071         while(abs(jump) > 0){
 
 5072             Mortontry = octants[idxtry].computeMorton();
 
 5073             jump = ((Mortontry<Morton)-(Mortontry>Morton))*abs(jump)/2;
 
 5076         if(octants[idxtry].computeMorton() == Morton && octants[idxtry].level == oct->level){
 
 5078             neighbours.push_back(idxtry);
 
 5084                 while(octants[idxtry].computeMorton() < Morton){
 
 5086                     if(idxtry > noctants-1){
 
 5087                         idxtry = noctants-1;
 
 5091                 while(octants[idxtry].computeMorton() > Morton){
 
 5093                     if(idxtry > noctants-1){
 
 5099             if (idxtry < noctants){
 
 5100                 if(octants[idxtry].computeMorton() == Morton && octants[idxtry].level == oct->level){
 
 5102                     neighbours.push_back(idxtry);
 
 5108                 Mortontry = octants[idxtry].computeMorton();
 
 5109                 while(Mortontry < Mortonlast && idxtry <= noctants-1){
 
 5110                     Dhx = int32_t(cx)*(int32_t(oct->x) - int32_t(octants[idxtry].x));
 
 5111                     Dhy = int32_t(cy)*(int32_t(oct->y) - int32_t(octants[idxtry].y));
 
 5112                     Dhz = int32_t(cz)*(int32_t(oct->z) - int32_t(octants[idxtry].z));
 
 5113                     Dhxref = int32_t(cx<0)*octants[idxtry].getSize() + int32_t(cx>0)*size;
 
 5114                     Dhyref = int32_t(cy<0)*octants[idxtry].getSize() + int32_t(cy>0)*size;
 
 5115                     Dhzref = int32_t(cz<0)*octants[idxtry].getSize() + int32_t(cz>0)*size;
 
 5116                     if ((abs(Dhx) == Dhxref) && (abs(Dhy) == Dhyref) && (abs(Dhz) == Dhzref)){
 
 5117                         neighbours.push_back(idxtry);
 
 5120                     Mortontry = octants[idxtry].computeMorton();
 
 5134 void computeIntersections() {
 
 5136         OctantsType::iterator it, obegin, oend;
 
 5138         u32vector neighbours;
 
 5139         vector<bool> isghost;
 
 5140         uint32_t counter, idx;
 
 5142         uint8_t iface, iface2;
 
 5144         intersections.clear();
 
 5145         intersections.reserve(2*3*octants.size());
 
 5150         obegin = ghosts.begin();
 
 5151         oend = ghosts.end();
 
 5152         for (it = obegin; it != oend; it++){
 
 5153             for (iface = 0; iface < 3; iface++){
 
 5155                 findGhostNeighbours(idx, iface2, neighbours);
 
 5156                 nsize = neighbours.size();
 
 5157                 for (i = 0; i < nsize; i++){
 
 5158                     intersection.finer = getGhostLevel(idx) >= getLevel((
int)neighbours[i]);
 
 5159                     intersection.owners[0]  = neighbours[i];
 
 5160                     intersection.owners[1] = idx;
 
 5161                     intersection.iface = global3D.
oppface[iface2] - (getGhostLevel(idx) >= getLevel((
int)neighbours[i]));
 
 5162                     intersection.isnew = 
false;
 
 5163                     intersection.isghost = 
true;
 
 5164                     intersection.bound = 
false;
 
 5165                     intersection.pbound = 
true;
 
 5166                     intersections.push_back(intersection);
 
 5175         obegin = octants.begin();
 
 5176         oend = octants.end();
 
 5177         for (it = obegin; it != oend; it++){
 
 5178             for (iface = 0; iface < 3; iface++){
 
 5180                 findNeighbours(idx, iface2, neighbours, isghost);
 
 5181                 nsize = neighbours.size();
 
 5183                     for (i = 0; i < nsize; i++){
 
 5185                             intersection.owners[0] = idx;
 
 5186                             intersection.owners[1] = neighbours[i];
 
 5187                             intersection.finer = (nsize>1);
 
 5188                             intersection.iface = iface2 + (nsize>1);
 
 5189                             intersection.isnew = 
false;
 
 5190                             intersection.isghost = 
true;
 
 5191                             intersection.bound = 
false;
 
 5192                             intersection.pbound = 
true;
 
 5193                             intersections.push_back(intersection);
 
 5197                             intersection.owners[0] = idx;
 
 5198                             intersection.owners[1] = neighbours[i];
 
 5199                             intersection.finer = (nsize>1);
 
 5200                             intersection.iface = iface2 + (nsize>1);
 
 5201                             intersection.isnew = 
false;
 
 5202                             intersection.isghost = 
false;
 
 5203                             intersection.bound = 
false;
 
 5204                             intersection.pbound = 
false;
 
 5205                             intersections.push_back(intersection);
 
 5211                     intersection.owners[0] = idx;
 
 5212                     intersection.owners[1] = idx;
 
 5213                     intersection.finer = 0;
 
 5214                     intersection.iface = iface2;
 
 5215                     intersection.isnew = 
false;
 
 5216                     intersection.isghost = 
false;
 
 5217                     intersection.bound = 
true;
 
 5218                     intersection.pbound = 
false;
 
 5219                     intersections.push_back(intersection);
 
 5222                 if (it->info[iface2+1]){
 
 5223                     intersection.owners[0] = idx;
 
 5224                     intersection.owners[1] = idx;
 
 5225                     intersection.finer = 0;
 
 5226                     intersection.iface = iface2+1;
 
 5227                     intersection.isnew = 
false;
 
 5228                     intersection.isghost = 
false;
 
 5229                     intersection.bound = 
true;
 
 5230                     intersection.pbound = 
false;
 
 5231                     intersections.push_back(intersection);
 
 5237 #if defined(__INTEL_COMPILER) || defined(__ICC) 
 5239         intersections.shrink_to_fit();
 
 5245     uint32_t findMorton(uint64_t Morton){               
 
 5246         uint32_t nocts = octants.size();
 
 5247         uint32_t idx = nocts/2;
 
 5248         uint64_t Mortontry = octants[idx].computeMorton();
 
 5249         int32_t jump = nocts/2;
 
 5251             if (Mortontry == Morton){
 
 5254             Mortontry = octants[idx].computeMorton();
 
 5255             jump = ((Mortontry<Morton)-(Mortontry>Morton))*abs(jump)/2;
 
 5261         if (Mortontry<Morton){
 
 5262             for (uint32_t idx2=idx; idx2<nocts; idx2++){
 
 5263                 Mortontry = octants[idx2].computeMorton();
 
 5264                 if (Mortontry == Morton){
 
 5270             for(uint32_t idx2=0; idx2<idx+1; idx2++){
 
 5271                 Mortontry = octants[idx2].computeMorton();
 
 5272                 if (Mortontry == Morton){
 
 5282     uint32_t findGhostMorton(uint64_t Morton){          
 
 5283         uint32_t nocts = ghosts.size();
 
 5284         uint32_t idx = nocts/2;
 
 5285         uint64_t Mortontry = ghosts[idx].computeMorton();
 
 5286         int32_t jump = nocts/2;
 
 5288             if (Mortontry == Morton){
 
 5291             Mortontry = ghosts[idx].computeMorton();
 
 5292             jump = (Mortontry<Morton)*jump/4;
 
 5298         if (Mortontry<Morton){
 
 5299             for (uint32_t idx2=idx; idx2<nocts; idx2++){
 
 5300                 Mortontry = ghosts[idx2].computeMorton();
 
 5301                 if (Mortontry == Morton){
 
 5307             for(uint32_t idx2=0; idx2<idx; idx2++){
 
 5308                 Mortontry = ghosts[idx2].computeMorton();
 
 5309                 if (Mortontry == Morton){
 
 5321     void computeConnectivity(){                     
 
 5322         map<uint64_t, vector<uint32_t> > mapnodes;
 
 5323         map<uint64_t, vector<uint32_t> >::iterator iter, iterend;
 
 5324         uint32_t i, k, counter;
 
 5326         uint32_t noctants = getNumOctants();
 
 5327         u32vector2D octnodes;
 
 5330         clearConnectivity();
 
 5331         octnodes.reserve(global3D.
nnodes);
 
 5333         if (nodes.size() == 0){
 
 5334             connectivity.resize(noctants);
 
 5335             for (i = 0; i < noctants; i++){
 
 5336                 octants[i].getNodes(octnodes);
 
 5337                 for (j = 0; j < global3D.
nnodes; j++){
 
 5339            morton = keyXYZ(octnodes[j][0], octnodes[j][1], octnodes[j][2]);
 
 5340                     if (mapnodes[morton].size()==0){
 
 5341                         mapnodes[morton].reserve(16);
 
 5342                         for (k = 0; k < 3; k++){
 
 5343                             mapnodes[morton].push_back(octnodes[j][k]);
 
 5346                     mapnodes[morton].push_back(i);
 
 5348                 u32vector2D().swap(octnodes);
 
 5350             iter    = mapnodes.begin();
 
 5351             iterend = mapnodes.end();
 
 5353             uint32_t numnodes = mapnodes.size();
 
 5354             nodes.resize(numnodes);
 
 5355             while (iter != iterend){
 
 5356                 vector<uint32_t> nodecasting(iter->second.begin(), iter->second.begin()+3);
 
 5357                 nodes[counter] = nodecasting;
 
 5358 #if defined(__INTEL_COMPILER) || defined(__ICC) 
 5360                 nodes[counter].shrink_to_fit();
 
 5362                 for(vector<uint32_t>::iterator iter2 = iter->second.begin()+3; iter2 != iter->second.end(); iter2++){
 
 5363                     if (connectivity[(*iter2)].size()==0){
 
 5364                         connectivity[(*iter2)].reserve(8);
 
 5366                     connectivity[(*iter2)].push_back(counter);
 
 5368                 mapnodes.erase(iter++);
 
 5371 #if defined(__INTEL_COMPILER) || defined(__ICC) 
 5373             nodes.shrink_to_fit();
 
 5376             for (uint32_t ii=0; ii<noctants; ii++){
 
 5377 #if defined(__INTEL_COMPILER) || defined(__ICC) 
 5379                 connectivity[ii].shrink_to_fit();
 
 5382 #if defined(__INTEL_COMPILER) || defined(__ICC) 
 5384             connectivity.shrink_to_fit();
 
 5387         map<uint64_t, vector<uint32_t> >().swap(mapnodes);
 
 5388         iter = mapnodes.end();
 
 5394     void clearConnectivity(){                       
 
 5395         u32vector2D().swap(nodes);
 
 5396         u32vector2D().swap(connectivity);
 
 5401     void updateConnectivity(){                      
 
 5402         clearConnectivity();
 
 5403         computeConnectivity();
 
 5408     void computeGhostsConnectivity(){               
 
 5409         map<uint64_t, vector<uint32_t> > mapnodes;
 
 5410         map<uint64_t, vector<uint32_t> >::iterator iter, iterend;
 
 5411         uint32_t i, k, counter;
 
 5413         uint32_t noctants = size_ghosts;
 
 5414         u32vector2D octnodes;
 
 5417         octnodes.reserve(global3D.
nnodes);
 
 5418         if (ghostsnodes.size() == 0){
 
 5419             ghostsconnectivity.resize(noctants);
 
 5420             for (i = 0; i < noctants; i++){
 
 5421                 ghosts[i].getNodes(octnodes);
 
 5422                 for (j = 0; j < global3D.
nnodes; j++){
 
 5424            morton = keyXYZ(octnodes[j][0], octnodes[j][1], octnodes[j][2]);
 
 5425                     if (mapnodes[morton].size()==0){
 
 5426                         for (k = 0; k < 3; k++){
 
 5427                             mapnodes[morton].push_back(octnodes[j][k]);
 
 5430                     mapnodes[morton].push_back(i);
 
 5432                 u32vector2D().swap(octnodes);
 
 5434             iter    = mapnodes.begin();
 
 5435             iterend = mapnodes.end();
 
 5436             uint32_t numnodes = mapnodes.size();
 
 5437             ghostsnodes.resize(numnodes);
 
 5439             while (iter != iterend){
 
 5440                 vector<uint32_t> nodecasting(iter->second.begin(), iter->second.begin()+3);
 
 5441                 ghostsnodes[counter] = nodecasting;
 
 5442 #if defined(__INTEL_COMPILER) || defined(__ICC) 
 5444                 ghostsnodes[counter].shrink_to_fit();
 
 5446                 for(vector<uint32_t>::iterator iter2 = iter->second.begin()+3; iter2 != iter->second.end(); iter2++){
 
 5447                     if (ghostsconnectivity[(*iter2)].size()==0){
 
 5448                         ghostsconnectivity[(*iter2)].reserve(8);
 
 5450                     ghostsconnectivity[(*iter2)].push_back(counter);
 
 5452                 mapnodes.erase(iter++);
 
 5455 #if defined(__INTEL_COMPILER) || defined(__ICC) 
 5457             ghostsnodes.shrink_to_fit();
 
 5460             for (uint32_t ii=0; ii<noctants; ii++){
 
 5461 #if defined(__INTEL_COMPILER) || defined(__ICC) 
 5463                 ghostsconnectivity[ii].shrink_to_fit();
 
 5466 #if defined(__INTEL_COMPILER) || defined(__ICC) 
 5468             ghostsconnectivity.shrink_to_fit();
 
 5471         iter = mapnodes.end();
 
 5477     void clearGhostsConnectivity(){                 
 
 5478         u32vector2D().swap(ghostsnodes);
 
 5479         u32vector2D().swap(ghostsconnectivity);
 
 5484     void updateGhostsConnectivity(){                    
 
 5485         clearGhostsConnectivity();
 
 5486         computeGhostsConnectivity();
 
uint64_t computeMorton() const 
 
Parallel Octree Manager Class. 
 
Octant class definition - 3D specialization. 
 
Intersection class definition - 3D specialization. 
 
Local octree portion for each process. 
 
void setMarker(int8_t marker)