From ca727209ba8a19462c3a11aa8d52a2662762ca81 Mon Sep 17 00:00:00 2001 From: Matti Pellika <matti.pellikka@tut.fi> Date: Thu, 25 Jun 2009 13:05:58 +0000 Subject: [PATCH] Added ability to "sacrifice" higher dimensional generators of homology groups in order to compute lower dimensional generators faster. --- Geo/CellComplex.cpp | 28 ++++++++++++++++------------ Geo/CellComplex.h | 4 ++-- Geo/Homology.cpp | 9 +++++---- Geo/Homology.h | 12 +++++++++++- Plugin/HomologyComputation.cpp | 13 +++++++------ 5 files changed, 41 insertions(+), 25 deletions(-) diff --git a/Geo/CellComplex.cpp b/Geo/CellComplex.cpp index 176260c60b..bf2ccd4894 100644 --- a/Geo/CellComplex.cpp +++ b/Geo/CellComplex.cpp @@ -365,7 +365,7 @@ int CellComplex::reduction(int dim){ } -int CellComplex::reduceComplex(bool omitHighdim){ +int CellComplex::reduceComplex(int omit){ printf("Cell complex before reduction: %d volumes, %d faces, %d edges and %d vertices.\n", getSize(3), getSize(2), getSize(1), getSize(0)); @@ -375,14 +375,17 @@ int CellComplex::reduceComplex(bool omitHighdim){ int omitted = 0; - if(count == 0 && omitHighdim){ + if(omit > getDim()) omit = getDim(); + for(int i = 0; i < omit; i++){ + //if(count == 0 && omit > 0){ CellComplex::removeSubdomain(); CellComplex::removeSubdomain(); std::set<Cell*, Less_Cell> generatorCells; - while (getSize(getDim()) != 0){ - citer cit = firstCell(getDim()); + + while (getSize(getDim()-i) != 0){ + citer cit = firstCell(getDim()-i); Cell* cell = *cit; generatorCells.insert(cell); @@ -400,7 +403,7 @@ int CellComplex::reduceComplex(bool omitHighdim){ Cell* cell = *cit; cell->clearBoundary(); cell->clearCoboundary(); - _cells[getDim()].insert(cell); + _cells[getDim()-i].insert(cell); } @@ -429,7 +432,7 @@ void CellComplex::removeSubdomain(){ } -int CellComplex::coreduceComplex(bool omitLowdim){ +int CellComplex::coreduceComplex(int omit){ printf("Cell complex before coreduction: %d volumes, %d faces, %d edges and %d vertices.\n", getSize(3), getSize(2), getSize(1), getSize(0)); @@ -450,14 +453,16 @@ int CellComplex::coreduceComplex(bool omitLowdim){ } int omitted = 0; - if(count == 0 && omitLowdim){ + //if(count == 0 && omit > 0){ + if(omit > getDim()) omit = getDim(); + for(int i = 0; i < omit; i++){ std::set<Cell*, Less_Cell> generatorCells; - while (getSize(0) != 0){ - citer cit = firstCell(0); + while (getSize(i) != 0){ + citer cit = firstCell(i); Cell* cell = *cit; generatorCells.insert(cell); removeCell(cell); - coreduceComplex(false); + coreduceComplex(0); //coreduction(cell); omitted++; } @@ -466,10 +471,9 @@ int CellComplex::coreduceComplex(bool omitLowdim){ Cell* cell = *cit; cell->clearBoundary(); cell->clearCoboundary(); - _cells[0].insert(cell); + _cells[i].insert(cell); } - } printf("Cell complex after coreduction: %d volumes, %d faces, %d edges and %d vertices.\n", diff --git a/Geo/CellComplex.h b/Geo/CellComplex.h index 0214377889..b83d700c79 100644 --- a/Geo/CellComplex.h +++ b/Geo/CellComplex.h @@ -766,8 +766,8 @@ class CellComplex // useful functions for (co)reduction of cell complex - int reduceComplex(bool omitHighdim = false); - int coreduceComplex(bool omitlowDim = false); + int reduceComplex(int omit = 0); + int coreduceComplex(int omit = 0); // add every volume, face and edge its missing boundary cells diff --git a/Geo/Homology.cpp b/Geo/Homology.cpp index 39b7eba797..657de3d120 100644 --- a/Geo/Homology.cpp +++ b/Geo/Homology.cpp @@ -15,6 +15,7 @@ Homology::Homology(GModel* model, std::vector<int> physicalDomain, std::vector<i _model = model; _combine = true; + _omit = 1; Msg::Info("Creating a Cell Complex..."); double t1 = Cpu(); @@ -76,7 +77,7 @@ void Homology::findGenerators(std::string fileName){ Msg::Info("Reducing Cell Complex..."); double t1 = Cpu(); - int omitted = _cellComplex->reduceComplex(true); + int omitted = _cellComplex->reduceComplex(_omit); if(getCombine()){ _cellComplex->combine(3); @@ -129,7 +130,7 @@ void Homology::findGenerators(std::string fileName){ Msg::Info("H1 = %d", HRank[1]); Msg::Info("H2 = %d", HRank[2]); Msg::Info("H3 = %d", HRank[3]); - if(omitted != 0) Msg::Info("Computation of %dD generators was omitted.", _cellComplex->getDim()); + if(omitted != 0) Msg::Info("Computation of generators in %d highest dimensions was omitted.", _omit); Msg::Info("Wrote results to %s.", fileName.c_str()); @@ -149,7 +150,7 @@ void Homology::findThickCuts(std::string fileName){ Msg::Info("Reducing Cell Complex..."); double t1 = Cpu(); - int omitted = _cellComplex->coreduceComplex(true); + int omitted = _cellComplex->coreduceComplex(_omit); //for(int i = 0; i < 4; i++) { printf("Dim %d: \n", i); _cellComplex->printComplex(i); } //_cellComplex->coreduceComplex(false); //_cellComplex->checkCoherence(); @@ -207,7 +208,7 @@ void Homology::findThickCuts(std::string fileName){ Msg::Info("H1 = %d", HRank[1]); Msg::Info("H2 = %d", HRank[2]); Msg::Info("H3 = %d", HRank[3]); - if(omitted != 0) Msg::Info("Computation of %dD thick cuts was omitted.", dim); + if(omitted != 0) Msg::Info("Computation of %d highest dimension thick cuts was omitted.", _omit); Msg::Info("Wrote results to %s.", fileName.c_str()); diff --git a/Geo/Homology.h b/Geo/Homology.h index e53ca8bd8d..fd572aeb96 100644 --- a/Geo/Homology.h +++ b/Geo/Homology.h @@ -29,6 +29,7 @@ class Homology GModel* _model; bool _combine; + int _omit; public: @@ -42,7 +43,16 @@ class Homology void findThickCuts(std::string fileName); void swapSubdomain() { _cellComplex->swapSubdomain(); } - + + int getOmit() {return _omit; } + void setOmit(int omit) { + if(omit > _cellComplex->getDim() || omit < 0) { + Msg::Error("Invalid number of dimensions to omit. Must be between 0 - %d.", _cellComplex->getDim()); + Msg::Warning("Set to omit 1 dimension."); + _omit = 1; + } + else _omit = omit; + } }; #endif diff --git a/Plugin/HomologyComputation.cpp b/Plugin/HomologyComputation.cpp index 41d6e8cbfb..6968bdf1bd 100644 --- a/Plugin/HomologyComputation.cpp +++ b/Plugin/HomologyComputation.cpp @@ -21,8 +21,7 @@ StringXNumber HomologyComputationOptions_Number[] = { {GMSH_FULLRC, "2. Physical group for subdomain", NULL, 0.}, {GMSH_FULLRC, "Compute generators", NULL, 1.}, {GMSH_FULLRC, "Compute thick cuts", NULL, 0.}, - {GMSH_FULLRC, "Swap subdomain", NULL, 0.}, - {GMSH_FULLRC, "Combine cells", NULL, 1.} + {GMSH_FULLRC, "Omit dimensions", NULL, 1.}, }; StringXString HomologyComputationOptions_String[] = { @@ -98,16 +97,18 @@ PView *GMSH_HomologyComputationPlugin::execute(PView *v) int gens = (int)HomologyComputationOptions_Number[4].def; int cuts = (int)HomologyComputationOptions_Number[5].def; - int swap = (int)HomologyComputationOptions_Number[6].def; - int combine = (int)HomologyComputationOptions_Number[7].def; + int omit = (int)HomologyComputationOptions_Number[6].def; + //int combine = (int)HomologyComputationOptions_Number[7].def; + GModel *m = GModel::current(); Homology* homology = new Homology(m, domain, subdomain); - if(combine == 0) homology->setCombine(false); + //if(combine == 0) homology->setCombine(false); + homology->setOmit(omit); + //if(swap == 1) homology->swapSubdomain(); - if(swap == 1) homology->swapSubdomain(); if(gens == 1 && cuts != 1) { homology->findGenerators(fileName); GmshMergeFile(fileName); -- GitLab