cgma
|
00001 #ifndef MCNP_INPUT_FORMAT_H 00002 #define MCNP_INPUT_FORMAT_H 00003 00004 #include <vector> 00005 #include <map> 00006 #include <iosfwd> 00007 #include <string> 00008 00009 typedef std::vector< std::string > token_list_t; 00010 00011 #include "dataref.hpp" 00012 #include "geometry.hpp" 00013 00014 class InputDeck; 00015 00019 class Card{ 00020 protected: 00021 InputDeck& parent_deck; 00022 00023 Card( InputDeck& deck_p ): 00024 parent_deck(deck_p) 00025 {} 00026 00027 virtual ~Card(){} 00028 00029 public: 00030 InputDeck& getDeck() { return parent_deck; } 00031 00032 }; 00033 00034 // forward defs 00035 class Transform; 00036 class Fill; 00037 00041 class CellCard : public Card { 00042 00043 public: 00044 enum geom_token_t {INTERSECT, UNION, COMPLEMENT, LPAREN, RPAREN, CELLNUM, SURFNUM, MBODYFACET}; 00045 // for CELLNUM and SURFNUM the second item in the geom_list_entry is the given number 00046 // (possibly negative for surfaces) 00047 // for MBODYFACET it is (cell number*10 + facet number) * sense (where sense=1 or -1) 00048 typedef std::pair<enum geom_token_t, int> geom_list_entry_t; 00049 typedef std::vector<geom_list_entry_t> geom_list_t; 00050 00051 enum lattice_type_t { NONE = 0, HEXAHEDRAL = 1, HEXAGONAL = 2 }; 00052 00053 protected: 00054 00055 CellCard( InputDeck& deck ); 00056 00057 private: 00058 // never defined and should never be called 00059 CellCard( const CellCard& c ); 00060 CellCard& operator=( const CellCard& c ); 00061 00062 public: 00063 00064 virtual int getIdent() const = 0; 00065 virtual const geom_list_t getGeom() const = 0; 00066 00067 virtual const DataRef<Transform>& getTrcl() const = 0; 00068 00069 virtual int getUniverse() const = 0; 00070 virtual bool hasFill() const = 0; 00071 virtual const Fill& getFill() const = 0; 00072 00073 virtual bool isLattice() const = 0; 00074 virtual lattice_type_t getLatticeType() const = 0; 00075 virtual const Lattice& getLattice() const = 0; 00076 00077 virtual int getMat() const = 0; 00078 virtual double getRho() const = 0; 00079 virtual const std::map<char,double>& getImportances() const = 0; 00080 00081 virtual void print( std::ostream& s ) const = 0; 00082 00083 }; 00084 00085 std::ostream& operator<<(std::ostream& str, const CellCard::geom_list_entry_t& t ); 00086 00087 00091 class SurfaceCard : public Card { 00092 protected: 00093 int ident; 00094 DataRef<Transform> *coord_xform; 00095 std::string mnemonic; 00096 std::vector<double> args; 00097 00098 public: 00099 SurfaceCard( InputDeck& deck, const token_list_t tokens ); 00100 00101 int getIdent() const { return ident; } 00102 void print( std::ostream& s ) const ; 00103 00104 const DataRef<Transform>& getTransform() const ; 00105 const std::string& getMnemonic() const { return mnemonic; } 00106 const std::vector<double>& getArgs() const { return args; } 00107 00108 00109 std::pair<Vector3d,double> getPlaneParams() const; 00110 std::vector< std::pair<Vector3d, double> > getMacrobodyPlaneParams() const; 00111 }; 00112 00117 class DataCard : public Card { 00118 00119 public: 00120 typedef enum { TR, OTHER } kind; 00121 typedef std::pair< kind, int > id_t; 00122 00123 DataCard( InputDeck& deck ) : Card( deck ) {} 00124 00125 virtual void print( std::ostream& str ) = 0; 00126 virtual kind getKind(){ return OTHER; } 00127 00128 }; 00129 00130 00134 class InputDeck{ 00135 00136 public: 00137 typedef std::vector< CellCard* > cell_card_list; 00138 typedef std::vector< SurfaceCard* > surface_card_list; 00139 typedef std::vector< DataCard* > data_card_list; 00140 00141 protected: 00142 class LineExtractor; 00143 00144 cell_card_list cells; 00145 surface_card_list surfaces; 00146 data_card_list datacards; 00147 00148 std::map<int, CellCard*> cell_map; 00149 std::map<int, SurfaceCard*> surface_map; 00150 std::map< DataCard::id_t, DataCard*> datacard_map; 00151 00152 bool do_line_continuation( LineExtractor& lines, token_list_t& token_buffer ); 00153 void parseTitle( LineExtractor& lines ); 00154 void parseCells( LineExtractor& lines ); 00155 void parseSurfaces( LineExtractor& lines ); 00156 void parseDataCards( LineExtractor& lines ); 00157 00158 public: 00159 00160 ~InputDeck(); 00161 00162 cell_card_list& getCells() { return cells; } 00163 surface_card_list& getSurfaces() { return surfaces; } 00164 data_card_list& getDataCards(){ return datacards; } 00165 00166 cell_card_list getCellsOfUniverse( int universe ); 00167 00168 CellCard* lookup_cell_card(int ident); 00169 SurfaceCard* lookup_surface_card(int ident); 00170 DataCard* lookup_data_card( const DataCard::id_t& ident ); 00171 00172 DataCard* lookup_data_card( DataCard::kind k, int ident ){ 00173 return lookup_data_card( std::make_pair( k, ident ) ); 00174 } 00175 00176 static InputDeck& build( std::istream& input ); 00177 00178 00179 }; 00180 00181 template < class T > 00182 std::ostream& operator<<( std::ostream& out, const std::vector<T>& list ); 00183 00184 #endif /* MCNP_INPUT_FORMAT_H */