diff --git a/Geo/CellComplex.cpp b/Geo/CellComplex.cpp index dcbad2b1d6657380c71bfdae3b71848cfdf01071..6827a1ae31c7148ab445bfbbf617edcdc518d0e1 100644 --- a/Geo/CellComplex.cpp +++ b/Geo/CellComplex.cpp @@ -7,6 +7,7 @@ #include "CellComplex.h" + CellComplex::CellComplex( std::vector<GEntity*> domain, std::vector<GEntity*> subdomain ){ _domain = domain; diff --git a/Geo/CellComplex.h b/Geo/CellComplex.h index 8961d5cbb12c31382953a7362532c1f6fdee195a..a1f494805412d4c2b4286fee35f8bc61c52149bd 100644 --- a/Geo/CellComplex.h +++ b/Geo/CellComplex.h @@ -26,7 +26,6 @@ #include "GVertex.h" - // Abstract class representing an elemtary cell of a cell complex. class Cell { @@ -498,7 +497,7 @@ class CombinedCell : public Cell{ // A class representing a cell complex made out of a finite element mesh. class CellComplex { - protected: + private: // the domain in the model which this cell complex covers std::vector<GEntity*> _domain; @@ -527,14 +526,14 @@ class CellComplex protected: // enqueue cells in queue if they are not there already - virtual void enqueueCells(std::list<Cell*>& cells, + void enqueueCells(std::list<Cell*>& cells, std::queue<Cell*>& Q, std::set<Cell*, Less_Cell>& Qset); // remove cell from the queue set - virtual void removeCellQset(Cell*& cell, std::set<Cell*, Less_Cell>& Qset); + void removeCellQset(Cell*& cell, std::set<Cell*, Less_Cell>& Qset); // insert cells into this cell complex //virtual void insert_cells(bool subdomain, bool boundary); - virtual void insert_cells(bool subdomain, bool boundary); + void insert_cells(bool subdomain, bool boundary); public: CellComplex( std::vector<GEntity*> domain, std::vector<GEntity*> subdomain, std::set<Cell*, Less_Cell> cells ) { @@ -571,68 +570,68 @@ class CellComplex CellComplex( std::vector<GEntity*> domain, std::vector<GEntity*> subdomain ); CellComplex(){} - virtual ~CellComplex(){} + ~CellComplex(){} // get the number of certain dimensional cells - virtual int getSize(int dim){ return _cells[dim].size(); } + int getSize(int dim){ return _cells[dim].size(); } - virtual int getDim() {return _dim; } + int getDim() {return _dim; } - virtual std::set<Cell*, Less_Cell> getCells(int dim){ return _cells[dim]; } + std::set<Cell*, Less_Cell> getCells(int dim){ return _cells[dim]; } // iterators to the first and last cells of certain dimension - virtual citer firstCell(int dim) {return _cells[dim].begin(); } - virtual citer lastCell(int dim) {return _cells[dim].end(); } + citer firstCell(int dim) {return _cells[dim].begin(); } + citer lastCell(int dim) {return _cells[dim].end(); } // kappa for two cells of this cell complex // implementation will vary depending on cell type - virtual inline int kappa(Cell* sigma, Cell* tau) const { return sigma->kappa(tau); } + inline int kappa(Cell* sigma, Cell* tau) const { return sigma->kappa(tau); } // remove a cell from this cell complex - virtual void removeCell(Cell* cell); - virtual void replaceCells(Cell* c1, Cell* c2, Cell* newCell, bool orMatch, bool co=false); + void removeCell(Cell* cell); + void replaceCells(Cell* c1, Cell* c2, Cell* newCell, bool orMatch, bool co=false); - virtual void insertCell(Cell* cell); + void insertCell(Cell* cell); // check whether two cells both belong to subdomain or if neither one does - virtual bool inSameDomain(Cell* c1, Cell* c2) const { return + bool inSameDomain(Cell* c1, Cell* c2) const { return ( (!c1->inSubdomain() && !c2->inSubdomain()) || (c1->inSubdomain() && c2->inSubdomain()) ); } // reduction of this cell complex // removes reduction pairs of cell of dimension dim and dim-1 - virtual int reduction(int dim); + int reduction(int dim); // useful functions for (co)reduction of cell complex - virtual void reduceComplex(bool omitHighdim = false); - virtual void coreduceComplex(bool omitlowDim = false); + void reduceComplex(bool omitHighdim = false); + void coreduceComplex(bool omitlowDim = false); // queued coreduction presented in Mrozek's paper - virtual int coreduction(Cell* generator); - + int coreduction(Cell* generator); + // add every volume, face and edge its missing boundary cells - //virtual void repairComplex(int i=3); + // void repairComplex(int i=3); // change non-subdomain cells to be in subdomain, subdomain cells to not to be in subdomain - virtual void swapSubdomain(); - virtual void removeSubdomain(); + void swapSubdomain(); + void removeSubdomain(); // print the vertices of cells of certain dimension - virtual void printComplex(int dim); + void printComplex(int dim); // write this cell complex in 2.0 MSH ASCII format - virtual int writeComplexMSH(const std::string &name); + int writeComplexMSH(const std::string &name); - virtual int combine(int dim); - virtual int cocombine(int dim); + int combine(int dim); + int cocombine(int dim); - virtual void computeBettiNumbers(); - virtual int getBettiNumber(int i) { if(i > -1 && i < 4) return _betti[i]; else return 0; } + void computeBettiNumbers(); + int getBettiNumber(int i) { if(i > -1 && i < 4) return _betti[i]; else return 0; } - virtual void makeDualComplex(){ + void makeDualComplex(){ std::set<Cell*, Less_Cell> temp = _cells[0]; _cells[0] = _cells[3]; _cells[3] = temp; diff --git a/Plugin/HomologyComputation.cpp b/Plugin/HomologyComputation.cpp new file mode 100644 index 0000000000000000000000000000000000000000..3f6b9ceaccc8403e0077be5571c4b47d7471215c --- /dev/null +++ b/Plugin/HomologyComputation.cpp @@ -0,0 +1,99 @@ +// Gmsh - Copyright (C) 1997-2009 C. Geuzaine, J.-F. Remacle +// +// See the LICENSE.txt file for license information. Please report all +// bugs and problems to <gmsh@geuz.org>. +// +// Contributed by Matti Pellikka + +#include <stdlib.h> +#include "GmshConfig.h" +#include "GModel.h" +#include "CellComplex.h" +#include "HomologyComputation.h" + + +StringXNumber HomologyComputationOptions_Number[] = { + {GMSH_FULLRC, "test number", NULL, 1.}, +}; + +StringXString HomologyComputationOptions_String[] = { + {GMSH_FULLRC, "test string", NULL, "test string"}, +}; + +extern "C" +{ + GMSH_Plugin *GMSH_RegisterHomologyComputationPlugin() + { + return new GMSH_HomologyComputationPlugin(); + } +} + +void GMSH_HomologyComputationPlugin::getName(char *name) const +{ + strcpy(name, "Homology Computation"); +} + +void GMSH_HomologyComputationPlugin::getInfos(char *author, char *copyright, + char *help_text) const +{ + strcpy(author, "Matti Pellikka"); + strcpy(copyright, "C. Geuzaine, J.-F. Remacle"); + strcpy(help_text, + "Plugin(HomologyComputation) is here!\n" + "\n" + "Plugin(HomologyComputation) creates a new view.\n"); +} + +int GMSH_HomologyComputationPlugin::getNbOptions() const +{ + return sizeof(HomologyComputationOptions_Number) / sizeof(StringXNumber); +} + +StringXNumber *GMSH_HomologyComputationPlugin::getOption(int iopt) +{ + return &HomologyComputationOptions_Number[iopt]; +} + +int GMSH_HomologyComputationPlugin::getNbOptionsStr() const +{ + return sizeof(HomologyComputationOptions_String) / sizeof(StringXString); +} + +StringXString *GMSH_HomologyComputationPlugin::getOptionStr(int iopt) +{ + return &HomologyComputationOptions_String[iopt]; +} + +void GMSH_HomologyComputationPlugin::catchErrorMessage(char *errorMessage) const +{ + strcpy(errorMessage, "Homology Computation failed..."); +} + + +PView *GMSH_HomologyComputationPlugin::execute(PView *v) +{ + std::string testString = HomologyComputationOptions_String[0].def; + int testInt = (int)HomologyComputationOptions_Number[0].def; + + GModel *m = GModel::current(); + std::map<int, std::vector<GEntity*> > groups[4]; + m->getPhysicalGroups(groups); + + std::map<int, std::vector<double> > data; + + std::vector<GEntity*> domain; + std::vector<GEntity*> subdomain; + + // Here's the problem, linker cannot find the method for the constructor of + // CellComplex class, or any other methods coded in Geo/CellComplex.cpp + + //CellComplex* testComplex = new CellComplex(domain, subdomain); + + // insert homology fun here + + PView *pv = new PView("homology", "ElementData", m, data, 0.); + + Msg::Error("test."); + + return 0; +} diff --git a/Plugin/HomologyComputation.h b/Plugin/HomologyComputation.h new file mode 100644 index 0000000000000000000000000000000000000000..5af64b6acfb3c92105f9f573632a93824e02bd63 --- /dev/null +++ b/Plugin/HomologyComputation.h @@ -0,0 +1,33 @@ +// Gmsh - Copyright (C) 1997-2009 C. Geuzaine, J.-F. Remacle +// +// See the LICENSE.txt file for license information. Please report all +// bugs and problems to <gmsh@geuz.org>. +// +// Contributed by Matti Pellikka + +#ifndef _HOMOLOGY_COMPUTATION_H_ +#define _HOMOLOGY_COMPUTATION_H_ + +#include <string> +#include "Plugin.h" + +extern "C" +{ + GMSH_Plugin *GMSH_RegisterHomologyComputationPlugin(); +} + +class GMSH_HomologyComputationPlugin : public GMSH_PostPlugin +{ +public: + GMSH_HomologyComputationPlugin(){} + void getName(char *name) const; + void getInfos(char *author, char *copyright, char *helpText) const; + void catchErrorMessage(char *errorMessage) const; + int getNbOptions() const; + StringXNumber *getOption(int iopt); + int getNbOptionsStr() const; + StringXString *getOptionStr(int iopt); + PView *execute(PView *); +}; + +#endif diff --git a/Plugin/Makefile b/Plugin/Makefile index 669efd0dbf5b71b2afe02194b1e6847f9cd42d91..a8b9869ea2305c532f0480f4f4dcaf91283809c2 100644 --- a/Plugin/Makefile +++ b/Plugin/Makefile @@ -33,7 +33,8 @@ SRC = Plugin.cpp PluginManager.cpp\ Annotate.cpp Remove.cpp\ Probe.cpp\ HarmonicToTime.cpp ModulusPhase.cpp\ - FiniteElement.cpp + FiniteElement.cpp\ + HomologyComputation.cpp OBJ = ${SRC:.cpp=${OBJEXT}} @@ -339,3 +340,6 @@ FiniteElement${OBJEXT}: FiniteElement.cpp ../Common/GmshConfig.h ../Geo/GModel.h ../Numeric/gmshTermOfFormulation.h ../Numeric/gmshFunction.h \ ../Numeric/GmshMatrix.h ../Numeric/gmshLinearSystemGmm.h \ ../Numeric/gmshLinearSystem.h +HomologyComputation${OBJEXT}: HomologyComputation.cpp Plugin.h \ + ../Geo/GModel.h ../Geo/GEntity.h ../Geo/CellComplex.h \ + ../Post/PView.h HomologyComputation.h diff --git a/Plugin/PluginManager.cpp b/Plugin/PluginManager.cpp index f683d6c48b30d1492badf5d3d65601d1dee6481a..64b0455ffe3839cfdb01fe432ae02a856344e395 100644 --- a/Plugin/PluginManager.cpp +++ b/Plugin/PluginManager.cpp @@ -43,6 +43,7 @@ #include "GSHHS.h" #include "FiniteElement.h" #include "Context.h" +#include "HomologyComputation.h" #if !defined(HAVE_NO_DLL) #include <dlfcn.h> @@ -228,6 +229,8 @@ void PluginManager::registerDefaultPlugins() #endif allPlugins.insert(std::pair<const char*, GMSH_Plugin*> ("FiniteElement", GMSH_RegisterFiniteElementPlugin())); + allPlugins.insert(std::pair<const char*, GMSH_Plugin*> + ("HomologyComputation", GMSH_RegisterHomologyComputationPlugin())); } #if defined(HAVE_FLTK)