Commit c0721881 by Francois Gygi

Merge changes in iter_cmd functionality from trunk


git-svn-id: http://qboxcode.org/svn/qb/branches/vext@1865 cba15fb0-1239-40c8-b417-11db7ca47a34
parent 1c4af254
......@@ -387,6 +387,30 @@ void BOSampleStepper::step(int niter)
}
// at this point, positions r0, velocities v0 and forces fion are
// consistent
// execute commands in iter_cmd if defined
if ( !iter_cmd_.empty() )
{
if ( iter % iter_cmd_period_ == 0 )
{
// copy positions and velocities from IonicStepper to AtomSet
if ( ionic_stepper )
{
ionic_stepper->set_positions();
ionic_stepper->set_velocities();
}
// command must be terminated with \n
istringstream cmdstream(iter_cmd_ + "\n");
s_.ui->processCmds(cmdstream,"[iter_cmd]",true);
// copy positions and velocities back from AtomSet
if ( ionic_stepper )
{
ionic_stepper->get_positions();
ionic_stepper->get_velocities();
}
}
}
double ekin_ion = 0.0, temp_ion = 0.0;
if ( ionic_stepper )
{
......@@ -1159,17 +1183,6 @@ void BOSampleStepper::step(int niter)
if ( atoms_move )
s_.constraints.update_constraints(dt);
// execute commands in iter_cmd if defined
if ( !s_.ctrl.iter_cmd.empty() )
{
if ( iter % s_.ctrl.iter_cmd_period == 0 )
{
// command must be terminated with \n
istringstream cmdstream(s_.ctrl.iter_cmd + "\n");
s_.ui->processCmds(cmdstream,"[iter_cmd]",true);
}
}
// print iteration time
double time = tm_iter.real();
double tmin = time;
......@@ -1272,17 +1285,10 @@ void BOSampleStepper::step(int niter)
ionic_stepper->compute_v(energy,fion);
// positions r0 and velocities v0 are consistent
}
else
{
// delete wavefunction velocities
if ( s_.wfv != 0 )
delete s_.wfv;
s_.wfv = 0;
}
for ( int ispin = 0; ispin < nspin; ispin++ )
{
delete mlwft[ispin];
delete mlwft[ispin];
}
// delete steppers
......
......@@ -15,7 +15,6 @@
// IonicStepper.h:
//
////////////////////////////////////////////////////////////////////////////////
// $Id: IonicStepper.h,v 1.15 2010-04-16 21:43:11 fgygi Exp $
#ifndef IONICSTEPPER_H
#define IONICSTEPPER_H
......@@ -68,8 +67,9 @@ class IonicStepper
pmass_[is] = atoms_.species_list[is]->mass() * 1822.89;
}
natoms_ = atoms_.size();
atoms_.get_positions(r0_);
atoms_.get_velocities(v0_);
// get positions and velocities from atoms_
get_positions();
get_velocities();
}
double r0(int is, int i) const { return r0_[is][i]; }
......@@ -77,6 +77,10 @@ class IonicStepper
const std::vector<std::vector<double> >& r0(void) const { return r0_; }
const std::vector<std::vector<double> >& v0(void) const { return v0_; }
const std::vector<double>& pmass(void) const { return pmass_; }
void get_positions(void) { atoms_.get_positions(r0_); }
void get_velocities(void) { atoms_.get_velocities(v0_); }
void set_positions(void) { atoms_.set_positions(r0_); }
void set_velocities(void) { atoms_.set_velocities(v0_); }
void setup_constraints(void)
{
......
......@@ -36,6 +36,13 @@ class IterCmd : public Var
int set ( int argc, char **argv )
{
if ( !strcmp(argv[1],"NULL") )
{
// reset iter_cmd to empty string
s->ctrl.iter_cmd.clear();
return 0;
}
// include all arguments until \n
string v;
for ( int i = 1; i < argc; i++ )
......
......@@ -15,7 +15,6 @@
// RunCmd.C:
//
////////////////////////////////////////////////////////////////////////////////
// $Id: RunCmd.C,v 1.11 2010-02-20 23:13:02 fgygi Exp $
#include "RunCmd.h"
#include<iostream>
......@@ -84,6 +83,8 @@ int RunCmd::action(int argc, char **argv)
stepper = new BOSampleStepper(*s,nitscf,nite);
assert(stepper!=0);
stepper->set_iter_cmd(s->ctrl.iter_cmd);
stepper->set_iter_cmd_period(s->ctrl.iter_cmd_period);
if ( atomic_density )
stepper->initialize_density();
......@@ -91,6 +92,14 @@ int RunCmd::action(int argc, char **argv)
s->wf.info(cout,"wavefunction");
stepper->step(niter);
// Delete wave function velocity if not using atoms_dyn = MD
if ( s->ctrl.atoms_dyn != "MD" )
{
if ( s->wfv != 0 )
delete s->wfv;
s->wfv = 0;
}
delete stepper;
return 0;
......
......@@ -39,6 +39,9 @@ class SampleStepper
std::vector<std::vector<double> > fion;
std::valarray<double> sigma_eks, sigma_kin, sigma_ext, sigma;
std::string iter_cmd_;
int iter_cmd_period_;
// Do not allow construction of SampleStepper unrelated to a Sample
SampleStepper(void);
......@@ -50,9 +53,13 @@ class SampleStepper
void print_stress(void);
void compute_sigma(void); // compute kinetic contribution to stress
virtual void initialize_density() {}
virtual EnergyFunctional& ef(void) {}
virtual ChargeDensity& cd(void) {}
void set_iter_cmd(std::string s) { iter_cmd_ = s; }
void set_iter_cmd_period(int i) { iter_cmd_period_ = i; }
SampleStepper(Sample& s);
virtual ~SampleStepper(void);
};
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment