The Original CHomP Software
Public Member Functions | Private Member Functions | Private Attributes | List of all members
chomp::homology::gcomplex< cell, euclidom > Class Template Reference

The class that defines a geometric complex - a set of cells (cubes, simplices, etc). More...

#include <gcomplex.h>

Public Member Functions

 gcomplex ()
 The default constructor. More...
 
 gcomplex (const gcomplex< cell, euclidom > &c)
 The copy constructor. More...
 
 ~gcomplex ()
 The destructor. More...
 
gcomplexoperator= (const gcomplex< cell, euclidom > &c)
 The assignment operator. More...
 
int dim () const
 Returns the dimension of the complex, that is, the highest dimension of any cell contained in the complex. More...
 
int_t size () const
 Returns the number of cells in the complex. More...
 
bool empty () const
 Returns 'true' iff the cell complex is empty. More...
 
const hashedset< cell > & operator[] (int d) const
 Returns the set of cells of the given dimension. More...
 
const hashedset< cell > & getcob (const cell &c) const
 Returns the coboundary of the given cell. More...
 
const hashedset< cell > & getcob (const cell &c, int d) const
 Returns the coboundary of the given cell. More...
 
gcomplex< cell, euclidom > & add (const cell &c)
 Add a cell to the geometric complex. More...
 
gcomplex< cell, euclidom > & add (const hashedset< cell > &c, int d)
 Adds a set of cells to the geometric complex. More...
 
gcomplex< cell, euclidom > & add (const hashedset< cell > &c)
 Adds a set of cells to the geometric complex. More...
 
gcomplex< cell, euclidom > & add (const gcomplex< cell, euclidom > &c)
 Adds all the cells from a geometric complex. More...
 
gcomplex< cell, euclidom > & remove (const cell &c)
 Remove a cell from the geometric complex. More...
 
gcomplex< cell, euclidom > & remove (const hashedset< cell > &c, int d)
 Removes a set of cells to the geometric complex. More...
 
gcomplex< cell, euclidom > & remove (const hashedset< cell > &c)
 Removes a set of cells to the geometric complex. More...
 
gcomplex< cell, euclidom > & remove (const gcomplex< cell, euclidom > &c)
 Adds all the cells from a geometric complex. More...
 
gcomplex< cell, euclidom > & removeall (int d)
 Remove all the cells of the given dimension. More...
 
bool check (const cell &c) const
 Check whether the given cell is in the complex. More...
 
int_t addboundaries (int d, bool addcob=false)
 Adds boundaries of all the cells of given dimension to the geometric complex. More...
 
int_t addboundaries (bool addcob=false)
 Adds boundaries of all the cells of all dimensions to the geometric complex. More...
 
int_t addboundaries (int d, gcomplex< cell, euclidom > &notthese, bool keepused=false)
 Adds boundaries of all the cells of given dimension to the geometric complex, except for the cells which belong to the geometric complex "notthese". More...
 
int_t addboundaries (gcomplex< cell, euclidom > &notthese, bool keepused=false)
 Adds boundaries of all the cells of all dimensions to the geometric complex, except for the cells which belong to the geometric complex "notthese". More...
 
int_t addboundaries (int d, chaincomplex< euclidom > &c)
 Adds boundaries and also fills in the given chain complex. More...
 
int_t addboundaries (chaincomplex< euclidom > &c)
 Adds boundaries and also fills in the given chain complex. More...
 
int_t addboundaries (int d, chaincomplex< euclidom > &c, gcomplex< cell, euclidom > &notthese, bool keepused=false)
 Adds boundaries and also fills in the given chain complex. More...
 
int_t addboundaries (chaincomplex< euclidom > &c, gcomplex< cell, euclidom > &notthese, bool keepused=false)
 Adds boundaries and also fills in the given chain complex. More...
 
int_t addboundaries (int d, chaincomplex< euclidom > *c, gcomplex< cell, euclidom > *notthese, bool dontadd, bool keepused, bool addcob)
 The actual function that is used for all the functions for adding boundaries of a fixed dimension. More...
 
int_t addboundaries (chaincomplex< euclidom > *c, gcomplex< cell, euclidom > *notthese, bool dontadd, bool keepused, bool addcob)
 The actual function that is used for all the functions for adding boundaries of all dimensions. More...
 
int_t collapse (int d, gcomplex< cell, euclidom > &other, const gcomplex< cell, euclidom > &keep, bool addbd, bool addcob, bool disjoint, bool quiet=false)
 Adds boundaries of all the cells of the given dimension and then performs free face collapses. More...
 
int_t collapse (gcomplex< cell, euclidom > &other, gcomplex< cell, euclidom > &keep, bool addbd, bool addcob, bool disjoint, const int *level=NULL, bool quiet=false)
 Adds boundaries to 'other' and 'keep', and then does the free face collapses. More...
 

Private Member Functions

void increasedimension (int d)
 Increases the dimension of the complex to take this cell. More...
 
void decreasedimension ()
 Frees empty sets if there are no cells of high dimensions. More...
 

Private Attributes

hashedset< cell > ** tab
 The tables with cells of dimension 0, 1, 2, etc. More...
 
mvmap< cell, cell > ** cob
 The tables with coboundaries of cells of these dimensions. More...
 
int n
 The number of tables. More...
 

Detailed Description

template<class cell, class euclidom>
class chomp::homology::gcomplex< cell, euclidom >

The class that defines a geometric complex - a set of cells (cubes, simplices, etc).

Each cell has its dimension returned by the method "dim ()" of the cell object. Additionally, the following functions must be defined for the cell objects: "boundarylength (cell)" returns the length of the boundary of a cell (i.e., the number of lower-dimensional cells in its boundary), "boundarycell (cell, i)" returns the i-th cell in the boundary, and "boundarycoef (cell, i)" returns the i-th integer coefficient in the boundary.

Definition at line 84 of file gcomplex.h.

Constructor & Destructor Documentation

◆ gcomplex() [1/2]

template<class cell , class euclidom >
chomp::homology::gcomplex< cell, euclidom >::gcomplex
inline

The default constructor.

Definition at line 252 of file gcomplex.h.

252 : tab (NULL), cob (NULL), n (0)
253{
254 return;
255} /* gcomplex<cell,euclidom>::gcomplex */
int n
The number of tables.
Definition: gcomplex.h:239
mvmap< cell, cell > ** cob
The tables with coboundaries of cells of these dimensions.
Definition: gcomplex.h:236
hashedset< cell > ** tab
The tables with cells of dimension 0, 1, 2, etc.
Definition: gcomplex.h:233

◆ gcomplex() [2/2]

template<class cell , class euclidom >
chomp::homology::gcomplex< cell, euclidom >::gcomplex ( const gcomplex< cell, euclidom > &  c)

The copy constructor.

Definition at line 258 of file gcomplex.h.

259{
260 n = c. n;
261 if (n > 0)
262 {
263 tab = new hashedset<cell> *[n];
264 cob = new mvmap<cell,cell> *[n];
265 if (!tab || !cob)
266 throw "Cannot copy a geometric complex.";
267 }
268 else
269 {
270 tab = NULL;
271 cob = NULL;
272 }
273 for (int i = 0; i < n; ++ i)
274 {
275 tab [i] = new hashedset<cell> (*(c. tab [i]));
276 cob [i] = new mvmap<cell,cell> (*(c. cob [i]));
277 if (!tab [i] || !cob [i])
278 throw "Cannot copy part of a geometric complex.";
279 }
280 return;
281} /* gcomplex<cell,euclidom>::gcomplex */

◆ ~gcomplex()

template<class cell , class euclidom >
chomp::homology::gcomplex< cell, euclidom >::~gcomplex

The destructor.

Definition at line 337 of file gcomplex.h.

338{
339 for (int i = 0; i < n; ++ i)
340 {
341 if (tab [i])
342 delete tab [i];
343 if (cob [i])
344 delete cob [i];
345 }
346 if (tab)
347 delete [] tab;
348 if (cob)
349 delete [] cob;
350 return;
351} /* gcomplex<cell,euclidom>::~gcomplex */

Member Function Documentation

◆ add() [1/4]

template<class cell , class euclidom >
gcomplex< cell, euclidom > & chomp::homology::gcomplex< cell, euclidom >::add ( const cell &  c)
inline

Add a cell to the geometric complex.

Definition at line 405 of file gcomplex.h.

406{
407 // get the dimension of the cell
408 int d = c. dim ();
409 if (d < 0)
410 throw "Negative dimension of a cell to be added.";
411
412 // if the dimension of the cell is beyond the allocated table,
413 // then increase the table
414 if (n <= d)
416
417 // add the cell to the suitable set of cells
418 tab [d] -> add (c);
419
420 return *this;
421} /* gcomplex<cell,euclidom>::add */
void increasedimension(int d)
Increases the dimension of the complex to take this cell.
Definition: gcomplex.h:1068
int dim() const
Returns the dimension of the complex, that is, the highest dimension of any cell contained in the com...
Definition: gcomplex.h:354
gcomplex< cell, euclidom > & add(const cell &c)
Add a cell to the geometric complex.
Definition: gcomplex.h:405

◆ add() [2/4]

template<class cell , class euclidom >
gcomplex< cell, euclidom > & chomp::homology::gcomplex< cell, euclidom >::add ( const gcomplex< cell, euclidom > &  c)

Adds all the cells from a geometric complex.

Definition at line 449 of file gcomplex.h.

451{
452 // increase the dimension of the complex if necessary
453 if (c. n > n)
454 increasedimension (c. dim ());
455
456 // add the sets of cells
457 for (int i = 0; i < c. n; ++ i)
458 {
459 tab [i] -> add (*(c. tab [i]));
460 /* const hashedset<cell> &cset = *(c. tab [i]);
461 for (int j = 0; j < cset. size (); ++ j)
462 {
463 const cell &thecell = cset [j];
464 tab [i] -> add (thecell);
465 if (cob && c. cob)
466 (*(cob [i])) [thecell] =
467 ((*(c. cob [i])) (thecell));
468 }
469 */
470 }
471
472 return *this;
473} /* gcomplex<cell,euclidom>::add */

◆ add() [3/4]

template<class cell , class euclidom >
gcomplex< cell, euclidom > & chomp::homology::gcomplex< cell, euclidom >::add ( const hashedset< cell > &  c)

Adds a set of cells to the geometric complex.

Definition at line 438 of file gcomplex.h.

440{
441 int_t size = c. size ();
442 for (int_t i = 0; i < size; ++ i)
443 add (c [i]);
444
445 return *this;
446} /* gcomplex<cell,euclidom>::add */
int_t size() const
Returns the number of cells in the complex.
Definition: gcomplex.h:360
int int_t
Index type for indexing arrays, counting cubes, etc.
Definition: config.h:115

◆ add() [4/4]

template<class cell , class euclidom >
gcomplex< cell, euclidom > & chomp::homology::gcomplex< cell, euclidom >::add ( const hashedset< cell > &  c,
int  d 
)
inline

Adds a set of cells to the geometric complex.

It is assumed that all the cells have dimension d.

Definition at line 424 of file gcomplex.h.

426{
427 // increase the dimension of the complex if necessary
428 if (d > n)
430
431 // add the set of cells to the suitable set
432 tab [d] -> add (c);
433
434 return *this;
435} /* gcomplex<cell,euclidom>::add */

◆ addboundaries() [1/10]

template<class cell , class euclidom >
int_t chomp::homology::gcomplex< cell, euclidom >::addboundaries ( bool  addcob = false)
inline

Adds boundaries of all the cells of all dimensions to the geometric complex.

If requested, keeps the information about the coboundaries. Returns the number of cells added.

Definition at line 653 of file gcomplex.h.

654{
655 return addboundaries (NULL, NULL, false, false, addcob);
656} /* gcomplex<cell,euclidom>::addboundaries */
int_t addboundaries(int d, bool addcob=false)
Adds boundaries of all the cells of given dimension to the geometric complex.
Definition: gcomplex.h:647

References chomp::homology::addboundaries().

◆ addboundaries() [2/10]

template<class cell , class euclidom >
int_t chomp::homology::gcomplex< cell, euclidom >::addboundaries ( chaincomplex< euclidom > &  c)
inline

Adds boundaries and also fills in the given chain complex.

Definition at line 680 of file gcomplex.h.

681{
682 return addboundaries (&c, NULL, false, false, false);
683} /* gcomplex<cell,euclidom>::addboundaries */

References chomp::homology::addboundaries().

◆ addboundaries() [3/10]

template<class cell , class euclidom >
int_t chomp::homology::gcomplex< cell, euclidom >::addboundaries ( chaincomplex< euclidom > &  c,
gcomplex< cell, euclidom > &  notthese,
bool  keepused = false 
)
inline

Adds boundaries and also fills in the given chain complex.

Definition at line 694 of file gcomplex.h.

696{
697 return addboundaries (&c, &notthese, false, keepused, false);
698} /* gcomplex<cell,euclidom>::addboundaries */

References chomp::homology::addboundaries().

◆ addboundaries() [4/10]

template<class cell , class euclidom >
int_t chomp::homology::gcomplex< cell, euclidom >::addboundaries ( chaincomplex< euclidom > *  c,
gcomplex< cell, euclidom > *  notthese,
bool  dontadd,
bool  keepused,
bool  addcob 
)

The actual function that is used for all the functions for adding boundaries of all dimensions.

Definition at line 635 of file gcomplex.h.

638{
639 int_t countadded = 0;
640 for (int d = n - 1; d > 0; -- d)
641 countadded += addboundaries (d, c, notthese,
642 dontadd, keepused, addcob);
643 return countadded;
644} /* gcomplex<cell,euclidom>::addboundaries */

References chomp::homology::addboundaries().

◆ addboundaries() [5/10]

template<class cell , class euclidom >
int_t chomp::homology::gcomplex< cell, euclidom >::addboundaries ( gcomplex< cell, euclidom > &  notthese,
bool  keepused = false 
)

Adds boundaries of all the cells of all dimensions to the geometric complex, except for the cells which belong to the geometric complex "notthese".

If "keepused" is set to false, then cells whose boundaries have been added are removed from the geometric complex; otherwise, they are kept there. Returns the number of cells added.

Definition at line 666 of file gcomplex.h.

668{
669 return addboundaries (NULL, &notthese, false, keepused, false);
670} /* gcomplex<cell,euclidom>::addboundaries */

References chomp::homology::addboundaries().

◆ addboundaries() [6/10]

template<class cell , class euclidom >
int_t chomp::homology::gcomplex< cell, euclidom >::addboundaries ( int  d,
bool  addcob = false 
)
inline

Adds boundaries of all the cells of given dimension to the geometric complex.

If requested, keeps the information about the coboundaries. Returns the number of cells added.

Definition at line 647 of file gcomplex.h.

648{
649 return addboundaries (d, NULL, NULL, false, false, addcob);
650} /* gcomplex<cell,euclidom>::addboundaries */

References chomp::homology::addboundaries().

◆ addboundaries() [7/10]

template<class cell , class euclidom >
int_t chomp::homology::gcomplex< cell, euclidom >::addboundaries ( int  d,
chaincomplex< euclidom > &  c 
)
inline

Adds boundaries and also fills in the given chain complex.

Definition at line 673 of file gcomplex.h.

675{
676 return addboundaries (d, &c, NULL, false, false, false);
677} /* gcomplex<cell,euclidom>::addboundaries */

References chomp::homology::addboundaries().

◆ addboundaries() [8/10]

template<class cell , class euclidom >
int_t chomp::homology::gcomplex< cell, euclidom >::addboundaries ( int  d,
chaincomplex< euclidom > &  c,
gcomplex< cell, euclidom > &  notthese,
bool  keepused = false 
)
inline

Adds boundaries and also fills in the given chain complex.

Definition at line 686 of file gcomplex.h.

689{
690 return addboundaries (d, &c, &notthese, false, keepused, false);
691} /* gcomplex<cell,euclidom>::addboundaries */

References chomp::homology::addboundaries().

◆ addboundaries() [9/10]

template<class cell , class euclidom >
int_t chomp::homology::gcomplex< cell, euclidom >::addboundaries ( int  d,
chaincomplex< euclidom > *  c,
gcomplex< cell, euclidom > *  notthese,
bool  dontadd,
bool  keepused,
bool  addcob 
)

The actual function that is used for all the functions for adding boundaries of a fixed dimension.

Definition at line 579 of file gcomplex.h.

582{
583 // if the dimension is inappropriate, do nothing
584 if ((d <= 0) || (d >= n))
585 return 0;
586
587 // first add boundaries to the other cell complex
588 if (notthese && !dontadd)
589 notthese -> addboundaries (d);
590
591 int_t prevsize = tab [d - 1] -> size ();
592 hashedset<cell> &cset = *(tab [d]);
593 for (int_t i = 0; i < cset. size (); ++ i)
594 {
595 const cell &thecell = cset [i];
596 int len = boundarylength (thecell);
597 for (int j = 0; j < len; ++ j)
598 {
599 // take the j-th boundary cell
600 cell bcell = boundarycell (thecell, j);
601
602 // add it to the cell complex unless it is unwanted
603 if (!notthese || !notthese -> check (bcell))
604 {
605 tab [d - 1] -> add (bcell);
606 if (c)
607 {
608 int icoef = boundarycoef (thecell, j);
609 euclidom coef;
610 if (icoef < 0)
611 {
612 coef = -icoef;
613 coef = -coef;
614 }
615 else
616 coef = icoef;
617 c -> add (d, tab [d - 1] ->
618 getnumber (bcell), i, coef);
619 }
620 if (addcob)
621 (*(cob [d - 1])) [bcell].
622 add (thecell);
623 }
624 }
625 }
626
627 // clean the used level in 'notthese'
628 if (notthese && !keepused)
629 notthese -> removeall (d);
630
631 return tab [d - 1] -> size () - prevsize;
632} /* gcomplex<cell,euclidom>::addboundaries */
bool check(const cell &c) const
Check whether the given cell is in the complex.
Definition: gcomplex.h:562
gcomplex< cell, euclidom > & removeall(int d)
Remove all the cells of the given dimension.
Definition: gcomplex.h:543
int boundarylength(const tCellBase< coordtype > &q)
Returns the length of the boundary of a cell.
Definition: cellbase.h:501
tCellBase< coordtype > boundarycell(const tCellBase< coordtype > &q, int i, bool onlyexisting)
Computes the i-th boundary element of a cell.
Definition: cellbase.h:485
int boundarycoef(const tCellBase< coordtype > &q, int i)
Returns the i-th coefficient in the boundary of a cell.
Definition: cellbase.h:508

References chomp::homology::addboundaries(), chomp::homology::boundarycell(), chomp::homology::boundarycoef(), and chomp::homology::boundarylength().

◆ addboundaries() [10/10]

template<class cell , class euclidom >
int_t chomp::homology::gcomplex< cell, euclidom >::addboundaries ( int  d,
gcomplex< cell, euclidom > &  notthese,
bool  keepused = false 
)
inline

Adds boundaries of all the cells of given dimension to the geometric complex, except for the cells which belong to the geometric complex "notthese".

If "keepused" is set to false, then cells whose boundaries have been added are removed from the geometric complex; otherwise, they are kept there. Returns the number of cells added.

Definition at line 659 of file gcomplex.h.

661{
662 return addboundaries (d, NULL, &notthese, false, keepused, false);
663} /* gcomplex<cell,euclidom>::addboundaries */

References chomp::homology::addboundaries().

◆ check()

template<class cell , class euclidom >
bool chomp::homology::gcomplex< cell, euclidom >::check ( const cell &  c) const

Check whether the given cell is in the complex.

Returns true if yes, false if not.

Definition at line 562 of file gcomplex.h.

563{
564 // get the dimension of the cell
565 int d = c. dim ();
566 if (d < 0)
567 throw "Negative dimension of a cell to be checked.";
568
569 // if the dimension of the cell is beyond the allocated table,
570 // then it is not there
571 if (n <= d)
572 return false;
573
574 // check for the existence of the cell in the suitable set of cells
575 return tab [d] -> check (c);
576} /* gcomplex<cell,euclidom>::check */

◆ collapse() [1/2]

template<class cell , class euclidom >
int_t chomp::homology::gcomplex< cell, euclidom >::collapse ( gcomplex< cell, euclidom > &  other,
gcomplex< cell, euclidom > &  keep,
bool  addbd,
bool  addcob,
bool  disjoint,
const int *  level = NULL,
bool  quiet = false 
)

Adds boundaries to 'other' and 'keep', and then does the free face collapses.

Does this at all levels or only the necessary ones. Remove sfrom 'other' cells that are not in the result. If 'disjoint', then removes 'other' from 'this'. Removes from 'keep' cells not contained in the result. Returns the number of collapses performed.

Definition at line 995 of file gcomplex.h.

998{
999 // determine the lower bound for the adding boundaries levels
1000 int dmin = 0;
1001 if (level)
1002 {
1003 while ((dmin < dim ()) && (!level [dmin]))
1004 ++ dmin;
1005 if (dmin && level [dmin])
1006 -- dmin;
1007 }
1008
1009 // add boundaries to high-dimensional cells in 'keep'
1010 while (keep. dim () > dim ())
1011 {
1012 keep. addboundaries (keep. dim ());
1013 keep. removeall (keep. dim ());
1014 }
1015
1016 // add boundaries to high-dimensional cells in 'other'
1017 if (other. dim () > dim ())
1018 {
1019 other. addboundaries (other. dim ());
1020 other. removeall (other. dim ());
1021 }
1022
1023 // add boundaries and collapse in all the dimensions of interest
1024 int_t counter = 0;
1025 for (int d = dim (); d > dmin; -- d)
1026 {
1027 // add boundaries to the other cell complexes
1028 keep. addboundaries (d);
1029
1030 // add boundaries and collapse this level
1031 counter += collapse (d, other, keep, addbd, addcob, disjoint,
1032 quiet);
1033
1034 // remove unnecessary cells from 'other'
1035 if (disjoint)
1036 other. removeall (d);
1037
1038 // remove unnecessary cells from 'keep'
1039 keep. removeall (d);
1040 }
1041
1042 // forget all the other cells of minimal dimension which are not used
1043 if (!disjoint && (dim () >= dmin) && (other. dim () >= dmin))
1044 {
1045 hashedset<cell> &cset = *(tab [dmin]);
1046 hashedset<cell> &cother = *(other. tab [dmin]);
1047 for (int_t i = 0; i < cother. size (); ++ i)
1048 {
1049 if (!(cset. check (cother [i])))
1050 cother. removenum (i --);
1051 }
1052 }
1053
1054 // remove unused cells which were supposed to be kept
1055 if (!keep. empty ())
1056 {
1057 gcomplex<cell,euclidom> empty;
1058 keep = empty;
1059 }
1060
1061 if (!quiet)
1062 scon << ' ';
1063
1064 return counter;
1065} /* gcomplex<cell,euclidom>::collapse */
int_t collapse(int d, gcomplex< cell, euclidom > &other, const gcomplex< cell, euclidom > &keep, bool addbd, bool addcob, bool disjoint, bool quiet=false)
Adds boundaries of all the cells of the given dimension and then performs free face collapses.
Definition: gcomplex.h:752
bool empty() const
Returns 'true' iff the cell complex is empty.
Definition: gcomplex.h:369
outputstream scon
The console output stream to which one should put all the junk that spoils the log file,...

References chomp::homology::addboundaries(), chomp::homology::collapse(), and chomp::homology::scon.

◆ collapse() [2/2]

template<class cell , class euclidom >
int_t chomp::homology::gcomplex< cell, euclidom >::collapse ( int  d,
gcomplex< cell, euclidom > &  other,
const gcomplex< cell, euclidom > &  keep,
bool  addbd,
bool  addcob,
bool  disjoint,
bool  quiet = false 
)

Adds boundaries of all the cells of the given dimension and then performs free face collapses.

Does not remove cells listed in 'keep'. Removes from 'other' and 'this' unnecessary d-dim cells. Returns the number of collapses performed.

Definition at line 752 of file gcomplex.h.

755{
756 if ((d <= 0) || (d > dim ()))
757 return 0;
758
759 // prepare references to the sets of cells of interest
760 hashedset<cell> &cset = *(tab [d]);
761 hashedset<cell> &bset = *(tab [d - 1]);
762 hashedset<cell> empty;
763 hashedset<cell> &cother = (other. dim () >= d) ?
764 *(other. tab [d]) : empty;
765 hashedset<cell> &bother = (other. dim () >= d - 1) ?
766 *(other. tab [d - 1]) : empty;
767 const hashedset<cell> &ckeep = (keep. dim () >= d) ?
768 *(keep. tab [d]) : empty;
769 const hashedset<cell> &bkeep = (keep. dim () >= d - 1) ?
770 *(keep. tab [d - 1]) : empty;
771
772 // show the currently processed dimension
773 if (!quiet)
774 {
775 if (d > 9)
776 scon << "#\b";
777 else
778 scon << d << '\b';
779 }
780
781 // go through all the cells from A and generate their boundaries
782 if (addbd)
783 {
784 if (!quiet)
785 {
786 sseq << "\"Adding boundaries of cells in A...\"\n";
787 sseq << "D 0\n";
788 }
789 for (int_t i = 0; i < cother. size (); ++ i)
790 {
791 // select the given cell in 'cother'
792 const cell &thecell = cother [i];
793
794 // detect the length of the boundary of this cell
795 int blen = boundarylength (thecell);
796
797 // add to 'bother' all the cells in this boundary
798 for (int j = 0; j < blen; ++ j)
799 bother. add (boundarycell (thecell, j));
800
801 // write the boundary cells to the sequential file
802 if (!quiet && (sseq. show || sseq. log))
803 {
804 for (int j = 0; j < blen; ++ j)
805 sseq << '2' << boundarycell
806 (thecell, j) << '\n';
807 }
808 }
809 }
810 if (!quiet)
811 sseq << "D 100\n";
812
813 // if the complexes should be disjoint, remove 'bother' from 'bset'
814 if (disjoint)
815 bset. remove (bother);
816
817 // prepare tables for coboundaries of cells in X and their lengths
818 multitable<int> coblen;
819 multitable<hashedset <cell> > coboundary;
820 if (!bset. empty ())
821 coblen. fill (0, bset. size ());
822
823 // go through the list of all the cells of dimension 'd' in the set,
824 // add their boundaries to 'bset' and create the coboundary links;
825 // note: these cells may appear in the 'other' complex
826 if (!quiet)
827 sseq << "\"Adding boundaries of cells of dimension " <<
828 d << "\"\nD 0\n";
829 bool maximal = (d == dim ());
830 for (int_t i = 0; i < cset. size (); ++ i)
831 {
832 // select the i-th d-dimensional cell
833 const cell &thecell = cset [i];
834
835 // check if this cell belongs to 'cother'
836 bool cbelongs = cother. check (thecell);
837
838 // if this cell should be removed, do it
839 if (cbelongs && (disjoint || maximal))
840 {
841 // if (!quiet && (sseq. show || sseq. log))
842 // sseq << '0' << thecell << '\n';
843 cother. remove (thecell);
844 cset. removenum (i --);
845 continue;
846 }
847
848 // detect the length of the boundary of this cell
849 int blen = boundarylength (thecell);
850
851 // should this cell be kept secure from the collapses?
852 bool keepit = ckeep. check (thecell);
853
854 // go through all the cells in this boundary
855 for (int j = 0; j < blen; ++ j)
856 {
857 // take the j-th boundary cell
858 cell bcell = boundarycell (thecell, j);
859
860 // check if this cell belongs to the other complex
861 bool bbelongs = bother. check (bcell);
862
863 // if it is in 'bother', then skip it if disjoint
864 if (bbelongs && disjoint)
865 continue;
866
867 // add this cell to 'bset' or get its number
868 int_t prev = bset. size ();
869 int_t number = addbd ? bset. add (bcell) :
870 bset. getnumber (bcell);
871
872 // if the cell is not there, skip it
873 if (number < 0)
874 continue;
875
876 // if this is the first occurrence of the cell
877 if ((prev < bset. size ()) || (coblen [number] == 0))
878 {
879 // write it to the sequence if necessary
880 if (!quiet && !bbelongs)
881 sseq << '1' << bcell << '\n';
882
883 // if this cell should be kept, mark it
884 if (keepit || bkeep. check (bset [number]) ||
885 bother. check (bset [number]))
886 coblen [number] = 13;
887 else
888 coblen [number] = 1;
889 coboundary [number]. add (thecell);
890 }
891
892 // otherwise add the corresponding coboundary link
893 else
894 {
895 ++ (coblen [number]);
896 coboundary [number]. add (thecell);
897 }
898 }
899 }
900 if (!quiet)
901 sseq << "D 100\n";
902
903 // show a dot
904 if (!quiet)
905 scon << "*\b";
906
907 // prepare tables for cells to be removed
908 hashedset<cell> cremove, bremove;
909 int_t nremove = 0;
910
911 // go through all the free faces
912 if (!quiet)
913 sseq << "\"Collapsing free faces...\"\n";
914 while (1)
915 {
916 // find a free face
917 int_t ncell = findelem (coblen, 1, bset. size ());
918
919 // if not found then finish
920 if (ncell < 0)
921 break;
922
923 // collapse this cell with its parent cell
924 const cell &parent = coboundary [ncell] [0];
925 int blen = boundarylength (parent);
926 coblen [ncell] = 0;
927
928 // remove the parent cell from coboundaries
929 for (int j = 0; j < blen; ++ j)
930 {
931 cell thecell = boundarycell (parent, j);
932 int_t number = bset. getnumber (thecell);
933 if ((number >= 0) && (coblen [number] > 0))
934 {
935 coboundary [number]. remove (parent);
936 -- (coblen [number]);
937 }
938 }
939
940 // write these cells to the sequence file
941 if (!quiet)
942 {
943 sseq << '0' << bset [ncell] << '\n';
944 sseq << '0' << parent << '\n';
945 }
946
947 // mark these cells for removal
948 cremove. add (parent);
949 bremove. add (bset [ncell]);
950 ++ nremove;
951
952 // clear the coboundary, because it is no longer used
953 coboundary [ncell] = empty;
954 }
955
956 // add the computed coboundaries if required
957 if (addcob)
958 {
959 for (int_t i = 0; i < bset. size (); ++ i)
960 if (!bremove. check (bset [i]))
961 {
962 coboundary [i]. remove (cremove);
963 (*(cob [d - 1])) [bset [i]]. add
964 (coboundary [i]);
965 }
966 }
967
968 // remove cells that are scheduled for removal from 'cset'
969 if (nremove == cset. size ())
970 {
971 removeall (d);
972 other. removeall (d);
973 }
974 else
975 {
976 for (int_t i = 0; i < nremove; ++ i)
977 cset. remove (cremove [i]);
978 }
979
980 // remove from the set of boundary cells these scheduled for removal
981 for (int_t i = 0; i < nremove; ++ i)
982 bset. remove (bremove [i]);
983
984 // update the dimension of the cell complex - is this necessary?
986
987 // show a dot
988 if (!quiet)
989 scon << '.';
990
991 return nremove;
992} /* gcomplex<cell,euclidom>::collapse */
gcomplex< cell, euclidom > & remove(const cell &c)
Remove a cell from the geometric complex.
Definition: gcomplex.h:477
void decreasedimension()
Frees empty sets if there are no cells of high dimensions.
Definition: gcomplex.h:1103
outputstream sseq
An auxiliary stream which captures sequences of processed data.
int_t findelem(const multitable< element > &tab, const element &e, int_t len)
Finds the given element in the table of given length.
Definition: gcomplex.h:705

References chomp::homology::boundarycell(), chomp::homology::boundarylength(), chomp::homology::decreasedimension(), chomp::homology::findelem(), chomp::homology::scon, and chomp::homology::sseq.

◆ decreasedimension()

template<class cell , class euclidom >
void chomp::homology::gcomplex< cell, euclidom >::decreasedimension
private

Frees empty sets if there are no cells of high dimensions.

Definition at line 1103 of file gcomplex.h.

1104{
1105 while (n && tab [n - 1] -> empty ())
1106 {
1107 -- n;
1108 delete tab [n];
1109 delete cob [n];
1110 }
1111 if (!n)
1112 {
1113 delete [] tab;
1114 tab = NULL;
1115 delete [] cob;
1116 cob = NULL;
1117 }
1118 return;
1119} /* gcomplex<cell,euclidom>::decreasedimension */

◆ dim()

template<class cell , class euclidom >
int chomp::homology::gcomplex< cell, euclidom >::dim
inline

Returns the dimension of the complex, that is, the highest dimension of any cell contained in the complex.

Definition at line 354 of file gcomplex.h.

355{
356 return n - 1;
357} /* gcomplex<cell,euclidom>::dim */

◆ empty()

template<class cell , class euclidom >
bool chomp::homology::gcomplex< cell, euclidom >::empty

Returns 'true' iff the cell complex is empty.

Definition at line 369 of file gcomplex.h.

370{
371 if (!n)
372 return true;
373 for (int i = 0; i < n; ++ i)
374 if (!(*(tab [i])). empty ())
375 return false;
376 return true;
377} /* gcomplex<cell,euclidom>::empty */

◆ getcob() [1/2]

template<class cell , class euclidom >
const hashedset< cell > & chomp::homology::gcomplex< cell, euclidom >::getcob ( const cell &  c) const
inline

Returns the coboundary of the given cell.

Definition at line 389 of file gcomplex.h.

391{
392 return getcob (c, c. dim ());
393} /* gcomplex<cell,euclidom>::getcob */
const hashedset< cell > & getcob(const cell &c) const
Returns the coboundary of the given cell.
Definition: gcomplex.h:389

◆ getcob() [2/2]

template<class cell , class euclidom >
const hashedset< cell > & chomp::homology::gcomplex< cell, euclidom >::getcob ( const cell &  c,
int  d 
) const
inline

Returns the coboundary of the given cell.

The dimension of the cell must be given.

Definition at line 396 of file gcomplex.h.

398{
399 if ((d < 0) || (d >= n))
400 throw "Dimension out of range for coboundary.";
401 return (*(cob [d])) (c);
402} /* gcomplex<cell,euclidom>::getcob */

◆ increasedimension()

template<class cell , class euclidom >
void chomp::homology::gcomplex< cell, euclidom >::increasedimension ( int  d)
private

Increases the dimension of the complex to take this cell.

Definition at line 1068 of file gcomplex.h.

1069{
1070 // create a new table for sets of cells
1071 hashedset<cell> **newtab = new hashedset<cell> *[d + 1];
1072 mvmap<cell,cell> **newcob = new mvmap<cell,cell> *[d + 1];
1073
1074 // copy anything that was in the old table
1075 for (int i = 0; i < n; ++ i)
1076 {
1077 newtab [i] = tab [i];
1078 newcob [i] = cob [i];
1079 }
1080
1081 // delete the old table if it was allocated
1082 if (tab)
1083 delete [] tab;
1084 if (cob)
1085 delete [] cob;
1086
1087 // initialize the remaining portion of the new table
1088 tab = newtab;
1089 cob = newcob;
1090 for (int i = n; i < d + 1; ++ i)
1091 {
1092 tab [i] = new hashedset<cell>;
1093 cob [i] = new mvmap<cell,cell>;
1094 }
1095
1096 // set the new dimension
1097 n = d + 1;
1098
1099 return;
1100} /* gcomplex<cell,euclidom>::increasedimension */

◆ operator=()

template<class cell , class euclidom >
gcomplex< cell, euclidom > & chomp::homology::gcomplex< cell, euclidom >::operator= ( const gcomplex< cell, euclidom > &  c)

The assignment operator.

Definition at line 284 of file gcomplex.h.

286{
287 // if the sizes of the tables are not the same, re-allocate the table
288 // and use the copying constructor to create an identical table
289 if (n != c. n)
290 {
291 if (tab)
292 {
293 for (int i = 0; i < n; ++ i)
294 delete tab [i];
295 delete [] tab;
296 }
297 if (cob)
298 {
299 for (int i = 0; i < n; ++ i)
300 delete cob [i];
301 delete [] cob;
302 }
303 n = c. n;
304 if (n > 0)
305 {
306 tab = new hashedset<cell> *[n];
307 cob = new mvmap<cell,cell> *[n];
308 if (!tab || !cob)
309 throw "Cannot copy a geometric complex.";
310 }
311 else
312 {
313 tab = NULL;
314 cob = NULL;
315 }
316 for (int i = 0; i < n; ++ i)
317 {
318 tab [i] = new hashedset<cell> (*(c. tab [i]));
319 cob [i] = new mvmap<cell,cell> (*(c. cob [i]));
320 if (!tab [i] || !cob [i])
321 throw "Cannot copy part of a geom. complex.";
322 }
323 }
324 // otherwise copy the source table to this complex
325 else
326 {
327 for (int i = 0; i < n; ++ i)
328 {
329 *(tab [i]) = *(c. tab [i]);
330 *(cob [i]) = *(c. cob [i]);
331 }
332 }
333 return *this;
334} /* gcomplex<cell,euclidom>::operator = */

