You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

56 lines
1.2 KiB

  1. #include <iostream>
  2. #include <StormEigen/Core>
  3. using namespace StormEigen;
  4. #ifndef SCALAR
  5. #define SCALAR float
  6. #endif
  7. #ifndef SIZE
  8. #define SIZE 10000
  9. #endif
  10. #ifndef REPEAT
  11. #define REPEAT 10000
  12. #endif
  13. typedef Matrix<SCALAR, StormEigen::Dynamic, 1> Vec;
  14. using namespace std;
  15. SCALAR E_VDW(const Vec &interactions1, const Vec &interactions2)
  16. {
  17. return (interactions2.cwise()/interactions1)
  18. .cwise().cube()
  19. .cwise().square()
  20. .cwise().square()
  21. .sum();
  22. }
  23. int main()
  24. {
  25. //
  26. // 1 2 3 4 ... (interactions)
  27. // ka . . . . ...
  28. // rab . . . . ...
  29. // energy . . . . ...
  30. // ... ... ... ... ... ...
  31. // (variables
  32. // for
  33. // interaction)
  34. //
  35. Vec interactions1(SIZE), interactions2(SIZE); // SIZE is the number of vdw interactions in our system
  36. // SetupCalculations()
  37. SCALAR rab = 1.0;
  38. interactions1.setConstant(2.4);
  39. interactions2.setConstant(rab);
  40. // Energy()
  41. SCALAR energy = 0.0;
  42. for (unsigned int i = 0; i<REPEAT; ++i) {
  43. energy += E_VDW(interactions1, interactions2);
  44. energy *= 1 + 1e-20 * i; // prevent compiler from optimizing the loop
  45. }
  46. cout << "energy = " << energy << endl;
  47. }