Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #ifndef _CHAINCON_HOMGVF0_H_
00029 #define _CHAINCON_HOMGVF0_H_
00030
00031
00032
00033 #include <istream>
00034 #include <ostream>
00035
00036
00037 #include "chomp/system/config.h"
00038 #include "chomp/system/timeused.h"
00039 #include "chomp/system/textfile.h"
00040 #include "chomp/struct/hashsets.h"
00041
00042
00043 #include "chaincon/combchain.h"
00044 #include "chaincon/comblinmap.h"
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058 template <class CellT, class CellArray1, class CellArray2>
00059 void homologyGVF0 (const CellArray1 &K, CellArray2 &H,
00060 tCombLinMap<CellT,CellT> &pi,
00061 tCombLinMap<CellT,CellT> &incl,
00062 tCombLinMap<CellT,CellT> &phi)
00063 {
00064 using chomp::homology::sout;
00065 using chomp::homology::scon;
00066
00067
00068 if (K. empty ())
00069 return;
00070
00071
00072 sout << "Computing a homology gradient vector field...\n";
00073
00074
00075 chomp::homology::timeused compTime;
00076 compTime = 0;
00077
00078
00079 chomp::homology::hashedset<CellT> homGener;
00080
00081
00082 int_t KSize = K. size ();
00083 for (int_t i = 0; i < KSize; ++ i)
00084 {
00085
00086 if (!(i % 17))
00087 scon << i << " out of " << KSize << ", " <<
00088 (i * 100 / KSize) << "% done.\r";
00089
00090
00091 const CellT &c = K [i];
00092
00093
00094 tCombChain<CellT> ch (c);
00095 ch. add (phi (boundary (c)));
00096
00097
00098 tCombChain<CellT> bd_ch (boundary (ch));
00099
00100
00101 if (bd_ch. empty ())
00102 {
00103
00104 homGener. add (c);
00105
00106
00107 incl. add (c, ch);
00108
00109
00110 pi. add (c, c);
00111
00112
00113 continue;
00114 }
00115
00116
00117 tCombChain<CellT> d (pi (bd_ch));
00118
00119
00120 if (d. empty ())
00121 {
00122 sout << "Debug: c = " << c << ".\n";
00123 sout << "Debug: bd_c = " << boundary (c) <<
00124 ".\n";
00125 sout << "Debug: ch = " << ch << ".\n";
00126 sout << "Debug: bd_ch = " << bd_ch << ".\n";
00127 throw "Empty boundary in the homology algorithm.";
00128 }
00129
00130
00131 const CellT &u = d [0];
00132
00133
00134 tCombLinMap<CellT,CellT> phiAdd;
00135
00136
00137 tCombLinMap<CellT,CellT> piAdd;
00138
00139
00140 for (int_t j = 0; j < i; ++ j)
00141 {
00142
00143 const CellT &cj = K [j];
00144
00145
00146 tCombChain<CellT> cjh;
00147 cjh. add (cj);
00148 cjh. add (phi (boundary (cj)));
00149 cjh. add (boundary (phi (cj)));
00150 tCombChain<CellT> xi (pi (cjh));
00151
00152
00153
00154 if (!xi. contains (u))
00155 continue;
00156
00157
00158 phiAdd. add (cj, ch);
00159
00160
00161 tCombChain<CellT> combination;
00162 combination. add (phi (boundary (cj)));
00163 combination. add (boundary (phi (cj)));
00164 combination. add (phiAdd (boundary (cj)));
00165 combination. add (boundary (phiAdd (cj)));
00166 piAdd. add (cj, pi (combination));
00167 }
00168
00169
00170
00171 tCombLinMap<CellT,CellT> piAddTest;
00172
00173
00174 for (int_t j = 0; j < i; ++ j)
00175 {
00176
00177 const CellT &cj = K [j];
00178
00179
00180 tCombChain<CellT> cjh (boundary (phi (cj)));
00181 cjh. add (phi (boundary (cj)));
00182 cjh. add (cj);
00183 tCombChain<CellT> xi (pi (cjh));
00184
00185
00186
00187 if (!xi. contains (u))
00188 continue;
00189
00190
00191 tCombChain<CellT> combination;
00192 combination. add (phi (boundary (cj)));
00193 combination. add (boundary (phi (cj)));
00194 combination. add (phiAdd (boundary (cj)));
00195 combination. add (boundary (phiAdd (cj)));
00196 piAddTest. add (cj, pi (combination));
00197 }
00198
00199
00200 if (!(piAdd == piAddTest))
00201 {
00202 sout << "ERROR: The computed two versions "
00203 "of the map pi are not the same!\n";
00204 sout << "i = " << i << ", c_i = " << c <<
00205 ", u = " << u << ".\n";
00206 sout << "The wrong map piAdd:\n" << piAdd;
00207 sout << "The correct map piAdd:\n" << piAddTest;
00208 throw "Wrong map pi detected.\n";
00209 }
00210
00211
00212
00213 phi. add (phiAdd);
00214
00215
00216 pi. add (piAdd);
00217
00218
00219 homGener. remove (u);
00220 incl. remove (u);
00221 }
00222
00223
00224 sout << "Homology gvf computed in " << compTime << ".\n";
00225
00226
00227 int_t genSize = homGener. size ();
00228 for (int_t i = 0; i < genSize; ++ i)
00229 H. push_back (homGener [i]);
00230
00231 return;
00232 }
00233
00234
00235 #endif // _CHAINCON_HOMGVF0_H_
00236