The ChainCon Software (Release 0.03)
awdiagcubs.h
Go to the documentation of this file.
1 /////////////////////////////////////////////////////////////////////////////
2 ///
3 /// \file
4 ///
5 /// A cubical version of the Alexander-Whitney diagonal,
6 /// based on simplicial subdivision of cubical cells.
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: April 11, 2013.
27 
28 
29 #ifndef _CHAINCON_AWDIAGCUBS_H_
30 #define _CHAINCON_AWDIAGCUBS_H_
31 
32 
33 // include some standard C++ header files
34 #include <istream>
35 #include <ostream>
36 
37 // include selected header files from the CHomP library
38 #include "chomp/system/config.h"
39 #include "chomp/cubes/pointbas.h"
40 
41 // include relevant local header files
42 #include "chaincon/cubcell.h"
43 #include "chaincon/combtensor.h"
44 #include "chaincon/tensor.h"
45 #include "chaincon/combchain.h"
46 #include "chaincon/chain.h"
47 #include "chaincon/simplex.h"
48 #include "chaincon/awdiagsim.h"
49 #include "chaincon/awdiag.h"
50 
51 
52 // --------------------------------------------------
53 // ------------------ AW diagonal -------------------
54 // --------------------------------------------------
55 
56 /// Computes the Alexander-Whitney diagonal of a cubical cell
57 /// using a simplicial subdivision of the cell.
58 /// Please, note that this formula has only been implemented
59 /// for 2-dimensional cells. Please, use the other function
60 /// based on Serre's paper for the general formula.
61 /// This is a combinatorial version of the function (coefficients in Z_p).
62 template <class CoordT, class WrapT, class EmptyT>
66 {
67  // prepare the data types to be used in this procedure
68  typedef tCubCell<CoordT,WrapT,EmptyT> CubeType;
69  typedef tSimplex<int_t,EmptyT> SimplexType;
70 
71  // abort the program if the dimension is different than two
72  if (c. dim () != 2)
73  {
74  throw "Trying to use a version of A-W diagonal "
75  "implemented for 2-dim cubes only.";
76  }
77 
78  // extract the coordinates of the four vertices of the cubical cell
79  int dim = c. spaceDim ();
80  CoordT coord [4] [chomp::homology::MaxBasDim];
81  int index = 0;
82  for (int i = 0; i < dim; ++ i)
83  {
84  coord [0] [i] = c. left (i);
85  coord [3] [i] = c. right (i);
86  if (coord [0] [i] != coord [3] [i])
87  {
88  coord [1] [i] = index ? coord [3] [i] :
89  coord [0] [i];
90  coord [2] [i] = index ? coord [0] [i] :
91  coord [3] [i];
92  ++ index;
93  }
94  else
95  {
96  coord [1] [i] = coord [0 ][i];
97  coord [2] [i] = coord [0] [i];
98  }
99  }
100 
101  // retrieve the numbers of the coordinates
102  int_t num [4];
103  for (int i = 0; i < 4; ++ i)
104  {
105  num [i] = chomp::homology::tPointBase<CoordT>::number
106  (coord [i], dim);
107  }
108 
109  // subdivide the cubical cell into simplices
111  int_t numbers [3];
112  numbers [0] = num [0];
113  numbers [1] = num [1];
114  numbers [2] = num [3];
115  std::sort (numbers, numbers + 3);
116  s. add (SimplexType (2, numbers));
117  numbers [0] = num [0];
118  numbers [1] = num [2];
119  numbers [2] = num [3];
120  std::sort (numbers, numbers + 3);
121  s. add (SimplexType (2, numbers));
122 
123  // compute the AW diagonal of the sum of these two simplices
125  AWdiagonal (s, simplTensor);
126 
127  // translate the simplices into cubical cells
128  // note: extract only the 1-dimensional cells
129  int_t size = simplTensor. size ();
130  for (int_t n = 0; n < size; ++ n)
131  {
132  // extract the pair of simplices that form the n-th term
133  // of the tensor product
134  SimplexType sim [2];
135  for (int side = 0; side < 2; ++ side)
136  {
137  sim [side] = side ? simplTensor. right (n) :
138  simplTensor. left (n);
139  }
140  if ((sim [0]. dim () != 1) || (sim [1]. dim () != 1))
141  continue;
142 
143  // find the indices of the cubical vertices of the simplices
144  int_t vert [2] [2];
145  for (int side = 0; side < 2; ++ side)
146  {
147  for (int v = 0; v < 2; ++ v)
148  {
149  int_t n = sim [side] [v];
150  int index = 0;
151  while (num [index] != n)
152  ++ index;
153  vert [side] [v] = index;
154  }
155  if (vert [side] [0] > vert [side] [1])
156  std::swap (vert [side] [0], vert [side] [1]);
157  }
158 
159  // convert this tensor product of simplices into cells
160  tCombChain<CubeType> cc [2];
161  for (int side = 0; side < 2; ++ side)
162  {
163  if ((vert [side] [0] == 0) && (vert [side] [1] == 3))
164  {
165  cc [side]. add (CubeType (dim,
166  coord [0], coord [1]));
167  cc [side]. add (CubeType (dim,
168  coord [1], coord [3]));
169  }
170  else
171  {
172  cc [side]. add (CubeType (dim,
173  coord [vert [side] [0]],
174  coord [vert [side] [1]]));
175  }
176  }
177 
178  // add the tensor products of the cells
179  for (int_t i = 0; i < cc [0]. size (); ++ i)
180  {
181  for (int_t j = 0; j < cc [1]. size (); ++ j)
182  {
183  t. add (cc [0]. getCell (i),
184  cc [1]. getCell (j));
185  }
186  }
187  }
188 
189  return;
190 } /* AWdiagonal */
191 
192 /// Computes the Alexander-Whitney diagonal of a cubical cell
193 /// using a simplicial subdivision of the cell.
194 /// A general version (for any coefficients).
195 template <class CoordT, class WrapT, class EmptyT, class CoefT>
196 inline void AWdiagonal (const tCubCell<CoordT,WrapT,EmptyT> &/*c*/,
198  tCubCell<CoordT,WrapT,EmptyT>,CoefT> &/*t*/)
199 {
200  throw "Trying to use a version of A-W diagonal "
201  "that was not implemented.";
202  return;
203 } /* AWdiagonal */
204 
205 
206 #endif // _CHAINCON_AWDIAGCUBS_H_
207 
void AWdiagonal(const tCubCell< CoordT, WrapT, EmptyT > &c, tCombTensor< tCubCell< CoordT, WrapT, EmptyT >, tCubCell< CoordT, WrapT, EmptyT > > &t)
Computes the Alexander-Whitney diagonal of a cubical cell using a simplicial subdivision of the cell...
Definition: awdiagcubs.h:63
A simplex with vertices of arbitrary type.
Definition: simplex.h:59
A combinatorial chain, that is, a chain with Z_2 coefficients.
A tensor of chains with coefficients in an arbitrary commutative ring.
A cubical cell.
Tensor of chains.
Definition: tensor.h:52
Combinatorial tensor of cells.
Definition: combtensor.h:53
A combinatorial chain.
Definition: combchain.h:49
A combinatorial tensor (for coefficients in Z_2).
A chain with coefficients in an arbitrary commutative ring.
A simplex class with arbitrary vertices.
Alexander-Whitney diagonal of a chain.
A simplicial version of the Alexander-Whitney diagonal.
An elementary cubical cell with vertex coordinates of integer type.
Definition: cubcell.h:63