30 #ifndef _CHAINCON_ATMODEL4R_H_ 31 #define _CHAINCON_ATMODEL4R_H_ 40 #include "chomp/system/config.h" 41 #include "chomp/system/textfile.h" 42 #include "chomp/system/timeused.h" 43 #include "chomp/struct/hashsets.h" 44 #include "chomp/struct/multitab.h" 45 #include "chomp/struct/integer.h" 46 #include "chomp/homology/chains.h" 67 template <
class CellT,
class CoefT,
class CellArray1,
class CellArray2,
73 const CellRestrT &restr)
75 using chomp::homology::sout;
77 using chomp::homology::sbug;
78 using chomp::homology::timeused;
79 using chomp::homology::multitable;
80 using chomp::homology::hashedset;
94 sbug <<
"[AT Model Algorithm 4r.]\n";
95 sout <<
"Splitting K into sets of cells of each dimension...\n";
100 multitable<hashedset<CellT> > cells;
106 const int_t KSize = K. size ();
107 for (int_t k = 0; k < KSize; ++ k)
109 const CellT &cell (K [k]);
110 int dim (cell. dim ());
112 cells [dim]. add (cell);
118 sout <<
"K split in " << splitTime <<
".\n";
121 sout <<
"Creating the matrices of the boundary operator on K...\n";
129 for (
int q = 0; q < maxDim; ++ q)
131 int_t nRows = (q > 0) ? cells [q - 1]. size () :
132 (CellT::EmptyType::exists () ? 1 : 0);
133 int_t nCols = cells [q]. size ();
136 matrix. setSize (q, nRows, nCols);
140 for (
int q = 0; q < maxDim; ++ q)
142 if ((q == 0) && !CellT::EmptyType::exists ())
144 int_t size (cells [q]. size ());
145 for (int_t cNum = 0; cNum < size; ++ cNum)
148 const CellT &c = cells [q] [cNum];
151 int_t bLen = c. boundaryLength ();
152 for (int_t j = 0; j < bLen; ++ j)
158 int_t bNum = (q > 0) ?
159 cells [q - 1]. getnumber (bCell) : 0;
166 CoefT bCoef (c. boundaryCoef (j));
172 matrix. add (q, bNum, cNum, bCoef);
178 sout <<
"The boundary matrices created in " << constrTime <<
".\n";
181 sout <<
"Computing the SNF of the boundary operator...\n";
184 matrix. computeSNF (maxDim);
187 sout <<
"The SNF computed in " << snfTime <<
".\n";
194 sout <<
"Composing an algebraic topological model from the SNF...\n";
195 timeused composingTime;
200 multitable<AlgMapType> psi;
203 for (
int q = 0; q < maxDim; ++ q)
209 int_t nCols = cells [q]. size ();
210 for (int_t cell = 0; cell < nCols; ++ cell)
213 int_t bcell = matrix. getColCell (q, cell);
218 const CoefT e (matrix. getColCoef (q, cell));
219 const int delta (e. delta ());
222 const AlgCellType dom (bcell);
223 const AlgCellType img (cell);
225 psi [q - 1]. add (dom, img, e);
229 throw "Non-invertible coefficient " 230 "encountered in the SNF.";
236 if ((q < maxDim - 1) &&
237 (matrix. getRowCell (q + 1, cell) >= 0))
243 const CellT &repr = cells [q] [genNumber];
248 const AlgChainType genChain
249 (matrix. getOldChain (q, cell));
252 int_t genSize = genChain. size ();
253 for (int_t j = 0; j < genSize; ++ j)
255 int_t n = genChain. getCell (j). getId ();
256 CoefT e = genChain. getCoef (j);
257 const CellT &genCell = cells [q] [n];
258 incl. add (repr, genCell, e);
264 const AlgChainType piRow
265 (matrix. getNewChainRow (q, cell));
266 int_t piRowSize = piRow. size ();
267 for (int_t j = 0; j < piRowSize; ++ j)
269 int_t n = piRow. getCell (j). getId ();
270 CoefT e = piRow. getCoef (j);
271 const CellT &cell = cells [q] [n];
272 pi. add (cell, repr, e);
279 sout <<
"Transferring the computed maps to the original basis...\n";
280 for (
int q = 1; q < maxDim; ++ q)
283 int_t nCells (cells [q - 1]. size ());
284 for (int_t cell = 0; cell < nCells; ++ cell)
287 AlgChainType ch (matrix. getNewChain (q - 1, cell));
290 AlgChainType psich (psi [q - 1] (ch));
293 AlgChainType algImage;
294 int_t size (psich. size ());
295 for (int_t i = 0; i < size; ++ i)
298 int_t n (psich. getCell (i). getId ());
299 const CoefT &e (psich. getCoef (i));
300 AlgChainType a (matrix. getOldChain (q, n));
307 int_t algSize (algImage. size ());
308 for (int_t i = 0; i < algSize; ++ i)
310 const CoefT &coef (algImage. getCoef (i));
311 int_t n (algImage. getCell (i). getId ());
312 const CellT &cell (cells [q] [n]);
313 image. add (cell, coef);
317 phi. getImage (cells [q - 1] [cell]). swap (image);
322 sout <<
"AT model composed from the SNF in " << composingTime <<
326 sout <<
"AT model computed in " << compTime <<
".\n";
332 #endif // _CHAINCON_ATMODEL4R_H_ A linear map for coefficients in an arbitrary commutative ring.
This file includes a specific interface to an SNF computation algorithm.
A chain with coefficients in an arbitrary ring.
void algTopModel4(const CellArray1 &K, CellArray2 &H, tLinMap< CellT, CellT, CoefT > &pi, tLinMap< CellT, CellT, CoefT > &incl, tLinMap< CellT, CellT, CoefT > &phi, const CellRestrT &restr)
Computes an algebraic topological model for the given filtered finite cell complex "K"...
An abstract algebraic cell.
A chain with coefficients in an arbitrary commutative ring.
The decision on whether the empty cell should be used as a valid cell of dimension -1...
void verifyChangeOfBasisSNF(const MatrixT &matrix, int maxDim)
Verifies if the change of basis matrices match each other.
An abstract algebraic cell, characterized by a unique identifier, dimension, and a formula for its bo...
An interface for the computation of the Smith Normal Form of a series of a few rectangular matrices w...