@@ -47,18 +47,61 @@ float energy(int natoms, float coords[], float charges[],
4747 return energy_vdw + energy_electrostatic;
4848}
4949
50+ const size_t NATOMS = 8 *8 + 1 ;
51+ const float MAXCOORD = 100.0 ;
52+ const float MAXCHARGE = 2.0 ;
53+
54+ void initialize_positions (float pos[]) {
55+ for (size_t n = 0 ; n < NATOMS*3 ; ++n)
56+ pos[n] = MAXCOORD * (float )rand ()/(float )RAND_MAX;
57+ }
58+
59+ void initialize_charges (float charges[]) {
60+ for (size_t n = 0 ; n < NATOMS; ++n)
61+ // Try to spread on both sides of zero.
62+ charges[n] = MAXCHARGE * (float )rand ()/(float )RAND_MAX - MAXCHARGE/2 ;
63+ }
64+
65+ void initialize_types (int types[]) {
66+ for (size_t n = 0 ; n < NATOMS; ++n)
67+ types[n] = rand () % 2 ;
68+ }
69+
70+ void initialize_exclusions (int nexcluded[], int excluded_indices[]) {
71+ // nonrandom: just exclude each atom from its next.
72+ size_t excluded_atom_index = 0 ;
73+ for (size_t n = 0 ; n < NATOMS; ++n) {
74+ nexcluded[n] = 1 ;
75+ excluded_indices[excluded_atom_index++] = (n+1 ) % NATOMS;
76+ }
77+ }
78+
79+ void display_atoms (float pos[], float charge[], int types[]) {
80+ for (size_t n = 0 ; n < NATOMS; ++n) {
81+ std::cout << " Atom #" << n << " : " ;
82+ std::cout << " Type " << types[n] << " @ " ;
83+ std::cout << " (" << pos[3 *n+0 ] << " ," << pos[3 *n+1 ] << " ," << pos[3 *n+2 ] << " ) " ;
84+ std::cout << " Charge " << charge[n] << std::endl;
85+ }
86+ }
87+
5088int main () {
51- float pos[12 ] = {0.0 , 19.0 ,3.0 , 10.0 , 7.0 , 80.0 ,
52- 20.0 , 15.0 ,17.0 , 25.0 , 44.0 , 23.0 };
53- float charge[4 ] = {0.85 , 0.95 , 1.05 , 1.15 };
54- int types[4 ] = {0 , 1 , 1 , 0 };
55- float cn1[2 ] = {0.5 , 0.7 };
56- float cn2[2 ] = {0.3 , 0.6 };
57- int nexcluded[4 ] = {1 , 1 , 1 , 1 };
58- // just exclude self-interactions.
59- int excluded_indices[4 ] = {0 , 1 , 2 , 3 };
89+ float pos[NATOMS*3 ];
90+ float charge[NATOMS];
91+ int types[NATOMS];
92+ float cn1[4 ] = {0.05 , 0.07 , 0.07 , 0.08 };
93+ float cn2[4 ] = {0.01 , 0.03 , 0.03 , 0.04 };
94+ int nexcluded[NATOMS];
95+ int excluded_indices[NATOMS];
96+
97+ initialize_positions (pos);
98+ initialize_charges (charge);
99+ initialize_types (types);
100+ initialize_exclusions (nexcluded, excluded_indices);
101+
102+ // display_atoms(pos, charge, types);
60103
61- float tenergy = energy (4 , pos, charge, 2 , types, cn1, cn2,
104+ float tenergy = energy (NATOMS , pos, charge, 2 , types, cn1, cn2,
62105 nexcluded, excluded_indices);
63106 std::cout << " Energy: " << tenergy << std::endl;
64107 return 0 ;
0 commit comments