MOAB: Mesh Oriented datABase  (version 5.4.1)
ReadRTT.hpp
Go to the documentation of this file.
00001 /**
00002  * MOAB, a Mesh-Oriented datABase, is a software component for creating,
00003  * storing and accessing finite element mesh data.
00004  *
00005  * Copyright 2004 Sandia Corporation.  Under the terms of Contract
00006  * DE-AC04-94AL85000 with Sandia Coroporation, the U.S. Government
00007  * retains certain rights in this software.
00008  *
00009  * This library is free software; you can redistribute it and/or
00010  * modify it under the terms of the GNU Lesser General Public
00011  * License as published by the Free Software Foundation; either
00012  * version 2.1 of the License, or (at your option) any later version.
00013  *
00014  */
00015 
00016 //-------------------------------------------------------------------------
00017 // Filename      : ReadRTT.hpp
00018 //
00019 // Purpose       : RTT file reader
00020 //
00021 // Creator       : Andrew Davis
00022 //
00023 // Date          : 02/2014
00024 //
00025 //-------------------------------------------------------------------------
00026 
00027 /**
00028  * The RTT file format is used by the Attila deterministic radiation
00029  * transport code. The specific mesh format can be found in Chapter 9
00030  * of the Attila manual. The format is defined by xml like, block/end block
00031  * type syntax. The implementation at the time of writing supports a subset
00032  * of the whole format, and even Attila does not support the entireity of
00033  * its own mesh format.
00034  *
00035  * The mesh contains several features, that as a whole allow the conversion
00036  * from the RTT format, to a DAGMC geometry and a Tet Mesh for tallying.
00037  *
00038  * Sides - Defines the 6 boundary condtions for top, bottom, front, back
00039  *         left and right, as well as internal and external.
00040  *---------------------------------------------------------------------
00041  * Faces - Logically equivalent to surfaces in DAGMC, containers for triangles, includes
00042  *         the definition of the sense of the faces with respect to the Cells (volumes)
00043  *         which bound it.
00044  *
00045  *         The face syntax looks like
00046  *
00047  *         1 (+)Pyrex@14
00048  *
00049  *         This means Face (surface) 1 is used to define the insde of the Pyrex cell only
00050  *
00051  *         75 (+)Pyrex/(-)Fuel30@25
00052  *
00053  *         This means Face (surface) 75 is used by both Cell Pyrex and Cell Fuel 30,
00054  *         the + and - signs refer to the sense, i.e. the inside sense defines the Pyrex and
00055  *         the outside sense defines the Fuel.
00056  *---------------------------------------------------------------------
00057  * Cells - Entityset like coillections of tetrahedra which define contiguous material properties
00058  *
00059  *        cell_flags
00060  *          1 REGIONS
00061  *            1 Pyrex
00062  *        end_cell_flags
00063  *
00064  * Defines that there is 1 region called Pyrex
00065  *---------------------------------------------------------------------
00066  * Nodes - Defines the vertices for facets and tets, the syntax of which is shown below
00067  *
00068  *   100  1.8900000000E+03  0.0000000000E+00  5.0000000000E+03 100
00069  *
00070  * Defines that this is node 100, and has the coordinates 1890.0, 0.0 5000.0 cm
00071  **---------------------------------------------------------------------
00072  * Side (element) - Triangles
00073  *
00074  *  1 3 874 132 154 3 6365
00075  *
00076  * Defines that this is side element 1, it has 3 nodes, 874, 132 and 154,
00077  * side ID 3 and surface number 6365
00078  *---------------------------------------------------------------------
00079  * Cells (element) - Tetrahedra
00080  *
00081  *   691 4 599 556 1218 1216 2
00082  *
00083  * Defines that this is tet 691, it has 4 connections to nodes 599, 556,
00084  * 1218, 1216 and belongs to cell number 2.
00085  *
00086  */
00087 
00088 #ifndef READRTT_HPP
00089 #define READRTT_HPP
00090 
00091 #ifndef IS_BUILDING_MB
00092 #error "ReadRTT.hpp isn't supposed to be included into an application"
00093 #endif
00094 
00095 #include <iostream>
00096 #include <fstream>
00097 #include <sstream>
00098 #include <map>
00099 #include <vector>
00100 
00101 #include "moab/Interface.hpp"
00102 #include "moab/ReaderIface.hpp"
00103 #include "FileTokenizer.hpp"
00104 #include "moab/RangeMap.hpp"
00105 
00106 namespace moab
00107 {
00108 
00109 class ReadUtilIface;
00110 class GeomTopoTool;
00111 
00112 class ReadRTT : public ReaderIface
00113 {
00114 
00115   public:
00116     // factory method
00117     static ReaderIface* factory( Interface* );
00118 
00119     // generic overloaded core -> load_file
00120     ErrorCode load_file( const char* file_name,
00121                          const EntityHandle* file_set,
00122                          const FileOptions& opts,
00123                          const SubsetList* subset_list = 0,
00124                          const Tag* file_id_tag        = 0 );
00125     // constructor
00126     ReadRTT( Interface* impl = NULL );
00127 
00128     // destructor
00129     virtual ~ReadRTT();
00130 
00131     // implementation empty
00132     ErrorCode read_tag_values( const char* file_name,
00133                                const char* tag_name,
00134                                const FileOptions& opts,
00135                                std::vector< int >& tag_values_out,
00136                                const SubsetList* subset_list = 0 );
00137 
00138   protected:
00139     // private functions
00140   private:
00141     // structure to hold the header data
00142     struct headerData
00143     {
00144         std::string version;
00145         std::string title;
00146         std::string date;
00147     };
00148 
00149     // structure to hold sense & vol data
00150     struct boundary
00151     {
00152         int sense;
00153         std::string name;
00154     };
00155 
00156     // structure to hold side data
00157     struct side
00158     {
00159         int id;
00160         int senses[2];
00161         std::string names[2];
00162         side() : id( 0 )
00163         {
00164             senses[0] = senses[1] = 0;
00165             names[0] = names[1] = "";
00166         }
00167     };
00168 
00169     // structure to hold cell data
00170     struct cell
00171     {
00172         int id;
00173         std::string name;
00174         cell() : id( 0 ), name( "" ) {}
00175     };
00176 
00177     // structure to hold node data
00178     struct node
00179     {
00180         int id;
00181         double x, y, z;
00182         node() : id( 0 ), x( 0. ), y( 0. ), z( 0. ) {}
00183     };
00184 
00185     // structure to hold facet data
00186     struct facet
00187     {
00188         int id;
00189         int connectivity[3];
00190         int side_id;
00191         int surface_number;
00192         facet() : id( 0 ), side_id( 0 ), surface_number( 0 )
00193         {
00194             for( int k = 0; k < 3; k++ )
00195                 connectivity[k] = 0;
00196         }
00197     };
00198 
00199     // structure to hold tet data
00200     struct tet
00201     {
00202         int id;
00203         int connectivity[4];
00204         int material_number;
00205         // with c++11 we could use tet(): id(0), connectivity({0}), material_number(0) {}
00206         tet() : id( 0 ), material_number( 0 )
00207         {
00208             for( int k = 0; k < 4; k++ )
00209                 connectivity[k] = 0;
00210         }
00211     };
00212 
00213     /**
00214      * generates the topology of the problem from the already read input data, loops over the 2 and
00215      * 3 dimension macrodata that exist from the rtt file, sides = dagmc surfaces, cells = dagmc
00216      * cells, creates a meshset for each surface and tags with the id number, and similarly makes a
00217      * meshset for dagmc cells and tags with the id number. The surfaces are added to the s surface
00218      * map, where the key is the surface ID number (1->N) and (cells and surfaces are added to an
00219      * dimesional entity map stored in the class
00220      *
00221      * @param side_data, vector of side data
00222      * @param cell_data, vector of vector of cell data
00223      * @param surface_map, reference to the surface map of data
00224      *
00225      */
00226     ErrorCode generate_topology( std::vector< side > side_data,
00227                                  std::vector< cell > cell_data,
00228                                  std::map< int, EntityHandle >& surface_map );
00229     /**
00230      * Generate parent child links to create DAGMC like structure of surface meshsets being children
00231      * of parent cell meshsets. By looping over the surfaces (1->N), look in the description of the
00232      * cells that are shared by that surface, and then make the surface the child of the parent
00233      * volume. The appropriate sense data will be set later
00234      *
00235      * @param num_ents[4], array containing the number of surfaces, cells, groups etc
00236      * @param entity_map[4], vector of maps containing data by dimension
00237      * @param side_data, vector of all the side data in the problem
00238      * @param cell_data, vector of the cell data in the problem
00239      *
00240      */
00241     void generate_parent_child_links( int num_ents[4],
00242                                       std::vector< EntityHandle > entity_map[4],
00243                                       std::vector< side > side_data,
00244                                       std::vector< cell > cell_data );
00245     /**
00246      * Sets the appropriate surface senses for each surface in the problem. By looping through all
00247      * the surfaces, we determine from the side_data vector, the volume id's that are shared, then
00248      * using 1 to mean +ve sense and -1 to mean -ve sense wrt the volume.
00249      *
00250      * @param num_ents[4], array containing the number of surfaces, cells, groups etc
00251      * @param entity_map[4], vector of maps containing data by dimension
00252      * @param side_data, vector of all the side data in the problem
00253      * @param cell_data, vector of the cell data in the problem
00254      *
00255      */
00256     void set_surface_senses( int num_ents[4],
00257                              std::vector< EntityHandle > entity_map[4],
00258                              std::vector< side > side_data,
00259                              std::vector< cell > cell_data );
00260 
00261     /**
00262      * creates the group data requried for dagmc, reflecting planes, material assignments etc
00263      * @param entity_map, vector of vector of entitiy handles for each dimension
00264      *
00265      * @returns moab::ErrorCode
00266      */
00267     ErrorCode setup_group_data( std::vector< EntityHandle > entity_map[4] );
00268 
00269     /**
00270      * create a group of a given name, mustkeep track of id
00271      * @param group_name, name of the group
00272      * @param id, integer id number
00273      *
00274      * returns the entity handle of the group
00275      */
00276     EntityHandle create_group( std::string group_name, int id );
00277 
00278     /**
00279      * Builds the full MOAB representation of the data, making vertices from coordinates, triangles
00280      * from vertices and tets from the same vertices. Tags appropriate to each dataset collection
00281      * are applied, triangles are tagged with the surface id and side id they belong to, as well as
00282      * tagging the surface with the same data. Tets are similarly tagged only with the Material
00283      * number
00284      *
00285      * @param node_data the node data
00286      * @param facet_data, the triangles in the problem
00287      * @param tet_data, the tets in the problem
00288      * @param surface_map, the map of surface meshset and id numbers
00289      *
00290      * @return moab::ErrorCode
00291      */
00292     ErrorCode build_moab( std::vector< node > node_data,
00293                           std::vector< facet > facet_data,
00294                           std::vector< tet > tet_data,
00295                           std::map< int, EntityHandle > surface_map );
00296 
00297     /**
00298      * reads the full set of header data
00299      *
00300      * @param filename, the file to read the data from
00301      *
00302      * @return moab::Error code
00303      */
00304     ErrorCode read_header( const char* filename );
00305 
00306     /**
00307      * Reads the full set of side data from the file
00308      *
00309      * @param filename, the file to read all the side data from
00310      * @param side data, a vector containing all the read side data
00311      *
00312      * @return moab::ErrorCode
00313      */
00314     ErrorCode read_sides( const char* filename, std::vector< side >& side_data );
00315 
00316     /**
00317      * Reads the full set of cell data from the file
00318      *
00319      * @param filename, the file to read all the side data from
00320      * @param cell data, a vector containing all the read cell data
00321      *
00322      * @return moab::ErrorCode
00323      */
00324     ErrorCode read_cells( const char* filename, std::vector< cell >& cell_data );
00325 
00326     /**
00327      * Reads the full set of node data from the file
00328      *
00329      * @param filename, the file to read all the side data from
00330      * @param node data, a vector containing all the read node data
00331      *
00332      * @return moab::ErrorCode
00333      */
00334     ErrorCode read_nodes( const char* filename, std::vector< node >& node_data );
00335 
00336     /**
00337      * Reads the full set of facet data from the file
00338      *
00339      * @param filename, the file to read all the side data from
00340      * @param facet data, a vector containing all the read facet data
00341      *
00342      * @return moab::ErrorCode
00343      */
00344     ErrorCode read_facets( const char* filename, std::vector< facet >& facet_data );
00345 
00346     /**
00347      * Reads the full set of tet data from the file
00348      *
00349      * @param filename, the file to read all the side data from
00350      * @param tet data, a vector containing all the read tet data
00351      *
00352      * @return moab::ErrorCode
00353      */
00354     ErrorCode read_tets( const char* filename, std::vector< tet >& tet_data );
00355 
00356     /**
00357      * Reads the header data into a class member structure
00358      *
00359      * @param input_file, an open filestream
00360      *
00361      * @return void
00362      */
00363     ErrorCode get_header_data( std::ifstream& input_file );
00364 
00365     /**
00366      * Reads a single atomic cell data string and populates a cell struct
00367      *
00368      * @param celldata, a string of read data and
00369      *
00370      * @return cell, the propulated cell struct
00371      */
00372     cell get_cell_data( std::string celldata );
00373 
00374     /**
00375      * Reads a single atomic side data string and populates a side struct
00376      *
00377      * @param sidedata, a string of read data and
00378      *
00379      * @return side, the propulated side struct
00380      */
00381     side get_side_data( std::string sidedata );
00382 
00383     /**
00384      * Reads a single atomic node data string and populates a node struct
00385      *
00386      * @param sidedata, a string of read data and
00387      *
00388      * @return node, the propulated node struct
00389      */
00390     node get_node_data( std::string nodedata );
00391 
00392     /**
00393      * Reads a single atomic facet data string and populates a facet struct
00394      *
00395      * @param facetdata, a string of facet data and
00396      *
00397      * @return facet, the propulated facet struct
00398      */
00399     facet get_facet_data( std::string facetdata );
00400 
00401     /**
00402      * Reads a single atomic tet data string and populates a tet struct
00403      *
00404      * @param tetdata, a string of tet data and
00405      *
00406      * @return tet, the propulated tet struct
00407      */
00408     tet get_tet_data( std::string tetdata );
00409 
00410     /**
00411      * Splits a string into a vector of substrings delimited by split_char
00412      *
00413      * @param string_to_split, the string that needs splitting into chunks
00414      * @param split_char, the character to split the string with
00415      *
00416      * @return a vector of strings that are delimited by split_char
00417      */
00418     std::vector< std::string > split_string( std::string string_to_split, char split_char );
00419 
00420     /**
00421      * Splits an Attila cellname and populates a boundary structure
00422      *
00423      * @param attila_cellname, string containing the boundary information
00424      *
00425      * @return a boundary object
00426      */
00427     boundary split_name( std::string atilla_cellname );
00428 
00429     /**
00430      * Count the number of unique surface numbers in the dataset, also get list of surface numbers
00431      * @param side_data, collection of all the side data in the mesh
00432      * @param surface_numbers, collection of surface numbers
00433      *
00434      * returns the number of surface numbers
00435      */
00436     int count_sides( std::vector< side > side_data, std::vector< int >& surface_numbers );
00437 
00438     // Class Member variables
00439   private:
00440     headerData header_data;
00441     // read mesh interface
00442     ReadUtilIface* readMeshIface;
00443     // Moab Interface
00444     Interface* MBI;
00445     // geom tool instance
00446     GeomTopoTool* myGeomTool;
00447     // tags used in the problem
00448     Tag geom_tag, id_tag, name_tag, category_tag, faceting_tol_tag;
00449 };
00450 
00451 }  // namespace moab
00452 
00453 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines