ViennaGrid - The Vienna Grid Library  2.1.0
viennagrid/algorithm/refine.hpp
Go to the documentation of this file.
00001 #ifndef VIENNAGRID_ALGORITHM_REFINE_HPP
00002 #define VIENNAGRID_ALGORITHM_REFINE_HPP
00003 
00004 /* =======================================================================
00005    Copyright (c) 2011-2014, Institute for Microelectronics,
00006                             Institute for Analysis and Scientific Computing,
00007                             TU Wien.
00008 
00009                             -----------------
00010                      ViennaGrid - The Vienna Grid Library
00011                             -----------------
00012 
00013    License:      MIT (X11), see file LICENSE in the base directory
00014 ======================================================================= */
00015 
00016 #include "viennagrid/forwards.hpp"
00017 #include "viennagrid/algorithm/centroid.hpp"
00018 #include "viennagrid/algorithm/norm.hpp"
00019 
00020 #include "viennagrid/mesh/element_creation.hpp"
00021 #include "viennagrid/mesh/mesh_operations.hpp"
00022 
00023 #include "viennagrid/algorithm/detail/refine_tri.hpp"
00024 #include "viennagrid/algorithm/detail/refine_tet.hpp"
00025 
00026 #include "viennagrid/algorithm/detail/numeric.hpp"
00027 
00032 namespace viennagrid
00033 {
00034 
00044   template<typename ElementTypeOrTagT,
00045             typename WrappedMeshConfigInT,
00046             typename WrappedMeshConfigOutT,
00047             typename VertexCopyMapT,
00048             typename EdgeRefinementFlagAccessorT, typename RefinementVertexAccessorT>
00049   void simple_refine(mesh<WrappedMeshConfigInT> const & mesh_in,
00050                      mesh<WrappedMeshConfigOutT> & mesh_out,
00051                      VertexCopyMapT & vertex_copy_map_,
00052                      EdgeRefinementFlagAccessorT const & edge_refinement_flag_accessor,
00053                      RefinementVertexAccessorT const & edge_to_vertex_handle_accessor)
00054   {
00055     typedef mesh<WrappedMeshConfigInT>       InputMeshType;
00056     typedef mesh<WrappedMeshConfigOutT>      OutputMeshType;
00057 
00058     typedef typename viennagrid::result_of::const_element_range<InputMeshType, ElementTypeOrTagT>::type  ElementRange;
00059     typedef typename viennagrid::result_of::iterator<ElementRange>::type                                 ElementIterator;
00060 
00061     ElementRange cells(mesh_in);
00062     for (ElementIterator cit  = cells.begin();
00063                       cit != cells.end();
00064                     ++cit)
00065     {
00066       typedef typename viennagrid::result_of::vertex_handle<OutputMeshType>::type OutputVertexHandleType;
00067       typedef std::vector<OutputVertexHandleType> VertexHandlesContainerType;
00068       typedef std::vector<VertexHandlesContainerType> ElementsContainerType;
00069       ElementsContainerType elements_vertices;
00070 
00071       detail::element_refinement<ElementTypeOrTagT>::apply(*cit, mesh_out, elements_vertices, vertex_copy_map_, edge_refinement_flag_accessor, edge_to_vertex_handle_accessor);
00072 
00073       for (typename ElementsContainerType::iterator it = elements_vertices.begin();
00074             it != elements_vertices.end();
00075             ++it)
00076         viennagrid::make_element<ElementTypeOrTagT>( mesh_out, it->begin(), it->end() );
00077     }
00078   }
00079 
00080 
00092   template<typename ElementTypeOrTagT,
00093             typename WrappedMeshConfigInT,  typename WrappedSegmentationConfigInT,
00094             typename WrappedMeshConfigOutT, typename WrappedSegmentationConfigOutT,
00095             typename VertexCopyMapT,
00096             typename EdgeRefinementFlagAccessorT, typename RefinementVertexAccessorT>
00097   void simple_refine(mesh<WrappedMeshConfigInT>                 const & mesh_in,
00098                      segmentation<WrappedSegmentationConfigInT> const & segmentation_in,
00099                      mesh<WrappedMeshConfigOutT>                      & mesh_out,
00100                      segmentation<WrappedSegmentationConfigOutT>      & segmentation_out,
00101                      VertexCopyMapT & vertex_copy_map_,
00102                      EdgeRefinementFlagAccessorT const & edge_refinement_flag_accessor,
00103                      RefinementVertexAccessorT const & edge_to_vertex_handle_accessor)
00104   {
00105     typedef mesh<WrappedMeshConfigInT>    InputMeshType;
00106     typedef mesh<WrappedMeshConfigOutT>   OutputMeshType;
00107 
00108     typedef segmentation<WrappedSegmentationConfigInT>      InputSegmentationType;
00109 
00110     typedef typename viennagrid::result_of::const_element_range<InputMeshType, ElementTypeOrTagT>::type ElementRange;
00111     typedef typename viennagrid::result_of::iterator<ElementRange>::type                                ElementIterator;
00112 
00113     ElementRange cells(mesh_in);
00114     for (ElementIterator cit  = cells.begin();
00115                       cit != cells.end();
00116                     ++cit)
00117     {
00118       typedef typename viennagrid::result_of::segment_id_range<InputSegmentationType, ElementTypeOrTagT>::type SegmentIDRangeType;
00119 
00120       SegmentIDRangeType segment_ids = viennagrid::segment_ids( segmentation_in, *cit );
00121 
00122       typedef typename viennagrid::result_of::vertex_handle<OutputMeshType>::type OutputVertexHandleType;
00123       typedef typename viennagrid::result_of::handle<OutputMeshType, ElementTypeOrTagT>::type OutputCellHandleType;
00124       typedef std::vector<OutputVertexHandleType> VertexHandlesContainerType;
00125       typedef std::vector<VertexHandlesContainerType> ElementsContainerType;
00126       ElementsContainerType elements_vertices;
00127 
00128       detail::element_refinement<ElementTypeOrTagT>::apply(*cit, mesh_out, elements_vertices, vertex_copy_map_, edge_refinement_flag_accessor, edge_to_vertex_handle_accessor);
00129 
00130       for (typename ElementsContainerType::iterator it = elements_vertices.begin();
00131             it != elements_vertices.end();
00132             ++it)
00133       {
00134         OutputCellHandleType new_cell = viennagrid::make_element<ElementTypeOrTagT>( mesh_out, it->begin(), it->end() );
00135         viennagrid::add( segmentation_out, segment_ids.begin(), segment_ids.end(), new_cell );
00136       }
00137     }
00138   }
00139 
00140 
00141 
00142 
00143   namespace detail
00144   {
00145 
00146 
00147 
00149     template<typename CellTagT,
00150               typename WrappedMeshConfigInT,
00151               typename WrappedMeshConfigOutT,
00152               typename PointAccessorT,
00153               typename VertexCopyMapT,
00154               typename EdgeRefinementFlagAccessorT, typename RefinementVertexAccessorT>
00155     void refine_impl(mesh<WrappedMeshConfigInT> const & mesh_in,
00156                      mesh<WrappedMeshConfigOutT> & mesh_out,
00157                      PointAccessorT const point_accessor_in,
00158                      VertexCopyMapT & vertex_copy_map_,
00159                      EdgeRefinementFlagAccessorT const & edge_refinement_flag_accessor,
00160                      RefinementVertexAccessorT & edge_to_vertex_handle_accessor)
00161     {
00162       typedef mesh<WrappedMeshConfigInT>       InputMeshType;
00163 
00164       typedef typename viennagrid::result_of::const_line_range<InputMeshType>::type                 EdgeRange;
00165       typedef typename viennagrid::result_of::iterator<EdgeRange>::type                             EdgeIterator;
00166 
00167       //
00168       // Step 1: Each tagged edge in old mesh results in a new vertex (temporarily store new vertex IDs on old mesh)
00169       //
00170       EdgeRange edges(mesh_in);
00171       for (EdgeIterator eit = edges.begin();
00172                         eit != edges.end();
00173                       ++eit)
00174       {
00175         if ( edge_refinement_flag_accessor(*eit) )
00176         {
00177           edge_to_vertex_handle_accessor( *eit ) = viennagrid::make_vertex( mesh_out, viennagrid::centroid(point_accessor_in, *eit) );
00178         }
00179       }
00180 
00181       //
00182       // Step 2: Now write new cells to new mesh
00183       //
00184       simple_refine<CellTagT>(mesh_in, mesh_out, vertex_copy_map_, edge_refinement_flag_accessor, edge_to_vertex_handle_accessor);
00185     }
00186 
00187 
00188 
00190     template<typename CellTagT,
00191               typename WrappedMeshConfigInT,  typename WrappedSegmentationConfigInT,
00192               typename WrappedMeshConfigOutT, typename WrappedSegmentationConfigOutT,
00193               typename PointAccessorT,
00194               typename VertexCopyMapT,
00195               typename EdgeRefinementFlagAccessorT, typename RefinementVertexAccessorT>
00196     void refine_impl(mesh<WrappedMeshConfigInT>                 const & mesh_in,
00197                      segmentation<WrappedSegmentationConfigInT> const & segmentation_in,
00198                      mesh<WrappedMeshConfigOutT>                      & mesh_out,
00199                      segmentation<WrappedSegmentationConfigOutT>      & segmentation_out,
00200                      PointAccessorT const point_accessor_in,
00201                      VertexCopyMapT & vertex_copy_map_,
00202                      EdgeRefinementFlagAccessorT const & edge_refinement_flag_accessor,
00203                      RefinementVertexAccessorT & edge_to_vertex_handle_accessor)
00204     {
00205       typedef mesh<WrappedMeshConfigInT>    InputMeshType;
00206 
00207       typedef typename viennagrid::result_of::const_line_range<InputMeshType>::type       EdgeRange;
00208       typedef typename viennagrid::result_of::iterator<EdgeRange>::type                               EdgeIterator;
00209 
00210 
00211       //
00212       // Step 1: Each tagged edge in old mesh results in a new vertex (temporarily store new vertex IDs on old mesh)
00213       //
00214       EdgeRange edges(mesh_in);
00215       for (EdgeIterator eit = edges.begin();
00216                         eit != edges.end();
00217                       ++eit)
00218       {
00219         if ( edge_refinement_flag_accessor(*eit) )
00220         {
00221           edge_to_vertex_handle_accessor( *eit ) = viennagrid::make_vertex( mesh_out, viennagrid::centroid(point_accessor_in, *eit) );
00222         }
00223       }
00224 
00225       //
00226       // Step 2: Now write new cells to new mesh
00227       //
00228       simple_refine<CellTagT>( mesh_in, segmentation_in, mesh_out, segmentation_out, vertex_copy_map_, edge_refinement_flag_accessor, edge_to_vertex_handle_accessor );
00229     }
00230 
00231 
00232   } //namespace detail
00233 
00234 
00235 
00237   template<typename CellTagIn, typename WrappedMeshConfigInT, typename EdgeRefinementFlagAccessorT>
00238   void ensure_longest_edge_refinement(mesh<WrappedMeshConfigInT> const & mesh_in, EdgeRefinementFlagAccessorT edge_refinement_flag_accessor)
00239   {
00240     typedef mesh<WrappedMeshConfigInT>                                            MeshInType;
00241 
00242     typedef typename viennagrid::result_of::element<MeshInType, vertex_tag>::type     VertexType;
00243     typedef typename viennagrid::result_of::element<MeshInType, line_tag>::type       EdgeType;
00244     typedef typename viennagrid::result_of::element<MeshInType, CellTagIn>::type      CellType;
00245 
00246     typedef typename viennagrid::result_of::const_element_range<MeshInType, CellTagIn>::type    CellRange;
00247     typedef typename viennagrid::result_of::iterator<CellRange>::type                             CellIterator;
00248     typedef typename viennagrid::result_of::const_element_range<CellType, line_tag>::type         EdgeOnCellRange;
00249     typedef typename viennagrid::result_of::iterator<EdgeOnCellRange>::type                       EdgeOnCellIterator;
00250     typedef typename viennagrid::result_of::const_element_range<EdgeType, vertex_tag>::type       VertexOnEdgeRange;
00251     typedef typename viennagrid::result_of::iterator<VertexOnEdgeRange>::type                     VertexOnEdgeIterator;
00252 
00253 
00254     bool something_changed = true;
00255     //std::size_t iter_cnt = 0;
00256 
00257     while (something_changed)
00258     {
00259       something_changed = false;
00260 
00261       CellRange cells = viennagrid::elements<CellTagIn>(mesh_in);
00262       for (CellIterator cit  = cells.begin();
00263                         cit != cells.end();
00264                       ++cit)
00265       {
00266         //
00267         // check if any edges are tagged for refinement
00268         //
00269         bool has_refinement = false;
00270         EdgeOnCellRange edges_on_cell = viennagrid::elements<line_tag>(*cit);
00271         for (EdgeOnCellIterator eocit = edges_on_cell.begin();
00272                                 eocit != edges_on_cell.end();
00273                               ++eocit)
00274         {
00275           if ( edge_refinement_flag_accessor(*eocit) )
00276           {
00277             has_refinement = true;
00278             break;
00279           }
00280         }
00281 
00282         if (has_refinement)
00283         {
00284           //
00285           // Find longest edge
00286           //
00287           EdgeType const * longest_edge_ptr = NULL;
00288           double longest_edge_len = 0;
00289 
00290           for (EdgeOnCellIterator eocit = edges_on_cell.begin();
00291                                   eocit != edges_on_cell.end();
00292                                 ++eocit)
00293           {
00294             VertexOnEdgeRange vertices_on_edge = viennagrid::elements<vertex_tag>(*eocit);
00295             VertexOnEdgeIterator voeit = vertices_on_edge.begin();
00296             VertexType const & v0 = *voeit; ++voeit;
00297             VertexType const & v1 = *voeit;
00298 
00299             double len = viennagrid::norm( viennagrid::point(mesh_in, v0) - viennagrid::point(mesh_in, v1) );
00300             if (len > longest_edge_len)
00301             {
00302               longest_edge_len = len;
00303               longest_edge_ptr = &(*eocit);
00304             }
00305           }
00306 
00307           //tag longest edge:
00308           if ( !edge_refinement_flag_accessor(*longest_edge_ptr) )
00309           {
00310             edge_refinement_flag_accessor(*longest_edge_ptr) = true;
00311             something_changed = true;
00312           }
00313         }
00314 
00315       } //for cells
00316 
00317 
00318     } //while
00319   } //ensure_longest_edge_refinement
00320 
00322   template<typename CellTagIn, typename WrappedMeshConfigInT, typename CellRefinementFlagAccessorT, typename EdgeRefinementFlagAccessorT>
00323   void cell_refinement_to_edge_refinement(mesh<WrappedMeshConfigInT> const & mesh_in,
00324                                           CellRefinementFlagAccessorT cell_refinement_flag, EdgeRefinementFlagAccessorT edge_refinement_flag_accessor)
00325   {
00326     typedef mesh<WrappedMeshConfigInT>                                                        MeshInType;
00327 
00328     typedef typename viennagrid::result_of::element<MeshInType, CellTagIn>::type                  CellType;
00329 
00330     typedef typename viennagrid::result_of::const_element_range<MeshInType, CellTagIn>::type      CellRange;
00331     typedef typename viennagrid::result_of::iterator<CellRange>::type                               CellIterator;
00332     typedef typename viennagrid::result_of::const_element_range<CellType, line_tag>::type           EdgeOnCellRange;
00333     typedef typename viennagrid::result_of::iterator<EdgeOnCellRange>::type                         EdgeOnCellIterator;
00334 
00335     std::size_t cells_for_refinement = 0;
00336     CellRange cells(mesh_in);
00337     for (CellIterator cit  = cells.begin();
00338                       cit != cells.end();
00339                     ++cit)
00340     {
00341       if ( cell_refinement_flag(*cit) )
00342       {
00343         ++cells_for_refinement;
00344 
00345         EdgeOnCellRange edges_on_cell(*cit);
00346         for (EdgeOnCellIterator eocit = edges_on_cell.begin();
00347                                 eocit != edges_on_cell.end();
00348                               ++eocit)
00349         {
00350           edge_refinement_flag_accessor(*eocit) = true;
00351         }
00352       }
00353     }
00354 
00355   }
00356 
00357 
00359   template<typename WrappedMeshConfigInT, typename EdgeRefinementFlagAccessorT>
00360   void mark_all_edge_refinement(mesh<WrappedMeshConfigInT> const & mesh_in, EdgeRefinementFlagAccessorT edge_refinement_flag_accessor)
00361   {
00362     typedef mesh<WrappedMeshConfigInT>                                                                MeshInType;
00363 
00364     typedef typename viennagrid::result_of::const_element_range<MeshInType, viennagrid::line_tag>::type   LineRange;
00365     typedef typename viennagrid::result_of::iterator<LineRange>::type                                       LineIterator;
00366 
00367     LineRange lines(mesh_in);
00368     for (LineIterator it = lines.begin(); it != lines.end(); ++it)
00369       edge_refinement_flag_accessor(*it) = true;
00370   }
00371 
00372 
00374   template<typename SrcMeshT, typename DstMeshT, typename PointT, typename LineRefinementTagContainerT, typename LineRefinementVertexHandleContainerT, typename NumericConfigT>
00375   void mark_edges_for_hyperplane_refine(SrcMeshT const & src_mesh, DstMeshT & dst_mesh,
00376                             PointT const & hyperplane_point, PointT const & hyperplane_normal,
00377                             LineRefinementTagContainerT & line_refinement_tag_accessor,
00378                             LineRefinementVertexHandleContainerT & line_refinement_vertex_handle_accessor,
00379                             NumericConfigT numeric_config)
00380   {
00381     typedef typename viennagrid::result_of::coord<SrcMeshT>::type NumericType;
00382     typedef typename viennagrid::result_of::const_line_range<SrcMeshT>::type ConstLineRangeType;
00383     typedef typename viennagrid::result_of::iterator<ConstLineRangeType>::type ConstLineIteratorType;
00384 
00385     ConstLineRangeType lines(src_mesh);
00386     for (ConstLineIteratorType lit = lines.begin(); lit != lines.end(); ++lit)
00387     {
00388       NumericType distance0 = viennagrid::inner_prod( hyperplane_normal, viennagrid::point( viennagrid::vertices(*lit)[0] )-hyperplane_point );
00389       NumericType distance1 = viennagrid::inner_prod( hyperplane_normal, viennagrid::point( viennagrid::vertices(*lit)[1] )-hyperplane_point );
00390 
00391       NumericType tolerance = viennagrid::detail::relative_tolerance(numeric_config, viennagrid::volume(*lit));
00392 
00393       if (distance0 > distance1)
00394         std::swap(distance0, distance1);
00395 
00396       if (distance0 < -tolerance && distance1 > tolerance)
00397       {
00398         line_refinement_tag_accessor(*lit) = true;
00399 
00400         PointT const & pt0 = viennagrid::point( viennagrid::vertices(*lit)[0] );
00401         PointT const & pt1 = viennagrid::point( viennagrid::vertices(*lit)[1] );
00402 
00403         double qd = viennagrid::inner_prod( hyperplane_normal, pt0-hyperplane_point );
00404         double pd = viennagrid::inner_prod( hyperplane_normal, pt1-hyperplane_point );
00405 
00406         PointT new_pt = pt1 - (pd / (pd-qd)) * (pt1 - pt0);
00407         line_refinement_vertex_handle_accessor(*lit) = viennagrid::make_unique_vertex( dst_mesh, new_pt );
00408       }
00409       else
00410         line_refinement_tag_accessor(*lit) = false;
00411     }
00412   }
00413 
00414 
00415 
00416 
00417 
00418 
00419 
00430   template<typename ElementTypeOrTagT,
00431            typename WrappedMeshConfigInT, typename WrappedMeshConfigOutT,
00432            typename PointAccessorType,
00433            typename VertexCopyMapT,
00434            typename EdgeRefinementFlagAccessorT, typename RefinementVertexAccessor>
00435   void refine(mesh<WrappedMeshConfigInT> const & mesh_in,
00436               mesh<WrappedMeshConfigOutT> & mesh_out,
00437               PointAccessorType point_accessor_in,
00438               VertexCopyMapT & vertex_copy_map_,
00439               EdgeRefinementFlagAccessorT const & edge_refinement_flag_accessor,
00440               RefinementVertexAccessor & edge_to_vertex_handle_accessor)
00441   {
00442       typedef typename viennagrid::result_of::element_tag<ElementTypeOrTagT>::type CellTag;
00443 
00444       detail::refine_impl<CellTag>(mesh_in, mesh_out, point_accessor_in,
00445                                   vertex_copy_map_,
00446                                   edge_refinement_flag_accessor, edge_to_vertex_handle_accessor);
00447   }
00448 
00449 
00458   template<typename ElementTypeOrTagT,
00459            typename WrappedMeshConfigInT, typename WrappedMeshConfigOutT,
00460            typename PointAccessorType,
00461            typename EdgeRefinementFlagAccessorT>
00462   void refine(mesh<WrappedMeshConfigInT> const & mesh_in,
00463               mesh<WrappedMeshConfigOutT> & mesh_out,
00464               PointAccessorType point_accessor_in,
00465               EdgeRefinementFlagAccessorT const & edge_refinement_flag_accessor)
00466   {
00467     typedef mesh<WrappedMeshConfigInT>                                             MeshInType;
00468     typedef mesh<WrappedMeshConfigOutT>                                             MeshOutType;
00469 
00470     typedef typename viennagrid::result_of::line<MeshOutType>::type                     EdgeType;
00471 
00472     typedef typename viennagrid::result_of::vertex_handle<MeshOutType>::type            VertexHandleType;
00473 
00474     viennagrid::vertex_copy_map<MeshInType, MeshOutType> vertex_map(mesh_out);
00475     std::deque<VertexHandleType> edge_refinement_vertex_handle_container;
00476     typename viennagrid::result_of::accessor<std::deque<VertexHandleType>, EdgeType>::type edge_refinement_vertex_handle_accessor(edge_refinement_vertex_handle_container);
00477 
00478     refine<ElementTypeOrTagT>(mesh_in, mesh_out, point_accessor_in,
00479                     vertex_map,
00480                     edge_refinement_flag_accessor,
00481                     edge_refinement_vertex_handle_accessor);
00482   }
00483 
00491   template<typename ElementTypeOrTagT,
00492            typename WrappedMeshConfigInT, typename WrappedMeshConfigOutT,
00493            typename EdgeRefinementFlagAccessorT>
00494   void refine(mesh<WrappedMeshConfigInT> const & mesh_in,
00495               mesh<WrappedMeshConfigOutT> & mesh_out,
00496               EdgeRefinementFlagAccessorT const & edge_refinement_flag_accessor)
00497   {
00498     refine<ElementTypeOrTagT>(mesh_in, mesh_out, default_point_accessor(mesh_in), edge_refinement_flag_accessor);
00499   }
00500 
00501 
00502 
00511   template<typename ElementTypeOrTagT,
00512            typename WrappedMeshConfigInT, typename WrappedMeshConfigOutT,
00513            typename PointAccessorType,
00514            typename CellRefinementFlagAccessorT>
00515   void element_refine(mesh<WrappedMeshConfigInT> const & mesh_in,
00516                       mesh<WrappedMeshConfigOutT> & mesh_out,
00517                       PointAccessorType point_accessor_in, CellRefinementFlagAccessorT const cell_refinement_flag_accessor)
00518   {
00519     typedef mesh<WrappedMeshConfigOutT>                                             MeshOutType;
00520 
00521     typedef typename viennagrid::result_of::line<MeshOutType>::type                     EdgeType;
00522 
00523     std::deque<bool> edge_refinement_flag;
00524 
00525     edge_refinement_flag.resize( static_cast<std::size_t>(viennagrid::id_upper_bound<EdgeType>(mesh_in).get()) );
00526 
00527     cell_refinement_to_edge_refinement<ElementTypeOrTagT>( mesh_in,
00528                                         cell_refinement_flag_accessor,
00529                                         viennagrid::make_accessor<EdgeType>(edge_refinement_flag));
00530 
00531     refine<ElementTypeOrTagT>(mesh_in, mesh_out, point_accessor_in,
00532                     viennagrid::make_accessor<EdgeType>(edge_refinement_flag));
00533   }
00534 
00542   template<typename ElementTypeOrTagT,
00543            typename WrappedMeshConfigInT, typename WrappedMeshConfigOutT,
00544            typename CellRefinementFlagAccessorT>
00545   void element_refine(mesh<WrappedMeshConfigInT> const & mesh_in,
00546                       mesh<WrappedMeshConfigOutT> & mesh_out,
00547                       CellRefinementFlagAccessorT const cell_refinement_flag_accessor)
00548   {
00549     element_refine<ElementTypeOrTagT>(mesh_in, mesh_out, default_point_accessor(mesh_in), cell_refinement_flag_accessor);
00550   }
00551 
00558   template<typename WrappedMeshConfigInT, typename WrappedMeshConfigOutT,
00559             typename CellRefinementFlagAccessorT>
00560   void cell_refine(mesh<WrappedMeshConfigInT> const & mesh_in,
00561                    mesh<WrappedMeshConfigOutT> & mesh_out,
00562                    CellRefinementFlagAccessorT const cell_refinement_flag_accessor)
00563   {
00564     typedef mesh<WrappedMeshConfigInT>                            MeshInType;
00565     typedef typename viennagrid::result_of::cell<MeshInType>::type    CellType;
00566 
00567     element_refine<CellType>(mesh_in, mesh_out, default_point_accessor(mesh_in), cell_refinement_flag_accessor);
00568   }
00569 
00570 
00571 
00572 
00583   template<typename ElementTypeOrTagT,
00584            typename WrappedMeshConfigInT, typename WrappedMeshConfigOutT,
00585            typename PointAccessorType,
00586            typename VertexCopyMapT,
00587            typename EdgeRefinementFlagAccessorT, typename RefinementVertexAccessor>
00588   void refine_uniformly(mesh<WrappedMeshConfigInT> const & mesh_in,
00589                         mesh<WrappedMeshConfigOutT> & mesh_out,
00590                         PointAccessorType point_accessor_in,
00591                         VertexCopyMapT vertex_copy_map_,
00592                         EdgeRefinementFlagAccessorT const & edge_refinement_flag_accessor,
00593                         RefinementVertexAccessor edge_to_vertex_handle_accessor)
00594   {
00595     mark_all_edge_refinement( mesh_in, edge_refinement_flag_accessor );
00596     refine<ElementTypeOrTagT>(mesh_in, mesh_out, point_accessor_in,
00597                           vertex_copy_map_,
00598                           edge_refinement_flag_accessor, edge_to_vertex_handle_accessor);
00599   }
00600 
00609   template<typename ElementTypeOrTagT,
00610            typename WrappedMeshConfigInT, typename WrappedMeshConfigOutT,
00611            typename PointAccessorType,
00612            typename EdgeRefinementFlagAccessorT>
00613   void refine_uniformly(mesh<WrappedMeshConfigInT> const & mesh_in,
00614                         mesh<WrappedMeshConfigOutT> & mesh_out,
00615                         PointAccessorType point_accessor_in,
00616                         EdgeRefinementFlagAccessorT const & edge_refinement_flag_accessor)
00617   {
00618     mark_all_edge_refinement( mesh_in, edge_refinement_flag_accessor );
00619     refine<ElementTypeOrTagT>(mesh_in, mesh_out, point_accessor_in, edge_refinement_flag_accessor);
00620   }
00621 
00629   template<typename ElementTypeOrTagT,
00630            typename WrappedMeshConfigInT, typename WrappedMeshConfigOutT,
00631            typename EdgeRefinementFlagAccessorT>
00632   void refine_uniformly(mesh<WrappedMeshConfigInT> const & mesh_in,
00633                         mesh<WrappedMeshConfigOutT> & mesh_out,
00634                         EdgeRefinementFlagAccessorT const & edge_refinement_flag_accessor)
00635   {
00636     refine_uniformly<ElementTypeOrTagT>(mesh_in, mesh_out, default_point_accessor(mesh_in), edge_refinement_flag_accessor);
00637   }
00638 
00645   template<typename ElementTypeOrTagT,
00646            typename WrappedMeshConfigInT, typename WrappedMeshConfigOutT>
00647   void refine_uniformly(mesh<WrappedMeshConfigInT> const & mesh_in,
00648                         mesh<WrappedMeshConfigOutT> & mesh_out)
00649   {
00650     typedef mesh<WrappedMeshConfigOutT>                             MeshOutType;
00651     typedef typename viennagrid::result_of::line<MeshOutType>::type     EdgeType;
00652     std::deque<bool> edge_refinement_flag;
00653 
00654     refine_uniformly<ElementTypeOrTagT>(mesh_in, mesh_out, viennagrid::make_accessor<EdgeType>(edge_refinement_flag));
00655   }
00656 
00662   template<typename WrappedMeshConfigInT, typename WrappedMeshConfigOutT>
00663   void cell_refine_uniformly(mesh<WrappedMeshConfigInT> const & mesh_in,
00664                              mesh<WrappedMeshConfigOutT> & mesh_out)
00665   {
00666     typedef mesh<WrappedMeshConfigInT>                            MeshInType;
00667     typedef typename viennagrid::result_of::cell<MeshInType>::type    CellType;
00668 
00669     refine_uniformly<CellType>(mesh_in, mesh_out);
00670   }
00671 
00680   template<typename SrcMeshT, typename DstMeshT, typename PointT, typename NumericConfigT>
00681   void hyperplane_refine(SrcMeshT const & src_mesh, DstMeshT & dst_mesh,
00682                          PointT const & hyperplane_point, PointT const & hyperplane_normal,
00683                          NumericConfigT numeric_config)
00684   {
00685     typedef typename viennagrid::result_of::cell_tag<SrcMeshT>::type CellTag;
00686     typedef typename viennagrid::result_of::line<SrcMeshT>::type LineType;
00687 
00688     typedef typename viennagrid::result_of::vertex_handle<DstMeshT>::type DstMeshVertexHandleType;
00689 
00690     viennagrid::vertex_copy_map<SrcMeshT, DstMeshT> vertex_map( dst_mesh );
00691 
00692     std::deque<bool> line_refinement_tag_container;
00693     typename viennagrid::result_of::accessor<std::deque<bool>, LineType>::type line_refinement_tag_accessor(line_refinement_tag_container);
00694 
00695     std::deque<DstMeshVertexHandleType> line_refinement_vertex_handle_container;
00696     typename viennagrid::result_of::accessor<std::deque<DstMeshVertexHandleType>, LineType>::type line_refinement_vertex_handle_accessor(line_refinement_vertex_handle_container);
00697 
00698     mark_edges_for_hyperplane_refine(src_mesh, dst_mesh, hyperplane_point, hyperplane_normal, line_refinement_tag_accessor, line_refinement_vertex_handle_accessor, numeric_config);
00699 
00700     viennagrid::simple_refine<CellTag>(src_mesh, dst_mesh,
00701                                        vertex_map,
00702                                        line_refinement_tag_accessor,
00703                                        line_refinement_vertex_handle_accessor);
00704   }
00705 
00706 
00707 
00708 
00709 
00710 
00723   template<typename ElementTypeOrTagT,
00724             typename WrappedMeshConfigInT, typename WrappedSegmentationConfigInT,
00725             typename WrappedMeshConfigOutT, typename WrappedSegmentationConfigOutT,
00726             typename PointAccessorT,
00727             typename VertexCopyMapT,
00728             typename EdgeRefinementFlagAccessorT, typename RefinementVertexAccessorT>
00729   void refine(mesh<WrappedMeshConfigInT> const & mesh_in,
00730               segmentation<WrappedSegmentationConfigInT> const & segmentation_in,
00731               mesh<WrappedMeshConfigOutT> & mesh_out,
00732               segmentation<WrappedSegmentationConfigOutT> & segmentation_out,
00733               PointAccessorT point_accessor_in,
00734               VertexCopyMapT & vertex_copy_map_,
00735               EdgeRefinementFlagAccessorT const & edge_refinement_flag_accessor,
00736               RefinementVertexAccessorT & edge_to_vertex_handle_accessor)
00737   {
00738     typedef typename viennagrid::result_of::element_tag<ElementTypeOrTagT>::type CellTag;
00739 
00740     detail::refine_impl<CellTag>(mesh_in, segmentation_in,
00741                                  mesh_out, segmentation_out,
00742                                  point_accessor_in,
00743                                  vertex_copy_map_,
00744                                  edge_refinement_flag_accessor, edge_to_vertex_handle_accessor);
00745   }
00746 
00747 
00758   template<typename ElementTypeOrTagT,
00759            typename WrappedMeshConfigInT,  typename WrappedSegmentationConfigInT,
00760            typename WrappedMeshConfigOutT, typename WrappedSegmentationConfigOutT,
00761            typename PointAccessorT,
00762            typename EdgeRefinementFlagAccessorT>
00763   void refine(mesh<WrappedMeshConfigInT> const & mesh_in,  segmentation<WrappedSegmentationConfigInT> const & segmentation_in,
00764               mesh<WrappedMeshConfigOutT> & mesh_out,      segmentation<WrappedSegmentationConfigOutT> & segmentation_out,
00765               PointAccessorT point_accessor_in,
00766               EdgeRefinementFlagAccessorT const & edge_refinement_flag_accessor)
00767   {
00768     typedef mesh<WrappedMeshConfigInT> MeshInT;
00769     typedef mesh<WrappedMeshConfigOutT> MeshOutT;
00770 
00771     typedef typename viennagrid::result_of::line<MeshOutT>::type EdgeType;
00772 
00773     typedef typename viennagrid::result_of::vertex_handle<MeshOutT>::type VertexHandleType;
00774 
00775     viennagrid::vertex_copy_map<MeshInT, MeshOutT> vertex_map(mesh_out);
00776     std::deque<VertexHandleType> edge_refinement_vertex_handle_container;
00777     typename viennagrid::result_of::accessor<std::deque<VertexHandleType>, EdgeType>::type edge_refinement_vertex_handle_accessor(edge_refinement_vertex_handle_container);
00778 
00779     refine<ElementTypeOrTagT>(mesh_in, segmentation_in,
00780                            mesh_out, segmentation_out,
00781                            point_accessor_in,
00782                            vertex_map,
00783                            edge_refinement_flag_accessor,
00784                            edge_refinement_vertex_handle_accessor);
00785   }
00786 
00796   template<typename ElementTypeOrTagT,
00797            typename WrappedMeshConfigInT,  typename WrappedSegmentationConfigInT,
00798            typename WrappedMeshConfigOutT, typename WrappedSegmentationConfigOutT,
00799            typename EdgeRefinementFlagAccessorT>
00800   void refine(mesh<WrappedMeshConfigInT> const & mesh_in,  segmentation<WrappedSegmentationConfigInT> const & segmentation_in,
00801               mesh<WrappedMeshConfigOutT> & mesh_out,      segmentation<WrappedSegmentationConfigOutT> & segmentation_out,
00802               EdgeRefinementFlagAccessorT const & edge_refinement_flag_accessor)
00803   {
00804     typedef mesh<WrappedMeshConfigOutT> MeshOutT;
00805 
00806     typedef typename viennagrid::result_of::vertex_handle<MeshOutT>::type VertexHandleType;
00807 
00808     std::deque<VertexHandleType> vertex_refinement_vertex_handle;
00809     std::deque<VertexHandleType> edge_refinement_vertex_handle;
00810 
00811     refine<ElementTypeOrTagT>(mesh_in, segmentation_in,
00812                            mesh_out, segmentation_out,
00813                            default_point_accessor(mesh_in),
00814                            edge_refinement_flag_accessor);
00815   }
00816 
00817 
00818 
00829   template<typename ElementTypeOrTagT,
00830            typename WrappedMeshConfigInT,   typename WrappedSegmentationConfigInT,
00831            typename WrappedMeshConfigOutT,  typename WrappedSegmentationConfigOutT,
00832            typename PointAccessorT,
00833            typename CellRefinementFlagAccessorT>
00834   void element_refine(mesh<WrappedMeshConfigInT> const & mesh_in,  segmentation<WrappedSegmentationConfigInT> const & segmentation_in,
00835                       mesh<WrappedMeshConfigOutT> & mesh_out,      segmentation<WrappedSegmentationConfigOutT> & segmentation_out,
00836                       PointAccessorT point_accessor_in,
00837                       CellRefinementFlagAccessorT const cell_refinement_flag_accessor)
00838   {
00839     typedef mesh<WrappedMeshConfigOutT> MeshOutT;
00840 
00841     typedef typename viennagrid::result_of::line<MeshOutT>::type EdgeType;
00842 
00843     std::deque<bool> edge_refinement_flag;
00844 
00845     edge_refinement_flag.resize( static_cast<std::size_t>(viennagrid::id_upper_bound<EdgeType>(mesh_in).get()) );
00846 
00847     cell_refinement_to_edge_refinement<ElementTypeOrTagT>(
00848                                         mesh_in,
00849                                         cell_refinement_flag_accessor,
00850                                         viennagrid::make_accessor<EdgeType>(edge_refinement_flag));
00851 
00852     refine<ElementTypeOrTagT>(mesh_in, segmentation_in,
00853                            mesh_out, segmentation_out,
00854                            point_accessor_in,
00855                            viennagrid::make_accessor<EdgeType>(edge_refinement_flag));
00856   }
00857 
00867   template<typename ElementTypeOrTagT,
00868            typename WrappedMeshConfigInT,   typename WrappedSegmentationConfigInT,
00869            typename WrappedMeshConfigOutT,  typename WrappedSegmentationConfigOutT,
00870            typename CellRefinementFlagAccessorT>
00871   void element_refine(mesh<WrappedMeshConfigInT> const & mesh_in,  segmentation<WrappedSegmentationConfigInT> const & segmentation_in,
00872                       mesh<WrappedMeshConfigOutT> & mesh_out,      segmentation<WrappedSegmentationConfigOutT> & segmentation_out,
00873                       CellRefinementFlagAccessorT const cell_refinement_flag_accessor)
00874   {
00875     element_refine<ElementTypeOrTagT>(mesh_in, segmentation_in,
00876                                    mesh_out, segmentation_out,
00877                                    default_point_accessor(mesh_in),
00878                                    cell_refinement_flag_accessor);
00879   }
00880 
00889   template<typename WrappedMeshConfigInT,   typename WrappedSegmentationConfigInT,
00890            typename WrappedMeshConfigOutT,  typename WrappedSegmentationConfigOutT,
00891            typename CellRefinementFlagAccessorT>
00892   void cell_refine(mesh<WrappedMeshConfigInT> const & mesh_in,  segmentation<WrappedSegmentationConfigInT> const & segmentation_in,
00893                    mesh<WrappedMeshConfigOutT> & mesh_out,      segmentation<WrappedSegmentationConfigOutT> & segmentation_out,
00894                    CellRefinementFlagAccessorT const cell_refinement_flag_accessor)
00895   {
00896     typedef mesh<WrappedMeshConfigInT>                              MeshInType;
00897     typedef typename viennagrid::result_of::cell_tag<MeshInType>::type  CellTag;
00898     element_refine<CellTag>(mesh_in, segmentation_in,
00899                             mesh_out, segmentation_out,
00900                             default_point_accessor(mesh_in),
00901                             cell_refinement_flag_accessor);
00902   }
00903 
00904 
00905 
00906 
00907 
00908 
00921   template<typename ElementTypeOrTagT,
00922            typename WrappedMeshConfigInT,   typename WrappedSegmentationConfigInT,
00923            typename WrappedMeshConfigOutT,  typename WrappedSegmentationConfigOutT,
00924            typename PointAccessorT,
00925            typename VertexCopyMapT,
00926            typename EdgeRefinementFlagAccessorT, typename RefinementVertexAccessorT>
00927   void refine_uniformly(mesh<WrappedMeshConfigInT> const & mesh_in,  segmentation<WrappedSegmentationConfigInT> const & segmentation_in,
00928                         mesh<WrappedMeshConfigOutT> & mesh_out,      segmentation<WrappedSegmentationConfigOutT> & segmentation_out,
00929                         PointAccessorT point_accessor_in,
00930                         VertexCopyMapT & vertex_copy_map_,
00931                         EdgeRefinementFlagAccessorT const & edge_refinement_flag_accessor,
00932                         RefinementVertexAccessorT & edge_to_vertex_handle_accessor)
00933   {
00934     mark_all_edge_refinement( mesh_in, edge_refinement_flag_accessor );
00935     refine<ElementTypeOrTagT>(mesh_in, segmentation_in,
00936                            mesh_out, segmentation_out,
00937                            point_accessor_in,
00938                            vertex_copy_map_,
00939                            edge_refinement_flag_accessor, edge_to_vertex_handle_accessor);
00940   }
00941 
00952   template<typename ElementTypeOrTagT,
00953            typename WrappedMeshConfigInT,   typename WrappedSegmentationConfigInT,
00954            typename WrappedMeshConfigOutT,  typename WrappedSegmentationConfigOutT,
00955            typename PointAccessorT,
00956            typename EdgeRefinementFlagAccessorT>
00957   void refine_uniformly(mesh<WrappedMeshConfigInT> const & mesh_in,  segmentation<WrappedSegmentationConfigInT> const & segmentation_in,
00958                         mesh<WrappedMeshConfigOutT> & mesh_out,      segmentation<WrappedSegmentationConfigOutT> & segmentation_out,
00959                         PointAccessorT point_accessor_in,
00960                         EdgeRefinementFlagAccessorT const & edge_refinement_flag_accessor)
00961   {
00962     mark_all_edge_refinement( mesh_in, edge_refinement_flag_accessor );
00963     refine<ElementTypeOrTagT>(mesh_in, segmentation_in,
00964                            mesh_out, segmentation_out,
00965                            point_accessor_in,
00966                            edge_refinement_flag_accessor);
00967   }
00968 
00978   template<typename ElementTypeOrTagT,
00979            typename WrappedMeshConfigInT,   typename WrappedSegmentationConfigInT,
00980            typename WrappedMeshConfigOutT,  typename WrappedSegmentationConfigOutT,
00981            typename EdgeRefinementFlagAccessorT>
00982   void refine_uniformly(mesh<WrappedMeshConfigInT> const & mesh_in,  segmentation<WrappedSegmentationConfigInT> const & segmentation_in,
00983                         mesh<WrappedMeshConfigOutT> & mesh_out,      segmentation<WrappedSegmentationConfigOutT> & segmentation_out,
00984                         EdgeRefinementFlagAccessorT const & edge_refinement_flag_accessor)
00985   {
00986     refine_uniformly<ElementTypeOrTagT>(mesh_in, segmentation_in, mesh_out, segmentation_out, default_point_accessor(mesh_in), edge_refinement_flag_accessor);
00987   }
00988 
00997   template<typename ElementTypeOrTagT,
00998            typename WrappedMeshConfigInT,   typename WrappedSegmentationConfigInT,
00999            typename WrappedMeshConfigOutT,  typename WrappedSegmentationConfigOutT>
01000   void refine_uniformly(mesh<WrappedMeshConfigInT> const & mesh_in,  segmentation<WrappedSegmentationConfigInT> const & segmentation_in,
01001                         mesh<WrappedMeshConfigOutT> & mesh_out,      segmentation<WrappedSegmentationConfigOutT> & segmentation_out)
01002   {
01003     typedef mesh<WrappedMeshConfigOutT>                           MeshOutType;
01004     typedef typename viennagrid::result_of::line<MeshOutType>::type   EdgeType;
01005     std::deque<bool> edge_refinement_flag;
01006 
01007     refine_uniformly<ElementTypeOrTagT>(mesh_in, segmentation_in, mesh_out, segmentation_out, viennagrid::make_accessor<EdgeType>(edge_refinement_flag));
01008   }
01009 
01017   template<typename WrappedMeshConfigInT,   typename WrappedSegmentationConfigInT,
01018            typename WrappedMeshConfigOutT,  typename WrappedSegmentationConfigOutT>
01019   void cell_refine_uniformly(mesh<WrappedMeshConfigInT> const & mesh_in,  segmentation<WrappedSegmentationConfigInT> const & segmentation_in,
01020                              mesh<WrappedMeshConfigOutT> & mesh_out,      segmentation<WrappedSegmentationConfigOutT> & segmentation_out)
01021   {
01022     typedef mesh<WrappedMeshConfigInT>                            MeshInType;
01023     typedef typename viennagrid::result_of::cell<MeshInType>::type    CellType;
01024     refine_uniformly<CellType>(mesh_in, segmentation_in, mesh_out, segmentation_out);
01025   }
01026 
01037   template<typename SrcMeshT, typename SrcSegmentationT, typename DstMeshT, typename DstSegmentationT, typename PointT, typename NumericConfigT>
01038   void hyperplane_refine(SrcMeshT const & src_mesh, SrcSegmentationT const & src_segmentation,
01039                          DstMeshT & dst_mesh, DstSegmentationT & dst_segmentation,
01040                          PointT const & hyperplane_point, PointT const & hyperplane_normal,
01041                          NumericConfigT numeric_config)
01042   {
01043     typedef typename viennagrid::result_of::cell_tag<SrcMeshT>::type CellTag;
01044     typedef typename viennagrid::result_of::line<SrcMeshT>::type LineType;
01045     typedef typename viennagrid::result_of::vertex_handle<DstMeshT>::type DstMeshVertexHandleType;
01046 
01047     viennagrid::vertex_copy_map<SrcMeshT, DstMeshT> vertex_map( dst_mesh );
01048 
01049     std::deque<bool> line_refinement_tag_container;
01050     typename viennagrid::result_of::accessor<std::deque<bool>, LineType>::type line_refinement_tag_accessor(line_refinement_tag_container);
01051 
01052     std::deque<DstMeshVertexHandleType> line_refinement_vertex_handle_container;
01053     typename viennagrid::result_of::accessor<std::deque<DstMeshVertexHandleType>, LineType>::type line_refinement_vertex_handle_accessor(line_refinement_vertex_handle_container);
01054 
01055     mark_edges_for_hyperplane_refine(src_mesh, dst_mesh, hyperplane_point, hyperplane_normal, line_refinement_tag_accessor, line_refinement_vertex_handle_accessor, numeric_config);
01056 
01057 
01058     viennagrid::simple_refine<CellTag>(src_mesh, src_segmentation,
01059                                        dst_mesh, dst_segmentation,
01060                                        vertex_map,
01061                                        line_refinement_tag_accessor,
01062                                        line_refinement_vertex_handle_accessor);
01063   }
01064 
01065 
01066 }
01067 
01068 #endif