cgma
InputDeck Class Reference

#include <MCNPInput.hpp>

List of all members.

Classes

class  LineExtractor

Public Types

typedef std::vector< CellCard * > cell_card_list
typedef std::vector
< SurfaceCard * > 
surface_card_list
typedef std::vector< DataCard * > data_card_list

Public Member Functions

 ~InputDeck ()
cell_card_listgetCells ()
surface_card_listgetSurfaces ()
data_card_listgetDataCards ()
cell_card_list getCellsOfUniverse (int universe)
CellCardlookup_cell_card (int ident)
SurfaceCardlookup_surface_card (int ident)
DataCardlookup_data_card (const DataCard::id_t &ident)
DataCardlookup_data_card (DataCard::kind k, int ident)

Static Public Member Functions

static InputDeckbuild (std::istream &input)

Protected Member Functions

bool do_line_continuation (LineExtractor &lines, token_list_t &token_buffer)
void parseTitle (LineExtractor &lines)
void parseCells (LineExtractor &lines)
void parseSurfaces (LineExtractor &lines)
void parseDataCards (LineExtractor &lines)

Protected Attributes

cell_card_list cells
surface_card_list surfaces
data_card_list datacards
std::map< int, CellCard * > cell_map
std::map< int, SurfaceCard * > surface_map
std::map< DataCard::id_t,
DataCard * > 
datacard_map

Detailed Description

Main interface to MCNP reader: the InputDeck

Definition at line 134 of file MCNPInput.hpp.


Member Typedef Documentation

typedef std::vector< CellCard* > InputDeck::cell_card_list

Definition at line 137 of file MCNPInput.hpp.

typedef std::vector< DataCard* > InputDeck::data_card_list

Definition at line 139 of file MCNPInput.hpp.

typedef std::vector< SurfaceCard* > InputDeck::surface_card_list

Definition at line 138 of file MCNPInput.hpp.


Constructor & Destructor Documentation

Definition at line 1163 of file MCNPInput.cpp.

                     {
  for(cell_card_list::iterator i = cells.begin(); i!=cells.end(); ++i){
    delete *i;
  }
  cells.clear();
  for(surface_card_list::iterator i = surfaces.begin(); i!=surfaces.end(); ++i){
    delete *i;
  }
  surfaces.clear();
  for(data_card_list::iterator i = datacards.begin(); i!=datacards.end(); ++i){
    delete *i;
  }
  datacards.clear();
  
}

Member Function Documentation

InputDeck & InputDeck::build ( std::istream &  input) [static]

Definition at line 1354 of file MCNPInput.cpp.

                                             {
 
  LineExtractor lines(input);

  InputDeck* deck = new InputDeck();

  deck->parseTitle(lines);
  deck->parseCells(lines);
  deck->parseSurfaces(lines);
  deck->parseDataCards(lines);


  for( std::vector<CellCard*>::iterator i = deck->cells.begin(); i!=deck->cells.end(); ++i){
    dynamic_cast<CellCardImpl*>(*i)->finish();
  }

  while(lines.hasLine()){ lines.takeLine(); }
  if( OPT_VERBOSE ) { std::cout << "Total lines read: " << lines.getLineCount()  <<  std::endl; }

  return *deck;
}
bool InputDeck::do_line_continuation ( LineExtractor lines,
token_list_t token_buffer 
) [protected]

Definition at line 1181 of file MCNPInput.cpp.

                                                                                      {

  /* check for final character being & */
  std::string last_token = token_buffer.at(token_buffer.size()-1);
  if( last_token.at(last_token.length()-1) == '&' ){

    if( last_token.length() == 1 ){
      token_buffer.pop_back();
    }
    else{
      last_token.resize(last_token.length()-1);
      token_buffer.at(token_buffer.size()-1).swap( last_token );
    }
    
    return true;
  } 
  /* check for next line beginning with five spaces */
  else if( lines.hasLine() && lines.peekLine().find("     ") == 0){
      /* but don't count it as a continuation if the line is entirely blank */
      if( lines.peekLine().find_first_not_of(" \t\n") != std::string::npos ){
          return true;
      }
  }
  
  return false;
}

Definition at line 162 of file MCNPInput.hpp.

{ return cells; }

Definition at line 1376 of file MCNPInput.cpp.

                                                                   {

  cell_card_list ret;
  for( cell_card_list::iterator i = cells.begin(); i!=cells.end(); ++i){
    CellCard* c = *i;
    if( std::abs(c->getUniverse()) == universe ){
      ret.push_back( *i );
    }
  }
  return ret;

}

Definition at line 164 of file MCNPInput.hpp.

{ return datacards; }

Definition at line 163 of file MCNPInput.hpp.

{ return surfaces; } 

Definition at line 1390 of file MCNPInput.cpp.

                                              {
  assert( cell_map.find(ident) != cell_map.end() );
  return (*cell_map.find(ident)).second;
}

Definition at line 1400 of file MCNPInput.cpp.

                                                                {
  assert( datacard_map.find(ident) != datacard_map.end() );
  return (*datacard_map.find(ident)).second;
}
DataCard* InputDeck::lookup_data_card ( DataCard::kind  k,
int  ident 
) [inline]

Definition at line 172 of file MCNPInput.hpp.

                                                         {
    return lookup_data_card( std::make_pair( k, ident ) );
  }

Definition at line 1395 of file MCNPInput.cpp.

                                                    {
  assert( surface_map.find(ident) != surface_map.end() );
  return (*surface_map.find(ident)).second;
}
void InputDeck::parseCells ( LineExtractor lines) [protected]

Definition at line 1208 of file MCNPInput.cpp.

                                                {

  std::string line;
  token_list_t token_buffer;

  while( !isblank(line = lines.takeLine()) ){

    tokenizeLine(line, token_buffer, "=");
    
    if( do_line_continuation( lines, token_buffer ) ){
      continue;
    }

    if( OPT_DEBUG ) std::cout << "Creating cell with the following tokens:\n" << token_buffer << std::endl;
    CellCard* c = new CellCardImpl(*this, token_buffer);

    if( OPT_VERBOSE ) c->print(std::cout);

    this->cells.push_back(c);
    this->cell_map.insert( std::make_pair(c->getIdent(), c) );

    token_buffer.clear();

  }


}
void InputDeck::parseDataCards ( LineExtractor lines) [protected]

Definition at line 1289 of file MCNPInput.cpp.

                                                    {

  std::string line;
  token_list_t token_buffer;

  while( lines.hasLine() && !isblank(line = lines.takeLine()) ){

    tokenizeLine(line, token_buffer );
    
    if( do_line_continuation( lines, token_buffer ) ){
      continue;
    }
    else if( token_buffer.at(0) == "#" ){
      std::cerr << "Vertical data card format not supported" << std::endl;
      std::cerr << "Data written in this format will be ignored." << std::endl;
    }

    DataCard* d = NULL;
    DataCard::kind t = DataCard::OTHER;
    int ident = 0;

    std::string cardname = token_buffer.at(0);
    token_buffer.erase( token_buffer.begin() );

    if( cardname.find("tr") == 0 || cardname.find("*tr") == 0 ){

      t = DataCard::TR;
      bool degree_format = false;
      if( cardname[0] == '*' ){
        degree_format = true;
        cardname = cardname.substr( 1 ); // remove leading * 
      }
      else if( cardname.find("*") == cardname.length()-1 ){
        // although it's undocumented, apparently TRn* is a synonym for *TRn
        // (the manual uses this undocumented form in chapter 4)
        degree_format = true;
        cardname.resize( cardname.length() -1 ); // remove trailing *
      }

      std::string id_string( cardname, 2 );

      // the id_string may be empty, indicating that n is missing from TRn.  
      // examples from the manual indicate it should be assumed to be 1
      if( id_string == "" ){
        ident = 1;
      }
      else{
        ident = makeint( id_string );
      }

      d = new TransformCard( *this, ident, degree_format, token_buffer);
    }
    
    if(d){
      if( OPT_VERBOSE ){ d->print( std::cout ); }
      this->datacards.push_back(d);
      this->datacard_map.insert( std::make_pair( std::make_pair(t,ident), d) );
    }

    token_buffer.clear();

  }

}
void InputDeck::parseSurfaces ( LineExtractor lines) [protected]

Definition at line 1265 of file MCNPInput.cpp.

                                                   {
  std::string line;
  token_list_t token_buffer;

  while( !isblank(line = lines.takeLine()) ){

    tokenizeLine(line, token_buffer );
    
    if( do_line_continuation( lines, token_buffer ) ){
      continue;
    }
   
    SurfaceCard* s = new SurfaceCard(*this, token_buffer);

    if( OPT_VERBOSE) s->print(std::cout);

    this->surfaces.push_back(s);
    this->surface_map.insert( std::make_pair(s->getIdent(), s) );

    token_buffer.clear();

  }
}
void InputDeck::parseTitle ( LineExtractor lines) [protected]

Definition at line 1238 of file MCNPInput.cpp.

                                                {
  
  // FIXME: will break if the title line looks like a comment card.

  int lineno;
  std::string topLine = lines.takeLine(lineno);
  if(topLine.find("message:") == 0){
    if( OPT_VERBOSE ) std::cout << "Skipping MCNP file message block..." << std::endl;
    do{
      // nothing
    }
    while( !isblank(lines.takeLine()) ) /*do nothing */;

    topLine = lines.takeLine(lineno);
  }

  if(topLine.find("continue") == 0){
    std::cerr << "Warning: this looks like it might be a `continue-run' input file." << std::endl;
    std::cerr << "  beware of trouble ahead!" << std::endl;
  }

  std::cout << "The MCNP title card is: " << topLine << std::endl;
  //std::cout << "    and occupies line " << lineno << std::endl;
}

Member Data Documentation

std::map<int, CellCard*> InputDeck::cell_map [protected]

Definition at line 148 of file MCNPInput.hpp.

Definition at line 142 of file MCNPInput.hpp.

Definition at line 150 of file MCNPInput.hpp.

Definition at line 146 of file MCNPInput.hpp.

std::map<int, SurfaceCard*> InputDeck::surface_map [protected]

Definition at line 149 of file MCNPInput.hpp.

Definition at line 145 of file MCNPInput.hpp.


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines