testWavefunction.C 3.34 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
// testWavefunction.C
//
////////////////////////////////////////////////////////////////////////////////
Francois Gygi committed
18
// $Id: testWavefunction.C,v 1.9 2008-09-08 15:56:20 fgygi Exp $
Francois Gygi committed
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38

#include "Context.h"
#include "Wavefunction.h"
#include "SlaterDet.h"
#include "Timer.h"

#include <iostream>
#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
  {
39
    // use:
Francois Gygi committed
40 41 42 43 44 45 46 47 48 49 50 51
    // testWavefunction a0 a1 a2 b0 b1 b2 c0 c1 c2 ecut nel nempty nspin nkp
    assert(argc==15);
    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);
    cout << " volume: " << cell.volume() << endl;
    double ecut = atof(argv[10]);
    int nel = atoi(argv[11]);
    int nempty = atoi(argv[12]);
    int nspin = atoi(argv[13]);
    int nkp = atoi(argv[14]);
52

Francois Gygi committed
53
    Context ctxt;
54

Francois Gygi committed
55 56
    Wavefunction wf(ctxt);
    Timer tm;
57

Francois Gygi committed
58 59 60
    tm.reset(); tm.start();
    wf.resize(cell,cell,ecut);
    tm.stop();
61
    cout << " wf.resize: CPU/Real: "
Francois Gygi committed
62 63 64 65 66
         << tm.cpu() << " / " << tm.real() << endl;

    tm.reset(); tm.start();
    wf.set_nel(nel);
    tm.stop();
67
    cout << " wf.set_nel: CPU/Real: "
Francois Gygi committed
68
         << tm.cpu() << " / " << tm.real() << endl;
69

Francois Gygi committed
70 71 72
    tm.reset(); tm.start();
    wf.set_nspin(nspin);
    tm.stop();
73
    cout << " wf.set_nspin: CPU/Real: "
Francois Gygi committed
74
         << tm.cpu() << " / " << tm.real() << endl;
75

Francois Gygi committed
76 77 78 79
    for ( int ikp = 0; ikp < nkp-1; ikp++ )
    {
      wf.add_kpoint(D3vector((0.5*(ikp+1))/(nkp-1),0,0),1.0);
    }
80

Francois Gygi committed
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
    for ( int ispin = 0; ispin < wf.nspin(); ispin++ )
    {
      for ( int ikp = 0; ikp < wf.nkp(); ikp++ )
      {
        if ( wf.sd(ispin,ikp) != 0 && wf.sdcontext(ispin,ikp)->active() )
        {
          cout << "wf.sd(ispin=" << ispin << ",ikp=" << ikp << "): "
               << wf.sd(ispin,ikp)->c().m() << "x"
               << wf.sd(ispin,ikp)->c().n() << endl;
          cout << ctxt.mype() << ":"
               << " sdcontext[" << ispin << "][" << ikp << "]: "
               << wf.sd(ispin,ikp)->context();
        }
      }
    }

    tm.reset();
    tm.start();
    wf.randomize(0.1);
    tm.stop();
101
    cout << " wf.randomize: CPU/Real: "
Francois Gygi committed
102 103 104 105 106
         << tm.cpu() << " / " << tm.real() << endl;

    tm.reset();
    tm.start();
    wf.gram();
107
    cout << " wf.gram: CPU/Real: "
Francois Gygi committed
108
         << tm.cpu() << " / " << tm.real() << endl;
109

Francois Gygi committed
110 111 112 113
    cout << " copy constructor...";
    Wavefunction wfm(wf);
    cout << "done" << endl;
    wfm.gram();
114

Francois Gygi committed
115 116 117 118 119 120 121 122
#if 0
    wf.randomize(0.1);
    wf.update_occ(false);
    for ( int ikp = 0; ikp < wf.nkp(); ikp++ )
    {
      if ( wf.sd[ikp] != 0 )
        cout << " ekin[" << ikp << "]: " << wf.sd[ikp]->ekin() << endl;
    }
123

Francois Gygi committed
124 125 126 127 128 129 130

#endif
  }
#if USE_MPI
  MPI_Finalize();
#endif
}