• Main Page
  • Classes
  • Files
  • File List
  • File Members

chaincon/awdiagcubs.h

Go to the documentation of this file.
00001 /////////////////////////////////////////////////////////////////////////////
00002 ///
00003 /// \file
00004 ///
00005 /// A cubical version of the Alexander-Whitney diagonal,
00006 /// based on simplicial subdivision of cubical cells.
00007 ///
00008 /////////////////////////////////////////////////////////////////////////////
00009 
00010 // Copyright (C) 2009-2011 by Pawel Pilarczyk.
00011 //
00012 // This file is part of my research software package. This is free software:
00013 // you can redistribute it and/or modify it under the terms of the GNU
00014 // General Public License as published by the Free Software Foundation,
00015 // either version 3 of the License, or (at your option) any later version.
00016 //
00017 // This software is distributed in the hope that it will be useful,
00018 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00019 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00020 // GNU General Public License for more details.
00021 //
00022 // You should have received a copy of the GNU General Public License
00023 // along with this software; see the file "license.txt". If not,
00024 // please, see <http://www.gnu.org/licenses/>.
00025 
00026 // Started on March 24, 2009. Last revision: March 6, 2011.
00027 
00028 
00029 #ifndef _CHAINCON_AWDIAGCUBS_H_
00030 #define _CHAINCON_AWDIAGCUBS_H_
00031 
00032 
00033 // include some standard C++ header files
00034 #include <istream>
00035 #include <ostream>
00036 
00037 // include selected header files from the CHomP library
00038 #include "chomp/system/config.h"
00039 #include "chomp/cubes/pointbas.h"
00040 
00041 // include relevant local header files
00042 #include "chaincon/cubcell.h"
00043 #include "chaincon/combtensor.h"
00044 #include "chaincon/combchain.h"
00045 #include "chaincon/simplex.h"
00046 #include "chaincon/awdiagsim.h"
00047 #include "chaincon/awdiag.h"
00048 
00049 
00050 // --------------------------------------------------
00051 // ------------------ AW diagonal -------------------
00052 // --------------------------------------------------
00053 
00054 /// Computes the Alexander-Whitney diagonal of a cubical cell
00055 /// using a simplicial subdivision of the cell.
00056 /// Please, note that this formula has only been implemented
00057 /// for 2-dimensional cells at the moment; the general formula
00058 /// will be implemented soon.
00059 template <class CoordT>
00060 inline tCombTensor<tCubCell<CoordT> > AWdiagonal (const tCubCell<CoordT> &c)
00061 {
00062         // abort the program if the dimension is different than two
00063         if (c. dim () != 2)
00064                 throw "A-W diagonal implemented for 2-dim cubes only.";
00065 
00066         // extract the coordinates of the four vertices of the cubical cell
00067         int dim = c. spaceDim ();
00068         CoordT coord [4] [chomp::homology::MaxBasDim];
00069         int indices [2];
00070         int index = 0;
00071         for (int i = 0; i < dim; ++ i)
00072         {
00073                 coord [0] [i] = c. left (i);
00074                 coord [3] [i] = c. right (i);
00075                 if (coord [0] [i] != coord [3] [i])
00076                 {
00077                         coord [1] [i] = index ? coord [3] [i] :
00078                                 coord [0] [i];
00079                         coord [2] [i] = index ? coord [0] [i] :
00080                                 coord [3] [i];
00081                         indices [index ++] = i;
00082                 }
00083                 else
00084                 {
00085                         coord [1] [i] = coord [0 ][i];
00086                         coord [2] [i] = coord [0] [i];
00087                 }
00088         }
00089 
00090         // retrieve the numbers of the coordinates
00091         int_t num [4];
00092         for (int i = 0; i < 4; ++ i)
00093         {
00094                 num [i] = chomp::homology::tPointBase<CoordT>::number
00095                         (coord [i], dim);
00096         }
00097 
00098         // subdivide the cubical cell into simplices
00099         tCombChain<tSimplex<int_t> > s;
00100         int_t numbers [3];
00101         numbers [0] = num [0];
00102         numbers [1] = num [1];
00103         numbers [2] = num [3];
00104         std::sort (numbers, numbers + 3);
00105         s. add (tSimplex<int_t> (2, numbers));
00106         numbers [0] = num [0];
00107         numbers [1] = num [2];
00108         numbers [2] = num [3];
00109         std::sort (numbers, numbers + 3);
00110         s. add (tSimplex<int_t> (2, numbers));
00111 
00112         // compute the AW diagonal of the sum of these two simplices
00113         tCombTensor<tSimplex<int_t> > simplTensor (AWdiagonal (s));
00114 
00115         // translate the simplices into cubical cells
00116         // note: extract only the 1-dimensional cells
00117         tCombTensor<tCubCell<CoordT> > tensor;
00118         int_t size = simplTensor. size ();
00119         for (int_t n = 0; n < size; ++ n)
00120         {
00121                 // extract the pair of simplices that form the n-th term
00122                 // of the tensor product
00123                 tSimplex<int_t> sim [2];
00124                 for (int side = 0; side < 2; ++ side)
00125                 {
00126                         sim [side] = side ? simplTensor. right (n) :
00127                                 simplTensor. left (n);
00128                 }
00129                 if ((sim [0]. dim () != 1) || (sim [1]. dim () != 1))
00130                         continue;
00131 
00132                 // find the indices of the cubical vertices of the simplices
00133                 int_t vert [2] [2];
00134                 for (int side = 0; side < 2; ++ side)
00135                 {
00136                         for (int v = 0; v < 2; ++ v)
00137                         {
00138                                 int_t n = sim [side] [v];
00139                                 int index = 0;
00140                                 while (num [index] != n)
00141                                         ++ index;
00142                                 vert [side] [v] = index;
00143                         }
00144                         if (vert [side] [0] > vert [side] [1])
00145                                 std::swap (vert [side] [0], vert [side] [1]);
00146                 }
00147 
00148                 // convert this tensor product of simplices into cells
00149                 tCombChain<tCubCell<CoordT> > cc [2];
00150                 for (int side = 0; side < 2; ++ side)
00151                 {
00152                         if ((vert [side] [0] == 0) && (vert [side] [1] == 3))
00153                         {
00154                                 cc [side]. add (tCubCell<CoordT> (dim,
00155                                         coord [0], coord [1]));
00156                                 cc [side]. add (tCubCell<CoordT> (dim,
00157                                         coord [1], coord [3]));
00158                         }
00159                         else
00160                         {
00161                                 cc [side]. add (tCubCell<CoordT> (dim,
00162                                         coord [vert [side] [0]],
00163                                         coord [vert [side] [1]]));
00164                         }
00165                 }
00166 
00167                 // add the tensor products of the cells
00168                 for (int_t i = 0; i < cc [0]. size (); ++ i)
00169                 {
00170                         for (int_t j = 0; j < cc [1]. size (); ++ j)
00171                         {
00172                                 tensor. add (cc [0] [i], cc [1] [j]);
00173                         }
00174                 }
00175         }
00176 
00177         return tensor;
00178 } /* AWdiagonal */
00179 
00180 
00181 #endif // _CHAINCON_AWDIAGCUBS_H_
00182 

Generated on Tue Apr 5 2011 00:06:32 for Chain Contraction Software by  doxygen 1.7.2