Commit edf03449 by mahe

Added IPA to response command. Made slight modification to vext variable to…

Added IPA to response command. Made slight modification to vext variable to facilitate cDFT implementaion.
parent e39dbb70
......@@ -46,7 +46,7 @@ using namespace std;
BOSampleStepper::BOSampleStepper(Sample& s, int nitscf, int nite) :
SampleStepper(s), cd_(s.wf), ef_(s,cd_),
dwf(s.wf), wfv(s.wfv), nitscf_(nitscf), nite_(nite),
update_density_first_(true), update_vxc_(true) {}
update_density_first_(true), update_vh_(true), update_vxc_(true) {}
////////////////////////////////////////////////////////////////////////////////
BOSampleStepper::~BOSampleStepper()
......@@ -848,20 +848,12 @@ void BOSampleStepper::step(int niter)
// at first scf step:
// - update both vh and vxc
// at later steps:
// - update vh
// - update vxc only if update_vxc_ is true
// - update depending of values of update_vh_ and update_vxc_
tmap["update_vhxc"].start();
if ( itscf == 0 )
ef_.update_vhxc(compute_stress);
else
{
if ( update_vxc_ )
ef_.update_vhxc(compute_stress);
else
// update vh only
ef_.update_vh(compute_stress);
}
ef_.update_vhxc(compute_stress, update_vh_, update_vxc_);
tmap["update_vhxc"].stop();
// reset stepper only if multiple non-selfconsistent steps
......
......@@ -43,7 +43,7 @@ class BOSampleStepper : public SampleStepper
IonicStepper* ionic_stepper;
bool update_density_first_;
bool update_vxc_;
bool update_vh_, update_vxc_;
// Do not allow construction of BOSampleStepper unrelated to a Sample
BOSampleStepper(void);
......@@ -55,6 +55,7 @@ class BOSampleStepper : public SampleStepper
void step(int niter);
// initialize density with sum of atomic densities
void initialize_density(void);
void set_update_vh(bool update_vh) { update_vh_ = update_vh; }
void set_update_vxc(bool update_vxc) { update_vxc_ = update_vxc; }
void set_update_density_first(bool update_density_first)
{ update_density_first_ = update_density_first; }
......
......@@ -25,6 +25,7 @@
#include <iomanip>
#include <algorithm> // fill
#include <functional>
#include <fstream>
using namespace std;
////////////////////////////////////////////////////////////////////////////////
......@@ -267,4 +268,4 @@ void ChargeDensity::update_rhog(void)
vft_->forward(&rhotmp[0],&rhog[ispin][0]);
}
}
\ No newline at end of file
}
......@@ -26,6 +26,7 @@
#include <map>
#include "Timer.h"
#include "Context.h"
#include "D3vector.h"
class Wavefunction;
class FourierTransform;
......
......@@ -226,7 +226,7 @@ EnergyFunctional::~EnergyFunctional(void)
}
////////////////////////////////////////////////////////////////////////////////
void EnergyFunctional::update_vhxc(bool compute_stress, bool update_vxc)
void EnergyFunctional::update_vhxc(bool compute_stress, bool update_vh, bool update_vxc)
{
// called when the charge density has changed
// update Hartree and xc potentials using the charge density cd_
......@@ -315,7 +315,7 @@ void EnergyFunctional::update_vhxc(bool compute_stress, bool update_vxc)
ehesum += norm(r) * g2i[ig];
ehepsum += 2.0*real(conj(r)*rp * g2i[ig]);
ehpsum += norm(rp) * g2i[ig];
rhogt[ig] = r+rp;
if ( update_vh ) rhogt[ig] = r+rp;
}
// factor 1/2 from definition of Ehart cancels with half sum over G
// Note: rhogt[ig] includes a factor 1/Omega
......
......@@ -111,11 +111,12 @@ class EnergyFunctional
const ConfinementPotential *confpot(int ikp) const { return cfp[ikp]; }
void update_vhxc(bool compute_stress, bool update_vxc);
void update_vhxc(bool compute_stress, bool update_vh, bool update_vxc);
// update both vh and vxc
void update_vhxc(bool compute_stress) { update_vhxc(compute_stress, true); }
// update only vh
void update_vh(bool compute_stress) { update_vhxc(compute_stress, false); }
void update_vhxc(bool compute_stress)
{
update_vhxc(compute_stress, true, true);
}
void atoms_moved(void);
void cell_moved(void);
......
......@@ -46,7 +46,7 @@ class ExternalPotential
ExternalPotential(Sample& s, std::string name, std::string io="cube",
int nx=0, int ny=0, int nz=0):
s_(s), filename_(name), ecut_(0.0), amplitude_(0.0), magnitude_(0.0), io_(io){
s_(s), filename_(name), ecut_(0.0), amplitude_(1.0), magnitude_(0.0), io_(io){
assert( io_ == "cube" || io == "base64_serial" || io == "base64_parallel" );
if (io != "cube")
{
......
......@@ -38,8 +38,8 @@ using namespace std;
int ResponseCmd::action(int argc, char **argv)
{
// " syntax: response amplitude nitscf [nite]\n\n"
// " syntax: response -vext vext_file [-RPA] [-amplitude a]
// [-io iomode -nx nx -ny ny -nz nz] nitscf [nite]\n\n"
// " syntax: response -vext vext_file [-RPA|-IPA] [-amplitude a]
// [-io iomode -nx nx -ny ny -nz nz] [-q qx qy qz] nitscf [nite]\n\n"
if ( s->wf.nst() == 0 )
{
......@@ -60,23 +60,42 @@ int ResponseCmd::action(int argc, char **argv)
int iarg = 1;
if ( !strcmp(argv[iarg],"-vext") )
{
// response to vext
if ( s->vext )
{
if ( ui->onpe0() )
cout << " ResponseCmd: cannot run when vext is already set" << endl;
return 1;
}
string filename;
bool rpa = false;
double amplitude = atof(argv[iarg]);
bool ipa = false;
double amplitude = 0.0;
string io = "cube";
int nx, ny, nz;
nx = ny = nz = 0;
iarg++;
// response to vext
if ( s->vext )
delete s->vext;
filename = argv[iarg];
iarg++;
if ( !strcmp(argv[iarg],"-RPA") )
{
rpa = true;
iarg++;
}
if ( !strcmp(argv[iarg],"-IPA") )
{
ipa = true;
iarg++;
}
if ( rpa && ipa )
{
if ( ui->onpe0() )
cout << " Only one of -RPA or -IPA can be specified" << endl;
return 1;
}
if ( !strcmp(argv[iarg],"-amplitude") )
{
iarg++;
......@@ -106,6 +125,7 @@ int ResponseCmd::action(int argc, char **argv)
iarg++;
}
}
nitscf = atoi(argv[iarg]);
iarg++;
......@@ -121,7 +141,9 @@ int ResponseCmd::action(int argc, char **argv)
s->vext = new ExternalPotential(*s, filename, io, nx, ny, nz);
s->vext->set_amplitude(amplitude);
responseVext(rpa, nitscf, nite, io, nx, ny, nz);
responseVext(rpa, ipa, nitscf, nite, io);
delete s->vext;
s->vext = 0;
}
else
{
......@@ -222,9 +244,15 @@ void ResponseCmd::responseEfield(double amplitude, int nitscf, int nite)
}
////////////////////////////////////////////////////////////////////////////////
void ResponseCmd::responseVext(bool rpa, int nitscf, int nite,
string io, int nxx, int nyy, int nzz)
void ResponseCmd::responseVext(bool rpa, bool ipa, int nitscf, int nite, string io)
{
// if (ui->onpe0())
// {
// cout << "ResponseCmd:responseVext:\n"
// << "RPA = " << rpa << ", IPA = " << ipa << ", io = " << io
// << ", q = " << q << ", nitscf = " << nitscf << ", nite = " << nite << "\n";
// }
s->wf.info(cout, "wavefunction");
const int nspin = s->wf.nspin();
......@@ -233,6 +261,12 @@ void ResponseCmd::responseVext(bool rpa, int nitscf, int nite,
if (rpa)
stepper->set_update_vxc(false);
if (ipa)
{
stepper->set_update_vh(false);
stepper->set_update_vxc(false);
}
// save a copy of initial wave functions
Wavefunction wf0(s->wf);
wf0 = s->wf;
......@@ -241,13 +275,15 @@ void ResponseCmd::responseVext(bool rpa, int nitscf, int nite,
MPI_Comm vcomm = cd.vcomm();
stepper->step(0);
const vector<vector<double> > rhor1 = cd.rhor; // density with +Vext
vector<vector<double> > rhor1; // density with +Vext
rhor1 = cd.rhor;
s->wf = wf0;
s->vext->reverse();
stepper->step(0);
const vector<vector<double> > rhor2 = cd.rhor; // density with -Vext
vector<vector<double> > rhor2; // density with -Vext
rhor2 = cd.rhor;
s->vext->reverse();
// restore initial wave functions
......
......@@ -27,9 +27,8 @@ class ResponseCmd : public Cmd
{
private:
void responseVext(bool rpa, int nitscf, int nite,
string io, int nx, int ny, int nz);
void responseEfield(double amplitude, int nitscf, int nite);
void responseVext(bool rpa, bool ipa, int nitscf, int nite, string io);
public:
......@@ -43,22 +42,25 @@ class ResponseCmd : public Cmd
return
"\n response\n\n"
" syntax: response amplitude nitscf [nite]\n"
" response -vext vext_file [-RPA] [-amplitude a] \n"
" response -vext vext_file [-RPA|-IPA] [-amplitude a] \n"
" [-io iomode -nx nx -ny ny -nz nz] nitscf [nite]\n\n"
" The response command computes the polarizability tensor by\n"
" finite differences using external electric fields in the x,y,z\n"
" directions with magnitude defined by the amplitude argument.\n"
" If the -vext option is used, the response command computes the\n"
" response to the external potential defined in the file vext_file.\n"
" Acceptable control flags are:\n"
" 1. -RPA. Compute response within Random Phase Approximation, Vxc is frozen.\n"
" 2. -amplitude a. Scale the Vext by a before any calculations, \n"
" then scale the charge density response by 1/a before output.\n"
" 3. -io iomode. How the vext/response file shall be read/write. Possible choice:\n"
" cube: Gaussian cube format.\n"
" base64_serial or base64_parallel: base64-encoded binary grid function.\n"
" grid size need to be specified by nx, ny, nz.\n"
" use cube for best compatibility and base64_parallel for best performance\n\n";
" Control flags:\n"
" -RPA Compute response within the Random Phase Approximation,\n"
" Vxc is frozen.\n"
" -IPA Compute response within the Independent Particle Approximation,\n"
" VHartree and Vxc are frozen.\n"
" -amplitude a\n"
" Scale the external potential by a before any calculation, \n"
" then scale the charge density response by 1/a before output.\n"
" -io iomode\n"
" Valid choices of iomode: cube, base64_serial, base64_parallel\n"
" -nx nx, -ny ny, -nz nz\n"
" grid size (for base64_serial and base64_parallel only)\n\n";
}
int action(int argc, char **argv);
......
......@@ -37,26 +37,37 @@ class Vext : public Var
int set ( int argc, char **argv )
{
if ( argc > 3 )
if ( argc == 2 )
{
if ( ui->onpe0() )
cout << " vext takes only one value" << endl;
return 1;
if ( !strcmp(argv[1],"NULL") )
{
// set vext NULL
delete s->vext;
s->vext = 0;
}
else
{
if ( s->vext )
delete s->vext;
s->vext = new ExternalPotential(*s,argv[1]);
}
}
if ( !strcmp(argv[1],"NULL") )
else if ( argc == 3 and !strcmp(argv[1],"amplitude") )
{
// set vext NULL
delete s->vext;
s->vext = 0;
if ( s->vext )
s->vext->set_amplitude(atof(argv[2]));
else
{
cout << "vext not set yet" << endl;
return 1;
}
}
else
{
if ( s->vext )
delete s->vext;
s->vext = new ExternalPotential(*s,argv[1]);
if ( ui->onpe0() )
cout << "unknown option for vext variable" << endl;
return 1;
}
return 0;
}
......@@ -68,7 +79,8 @@ class Vext : public Var
if ( s->vext )
{
st.setf(ios::right,ios::adjustfield);
st << setw(10) << s->vext->filename();
st << setw(10) << s->vext->filename()
<< " (amplitude" << " = " << s->vext->amplitude() << ")";
}
return st.str();
}
......
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