◆ operator[]()

template<class cell , class euclidom >
const hashedset< cell > & chomp::homology::gcomplex< cell, euclidom >::operator[] ( int  d) const
inline

Returns the set of cells of the given dimension.

Definition at line 380 of file gcomplex.h.

382{
383 if ((d < 0) || (d >= n))
384 throw "Dimension out of range for retrieving cells.";
385 return *(tab [d]);
386} /* gcomplex<cell,euclidom>::operator [] */

◆ remove() [1/4]

template<class cell , class euclidom >
gcomplex< cell, euclidom > & chomp::homology::gcomplex< cell, euclidom >::remove ( const cell &  c)
inline

Remove a cell from the geometric complex.

Definition at line 476 of file gcomplex.h.

478{
479 // get the dimension of the cell
480 int d = c. dim ();
481 if (d < 0)
482 throw "Negative dimension of a cell to be removed.";
483
484 // if the dimension of the cell is beyond the allocated table,
485 // then ignore it
486 if (n <= d)
487 return *this;
488
489 // remove the cell from the suitable set of cells
490 tab [d] -> remove (c);
491
492 // decrease the dimension of the complex if no cells remain
493 if ((d == n - 1) && tab [d] -> empty ())
495
496 return *this;
497} /* gcomplex<cell,euclidom>::remove */

References chomp::homology::decreasedimension().

◆ remove() [2/4]

template<class cell , class euclidom >
gcomplex< cell, euclidom > & chomp::homology::gcomplex< cell, euclidom >::remove ( const gcomplex< cell, euclidom > &  c)

Adds all the cells from a geometric complex.

Definition at line 500 of file gcomplex.h.

502{
503 // figure out the number of tables to work on
504 int m = c. n;
505 if (m > n)
506 m = n;
507
508 // remove the sets of cells
509 for (int i = 0; i < m; ++ i)
510 tab [i] -> remove (*(c. tab [i]));
511
512 // decrease the dimension of the complex if no highdim cells remain
514
515 return *this;
516} /* gcomplex<cell,euclidom>::remove */

References chomp::homology::decreasedimension().

◆ remove() [3/4]

template<class cell , class euclidom >
gcomplex< cell, euclidom > & chomp::homology::gcomplex< cell, euclidom >::remove ( const hashedset< cell > &  c)

Removes a set of cells to the geometric complex.

Definition at line 532 of file gcomplex.h.

534{
535 int_t size = c. size ();
536 for (int_t i = 0; i < size; ++ i)
537 remove (c [i]);
538
539 return *this;
540} /* gcomplex<cell,euclidom>::remove */

◆ remove() [4/4]

template<class cell , class euclidom >
gcomplex< cell, euclidom > & chomp::homology::gcomplex< cell, euclidom >::remove ( const hashedset< cell > &  c,
int  d 
)
inline

Removes a set of cells to the geometric complex.

It is assumed that all the cells have dimension d.

Definition at line 519 of file gcomplex.h.

521{
522 // remove the set of cells to the suitable set
523 tab [d] -> remove (c);
524
525 // decrease the dimension of the complex if no highdim cells remain
527
528 return *this;
529} /* gcomplex<cell,euclidom>::remove */

References chomp::homology::decreasedimension().

◆ removeall()

template<class cell , class euclidom >
gcomplex< cell, euclidom > & chomp::homology::gcomplex< cell, euclidom >::removeall ( int  d)

Remove all the cells of the given dimension.

Definition at line 543 of file gcomplex.h.

544{
545 if (d == n - 1)
546 {
547 -- n;
548 delete tab [n];
549 delete cob [n];
551 }
552 else if ((d >= 0) && (d < n))
553 {
554 delete tab [d];
555 tab [d] = new hashedset<cell>;
556 }
557
558 return *this;
559} /* gcomplex<cell,euclidom>::removeall */

References chomp::homology::decreasedimension().

◆ size()

template<class cell , class euclidom >
int_t chomp::homology::gcomplex< cell, euclidom >::size

Returns the number of cells in the complex.

Definition at line 360 of file gcomplex.h.

361{
362 int_t count = 0;
363 for (int i = 0; i < n; ++ i)
364 count += tab [i] -> size ();
365 return count;
366} /* gcomplex<cell,euclidom>::size */

Member Data Documentation

◆ cob

template<class cell , class euclidom >
mvmap<cell,cell>** chomp::homology::gcomplex< cell, euclidom >::cob
private

The tables with coboundaries of cells of these dimensions.

Definition at line 236 of file gcomplex.h.

◆ n

template<class cell , class euclidom >
int chomp::homology::gcomplex< cell, euclidom >::n
private

The number of tables.

Definition at line 239 of file gcomplex.h.

◆ tab

template<class cell , class euclidom >
hashedset<cell>** chomp::homology::gcomplex< cell, euclidom >::tab
private

The tables with cells of dimension 0, 1, 2, etc.

Definition at line 233 of file gcomplex.h.


The documentation for this class was generated from the following file: