MOAB: Mesh Oriented datABase  (version 5.2.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, const EntityHandle* file_set, const FileOptions& opts,
00121                          const SubsetList* subset_list = 0, const Tag* file_id_tag = 0 );
00122     // constructor
00123     ReadRTT( Interface* impl = NULL );
00124 
00125     // destructor
00126     virtual ~ReadRTT();
00127 
00128     // implementation empty
00129     ErrorCode read_tag_values( const char* file_name, const char* tag_name, const FileOptions& opts,
00130                                std::vector< int >& tag_values_out, const SubsetList* subset_list = 0 );
00131 
00132   protected:
00133     // private functions
00134   private:
00135     // structure to hold the header data
00136     struct headerData
00137     {
00138         std::string version;
00139         std::string title;
00140         std::string date;
00141     };
00142 
00143     // structure to hold sense & vol data
00144     struct boundary
00145     {
00146         int sense;
00147         std::string name;
00148     };
00149 
00150     // structure to hold side data
00151     struct side
00152     {
00153         int id;
00154         int senses[2];
00155         std::string names[2];
00156         side() : id( 0 )
00157         {
00158             senses[0] = senses[1] = 0;
00159             names[0] = names[1] = "";
00160         }
00161     };
00162 
00163     // structure to hold cell data
00164     struct cell
00165     {
00166         int id;
00167         std::string name;
00168         cell() : id( 0 ), name( "" ) {}
00169     };
00170 
00171     // structure to hold node data
00172     struct node
00173     {
00174         int id;
00175         double x, y, z;
00176         node() : id( 0 ), x( 0. ), y( 0. ), z( 0. ) {}
00177     };
00178 
00179     // structure to hold facet data
00180     struct facet
00181     {
00182         int id;
00183         int connectivity[3];
00184         int side_id;
00185         int surface_number;
00186         facet() : id( 0 ), side_id( 0 ), surface_number( 0 )
00187         {
00188             for( int k = 0; k < 3; k++ )
00189                 connectivity[k] = 0;
00190         }
00191     };
00192 
00193     // structure to hold tet data
00194     struct tet
00195     {
00196         int id;
00197         int connectivity[4];
00198         int material_number;
00199         // with c++11 we could use tet(): id(0), connectivity({0}), material_number(0) {}
00200         tet() : id( 0 ), material_number( 0 )
00201         {
00202             for( int k = 0; k < 4; k++ )
00203                 connectivity[k] = 0;
00204         }
00205     };
00206 
00207     /**
00208      * generates the topology of the problem from the already read input data, loops over the 2 and
00209      * 3 dimension macrodata that exist from the rtt file, sides = dagmc surfaces, cells = dagmc
00210      * cells, creates a meshset for each surface and tags with the id number, and similarly makes a
00211      * meshset for dagmc cells and tags with the id number. The surfaces are added to the s surface
00212      * map, where the key is the surface ID number (1->N) and (cells and surfaces are added to an
00213      * dimesional entity map stored in the class
00214      *
00215      * @param side_data, vector of side data
00216      * @param cell_data, vector of vector of cell data
00217      * @param surface_map, reference to the surface map of data
00218      *
00219      */
00220     ErrorCode generate_topology( std::vector< side > side_data, std::vector< cell > cell_data,
00221                                  std::map< int, EntityHandle >& surface_map );
00222     /**
00223      * Generate parent child links to create DAGMC like structure of surface meshsets being children
00224      * of parent cell meshsets. By looping over the surfaces (1->N), look in the description of the
00225      * cells that are shared by that surface, and then make the surface the child of the parent
00226      * volume. The appropriate sense data will be set later
00227      *
00228      * @param num_ents[4], array containing the number of surfaces, cells, groups etc
00229      * @param entity_map[4], vector of maps containing data by dimension
00230      * @param side_data, vector of all the side data in the problem
00231      * @param cell_data, vector of the cell data in the problem
00232      *
00233      */
00234     void generate_parent_child_links( int num_ents[4], std::vector< EntityHandle > entity_map[4],
00235                                       std::vector< side > side_data, std::vector< cell > cell_data );
00236     /**
00237      * Sets the appropriate surface senses for each surface in the problem. By looping through all
00238      * the surfaces, we determine from the side_data vector, the volume id's that are shared, then
00239      * using 1 to mean +ve sense and -1 to mean -ve sense wrt the volume.
00240      *
00241      * @param num_ents[4], array containing the number of surfaces, cells, groups etc
00242      * @param entity_map[4], vector of maps containing data by dimension
00243      * @param side_data, vector of all the side data in the problem
00244      * @param cell_data, vector of the cell data in the problem
00245      *
00246      */
00247     void set_surface_senses( int num_ents[4], std::vector< EntityHandle > entity_map[4], std::vector< side > side_data,
00248                              std::vector< cell > cell_data );
00249 
00250     /**
00251      * creates the group data requried for dagmc, reflecting planes, material assignments etc
00252      * @param entity_map, vector of vector of entitiy handles for each dimension
00253      *
00254      * @returns moab::ErrorCode
00255      */
00256     ErrorCode setup_group_data( std::vector< EntityHandle > entity_map[4] );
00257 
00258     /**
00259      * create a group of a given name, mustkeep track of id
00260      * @param group_name, name of the group
00261      * @param id, integer id number
00262      *
00263      * returns the entity handle of the group
00264      */
00265     EntityHandle create_group( std::string group_name, int id );
00266 
00267     /**
00268      * Builds the full MOAB representation of the data, making vertices from coordinates, triangles
00269      * from vertices and tets from the same vertices. Tags appropriate to each dataset collection
00270      * are applied, triangles are tagged with the surface id and side id they belong to, as well as
00271      * tagging the surface with the same data. Tets are similarly tagged only with the Material
00272      * number
00273      *
00274      * @param node_data the node data
00275      * @param facet_data, the triangles in the problem
00276      * @param tet_data, the tets in the problem
00277      * @param surface_map, the map of surface meshset and id numbers
00278      *
00279      * @return moab::ErrorCode
00280      */
00281     ErrorCode build_moab( std::vector< node > node_data, std::vector< facet > facet_data, std::vector< tet > tet_data,
00282                           std::map< int, EntityHandle > surface_map );
00283 
00284     /**
00285      * reads the full set of header data
00286      *
00287      * @param filename, the file to read the data from
00288      *
00289      * @return moab::Error code
00290      */
00291     ErrorCode read_header( const char* filename );
00292 
00293     /**
00294      * Reads the full set of side data from the file
00295      *
00296      * @param filename, the file to read all the side data from
00297      * @param side data, a vector containing all the read side data
00298      *
00299      * @return moab::ErrorCode
00300      */
00301     ErrorCode read_sides( const char* filename, std::vector< side >& side_data );
00302 
00303     /**
00304      * Reads the full set of cell data from the file
00305      *
00306      * @param filename, the file to read all the side data from
00307      * @param cell data, a vector containing all the read cell data
00308      *
00309      * @return moab::ErrorCode
00310      */
00311     ErrorCode read_cells( const char* filename, std::vector< cell >& cell_data );
00312 
00313     /**
00314      * Reads the full set of node data from the file
00315      *
00316      * @param filename, the file to read all the side data from
00317      * @param node data, a vector containing all the read node data
00318      *
00319      * @return moab::ErrorCode
00320      */
00321     ErrorCode read_nodes( const char* filename, std::vector< node >& node_data );
00322 
00323     /**
00324      * Reads the full set of facet data from the file
00325      *
00326      * @param filename, the file to read all the side data from
00327      * @param facet data, a vector containing all the read facet data
00328      *
00329      * @return moab::ErrorCode
00330      */
00331     ErrorCode read_facets( const char* filename, std::vector< facet >& facet_data );
00332 
00333     /**
00334      * Reads the full set of tet data from the file
00335      *
00336      * @param filename, the file to read all the side data from
00337      * @param tet data, a vector containing all the read tet data
00338      *
00339      * @return moab::ErrorCode
00340      */
00341     ErrorCode read_tets( const char* filename, std::vector< tet >& tet_data );
00342 
00343     /**
00344      * Reads the header data into a class member structure
00345      *
00346      * @param input_file, an open filestream
00347      *
00348      * @return void
00349      */
00350     ErrorCode get_header_data( std::ifstream& input_file );
00351 
00352     /**
00353      * Reads a single atomic cell data string and populates a cell struct
00354      *
00355      * @param celldata, a string of read data and
00356      *
00357      * @return cell, the propulated cell struct
00358      */
00359     cell get_cell_data( std::string celldata );
00360 
00361     /**
00362      * Reads a single atomic side data string and populates a side struct
00363      *
00364      * @param sidedata, a string of read data and
00365      *
00366      * @return side, the propulated side struct
00367      */
00368     side get_side_data( std::string sidedata );
00369 
00370     /**
00371      * Reads a single atomic node data string and populates a node struct
00372      *
00373      * @param sidedata, a string of read data and
00374      *
00375      * @return node, the propulated node struct
00376      */
00377     node get_node_data( std::string nodedata );
00378 
00379     /**
00380      * Reads a single atomic facet data string and populates a facet struct
00381      *
00382      * @param facetdata, a string of facet data and
00383      *
00384      * @return facet, the propulated facet struct
00385      */
00386     facet get_facet_data( std::string facetdata );
00387 
00388     /**
00389      * Reads a single atomic tet data string and populates a tet struct
00390      *
00391      * @param tetdata, a string of tet data and
00392      *
00393      * @return tet, the propulated tet struct
00394      */
00395     tet get_tet_data( std::string tetdata );
00396 
00397     /**
00398      * Splits a string into a vector of substrings delimited by split_char
00399      *
00400      * @param string_to_split, the string that needs splitting into chunks
00401      * @param split_char, the character to split the string with
00402      *
00403      * @return a vector of strings that are delimited by split_char
00404      */
00405     std::vector< std::string > split_string( std::string string_to_split, char split_char );
00406 
00407     /**
00408      * Splits an Attila cellname and populates a boundary structure
00409      *
00410      * @param attila_cellname, string containing the boundary information
00411      *
00412      * @return a boundary object
00413      */
00414     boundary split_name( std::string atilla_cellname );
00415 
00416     /**
00417      * Count the number of unique surface numbers in the dataset, also get list of surface numbers
00418      * @param side_data, collection of all the side data in the mesh
00419      * @param surface_numbers, collection of surface numbers
00420      *
00421      * returns the number of surface numbers
00422      */
00423     int count_sides( std::vector< side > side_data, std::vector< int >& surface_numbers );
00424 
00425     // Class Member variables
00426   private:
00427     headerData header_data;
00428     // read mesh interface
00429     ReadUtilIface* readMeshIface;
00430     // Moab Interface
00431     Interface* MBI;
00432     // geom tool instance
00433     GeomTopoTool* myGeomTool;
00434     // tags used in the problem
00435     Tag geom_tag, id_tag, name_tag, category_tag, faceting_tol_tag;
00436 };
00437 
00438 }  // namespace moab
00439 
00440 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines