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

Tuning.

parent f03912b5
No related branches found
No related tags found
No related merge requests found
...@@ -84,6 +84,23 @@ class Cell ...@@ -84,6 +84,23 @@ class Cell
virtual MElement* getImageMElement() const { return _image; }; virtual MElement* getImageMElement() const { return _image; };
// get the number of vertices this cell has
virtual int getNumVertices() const { return _image->getNumVertices(); }
// get the number of facets of this cell
virtual int getNumFacets() const;
// get the vertices on a facet of this cell
virtual void getFacetVertices(const int num, std::vector<MVertex*> &v) const;
// get boundary cell orientation
virtual int getFacetOri(std::vector<MVertex*> &v);
virtual int getFacetOri(Cell* cell) {
std::vector<MVertex*> v;
for(int i = 0; i < cell->getNumVertices(); i++) {
v.push_back(cell->getVertex(i));
}
return getFacetOri(v);
}
virtual int getDim() const { return _dim; }; virtual int getDim() const { return _dim; };
virtual int getIndex() const { return _index; }; virtual int getIndex() const { return _index; };
virtual void setIndex(int index) { _index = index; }; virtual void setIndex(int index) { _index = index; };
...@@ -94,9 +111,6 @@ class Cell ...@@ -94,9 +111,6 @@ class Cell
virtual void setDeleteImage(bool deleteImage) { virtual void setDeleteImage(bool deleteImage) {
_deleteImage = deleteImage; }; _deleteImage = deleteImage; };
virtual bool getDeleteImage() const { return _deleteImage; }; virtual bool getDeleteImage() const { return _deleteImage; };
// get the number of vertices this cell has
virtual int getNumVertices() const { return _image->getNumVertices(); }
virtual int getSortedVertex(int vertex) const { return _vs.at(vertex); } virtual int getSortedVertex(int vertex) const { return _vs.at(vertex); }
// restores the cell information to its original state before reduction // restores the cell information to its original state before reduction
...@@ -147,21 +161,6 @@ class Cell ...@@ -147,21 +161,6 @@ class Cell
virtual void printBoundary(bool org=false); virtual void printBoundary(bool org=false);
virtual void printCoboundary(bool org=false); virtual void printCoboundary(bool org=false);
// get the number of facets of this cell
virtual int getNumFacets() const;
// get the vertices on a facet of this cell
virtual void getFacetVertices(const int num, std::vector<MVertex*> &v) const;
// get boundary cell orientation
virtual int getFacetOri(std::vector<MVertex*> &v);
virtual int getFacetOri(Cell* cell) {
std::vector<MVertex*> v;
for(int i = 0; i < cell->getNumVertices(); i++) {
v.push_back(cell->getVertex(i));
}
return getFacetOri(v);
}
// tools for combined cells // tools for combined cells
virtual bool isCombined() { return _combined; } virtual bool isCombined() { return _combined; }
virtual void getCells( std::list< std::pair<int, Cell*> >& cells) { virtual void getCells( std::list< std::pair<int, Cell*> >& cells) {
...@@ -183,6 +182,14 @@ class Cell ...@@ -183,6 +182,14 @@ class Cell
} }
return true; return true;
} }
/*
Cell operator=(const Cell& c2) {
Cell cell;
cell._ocbd = c2._ocbd;
return cell;
}
Cell(const Cell& c2){ *this = c2; }*/
}; };
// A cell that is a combination of cells of same dimension // A cell that is a combination of cells of same dimension
...@@ -194,17 +201,20 @@ class CombinedCell : public Cell{ ...@@ -194,17 +201,20 @@ class CombinedCell : public Cell{
// list of cells this cell is a combination of // list of cells this cell is a combination of
std::list< std::pair<int, Cell*> > _cells; std::list< std::pair<int, Cell*> > _cells;
MVertex* getVertex(int vertex) const { return NULL; } MVertex* getVertex(int vertex) const {
printf("ERROR: No mesh vertices for combined cell."); }
public: public:
CombinedCell(Cell* c1, Cell* c2, bool orMatch, bool co=false); CombinedCell(Cell* c1, Cell* c2, bool orMatch, bool co=false);
~CombinedCell() {} ~CombinedCell() {}
int getNum() const { return 0; } MElement* getImageMElement() const {
int getType() const { return 0; } printf("ERROR: No image mesh element for combined cell."); }
int getTypeForMSH() const { return 0; } int getNumFacets() const { return 0; }
int getPartition() const { return 0; } void getFacetVertices(const int num, std::vector<MVertex*> &v) const {}
int getFacetOri(std::vector<MVertex*> &v) { return 0; }
int getFacetOri(Cell* cell) { return 0; }
int getNumVertices() const { return _vs.size(); } int getNumVertices() const { return _vs.size(); }
int getSortedVertex(int vertex) const { return _vs.at(vertex); } int getSortedVertex(int vertex) const { return _vs.at(vertex); }
......
...@@ -621,4 +621,23 @@ void CellComplex::getCells(std::set<Cell*, Less_Cell>& cells, ...@@ -621,4 +621,23 @@ void CellComplex::getCells(std::set<Cell*, Less_Cell>& cells,
} }
} }
} }
void CellComplex::restoreComplex()
{
for(int i = 0; i < 4; i++){
_cells[i] = _ocells[i];
for(citer cit = firstCell(i); cit != lastCell(i); cit++){
Cell* cell = *cit;
cell->restoreCell();
}
}
for(unsigned int i = 0; i < _newcells.size(); i++){
Cell* cell = _newcells.at(i);
delete cell;
}
_newcells.clear();
_store.clear();
}
#endif #endif
...@@ -131,6 +131,8 @@ class CellComplex ...@@ -131,6 +131,8 @@ class CellComplex
int getNumOmitted() { return _store.size(); } int getNumOmitted() { return _store.size(); }
std::set<Cell*, Less_Cell> getOmitted(int i) { return _store.at(i); } std::set<Cell*, Less_Cell> getOmitted(int i) { return _store.at(i); }
void restoreComplex();
}; };
#endif #endif
......
...@@ -108,10 +108,14 @@ Homology::~Homology() ...@@ -108,10 +108,14 @@ Homology::~Homology()
} }
void Homology::findGenerators() void Homology::findGenerators(CellComplex* cellComplex)
{ {
bool ownComplex = false;
if(cellComplex==NULL){
CellComplex* cellComplex = createCellComplex(_domainEntities, CellComplex* cellComplex = createCellComplex(_domainEntities,
_subdomainEntities); _subdomainEntities);
ownComplex = true;
}
std::string domainString = getDomainString(_domain, _subdomain); std::string domainString = getDomainString(_domain, _subdomain);
Msg::Info("Reducing the Cell Complex..."); Msg::Info("Reducing the Cell Complex...");
...@@ -206,7 +210,7 @@ void Homology::findGenerators() ...@@ -206,7 +210,7 @@ void Homology::findGenerators()
if(_fileName != "") writeGeneratorsMSH(); if(_fileName != "") writeGeneratorsMSH();
delete cellComplex; if(ownComplex) delete cellComplex;
delete chains; delete chains;
Msg::Info("Ranks of homology spaces for primal cell complex:"); Msg::Info("Ranks of homology spaces for primal cell complex:");
...@@ -221,10 +225,14 @@ void Homology::findGenerators() ...@@ -221,10 +225,14 @@ void Homology::findGenerators()
HRank[0], HRank[1], HRank[2], HRank[3]); HRank[0], HRank[1], HRank[2], HRank[3]);
} }
void Homology::findDualGenerators() void Homology::findDualGenerators(CellComplex* cellComplex)
{ {
bool ownComplex = false;
if(cellComplex==NULL){
CellComplex* cellComplex = createCellComplex(_domainEntities, CellComplex* cellComplex = createCellComplex(_domainEntities,
_subdomainEntities); _subdomainEntities);
ownComplex = true;
}
Msg::Info("Reducing Cell Complex..."); Msg::Info("Reducing Cell Complex...");
Msg::StatusBar(1, false, "Reducing..."); Msg::StatusBar(1, false, "Reducing...");
...@@ -321,7 +329,7 @@ void Homology::findDualGenerators() ...@@ -321,7 +329,7 @@ void Homology::findDualGenerators()
if(_fileName != "") writeGeneratorsMSH(); if(_fileName != "") writeGeneratorsMSH();
delete cellComplex; if(ownComplex) delete cellComplex;
delete chains; delete chains;
Msg::Info("Ranks of homology spaces for the dual cell complex:"); Msg::Info("Ranks of homology spaces for the dual cell complex:");
......
...@@ -42,8 +42,7 @@ class Homology ...@@ -42,8 +42,7 @@ class Homology
std::vector<GEntity*> _domainEntities; std::vector<GEntity*> _domainEntities;
std::vector<GEntity*> _subdomainEntities; std::vector<GEntity*> _subdomainEntities;
// generator chains, and their physical group number // physical group numbers of generator chains in model
//std::map<int, Chain*> _generators;
std::vector<int> _generators; std::vector<int> _generators;
std::string _fileName; std::string _fileName;
...@@ -54,17 +53,20 @@ class Homology ...@@ -54,17 +53,20 @@ class Homology
std::vector<int> physicalSubdomain); std::vector<int> physicalSubdomain);
~Homology(); ~Homology();
CellComplex* createCellComplex(std::vector<GEntity*>& domainEntities, CellComplex* createCellComplex(std::vector<GEntity*>& domainEntities,
std::vector<GEntity*>& subdomainEntities); std::vector<GEntity*>& subdomainEntities);
CellComplex* createCellComplex() {
return createCellComplex(_domainEntities, _subdomainEntities); }
void setFileName(std::string fileName) { _fileName = fileName; } void setFileName(std::string fileName) { _fileName = fileName; }
// Find the generators/duals of homology spaces, // Find the generators/duals of homology spaces,
// or just compute the ranks of homology spaces // or just compute the ranks of homology spaces
void findGenerators(); void findGenerators(CellComplex* cellComplex=NULL);
void findDualGenerators(); void findDualGenerators(CellComplex* cellComplex=NULL);
void computeRanks() {}
void computeRanks() {}
void findHomSequence(); void findHomSequence();
......
...@@ -21,7 +21,7 @@ StringXNumber HomologyComputationOptions_Number[] = { ...@@ -21,7 +21,7 @@ StringXNumber HomologyComputationOptions_Number[] = {
{GMSH_FULLRC, "PhysicalGroupForSubdomain2", NULL, 0.}, {GMSH_FULLRC, "PhysicalGroupForSubdomain2", NULL, 0.},
{GMSH_FULLRC, "ComputeGenerators", NULL, 1.}, {GMSH_FULLRC, "ComputeGenerators", NULL, 1.},
{GMSH_FULLRC, "ComputeCuts", NULL, 0.}, {GMSH_FULLRC, "ComputeCuts", NULL, 0.},
{GMSH_FULLRC, "ComputeRanks", NULL, 0.}, //{GMSH_FULLRC, "ComputeRanks", NULL, 0.},
}; };
StringXString HomologyComputationOptions_String[] = { StringXString HomologyComputationOptions_String[] = {
...@@ -89,28 +89,26 @@ PView *GMSH_HomologyComputationPlugin::execute(PView *v) ...@@ -89,28 +89,26 @@ PView *GMSH_HomologyComputationPlugin::execute(PView *v)
int gens = (int)HomologyComputationOptions_Number[4].def; int gens = (int)HomologyComputationOptions_Number[4].def;
int cuts = (int)HomologyComputationOptions_Number[5].def; int cuts = (int)HomologyComputationOptions_Number[5].def;
int rank = (int)HomologyComputationOptions_Number[6].def; //int rank = (int)HomologyComputationOptions_Number[6].def;
GModel *m = GModel::current(); GModel *m = GModel::current();
if(gens != 0){
Homology* homology = new Homology(m, domain, subdomain); Homology* homology = new Homology(m, domain, subdomain);
homology->setFileName(fileName); homology->setFileName(fileName);
homology->findGenerators(); CellComplex* cc = homology->createCellComplex();
delete homology; if(gens != 0){
homology->findGenerators(cc);
} }
if(cuts != 0){ if(cuts != 0){
Homology* homology = new Homology(m, domain, subdomain); cc->restoreComplex();
homology->setFileName(fileName); homology->findDualGenerators(cc);
homology->findDualGenerators();
delete homology;
} }
if(rank != 0){ /*if(rank != 0){
Homology* homology = new Homology(m, domain, subdomain);
homology->setFileName(fileName);
homology->computeRanks(); homology->computeRanks();
}*/
delete cc;
delete homology; delete homology;
}
return 0; return 0;
} }
......
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
#include <gmsh/GModel.h> #include <gmsh/GModel.h>
#include <gmsh/MElement.h> #include <gmsh/MElement.h>
#include <gmsh/CellComplex.h> #include <gmsh/CellComplex.h>
#include <gmsh/ChainComplex.h> //#include <gmsh/ChainComplex.h>
#include <gmsh/Homology.h> #include <gmsh/Homology.h>
int main(int argc, char **argv) int main(int argc, char **argv)
...@@ -25,21 +25,31 @@ int main(int argc, char **argv) ...@@ -25,21 +25,31 @@ int main(int argc, char **argv)
// OR // OR
// m->readMSH("model.msh"); // m->readMSH("model.msh");
// List of physical regions as domain for homology computation (relative to subdomain). // List of physical regions as domain for homology computation
// (relative to subdomain).
std::vector<int> domain; std::vector<int> domain;
std::vector<int> subdomain; std::vector<int> subdomain;
Homology* homology1 = new Homology(m, domain, subdomain); // initialize
std::string fileName = "homology.msh"; Homology* homology = new Homology(m, domain, subdomain);
homology->findGenerators();
homology->setFileName(fileName);
delete homology1;
Homology* homology2 = new Homology(m, domain, subdomain); // save all resulting chains to a file as physical groups
homology->findDualGenerators(); homology->setFileName("homology.msh");
homology->setFileName(fileName);
delete homology2;
// construct cell complex of the meshed domain
CellComplex cc = homology->createCellComplex();
// find homology generator chains
homology->findGenerators(cc);
// restore cell complex for a new run
cc->restoreComplex();
// find thick cuts
homology->findDualGenerators(cc);
delete cc;
delete homology;
delete m; delete m;
GmshFinalize(); GmshFinalize();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment