# | Line 1 | Line 1 | |
---|---|---|
1 | + | /* |
2 | + | * Copyright (c) 2005 The University of Notre Dame. All Rights Reserved. |
3 | + | * |
4 | + | * The University of Notre Dame grants you ("Licensee") a |
5 | + | * non-exclusive, royalty free, license to use, modify and |
6 | + | * redistribute this software in source and binary code form, provided |
7 | + | * that the following conditions are met: |
8 | + | * |
9 | + | * 1. Acknowledgement of the program authors must be made in any |
10 | + | * publication of scientific results based in part on use of the |
11 | + | * program. An acceptable form of acknowledgement is citation of |
12 | + | * the article in which the program was described (Matthew |
13 | + | * A. Meineke, Charles F. Vardeman II, Teng Lin, Christopher |
14 | + | * J. Fennell and J. Daniel Gezelter, "OOPSE: An Object-Oriented |
15 | + | * Parallel Simulation Engine for Molecular Dynamics," |
16 | + | * J. Comput. Chem. 26, pp. 252-271 (2005)) |
17 | + | * |
18 | + | * 2. Redistributions of source code must retain the above copyright |
19 | + | * notice, this list of conditions and the following disclaimer. |
20 | + | * |
21 | + | * 3. Redistributions in binary form must reproduce the above copyright |
22 | + | * notice, this list of conditions and the following disclaimer in the |
23 | + | * documentation and/or other materials provided with the |
24 | + | * distribution. |
25 | + | * |
26 | + | * This software is provided "AS IS," without a warranty of any |
27 | + | * kind. All express or implied conditions, representations and |
28 | + | * warranties, including any implied warranty of merchantability, |
29 | + | * fitness for a particular purpose or non-infringement, are hereby |
30 | + | * excluded. The University of Notre Dame and its licensors shall not |
31 | + | * be liable for any damages suffered by licensee as a result of |
32 | + | * using, modifying or distributing the software or its |
33 | + | * derivatives. In no event will the University of Notre Dame or its |
34 | + | * licensors be liable for any lost revenue, profit or data, or for |
35 | + | * direct, indirect, special, consequential, incidental or punitive |
36 | + | * damages, however caused and regardless of the theory of liability, |
37 | + | * arising out of the use of or inability to use software, even if the |
38 | + | * University of Notre Dame has been advised of the possibility of |
39 | + | * such damages. |
40 | + | */ |
41 | + | |
42 | #include <stdlib.h> | |
43 | #include <stdio.h> | |
44 | #include <string.h> | |
45 | ||
46 | < | #include "Globals.hpp" |
47 | < | #include "simError.h" |
46 | > | #include "io/Globals.hpp" |
47 | > | #include "utils/simError.h" |
48 | #ifdef IS_MPI | |
49 | < | #include "mpiBASS.h" |
49 | > | #include "io/mpiBASS.h" |
50 | #endif // is_mpi | |
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 71 | Line 112 | |
112 | #define G_THERM_INT_LAMBDA 50 | |
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 | ||
120 | Globals::Globals(){ | |
121 | initalize(); | |
# | Line 78 | Line 123 | Globals::~Globals(){ | |
123 | ||
124 | Globals::~Globals(){ | |
125 | int i; | |
81 | – | |
82 | – | for( i=0; i<hash_size; i++ ){ |
83 | – | if( command_table[i] != NULL ) delete command_table[i]; |
84 | – | } |
85 | – | delete[] command_table; |
86 | – | |
126 | if( components != NULL ){ | |
127 | for( i=0; i<n_components; i++ ) delete components[i]; | |
128 | delete[] components; | |
# | Line 93 | Line 132 | void Globals::initalize(){ | |
132 | void Globals::initalize(){ | |
133 | int i; | |
134 | ||
96 | – | hash_size = 23; |
97 | – | hash_shift = 4; |
98 | – | |
135 | components = NULL; | |
136 | ||
137 | < | command_table = new LinkedCommand*[hash_size]; |
138 | < | for( i=0; i<hash_size; i++ ) command_table[i] = NULL; |
139 | < | |
140 | < | addHash( "forceField", G_FORCEFIELD ); |
141 | < | addHash( "nComponents", G_NCOMPONENTS ); |
142 | < | addHash( "targetTemp", G_TARGETTEMP ); |
143 | < | addHash( "ensemble", G_ENSEMBLE ); |
144 | < | |
145 | < | addHash( "dt", G_DT ); |
146 | < | addHash( "runTime", G_RUNTIME ); |
147 | < | |
148 | < | addHash( "initialConfig", G_INITIALCONFIG ); |
149 | < | addHash( "finalConfig", G_FINALCONFIG ); |
150 | < | addHash( "nMol", G_NMOL ); |
151 | < | addHash( "density", G_DENSITY ); |
152 | < | addHash( "box", G_BOX ); |
153 | < | addHash( "boxX", G_BOXX ); |
154 | < | addHash( "boxY", G_BOXY ); |
155 | < | addHash( "boxZ", G_BOXZ ); |
156 | < | addHash( "sampleTime", G_SAMPLETIME ); |
157 | < | addHash( "resetTime", G_RESETTIME ); |
158 | < | addHash( "statusTime", G_STATUSTIME ); |
159 | < | addHash( "cutoffRadius", G_RCUT ); |
160 | < | addHash( "switchingRadius", G_RSW ); |
161 | < | addHash( "dielectric", G_DIELECTRIC ); |
162 | < | addHash( "tempSet", G_TEMPSET ); |
163 | < | addHash( "thermalTime", G_THERMALTIME ); |
164 | < | addHash( "mixingRule", G_MIXINGRULE); |
165 | < | addHash( "usePeriodicBoundaryConditions", G_USEPBC); |
166 | < | addHash( "useReactionField", G_USERF ); |
167 | < | addHash( "targetPressure", G_TARGETPRESSURE); |
168 | < | addHash( "tauThermostat", G_TAUTHERMOSTAT); |
169 | < | addHash( "tauBarostat", G_TAUBAROSTAT); |
170 | < | addHash( "zconsTime", G_ZCONSTIME); |
171 | < | addHash( "nZconstraints", G_NZCONSTRAINTS); |
172 | < | addHash( "zconsTol", G_ZCONSTOL); |
173 | < | addHash( "zconsForcePolicy", G_ZCONSFORCEPOLICY); |
174 | < | addHash( "seed", G_SEED); |
175 | < | addHash( "useInitialTime", G_USEINITTIME); |
176 | < | addHash( "useInitialExtendedSystemState", G_USEINIT_XS_STATE); |
177 | < | addHash( "orthoBoxTolerance", G_ORTHOBOXTOLERANCE); |
178 | < | addHash( "minimizer", G_MINIMIZER); |
179 | < | addHash( "minimizerMaxIter", G_MIN_MAXITER); |
180 | < | addHash( "minimizerWriteFrq", G_MIN_WRITEFRQ); |
181 | < | addHash( "minimizerStepSize", G_MIN_STEPSIZE); |
182 | < | addHash( "minimizerFTol", G_MIN_FTOL); |
183 | < | addHash( "minimizerGTol", G_MIN_GTOL); |
184 | < | addHash( "minimizerLSTol", G_MIN_LSTOL); |
185 | < | addHash( "minimizerLSMaxIter", G_MIN_LSMAXITER); |
186 | < | addHash( "zconsGap", G_ZCONSGAP); |
187 | < | addHash( "zconsFixtime", G_ZCONSFIXTIME); |
188 | < | addHash( "zconsUsingSMD", G_ZCONSUSINGSMD); |
189 | < | addHash( "useSolidThermInt", G_USE_SOLID_THERM_INT); |
190 | < | addHash( "useLiquidThermInt", G_USE_LIQUID_THERM_INT); |
191 | < | addHash( "thermodynamicIntegrationLambda", G_THERM_INT_LAMBDA); |
192 | < | addHash( "thermodynamicIntegrationK", G_THERM_INT_K); |
157 | < | addHash( "forceFieldVariant", G_FORCEFIELD_VARIANT); |
137 | > | command_table.insert(CommandMapType::value_type("forceField", G_FORCEFIELD)); |
138 | > | command_table.insert(CommandMapType::value_type("nComponents", G_NCOMPONENTS)); |
139 | > | command_table.insert(CommandMapType::value_type("targetTemp", G_TARGETTEMP)); |
140 | > | command_table.insert(CommandMapType::value_type("ensemble", G_ENSEMBLE)); |
141 | > | command_table.insert(CommandMapType::value_type("dt", G_DT)); |
142 | > | command_table.insert(CommandMapType::value_type("runTime", G_RUNTIME)); |
143 | > | command_table.insert(CommandMapType::value_type("initialConfig", G_INITIALCONFIG)); |
144 | > | command_table.insert(CommandMapType::value_type("finalConfig", G_FINALCONFIG)); |
145 | > | command_table.insert(CommandMapType::value_type("nMol", G_NMOL)); |
146 | > | command_table.insert(CommandMapType::value_type("density", G_DENSITY)); |
147 | > | command_table.insert(CommandMapType::value_type("box", G_BOX)); |
148 | > | command_table.insert(CommandMapType::value_type("boxX", G_BOXX)); |
149 | > | command_table.insert(CommandMapType::value_type("boxY", G_BOXY)); |
150 | > | command_table.insert(CommandMapType::value_type("boxZ", G_BOXZ)); |
151 | > | command_table.insert(CommandMapType::value_type("sampleTime", G_SAMPLETIME)); |
152 | > | command_table.insert(CommandMapType::value_type("resetTime", G_RESETTIME)); |
153 | > | command_table.insert(CommandMapType::value_type("statusTime", G_STATUSTIME)); |
154 | > | command_table.insert(CommandMapType::value_type("cutoffRadius", G_RCUT)); |
155 | > | command_table.insert(CommandMapType::value_type("switchingRadius", G_RSW)); |
156 | > | command_table.insert(CommandMapType::value_type("dielectric", G_DIELECTRIC)); |
157 | > | command_table.insert(CommandMapType::value_type("tempSet", G_TEMPSET)); |
158 | > | command_table.insert(CommandMapType::value_type("thermalTime", G_THERMALTIME)); |
159 | > | command_table.insert(CommandMapType::value_type("mixingRule", G_MIXINGRULE)); |
160 | > | command_table.insert(CommandMapType::value_type("usePeriodicBoundaryConditions", G_USEPBC)); |
161 | > | command_table.insert(CommandMapType::value_type("useReactionField", G_USERF)); |
162 | > | command_table.insert(CommandMapType::value_type("targetPressure", G_TARGETPRESSURE)); |
163 | > | command_table.insert(CommandMapType::value_type("tauThermostat", G_TAUTHERMOSTAT)); |
164 | > | command_table.insert(CommandMapType::value_type("tauBarostat", G_TAUBAROSTAT)); |
165 | > | command_table.insert(CommandMapType::value_type("zconsTime", G_ZCONSTIME)); |
166 | > | command_table.insert(CommandMapType::value_type("nZconstraints", G_NZCONSTRAINTS)); |
167 | > | command_table.insert(CommandMapType::value_type("zconsTol", G_ZCONSTOL)); |
168 | > | command_table.insert(CommandMapType::value_type("zconsForcePolicy", G_ZCONSFORCEPOLICY)); |
169 | > | command_table.insert(CommandMapType::value_type("seed", G_SEED)); |
170 | > | command_table.insert(CommandMapType::value_type("useInitialTime", G_USEINITTIME)); |
171 | > | command_table.insert(CommandMapType::value_type("useInitialExtendedSystemState", G_USEINIT_XS_STATE)); |
172 | > | command_table.insert(CommandMapType::value_type("orthoBoxTolerance", G_ORTHOBOXTOLERANCE)); |
173 | > | command_table.insert(CommandMapType::value_type("minimizer", G_MINIMIZER)); |
174 | > | command_table.insert(CommandMapType::value_type("minimizerMaxIter", G_MIN_MAXITER)); |
175 | > | command_table.insert(CommandMapType::value_type("minimizerWriteFrq", G_MIN_WRITEFRQ)); |
176 | > | command_table.insert(CommandMapType::value_type("minimizerStepSize", G_MIN_STEPSIZE)); |
177 | > | command_table.insert(CommandMapType::value_type("minimizerFTol", G_MIN_FTOL)); |
178 | > | command_table.insert(CommandMapType::value_type("minimizerGTol", G_MIN_GTOL)); |
179 | > | command_table.insert(CommandMapType::value_type("minimizerLSTol", G_MIN_LSTOL)); |
180 | > | command_table.insert(CommandMapType::value_type("minimizerLSMaxIter", G_MIN_LSMAXITER)); |
181 | > | command_table.insert(CommandMapType::value_type("zconsGap", G_ZCONSGAP)); |
182 | > | command_table.insert(CommandMapType::value_type("zconsFixtime", G_ZCONSFIXTIME)); |
183 | > | command_table.insert(CommandMapType::value_type("zconsUsingSMD", G_ZCONSUSINGSMD)); |
184 | > | command_table.insert(CommandMapType::value_type("useSolidThermInt", G_USE_SOLID_THERM_INT)); |
185 | > | command_table.insert(CommandMapType::value_type("useLiquidThermInt", G_USE_LIQUID_THERM_INT)); |
186 | > | command_table.insert(CommandMapType::value_type("thermodynamicIntegrationLambda", G_THERM_INT_LAMBDA)); |
187 | > | command_table.insert(CommandMapType::value_type("thermodynamicIntegrationK", G_THERM_INT_K)); |
188 | > | command_table.insert(CommandMapType::value_type("forceFieldVariant", G_FORCEFIELD_VARIANT)); |
189 | > | command_table.insert(CommandMapType::value_type("forceFieldFileName", G_FORCEFIELD_FILENAME)); |
190 | > | command_table.insert(CommandMapType::value_type("thermIntDistSpringConst", G_THERM_INT_DIST_SPRING)); |
191 | > | command_table.insert(CommandMapType::value_type("thermIntThetaSpringConst", G_THERM_INT_THETA_SPRING)); |
192 | > | command_table.insert(CommandMapType::value_type("thermIntOmegaSpringConst", G_THERM_INT_OMEGA_SPRING)); |
193 | ||
194 | + | |
195 | strcpy( mixingRule,"standard"); //default mixing rules to standard. | |
196 | usePBC = 1; //default periodic boundry conditions to on | |
197 | useRF = 0; | |
# | Line 212 | Line 248 | void Globals::initalize(){ | |
248 | have_thermodynamic_integration_lambda = 0; | |
249 | have_thermodynamic_integration_k = 0; | |
250 | have_forcefield_variant = 0; | |
251 | < | |
251 | > | have_forcefield_filename = 0; |
252 | > | have_dist_spring_constant = 0; |
253 | > | have_theta_spring_constant = 0; |
254 | > | have_omega_spring_constant = 0; |
255 | } | |
256 | ||
257 | int Globals::newComponent( event* the_event ){ | |
# | Line 360 | Line 399 | int Globals::globalAssign( event* the_event ){ | |
399 | char err[300]; | |
400 | ||
401 | token = 0; | |
402 | < | key = hash( lhs ); |
403 | < | if( command_table[key] != NULL ) token = command_table[key]->match( lhs ); |
402 | > | |
403 | > | CommandMapType::iterator iter; |
404 | > | std::string keyword(lhs); |
405 | > | iter = command_table.find(keyword); |
406 | > | if (iter != command_table.end()) { |
407 | > | token = iter->second; |
408 | > | } |
409 | ||
410 | if( token ){ | |
411 | ||
# | Line 1389 | Line 1433 | int Globals::globalAssign( event* the_event ){ | |
1433 | ||
1434 | case STRING: | |
1435 | the_event->err_msg = | |
1436 | < | strdup( "Error in parsing meta-data file!\n\tminimizer_writefrq is not a double or int.\n" ); |
1436 | > | strdup( "Error in parsing meta-data file!\n\tminimizer_writefrq is not an int.\n" ); |
1437 | return 1; | |
1438 | break; | |
1439 | ||
1440 | case DOUBLE: | |
1441 | < | minimizer_writefrq= the_event->evt.asmt.rhs.dval; |
1442 | < | have_minimizer_writefrq = 1; |
1441 | > | the_event->err_msg = |
1442 | > | strdup( "Error in parsing meta-data file!\n\tminimizer_writefrq is not an int.\n" ); |
1443 | return 1; | |
1444 | break; | |
1445 | ||
# | Line 1505 | Line 1549 | int Globals::globalAssign( event* the_event ){ | |
1549 | ||
1550 | case STRING: | |
1551 | the_event->err_msg = | |
1552 | < | strdup( "Error in parsing meta-data file!\n\tminimizer_ls_maxiteration is not a double or int.\n" ); |
1552 | > | strdup( "Error in parsing meta-data file!\n\tminimizer_ls_maxiteration is not an int.\n" ); |
1553 | return 1; | |
1554 | break; | |
1555 | ||
1556 | case DOUBLE: | |
1557 | < | minimizer_ls_maxiteration = the_event->evt.asmt.rhs.dval; |
1558 | < | have_minimizer_ls_maxiteration = 1; |
1557 | > | the_event->err_msg = |
1558 | > | strdup( "Error in parsing meta-data file!\n\tminimizer_ls_maxiteration is not an int.\n" ); |
1559 | return 1; | |
1560 | break; | |
1561 | ||
# | Line 1681 | Line 1725 | int Globals::globalAssign( event* the_event ){ | |
1725 | return 0; | |
1726 | break; | |
1727 | } | |
1728 | < | break; |
1728 | > | break; |
1729 | > | |
1730 | case G_FORCEFIELD_VARIANT: | |
1731 | if( the_type == STRING ){ | |
1732 | strcpy( forcefield_variant, the_event->evt.asmt.rhs.sval ); | |
# | Line 1694 | Line 1739 | int Globals::globalAssign( event* the_event ){ | |
1739 | return 0; | |
1740 | break; | |
1741 | // add more token cases here. | |
1742 | + | |
1743 | + | case G_FORCEFIELD_FILENAME: |
1744 | + | if( the_type == STRING ){ |
1745 | + | strcpy( forcefield_filename, the_event->evt.asmt.rhs.sval ); |
1746 | + | have_forcefield_filename = 1; |
1747 | + | return 1; |
1748 | + | } |
1749 | + | |
1750 | + | the_event->err_msg = |
1751 | + | strdup( "Error in parsing meta-data file!\n\tforceFieldFileName was not a string assignment.\n" ); |
1752 | + | return 0; |
1753 | + | break; |
1754 | + | |
1755 | + | case G_THERM_INT_DIST_SPRING: |
1756 | + | switch( the_type ){ |
1757 | + | |
1758 | + | case STRING: |
1759 | + | the_event->err_msg = |
1760 | + | strdup( "Error in parsing meta-data file!\n\tthermIntDistSpringConst is not a double or int.\n" ); |
1761 | + | return 1; |
1762 | + | break; |
1763 | + | |
1764 | + | case DOUBLE: |
1765 | + | therm_int_dist_spring = the_event->evt.asmt.rhs.dval; |
1766 | + | have_dist_spring_constant = 1; |
1767 | + | return 1; |
1768 | + | break; |
1769 | + | |
1770 | + | case INT: |
1771 | + | therm_int_dist_spring = (double)the_event->evt.asmt.rhs.dval; |
1772 | + | have_dist_spring_constant = 1; |
1773 | + | return 1; |
1774 | + | break; |
1775 | + | |
1776 | + | default: |
1777 | + | the_event->err_msg = |
1778 | + | strdup( "Error in parsing meta-data file!\n\tthermIntDistSpringConst unrecognized.\n" ); |
1779 | + | return 0; |
1780 | + | break; |
1781 | + | } |
1782 | + | break; |
1783 | + | |
1784 | + | case G_THERM_INT_THETA_SPRING: |
1785 | + | switch( the_type ){ |
1786 | + | |
1787 | + | case STRING: |
1788 | + | the_event->err_msg = |
1789 | + | strdup( "Error in parsing meta-data file!\n\tthermIntThetaSpringConst is not a double or int.\n" ); |
1790 | + | return 1; |
1791 | + | break; |
1792 | + | |
1793 | + | case DOUBLE: |
1794 | + | therm_int_theta_spring = the_event->evt.asmt.rhs.dval; |
1795 | + | have_theta_spring_constant = 1; |
1796 | + | return 1; |
1797 | + | break; |
1798 | + | |
1799 | + | case INT: |
1800 | + | therm_int_theta_spring = (double)the_event->evt.asmt.rhs.dval; |
1801 | + | have_theta_spring_constant = 1; |
1802 | + | return 1; |
1803 | + | break; |
1804 | + | |
1805 | + | default: |
1806 | + | the_event->err_msg = |
1807 | + | strdup( "Error in parsing meta-data file!\n\tthermIntThetaSpringConst unrecognized.\n" ); |
1808 | + | return 0; |
1809 | + | break; |
1810 | + | } |
1811 | + | break; |
1812 | + | |
1813 | + | case G_THERM_INT_OMEGA_SPRING: |
1814 | + | switch( the_type ){ |
1815 | + | |
1816 | + | case STRING: |
1817 | + | the_event->err_msg = |
1818 | + | strdup( "Error in parsing meta-data file!\n\tthermIntOmegaSpringConst is not a double or int.\n" ); |
1819 | + | return 1; |
1820 | + | break; |
1821 | + | |
1822 | + | case DOUBLE: |
1823 | + | therm_int_omega_spring = the_event->evt.asmt.rhs.dval; |
1824 | + | have_omega_spring_constant = 1; |
1825 | + | return 1; |
1826 | + | break; |
1827 | + | |
1828 | + | case INT: |
1829 | + | therm_int_omega_spring = (double)the_event->evt.asmt.rhs.dval; |
1830 | + | have_omega_spring_constant = 1; |
1831 | + | return 1; |
1832 | + | break; |
1833 | + | |
1834 | + | default: |
1835 | + | the_event->err_msg = |
1836 | + | strdup( "Error in parsing meta-data file!\n\tthermIntOmegaSpringConst unrecognized.\n" ); |
1837 | + | return 0; |
1838 | + | break; |
1839 | + | } |
1840 | + | break; |
1841 | + | // add more token cases here. |
1842 | } | |
1843 | } | |
1844 | ||
# | Line 1784 | Line 1929 | int Globals::globalEnd( event* the_event ){ | |
1929 | return 1; | |
1930 | } | |
1931 | ||
1787 | – | int Globals::hash( char* text ){ |
1788 | – | |
1789 | – | register unsigned short int i = 0; // loop counter |
1790 | – | int key = 0; // the hash key |
1791 | – | |
1792 | – | while( text[i] != '\0' ){ |
1793 | – | |
1794 | – | key = ( ( key << hash_shift ) + text[i] ) % hash_size; |
1795 | – | |
1796 | – | i++; |
1797 | – | } |
1798 | – | |
1799 | – | if( key < 0 ){ |
1800 | – | |
1801 | – | // if the key is less than zero, we've had an overflow error |
1802 | – | |
1803 | – | sprintf( painCave.errMsg, |
1804 | – | "There has been an overflow error in the Globals' hash key."); |
1805 | – | painCave.isFatal = 1; |
1806 | – | simError(); |
1807 | – | #ifdef IS_MPI |
1808 | – | if( painCave.isEventLoop ){ |
1809 | – | if( worldRank == 0 ) mpiInterfaceExit(); |
1810 | – | } |
1811 | – | #endif //is_mpi |
1812 | – | } |
1813 | – | |
1814 | – | return key; |
1815 | – | } |
1816 | – | |
1817 | – | void Globals::addHash( char* text, int token ){ |
1818 | – | |
1819 | – | int key; |
1820 | – | LinkedCommand* the_element; |
1821 | – | |
1822 | – | the_element = new LinkedCommand; |
1823 | – | the_element->setValues( text, token ); |
1824 | – | |
1825 | – | key = hash( text ); |
1826 | – | |
1827 | – | the_element->setNext( command_table[key] ); |
1828 | – | command_table[key] = the_element; |
1829 | – | } |
– | Removed lines |
+ | Added lines |
< | Changed lines |
> | Changed lines |