ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/OOPSE-2.0/src/io/Globals.cpp
(Generate patch)

Comparing trunk/OOPSE-2.0/src/io/Globals.cpp (file contents):
Revision 2088 by gezelter, Tue Mar 8 21:07:14 2005 UTC vs.
Revision 2235 by tim, Thu May 19 21:31:23 2005 UTC

# Line 51 | Line 51
51  
52   /*
53   * The following section lists all of the defined tokens for the
54 < * gloabal assignment statements. All are prefixed with a G_ to avoid
54 > * global assignment statements. All are prefixed with a G_ to avoid
55   * stepping on any previously defined enumerations.
56   *
57   * NOTE: tokens start at 1, 0 is a resrved token number
# Line 113 | Line 113 | Globals::Globals(){
113   #define G_THERM_INT_K       51
114   #define G_FORCEFIELD_VARIANT 52
115   #define G_FORCEFIELD_FILENAME 53
116 + #define G_THERM_INT_DIST_SPRING  54
117 + #define G_THERM_INT_THETA_SPRING 55
118 + #define G_THERM_INT_OMEGA_SPRING 56
119 + #define G_SURFACETENSION 57
120 +
121   Globals::Globals(){
122    initalize();
123   }
124  
125   Globals::~Globals(){
126    int i;
122
123  for( i=0; i<hash_size; i++ ){
124    if( command_table[i] != NULL ) delete command_table[i];
125  }
126  delete[] command_table;
127
127    if( components != NULL ){
128      for( i=0; i<n_components; i++ ) delete components[i];
129      delete[] components;
# Line 134 | Line 133 | void Globals::initalize(){
133   void Globals::initalize(){
134    int i;
135    
137  hash_size = 23;
138  hash_shift = 4;
139  
136    components = NULL;
137    
138 <  command_table = new LinkedCommand*[hash_size];
139 <  for( i=0; i<hash_size; i++ ) command_table[i] = NULL;
140 <  
141 <  addHash( "forceField",    G_FORCEFIELD );
142 <  addHash( "nComponents",   G_NCOMPONENTS );
143 <  addHash( "targetTemp",    G_TARGETTEMP );
144 <  addHash( "ensemble",      G_ENSEMBLE );
145 <  
146 <  addHash( "dt",            G_DT );
147 <  addHash( "runTime",       G_RUNTIME );
148 <  
149 <  addHash( "initialConfig", G_INITIALCONFIG );
150 <  addHash( "finalConfig",   G_FINALCONFIG );
151 <  addHash( "nMol",          G_NMOL );
152 <  addHash( "density",       G_DENSITY );
153 <  addHash( "box",           G_BOX );
154 <  addHash( "boxX",          G_BOXX );
155 <  addHash( "boxY",          G_BOXY );
156 <  addHash( "boxZ",          G_BOXZ );
157 <  addHash( "sampleTime",    G_SAMPLETIME );
158 <  addHash( "resetTime",     G_RESETTIME );
159 <  addHash( "statusTime",    G_STATUSTIME );
160 <  addHash( "cutoffRadius",  G_RCUT );
161 <  addHash( "switchingRadius",  G_RSW );
162 <  addHash( "dielectric",    G_DIELECTRIC );
163 <  addHash( "tempSet",       G_TEMPSET );
164 <  addHash( "thermalTime",   G_THERMALTIME );
165 <  addHash( "mixingRule",    G_MIXINGRULE);
166 <  addHash( "usePeriodicBoundaryConditions",        G_USEPBC);
167 <  addHash( "useReactionField",                     G_USERF );
168 <  addHash( "targetPressure",                       G_TARGETPRESSURE);
169 <  addHash( "tauThermostat",                        G_TAUTHERMOSTAT);
170 <  addHash( "tauBarostat",                          G_TAUBAROSTAT);
171 <  addHash( "zconsTime",                            G_ZCONSTIME);
172 <  addHash( "nZconstraints",                        G_NZCONSTRAINTS);
173 <  addHash( "zconsTol",                             G_ZCONSTOL);
174 <  addHash( "zconsForcePolicy",                     G_ZCONSFORCEPOLICY);
175 <  addHash( "seed",                                 G_SEED);
176 <  addHash( "useInitialTime",                       G_USEINITTIME);
177 <  addHash( "useInitialExtendedSystemState",        G_USEINIT_XS_STATE);
178 <  addHash( "orthoBoxTolerance",                    G_ORTHOBOXTOLERANCE);
179 <  addHash( "minimizer",                            G_MINIMIZER);
180 <  addHash( "minimizerMaxIter",                     G_MIN_MAXITER);
181 <  addHash( "minimizerWriteFrq",                    G_MIN_WRITEFRQ);
182 <  addHash( "minimizerStepSize",                    G_MIN_STEPSIZE);
183 <  addHash( "minimizerFTol",                        G_MIN_FTOL);
184 <  addHash( "minimizerGTol",                        G_MIN_GTOL);
185 <  addHash( "minimizerLSTol",                       G_MIN_LSTOL);
186 <  addHash( "minimizerLSMaxIter",                   G_MIN_LSMAXITER);
187 <  addHash( "zconsGap",                             G_ZCONSGAP);
188 <  addHash( "zconsFixtime",                         G_ZCONSFIXTIME);
189 <  addHash( "zconsUsingSMD",                        G_ZCONSUSINGSMD);
190 <  addHash( "useSolidThermInt",                     G_USE_SOLID_THERM_INT);
191 <  addHash( "useLiquidThermInt",                    G_USE_LIQUID_THERM_INT);
192 <  addHash( "thermodynamicIntegrationLambda",       G_THERM_INT_LAMBDA);
193 <  addHash( "thermodynamicIntegrationK",            G_THERM_INT_K);
194 <  addHash( "forceFieldVariant",                    G_FORCEFIELD_VARIANT);
195 <  addHash( "forceFieldFileName",                    G_FORCEFIELD_FILENAME);
196 <  
138 >  command_table.insert(CommandMapType::value_type("forceField", G_FORCEFIELD));
139 >  command_table.insert(CommandMapType::value_type("nComponents", G_NCOMPONENTS));
140 >  command_table.insert(CommandMapType::value_type("targetTemp", G_TARGETTEMP));
141 >  command_table.insert(CommandMapType::value_type("ensemble", G_ENSEMBLE));
142 >  command_table.insert(CommandMapType::value_type("dt", G_DT));
143 >  command_table.insert(CommandMapType::value_type("runTime", G_RUNTIME));
144 >  command_table.insert(CommandMapType::value_type("initialConfig", G_INITIALCONFIG));
145 >  command_table.insert(CommandMapType::value_type("finalConfig", G_FINALCONFIG));
146 >  command_table.insert(CommandMapType::value_type("nMol", G_NMOL));
147 >  command_table.insert(CommandMapType::value_type("density", G_DENSITY));
148 >  command_table.insert(CommandMapType::value_type("box", G_BOX));
149 >  command_table.insert(CommandMapType::value_type("boxX", G_BOXX));
150 >  command_table.insert(CommandMapType::value_type("boxY", G_BOXY));
151 >  command_table.insert(CommandMapType::value_type("boxZ", G_BOXZ));
152 >  command_table.insert(CommandMapType::value_type("sampleTime", G_SAMPLETIME));
153 >  command_table.insert(CommandMapType::value_type("resetTime", G_RESETTIME));
154 >  command_table.insert(CommandMapType::value_type("statusTime", G_STATUSTIME));
155 >  command_table.insert(CommandMapType::value_type("cutoffRadius", G_RCUT));
156 >  command_table.insert(CommandMapType::value_type("switchingRadius", G_RSW));
157 >  command_table.insert(CommandMapType::value_type("dielectric", G_DIELECTRIC));
158 >  command_table.insert(CommandMapType::value_type("tempSet", G_TEMPSET));
159 >  command_table.insert(CommandMapType::value_type("thermalTime", G_THERMALTIME));
160 >  command_table.insert(CommandMapType::value_type("mixingRule", G_MIXINGRULE));
161 >  command_table.insert(CommandMapType::value_type("usePeriodicBoundaryConditions", G_USEPBC));
162 >  command_table.insert(CommandMapType::value_type("useReactionField", G_USERF));
163 >  command_table.insert(CommandMapType::value_type("targetPressure", G_TARGETPRESSURE));
164 >  command_table.insert(CommandMapType::value_type("tauThermostat", G_TAUTHERMOSTAT));
165 >  command_table.insert(CommandMapType::value_type("tauBarostat", G_TAUBAROSTAT));
166 >  command_table.insert(CommandMapType::value_type("zconsTime", G_ZCONSTIME));
167 >  command_table.insert(CommandMapType::value_type("nZconstraints", G_NZCONSTRAINTS));
168 >  command_table.insert(CommandMapType::value_type("zconsTol", G_ZCONSTOL));
169 >  command_table.insert(CommandMapType::value_type("zconsForcePolicy", G_ZCONSFORCEPOLICY));
170 >  command_table.insert(CommandMapType::value_type("seed", G_SEED));
171 >  command_table.insert(CommandMapType::value_type("useInitialTime", G_USEINITTIME));
172 >  command_table.insert(CommandMapType::value_type("useInitialExtendedSystemState", G_USEINIT_XS_STATE));
173 >  command_table.insert(CommandMapType::value_type("orthoBoxTolerance", G_ORTHOBOXTOLERANCE));
174 >  command_table.insert(CommandMapType::value_type("minimizer", G_MINIMIZER));
175 >  command_table.insert(CommandMapType::value_type("minimizerMaxIter", G_MIN_MAXITER));
176 >  command_table.insert(CommandMapType::value_type("minimizerWriteFrq", G_MIN_WRITEFRQ));
177 >  command_table.insert(CommandMapType::value_type("minimizerStepSize", G_MIN_STEPSIZE));
178 >  command_table.insert(CommandMapType::value_type("minimizerFTol", G_MIN_FTOL));
179 >  command_table.insert(CommandMapType::value_type("minimizerGTol", G_MIN_GTOL));
180 >  command_table.insert(CommandMapType::value_type("minimizerLSTol", G_MIN_LSTOL));
181 >  command_table.insert(CommandMapType::value_type("minimizerLSMaxIter", G_MIN_LSMAXITER));
182 >  command_table.insert(CommandMapType::value_type("zconsGap", G_ZCONSGAP));
183 >  command_table.insert(CommandMapType::value_type("zconsFixtime", G_ZCONSFIXTIME));
184 >  command_table.insert(CommandMapType::value_type("zconsUsingSMD", G_ZCONSUSINGSMD));
185 >  command_table.insert(CommandMapType::value_type("useSolidThermInt", G_USE_SOLID_THERM_INT));
186 >  command_table.insert(CommandMapType::value_type("useLiquidThermInt", G_USE_LIQUID_THERM_INT));
187 >  command_table.insert(CommandMapType::value_type("thermodynamicIntegrationLambda", G_THERM_INT_LAMBDA));
188 >  command_table.insert(CommandMapType::value_type("thermodynamicIntegrationK", G_THERM_INT_K));
189 >  command_table.insert(CommandMapType::value_type("forceFieldVariant", G_FORCEFIELD_VARIANT));
190 >  command_table.insert(CommandMapType::value_type("forceFieldFileName", G_FORCEFIELD_FILENAME));
191 >  command_table.insert(CommandMapType::value_type("thermIntDistSpringConst", G_THERM_INT_DIST_SPRING));
192 >  command_table.insert(CommandMapType::value_type("thermIntThetaSpringConst", G_THERM_INT_THETA_SPRING));
193 >  command_table.insert(CommandMapType::value_type("thermIntOmegaSpringConst", G_THERM_INT_OMEGA_SPRING));
194 >  command_table.insert(CommandMapType::value_type("targetStress", G_SURFACETENSION));
195 >
196 >
197    strcpy( mixingRule,"standard");  //default mixing rules to standard.
198    usePBC = 1; //default  periodic boundry conditions to on
199    useRF  = 0;
# Line 255 | Line 251 | void Globals::initalize(){
251    have_thermodynamic_integration_k = 0;
252    have_forcefield_variant = 0;
253    have_forcefield_filename = 0;
254 <
254 >  have_dist_spring_constant =  0;
255 >  have_theta_spring_constant = 0;
256 >  have_omega_spring_constant = 0;
257 >  have_surface_tension = 0;
258   }
259  
260   int Globals::newComponent( event* the_event ){
# Line 403 | Line 402 | int Globals::globalAssign( event* the_event ){
402    char err[300];
403    
404    token = 0;
405 <  key = hash( lhs );
406 <  if( command_table[key] != NULL ) token = command_table[key]->match( lhs );
405 >
406 >  CommandMapType::iterator iter;
407 >  std::string keyword(lhs);
408 >  iter = command_table.find(keyword);
409 >  if (iter != command_table.end()) {
410 >    token = iter->second;
411 >  }
412    
413    if( token ){
414      
# Line 1248 | Line 1252 | int Globals::globalAssign( event* the_event ){
1252        switch( the_type ){
1253          
1254        case STRING:
1255 <   strcpy(zconsForcePolicy, the_event->evt.asmt.rhs.sval);
1255 >        strcpy(zconsForcePolicy, the_event->evt.asmt.rhs.sval);
1256  
1257 <   for(int i = 0; zconsForcePolicy[i] != '\0'; i++)
1258 <        {
1259 <      zconsForcePolicy[i] = toupper(zconsForcePolicy[i]);
1260 <   }
1257 >        for(int i = 0; zconsForcePolicy[i] != '\0'; i++)
1258 >          {
1259 >            zconsForcePolicy[i] = toupper(zconsForcePolicy[i]);
1260 >          }
1261          have_zcons_force_policy = 1;
1262 <   return 1;
1262 >        return 1;
1263          break;
1264          
1265        case DOUBLE:
# Line 1606 | Line 1610 | int Globals::globalAssign( event* the_event ){
1610        switch( the_type ){
1611          
1612        case STRING:
1613 <   the_event->err_msg =
1613 >        the_event->err_msg =
1614            strdup( "Error in parsing meta-data file!\n\tseed is not a string.\n" );
1615          return 0;
1616 <   return 0;
1616 >        return 0;
1617          break;
1618          
1619        case DOUBLE:
1620 <   have_seed = 1;
1621 <   seed = (int)the_event->evt.asmt.rhs.dval;
1620 >        have_seed = 1;
1621 >        seed = (int)the_event->evt.asmt.rhs.dval;
1622          return 1;
1623          break;
1624          
1625        case INT:
1626 <   have_seed = 1;
1627 <   seed =  the_event->evt.asmt.rhs.ival ;
1626 >        have_seed = 1;
1627 >        seed =  the_event->evt.asmt.rhs.ival ;
1628          return 1;
1629          break;
1630          
# Line 1724 | Line 1728 | int Globals::globalAssign( event* the_event ){
1728          return 0;
1729          break;
1730        }
1731 <      break;      
1731 >      break;  
1732 >  
1733      case G_FORCEFIELD_VARIANT:
1734        if( the_type == STRING ){
1735          strcpy( forcefield_variant, the_event->evt.asmt.rhs.sval );
# Line 1749 | Line 1754 | int Globals::globalAssign( event* the_event ){
1754          strdup( "Error in parsing meta-data file!\n\tforceFieldFileName was not a string assignment.\n" );
1755        return 0;
1756        break;      
1757 +
1758 +    case G_THERM_INT_DIST_SPRING:
1759 +      switch( the_type ){
1760 +        
1761 +      case STRING:
1762 +        the_event->err_msg =
1763 +          strdup( "Error in parsing meta-data file!\n\tthermIntDistSpringConst is not a double or int.\n" );
1764 +        return 1;
1765 +        break;
1766 +        
1767 +      case DOUBLE:
1768 +        therm_int_dist_spring = the_event->evt.asmt.rhs.dval;
1769 +        have_dist_spring_constant = 1;
1770 +        return 1;
1771 +        break;
1772 +        
1773 +      case INT:
1774 +        therm_int_dist_spring = (double)the_event->evt.asmt.rhs.dval;
1775 +        have_dist_spring_constant = 1;
1776 +        return 1;
1777 +        break;
1778 +        
1779 +      default:
1780 +        the_event->err_msg =
1781 +          strdup( "Error in parsing meta-data file!\n\tthermIntDistSpringConst unrecognized.\n" );
1782 +        return 0;
1783 +        break;
1784 +      }
1785 +      break;  
1786 +
1787 +    case G_THERM_INT_THETA_SPRING:
1788 +      switch( the_type ){
1789 +        
1790 +      case STRING:
1791 +        the_event->err_msg =
1792 +          strdup( "Error in parsing meta-data file!\n\tthermIntThetaSpringConst is not a double or int.\n" );
1793 +        return 1;
1794 +        break;
1795 +        
1796 +      case DOUBLE:
1797 +        therm_int_theta_spring = the_event->evt.asmt.rhs.dval;
1798 +        have_theta_spring_constant = 1;
1799 +        return 1;
1800 +        break;
1801 +        
1802 +      case INT:
1803 +        therm_int_theta_spring = (double)the_event->evt.asmt.rhs.dval;
1804 +        have_theta_spring_constant = 1;
1805 +        return 1;
1806 +        break;
1807 +        
1808 +      default:
1809 +        the_event->err_msg =
1810 +          strdup( "Error in parsing meta-data file!\n\tthermIntThetaSpringConst unrecognized.\n" );
1811 +        return 0;
1812 +        break;
1813 +      }
1814 +      break;
1815 +
1816 +    case G_THERM_INT_OMEGA_SPRING:
1817 +      switch( the_type ){
1818 +        
1819 +      case STRING:
1820 +        the_event->err_msg =
1821 +          strdup( "Error in parsing meta-data file!\n\tthermIntOmegaSpringConst is not a double or int.\n" );
1822 +        return 1;
1823 +        break;
1824 +        
1825 +      case DOUBLE:
1826 +        therm_int_omega_spring = the_event->evt.asmt.rhs.dval;
1827 +        have_omega_spring_constant = 1;
1828 +        return 1;
1829 +        break;
1830 +        
1831 +      case INT:
1832 +        therm_int_omega_spring = (double)the_event->evt.asmt.rhs.dval;
1833 +        have_omega_spring_constant = 1;
1834 +        return 1;
1835 +        break;
1836 +        
1837 +      default:
1838 +        the_event->err_msg =
1839 +          strdup( "Error in parsing meta-data file!\n\tthermIntOmegaSpringConst unrecognized.\n" );
1840 +        return 0;
1841 +        break;
1842 +      }
1843 +      break;  
1844 +
1845 +    case G_SURFACETENSION:
1846 +        switch( the_type ){
1847 +      
1848 +        case STRING:
1849 +          the_event->err_msg =
1850 +            strdup( "Error in parsing meta-data file!\n\tsurfaceTension is not a double or int.\n" );
1851 +          return 1;
1852 +          break;
1853 +          
1854 +        case DOUBLE:
1855 +          surface_tension= the_event->evt.asmt.rhs.dval;
1856 +          have_surface_tension = 1;
1857 +          return 1;
1858 +          break;
1859 +          
1860 +        case INT:
1861 +          surface_tension = (double)the_event->evt.asmt.rhs.dval;
1862 +          have_surface_tension = 1;
1863 +          return 1;
1864 +          break;
1865 +          
1866 +        default:
1867 +          the_event->err_msg =
1868 +            strdup( "Error in parsing meta-data file!\n\tsurfaceTension unrecognized.\n" );
1869 +          return 0;
1870 +          break;
1871 +        }
1872 +        break;
1873 +        
1874 +
1875 +      
1876        // add more token cases here.      
1877      }
1878    }
# Line 1840 | Line 1964 | int Globals::hash( char* text ){
1964    return 1;
1965   }
1966  
1843 int Globals::hash( char* text ){
1844
1845  register unsigned short int i = 0; // loop counter
1846  int key = 0; // the hash key
1847  
1848  while( text[i] != '\0' ){
1849    
1850    key = ( ( key << hash_shift ) + text[i] ) % hash_size;
1851    
1852    i++;
1853  }
1854  
1855  if( key < 0 ){
1856
1857    // if the key is less than zero, we've had an overflow error
1858
1859    sprintf( painCave.errMsg,
1860             "There has been an overflow error in the Globals' hash key.");
1861    painCave.isFatal = 1;
1862    simError();
1863 #ifdef IS_MPI
1864    if( painCave.isEventLoop ){
1865      if( worldRank == 0 ) mpiInterfaceExit();
1866    }
1867 #endif //is_mpi
1868  }
1869  
1870  return key;
1871 }
1872
1873 void Globals::addHash( char* text, int token ){
1874
1875  int key;
1876  LinkedCommand* the_element;
1877
1878  the_element = new LinkedCommand;
1879  the_element->setValues( text, token );
1880
1881  key = hash( text );
1882
1883  the_element->setNext( command_table[key] );
1884  command_table[key] = the_element;
1885 }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines