RunCmd.C 2.2 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
// RunCmd.C:
//
////////////////////////////////////////////////////////////////////////////////
Francois Gygi committed
18
// $Id: RunCmd.C,v 1.11 2010-02-20 23:13:02 fgygi Exp $
Francois Gygi committed
19 20 21 22

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

#include<ctime>
#include<cassert>

int RunCmd::action(int argc, char **argv)
{
31
  if ( argc < 2 || argc > 5)
Francois Gygi committed
32 33
  {
    if ( ui->onpe0() )
34 35 36
      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
37 38
    return 1;
  }
39

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

53
  SampleStepper* stepper;
54

55 56 57 58 59 60 61 62 63 64
  int iarg = 1;
  bool atomic_density = false;
  if ( !strcmp(argv[iarg],"-atomic_density") )
  {
    atomic_density = true;
    iarg++;
    argc--;
  }

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

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

81
  if ( s->ctrl.wf_dyn == "MD" )
Francois Gygi committed
82
    stepper = new CPSampleStepper(*s);
83
  else
Francois Gygi committed
84
    stepper = new BOSampleStepper(*s,nitscf,nite);
85

86
  assert(stepper!=0);
87

88 89 90
  if ( atomic_density )
    stepper->initialize_density();

91
  s->wf.info(cout,"wavefunction");
92
  stepper->step(niter);
93

94
  delete stepper;
95

Francois Gygi committed
96 97
  return 0;
}