<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
======================================================================= */

#ifndef VIENNAGRID_IO_TDR_READER_GUARD
#define VIENNAGRID_IO_TDR_READER_GUARD


// NOT INCLUDED IN RELEASE !!


// system includes
#include <iostream>
#include <string>
#include <cstdlib>
#include <vector>
#include <map>

#include "viennagrid/forwards.h"
#include "viennagrid/domain.hpp"

// HDF includes
#include "H5Cpp.h"

//
// [JW][TIP] for debugging purposes use the h5dump utility to dump a hdf5 file
//

//#define VIENNAGRID_DEBUG_IO

namespace viennagrid
{
  namespace io
  {

    struct tdr_reader
    {
      struct dataset_t 
      {
        std::string          name, quantity, unit;
        std::size_t          nvalues;
        double               conversion_factor;
        std::vector<double>  values;
      };  
      
      struct region_t 
      {
        std::size_t                              regnr,nelements,npointidx;
        std::string                              name,material;
        std::vector<std::vector<std::size_t> >   elements;
        std::map<std::string,dataset_t>          dataset;
      };    
    
      typedef std::map<std::string, dataset_t>     dataset_cont_type;
      typedef std::map<std::string,region_t>       region_cont_type;
    
      tdr_reader(std::string const& filename) 
      {
          using namespace H5;

          segment_counter = 0;
          contact_counter = 0;
          
          H5File file( filename, H5F_ACC_RDONLY );
          
          // read tdr file and store in the the tdr_readers 
          // internal datastructure
          //
          read_collection(file.openGroup("collection"));
          
      }

      // transfer data from tdr_reader datastructure
      // to a viennagrid::domain
      //
      template <typename DomainT>
      int operator()(DomainT & domain) 
      {
      #ifdef VIENNAGRID_DEBUG_IO
          std::cout << "transferring to viennagrid domain .. " << std::endl;
      #endif
          typedef typename DomainT::config_type                                            domain_config_type;
          typedef typename domain_config_type::cell_tag                                    cell_tag;      
          typedef typename viennagrid::result_of::ncell<domain_config_type, 0>::type  vertex_type; 
          typedef typename viennagrid::result_of::ncell<domain_config_type, cell_tag::topology_level>::type     cell_type;            

          static const std::size_t CELLSIZE = viennagrid::topology::subcell_desc<cell_tag, 0>::num_elements;         
          static const std::size_t DIMG     = domain_config_type::dimension_tag::value;      
      
          // transfer geometry
          //    note: point vectors are linearly stored, x1 y1 z1 x2 y2 z2 ...
          //   
          vertex_type  vertex;
          std::size_t  index;
      #ifdef VIENNAGRID_DEBUG_IO      
          std::cout << "  processing geometry .."<< std::endl;
      #endif      
          for (std::size_t i=0; i<geometry_space.size(); i++)
          {
            // 3 is the offset due to three-dimensional geometry space
            index = i * DIMG; 
            
            for(std::size_t d = 0; d < DIMG; d++)
               vertex.getPoint()[d] = geometry_space[index+d];

//            vertex.getPoint()[0] = geometry_space[index];
//            vertex.getPoint()[1] = geometry_space[index+1];
//            vertex.getPoint()[2] = geometry_space[index+2];
            index_map[i] = domain.add(vertex)->id();
          }
          
          // transfer topology
          // 
      #ifdef VIENNAGRID_DEBUG_IO      
          std::cout << "  processing topology .. " << std::endl;
          std::cout << "  segments: " << segment_counter << std::endl;
          std::cout << "  contacts: " << contact_counter << std::endl;
      #endif
          domain.create_segments(segment_counter); 
          std::size_t seg_cnt = 0;
          for (std::map<std::string,region_t>::const_iterator rit = region.begin();  
              rit != region.end(); rit++)
          {   
      #ifdef VIENNAGRID_DEBUG_IO
            std::cout << "    region-name:     " << rit->second.name << 
                        "  material: " << rit->second.material << std::endl;    
      #endif      
////            // special treatment for a contact region
////            //
////            if(rit->second.material == "Contact")
////            {

////            }
            // the general case of a segment/material region
            //
            if(rit->second.material != "Contact")
            {
              vertex_type *vertices[CELLSIZE];
              
              std::vector<std::vector<std::size_t> > const& elements = rit->second.elements;
              for (std::vector<std::vector<std::size_t> >::const_iterator cit = elements.begin(); 
                  cit != elements.end(); cit++)
              {
                  std::vector<std::size_t> const& tempcell = *cit;
                
                  for(std::size_t d = 0; d < CELLSIZE; d++)
                     vertices[d] = &(domain.vertex(tempcell[d]));

//                  vertices[0] = &(domain.vertex(tempcell[0]));
//                  vertices[1] = &(domain.vertex(tempcell[1])); 
//                  vertices[2] = &(domain.vertex(tempcell[2])); 
//                  vertices[3] = &(domain.vertex(tempcell[3]));                                               
                
                  cell_type cell;
                  cell.setVertices(vertices);             
                  domain.segment(seg_cnt).add(cell);
              }
              
              seg_cnt++;
            }
      
          }   
      //        case 5:  for (int i=0; i<4; i++)
      //        region.elements.back().push_back(el[elct++]);
      
          return 0;
      }
      
      
      region_cont_type& acc_region()
      {
         return region;
      }
      <commit_msg>TDR reader: updated new segment handling<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
======================================================================= */

#ifndef VIENNAGRID_IO_TDR_READER_GUARD
#define VIENNAGRID_IO_TDR_READER_GUARD


// NOT INCLUDED IN RELEASE !!


// system includes
#include <iostream>
#include <string>
#include <cstdlib>
#include <vector>
#include <map>

#include "viennagrid/forwards.h"
#include "viennagrid/domain.hpp"

// HDF includes
#include "H5Cpp.h"

//
// [JW][TIP] for debugging purposes use the h5dump utility to dump a hdf5 file
//

//#define VIENNAGRID_DEBUG_IO

namespace viennagrid
{
  namespace io
  {

    struct tdr_reader
    {
      struct dataset_t 
      {
        std::string          name, quantity, unit;
        std::size_t          nvalues;
        double               conversion_factor;
        std::vector<double>  values;
      };  
      
      struct region_t 
      {
        std::size_t                              regnr,nelements,npointidx;
        std::string                              name,material;
        std::vector<std::vector<std::size_t> >   elements;
        std::map<std::string,dataset_t>          dataset;
      };    
    
      typedef std::map<std::string, dataset_t>     dataset_cont_type;
      typedef std::map<std::string,region_t>       region_cont_type;
    
      tdr_reader(std::string const& filename) 
      {
          using namespace H5;

          segment_counter = 0;
          contact_counter = 0;
          
          H5File file( filename, H5F_ACC_RDONLY );
          
          // read tdr file and store in the the tdr_readers 
          // internal datastructure
          //
          read_collection(file.openGroup("collection"));
          
      }

      // transfer data from tdr_reader datastructure
      // to a viennagrid::domain
      //
      template <typename DomainT>
      int operator()(DomainT & domain) 
      {
      #ifdef VIENNAGRID_DEBUG_IO
          std::cout << "transferring to viennagrid domain .. " << std::endl;
      #endif
          typedef typename DomainT::config_type                                            domain_config_type;
          typedef typename domain_config_type::cell_tag                                    cell_tag;      
          typedef typename viennagrid::result_of::ncell<domain_config_type, 0>::type  vertex_type; 
          typedef typename viennagrid::result_of::ncell<domain_config_type, cell_tag::topology_level>::type     cell_type;            

          static const std::size_t CELLSIZE = viennagrid::topology::subcell_desc<cell_tag, 0>::num_elements;         
          static const std::size_t DIMG     = domain_config_type::dimension_tag::value;      
      
          // transfer geometry
          //    note: point vectors are linearly stored, x1 y1 z1 x2 y2 z2 ...
          //   
          vertex_type  vertex;
          std::size_t  index;
      #ifdef VIENNAGRID_DEBUG_IO      
          std::cout << "  processing geometry .."<< std::endl;
      #endif      
          for (std::size_t i=0; i<geometry_space.size(); i++)
          {
            // 3 is the offset due to three-dimensional geometry space
            index = i * DIMG; 
            
            for(std::size_t d = 0; d < DIMG; d++)
               vertex.getPoint()[d] = geometry_space[index+d];

//            vertex.getPoint()[0] = geometry_space[index];
//            vertex.getPoint()[1] = geometry_space[index+1];
//            vertex.getPoint()[2] = geometry_space[index+2];
            index_map[i] = domain.add(vertex)->id();
          }
          
          // transfer topology
          // 
      #ifdef VIENNAGRID_DEBUG_IO      
          std::cout << "  processing topology .. " << std::endl;
          std::cout << "  segments: " << segment_counter << std::endl;
          std::cout << "  contacts: " << contact_counter << std::endl;
      #endif
          domain.segments().resize(segment_counter);
          std::size_t seg_cnt = 0;
          for (std::map<std::string,region_t>::const_iterator rit = region.begin();  
              rit != region.end(); rit++)
          {   
      #ifdef VIENNAGRID_DEBUG_IO
            std::cout << "    region-name:     " << rit->second.name << 
                        "  material: " << rit->second.material << std::endl;    
      #endif      
////            // special treatment for a contact region
////            //
////            if(rit->second.material == "Contact")
////            {

////            }
            // the general case of a segment/material region
            //
            if(rit->second.material != "Contact")
            {
              vertex_type *vertices[CELLSIZE];
              
              std::vector<std::vector<std::size_t> > const& elements = rit->second.elements;
              for (std::vector<std::vector<std::size_t> >::const_iterator cit = elements.begin(); 
                  cit != elements.end(); cit++)
              {
                  std::vector<std::size_t> const& tempcell = *cit;
                
                  for(std::size_t d = 0; d < CELLSIZE; d++)
                     vertices[d] = &(domain.vertex(tempcell[d]));

//                  vertices[0] = &(domain.vertex(tempcell[0]));
//                  vertices[1] = &(domain.vertex(tempcell[1])); 
//                  vertices[2] = &(domain.vertex(tempcell[2])); 
//                  vertices[3] = &(domain.vertex(tempcell[3]));                                               
                
                  cell_type cell;
                  cell.setVertices(vertices);             
                  domain.segments()[seg_cnt].add(cell);
              }
              
              seg_cnt++;
            }
      
          }   
      //        case 5:  for (int i=0; i<4; i++)
      //        region.elements.back().push_back(el[elct++]);
      
          return 0;
      }
      
      
      region_cont_type& acc_region()
      {
         return region;
      }
      
{'fraction_non_alphanumeric': 0.13671193384416963, 'fraction_numerical': 0.006676276458538806, 'mean_word_length': 1.4947009841029524, 'pattern_counts': {'":': 0, '<': 129, '<?xml version=': 0, '>': 65, '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': '3369796', 'n_tokens_mistral': 3722, 'n_tokens_neox': 3548, 'n_words': 741}