RunCmd.C 2.38 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
// RunCmd.C:
//
////////////////////////////////////////////////////////////////////////////////

#include "RunCmd.h"
#include<iostream>
using namespace std;
22 23
#include "BOSampleStepper.h"
#include "CPSampleStepper.h"
Francois Gygi committed
24 25 26 27 28 29

#include<ctime>
#include<cassert>

int RunCmd::action(int argc, char **argv)
{
30
  if ( argc < 2 || argc > 5)
Francois Gygi committed
31 32
  {
    if ( ui->onpe0() )
33 34 35
      cout << " use: run [-atomic_density] niter" << endl;
      cout << "      run [-atomic_density] niter nitscf" << endl;
      cout << "      run [-atomic_density] niter nitscf nite" << endl;
Francois Gygi committed
36 37
    return 1;
  }
38

Francois Gygi committed
39 40 41
  if ( s->wf.nst() == 0 )
  {
    if ( ui->onpe0() )
42
      cout << " RunCmd: no states, cannot run" << endl;
Francois Gygi committed
43 44
    return 1;
  }
45 46 47
  if ( s->wf.ecut() == 0.0 )
  {
    if ( ui->onpe0() )
48
      cout << " RunCmd: ecut = 0.0, cannot run" << endl;
49 50
    return 1;
  }
51 52 53 54 55 56
  if ( s->wf.cell().volume() == 0.0 )
  {
    if ( ui->onpe0() )
      cout << " RunCmd: volume = 0.0, cannot run" << endl;
    return 1;
  }
57

58
  SampleStepper* stepper;
59

60 61 62 63 64 65 66 67 68 69
  int iarg = 1;
  bool atomic_density = false;
  if ( !strcmp(argv[iarg],"-atomic_density") )
  {
    atomic_density = true;
    iarg++;
    argc--;
  }

  int niter = atoi(argv[iarg]);
70
  int nite = 0;
Francois Gygi committed
71
  int nitscf = 1;
72 73
  if ( argc == 3 )
  {
Francois Gygi committed
74
    // run niter nitscf
75
    nitscf = atoi(argv[iarg+1]);
Francois Gygi committed
76 77 78 79
  }
  else if ( argc == 4 )
  {
    // run niter nitscf nite
80 81
    nitscf = atoi(argv[iarg+1]);
    nite = atoi(argv[iarg+2]);
82
  }
Francois Gygi committed
83 84 85

  s->extforces.setup(s->atoms);

86
  if ( s->ctrl.wf_dyn == "MD" )
Francois Gygi committed
87
    stepper = new CPSampleStepper(*s);
88
  else
Francois Gygi committed
89
    stepper = new BOSampleStepper(*s,nitscf,nite);
90

91
  assert(stepper!=0);
92 93
  stepper->set_iter_cmd(s->ctrl.iter_cmd);
  stepper->set_iter_cmd_period(s->ctrl.iter_cmd_period);
94

95 96 97
  if ( atomic_density )
    stepper->initialize_density();

98
  s->wf.info(cout,"wavefunction");
99
  stepper->step(niter);
100

101
  delete stepper;
102

Francois Gygi committed
103 104
  return 0;
}