vdw_new.cpp
Go to the documentation of this file.
00001 #include <iostream>
00002 #include <Eigen/Core>
00003 
00004 using namespace Eigen;
00005 
00006 #ifndef SCALAR
00007 #define SCALAR float
00008 #endif
00009 
00010 #ifndef SIZE
00011 #define SIZE 10000
00012 #endif
00013 
00014 #ifndef REPEAT
00015 #define REPEAT 10000
00016 #endif
00017 
00018 typedef Matrix<SCALAR, Eigen::Dynamic, 1> Vec;
00019 
00020 using namespace std;
00021 
00022 SCALAR E_VDW(const Vec &interactions1, const Vec &interactions2)
00023 {
00024   return (interactions2.cwise()/interactions1)
00025          .cwise().cube()
00026          .cwise().square()
00027          .cwise().square()
00028          .sum();
00029 }
00030 
00031 int main() 
00032 {
00033   //
00034   //          1   2   3   4  ... (interactions)
00035   // ka       .   .   .   .  ...
00036   // rab      .   .   .   .  ...
00037   // energy   .   .   .   .  ...
00038   // ...     ... ... ... ... ...
00039   // (variables
00040   //    for
00041   // interaction)
00042   //
00043   Vec interactions1(SIZE), interactions2(SIZE); // SIZE is the number of vdw interactions in our system
00044   // SetupCalculations()
00045   SCALAR rab = 1.0;  
00046   interactions1.setConstant(2.4);
00047   interactions2.setConstant(rab);
00048   
00049   // Energy()
00050   SCALAR energy = 0.0;
00051   for (unsigned int i = 0; i<REPEAT; ++i) {
00052     energy += E_VDW(interactions1, interactions2);
00053     energy *= 1 + 1e-20 * i; // prevent compiler from optimizing the loop
00054   }
00055   cout << "energy = " << energy << endl;
00056 }


re_vision
Author(s): Dorian Galvez-Lopez
autogenerated on Sun Jan 5 2014 11:33:40