/[escript]/branches/refine/buckley/src/OctCell.cc
ViewVC logotype

Diff of /branches/refine/buckley/src/OctCell.cc

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 3679 by jfenwick, Wed Nov 16 01:49:46 2011 UTC revision 3680 by jfenwick, Fri Nov 18 04:48:53 2011 UTC
# Line 58  OctCell::~OctCell() Line 58  OctCell::~OctCell()
58  // If we are allocating from a pool we need to keep a record of it somewhere  // If we are allocating from a pool we need to keep a record of it somewhere
59  // maybe keep track (static?) of holding object with operators  // maybe keep track (static?) of holding object with operators
60  // or define OctCell::new ?  // or define OctCell::new ?
61  void OctCell::split()  void OctCell::split(size_t* leafc)
62  {  {
63      if (leaf)      if (leaf)
64      {      {
# Line 66  void OctCell::split() Line 66  void OctCell::split()
66      {      {
67          if (leafinfo->next[f] && (depth>leafinfo->next[f]->owner->depth))          if (leafinfo->next[f] && (depth>leafinfo->next[f]->owner->depth))
68          {          {
69          leafinfo->next[f]->owner->split();          leafinfo->next[f]->owner->split(leafc);
70          }            }  
71                
72      }      }
# Line 88  void OctCell::split() Line 88  void OctCell::split()
88      leafinfo->split(kids);      leafinfo->split(kids);
89      delete leafinfo;      delete leafinfo;
90      leafinfo=0;      leafinfo=0;
91        (*leafc)+=7;
92      }        }  
93  }  }
94    
95  void OctCell::allSplit(unsigned int depth)  void OctCell::allSplit(unsigned int depth, size_t* leafc)
96  {  {
97      if (depth>0)        if (depth>0)  
98      {      {
99          if (leaf)          if (leaf)
100      {      {
101          split();              split(leafc);    
102      }      }
103      if (depth==1)      if (depth==1)
104      {      {
# Line 105  void OctCell::allSplit(unsigned int dept Line 106  void OctCell::allSplit(unsigned int dept
106      }      }
107          for (unsigned int i=0;i<8;i++)          for (unsigned int i=0;i<8;i++)
108      {      {
109          kids[i]->split();          kids[i]->split(leafc);
110          kids[i]->allSplit(depth-1);          kids[i]->allSplit(depth-1, leafc);
111      }      }
112      }      }
113  }  }
# Line 129  OctCell* OctCell::findLeaf(double x, dou Line 130  OctCell* OctCell::findLeaf(double x, dou
130    
131  // divide the leaf containing the point (if required)  // divide the leaf containing the point (if required)
132  // This needs to be more efficient but will do for now  // This needs to be more efficient but will do for now
133  void OctCell::splitPoint(double x, double y, double z, unsigned d)  void OctCell::splitPoint(double x, double y, double z, unsigned d, size_t* leafc)
134  {  {
135      // find cell      // find cell
136      // if it doesn't need refining, then bail      // if it doesn't need refining, then bail
# Line 143  void OctCell::splitPoint(double x, doubl Line 144  void OctCell::splitPoint(double x, doubl
144      {      {
145          return;            return;  
146      }      }
147      l->split();      l->split(leafc);
148      start=l;      start=l;
149      } while (start->depth+1 <d);      } while (start->depth+1 <d);
150  }  }
151    
152  // collapse the children of this cell into it  // collapse the children of this cell into it
153  void OctCell::collapse()  void OctCell::collapse(size_t* leafc)
154  {  {
155      if (!leaf)      if (!leaf)
156      {      {
# Line 158  void OctCell::collapse() Line 159  void OctCell::collapse()
159      {      {
160          if (! kids[i]->leaf)          if (! kids[i]->leaf)
161          {          {
162                  kids[i]->collapse();    // so we know we are only dealing with leaves                  kids[i]->collapse(leafc);   // so we know we are only dealing with leaves
163          }          }
164      }      }
165      // now we need to ensure that collapsing this would not break any neighbours      // now we need to ensure that collapsing this would not break any neighbours
# Line 267  void OctCell::collapse() Line 268  void OctCell::collapse()
268      {      {
269          if (! nparent->kids[faces[oppdir(k)][i]]->leaf) // if there are any non-leaves on the neighbour face          if (! nparent->kids[faces[oppdir(k)][i]]->leaf) // if there are any non-leaves on the neighbour face
270          {          {
271          nparent->kids[faces[oppdir(k)][i]]->collapse();          nparent->kids[faces[oppdir(k)][i]]->collapse(leafc);
272          }                }      
273      }      }
274      }      }
# Line 277  void OctCell::collapse() Line 278  void OctCell::collapse()
278      {      {
279          delete kids[i];          delete kids[i];
280      }      }
281      leaf=true;        leaf=true;
282        (*leafc)-=7;
283      }      }
284  }  }
285    
286  void OctCell::collapseAll(unsigned int desdepth)  void OctCell::collapseAll(unsigned int desdepth, size_t* leafc)
287  {  {
288      if (leaf)      if (leaf)
289      {      {
# Line 289  void OctCell::collapseAll(unsigned int d Line 291  void OctCell::collapseAll(unsigned int d
291      }      }
292      for (unsigned i=0;i<8;++i)      for (unsigned i=0;i<8;++i)
293      {      {
294      kids[i]->collapseAll(desdepth);      kids[i]->collapseAll(desdepth, leafc);
295      }      }
296      if (depth>=desdepth)      if (depth>=desdepth)
297      {      {
298          collapse();          collapse(leafc);
299      }      }
300  }  }
301    
302    
303  // The leaf which contains (x,y,z) should be at depth at most d  // The leaf which contains (x,y,z) should be at depth at most d
304  void OctCell::collapsePoint(double x, double y, double z, unsigned d)  void OctCell::collapsePoint(double x, double y, double z, unsigned d, size_t* leafc)
305  {  {
306      // find cell      // find cell
307      // if it doesn't need refining, then bail      // if it doesn't need refining, then bail
# Line 314  void OctCell::collapsePoint(double x, do Line 316  void OctCell::collapsePoint(double x, do
316          return;            return;  
317      }      }
318      l=l->parent;      l=l->parent;
319      l->collapse();      l->collapse(leafc);
320      start=l;      start=l;
321      } while (start->depth+1 >d);      } while (start->depth+1 >d);
322        
323  }  }
324    
325  void OctCell::doLeafWalk(cellfunct c, void* v)  
326    void OctCell::doLeafWalk_const(const_cellfn c, void* v) const
327    {
328        if (leaf)
329        {
330            c(*this, v);
331        }
332        else
333        {
334            for (unsigned int i=0;i<8;++i)
335            {
336                kids[i]->doLeafWalk_const(c,v);
337            }
338        }  
339    }
340    
341    void OctCell::doLeafWalk(cellfn c, void* v)
342  {  {
343      if (leaf)      if (leaf)
344      {      {
# Line 335  void OctCell::doLeafWalk(cellfunct c, vo Line 353  void OctCell::doLeafWalk(cellfunct c, vo
353      }      }
354  }  }
355    
356  void OctCell::doLeafWalkWithKids(cellfunct2 c, int k, void* v)  void OctCell::doLeafWalkWithKids_const(const_cellfn2 c, int k, void* v) const
357  {  {
358      if (leaf)      if (leaf)
359      {      {
# Line 345  void OctCell::doLeafWalkWithKids(cellfun Line 363  void OctCell::doLeafWalkWithKids(cellfun
363      {      {
364          for (unsigned int i=0;i<8;++i)          for (unsigned int i=0;i<8;++i)
365          {          {
366              kids[i]->doLeafWalkWithKids(c,i, v);              kids[i]->doLeafWalkWithKids_const(c,i, v);
367          }          }
368      }      }
369        
# Line 481  void writeEl(const OctCell& c, void* v) Line 499  void writeEl(const OctCell& c, void* v)
499      static int e=1;      static int e=1;
500      static int i=1;      static int i=1;
501      ostream& os=reinterpret_cast<ostream&>(v);      ostream& os=reinterpret_cast<ostream&>(v);
502      cout << e << " 5 0 ";       // element number      os << e << " 5 0 ";     // element number
503      cout << i << ' ' << (i+1) << ' ' << (i+2) << ' ' << (i+3) << ' ';      os << i << ' ' << (i+1) << ' ' << (i+2) << ' ' << (i+3) << ' ';
504      cout << (i+4) << ' ' << (i+5) << ' ' << (i+6) << ' ' << (i+7) << endl;      os << (i+4) << ' ' << (i+5) << ' ' << (i+6) << ' ' << (i+7) << endl;
505      e++;      e++;
506      i+=8;      i+=8;
507  }  }
# Line 503  void OctCell::gmshDump() Line 521  void OctCell::gmshDump()
521        os << "$MeshFormat\n2.2 0 8\n$EndMeshFormat\n$Nodes\n";        os << "$MeshFormat\n2.2 0 8\n$EndMeshFormat\n$Nodes\n";
522    
523        int c=0;        int c=0;
524        doLeafWalk(countleaves, &c);        doLeafWalk_const(countleaves, &c);
525        os << c*8 << endl;        os << c*8 << endl;
526        int i=1;        int i=1;
527        doLeafWalk(writePoints, &os);        doLeafWalk_const(writePoints, &os);
528        os << "$EndNodes\n";        os << "$EndNodes\n";
529        os << "$Elements\n";        os << "$Elements\n";
530        os << c << endl;        os << c << endl;
531        doLeafWalk(writeEl, &os);        doLeafWalk_const(writeEl, &os);
532        i=1;        i=1;
533        os << "$EndElements\n";          os << "$EndElements\n";  
534      }      }

Legend:
Removed from v.3679  
changed lines
  Added in v.3680

  ViewVC Help
Powered by ViewVC 1.1.26