00001 #ifndef GRAL_BASE_GB_GRIDFUNCTORS_H
00002 #define GRAL_BASE_GB_GRIDFUNCTORS_H
00003
00004
00005
00006
00007 #include "Config/compiler-config.h"
00008 #include "Utility/pre-post-conditions.h"
00009 #include "Gral/Base/common-grid-basics.h"
00010
00011
00049
00050
00051
00075 template<class G>
00076 struct cell2handle_map {
00077 typedef G grid_type;
00078 typedef grid_types<G> gt;
00079 typedef typename gt::Cell Cell;
00080 typedef Cell Element;
00081 typedef Cell element_type;
00082 typedef typename gt::cell_handle cell_handle;
00083
00084
00085 const G* g;
00086 public:
00087 typedef Cell argument_type;
00088 typedef cell_handle result_type;
00089
00090 cell2handle_map() : g(0) {}
00091 cell2handle_map(const G& gg) : g(&gg) {}
00092
00093 result_type operator()(const argument_type& c) const {
00094 REQUIRE((g != 0), "no grid!\n",1);
00095 return c.handle();
00096 }
00097
00098 grid_type const& TheGrid() const {
00099 REQUIRE((g!=0),"no grid!\n",1);
00100 return *g;
00101 }
00102 };
00103
00108 template<class G>
00109 inline cell2handle_map<G> cell2handle(const G& g)
00110 { return cell2handle_map<G>(g);}
00111
00112
00113
00114
00115
00121 template<class G>
00122 struct handle2cell_map {
00123 typedef G grid_type;
00124 typedef grid_types<G> gt;
00125 typedef typename gt::Cell Cell;
00126 typedef Cell element_type;
00127 typedef typename gt::cell_handle cell_handle;
00128
00129
00130 const G* g;
00131 public:
00132 typedef Cell result_type;
00133 typedef cell_handle argument_type;
00134
00135 handle2cell_map() : g(0) {}
00136 handle2cell_map(const G& gg) : g(&gg) {}
00137
00138 result_type operator()(const argument_type& c) const {
00139 REQUIRE((g != 0), "no grid!\n",1);
00140 return g->cell(c);
00141 }
00142 grid_type const& TheGrid() const {
00143 return *g;
00144 }
00145 };
00146
00151 template<class G>
00152 inline handle2cell_map<G> handle2cell(const G& g)
00153 { return handle2cell_map<G>(g);}
00154
00155
00156
00157
00158
00159
00160
00161
00162
00168 template<class G>
00169 struct vertex2handle_map {
00170 typedef G grid_type;
00171 typedef grid_types<G> gt;
00172 typedef typename gt::Vertex Vertex;
00173 typedef Vertex Element;
00174 typedef Vertex element_type;
00175 typedef typename gt::vertex_handle vertex_handle;
00176
00177
00178 const G* g;
00179 public:
00180 typedef Vertex argument_type;
00181 typedef vertex_handle result_type;
00182
00183 vertex2handle_map() : g(0) {}
00184 vertex2handle_map(const G& gg) : g(&gg) {}
00185
00186 result_type operator()(const argument_type& c) const {
00187 REQUIRE((g != 0), "no grid!\n",1);
00188 return c.handle();
00189 }
00190 grid_type const& TheGrid() const {
00191 REQUIRE((g!=0),"no grid!\n",1);
00192 return *g;
00193 }
00194 };
00195
00200 template<class G>
00201 inline vertex2handle_map<G> vertex2handle(const G& g)
00202 { return vertex2handle_map<G>(g);}
00203
00204
00205
00206
00207
00208
00209
00215 template<class G>
00216 struct handle2vertex_map {
00217 typedef G grid_type;
00218 typedef grid_types<G> gt;
00219 typedef typename gt::Vertex Vertex;
00220 typedef typename gt::vertex_handle vertex_handle;
00221
00222
00223 const G* g;
00224 public:
00225 typedef Vertex result_type;
00226 typedef vertex_handle argument_type;
00227
00228 handle2vertex_map() : g(0) {}
00229 handle2vertex_map(const G& gg) : g(&gg) {}
00230
00231 result_type operator()(const argument_type& c) const {
00232 REQUIRE((g != 0), "no grid!\n",1);
00233 return g->vertex(c);
00234 }
00235 grid_type const& TheGrid() const {
00236 REQUIRE((g!=0),"no grid!\n",1);
00237 return *g;
00238 }
00239 };
00240
00245 template<class G>
00246 inline handle2vertex_map<G> handle2vertex(const G& g)
00247 { return handle2vertex_map<G>(g);}
00248
00249
00250
00251
00252
00253
00254
00261 template<class E>
00262 struct element2handle_map {
00263 typedef element_traits<E> et;
00264 typedef typename et::grid_type grid_type;
00265 typedef grid_types<grid_type> gt;
00266 typedef typename et::handle_type element_handle;
00267 typedef E Element;
00268 typedef E element_type;
00269
00270
00271
00272 const grid_type* g;
00273 public:
00274 typedef Element argument_type;
00275 typedef element_handle result_type;
00276
00277 element2handle_map() : g(0) {}
00278 element2handle_map(const grid_type& gg) : g(&gg) {}
00279
00280 result_type operator()(const argument_type& e) const {
00281 REQUIRE((g != 0), "no grid!\n",1);
00282 return e.handle();
00283 }
00284 grid_type const& TheGrid() const {
00285 REQUIRE((g!=0),"no grid!\n",1);
00286 return *g;
00287 }
00288 };
00289
00294 template<class E>
00295 inline element2handle_map<E> element2handle(const E& e)
00296 { return element2handle_map<E>(e.TheGrid());}
00297
00302 template<class E, class G>
00303 inline element2handle_map<E> element2handle(const tp<E>&, const G& g)
00304 { return element2handle_map<E>(g);}
00305
00306
00307
00308
00309
00310
00318 template<class E>
00319 struct handle2element_map {
00320 typedef element_traits<E> et;
00321 typedef typename et::grid_type grid_type;
00322 typedef grid_types<grid_type> gt;
00323 typedef typename et::handle_type element_handle;
00324 typedef E Element;
00325 typedef E element_type;
00326 typedef Element result_type;
00327 typedef result_type value_type;
00328 typedef element_handle argument_type;
00329
00330
00331 const grid_type* g;
00332 public:
00333
00334 handle2element_map() : g(0) {}
00335 handle2element_map(const grid_type& gg) : g(&gg) {}
00336
00337 result_type operator()(const argument_type& e) const {
00338 REQUIRE((g != 0), "no grid!\n",1);
00339 return et::handle2element(*g,e);
00340 }
00341 grid_type const& TheGrid() const {
00342 REQUIRE((g!=0),"no grid!\n",1);
00343 return *g;
00344 }
00345 };
00346
00351 template<class E>
00352 inline handle2element_map<E> handle2element(const E& e)
00353 { return handle2element_map<E>(e.TheGrid());}
00354
00359 template<class E,class G>
00360 inline handle2element_map<E> handle2element(const tp<E>&, const G& g)
00361 { return handle2element_map<E>(g);}
00362
00363
00364
00365
00366
00367
00368
00378 template<class G>
00379 class iscellinside_pred {
00380 private:
00381 const G* g;
00382
00383 public:
00384 typedef G grid_type;
00385 typedef grid_types<G> gt;
00386 typedef typename gt::Cell Cell;
00387 typedef Cell element_type;
00388 typedef Cell argument_type;
00389 typedef bool result_type;
00390 typedef result_type value_type;
00391
00392 iscellinside_pred() : g(0) {}
00393 iscellinside_pred(const G& gg) : g(&gg) {}
00394 bool operator()(const Cell& c) const {
00395 REQUIRE((g!=0),"no grid!\n",1);
00396 return g->IsInside(c);
00397 }
00398
00399 grid_type const& TheGrid() const {
00400 REQUIRE((g!=0),"no grid!\n",1);
00401 return *g;
00402 }
00403 };
00404
00408 template<class G>
00409 inline iscellinside_pred<G>
00410 IsCellInside(const G& g) { return iscellinside_pred<G>(g);}
00411
00412
00419 template<class E>
00420 class isonboundary_pred {
00421 typedef element_traits<E> et;
00422 typedef typename et::grid_type grid_type;
00423 typedef typename et::element_type element_type;
00424 typedef E argument_type;
00425 typedef bool result_type;
00426 typedef result_type value_type;
00427 private:
00428 const grid_type* g;
00429
00430 public:
00431
00432 isonboundary_pred(grid_type const& gg) : g(&gg) {}
00433 bool operator()(const E& e) const {
00434 REQUIRE((g!=0),"no grid!\n",1);
00435 return g->IsOnBoundary(e);
00436 }
00437
00438 grid_type const& TheGrid() const {
00439 REQUIRE((g!=0),"no grid!\n",1);
00440 return *g;
00441 }
00442 };
00443
00448 template<class G>
00449 inline
00450 isonboundary_pred<typename G::Edge>
00451 IsEdgeOnBoundary(const G& g)
00452 { return isonboundary_pred<typename grid_types<G>::Edge>(g);}
00453
00458 template<class G>
00459 inline
00460 isonboundary_pred<typename G::Facet>
00461 IsFacetOnBoundary(const G& g)
00462 { return isonboundary_pred<typename grid_types<G>::Facet>(g);}
00463
00464
00465
00482 template<class G>
00483 class cell_nb_degree {
00484 public:
00485 typedef G grid_type;
00486 typedef grid_types<G> gt;
00487 typedef typename gt::Cell Cell;
00488 typedef Cell element_type;
00489 typedef Cell argument_type;
00490 typedef unsigned result_type;
00491 typedef result_type value_type;
00492
00493 cell_nb_degree() {}
00494 unsigned operator()(const Cell& c) const { return c.NumOfNeighbours();}
00495
00496 };
00497
00501 template<class G>
00502 inline cell_nb_degree<G>
00503 CellNbDegree(const G& g) { return cell_nb_degree<G>();}
00504
00511 template<class G>
00512 class cell_vtx_degree {
00513 public:
00514 typedef G grid_type;
00515 typedef grid_types<G> gt;
00516 typedef typename gt::Cell Cell;
00517 typedef Cell element_type;
00518 typedef Cell argument_type;
00519 typedef bool result_type;
00520 typedef result_type value_type;
00521
00522 cell_vtx_degree() {}
00523 bool operator()(const Cell& c) const { return c.NumOfVertices();}
00524 };
00525
00526
00530 template<class G>
00531 inline cell_vtx_degree<G>
00532 CellVertexDegree(const G& g) { return cell_vtx_degree<G>();}
00533
00534
00535
00536
00537
00538
00539
00548 template<class Cell>
00549 class cell_is_nb_pred {
00550 public:
00551 typedef typename Cell::grid_type grid_type;
00552 typedef grid_types<grid_type> gt;
00553 typedef typename gt::CellOnCellIterator NbIterator;
00554 typedef Cell element_type;
00555 typedef Cell argument_type;
00556 typedef bool result_type;
00557 typedef result_type value_type;
00558
00559 private:
00560 Cell C;
00561 public:
00562 cell_is_nb_pred(const Cell& CC) : C(CC) {}
00563
00564 bool operator()(const Cell& rs) const
00565 {
00566 for(NbIterator N = C.FirstNeighbour(); ! N.IsDone(); ++N)
00567 if(*N == rs)
00568 return true;
00569 return false;
00570 }
00571
00572 grid_type const& TheGrid() const { return C.TheGrid();}
00573 };
00574
00578 template<class Cell>
00579 cell_is_nb_pred<Cell> IsNeighbourCell(const Cell& rs)
00580 { return cell_is_nb_pred<Cell>(rs); }
00581
00582
00583 #endif
00584