From 74e4b11b9493a309318dedb8400a8e5f04f8b069 Mon Sep 17 00:00:00 2001 From: Matti Pellika <matti.pellikka@tut.fi> Date: Wed, 28 Mar 2012 05:31:04 +0000 Subject: [PATCH] Cleaning --- Geo/Cell.h | 1 + Geo/CellComplex.cpp | 20 ++++++++++++++------ Geo/CellComplex.h | 2 +- Geo/ChainComplex.cpp | 15 +++++++++++++-- Geo/ChainComplex.h | 6 ++---- 5 files changed, 31 insertions(+), 13 deletions(-) diff --git a/Geo/Cell.h b/Geo/Cell.h index 4e18beb45f..9fd14e014d 100644 --- a/Geo/Cell.h +++ b/Geo/Cell.h @@ -72,6 +72,7 @@ class Cell { Cell(Cell* parent, int i); int getDomain() const { return _domain; } + void setDomain(int domain) { _domain = domain; } int getNum() const { return _num; } void setNum(int num) { _num = num; }; int getTypeMSH() const; diff --git a/Geo/CellComplex.cpp b/Geo/CellComplex.cpp index cf4021e3fa..3d59c7fac1 100644 --- a/Geo/CellComplex.cpp +++ b/Geo/CellComplex.cpp @@ -19,7 +19,6 @@ CellComplex::CellComplex(GModel* model, _insertCells(subdomainElements, 1); _insertCells(domainElements, 0); _immunizeCells(immuneElements); - int num = 0; for(int dim = 0; dim < 4; dim++){ if(getSize(dim) != 0) _dim = dim; @@ -48,8 +47,13 @@ bool CellComplex::_insertCells(std::vector<MElement*>& elements, if(type == TYPE_QUA || type == TYPE_HEX) _simplicial = false; Cell* cell = new Cell(element, domain); - bool insert = _cells[cell->getDim()].insert(cell).second; - if(!insert) delete cell; + std::pair<citer, bool> insert = + _cells[cell->getDim()].insert(cell); + if(!insert.second) { + delete cell; + cell = *(insert.first); + if(domain) cell->setDomain(domain); + } } for (int dim = 3; dim > 0; dim--){ @@ -62,6 +66,7 @@ bool CellComplex::_insertCells(std::vector<MElement*>& elements, if(!insert.second) { delete newCell; newCell = *(insert.first); + if(domain) newCell->setDomain(domain); } if(domain == 0) { int ori = cell->findBdCellOrientation(newCell, i); @@ -83,6 +88,7 @@ bool CellComplex::_immunizeCells(std::vector<MElement*>& elements) if(cit != lastCell(dim)) (*cit)->setImmune(true); delete cell; } + return true; } CellComplex::~CellComplex() @@ -285,7 +291,7 @@ int CellComplex::reduceComplex(bool docombine, bool omit) std::vector<Cell*> empty; for(int i = 3; i > 0; i--) count = count + reduction(i, false, empty); - if(omit){ + if(omit && !count){ removeSubdomain(); std::vector<Cell*> newCells; @@ -318,7 +324,8 @@ int CellComplex::reduceComplex(bool docombine, bool omit) if(docombine) combine(1); Msg::Debug(" %d volumes, %d faces, %d edges and %d vertices", - getSize(3), getSize(2), getSize(1), getSize(0)); + getSize(3), getSize(2), getSize(1), getSize(0)); + _reduced = true; return 0; } @@ -355,7 +362,7 @@ int CellComplex::coreduceComplex(bool docombine, bool omit) } } - if(omit){ + if(omit && !count){ std::vector<Cell*> newCells; while (getSize(0) != 0){ citer cit = firstCell(0); @@ -386,6 +393,7 @@ int CellComplex::coreduceComplex(bool docombine, bool omit) coherent(); Msg::Debug(" %d volumes, %d faces, %d edges and %d vertices", getSize(3), getSize(2), getSize(1), getSize(0)); + _reduced = true; return 0; } diff --git a/Geo/CellComplex.h b/Geo/CellComplex.h index 3f149d4195..c6d4a76bf4 100644 --- a/Geo/CellComplex.h +++ b/Geo/CellComplex.h @@ -38,8 +38,8 @@ class CellComplex std::vector<Cell*> _newcells; std::vector<Cell*> _removedcells; - bool _simplicial; int _dim; + bool _simplicial; bool _saveorig; int _deleteCount; diff --git a/Geo/ChainComplex.cpp b/Geo/ChainComplex.cpp index 4506f124dc..bf57dcf797 100644 --- a/Geo/ChainComplex.cpp +++ b/Geo/ChainComplex.cpp @@ -38,11 +38,12 @@ ChainComplex::ChainComplex(CellComplex* cellComplex, int domain) if((domain == 0 && !cell->inSubdomain()) || domain == 1 || (domain == 2 && cell->inSubdomain()) ){ cols++; -_cellIndices[dim][cell] = index; + _cellIndices[dim][cell] = index; index++; } else _cellIndices[dim][cell] = 0; } + if(dim > 0) rows = lastCols; lastCols = cols; @@ -54,7 +55,6 @@ _cellIndices[dim][cell] = index; _HMatrix[dim] = create_gmp_matrix_zero(1, cols); //_HMatrix[dim] = NULL; } - else{ mpz_t elem; mpz_init(elem); @@ -117,6 +117,17 @@ ChainComplex::~ChainComplex() } } +void ChainComplex::transposeHMatrices() +{ + for(int i = 0; i < 5; i++) + if(_HMatrix[i] != NULL) gmp_matrix_transp(_HMatrix[i]); +} +void ChainComplex::transposeHMatrix(int dim) +{ + if(dim > -1 && dim < 5 && _HMatrix[dim] != NULL) + gmp_matrix_transp(_HMatrix[dim]); +} + void ChainComplex::KerCod(int dim) { if(dim < 0 || dim > 3 || _HMatrix[dim] == NULL) return; diff --git a/Geo/ChainComplex.h b/Geo/ChainComplex.h index 45a7b3e9b0..5a1b46540e 100644 --- a/Geo/ChainComplex.h +++ b/Geo/ChainComplex.h @@ -133,10 +133,8 @@ class ChainComplex // transpose the boundary operator matrices, these are boundary operator // matrices for the dual mesh - void transposeHMatrices() { - for(int i = 0; i < 5; i++) gmp_matrix_transp(_HMatrix[i]); } - void transposeHMatrix(int dim) { - if(dim > -1 && dim < 5) gmp_matrix_transp(_HMatrix[dim]); } + void transposeHMatrices(); + void transposeHMatrix(int dim); // Compute bases for the homology groups of this chain complex void computeHomology(bool dual=false); -- GitLab