testEnergyFunctional.C 2.77 KB
Newer Older
Francois Gygi committed
1 2
////////////////////////////////////////////////////////////////////////////////
//
Francois Gygi committed
3 4 5 6
// Copyright (c) 2008 The Regents of the University of California
//
// This file is part of Qbox
//
Francois Gygi committed
7 8
// Qbox is distributed under the terms of the GNU General Public License
// as published by the Free Software Foundation, either version 2 of
Francois Gygi committed
9 10 11 12 13 14
// the License, or (at your option) any later version.
// See the file COPYING in the root directory of this distribution
// or <http://www.gnu.org/licenses/>.
//
////////////////////////////////////////////////////////////////////////////////
//
Francois Gygi committed
15 16 17 18 19 20 21
// testEnergyFunctional.C
//
////////////////////////////////////////////////////////////////////////////////

#include "Context.h"
#include "Sample.h"
#include "Wavefunction.h"
Francois Gygi committed
22
#include "ChargeDensity.h"
Francois Gygi committed
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
#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
Francois Gygi committed
42 43 44 45 46 47
    if ( argc != 12 )
    {
      cout << "use: testEnergyFunctional a0 a1 a2 b0 b1 b2 c0 c1 c2 ecut nel"
           << endl;
      return 1;
    }
Francois Gygi committed
48 49 50 51 52 53
    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]);
54

Francois Gygi committed
55
    Timer tm;
56

Francois Gygi committed
57
    Context ctxt(MPI_COMM_WORLD);
Francois Gygi committed
58 59
    cout << " initial context: " << ctxt;
    Sample s(ctxt);
60

Francois Gygi committed
61 62
    s.wf.resize(cell,cell,ecut);
    s.wf.set_nel(nel);
63

Francois Gygi committed
64 65
    if ( ctxt.onpe0() ) cout << " nel: " << s.wf.nel() << endl;

Francois Gygi committed
66 67
    s.wf.update_occ(0.0);
    s.wf.randomize(0.05);
68

Francois Gygi committed
69 70 71 72 73 74
    tm.reset();
    tm.start();
    s.wf.gram();
    tm.stop();
    cout << " Gram: CPU/Real: " << tm.cpu() << " / " << tm.real() << endl;

Francois Gygi committed
75
    ChargeDensity cd(s.wf);
Francois Gygi committed
76 77
    tm.reset();
    tm.start();
Francois Gygi committed
78 79 80 81 82 83 84 85 86 87 88
    cout << " ChargeDensity::update_density..." << endl;
    cd.update_density();
    tm.stop();
    cout << " ChargeDensity::update_density: CPU/Real: "
         << tm.cpu() << " / " << tm.real() << endl;

    s.ctrl.xc = "LDA";
    s.ctrl.polarization = "OFF";
    tm.reset();
    tm.start();
    EnergyFunctional ef(s,cd);
Francois Gygi committed
89
    tm.stop();
90
    cout << " EnergyFunctional:ctor: CPU/Real: "
Francois Gygi committed
91
         << tm.cpu() << " / " << tm.real() << endl;
92

Francois Gygi committed
93 94
    tm.reset();
    tm.start();
Francois Gygi committed
95 96 97 98 99
    Wavefunction dwf(s.wf);
    vector<vector<double> > fion;
    valarray<double> sigma(6);
    double e = ef.energy(true,dwf,false,fion,false,sigma);
    cout << " ef.energy(): " << e << endl;
Francois Gygi committed
100
    tm.stop();
101
    cout << " EnergyFunctional:energy: CPU/Real: "
Francois Gygi committed
102 103 104 105 106 107
         << tm.cpu() << " / " << tm.real() << endl;
  }
#if USE_MPI
  MPI_Finalize();
#endif
}