The ChainCon Software (Release 0.03)
cringmain.h
Go to the documentation of this file.
1 /////////////////////////////////////////////////////////////////////////////
2 ///
3 /// \file
4 ///
5 /// The main function of a program for computing the cubical cohomology ring
6 /// of a cellular complex of a given type.
7 ///
8 /////////////////////////////////////////////////////////////////////////////
9 
10 // Copyright (C) 2009-2016 by Pawel Pilarczyk.
11 //
12 // This file is part of my research software package. This is free software:
13 // you can redistribute it and/or modify it under the terms of the GNU
14 // General Public License as published by the Free Software Foundation,
15 // either version 3 of the License, or (at your option) any later version.
16 //
17 // This software is distributed in the hope that it will be useful,
18 // but WITHOUT ANY WARRANTY; without even the implied warranty of
19 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 // GNU General Public License for more details.
21 //
22 // You should have received a copy of the GNU General Public License
23 // along with this software; see the file "license.txt". If not,
24 // please, see <http://www.gnu.org/licenses/>.
25 
26 // Started on March 24, 2009. Last revision: June 10, 2015.
27 
28 
29 #ifndef _CRINGMAIN_H_
30 #define _CRINGMAIN_H_
31 
32 
33 // include some standard C++ header files
34 #include <istream>
35 #include <ostream>
36 #include <vector>
37 
38 // include selected header files from the CHomP library
39 #include "chomp/system/config.h"
40 #include "chomp/system/textfile.h"
41 #include "chomp/system/timeused.h"
42 #include "chomp/system/arg.h"
43 #include "chomp/struct/hashsets.h"
44 
45 // include relevant local header files
46 #include "chaincon/linmap.h"
47 #include "chaincon/ringzp.h"
48 #include "chaincon/cellnames.h"
49 #ifdef SPACE_WRAPPING
50 #include "chaincon/wrapping.h"
51 #endif
52 #include "ammodcomp.h"
53 #include "cringcomp.h"
54 
55 
56 // --------------------------------------------------
57 // ---------------------- main ----------------------
58 // --------------------------------------------------
59 
60 /// The main procedure of a program for the computation of a cohomology ring.
61 /// Returns: 0 = Ok, -1 = Error, 1 = Help displayed, 2 = Wrong arguments.
62 template <class CellT>
63 inline int cohomRingMain (int argc, char *argv [],
64  const char *title, const char *helpinfo)
65 {
66  using namespace chomp::homology;
67 
68  // turn on a message that will appear if the program does not finish
69  program_time = "Aborted after";
70 
71  // prepare user-configurable data
72  char *Xname = 0;
73  char *Aname = 0;
74  int p = 0;
75  bool reduced = false;
76  bool addBoundariesX = true;
77  bool addBoundariesA = true;
78  bool addNoBoundaries = false;
79  bool displayPi = false;
80  bool displayIncl = false;
81  bool displayPhi = false;
82  bool displayD = false;
83  bool verify = false;
84 #ifdef SPACE_WRAPPING
85  const int maxWrapping = 100;
86  char *wrapping [maxWrapping];
87  int nWrapping = 0;
88 #endif
89 
90  // analyze the command line
91  arguments a;
92  arg (a, NULL, Xname);
93  arg (a, NULL, Aname);
94  arg (a, "p", p);
95 #ifdef SPACE_WRAPPING
96  arg (a, "w", wrapping, nWrapping, maxWrapping);
97 #endif
98  argswitch (a, "r", reduced, true);
99  argswitch (a, "bx", addBoundariesX, false);
100  argswitch (a, "ba", addBoundariesA, false);
101  argswitch (a, "b", addNoBoundaries, true);
102  argswitch (a, "dpi", displayPi, true);
103  argswitch (a, "dincl", displayIncl, true);
104  argswitch (a, "dphi", displayPhi, true);
105  argswitch (a, "dd", displayD, true);
106  argswitch (a, "-verify", verify, true);
107  arghelp (a);
108 
109  argstreamprepare (a);
110  int argresult = a. analyze (argc, argv);
111  argstreamset ();
112 
113  // show the program's title
114  if (argresult >= 0)
115  sout << title << '\n';
116 
117  // if something was incorrect, show an additional message and exit
118  if (argresult < 0)
119  {
120  sout << "Call with '--help' for help.\n";
121  return 2;
122  }
123 
124  // if help requested or no filename present, show help information
125  if ((argresult > 0) || !Xname || (p < 0))
126  {
127  sout << helpinfo << '\n';
128  return 1;
129  }
130 
131  // try running the main function and catch an error message if thrown
132  try
133  {
134  // set the existence of the empty cell if desired
135  if (reduced)
136  CellT::EmptyType::setExistence (true);
137 
138 #ifdef SPACE_WRAPPING
139  // set wrapping as desired
140  for (int i = 0; i < nWrapping; ++ i)
141  {
142  setWrapping<typename CellT::WrapType>
143  (std::string (wrapping [i]));
144  }
145 #endif
146 
147  // prepare the ring of coefficients
148  typedef tZp<short> CoefT;
149  CoefT::setp (p);
150  p = CoefT::getp ();
151 
152  // prepare the data for storing the result of computations
153  chomp::homology::hashedset<CellT> H, A, B;
154  std::vector<CoefT> Q;
155 
156  // compute the homology groups and generators
157  sout << "Carrying out computations in the ring " <<
158  CoefT::ringsymbol () << ".\n";
159  tLinMap<CellT,CellT,CoefT> pi, incl, phi;
160  tCellNames<CellT> dummyCellNames;
161  tCellNames<CellT> cellNames;
162  // cellNames. setPrefix ("g");
163 
164  // read the filtered cell complexes
167  readFilteredComplexes (Xname, Aname, K, L,
168  addBoundariesX && !addNoBoundaries,
169  addBoundariesA && !addNoBoundaries);
170 
171  sout << "=== Computing the minimal model ===\n";
172  computeAlgMinModel (K, !L. empty (), H, A, B, Q,
173  pi, incl, phi, dummyCellNames, cellNames,
174  displayPi, displayIncl, displayPhi, displayD,
175  verify);
176 
177  sout << "=== Computing the cohomology ring ===\n";
178  computeCohomRing (H, A, B, Q, pi, incl, cellNames, verify);
179 
180  program_time = "Total time used:";
181  program_time = 1;
182  return 0;
183  }
184  catch (const char *msg)
185  {
186  sout << "ERROR: " << msg << '\n';
187  return -1;
188  }
189  catch (const std::exception &e)
190  {
191  sout << "ERROR: " << e. what () << '\n';
192  return -1;
193  }
194  catch (...)
195  {
196  sout << "ABORT: An unknown error occurred.\n";
197  return -1;
198  }
199 } /* cohomRingMain */
200 
201 
202 #endif // _CRINGMAIN_H_
203 
void computeCohomRing(const CellArray1 &H, const CellArray2 &A, const CellArray3 &B, const CoefArray &Q, const tLinMap< CellT, CellT, CoefT > &pi, const tLinMap< CellT, CellT, CoefT > &incl, CellNames &cellNames, bool verify)
Computes the cohomology ring, given a minimal model of a cell complex, and shows the result...
Definition: cringcomp.h:63
Elements of the ring Z_p.
A generic procedure for the computation of the cohomology ring structure for an algebraic minimal mod...
A generic procedure for the computation of an algebraic minimal model of a filtered cell complex stor...
A linear map for coefficients in an arbitrary commutative ring.
const char * helpinfo
Brief help information on the program&#39;s usage.
Definition: ammodcub.cpp:53
A class whose instances can be used to generate names of cells with subsequent numbers, in each dimension separately.
Definition: cellnames.h:61
Tools for coordinate wrapping, a.k.a.
A linear map.
Definition: linmap.h:55
A filtered complex.
Definition: filtcomplex.h:53
void readFilteredComplexes(const char *Xname, const char *Aname, tFilteredComplex< CellT > &K, tFilteredComplex< CellT > &L, bool addBoundariesX, bool addBoundariesA)
Reads a filtered cell complex or a pair of filtered cell complexes from text files.
Definition: readfcompl.h:56
A class for naming cells for nice text data output.
const char * title
The title of the program and licensing information.
Definition: ammodcub.cpp:47
int cohomRingMain(int argc, char *argv [], const char *title, const char *helpinfo)
The main procedure of a program for the computation of a cohomology ring.
Definition: cringmain.h:63
void computeAlgMinModel(const tFilteredComplex< CellT > &K, bool relativeComplex, CellArray1 &H, CellArray2 &A, CellArray3 &B, CoefArray &Q, tLinMap< CellT, CellT, CoefT > &pi, tLinMap< CellT, CellT, CoefT > &incl, tLinMap< CellT, CellT, CoefT > &phi, CellNames &homCellNames, CellNames &cohomCellNames, bool displayPi, bool displayIncl, bool displayPhi, bool displayD, bool verify)
Computes the homology of a cellular complex.
Definition: ammodcomp.h:68
An element of the ring Z_p, where p is globally set.
Definition: ringzp.h:179