<commit_before>/* =======================================================================
   Copyright (c) 2011, Institute for Microelectronics,
                       Institute for Analysis and Scientific Computing,
                       TU Wien.

                            -----------------
                     ViennaGrid - The Vienna Grid Library
                            -----------------

   Authors:      <NAME>                           <EMAIL>
                 <NAME>                    <EMAIL>
               
   (A list of additional contributors can be found in the PDF manual)

   License:      MIT (X11), see file LICENSE in the base directory
======================================================================= */

#ifdef _MSC_VER      //Visual Studio complains about potentially dangerous things, which are perfectly legal in our context
  #pragma warning( disable : 4355 )     //use of this in member initializer list
  #pragma warning( disable : 4503 )     //truncated name decoration
#endif


#include <iostream>
#include <fstream>
#include <vector>

#include "viennagrid/config/domain_config.hpp"
#include "viennagrid/config/default_configs.hpp"
#include "viennagrid/algorithm/volume.hpp"
#include "viennagrid/algorithm/voronoi.hpp"
#include "viennagrid/io/netgen_reader.hpp"
#include "viennagrid/domain/coboundary_iteration.hpp"




int main()
{
  typedef viennagrid::point_t<double, viennagrid::cartesian_cs<3> >    PointType;  //use this for a 3d examples
  typedef viennagrid::tetrahedron_tag                                  CellTag;
  typedef viennagrid::config::tetrahedral_3d                           ConfigType;  //use this for a 3d example
  //typedef viennagrid::config::triangular_2d                            ConfigType;  //use this for a 2d example (also change filename for Netgen reader below!)
  typedef viennagrid::domain_t< ConfigType >                           DomainType;
  typedef viennagrid::result_of::segmentation<DomainType>::type        Segmentation;

    
  //typedef viennagrid::result_of::domain<ConfigType>::type         DomainType;
  //typedef ConfigType::cell_tag                           CellTag;

  //
  // Define the types of the elements in the domain (derived from ConfigType):
  //
  typedef viennagrid::result_of::element<DomainType, viennagrid::vertex_tag>::type                          VertexType;
  typedef viennagrid::result_of::handle<DomainType, viennagrid::vertex_tag>::type                          VertexHandleType;
  typedef viennagrid::result_of::element<DomainType, viennagrid::line_tag>::type                          EdgeType;
  typedef viennagrid::result_of::element<DomainType, CellTag::facet_tag>::type  FacetType;
  typedef viennagrid::result_of::element<DomainType, CellTag>::type    CellType;

  std::cout << "--------------------------------------------------" << std::endl;
  std::cout << "-- ViennaGrid tutorial: Iteration over elements --" << std::endl;
  std::cout << "-------------------------------------------------- " << std::endl;
  std::cout << std::endl;
  
  DomainType    domain;
  Segmentation  segments(domain);
  
  
  //
  // Read domain from Netgen file
  //
  try
  {
    viennagrid::io::netgen_reader reader;
    reader(domain, segments, "../examples/data/cube6.mesh");    //use this for a 3d example
    //reader(domain, segments, "../examples/data/square8.mesh"); //use this for a 2d example (also change ConfigType defined above!)
  }
  catch (std::exception & e)
  {
    std::cout << "Error reading Netgen mesh file: " << std::endl;
    std::cout << e.what() << std::endl;
    return EXIT_FAILURE;
  }
  
  

  
  //
  ////////////////     Section 1: Iteration over n-cells in the domain/segment      ////////////////////////
  //
  
  //
  // Get the types for a global vertex range and the corresponding iterator. 
  // This allows to traverse all vertices in the domain.
  // The first template argument to ncell_range<> denotes the enclosing body (here: the domain),
  // and the second argument denotes the topological dimension of the elements over which to iterate (0...vertices, 1...lines, etc.)
  //
  typedef viennagrid::result_of::element_range<DomainType, viennagrid::vertex_tag>::type     VertexRange;
  typedef viennagrid::result_of::iterator<VertexRange>::type          VertexIterator;
  
  //
  // Define global edge, facet and cell ranges and their iterator types in the same way:
  //
  typedef viennagrid::result_of::element_range<DomainType, viennagrid::line_tag>::type     EdgeRange;
  typedef viennagrid::result_of::iterator<EdgeRange>::type            EdgeIterator;

  typedef viennagrid::result_of::element_range<DomainType, CellTag::facet_tag>::type     FacetRange;
  typedef viennagrid::result_of::iterator<FacetRange>::type                        FacetIterator;
  
  typedef viennagrid::result_of::element_range<DomainType, CellTag>::type       CellRange;
  typedef viennagrid::result_of::iterator<CellRange>::type                         CellIterator;
  
  
  //
  // Iterate over all vertices of the domain:
  // Note: when assigned to a range, the topological level usually required as template argument for ncells<>()
  //       can be deduced automatically and may thus be omitted
  //
  VertexRange vertices = viennagrid::elements<viennagrid::vertex_tag>(domain);   
  
  for (VertexIterator vit = vertices.begin();  //STL-like iteration
                      vit != vertices.end();
                    ++vit)
  {
    std::cout << *vit << std::endl;
  }
  
  
  //
  // Iterate over all edges of the domain.
  // Can be done like above. To show alternatives as well, this time the range is not set up explicitly in a named variable:
  std::size_t num_edges = 0;
  for (EdgeIterator eit = viennagrid::elements<viennagrid::line_tag>(domain).begin();   //Note that the template parameter '1' is mandatory here to select edges
                    eit != viennagrid::elements<viennagrid::line_tag>(domain).end();
                  ++eit)
  {
    //do something with *eit here. 
    ++num_edges;  
  }
  std::cout << "Number of edges traversed: " << num_edges << std::endl;
  std::cout << "Number of edges in domain: " << viennagrid::elements<viennagrid::line_tag>(domain).size() << std::endl;
  
  //
  // Even though not recommended, it is also possible to iterate through the elements using operator[]:
  // However, this does not work for all domain storage configurations. Cells and vertices will always work.
  //
  std::size_t num_cells = 0;
  CellRange cells = viennagrid::elements<CellTag>(domain);
  for (std::size_t i=0; i<cells.size(); ++i)
  {
    ++num_cells;
  }
  std::cout << "Number of cells traversed: " << num_cells << std::endl;
  std::cout << "Number of cells in domain: " << viennagrid::elements<CellTag>(domain).size() << std::endl;
  
  //
  // In the same manner, iteration over all facets can be carried out using one of the three methods presented above
  //
  
  
  
  
  //
  ////////////////     Section 2: Iteration over boundary cells of smaller topological level      ////////////////////////
  //
  
  
  //
  // Define some on-element ranges and iterators in the same way.
  // Mind the first template argument of ncell_range<>, which is the enclosing element.
  //
  typedef viennagrid::result_of::element_range<FacetType, viennagrid::vertex_tag>::type                VertexOnFacetRange;
  typedef viennagrid::result_of::iterator<VertexOnFacetRange>::type             VertexOnFacetIterator;
  
  typedef viennagrid::result_of::element_range<FacetType, viennagrid::line_tag>::type                EdgeOnFacetRange;
  typedef viennagrid::result_of::iterator<EdgeOnFacetRange>::type               EdgeOnFacetIterator;
  
  typedef viennagrid::result_of::element_range<CellType, CellTag::facet_tag>::type    FacetOnCellRange;
//   typedef viennagrid::result_of::handle_iterator<FacetOnCellRange>::type               FacetOnCellHandleIterator;
  typedef viennagrid::result_of::iterator<FacetOnCellRange>::type               FacetOnCellIterator;

  for (CellIterator cit = cells.begin(); cit != cells.end(); ++cit) //iterate over all cells
  {
    std::cout << *cit << std::endl;
    
    //
    // The facets of the cell are obtained by passing the cell as parameter to the ncell() function
    //
    FacetOnCellRange facets_on_cells = viennagrid::elements<CellTag::facet_tag>(*cit);
    for (FacetOnCellIterator focit = facets_on_cells.begin();
                             focit != facets_on_cells.end();
                           ++focit)
    {
      FacetType & facet = *focit;
        
      // Iterate over all vertices of the facet:
      std::cout << "Vertices in global orientation: " << std::endl;
      for (VertexOnFacetIterator vofit = viennagrid::vertices(facet).begin();
                                 vofit != viennagrid::vertices(facet).end();
                               ++vofit)
      {
        std::cout << *vofit << std::endl;
      }

      // Same again, but using the orientation imposed by the cell
      std::cout << "Vertices in local orientation: " << std::endl;
      for (std::size_t i=0; i<viennagrid::vertices(facet).size(); ++i)
        std::cout << viennagrid::local_vertex(domain, *cit, focit.handle(), i) << std::endl;
    }
    
    std::cout << std::endl << "---------------" << std::endl << std::endl;
  }

  
  
  //
  ////////////////     Section 3: Iteration over elements of larger topological level      ////////////////////////
  //

  //
  // Ranges and iterators are again obtained from the ncell_range metafunction.
  // As before, the first argument specifies the root of the iteration,
  // the second argument denotes the topological dimension of the elements over which to iterate.
  //
  typedef viennagrid::result_of::coboundary_range<DomainType, viennagrid::vertex_tag, viennagrid::line_tag>::type    EdgeOnVertexRange;
  typedef viennagrid::result_of::iterator<EdgeOnVertexRange>::type                                                   EdgeOnVertexIterator;
  
  typedef viennagrid::result_of::coboundary_range<DomainType, viennagrid::line_tag, CellTag>::type   CellOnEdgeRange;
  typedef viennagrid::result_of::iterator<CellOnEdgeRange>::type                                     CellOnEdgeIterator;
  
  
  // Iteration over all edges connected to the first vertex in the domain:
  VertexHandleType vh0 = viennagrid::elements<viennagrid::vertex_tag>(domain).handle_at(0);
  std::size_t num_v0edges = 0;
  
  // To set up the range, two arguments need to be passed to the ncells() function.
  // The second argument denotes the enclosing complex over which to iterate and is either a segment or the full domain.
  EdgeOnVertexRange edges_on_v0 = viennagrid::coboundary_elements<viennagrid::vertex_tag, viennagrid::line_tag>(domain, vh0);
  for (EdgeOnVertexIterator eovit = edges_on_v0.begin();
                            eovit != edges_on_v0.end();
                          ++eovit)
  {
    ++num_v0edges;
  }
  std::cout << "Edges connected to vh0 visited: " << num_v0edges << std::endl;
  std::cout << "Edges connected to vh0 available: " << edges_on_v0.size() << std::endl;
  
  //
  // In the same manner, other co-boundary operations are carried out, e.g. cell-on-edge, facet-on-vertex.
  //
  
  
  std::cout << "-----------------------------------------------" << std::endl;<commit_msg>clean-up and comments<commit_after>/* =======================================================================
   Copyright (c) 2011, Institute for Microelectronics,
                       Institute for Analysis and Scientific Computing,
                       TU Wien.

                            -----------------
                     ViennaGrid - The Vienna Grid Library
                            -----------------

   Authors:      <NAME>                           <EMAIL>
                 <NAME>                    <EMAIL>
               
   (A list of additional contributors can be found in the PDF manual)

   License:      MIT (X11), see file LICENSE in the base directory
======================================================================= */

#ifdef _MSC_VER      //Visual Studio complains about potentially dangerous things, which are perfectly legal in our context
  #pragma warning( disable : 4355 )     //use of this in member initializer list
  #pragma warning( disable : 4503 )     //truncated name decoration
#endif


#include <iostream>
#include <fstream>
#include <vector>

#include "viennagrid/config/domain_config.hpp"
#include "viennagrid/config/default_configs.hpp"
#include "viennagrid/algorithm/volume.hpp"
#include "viennagrid/algorithm/voronoi.hpp"
#include "viennagrid/io/netgen_reader.hpp"
#include "viennagrid/domain/coboundary_iteration.hpp"




int main()
{
  //
  // Define the domain and segmentation types
  //
  typedef viennagrid::tetrahedral_3d_domain                             DomainType;
//   typedef viennagrid::triangular_2d_domain                              DomainType; // use this for a 2d domain
  typedef viennagrid::result_of::segmentation<DomainType>::type         Segmentation;
  typedef viennagrid::result_of::cell_tag<DomainType>::type             CellTag;
  
  //
  // Define the types of the elements in the domain (derived from DomainType):
  //
  typedef viennagrid::result_of::point<DomainType>::type                PointType;
  typedef viennagrid::result_of::vertex<DomainType>::type               VertexType;
  typedef viennagrid::result_of::vertex_handle<DomainType>::type        VertexHandleType;
  typedef viennagrid::result_of::edge<DomainType>::type                 EdgeType;
  typedef viennagrid::result_of::facet<DomainType>::type                FacetType;
  typedef viennagrid::result_of::cell<DomainType>::type                 CellType;

  std::cout << "--------------------------------------------------" << std::endl;
  std::cout << "-- ViennaGrid tutorial: Iteration over elements --" << std::endl;
  std::cout << "-------------------------------------------------- " << std::endl;
  std::cout << std::endl;
  
  DomainType    domain;
  Segmentation  segmentation(domain);
  
  
  //
  // Read domain from Netgen file
  //
  try
  {
    viennagrid::io::netgen_reader reader;
    reader(domain, segmentation, "../examples/data/cube6.mesh");    //use this for a 3d example
    //reader(domain, segmentation, "../examples/data/square8.mesh"); //use this for a 2d example (also change DomainType defined above!)
  }
  catch (std::exception & e)
  {
    std::cout << "Error reading Netgen mesh file: " << std::endl;
    std::cout << e.what() << std::endl;
    return EXIT_FAILURE;
  }
  
  

  
  //
  ////////////////     Section 1: Iteration over n-cells in the domain/segment      ////////////////////////
  //
  
  //
  // Get the types for a global vertex range and the corresponding iterator. 
  // This allows to traverse all vertices in the domain.
  // The first template argument to *_range<> denotes the enclosing body (here: the domain),
  //
  typedef viennagrid::result_of::vertex_range<DomainType>::type     VertexRange;
  typedef viennagrid::result_of::iterator<VertexRange>::type        VertexIterator;
  
  //
  // Define global edge, facet and cell ranges and their iterator types in the same way:
  //
  typedef viennagrid::result_of::edge_range<DomainType>::type       EdgeRange;
  typedef viennagrid::result_of::iterator<EdgeRange>::type          EdgeIterator;

  typedef viennagrid::result_of::facet_range<DomainType>::type      FacetRange;
  typedef viennagrid::result_of::iterator<FacetRange>::type         FacetIterator;
  
  typedef viennagrid::result_of::cell_range<DomainType>::type       CellRange;
  typedef viennagrid::result_of::iterator<CellRange>::type          CellIterator;
  
  
  //
  // Iterate over all vertices of the domain:
  // Note: when assigned to a range, no template argument is required for elements<>()
  //
  VertexRange vertices = viennagrid::elements(domain);   
  
  for (VertexIterator vit = vertices.begin();  //STL-like iteration
                      vit != vertices.end();
                    ++vit)
  {
    std::cout << *vit << std::endl;
  }
  
  
  //
  // Iterate over all edges of the domain.
  // Can be done like above. To show alternatives as well, this time the range is not set up explicitly in a named variable:
  // Note: the result of elements<>() is not assigned to a range, so an element tag is required!
  std::size_t num_edges = 0;
  for (EdgeIterator eit = viennagrid::elements<viennagrid::line_tag>(domain).begin();   //Note that the template parameter '1' is mandatory here to select edges
                    eit != viennagrid::elements<viennagrid::line_tag>(domain).end();
                  ++eit)
  {
    //do something with *eit here. 
    ++num_edges;  
  }
  std::cout << "Number of edges traversed: " << num_edges << std::endl;
  std::cout << "Number of edges in domain: " << viennagrid::elements<viennagrid::line_tag>(domain).size() << std::endl;
  
  //
  // Even though not recommended, it is also possible to iterate through the elements using operator[]:
  // However, this does not work for all domain storage configurations. Elements in a domain will always work, segments and view might not work
  //
  std::size_t num_cells = 0;
  CellRange cells = viennagrid::elements(domain);
  for (std::size_t i=0; i<cells.size(); ++i)
  {
    // do something with cells[i]
    ++num_cells;
  }
  std::cout << "Number of cells traversed: " << num_cells << std::endl;
  std::cout << "Number of cells in domain: " << viennagrid::elements<CellTag>(domain).size() << std::endl;
  
  //
  // In the same manner, iteration over all facets can be carried out using one of the three methods presented above
  //
  
  
  
  
  //
  ////////////////     Section 2: Iteration over boundary cells of smaller topological level      ////////////////////////
  //
  
  
  //
  // Define some on-element ranges and iterators in the same way.
  //
  typedef viennagrid::result_of::vertex_range<FacetType>::type        VertexOnFacetRange;
  typedef viennagrid::result_of::iterator<VertexOnFacetRange>::type   VertexOnFacetIterator;
  
  typedef viennagrid::result_of::edge_range<FacetType>::type          EdgeOnFacetRange;
  typedef viennagrid::result_of::iterator<EdgeOnFacetRange>::type     EdgeOnFacetIterator;
  
  typedef viennagrid::result_of::facet_range<CellType>::type          FacetOnCellRange;
  typedef viennagrid::result_of::iterator<FacetOnCellRange>::type     FacetOnCellIterator;

  for (CellIterator cit = cells.begin(); cit != cells.end(); ++cit) //iterate over all cells
  {
    std::cout << *cit << std::endl;
    
    //
    // The facets of the cell are obtained by passing the cell as parameter to the elements<>() function
    // Note: again, assignment to range doesn't require to pass the element tag to elements<>()
    //
    FacetOnCellRange facets_on_cells = viennagrid::elements(*cit);
    for (FacetOnCellIterator focit = facets_on_cells.begin();
                             focit != facets_on_cells.end();
                           ++focit)
    {
      FacetType & facet = *focit;
        
      // Iterate over all vertices of the facet:
      std::cout << "Vertices in global orientation: " << std::endl;
      for (VertexOnFacetIterator vofit = viennagrid::vertices(facet).begin();
                                 vofit != viennagrid::vertices(facet).end();
                               ++vofit)
      {
        std::cout << *vofit << std::endl;
      }

      // Same again, but using the orientation imposed by the cell
      std::cout << "Vertices in local orientation: " << std::endl;
      for (std::size_t i=0; i<viennagrid::vertices(facet).size(); ++i)
        std::cout << viennagrid::local_vertex(domain, *cit, focit.handle(), i) << std::endl;
    }
    
    std::cout << std::endl << "---------------" << std::endl << std::endl;
  }

  
  
  //
  ////////////////     Section 3: Iteration over elements of larger topological level      ////////////////////////
  //

  //
  // Ranges and iterators are again obtained from the coboundary_range metafunction.
  // The first argument specifies the root of the iteration,
  // the second argument denotes the element tag of the element from which the coboundary elements are requested
  // the third argument denotes the element tag of the elements over which to iterate.
  //
  typedef viennagrid::result_of::coboundary_range<DomainType, viennagrid::vertex_tag, viennagrid::line_tag>::type     EdgeOnVertexRange;
  typedef viennagrid::result_of::iterator<EdgeOnVertexRange>::type                                                    EdgeOnVertexIterator;
  
  typedef viennagrid::result_of::coboundary_range<DomainType, viennagrid::line_tag, CellTag>::type                    CellOnEdgeRange;
  typedef viennagrid::result_of::iterator<CellOnEdgeRange>::type                                                      CellOnEdgeIterator;
  
  
  // Iteration over all edges connected to the first vertex in the domain:
  VertexHandleType vh0 = viennagrid::elements<viennagrid::vertex_tag>(domain).handle_at(0);
  std::size_t num_v0edges = 0;
  
  // To set up the range, two arguments need to be passed to the ncells() function.
  // The second argument denotes the enclosing complex over which to iterate and is either a segment or the full domain.
  EdgeOnVertexRange edges_on_v0 = viennagrid::coboundary_elements<viennagrid::vertex_tag, viennagrid::line_tag>(domain, vh0);
  for (EdgeOnVertexIterator eovit = edges_on_v0.begin();
                            eovit != edges_on_v0.end();
                          ++eovit)
  {
    ++num_v0edges;
  }
  std::cout << "Edges connected to vh0 visited: " << num_v0edges << std::endl;
  std::cout << "Edges connected to vh0 available: " << edges_on_v0.size() << std::endl;
  
  //
  // In the same manner, other co-boundary operations are carried out, e.g. cell-on-edge, facet-on-vertex.
  //
  
  
  std::cout << "-----------------------------------------------" << std::endl;
{'fraction_non_alphanumeric': 0.14724205356736847, 'fraction_numerical': 0.004047110181437861, 'mean_word_length': 2.5430965039471563, 'pattern_counts': {'":': 0, '<': 287, '<?xml version=': 0, '>': 95, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 10, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2466723', 'n_tokens_mistral': 6517, 'n_tokens_neox': 6132, 'n_words': 1697}