Skip to content
Snippets Groups Projects
Commit a4bf0b0d authored by Matti Pellika's avatar Matti Pellika
Browse files

Not not prepare to restore cell complex if not necessary.

parent 0ba0fc79
No related branches found
No related tags found
No related merge requests found
...@@ -10,8 +10,9 @@ ...@@ -10,8 +10,9 @@
CellComplex::CellComplex(GModel* model, CellComplex::CellComplex(GModel* model,
std::vector<MElement*>& domainElements, std::vector<MElement*>& domainElements,
std::vector<MElement*>& subdomainElements) : std::vector<MElement*>& subdomainElements,
_model(model), _dim(0), _simplicial(true), _saveorig(true) bool saveOriginalComplex) :
_model(model), _dim(0), _simplicial(true), _saveorig(saveOriginalComplex)
{ {
_insertCells(subdomainElements, 1); _insertCells(subdomainElements, 1);
...@@ -20,7 +21,7 @@ CellComplex::CellComplex(GModel* model, ...@@ -20,7 +21,7 @@ CellComplex::CellComplex(GModel* model,
int num = 0; int num = 0;
for(int dim = 0; dim < 4; dim++){ for(int dim = 0; dim < 4; dim++){
if(getSize(dim) != 0) _dim = dim; if(getSize(dim) != 0) _dim = dim;
_ocells[dim] = _cells[dim]; if(_saveorig) _ocells[dim] = _cells[dim];
for(citer cit = firstCell(dim); cit != lastCell(dim); cit++){ for(citer cit = firstCell(dim); cit != lastCell(dim); cit++){
Cell* cell = *cit; Cell* cell = *cit;
cell->setNum(++num); cell->setNum(++num);
...@@ -71,11 +72,19 @@ bool CellComplex::_insertCells(std::vector<MElement*>& elements, ...@@ -71,11 +72,19 @@ bool CellComplex::_insertCells(std::vector<MElement*>& elements,
CellComplex::~CellComplex() CellComplex::~CellComplex()
{ {
for(int i = 0; i < 4; i++){ for(int i = 0; i < 4; i++){
if(_saveorig) {
for(citer cit = _ocells[i].begin(); cit != _ocells[i].end(); cit++){ for(citer cit = _ocells[i].begin(); cit != _ocells[i].end(); cit++){
Cell* cell = *cit; Cell* cell = *cit;
delete cell; delete cell;
} }
} }
else {
for(citer cit = _cells[i].begin(); cit != _cells[i].end(); cit++){
Cell* cell = *cit;
delete cell;
}
}
}
for(unsigned int i = 0; i < _newcells.size(); i++) delete _newcells.at(i); for(unsigned int i = 0; i < _newcells.size(); i++) delete _newcells.at(i);
for(unsigned int i = 0; i < _removedcells.size(); i++) delete _removedcells.at(i); for(unsigned int i = 0; i < _removedcells.size(); i++) delete _removedcells.at(i);
} }
...@@ -94,7 +103,7 @@ void CellComplex::insertCell(Cell* cell) ...@@ -94,7 +103,7 @@ void CellComplex::insertCell(Cell* cell)
void CellComplex::removeCell(Cell* cell, bool other) void CellComplex::removeCell(Cell* cell, bool other)
{ {
if(!hasCell(cell)) return; //if(!hasCell(cell)) return;
std::map<Cell*, short int, Less_Cell > coboundary; std::map<Cell*, short int, Less_Cell > coboundary;
cell->getCoboundary(coboundary); cell->getCoboundary(coboundary);
std::map<Cell*, short int, Less_Cell > boundary; std::map<Cell*, short int, Less_Cell > boundary;
...@@ -120,7 +129,8 @@ void CellComplex::removeCell(Cell* cell, bool other) ...@@ -120,7 +129,8 @@ void CellComplex::removeCell(Cell* cell, bool other)
bdCell->removeCoboundaryCell(cell, false); bdCell->removeCoboundaryCell(cell, false);
}*/ }*/
_cells[cell->getDim()].erase(cell); int erased = _cells[cell->getDim()].erase(cell);
if(!erased) Msg::Debug("Tried to remove a cell from the cell complex \n");
if(!_saveorig && !cell->isCombined()) _removedcells.push_back(cell); if(!_saveorig && !cell->isCombined()) _removedcells.push_back(cell);
} }
......
...@@ -60,7 +60,8 @@ class CellComplex ...@@ -60,7 +60,8 @@ class CellComplex
public: public:
CellComplex(GModel* model, CellComplex(GModel* model,
std::vector<MElement*>& domainElements, std::vector<MElement*>& domainElements,
std::vector<MElement*>& subdomainElements); std::vector<MElement*>& subdomainElements,
bool saveOriginalComplex=true);
~CellComplex(); ~CellComplex();
......
...@@ -2762,8 +2762,9 @@ void GModel::computeHomology() ...@@ -2762,8 +2762,9 @@ void GModel::computeHomology()
std::pair<std::multimap<dpair, std::string>::iterator, std::pair<std::multimap<dpair, std::string>::iterator,
std::multimap<dpair, std::string>::iterator> itp = std::multimap<dpair, std::string>::iterator> itp =
_homologyRequests.equal_range(*it); _homologyRequests.equal_range(*it);
bool prepareToRestore = (itp.first != itp.second);
Homology* homology = new Homology(this, itp.first->first.first, Homology* homology = new Homology(this, itp.first->first.first,
itp.first->first.second, false); itp.first->first.second, false, prepareToRestore);
CellComplex *cellcomplex = homology->createCellComplex(); CellComplex *cellcomplex = homology->createCellComplex();
if(cellcomplex->getSize(0)){ if(cellcomplex->getSize(0)){
for(std::multimap<dpair, std::string>::iterator itt = itp.first; for(std::multimap<dpair, std::string>::iterator itt = itp.first;
......
...@@ -15,10 +15,12 @@ ...@@ -15,10 +15,12 @@
#if defined(HAVE_KBIPACK) #if defined(HAVE_KBIPACK)
Homology::Homology(GModel* model, std::vector<int> physicalDomain, Homology::Homology(GModel* model, std::vector<int> physicalDomain,
std::vector<int> physicalSubdomain, bool save0N, std::vector<int> physicalSubdomain,
bool save0N, bool saveOrig,
bool combine, bool omit, bool smoothen) : bool combine, bool omit, bool smoothen) :
_model(model), _domain(physicalDomain), _subdomain(physicalSubdomain), _model(model), _domain(physicalDomain), _subdomain(physicalSubdomain),
_save0N(save0N), _combine(combine), _omit(omit), _smoothen(smoothen) _save0N(save0N), _saveOrig(saveOrig),
_combine(combine), _omit(omit), _smoothen(smoothen)
{ {
_fileName = ""; _fileName = "";
...@@ -90,7 +92,8 @@ CellComplex* Homology::createCellComplex(std::vector<GEntity*>& domainEntities, ...@@ -90,7 +92,8 @@ CellComplex* Homology::createCellComplex(std::vector<GEntity*>& domainEntities,
CellComplex* cellComplex = new CellComplex(_model, CellComplex* cellComplex = new CellComplex(_model,
domainElements, domainElements,
subdomainElements); subdomainElements,
_saveOrig);
if(cellComplex->getSize(0) == 0){ if(cellComplex->getSize(0) == 0){
Msg::Error("Cell Complex is empty: check the domain and the mesh"); Msg::Error("Cell Complex is empty: check the domain and the mesh");
......
...@@ -52,6 +52,7 @@ class Homology ...@@ -52,6 +52,7 @@ class Homology
// save chains of 0 and highest dimension // save chains of 0 and highest dimension
bool _save0N; bool _save0N;
bool _saveOrig;
int _maxdomain; int _maxdomain;
int _maxnum; int _maxnum;
...@@ -64,7 +65,8 @@ class Homology ...@@ -64,7 +65,8 @@ class Homology
public: public:
Homology(GModel* model, std::vector<int> physicalDomain, Homology(GModel* model, std::vector<int> physicalDomain,
std::vector<int> physicalSubdomain, bool save0N=false, std::vector<int> physicalSubdomain,
bool save0N=false, bool saveOrig=true,
bool combine=true, bool omit=true, bool smoothen=true); bool combine=true, bool omit=true, bool smoothen=true);
~Homology(); ~Homology();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment