LCOV - code coverage report
Current view: top level - src/io - ReadRTT.hpp (source / functions) Hit Total Coverage
Test: coverage_sk.info Lines: 1 18 5.6 %
Date: 2020-12-16 07:07:30 Functions: 2 15 13.3 %
Branches: 2 40 5.0 %

           Branch data     Line data    Source code
       1                 :            : /**
       2                 :            :  * MOAB, a Mesh-Oriented datABase, is a software component for creating,
       3                 :            :  * storing and accessing finite element mesh data.
       4                 :            :  *
       5                 :            :  * Copyright 2004 Sandia Corporation.  Under the terms of Contract
       6                 :            :  * DE-AC04-94AL85000 with Sandia Coroporation, the U.S. Government
       7                 :            :  * retains certain rights in this software.
       8                 :            :  *
       9                 :            :  * This library is free software; you can redistribute it and/or
      10                 :            :  * modify it under the terms of the GNU Lesser General Public
      11                 :            :  * License as published by the Free Software Foundation; either
      12                 :            :  * version 2.1 of the License, or (at your option) any later version.
      13                 :            :  *
      14                 :            :  */
      15                 :            : 
      16                 :            : //-------------------------------------------------------------------------
      17                 :            : // Filename      : ReadRTT.hpp
      18                 :            : //
      19                 :            : // Purpose       : RTT file reader
      20                 :            : //
      21                 :            : // Creator       : Andrew Davis
      22                 :            : //
      23                 :            : // Date          : 02/2014
      24                 :            : //
      25                 :            : //-------------------------------------------------------------------------
      26                 :            : 
      27                 :            : /**
      28                 :            :  * The RTT file format is used by the Attila deterministic radiation
      29                 :            :  * transport code. The specific mesh format can be found in Chapter 9
      30                 :            :  * of the Attila manual. The format is defined by xml like, block/end block
      31                 :            :  * type syntax. The implementation at the time of writing supports a subset
      32                 :            :  * of the whole format, and even Attila does not support the entireity of
      33                 :            :  * its own mesh format.
      34                 :            :  *
      35                 :            :  * The mesh contains several features, that as a whole allow the conversion
      36                 :            :  * from the RTT format, to a DAGMC geometry and a Tet Mesh for tallying.
      37                 :            :  *
      38                 :            :  * Sides - Defines the 6 boundary condtions for top, bottom, front, back
      39                 :            :  *         left and right, as well as internal and external.
      40                 :            :  *---------------------------------------------------------------------
      41                 :            :  * Faces - Logically equivalent to surfaces in DAGMC, containers for triangles, includes
      42                 :            :  *         the definition of the sense of the faces with respect to the Cells (volumes)
      43                 :            :  *         which bound it.
      44                 :            :  *
      45                 :            :  *         The face syntax looks like
      46                 :            :  *
      47                 :            :  *         1 (+)Pyrex@14
      48                 :            :  *
      49                 :            :  *         This means Face (surface) 1 is used to define the insde of the Pyrex cell only
      50                 :            :  *
      51                 :            :  *         75 (+)Pyrex/(-)Fuel30@25
      52                 :            :  *
      53                 :            :  *         This means Face (surface) 75 is used by both Cell Pyrex and Cell Fuel 30,
      54                 :            :  *         the + and - signs refer to the sense, i.e. the inside sense defines the Pyrex and
      55                 :            :  *         the outside sense defines the Fuel.
      56                 :            :  *---------------------------------------------------------------------
      57                 :            :  * Cells - Entityset like coillections of tetrahedra which define contiguous material properties
      58                 :            :  *
      59                 :            :  *        cell_flags
      60                 :            :  *          1 REGIONS
      61                 :            :  *            1 Pyrex
      62                 :            :  *        end_cell_flags
      63                 :            :  *
      64                 :            :  * Defines that there is 1 region called Pyrex
      65                 :            :  *---------------------------------------------------------------------
      66                 :            :  * Nodes - Defines the vertices for facets and tets, the syntax of which is shown below
      67                 :            :  *
      68                 :            :  *   100  1.8900000000E+03  0.0000000000E+00  5.0000000000E+03 100
      69                 :            :  *
      70                 :            :  * Defines that this is node 100, and has the coordinates 1890.0, 0.0 5000.0 cm
      71                 :            :  **---------------------------------------------------------------------
      72                 :            :  * Side (element) - Triangles
      73                 :            :  *
      74                 :            :  *  1 3 874 132 154 3 6365
      75                 :            :  *
      76                 :            :  * Defines that this is side element 1, it has 3 nodes, 874, 132 and 154,
      77                 :            :  * side ID 3 and surface number 6365
      78                 :            :  *---------------------------------------------------------------------
      79                 :            :  * Cells (element) - Tetrahedra
      80                 :            :  *
      81                 :            :  *   691 4 599 556 1218 1216 2
      82                 :            :  *
      83                 :            :  * Defines that this is tet 691, it has 4 connections to nodes 599, 556,
      84                 :            :  * 1218, 1216 and belongs to cell number 2.
      85                 :            :  *
      86                 :            :  */
      87                 :            : 
      88                 :            : #ifndef READRTT_HPP
      89                 :            : #define READRTT_HPP
      90                 :            : 
      91                 :            : #ifndef IS_BUILDING_MB
      92                 :            : #error "ReadRTT.hpp isn't supposed to be included into an application"
      93                 :            : #endif
      94                 :            : 
      95                 :            : #include <iostream>
      96                 :            : #include <fstream>
      97                 :            : #include <sstream>
      98                 :            : #include <map>
      99                 :            : #include <vector>
     100                 :            : 
     101                 :            : #include "moab/Interface.hpp"
     102                 :            : #include "moab/ReaderIface.hpp"
     103                 :            : #include "FileTokenizer.hpp"
     104                 :            : #include "moab/RangeMap.hpp"
     105                 :            : 
     106                 :            : namespace moab
     107                 :            : {
     108                 :            : 
     109                 :            : class ReadUtilIface;
     110                 :            : class GeomTopoTool;
     111                 :            : 
     112                 :            : class ReadRTT : public ReaderIface
     113                 :            : {
     114                 :            : 
     115                 :            :   public:
     116                 :            :     // factory method
     117                 :            :     static ReaderIface* factory( Interface* );
     118                 :            : 
     119                 :            :     // generic overloaded core -> load_file
     120                 :            :     ErrorCode load_file( const char* file_name, const EntityHandle* file_set, const FileOptions& opts,
     121                 :            :                          const SubsetList* subset_list = 0, const Tag* file_id_tag = 0 );
     122                 :            :     // constructor
     123                 :            :     ReadRTT( Interface* impl = NULL );
     124                 :            : 
     125                 :            :     // destructor
     126                 :            :     virtual ~ReadRTT();
     127                 :            : 
     128                 :            :     // implementation empty
     129                 :            :     ErrorCode read_tag_values( const char* file_name, const char* tag_name, const FileOptions& opts,
     130                 :            :                                std::vector< int >& tag_values_out, const SubsetList* subset_list = 0 );
     131                 :            : 
     132                 :            :   protected:
     133                 :            :     // private functions
     134                 :            :   private:
     135                 :            :     // structure to hold the header data
     136 [ +  - ][ +  - ]:          3 :     struct headerData
     137                 :            :     {
     138                 :            :         std::string version;
     139                 :            :         std::string title;
     140                 :            :         std::string date;
     141                 :            :     };
     142                 :            : 
     143                 :            :     // structure to hold sense & vol data
     144                 :          0 :     struct boundary
     145                 :            :     {
     146                 :            :         int sense;
     147                 :            :         std::string name;
     148                 :            :     };
     149                 :            : 
     150                 :            :     // structure to hold side data
     151 [ #  # ][ #  # ]:          0 :     struct side
           [ #  #  #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     152                 :            :     {
     153                 :            :         int id;
     154                 :            :         int senses[2];
     155                 :            :         std::string names[2];
     156 [ #  # ][ #  #  :          0 :         side() : id( 0 )
          #  #  #  #  #  
                      # ]
     157                 :            :         {
     158                 :          0 :             senses[0] = senses[1] = 0;
     159 [ #  # ][ #  # ]:          0 :             names[0] = names[1] = "";
     160         [ #  # ]:          0 :         }
     161                 :            :     };
     162                 :            : 
     163                 :            :     // structure to hold cell data
     164                 :          0 :     struct cell
     165                 :            :     {
     166                 :            :         int id;
     167                 :            :         std::string name;
     168         [ #  # ]:          0 :         cell() : id( 0 ), name( "" ) {}
     169                 :            :     };
     170                 :            : 
     171                 :            :     // structure to hold node data
     172                 :            :     struct node
     173                 :            :     {
     174                 :            :         int id;
     175                 :            :         double x, y, z;
     176                 :          0 :         node() : id( 0 ), x( 0. ), y( 0. ), z( 0. ) {}
     177                 :            :     };
     178                 :            : 
     179                 :            :     // structure to hold facet data
     180                 :            :     struct facet
     181                 :            :     {
     182                 :            :         int id;
     183                 :            :         int connectivity[3];
     184                 :            :         int side_id;
     185                 :            :         int surface_number;
     186                 :          0 :         facet() : id( 0 ), side_id( 0 ), surface_number( 0 )
     187                 :            :         {
     188         [ #  # ]:          0 :             for( int k = 0; k < 3; k++ )
     189                 :          0 :                 connectivity[k] = 0;
     190                 :          0 :         }
     191                 :            :     };
     192                 :            : 
     193                 :            :     // structure to hold tet data
     194                 :            :     struct tet
     195                 :            :     {
     196                 :            :         int id;
     197                 :            :         int connectivity[4];
     198                 :            :         int material_number;
     199                 :            :         // with c++11 we could use tet(): id(0), connectivity({0}), material_number(0) {}
     200                 :          0 :         tet() : id( 0 ), material_number( 0 )
     201                 :            :         {
     202         [ #  # ]:          0 :             for( int k = 0; k < 4; k++ )
     203                 :          0 :                 connectivity[k] = 0;
     204                 :          0 :         }
     205                 :            :     };
     206                 :            : 
     207                 :            :     /**
     208                 :            :      * generates the topology of the problem from the already read input data, loops over the 2 and
     209                 :            :      * 3 dimension macrodata that exist from the rtt file, sides = dagmc surfaces, cells = dagmc
     210                 :            :      * cells, creates a meshset for each surface and tags with the id number, and similarly makes a
     211                 :            :      * meshset for dagmc cells and tags with the id number. The surfaces are added to the s surface
     212                 :            :      * map, where the key is the surface ID number (1->N) and (cells and surfaces are added to an
     213                 :            :      * dimesional entity map stored in the class
     214                 :            :      *
     215                 :            :      * @param side_data, vector of side data
     216                 :            :      * @param cell_data, vector of vector of cell data
     217                 :            :      * @param surface_map, reference to the surface map of data
     218                 :            :      *
     219                 :            :      */
     220                 :            :     ErrorCode generate_topology( std::vector< side > side_data, std::vector< cell > cell_data,
     221                 :            :                                  std::map< int, EntityHandle >& surface_map );
     222                 :            :     /**
     223                 :            :      * Generate parent child links to create DAGMC like structure of surface meshsets being children
     224                 :            :      * of parent cell meshsets. By looping over the surfaces (1->N), look in the description of the
     225                 :            :      * cells that are shared by that surface, and then make the surface the child of the parent
     226                 :            :      * volume. The appropriate sense data will be set later
     227                 :            :      *
     228                 :            :      * @param num_ents[4], array containing the number of surfaces, cells, groups etc
     229                 :            :      * @param entity_map[4], vector of maps containing data by dimension
     230                 :            :      * @param side_data, vector of all the side data in the problem
     231                 :            :      * @param cell_data, vector of the cell data in the problem
     232                 :            :      *
     233                 :            :      */
     234                 :            :     void generate_parent_child_links( int num_ents[4], std::vector< EntityHandle > entity_map[4],
     235                 :            :                                       std::vector< side > side_data, std::vector< cell > cell_data );
     236                 :            :     /**
     237                 :            :      * Sets the appropriate surface senses for each surface in the problem. By looping through all
     238                 :            :      * the surfaces, we determine from the side_data vector, the volume id's that are shared, then
     239                 :            :      * using 1 to mean +ve sense and -1 to mean -ve sense wrt the volume.
     240                 :            :      *
     241                 :            :      * @param num_ents[4], array containing the number of surfaces, cells, groups etc
     242                 :            :      * @param entity_map[4], vector of maps containing data by dimension
     243                 :            :      * @param side_data, vector of all the side data in the problem
     244                 :            :      * @param cell_data, vector of the cell data in the problem
     245                 :            :      *
     246                 :            :      */
     247                 :            :     void set_surface_senses( int num_ents[4], std::vector< EntityHandle > entity_map[4], std::vector< side > side_data,
     248                 :            :                              std::vector< cell > cell_data );
     249                 :            : 
     250                 :            :     /**
     251                 :            :      * creates the group data requried for dagmc, reflecting planes, material assignments etc
     252                 :            :      * @param entity_map, vector of vector of entitiy handles for each dimension
     253                 :            :      *
     254                 :            :      * @returns moab::ErrorCode
     255                 :            :      */
     256                 :            :     ErrorCode setup_group_data( std::vector< EntityHandle > entity_map[4] );
     257                 :            : 
     258                 :            :     /**
     259                 :            :      * create a group of a given name, mustkeep track of id
     260                 :            :      * @param group_name, name of the group
     261                 :            :      * @param id, integer id number
     262                 :            :      *
     263                 :            :      * returns the entity handle of the group
     264                 :            :      */
     265                 :            :     EntityHandle create_group( std::string group_name, int id );
     266                 :            : 
     267                 :            :     /**
     268                 :            :      * Builds the full MOAB representation of the data, making vertices from coordinates, triangles
     269                 :            :      * from vertices and tets from the same vertices. Tags appropriate to each dataset collection
     270                 :            :      * are applied, triangles are tagged with the surface id and side id they belong to, as well as
     271                 :            :      * tagging the surface with the same data. Tets are similarly tagged only with the Material
     272                 :            :      * number
     273                 :            :      *
     274                 :            :      * @param node_data the node data
     275                 :            :      * @param facet_data, the triangles in the problem
     276                 :            :      * @param tet_data, the tets in the problem
     277                 :            :      * @param surface_map, the map of surface meshset and id numbers
     278                 :            :      *
     279                 :            :      * @return moab::ErrorCode
     280                 :            :      */
     281                 :            :     ErrorCode build_moab( std::vector< node > node_data, std::vector< facet > facet_data, std::vector< tet > tet_data,
     282                 :            :                           std::map< int, EntityHandle > surface_map );
     283                 :            : 
     284                 :            :     /**
     285                 :            :      * reads the full set of header data
     286                 :            :      *
     287                 :            :      * @param filename, the file to read the data from
     288                 :            :      *
     289                 :            :      * @return moab::Error code
     290                 :            :      */
     291                 :            :     ErrorCode read_header( const char* filename );
     292                 :            : 
     293                 :            :     /**
     294                 :            :      * Reads the full set of side data from the file
     295                 :            :      *
     296                 :            :      * @param filename, the file to read all the side data from
     297                 :            :      * @param side data, a vector containing all the read side data
     298                 :            :      *
     299                 :            :      * @return moab::ErrorCode
     300                 :            :      */
     301                 :            :     ErrorCode read_sides( const char* filename, std::vector< side >& side_data );
     302                 :            : 
     303                 :            :     /**
     304                 :            :      * Reads the full set of cell data from the file
     305                 :            :      *
     306                 :            :      * @param filename, the file to read all the side data from
     307                 :            :      * @param cell data, a vector containing all the read cell data
     308                 :            :      *
     309                 :            :      * @return moab::ErrorCode
     310                 :            :      */
     311                 :            :     ErrorCode read_cells( const char* filename, std::vector< cell >& cell_data );
     312                 :            : 
     313                 :            :     /**
     314                 :            :      * Reads the full set of node data from the file
     315                 :            :      *
     316                 :            :      * @param filename, the file to read all the side data from
     317                 :            :      * @param node data, a vector containing all the read node data
     318                 :            :      *
     319                 :            :      * @return moab::ErrorCode
     320                 :            :      */
     321                 :            :     ErrorCode read_nodes( const char* filename, std::vector< node >& node_data );
     322                 :            : 
     323                 :            :     /**
     324                 :            :      * Reads the full set of facet data from the file
     325                 :            :      *
     326                 :            :      * @param filename, the file to read all the side data from
     327                 :            :      * @param facet data, a vector containing all the read facet data
     328                 :            :      *
     329                 :            :      * @return moab::ErrorCode
     330                 :            :      */
     331                 :            :     ErrorCode read_facets( const char* filename, std::vector< facet >& facet_data );
     332                 :            : 
     333                 :            :     /**
     334                 :            :      * Reads the full set of tet data from the file
     335                 :            :      *
     336                 :            :      * @param filename, the file to read all the side data from
     337                 :            :      * @param tet data, a vector containing all the read tet data
     338                 :            :      *
     339                 :            :      * @return moab::ErrorCode
     340                 :            :      */
     341                 :            :     ErrorCode read_tets( const char* filename, std::vector< tet >& tet_data );
     342                 :            : 
     343                 :            :     /**
     344                 :            :      * Reads the header data into a class member structure
     345                 :            :      *
     346                 :            :      * @param input_file, an open filestream
     347                 :            :      *
     348                 :            :      * @return void
     349                 :            :      */
     350                 :            :     ErrorCode get_header_data( std::ifstream& input_file );
     351                 :            : 
     352                 :            :     /**
     353                 :            :      * Reads a single atomic cell data string and populates a cell struct
     354                 :            :      *
     355                 :            :      * @param celldata, a string of read data and
     356                 :            :      *
     357                 :            :      * @return cell, the propulated cell struct
     358                 :            :      */
     359                 :            :     cell get_cell_data( std::string celldata );
     360                 :            : 
     361                 :            :     /**
     362                 :            :      * Reads a single atomic side data string and populates a side struct
     363                 :            :      *
     364                 :            :      * @param sidedata, a string of read data and
     365                 :            :      *
     366                 :            :      * @return side, the propulated side struct
     367                 :            :      */
     368                 :            :     side get_side_data( std::string sidedata );
     369                 :            : 
     370                 :            :     /**
     371                 :            :      * Reads a single atomic node data string and populates a node struct
     372                 :            :      *
     373                 :            :      * @param sidedata, a string of read data and
     374                 :            :      *
     375                 :            :      * @return node, the propulated node struct
     376                 :            :      */
     377                 :            :     node get_node_data( std::string nodedata );
     378                 :            : 
     379                 :            :     /**
     380                 :            :      * Reads a single atomic facet data string and populates a facet struct
     381                 :            :      *
     382                 :            :      * @param facetdata, a string of facet data and
     383                 :            :      *
     384                 :            :      * @return facet, the propulated facet struct
     385                 :            :      */
     386                 :            :     facet get_facet_data( std::string facetdata );
     387                 :            : 
     388                 :            :     /**
     389                 :            :      * Reads a single atomic tet data string and populates a tet struct
     390                 :            :      *
     391                 :            :      * @param tetdata, a string of tet data and
     392                 :            :      *
     393                 :            :      * @return tet, the propulated tet struct
     394                 :            :      */
     395                 :            :     tet get_tet_data( std::string tetdata );
     396                 :            : 
     397                 :            :     /**
     398                 :            :      * Splits a string into a vector of substrings delimited by split_char
     399                 :            :      *
     400                 :            :      * @param string_to_split, the string that needs splitting into chunks
     401                 :            :      * @param split_char, the character to split the string with
     402                 :            :      *
     403                 :            :      * @return a vector of strings that are delimited by split_char
     404                 :            :      */
     405                 :            :     std::vector< std::string > split_string( std::string string_to_split, char split_char );
     406                 :            : 
     407                 :            :     /**
     408                 :            :      * Splits an Attila cellname and populates a boundary structure
     409                 :            :      *
     410                 :            :      * @param attila_cellname, string containing the boundary information
     411                 :            :      *
     412                 :            :      * @return a boundary object
     413                 :            :      */
     414                 :            :     boundary split_name( std::string atilla_cellname );
     415                 :            : 
     416                 :            :     /**
     417                 :            :      * Count the number of unique surface numbers in the dataset, also get list of surface numbers
     418                 :            :      * @param side_data, collection of all the side data in the mesh
     419                 :            :      * @param surface_numbers, collection of surface numbers
     420                 :            :      *
     421                 :            :      * returns the number of surface numbers
     422                 :            :      */
     423                 :            :     int count_sides( std::vector< side > side_data, std::vector< int >& surface_numbers );
     424                 :            : 
     425                 :            :     // Class Member variables
     426                 :            :   private:
     427                 :            :     headerData header_data;
     428                 :            :     // read mesh interface
     429                 :            :     ReadUtilIface* readMeshIface;
     430                 :            :     // Moab Interface
     431                 :            :     Interface* MBI;
     432                 :            :     // geom tool instance
     433                 :            :     GeomTopoTool* myGeomTool;
     434                 :            :     // tags used in the problem
     435                 :            :     Tag geom_tag, id_tag, name_tag, category_tag, faceting_tol_tag;
     436                 :            : };
     437                 :            : 
     438                 :            : }  // namespace moab
     439                 :            : 
     440                 :            : #endif

Generated by: LCOV version 1.11