testEnergyFunctional.C 1.87 KB
Newer Older
Francois Gygi committed
1 2 3 4 5
////////////////////////////////////////////////////////////////////////////////
//
// testEnergyFunctional.C
//
////////////////////////////////////////////////////////////////////////////////
6
// $Id: testEnergyFunctional.C,v 1.5 2007-10-19 16:24:06 fgygi Exp $
Francois Gygi committed
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36

#include "Context.h"
#include "Sample.h"
#include "Wavefunction.h"
#include "EnergyFunctional.h"
#include "Timer.h"

#include <iostream>
#include <iomanip>
#include <cassert>
using namespace std;

#ifdef USE_MPI
#include <mpi.h>
#endif

int main(int argc, char **argv)
{
#if USE_MPI
  MPI_Init(&argc,&argv);
#endif
  {
    // use: testEnergyFunctional a0 a1 a2 b0 b1 b2 c0 c1 c2 ecut nel
    assert(argc==12);
    D3vector a(atof(argv[1]),atof(argv[2]),atof(argv[3]));
    D3vector b(atof(argv[4]),atof(argv[5]),atof(argv[6]));
    D3vector c(atof(argv[7]),atof(argv[8]),atof(argv[9]));
    UnitCell cell(a,b,c);
    double ecut = atof(argv[10]);
    int nel = atoi(argv[11]);
37

Francois Gygi committed
38
    Timer tm;
39

Francois Gygi committed
40 41 42 43 44 45 46
    Context ctxt;
    cout << " initial context: " << ctxt;
    Sample s(ctxt);
    s.atoms.addAtom(
      new Atom("G","gaussium",D3vector(0.2,0.3,0),D3vector(0,0,0)));
    s.atoms.listAtoms();
    s.atoms.listSpecies();
47

Francois Gygi committed
48 49
    s.wf.resize(cell,cell,ecut);
    s.wf.set_nel(nel);
50

Francois Gygi committed
51 52 53 54
    if ( ctxt.onpe0() ) cout << " nel: " << s.wf.nel() << endl;

    s.wf.update_occ();
    //s.wf.randomize(0.05);
55

Francois Gygi committed
56 57 58 59 60 61 62 63 64 65
    tm.reset();
    tm.start();
    s.wf.gram();
    tm.stop();
    cout << " Gram: CPU/Real: " << tm.cpu() << " / " << tm.real() << endl;

    tm.reset();
    tm.start();
    EnergyFunctional ef(s);
    tm.stop();
66
    cout << " EnergyFunctional:ctor: CPU/Real: "
Francois Gygi committed
67
         << tm.cpu() << " / " << tm.real() << endl;
68

Francois Gygi committed
69 70 71 72
    tm.reset();
    tm.start();
    cout << " ef.energy(): " << ef.energy() << endl;
    tm.stop();
73
    cout << " EnergyFunctional:energy: CPU/Real: "
Francois Gygi committed
74 75 76 77 78 79
         << tm.cpu() << " / " << tm.real() << endl;
  }
#if USE_MPI
  MPI_Finalize();
#endif
}