13 #include "GmshConfig.h"
18 #if defined(HAVE_KBIPACK)
23 {
GMSH_FULLRC,
"HomologyPhysicalGroupsBegin",
nullptr, -1.},
24 {
GMSH_FULLRC,
"CohomologyPhysicalGroupsBegin",
nullptr, -1.},
25 {
GMSH_FULLRC,
"CreatePostProcessingViews",
nullptr, 1.},
33 {
GMSH_FULLRC,
"SubdomainPhysicalGroups",
nullptr,
""},
34 {
GMSH_FULLRC,
"ReductionImmunePhysicalGroups",
nullptr,
""},
35 {
GMSH_FULLRC,
"DimensionOfChainsToSave",
nullptr,
"0, 1, 2, 3"},
36 {
GMSH_FULLRC,
"Filename",
nullptr,
"homology.msh"}};
39 GMSH_Plugin *GMSH_RegisterHomologyComputationPlugin()
41 return new GMSH_HomologyComputationPlugin();
45 std::string GMSH_HomologyComputationPlugin::getHelp()
const
47 return "Plugin(HomologyComputation) computes representative chains "
48 "of basis elements of (relative) homology and cohomology spaces.\n\n"
50 "Define physical groups in order to specify the computation "
51 "domain and the relative subdomain. Otherwise the whole mesh "
52 "is the domain and the relative subdomain is empty. \n\n"
54 "Plugin(HomologyComputation) creates new views, one for each "
55 "basis element. The resulting basis chains of desired dimension "
56 "together with the mesh are saved to the given file.";
59 int GMSH_HomologyComputationPlugin::getNbOptions()
const
61 return sizeof(HomologyComputationOptions_Number) /
sizeof(
StringXNumber);
64 StringXNumber *GMSH_HomologyComputationPlugin::getOption(
int iopt)
66 return &HomologyComputationOptions_Number[iopt];
69 int GMSH_HomologyComputationPlugin::getNbOptionsStr()
const
71 return sizeof(HomologyComputationOptions_String) /
sizeof(
StringXString);
74 StringXString *GMSH_HomologyComputationPlugin::getOptionStr(
int iopt)
76 return &HomologyComputationOptions_String[iopt];
79 bool GMSH_HomologyComputationPlugin::parseStringOpt(
int stringOpt,
80 std::vector<int> &intList)
82 std::string list = HomologyComputationOptions_String[stringOpt].
def;
87 std::istringstream ss(list);
92 Msg::Error(
"Unexpected character \'%c\' while parsing \'%s\'", a,
93 HomologyComputationOptions_String[stringOpt].str);
101 PView *GMSH_HomologyComputationPlugin::execute(
PView *v)
103 std::string fileName = HomologyComputationOptions_String[4].
def;
104 int hom = (int)HomologyComputationOptions_Number[0].def;
105 int coh = (int)HomologyComputationOptions_Number[1].def;
106 int hompg = (int)HomologyComputationOptions_Number[2].def;
107 int cohpg = (int)HomologyComputationOptions_Number[3].def;
108 bool pviews = (bool)HomologyComputationOptions_Number[4].def;
109 bool omit = (bool)HomologyComputationOptions_Number[5].def;
110 int combine = (int)HomologyComputationOptions_Number[6].def;
111 bool smoothen = (bool)HomologyComputationOptions_Number[7].def;
112 int heuristic = (int)HomologyComputationOptions_Number[8].def;
114 std::vector<int> domain;
115 std::vector<int> subdomain;
116 std::vector<int> imdomain;
117 std::vector<int> dimsave;
118 if(!parseStringOpt(0, domain))
return nullptr;
119 if(!parseStringOpt(1, subdomain))
return nullptr;
120 if(!parseStringOpt(2, imdomain))
return nullptr;
121 if(!parseStringOpt(3, dimsave))
return nullptr;
125 Homology *homology =
new Homology(m, domain, subdomain, imdomain,
true,
126 combine, omit, smoothen, heuristic);
127 homology->setFileName(fileName);
129 if(hom != 0) homology->findHomologyBasis(dimsave);
130 if(coh != 0) homology->findCohomologyBasis(dimsave);
132 for(std::size_t i = 0; i < dimsave.size(); i++) {
133 int dim = dimsave.at(i);
134 if(dim > -1 && dim < 4 && hom != 0) {
135 homology->addChainsToModel(dim, pviews, hompg);
136 if(hompg != -1) hompg += homology->betti(dim);
139 for(std::size_t i = 0; i < dimsave.size(); i++) {
140 int dim = dimsave.at(i);
141 if(dim > -1 && dim < 4 && coh != 0) {
142 homology->addCochainsToModel(dim, pviews, cohpg);
143 if(cohpg != -1) cohpg += homology->betti(dim);