From ce7baae5d84162403c4361394ca76ea4ee4b679a Mon Sep 17 00:00:00 2001 From: Francois Gygi Date: Fri, 19 Oct 2007 16:24:36 +0000 Subject: [PATCH] removed trailing blanks in *.[Ch] *.mk Makefile git-svn-id: http://qboxcode.org/svn/qb/trunk@515 cba15fb0-1239-40c8-b417-11db7ca47a34 --- src/AndersonMixer.C | 16 ++++++++-------- src/AndersonMixer.h | 4 ++-- src/AngleCmd.h | 44 ++++++++++++++++++++++---------------------- src/AngleConstraint.C | 118 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++----------------------------------------------------------- src/AngleConstraint.h | 18 +++++++++--------- src/Atom.h | 6 +++--- src/AtomCmd.h | 20 ++++++++++---------- src/AtomSet.C | 30 +++++++++++++++--------------- src/AtomSet.h | 10 +++++----- src/AtomSetHandler.C | 40 ++++++++++++++++++++-------------------- src/AtomSetHandler.h | 16 ++++++++-------- src/AtomsDyn.h | 6 +++--- src/BLYPFunctional.C | 40 ++++++++++++++++++++-------------------- src/BLYPFunctional.h | 22 +++++++++++----------- src/BOSampleStepper.C | 456 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ src/BOSampleStepper.h | 8 ++++---- src/Base64Transcoder.C | 60 ++++++++++++++++++++++++++++++------------------------------ src/Base64Transcoder.h | 4 ++-- src/Basis.C | 172 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-------------------------------------------------------------------------------------- src/Basis.h | 30 +++++++++++++++--------------- src/BasisMapping.C | 66 +++++++++++++++++++++++++++++++++--------------------------------- src/BasisMapping.h | 20 ++++++++++---------- src/CPSampleStepper.C | 104 ++++++++++++++++++++++++++++++++++++++++++++++++++++---------------------------------------------------- src/CPSampleStepper.h | 8 ++++---- src/Cell.h | 10 +++++----- src/CellDyn.h | 6 +++--- src/CellLock.h | 6 +++--- src/CellMass.h | 4 ++-- src/CellStepper.h | 10 +++++----- src/ChargeDensity.C | 32 ++++++++++++++++---------------- src/ChargeDensity.h | 10 +++++----- src/ChargeMixCoeff.h | 4 ++-- src/ChargeMixRcut.h | 4 ++-- src/ComputeMLWFCmd.C | 8 ++++---- src/ComputeMLWFCmd.h | 6 +++--- src/ConfinementPotential.C | 10 +++++----- src/ConfinementPotential.h | 14 +++++++------- src/Constraint.C | 6 +++--- src/Constraint.h | 12 ++++++------ src/ConstraintCmd.h | 6 +++--- src/ConstraintSet.C | 180 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++------------------------------------------------------------------------------------------ src/ConstraintSet.h | 6 +++--- src/Context.C | 188 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---------------------------------------------------------------------------------------------- src/Context.h | 94 +++++++++++++++++++++++++++++++++++++++++++++++----------------------------------------------- src/Control.h | 18 +++++++++--------- src/D3vector.h | 12 ++++++------ src/Debug.h | 6 +++--- src/DistanceCmd.h | 26 +++++++++++++------------- src/DistanceConstraint.C | 54 +++++++++++++++++++++++++++--------------------------- src/DistanceConstraint.h | 14 +++++++------- src/Dt.h | 4 ++-- src/Ecut.h | 10 +++++----- src/Ecutprec.h | 6 +++--- src/Ecuts.h | 6 +++--- src/Emass.h | 4 ++-- src/EnergyFunctional.C | 204 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++------------------------------------------------------------------------------------------------------ src/EnergyFunctional.h | 24 ++++++++++++------------ src/ExtStress.h | 8 ++++---- src/FermiTemp.h | 4 ++-- src/FourierTransform.C | 192 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++------------------------------------------------------------------------------------------------ src/FourierTransform.h | 26 +++++++++++++------------- src/HelpCmd.h | 4 ++-- src/IonicStepper.h | 28 ++++++++++++++-------------- src/LDAFunctional.C | 16 ++++++++-------- src/LDAFunctional.h | 14 +++++++------- src/ListAtomsCmd.h | 4 ++-- src/ListConstraintsCmd.h | 4 ++-- src/ListSpeciesCmd.h | 4 ++-- src/LoadCmd.C | 16 ++++++++-------- src/LoadCmd.h | 4 ++-- src/MDIonicStepper.C | 74 +++++++++++++++++++++++++++++++++++++------------------------------------- src/MDIonicStepper.h | 6 +++--- src/MDWavefunctionStepper.C | 34 +++++++++++++++++----------------- src/MLWFTransform.C | 98 +++++++++++++++++++++++++++++++++++++++++++++++++------------------------------------------------- src/MLWFTransform.h | 12 ++++++------ src/Makefile | 16 ++++++++-------- src/Matrix.C | 418 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- src/Matrix.h | 200 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---------------------------------------------------------------------------------------------------- src/MoveCmd.h | 14 +++++++------- src/Nempty.h | 6 +++--- src/NetCharge.h | 10 +++++----- src/NonLocalPotential.C | 1042 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- src/NonLocalPotential.h | 26 +++++++++++++------------- src/Nrowmax.h | 6 +++--- src/PBEFunctional.C | 58 +++++++++++++++++++++++++++++----------------------------- src/PBEFunctional.h | 26 +++++++++++++------------- src/PSDAWavefunctionStepper.C | 64 ++++++++++++++++++++++++++++++++-------------------------------- src/PSDAWavefunctionStepper.h | 4 ++-- src/PSDWavefunctionStepper.C | 22 +++++++++++----------- src/PSDWavefunctionStepper.h | 6 +++--- src/Preconditioner.C | 6 +++--- src/Preconditioner.h | 6 +++--- src/PrintCmd.h | 4 ++-- src/QuitCmd.h | 6 +++--- src/RandomizeWfCmd.h | 4 ++-- src/RefCell.h | 10 +++++----- src/ResetVcmCmd.h | 4 ++-- src/RunCmd.C | 16 ++++++++-------- src/RunCmd.h | 4 ++-- src/SDAIonicStepper.C | 14 +++++++------- src/SDAIonicStepper.h | 8 ++++---- src/SDCellStepper.C | 44 ++++++++++++++++++++++---------------------- src/SDCellStepper.h | 6 +++--- src/SDIonicStepper.h | 6 +++--- src/SDWavefunctionStepper.C | 4 ++-- src/Sample.h | 6 +++--- src/SampleHandler.C | 14 +++++++------- src/SampleHandler.h | 18 +++++++++--------- src/SampleReader.C | 108 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++---------------------------------------------------- src/SampleReader.h | 4 ++-- src/SampleStepper.C | 10 +++++----- src/SampleStepper.h | 8 ++++---- src/SampleWriter.C | 26 +++++++++++++------------- src/SampleWriter.h | 4 ++-- src/SaveCmd.C | 16 ++++++++-------- src/SaveCmd.h | 4 ++-- src/SetCmd.h | 6 +++--- src/SlaterDet.C | 358 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- src/SlaterDet.h | 8 ++++---- src/Species.C | 76 ++++++++++++++++++++++++++++++++++++++-------------------------------------- src/Species.h | 30 +++++++++++++++--------------- src/SpeciesCmd.C | 10 +++++----- src/SpeciesCmd.h | 4 ++-- src/SpeciesHandler.C | 20 ++++++++++---------- src/SpeciesHandler.h | 18 +++++++++--------- src/SpeciesReader.C | 64 ++++++++++++++++++++++++++++++++-------------------------------- src/SpeciesReader.h | 8 ++++---- src/StatusCmd.h | 4 ++-- src/Stress.h | 6 +++--- src/StructureFactor.C | 56 ++++++++++++++++++++++++++++---------------------------- src/StructureFactor.h | 38 +++++++++++++++++++------------------- src/StructureHandler.h | 16 ++++++++-------- src/StructuredDocumentHandler.C | 12 ++++++------ src/StructuredDocumentHandler.h | 10 +++++----- src/ThTemp.h | 4 ++-- src/ThTime.h | 4 ++-- src/ThWidth.h | 4 ++-- src/Thermostat.h | 8 ++++---- src/Timer.h | 12 ++++++------ src/TorsionCmd.h | 60 ++++++++++++++++++++++++++++++------------------------------ src/TorsionConstraint.C | 138 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--------------------------------------------------------------------- src/TorsionConstraint.h | 14 +++++++------- src/UnitCell.C | 102 +++++++++++++++++++++++++++++++++++++++++++++++++++--------------------------------------------------- src/UnitCell.h | 28 ++++++++++++++-------------- src/UserInterface.C | 26 +++++++++++++------------- src/UserInterface.h | 10 +++++----- src/Wavefunction.C | 114 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++--------------------------------------------------------- src/Wavefunction.h | 34 +++++++++++++++++----------------- src/WavefunctionHandler.C | 78 +++++++++++++++++++++++++++++++++++++++--------------------------------------- src/WavefunctionHandler.h | 18 +++++++++--------- src/WavefunctionStepper.h | 8 ++++---- src/WfDiag.h | 6 +++--- src/WfDyn.h | 10 +++++----- src/XCFunctional.h | 20 ++++++++++---------- src/XCPotential.C | 80 ++++++++++++++++++++++++++++++++++++++++---------------------------------------- src/XCPotential.h | 12 ++++++------ src/XMLGFPreprocessor.C | 206 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++------------------------------------------------------------------------------------------------------- src/XMLGFPreprocessor.h | 10 +++++----- src/Xc.h | 6 +++--- src/aix64_mpi.mk | 12 ++++++------ src/aix_mpi.mk | 12 ++++++------ src/aix_mpi_gcc.mk | 12 ++++++------ src/aix_mpip.mk | 10 +++++----- src/bgl.mk | 4 ++-- src/blacs.h | 4 ++-- src/blas.h | 68 ++++++++++++++++++++++++++++++++++---------------------------------- src/fpmd.mk | 14 +++++++------- src/fpmd_sse2.mk | 14 +++++++------- src/hbar-gcc.mk | 14 +++++++------- src/hbar-icc.mk | 14 +++++++------- src/hbar2-gcc.mk | 14 +++++++------- src/jacobi.C | 164 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---------------------------------------------------------------------------------- src/jade.C | 276 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++------------------------------------------------------------------------------------------------------------------------------------------ src/jade.h | 2 +- src/linux-pc.mk | 6 +++--- src/linux-pc_mpi.mk | 16 ++++++++-------- src/linux-pc_mpi_icc.mk | 14 +++++++------- src/linux-pc_mpi_kcc.mk | 16 ++++++++-------- src/mcr-gcc.mk | 12 ++++++------ src/mcr.mk | 20 ++++++++++---------- src/mcr_sse2.mk | 18 +++++++++--------- src/pavane.mk | 14 +++++++------- src/qb.C | 26 +++++++++++++------------- src/spline.C | 4 ++-- src/spline.h | 6 +++--- src/testAndersonMixer.C | 18 +++++++++--------- src/testBase64Transcoder.C | 22 +++++++++++----------- src/testBasis.C | 12 ++++++------ src/testBasisMapping.C | 34 +++++++++++++++++----------------- src/testChargeDensity.C | 48 ++++++++++++++++++++++++------------------------ src/testContext.C | 32 ++++++++++++++++---------------- src/testEnergyFunctional.C | 18 +++++++++--------- src/testFourierTransform.C | 46 +++++++++++++++++++++++----------------------- src/testLDAFunctional.C | 22 +++++++++++----------- src/testMatrix.C | 86 +++++++++++++++++++++++++++++++++++++++++++------------------------------------------- src/testSample.C | 10 +++++----- src/testSlaterDet.C | 56 ++++++++++++++++++++++++++++---------------------------- src/testSpecies.C | 32 ++++++++++++++++---------------- src/testUnitCell.C | 48 ++++++++++++++++++++++++------------------------ src/testWavefunction.C | 32 ++++++++++++++++---------------- src/testXCFunctional.C | 20 ++++++++++---------- src/testXMLGFPreprocessor.C | 12 ++++++------ src/test_fftw.C | 20 ++++++++++---------- src/testjacobi.C | 30 +++++++++++++++--------------- src/testjade.C | 64 ++++++++++++++++++++++++++++++++-------------------------------- src/x8664_gcc.mk | 18 +++++++++--------- src/xml2xy.C | 28 ++++++++++++++-------------- src/xmlSpecies.C | 22 +++++++++++----------- src/xmlget.C | 28 ++++++++++++++-------------- 209 files changed, 4226 insertions(+), 4222 deletions(-) diff --git a/src/AndersonMixer.C b/src/AndersonMixer.C index 46d055b..997198c 100644 --- a/src/AndersonMixer.C +++ b/src/AndersonMixer.C @@ -3,7 +3,7 @@ // AndersonMixer.C // //////////////////////////////////////////////////////////////////////////////// -// $Id: AndersonMixer.C,v 1.4 2007-03-17 01:14:00 fgygi Exp $ +// $Id: AndersonMixer.C,v 1.5 2007-10-19 16:24:03 fgygi Exp $ #include "AndersonMixer.h" #include "blas.h" @@ -28,13 +28,13 @@ void AndersonMixer::update(const double* f, double* theta, double* fbar) // tmp0 = delta_F = f - flast for ( int i = 0; i < n_; i++ ) tmp0[i] = f[i] - flast_[i]; - + // a = delta_F * F double a = ddot(&n_, &tmp0[0], &ione, f, &ione); - + // b = delta_F * delta_F double b = ddot(&n_, &tmp0[0], &ione, &tmp0[0], &ione); - + if ( pctxt_ != 0 ) { double work[2] = { a, b }; @@ -47,16 +47,16 @@ void AndersonMixer::update(const double* f, double* theta, double* fbar) *theta = - a / b; else *theta = 0.0; - + // test if residual has increased if ( *theta <= -1.0 ) { *theta = theta_nc_; } - + *theta = min(theta_max_,*theta); } - + // fbar = f + theta * ( f - flast ) // flast_ = f_ for ( int i = 0; i < n_; i++ ) @@ -64,6 +64,6 @@ void AndersonMixer::update(const double* f, double* theta, double* fbar) const double ftmp = f[i]; fbar[i] = ftmp + *theta * ( ftmp - flast_[i] ); flast_[i] = ftmp; - } + } extrapolate_ = true; } diff --git a/src/AndersonMixer.h b/src/AndersonMixer.h index 8488520..474a965 100644 --- a/src/AndersonMixer.h +++ b/src/AndersonMixer.h @@ -3,7 +3,7 @@ // AndersonMixer.h // //////////////////////////////////////////////////////////////////////////////// -// $Id: AndersonMixer.h,v 1.4 2007-03-17 01:14:00 fgygi Exp $ +// $Id: AndersonMixer.h,v 1.5 2007-10-19 16:24:03 fgygi Exp $ #ifndef ANDERSONMIXER_H #define ANDERSONMIXER_H @@ -18,7 +18,7 @@ class AndersonMixer const Context* const pctxt_; // pointer to relevant Context, null if local double theta_max_; // maximum extrapolation double theta_nc_; // negative curvature value - + std::valarray flast_; // last residual bool extrapolate_; // state variable diff --git a/src/AngleCmd.h b/src/AngleCmd.h index a6f6f29..2c1593b 100644 --- a/src/AngleCmd.h +++ b/src/AngleCmd.h @@ -3,7 +3,7 @@ // AngleCmd.h: // //////////////////////////////////////////////////////////////////////////////// -// $Id: AngleCmd.h,v 1.1 2005-06-27 22:35:26 fgygi Exp $ +// $Id: AngleCmd.h,v 1.2 2007-10-19 16:24:03 fgygi Exp $ #ifndef ANGLECMD_H #define ANGLECMD_H @@ -24,7 +24,7 @@ class AngleCmd : public Cmd char *name(void) const { return "angle"; } char *help_msg(void) const { - return + return "\n angle\n\n" " syntax: angle name1 name2 name3\n\n" " The angle command prints the angle defined by three atoms.\n\n"; @@ -40,15 +40,15 @@ class AngleCmd : public Cmd } return 1; } - - string name1(argv[1]); - string name2(argv[2]); - string name3(argv[3]); - Atom* a1 = s->atoms.findAtom(name1); - Atom* a2 = s->atoms.findAtom(name2); - Atom* a3 = s->atoms.findAtom(name3); - if ( a1 == 0 || a2 == 0 || a3 == 0 ) - { + + string name1(argv[1]); + string name2(argv[2]); + string name3(argv[3]); + Atom* a1 = s->atoms.findAtom(name1); + Atom* a2 = s->atoms.findAtom(name2); + Atom* a3 = s->atoms.findAtom(name3); + if ( a1 == 0 || a2 == 0 || a3 == 0 ) + { if ( ui->onpe0() ) { if ( a1 == 0 ) @@ -63,28 +63,28 @@ class AngleCmd : public Cmd } return 1; } - - if ( a1 == a2 || a2 == a3 || a3 == a1 ) - { + + if ( a1 == a2 || a2 == a3 || a3 == a1 ) + { if ( ui->onpe0() ) { - cout << " " << endl; + cout << " " << endl; } return 1; } - + D3vector r12(a1->position()-a2->position()); D3vector r32(a3->position()-a2->position()); if ( norm(r12) == 0.0 || norm(r32) == 0.0 ) - { + { if ( ui->onpe0() ) { cout << " " << endl; } return 1; } - + const double sp = normalized(r12) * normalized(r32); const double c = max(-1.0,min(1.0,sp)); const double a = (180.0/M_PI)*acos(c); @@ -92,9 +92,9 @@ class AngleCmd : public Cmd { cout.setf(ios::fixed,ios::floatfield); cout << " " << endl; + << ": " + << setprecision(3) + << a << " (deg) -->" << endl; } return 0; } diff --git a/src/AngleConstraint.C b/src/AngleConstraint.C index a7c116c..a1693d4 100644 --- a/src/AngleConstraint.C +++ b/src/AngleConstraint.C @@ -3,7 +3,7 @@ // AngleConstraint.C // //////////////////////////////////////////////////////////////////////////////// -// $Id: AngleConstraint.C,v 1.2 2005-09-16 23:08:11 fgygi Exp $ +// $Id: AngleConstraint.C,v 1.3 2007-10-19 16:24:03 fgygi Exp $ #include "AngleConstraint.h" #include "AtomSet.h" @@ -26,7 +26,7 @@ void AngleConstraint::setup(const AtomSet& atoms) m1_ = atoms.species_list[is1_]->mass() * 1822.89; assert(m1_>0.0); m1_inv_ = 1.0 / m1_; - + is2_ = atoms.is(name2_); ia2_ = atoms.ia(name2_); assert(is2_>=0); @@ -34,7 +34,7 @@ void AngleConstraint::setup(const AtomSet& atoms) m2_ = atoms.species_list[is2_]->mass() * 1822.89; assert(m2_>0.0); m2_inv_ = 1.0 / m2_; - + is3_ = atoms.is(name3_); ia3_ = atoms.ia(name3_); assert(is3_>=0); @@ -63,7 +63,7 @@ vector > &rp) const double* pr1p = &rp[is1_][3*ia1_]; double* pr2p = &rp[is2_][3*ia2_]; double* pr3p = &rp[is3_][3*ia3_]; - + D3vector r1(pr1); D3vector r2(pr2); D3vector r3(pr3); @@ -72,7 +72,7 @@ vector > &rp) const const double a = bond_angle(r1,r2,r3); double ng = g1*g1 + g2*g2 + g3*g3; assert(ng>=0.0); - + D3vector r1p(pr1p); D3vector r2p(pr2p); D3vector r3p(pr3p); @@ -81,7 +81,7 @@ vector > &rp) const const double ap = bond_angle(r1p,r2p,r3p); const double ngp = g1p*g1p + g2p*g2p + g3p*g3p; assert(ngp>=0.0); - + const double err = fabs(ap-angle_); if ( ng == 0.0 ) @@ -119,25 +119,25 @@ vector > &rp) const // no action necessary } } - + // test alignment of the gradient at r and at rp // compute scalar product of normalized gradients const double sp = ( g1*g1p + g2*g2p + g3*g3p ) / sqrt( ng * ngp ); - + if ( fabs(sp) < 0.5*sqrt(3.0) ) { - g1 = g1p; - g2 = g2p; - g3 = g3p; + g1 = g1p; + g2 = g2p; + g3 = g3p; } - - const double den = m1_inv_ * g1 * g1p + + + const double den = m1_inv_ * g1 * g1p + m2_inv_ * g2 * g2p + m3_inv_ * g3 * g3p; - + #if DEBUG_CONSTRAINTS cout << " " << endl; #endif if ( err < tol_ ) return true; - + // make one shake iteration - + assert(fabs(den)>0.0); - + const double lambda = - sigma(r1p,r2p,r3p) / den; - + pr1p[0] += m1_inv_ * lambda * g1.x; pr1p[1] += m1_inv_ * lambda * g1.y; pr1p[2] += m1_inv_ * lambda * g1.z; - + pr2p[0] += m2_inv_ * lambda * g2.x; pr2p[1] += m2_inv_ * lambda * g2.y; pr2p[2] += m2_inv_ * lambda * g2.z; - + pr3p[0] += m3_inv_ * lambda * g3.x; pr3p[1] += m3_inv_ * lambda * g3.y; pr3p[2] += m3_inv_ * lambda * g3.z; - + return false; } @@ -191,30 +191,30 @@ vector > &v0) const double* pv1 = &v0[is1_][3*ia1_]; double* pv2 = &v0[is2_][3*ia2_]; double* pv3 = &v0[is3_][3*ia3_]; - + D3vector r1(pr1); D3vector r2(pr2); D3vector r3(pr3); - + D3vector g1,g2,g3; - + grad_sigma(r1,r2,r3,g1,g2,g3); - + D3vector v1(pv1); D3vector v2(pv2); D3vector v3(pv3); - + const double proj = v1*g1 + v2*g2 + v3*g3; const double norm2 = g1*g1 + g2*g2 + g3*g3; - + // if the gradient is too small, do not attempt correction if ( norm2 < 1.e-6 ) return true; const double err = fabs(proj)/sqrt(norm2); - + #if DEBUG_CONSTRAINTS cout << " " << endl; #endif if ( err < tol_ ) return true; - + // make one shake iteration - const double den = m1_inv_ * g1 * g1 + + const double den = m1_inv_ * g1 * g1 + m2_inv_ * g2 * g2 + m3_inv_ * g3 * g3; assert(den>0.0); - + const double eta = -proj / den; - + pv1[0] += m1_inv_ * eta * g1.x; pv1[1] += m1_inv_ * eta * g1.y; pv1[2] += m1_inv_ * eta * g1.z; - + pv2[0] += m2_inv_ * eta * g2.x; pv2[1] += m2_inv_ * eta * g2.y; pv2[2] += m2_inv_ * eta * g2.z; - + pv3[0] += m3_inv_ * eta * g3.x; pv3[1] += m3_inv_ * eta * g3.y; pv3[2] += m3_inv_ * eta * g3.z; - + return false; } @@ -258,30 +258,30 @@ void AngleConstraint::compute_force(const vector > &r0, const double* pf1 = &f[is1_][3*ia1_]; const double* pf2 = &f[is2_][3*ia2_]; const double* pf3 = &f[is3_][3*ia3_]; - + D3vector r1(pr1); D3vector r2(pr2); D3vector r3(pr3); D3vector g1,g2,g3; - + grad_sigma(r1,r2,r3,g1,g2,g3); - + D3vector f1(pf1); D3vector f2(pf2); D3vector f3(pf3); - + const double norm2 = g1*g1 + g2*g2 + g3*g3; if ( norm2 == 0.0 ) { force_ = 0.0; return; } - + const double proj = f1*g1 + f2*g2 + f3*g3; force_ = -proj/norm2; - + // compute weight - const double z = m1_inv_ * g1 * g1 + + const double z = m1_inv_ * g1 * g1 + m2_inv_ * g2 * g2 + m3_inv_ * g3 * g3; assert(z > 0.0); @@ -292,10 +292,10 @@ void AngleConstraint::compute_force(const vector > &r0, const double r32s = norm(r3-r2); const double fac = 180.0/M_PI; const double cos_theta = normalized(r1-r2)*normalized(r3-r2); - const double zcheck = fac*fac * + const double zcheck = fac*fac * ( m1_inv_ / r12s + m2_inv_ * ( (r12s+r32s-2*sqrt(r12s*r32s)*cos_theta) /(r12s*r32s) ) + - m3_inv_ / r32s + m3_inv_ / r32s ); cout << " " << endl; @@ -310,7 +310,7 @@ double AngleConstraint::sigma(D3vector a, D3vector b, D3vector c) const } //////////////////////////////////////////////////////////////////////////////// -void AngleConstraint::grad_sigma(const D3vector &r1, const D3vector &r2, +void AngleConstraint::grad_sigma(const D3vector &r1, const D3vector &r2, const D3vector &r3, D3vector &g1, D3vector &g2, D3vector &g3) const { @@ -321,7 +321,7 @@ void AngleConstraint::grad_sigma(const D3vector &r1, const D3vector &r2, D3vector e12(normalized(r12)); D3vector e32(normalized(r32)); const double ss = length(e12^e32); - + // use simplified expression if the angle is smaller than 0.2 degrees if ( ss < sin(0.2*(M_PI/180.0) ) ) { @@ -351,43 +351,43 @@ void AngleConstraint::grad_sigma(const D3vector &r1, const D3vector &r2, { // angle is large enough. Use finite differences //cout << " ========= grad_sigma using finite differences" << endl; - + const double r12_inv = 1.0/length(r12); const double r32_inv = 1.0/length(r32); const double a = bond_angle(r1,r2,r3); - + const double l12 = length(r1-r2); const double l32 = length(r3-r2); // displacement h causes changes in angle of less than 0.05 degrees const double h = 0.05 * (M_PI/180.0) * min(l12,l32); const double fac = 0.5 / h; D3vector dx(h,0,0), dy(0,h,0), dz(0,0,h); - + // compute gradient at r - + g1.x = fac * ( sigma(r1+dx,r2,r3) - sigma(r1-dx,r2,r3) ); g1.y = fac * ( sigma(r1+dy,r2,r3) - sigma(r1-dy,r2,r3) ); g1.z = fac * ( sigma(r1+dz,r2,r3) - sigma(r1-dz,r2,r3) ); - + g2.x = fac * ( sigma(r1,r2+dx,r3) - sigma(r1,r2-dx,r3) ); g2.y = fac * ( sigma(r1,r2+dy,r3) - sigma(r1,r2-dy,r3) ); g2.z = fac * ( sigma(r1,r2+dz,r3) - sigma(r1,r2-dz,r3) ); - + g3.x = fac * ( sigma(r1,r2,r3+dx) - sigma(r1,r2,r3-dx) ); g3.y = fac * ( sigma(r1,r2,r3+dy) - sigma(r1,r2,r3-dy) ); g3.z = fac * ( sigma(r1,r2,r3+dz) - sigma(r1,r2,r3-dz) ); - } + } } - + //////////////////////////////////////////////////////////////////////////////// double AngleConstraint::bond_angle(D3vector a, D3vector b, D3vector c) const { // compute the bond angle defined by vectors a,b,c D3vector e12(normalized(a-b)); D3vector e32(normalized(c-b)); - const double ss = length(e12^e32); - const double cc = e12*e32; - double an = (180.0/M_PI) * atan2(ss,cc); + const double ss = length(e12^e32); + const double cc = e12*e32; + double an = (180.0/M_PI) * atan2(ss,cc); return an; } diff --git a/src/AngleConstraint.h b/src/AngleConstraint.h index c877240..fcecf7e 100644 --- a/src/AngleConstraint.h +++ b/src/AngleConstraint.h @@ -3,7 +3,7 @@ // AngleConstraint.h // //////////////////////////////////////////////////////////////////////////////// -// $Id: AngleConstraint.h,v 1.3 2007-03-17 01:14:00 fgygi Exp $ +// $Id: AngleConstraint.h,v 1.4 2007-10-19 16:24:03 fgygi Exp $ #ifndef ANGLECONSTRAINT_H #define ANGLECONSTRAINT_H @@ -24,16 +24,16 @@ class AngleConstraint : public Constraint void grad_sigma(const D3vector &r1, const D3vector &r2, const D3vector &r3, D3vector &g1, D3vector &g2,D3vector &g3) const; double bond_angle(D3vector a, D3vector b, D3vector c) const; - + public: - - AngleConstraint(std::string name, std::string name1, + + AngleConstraint(std::string name, std::string name1, std::string name2, std::string name3, double angle, double velocity, double tolerance): - name1_(name1), name2_(name2), name3_(name3), + name1_(name1), name2_(name2), name3_(name3), velocity_(velocity), tol_(tolerance), m1_(0.0), m2_(0.0), m3_(0.0) - { + { set_value(angle); name_ = name; names_.resize(3); @@ -43,7 +43,7 @@ class AngleConstraint : public Constraint force_ = 0.0; weight_ = 1.0; } - + std::string type(void) const { return "angle"; } double value(void) const { return angle_; } double velocity(void) const { return velocity_; } @@ -60,7 +60,7 @@ class AngleConstraint : public Constraint { velocity_ = velocity; } - + void setup(const AtomSet& atoms); void update(double dt); bool enforce_r(const std::vector > &r0, @@ -70,6 +70,6 @@ class AngleConstraint : public Constraint void compute_force(const std::vector > &r0, const std::vector > &f); std::ostream& print( std::ostream& os ); - + }; #endif diff --git a/src/Atom.h b/src/Atom.h index 1b42e3d..5422e54 100644 --- a/src/Atom.h +++ b/src/Atom.h @@ -3,7 +3,7 @@ // Atom.h: // //////////////////////////////////////////////////////////////////////////////// -// $Id: Atom.h,v 1.3 2007-03-17 01:14:00 fgygi Exp $ +// $Id: Atom.h,v 1.4 2007-10-19 16:24:03 fgygi Exp $ #ifndef ATOM_H #define ATOM_H @@ -14,7 +14,7 @@ class Atom { private: - + std::string name_; std::string species_; D3vector position_; @@ -22,7 +22,7 @@ class Atom public: - Atom (std::string name, std::string species, + Atom (std::string name, std::string species, D3vector position, D3vector velocity); std::string name(void) { return name_; }; std::string species(void) { return species_; }; diff --git a/src/AtomCmd.h b/src/AtomCmd.h index 190cc30..a19a5e9 100644 --- a/src/AtomCmd.h +++ b/src/AtomCmd.h @@ -3,7 +3,7 @@ // AtomCmd.h: // //////////////////////////////////////////////////////////////////////////////// -// $Id: AtomCmd.h,v 1.7 2007-03-17 01:14:00 fgygi Exp $ +// $Id: AtomCmd.h,v 1.8 2007-10-19 16:24:03 fgygi Exp $ #ifndef ATOMCMD_H #define ATOMCMD_H @@ -25,7 +25,7 @@ class AtomCmd : public Cmd char *name(void) const { return "atom"; } char *help_msg(void) const { - return + return "\n atom\n\n" " syntax: atom name species x y z [vx vy vz]\n\n" " The atom command defines a new atom and adds it to the atom list.\n" @@ -41,7 +41,7 @@ class AtomCmd : public Cmd string species; D3vector position; D3vector velocity; - + // atom must be defined with either 3 or 6 arguments if ( argc != 6 && argc != 9 ) { @@ -49,7 +49,7 @@ class AtomCmd : public Cmd cout << " use: atom name species x y z [vx vy vz]" << endl; return 1; } - + name = argv[1]; species = argv[2]; position.x = atof(argv[3]); @@ -61,10 +61,10 @@ class AtomCmd : public Cmd velocity.y = atof(argv[7]); velocity.z = atof(argv[8]); } - + Atom *a = new Atom(name,species,position,velocity); - - const int atoms_nel_before = s->atoms.nel(); + + const int atoms_nel_before = s->atoms.nel(); if ( !(s->atoms.addAtom( a ) ) ) { if ( ui->onpe0() ) @@ -73,9 +73,9 @@ class AtomCmd : public Cmd return 1; } const int atoms_nel_after = s->atoms.nel(); - const int delta_nel = atoms_nel_after - atoms_nel_before; + const int delta_nel = atoms_nel_after - atoms_nel_before; const int wf_nel = s->wf.nel(); - + s->wf.set_nel(wf_nel+delta_nel); s->wf.update_occ(0.0); if ( s->wfv != 0 ) @@ -83,7 +83,7 @@ class AtomCmd : public Cmd s->wfv->set_nel(wf_nel+delta_nel); s->wfv->clear(); } - + return 0; } }; diff --git a/src/AtomSet.C b/src/AtomSet.C index ec8ac6a..3c9c8e4 100644 --- a/src/AtomSet.C +++ b/src/AtomSet.C @@ -3,7 +3,7 @@ // AtomSet.C // //////////////////////////////////////////////////////////////////////////////// -// $Id: AtomSet.C,v 1.16 2007-10-16 18:23:20 fgygi Exp $ +// $Id: AtomSet.C,v 1.17 2007-10-19 16:24:03 fgygi Exp $ #include "AtomSet.h" #include "Species.h" @@ -23,10 +23,10 @@ bool AtomSet::addSpecies(Species* sp, string name) << " is already defined" << endl; return false; } - + const double rcps = 1.0; sp->initialize(rcps); - + // create new entry in species list species_list.push_back(sp); spname.push_back(name); @@ -34,7 +34,7 @@ bool AtomSet::addSpecies(Species* sp, string name) na_.insert(map::value_type(name,0)); atom_list.resize(atom_list.size()+1); is_[name] = spname.size()-1; - + return true; } @@ -63,7 +63,7 @@ bool AtomSet::addAtom(Atom *a) << " is undefined" << endl; return false; } - + // add an atom to the atom_list int is = isp(spname); assert ( is >= 0 ); @@ -74,7 +74,7 @@ bool AtomSet::addAtom(Atom *a) // update count of atoms of species spname // increment count na_[spname]++; - + // update total number of electrons nel_ = 0; for ( int is = 0; is < species_list.size(); is++ ) @@ -100,16 +100,16 @@ bool AtomSet::delAtom(string name) string spname = atom_list[is][ia]->species(); na_[spname]--; delete atom_list[is][ia]; - + // remove map entries ia_[name] and is_[name] map::iterator i = ia_.find(name); ia_.erase(i); i = is_.find(name); is_.erase(i); - + atom_list[is].erase(pa); nel_ -= species_list[is]->zval(); - + return true; } pa++; @@ -117,7 +117,7 @@ bool AtomSet::delAtom(string name) psa++; ps++; } - + // this name was not found in the atom list if ( ctxt_.onpe0() ) cout << " AtomSet:delAtom: no such atom: " << name << endl; @@ -235,7 +235,7 @@ int AtomSet::size(void) const bool AtomSet::reset(void) { // delete all atoms and species - + for ( int is = 0; is < species_list.size(); is++ ) { for ( int ia = 0; ia < atom_list[is].size(); ia++ ) @@ -243,14 +243,14 @@ bool AtomSet::reset(void) delete atom_list[is][ia]; } atom_list[is].resize(0); - + delete species_list[is]; } atom_list.resize(0); species_list.resize(0); - + nel_ = 0; - + return true; } @@ -391,7 +391,7 @@ D3vector AtomSet::dipole(void) const for ( int ia = 0; ia < atom_list[is].size(); ia++ ) { D3vector p = atom_list[is][ia]->position(); - sum += charge * p; + sum += charge * p; } } return sum; diff --git a/src/AtomSet.h b/src/AtomSet.h index bb7bd48..857173f 100644 --- a/src/AtomSet.h +++ b/src/AtomSet.h @@ -3,7 +3,7 @@ // AtomSet.h // //////////////////////////////////////////////////////////////////////////////// -// $Id: AtomSet.h,v 1.16 2007-08-14 04:11:19 fgygi Exp $ +// $Id: AtomSet.h,v 1.17 2007-10-19 16:24:03 fgygi Exp $ #ifndef ATOMSET_H #define ATOMSET_H @@ -21,18 +21,18 @@ class Species; class AtomSet { private: - + const Context& ctxt_; - + int nel_; std::map na_; // na_[sp_name]: number of at. of spec. sp_name std::map isp_; // isp_[sp_name]: index of species sp_name std::map is_; // is_[atom_name]: is index of atom atom_name std::map ia_; // ia_[atom_name]: ia index of atom atom_name std::vector spname; // spname[is]: name of species is - + public: - + AtomSet(const Context& ctxt) : ctxt_(ctxt), nel_(0) {} std::vector > atom_list; // atom_list[is][ia] diff --git a/src/AtomSetHandler.C b/src/AtomSetHandler.C index 25263e8..805692f 100644 --- a/src/AtomSetHandler.C +++ b/src/AtomSetHandler.C @@ -3,7 +3,7 @@ // AtomSetHandler.C // //////////////////////////////////////////////////////////////////////////////// -// $Id: AtomSetHandler.C,v 1.5 2006-05-13 05:36:52 fgygi Exp $ +// $Id: AtomSetHandler.C,v 1.6 2007-10-19 16:24:03 fgygi Exp $ #if USE_XERCES @@ -20,7 +20,7 @@ using namespace xercesc; using namespace std; //////////////////////////////////////////////////////////////////////////////// -AtomSetHandler::AtomSetHandler(AtomSet& as) : +AtomSetHandler::AtomSetHandler(AtomSet& as) : as_(as) {} //////////////////////////////////////////////////////////////////////////////// @@ -30,17 +30,17 @@ AtomSetHandler::~AtomSetHandler() {} void AtomSetHandler::startElement(const XMLCh* const uri, const XMLCh* const localname, const XMLCh* const qname, const Attributes& attributes) -{ +{ // cout << " AtomSetHandler::startElement " << StrX(qname) << endl; string locname(XMLString::transcode(localname)); - + // consider only elements that are dealt with directly by AtomSetHandler // i.e. "atom". The "species" element is delegated to a SpeciesHandler if ( locname == "atom") { // set default velocity to zero current_atom_velocity = D3vector(0.0,0.0,0.0); - + unsigned int len = attributes.getLength(); for (unsigned int index = 0; index < len; index++) { @@ -68,13 +68,13 @@ void AtomSetHandler::endElement(const XMLCh* const uri, { // create an instance of Atom using the current values read so far // add the Atom to the current AtomSet - // cout << " AtomSetHandler::endElement: creating Atom(position=" + // cout << " AtomSetHandler::endElement: creating Atom(position=" // << current_atom_position - // << ", velocity=" << current_atom_velocity + // << ", velocity=" << current_atom_velocity // << ", name=" << current_atom_name // << ", species=" << current_atom_species // << ")" << endl; - + try { Atom* a = new Atom(current_atom_name, current_atom_species, @@ -87,7 +87,7 @@ void AtomSetHandler::endElement(const XMLCh* const uri, << " in AtomSet::addAtom" << endl; throw; } - + // notify listening nodes and broadcast atom info int tag = 2; // species tag as_.context().ibcast_send(1,1,&tag,1); @@ -102,7 +102,7 @@ void AtomSetHandler::endElement(const XMLCh* const uri, buf[1] = current_atom_velocity.y; buf[2] = current_atom_velocity.z; as_.context().dbcast_send(3,1,buf,1); - + } else if ( locname == "position" ) { @@ -116,13 +116,13 @@ void AtomSetHandler::endElement(const XMLCh* const uri, //////////////////////////////////////////////////////////////////////////////// StructureHandler* AtomSetHandler::startSubHandler(const XMLCh* const uri, - const XMLCh* const localname, const XMLCh* const qname, + const XMLCh* const localname, const XMLCh* const qname, const Attributes& attributes) { // check if element qname can be processed by another StructureHandler // If it can, return a pointer to the StructureHandler, otherwise return 0 // cout << " AtomSetHandler::startSubHandler " << StrX(qname) << endl; - + string locname(XMLString::transcode(localname)); if ( locname == "species") { @@ -136,7 +136,7 @@ StructureHandler* AtomSetHandler::startSubHandler(const XMLCh* const uri, current_species_name = StrX(attributes.getValue(index)).localForm(); } } - + // delegate to SpeciesHandler current_species = new Species(as_.context(),current_species_name); return new SpeciesHandler(*current_species); @@ -149,7 +149,7 @@ StructureHandler* AtomSetHandler::startSubHandler(const XMLCh* const uri, //////////////////////////////////////////////////////////////////////////////// void AtomSetHandler::endSubHandler(const XMLCh* const uri, - const XMLCh* const localname, const XMLCh* const qname, + const XMLCh* const localname, const XMLCh* const qname, const StructureHandler* const last) { string locname(XMLString::transcode(localname)); @@ -157,13 +157,13 @@ void AtomSetHandler::endSubHandler(const XMLCh* const uri, if ( locname == "species" ) { SpeciesReader sp_reader(current_species->context()); - + // check if only the uri was provided if ( current_species->uri() != "" ) { // href was found in species definition // attempt to read the species from that uri - + try { sp_reader.readSpecies(*current_species,current_species->uri()); @@ -173,14 +173,14 @@ void AtomSetHandler::endSubHandler(const XMLCh* const uri, cout << " SpeciesReaderException caught in AtomSetHandler" << endl; } } - + // notify listening nodes and broadcast species info int tag = 1; // species tag as_.context().ibcast_send(1,1,&tag,1); as_.context().string_bcast(current_species_name,0); sp_reader.bcastSpecies(*current_species); - - // cout << "AtomSetHandler::endSubHandler: adding Species:" + + // cout << "AtomSetHandler::endSubHandler: adding Species:" // << current_species_name << endl; try { @@ -195,5 +195,5 @@ void AtomSetHandler::endSubHandler(const XMLCh* const uri, } delete last; } - + #endif diff --git a/src/AtomSetHandler.h b/src/AtomSetHandler.h index 6a48989..6caebb3 100644 --- a/src/AtomSetHandler.h +++ b/src/AtomSetHandler.h @@ -3,7 +3,7 @@ // AtomSetHandler.h // //////////////////////////////////////////////////////////////////////////////// -// $Id: AtomSetHandler.h,v 1.2 2007-03-17 01:14:00 fgygi Exp $ +// $Id: AtomSetHandler.h,v 1.3 2007-10-19 16:24:04 fgygi Exp $ #ifndef ATOMSETHANDLER_H #define ATOMSETHANDLER_H @@ -18,7 +18,7 @@ class Species; class AtomSetHandler : public StructureHandler { private: - + AtomSet& as_; std::string current_atom_name, current_atom_species; std::string current_species_name; @@ -26,23 +26,23 @@ class AtomSetHandler : public StructureHandler Species* current_species; public: - + // Start of the root element in the structure being handled virtual void startElement(const XMLCh* const uri,const XMLCh* const localname, const XMLCh* const qname, const Attributes& attributes); // End of the root element in the structure being handled - virtual void endElement(const XMLCh* const uri, const XMLCh* const localname, + virtual void endElement(const XMLCh* const uri, const XMLCh* const localname, const XMLCh* const qname, std::string& content); - + // start a subhandler virtual StructureHandler* startSubHandler(const XMLCh* const uri, - const XMLCh* const localname, const XMLCh* const qname, + const XMLCh* const localname, const XMLCh* const qname, const Attributes& attributes); - + // end a subhandler virtual void endSubHandler(const XMLCh* const uri, - const XMLCh* const localname, const XMLCh* const qname, + const XMLCh* const localname, const XMLCh* const qname, const StructureHandler* const subHandler); AtomSetHandler(AtomSet& as); diff --git a/src/AtomsDyn.h b/src/AtomsDyn.h index 860f821..2730468 100644 --- a/src/AtomsDyn.h +++ b/src/AtomsDyn.h @@ -3,7 +3,7 @@ // AtomsDyn.h // //////////////////////////////////////////////////////////////////////////////// -// $Id: AtomsDyn.h,v 1.2 2004-12-10 01:07:48 fgygi Exp $ +// $Id: AtomsDyn.h,v 1.3 2007-10-19 16:24:04 fgygi Exp $ #ifndef ATOMSDYN_H #define ATOMSDYN_H @@ -31,7 +31,7 @@ class AtomsDyn : public Var cout << " atoms_dyn takes only one value" << endl; return 1; } - + string v = argv[1]; if ( !( v == "LOCKED" || v == "SD" || v == "SDA" || v == "MD" ) ) { @@ -41,7 +41,7 @@ class AtomsDyn : public Var } s->ctrl.atoms_dyn = v; - + return 0; } diff --git a/src/BLYPFunctional.C b/src/BLYPFunctional.C index c797355..b315d7f 100644 --- a/src/BLYPFunctional.C +++ b/src/BLYPFunctional.C @@ -3,7 +3,7 @@ // BLYPFunctional.C // //////////////////////////////////////////////////////////////////////////////// -// $Id: BLYPFunctional.C,v 1.3 2004-09-14 22:24:11 fgygi Exp $ +// $Id: BLYPFunctional.C,v 1.4 2007-10-19 16:24:04 fgygi Exp $ #include #include @@ -16,7 +16,7 @@ BLYPFunctional::BLYPFunctional(const vector > &rhoe) _nspin = rhoe.size(); if ( _nspin > 1 ) assert(rhoe[0].size() == rhoe[1].size()); _np = rhoe[0].size(); - + if ( _nspin == 1 ) { _exc.resize(_np); @@ -41,7 +41,7 @@ BLYPFunctional::BLYPFunctional(const vector > &rhoe) } //////////////////////////////////////////////////////////////////////////////// -void BLYPFunctional::setxc(void) +void BLYPFunctional::setxc(void) { if ( _np == 0 ) return; if ( _nspin == 1 ) @@ -97,7 +97,7 @@ void BLYPFunctional::setxc(void) } } //////////////////////////////////////////////////////////////////////////////// -void BLYPFunctional::excblyp(double rho, double grad, +void BLYPFunctional::excblyp(double rho, double grad, double *exc, double *vxc1, double *vxc2) { /* Becke exchange constants */ @@ -118,12 +118,12 @@ void BLYPFunctional::excblyp(double rho, double grad, const double d_third = d / 3.0; const double cf = 2.87123400018819; /* (3/10)*pow(3*pi*pi,2/3) */ const double cfb = cf * b; - + *exc = 0.0; *vxc1 = 0.0; *vxc2 = 0.0; - if ( rho < 1.e-18 ) + if ( rho < 1.e-18 ) { return; } @@ -132,10 +132,10 @@ void BLYPFunctional::excblyp(double rho, double grad, * Becke's exchange * A.D.Becke, Phys.Rev. B38, 3098 (1988) */ - + const double rha = 0.5 * rho; const double grada = 0.5 * grad; - + const double rha13 = pow ( rha, third ); const double rha43 = rha * rha13; const double xa = grada / rha43; @@ -145,13 +145,13 @@ void BLYPFunctional::excblyp(double rho, double grad, const double ga = axa - beta * xa2 * frac; /* N.B. in next line, ex is the energy density, hence rh13 */ const double ex = rha13 * ga; - + /* energy done, now the potential */ const double gpa = ( 6.0*beta*beta*xa2 * ( xa/sqrt(xa2+1.0) - asinhxa ) - 2.0*beta*xa ) * frac*frac; const double vx1 = rha13 * fourthirds * ( ga - xa * gpa ); const double vx2 = - 0.5 * gpa / grada; - + /*------------------------------------------------------------*/ /* LYP correlation */ /* Phys. Rev. B 37, 785 (1988). */ @@ -164,35 +164,35 @@ void BLYPFunctional::excblyp(double rho, double grad, const double den = 1.0 + d * rhm13; const double deninv = 1.0 / den; const double cfrac = num * deninv; - - const double delta = rhm13 * ( c + d * deninv ); + + const double delta = rhm13 * ( c + d * deninv ); const double rhm53 = rhm43 * rhm13; const double t1 = e * deninv; const double t2 = rhm53; const double t3 = 6.0 + 14.0 * delta; - + const double g = ab36 * t1 * t2 * t3; - + /* next line, ec is the energy density, hence divide the energy by rho */ const double ec = - a * cfrac + 0.25 * g * grad * grad / rho; - + /* energy done, now the potential */ const double de = c_third * rhm43 * e; const double dnum = cfb * de; const double dden = - d_third * rhm43; const double dfrac = ( dnum * den - dden * num ) * deninv * deninv; - + const double ddelta = - third * rhm43 * ( c + d * deninv ) - rhm13 * d * dden * deninv * deninv; const double dt1 = de * deninv - e * dden * deninv * deninv; const double dt2 = - fivethirds * rhm53/rho; const double dt3 = 14.0 * ddelta; - + const double dg = ab36 * ( dt1 * t2 * t3 + t1 * dt2 * t3 + t1 * t2 * dt3 ); - - const double vc1 = - a * ( cfrac + rho * dfrac ) + 0.25 * dg * grad * grad; + + const double vc1 = - a * ( cfrac + rho * dfrac ) + 0.25 * dg * grad * grad; const double vc2 = -0.5 * g; - + *exc = ex + ec; *vxc1 = vx1 + vc1; *vxc2 = vx2 + vc2; diff --git a/src/BLYPFunctional.h b/src/BLYPFunctional.h index 9d148d1..08d4cd3 100644 --- a/src/BLYPFunctional.h +++ b/src/BLYPFunctional.h @@ -3,7 +3,7 @@ // BLYPFunctional.h // //////////////////////////////////////////////////////////////////////////////// -// $Id: BLYPFunctional.h,v 1.3 2007-03-17 01:14:00 fgygi Exp $ +// $Id: BLYPFunctional.h,v 1.4 2007-10-19 16:24:04 fgygi Exp $ #ifndef BLYPFUNCTIONAL_H #define BLYPFUNCTIONAL_H @@ -14,27 +14,27 @@ class BLYPFunctional : public XCFunctional { BLYPFunctional(); - + std::vector _exc, _exc_up, _exc_dn; - std::vector _vxc1, _vxc1_up, _vxc1_dn, + std::vector _vxc1, _vxc1_up, _vxc1_dn, _vxc2, _vxc2_upup, _vxc2_updn, _vxc2_dnup, _vxc2_dndn; std::vector _grad_rho[3], _grad_rho_up[3], _grad_rho_dn[3]; - - void excblyp(double rho, double grad, + + void excblyp(double rho, double grad, double *exc, double *vxc1, double *vxc2); - - void excblyp_sp(double rho_up, double rho_dn, - double grad_up, double grad_dn, double grad, + + void excblyp_sp(double rho_up, double rho_dn, + double grad_up, double grad_dn, double grad, double *exc_up, double *exc_dn, double *vxc1_up, double *vxc1_dn, double *vxc2_upup, double *vxc2_dndn, double *vxc2_updn, double *vxc2_dnup); public: - + BLYPFunctional(const std::vector > &rhoe); - + bool isGGA() { return true; }; std::string name() { return "BLYP"; }; - void setxc(void); + void setxc(void); }; #endif diff --git a/src/BOSampleStepper.C b/src/BOSampleStepper.C index 3231f44..f7711f4 100644 --- a/src/BOSampleStepper.C +++ b/src/BOSampleStepper.C @@ -3,7 +3,7 @@ // BOSampleStepper.C // //////////////////////////////////////////////////////////////////////////////// -// $Id: BOSampleStepper.C,v 1.32 2007-10-16 18:23:20 fgygi Exp $ +// $Id: BOSampleStepper.C,v 1.33 2007-10-19 16:24:04 fgygi Exp $ #include "BOSampleStepper.h" #include "EnergyFunctional.h" @@ -29,8 +29,8 @@ using namespace std; //////////////////////////////////////////////////////////////////////////////// -BOSampleStepper::BOSampleStepper(Sample& s, int nitscf, int nite) : - SampleStepper(s), cd_(s.wf), ef_(s,cd_), +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) {} //////////////////////////////////////////////////////////////////////////////// @@ -58,7 +58,7 @@ void BOSampleStepper::step(int niter) { const bool onpe0 = s_.ctxt_.onpe0(); - const bool anderson_charge_mixing = + const bool anderson_charge_mixing = ( s_.ctrl.debug.find("AND_CHMIX") != string::npos ); // determine whether eigenvectors must be computed @@ -67,40 +67,40 @@ void BOSampleStepper::step(int niter) const bool fractional_occ = (s_.wf.nel() != 2 * s_.wf.nst()); const bool compute_eigvec = fractional_occ || s_.ctrl.wf_diag == "T"; enum ortho_type { GRAM, LOWDIN, ORTHO_ALIGN, RICCATI }; - + const bool extrapolate_wf = !fractional_occ; AtomSet& atoms = s_.atoms; Wavefunction& wf = s_.wf; const int nspin = wf.nspin(); - + const UnitCell& cell = wf.cell(); const double omega = cell.volume(); - + const double dt = s_.ctrl.dt; const double dt_inv = 1.0 / dt; - + const string wf_dyn = s_.ctrl.wf_dyn; const string atoms_dyn = s_.ctrl.atoms_dyn; const string cell_dyn = s_.ctrl.cell_dyn; - + if ( onpe0 ) cout << " extrapolate_wf=" << extrapolate_wf << endl; - const bool ntc_extrapolation = + const bool ntc_extrapolation = s_.ctrl.debug.find("NTC_EXTRAPOLATION") != string::npos; - const bool asp_extrapolation = + const bool asp_extrapolation = s_.ctrl.debug.find("ASP_EXTRAPOLATION") != string::npos; Wavefunction* wfmm; if ( extrapolate_wf && ( ntc_extrapolation || asp_extrapolation ) ) wfmm = new Wavefunction(wf); - + const bool compute_hpsi = ( wf_dyn != "LOCKED" ); const bool compute_forces = ( atoms_dyn != "LOCKED" ); const bool compute_stress = ( s_.ctrl.stress == "ON" ); const bool use_confinement = ( s_.ctrl.ecuts > 0.0 ); - + Timer tm_iter; - + const bool use_preconditioner = wf_dyn == "PSD" || wf_dyn == "PSDA"; Preconditioner *preconditioner = 0; if ( use_preconditioner ) @@ -109,13 +109,13 @@ void BOSampleStepper::step(int niter) // and the information about the hessian in df preconditioner = new Preconditioner(s_,ef_); } - + WavefunctionStepper* wf_stepper = 0; if ( wf_dyn == "SD" ) { const double emass = s_.ctrl.emass; double dt2bye = (emass == 0.0) ? 0.5 / wf.ecut() : dt*dt/emass; - + // divide dt2bye by facs coefficient if stress == ON const double facs = 2.0; if ( s_.ctrl.stress == "ON" ) @@ -128,9 +128,9 @@ void BOSampleStepper::step(int niter) wf_stepper = new PSDWavefunctionStepper(wf,*preconditioner,tmap); else if ( wf_dyn == "PSDA" ) wf_stepper = new PSDAWavefunctionStepper(wf,*preconditioner,tmap); - + // wf_stepper == 0 indicates that wf_dyn == LOCKED - + IonicStepper* ionic_stepper = 0; if ( atoms_dyn == "SD" ) ionic_stepper = new SDIonicStepper(s_); @@ -138,14 +138,14 @@ void BOSampleStepper::step(int niter) ionic_stepper = new SDAIonicStepper(s_); else if ( atoms_dyn == "MD" ) ionic_stepper = new MDIonicStepper(s_); - + if ( ionic_stepper ) ionic_stepper->setup_constraints(); - + CellStepper* cell_stepper = 0; if ( cell_dyn == "SD" ) cell_stepper = new SDCellStepper(s_); - + // Allocate wavefunction velocity if not available if ( atoms_dyn != "LOCKED" && extrapolate_wf ) { @@ -173,22 +173,22 @@ void BOSampleStepper::step(int niter) cout << ef_; } } - + for ( int iter = 0; iter < niter; iter++ ) { // ionic iteration - + tm_iter.start(); #ifdef USE_APC ApcStart(1); #endif - + if ( onpe0 ) cout << " \n"; - + if ( ionic_stepper ) atoms.sync(); - + double energy = 0.0; if ( compute_forces || compute_stress ) { @@ -197,7 +197,7 @@ void BOSampleStepper::step(int niter) tmap["charge"].start(); cd_.update_density(); tmap["charge"].stop(); - + ef_.update_vhxc(); energy = ef_.energy(false,dwf,compute_forces,fion,compute_stress,sigma_eks); @@ -229,53 +229,53 @@ void BOSampleStepper::step(int niter) } } } - + if ( compute_forces ) { - if ( iter > 0 ) + if ( iter > 0 ) { ionic_stepper->compute_v(energy,fion); } // at this point, positions r0, velocities v0 and forces fion are // consistent - const double ekin_ion = ionic_stepper->ekin(); - const double temp_ion = ionic_stepper->temp(); - - // print positions, velocities and forces at time t0 + const double ekin_ion = ionic_stepper->ekin(); + const double temp_ion = ionic_stepper->temp(); + + // print positions, velocities and forces at time t0 if ( onpe0 ) - { - for ( int is = 0; is < atoms.atom_list.size(); is++ ) - { - int i = 0; - for ( int ia = 0; ia < atoms.atom_list[is].size(); ia++ ) - { - Atom* pa = atoms.atom_list[is][ia]; - cout << " name() << "\"" - << " species=\"" << pa->species() - << "\">\n" - << " " - << ionic_stepper->r0(is,i) << " " - << ionic_stepper->r0(is,i+1) << " " - << ionic_stepper->r0(is,i+2) << " \n" - << " " - << ionic_stepper->v0(is,i) << " " - << ionic_stepper->v0(is,i+1) << " " + { + for ( int is = 0; is < atoms.atom_list.size(); is++ ) + { + int i = 0; + for ( int ia = 0; ia < atoms.atom_list[is].size(); ia++ ) + { + Atom* pa = atoms.atom_list[is][ia]; + cout << " name() << "\"" + << " species=\"" << pa->species() + << "\">\n" + << " " + << ionic_stepper->r0(is,i) << " " + << ionic_stepper->r0(is,i+1) << " " + << ionic_stepper->r0(is,i+2) << " \n" + << " " + << ionic_stepper->v0(is,i) << " " + << ionic_stepper->v0(is,i+1) << " " << ionic_stepper->v0(is,i+2) << " \n" - << " " - << fion[is][i] << " " - << fion[is][i+1] << " " - << fion[is][i+2] - << " \n"; - cout << " " << endl; - i += 3; - } + << " " + << fion[is][i] << " " + << fion[is][i+1] << " " + << fion[is][i+2] + << " \n"; + cout << " " << endl; + i += 3; + } } - cout << " " << energy+ekin_ion << " \n"; - cout << " " << ekin_ion << " \n"; - cout << " " << temp_ion << " \n"; + cout << " " << energy+ekin_ion << " \n"; + cout << " " << ekin_ion << " \n"; + cout << " " << temp_ion << " \n"; } } - + if ( compute_forces ) { if ( s_.constraints.size() > 0 ) @@ -290,35 +290,35 @@ void BOSampleStepper::step(int niter) ionic_stepper->compute_r(energy,fion); ef_.atoms_moved(); } - + if ( compute_stress ) { - if ( onpe0 ) - { - cout << "" << endl; - cout << s_.wf.cell(); - cout << "" << endl; - } + if ( onpe0 ) + { + cout << "" << endl; + cout << s_.wf.cell(); + cout << "" << endl; + } compute_sigma(); print_stress(); - + if ( cell_dyn != "LOCKED" ) { cell_stepper->compute_new_cell(sigma); - + // Update cell cell_stepper->update_cell(); - + ef_.cell_moved(); ef_.atoms_moved(); // modifications of the cell also move ions - + if ( use_preconditioner ) preconditioner->update(); } } - + // Recalculate ground state wavefunctions - + // wavefunction extrapolation if ( compute_forces && extrapolate_wf ) { @@ -332,12 +332,12 @@ void BOSampleStepper::step(int niter) { if ( ntc_extrapolation ) { - double* c = (double*) s_.wf.sd(ispin,ikp)->c().cvalptr(); - double* cv = (double*) s_.wfv->sd(ispin,ikp)->c().cvalptr(); - double* cmm = (double*) wfmm->sd(ispin,ikp)->c().cvalptr(); - const int mloc = s_.wf.sd(ispin,ikp)->c().mloc(); + double* c = (double*) s_.wf.sd(ispin,ikp)->c().cvalptr(); + double* cv = (double*) s_.wfv->sd(ispin,ikp)->c().cvalptr(); + double* cmm = (double*) wfmm->sd(ispin,ikp)->c().cvalptr(); + const int mloc = s_.wf.sd(ispin,ikp)->c().mloc(); const int nloc = s_.wf.sd(ispin,ikp)->c().nloc(); - const int len = 2*mloc*nloc; + const int len = 2*mloc*nloc; if ( iter == 0 ) { for ( int i = 0; i < len; i++ ) @@ -346,11 +346,11 @@ void BOSampleStepper::step(int niter) const double v = cv[i]; // extrapolation using velocity in cv c[i] = x + dt * v; - cv[i] = x; + cv[i] = x; } - tmap["gram"].start(); - s_.wf.sd(ispin,ikp)->gram(); - tmap["gram"].stop(); + tmap["gram"].start(); + s_.wf.sd(ispin,ikp)->gram(); + tmap["gram"].stop(); } else if ( iter == 1 ) { @@ -360,55 +360,55 @@ void BOSampleStepper::step(int niter) const double x = c[i]; const double xm = cv[i]; c[i] = 2.0 * x - xm; - cv[i] = x; + cv[i] = x; cmm[i] = xm; } - tmap["gram"].start(); - s_.wf.sd(ispin,ikp)->gram(); - tmap["gram"].stop(); + tmap["gram"].start(); + s_.wf.sd(ispin,ikp)->gram(); + tmap["gram"].stop(); } else { // align wf with wfmm before extrapolation // s_.wf.align(*wfmm); wfmm->align(s_.wf); - + // extrapolate - for ( int i = 0; i < len; i++ ) - { + for ( int i = 0; i < len; i++ ) + { const double x = c[i]; // current wf (scf converged) at t - const double xm = cv[i]; // extrapolated wf at t - const double xmm = cmm[i]; // extrapolated wf at t-dt - c[i] = 2.0 * x - xmm; - // save extrapolated value at t in cmm - cmm[i] = xm; + const double xm = cv[i]; // extrapolated wf at t + const double xmm = cmm[i]; // extrapolated wf at t-dt + c[i] = 2.0 * x - xmm; + // save extrapolated value at t in cmm + cmm[i] = xm; + } + + // orthogonalize the extrapolated value + tmap["gram"].start(); + s_.wf.sd(ispin,ikp)->gram(); + tmap["gram"].stop(); + //tmap["lowdin"].start(); + //s_.wf.sd(ispin,ikp)->lowdin(); + //tmap["lowdin"].stop(); + + // c[i] now contains the extrapolated value + // save a copy in cv[i] + for ( int i = 0; i < len; i++ ) + { + cv[i] = c[i]; } - - // orthogonalize the extrapolated value - tmap["gram"].start(); - s_.wf.sd(ispin,ikp)->gram(); - tmap["gram"].stop(); - //tmap["lowdin"].start(); - //s_.wf.sd(ispin,ikp)->lowdin(); - //tmap["lowdin"].stop(); - - // c[i] now contains the extrapolated value - // save a copy in cv[i] - for ( int i = 0; i < len; i++ ) - { - cv[i] = c[i]; - } } // c[i] is now ready for electronic iterations } else if ( asp_extrapolation ) { - double* c = (double*) s_.wf.sd(ispin,ikp)->c().cvalptr(); - double* cv = (double*) s_.wfv->sd(ispin,ikp)->c().cvalptr(); - double* cmm = (double*) wfmm->sd(ispin,ikp)->c().cvalptr(); - const int mloc = s_.wf.sd(ispin,ikp)->c().mloc(); + double* c = (double*) s_.wf.sd(ispin,ikp)->c().cvalptr(); + double* cv = (double*) s_.wfv->sd(ispin,ikp)->c().cvalptr(); + double* cmm = (double*) wfmm->sd(ispin,ikp)->c().cvalptr(); + const int mloc = s_.wf.sd(ispin,ikp)->c().mloc(); const int nloc = s_.wf.sd(ispin,ikp)->c().nloc(); - const int len = 2*mloc*nloc; + const int len = 2*mloc*nloc; if ( iter == 0 ) { for ( int i = 0; i < len; i++ ) @@ -417,11 +417,11 @@ void BOSampleStepper::step(int niter) const double v = cv[i]; // extrapolation using velocity in cv c[i] = x + dt * v; - cv[i] = x; + cv[i] = x; } - tmap["gram"].start(); - s_.wf.sd(ispin,ikp)->gram(); - tmap["gram"].stop(); + tmap["gram"].start(); + s_.wf.sd(ispin,ikp)->gram(); + tmap["gram"].stop(); } else if ( iter == 1 ) { @@ -431,42 +431,42 @@ void BOSampleStepper::step(int niter) const double x = c[i]; const double xm = cv[i]; c[i] = 2.0 * x - xm; - cv[i] = x; + cv[i] = x; cmm[i] = xm; } - tmap["gram"].start(); - s_.wf.sd(ispin,ikp)->gram(); - tmap["gram"].stop(); + tmap["gram"].start(); + s_.wf.sd(ispin,ikp)->gram(); + tmap["gram"].stop(); } else { // align wf with wfmm before extrapolation // s_.wf.align(*wfmm); // wfmm->align(s_.wf); - + // extrapolate - for ( int i = 0; i < len; i++ ) - { + for ( int i = 0; i < len; i++ ) + { const double x = c[i]; // current wf (scf converged) at t - const double xm = cv[i]; // extrapolated wf at t - const double xmm = cmm[i]; // extrapolated wf at t-dt + const double xm = cv[i]; // extrapolated wf at t + const double xmm = cmm[i]; // extrapolated wf at t-dt const double asp_a1 = 0.5; - c[i] = 2.0 * x - xm + - asp_a1 * ( x - 2.0 * xm + xmm ); - //c[i] = 2.5 * x - 2.0 * xm + 0.5 * xmm; + c[i] = 2.0 * x - xm + + asp_a1 * ( x - 2.0 * xm + xmm ); + //c[i] = 2.5 * x - 2.0 * xm + 0.5 * xmm; cmm[i] = xm; - cv[i] = x; + cv[i] = x; } - - // orthogonalize the extrapolated value - tmap["gram"].start(); - s_.wf.sd(ispin,ikp)->gram(); - tmap["gram"].stop(); - //tmap["lowdin"].start(); - //s_.wf.sd(ispin,ikp)->lowdin(); - //tmap["lowdin"].stop(); - - // c[i] now contains the extrapolated value + + // orthogonalize the extrapolated value + tmap["gram"].start(); + s_.wf.sd(ispin,ikp)->gram(); + tmap["gram"].stop(); + //tmap["lowdin"].start(); + //s_.wf.sd(ispin,ikp)->lowdin(); + //tmap["lowdin"].stop(); + + // c[i] now contains the extrapolated value } // c[i] is now ready for electronic iterations } @@ -478,11 +478,11 @@ void BOSampleStepper::step(int niter) // wfv contains wfm since iter > 0 s_.wfv->align(s_.wf); } - double* c = (double*) s_.wf.sd(ispin,ikp)->c().cvalptr(); - double* cv = (double*) s_.wfv->sd(ispin,ikp)->c().cvalptr(); - const int mloc = s_.wf.sd(ispin,ikp)->c().mloc(); + double* c = (double*) s_.wf.sd(ispin,ikp)->c().cvalptr(); + double* cv = (double*) s_.wfv->sd(ispin,ikp)->c().cvalptr(); + const int mloc = s_.wf.sd(ispin,ikp)->c().mloc(); const int nloc = s_.wf.sd(ispin,ikp)->c().nloc(); - const int len = 2*mloc*nloc; + const int len = 2*mloc*nloc; if ( iter == 0 ) { // linear extrapolation using the velocity in wfv @@ -494,24 +494,24 @@ void BOSampleStepper::step(int niter) c[i] = x + dt * v; cv[i] = x; } - tmap["lowdin"].start(); - s_.wf.sd(ispin,ikp)->lowdin(); - tmap["lowdin"].stop(); + tmap["lowdin"].start(); + s_.wf.sd(ispin,ikp)->lowdin(); + tmap["lowdin"].stop(); } else { - // linear extrapolation - for ( int i = 0; i < len; i++ ) + // linear extrapolation + for ( int i = 0; i < len; i++ ) { const double x = c[i]; const double xm = cv[i]; - c[i] = 2.0 * x - xm; - cv[i] = x; + c[i] = 2.0 * x - xm; + cv[i] = x; } - tmap["ortho_align"].start(); - s_.wf.sd(ispin,ikp)->ortho_align(*s_.wfv->sd(ispin,ikp)); - tmap["ortho_align"].stop(); - + tmap["ortho_align"].start(); + s_.wf.sd(ispin,ikp)->ortho_align(*s_.wfv->sd(ispin,ikp)); + tmap["ortho_align"].stop(); + //tmap["riccati"].start(); //s_.wf.sd(ispin,ikp)->riccati(*s_.wfv->sd(ispin,ikp)); //tmap["riccati"].stop(); @@ -533,18 +533,18 @@ void BOSampleStepper::step(int niter) vector > drhog_bar(rhog_current.size()); AndersonMixer mixer(2*rhog_current.size(),&cd_.vcontext()); mixer.set_theta_max(2.0); - + wf_stepper->preprocess(); for ( int itscf = 0; itscf < nitscf_; itscf++ ) { if ( nite_ > 1 && onpe0 ) cout << " " << endl; - + // compute new density in cd_.rhog tmap["charge"].start(); cd_.update_density(); tmap["charge"].stop(); - + // charge mixing if ( nite_ > 1 ) { @@ -560,36 +560,36 @@ void BOSampleStepper::step(int niter) drhog[i] = (cd_.rhog[0][i] - rhog_current[i]); } - // Apply Kerker preconditioner to drhog - // Use Kerker preconditioning if rc_Kerker > 0.0, - // no preconditioning otherwise - const double alpha = s_.ctrl.charge_mix_coeff; - const double *const g2 = cd_.vbasis()->g2_ptr(); - // real space Kerker cutoff in a.u. - const double rc_Kerker = s_.ctrl.charge_mix_rcut; - if ( rc_Kerker > 0.0 ) - { - const double q0_kerker = 2 * M_PI / rc_Kerker; - const double q0_kerker2 = q0_kerker * q0_kerker; - for ( int i=0; i < rhog_current.size(); i++ ) - { - drhog[i] *= alpha * g2[i] / ( g2[i] + q0_kerker2 ); - } - } - else - { - for ( int i=0; i < rhog_current.size(); i++ ) - { - drhog[i] *= alpha; - } + // Apply Kerker preconditioner to drhog + // Use Kerker preconditioning if rc_Kerker > 0.0, + // no preconditioning otherwise + const double alpha = s_.ctrl.charge_mix_coeff; + const double *const g2 = cd_.vbasis()->g2_ptr(); + // real space Kerker cutoff in a.u. + const double rc_Kerker = s_.ctrl.charge_mix_rcut; + if ( rc_Kerker > 0.0 ) + { + const double q0_kerker = 2 * M_PI / rc_Kerker; + const double q0_kerker2 = q0_kerker * q0_kerker; + for ( int i=0; i < rhog_current.size(); i++ ) + { + drhog[i] *= alpha * g2[i] / ( g2[i] + q0_kerker2 ); + } + } + else + { + for ( int i=0; i < rhog_current.size(); i++ ) + { + drhog[i] *= alpha; + } } // Anderson acceleration double theta = 0.0; - for ( int i=0; i < rhog_current.size(); i++ ) - { - drhog_bar[i] = drhog[i]; - } + for ( int i=0; i < rhog_current.size(); i++ ) + { + drhog_bar[i] = drhog[i]; + } if ( anderson_charge_mixing ) { @@ -600,10 +600,10 @@ void BOSampleStepper::step(int niter) << theta << " -->" << endl; } } - - // update rhog_current + + // update rhog_current // rhog_current = rhog_current + theta*(rhog_current-rhog_last) - + for ( int i=0; i < rhog_current.size(); i++ ) { complex rhotmp = rhog_current[i]; @@ -614,21 +614,21 @@ void BOSampleStepper::step(int niter) // Apply correction for ( int i=0; i < rhog_current.size(); i++ ) { - cd_.rhog[0][i] = rhog_current[i] + drhog_bar[i]; + cd_.rhog[0][i] = rhog_current[i] + drhog_bar[i]; } rhog_current = cd_.rhog[0]; cd_.update_rhor(); } // if nite > 1 ef_.update_vhxc(); - + // reset stepper only if multiple non-selfconsistent steps if ( nite_ > 1 ) wf_stepper->preprocess(); - + for ( int ite = 0; ite < nite_; ite++ ) { double energy = ef_.energy(true,dwf,false,fion,false,sigma_eks); - + // compute the sum of eigenvalues (with fixed weight) // to measure convergence of the subspace update // compute trace of the Hamiltonian matrix Y^T H Y @@ -637,9 +637,9 @@ void BOSampleStepper::step(int niter) if ( onpe0 ) cout << " " << eigenvalue_sum << " " << endl; - + wf_stepper->update(dwf); - + if ( onpe0 ) { cout.setf(ios::fixed,ios::floatfield); @@ -650,19 +650,19 @@ void BOSampleStepper::step(int niter) { const double pext = (sigma_ext[0]+sigma_ext[1]+sigma_ext[2])/3.0; const double enthalpy = energy + pext * cell.volume(); - cout << " " << setw(15) + cout << " " << setw(15) << enthalpy << " \n" << flush; } } } // for ite - + // subspace diagonalization if ( compute_eigvec || s_.ctrl.wf_diag == "EIGVAL" ) { energy = ef_.energy(true,dwf,false,fion,false,sigma_eks); s_.wf.diag(dwf,compute_eigvec); - if ( onpe0 ) + if ( onpe0 ) { // print eigenvalues for ( int ispin = 0; ispin < wf.nspin(); ispin++ ) @@ -674,25 +674,25 @@ void BOSampleStepper::step(int niter) if ( wf.sdcontext(ispin,ikp)->active() ) { const int nst = wf.sd(ispin,ikp)->nst(); - const double eVolt = 2.0 * 13.6058; - cout << " kpoint() - << "\" n=\"" << nst << "\">" << endl; - for ( int i = 0; i < nst; i++ ) - { - cout << setw(12) << setprecision(5) + const double eVolt = 2.0 * 13.6058; + cout << " kpoint() + << "\" n=\"" << nst << "\">" << endl; + for ( int i = 0; i < nst; i++ ) + { + cout << setw(12) << setprecision(5) << wf.sd(ispin,ikp)->eig(i)*eVolt; - if ( i%5 == 4 ) cout << endl; - } - if ( nst%5 != 0 ) cout << endl; + if ( i%5 == 4 ) cout << endl; + } + if ( nst%5 != 0 ) cout << endl; cout << " " << endl; } } } - } - } + } + } } - + // update occupation numbers if fractionally occupied states if ( fractional_occ ) { @@ -708,16 +708,16 @@ void BOSampleStepper::step(int niter) << " -->" << endl; } } - + if ( nite_ > 1 && onpe0 ) cout << " " << endl; } // for itscf - - + + if ( !compute_forces && !compute_stress ) if ( onpe0 ) cout << ef_; - + wf_stepper->postprocess(); } else @@ -734,7 +734,7 @@ void BOSampleStepper::step(int niter) cout << ef_; } } - + #ifdef USE_APC ApcStop(1); #endif @@ -755,18 +755,18 @@ void BOSampleStepper::step(int niter) if ( compute_forces ) s_.constraints.update_constraints(dt); } // for iter - + if ( compute_forces && extrapolate_wf ) { // compute wavefunction velocity after last iteration // s_.wfv contains the previous wavefunction - + // if eigenvectors were computed, use alignment before computing velocity if ( compute_eigvec ) { s_.wfv->align(s_.wf); } - + for ( int ispin = 0; ispin < s_.wf.nspin(); ispin++ ) { for ( int ikp = 0; ikp < s_.wf.nkp(); ikp++ ) @@ -779,10 +779,10 @@ void BOSampleStepper::step(int niter) double* cm = (double*) s_.wfv->sd(ispin,ikp)->c().cvalptr(); const int mloc = s_.wf.sd(ispin,ikp)->c().mloc(); const int nloc = s_.wf.sd(ispin,ikp)->c().nloc(); - const int len = 2*mloc*nloc; + const int len = 2*mloc*nloc; if ( ntc_extrapolation ) { - double* cmm = (double*) wfmm->sd(ispin,ikp)->c().cvalptr(); + double* cmm = (double*) wfmm->sd(ispin,ikp)->c().cvalptr(); for ( int i = 0; i < len; i++ ) { const double x = c[i]; @@ -809,17 +809,17 @@ void BOSampleStepper::step(int niter) } } } - + // compute ionic forces at last position to update velocities // consistently with last position tmap["charge"].start(); cd_.update_density(); tmap["charge"].stop(); - + ef_.update_vhxc(); - double energy = + double energy = ef_.energy(false,dwf,compute_forces,fion,compute_stress,sigma_eks); - + ionic_stepper->compute_v(energy,fion); // positions r0 and velocities v0 are consistent } @@ -830,12 +830,12 @@ void BOSampleStepper::step(int niter) delete s_.wfv; s_.wfv = 0; } - + // delete steppers if ( wf_stepper != 0 ) delete wf_stepper; if ( ionic_stepper != 0 ) delete ionic_stepper; if ( cell_stepper != 0 ) delete cell_stepper; - + // delete preconditioner if ( use_preconditioner ) delete preconditioner; if ( ntc_extrapolation || asp_extrapolation ) delete wfmm; diff --git a/src/BOSampleStepper.h b/src/BOSampleStepper.h index d735eb7..1405e5f 100644 --- a/src/BOSampleStepper.h +++ b/src/BOSampleStepper.h @@ -3,7 +3,7 @@ // BOSampleStepper.h // //////////////////////////////////////////////////////////////////////////////// -// $Id: BOSampleStepper.h,v 1.5 2007-03-17 01:14:00 fgygi Exp $ +// $Id: BOSampleStepper.h,v 1.6 2007-10-19 16:24:04 fgygi Exp $ #ifndef BOSAMPLESTEPPER_H #define BOSAMPLESTEPPER_H @@ -19,14 +19,14 @@ class IonicStepper; class BOSampleStepper : public SampleStepper { private: - + Wavefunction dwf; Wavefunction* wfv; int nitscf_; int nite_; ChargeDensity cd_; EnergyFunctional ef_; - + WavefunctionStepper* wf_stepper; IonicStepper* ionic_stepper; @@ -36,7 +36,7 @@ class BOSampleStepper : public SampleStepper public: mutable TimerMap tmap; - + void step(int niter); BOSampleStepper(Sample& s, int nitscf, int nite); diff --git a/src/Base64Transcoder.C b/src/Base64Transcoder.C index cae2669..474318b 100644 --- a/src/Base64Transcoder.C +++ b/src/Base64Transcoder.C @@ -3,7 +3,7 @@ // Base64Transcoder.C // //////////////////////////////////////////////////////////////////////////////// -// $Id: Base64Transcoder.C,v 1.3 2004-12-08 19:01:20 fgygi Exp $ +// $Id: Base64Transcoder.C,v 1.4 2007-10-19 16:24:04 fgygi Exp $ #include "Base64Transcoder.h" #include @@ -16,7 +16,7 @@ using namespace std; Base64Transcoder::Base64Transcoder() { // initialize encoding/decoding tables - + for (int i = 0; i < 26; i++) { etable[i] = 'A' + i; @@ -55,9 +55,9 @@ int Base64Transcoder::encode(int nbytes, const byte* const from, char* const to) { const byte* fptr = from; char* tptr = to; - + int n3 = nbytes / 3; // number of groups of three bytes - + while ( n3-- > 0 ) { byte ig0 = *fptr++; @@ -67,17 +67,17 @@ int Base64Transcoder::encode(int nbytes, const byte* const from, char* const to) *tptr++ = etable[ig0 >> 2]; *tptr++ = etable[((ig0 & 3) << 4) | (ig1 >> 4)]; *tptr++ = etable[((ig1 & 0xF) << 2) | (ig2 >> 6)]; - *tptr++ = etable[ig2 & 0x3F]; + *tptr++ = etable[ig2 & 0x3F]; } - + int nr = nbytes % 3; // remaining bytes - + if ( nr == 2 ) { byte ig0 = *fptr++; byte ig1 = *fptr++; byte ig2 = 0; - + *tptr++ = etable[ig0 >> 2]; *tptr++ = etable[((ig0 & 3) << 4) | (ig1 >> 4)]; *tptr++ = etable[((ig1 & 0xF) << 2) | (ig2 >> 6)]; @@ -87,19 +87,19 @@ int Base64Transcoder::encode(int nbytes, const byte* const from, char* const to) { byte ig0 = *fptr++; byte ig1 = 0; - + *tptr++ = etable[ig0 >> 2]; *tptr++ = etable[((ig0 & 3) << 4) | (ig1 >> 4)]; *tptr++ = '='; *tptr++ = '='; } - - return 0; + + return 0; } //////////////////////////////////////////////////////////////////////////////// -int Base64Transcoder::decode(const int nchars, const char* const from, - byte* const to) +int Base64Transcoder::decode(const int nchars, const char* const from, + byte* const to) { // Decode Base64 chars in array "from" into bytes in array "to" // White space and new lines are skipped @@ -107,13 +107,13 @@ int Base64Transcoder::decode(const int nchars, const char* const from, // ignored. // nchars: number of chars in array "from" // the number of bytes successfully translated is returned - + byte a0,a1,a2,a3,b0,b1,b2,b3; int c; const char* fptr = from; const char* const fptr_end = from+nchars+1; byte* tptr = to; - + while ( fptr < fptr_end-4 ) { // get 4 valid characters from input string @@ -132,7 +132,7 @@ int Base64Transcoder::decode(const int nchars, const char* const from, } a0 = (byte) c; b0 = (byte) dtable[c]; - + do { c = *fptr++; @@ -148,7 +148,7 @@ int Base64Transcoder::decode(const int nchars, const char* const from, } a1 = (byte) c; b1 = (byte) dtable[c]; - + do { c = *fptr++; @@ -164,7 +164,7 @@ int Base64Transcoder::decode(const int nchars, const char* const from, } a2 = (byte) c; b2 = (byte) dtable[c]; - + do { c = *fptr++; @@ -180,7 +180,7 @@ int Base64Transcoder::decode(const int nchars, const char* const from, } a3 = (byte) c; b3 = (byte) dtable[c]; - + if ((b0|b1|b2|b3) & 0x80) { #ifdef DEBUG @@ -189,7 +189,7 @@ int Base64Transcoder::decode(const int nchars, const char* const from, #endif return tptr - to; } - + if ( a3 == '=' ) { if ( a2 == '=' ) @@ -211,7 +211,7 @@ int Base64Transcoder::decode(const int nchars, const char* const from, *tptr++ = (b1 << 4) | (b2 >> 2); *tptr++ = (b2 << 6) | b3; } - + } #ifdef DEBUG if ( fptr >= fptr_end ) @@ -220,7 +220,7 @@ int Base64Transcoder::decode(const int nchars, const char* const from, << endl; } #endif - + return tptr - to; } @@ -236,10 +236,10 @@ void Base64Transcoder::byteswap_double(size_t n, double* const x) tmp = c[6]; c[6] = c[1]; c[1] = tmp; tmp = c[5]; c[5] = c[2]; c[2] = tmp; tmp = c[4]; c[4] = c[3]; c[3] = tmp; - + c+=8; } -} +} //////////////////////////////////////////////////////////////////////////////// void Base64Transcoder::byteswap_int(size_t n, int* const x) @@ -251,10 +251,10 @@ void Base64Transcoder::byteswap_int(size_t n, int* const x) unsigned char tmp; tmp = c[3]; c[3] = c[0]; c[0] = tmp; tmp = c[2]; c[2] = c[1]; c[1] = tmp; - + c+=4; } -} +} //////////////////////////////////////////////////////////////////////////////// int Base64Transcoder::print(const string buf, ostream& o) @@ -268,7 +268,7 @@ int Base64Transcoder::print(const string buf, ostream& o) o << endl; b += 72; } - + o.write(b,nchars%72); o << endl; return 0; @@ -285,7 +285,7 @@ int Base64Transcoder::print(int nchars, const char* const buf, ostream& o) o << endl; b += 72; } - + o.write(b,nchars%72); o << endl; return 0; @@ -303,7 +303,7 @@ int Base64Transcoder::print(const string buf, FILE* outfile) fwrite(&nlchar,sizeof(char),1,outfile); b += 72; } - + if ( nchars%72 != 0 ) { fwrite(b,sizeof(char),nchars%72,outfile); @@ -324,7 +324,7 @@ int Base64Transcoder::print(int nchars, const char* const buf, FILE* outfile) fwrite(&nlchar,sizeof(char),1,outfile); b += 72; } - + if ( nchars%72 != 0 ) { fwrite(b,sizeof(char),nchars%72,outfile); diff --git a/src/Base64Transcoder.h b/src/Base64Transcoder.h index fe18e13..eee177d 100644 --- a/src/Base64Transcoder.h +++ b/src/Base64Transcoder.h @@ -3,7 +3,7 @@ // Base64Transcoder.h // //////////////////////////////////////////////////////////////////////////////// -// $Id: Base64Transcoder.h,v 1.4 2007-03-17 01:14:00 fgygi Exp $ +// $Id: Base64Transcoder.h,v 1.5 2007-10-19 16:24:04 fgygi Exp $ #ifndef BASE64TRANSCODER_H #define BASE64TRANSCODER_H @@ -20,7 +20,7 @@ class Base64Transcoder byte dtable[256]; // decode table public: - + Base64Transcoder(); int encode(int nbytes, const byte* const from, char* const to); int decode(int nchars, const char* const from, byte* const to); diff --git a/src/Basis.C b/src/Basis.C index 8b48450..fc15bf7 100644 --- a/src/Basis.C +++ b/src/Basis.C @@ -3,7 +3,7 @@ // Basis.C // //////////////////////////////////////////////////////////////////////////////// -// $Id: Basis.C,v 1.13 2005-01-04 22:07:39 fgygi Exp $ +// $Id: Basis.C,v 1.14 2007-10-19 16:24:04 fgygi Exp $ #include "Basis.h" #include "Context.h" @@ -23,13 +23,13 @@ struct BasisImpl { Context ctxt_; int nprow_, myrow_; - + UnitCell cell_; // cell dimensions UnitCell refcell_; // reference cell dimensions D3vector kpoint_; // k-point in units of b0,b1,b2 double ecut_; // energy cutoff of wavefunctions in Rydberg - int idxmin_[3]; // minimum index in each direction - int idxmax_[3]; // maximum index in each direction + int idxmin_[3]; // minimum index in each direction + int idxmax_[3]; // maximum index in each direction int size_; // basis size int nrods_; // total number of rods vector localsize_; // localsize_[ipe] @@ -40,7 +40,7 @@ struct BasisImpl vector > rod_lmin_; vector > rod_size_; vector > rod_first_; - + vector idx_; // 3-d index of vectors idx[i*3+j] vector g_; // norm of g vectors g[localsize] vector kpg_; // norm of g vectors g[localsize] @@ -53,21 +53,21 @@ struct BasisImpl vector gx2_; // g vectors components^2 gx2[j*localsize+i], j=0,1,2 vector isort_loc; // index array to access locally sorted vectors // g2_[isort_loc[i]] < g2_[isort_loc[j]] if i < j - bool real_; // true if k=0 - + bool real_; // true if k=0 + bool resize(const UnitCell& cell, const UnitCell& refcell, double ecut); - + BasisImpl(const Context &ctxt, D3vector kpoint); ~BasisImpl(void); - + void update_g(void); - + }; //////////////////////////////////////////////////////////////////////////////// double Basis::localmemsize(void) const -{ - return +{ + return 5.0 * (pimpl_->nprow_*pimpl_->nrods_*sizeof(int)) // x[ipe][irod] + pimpl_->localsize_[pimpl_->myrow_] * (3.0*sizeof(int) + 10 * sizeof(double)); } @@ -136,21 +136,21 @@ const double* Basis::gi_ptr(void) const { return &(pimpl_->gi_[0]); } const double* Basis::g2_ptr(void) const { return &(pimpl_->g2_[0]); } const double* Basis::kpg2_ptr(void) const { return &(pimpl_->kpg2_[0]); } const double* Basis::g2i_ptr(void) const { return &(pimpl_->g2i_[0]); } -const double* Basis::gx_ptr(int j) const +const double* Basis::gx_ptr(int j) const { return &(pimpl_->gx_[j*pimpl_->localsize_[pimpl_->myrow_]]); } -const double* Basis::gx2_ptr(int j) const +const double* Basis::gx2_ptr(int j) const { return &(pimpl_->gx2_[j*pimpl_->localsize_[pimpl_->myrow_]]); } //////////////////////////////////////////////////////////////////////////////// inline bool factorizable(int n) { // next lines: use AIX criterion for all platforms (AIX and fftw) - + //#if AIX // Acceptable lengths for FFTs in the ESSL library: - // n = (2^h) (3^i) (5^j) (7^k) (11^m) for n <= 37748736 - // where: + // n = (2^h) (3^i) (5^j) (7^k) (11^m) for n <= 37748736 + // where: // h = 1, 2, ..., 25 // i = 0, 1, 2 // j, k, m = 0, 1 @@ -163,7 +163,7 @@ inline bool factorizable(int n) // memory allocation problems while ( ( n % 2 == 0 ) ) n /= 2; return ( n == 1 ); - + // #else // while ( n % 5 == 0 ) n /= 5; // while ( n % 3 == 0 ) n /= 3; @@ -188,11 +188,11 @@ bool Basis::resize(const UnitCell& cell, const UnitCell& refcell, double ecut) } //////////////////////////////////////////////////////////////////////////////// -Basis::Basis(const Context& ctxt, D3vector kpoint) : +Basis::Basis(const Context& ctxt, D3vector kpoint) : pimpl_(new BasisImpl(ctxt,kpoint)) {} //////////////////////////////////////////////////////////////////////////////// -Basis::Basis(const Basis& b) : +Basis::Basis(const Basis& b) : pimpl_(new BasisImpl(b.context(),b.kpoint())) { resize(b.cell(),b.refcell(),b.ecut()); @@ -209,11 +209,11 @@ class Rod { // z-column of non-zero reciprocal lattice vectors int h_, k_, lmin_, size_; - + public: - Rod(int h, int k, int lmin, int size) : h_(h), k_(k), + Rod(int h, int k, int lmin, int size) : h_(h), k_(k), lmin_(lmin), size_(size) {} - + int h(void) const { return h_; } int k(void) const { return k_; } int lmin(void) const { return lmin_; } @@ -228,15 +228,15 @@ class Rod class Node { int id_, nrods_, size_; - + public: Node() : id_(0), nrods_(0), size_(0) {} Node(int id) : id_(id), nrods_(0), size_(0) {} - + int id(void) const { return id_; } int nrods(void) const { return nrods_; } int size(void) const { return size_; } - + void addrod(const Rod& r) { nrods_++; @@ -275,7 +275,7 @@ struct VectorLess return a_[i] < a_[j]; } }; - + //////////////////////////////////////////////////////////////////////////////// BasisImpl::BasisImpl(const Context& ctxt, D3vector kpoint) : ctxt_(ctxt) { @@ -287,7 +287,7 @@ BasisImpl::BasisImpl(const Context& ctxt, D3vector kpoint) : ctxt_(ctxt) ecut_ = 0.0; kpoint_ = kpoint; real_ = ( kpoint == D3vector(0.0,0.0,0.0) ); - + localsize_.resize(nprow_); nrod_loc_.resize(nprow_); rod_h_.resize(nprow_); @@ -295,7 +295,7 @@ BasisImpl::BasisImpl(const Context& ctxt, D3vector kpoint) : ctxt_(ctxt) rod_lmin_.resize(nprow_); rod_size_.resize(nprow_); rod_first_.resize(nprow_); - + // resize with zero cutoff to initialize empty Basis resize(cell_,refcell_,0.0); } @@ -304,13 +304,13 @@ BasisImpl::BasisImpl(const Context& ctxt, D3vector kpoint) : ctxt_(ctxt) BasisImpl::~BasisImpl(void) {} //////////////////////////////////////////////////////////////////////////////// -bool BasisImpl::resize(const UnitCell& cell, const UnitCell& refcell, +bool BasisImpl::resize(const UnitCell& cell, const UnitCell& refcell, double ecut) { assert(ecut>=0.0); assert(cell.volume() >= 0.0); assert(refcell.volume() >= 0.0); - + if ( ecut == ecut_ && refcell == refcell_ && refcell_.volume() != 0.0 ) { cell_ = cell; @@ -318,11 +318,11 @@ bool BasisImpl::resize(const UnitCell& cell, const UnitCell& refcell, update_g(); return true; } - + ecut_ = ecut; cell_ = cell; refcell_ = refcell; - + if ( ecut == 0.0 || cell.volume() == 0.0) { idxmax_[0] = 0; @@ -331,7 +331,7 @@ bool BasisImpl::resize(const UnitCell& cell, const UnitCell& refcell, idxmin_[0] = 0; idxmin_[1] = 0; idxmin_[2] = 0; - + size_ = 0; nrods_ = 0; for ( int ipe = 0; ipe < nprow_; ipe++ ) @@ -353,14 +353,14 @@ bool BasisImpl::resize(const UnitCell& cell, const UnitCell& refcell, isort_loc.resize(localsize_[myrow_]); return true; } - + const double two_ecut = 2.0 * ecut; const double twopi = 2.0 * M_PI; const double kpx = kpoint_.x; const double kpy = kpoint_.y; const double kpz = kpoint_.z; - + UnitCell defcell; // defcell: cell used to define which vectors are contained in the Basis // if refcell is defined, defcell = refcell @@ -373,39 +373,39 @@ bool BasisImpl::resize(const UnitCell& cell, const UnitCell& refcell, { defcell = refcell; } - + const D3vector b0 = defcell.b(0); const D3vector b1 = defcell.b(1); const D3vector b2 = defcell.b(2); - + const double normb2 = norm(b2); const double b2inv2 = 1.0 / normb2; - + const D3vector kp = kpx*b0 + kpy*b1 + kpz*b2; - + if ( !cell.in_bz(kp) ) cout << " Basis::resize: warning: " << kpoint_ << " out of the BZ: " << kp << endl; const double fac = sqrt(two_ecut) / twopi; - // define safe enclosing domain + // define safe enclosing domain const int hmax = (int) ( fac * ( abs(defcell.a(0).x) + abs(defcell.a(0).y) + abs(defcell.a(0).z) ) ); const int hmin = - hmax; - + const int kmax = (int) ( fac * ( abs(defcell.a(1).x) + abs(defcell.a(1).y) + abs(defcell.a(1).z) ) ); const int kmin = - kmax; - + const int lmax = (int) ( fac * ( abs(defcell.a(2).x) + abs(defcell.a(2).y) + abs(defcell.a(2).z) ) ); const int lmin = - lmax; - + multiset rodset; - + // build rod set - + int hmax_used = hmin; int hmin_used = hmax; int kmax_used = kmin; @@ -430,7 +430,7 @@ bool BasisImpl::resize(const UnitCell& cell, const UnitCell& refcell, kmax_used = 0; lmin_used = 0; lmax_used = lend; - + // rods (0,k,l) for ( int k = 1; k <= kmax; k++ ) { @@ -533,7 +533,7 @@ bool BasisImpl::resize(const UnitCell& cell, const UnitCell& refcell, } } } - + //cout << " hmin/hmax: " << hmin << " / " << hmax << endl; //cout << " kmin/kmax: " << kmin << " / " << kmax << endl; //cout << " lmin/lmax: " << lmin << " / " << lmax << endl; @@ -543,20 +543,20 @@ bool BasisImpl::resize(const UnitCell& cell, const UnitCell& refcell, idxmax_[0] = hmax_used; idxmin_[0] = hmin_used; - + idxmax_[1] = kmax_used; idxmin_[1] = kmin_used; - + idxmax_[2] = lmax_used; idxmin_[2] = lmin_used; - + assert(hmax_used <= hmax); assert(hmin_used >= hmin); assert(kmax_used <= kmax); assert(kmin_used >= kmin); assert(lmax_used <= lmax); assert(lmin_used >= lmin); - + // compute good FFT sizes for ( int i = 0; i < 3; i++ ) { @@ -568,9 +568,9 @@ bool BasisImpl::resize(const UnitCell& cell, const UnitCell& refcell, // Distribute the basis on nprow_ processors // build a min-heap of Nodes - + vector nodes(nprow_); - + for ( int ipe = 0; ipe < nprow_; ipe++ ) { nodes[ipe] = new Node(ipe); @@ -583,7 +583,7 @@ bool BasisImpl::resize(const UnitCell& cell, const UnitCell& refcell, } // nodes contains a valid min-heap of zero-size Nodes - + // insert rods into the min-heap // keep track of where rod(0,0,0) goes int pe_rod0 = -1, rank_rod0 = -1; @@ -592,7 +592,7 @@ bool BasisImpl::resize(const UnitCell& cell, const UnitCell& refcell, { // pop smallest element pop_heap(nodes.begin(), nodes.end(), ptr_greater()); - + // add rod size to smaller element nodes[nprow_-1]->addrod(*p); int ipe = nodes[nprow_-1]->id(); @@ -612,20 +612,20 @@ bool BasisImpl::resize(const UnitCell& cell, const UnitCell& refcell, // push modified element back in the heap push_heap(nodes.begin(), nodes.end(), ptr_greater()); - + p++; } - - maxlocalsize_ = (*max_element(nodes.begin(), nodes.end(), + + maxlocalsize_ = (*max_element(nodes.begin(), nodes.end(), ptr_less()))->size(); - minlocalsize_ = (*min_element(nodes.begin(), nodes.end(), + minlocalsize_ = (*min_element(nodes.begin(), nodes.end(), ptr_less()))->size(); - + for ( int ipe = 0; ipe < nprow_; ipe++ ) { delete nodes[ipe]; } - + // swap node pe_rod0 with node 0 in order to have rod(0,0,0) on node 0 swap(nrod_loc_[0], nrod_loc_[pe_rod0]); rod_h_[pe_rod0].swap(rod_h_[0]); @@ -633,15 +633,15 @@ bool BasisImpl::resize(const UnitCell& cell, const UnitCell& refcell, rod_lmin_[pe_rod0].swap(rod_lmin_[0]); rod_size_[pe_rod0].swap(rod_size_[0]); swap(localsize_[0], localsize_[pe_rod0]); - //Node *tmpnodeptr = nodes[0]; nodes[0] = nodes[pe_rod0]; + //Node *tmpnodeptr = nodes[0]; nodes[0] = nodes[pe_rod0]; // nodes[pe_rod0]=tmpnodeptr; - + // reorder rods on node 0 so that rod(0,0,0) comes first swap(rod_h_[0][rank_rod0], rod_h_[0][0]); swap(rod_k_[0][rank_rod0], rod_k_[0][0]); swap(rod_lmin_[0][rank_rod0], rod_lmin_[0][0]); swap(rod_size_[0][rank_rod0], rod_size_[0][0]); - + // compute position of first element of rod (ipe,irod) for ( int ipe = 0; ipe < nprow_; ipe++ ) { @@ -653,7 +653,7 @@ bool BasisImpl::resize(const UnitCell& cell, const UnitCell& refcell, rod_first_[ipe][irod] = rod_first_[ipe][irod-1] + rod_size_[ipe][irod-1]; } } - + // local arrays idx, g, gi, g2i, g2, gx, gx2 idx_.resize(3*localsize_[myrow_]); int i = 0; @@ -664,11 +664,11 @@ bool BasisImpl::resize(const UnitCell& cell, const UnitCell& refcell, idx_[3*i] = rod_h_[myrow_][irod]; idx_[3*i+1] = rod_k_[myrow_][irod]; idx_[3*i+2] = rod_lmin_[myrow_][irod] + l; - + i++; } } - + g_.resize(localsize_[myrow_]); kpg_.resize(localsize_[myrow_]); gi_.resize(localsize_[myrow_]); @@ -678,11 +678,11 @@ bool BasisImpl::resize(const UnitCell& cell, const UnitCell& refcell, gx_.resize(3*localsize_[myrow_]); gx2_.resize(3*localsize_[myrow_]); isort_loc.resize(localsize_[myrow_]); - + update_g(); - + // basis set construction is complete - + return true; } @@ -691,33 +691,33 @@ void BasisImpl::update_g(void) { // compute the values of g, kpg, gi, g2i, g2, kpg2, gx, gx2 // N.B. use the values of cell (not defcell) - + const int locsize = localsize_[myrow_]; for ( int i = 0; i < locsize; i++ ) { D3vector gt = idx_[3*i+0] * cell_.b(0) + idx_[3*i+1] * cell_.b(1) + idx_[3*i+2] * cell_.b(2); - + D3vector kpgt = (kpoint_.x + idx_[3*i+0]) * cell_.b(0) + (kpoint_.y + idx_[3*i+1]) * cell_.b(1) + (kpoint_.z + idx_[3*i+2]) * cell_.b(2); - + gx_[i] = gt.x; gx_[locsize+i] = gt.y; gx_[locsize+locsize+i] = gt.z; g2_[i] = norm(gt); g_[i] = sqrt( g2_[i] ); - + kpg2_[i] = norm(kpgt); kpg_[i] = sqrt( kpg2_[i] ); - + gi_[i] = g_[i] > 0.0 ? 1.0 / g_[i] : 0.0; g2i_[i] = gi_[i] * gi_[i]; isort_loc[i] = i; } - + VectorLess g2_less(g2_); sort(isort_loc.begin(), isort_loc.end(), g2_less); #if DEBUG @@ -738,7 +738,7 @@ void Basis::print(ostream& os) << kpoint().y << " * b1 + " << kpoint().z << " * b2" << endl; os << context().mype() << ": "; - os << " Basis.kpoint(): " << kpoint().x * cell().b(0) + + os << " Basis.kpoint(): " << kpoint().x * cell().b(0) + kpoint().y * cell().b(1) + kpoint().z * cell().b(2) << endl; os << context().mype() << ": "; @@ -768,23 +768,23 @@ void Basis::print(ostream& os) os << " Basis total mem size: " << memsize() / 1048576 << endl; os << context().mype() << ": "; os << " Basis local mem size: " << localmemsize() / 1048576 << endl; - + os << context().mype() << ": "; - os << " ig i j k gx gy gz |k+g|^2" + os << " ig i j k gx gy gz |k+g|^2" << endl; os << context().mype() << ": "; - os << " -- - - - -- -- -- -------" + os << " -- - - - -- -- -- -------" << endl; for ( int i = 0; i < localsize(); i++ ) { os << context().mype() << ": "; - os << setw(5) << i << " " - << setw(4) << idx(3*i) - << setw(4) << idx(3*i+1) + os << setw(5) << i << " " + << setw(4) << idx(3*i) + << setw(4) << idx(3*i+1) << setw(4) << idx(3*i+2) << " " - << setw(8) << gx(i) - << setw(8) << gx(i+localsize()) + << setw(8) << gx(i) + << setw(8) << gx(i+localsize()) << setw(8) << gx(i+2*localsize()) << setw(12) << setprecision(4) << 0.5 * kpg2(i) << endl; diff --git a/src/Basis.h b/src/Basis.h index d2d0662..a9cfcca 100644 --- a/src/Basis.h +++ b/src/Basis.h @@ -3,7 +3,7 @@ // Basis.h // //////////////////////////////////////////////////////////////////////////////// -// $Id: Basis.h,v 1.6 2007-03-17 01:14:00 fgygi Exp $ +// $Id: Basis.h,v 1.7 2007-10-19 16:24:04 fgygi Exp $ #ifndef BASIS_H #define BASIS_H @@ -16,11 +16,11 @@ class Context; class Basis { private: - + struct BasisImpl* pimpl_; - + public: - + const Context& context(void) const; // context on which Basis is defined const UnitCell& cell() const; // cell dimensions @@ -31,17 +31,17 @@ class Basis int idxmax(int i) const; // largest index in direction i double ecut() const; // energy cutoff in Hartree bool real() const; // return true if kpoint == (0,0,0) - + int size() const; // total number of g vectors int localsize() const; // local number of g vectors on current process int localsize(int ipe) const; // local number of g vectors on process ipe int maxlocalsize() const; // largest local size int minlocalsize() const; // smallest local size - + int nrods() const; // total number of rods int nrod_loc() const; // local number of rods on current process int nrod_loc(int ipe) const; // local number of rods on process ipe - + int rod_h(int irod) const; // h-position of rod irod on current process int rod_h(int ipe, int irod) const; // h-position of rod irod on process ipe @@ -52,13 +52,13 @@ class Basis int rod_lmin(int ipe, int irod) const; // lmin-pos. of rod irod on process ipe // size of rod irod - int rod_size(int irod) const; + int rod_size(int irod) const; int rod_size(int ipe, int irod) const; - // local position of first elem. of rod irod - int rod_first(int irod) const; + // local position of first elem. of rod irod + int rod_first(int irod) const; int rod_first(int ipe, int irod) const; - + int idx(int i) const; // integer indices of vectors idx[i*3+j] double g(int i) const; // norm of g vectors g[i] double kpg(int i) const; // norm of k+g vectors kpg[i] @@ -68,9 +68,9 @@ class Basis double g2i(int i) const; // inverse square norm of g g2i[i] double gx(int i) const; // g vectors gx[i+localsize*j],j=0,1,2 double gx2(int i) const; // g vectors components^2 gx2[i+localsize*j] - + int isort(int i) const; // index of vectors locally sorted by norm - + const int* idx_ptr(void) const; const double* g_ptr(void) const; const double* kpg_ptr(void) const; @@ -80,14 +80,14 @@ class Basis const double* g2i_ptr(void) const; const double* gx_ptr(int j) const; const double* gx2_ptr(int j) const; - + double memsize(void) const; double localmemsize(void) const; Basis(const Context &ctxt, D3vector kpoint); Basis(const Basis &b); ~Basis(void); - + bool resize(const UnitCell& cell, const UnitCell& refcell, double ecut); void print(std::ostream& os); }; diff --git a/src/BasisMapping.C b/src/BasisMapping.C index 8baf604..8857c7c 100644 --- a/src/BasisMapping.C +++ b/src/BasisMapping.C @@ -3,7 +3,7 @@ // BasisMapping.C // //////////////////////////////////////////////////////////////////////////////// -// $Id: BasisMapping.C,v 1.1 2007-08-13 21:26:27 fgygi Exp $ +// $Id: BasisMapping.C,v 1.2 2007-10-19 16:24:04 fgygi Exp $ #include "Basis.h" #include "Context.h" @@ -14,14 +14,14 @@ using namespace std; //////////////////////////////////////////////////////////////////////////////// -BasisMapping::BasisMapping (const Basis &basis) : ctxt_(basis.context()), +BasisMapping::BasisMapping (const Basis &basis) : ctxt_(basis.context()), basis_(basis) - + { assert(ctxt_.npcol() == 1); nprocs_ = ctxt_.size(); myproc_ = ctxt_.myproc(); - + np0_ = basis.np(0); np1_ = basis.np(1); np2_ = basis.np(2); @@ -31,7 +31,7 @@ BasisMapping::BasisMapping (const Basis &basis) : ctxt_(basis.context()), np2_first_.resize(nprocs_); // Block-cyclic distribution for np2 - // Partition np2 into nprocs_ intervals and + // Partition np2 into nprocs_ intervals and // store local sizes in np2_loc_[iproc] // Use same block distribution as in ScaLAPACK // Blocks 0,...,nprocs_-2 have size np2_block_size @@ -75,16 +75,16 @@ BasisMapping::BasisMapping (const Basis &basis) : ctxt_(basis.context()), { nvec_ = basis_.nrod_loc(); } - + // allocate send buffer sbuf.resize(nvec_ * np2_); - + // allocate receive buffer if ( basis_.real() ) rbuf.resize((2 * basis_.nrods() - 1) * np2_loc_[myproc_]); else rbuf.resize(basis_.nrods() * np2_loc_[myproc_]); - + // compute send/receive counts and displacements in units of sizeof(double) scounts.resize(nprocs_); @@ -119,13 +119,13 @@ BasisMapping::BasisMapping (const Basis &basis) : ctxt_(basis.context()), sdispl[iproc] = sdispl[iproc-1] + scounts[iproc-1]; rdispl[iproc] = rdispl[iproc-1] + rcounts[iproc-1]; } - + if ( basis_.real() ) { // compute index arrays ip_ and im_ for mapping vector->zvec ip_.resize(basis_.localsize()); im_.resize(basis_.localsize()); - + if ( myproc_ == 0 ) { // this process holds rod(0,0) @@ -210,7 +210,7 @@ BasisMapping::BasisMapping (const Basis &basis) : ctxt_(basis.context()), isource += np2_; } } - + // compute array iunpack // used in unpacking rbuf into val // val[iunpack[i]] = rbuf[i] @@ -228,7 +228,7 @@ BasisMapping::BasisMapping (const Basis &basis) : ctxt_(basis.context()), } int isource_p = np2_loc_[myproc_]; int isource_m = 2 * np2_loc_[myproc_]; - + // all rods of pe 0 for ( int irod = 1; irod < basis_.nrod_loc(0); irod++ ) { @@ -271,17 +271,17 @@ BasisMapping::BasisMapping (const Basis &basis) : ctxt_(basis.context()), int kp = basis_.rod_k(iproc,irod); if ( hp < 0 ) hp += np0_; if ( kp < 0 ) kp += np1_; - + int hm = -hp; int km = -kp; if ( hm < 0 ) hm += np0_; if ( km < 0 ) km += np1_; - + for ( int l = 0; l < np2_loc_[myproc_]; l++ ) { int idest_p = hp + np0_ * ( kp + np1_ * l ); iunpack_[isource_p+l] = idest_p; - + int idest_m = hm + np0_ * ( km + np1_ * l ); iunpack_[isource_m+l] = idest_m; } @@ -296,7 +296,7 @@ BasisMapping::BasisMapping (const Basis &basis) : ctxt_(basis.context()), // compute index array ip_ for mapping vector->zvec // Note: im_ is not used ip_.resize(basis_.localsize()); - + // map rods(h,k) // rod(h,k) maps onto column irod*np2_ of zvec_, irod=0,..,nrods-1 int ig = 0; @@ -333,7 +333,7 @@ BasisMapping::BasisMapping (const Basis &basis) : ctxt_(basis.context()), isource += np2_; } } - + // compute array iunpack // used in unpacking rbuf into val // val[iunpack[i]] = rbuf[i] @@ -355,18 +355,18 @@ BasisMapping::BasisMapping (const Basis &basis) : ctxt_(basis.context()), int k = basis_.rod_k(iproc,irod); if ( h < 0 ) h += np0_; if ( k < 0 ) k += np1_; - + for ( int l = 0; l < np2_loc_[myproc_]; l++ ) { int idest = h + np0_ * ( k + np1_ * l ); iunpack_[isource+l] = idest; - + } isource += np2_loc_[myproc_]; } } } - + #if USE_GATHER_SCATTER // shift index array by one for fortran ZGTHR and ZSCTR calls for ( int i = 0; i < iunpack_.size(); i++ ) @@ -381,7 +381,7 @@ BasisMapping::BasisMapping (const Basis &basis) : ctxt_(basis.context()), } //////////////////////////////////////////////////////////////////////////////// -void BasisMapping::transpose_fwd(const complex *zvec, +void BasisMapping::transpose_fwd(const complex *zvec, complex *ct) { // Transpose zvec to ct @@ -409,9 +409,9 @@ void BasisMapping::transpose_fwd(const complex *zvec, ps[2*ip+1] = b; } #endif - + // segments of z-vectors are now in sbuf - + // transpose #if USE_MPI int status = MPI_Alltoallv((double*)&sbuf[0],&scounts[0],&sdispl[0], @@ -426,7 +426,7 @@ void BasisMapping::transpose_fwd(const complex *zvec, assert(sbuf.size()==rbuf.size()); rbuf = sbuf; #endif - + // copy from rbuf to ct // scatter index array iunpack { @@ -438,7 +438,7 @@ void BasisMapping::transpose_fwd(const complex *zvec, pv[2*i+1] = 0.0; } } - + #if USE_GATHER_SCATTER // zsctr(n,x,indx,y): y(indx(i)) = x(i) { @@ -466,9 +466,9 @@ void BasisMapping::transpose_fwd(const complex *zvec, // coefficients are now in ct } - + //////////////////////////////////////////////////////////////////////////////// -void BasisMapping::transpose_bwd(const complex *ct, +void BasisMapping::transpose_bwd(const complex *ct, complex *zvec) { // transpose back distributed array ct into zvec @@ -496,7 +496,7 @@ void BasisMapping::transpose_bwd(const complex *ct, pr[2*i+1] = b; } #endif - + // transpose #if USE_MPI int status = MPI_Alltoallv((double*)&rbuf[0],&rcounts[0],&rdispl[0], @@ -507,10 +507,10 @@ void BasisMapping::transpose_bwd(const complex *ct, assert(sbuf.size()==rbuf.size()); rbuf = sbuf; #endif - + // segments of z-vectors are now in sbuf // gather sbuf into zvec_ - + #if USE_GATHER_SCATTER // zgthr: x(i) = y(indx(i)) // void zgthr_(int* n, complex* y, complex* x, int*indx); @@ -537,7 +537,7 @@ void BasisMapping::transpose_bwd(const complex *ct, } //////////////////////////////////////////////////////////////////////////////// -void BasisMapping::vector_to_zvec(const complex *c, +void BasisMapping::vector_to_zvec(const complex *c, complex *zvec) { // map coefficients from the basis order to a zvec @@ -551,7 +551,7 @@ void BasisMapping::vector_to_zvec(const complex *c, } const double* const pc = (const double*) c; if ( basis_.real() ) - { + { for ( int ig = 0; ig < ng; ig++ ) { // zvec[ip_[ig]] = c[ig]; @@ -578,7 +578,7 @@ void BasisMapping::vector_to_zvec(const complex *c, } } //////////////////////////////////////////////////////////////////////////////// -void BasisMapping::zvec_to_vector(const complex *zvec, +void BasisMapping::zvec_to_vector(const complex *zvec, complex *c) { const int ng = basis_.localsize(); diff --git a/src/BasisMapping.h b/src/BasisMapping.h index 609efcb..ecac7ea 100644 --- a/src/BasisMapping.h +++ b/src/BasisMapping.h @@ -3,7 +3,7 @@ // BasisMapping.h // //////////////////////////////////////////////////////////////////////////////// -// $Id: BasisMapping.h,v 1.1 2007-08-13 21:26:27 fgygi Exp $ +// $Id: BasisMapping.h,v 1.2 2007-10-19 16:24:04 fgygi Exp $ #ifndef BASISMAPPING_H #define BASISMAPPING_H @@ -24,16 +24,16 @@ class BasisMapping int np0_, np1_, np2_, np012_, np012loc_; int nvec_; - + std::vector np2_loc_; // np2_loc_[iproc], iproc=0, nprocs_-1 std::vector np2_first_; // np2_first_[iproc], iproc=0, nprocs_-1 - + std::vector scounts, sdispl, rcounts, rdispl; std::vector > sbuf, rbuf; std::vector ip_, im_; std::vector ipack_, iunpack_; - + public: BasisMapping (const Basis &basis); @@ -47,17 +47,17 @@ class BasisMapping int zvec_size(void) const { return nvec_ * np2_; } const Context& context(void) const { return ctxt_; } - + // map a function c(G) to zvec_ - void vector_to_zvec(const std::complex *c, + void vector_to_zvec(const std::complex *c, std::complex *zvec); // map zvec_ to a function c(G) - void zvec_to_vector(const std::complex *zvec, + void zvec_to_vector(const std::complex *zvec, std::complex *c); - - void transpose_fwd(const std::complex *zvec, + + void transpose_fwd(const std::complex *zvec, std::complex *ct); - void transpose_bwd(const std::complex *ct, + void transpose_bwd(const std::complex *ct, std::complex *zvec); }; #endif diff --git a/src/CPSampleStepper.C b/src/CPSampleStepper.C index dd725c9..e406130 100644 --- a/src/CPSampleStepper.C +++ b/src/CPSampleStepper.C @@ -3,7 +3,7 @@ // CPSampleStepper.C // //////////////////////////////////////////////////////////////////////////////// -// $Id: CPSampleStepper.C,v 1.12 2007-01-27 23:46:31 fgygi Exp $ +// $Id: CPSampleStepper.C,v 1.13 2007-10-19 16:24:04 fgygi Exp $ #include "CPSampleStepper.h" #include "SlaterDet.h" @@ -18,19 +18,19 @@ using namespace std; //////////////////////////////////////////////////////////////////////////////// -CPSampleStepper::CPSampleStepper(Sample& s) : +CPSampleStepper::CPSampleStepper(Sample& s) : SampleStepper(s), cd_(s.wf), ef_(s,cd_), dwf(s.wf), wfv(s.wfv) { const double emass = s.ctrl.emass; const double dt = s.ctrl.dt; - double dt2bye = (emass == 0.0) ? 0.5 / s.wf.ecut() : dt*dt/emass; - - // divide dt2bye by facs coefficient if stress == ON - const double facs = 2.0; - if ( s.ctrl.stress == "ON" ) - { - dt2bye /= facs; - } + double dt2bye = (emass == 0.0) ? 0.5 / s.wf.ecut() : dt*dt/emass; + + // divide dt2bye by facs coefficient if stress == ON + const double facs = 2.0; + if ( s.ctrl.stress == "ON" ) + { + dt2bye /= facs; + } mdwf_stepper = new MDWavefunctionStepper(s.wf,s.wfv,dt,dt2bye,tmap); assert(mdwf_stepper!=0); mdionic_stepper = 0; @@ -76,18 +76,18 @@ void CPSampleStepper::step(int niter) } return; } - + AtomSet& atoms = s_.atoms; Wavefunction& wf = s_.wf; - + const double dt = s_.ctrl.dt; double ekin_ion=0.0,ekin_e, temp_ion, eta; - + const string wf_dyn = s_.ctrl.wf_dyn; assert(wf_dyn=="MD"); const string atoms_dyn = s_.ctrl.atoms_dyn; const string cell_dyn = s_.ctrl.cell_dyn; - + const bool compute_hpsi = true; const bool compute_forces = ( atoms_dyn != "LOCKED" ); const bool compute_stress = ( s_.ctrl.stress == "ON" ); @@ -96,26 +96,26 @@ void CPSampleStepper::step(int niter) CellStepper* cell_stepper = 0; if ( cell_dyn == "SD" ) cell_stepper = new SDCellStepper(s_); - + if ( s_.wfv == 0 ) { s_.wfv = new Wavefunction(wf); s_.wfv->clear(); } - + if ( mdionic_stepper ) mdionic_stepper->setup_constraints(); - + Timer tm_iter; - + tmap["charge"].start(); cd_.update_density(); tmap["charge"].stop(); - + ef_.update_vhxc(); double energy = ef_.energy(compute_hpsi,dwf,compute_forces,fion,compute_stress,sigma_eks); - + mdwf_stepper->compute_wfm(dwf); for ( int iter = 0; iter < niter; iter++ ) @@ -124,14 +124,14 @@ void CPSampleStepper::step(int niter) tm_iter.start(); if ( s_.ctxt_.mype() == 0 ) cout << " \n"; - + if ( mdionic_stepper ) atoms.sync(); - + mdwf_stepper->update(dwf); - + ekin_e = mdwf_stepper->ekin(); - + if ( onpe0 ) { cout.setf(ios::fixed,ios::floatfield); @@ -161,16 +161,16 @@ void CPSampleStepper::step(int niter) << flush; } } - + if ( compute_forces ) { - if ( iter > 0 ) + if ( iter > 0 ) { mdionic_stepper->compute_v(energy,fion); } mdionic_stepper->compute_r(energy,fion); ekin_ion = mdionic_stepper->ekin(); - + if ( onpe0 ) { for ( int is = 0; is < atoms.atom_list.size(); is++ ) @@ -182,20 +182,20 @@ void CPSampleStepper::step(int niter) cout << " name() << "\"" << " species=\"" << pa->species() << "\">\n" - << " " + << " " << mdionic_stepper->r0(is,i) << " " - << mdionic_stepper->r0(is,i+1) << " " + << mdionic_stepper->r0(is,i+1) << " " << mdionic_stepper->r0(is,i+2) << " \n" - << " " + << " " << mdionic_stepper->v0(is,i) << " " - << mdionic_stepper->v0(is,i+1) << " " + << mdionic_stepper->v0(is,i+1) << " " << mdionic_stepper->v0(is,i+2) << " \n" - << " " + << " " << fion[is][i] << " " - << fion[is][i+1] << " " + << fion[is][i+1] << " " << fion[is][i+2] << " \n " << endl; - + i += 3; } } @@ -211,11 +211,11 @@ void CPSampleStepper::step(int niter) } #endif } - + if ( onpe0 ) { cout << " " << ekin_e << " \n"; - + if ( compute_forces ) { cout << " " << ekin_ion << " \n"; @@ -225,35 +225,35 @@ void CPSampleStepper::step(int niter) cout << " " << energy+ekin_ion+ekin_e << " \n"; cout << " " << energy+ekin_ion+2*ekin_e << " \n"; } - + if ( compute_stress ) { - if ( onpe0 ) - { - cout << "" << endl; - cout << s_.wf.cell(); - cout << "" << endl; - } + if ( onpe0 ) + { + cout << "" << endl; + cout << s_.wf.cell(); + cout << "" << endl; + } compute_sigma(); print_stress(); - + if ( cell_dyn != "LOCKED" ) { cell_stepper->compute_new_cell(sigma); - + // Update cell cell_stepper->update_cell(); - + ef_.cell_moved(); ef_.atoms_moved(); } } - + if ( compute_forces ) { ef_.atoms_moved(); } - + tmap["charge"].start(); cd_.update_density(); tmap["charge"].stop(); @@ -281,17 +281,17 @@ void CPSampleStepper::step(int niter) if ( compute_forces ) s_.constraints.update_constraints(dt); } // iter - + // dwf and fion now contain the forces on wavefunctions and ions at the // endpoint - + mdwf_stepper->compute_wfv(dwf); // replace wfm by wfv - + if ( compute_forces ) { // Note: next line function call updates velocities in the AtomSet mdionic_stepper->compute_v(energy,fion); } - + if ( cell_stepper != 0 ) delete cell_stepper; } diff --git a/src/CPSampleStepper.h b/src/CPSampleStepper.h index 5bae677..f0e08ac 100644 --- a/src/CPSampleStepper.h +++ b/src/CPSampleStepper.h @@ -3,7 +3,7 @@ // CPSampleStepper.h // //////////////////////////////////////////////////////////////////////////////// -// $Id: CPSampleStepper.h,v 1.4 2007-03-17 01:14:00 fgygi Exp $ +// $Id: CPSampleStepper.h,v 1.5 2007-10-19 16:24:04 fgygi Exp $ #ifndef CPSAMPLESTEPPER_H #define CPSAMPLESTEPPER_H @@ -19,12 +19,12 @@ class MDIonicStepper; class CPSampleStepper : public SampleStepper { private: - + ChargeDensity cd_; EnergyFunctional ef_; Wavefunction dwf; Wavefunction* wfv; - + MDWavefunctionStepper* mdwf_stepper; MDIonicStepper* mdionic_stepper; @@ -34,7 +34,7 @@ class CPSampleStepper : public SampleStepper public: mutable TimerMap tmap; - + void step(int niter); CPSampleStepper(Sample& s); diff --git a/src/Cell.h b/src/Cell.h index 77ef9cb..0249631 100644 --- a/src/Cell.h +++ b/src/Cell.h @@ -3,7 +3,7 @@ // Cell.h // //////////////////////////////////////////////////////////////////////////////// -// $Id: Cell.h,v 1.4 2003-09-16 16:24:26 fgygi Exp $ +// $Id: Cell.h,v 1.5 2007-10-19 16:24:04 fgygi Exp $ #ifndef CELL_H #define CELL_H @@ -31,12 +31,12 @@ class Cell : public Var cout << " cell must be specified with 3 vectors (9 values)" << endl; return 1; } - + D3vector a0(atof(argv[1]),atof(argv[2]),atof(argv[3])); D3vector a1(atof(argv[4]),atof(argv[5]),atof(argv[6])); D3vector a2(atof(argv[7]),atof(argv[8]),atof(argv[9])); UnitCell cell(a0,a1,a2); - + if ( cell.volume() < 0.0 ) { if ( ui->onpe0() ) @@ -50,11 +50,11 @@ class Cell : public Var s->wfv->resize(cell,s->wf.refcell(),s->wf.ecut()); s->wfv->clear(); } - + if ( ui->onpe0() ) { cout << " \n" - << s->wf.cell() + << s->wf.cell() << " " << endl; } return 0; diff --git a/src/CellDyn.h b/src/CellDyn.h index b93e2d0..f2d1139 100644 --- a/src/CellDyn.h +++ b/src/CellDyn.h @@ -3,7 +3,7 @@ // CellDyn.h // //////////////////////////////////////////////////////////////////////////////// -// $Id: CellDyn.h,v 1.2 2004-03-11 21:52:31 fgygi Exp $ +// $Id: CellDyn.h,v 1.3 2007-10-19 16:24:04 fgygi Exp $ #ifndef CELLDYN_H #define CELLDYN_H @@ -33,7 +33,7 @@ class CellDyn : public Var cout << " cell_dyn takes only one value" << endl; return 1; } - + string v = argv[1]; if ( !( v == "LOCKED" || v == "SD" ) ) { @@ -43,7 +43,7 @@ class CellDyn : public Var } s->ctrl.cell_dyn = v; - + return 0; } diff --git a/src/CellLock.h b/src/CellLock.h index 237ec5b..8e357d3 100644 --- a/src/CellLock.h +++ b/src/CellLock.h @@ -3,7 +3,7 @@ // CellLock.h // //////////////////////////////////////////////////////////////////////////////// -// $Id: CellLock.h,v 1.3 2004-05-04 21:24:11 fgygi Exp $ +// $Id: CellLock.h,v 1.4 2007-10-19 16:24:04 fgygi Exp $ #ifndef CELLLOCK_H #define CELLLOCK_H @@ -31,7 +31,7 @@ class CellLock : public Var cout << " cell_lock takes only one value" << endl; return 1; } - + string v = argv[1]; if ( !( v == "OFF" || v == "A" || v == "B" || v == "C" || v == "AB" || v == "AC" || v == "BC" || v == "ABC" || @@ -45,7 +45,7 @@ class CellLock : public Var } s->ctrl.cell_lock = v; - + return 0; } diff --git a/src/CellMass.h b/src/CellMass.h index 040e144..dac23b0 100644 --- a/src/CellMass.h +++ b/src/CellMass.h @@ -3,7 +3,7 @@ // CellMass.h // //////////////////////////////////////////////////////////////////////////////// -// $Id: CellMass.h,v 1.1 2004-02-04 19:52:27 fgygi Exp $ +// $Id: CellMass.h,v 1.2 2007-10-19 16:24:04 fgygi Exp $ #ifndef CELLMASS_H #define CELLMASS_H @@ -31,7 +31,7 @@ class CellMass : public Var cout << " cell_mass takes only one value" << endl; return 1; } - + double v = atof(argv[1]); if ( v <= 0.0 ) { diff --git a/src/CellStepper.h b/src/CellStepper.h index e62a8de..d6cfc00 100644 --- a/src/CellStepper.h +++ b/src/CellStepper.h @@ -3,7 +3,7 @@ // CellStepper.h: // //////////////////////////////////////////////////////////////////////////////// -// $Id: CellStepper.h,v 1.2 2007-03-17 01:14:00 fgygi Exp $ +// $Id: CellStepper.h,v 1.3 2007-10-19 16:24:04 fgygi Exp $ #ifndef CELLSTEPPER_H #define CELLSTEPPER_H @@ -14,19 +14,19 @@ class CellStepper { protected: - + Sample& s_; AtomSet& atoms_; double ekin_; UnitCell cellp; public: - + CellStepper (Sample& s) : s_(s), atoms_(s.atoms), ekin_(0.0) {} - + virtual void compute_new_cell(const std::valarray& sigma) = 0; virtual void update_cell(void) = 0; - + double ekin(void) const { return ekin_; } virtual ~CellStepper() {} }; diff --git a/src/ChargeDensity.C b/src/ChargeDensity.C index 4c7016b..904f781 100644 --- a/src/ChargeDensity.C +++ b/src/ChargeDensity.C @@ -3,7 +3,7 @@ // ChargeDensity.C // //////////////////////////////////////////////////////////////////////////////// -// $Id: ChargeDensity.C,v 1.11 2004-11-10 22:30:53 fgygi Exp $ +// $Id: ChargeDensity.C,v 1.12 2007-10-19 16:24:04 fgygi Exp $ #include "ChargeDensity.h" #include "Basis.h" @@ -16,19 +16,19 @@ using namespace std; //////////////////////////////////////////////////////////////////////////////// ChargeDensity::ChargeDensity(const Wavefunction& wf) : ctxt_(wf.context()), -wf_(wf), vcontext_(wf.sd(0,0)->basis().context()) +wf_(wf), vcontext_(wf.sd(0,0)->basis().context()) { vbasis_ = new Basis(vcontext_, D3vector(0,0,0)); vbasis_->resize(wf.cell(),wf.refcell(),4.0*wf.ecut()); - + // define vft_, FT on vbasis context for transforming the density - + int np0v = vbasis_->np(0); int np1v = vbasis_->np(1); int np2v = vbasis_->np(2); vft_ = new FourierTransform(*vbasis_,np0v,np1v,np2v); - + rhor.resize(wf.nspin()); rhog.resize(wf.nspin()); for ( int ispin = 0; ispin < wf.nspin(); ispin++ ) @@ -37,7 +37,7 @@ wf_(wf), vcontext_(wf.sd(0,0)->basis().context()) rhog[ispin].resize(vbasis_->localsize()); } rhotmp.resize(vft_->np012loc()); - + // FT for interpolation of wavefunctions on the fine grid ft_.resize(wf.nkp()); for ( int ispin = 0; ispin < wf.nspin(); ispin++ ) @@ -82,7 +82,7 @@ void ChargeDensity::update_density(void) { assert(rhor.size() == wf_.nspin()); const double omega = vbasis_->cell().volume(); - + for ( int ispin = 0; ispin < wf_.nspin(); ispin++ ) { if ( wf_.spincontext(ispin)->active()) @@ -94,20 +94,20 @@ void ChargeDensity::update_density(void) { if ( wf_.sd(ispin,ikp) != 0 && wf_.sdcontext(ispin,ikp)->active() ) { - + wf_.sd(ispin,ikp)->compute_density(*ft_[ikp], wf_.weight(ikp), &rhor[ispin][0]); - + } } tmap["charge_compute"].stop(); - + // sum across rows of spincontext[ispin] context tmap["charge_rowsum"].start(); wf_.spincontext(ispin)->dsum('r',vft_->np012loc(),1, &rhor[ispin][0],vft_->np012loc()); tmap["charge_rowsum"].stop(); - + // check integral of charge density // compute Fourier coefficients of the charge density double sum = 0.0; @@ -129,10 +129,10 @@ void ChargeDensity::update_density(void) { cout.setf(ios::fixed,ios::floatfield); cout.setf(ios::right,ios::adjustfield); - cout << " " << endl; } - + tmap["charge_vft"].start(); vft_->forward(&rhotmp[0],&rhog[ispin][0]); tmap["charge_vft"].stop(); @@ -147,14 +147,14 @@ void ChargeDensity::update_rhor(void) const double omega = vbasis_->cell().volume(); assert(omega!=0.0); const double omega_inv = 1.0 / omega; - + for ( int ispin = 0; ispin < wf_.nspin(); ispin++ ) { if ( wf_.spincontext(ispin)->active()) { assert(rhor[ispin].size() == vft_->np012loc() ); assert(rhotmp.size() == vft_->np012loc() ); - + vft_->backward(&rhog[ispin][0],&rhotmp[0]); const int rhor_size = rhor[ispin].size(); @@ -168,4 +168,4 @@ void ChargeDensity::update_rhor(void) } } - + diff --git a/src/ChargeDensity.h b/src/ChargeDensity.h index 615e56a..c629e88 100644 --- a/src/ChargeDensity.h +++ b/src/ChargeDensity.h @@ -3,7 +3,7 @@ // ChargeDensity.h // //////////////////////////////////////////////////////////////////////////////// -// $Id: ChargeDensity.h,v 1.5 2007-03-17 01:14:00 fgygi Exp $ +// $Id: ChargeDensity.h,v 1.6 2007-10-19 16:24:04 fgygi Exp $ #ifndef CHARGEDENSITY_H #define CHARGEDENSITY_H @@ -25,7 +25,7 @@ typedef std::map TimerMap; class ChargeDensity { private: - + const Context& ctxt_; const Context& vcontext_; const Wavefunction& wf_; @@ -33,9 +33,9 @@ class ChargeDensity FourierTransform* vft_; std::vector ft_; // ft_[ikp]; std::valarray > rhotmp; - + public: - + mutable TimerMap tmap; std::vector > rhor; // rhor[ispin][i] @@ -43,7 +43,7 @@ class ChargeDensity void update_density(void); void update_rhor(void); - + Basis* vbasis(void) const { return vbasis_; } const Context& vcontext(void) const { return vcontext_; } FourierTransform* vft(void) const { return vft_; } diff --git a/src/ChargeMixCoeff.h b/src/ChargeMixCoeff.h index 1bfc5dd..5487885 100644 --- a/src/ChargeMixCoeff.h +++ b/src/ChargeMixCoeff.h @@ -3,7 +3,7 @@ // ChargeMixCoeff.h // //////////////////////////////////////////////////////////////////////////////// -// $Id: ChargeMixCoeff.h,v 1.3 2007-09-30 04:44:58 fgygi Exp $ +// $Id: ChargeMixCoeff.h,v 1.4 2007-10-19 16:24:04 fgygi Exp $ #ifndef CHARGEMIXCOEFF_H #define CHARGEMIXCOEFF_H @@ -31,7 +31,7 @@ class ChargeMixCoeff : public Var cout << " charge_mix_coeff takes only one value" << endl; return 1; } - + double v = atof(argv[1]); if ( v < 0.0 ) { diff --git a/src/ChargeMixRcut.h b/src/ChargeMixRcut.h index 1a19073..a80a023 100644 --- a/src/ChargeMixRcut.h +++ b/src/ChargeMixRcut.h @@ -3,7 +3,7 @@ // ChargeMixRcut.h // //////////////////////////////////////////////////////////////////////////////// -// $Id: ChargeMixRcut.h,v 1.1 2004-12-02 22:20:23 fgygi Exp $ +// $Id: ChargeMixRcut.h,v 1.2 2007-10-19 16:24:04 fgygi Exp $ #ifndef CHARGEMIXRCUT_H #define CHARGEMIXRCUT_H @@ -31,7 +31,7 @@ class ChargeMixRcut : public Var cout << " charge_mix_rcut takes only one value" << endl; return 1; } - + double v = atof(argv[1]); if ( v < 0.0 ) { diff --git a/src/ComputeMLWFCmd.C b/src/ComputeMLWFCmd.C index 38f752a..96176ae 100644 --- a/src/ComputeMLWFCmd.C +++ b/src/ComputeMLWFCmd.C @@ -3,7 +3,7 @@ // ComputeMLWFCmd.C: // //////////////////////////////////////////////////////////////////////////////// -// $Id: ComputeMLWFCmd.C,v 1.4 2007-10-16 18:23:20 fgygi Exp $ +// $Id: ComputeMLWFCmd.C,v 1.5 2007-10-19 16:24:04 fgygi Exp $ #include "ComputeMLWFCmd.h" #include @@ -15,9 +15,9 @@ int ComputeMLWFCmd::action(int argc, char **argv) { Wavefunction& wf = s->wf; SlaterDet& sd = *(wf.sd(0,0)); - + mlwft = new MLWFTransform(sd); - + mlwft->compute_transform(); mlwft->apply_transform(sd); @@ -30,7 +30,7 @@ int ComputeMLWFCmd::action(int argc, char **argv) double sp = mlwft->spread(i); cout.setf(ios::fixed, ios::floatfield); cout.setf(ios::right, ios::adjustfield); - cout << " fstress_, dfstress_; public: - + double facs(void) const { return facs_; } double sigmas(void) const { return sigmas_; } double ecuts(void) const { return ecuts_; } - + const std::valarray& fstress(void) const { return fstress_; } const std::valarray& dfstress(void) const { return dfstress_; } - + void update(void); - + const Basis& basis() const { return basis_; } - ConfinementPotential(double ecuts, double facs, double sigmas, + ConfinementPotential(double ecuts, double facs, double sigmas, const Basis& basis); ~ConfinementPotential(); }; diff --git a/src/Constraint.C b/src/Constraint.C index 2908cfc..66fefcc 100644 --- a/src/Constraint.C +++ b/src/Constraint.C @@ -3,7 +3,7 @@ // Constraint.C // //////////////////////////////////////////////////////////////////////////////// -// $Id: Constraint.C,v 1.1 2005-06-27 22:34:46 fgygi Exp $ +// $Id: Constraint.C,v 1.2 2007-10-19 16:24:04 fgygi Exp $ #include "Constraint.h" #include @@ -12,5 +12,5 @@ using namespace std; ostream& operator << ( ostream &os, Constraint &c ) { return c.print(os); -} - +} + diff --git a/src/Constraint.h b/src/Constraint.h index e461f61..14f9d6f 100644 --- a/src/Constraint.h +++ b/src/Constraint.h @@ -3,7 +3,7 @@ // Constraint.h // //////////////////////////////////////////////////////////////////////////////// -// $Id: Constraint.h,v 1.3 2007-03-17 01:14:00 fgygi Exp $ +// $Id: Constraint.h,v 1.4 2007-10-19 16:24:04 fgygi Exp $ #ifndef CONSTRAINT_H #define CONSTRAINT_H @@ -17,12 +17,12 @@ class AtomSet; class Constraint { protected: - + std::string name_; // constraint name std::vector names_; // names of atoms involved in the constraint - + public: - + virtual std::string type(void) const = 0; virtual double value(void) const = 0; virtual double velocity(void) const = 0; @@ -49,5 +49,5 @@ class Constraint }; std::ostream& operator << ( std::ostream &os, Constraint &c ); #endif - - + + diff --git a/src/ConstraintCmd.h b/src/ConstraintCmd.h index 6cd6d3a..b8a2bd9 100644 --- a/src/ConstraintCmd.h +++ b/src/ConstraintCmd.h @@ -3,7 +3,7 @@ // ConstraintCmd.h: // //////////////////////////////////////////////////////////////////////////////// -// $Id: ConstraintCmd.h,v 1.2 2005-09-16 23:08:11 fgygi Exp $ +// $Id: ConstraintCmd.h,v 1.3 2007-10-19 16:24:04 fgygi Exp $ #ifndef CONSTRAINTCMD_H #define CONSTRAINTCMD_H @@ -22,7 +22,7 @@ class ConstraintCmd : public Cmd char *name(void) const { return "constraint"; } char *help_msg(void) const { - return + return "\n constraint\n\n" " syntax:\n\n" " constraint define distance name atom1 atom2 distance [velocity]\n" @@ -75,7 +75,7 @@ class ConstraintCmd : public Cmd if ( onpe0 ) cout << help_msg(); } - + return 0; } }; diff --git a/src/ConstraintSet.C b/src/ConstraintSet.C index 5299d6f..fbaf68b 100644 --- a/src/ConstraintSet.C +++ b/src/ConstraintSet.C @@ -3,7 +3,7 @@ // ConstraintSet.C // //////////////////////////////////////////////////////////////////////////////// -// $Id: ConstraintSet.C,v 1.2 2005-09-16 23:08:11 fgygi Exp $ +// $Id: ConstraintSet.C,v 1.3 2007-10-19 16:24:04 fgygi Exp $ #include "ConstraintSet.h" #include "DistanceConstraint.h" @@ -22,13 +22,13 @@ const int constraints_maxiter = 10; //////////////////////////////////////////////////////////////////////////////// bool ConstraintSet::define_constraint(AtomSet &atoms, int argc, char **argv) { - enum constraint_type { unknown, distance_type, multidistance_type, + enum constraint_type { unknown, distance_type, multidistance_type, angle_type, torsion_type } type = unknown; const double distance_tolerance = 1.0e-7; const double angle_tolerance = 1.0e-4; const bool onpe0 = ctxt_.onpe0(); - + // argv[0] == "constraint" // argv[1] == "define" // argv[2] == {"distance", "angle", "torsion"} @@ -41,12 +41,12 @@ bool ConstraintSet::define_constraint(AtomSet &atoms, int argc, char **argv) { if ( onpe0 ) { - cout << " " + << " [velocity] -->" << endl; } return false; @@ -66,12 +66,12 @@ bool ConstraintSet::define_constraint(AtomSet &atoms, int argc, char **argv) } else { - if ( onpe0 ) - cout << " " << endl; return false; } - + if ( type == distance_type ) { // define name distance A B value @@ -79,8 +79,8 @@ bool ConstraintSet::define_constraint(AtomSet &atoms, int argc, char **argv) if ( argc < 7 || argc > 8 ) { - if ( onpe0 ) - cout << " " << endl; return false; } @@ -88,10 +88,10 @@ bool ConstraintSet::define_constraint(AtomSet &atoms, int argc, char **argv) string name = argv[3]; string name1 = argv[4]; string name2 = argv[5]; - + Atom *a1 = atoms.findAtom(name1); Atom *a2 = atoms.findAtom(name2); - + if ( a1 == 0 || a2 == 0 ) { if ( onpe0 ) @@ -102,25 +102,25 @@ bool ConstraintSet::define_constraint(AtomSet &atoms, int argc, char **argv) if ( a2 == 0 ) cout << " " << endl; - + cout << " " << endl; } return false; } if ( name1 == name2 ) { - if ( onpe0 ) + if ( onpe0 ) cout << " " << endl; return false; } - + distance = atof(argv[6]); if ( argc == 8 ) { velocity = atof(argv[7]); } - + if ( distance <= 0.0 ) { if ( onpe0 ) @@ -128,7 +128,7 @@ bool ConstraintSet::define_constraint(AtomSet &atoms, int argc, char **argv) << " " << endl; return false; } - + // check if constraint is already defined bool found = false; Constraint *pc = 0; @@ -144,7 +144,7 @@ bool ConstraintSet::define_constraint(AtomSet &atoms, int argc, char **argv) if ( pc->type() == "distance" && pc->name() == name ) found = true; } - + if ( found ) { if ( onpe0 ) @@ -157,7 +157,7 @@ bool ConstraintSet::define_constraint(AtomSet &atoms, int argc, char **argv) DistanceConstraint *c = new DistanceConstraint(name,name1,name2,distance, velocity,distance_tolerance); - + constraint_list.push_back(c); } } @@ -177,17 +177,17 @@ bool ConstraintSet::define_constraint(AtomSet &atoms, int argc, char **argv) string name1 = argv[4]; string name2 = argv[5]; string name3 = argv[6]; - + Atom *a1 = atoms.findAtom(name1); Atom *a2 = atoms.findAtom(name2); Atom *a3 = atoms.findAtom(name3); - + if ( a1 == 0 || a2 == 0 || a3 == 0 ) { - if ( onpe0 ) + if ( onpe0 ) { if ( a1 == 0 ) - cout << " " << endl; if ( a2 == 0 ) cout << " " << endl; return false; } - + const double angle = atof(argv[7]); double velocity = 0.0; if ( argc == 9 ) { velocity = atof(argv[8]); } - + if ( angle < 0.0 || angle > 180.0 ) { if ( onpe0 ) @@ -222,7 +222,7 @@ bool ConstraintSet::define_constraint(AtomSet &atoms, int argc, char **argv) << " " << endl; return false; } - + // check if equivalent constraint is already defined bool found = false; Constraint *pc = 0; @@ -230,18 +230,18 @@ bool ConstraintSet::define_constraint(AtomSet &atoms, int argc, char **argv) { pc = constraint_list[i]; assert(pc != 0); - // check if a constraint (name1,name2,name3) or + // check if a constraint (name1,name2,name3) or // (name3,name2,name1) is defined if ( pc->type() == "angle" && - ( pc->names(0) == name1 && - pc->names(1) == name2 && + ( pc->names(0) == name1 && + pc->names(1) == name2 && pc->names(2) == name3) || - ( pc->names(0) == name3 && + ( pc->names(0) == name3 && pc->names(1) == name2 && pc->names(2) == name1) ) found = true; } - + if ( found ) { if ( onpe0 ) @@ -276,18 +276,18 @@ bool ConstraintSet::define_constraint(AtomSet &atoms, int argc, char **argv) string name2 = argv[5]; string name3 = argv[6]; string name4 = argv[7]; - + Atom *a1 = atoms.findAtom(name1); Atom *a2 = atoms.findAtom(name2); Atom *a3 = atoms.findAtom(name3); Atom *a4 = atoms.findAtom(name4); - + if ( a1 == 0 || a2 == 0 || a3 == 0 || a4 == 0 ) { if ( onpe0 ) - { + { if ( a1 == 0 ) - cout << " " << endl; if ( a2 == 0 ) cout << " " << endl; - + cout << " " << endl; } return false; @@ -306,13 +306,13 @@ bool ConstraintSet::define_constraint(AtomSet &atoms, int argc, char **argv) if ( name1 == name2 || name1 == name3 || name1 == name4 || name2 == name3 || name2 == name4 || name3 == name4 ) { - if ( onpe0 ) + if ( onpe0 ) cout << " " << endl; return false; } - + double angle = atof(argv[8]); if ( angle > 180.0 ) while ( angle > 180.0 ) angle -= 360.0; @@ -324,7 +324,7 @@ bool ConstraintSet::define_constraint(AtomSet &atoms, int argc, char **argv) { velocity = atof(argv[9]); } - + // check if equivalent constraint is already defined bool found = false; Constraint *pc = 0; @@ -332,20 +332,20 @@ bool ConstraintSet::define_constraint(AtomSet &atoms, int argc, char **argv) { pc = constraint_list[i]; assert(pc != 0); - // check if an equivalent constraint (name1,name2,name3,name4) or + // check if an equivalent constraint (name1,name2,name3,name4) or // (name4,name3,name2,name1) is defined if ( pc->type() == "angle" && - ( pc->names(0) == name1 && - pc->names(1) == name2 && - pc->names(2) == name3 && + ( pc->names(0) == name1 && + pc->names(1) == name2 && + pc->names(2) == name3 && pc->names(3) == name4) || - ( pc->names(0) == name4 && + ( pc->names(0) == name4 && pc->names(1) == name3 && pc->names(2) == name2 && pc->names(3) == name1) ) found = true; } - + if ( found ) { if ( onpe0 ) @@ -369,7 +369,7 @@ bool ConstraintSet::define_constraint(AtomSet &atoms, int argc, char **argv) cout << "" << endl; return false; } - + return true; } @@ -388,27 +388,27 @@ bool ConstraintSet::set_constraint(int argc, char **argv) double velocity = 0.0; const bool set_velocity = ( argc == 5 ); if ( set_velocity ) velocity = atof(argv[4]); - + // check if constraint is already defined bool found = false; - vector::iterator i = constraint_list.begin(); - while ( !found && i != constraint_list.end() ) - { - Constraint *pc = *i; - assert(pc != 0); - - if ( pc->name() == name ) + vector::iterator i = constraint_list.begin(); + while ( !found && i != constraint_list.end() ) + { + Constraint *pc = *i; + assert(pc != 0); + + if ( pc->name() == name ) { - found = true; + found = true; pc->set_value(value); if ( set_velocity ) pc->set_velocity(velocity); } i++; } - - if ( !found ) - { - if ( onpe0 ) + + if ( !found ) + { + if ( onpe0 ) cout << " " << endl; return false; } @@ -425,33 +425,33 @@ bool ConstraintSet::delete_constraint(int argc, char **argv) string name = argv[2]; const bool onpe0 = ctxt_.onpe0(); - bool found = false; - // note next loop in reverse: avoid use of invalidated iterators - // after erase operation - - vector::iterator i = constraint_list.begin(); - while ( !found && i != constraint_list.end() ) - { - Constraint *pc = *i; - assert(pc != 0); - - // note structure of if else test to avoid incrementing - // invalidated iterator after erase (see Meyers STL, p.45) - if ( pc->name() == name ) + bool found = false; + // note next loop in reverse: avoid use of invalidated iterators + // after erase operation + + vector::iterator i = constraint_list.begin(); + while ( !found && i != constraint_list.end() ) + { + Constraint *pc = *i; + assert(pc != 0); + + // note structure of if else test to avoid incrementing + // invalidated iterator after erase (see Meyers STL, p.45) + if ( pc->name() == name ) { - found = true; - delete pc; - - // remove constraint pointer from the list - // note: iterator is incremented before erasing, remains valid - constraint_list.erase(i++); + found = true; + delete pc; + + // remove constraint pointer from the list + // note: iterator is incremented before erasing, remains valid + constraint_list.erase(i++); + } + else + { + i++; } - else - { - i++; - } } - + if ( !found ) { if ( onpe0 ) cout << " " << endl; @@ -495,7 +495,7 @@ void ConstraintSet::enforce_r(const vector > &r0, const bool onpe0 = ctxt_.onpe0(); int iter = 0; bool done = false; - while ( !done && (iter < constraints_maxiter) ) + while ( !done && (iter < constraints_maxiter) ) { done = true; for ( int i = 0; i < constraint_list.size(); i++ ) @@ -506,7 +506,7 @@ void ConstraintSet::enforce_r(const vector > &r0, } iter++; } - + if ( !done ) { if ( onpe0 ) @@ -522,7 +522,7 @@ void ConstraintSet::enforce_v(const vector > &r0, const bool onpe0 = ctxt_.onpe0(); int iter = 0; bool done = false; - while ( !done && (iter < constraints_maxiter) ) + while ( !done && (iter < constraints_maxiter) ) { done = true; for ( int i = 0; i < constraint_list.size(); i++ ) @@ -532,7 +532,7 @@ void ConstraintSet::enforce_v(const vector > &r0, } iter++; } - + if ( !done ) { if ( onpe0 ) diff --git a/src/ConstraintSet.h b/src/ConstraintSet.h index 3abfb7f..ea6519a 100644 --- a/src/ConstraintSet.h +++ b/src/ConstraintSet.h @@ -3,7 +3,7 @@ // ConstraintSet.h // //////////////////////////////////////////////////////////////////////////////// -// $Id: ConstraintSet.h,v 1.3 2007-03-17 01:14:00 fgygi Exp $ +// $Id: ConstraintSet.h,v 1.4 2007-10-19 16:24:04 fgygi Exp $ #ifndef CONSTRAINTSET_H #define CONSTRAINTSET_H @@ -19,10 +19,10 @@ class Context; class ConstraintSet { private: - + const Context& ctxt_; std::vector constraint_list; - + public: ConstraintSet(const Context& ctxt) : ctxt_(ctxt) {} diff --git a/src/Context.C b/src/Context.C index 4fc5461..2e43c9e 100644 --- a/src/Context.C +++ b/src/Context.C @@ -3,7 +3,7 @@ // Context.C // //////////////////////////////////////////////////////////////////////////////// -// $Id: Context.C,v 1.13 2007-03-17 01:14:00 fgygi Exp $ +// $Id: Context.C,v 1.14 2007-10-19 16:24:04 fgygi Exp $ #include "Context.h" #include @@ -59,7 +59,7 @@ void Cblacs_gridexit(int icontxt) return; } -void Cblacs_gridinfo(int icontxt, int *nprow, int *npcol, +void Cblacs_gridinfo(int icontxt, int *nprow, int *npcol, int *myprow, int *mypcol) { *nprow=1; *npcol=1; *myprow=0; *mypcol=0; return; @@ -74,7 +74,7 @@ void Cdgesd2d(int icontxt,int m,int n,double *A,int lda,int rdest,int cdest) void Cdgerv2d(int icontxt,int m,int n,double *A,int lda,int rdest,int cdest) { return; } -void Cdgsum2d(int icontxt, char* scope, char* top, +void Cdgsum2d(int icontxt, char* scope, char* top, int m, int n, double *a, int lda, int rdest, int cdest) { return; } @@ -100,15 +100,15 @@ void Cigesd2d(int icontxt,int m,int n,int *A,int lda,int rdest,int cdest) void Cigerv2d(int icontxt,int m,int n,int *A,int lda,int rdest,int cdest) { return; } -void Cigsum2d(int icontxt, char* scope, char* top, +void Cigsum2d(int icontxt, char* scope, char* top, int m, int n, int *a, int lda, int rdest, int cdest) { return; } -void Cigamx2d(int icontxt, char scope[], char top[],int m,int n,int *A,int lda, +void Cigamx2d(int icontxt, char scope[], char top[],int m,int n,int *A,int lda, int *ra, int *ca, int rcflag, int rdest, int cdest) { return; } -void Cigamn2d(int icontxt, char scope[], char top[],int m,int n,int *A,int lda, +void Cigamn2d(int icontxt, char scope[], char top[],int m,int n,int *A,int lda, int *ra, int *ca, int rcflag, int rdest, int cdest) { return; } @@ -130,9 +130,9 @@ const int MPI_COMM_NULL = 0; #endif struct ContextRep -{ +{ private: - + int ictxt_; int myrow_; int mycol_; @@ -143,22 +143,22 @@ struct ContextRep int mype_; bool onpe0_; bool active_; - + vector pmap_; MPI_Comm comm_; - + // keep assignment and copy constructors private ContextRep& operator=(const Context& c); ContextRep(const Context& c); public: - + int ictxt() const { return ictxt_; } int myrow() const { return myrow_; } int mycol() const { return mycol_; } int nprow() const { return nprow_; } int npcol() const { return npcol_; } - + // number of processes in the context // returns -1 if current process is not part of this context int size() const { return size_; } @@ -167,117 +167,117 @@ struct ContextRep int myproc() const { return myproc_; } int mype() const { return mype_; } int pmap(int irow, int icol) const { return pmap_[irow+nprow_*icol]; } - + bool onpe0(void) const { return onpe0_; } bool active(void) const { return active_; } void abort(int ierr) const { Cblacs_abort(ictxt_,ierr); } void barrier(void) const { Cblacs_barrier(ictxt_,"A"); } void barrier(char scope) const { Cblacs_barrier(ictxt_,&scope); } - + void dsend(int m, int n, double* a, int lda, int rdest, int cdest) const { Cdgesd2d(ictxt_,m,n,a,lda,rdest,cdest); } - + void drecv(int m, int n, double* a, int lda, int rsrc, int csrc) const { Cdgerv2d(ictxt_,m,n,a,lda,rsrc,csrc); } - + void dsum(char scope, char topology, int m, int n, double* a, int lda, int rdest, int cdest) const { Cdgsum2d(ictxt_,&scope,&topology,m,n,a,lda,rdest,cdest); } - + void dmax(char scope, char topology, int m, int n, double* a, int lda, int rdest, int cdest) const { Cdgamx2d(ictxt_,&scope,&topology,m,n,a,lda,(int*)0,(int*)0,-1,rdest,cdest); } - + void dmax(char scope, char topology, int m, int n, double* a, int lda, int* ra, int* ca, int rcflag, int rdest, int cdest) const { Cdgamx2d(ictxt_,&scope,&topology,m,n,a,lda,ra,ca,rcflag,rdest,cdest); } - + void dmin(char scope, char topology, int m, int n, double* a, int lda, int* ra, int* ca, int rcflag, int rdest, int cdest) const { Cdgamn2d(ictxt_,&scope,&topology,m,n,a,lda,ra,ca,rcflag,rdest,cdest); } - + void dmin(char scope, char topology, int m, int n, double* a, int lda, int rdest, int cdest) const { Cdgamn2d(ictxt_,&scope,&topology,m,n,a,lda,(int*)0,(int*)0,-1,rdest,cdest); } - - void dbcast_send(char scope, char topology, + + void dbcast_send(char scope, char topology, int m, int n, double* a,int lda) const { Cdgebs2d(ictxt_,&scope,&topology,m,n,a,lda); } - + void dbcast_recv(char scope, char topology, int m, int n, double* a, int lda, int rsrc, int csrc) const { Cdgebr2d(ictxt_,&scope,&topology,m,n,a,lda,rsrc,csrc); } - + void isend(int m, int n, int* a, int lda, int rdest, int cdest) const { Cigesd2d(ictxt_,m,n,a,lda,rdest,cdest); } - + void irecv(int m, int n, int* a, int lda, int rsrc, int csrc) const { Cigerv2d(ictxt_,m,n,a,lda,rsrc,csrc); } - + void isum(char scope, char topology, int m, int n, int* a, int lda, int rdest, int cdest) const { Cigsum2d(ictxt_,&scope,&topology,m,n,a,lda,rdest,cdest); } - + void imax(char scope, char topology, int m, int n, int* a, int lda, int* ra, int* ca, int rcflag, int rdest, int cdest) const { Cigamx2d(ictxt_,&scope,&topology,m,n,a,lda,ra,ca,rcflag,rdest,cdest); } - + void imax(char scope, char topology, int m, int n, int* a, int lda, int rdest, int cdest) const { Cigamx2d(ictxt_,&scope,&topology,m,n,a,lda,(int*)0,(int*)0,-1,rdest,cdest); } - + void imin(char scope, char topology, int m, int n, int* a, int lda, int* ra, int* ca, int rcflag, int rdest, int cdest) const { Cigamn2d(ictxt_,&scope,&topology,m,n,a,lda,ra,ca,rcflag,rdest,cdest); } - + void imin(char scope, char topology, int m, int n, int* a, int lda, int rdest, int cdest) const { Cigamn2d(ictxt_,&scope,&topology,m,n,a,lda,(int*)0,(int*)0,-1,rdest,cdest); } - - void ibcast_send(char scope, char topology, + + void ibcast_send(char scope, char topology, int m, int n, int* a,int lda) const { Cigebs2d(ictxt_,&scope,&topology,m,n,a,lda); } - + void ibcast_recv(char scope, char topology, int m, int n, int* a, int lda, int rsrc, int csrc) const { Cigebr2d(ictxt_,&scope,&topology,m,n,a,lda,rsrc,csrc); } - + void string_send(string& s, int rdest, int cdest) const { #if USE_MPI @@ -291,7 +291,7 @@ struct ContextRep delete [] ibuf; #endif } - + void string_recv(string& s, int rsrc, int csrc) const { #if USE_MPI @@ -306,7 +306,7 @@ struct ContextRep delete [] ibuf; #endif } - + void string_bcast(string& s, int isrc) const { #if USE_MPI @@ -329,29 +329,29 @@ struct ContextRep delete [] buf; #endif } - + bool operator==(const ContextRep& c) const { return (ictxt_==c.ictxt());} - + // MPI communicator for this context. Returns MPI_COMM_NULL if // this process is not part of the context MPI_Comm comm(void) const { return comm_; } - + // Constructors // default global context: construct a single-row global ContextRep explicit ContextRep(); - + // global ContextRep of size nprow * npcol with column major order explicit ContextRep(int nprow, int npcol); - + // construct a ContextRep of size nprow*npcol using the processes - // in context c starting at process (irstart,icstart) - explicit ContextRep(const ContextRep &c, int nprow, int npcol, + // in context c starting at process (irstart,icstart) + explicit ContextRep(const ContextRep &c, int nprow, int npcol, int irstart, int icstart); - + ~ContextRep(); - + void print(ostream& os) const; }; @@ -371,7 +371,7 @@ ContextRep::ContextRep() : ictxt_(-1), myrow_(-1), mycol_(-1) // get values of nprow_, npcol_, myrow_ and mycol_ in the new context if ( ictxt_ >= 0 ) Cblacs_gridinfo(ictxt_, &nprow_, &npcol_, &myrow_, &mycol_); - + size_ = nprow_ * npcol_; myproc_ = myrow_ < 0 ? -1 : mycol_ + npcol_ * myrow_; onpe0_ = ( mype_ == 0 ); @@ -412,12 +412,12 @@ ContextRep::ContextRep(int nprow, int npcol) : // get values of nprow_, npcol_, myrow_ and mycol_ in the new context if ( ictxt_ >= 0 ) Cblacs_gridinfo(ictxt_, &nprow_, &npcol_, &myrow_, &mycol_); - + size_ = nprow_ * npcol_; myproc_ = Cblacs_pnum(ictxt_,myrow_,mycol_); onpe0_ = ( mype_ == 0 ); active_ = ( ictxt_ >= 0 ); - + pmap_.resize(size_); // column-major order int i = 0; @@ -439,20 +439,20 @@ ContextRep::ContextRep(int nprow, int npcol) : comm_ = 0; #endif } - + //////////////////////////////////////////////////////////////////////////////// -ContextRep::ContextRep(const ContextRep& c, int nprow, int npcol, +ContextRep::ContextRep(const ContextRep& c, int nprow, int npcol, int irstart, int icstart) : ictxt_(-1), myrow_(-1), mycol_(-1), nprow_(nprow), npcol_(npcol) { assert(c.active()); vector gmap_; - + int nprocs; Cblacs_pinfo( &mype_, &nprocs ); // construct a (nprow*npcol) context using the processes in c // located at (irstart,icstart) - if ( irstart < 0 || icstart < 0 || + if ( irstart < 0 || icstart < 0 || irstart+nprow > c.nprow() || icstart+npcol > c.npcol() ) { cout << " Context::Context: cut rectangle: invalid parameters" << endl; @@ -470,19 +470,19 @@ ictxt_(-1), myrow_(-1), mycol_(-1), nprow_(nprow), npcol_(npcol) gmap_[i] = ic + c.npcol()*ir; i++; } - + Cblacs_get(c.ictxt(), 10, &ictxt_ ); Cblacs_gridmap(&ictxt_,&gmap_[0],nprow,nprow,npcol); - + // get values of nprow_, npcol_, myrow_ and mycol_ in the new context if ( ictxt_ >= 0 ) Cblacs_gridinfo(ictxt_, &nprow_, &npcol_, &myrow_, &mycol_); - + size_ = nprow_ * npcol_; myproc_ = myrow_ < 0 ? -1 : mycol_ + npcol_ * myrow_; onpe0_ = ( mype_ == 0 ); active_ = ( ictxt_ >= 0 ); - + #if USE_MPI MPI_Group c_group, subgroup; MPI_Comm_group(c.comm(),&c_group); @@ -498,7 +498,7 @@ ictxt_(-1), myrow_(-1), mycol_(-1), nprow_(nprow), npcol_(npcol) //////////////////////////////////////////////////////////////////////////////// ContextRep::~ContextRep() { - if ( myrow_ != -1 ) + if ( myrow_ != -1 ) { // cout << " ContextRep destructor called on ictxt = " << ictxt_ << endl; Cblacs_gridexit( ictxt_ ); @@ -541,18 +541,18 @@ void ContextRep::print(ostream& os) const class ContextImpl { private: - + ContextRep* rep; int* pcount; - + public: - + ContextRep* operator->() { return rep; } ContextRep* get_rep(void) { return rep; } ContextImpl(ContextRep* pp) : rep(pp), pcount(new int(1)) {} ContextImpl(const ContextImpl& r) : rep(r.rep), pcount(r.pcount) { (*pcount)++; } - + ContextImpl& operator=(const ContextImpl& r) { if ( rep == r.rep ) return *this; @@ -566,7 +566,7 @@ class ContextImpl (*pcount)++; return *this; } - + ~ContextImpl(void) { if ( --(*pcount) == 0 ) @@ -581,15 +581,15 @@ class ContextImpl Context::Context(void) : pimpl_(new ContextImpl(new ContextRep())) {} //////////////////////////////////////////////////////////////////////////////// -Context::Context(int nprow, int npcol): +Context::Context(int nprow, int npcol): pimpl_(new ContextImpl(new ContextRep(nprow,npcol))) {} - + //////////////////////////////////////////////////////////////////////////////// -Context::Context(const Context &c, int nprow, int npcol, - int irstart, int icstart) : +Context::Context(const Context &c, int nprow, int npcol, + int irstart, int icstart) : pimpl_(new ContextImpl(new ContextRep(*(c.pimpl_)->get_rep(),nprow,npcol, irstart,icstart))) {} - + //////////////////////////////////////////////////////////////////////////////// Context::~Context() { delete pimpl_; } @@ -648,15 +648,15 @@ void Context::barrier(void) const { (*pimpl_)->barrier(); } void Context::barrier(char scope) const { (*pimpl_)->barrier(scope); } //////////////////////////////////////////////////////////////////////////////// -void Context::dsend(int m, int n, double* a, +void Context::dsend(int m, int n, double* a, int lda, int rdest, int cdest) const { (*pimpl_)->dsend(m,n,a,lda,rdest,cdest); } -void Context::drecv(int m, int n, double* a, +void Context::drecv(int m, int n, double* a, int lda, int rsrc, int csrc) const { (*pimpl_)->drecv(m,n,a,lda,rsrc,csrc); } -void Context::dsum(char scope, char topology, +void Context::dsum(char scope, char topology, int m, int n, double* a, int lda, int rdest, int cdest) const { (*pimpl_)->dsum(scope,topology,m,n,a,lda,rdest,cdest); } @@ -666,12 +666,12 @@ void Context::dsum(char scope, int m, int n, double* a, int lda) const void Context::dsum(int m, int n, double* a, int lda) const { (*pimpl_)->dsum('A',' ',m,n,a,lda,-1,-1); } -void Context::dmax(char scope, char topology, - int m, int n, double* a, int lda, int* ra, int* ca, int rcflag, +void Context::dmax(char scope, char topology, + int m, int n, double* a, int lda, int* ra, int* ca, int rcflag, int rdest, int cdest) const { (*pimpl_)->dmax(scope,topology,m,n,a,lda,ra,ca,rcflag,rdest,cdest); } -void Context::dmax(char scope, char topology, +void Context::dmax(char scope, char topology, int m, int n, double* a, int lda, int rdest, int cdest) const { (*pimpl_)->dmax(scope,topology,m,n,a,lda,rdest,cdest); } @@ -681,12 +681,12 @@ void Context::dmax(char scope, int m, int n, double* a, int lda) const void Context::dmax(int m, int n, double* a, int lda) const { (*pimpl_)->dmax('A',' ',m,n,a,lda,-1,-1); } -void Context::dmin(char scope, char topology, - int m, int n, double* a, int lda, int* ra, int* ca, int rcflag, +void Context::dmin(char scope, char topology, + int m, int n, double* a, int lda, int* ra, int* ca, int rcflag, int rdest, int cdest) const { (*pimpl_)->dmin(scope,topology,m,n,a,lda,ra,ca,rcflag,rdest,cdest); } -void Context::dmin(char scope, char topology, +void Context::dmin(char scope, char topology, int m, int n, double* a, int lda, int rdest, int cdest) const { (*pimpl_)->dmin(scope,topology,m,n,a,lda,rdest,cdest); } @@ -696,7 +696,7 @@ void Context::dmin(char scope, int m, int n, double* a, int lda) const void Context::dmin(int m, int n, double* a, int lda) const { (*pimpl_)->dmin('A',' ',m,n,a,lda,-1,-1); } -void Context::dbcast_send(char scope, char topology, +void Context::dbcast_send(char scope, char topology, int m, int n, double* a, int lda) const { (*pimpl_)->dbcast_send(scope,topology,m,n,a,lda); } @@ -706,28 +706,28 @@ void Context::dbcast_send(char scope, int m, int n, double* a, int lda) const void Context::dbcast_send(int m, int n, double* a, int lda) const { (*pimpl_)->dbcast_send('A',' ',m,n,a,lda); } -void Context::dbcast_recv(char scope, char topology, +void Context::dbcast_recv(char scope, char topology, int m, int n, double* a, int lda, int rsrc,int csrc) const { (*pimpl_)->dbcast_recv(scope,topology,m,n,a,lda,rsrc,csrc); } -void Context::dbcast_recv(char scope, +void Context::dbcast_recv(char scope, int m, int n, double* a, int lda, int rsrc, int csrc) const { (*pimpl_)->dbcast_recv(scope,' ',m,n,a,lda,rsrc,csrc); } -void Context::dbcast_recv(int m, int n, double* a, int lda, +void Context::dbcast_recv(int m, int n, double* a, int lda, int rsrc,int csrc) const { (*pimpl_)->dbcast_recv('A',' ',m,n,a,lda,rsrc,csrc); } //////////////////////////////////////////////////////////////////////////////// -void Context::isend(int m, int n, int* a, +void Context::isend(int m, int n, int* a, int lda, int rdest, int cdest) const { (*pimpl_)->isend(m,n,a,lda,rdest,cdest); } -void Context::irecv(int m, int n, int* a, +void Context::irecv(int m, int n, int* a, int lda, int rsrc, int csrc) const { (*pimpl_)->irecv(m,n,a,lda,rsrc,csrc); } -void Context::isum(char scope, char topology, +void Context::isum(char scope, char topology, int m, int n, int* a, int lda, int rdest, int cdest) const { (*pimpl_)->isum(scope,topology,m,n,a,lda,rdest,cdest); } @@ -737,12 +737,12 @@ void Context::isum(char scope, int m, int n, int* a, int lda) const void Context::isum(int m, int n, int* a, int lda) const { (*pimpl_)->isum('A',' ',m,n,a,lda,-1,-1); } -void Context::imax(char scope, char topology, - int m, int n, int* a, int lda, int* ra, int* ca, int rcflag, +void Context::imax(char scope, char topology, + int m, int n, int* a, int lda, int* ra, int* ca, int rcflag, int rdest, int cdest) const { (*pimpl_)->imax(scope,topology,m,n,a,lda,ra,ca,rcflag,rdest,cdest); } -void Context::imax(char scope, char topology, +void Context::imax(char scope, char topology, int m, int n, int* a, int lda, int rdest, int cdest) const { (*pimpl_)->imax(scope,topology,m,n,a,lda,rdest,cdest); } @@ -752,12 +752,12 @@ void Context::imax(char scope, int m, int n, int* a, int lda) const void Context::imax(int m, int n, int* a, int lda) const { (*pimpl_)->imax('A',' ',m,n,a,lda,-1,-1); } -void Context::imin(char scope, char topology, - int m, int n, int* a, int lda, int* ra, int* ca, int rcflag, +void Context::imin(char scope, char topology, + int m, int n, int* a, int lda, int* ra, int* ca, int rcflag, int rdest, int cdest) const { (*pimpl_)->imin(scope,topology,m,n,a,lda,ra,ca,rcflag,rdest,cdest); } -void Context::imin(char scope, char topology, +void Context::imin(char scope, char topology, int m, int n, int* a, int lda, int rdest, int cdest) const { (*pimpl_)->imin(scope,topology,m,n,a,lda,rdest,cdest); } @@ -767,7 +767,7 @@ void Context::imin(char scope, int m, int n, int* a, int lda) const void Context::imin(int m, int n, int* a, int lda) const { (*pimpl_)->imin('A',' ',m,n,a,lda,-1,-1); } -void Context::ibcast_send(char scope, char topology, +void Context::ibcast_send(char scope, char topology, int m, int n, int* a, int lda) const { (*pimpl_)->ibcast_send(scope,topology,m,n,a,lda); } @@ -777,15 +777,15 @@ void Context::ibcast_send(char scope, int m, int n, int* a, int lda) const void Context::ibcast_send(int m, int n, int* a, int lda) const { (*pimpl_)->ibcast_send('A',' ',m,n,a,lda); } -void Context::ibcast_recv(char scope, char topology, +void Context::ibcast_recv(char scope, char topology, int m, int n, int* a, int lda, int rsrc,int csrc) const { (*pimpl_)->ibcast_recv(scope,topology,m,n,a,lda,rsrc,csrc); } -void Context::ibcast_recv(char scope, +void Context::ibcast_recv(char scope, int m, int n, int* a, int lda, int rsrc, int csrc) const { (*pimpl_)->ibcast_recv(scope,' ',m,n,a,lda,rsrc,csrc); } -void Context::ibcast_recv(int m, int n, int* a, int lda, +void Context::ibcast_recv(int m, int n, int* a, int lda, int rsrc,int csrc) const { (*pimpl_)->ibcast_recv('A',' ',m,n,a,lda,rsrc,csrc); } @@ -804,7 +804,7 @@ bool Context::operator==(const Context& ctxt) const //////////////////////////////////////////////////////////////////////////////// MPI_Comm Context::comm(void) const { return (*pimpl_)->comm(); } - + //////////////////////////////////////////////////////////////////////////////// void Context::print(ostream& os) const { (*pimpl_)->print(os);} diff --git a/src/Context.h b/src/Context.h index 7ad581e..5c4df22 100644 --- a/src/Context.h +++ b/src/Context.h @@ -3,7 +3,7 @@ // Context.h // //////////////////////////////////////////////////////////////////////////////// -// $Id: Context.h,v 1.9 2007-03-17 01:14:00 fgygi Exp $ +// $Id: Context.h,v 1.10 2007-10-19 16:24:04 fgygi Exp $ #ifndef CONTEXT_H #define CONTEXT_H @@ -20,17 +20,17 @@ typedef int MPI_Comm; class Context { private: - + struct ContextImpl* pimpl_; public: - + int ictxt() const; int myrow() const; int mycol() const; int nprow() const; int npcol() const; - + // number of processes in the context // returns -1 if current process is not part of this context int size() const; @@ -40,112 +40,112 @@ class Context int mype() const; // process id of process (irow,icol) int pmap(int irow, int icol) const; - + bool onpe0(void) const; bool active(void) const; void abort(int ierr) const; void barrier(void) const; void barrier(char scope) const; - + // double communications void dsend(int m, int n, double* a, int lda, int rdest, int cdest) const; void drecv(int m, int n, double* a, int lda, int rsrc, int csrc) const; - - void dsum(char scope, char topology, + + void dsum(char scope, char topology, int m, int n, double* a, int lda, int rdest, int cdest) const; void dsum(char scope, int m, int n, double* a, int lda) const; void dsum(int m, int n, double* a, int lda) const; - - void dmax(char scope, char topology, - int m, int n, double* a, int lda, + + void dmax(char scope, char topology, + int m, int n, double* a, int lda, int* ra, int* ca, int rcflag, int rdest, int cdest) const; - void dmax(char scope, char topology, + void dmax(char scope, char topology, int m, int n, double* a, int lda, int rdest, int cdest) const; void dmax(char scope, int m, int n, double* a, int lda) const; void dmax(int m, int n, double* a, int lda) const; - - void dmin(char scope, char topology, - int m, int n, double* a, int lda, + + void dmin(char scope, char topology, + int m, int n, double* a, int lda, int* ra, int* ca, int rcflag, int rdest, int cdest) const; - void dmin(char scope, char topology, + void dmin(char scope, char topology, int m, int n, double* a, int lda, int rdest, int cdest) const; void dmin(char scope, int m, int n, double* a, int lda) const; void dmin(int m, int n, double* a, int lda) const; - - void dbcast_send(char scope, char topology, + + void dbcast_send(char scope, char topology, int m, int n, double* a, int lda) const; void dbcast_send(char scope, int m, int n, double* a, int lda) const; void dbcast_send(int m, int n, double* a, int lda) const; - - void dbcast_recv(char scope, char topology, + + void dbcast_recv(char scope, char topology, int m, int n, double* a, int lda, int rsrc, int csrc) const; - void dbcast_recv(char scope, int m, int n, double* a, + void dbcast_recv(char scope, int m, int n, double* a, int lda,int rsrc, int csrc) const; void dbcast_recv(int m, int n, double* a, int lda,int rsrc, int csrc) const; - + // integer communications void isend(int m, int n, int* a, int lda, int rdest, int cdest) const; void irecv(int m, int n, int* a, int lda, int rsrc, int csrc) const; - void isum(char scope, char topology, + void isum(char scope, char topology, int m, int n, int* a, int lda, int rdest, int cdest) const; void isum(char scope, int m, int n, int* a, int lda) const; void isum(int m, int n, int* a, int lda) const; - - void imax(char scope, char topology, - int m, int n, int* a, int lda, + + void imax(char scope, char topology, + int m, int n, int* a, int lda, int* ra, int* ca, int rcflag, int rdest, int cdest) const; - void imax(char scope, char topology, + void imax(char scope, char topology, int m, int n, int* a, int lda, int rdest, int cdest) const; void imax(char scope, int m, int n, int* a, int lda) const; void imax(int m, int n, int* a, int lda) const; - - void imin(char scope, char topology, - int m, int n, int* a, int lda, + + void imin(char scope, char topology, + int m, int n, int* a, int lda, int* ra, int* ca, int rcflag, int rdest, int cdest) const; - void imin(char scope, char topology, + void imin(char scope, char topology, int m, int n, int* a, int lda, int rdest, int cdest) const; void imin(char scope, int m, int n, int* a, int lda) const; void imin(int m, int n, int* a, int lda) const; - - void ibcast_send(char scope, char topology, + + void ibcast_send(char scope, char topology, int m, int n, int* a, int lda) const; void ibcast_send(char scope, int m, int n, int* a, int lda) const; void ibcast_send(int m, int n, int* a, int lda) const; - - void ibcast_recv(char scope, char topology, + + void ibcast_recv(char scope, char topology, int m, int n, int* a, int lda, int rsrc, int csrc) const; - void ibcast_recv(char scope, int m, int n, + void ibcast_recv(char scope, int m, int n, int* a, int lda,int rsrc, int csrc) const; void ibcast_recv(int m, int n, int* a, int lda,int rsrc, int csrc) const; - + void string_send(std::string& s, int rdest, int cdest) const; void string_recv(std::string& s, int rsrc, int csrc) const; void string_bcast(std::string& s, int isrc) const; - + bool operator==(const Context& ctxt) const; - + // MPI communicator for this context. Returns MPI_COMM_NULL if // this process is not part of the context MPI_Comm comm(void) const; - + // Constructors // default global context: construct a single-row global Context explicit Context(); - + // global Context of size nprow * npcol with column major order explicit Context(int nprow, int npcol); - + // construct a Context of size nprow*npcol from the processes - // in context ctxt starting at process (irstart,icstart) - explicit Context(const Context &ctxt, int nprow, int npcol, + // in context ctxt starting at process (irstart,icstart) + explicit Context(const Context &ctxt, int nprow, int npcol, int irstart, int icstart); - + ~Context(); - + Context(const Context& ctxt); Context& operator=(const Context& rhs); - + void print(std::ostream& os) const; }; std::ostream& operator << ( std::ostream& os, const Context& ctxt ); diff --git a/src/Control.h b/src/Control.h index a670d7e..497a65d 100644 --- a/src/Control.h +++ b/src/Control.h @@ -3,7 +3,7 @@ // Control.h: // //////////////////////////////////////////////////////////////////////////////// -// $Id: Control.h,v 1.11 2007-03-17 01:14:00 fgygi Exp $ +// $Id: Control.h,v 1.12 2007-10-19 16:24:04 fgygi Exp $ #ifndef CONTROL_H #define CONTROL_H @@ -15,31 +15,31 @@ struct Control { // control variables std::string debug, timing; - std::string wf_dyn, atoms_dyn; // dynamics string flags + std::string wf_dyn, atoms_dyn; // dynamics string flags int nite; double emass; // electron mass - + double fermi_temp; // temperature of Fermi distribution double ecutprec; std::string wf_diag; - + std::string tcp; double tcp_rcut; double tcp_sigma; - + double gms_mix; // mixing factor for generalized minimum spread functions - + std::string thermostat; double th_temp,th_time, th_width; // thermostat control - + std::string stress; std::string cell_dyn; std::string cell_lock; double cell_mass; double ecuts; // confinement potential energy cutoff double ext_stress[6]; // external stress tensor: xx,yy,zz,xy,yz,xz - + std::string xc; std::string spin; int delta_spin; @@ -47,7 +47,7 @@ struct Control double dt; int iprint; int timeout; - + double charge_mix_coeff; double charge_mix_rcut; }; diff --git a/src/D3vector.h b/src/D3vector.h index 8290cc2..6b3a724 100644 --- a/src/D3vector.h +++ b/src/D3vector.h @@ -5,7 +5,7 @@ // double 3-vectors // //////////////////////////////////////////////////////////////////////////////// -// $Id: D3vector.h,v 1.5 2007-03-17 01:14:00 fgygi Exp $ +// $Id: D3vector.h,v 1.6 2007-10-19 16:24:04 fgygi Exp $ #ifndef D3VECTOR_H #define D3VECTOR_H @@ -17,15 +17,15 @@ class D3vector { public: - double x, y, z; + double x, y, z; // explicit constructor to avoid implicit conversion from double to D3vector explicit D3vector(const double& xv, const double& yv, const double& zv) : x(xv), y(yv), z(zv) {} explicit D3vector(void) : x(0.0), y(0.0), z(0.0) {} - + explicit D3vector(const double* r) : x(r[0]), y(r[1]), z(r[2]) {} - + double& operator[](const int &i) { assert(i>=0 && i <3); @@ -33,12 +33,12 @@ class D3vector else if ( i == 1 ) return y; else return z; } - + bool operator==(const D3vector &rhs) const { return x == rhs.x && y == rhs.y && z == rhs.z; } - + bool operator!=(const D3vector &rhs) const { return x != rhs.x || y != rhs.y || z != rhs.z; diff --git a/src/Debug.h b/src/Debug.h index 816dcd8..4528cff 100644 --- a/src/Debug.h +++ b/src/Debug.h @@ -3,7 +3,7 @@ // Debug.h // //////////////////////////////////////////////////////////////////////////////// -// $Id: Debug.h,v 1.2 2006-07-21 17:48:56 fgygi Exp $ +// $Id: Debug.h,v 1.3 2007-10-19 16:24:04 fgygi Exp $ #ifndef DEBUG_H #define DEBUG_H @@ -31,9 +31,9 @@ class Debug : public Var string vt = argv[iarg]; v += " " + vt; } - + s->ctrl.debug = v; - + return 0; } diff --git a/src/DistanceCmd.h b/src/DistanceCmd.h index de39e2f..152637a 100644 --- a/src/DistanceCmd.h +++ b/src/DistanceCmd.h @@ -3,7 +3,7 @@ // DistanceCmd.h: // //////////////////////////////////////////////////////////////////////////////// -// $Id: DistanceCmd.h,v 1.2 2005-09-16 23:08:11 fgygi Exp $ +// $Id: DistanceCmd.h,v 1.3 2007-10-19 16:24:04 fgygi Exp $ #ifndef DISTANCECMD_H #define DISTANCECMD_H @@ -24,7 +24,7 @@ class DistanceCmd : public Cmd char *name(void) const { return "distance"; } char *help_msg(void) const { - return + return "\n distance\n\n" " syntax: distance name1 name2\n\n" " The distance command prints the distance between two atoms.\n\n"; @@ -40,13 +40,13 @@ class DistanceCmd : public Cmd } return 1; } - - string name1(argv[1]); - string name2(argv[2]); - Atom* a1 = s->atoms.findAtom(name1); - Atom* a2 = s->atoms.findAtom(name2); - if ( a1 == 0 || a2 == 0 ) - { + + string name1(argv[1]); + string name2(argv[2]); + Atom* a1 = s->atoms.findAtom(name1); + Atom* a2 = s->atoms.findAtom(name2); + if ( a1 == 0 || a2 == 0 ) + { // either a1 or a2 was not found if ( ui->onpe0() ) { @@ -59,14 +59,14 @@ class DistanceCmd : public Cmd } return 1; } - + if ( ui->onpe0() ) { const double d = length(a1->position()-a2->position()); cout.setf(ios::fixed,ios::floatfield); - cout << " " << endl; + cout << " " << endl; } return 0; } diff --git a/src/DistanceConstraint.C b/src/DistanceConstraint.C index dabe77a..4c34e60 100644 --- a/src/DistanceConstraint.C +++ b/src/DistanceConstraint.C @@ -3,7 +3,7 @@ // DistanceConstraint.C // //////////////////////////////////////////////////////////////////////////////// -// $Id: DistanceConstraint.C,v 1.2 2005-09-16 23:08:11 fgygi Exp $ +// $Id: DistanceConstraint.C,v 1.3 2007-10-19 16:24:04 fgygi Exp $ #include "DistanceConstraint.h" #include "AtomSet.h" @@ -26,7 +26,7 @@ void DistanceConstraint::setup(const AtomSet& atoms) m1_ = atoms.species_list[is1_]->mass() * 1822.89; assert(m1_>0.0); m1_inv_ = 1.0/m1_; - + is2_ = atoms.is(name2_); ia2_ = atoms.ia(name2_); assert(is2_>=0); @@ -56,7 +56,7 @@ vector > &rp) const double* pr2p = &rp[is2_][3*ia2_]; D3vector r1p(pr1p); D3vector r2p(pr2p); - + // compute gradient at r D3vector r12(r1-r2); D3vector g1,g2; @@ -64,7 +64,7 @@ vector > &rp) const g2 = -g1; double ng = g1*g1 + g2*g2; assert(ng>=0.0); - + // compute gradient at rp D3vector r12p(r1p-r2p); D3vector g1p,g2p; @@ -72,19 +72,19 @@ vector > &rp) const g2p = -g1p; const double ngp = g1p*g1p + g2p*g2p; assert(ngp>=0.0); - + // test alignment of the gradient at r and at rp // compute scalar product of normalized gradients const double sp = ( g1*g1p + g2*g2p ) / sqrt( ng * ngp ); if ( fabs(sp) < 0.5*sqrt(3.0) ) { - g1 = g1p; - g2 = g2p; + g1 = g1p; + g2 = g2p; #if DEBUG_CONSTRAINTS cout << " " << endl; #endif } - + const double sigma = r12p*r12p - distance_*distance_; #if DEBUG_CONSTRAINTS cout << " " << endl; #endif if ( fabs(sigma) < tol_ ) return true; - + // make one shake iteration const double den = m1_inv_ * g1 * g1p + m2_inv_ * g2 * g2p; - + const double lambda = -sigma / den; - + pr1p[0] += m1_inv_ * lambda * g1.x; pr1p[1] += m1_inv_ * lambda * g1.y; pr1p[2] += m1_inv_ * lambda * g1.z; - + pr2p[0] += m2_inv_ * lambda * g2.x; pr2p[1] += m2_inv_ * lambda * g2.y; pr2p[2] += m2_inv_ * lambda * g2.z; - + return false; } @@ -129,7 +129,7 @@ vector > &v0) const double* pv2 = &v0[is2_][3*ia2_]; D3vector v1(pv1); D3vector v2(pv2); - + // compute gradient at r D3vector r12(r1-r2); D3vector g1,g2; @@ -137,7 +137,7 @@ vector > &v0) const g2 = -g1; const double norm2 = g1*g1 + g2*g2; assert(norm2>=0.0); - + // if the gradient is too small, do not attempt correction if ( norm2 < 1.e-6 ) return true; const double proj = v1 * g1 + v2 * g2; @@ -147,9 +147,9 @@ vector > &v0) const cout << " DistanceConstraint::enforce_v: " << name1_ << " " << name2_ << endl; cout << " DistanceConstraint::enforce_v: r1 = " << r1 << endl; cout << " DistanceConstraint::enforce_v: r2 = " << r2 << endl; - cout << " DistanceConstraint::enforce_v: v1 = " + cout << " DistanceConstraint::enforce_v: v1 = " << v1[0] << " " << v1[1] << " " << v1[2] << endl; - cout << " DistanceConstraint::enforce_v: v2 = " + cout << " DistanceConstraint::enforce_v: v2 = " << v2[0] << " " << v2[1] << " " << v2[2] << endl; cout << " DistanceConstraint::enforce_v: tol = " << tol_ << endl; cout << " DistanceConstraint::enforce_v: err = " << err @@ -157,22 +157,22 @@ vector > &v0) const cout << " -->" << endl; #endif if ( err < tol_ ) return true; - + // make one shake iteration - - const double den = m1_inv_ * g1 * g1 + + + const double den = m1_inv_ * g1 * g1 + m2_inv_ * g2 * g2; assert(den>0.0); const double eta = -proj / den; - + pv1[0] += m1_inv_ * eta * g1.x; pv1[1] += m1_inv_ * eta * g1.y; pv1[2] += m1_inv_ * eta * g1.z; - + pv2[0] += m2_inv_ * eta * g2.x; pv2[1] += m2_inv_ * eta * g2.y; pv2[2] += m2_inv_ * eta * g2.z; - + return false; } @@ -188,7 +188,7 @@ void DistanceConstraint::compute_force(const vector > &r0, const double* pf2 = &f[is2_][3*ia2_]; D3vector f1(pf1); D3vector f2(pf2); - + // compute gradient at r D3vector r12(r1-r2); D3vector g1,g2; @@ -202,13 +202,13 @@ void DistanceConstraint::compute_force(const vector > &r0, return; } const double norm = sqrt(norm2); - + D3vector e1(g1/norm); D3vector e2(-e1); - + const double proj1 = f1*e1; const double proj2 = f2*e2; - + force_ = -0.5*(proj1+proj2); } diff --git a/src/DistanceConstraint.h b/src/DistanceConstraint.h index 27a6a4d..d380b44 100644 --- a/src/DistanceConstraint.h +++ b/src/DistanceConstraint.h @@ -3,7 +3,7 @@ // DistanceConstraint.h // //////////////////////////////////////////////////////////////////////////////// -// $Id: DistanceConstraint.h,v 1.3 2007-03-17 01:14:00 fgygi Exp $ +// $Id: DistanceConstraint.h,v 1.4 2007-10-19 16:24:04 fgygi Exp $ #ifndef DISTANCECONSTRAINT_H #define DISTANCECONSTRAINT_H @@ -20,12 +20,12 @@ class DistanceConstraint : public Constraint int ia1_, ia2_, is1_, is2_; double m1_, m2_, m1_inv_, m2_inv_; double distance_, velocity_, force_, weight_, tol_; - + public: - + DistanceConstraint(std::string name, std::string name1, std::string name2, double distance, double velocity, double tolerance): - name1_(name1), name2_(name2), distance_(distance), + name1_(name1), name2_(name2), distance_(distance), velocity_(velocity), tol_(tolerance), m1_(0.0), m2_(0.0) { name_ = name; @@ -35,7 +35,7 @@ class DistanceConstraint : public Constraint force_ = 0.0; weight_ = 1.0; } - + std::string type(void) const { return "distance"; } double value(void) const { return distance_; } double velocity(void) const { return velocity_; } @@ -50,7 +50,7 @@ class DistanceConstraint : public Constraint { velocity_ = velocity; } - + void setup(const AtomSet& atoms); void update(double dt); bool enforce_r(const std::vector > &r0, @@ -60,6 +60,6 @@ class DistanceConstraint : public Constraint void compute_force(const std::vector > &r0, const std::vector > &f); std::ostream& print( std::ostream& os ); - + }; #endif diff --git a/src/Dt.h b/src/Dt.h index 18b042e..02d0d77 100644 --- a/src/Dt.h +++ b/src/Dt.h @@ -3,7 +3,7 @@ // Dt.h // //////////////////////////////////////////////////////////////////////////////// -// $Id: Dt.h,v 1.2 2007-03-17 01:22:50 fgygi Exp $ +// $Id: Dt.h,v 1.3 2007-10-19 16:24:04 fgygi Exp $ #ifndef DT_H #define DT_H @@ -31,7 +31,7 @@ class Dt : public Var cout << " dt takes only one value" << endl; return 1; } - + double v = atof(argv[1]); if ( v == 0.0 ) { diff --git a/src/Ecut.h b/src/Ecut.h index 19883c7..0846657 100644 --- a/src/Ecut.h +++ b/src/Ecut.h @@ -3,7 +3,7 @@ // Ecut.h // //////////////////////////////////////////////////////////////////////////////// -// $Id: Ecut.h,v 1.5 2004-05-20 00:17:33 fgygi Exp $ +// $Id: Ecut.h,v 1.6 2007-10-19 16:24:04 fgygi Exp $ #ifndef ECUT_H #define ECUT_H @@ -31,7 +31,7 @@ class Ecut : public Var cout << " ecut takes only one value" << endl; return 1; } - + double v = atof(argv[1]); if ( v < 0.0 ) { @@ -39,17 +39,17 @@ class Ecut : public Var cout << " ecut must be non-negative" << endl; return 1; } - + if ( s->wf.ecut() == 0.5 * v ) return 0; s->wf.resize(0.5*v); - if ( s->wfv != 0 ) + if ( s->wfv != 0 ) { s->wfv->resize(0.5*v); s->wfv->clear(); } - + return 0; } diff --git a/src/Ecutprec.h b/src/Ecutprec.h index 82c309c..155e187 100644 --- a/src/Ecutprec.h +++ b/src/Ecutprec.h @@ -3,7 +3,7 @@ // Ecutprec.h // //////////////////////////////////////////////////////////////////////////////// -// $Id: Ecutprec.h,v 1.1 2003-05-23 21:54:26 fgygi Exp $ +// $Id: Ecutprec.h,v 1.2 2007-10-19 16:24:04 fgygi Exp $ #ifndef ECUTPREC_H #define ECUTPREC_H @@ -31,7 +31,7 @@ class Ecutprec : public Var cout << " ecutprec takes only one value" << endl; return 1; } - + double v = atof(argv[1]); if ( v < 0.0 ) { @@ -41,7 +41,7 @@ class Ecutprec : public Var } s->ctrl.ecutprec = 0.5*v; - + return 0; } diff --git a/src/Ecuts.h b/src/Ecuts.h index 1041887..f8d35f7 100644 --- a/src/Ecuts.h +++ b/src/Ecuts.h @@ -3,7 +3,7 @@ // Ecuts.h // //////////////////////////////////////////////////////////////////////////////// -// $Id: Ecuts.h,v 1.1 2004-02-04 19:52:27 fgygi Exp $ +// $Id: Ecuts.h,v 1.2 2007-10-19 16:24:04 fgygi Exp $ #ifndef ECUTS_H #define ECUTS_H @@ -31,7 +31,7 @@ class Ecuts : public Var cout << " ecuts takes only one value" << endl; return 1; } - + double v = atof(argv[1]); if ( v < 0.0 ) { @@ -41,7 +41,7 @@ class Ecuts : public Var } s->ctrl.ecuts = 0.5 * v; - + return 0; } diff --git a/src/Emass.h b/src/Emass.h index e9f36a1..de1249e 100644 --- a/src/Emass.h +++ b/src/Emass.h @@ -3,7 +3,7 @@ // Emass.h // //////////////////////////////////////////////////////////////////////////////// -// $Id: Emass.h,v 1.1 2003-08-28 00:28:51 fgygi Exp $ +// $Id: Emass.h,v 1.2 2007-10-19 16:24:04 fgygi Exp $ #ifndef EMASS_H #define EMASS_H @@ -31,7 +31,7 @@ class Emass : public Var cout << " emass takes only one value" << endl; return 1; } - + double v = atof(argv[1]); if ( v <= 0.0 ) { diff --git a/src/EnergyFunctional.C b/src/EnergyFunctional.C index af4e438..174836e 100644 --- a/src/EnergyFunctional.C +++ b/src/EnergyFunctional.C @@ -3,7 +3,7 @@ // EnergyFunctional.C // //////////////////////////////////////////////////////////////////////////////// -// $Id: EnergyFunctional.C,v 1.24 2007-10-16 18:23:20 fgygi Exp $ +// $Id: EnergyFunctional.C,v 1.25 2007-10-19 16:24:04 fgygi Exp $ #include "EnergyFunctional.h" #include "Sample.h" @@ -31,7 +31,7 @@ EnergyFunctional::EnergyFunctional(const Sample& s, const ChargeDensity& cd) { const AtomSet& atoms = s_.atoms; const Wavefunction& wf = s_.wf; - + sigma_ekin.resize(6); sigma_econf.resize(6); sigma_eps.resize(6); @@ -40,18 +40,18 @@ EnergyFunctional::EnergyFunctional(const Sample& s, const ChargeDensity& cd) sigma_enl.resize(6); sigma_esr.resize(6); sigma.resize(6); - + vbasis_ = cd_.vbasis(); - //cout << vbasis_->context().mype() << ": vbasis_->context() = " + //cout << vbasis_->context().mype() << ": vbasis_->context() = " // << vbasis_->context() << endl; - + // define FT's on vbasis contexts - + int np0v = vbasis_->np(0); int np1v = vbasis_->np(1); int np2v = vbasis_->np(2); vft = cd_.vft(); - + v_r.resize(wf.nspin()); for ( int ispin = 0; ispin < wf.nspin(); ispin++ ) { @@ -66,21 +66,21 @@ EnergyFunctional::EnergyFunctional(const Sample& s, const ChargeDensity& cd) cout << " " << endl; } - + const int ngloc = vbasis_->localsize(); //cout << " EnergyFunctional: ngloc: " << ngloc << endl; - + nsp_ = atoms.nsp(); - + vps.resize(nsp_); dvps.resize(nsp_); rhops.resize(nsp_); - + zv_.resize(nsp_); rcps_.resize(nsp_); na_.resize(nsp_); namax_ = 0; - + for ( int is = 0; is < nsp_; is++ ) { vps[is].resize(ngloc); @@ -88,10 +88,10 @@ EnergyFunctional::EnergyFunctional(const Sample& s, const ChargeDensity& cd) rhops[is].resize(ngloc); if ( atoms.na(is) > namax_ ) namax_ = atoms.na(is); } - + xcp = new XCPotential(cd_,s_.ctrl.xc); nlp = new NonLocalPotential(s_.atoms, *wf.sd(0,0)); - + vion_local_g.resize(ngloc); dvion_local_g.resize(ngloc); vlocal_g.resize(ngloc); @@ -99,35 +99,35 @@ EnergyFunctional::EnergyFunctional(const Sample& s, const ChargeDensity& cd) rhoelg.resize(ngloc); rhogt.resize(ngloc); rhopst.resize(ngloc); - + tau0.resize(nsp_); fion_esr.resize(nsp_); ftmp.resize(3*namax_); - + eself_ = 0.0; - + for ( int is = 0; is < nsp_; is++ ) { Species *s = atoms.species_list[is]; - + const int na = atoms.na(is); tau0[is].resize(3*na); fion_esr[is].resize(3*na); - + eself_ += na * s->eself(); na_[is] = na; - + zv_[is] = s->zval(); rcps_[is] = s->rcps(); } - + // FT for interpolation of wavefunctions on the fine grid ft.resize(wf.nkp()); for ( int ikp = 0; ikp < wf.nkp(); ikp++ ) { ft[ikp] = cd_.ft(ikp); } - + // Confinement potentials cfp.resize(wf.nkp()); for ( int ikp = 0; ikp < wf.nkp(); ikp++ ) @@ -140,18 +140,18 @@ EnergyFunctional::EnergyFunctional(const Sample& s, const ChargeDensity& cd) { const double facs = 2.0; const double sigmas = 0.5; - cfp[ikp] = + cfp[ikp] = new ConfinementPotential(s_.ctrl.ecuts,facs,sigmas, wf.sd(0,ikp)->basis()); } } - + sf.init(tau0,*vbasis_); - + cell_moved(); - + atoms_moved(); - + } //////////////////////////////////////////////////////////////////////////////// @@ -159,7 +159,7 @@ EnergyFunctional::~EnergyFunctional(void) { delete xcp; delete nlp; - + for ( TimerMap::iterator i = tmap.begin(); i != tmap.end(); i++ ) { double time = (*i).second.real(); @@ -183,7 +183,7 @@ void EnergyFunctional::update_vhxc(void) // called when the charge density has changed // update Hartree and xc potentials using the charge density cd_ // compute Hartree and xc energies - + const Wavefunction& wf = s_.wf; const UnitCell& cell = wf.cell(); const double omega = cell.volume(); @@ -192,7 +192,7 @@ void EnergyFunctional::update_vhxc(void) const double fpi = 4.0 * M_PI; const int ngloc = vbasis_->localsize(); double tsum[2]; - + // compute total electronic density: rhoelg = rho_up + rho_dn if ( wf.nspin() == 1 ) { @@ -208,7 +208,7 @@ void EnergyFunctional::update_vhxc(void) rhoelg[ig] = omega_inv * ( cd_.rhog[0][ig] + cd_.rhog[1][ig] ); } } - + // update XC energy and potential tmap["exc"].start(); for ( int ispin = 0; ispin < wf.nspin(); ispin++ ) @@ -216,8 +216,8 @@ void EnergyFunctional::update_vhxc(void) xcp->update(v_r); exc_ = xcp->exc(); tmap["exc"].stop(); - - // compute local potential energy: + + // compute local potential energy: // integral of el. charge times ionic local pot. int len=2*ngloc,inc1=1; tsum[0] = 2.0 * ddot(&len,(double*)&rhoelg[0],&inc1, @@ -228,7 +228,7 @@ void EnergyFunctional::update_vhxc(void) tsum[0] -= real(conj(rhoelg[0])*vion_local_g[0]); } tsum[0] *= omega; // tsum[0] contains eps - + // Hartree energy ehart_ = 0.0; double ehsum = 0.0; @@ -243,21 +243,21 @@ void EnergyFunctional::update_vhxc(void) // Factor omega in next line yields prefactor 4 pi / omega in tsum[1] = omega * fpi * ehsum; // tsum[1] contains ehart - + vbasis_->context().dsum(2,1,&tsum[0],2); eps_ = tsum[0]; ehart_ = tsum[1]; - + // compute vlocal_g = vion_local_g + vhart_g // where vhart_g = 4 * pi * (rhoelg + rhopst) * g2i for ( int ig = 0; ig < ngloc; ig++ ) { vlocal_g[ig] = vion_local_g[ig] + fpi * rhogt[ig] * g2i[ig]; } - + // FT to tmpr_r vft->backward(&vlocal_g[0],&tmp_r[0]); - + // add local potential in tmp_r to v_r[ispin][i] // v_r contains the xc potential const int size = tmp_r.size(); @@ -284,7 +284,7 @@ double EnergyFunctional::energy(bool compute_hpsi, Wavefunction& dwf, bool compute_forces, vector >& fion, bool compute_stress, valarray& sigma) { - const bool debug_stress = compute_stress && + const bool debug_stress = compute_stress && s_.ctrl.debug.find("STRESS") != string::npos; const double fpi = 4.0 * M_PI; @@ -295,23 +295,23 @@ double EnergyFunctional::energy(bool compute_hpsi, Wavefunction& dwf, const int ngloc = vbasis_->localsize(); const double *const g2i = vbasis_->g2i_ptr(); assert(wf.nspin()==1); - + const bool use_confinement = s_.ctrl.ecuts > 0.0; - + for ( int is = 0; is < fion.size(); is++ ) for ( int ia = 0; ia < fion[is].size(); ia++ ) fion[is][ia] = 0.0; - + if ( compute_hpsi ) { for ( int ispin = 0; ispin < wf.nspin(); ispin++ ) for ( int ikp = 0; ikp < wf.nkp(); ikp++ ) dwf.sd(ispin,ikp)->c().clear(); } - + // kinetic energy tmap["ekin"].start(); - + // compute ekin, confinement energy, stress from ekin and econf // ekin = sum_G |c_G|^2 G^2 // econf = sum_G |c_G|^2 fstress[G] @@ -336,12 +336,12 @@ double EnergyFunctional::energy(bool compute_hpsi, Wavefunction& dwf, // note: if basis is real, the factor of 2.0 for G=0 need not be // corrected since G^2 = 0 // Note: the calculation of fac in next line is valid only for nkp=1 - // If k!=0, kpg2(0) !=0 and the ig=0 coefficient must be dealt with + // If k!=0, kpg2(0) !=0 and the ig=0 coefficient must be dealt with // separately const double fac = wfbasis.real() ? 1.0 : 0.5; const ComplexMatrix& c = sd.c(); const Context& sdctxt = sd.context(); - + // compute psi2sum(G) = fac * sum_G occ(n) psi2(n,G) const int ngwloc = wfbasis.localsize(); valarray psi2sum(ngwloc); @@ -361,7 +361,7 @@ double EnergyFunctional::energy(bool compute_hpsi, Wavefunction& dwf, } psi2sum[ig] = tmpsum; } - + // accumulate contributions to ekin,econf,sigma_ekin,sigma_econf in tsum // Note: next lines to be changed to kpg_ptr for nkp>1 const double *const g2 = wfbasis.g2_ptr(); @@ -369,34 +369,34 @@ double EnergyFunctional::energy(bool compute_hpsi, Wavefunction& dwf, const double *const g_y = wfbasis.gx_ptr(1); const double *const g_z = wfbasis.gx_ptr(2); tsum = 0.0; - + for ( int ig = 0; ig < ngwloc; ig++ ) { const double psi2s = psi2sum[ig]; - + // tsum[0]: ekin partial sum tsum[0] += psi2s * g2[ig]; - + if ( compute_stress ) { const double tgx = g_x[ig]; const double tgy = g_y[ig]; const double tgz = g_z[ig]; - + const double fac_ekin = 2.0 * psi2s; - + tsum[1] += fac_ekin * tgx * tgx; tsum[2] += fac_ekin * tgy * tgy; tsum[3] += fac_ekin * tgz * tgz; tsum[4] += fac_ekin * tgx * tgy; tsum[5] += fac_ekin * tgy * tgz; tsum[6] += fac_ekin * tgx * tgz; - + } // tsum[0-6] contains the contributions to // ekin, sigma_ekin, from vector ig } // ig - + if ( use_confinement ) { const valarray& fstress = cfp[ikp]->fstress(); @@ -406,13 +406,13 @@ double EnergyFunctional::energy(bool compute_hpsi, Wavefunction& dwf, const double psi2s = psi2sum[ig]; // tsum[7]: econf partial sum tsum[7] += psi2s * fstress[ig]; - + if ( compute_stress ) { const double tgx = g_x[ig]; const double tgy = g_y[ig]; const double tgz = g_z[ig]; - + const double fac_econf = psi2s * dfstress[ig]; tsum[8] += fac_econf * tgx * tgx; tsum[9] += fac_econf * tgy * tgy; @@ -425,15 +425,15 @@ double EnergyFunctional::energy(bool compute_hpsi, Wavefunction& dwf, // econf,sigma_econf from vector ig } // ig } - + sum += weight * tsum; } } // ikp } // ispin - + // sum contains the contributions to ekin, etc.. from this task wf.context().dsum(14,1,&sum[0],14); - + ekin_ = sum[0]; sigma_ekin[0] = sum[1]; sigma_ekin[1] = sum[2]; @@ -441,7 +441,7 @@ double EnergyFunctional::energy(bool compute_hpsi, Wavefunction& dwf, sigma_ekin[3] = sum[4]; sigma_ekin[4] = sum[5]; sigma_ekin[5] = sum[6]; - + econf_ = sum[7]; sigma_econf[0] = sum[8]; sigma_econf[1] = sum[9]; @@ -449,12 +449,12 @@ double EnergyFunctional::energy(bool compute_hpsi, Wavefunction& dwf, sigma_econf[3] = sum[11]; sigma_econf[4] = sum[12]; sigma_econf[5] = sum[13]; - + sigma_ekin *= omega_inv; sigma_econf *= omega_inv; - + tmap["ekin"].stop(); - + // Stress from Eps sigma_eps = 0.0; if ( compute_stress ) @@ -468,13 +468,13 @@ double EnergyFunctional::energy(bool compute_hpsi, Wavefunction& dwf, { // factor of 2 in next line: G and -G // note: gi[0] == 0.0 in next line (no division by zero) - const double fac = 2.0 * gi[ig] * + const double fac = 2.0 * gi[ig] * real( conj(rhoelg[ig]) * dvion_local_g[ig] ); - + const double tgx = g_x[ig]; const double tgy = g_y[ig]; const double tgz = g_z[ig]; - + tsum[0] += fac * tgx * tgx; tsum[1] += fac * tgy * tgy; tsum[2] += fac * tgz * tgz; @@ -491,7 +491,7 @@ double EnergyFunctional::energy(bool compute_hpsi, Wavefunction& dwf, sigma_eps[4] = tsum[4]; sigma_eps[5] = tsum[5]; } - + // Stress from Hartree energy if ( compute_stress ) { @@ -499,7 +499,7 @@ double EnergyFunctional::energy(bool compute_hpsi, Wavefunction& dwf, const double *const g_x = vbasis_->gx_ptr(0); const double *const g_y = vbasis_->gx_ptr(1); const double *const g_z = vbasis_->gx_ptr(2); - + for ( int ig = 0; ig < ngloc; ig++ ) { const double temp = norm(rhogt[ig]) * g2i[ig] * g2i[ig]; @@ -530,7 +530,7 @@ double EnergyFunctional::energy(bool compute_hpsi, Wavefunction& dwf, ( rg.real() * sg.real() + rg.imag() * sg.imag() ) * rhops[is][ig] * g2i[ig]; - + const double tgx = g_x[ig]; const double tgy = g_y[ig]; const double tgz = g_z[ig]; @@ -555,13 +555,13 @@ double EnergyFunctional::energy(bool compute_hpsi, Wavefunction& dwf, sigma_ehart[4] = - 2.0 * fpi * tsum[4]; sigma_ehart[5] = - 2.0 * fpi * tsum[5]; } // compute_stress - + // Stress from exchange-correlation if ( compute_stress ) { xcp->compute_stress(sigma_exc); } - + // Non local energy // Note: next line for nspin==0, nkp==0 only tmap["nonlocal"].start(); @@ -578,7 +578,7 @@ double EnergyFunctional::energy(bool compute_hpsi, Wavefunction& dwf, ets_ = - wf_entropy * s_.ctrl.fermi_temp * boltz; } etotal_ = ekin_ + econf_ + eps_ + enl_ + ecoul_ + exc_ + ets_; - + if ( compute_hpsi ) { tmap["hpsi"].start(); @@ -597,7 +597,7 @@ double EnergyFunctional::energy(bool compute_hpsi, Wavefunction& dwf, const int mloc = cp.mloc(); const double* kpg2 = wfbasis.kpg2_ptr(); const int ngwloc = wfbasis.localsize(); - + // Laplacian if ( use_confinement ) { @@ -607,7 +607,7 @@ double EnergyFunctional::energy(bool compute_hpsi, Wavefunction& dwf, const valarray& fstress = cfp[ikp]->fstress(); for ( int ig = 0; ig < ngwloc; ig++ ) { - cp[ig+mloc*n] += 0.5 * ( kpg2[ig] + fstress[ig] ) * + cp[ig+mloc*n] += 0.5 * ( kpg2[ig] + fstress[ig] ) * c[ig+mloc*n]; } } @@ -628,14 +628,14 @@ double EnergyFunctional::energy(bool compute_hpsi, Wavefunction& dwf, } tmap["hpsi"].stop(); } // if compute_hpsi - + if ( compute_forces ) { const int* idx = vbasis_->idx_ptr(); const double* gx0 = vbasis_->gx_ptr(0); const double* gx1 = vbasis_->gx_ptr(1); const double* gx2 = vbasis_->gx_ptr(2); - + for ( int is = 0; is < nsp_; is++ ) { for ( int ig = 0; ig < ngloc; ig++ ) @@ -664,26 +664,26 @@ double EnergyFunctional::energy(bool compute_hpsi, Wavefunction& dwf, const int kx = idx[iii]; const int ky = idx[iii+1]; const int kz = idx[iii+2]; - + const double cos_a = c0[kx]; const double cos_b = c1[ky]; const double cos_c = c2[kz]; - + const double sin_a = s0[kx]; const double sin_b = s1[ky]; const double sin_c = s2[kz]; - + // Next line: exp(-i*gr) = // (cos_a - I sin_a)*(cos_b - I sin_b)*(cos_c - I sin_c) - double teigr_re = + double teigr_re = cos_a*cos_b*cos_c - sin_a*sin_b*cos_c - sin_a*cos_b*sin_c - cos_a*sin_b*sin_c; - double teigr_im = + double teigr_im = sin_a*sin_b*sin_c - sin_a*cos_b*cos_c - cos_a*sin_b*cos_c - cos_a*cos_b*sin_c; - + /* fion is real */ - double tmp = teigr_re * vtemp[ig].imag() + + double tmp = teigr_re * vtemp[ig].imag() + teigr_im * vtemp[ig].real(); sum0 += tmp * gx0[ig]; @@ -695,7 +695,7 @@ double EnergyFunctional::energy(bool compute_hpsi, Wavefunction& dwf, ftmp[3*ia+2] = sum2; } - + int len = 3*na_[is]; vbasis_->context().dsum(len,1,&ftmp[0],len); @@ -706,7 +706,7 @@ double EnergyFunctional::energy(bool compute_hpsi, Wavefunction& dwf, } } } - + sigma = sigma_ekin + sigma_econf + sigma_eps + sigma_enl + sigma_ehart + sigma_exc + sigma_esr; if ( debug_stress && s_.ctxt_.onpe0() ) @@ -772,8 +772,8 @@ double EnergyFunctional::energy(bool compute_hpsi, Wavefunction& dwf, << " " << setw(12) << sigma[5] << " \n" << " " << endl; } - - + + return etotal_; } @@ -784,10 +784,10 @@ void EnergyFunctional::atoms_moved(void) int ngloc = vbasis_->localsize(); // fill tau0 with values in atom_list - + atoms.get_positions(tau0); sf.update(tau0,*vbasis_); - + // compute Fourier coefficients of the local potential memset( (void*)&vion_local_g[0], 0, 2*ngloc*sizeof(double) ); memset( (void*)&dvion_local_g[0], 0, 2*ngloc*sizeof(double) ); @@ -803,11 +803,11 @@ void EnergyFunctional::atoms_moved(void) dvion_local_g[ig] += sg * dvps[is][ig]; } } - + // compute esr: pseudocharge repulsion energy const UnitCell& cell = s_.wf.cell(); const double omega_inv = 1.0 / cell.volume(); - + esr_ = 0.0; sigma_esr = 0.0; for ( int is = 0; is < nsp_; is++ ) @@ -842,7 +842,7 @@ void EnergyFunctional::atoms_moved(void) esr_ += esr_lm; double desr_erfc = 2.0 * zv_[k]*zv_[j]*exp(-arg*arg)/rckj/sqrt(M_PI); - + // desrdr = (1/r) d Esr / dr double desrdr = -(esr_lm+desr_erfc) / ( rlm*rlm ); fion_esr[k][3*l+0] -= desrdr * xlm; @@ -872,27 +872,27 @@ void EnergyFunctional::cell_moved(void) const UnitCell& cell = wf.cell(); // resize vbasis_ vbasis_->resize(cell,s_.wf.refcell(),4.0*s_.wf.ecut()); - + const int ngloc = vbasis_->localsize(); const double omega = cell.volume(); assert(omega != 0.0); - const double omega_inv = 1.0 / omega; - + const double omega_inv = 1.0 / omega; + const AtomSet& atoms = s_.atoms; for ( int is = 0; is < nsp_; is++ ) { Species *s = atoms.species_list[is]; const double * const g = vbasis_->g_ptr(); - double v,dv; + double v,dv; for ( int ig = 0; ig < ngloc; ig++ ) { rhops[is][ig] = s->rhopsg(g[ig]) * omega_inv; s->dvlocg(g[ig],v,dv); vps[is][ig] = v * omega_inv; dvps[is][ig] = dv * omega_inv; - } + } } - + // Update confinement potentials for ( int ikp = 0; ikp < wf.nkp(); ikp++ ) { @@ -901,7 +901,7 @@ void EnergyFunctional::cell_moved(void) cfp[ikp]->update(); } } - + // update non-local potential nlp->update_twnl(); } @@ -924,10 +924,10 @@ void EnergyFunctional::print(ostream& os) const << " " << setw(15) << etotal() << " \n" << flush; } - + //////////////////////////////////////////////////////////////////////////////// ostream& operator<< ( ostream& os, const EnergyFunctional& e ) -{ - e.print(os); +{ + e.print(os); return os; } diff --git a/src/EnergyFunctional.h b/src/EnergyFunctional.h index 3a5fc09..057a644 100644 --- a/src/EnergyFunctional.h +++ b/src/EnergyFunctional.h @@ -3,7 +3,7 @@ // EnergyFunctional.h // //////////////////////////////////////////////////////////////////////////////// -// $Id: EnergyFunctional.h,v 1.15 2007-03-17 01:14:00 fgygi Exp $ +// $Id: EnergyFunctional.h,v 1.16 2007-10-19 16:24:04 fgygi Exp $ #ifndef ENERGYFUNCTIONAL_H #define ENERGYFUNCTIONAL_H @@ -32,7 +32,7 @@ typedef std::map TimerMap; class EnergyFunctional { private: - + const Sample& s_; const ChargeDensity& cd_; Basis* vbasis_; @@ -42,18 +42,18 @@ class EnergyFunctional XCPotential* xcp; NonLocalPotential* nlp; std::vector cfp; // cfp[ikp] - + std::vector > vps, dvps, rhops; - std::vector > tmp_r, vion_local_g, + std::vector > tmp_r, vion_local_g, dvion_local_g, vlocal_g, rhopst, rhogt, rhoelg, vtemp; std::vector ftmp; - + std::vector > tau0, fion_esr; std::vector zv_, rcps_; std::vector na_; int namax_; int nsp_; - double ekin_, econf_, eps_, enl_, ehart_, + double ekin_, econf_, eps_, enl_, ehart_, ecoul_, exc_, esr_, eself_, ets_, etotal_; std::valarray sigma_ekin,sigma_econf,sigma_eps,sigma_ehart,sigma_exc, sigma_enl, sigma_esr, sigma; @@ -62,11 +62,11 @@ class EnergyFunctional std::vector > v_r; mutable TimerMap tmap; - + double energy(bool compute_hpsi, Wavefunction& dwf, bool compute_forces, std::vector >& fion, bool compute_stress, std::valarray& sigma); - + double etotal(void) const { return etotal_; } double ekin(void) const { return ekin_; } double econf(void) const { return econf_; } @@ -78,14 +78,14 @@ class EnergyFunctional double esr(void) const { return esr_; } double eself(void) const { return eself_; } double ets(void) const { return ets_; } - + const ConfinementPotential *confpot(int ikp) const { return cfp[ikp]; } - + void update_vhxc(void); - + void atoms_moved(void); void cell_moved(void); - + void print(std::ostream& os) const; EnergyFunctional(const Sample& s, const ChargeDensity& cd); diff --git a/src/ExtStress.h b/src/ExtStress.h index f44f43d..ef3c960 100644 --- a/src/ExtStress.h +++ b/src/ExtStress.h @@ -3,7 +3,7 @@ // ExtStress.h // //////////////////////////////////////////////////////////////////////////////// -// $Id: ExtStress.h,v 1.2 2006-11-04 20:20:52 fgygi Exp $ +// $Id: ExtStress.h,v 1.3 2007-10-19 16:24:04 fgygi Exp $ #ifndef EXTSTRESS_H #define EXTSTRESS_H @@ -28,14 +28,14 @@ class ExtStress : public Var if ( argc != 7 ) { if ( ui->onpe0() ) - cout << " ext_stress must be specified as s_xx,s_yy,s_zz,s_xy,s_yz,s_xz" + cout << " ext_stress must be specified as s_xx,s_yy,s_zz,s_xy,s_yz,s_xz" << endl; return 1; } - + for ( int i = 0; i < 6; i++ ) s->ctrl.ext_stress[i] = atof(argv[i+1]); - + return 0; } diff --git a/src/FermiTemp.h b/src/FermiTemp.h index 41ab5d9..faa5dec 100644 --- a/src/FermiTemp.h +++ b/src/FermiTemp.h @@ -3,7 +3,7 @@ // FermiTemp.h // //////////////////////////////////////////////////////////////////////////////// -// $Id: FermiTemp.h,v 1.1 2004-10-04 19:55:39 fgygi Exp $ +// $Id: FermiTemp.h,v 1.2 2007-10-19 16:24:04 fgygi Exp $ #ifndef FERMITEMP_H #define FERMITEMP_H @@ -31,7 +31,7 @@ class FermiTemp : public Var cout << " fermi_temp takes only one value" << endl; return 1; } - + double v = atof(argv[1]); if ( v < 0.0 ) { diff --git a/src/FourierTransform.C b/src/FourierTransform.C index 8d0acc4..db5cc60 100644 --- a/src/FourierTransform.C +++ b/src/FourierTransform.C @@ -3,7 +3,7 @@ // FourierTransform.C // //////////////////////////////////////////////////////////////////////////////// -// $Id: FourierTransform.C,v 1.17 2007-03-17 01:14:00 fgygi Exp $ +// $Id: FourierTransform.C,v 1.18 2007-10-19 16:24:04 fgygi Exp $ // The following macros must be defined: USE_FFTW, USE_ESSL, USE_ESSL_2DFFT @@ -45,17 +45,17 @@ extern "C" { } #else #define NO_FFT_LIB 1 -void cfftm ( std::complex *ain, std::complex *aout, +void cfftm ( std::complex *ain, std::complex *aout, double scale, int ntrans, int length, int ainc, int ajmp, int idir ); #endif #if USE_GATHER_SCATTER extern "C" { // zgthr: x(i) = y(indx(i)) - void zgthr_(int* n, std::complex* y, + void zgthr_(int* n, std::complex* y, std::complex* x, int*indx); // zsctr: y(indx(i)) = x(i) - void zsctr_(int* n, std::complex* x, int* indx, + void zsctr_(int* n, std::complex* x, int* indx, std::complex* y); } #endif @@ -77,7 +77,7 @@ FourierTransform::~FourierTransform() //////////////////////////////////////////////////////////////////////////////// FourierTransform::FourierTransform (const Basis &basis, - int np0, int np1, int np2) : ctxt_(basis.context()), basis_(basis), + int np0, int np1, int np2) : ctxt_(basis.context()), basis_(basis), np0_(np0), np1_(np1), np2_(np2) { assert(ctxt_.npcol() == 1); @@ -91,7 +91,7 @@ FourierTransform::FourierTransform (const Basis &basis, np2_first_.resize(nprocs_); // Block-cyclic distribution for np2 - // Partition np2 into nprocs_ intervals and + // Partition np2 into nprocs_ intervals and // store local sizes in np2_loc_[iproc] // Use same block distribution as in ScaLAPACK // Blocks 0,...,nprocs_-2 have size np2_block_size @@ -120,7 +120,7 @@ FourierTransform::FourierTransform (const Basis &basis, { np2_first_[iproc] = np2_first_[iproc-1] + np2_loc_[iproc-1]; } - + // number of local z vectors if ( basis_.real() ) { @@ -134,29 +134,29 @@ FourierTransform::FourierTransform (const Basis &basis, { nvec_ = basis_.nrod_loc(); } - + // compute number of transforms along the x,y and z directions // ntrans0_ is the number of transforms along x in one of the two blocks // of vectors corresponding to positive and negative y indices ntrans0_ = max(abs(basis_.idxmax(1)),abs(basis_.idxmin(1)))+1; ntrans1_ = np0_; ntrans2_ = nvec_; - + // resize array zvec holding columns zvec_.resize(nvec_ * np2_); - + // Initialize FT library auxiliary arrays init_lib(); - + // allocate send buffer sbuf.resize(nvec_ * np2_); - + // allocate receive buffer if ( basis_.real() ) rbuf.resize((2 * basis_.nrods() - 1) * np2_loc_[myproc_]); else rbuf.resize(basis_.nrods() * np2_loc_[myproc_]); - + // compute send/receive counts and displacements in units of sizeof(double) scounts.resize(nprocs_); @@ -191,13 +191,13 @@ FourierTransform::FourierTransform (const Basis &basis, sdispl[iproc] = sdispl[iproc-1] + scounts[iproc-1]; rdispl[iproc] = rdispl[iproc-1] + rcounts[iproc-1]; } - + if ( basis_.real() ) { // compute index arrays ifftp_ and ifftm_ for mapping vector->zvec ifftp_.resize(basis_.localsize()); ifftm_.resize(basis_.localsize()); - + if ( myproc_ == 0 ) { // this process holds rod(0,0) @@ -282,7 +282,7 @@ FourierTransform::FourierTransform (const Basis &basis, isource += np2_; } } - + // compute array iunpack // used in unpacking rbuf into val // val[iunpack[i]] = rbuf[i] @@ -300,7 +300,7 @@ FourierTransform::FourierTransform (const Basis &basis, } int isource_p = np2_loc_[myproc_]; int isource_m = 2 * np2_loc_[myproc_]; - + // all rods of pe 0 for ( int irod = 1; irod < basis_.nrod_loc(0); irod++ ) { @@ -343,17 +343,17 @@ FourierTransform::FourierTransform (const Basis &basis, int kp = basis_.rod_k(iproc,irod); if ( hp < 0 ) hp += np0_; if ( kp < 0 ) kp += np1_; - + int hm = -hp; int km = -kp; if ( hm < 0 ) hm += np0_; if ( km < 0 ) km += np1_; - + for ( int l = 0; l < np2_loc_[myproc_]; l++ ) { int idest_p = hp + np0_ * ( kp + np1_ * l ); iunpack_[isource_p+l] = idest_p; - + int idest_m = hm + np0_ * ( km + np1_ * l ); iunpack_[isource_m+l] = idest_m; } @@ -368,7 +368,7 @@ FourierTransform::FourierTransform (const Basis &basis, // compute index array ifftp_ for mapping vector->zvec // Note: ifftm_ is not used ifftp_.resize(basis_.localsize()); - + // map rods(h,k) // rod(h,k) maps onto column irod*np2_ of zvec_, irod=0,..,nrods-1 int ig = 0; @@ -405,7 +405,7 @@ FourierTransform::FourierTransform (const Basis &basis, isource += np2_; } } - + // compute array iunpack // used in unpacking rbuf into val // val[iunpack[i]] = rbuf[i] @@ -427,24 +427,24 @@ FourierTransform::FourierTransform (const Basis &basis, int k = basis_.rod_k(iproc,irod); if ( h < 0 ) h += np0_; if ( k < 0 ) k += np1_; - + for ( int l = 0; l < np2_loc_[myproc_]; l++ ) { int idest = h + np0_ * ( k + np1_ * l ); iunpack_[isource+l] = idest; - + } isource += np2_loc_[myproc_]; } } } - + // for ( int ig = 0; ig < basis_.localsize(); ig++ ) // { // assert(ifftp_[ig] >= 0 && ifftp_[ig] < zvec_.size()); // assert(ifftm_[ig] >= 0 && ifftm_[ig] < zvec_.size()); // } - + #if USE_GATHER_SCATTER // shift index array by one for fortran ZGTHR and ZSCTR calls for ( int i = 0; i < iunpack_.size(); i++ ) @@ -485,7 +485,7 @@ void FourierTransform::forward(complex* f, complex* c) } //////////////////////////////////////////////////////////////////////////////// -void FourierTransform::backward(const complex* c1, +void FourierTransform::backward(const complex* c1, const complex* c2, complex* f) { @@ -512,7 +512,7 @@ void FourierTransform::forward(complex* f, tm_f_map.stop(); #endif } - + //////////////////////////////////////////////////////////////////////////////// void FourierTransform::bwd(complex* val) { @@ -520,8 +520,8 @@ void FourierTransform::bwd(complex* val) // result in val // The columns of zvec[nvec_ * np2_] contain the full vectors // to be transformed - // - // If the basis is real: Column (h,k) is followed by column (-h,-k), + // + // If the basis is real: Column (h,k) is followed by column (-h,-k), // except for (0,0) #if TIMING @@ -531,12 +531,12 @@ void FourierTransform::bwd(complex* val) #if USE_ESSL int inc1 = 1, inc2 = np2_, ntrans = nvec_, isign = -1, initflag = 0; double scale = 1.0; - + dcft_(&initflag,&zvec_[0],&inc1,&inc2,&zvec_[0],&inc1,&inc2,&np2_,&ntrans, &isign,&scale,&aux1zb[0],&naux1z,&aux2[0],&naux2); #elif USE_FFTW - /* + /* * void fftw(fftw_plan plan, int howmany, * FFTW_COMPLEX *in, int istride, int idist, * FFTW_COMPLEX *out, int ostride, int odist); @@ -559,12 +559,12 @@ void FourierTransform::bwd(complex* val) int idir = -1; cfftm ( &zvec_[0], &zvec_[0], scale, ntrans, length, ainc, ajmp, idir ); #endif - + #if TIMING tm_b_fft.stop(); tm_b_pack.start(); #endif - + // scatter zvec_ to sbuf for transpose #if USE_GATHER_SCATTER // zsctr: y(indx(i)) = x(i) @@ -589,9 +589,9 @@ void FourierTransform::bwd(complex* val) ps[2*ip+1] = b; } #endif - + // segments of z-vectors are now in sbuf - + #if TIMING tm_b_pack.stop(); tm_b_mpi.start(); @@ -611,7 +611,7 @@ void FourierTransform::bwd(complex* val) assert(sbuf.size()==rbuf.size()); rbuf = sbuf; #endif - + #if TIMING tm_b_mpi.stop(); tm_b_zero.start(); @@ -628,7 +628,7 @@ void FourierTransform::bwd(complex* val) pv[2*i+1] = 0.0; } } - + #if TIMING tm_b_zero.stop(); tm_b_unpack.start(); @@ -658,7 +658,7 @@ void FourierTransform::bwd(complex* val) } } #endif - + #if TIMING tm_b_unpack.stop(); tm_b_fft.start(); @@ -674,9 +674,9 @@ void FourierTransform::bwd(complex* val) // use 2D FFT for x and y transforms int inc1, inc2, istart, isign = -1, initflag = 0; double scale = 1.0; - + // xy transform - istart = k * np0_ * np1_; + istart = k * np0_ * np1_; inc1 = 1; inc2 = np0_; dcft2_(&initflag,&val[istart],&inc1,&inc2,&val[istart],&inc1,&inc2, &np0_,&np1_,&isign,&scale,&aux1xyb[0],&naux1xy,&aux2[0],&naux2); @@ -684,7 +684,7 @@ void FourierTransform::bwd(complex* val) #else // use multiple 1-d FFTs for x and y transforms - + int inc1, inc2, ntrans, istart, length, isign = -1, initflag = 0; double scale = 1.0; // transform only non-zero vectors along x @@ -696,7 +696,7 @@ void FourierTransform::bwd(complex* val) length = np0_; dcft_(&initflag,&val[istart],&inc1,&inc2,&val[istart],&inc1,&inc2, &length,&ntrans,&isign,&scale,&aux1xb[0],&naux1x,&aux2[0],&naux2); - + // Second block: negative y indices: [np1-ntrans0_,np1-1] inc1 = 1; inc2 = np0_; @@ -704,7 +704,7 @@ void FourierTransform::bwd(complex* val) length = np0_; dcft_(&initflag,&val[istart],&inc1,&inc2,&val[istart],&inc1,&inc2, &length,&ntrans,&isign,&scale,&aux1xb[0],&naux1x,&aux2[0],&naux2); - + // transform along y for all values of x ntrans = np0_; inc1 = np0_; @@ -713,7 +713,7 @@ void FourierTransform::bwd(complex* val) length = np1_; dcft_(&initflag,&val[istart],&inc1,&inc2,&val[istart],&inc1,&inc2, &length,&ntrans,&isign,&scale,&aux1yb[0],&naux1y,&aux2[0],&naux2); -#endif +#endif #elif USE_FFTW int inc1, inc2, istart; @@ -721,7 +721,7 @@ void FourierTransform::bwd(complex* val) // Transform first block along x: positive y indices inc1 = 1; inc2 = np0_; - istart = k * np0_ * np1_; + istart = k * np0_ * np1_; fftw(bwplan0,ntrans,(FFTW_COMPLEX*)&val[istart],inc1,inc2, (FFTW_COMPLEX*)0,0,0); // Transform second block along x: negative y indices @@ -730,12 +730,12 @@ void FourierTransform::bwd(complex* val) istart = np0_ * ( (np1_-ntrans) + k * np1_ ); fftw(bwplan0,ntrans,(FFTW_COMPLEX*)&val[istart],inc1,inc2, (FFTW_COMPLEX*)0,0,0); - + // transform along y for all values of x ntrans = np0_; inc1 = np0_; inc2 = 1; - istart = k * np0_ * np1_; + istart = k * np0_ * np1_; fftw(bwplan1,ntrans,(FFTW_COMPLEX*)&val[istart],inc1,inc2, (FFTW_COMPLEX*)0,0,0); #else @@ -750,11 +750,11 @@ void FourierTransform::bwd(complex* val) double scale = 1.0; int idir = -1; cfftm (&val[istart],&val[istart],scale,ntrans,length,ainc,ajmp,idir ); - + // Transform second block along x: negative y indices istart = np0_ * ( (np1_-ntrans) + k * np1_ ); cfftm (&val[istart],&val[istart],scale,ntrans,length,ainc,ajmp,idir ); - + // transform along y for all values of x ntrans = np0_; istart = k * np0_ * np1_; @@ -765,7 +765,7 @@ void FourierTransform::bwd(complex* val) #endif } // for k - + #if TIMING tm_b_fft.stop(); #endif @@ -787,7 +787,7 @@ void FourierTransform::fwd(complex* val) // use 2D FFT for x and y transforms int inc1, inc2, istart, isign = 1, initflag = 0; double scale = 1.0; - + // xy transform istart = k * np0_ * np1_; inc1 = 1; inc2 = np0_; @@ -797,7 +797,7 @@ void FourierTransform::fwd(complex* val) #else // use multiple 1-d FFTs for x and y transforms - + int inc1, inc2, ntrans, istart, length, isign = 1, initflag = 0; double scale = 1.0; // transform along y for all values of x @@ -808,7 +808,7 @@ void FourierTransform::fwd(complex* val) length = np1_; dcft_(&initflag,&val[istart],&inc1,&inc2,&val[istart],&inc1,&inc2, &length,&ntrans,&isign,&scale,&aux1yf[0],&naux1y,&aux2[0],&naux2); - + // transform only non-zero vectors along x ntrans = ntrans0_; inc1 = 1; @@ -817,14 +817,14 @@ void FourierTransform::fwd(complex* val) length = np0_; dcft_(&initflag,&val[istart],&inc1,&inc2,&val[istart],&inc1,&inc2, &length,&ntrans,&isign,&scale,&aux1xf[0],&naux1x,&aux2[0],&naux2); - + inc1 = 1; inc2 = np0_; istart = np0_ * ( (np1_-ntrans) + k * np1_ ); length = np0_; dcft_(&initflag,&val[istart],&inc1,&inc2,&val[istart],&inc1,&inc2, &length,&ntrans,&isign,&scale,&aux1xf[0],&naux1x,&aux2[0],&naux2); -#endif +#endif #elif USE_FFTW int inc1, inc2, istart; @@ -832,15 +832,15 @@ void FourierTransform::fwd(complex* val) int ntrans = np0_; inc1 = np0_; inc2 = 1; - istart = k * np0_ * np1_; + istart = k * np0_ * np1_; fftw(fwplan1,ntrans,(FFTW_COMPLEX*)&val[istart],inc1,inc2, (FFTW_COMPLEX*)0,0,0); - + ntrans = ntrans0_; // Transform first block along x: positive y indices inc1 = 1; inc2 = np0_; - istart = k * np0_ * np1_; + istart = k * np0_ * np1_; fftw(fwplan0,ntrans,(FFTW_COMPLEX*)&val[istart],inc1,inc2, (FFTW_COMPLEX*)0,0,0); // Transform second block along x: negative y indices @@ -849,7 +849,7 @@ void FourierTransform::fwd(complex* val) istart = np0_ * ( (np1_-ntrans) + k * np1_ ); fftw(fwplan0,ntrans,(FFTW_COMPLEX*)&val[istart],inc1,inc2, (FFTW_COMPLEX*)0,0,0); - + #else // No library // transform along y for all values of x @@ -861,7 +861,7 @@ void FourierTransform::fwd(complex* val) double scale = 1.0; int idir = 1; cfftm (&val[istart],&val[istart],scale,ntrans,length,ainc,ajmp,idir ); - + // transform along x for non-zero elements ntrans = ntrans0_; istart = k * np0_ * np1_; @@ -869,12 +869,12 @@ void FourierTransform::fwd(complex* val) ainc = 1; ajmp = np0_; cfftm (&val[istart],&val[istart],scale,ntrans,length,ainc,ajmp,idir ); - + istart = np0_ * ( (np1_-ntrans) + k * np1_ ); cfftm (&val[istart],&val[istart],scale,ntrans,length,ainc,ajmp,idir ); #endif } // for k - + // gather val into rbuf #if TIMING tm_f_fft.stop(); @@ -904,7 +904,7 @@ void FourierTransform::fwd(complex* val) pr[2*i+1] = b; } #endif - + // transpose #if TIMING tm_f_pack.stop(); @@ -919,14 +919,14 @@ void FourierTransform::fwd(complex* val) assert(sbuf.size()==rbuf.size()); rbuf = sbuf; #endif - + // segments of z-vectors are now in sbuf // gather sbuf into zvec_ #if TIMING tm_f_mpi.stop(); tm_f_unpack.start(); #endif - + #if USE_GATHER_SCATTER // zgthr: x(i) = y(indx(i)) // void zgthr_(int* n, complex* y, complex* x, int*indx); @@ -956,14 +956,14 @@ void FourierTransform::fwd(complex* val) tm_f_unpack.stop(); tm_f_fft.start(); #endif - + #if USE_ESSL int inc1 = 1, inc2 = np2_, ntrans = nvec_, isign = 1, initflag = 0; double scale = 1.0 / (np0_ * np1_ * np2_); - + dcft_(&initflag,&zvec_[0],&inc1,&inc2,&zvec_[0],&inc1,&inc2,&np2_,&ntrans, &isign,&scale,&aux1zf[0],&naux1z,&aux2[0],&naux2); - + #elif USE_FFTW /* * void fftw(fftw_plan plan, int howmany, @@ -1003,7 +1003,7 @@ void FourierTransform::init_lib(void) // initialization of FFT libs #if USE_ESSL -#if USE_ESSL_2DFFT +#if USE_ESSL_2DFFT // use 2D FFT for x and y transforms and 1D FFT for z transforms naux1xy = 40000 + 2.28 * (np0_+np1_); aux1xyf.resize(naux1xy); @@ -1011,18 +1011,18 @@ void FourierTransform::init_lib(void) int r = max(np0_,np1_); int s = min(64,min(np0_,np1_)); naux2 = 20000 + (2*r+256)*(s+2.28); - + naux1z = 20000 + 2.28 * np2_; aux1zf.resize(naux1z); aux1zb.resize(naux1z); - + int ntrans2 = nvec_; int naux2z = 20000 + 2.28 * np2_ + (256 + 2*np2_)*min(64,ntrans2); naux2 = max( naux2, naux2z ); aux2.resize(naux2); - + double scale = 1.0; - + // initialize xy transforms int initflag = 1, inc1, inc2, isign = -1; inc1 = 1; inc2 = np0_; @@ -1034,7 +1034,7 @@ void FourierTransform::init_lib(void) // initialize z transforms int ntrans = nvec_; - inc1 = 1; inc2 = np2_; + inc1 = 1; inc2 = np2_; isign = -1; dcft_(&initflag,p,&inc1,&inc2,p,&inc1,&inc2,&np2_,&ntrans, &isign,&scale,&aux1zb[0],&naux1z,&aux2[0],&naux2); @@ -1043,7 +1043,7 @@ void FourierTransform::init_lib(void) &isign,&scale,&aux1zf[0],&naux1z,&aux2[0],&naux2); #else - + naux1x = (int) (20000 + 2.28 * np0_); naux1y = (int) (20000 + 2.28 * np1_); naux1z = (int) (20000 + 2.28 * np2_); @@ -1061,13 +1061,13 @@ void FourierTransform::init_lib(void) int naux2z = (int) (20000 + 2.28 * np2_ + (256 + 2*np2_)*min(64,ntrans2_)); naux2 = max( naux2, naux2z ); aux2.resize(naux2); - + // initialize x, y and z transforms int initflag = 1, inc1, inc2, ntrans, isign; double scale = 1.0; complex *p = 0; - + // x transforms inc1 = 1; inc2 = np0_; ntrans = ntrans0_; isign = -1; @@ -1076,7 +1076,7 @@ void FourierTransform::init_lib(void) isign = 1; dcft_(&initflag,p,&inc1,&inc2,p,&inc1,&inc2,&np0_,&ntrans, &isign,&scale,&aux1xf[0],&naux1x,&aux2[0],&naux2); - + // y transforms inc1 = np0_; inc2 = 1; ntrans = ntrans1_; isign = -1; @@ -1085,7 +1085,7 @@ void FourierTransform::init_lib(void) isign = 1; dcft_(&initflag,p,&inc1,&inc2,p,&inc1,&inc2,&np1_,&ntrans, &isign,&scale,&aux1yf[0],&naux1y,&aux2[0],&naux2); - + // z transforms inc1 = 1; inc2 = np2_; ntrans = ntrans2_; isign = -1; @@ -1135,7 +1135,7 @@ void FourierTransform::vector_to_zvec(const complex *c) } const double* const pc = (double*) &c[0]; if ( basis_.real() ) - { + { for ( int ig = 0; ig < ng; ig++ ) { // zvec_[ifftp_[ig]] = c[ig]; @@ -1216,10 +1216,10 @@ void FourierTransform::doublevector_to_zvec(const complex *c1, } //////////////////////////////////////////////////////////////////////////////// -void FourierTransform::zvec_to_doublevector(complex *c1, +void FourierTransform::zvec_to_doublevector(complex *c1, complex *c2 ) { - // Mapping of zvec onto two real functions + // Mapping of zvec onto two real functions assert(basis_.real()); const int ng = basis_.localsize(); const double* const pz = (double*) &zvec_[0]; @@ -1252,8 +1252,8 @@ void FourierTransform::zvec_to_doublevector(complex *c1, //////////////////////////////////////////////////////////////////////////////// // // /* no library: use cfftm function */ -// -// +// +// // /* Transform along x */ // int i2; // int ntrans = np1*np2; @@ -1272,9 +1272,9 @@ void FourierTransform::zvec_to_doublevector(complex *c1, // idir = 1; // scale = 1.0; // } -// +// // cfftm ( &val[0], &val[0], scale, ntrans, length, ainc, ajmp, idir ); -// +// // /* Transform along y */ // for ( i2 = 0; i2 < np2; i2++ ) // { @@ -1286,7 +1286,7 @@ void FourierTransform::zvec_to_doublevector(complex *c1, // scale = 1.0; // cfftm ( &val[ist], &val[ist], scale, ntrans, length, ainc, ajmp, idir ); // } -// +// // /* Transform along z */ // ntrans = np0i*np1; // length = np2; @@ -1294,7 +1294,7 @@ void FourierTransform::zvec_to_doublevector(complex *c1, // ajmp = 1; // scale = 1.0; // cfftm ( &val[0], &val[0], scale, ntrans, length, ainc, ajmp, idir ); -// +// //////////////////////////////////////////////////////////////////////////////// /* define multiple FFT function here */ @@ -1347,8 +1347,8 @@ void cfftm ( complex *ain, complex *aout, double scale, /******************************************************************************* * - * Complex FFT - * C version + * Complex FFT + * C version * * From: C++ Language System Release 3.0 Library Manual * Transcription from 'FFT as Nested Multiplication, with a twist' @@ -1365,12 +1365,12 @@ void cfftm ( complex *ain, complex *aout, double scale, void cfft ( int idir, complex *z1, complex *z2, int n, int *inzee ) { - // Compute the discrete Fourier transform of z1 (or z2) in + // Compute the discrete Fourier transform of z1 (or z2) in // the Cooley-Tukey way, but with a twist. // z1[before], z2[before] // *inzee == 1 means input in z1; *inzee == 2 means input in z2 - void fftstp ( int idir, complex *zin, int after, + void fftstp ( int idir, complex *zin, int after, int now, int before, complex *zout ); static int prime[NEXTMX] = { 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37 }; int before = n; @@ -1387,7 +1387,7 @@ void cfft ( int idir, complex *z1, complex *z2, int n, if ( ++next < NEXTMX ) continue; now = before; before = 1; - } + } else { now = np; @@ -1403,7 +1403,7 @@ void cfft ( int idir, complex *z1, complex *z2, int n, } -void fftstp ( int idir, complex *zin, int after, +void fftstp ( int idir, complex *zin, int after, int now, int before, complex *zout ) { @@ -1437,7 +1437,7 @@ void fftstp ( int idir, complex *zin, int after, l = ia + j*after + ib*now*after; zout[l] = value; } - + /* arg *= omega; */ arg *= omega; diff --git a/src/FourierTransform.h b/src/FourierTransform.h index 0501042..628843f 100644 --- a/src/FourierTransform.h +++ b/src/FourierTransform.h @@ -3,7 +3,7 @@ // FourierTransform.h // //////////////////////////////////////////////////////////////////////////////// -// $Id: FourierTransform.h,v 1.10 2007-03-17 01:14:00 fgygi Exp $ +// $Id: FourierTransform.h,v 1.11 2007-10-19 16:24:04 fgygi Exp $ #ifndef FOURIERTRANSFORM_H #define FOURIERTRANSFORM_H @@ -30,21 +30,21 @@ class FourierTransform int np0_,np1_,np2_; int ntrans0_,ntrans1_,ntrans2_; - + int nvec_; - + std::vector np2_loc_; // np2_loc_[iproc], iproc=0, nprocs_-1 std::vector np2_first_; // np2_first_[iproc], iproc=0, nprocs_-1 std::vector > zvec_; - + std::vector scounts, sdispl, rcounts, rdispl; std::vector > sbuf, rbuf; std::vector ifftp_, ifftm_; std::vector ipack_, iunpack_; - + void init_lib(void); - + #if USE_ESSL #if USE_ESSL_2DFFT std::vector aux1xyf; @@ -69,13 +69,13 @@ class FourierTransform void zvec_to_doublevector(std::complex* c1, std::complex* c2); void fwd(std::complex* val); void bwd(std::complex* val); - + public: FourierTransform (const Basis &basis, int np0, int np1, int np2); ~FourierTransform (); const Context& context(void) const { return ctxt_; } - + // backward: Fourier synthesis, compute real-space function // forward: Fourier analysis, compute Fourier coefficients // forward transform includes scaling by 1/np012 @@ -83,14 +83,14 @@ class FourierTransform void backward (const std::complex* c, std::complex* f); // Note: forward transforms overwrite the array f void forward(std::complex* f, std::complex* c); - + // double transforms: c1 + i*c2 -> f, f -> c1 + i*c2 - void backward (const std::complex* c1, + void backward (const std::complex* c1, const std::complex* c2, std::complex* f); // Note: forward transforms overwrite the array f - void forward(std::complex* f, + void forward(std::complex* f, std::complex* c1, std::complex* c2); - + int np0() const { return np0_; } int np1() const { return np1_; } int np2() const { return np2_; } @@ -102,7 +102,7 @@ class FourierTransform int np012loc(int iproc) const { return np0_ * np1_ * np2_loc_[iproc]; } int np012loc() const { return np0_ * np1_ * np2_loc_[myproc_]; } int index(int i, int j, int k) const - { return i + np0_ * ( j + np1_ * k ); } + { return i + np0_ * ( j + np1_ * k ); } void reset_timers(void); Timer tm_f_map, tm_f_fft, tm_f_pack, tm_f_mpi, tm_f_zero, tm_f_unpack, diff --git a/src/HelpCmd.h b/src/HelpCmd.h index 84025e4..4b3d149 100644 --- a/src/HelpCmd.h +++ b/src/HelpCmd.h @@ -3,7 +3,7 @@ // HelpCmd.h: // //////////////////////////////////////////////////////////////////////////////// -// $Id: HelpCmd.h,v 1.1 2003-01-10 00:35:36 fgygi Exp $ +// $Id: HelpCmd.h,v 1.2 2007-10-19 16:24:04 fgygi Exp $ #ifndef HELPCMD_H #define HELPCMD_H @@ -28,7 +28,7 @@ class HelpCmd : public Cmd char *help_msg(void) const { - return + return "\n help\n\n" " syntax: help [command_name]\n\n" " The help command gives a short description of a command. If used\n" diff --git a/src/IonicStepper.h b/src/IonicStepper.h index 7bcaa56..55764e3 100644 --- a/src/IonicStepper.h +++ b/src/IonicStepper.h @@ -3,7 +3,7 @@ // IonicStepper.h: // //////////////////////////////////////////////////////////////////////////////// -// $Id: IonicStepper.h,v 1.8 2007-03-17 01:14:00 fgygi Exp $ +// $Id: IonicStepper.h,v 1.9 2007-10-19 16:24:04 fgygi Exp $ #ifndef IONICSTEPPER_H #define IONICSTEPPER_H @@ -15,7 +15,7 @@ class IonicStepper { protected: - + Sample& s_; AtomSet& atoms_; ConstraintSet& constraints_; @@ -23,15 +23,15 @@ class IonicStepper int nsp_; int ndofs_; std::vector na_; // number of atoms per species na_[nsp_] - std::vector > r0_; // r0_[nsp_][3*na_] - std::vector > rp_; // rp_[nsp_][3*na_] - std::vector > rm_; // rm_[nsp_][3*na_] - std::vector > v0_; // v0_[nsp_][3*na_] + std::vector > r0_; // r0_[nsp_][3*na_] + std::vector > rp_; // rp_[nsp_][3*na_] + std::vector > rm_; // rm_[nsp_][3*na_] + std::vector > v0_; // v0_[nsp_][3*na_] std::vector pmass_; // pmass_[nsp_] public: - - IonicStepper (Sample& s) : s_(s), atoms_(s.atoms), + + IonicStepper (Sample& s) : s_(s), atoms_(s.atoms), constraints_(s.constraints), dt_(s.ctrl.dt) { ndofs_ = 3 * atoms_.size() - constraints_.size(); @@ -55,26 +55,26 @@ class IonicStepper atoms_.get_positions(r0_); atoms_.get_velocities(v0_); } - + double r0(int is, int i) const { return r0_[is][i]; } double v0(int is, int i) const { return v0_[is][i]; } const std::vector >& r0(void) const { return r0_; } const std::vector >& v0(void) const { return v0_; } const std::vector& pmass(void) const { return pmass_; } - + void setup_constraints(void) { constraints_.setup(atoms_); } - virtual void compute_r(double e0, + virtual void compute_r(double e0, const std::vector >& f0) = 0; - virtual void compute_v(double e0, + virtual void compute_v(double e0, const std::vector >& f0) = 0; virtual void reset(void) {} virtual double ekin(void) const { return 0.0; } virtual double temp(void) const { return 0.0; } - + virtual ~IonicStepper() {} - + }; #endif diff --git a/src/LDAFunctional.C b/src/LDAFunctional.C index d12db12..beca3f6 100644 --- a/src/LDAFunctional.C +++ b/src/LDAFunctional.C @@ -6,14 +6,14 @@ // Ceperley & Alder, parametrized by Perdew and Zunger // //////////////////////////////////////////////////////////////////////////////// -// $Id: LDAFunctional.C,v 1.4 2004-08-14 00:18:34 fgygi Exp $ +// $Id: LDAFunctional.C,v 1.5 2007-10-19 16:24:04 fgygi Exp $ #include #include #include #include "LDAFunctional.h" -void LDAFunctional::setxc(void) +void LDAFunctional::setxc(void) { if ( _np == 0 ) return; if ( _nspin == 1 ) @@ -78,7 +78,7 @@ void LDAFunctional::setxc(void) void LDAFunctional::xc_unpolarized(const double rh, double &ee, double &vv) { - // compute LDA xc energy and potential, unpolarized + // compute LDA xc energy and potential, unpolarized // const double third=1.0/3.0; // c1 is (3.D0/(4.D0*pi))**third const double c1 = 0.6203504908994001; @@ -94,13 +94,13 @@ void LDAFunctional::xc_unpolarized(const double rh, double &ee, double &vv) const double b1 = 1.0529; const double b2 = 0.3334; const double G = -0.1423; - + // C from the PZ paper: const double C = 0.0020; // D from the PZ paper: const double D = -0.0116; // C and D by matching Ec and Vc at rs=1 const double D = G / ( 1.0 + b1 + b2 ) - B; const double C = -A - D - G * ( (b1/2.0 + b2) / ((1.0+b1+b2)*(1.0+b1+b2))); - + ee = 0.0; vv = 0.0; @@ -114,7 +114,7 @@ void LDAFunctional::xc_unpolarized(const double rh, double &ee, double &vv) // Next line : exchange part in Hartree units vx = c3 / rs; ex = 0.75 * vx; - + // Next lines : Ceperley & Alder correlation (Zunger & Perdew) if ( rs < 1.0 ) { @@ -150,7 +150,7 @@ void LDAFunctional::xc_polarized(const double rh, double &ee, double &vv) // const double c2 = -0.458165293283; // c3 = (4/3) * c2 = -0.610887057711 // const double c3 = -0.610887057711; - // c4 = 2**third * c3 + // c4 = 2**third * c3 const double c4 = -0.769669463118; const double A = 0.01555; @@ -177,7 +177,7 @@ void LDAFunctional::xc_polarized(const double rh, double &ee, double &vv) // Next line : exchange part in Hartree units vx = c4 / rs; ex = 0.75 * vx; - + // Next lines : Ceperley & Alder correlation (Zunger & Perdew) if ( rs < 1.0 ) { diff --git a/src/LDAFunctional.h b/src/LDAFunctional.h index cac4688..ae099eb 100644 --- a/src/LDAFunctional.h +++ b/src/LDAFunctional.h @@ -3,7 +3,7 @@ // LDAFunctional.h // //////////////////////////////////////////////////////////////////////////////// -// $Id: LDAFunctional.h,v 1.4 2007-03-17 01:14:00 fgygi Exp $ +// $Id: LDAFunctional.h,v 1.5 2007-10-19 16:24:04 fgygi Exp $ #ifndef LDAFUNCTIONAL_H #define LDAFUNCTIONAL_H @@ -15,14 +15,14 @@ class LDAFunctional : public XCFunctional { void xc_unpolarized(const double rh, double &ee, double &vv); - void xc_polarized(const double rh, double &ee, double &vv); + void xc_polarized(const double rh, double &ee, double &vv); std::vector _exc; std::vector > _vxc; - + LDAFunctional(); - + public: - + LDAFunctional(const std::vector > &rhoe) { _nspin = rhoe.size(); @@ -34,7 +34,7 @@ class LDAFunctional : public XCFunctional { _vxc[i].resize(_np); } - + if ( _nspin == 1 ) { rho = &rhoe[0][0]; @@ -50,7 +50,7 @@ class LDAFunctional : public XCFunctional vxc1_dn = &_vxc[1][0]; } }; - + bool isGGA() { return false; }; std::string name() { return "LDA"; }; void setxc(void); diff --git a/src/ListAtomsCmd.h b/src/ListAtomsCmd.h index 657a311..c65df63 100644 --- a/src/ListAtomsCmd.h +++ b/src/ListAtomsCmd.h @@ -3,7 +3,7 @@ // ListAtomsCmd.h: // //////////////////////////////////////////////////////////////////////////////// -// $Id: ListAtomsCmd.h,v 1.2 2003-03-27 22:05:59 fgygi Exp $ +// $Id: ListAtomsCmd.h,v 1.3 2007-10-19 16:24:04 fgygi Exp $ #ifndef LISTATOMSCMD_H #define LISTATOMSCMD_H @@ -24,7 +24,7 @@ class ListAtomsCmd : public Cmd char *name(void) const { return "list_atoms"; } char *help_msg(void) const { - return + return "\n list_atoms\n\n" " syntax: list_atoms\n\n" " The list_atoms command prints a list of all defined atoms.\n\n"; diff --git a/src/ListConstraintsCmd.h b/src/ListConstraintsCmd.h index 95aa78d..f1dc332 100644 --- a/src/ListConstraintsCmd.h +++ b/src/ListConstraintsCmd.h @@ -3,7 +3,7 @@ // ListConstraintsCmd.h: // //////////////////////////////////////////////////////////////////////////////// -// $Id: ListConstraintsCmd.h,v 1.1 2005-06-27 22:34:46 fgygi Exp $ +// $Id: ListConstraintsCmd.h,v 1.2 2007-10-19 16:24:04 fgygi Exp $ #ifndef LISTCONSTRAINTSCMD_H #define LISTCONSTRAINTSCMD_H @@ -25,7 +25,7 @@ class ListConstraintsCmd : public Cmd char *name(void) const { return "list_constraints"; } char *help_msg(void) const { - return + return "\n list_constraints\n\n" " syntax: list_constraints\n\n" " The list_constraints command prints the list" diff --git a/src/ListSpeciesCmd.h b/src/ListSpeciesCmd.h index 2307762..85718d4 100644 --- a/src/ListSpeciesCmd.h +++ b/src/ListSpeciesCmd.h @@ -3,7 +3,7 @@ // ListSpeciesCmd.h: // //////////////////////////////////////////////////////////////////////////////// -// $Id: ListSpeciesCmd.h,v 1.1 2003-03-27 22:05:59 fgygi Exp $ +// $Id: ListSpeciesCmd.h,v 1.2 2007-10-19 16:24:04 fgygi Exp $ #ifndef LISTSPECIESCMD_H #define LISTSPECIESCMD_H @@ -24,7 +24,7 @@ class ListSpeciesCmd : public Cmd char *name(void) const { return "list_species"; } char *help_msg(void) const { - return + return "\n list_species\n\n" " syntax: list_species\n\n" " The list_species command prints a list of all defined species.\n\n"; diff --git a/src/LoadCmd.C b/src/LoadCmd.C index 39e5d74..36c8dab 100644 --- a/src/LoadCmd.C +++ b/src/LoadCmd.C @@ -3,7 +3,7 @@ // LoadCmd.C // //////////////////////////////////////////////////////////////////////////////// -// $Id: LoadCmd.C,v 1.7 2005-04-29 18:12:37 fgygi Exp $ +// $Id: LoadCmd.C,v 1.8 2007-10-19 16:24:04 fgygi Exp $ #include "LoadCmd.h" #include "SampleReader.h" @@ -18,10 +18,10 @@ int LoadCmd::action(int argc, char **argv) cout << " " << endl; return 1; } - + int iarg = 1; bool serial = false; - + if ( !strcmp(argv[iarg],"-serial") ) { serial = true; @@ -32,10 +32,10 @@ int LoadCmd::action(int argc, char **argv) cout << " " << endl; SampleReader s_reader(s->ctxt_); - + if ( ui->onpe0() ) cout << " " << endl; - + return 0; } diff --git a/src/LoadCmd.h b/src/LoadCmd.h index 384daea..62fb7c4 100644 --- a/src/LoadCmd.h +++ b/src/LoadCmd.h @@ -3,7 +3,7 @@ // LoadCmd.h: // //////////////////////////////////////////////////////////////////////////////// -// $Id: LoadCmd.h,v 1.2 2003-10-02 17:39:32 fgygi Exp $ +// $Id: LoadCmd.h,v 1.3 2007-10-19 16:24:04 fgygi Exp $ #ifndef LOADCMD_H #define LOADCMD_H @@ -28,7 +28,7 @@ class LoadCmd : public Cmd char *help_msg(void) const { - return + return "\n load\n\n" " syntax: load [-serial] filename \n\n" " The load command loads a sample from the file filename.\n" diff --git a/src/MDIonicStepper.C b/src/MDIonicStepper.C index 1c35ad2..d949bca 100644 --- a/src/MDIonicStepper.C +++ b/src/MDIonicStepper.C @@ -3,7 +3,7 @@ // MDIonicStepper.C // //////////////////////////////////////////////////////////////////////////////// -// $Id: MDIonicStepper.C,v 1.13 2007-03-17 01:22:50 fgygi Exp $ +// $Id: MDIonicStepper.C,v 1.14 2007-10-19 16:24:04 fgygi Exp $ #include "MDIonicStepper.h" using namespace std; @@ -15,7 +15,7 @@ void MDIonicStepper::compute_r(double e0, const vector >& f0) // Compute new positions rp using the velocity Verlet algorithm // enforce constraints for rp // update rm <- r0, r0 <- rp, and update atomset - + // compute rp for ( int is = 0; is < r0_.size(); is++ ) { @@ -25,7 +25,7 @@ void MDIonicStepper::compute_r(double e0, const vector >& f0) rp_[is][i] = r0_[is][i] + v0_[is][i] * dt_ + dt2by2m * f0[is][i]; } } - + constraints_.enforce_r(r0_,rp_); rm_ = r0_; r0_ = rp_; @@ -38,7 +38,7 @@ void MDIonicStepper::compute_v(double e0, const vector >& f0) // compute velocities v0_ using r0_, rm_ and f0(r0) // enforce constraints for vp // adjust velocities with the thermostat - + assert(dt_ != 0.0); for ( int is = 0; is < v0_.size(); is++ ) { @@ -51,7 +51,7 @@ void MDIonicStepper::compute_v(double e0, const vector >& f0) } } compute_ekin(); - + if ( thermostat_ == "SCALING" ) { eta_ = tanh ( ( temp() - th_temp_ ) / th_width_ ) / th_time_; @@ -61,7 +61,7 @@ void MDIonicStepper::compute_v(double e0, const vector >& f0) cout << " " << endl; cout << " " << endl; } - + const double fac = (1.0 - eta_ * fabs(dt_)); for ( int is = 0; is < r0_.size(); is++ ) { @@ -77,29 +77,29 @@ void MDIonicStepper::compute_v(double e0, const vector >& f0) const double boltz = 1.0 / ( 11605.0 * 2.0 * 13.6058 ); for ( int is = 0; is < nsp_; is++ ) { - const double m = pmass_[is]; + const double m = pmass_[is]; const double width = sqrt( boltz * th_temp_ / m ); - for ( int ia = 0; ia < na_[is]; ia++ ) - { + for ( int ia = 0; ia < na_[is]; ia++ ) + { // if th_time is zero, set probability to one - if ( th_time_ == 0.0 || drand48() < fabs(dt_) / th_time_ ) - { - // draw gaussian random variables - double xi0 = drand48() + drand48() + drand48() + - drand48() + drand48() + drand48() + - drand48() + drand48() + drand48() + - drand48() + drand48() + drand48() - 6.0; - double xi1 = drand48() + drand48() + drand48() + - drand48() + drand48() + drand48() + - drand48() + drand48() + drand48() + - drand48() + drand48() + drand48() - 6.0; - double xi2 = drand48() + drand48() + drand48() + - drand48() + drand48() + drand48() + - drand48() + drand48() + drand48() + - drand48() + drand48() + drand48() - 6.0; - v0_[is][3*ia+0] = width * xi0; - v0_[is][3*ia+1] = width * xi1; - v0_[is][3*ia+2] = width * xi2; + if ( th_time_ == 0.0 || drand48() < fabs(dt_) / th_time_ ) + { + // draw gaussian random variables + double xi0 = drand48() + drand48() + drand48() + + drand48() + drand48() + drand48() + + drand48() + drand48() + drand48() + + drand48() + drand48() + drand48() - 6.0; + double xi1 = drand48() + drand48() + drand48() + + drand48() + drand48() + drand48() + + drand48() + drand48() + drand48() + + drand48() + drand48() + drand48() - 6.0; + double xi2 = drand48() + drand48() + drand48() + + drand48() + drand48() + drand48() + + drand48() + drand48() + drand48() + + drand48() + drand48() + drand48() - 6.0; + v0_[is][3*ia+0] = width * xi0; + v0_[is][3*ia+1] = width * xi1; + v0_[is][3*ia+2] = width * xi2; } } } @@ -107,15 +107,15 @@ void MDIonicStepper::compute_v(double e0, const vector >& f0) else if ( thermostat_ == "LOWE" ) { const double boltz = 1.0 / ( 11605.0 * 2.0 * 13.6058 ); - + // scan all atom pairs in the space (is,ia) //int npairs = 0; for ( int is1 = 0; is1 < nsp_; is1++ ) { for ( int is2 = is1; is2 < nsp_; is2++ ) { - const double m1 = pmass_[is1]; - const double m2 = pmass_[is2]; + const double m1 = pmass_[is1]; + const double m2 = pmass_[is2]; const double mu = m1*m2/(m1+m2); const double width = sqrt(boltz * th_temp_ / mu); for ( int ia1 = 0; ia1 < na_[is1]; ia1++ ) @@ -125,9 +125,9 @@ void MDIonicStepper::compute_v(double e0, const vector >& f0) for ( int ia2 = ia2min; ia2 < na_[is2]; ia2++ ) { // if th_time is zero, set probability to one - if ( th_time_ == 0.0 || drand48() < fabs(dt_) / th_time_ ) - { - //cout << " pair " << is1 << " " << ia1 << " " + if ( th_time_ == 0.0 || drand48() < fabs(dt_) / th_time_ ) + { + //cout << " pair " << is1 << " " << ia1 << " " // << is2 << " " << ia2 << endl; D3vector r1(&r0_[is1][3*ia1]); D3vector r2(&r0_[is2][3*ia2]); @@ -146,16 +146,16 @@ void MDIonicStepper::compute_v(double e0, const vector >& f0) D3vector dv12 = mu * ( lambda - v12*e12 ) * e12; D3vector v1p = v1 + (1.0/m1) * dv12; D3vector v2p = v2 - (1.0/m2) * dv12; - + v0_[is1][3*ia1+0] = v1p.x; v0_[is1][3*ia1+1] = v1p.y; v0_[is1][3*ia1+2] = v1p.z; - + v0_[is2][3*ia2+0] = v2p.x; v0_[is2][3*ia2+1] = v2p.y; - v0_[is2][3*ia2+2] = v2p.z; + v0_[is2][3*ia2+2] = v2p.z; } - //npairs++; + //npairs++; } } } diff --git a/src/MDIonicStepper.h b/src/MDIonicStepper.h index f9378c7..23d0490 100644 --- a/src/MDIonicStepper.h +++ b/src/MDIonicStepper.h @@ -3,7 +3,7 @@ // MDIonicStepper.h: // //////////////////////////////////////////////////////////////////////////////// -// $Id: MDIonicStepper.h,v 1.9 2007-03-17 01:14:00 fgygi Exp $ +// $Id: MDIonicStepper.h,v 1.10 2007-10-19 16:24:04 fgygi Exp $ // // IonicStepper is used in the following way @@ -42,7 +42,7 @@ class MDIonicStepper : public IonicStepper { private: - + double th_temp_; double th_time_; double th_width_; @@ -52,7 +52,7 @@ class MDIonicStepper : public IonicStepper void compute_ekin(void); public: - + MDIonicStepper(Sample& s) : IonicStepper(s) { thermostat_ = s.ctrl.thermostat; diff --git a/src/MDWavefunctionStepper.C b/src/MDWavefunctionStepper.C index 3e8c1e6..cdb2d2b 100644 --- a/src/MDWavefunctionStepper.C +++ b/src/MDWavefunctionStepper.C @@ -3,7 +3,7 @@ // MDWavefunctionStepper.C // //////////////////////////////////////////////////////////////////////////////// -// $Id: MDWavefunctionStepper.C,v 1.7 2007-01-27 23:46:31 fgygi Exp $ +// $Id: MDWavefunctionStepper.C,v 1.8 2007-10-19 16:24:04 fgygi Exp $ #include "MDWavefunctionStepper.h" #include "Wavefunction.h" @@ -13,8 +13,8 @@ using namespace std; //////////////////////////////////////////////////////////////////////////////// -MDWavefunctionStepper::MDWavefunctionStepper(Wavefunction& wf, - Wavefunction *wfv, double dt, double dt2bye, TimerMap& tmap) : +MDWavefunctionStepper::MDWavefunctionStepper(Wavefunction& wf, + Wavefunction *wfv, double dt, double dt2bye, TimerMap& tmap) : wfv_(wfv), dt_(dt), dt2bye_(dt2bye), WavefunctionStepper(wf,tmap) { assert(wfv!=0); @@ -62,7 +62,7 @@ void MDWavefunctionStepper::update(Wavefunction& dwf) const double dctmp1 = dc[2*i+1]; const double cptmp = 2.0*ctmp - cmtmp - dt2bye_ * dctmp; const double cptmp1= 2.0*ctmp1 - cmtmp1 - dt2bye_ * dctmp1; - + c[2*i] = cptmp; c[2*i+1] = cptmp1; cm[2*i] = ctmp; @@ -70,7 +70,7 @@ void MDWavefunctionStepper::update(Wavefunction& dwf) } } tmap_["md_update_wf"].stop(); - + tmap_["riccati"].start(); wf_.sd(ispin,ikp)->riccati(*(wfv_->sd(ispin,ikp))); tmap_["riccati"].stop(); @@ -87,7 +87,7 @@ void MDWavefunctionStepper::compute_wfm(Wavefunction& dwf) { // Compute wfm for first MD step using wf, wfv and dwf (= Hpsi) // Replace then wfv by wfm - + // Compute cm using c and wavefunction velocity // cm = c - dt * v - 0.5 * dt2/m * hpsi // replace wfv by wfm @@ -101,7 +101,7 @@ void MDWavefunctionStepper::compute_wfm(Wavefunction& dwf) if ( wf_.sdcontext(ispin,ikp)->active() ) { SlaterDet* sd = wf_.sd(ispin,ikp); - + double* cptr = (double*) sd->c().valptr(); double* cptrv = (double*) wfv_->sd(ispin,ikp)->c().valptr(); const double* dcptr = @@ -148,7 +148,7 @@ void MDWavefunctionStepper::compute_wfm(Wavefunction& dwf) void MDWavefunctionStepper::compute_wfv(Wavefunction& dwf) { // Compute wfv = (wf - wfm)/dt - 0.5*dtbye*dwf - + assert(dt_!=0.0); for ( int ispin = 0; ispin < wf_.nspin(); ispin++ ) { @@ -160,26 +160,26 @@ void MDWavefunctionStepper::compute_wfv(Wavefunction& dwf) { // compute final velocity wfv // v = ( c - cm ) / dt - 0.5 * dt/m * hpsi - + // Note: At this point, *wfv_ contains wf(t-dt) - + // hpsi must be orthogonal to the subspace spanned by c // compute descent direction H psi - psi (psi^T H psi) - + SlaterDet* sd = wf_.sd(ispin,ikp); if ( sd->basis().real() ) { // proxy real matrices c, cp DoubleMatrix c(sd->c()); DoubleMatrix cp(dwf.sd(ispin,ikp)->c()); - + DoubleMatrix a(c.context(),c.n(),c.n(),c.nb(),c.nb()); - + // factor 2.0 in next line: G and -G a.gemm('t','n',2.0,c,cp,0.0); // rank-1 update correction a.ger(-1.0,c,0,cp,0); - + // cp = cp - c * a cp.gemm('n','n',-1.0,c,a,1.0); } @@ -188,7 +188,7 @@ void MDWavefunctionStepper::compute_wfv(Wavefunction& dwf) // not implemented in the complex case assert(false); } - + const double dt_inv = 1.0/dt_; const double half_dtbye = 0.5 * dt2bye_ / dt_; double* cptr = (double*) sd->c().valptr(); @@ -211,7 +211,7 @@ void MDWavefunctionStepper::compute_wfv(Wavefunction& dwf) const double cmtmp1 = cv[2*i+1]; const double dctmp = dc[2*i]; const double dctmp1 = dc[2*i+1]; - + cv[2*i] = ( ctmp - cmtmp ) * dt_inv - half_dtbye * dctmp; cv[2*i+1] = ( ctmp1 - cmtmp1 ) * dt_inv @@ -270,7 +270,7 @@ double MDWavefunctionStepper::ekin_eh(void) const double ctmp1 = c[2*i+1]; const double cmtmp = cm[2*i]; const double cmtmp1 = cm[2*i+1]; - + tmpsum += (ctmp -cmtmp )*(ctmp -cmtmp ) + (ctmp1-cmtmp1)*(ctmp1-cmtmp1); } diff --git a/src/MLWFTransform.C b/src/MLWFTransform.C index a168bc7..b36560a 100644 --- a/src/MLWFTransform.C +++ b/src/MLWFTransform.C @@ -3,7 +3,7 @@ // MLWFTransform.C // //////////////////////////////////////////////////////////////////////////////// -// $Id: MLWFTransform.C,v 1.2 2007-08-14 04:11:19 fgygi Exp $ +// $Id: MLWFTransform.C,v 1.3 2007-10-19 16:24:04 fgygi Exp $ #include #include @@ -20,7 +20,7 @@ using namespace std; //////////////////////////////////////////////////////////////////////////////// -MLWFTransform::MLWFTransform(const SlaterDet& sd) : sd_(sd), +MLWFTransform::MLWFTransform(const SlaterDet& sd) : sd_(sd), cell_(sd.basis().cell()), ctxt_(sd.context()), bm_(BasisMapping(sd.basis())) { a_.resize(6); @@ -48,8 +48,8 @@ void MLWFTransform::compute_transform(void) { const int maxsweep = 50; const double tol = 1.e-8; - - SlaterDet sdcosx(sd_), sdsinx(sd_), + + SlaterDet sdcosx(sd_), sdsinx(sd_), sdcosy(sd_), sdsiny(sd_), sdcosz(sd_), sdsinz(sd_); const ComplexMatrix& c = sd_.c(); @@ -77,7 +77,7 @@ void MLWFTransform::compute_transform(void) adiag_[i].resize(c.n()); } u_->resize(c.n(), c.n(), c.nb(), c.nb()); - + // loop over all local states const int np0 = bm_.np0(); const int np1 = bm_.np1(); @@ -94,24 +94,24 @@ void MLWFTransform::compute_transform(void) complex* fsy = csiny.valptr(n*c.mloc()); complex* fcz = ccosz.valptr(n*c.mloc()); complex* fsz = csinz.valptr(n*c.mloc()); - + // direction z // map state to array zvec_ bm_.vector_to_zvec(&f[0],&zvec[0]); - + for ( int ivec = 0; ivec < nvec; ivec++ ) { const int ibase = ivec * np2; compute_sincos(np2,&zvec[ibase],&zvec_cos[ibase],&zvec_sin[ibase]); } // map back zvec_cos to sdcos and zvec_sin to sdsin - bm_.zvec_to_vector(&zvec_cos[0],&fcz[0]); + bm_.zvec_to_vector(&zvec_cos[0],&fcz[0]); bm_.zvec_to_vector(&zvec_sin[0],&fsz[0]); - - // x direction - // map zvec to ct + + // x direction + // map zvec to ct bm_.transpose_fwd(&zvec[0],&ct[0]); - + for ( int iz = 0; iz < np2loc; iz++ ) { for ( int iy = 0; iy < np1; iy++ ) @@ -121,14 +121,14 @@ void MLWFTransform::compute_transform(void) } } // transpose back ct_cos to zvec_cos - bm_.transpose_bwd(&ct_cos[0],&zvec_cos[0]); + bm_.transpose_bwd(&ct_cos[0],&zvec_cos[0]); // transpose back ct_sin to zvec_sin - bm_.transpose_bwd(&ct_sin[0],&zvec_sin[0]); - + bm_.transpose_bwd(&ct_sin[0],&zvec_sin[0]); + // map back zvec_cos to sdcos and zvec_sin to sdsin - bm_.zvec_to_vector(&zvec_cos[0],&fcx[0]); + bm_.zvec_to_vector(&zvec_cos[0],&fcx[0]); bm_.zvec_to_vector(&zvec_sin[0],&fsx[0]); - + // y direction vector > c_tmp(np1),ccos_tmp(np1),csin_tmp(np1); int one = 1; @@ -146,65 +146,65 @@ void MLWFTransform::compute_transform(void) } } // transpose back ct_cos to zvec_cos - bm_.transpose_bwd(&ct_cos[0],&zvec_cos[0]); + bm_.transpose_bwd(&ct_cos[0],&zvec_cos[0]); // transpose back ct_sin to zvec_sin - bm_.transpose_bwd(&ct_sin[0],&zvec_sin[0]); - + bm_.transpose_bwd(&ct_sin[0],&zvec_sin[0]); + // map back zvec_cos and zvec_sin - bm_.zvec_to_vector(&zvec_cos[0],&fcy[0]); + bm_.zvec_to_vector(&zvec_cos[0],&fcy[0]); bm_.zvec_to_vector(&zvec_sin[0],&fsy[0]); - } + } - // dot products a_[0] = , a_[1] = - a_[0]->gemm('t','n',2.0,cr,ccx,0.0); - a_[0]->ger(-1.0,cr,0,ccx,0); - a_[1]->gemm('t','n',2.0,cr,csx,0.0); - a_[1]->ger(-1.0,cr,0,csx,0); + // dot products a_[0] = , a_[1] = + a_[0]->gemm('t','n',2.0,cr,ccx,0.0); + a_[0]->ger(-1.0,cr,0,ccx,0); + a_[1]->gemm('t','n',2.0,cr,csx,0.0); + a_[1]->ger(-1.0,cr,0,csx,0); - // dot products a_[2] = , a_[3] = - a_[2]->gemm('t','n',2.0,cr,ccy,0.0); - a_[2]->ger(-1.0,cr,0,ccy,0); - a_[3]->gemm('t','n',2.0,cr,csy,0.0); - a_[3]->ger(-1.0,cr,0,csy,0); + // dot products a_[2] = , a_[3] = + a_[2]->gemm('t','n',2.0,cr,ccy,0.0); + a_[2]->ger(-1.0,cr,0,ccy,0); + a_[3]->gemm('t','n',2.0,cr,csy,0.0); + a_[3]->ger(-1.0,cr,0,csy,0); - // dot products a_[4] = , a_[5] = - a_[4]->gemm('t','n',2.0,cr,ccz,0.0); - a_[4]->ger(-1.0,cr,0,ccz,0); - a_[5]->gemm('t','n',2.0,cr,csz,0.0); - a_[5]->ger(-1.0,cr,0,csz,0); + // dot products a_[4] = , a_[5] = + a_[4]->gemm('t','n',2.0,cr,ccz,0.0); + a_[4]->ger(-1.0,cr,0,ccz,0); + a_[5]->gemm('t','n',2.0,cr,csz,0.0); + a_[5]->ger(-1.0,cr,0,csz,0); int nsweep = jade(maxsweep,tol,a_,*u_,adiag_); } //////////////////////////////////////////////////////////////////////////////// -void MLWFTransform::compute_sincos(const int n, const complex* f, +void MLWFTransform::compute_sincos(const int n, const complex* f, complex* fc, complex* fs) { // fc[i] = 0.5 * ( f[i-1] + f[i+1] ) // fs[i] = (0.5/i) * ( f[i-1] - f[i+1] ) // i = 0 - complex zp = f[n-1]; - complex zm = f[1]; - fc[0] = 0.5 * ( zp + zm ); - complex zdiff = zp - zm; - fs[0] = 0.5 * complex(imag(zdiff),-real(zdiff)); + complex zp = f[n-1]; + complex zm = f[1]; + fc[0] = 0.5 * ( zp + zm ); + complex zdiff = zp - zm; + fs[0] = 0.5 * complex(imag(zdiff),-real(zdiff)); for ( int i = 1; i < n-1; i++ ) { const complex zzp = f[i-1]; const complex zzm = f[i+1]; fc[i] = 0.5 * ( zzp + zzm ); - const complex zzdiff = zzp - zzm; + const complex zzdiff = zzp - zzm; fs[i] = 0.5 * complex(imag(zzdiff),-real(zzdiff)); } // i = n-1 - zp = f[n-2]; - zm = f[0]; + zp = f[n-2]; + zm = f[0]; fc[n-1] = 0.5 * ( zp + zm ); - zdiff = zp - zm; + zdiff = zp - zm; fs[n-1] = 0.5 * complex(imag(zdiff),-real(zdiff)); } - + //////////////////////////////////////////////////////////////////////////////// D3vector MLWFTransform::center(int i) { @@ -223,7 +223,7 @@ D3vector MLWFTransform::center(int i) const double x = t0*cell_.a(0).x + t1*cell_.a(1).x + t2*cell_.a(2).x; const double y = t0*cell_.a(0).y + t1*cell_.a(1).y + t2*cell_.a(2).y; const double z = t0*cell_.a(0).z + t1*cell_.a(1).z + t2*cell_.a(2).z; - + return D3vector(x,y,z); } diff --git a/src/MLWFTransform.h b/src/MLWFTransform.h index 5aab5d5..de730a2 100644 --- a/src/MLWFTransform.h +++ b/src/MLWFTransform.h @@ -3,7 +3,7 @@ // MLWFTransform.h // //////////////////////////////////////////////////////////////////////////////// -// $Id: MLWFTransform.h,v 1.2 2007-08-14 04:11:19 fgygi Exp $ +// $Id: MLWFTransform.h,v 1.3 2007-10-19 16:24:04 fgygi Exp $ #ifndef MLWFTRANSFORM_H #define MLWFTRANSFORM_H @@ -21,18 +21,18 @@ class MLWFTransform private: const SlaterDet& sd_; - const UnitCell& cell_; + const UnitCell& cell_; const Context& ctxt_; BasisMapping bm_; std::vector a_; // cosine and sine matrices DoubleMatrix* u_; // orthogonal transformation std::vector > adiag_; // diagonal elements - + public: - + void compute_transform(void); - void compute_sincos(const int n, const std::complex* f, + void compute_sincos(const int n, const std::complex* f, std::complex* fc, std::complex* fs); void apply_transform(SlaterDet& sd); @@ -43,7 +43,7 @@ class MLWFTransform double spread(void); D3vector center(int i); D3vector dipole(void); - + MLWFTransform(const SlaterDet& sd); ~MLWFTransform(void); }; diff --git a/src/Makefile b/src/Makefile index 7adb913..a2d535e 100644 --- a/src/Makefile +++ b/src/Makefile @@ -1,5 +1,5 @@ #------------------------------------------------------------------------------- -# $Id: Makefile,v 1.45 2007-09-30 04:49:29 fgygi Exp $ +# $Id: Makefile,v 1.46 2007-10-19 16:24:36 fgygi Exp $ #------------------------------------------------------------------------------ # include $(TARGET).mk @@ -50,7 +50,7 @@ CXXFLAGS += -DTARGET='"$(TARGET)"' testSample: testSample.o AtomSet.o Atom.o Species.o \ Wavefunction.o SlaterDet.o \ Basis.o FourierTransform.o Matrix.o Context.o \ - sinft.o spline.o UnitCell.o + sinft.o spline.o UnitCell.o $(LD) $(DFLAGS) -o $@ $^ $(LDFLAGS) testreadSample: testreadSample.o \ Context.o AtomSet.o Atom.o Basis.o SlaterDet.o \ @@ -92,7 +92,7 @@ CXXFLAGS += -DTARGET='"$(TARGET)"' SlaterDet.o Matrix.o UnitCell.o Context.o FourierTransform.o \ Wavefunction.o Species.o Atom.o AtomSet.o StructureFactor.o \ ChargeDensity.o \ - sinft.o spline.o + sinft.o spline.o $(LD) $(DFLAGS) -o $@ $^ $(LDFLAGS) testSlaterDet: testSlaterDet.o SlaterDet.o FourierTransform.o \ Basis.o UnitCell.o Matrix.o Context.o Base64Transcoder.o @@ -106,14 +106,14 @@ CXXFLAGS += -DTARGET='"$(TARGET)"' testXCFunctional: testXCFunctional.o LDAFunctional.o PBEFunctional.o $(LD) $(DFLAGS) -o $@ $^ $(LDFLAGS) #testMatrix: testMatrix.o Matrix.o Context.o pdgetri.o - testMatrix: testMatrix.o Matrix.o Context.o + testMatrix: testMatrix.o Matrix.o Context.o $(LD) $(DFLAGS) -o $@ $^ $(LDFLAGS) testjacobi: testjacobi.o jacobi.o Matrix.o Context.o $(LD) $(DFLAGS) -o $@ $^ $(LDFLAGS) testjade: testjade.o jade.o Matrix.o Context.o $(LD) $(DFLAGS) -o $@ $^ $(LDFLAGS) testFourierTransform: testFourierTransform.o FourierTransform.o \ - Context.o Basis.o UnitCell.o + Context.o Basis.o UnitCell.o $(LD) $(DFLAGS) -o $@ $^ $(LDFLAGS) testFTGrid: testFTGrid.o FTGrid.o BlacsContext.o Basis.o $(LD) $(DFLAGS) -o $@ $^ $(LDFLAGS) @@ -139,10 +139,10 @@ CXXFLAGS += -DTARGET='"$(TARGET)"' $(LD) $(DFLAGS) -o $@ $^ $(LDFLAGS) xmlget: xmlget.o $(LD) -o xmlget xmlget.C -I$(XERCESCDIR)/include \ - -L$(XERCESCDIR)/lib -lxerces-c + -L$(XERCESCDIR)/lib -lxerces-c xmlextract: xmlextract.o $(LD) -o xmlextract xmlextract.C -I$(XERCESCDIR)/include \ - -L$(XERCESCDIR)/lib -lxerces-c + -L$(XERCESCDIR)/lib -lxerces-c testXMLGFPreprocessor: testXMLGFPreprocessor.o XMLGFPreprocessor.o Context.o \ Base64Transcoder.o Matrix.o $(LD) $(DFLAGS) -o $@ $^ $(LDFLAGS) @@ -151,7 +151,7 @@ CXXFLAGS += -DTARGET='"$(TARGET)"' testStepper: testStepper.o AtomSet.o Context.o MDIonicStepper.o \ Wavefunction.o Species.o SlaterDet.o spline.o sinft.o Basis.o Matrix.o \ FourierTransform.o UnitCell.o Atom.o BOSampleStepper.o \ -SampleStepper.o EnergyFunctional.o +SampleStepper.o EnergyFunctional.o $(LD) $(DFLAGS) -o $@ $^ $(LDFLAGS) test_fftw: test_fftw.o $(PLTOBJECTS) $(LD) $(DFLAGS) -o $@ $^ $(LDFLAGS) diff --git a/src/Matrix.C b/src/Matrix.C index 8a5fe38..5285b67 100644 --- a/src/Matrix.C +++ b/src/Matrix.C @@ -3,7 +3,7 @@ // Matrix.C // //////////////////////////////////////////////////////////////////////////////// -// $Id: Matrix.C,v 1.15 2006-03-07 07:06:34 fgygi Exp $ +// $Id: Matrix.C,v 1.16 2007-10-19 16:24:04 fgygi Exp $ #include #include @@ -99,66 +99,66 @@ extern "C" const double*, const int*, const int*, const int*, const double*, const int*, const int*, const int*, const double*, double*, const int*, const int*, const int*); - void pzsymm(const char*, const char*, const int*, const int*, + void pzsymm(const char*, const char*, const int*, const int*, const complex*, const complex*, const int*, const int*, const int*, const complex*, const int*, const int*, const int*, - const complex*, complex*, const int*, const int*, + const complex*, complex*, const int*, const int*, const int*); - void pzhemm(const char*, const char*, const int*, const int*, + void pzhemm(const char*, const char*, const int*, const int*, const complex*, const complex*, const int*, const int*, const int*, const complex*, const int*, const int*, const int*, - const complex*, complex*, const int*, const int*, + const complex*, complex*, const int*, const int*, const int*); - void pdgemm(const char*, const char*, const int*, + void pdgemm(const char*, const char*, const int*, const int*, const int*, const double*, const double*, const int*, const int*, const int*, const double*, const int*, const int*, const int*, const double*, double*, const int*, const int*, const int*); - void pzgemm(const char*, const char*, const int*, + void pzgemm(const char*, const char*, const int*, const int*, const int*, const complex*, const complex*, const int*, const int*, const int*, const complex*, const int*, const int*, const int*, - const complex*, complex*, const int*, const int*, + const complex*, complex*, const int*, const int*, const int*); void pdger(const int*, const int*, const double*, const double*, const int*, const int*, const int*, const int*, const double*, const int*, const int*, const int*, const int*, double*, const int*, const int*, const int*); - void pdsyr(const char*, const int*, + void pdsyr(const char*, const int*, const double*, const double*, const int*, const int*, const int*, const int*, double*, const int*, const int*, const int*); - void pdsyrk(const char*, const char*, const int*, const int*, + void pdsyrk(const char*, const char*, const int*, const int*, const double*, const double*, const int*, const int*, const int*, const double*, double*, const int*, const int*, const int*); - void pzherk(const char*, const char*, const int*, const int*, - const complex*, const complex*, const int*, + void pzherk(const char*, const char*, const int*, const int*, + const complex*, const complex*, const int*, const int*, const int*, - const complex*, complex*, const int*, + const complex*, complex*, const int*, const int*, const int*); void pdtran(const int*,const int*, const double*, const double*, const int*, const int*, const int*, double*, const double*, const int*, const int*, const int*); void pztranc(const int*, const int*, const complex*, const complex*, const int*, const int*, const int*, - complex*, const complex*, const int*, const int*, + complex*, const complex*, const int*, const int*, const int*); - void pdtrmm(const char*, const char*, const char*, const char*, - const int*, const int*, const double*, + void pdtrmm(const char*, const char*, const char*, const char*, + const int*, const int*, const double*, const double*, const int*, const int*, const int*, double*, const int*, const int*, const int*); - void pdtrsm(const char*, const char*, const char*, const char*, - const int*, const int*, const double*, + void pdtrsm(const char*, const char*, const char*, const char*, + const int*, const int*, const double*, const double*, const int*, const int*, const int*, double*, const int*, const int*, const int*); - void pztrsm(const char*, const char*, const char*, const char*, - const int*, const int*, const complex*, + void pztrsm(const char*, const char*, const char*, const char*, + const int*, const int*, const complex*, const complex*, const int*, const int*, const int*, complex*, const int*, const int*, const int*); double pdlatra(const int*,const double*,const int*,const int*,const int*); // SCALAPACK - void pdtrtrs(const char*, const char*, const char*, const int*, const int*, + void pdtrtrs(const char*, const char*, const char*, const int*, const int*, const double*, const int*, const int*, const int*, double*, const int*, const int*, const int*, int*); void pdgemr2d(const int*,const int*, @@ -169,25 +169,25 @@ extern "C" complex*,const int*,const int*,const int*,const int*); void pdpotrf(const char*, const int*, double*, const int*, const int*, const int*, const int*); - void pzpotrf(const char*, const int*, complex*, const int*, + void pzpotrf(const char*, const int*, complex*, const int*, const int*, const int*, const int*); - void pdpotri(const char*, const int*, double*, const int*, + void pdpotri(const char*, const int*, double*, const int*, const int*, const int*, const int*); - void pdpocon(const char*, const int*, const double*, + void pdpocon(const char*, const int*, const double*, const int*, const int*, const int*, const double*, double*, double*, const int*, int*, const int*, int*); - void pdsygst(const int*, const char*, const int*, double*, + void pdsygst(const int*, const char*, const int*, double*, const int*, const int*, const int*, const double*, const int*, const int*, const int*, double*, int*); - void pdsyev(const char*, const char*, const int*, + void pdsyev(const char*, const char*, const int*, double*, const int*, const int*, const int*, double*, double*, const int*, const int*, const int*, double*, const int*, int*); - void pdsyevd(const char*, const char*, const int*, + void pdsyevd(const char*, const char*, const int*, double*, const int*, const int*, const int*, double*, double*, const int*, const int*, const int*, double*, const int*, int*, int*, int*); void pdsyevx(const char* jobz, const char* range, const char* uplo, - const int* n, double* a, const int* ia, const int* ja, + const int* n, double* a, const int* ia, const int* ja, const int* desca, double* vl, double* vu, const int* il, const int* iu, double* abstol, int* nfound, int* nz, double* w, @@ -195,99 +195,99 @@ extern "C" const int* descz, double* work, const int* lwork, int* iwork, const int* liwork, int* ifail, int* icluster, double* gap, int* info); - void pzheev(const char* jobz, const char* uplo, const int* n, - complex* a, const int* ia, const int* ja, + void pzheev(const char* jobz, const char* uplo, const int* n, + complex* a, const int* ia, const int* ja, const int* desca, double* w, complex *z, - const int* iz, const int* jz, const int* descz, + const int* iz, const int* jz, const int* descz, complex* work, const int* lwork, double* rwork, const int* lrwork, int* info); - void pdtrtri(const char*, const char*, const int*, double*, + void pdtrtri(const char*, const char*, const int*, double*, const int*, const int*, const int*, int*); - void pdgetrf(const int* m, const int* n, double* val, + void pdgetrf(const int* m, const int* n, double* val, int* ia, const int* ja, const int* desca, int* ipiv, int* info); - void pdgetri(const int* n, double* val, - const int* ia, const int* ja, int* desca, int* ipiv, + void pdgetri(const int* n, double* val, + const int* ia, const int* ja, int* desca, int* ipiv, double* work, int* lwork, int* iwork, int* liwork, int* info); #endif // BLAS1 void dscal(const int*, const double*, double*, const int*); void zscal(const int*, const complex*, complex*, const int*); void zdscal(const int*, const double*, complex*, const int*); - void daxpy(const int *, const double *, const double *, const int *, + void daxpy(const int *, const double *, const double *, const int *, double *, const int *); - void zaxpy(const int *, const complex *, const complex *, + void zaxpy(const int *, const complex *, const complex *, const int *, complex *, const int *); void dcopy(const int *, const double*, const int *, double*, const int*); - double ddot(const int *, const double *, const int *, + double ddot(const int *, const double *, const int *, const double *, const int *); - complex zdotc(const int *, const complex*, const int *, + complex zdotc(const int *, const complex*, const int *, const complex*, const int *); - complex zdotu(const int *, const complex*, const int *, + complex zdotu(const int *, const complex*, const int *, const complex*, const int *); int idamax(const int *, const double*, const int*); // BLAS3 void dsymm(const char*, const char*, const int*, const int *, - const double*, const double*, const int*, + const double*, const double*, const int*, const double*, const int*, const double*, double*, const int*); void zsymm(const char*, const char*, const int*, const int *, - const complex*, const complex*, const int*, + const complex*, const complex*, const int*, const complex*, const int*, const complex*, complex*, const int*); void zhemm(const char*, const char*, const int*, const int *, - const complex*, const complex*, const int*, + const complex*, const complex*, const int*, const complex*, const int*, const complex*, complex*, const int*); void dgemm(const char*, const char*, const int*, const int *, const int*, - const double*, const double*, const int*, + const double*, const double*, const int*, const double*, const int*, const double*, double*, const int*); void zgemm(const char*, const char*, const int*, const int *, const int*, - const complex*, const complex*, const int*, + const complex*, const complex*, const int*, const complex*, const int*, const complex*, complex*, const int*); - void dger(const int *, const int*, const double *, + void dger(const int *, const int*, const double *, const double *, const int *, const double *, const int *, double*, const int*); - void dsyr(const char*, const int *, const double *, + void dsyr(const char*, const int *, const double *, const double *, const int *, double *, const int *); void dsyrk(const char*, const char*, const int *, const int *, - const double *, const double *, const int *, + const double *, const double *, const int *, const double *, double *, const int *); void zherk(const char* uplo, const char* trans, const int* n, const int* k, - const complex* alpha, const complex* a, - const int* lda, + const complex* alpha, const complex* a, + const int* lda, const complex* beta, complex* c, const int* ldc); - void dtrmm(const char*, const char*, const char*, const char*, - const int*, const int *, const double*, const double*, + void dtrmm(const char*, const char*, const char*, const char*, + const int*, const int *, const double*, const double*, const int*, double*, const int*); - void dtrsm(const char*, const char*, const char*, const char*, - const int*, const int *, const double*, const double*, + void dtrsm(const char*, const char*, const char*, const char*, + const int*, const int *, const double*, const double*, const int*, double*, const int*); - void ztrsm(const char*, const char*, const char*, const char*, - const int*, const int *, const complex*, + void ztrsm(const char*, const char*, const char*, const char*, + const int*, const int *, const complex*, const complex*, const int*, complex*, const int*); // LAPACK - void dtrtrs(const char*, const char*, const char*, - const int*, const int*, const double*, const int*, + void dtrtrs(const char*, const char*, const char*, + const int*, const int*, const double*, const int*, double*, const int*, int*); void dpotrf(const char*, const int*, double*, const int*, int*); void zpotrf(const char*, const int*, complex*, const int*, int*); void dpotri(const char*, const int*, double*, const int*, int*); - void dpocon(const char*, const int *, const double *, const int *, + void dpocon(const char*, const int *, const double *, const int *, const double *, double *, double *, const int *, int *); - void dsygst(const int*, const char*, const int*, + void dsygst(const int*, const char*, const int*, double*, const int*, const double*, const int*, int*); - void dsyev(const char* jobz, const char* uplo, const int* n, double* a, + void dsyev(const char* jobz, const char* uplo, const int* n, double* a, const int *lda, double *w, double*work, const int *lwork, int *info); - void zheev(const char* jobz, const char* uplo, const int *n, + void zheev(const char* jobz, const char* uplo, const int *n, complex* a, const int *lda, double* w, complex* work, const int *lwork, double* rwork, int *info); void dtrtri(const char*, const char*, const int*, double*, const int*, int* ); - void dgetrf(const int* m, const int* n, double* a, const int* lda, + void dgetrf(const int* m, const int* n, double* a, const int* lda, int* ipiv, int*info); - void dgetri(const int* m, double* val, const int* lda, int* ipiv, + void dgetri(const int* m, double* val, const int* lda, int* ipiv, double* work, int* lwork, int* info); } @@ -333,7 +333,7 @@ ComplexMatrix::ComplexMatrix(DoubleMatrix& rhs) : ctxt_(rhs.context()), init_size(new_m,rhs.n(),new_mb,rhs.nb()); val = (complex*) rhs.valptr(); } - + //////////////////////////////////////////////////////////////////////////////// // reference constructor create a proxy for a const DoubleMatrix rhs ComplexMatrix::ComplexMatrix(const DoubleMatrix& rhs) : ctxt_(rhs.context()), @@ -346,7 +346,7 @@ ComplexMatrix::ComplexMatrix(const DoubleMatrix& rhs) : ctxt_(rhs.context()), init_size(new_m,rhs.n(),new_mb,rhs.nb()); val = (complex*) rhs.cvalptr(); } - + //////////////////////////////////////////////////////////////////////////////// void DoubleMatrix::init_size(int m, int n, int mb, int nb) { @@ -379,7 +379,7 @@ void DoubleMatrix::init_size(int m, int n, int mb, int nb) if ( n_ != 0 ) nloc_ = numroc(&n_,&nb_,&mycol_,&isrcproc,&npcol_); size_ = mloc_ * nloc_; - + // set leading dimension of val array to mloc_; lld_ = mloc_; if ( lld_ == 0 ) lld_ = 1; @@ -415,7 +415,7 @@ void DoubleMatrix::init_size(int m, int n, int mb, int nb) desc_[8] = lld_; } - + //////////////////////////////////////////////////////////////////////////////// void ComplexMatrix::init_size(int m, int n, int mb, int nb) { @@ -443,7 +443,7 @@ void ComplexMatrix::init_size(int m, int n, int mb, int nb) int isrcproc=0; mloc_ = 0; nloc_ = 0; - + if ( m_ != 0 ) mloc_ = numroc(&m_,&mb_,&myrow_,&isrcproc,&nprow_); if ( n_ != 0 ) @@ -485,7 +485,7 @@ void ComplexMatrix::init_size(int m, int n, int mb, int nb) desc_[8] = lld_; } - + //////////////////////////////////////////////////////////////////////////////// void DoubleMatrix::clear(void) { @@ -583,17 +583,17 @@ void DoubleMatrix::set(char uplo, double xx) // << " block (" << ll << "," << mm << ")" // << " imin/imax=" << imin << "/" << imax // << " jmin/jmax=" << jmin << "/" << jmax << endl; - + if ((imin <= jmax) && (imax >= jmin)) { // block (ll,mm) holds diagonal elements int idiagmin = max(imin,jmin); int idiagmax = min(imax,jmax); - + // cout << " process (" << myrow_ << "," << mycol_ << ")" // << " holds diagonal elements " << idiagmin << " to " << // idiagmax << " in block (" << ll << "," << mm << ")" << endl; - + for ( int ii = idiagmin; ii <= idiagmax; ii++ ) { // access element (ii,ii) @@ -679,17 +679,17 @@ void ComplexMatrix::set(char uplo, complex xx) // << " block (" << ll << "," << mm << ")" // << " imin/imax=" << imin << "/" << imax // << " jmin/jmax=" << jmin << "/" << jmax << endl; - + if ((imin <= jmax) && (imax >= jmin)) { // block (ll,mm) holds diagonal elements int idiagmin = max(imin,jmin); int idiagmax = min(imax,jmax); - + // cout << " process (" << myrow_ << "," << mycol_ << ")" // << " holds diagonal elements " << idiagmin << " to " << // idiagmax << " in block (" << ll << "," << mm << ")" << endl; - + for ( int ii = idiagmin; ii <= idiagmax; ii++ ) { // access element (ii,ii) @@ -787,7 +787,7 @@ complex ComplexMatrix::dot(const ComplexMatrix &x) const } #ifdef SCALAPACK if ( active_ ) - MPI_Allreduce((double*)&tsum, (double*)&sum, 2, + MPI_Allreduce((double*)&tsum, (double*)&sum, 2, MPI_DOUBLE, MPI_SUM, ctxt_.comm() ); #else sum=tsum; @@ -817,7 +817,7 @@ complex ComplexMatrix::dotu(const ComplexMatrix &x) const } #ifdef SCALAPACK if ( active_ ) - MPI_Allreduce((double*)&tsum, (double*)&sum, 2, + MPI_Allreduce((double*)&tsum, (double*)&sum, 2, MPI_DOUBLE, MPI_SUM, ctxt_.comm() ); #else sum=tsum; @@ -942,12 +942,12 @@ void DoubleMatrix::transpose(double alpha, const DoubleMatrix& a, double beta) { assert(this != &a); assert( ictxt_ == a.ictxt() ); - + if ( active() ) { assert(a.m() == n_); assert(a.n() == m_); - + #ifdef SCALAPACK int ione = 1; pdtran(&m_, &n_, &alpha, @@ -957,7 +957,7 @@ void DoubleMatrix::transpose(double alpha, const DoubleMatrix& a, double beta) scal(beta); for ( int i=0; i alpha, const ComplexMatrix& a, { assert(this != &a); assert( ictxt_ == a.ictxt() ); - + if ( active() ) { assert(a.m() == n_); assert(a.n() == m_); - + #ifdef SCALAPACK int ione = 1; pztranc(&m_, &n_, &alpha, @@ -1001,7 +1001,7 @@ void ComplexMatrix::transpose(complex alpha, const ComplexMatrix& a, scal(beta); for ( int i=0; i alpha, const ComplexMatrix& a) { if ( active() ) @@ -1651,7 +1651,7 @@ void ComplexMatrix::trsm(char side, char uplo, char trans, &alpha, a.val, &ione, &ione, a.desc_, val, &ione, &ione, desc_); #else - ztrsm(&side, &uplo, &trans, &diag, + ztrsm(&side, &uplo, &trans, &diag, &m_, &n_, &alpha, a.val, &a.m_, val, &m_); #endif } @@ -1663,7 +1663,7 @@ void ComplexMatrix::trsm(char side, char uplo, char trans, // and B is an N-by-NRHS matrix. // Output in B. //////////////////////////////////////////////////////////////////////////////// -void DoubleMatrix::trtrs(char uplo, char trans, char diag, +void DoubleMatrix::trtrs(char uplo, char trans, char diag, DoubleMatrix& b) const { int info; @@ -1673,11 +1673,11 @@ void DoubleMatrix::trtrs(char uplo, char trans, char diag, #ifdef SCALAPACK int ione=1; - pdtrtrs(&uplo, &trans, &diag, &m_, &b.n_, + pdtrtrs(&uplo, &trans, &diag, &m_, &b.n_, val, &ione, &ione, desc_, b.val, &ione, &ione, b.desc_, &info); #else - dtrtrs(&uplo, &trans, &diag, &m_, &b.n_, val, &m_, + dtrtrs(&uplo, &trans, &diag, &m_, &b.n_, val, &m_, b.val, &b.m_, &info); #endif if(info!=0) @@ -1693,7 +1693,7 @@ void DoubleMatrix::trtrs(char uplo, char trans, char diag, } //////////////////////////////////////////////////////////////////////////////// -// LU decomposition of a general matrix +// LU decomposition of a general matrix //////////////////////////////////////////////////////////////////////////////// void DoubleMatrix::lu(valarray& ipiv) { @@ -1722,7 +1722,7 @@ void DoubleMatrix::lu(valarray& ipiv) } //////////////////////////////////////////////////////////////////////////////// -// inverse of a general square matrix +// inverse of a general square matrix //////////////////////////////////////////////////////////////////////////////// void DoubleMatrix::inverse(void) { @@ -1757,15 +1757,15 @@ void DoubleMatrix::inverse(void) int liwork = -1; // First call to compute dimensions of work arrays lwork and liwork // dimensions are returned in work[0] and iwork[0]; - pdgetri(&n_, val, &ione, &ione, desc_, &ipiv[0], + pdgetri(&n_, val, &ione, &ione, desc_, &ipiv[0], &work[0], &lwork, &iwork[0], &liwork, &info); lwork = (int) work[0] + 1; liwork = iwork[0]; work.resize(lwork); iwork.resize(liwork); - + // Compute inverse - pdgetri(&n_, val, &ione, &ione, desc_, &ipiv[0], + pdgetri(&n_, val, &ione, &ione, desc_, &ipiv[0], &work[0], &lwork, &iwork[0], &liwork, &info); #else valarray work(1); @@ -1790,7 +1790,7 @@ void DoubleMatrix::inverse(void) //////////////////////////////////////////////////////////////////////////////// // Real Cholesky factorization of a -// symmetric positive definite distributed matrix +// symmetric positive definite distributed matrix //////////////////////////////////////////////////////////////////////////////// void DoubleMatrix::potrf(char uplo) { @@ -1819,7 +1819,7 @@ void DoubleMatrix::potrf(char uplo) //////////////////////////////////////////////////////////////////////////////// // Complex Cholesky factorization of a -// hermitian positive definite distributed matrix +// hermitian positive definite distributed matrix //////////////////////////////////////////////////////////////////////////////// void ComplexMatrix::potrf(char uplo) { @@ -1848,7 +1848,7 @@ void ComplexMatrix::potrf(char uplo) //////////////////////////////////////////////////////////////////////////////// // Compute the inverse of a real symmetric positive definite matrix -// using the Cholesky factorization A = U**T*U or A = L*L**T computed +// using the Cholesky factorization A = U**T*U or A = L*L**T computed // by DoubleMatrix::potrf //////////////////////////////////////////////////////////////////////////////// void DoubleMatrix::potri(char uplo) @@ -1906,7 +1906,7 @@ void DoubleMatrix::trtri(char uplo, char diag) //////////////////////////////////////////////////////////////////////////////// // estimate the reciprocal of the condition number (in the 1-norm) of a -// real symmetric positive definite matrix using the Cholesky factorization +// real symmetric positive definite matrix using the Cholesky factorization // A = U**T*U or A = L*L**T computed by DoubleMatrix::potrf //////////////////////////////////////////////////////////////////////////////// double DoubleMatrix::pocon(char uplo) const @@ -1924,11 +1924,11 @@ double DoubleMatrix::pocon(char uplo) const int liwork=mloc_; double* work=new double[lwork]; int* iwork=new int[liwork]; - pdpocon(&uplo, &m_, val, &ione, &ione, desc_, + pdpocon(&uplo, &m_, val, &ione, &ione, desc_, &anorm, &rcond, work, &lwork, iwork, &liwork, &info); if (info!=0) { - cout << "DoubleMatrix::pocon: lwork=" << lwork + cout << "DoubleMatrix::pocon: lwork=" << lwork << ", but should be at least " << work[0] << endl; cout << "DoubleMatrix::pocon: liwork=" << liwork << ", but should be at least " << iwork[0] << endl; @@ -1963,9 +1963,9 @@ double DoubleMatrix::pocon(char uplo) const void DoubleMatrix::syrk(char uplo, char trans, double alpha, const DoubleMatrix& a, double beta) { - assert( ictxt_ == a.ictxt() ); + assert( ictxt_ == a.ictxt() ); assert( n_ == m_ ); // *this must be a square matrix - + if ( active() ) { int n, k; @@ -1979,7 +1979,7 @@ void DoubleMatrix::syrk(char uplo, char trans, n = m_; k = a.m(); } - + #ifdef SCALAPACK int ione = 1; pdsyrk(&uplo, &trans, &n, &k, &alpha, @@ -1997,12 +1997,12 @@ void DoubleMatrix::syrk(char uplo, char trans, // this = beta * this + alpha * A^H * A (trans=='c') //////////////////////////////////////////////////////////////////////////////// void ComplexMatrix::herk(char uplo, char trans, - complex alpha, const ComplexMatrix& a, + complex alpha, const ComplexMatrix& a, complex beta) { - assert( ictxt_ == a.ictxt() ); + assert( ictxt_ == a.ictxt() ); assert( n_ == m_ ); // *this must be a square matrix - + if ( active() ) { int n, k; @@ -2025,21 +2025,21 @@ void ComplexMatrix::herk(char uplo, char trans, exit(2); #endif } - + #ifdef SCALAPACK int ione = 1; pzherk(&uplo, &trans, &n, &k, &alpha, a.val, &ione, &ione, a.desc_, &beta, val, &ione, &ione, desc_); #else - zherk(&uplo, &trans, &n, &k, &alpha, a.val, &a.m_, + zherk(&uplo, &trans, &n, &k, &alpha, a.val, &a.m_, &beta, val, &m_); #endif } } //////////////////////////////////////////////////////////////////////////////// -// +// // Generate a duplicated matrix from a distributed matrix // //////////////////////////////////////////////////////////////////////////////// @@ -2120,17 +2120,17 @@ void DoubleMatrix::initdiag(const double* const dmat) // << " block (" << ll << "," << mm << ")" // << " imin/imax=" << imin << "/" << imax // << " jmin/jmax=" << jmin << "/" << jmax << endl; - + if ((imin <= jmax) && (imax >= jmin)) { // block (ll,mm) holds diagonal elements int idiagmin = max(imin,jmin); int idiagmax = min(imax,jmax); - + // cout << " process (" << myrow_ << "," << mycol_ << ")" // << " holds diagonal elements " << idiagmin << " to " << // idiagmax << " in block (" << ll << "," << mm << ")" << endl; - + for ( int ii = idiagmin; ii <= idiagmax; ii++ ) { // access element (ii,ii) @@ -2169,7 +2169,7 @@ double DoubleMatrix::trace(void) const // and A (=*this) is overwritten by inv(U**T)*A*inv(U) or inv(L)*A*inv(L**T) // If itype = 2 or 3, the problem is A*B*x = lambda*x or // B*A*x = lambda*x, and *this is overwritten by U*A*U**T or L**T*A*L. -// B must have been previously factorized as U**T*U or L*L**T by +// B must have been previously factorized as U**T*U or L*L**T by // DoubleMatrix::dpotrf. //////////////////////////////////////////////////////////////////////////////// void DoubleMatrix::sygst(int itype, char uplo, const DoubleMatrix& b) @@ -2182,13 +2182,13 @@ void DoubleMatrix::sygst(int itype, char uplo, const DoubleMatrix& b) #ifdef SCALAPACK int ione=1; double scale; - pdsygst(&itype, &uplo, &m_, val, &ione, &ione, desc_, + pdsygst(&itype, &uplo, &m_, val, &ione, &ione, desc_, b.val, &ione, &ione, b.desc_, &scale, &info); #else dsygst(&itype, &uplo, &m_, val, &m_, b.val, &b.m_, &info); #endif if ( info != 0 ) - { + { cout << " Matrix::sygst, info=" << info << endl; #ifdef USE_MPI MPI_Abort(MPI_COMM_WORLD, 2); @@ -2213,27 +2213,27 @@ void DoubleMatrix::syev(char uplo, valarray& w, DoubleMatrix& z) int ione=1; int lwork=-1; double tmpwork; - - pdsyev(&jobz, &uplo, &m_, val, &ione, &ione, desc_, &w[0], - z.val, &ione, &ione, z.desc_, &tmpwork, &lwork, + + pdsyev(&jobz, &uplo, &m_, val, &ione, &ione, desc_, &w[0], + z.val, &ione, &ione, z.desc_, &tmpwork, &lwork, &info); lwork = (int) (tmpwork + 0.1); double* work=new double[lwork]; - pdsyev(&jobz, &uplo, &m_, val, &ione, &ione, desc_, &w[0], - z.val, &ione, &ione, z.desc_, work, &lwork, + pdsyev(&jobz, &uplo, &m_, val, &ione, &ione, desc_, &w[0], + z.val, &ione, &ione, z.desc_, work, &lwork, &info); - + MPI_Bcast(&w[0], m_, MPI_DOUBLE, 0, ctxt_.comm()); #else int lwork=-1; double tmplwork; - + dsyev(&jobz, &uplo, &m_, z.val, &m_, &w[0], &tmplwork, &lwork, &info); - + lwork = (int) tmplwork + 1; double* work = new double[lwork]; - + z = *this; dsyev(&jobz, &uplo, &m_, z.val, &m_, &w[0], work, &lwork, &info); #endif @@ -2267,32 +2267,32 @@ void DoubleMatrix::syevd(char uplo, valarray& w, DoubleMatrix& z) int ione=1; int lwork=-1; double tmpwork; - + int liwork=-1; int tmpiwork; - - pdsyevd(&jobz, &uplo, &m_, val, &ione, &ione, desc_, &w[0], - z.val, &ione, &ione, z.desc_, &tmpwork, &lwork, + + pdsyevd(&jobz, &uplo, &m_, val, &ione, &ione, desc_, &w[0], + z.val, &ione, &ione, z.desc_, &tmpwork, &lwork, &tmpiwork, &liwork, &info); lwork = (int) (tmpwork + 0.1); double* work=new double[lwork]; liwork = tmpiwork; int* iwork = new int[liwork]; - pdsyevd(&jobz, &uplo, &m_, val, &ione, &ione, desc_, &w[0], + pdsyevd(&jobz, &uplo, &m_, val, &ione, &ione, desc_, &w[0], z.val, &ione, &ione, z.desc_, work, &lwork, iwork, &liwork, &info); - + MPI_Bcast(&w[0], m_, MPI_DOUBLE, 0, ctxt_.comm()); delete[] iwork; #else int lwork=-1; double tmplwork; - + dsyev(&jobz, &uplo, &m_, z.val, &m_, &w[0], &tmplwork, &lwork, &info); - + lwork = (int) tmplwork + 1; double* work = new double[lwork]; - + z = *this; dsyev(&jobz, &uplo, &m_, z.val, &m_, &w[0], work, &lwork, &info); #endif @@ -2328,7 +2328,7 @@ void DoubleMatrix::syevx(char uplo, valarray& w, DoubleMatrix& z, int ione=1; int lwork=-1; double tmpwork; - + int liwork=-1; int tmpiwork; valarray ifail(n_); @@ -2339,34 +2339,34 @@ void DoubleMatrix::syevx(char uplo, valarray& w, DoubleMatrix& z, double orfac=-1.0; valarray icluster(2*ctxt_.size()); valarray gap(ctxt_.size()); - - pdsyevx(&jobz, &range, &uplo, &m_, val, &ione, &ione, desc_, + + pdsyevx(&jobz, &range, &uplo, &m_, val, &ione, &ione, desc_, &vl, &vu, &il, &iu, &abstol, &nfound, &nz, &w[0], - &orfac, z.val, &ione, &ione, z.desc_, &tmpwork, &lwork, + &orfac, z.val, &ione, &ione, z.desc_, &tmpwork, &lwork, &tmpiwork, &liwork, &ifail[0], &icluster[0], &gap[0], &info); - + assert(info==0); lwork = (int) (tmpwork + 0.1); double* work=new double[lwork]; liwork = tmpiwork; int* iwork = new int[liwork]; - pdsyevx(&jobz, &range, &uplo, &m_, val, &ione, &ione, desc_, + pdsyevx(&jobz, &range, &uplo, &m_, val, &ione, &ione, desc_, &vl, &vu, &il, &iu, &abstol, &nfound, &nz, &w[0], - &orfac, z.val, &ione, &ione, z.desc_, work, &lwork, + &orfac, z.val, &ione, &ione, z.desc_, work, &lwork, iwork, &liwork, &ifail[0], &icluster[0], &gap[0], &info); - + MPI_Bcast(&w[0], m_, MPI_DOUBLE, 0, ctxt_.comm()); delete[] iwork; #else int lwork=-1; double tmplwork; - + dsyev(&jobz, &uplo, &m_, z.val, &m_, &w[0], &tmplwork, &lwork, &info); - + lwork = (int) tmplwork + 1; double* work = new double[lwork]; - + z = *this; dsyev(&jobz, &uplo, &m_, z.val, &m_, &w[0], work, &lwork, &info); #endif @@ -2402,26 +2402,26 @@ void DoubleMatrix::syev(char uplo, valarray& w) double tmplwork; double *zval = 0; // zval is not referenced since jobz == 'N' int * descz = 0; - - pdsyev(&jobz, &uplo, &m_, val, &ione, &ione, desc_, &w[0], + + pdsyev(&jobz, &uplo, &m_, val, &ione, &ione, desc_, &w[0], zval, &ione, &ione, descz, &tmplwork, &lwork, &info); - + lwork = (int) tmplwork + 1; double* work=new double[lwork]; - - pdsyev(&jobz, &uplo, &m_, val, &ione, &ione, desc_, &w[0], + + pdsyev(&jobz, &uplo, &m_, val, &ione, &ione, desc_, &w[0], zval, &ione, &ione, descz, work, &lwork, &info); - + MPI_Bcast(&w[0], m_, MPI_DOUBLE, 0, ctxt_.comm()); #else int lwork=-1; double tmplwork; - + dsyev(&jobz, &uplo, &m_, val, &m_, &w[0], &tmplwork, &lwork, &info); - + lwork = (int) tmplwork + 1; double* work = new double[lwork]; - + dsyev(&jobz, &uplo, &m_, val, &m_, &w[0], work, &lwork, &info); #endif if ( info != 0 ) @@ -2455,34 +2455,34 @@ void DoubleMatrix::syevd(char uplo, valarray& w) int ione=1; int lwork=-1; double tmpwork; - + int liwork=-1; int tmpiwork; double *zval = 0; // zval is not referenced since jobz == 'N' int * descz = 0; - - pdsyevd(&jobz, &uplo, &m_, val, &ione, &ione, desc_, &w[0], - zval, &ione, &ione, descz, &tmpwork, &lwork, + + pdsyevd(&jobz, &uplo, &m_, val, &ione, &ione, desc_, &w[0], + zval, &ione, &ione, descz, &tmpwork, &lwork, &tmpiwork, &liwork, &info); lwork = (int) (tmpwork + 0.1); double* work=new double[lwork]; liwork = tmpiwork; int* iwork = new int[liwork]; - pdsyevd(&jobz, &uplo, &m_, val, &ione, &ione, desc_, &w[0], + pdsyevd(&jobz, &uplo, &m_, val, &ione, &ione, desc_, &w[0], zval, &ione, &ione, descz, work, &lwork, iwork, &liwork, &info); - + MPI_Bcast(&w[0], m_, MPI_DOUBLE, 0, ctxt_.comm()); delete[] iwork; #else int lwork=-1; double tmplwork; - + dsyev(&jobz, &uplo, &m_, val, &m_, &w[0], &tmplwork, &lwork, &info); - + lwork = (int) tmplwork + 1; double* work = new double[lwork]; - + dsyev(&jobz, &uplo, &m_, val, &m_, &w[0], work, &lwork, &info); #endif if ( info != 0 ) @@ -2515,21 +2515,21 @@ void ComplexMatrix::heev(char uplo, valarray& w, ComplexMatrix& z) int lrwork=-1; complex tmplwork; double tmplrwork; - + // first call to get optimal lwork and lrwork sizes - pzheev(&jobz, &uplo, &n_, val, &ione, &ione, desc_, &w[0], + pzheev(&jobz, &uplo, &n_, val, &ione, &ione, desc_, &w[0], z.val, &ione, &ione, z.desc_, &tmplwork, &lwork, &tmplrwork, &lrwork, &info); - + lwork = (int) real(tmplwork) + 1; complex* work=new complex[lwork]; lrwork = (int) tmplrwork + 1; double* rwork = new double[lrwork]; - - pzheev(&jobz, &uplo, &n_, val, &ione, &ione, desc_, &w[0], + + pzheev(&jobz, &uplo, &n_, val, &ione, &ione, desc_, &w[0], z.val, &ione, &ione, z.desc_, work, &lwork, rwork, &lrwork, &info); - + MPI_Bcast(&w[0], m_, MPI_DOUBLE, 0, ctxt_.comm()); #else // request optimal lwork size @@ -2537,13 +2537,13 @@ void ComplexMatrix::heev(char uplo, valarray& w, ComplexMatrix& z) complex tmplwork; int lrwork = max(1,3*n_-2); double* rwork = new double[lrwork]; - + zheev(&jobz, &uplo, &m_, z.val, &m_, &w[0], &tmplwork, &lwork, rwork, &info); - + lwork = (int) real(tmplwork) + 1; complex* work = new complex[lwork]; - + z=*this; zheev(&jobz, &uplo, &m_, z.val, &m_, &w[0], work, &lwork, rwork, &info); @@ -2582,35 +2582,35 @@ void ComplexMatrix::heev(char uplo, valarray& w) double tmplrwork; complex *zval = 0; int *descz = 0; - + // first call to get optimal lwork and lrwork sizes - pzheev(&jobz, &uplo, &n_, val, &ione, &ione, desc_, &w[0], + pzheev(&jobz, &uplo, &n_, val, &ione, &ione, desc_, &w[0], zval, &ione, &ione, descz, &tmplwork, &lwork, &tmplrwork, &lrwork, &info); lwork = (int) real(tmplwork) + 1; complex* work = new complex[lwork]; lrwork = (int) tmplrwork + 1; double* rwork = new double[lrwork]; - - pzheev(&jobz, &uplo, &n_, val, &ione, &ione, desc_, &w[0], + + pzheev(&jobz, &uplo, &n_, val, &ione, &ione, desc_, &w[0], zval, &ione, &ione, descz, work, &lwork, rwork, &lrwork, &info); - + MPI_Bcast(&w[0], m_, MPI_DOUBLE, 0, ctxt_.comm()); #else // request optimal lwork size int lwork=-1; complex tmplwork; - + int lrwork = max(1,3*n_-2); double* rwork = new double[lrwork]; - + zheev(&jobz, &uplo, &m_, val, &m_, &w[0], &tmplwork, &lwork, rwork, &info); - + lwork = (int) real(tmplwork); complex* work = new complex[lwork]; - + zheev(&jobz, &uplo, &m_, val, &m_, &w[0], work, &lwork, rwork, &info); #endif @@ -2655,7 +2655,7 @@ void DoubleMatrix::print(ostream& os) const { for ( int ii = 0; ii < m_; ii++ ) { - os << "(" << ii << "," << jj+jb*maxbs << ")=" + os << "(" << ii << "," << jj+jb*maxbs << ")=" << t.val[ii+t.mloc()*jj] << endl; } } @@ -2687,7 +2687,7 @@ void ComplexMatrix::print(ostream& os) const { for ( int ii = 0; ii < m_; ii++ ) { - os << "(" << ii << "," << jj+jb*maxbs << ")=" + os << "(" << ii << "," << jj+jb*maxbs << ")=" << t.val[ii+t.mloc()*jj] << endl; } } diff --git a/src/Matrix.h b/src/Matrix.h index db5a623..a88cb43 100644 --- a/src/Matrix.h +++ b/src/Matrix.h @@ -3,7 +3,7 @@ // Matrix.h // //////////////////////////////////////////////////////////////////////////////// -// $Id: Matrix.h,v 1.13 2007-09-30 04:46:35 fgygi Exp $ +// $Id: Matrix.h,v 1.14 2007-10-19 16:24:04 fgygi Exp $ #ifndef MATRIX_H #define MATRIX_H @@ -20,7 +20,7 @@ class ComplexMatrix; class DoubleMatrix { private: - + Context ctxt_; int ictxt_; int lld_; // leading dimension of local matrix @@ -38,7 +38,7 @@ class DoubleMatrix double* val; public: - + double* valptr(int i=0) { return &val[i]; } const double* cvalptr(int i=0) const { return &val[i]; } double& operator[] (int i) { return val[i]; } @@ -58,7 +58,7 @@ class DoubleMatrix double localmemsize(void) const { return (double) mloc_ * (double) nloc_ * sizeof(double); } const int* desc(void) const { return &desc_[0]; } - + // local block size of block (l,m) int mbs(int l) const { @@ -72,46 +72,46 @@ class DoubleMatrix // block, then the size is n_%nb_. Otherwise, it is nb_. return ( (m==nblocks_-1) && ( n_incomplete_ ) ) ? n_%nb_ : nb_; } - + // number of local blocks - int mblocks(void) const { return mblocks_; } + int mblocks(void) const { return mblocks_; } int nblocks(void) const { return nblocks_; } - + // functions to compute local indices from global indices // index of blocks: element (i,j) is at position (x,y) - // in local block (l,m) of process (pr,pc) + // in local block (l,m) of process (pr,pc) int l(int i) const { return i/(nprow_*mb_); } int x(int i) const { return i % mb_; } int pr(int i) const { return (i/mb_) % nprow_; } - + int m(int j) const { return j/(npcol_*nb_); } int y(int j) const { return j % nb_; } int pc(int j) const { return (j/nb_) % npcol_; } - + // global indices: // (i,j) is the global index of element (x,y) of block (l,m) - int i(int l, int x) const { return (l * nprow_ + myrow_) * mb_ + x; } + int i(int l, int x) const { return (l * nprow_ + myrow_) * mb_ + x; } int j(int m, int y) const { return (m * npcol_ + mycol_) * nb_ + y; } int iglobal(int ilocal) const { return mb_*(nprow_*(ilocal/mb_)+myrow_)+ilocal%mb_; } int jglobal(int jlocal) const { return nb_*(npcol_*(jlocal/nb_)+mycol_)+jlocal%nb_; } - + // store element a(ii,jj) (where ii,jj are global indices) // in array val: // int iii = l(ii) * mb_ + x(ii); // int jjj = m(jj) * nb_ + y(jj); // val[iii+mloc_*jjj] = a_ij; - + // active flag: the matrix has elements on this process bool active(void) const { return active_; } - - void init_size(int m, int n, int mb = MATRIX_DEF_BLOCK_SIZE, + + void init_size(int m, int n, int mb = MATRIX_DEF_BLOCK_SIZE, int nb = MATRIX_DEF_BLOCK_SIZE); - - void resize(int m, int n, int mb = MATRIX_DEF_BLOCK_SIZE, + + void resize(int m, int n, int mb = MATRIX_DEF_BLOCK_SIZE, int nb = MATRIX_DEF_BLOCK_SIZE) { const int old_size = size_; @@ -121,22 +121,22 @@ class DoubleMatrix delete[] val; val = new double[size_]; clear(); - } - + } + void print(std::ostream& os) const; - + explicit DoubleMatrix(const Context& ctxt) : ctxt_(ctxt), m_(0), n_(0), mb_(0), nb_(0), size_(0), reference_(false), val(0) {} - + // Construct a DoubleMatrix of dimensions m,n explicit DoubleMatrix(const Context& ctxt, int m, int n, - int mb=MATRIX_DEF_BLOCK_SIZE, + int mb=MATRIX_DEF_BLOCK_SIZE, int nb=MATRIX_DEF_BLOCK_SIZE) : ctxt_(ctxt), m_(0), n_(0), mb_(0), nb_(0), size_(0), reference_(false), val(0) { resize(m,n,mb,nb); } - + // copy constructor: create a separate copy of rhs explicit DoubleMatrix(const DoubleMatrix& rhs) : ctxt_(rhs.context()), reference_(false) @@ -145,23 +145,23 @@ class DoubleMatrix val = new double[size_]; memcpy(val, rhs.val, size_*sizeof(double)); } - + // reference constructor create a proxy for a ComplexMatrix rhs explicit DoubleMatrix(ComplexMatrix& rhs); explicit DoubleMatrix(const ComplexMatrix& rhs); - - ~DoubleMatrix(void) - { + + ~DoubleMatrix(void) + { if ( !reference_ ) delete[] val; } - + DoubleMatrix& operator=(const DoubleMatrix& a); - + DoubleMatrix& operator+=(const DoubleMatrix& a); DoubleMatrix& operator-=(const DoubleMatrix& a); - + DoubleMatrix& operator*=(double a); - + void matgather(double *a, int lda) const; void initdiag(const double* const a); // initialize diagonal from a[] @@ -169,17 +169,17 @@ class DoubleMatrix void set(char uplo, double x); void identity(void); void clear(void); - + double dot(const DoubleMatrix &a) const; void axpy(double alpha, const DoubleMatrix &a); void scal(double alpha); - + double nrm2(void) const; double asum(void) const; double amax(void) const; double trace(void) const; void symmetrize(char uplo); - + // rank-1 update: *this += alpha * x(kx) * (y(ky))^T // where x(kx) is row kx of x, and y(ky) is row ky of y void ger(double alpha, const DoubleMatrix& x, int kx, @@ -188,22 +188,22 @@ class DoubleMatrix // symmetric rank-1 update void syr(char uplo, double alpha, const DoubleMatrix& x, int ix, char rowcol); - + // get submatrix A(ia:ia+m,ja:ja+n) of A void getsub(const DoubleMatrix& a,int m,int n,int ia,int ja); - + // matrix * matrix // this = alpha*op(A)*op(B)+beta*this void gemm(char transa, char transb, double alpha, const DoubleMatrix& a, const DoubleMatrix& b, double beta); - + // symmetric_matrix * matrix // *this = alpha * A * B + beta * this void symm(char side, char uplo, double alpha, const DoubleMatrix& a, const DoubleMatrix& b, double beta); - + // symmetric rank k update // this = beta * this + alpha * A * A^T (trans=='n') // this = beta * this + alpha * A^T * A (trans=='t') @@ -215,50 +215,50 @@ class DoubleMatrix void transpose(double alpha, const DoubleMatrix& a, double beta); void transpose(const DoubleMatrix& a); - void trmm(char side, char uplo, char trans, char diag, + void trmm(char side, char uplo, char trans, char diag, double alpha, const DoubleMatrix& a); - + // solve triangular system - void trsm(char side, char uplo, char trans, char diag, + void trsm(char side, char uplo, char trans, char diag, double alpha, const DoubleMatrix& a); void trtrs(char uplo, char trans, char diag, DoubleMatrix& b) const; - + // Cholesky decomposition of a symmetric matrix void potrf(char uplo); // Inverse of a symmetric matrix from Cholesky factor void potri(char uplo); - + // LU decomposition void lu(std::valarray& ipiv); - + // compute inverse of a square matrix void inverse(void); - + // Inverse of triangular matrix void trtri(char uplo,char diag); - + double pocon(char) const; void sygst(int, char, const DoubleMatrix&); - + // compute eigenvalues and eigenvectors of symmetric matrix *this void syev(char uplo, std::valarray& w, DoubleMatrix& z); - + // compute eigenvalues (only) of symmetric matrix *this void syev(char uplo, std::valarray& w); // compute eigenvalues and eigenvectors of symmetric matrix *this // using the divide and conquer method of Tisseur and Dongarra void syevd(char uplo, std::valarray& w, DoubleMatrix& z); - + // compute eigenvalues (only) of symmetric matrix *this // using the divide and conquer method of Tisseur and Dongarra void syevd(char uplo, std::valarray& w); // compute eigenvalues and eigenvectors of symmetric matrix *this // using the expert driver - void syevx(char uplo, std::valarray& w, DoubleMatrix& z, + void syevx(char uplo, std::valarray& w, DoubleMatrix& z, double abstol); - + // compute eigenvalues (only) of symmetric matrix *this // using the divide and conquer method of Tisseur and Dongarra //void syevx(char uplo, std::valarray& w); @@ -268,7 +268,7 @@ std::ostream& operator << ( std::ostream& os, const DoubleMatrix& a ); class ComplexMatrix { private: - + Context ctxt_; int ictxt_; int lld_; // leading dimension of local matrix @@ -286,7 +286,7 @@ class ComplexMatrix std::complex* val; public: - + std::complex* valptr(int i=0) { return &val[i]; } const std::complex* cvalptr(int i=0) const { return &val[i]; } std::complex& operator[] (int i) { return val[i]; } @@ -302,12 +302,12 @@ class ComplexMatrix int nloc(void) const { return nloc_; } // size of local array int size(void) const { return size_; } // size of local array int localsize(void) const { return mloc_*nloc_; } // local size of val - double memsize(void) const + double memsize(void) const { return (double) m_ * (double) n_ * sizeof(std::complex); } double localmemsize(void) const { return (double) mloc_ * (double) nloc_ * sizeof(std::complex); } const int* desc(void) const { return &desc_[0]; } - + // local block size of block (l,m) int mbs(int l) const { @@ -321,41 +321,41 @@ class ComplexMatrix // block, then the size is n_%nb_. Otherwise, it is nb_. return ( (m==nblocks_-1) && ( n_incomplete_ ) ) ? n_%nb_ : nb_; } - + // number of local blocks - int mblocks(void) const { return mblocks_; } + int mblocks(void) const { return mblocks_; } int nblocks(void) const { return nblocks_; } - + // functions to compute local indices from global indices // index of blocks: element (i,j) is at position (x,y) - // in local block (l,m) of process (pr,pc) + // in local block (l,m) of process (pr,pc) int l(int i) const { return i/(nprow_*mb_); } int x(int i) const { return i % mb_; } int pr(int i) const { return (i/mb_) % nprow_; } - + int m(int j) const { return j/(npcol_*nb_); } int y(int j) const { return j % nb_; } int pc(int j) const { return (j/nb_) % npcol_; } - + // global indices: // (i,j) is the global index of element (x,y) of block (l,m) - int i(int l, int x) const { return (l * nprow_ + myrow_) * mb_ + x; } + int i(int l, int x) const { return (l * nprow_ + myrow_) * mb_ + x; } int j(int m, int y) const { return (m * npcol_ + mycol_) * nb_ + y; } - + // store element a(ii,jj) (where ii,jj are global indices) // in array val: // int iii = l(ii) * mb_ + x(ii); // int jjj = m(jj) * nb_ + y(jj); // val[iii+mloc_*jjj] = a_ij; - + // active flag: the matrix has elements on this process bool active(void) const { return active_; } - - void init_size(int m, int n, int mb = MATRIX_DEF_BLOCK_SIZE, + + void init_size(int m, int n, int mb = MATRIX_DEF_BLOCK_SIZE, int nb = MATRIX_DEF_BLOCK_SIZE); - - void resize(int m, int n, int mb = MATRIX_DEF_BLOCK_SIZE, + + void resize(int m, int n, int mb = MATRIX_DEF_BLOCK_SIZE, int nb = MATRIX_DEF_BLOCK_SIZE) { const int old_size = size_; @@ -364,22 +364,22 @@ class ComplexMatrix delete[] val; val = new std::complex[size_]; clear(); - } - + } + void print(std::ostream& os) const; - + explicit ComplexMatrix(const Context& ctxt) : ctxt_(ctxt), m_(0), n_(0), mb_(0), nb_(0), size_(0), reference_(false), val(0) {} - + // Construct a ComplexMatrix of dimensions m,n explicit ComplexMatrix(const Context& ctxt, int m, int n, - int mb=MATRIX_DEF_BLOCK_SIZE, - int nb=MATRIX_DEF_BLOCK_SIZE) : ctxt_(ctxt), + int mb=MATRIX_DEF_BLOCK_SIZE, + int nb=MATRIX_DEF_BLOCK_SIZE) : ctxt_(ctxt), m_(0), n_(0), mb_(0), nb_(0), size_(0), reference_(false), val(0) { resize(m,n,mb,nb); } - + // copy constructor: create a separate copy of rhs explicit ComplexMatrix(const ComplexMatrix& rhs) : ctxt_(rhs.context()), reference_(false) @@ -388,45 +388,45 @@ class ComplexMatrix val = new std::complex[size_]; memcpy(val, rhs.val, size_*sizeof(std::complex)); } - + // reference constructor: create a proxy for a DoubleMatrix rhs explicit ComplexMatrix(DoubleMatrix& rhs); explicit ComplexMatrix(const DoubleMatrix& rhs); - + ~ComplexMatrix(void) - { + { if ( !reference_ ) delete[] val; } - + ComplexMatrix& operator=(const ComplexMatrix& a); - + ComplexMatrix& operator+=(const ComplexMatrix& a); ComplexMatrix& operator-=(const ComplexMatrix& a); - + ComplexMatrix& operator*=(double a); ComplexMatrix& operator*=(std::complex a); - + void matgather(std::complex *a, int lda) const; - void initdiag(const std::complex* const a); // initialize diagonal + void initdiag(const std::complex* const a); // initialize diagonal void init(const std::complex* const a, int lda); void set(char uplo, std::complex x); void identity(void); void clear(void); - + std::complex dot(const ComplexMatrix &a) const; // tr A^H * A std::complex dotu(const ComplexMatrix &a) const; // tr A^T * A void axpy(std::complex alpha, const ComplexMatrix &a); void axpy(double alpha, const ComplexMatrix &a); void scal(std::complex alpha); void scal(double alpha); - + double nrm2(void) const; double asum(void) const; double amax(void) const; std::complex trace(void) const; void symmetrize(char uplo); - + // rank-1 update: *this += alpha * x(kx) * (y(ky))^T // where x(kx) is row kx of x, and y(ky) is row ky of y void ger(std::complex alpha, const ComplexMatrix& x,int kx, @@ -437,59 +437,59 @@ class ComplexMatrix const ComplexMatrix& y,int ky); // symmetric rank-1 update - void her(char uplo, std::complex alpha, + void her(char uplo, std::complex alpha, const ComplexMatrix& x, int ix, char rowcol); - + // get submatrix A(ia:ia+m,ja:ja+n) of A void getsub(const ComplexMatrix& a, int m, int n, int ia, int ja); - + // matrix * matrix // this = alpha*op(A)*op(B)+beta*this void gemm(char transa, char transb, std::complex alpha, const ComplexMatrix& a, const ComplexMatrix& b, std::complex beta); - + // hermitian_matrix * matrix // *this = alpha * A * B + beta * this void hemm(char side, char uplo, std::complex alpha, const ComplexMatrix& a, const ComplexMatrix& b, std::complex beta); - + // complex_symmetric_matrix * matrix // *this = alpha * A * B + beta * this void symm(char side, char uplo, std::complex alpha, const ComplexMatrix& a, const ComplexMatrix& b, std::complex beta); - + // hermitian rank k update // this = beta * this + alpha * A * A^T (trans=='n') // this = beta * this + alpha * A^T * A (trans=='t') void herk(char uplo, char trans, - std::complex alpha, const ComplexMatrix& a, + std::complex alpha, const ComplexMatrix& a, std::complex beta); // matrix transpose // this = alpha * transpose(A) + beta * this - void transpose(std::complex alpha, const ComplexMatrix& a, + void transpose(std::complex alpha, const ComplexMatrix& a, std::complex beta); void transpose(const ComplexMatrix& a); - void trmm(char side, char uplo, char trans, char diag, + void trmm(char side, char uplo, char trans, char diag, std::complex alpha, const ComplexMatrix& a); - void trsm(char side, char uplo, char trans, char diag, + void trsm(char side, char uplo, char trans, char diag, std::complex alpha, const ComplexMatrix& a); void trtrs(char uplo, char trans, char diag, ComplexMatrix& b) const; - + // Cholesky decomposition of a hermitian matrix void potrf(char uplo); // Inverse of a symmetric matrix from Cholesky factor void potri(char uplo); - + // Inverse of triangular matrix void trtri(char uplo,char diag); - + double pocon(char) const; - + // compute eigenvalues and eigenvectors of hermitian matrix *this void heev(char uplo, std::valarray& w, ComplexMatrix& z); // compute eigenvalues (only) of hermitian matrix *this diff --git a/src/MoveCmd.h b/src/MoveCmd.h index 4354f26..4479b91 100644 --- a/src/MoveCmd.h +++ b/src/MoveCmd.h @@ -3,7 +3,7 @@ // MoveCmd.h: // //////////////////////////////////////////////////////////////////////////////// -// $Id: MoveCmd.h,v 1.1 2005-06-27 22:35:26 fgygi Exp $ +// $Id: MoveCmd.h,v 1.2 2007-10-19 16:24:04 fgygi Exp $ #ifndef MOVECMD_H #define MOVECMD_H @@ -27,7 +27,7 @@ class MoveCmd : public Cmd char *name(void) const { return "move"; } char *help_msg(void) const { - return + return "\n move\n\n" " syntax: move atom_name {to|by} x y z \n\n" " The move command displaces an atom to a new position.\n" @@ -44,7 +44,7 @@ class MoveCmd : public Cmd cout << " use: move atom_name {to|by} x y z " << endl; return 1; } - + const string atom_name = argv[1]; const string mode = argv[2]; const string xs = argv[3]; @@ -65,7 +65,7 @@ class MoveCmd : public Cmd double x = pos.x; double y = pos.y; double z = pos.z; - + if ( mode == "to" ) { if ( xs != "*" ) @@ -74,14 +74,14 @@ class MoveCmd : public Cmd y = atof(argv[4]); if ( zs != "*" ) z = atof(argv[5]); - pos = D3vector(x,y,z); + pos = D3vector(x,y,z); } else if ( mode == "by" ) { x += atof(argv[3]); y += atof(argv[4]); z += atof(argv[5]); - pos = D3vector(x,y,z); + pos = D3vector(x,y,z); } else { @@ -94,7 +94,7 @@ class MoveCmd : public Cmd if ( ui->onpe0() ) cout << " " << endl; - + return 0; } }; diff --git a/src/Nempty.h b/src/Nempty.h index a6f1a20..0606f8c 100644 --- a/src/Nempty.h +++ b/src/Nempty.h @@ -3,7 +3,7 @@ // Nempty.h // //////////////////////////////////////////////////////////////////////////////// -// $Id: Nempty.h,v 1.2 2005-04-29 18:12:37 fgygi Exp $ +// $Id: Nempty.h,v 1.3 2007-10-19 16:24:04 fgygi Exp $ #ifndef NEMPTY_H #define NEMPTY_H @@ -31,7 +31,7 @@ class Nempty : public Var cout << " nempty takes only one value" << endl; return 1; } - + int v = atoi(argv[1]); if ( v < 0 ) { @@ -45,7 +45,7 @@ class Nempty : public Var { s->wfv->set_nempty(v); } - + return 0; } diff --git a/src/NetCharge.h b/src/NetCharge.h index 3b9e539..826b3d8 100644 --- a/src/NetCharge.h +++ b/src/NetCharge.h @@ -3,7 +3,7 @@ // NetCharge.h // //////////////////////////////////////////////////////////////////////////////// -// $Id: NetCharge.h,v 1.1 2005-04-29 18:13:12 fgygi Exp $ +// $Id: NetCharge.h,v 1.2 2007-10-19 16:24:04 fgygi Exp $ #ifndef NETCHARGE_H #define NETCHARGE_H @@ -31,7 +31,7 @@ class NetCharge : public Var cout << " net_charge takes only one value" << endl; return 1; } - + const int v = atoi(argv[1]); // compute the current netcharge @@ -40,7 +40,7 @@ class NetCharge : public Var const int netcharge_before = s->atoms.nel() - s->wf.nel(); if ( v == netcharge_before ) return 0; - + // set new netcharge to v if ( s->atoms.nel() - v < 0 ) { @@ -49,14 +49,14 @@ class NetCharge : public Var << s->atoms.nel() << " electrons" << endl; return 1; } - + s->wf.set_nel(s->atoms.nel() - v); s->wf.update_occ(0.0); if ( s->wfv != 0 ) { s->wfv->set_nel(s->atoms.nel() - v); } - + return 0; } diff --git a/src/NonLocalPotential.C b/src/NonLocalPotential.C index 28fdf6f..9db61b9 100644 --- a/src/NonLocalPotential.C +++ b/src/NonLocalPotential.C @@ -3,7 +3,7 @@ // NonLocalPotential.C // //////////////////////////////////////////////////////////////////////////////// -// $Id: NonLocalPotential.C,v 1.21 2006-03-07 07:07:43 fgygi Exp $ +// $Id: NonLocalPotential.C,v 1.22 2007-10-19 16:24:04 fgygi Exp $ #include "NonLocalPotential.h" #include "Species.h" @@ -48,9 +48,9 @@ void NonLocalPotential::init(void) const double epsilon = 1.e-4; const int ngwl = basis_.localsize(); - + nsp = atoms_.nsp(); - + lmax.resize(nsp); lloc.resize(nsp); lproj.resize(nsp); @@ -60,19 +60,19 @@ void NonLocalPotential::init(void) wt.resize(nsp); twnl.resize(nsp); dtwnl.resize(nsp); - + nquad.resize(nsp); rquad.resize(nsp); wquad.resize(nsp); - + nspnl = 0; for ( int is = 0; is < nsp; is++ ) { Species *s = atoms_.species_list[is]; - + npr[is] = 0; nprna[is] = 0; - + if ( s->non_local() ) { nspnl++; @@ -80,7 +80,7 @@ void NonLocalPotential::init(void) lmax[is] = s->lmax(); lloc[is] = s->llocal(); nquad[is] = s->nquad(); - + // compute total number of projectors npr[is] // KB potentials have nlm projectors // semilocal potentials have nlm*nquad projectors @@ -93,21 +93,21 @@ void NonLocalPotential::init(void) npr[is] = s->nlm() * nquad[is]; } nprna[is] = npr[is] * na[is]; - + // l value for projector ipr lproj[is].resize(npr[is]); - - twnl[is].resize(npr[is]*ngwl); + + twnl[is].resize(npr[is]*ngwl); dtwnl[is].resize(npr[is]*6*ngwl); - + // quadrature abcissae and weights rquad[is].resize(nquad[is]); wquad[is].resize(nquad[is]); - - enum quadrature_rule_type { TRAPEZOID, MODIF_TRAPEZOID, - TRAPEZOID_WITH_RIGHT_ENDPOINT, + + enum quadrature_rule_type { TRAPEZOID, MODIF_TRAPEZOID, + TRAPEZOID_WITH_RIGHT_ENDPOINT, SIMPSON }; - + const quadrature_rule_type quad_rule = TRAPEZOID; //const quadrature_rule_type quad_rule = MODIF_TRAPEZOID; //const quadrature_rule_type quad_rule = TRAPEZOID_WITH_RIGHT_ENDPOINT; @@ -176,11 +176,11 @@ void NonLocalPotential::init(void) { assert(false); } - + // compute weights wt[is][ipr] wt[is].resize(npr[is]); - - // compute lproj[is][ipr] + + // compute lproj[is][ipr] int ipr_base = 0; for ( int l = 0; l <= lmax[is]; l++ ) { @@ -205,8 +205,8 @@ void NonLocalPotential::init(void) { const double r = rquad[is][iquad]; double v,dv,vl,dvl; - s->dvpsr(l,r,v,dv); - s->dvpsr(lloc[is],r,vl,dvl); + s->dvpsr(l,r,v,dv); + s->dvpsr(lloc[is],r,vl,dvl); // wt[is][iquad+ipr*nquad] for ( int m = 0; m < 2*l+1; m++ ) { @@ -231,14 +231,14 @@ void NonLocalPotential::update_twnl(void) // following a change of cell dimensions // It is assumed that basis_ has been updated // It is assumed that nsp, npr[is], nquad[is] did not change since init - + tmap["update_twnl"].start(); - + const int ngwl = basis_.localsize(); const double pi = M_PI; const double fpi = 4.0 * pi; const double s14pi = sqrt(1.0/fpi); - const double s34pi = sqrt(3.0/fpi); + const double s34pi = sqrt(3.0/fpi); const double s54pi = sqrt(5.0/fpi); const double s20pi = sqrt(20.0*pi); const double s20pi3 = sqrt(20.0*pi/3.0); @@ -250,15 +250,15 @@ void NonLocalPotential::update_twnl(void) const double *g_x = basis_.gx_ptr(0); const double *g_y = basis_.gx_ptr(1); const double *g_z = basis_.gx_ptr(2); - + // compute twnl and dtwnl for ( int is = 0; is < nsp; is++ ) { Species *s = atoms_.species_list[is]; - + int ilm = 0; for ( int l = 0; l <= lmax[is]; l++ ) - { + { if ( l != lloc[is] ) { if ( l == 0 ) @@ -266,12 +266,12 @@ void NonLocalPotential::update_twnl(void) if ( nquad[is] == 0 ) { // Kleinman-Bylander - + // twnl[is][ipr][ig] // ipr = ilm = 0 // index = ig + ngwl*ipr, i.e. index = ig double *t0 = &twnl[is][0]; - + // dtwnl[is][ipr][ij][ngwl] // index = ig + ngwl * ( ij + 6 * ipr ), ipr = 0 // i.e. index = ig + ij * ngwl @@ -287,14 +287,14 @@ void NonLocalPotential::update_twnl(void) s->dvnlg(0,g[ig],v,dv); t0[ig] = s14pi * v; - + const double tgx = g_x[ig]; const double tgy = g_y[ig]; const double tgz = g_z[ig]; const double tgx2 = tgx * tgx; const double tgy2 = tgy * tgy; const double tgz2 = tgz * tgz; - + const double tmp = gi[ig] * s14pi * dv; dt0_xx[ig] = tmp * tgx * tgx; dt0_yy[ig] = tmp * tgy * tgy; @@ -332,10 +332,10 @@ void NonLocalPotential::update_twnl(void) // twnl[is][ipr][l][ig] = 4 pi j_0(Gr_i) r_i Ylm // j_0(Gr) = sin(Gr) / (Gr) == 1.0 // Ylm = s14pi - + // next line: sin(Gr)/(Gr) replaced by 1 t0[ig] = fpi * s14pi * r; - + // dtwnl = fpi s14pi G_i G_j / G (r cos(Gr)/G -sin(Gr)/G^2) // dtwnl = 0.0; dt0_xx[ig] = 0.0; @@ -355,18 +355,18 @@ void NonLocalPotential::update_twnl(void) // Ylm = s14pi const double arg = g[ig] * r; // Note: for G=0, gi[0] = 0 - + const double tgx = g_x[ig]; const double tgy = g_y[ig]; const double tgz = g_z[ig]; const double tgi = gi[ig]; const double tgi2 = tgi * tgi; - + const double ts = sin(arg); const double tc = cos(arg); - + t0[ig] = fpi * s14pi * ts * tgi; - + // dtwnl = fpi s14pi G_i G_j / G (r cos(Gr)/G -sin(Gr)/G^2) const double tmp = fpi * s14pi * tgi2 * (r*tc - ts*tgi); dt0_xx[ig] = tmp * tgx * tgx; @@ -375,7 +375,7 @@ void NonLocalPotential::update_twnl(void) dt0_xy[ig] = tmp * tgx * tgy; dt0_yz[ig] = tmp * tgy * tgz; dt0_xz[ig] = tmp * tgx * tgz; - + } for ( int ig = 1; ig < ngwl; ig++ ) @@ -386,18 +386,18 @@ void NonLocalPotential::update_twnl(void) // Ylm = s14pi const double arg = g[ig] * r; // Note: for G=0, gi[0] = 0 - + const double tgx = g_x[ig]; const double tgy = g_y[ig]; const double tgz = g_z[ig]; const double tgi = gi[ig]; const double tgi2 = tgi * tgi; - + const double ts = sin(arg); const double tc = cos(arg); - + t0[ig] = fpi * s14pi * ts * tgi; - + // dtwnl = fpi s14pi G_i G_j / G (r cos(Gr)/G -sin(Gr)/G^2) const double tmp = fpi * s14pi * tgi2 * (r*tc - ts*tgi); dt0_xx[ig] = tmp * tgx * tgx; @@ -416,7 +416,7 @@ void NonLocalPotential::update_twnl(void) if ( nquad[is] == 0 ) { // Kleinman-Bylander - + // twnl[is][ipr][ig] // ipr = ilm const int ipr1 = ilm; @@ -426,7 +426,7 @@ void NonLocalPotential::update_twnl(void) double *t1 = &twnl[is][ngwl*ipr1]; double *t2 = &twnl[is][ngwl*ipr2]; double *t3 = &twnl[is][ngwl*ipr3]; - + // dtwnl[is][ipr][ij][ngwl] // index = ig + ngwl * ( ij + 6 * ipr ) double *dt1_xx = &dtwnl[is][ngwl*(0+6*ipr1)]; @@ -455,21 +455,21 @@ void NonLocalPotential::update_twnl(void) double v,dv; const double tg = g[ig]; s->dvnlg(l,tg,v,dv); - + const double tgx = g_x[ig]; const double tgy = g_y[ig]; const double tgz = g_z[ig]; const double tgx2 = tgx * tgx; const double tgy2 = tgy * tgy; const double tgz2 = tgz * tgz; - + const double tgi = gi[ig]; const double tgi2 = tgi * tgi; - + const double y1 = s34pi * tgx * tgi; const double y2 = s34pi * tgy * tgi; const double y3 = s34pi * tgz * tgi; - + t1[ig] = y1 * v; t2[ig] = y2 * v; t3[ig] = y3 * v; @@ -482,7 +482,7 @@ void NonLocalPotential::update_twnl(void) dt1_xy[ig] = fac1 * tgx * tgy; dt1_yz[ig] = fac1 * tgy * tgz; dt1_xz[ig] = fac1 * tgx * tgz; - + const double fac2 = - y2 * ( v - tg * dv ) * tgi2; // m=y dt2_xx[ig] = fac2 * tgx2; @@ -491,7 +491,7 @@ void NonLocalPotential::update_twnl(void) dt2_xy[ig] = fac2 * tgx * tgy + v * y1; dt2_yz[ig] = fac2 * tgy * tgz; dt2_xz[ig] = fac2 * tgx * tgz; - + const double fac3 = - y3 * ( v - tg * dv ) * tgi2; // m=z dt3_xx[ig] = fac3 * tgx2; @@ -515,7 +515,7 @@ void NonLocalPotential::update_twnl(void) double *t1 = &twnl[is][ngwl*ipr1]; double *t2 = &twnl[is][ngwl*ipr2]; double *t3 = &twnl[is][ngwl*ipr3]; - + // dtwnl[is][ipr][j][ngwl] // index = ig + ngwl * ( ij + 6 * ipr ) double *dt1_xx = &dtwnl[is][ngwl*(0+6*ipr1)]; @@ -538,7 +538,7 @@ void NonLocalPotential::update_twnl(void) double *dt3_xy = &dtwnl[is][ngwl*(3+6*ipr3)]; double *dt3_yz = &dtwnl[is][ngwl*(4+6*ipr3)]; double *dt3_xz = &dtwnl[is][ngwl*(5+6*ipr3)]; - + const double r = rquad[is][iquad]; for ( int ig = 0; ig < ngwl; ig++ ) { @@ -552,7 +552,7 @@ void NonLocalPotential::update_twnl(void) const double c = cos(z); const double s = sin(z); const double j1 = ( s * zi - c ) * zi; - const double dj1 = + const double dj1 = ( 2.0 * z * c + ( z*z - 2.0 ) * s ) * zi*zi*zi; // v = 4 pi j1(Gr) r v = fpi * j1 * r; @@ -560,21 +560,21 @@ void NonLocalPotential::update_twnl(void) // = 4 pi dj1 r^2 dv = fpi * dj1 * r * r; } - + const double tgx = g_x[ig]; const double tgy = g_y[ig]; const double tgz = g_z[ig]; const double tgx2 = tgx * tgx; const double tgy2 = tgy * tgy; const double tgz2 = tgz * tgz; - + const double tgi = gi[ig]; const double tgi2 = tgi * tgi; - + const double y1 = s34pi * tgx * tgi; const double y2 = s34pi * tgy * tgi; const double y3 = s34pi * tgz * tgi; - + t1[ig] = y1 * v; t2[ig] = y2 * v; t3[ig] = y3 * v; @@ -587,7 +587,7 @@ void NonLocalPotential::update_twnl(void) dt1_xy[ig] = fac1 * tgx * tgy; dt1_yz[ig] = fac1 * tgy * tgz; dt1_xz[ig] = fac1 * tgx * tgz; - + const double fac2 = - y2 * ( v - tg * dv ) * tgi2; // m=y dt2_xx[ig] = fac2 * tgx2; @@ -596,7 +596,7 @@ void NonLocalPotential::update_twnl(void) dt2_xy[ig] = fac2 * tgx * tgy + v * y1; dt2_yz[ig] = fac2 * tgy * tgz; dt2_xz[ig] = fac2 * tgx * tgz; - + const double fac3 = - y3 * ( v - tg * dv ) * tgi2; // m=z dt3_xx[ig] = fac3 * tgx2; @@ -620,13 +620,13 @@ void NonLocalPotential::update_twnl(void) const int ipr6 = ilm+2; const int ipr7 = ilm+3; const int ipr8 = ilm+4; - + double *t4 = &twnl[is][ngwl*ipr4]; double *t5 = &twnl[is][ngwl*ipr5]; double *t6 = &twnl[is][ngwl*ipr6]; double *t7 = &twnl[is][ngwl*ipr7]; double *t8 = &twnl[is][ngwl*ipr8]; - + // dtwnl[is][ipr][ij][ngwl] // index = ig + ngwl * ( ij + 6 * ipr ) double *dt4_xx = &dtwnl[is][ngwl*(0+6*ipr4)]; @@ -642,21 +642,21 @@ void NonLocalPotential::update_twnl(void) double *dt5_xy = &dtwnl[is][ngwl*(3+6*ipr5)]; double *dt5_yz = &dtwnl[is][ngwl*(4+6*ipr5)]; double *dt5_xz = &dtwnl[is][ngwl*(5+6*ipr5)]; - + double *dt6_xx = &dtwnl[is][ngwl*(0+6*ipr6)]; double *dt6_yy = &dtwnl[is][ngwl*(1+6*ipr6)]; double *dt6_zz = &dtwnl[is][ngwl*(2+6*ipr6)]; double *dt6_xy = &dtwnl[is][ngwl*(3+6*ipr6)]; double *dt6_yz = &dtwnl[is][ngwl*(4+6*ipr6)]; double *dt6_xz = &dtwnl[is][ngwl*(5+6*ipr6)]; - + double *dt7_xx = &dtwnl[is][ngwl*(0+6*ipr7)]; double *dt7_yy = &dtwnl[is][ngwl*(1+6*ipr7)]; double *dt7_zz = &dtwnl[is][ngwl*(2+6*ipr7)]; double *dt7_xy = &dtwnl[is][ngwl*(3+6*ipr7)]; double *dt7_yz = &dtwnl[is][ngwl*(4+6*ipr7)]; double *dt7_xz = &dtwnl[is][ngwl*(5+6*ipr7)]; - + double *dt8_xx = &dtwnl[is][ngwl*(0+6*ipr8)]; double *dt8_yy = &dtwnl[is][ngwl*(1+6*ipr8)]; double *dt8_zz = &dtwnl[is][ngwl*(2+6*ipr8)]; @@ -668,58 +668,58 @@ void NonLocalPotential::update_twnl(void) { double v,dv; const double tg = g[ig]; - + s->dvnlg(l,tg,v,dv); - + const double tgx = g_x[ig]; const double tgy = g_y[ig]; const double tgz = g_z[ig]; const double tgx2 = tgx * tgx; const double tgy2 = tgy * tgy; const double tgz2 = tgz * tgz; - + const double tgi = gi[ig]; const double tg2 = tg * tg; const double tgi2 = tgi * tgi; - + const double tgxx = tgx2 * tgi2; const double tgyy = tgy2 * tgi2; const double tgzz = tgz2 * tgi2; const double tgxy = tgx * tgy * tgi2; const double tgyz = tgy * tgz * tgi2; const double tgxz = tgx * tgz * tgi2; - + const double y4 = s54pi * 0.5 * (3.0 * tgzz - 1.0 ); const double y5 = s54pi * 0.5 * s3 * ( tgxx - tgyy ); const double y6 = s54pi * s3 * tgxy; const double y7 = s54pi * s3 * tgyz; const double y8 = s54pi * s3 * tgxz; - + const double y1x = s34pi * tgx * tgi; const double y1y = s34pi * tgy * tgi; const double y1z = s34pi * tgz * tgi; - + const double dx_xx = y1x * tgxx - y1x; const double dx_yy = y1x * tgyy; const double dx_zz = y1x * tgzz; const double dx_xy = y1x * tgxy; const double dx_yz = y1x * tgyz; const double dx_xz = y1x * tgxz; - + const double dy_xx = y1y * tgxx; const double dy_yy = y1y * tgyy - y1y; const double dy_zz = y1y * tgzz; const double dy_xy = y1y * tgxy - y1x; const double dy_yz = y1y * tgyz; const double dy_xz = y1y * tgxz; - + const double dz_xx = y1z * tgxx; const double dz_yy = y1z * tgyy; const double dz_zz = y1z * tgzz - y1z; const double dz_xy = y1z * tgxy; const double dz_yz = y1z * tgyz - y1y; const double dz_xz = y1z * tgxz - y1x; - + t4[ig] = y4 * v; t5[ig] = y5 * v; t6[ig] = y6 * v; @@ -733,7 +733,7 @@ void NonLocalPotential::update_twnl(void) dt4_xy[ig] = -(v * s20pi * dz_xy * y1z - y4 * dv * tg * tgxy); dt4_yz[ig] = -(v * s20pi * dz_yz * y1z - y4 * dv * tg * tgyz); dt4_xz[ig] = -(v * s20pi * dz_xz * y1z - y4 * dv * tg * tgxz); - + // y5 = s54pi sqrt(3)/2 ( x^2 - y^2 ) / r^2 dt5_xx[ig] = -(v * s20pi3 * (y1x * dx_xx - y1y * dy_xx) - y5 * dv * tg * tgxx); dt5_yy[ig] = -(v * s20pi3 * (y1x * dx_yy - y1y * dy_yy) - y5 * dv * tg * tgyy); @@ -757,7 +757,7 @@ void NonLocalPotential::update_twnl(void) dt7_xy[ig] = -(v * s20pi3 * (dy_xy * y1z + y1y * dz_xy) - y7 * dv * tg * tgxy); dt7_yz[ig] = -(v * s20pi3 * (dy_yz * y1z + y1y * dz_yz) - y7 * dv * tg * tgyz); dt7_xz[ig] = -(v * s20pi3 * (dy_xz * y1z + y1y * dz_xz) - y7 * dv * tg * tgxz); - + // y8 = s54pi sqrt(3) z x / r^2 dt8_xx[ig] = -(v * s20pi3 * (dx_xx * y1z + y1x * dz_xx) - y8 * dv * tg * tgxx); dt8_yy[ig] = -(v * s20pi3 * (dx_yy * y1z + y1x * dz_yy) - y8 * dv * tg * tgyy); @@ -780,7 +780,7 @@ void NonLocalPotential::update_twnl(void) const int ipr6 = iquad+nquad[is]*(ilm+2); const int ipr7 = iquad+nquad[is]*(ilm+3); const int ipr8 = iquad+nquad[is]*(ilm+4); - + double *t4 = &twnl[is][ngwl*ipr4]; double *t5 = &twnl[is][ngwl*ipr5]; double *t6 = &twnl[is][ngwl*ipr6]; @@ -802,21 +802,21 @@ void NonLocalPotential::update_twnl(void) double *dt5_xy = &dtwnl[is][ngwl*(3+6*ipr5)]; double *dt5_yz = &dtwnl[is][ngwl*(4+6*ipr5)]; double *dt5_xz = &dtwnl[is][ngwl*(5+6*ipr5)]; - + double *dt6_xx = &dtwnl[is][ngwl*(0+6*ipr6)]; double *dt6_yy = &dtwnl[is][ngwl*(1+6*ipr6)]; double *dt6_zz = &dtwnl[is][ngwl*(2+6*ipr6)]; double *dt6_xy = &dtwnl[is][ngwl*(3+6*ipr6)]; double *dt6_yz = &dtwnl[is][ngwl*(4+6*ipr6)]; double *dt6_xz = &dtwnl[is][ngwl*(5+6*ipr6)]; - + double *dt7_xx = &dtwnl[is][ngwl*(0+6*ipr7)]; double *dt7_yy = &dtwnl[is][ngwl*(1+6*ipr7)]; double *dt7_zz = &dtwnl[is][ngwl*(2+6*ipr7)]; double *dt7_xy = &dtwnl[is][ngwl*(3+6*ipr7)]; double *dt7_yz = &dtwnl[is][ngwl*(4+6*ipr7)]; double *dt7_xz = &dtwnl[is][ngwl*(5+6*ipr7)]; - + double *dt8_xx = &dtwnl[is][ngwl*(0+6*ipr8)]; double *dt8_yy = &dtwnl[is][ngwl*(1+6*ipr8)]; double *dt8_zz = &dtwnl[is][ngwl*(2+6*ipr8)]; @@ -830,7 +830,7 @@ void NonLocalPotential::update_twnl(void) double v = 0.0, dv = 0.0; // j_2(z) = (3/z^3-1/z) sin(z) - 3/z^2 cos(z) // j_2(z) = (1/z)*((3/z^2-1)*sin(z) - (3/z) cos(z) ) - + const double tg = g[ig]; const double z = tg * r; if ( z != 0.0 ) @@ -840,64 +840,64 @@ void NonLocalPotential::update_twnl(void) const double s = sin(z); const double j2 = ((3.0*zi*zi - 1.0) * s - 3.0*zi * c ) * zi; const double z2 = z * z; - const double dj2 = + const double dj2 = ( (4.0 * z2 - 9.0) * s + z*(9.0-z2) * c ) / (z2*z2) ; // v = 4 pi j2(Gr) r v = fpi * j2 * r; // dv = d/dG v = 4 pi dj2(Gr)/d(Gr) d(Gr)/dG r // = 4 pi dj2 r^2 - dv = fpi * dj2 * r * r; + dv = fpi * dj2 * r * r; } - + const double tgx = g_x[ig]; const double tgy = g_y[ig]; const double tgz = g_z[ig]; const double tgx2 = tgx * tgx; const double tgy2 = tgy * tgy; const double tgz2 = tgz * tgz; - + const double tgi = gi[ig]; const double tg2 = tg * tg; const double tgi2 = tgi * tgi; - + const double tgxx = tgx2 * tgi2; const double tgyy = tgy2 * tgi2; const double tgzz = tgz2 * tgi2; const double tgxy = tgx * tgy * tgi2; const double tgyz = tgy * tgz * tgi2; const double tgxz = tgx * tgz * tgi2; - + const double y4 = s54pi * 0.5 * (3.0 * tgzz - 1.0 ); const double y5 = s54pi * 0.5 * s3 * ( tgxx - tgyy ); const double y6 = s54pi * s3 * tgxy; const double y7 = s54pi * s3 * tgyz; const double y8 = s54pi * s3 * tgxz; - + const double y1x = s34pi * tgx * tgi; const double y1y = s34pi * tgy * tgi; const double y1z = s34pi * tgz * tgi; - + const double dx_xx = y1x * tgxx - y1x; const double dx_yy = y1x * tgyy; const double dx_zz = y1x * tgzz; const double dx_xy = y1x * tgxy; const double dx_yz = y1x * tgyz; const double dx_xz = y1x * tgxz; - + const double dy_xx = y1y * tgxx; const double dy_yy = y1y * tgyy - y1y; const double dy_zz = y1y * tgzz; const double dy_xy = y1y * tgxy - y1x; const double dy_yz = y1y * tgyz; const double dy_xz = y1y * tgxz; - + const double dz_xx = y1z * tgxx; const double dz_yy = y1z * tgyy; const double dz_zz = y1z * tgzz - y1z; const double dz_xy = y1z * tgxy; const double dz_yz = y1z * tgyz - y1y; const double dz_xz = y1z * tgxz - y1x; - + t4[ig] = y4 * v; t5[ig] = y5 * v; t6[ig] = y6 * v; @@ -911,7 +911,7 @@ void NonLocalPotential::update_twnl(void) dt4_xy[ig] = -(v * s20pi * dz_xy * y1z - y4 * dv * tg * tgxy); dt4_yz[ig] = -(v * s20pi * dz_yz * y1z - y4 * dv * tg * tgyz); dt4_xz[ig] = -(v * s20pi * dz_xz * y1z - y4 * dv * tg * tgxz); - + // y5 = s54pi sqrt(3)/2 ( x^2 - y^2 ) / r^2 dt5_xx[ig] = -(v * s20pi3 * (y1x * dx_xx - y1y * dy_xx) - y5 * dv * tg * tgxx); dt5_yy[ig] = -(v * s20pi3 * (y1x * dx_yy - y1y * dy_yy) - y5 * dv * tg * tgyy); @@ -935,7 +935,7 @@ void NonLocalPotential::update_twnl(void) dt7_xy[ig] = -(v * s20pi3 * (dy_xy * y1z + y1y * dz_xy) - y7 * dv * tg * tgxy); dt7_yz[ig] = -(v * s20pi3 * (dy_yz * y1z + y1y * dz_yz) - y7 * dv * tg * tgyz); dt7_xz[ig] = -(v * s20pi3 * (dy_xz * y1z + y1y * dz_xz) - y7 * dv * tg * tgxz); - + // y8 = s54pi sqrt(3) z x / r^2 dt8_xx[ig] = -(v * s20pi3 * (dx_xx * y1z + y1x * dz_xx) - y8 * dv * tg * tgxx); dt8_yy[ig] = -(v * s20pi3 * (dx_yy * y1z + y1x * dz_yy) - y8 * dv * tg * tgyy); @@ -960,8 +960,8 @@ void NonLocalPotential::update_twnl(void) } //////////////////////////////////////////////////////////////////////////////// -double NonLocalPotential::energy(bool compute_hpsi, SlaterDet& dsd, - bool compute_forces, vector >& fion, +double NonLocalPotential::energy(bool compute_hpsi, SlaterDet& dsd, + bool compute_forces, vector >& fion, bool compute_stress, valarray& sigma_enl) { const vector& occ = sd_.occ(); @@ -981,440 +981,440 @@ double NonLocalPotential::energy(bool compute_hpsi, SlaterDet& dsd, const double omega = basis_.cell().volume(); assert(omega != 0.0); const double omega_inv = 1.0 / omega; - - for ( int is = 0; is < nsp; is++ ) - { + + for ( int is = 0; is < nsp; is++ ) + { if ( npr[is] > 0 ) // species is is non-local { - valarray tmpfion(3*na[is]); - tmpfion = 0.0; - // define number of atom blocks - const int na_blocks = na[is] / na_block_size + - ( na[is] % na_block_size == 0 ? 0 : 1 ); - - valarray anl_loc(npr[is]*na_block_size*2*ngwl); - const int nstloc = sd_.nstloc(); - // fnl_loc[ipra][n] - valarray fnl_loc(npr[is]*na_block_size*nstloc); - valarray fnl_buf(npr[is]*na_block_size*nstloc); - for ( int ia_block = 0; ia_block < na_blocks; ia_block++ ) - { - // process projectors of atoms in block ia_block - - const int iastart = ia_block * na_block_size; - const int iaend = (ia_block+1) * na_block_size < na[is] ? - (ia_block+1) * na_block_size : - na[is]; - const int ia_block_size = iaend - iastart; - - // compute cgr[is][ia][ig], sgr[is][ia][ig] - tmap["comp_eigr"].start(); - int k = 3; - double mone = -1.0, zero = 0.0; - char cn='n'; - - // next line: const cast is ok since dgemm_ does not modify argument - double* gx = const_cast(basis_.gx_ptr(0)); - dgemm(&cn,&cn,(int*)&ngwl,(int*)&ia_block_size,&k,&mone, - gx,(int*)&ngwl, &tau[is][3*iastart],&k, - &zero,&gr[0],(int*)&ngwl); - - int len = ia_block_size * ngwl; -#if AIX || BGL - vsincos(&sgr[0],&cgr[0],&gr[0],&len); + valarray tmpfion(3*na[is]); + tmpfion = 0.0; + // define number of atom blocks + const int na_blocks = na[is] / na_block_size + + ( na[is] % na_block_size == 0 ? 0 : 1 ); + + valarray anl_loc(npr[is]*na_block_size*2*ngwl); + const int nstloc = sd_.nstloc(); + // fnl_loc[ipra][n] + valarray fnl_loc(npr[is]*na_block_size*nstloc); + valarray fnl_buf(npr[is]*na_block_size*nstloc); + for ( int ia_block = 0; ia_block < na_blocks; ia_block++ ) + { + // process projectors of atoms in block ia_block + + const int iastart = ia_block * na_block_size; + const int iaend = (ia_block+1) * na_block_size < na[is] ? + (ia_block+1) * na_block_size : + na[is]; + const int ia_block_size = iaend - iastart; + + // compute cgr[is][ia][ig], sgr[is][ia][ig] + tmap["comp_eigr"].start(); + int k = 3; + double mone = -1.0, zero = 0.0; + char cn='n'; + + // next line: const cast is ok since dgemm_ does not modify argument + double* gx = const_cast(basis_.gx_ptr(0)); + dgemm(&cn,&cn,(int*)&ngwl,(int*)&ia_block_size,&k,&mone, + gx,(int*)&ngwl, &tau[is][3*iastart],&k, + &zero,&gr[0],(int*)&ngwl); + + int len = ia_block_size * ngwl; +#if AIX || BGL + vsincos(&sgr[0],&cgr[0],&gr[0],&len); #else - for ( int i = 0; i < len; i++ ) - { - const double arg = gr[i]; - sgr[i] = sin(arg); - cgr[i] = cos(arg); - } + for ( int i = 0; i < len; i++ ) + { + const double arg = gr[i]; + sgr[i] = sin(arg); + cgr[i] = cos(arg); + } #endif - tmap["comp_eigr"].stop(); - - // compute anl_loc - tmap["comp_anl"].start(); - for ( int ipr = 0; ipr < npr[is]; ipr++ ) - { - // twnl[is][ig+ngwl*ipr] - const double * t = &twnl[is][ngwl*ipr]; - const int l = lproj[is][ipr]; - - // anl_loc[ig+ipra*ngwl] - - for ( int ia = 0; ia < ia_block_size; ia++ ) - { - double* a = &anl_loc[2*(ia+ipr*ia_block_size)*ngwl]; - const double* c = &cgr[ia*ngwl]; - const double* s = &sgr[ia*ngwl]; - if ( l == 0 ) - { - for ( int ig = 0; ig < ngwl; ig++ ) - { - a[2*ig] = t[ig] * c[ig]; - a[2*ig+1] = t[ig] * s[ig]; - } - } - else if ( l == 1 ) - { - for ( int ig = 0; ig < ngwl; ig++ ) - { - /* Next line: -i * eigr */ - /* -i * (a+i*b) = b - i*a */ - a[2*ig] = t[ig] * s[ig]; - a[2*ig+1] = -t[ig] * c[ig]; - } - } - else if ( l == 2 ) - { - for ( int ig = 0; ig < ngwl; ig++ ) - { - // Next line: (-) sign for -eigr - a[2*ig] = -t[ig] * c[ig]; - a[2*ig+1] = -t[ig] * s[ig]; - } - } - } - } // ipr - tmap["comp_anl"].stop(); - - // array anl_loc is complete - - // compute fnl[npra][nstloc] = anl^T * c - double one=1.0; - char ct='t'; - int twongwl = 2 * ngwl; - int nprnaloc = ia_block_size * npr[is]; - int c_lda = 2*sd_.c().mloc(); - const complex* c = sd_.c().cvalptr(); - tmap["fnl_gemm"].start(); - dgemm(&ct,&cn,&nprnaloc,(int*)&nstloc,&twongwl,&one, - &anl_loc[0],&twongwl, (double*)c, &c_lda, - &zero,&fnl_loc[0],&nprnaloc); - tmap["fnl_gemm"].stop(); - - // correct for double counting if ctxt_.myrow() == 0 - if ( ctxt_.myrow() == 0 ) - { - // rank-one update - // dger(m,n,alpha,x,incx,y,incy,a,lda); - // a += alpha * x * transpose(y) - // x = first row of anl_loc - // y^T = first row of c - double alpha = -0.5; - dger(&nprnaloc,(int*)&nstloc,&alpha,&anl_loc[0],&twongwl, - (double*)c,&c_lda,&fnl_loc[0],&nprnaloc); - } - + tmap["comp_eigr"].stop(); + + // compute anl_loc + tmap["comp_anl"].start(); + for ( int ipr = 0; ipr < npr[is]; ipr++ ) + { + // twnl[is][ig+ngwl*ipr] + const double * t = &twnl[is][ngwl*ipr]; + const int l = lproj[is][ipr]; + + // anl_loc[ig+ipra*ngwl] + + for ( int ia = 0; ia < ia_block_size; ia++ ) + { + double* a = &anl_loc[2*(ia+ipr*ia_block_size)*ngwl]; + const double* c = &cgr[ia*ngwl]; + const double* s = &sgr[ia*ngwl]; + if ( l == 0 ) + { + for ( int ig = 0; ig < ngwl; ig++ ) + { + a[2*ig] = t[ig] * c[ig]; + a[2*ig+1] = t[ig] * s[ig]; + } + } + else if ( l == 1 ) + { + for ( int ig = 0; ig < ngwl; ig++ ) + { + /* Next line: -i * eigr */ + /* -i * (a+i*b) = b - i*a */ + a[2*ig] = t[ig] * s[ig]; + a[2*ig+1] = -t[ig] * c[ig]; + } + } + else if ( l == 2 ) + { + for ( int ig = 0; ig < ngwl; ig++ ) + { + // Next line: (-) sign for -eigr + a[2*ig] = -t[ig] * c[ig]; + a[2*ig+1] = -t[ig] * s[ig]; + } + } + } + } // ipr + tmap["comp_anl"].stop(); + + // array anl_loc is complete + + // compute fnl[npra][nstloc] = anl^T * c + double one=1.0; + char ct='t'; + int twongwl = 2 * ngwl; + int nprnaloc = ia_block_size * npr[is]; + int c_lda = 2*sd_.c().mloc(); + const complex* c = sd_.c().cvalptr(); + tmap["fnl_gemm"].start(); + dgemm(&ct,&cn,&nprnaloc,(int*)&nstloc,&twongwl,&one, + &anl_loc[0],&twongwl, (double*)c, &c_lda, + &zero,&fnl_loc[0],&nprnaloc); + tmap["fnl_gemm"].stop(); + + // correct for double counting if ctxt_.myrow() == 0 + if ( ctxt_.myrow() == 0 ) + { + // rank-one update + // dger(m,n,alpha,x,incx,y,incy,a,lda); + // a += alpha * x * transpose(y) + // x = first row of anl_loc + // y^T = first row of c + double alpha = -0.5; + dger(&nprnaloc,(int*)&nstloc,&alpha,&anl_loc[0],&twongwl, + (double*)c,&c_lda,&fnl_loc[0],&nprnaloc); + } + #if USE_MPI - tmap["fnl_allreduce"].start(); - // Allreduce fnl partial sum - MPI_Comm basis_comm = basis_.context().comm(); - int fnl_size = nprnaloc*nstloc; - MPI_Allreduce(&fnl_loc[0],&fnl_buf[0],fnl_size, - MPI_DOUBLE,MPI_SUM,basis_comm); - tmap["fnl_allreduce"].stop(); - - // factor 2.0 in next line is: counting G, -G + tmap["fnl_allreduce"].start(); + // Allreduce fnl partial sum + MPI_Comm basis_comm = basis_.context().comm(); + int fnl_size = nprnaloc*nstloc; + MPI_Allreduce(&fnl_loc[0],&fnl_buf[0],fnl_size, + MPI_DOUBLE,MPI_SUM,basis_comm); + tmap["fnl_allreduce"].stop(); + + // factor 2.0 in next line is: counting G, -G fnl_loc = 2.0 * fnl_buf; #else - // factor 2.0 in next line is: counting G, -G + // factor 2.0 in next line is: counting G, -G fnl_loc *= 2.0; #endif - - // accumulate Enl contribution - const int nbase = ctxt_.mycol() * sd_.c().nb(); - for ( int ipr = 0; ipr < npr[is]; ipr++ ) - { - const double fac = wt[is][ipr] * omega_inv; - for ( int n = 0; n < nstloc; n++ ) - { - const double facn = fac * occ[n + nbase]; - for ( int ia = 0; ia < ia_block_size; ia++ ) - { - const int i = ia + ipr*ia_block_size + n * nprnaloc; - //cout << "fnl_loc[ipr=" << ipr << ",ia=" << ia - // << ",n=" << n << "]: " << fnl_loc[i] << endl; - const double tmp = fnl_loc[i]; - enl += facn * tmp * tmp; - fnl_loc[i] = fac * tmp; - } - } - } - - if ( compute_hpsi ) - { - tmap["enl_hpsi"].start(); - // compute cp += anl * fnl - complex* cp = dsd.c().valptr(); - int cp_lda = 2*dsd.c().mloc(); - dgemm(&cn,&cn,&twongwl,(int*)&nstloc,&nprnaloc,&one, - &anl_loc[0],&twongwl, &fnl_loc[0],&nprnaloc, - &one,(double*)cp, &cp_lda); - tmap["enl_hpsi"].stop(); - } - - // ionic forces - if ( compute_forces ) - { - tmap["enl_fion"].start(); - - valarray dfnl_loc(npr[is]*na_block_size*nstloc); - for ( int j = 0; j < 3; j++ ) - { - const double *const gxj = basis_.gx_ptr(j); - - // compute anl_loc - for ( int ipr = 0; ipr < npr[is]; ipr++ ) - { - // twnl[is][ig+ngwl*ipr] - const double * t = &twnl[is][ngwl*ipr]; - const int l = lproj[is][ipr]; - - // anl_loc[ig+ipra*ngwl] - - for ( int ia = 0; ia < ia_block_size; ia++ ) - { - double* a = &anl_loc[2*(ia+ipr*ia_block_size)*ngwl]; - const double* c = &cgr[ia*ngwl]; - const double* s = &sgr[ia*ngwl]; - if ( l == 0 ) - { - for ( int ig = 0; ig < ngwl; ig++ ) - { - const double tt = gxj[ig] * t[ig]; - // Next lines: -i * ( a + ib ) = b - ia - a[2*ig] = tt * s[ig]; - a[2*ig+1] = -tt * c[ig]; - } - } - else if ( l == 1 ) - { - for ( int ig = 0; ig < ngwl; ig++ ) - { - // Next lines: (-i)**2 * ( a + ib ) = - a - ib - const double tt = - gxj[ig] * t[ig]; - a[2*ig] = tt * c[ig]; - a[2*ig+1] = tt * s[ig]; - } - } - else if ( l == 2 ) - { - for ( int ig = 0; ig < ngwl; ig++ ) - { - // Next lines: (-i) * - ( a + ib ) = i*(a+ib) = - b + ia - const double tt = gxj[ig] * t[ig]; - a[2*ig] = -tt * s[ig]; - a[2*ig+1] = tt * c[ig]; - } - } - } - } // ipr - - // array anl_loc is complete - - // compute dfnl - // dfnl.gemm('t','n',2.0,anl,c_proxy,0.0); - // compute dfnl[npra][nstloc] = anl^T * c - double one=1.0; - char ct='t'; - const int twongwl = 2 * ngwl; - const int nprnaloc = ia_block_size * npr[is]; - const complex* c = sd_.c().cvalptr(); - dgemm(&ct,&cn,(int*)&nprnaloc,(int*)&nstloc,(int*)&twongwl,&one, - &anl_loc[0],(int*)&twongwl, (double*)c,(int*)&c_lda, - &zero,&dfnl_loc[0],(int*)&nprnaloc); - - - // Note: no need to correct for double counting of the - // G=0 component which is always zero - - // factor 2.0 in next line is: counting G, -G - dfnl_loc *= 2.0; - - // accumulate non-local contributions to forces - for ( int ipr = 0; ipr < npr[is]; ipr++ ) - { - for ( int n = 0; n < nstloc; n++ ) - { - // Factor 2.0 in next line from derivative of |Fnl|^2 - const double facn = 2.0 * occ[n + nbase]; - for ( int ia = 0; ia < ia_block_size; ia++ ) - { - const int ia_global = ia + iastart; - const int i = ia + ipr*ia_block_size + n * nprnaloc; - //cout << "fnl_loc[ipr=" << ipr << ",ia=" << ia - // << ",n=" << n << "]: " << fnl_loc[i] << endl; - tmpfion[3*ia_global+j] -= facn * - fnl_loc[i] * dfnl_loc[i]; - } - } - } - } // j - - tmap["enl_fion"].stop(); - } // compute_forces - - if ( compute_stress ) - { - tmap["enl_sigma"].start(); - valarray dfnl_loc(npr[is]*na_block_size*nstloc); - - for ( int ij = 0; ij < 6; ij++ ) - { - // compute anl_loc - int ipr = 0; - while ( ipr < npr[is] ) - { - // twnl[is][ig+ngwl*ipr] - const int l = lproj[is][ipr]; - if ( l == 0 ) - { - // dtwnl[is][ipr][ij][ngwl] - // index = ig + ngwl * ( ij + 6 * ipr)) - // ipr = iquad + nquad[is] * ilm, where ilm = 0 - const double *const dt0 = &dtwnl[is][ngwl*(ij+6*ipr)]; - for ( int ia = 0; ia < ia_block_size; ia++ ) - { - double* a0 = &anl_loc[2*(ia+ipr*ia_block_size)*ngwl]; - const double* c = &cgr[ia*ngwl]; - const double* s = &sgr[ia*ngwl]; - for ( int ig = 0; ig < ngwl; ig++ ) - { - const double d0 = dt0[ig]; - // Next lines: -i * ( a + ib ) = b - ia - a0[2*ig] = d0 * c[ig]; - a0[2*ig+1] = d0 * s[ig]; - } - } - } - else if ( l == 1 ) - { - const int ipr1 = ipr; - const int ipr2 = ipr + 1; - const int ipr3 = ipr + 2; - // dtwnl[is][ipr][ij][ngwl] - // index = ig + ngwl * ( ij + 6 * iprx )) - const double *dt1 = &dtwnl[is][ngwl*(ij+6*ipr1)]; - const double *dt2 = &dtwnl[is][ngwl*(ij+6*ipr2)]; - const double *dt3 = &dtwnl[is][ngwl*(ij+6*ipr3)]; - for ( int ia = 0; ia < ia_block_size; ia++ ) - { - double* a1 = &anl_loc[2*(ia+ipr1*ia_block_size)*ngwl]; - double* a2 = &anl_loc[2*(ia+ipr2*ia_block_size)*ngwl]; - double* a3 = &anl_loc[2*(ia+ipr3*ia_block_size)*ngwl]; - const double* c = &cgr[ia*ngwl]; - const double* s = &sgr[ia*ngwl]; - for ( int ig = 0; ig < ngwl; ig++ ) - { - const double d1 = dt1[ig]; - const double d2 = dt2[ig]; - const double d3 = dt3[ig]; - // Next line: (-i)^l factor is -i - // Next line: -i * eigr - // -i * (a+i*b) = b - i*a - const double tc = -c[ig]; // -cosgr[ia][ig] - const double ts = s[ig]; // singr[ia][ig] - a1[2*ig] = d1 * ts; - a1[2*ig+1] = d1 * tc; - a2[2*ig] = d2 * ts; - a2[2*ig+1] = d2 * tc; - a3[2*ig] = d3 * ts; - a3[2*ig+1] = d3 * tc; - } - } - } - else if ( l == 2 ) - { - const int ipr4 = ipr; - const int ipr5 = ipr + 1; - const int ipr6 = ipr + 2; - const int ipr7 = ipr + 3; - const int ipr8 = ipr + 4; - // dtwnl[is][ipr][iquad][ij][ngwl] + + // accumulate Enl contribution + const int nbase = ctxt_.mycol() * sd_.c().nb(); + for ( int ipr = 0; ipr < npr[is]; ipr++ ) + { + const double fac = wt[is][ipr] * omega_inv; + for ( int n = 0; n < nstloc; n++ ) + { + const double facn = fac * occ[n + nbase]; + for ( int ia = 0; ia < ia_block_size; ia++ ) + { + const int i = ia + ipr*ia_block_size + n * nprnaloc; + //cout << "fnl_loc[ipr=" << ipr << ",ia=" << ia + // << ",n=" << n << "]: " << fnl_loc[i] << endl; + const double tmp = fnl_loc[i]; + enl += facn * tmp * tmp; + fnl_loc[i] = fac * tmp; + } + } + } + + if ( compute_hpsi ) + { + tmap["enl_hpsi"].start(); + // compute cp += anl * fnl + complex* cp = dsd.c().valptr(); + int cp_lda = 2*dsd.c().mloc(); + dgemm(&cn,&cn,&twongwl,(int*)&nstloc,&nprnaloc,&one, + &anl_loc[0],&twongwl, &fnl_loc[0],&nprnaloc, + &one,(double*)cp, &cp_lda); + tmap["enl_hpsi"].stop(); + } + + // ionic forces + if ( compute_forces ) + { + tmap["enl_fion"].start(); + + valarray dfnl_loc(npr[is]*na_block_size*nstloc); + for ( int j = 0; j < 3; j++ ) + { + const double *const gxj = basis_.gx_ptr(j); + + // compute anl_loc + for ( int ipr = 0; ipr < npr[is]; ipr++ ) + { + // twnl[is][ig+ngwl*ipr] + const double * t = &twnl[is][ngwl*ipr]; + const int l = lproj[is][ipr]; + + // anl_loc[ig+ipra*ngwl] + + for ( int ia = 0; ia < ia_block_size; ia++ ) + { + double* a = &anl_loc[2*(ia+ipr*ia_block_size)*ngwl]; + const double* c = &cgr[ia*ngwl]; + const double* s = &sgr[ia*ngwl]; + if ( l == 0 ) + { + for ( int ig = 0; ig < ngwl; ig++ ) + { + const double tt = gxj[ig] * t[ig]; + // Next lines: -i * ( a + ib ) = b - ia + a[2*ig] = tt * s[ig]; + a[2*ig+1] = -tt * c[ig]; + } + } + else if ( l == 1 ) + { + for ( int ig = 0; ig < ngwl; ig++ ) + { + // Next lines: (-i)**2 * ( a + ib ) = - a - ib + const double tt = - gxj[ig] * t[ig]; + a[2*ig] = tt * c[ig]; + a[2*ig+1] = tt * s[ig]; + } + } + else if ( l == 2 ) + { + for ( int ig = 0; ig < ngwl; ig++ ) + { + // Next lines: (-i) * - ( a + ib ) = i*(a+ib) = - b + ia + const double tt = gxj[ig] * t[ig]; + a[2*ig] = -tt * s[ig]; + a[2*ig+1] = tt * c[ig]; + } + } + } + } // ipr + + // array anl_loc is complete + + // compute dfnl + // dfnl.gemm('t','n',2.0,anl,c_proxy,0.0); + // compute dfnl[npra][nstloc] = anl^T * c + double one=1.0; + char ct='t'; + const int twongwl = 2 * ngwl; + const int nprnaloc = ia_block_size * npr[is]; + const complex* c = sd_.c().cvalptr(); + dgemm(&ct,&cn,(int*)&nprnaloc,(int*)&nstloc,(int*)&twongwl,&one, + &anl_loc[0],(int*)&twongwl, (double*)c,(int*)&c_lda, + &zero,&dfnl_loc[0],(int*)&nprnaloc); + + + // Note: no need to correct for double counting of the + // G=0 component which is always zero + + // factor 2.0 in next line is: counting G, -G + dfnl_loc *= 2.0; + + // accumulate non-local contributions to forces + for ( int ipr = 0; ipr < npr[is]; ipr++ ) + { + for ( int n = 0; n < nstloc; n++ ) + { + // Factor 2.0 in next line from derivative of |Fnl|^2 + const double facn = 2.0 * occ[n + nbase]; + for ( int ia = 0; ia < ia_block_size; ia++ ) + { + const int ia_global = ia + iastart; + const int i = ia + ipr*ia_block_size + n * nprnaloc; + //cout << "fnl_loc[ipr=" << ipr << ",ia=" << ia + // << ",n=" << n << "]: " << fnl_loc[i] << endl; + tmpfion[3*ia_global+j] -= facn * + fnl_loc[i] * dfnl_loc[i]; + } + } + } + } // j + + tmap["enl_fion"].stop(); + } // compute_forces + + if ( compute_stress ) + { + tmap["enl_sigma"].start(); + valarray dfnl_loc(npr[is]*na_block_size*nstloc); + + for ( int ij = 0; ij < 6; ij++ ) + { + // compute anl_loc + int ipr = 0; + while ( ipr < npr[is] ) + { + // twnl[is][ig+ngwl*ipr] + const int l = lproj[is][ipr]; + if ( l == 0 ) + { + // dtwnl[is][ipr][ij][ngwl] + // index = ig + ngwl * ( ij + 6 * ipr)) + // ipr = iquad + nquad[is] * ilm, where ilm = 0 + const double *const dt0 = &dtwnl[is][ngwl*(ij+6*ipr)]; + for ( int ia = 0; ia < ia_block_size; ia++ ) + { + double* a0 = &anl_loc[2*(ia+ipr*ia_block_size)*ngwl]; + const double* c = &cgr[ia*ngwl]; + const double* s = &sgr[ia*ngwl]; + for ( int ig = 0; ig < ngwl; ig++ ) + { + const double d0 = dt0[ig]; + // Next lines: -i * ( a + ib ) = b - ia + a0[2*ig] = d0 * c[ig]; + a0[2*ig+1] = d0 * s[ig]; + } + } + } + else if ( l == 1 ) + { + const int ipr1 = ipr; + const int ipr2 = ipr + 1; + const int ipr3 = ipr + 2; + // dtwnl[is][ipr][ij][ngwl] + // index = ig + ngwl * ( ij + 6 * iprx )) + const double *dt1 = &dtwnl[is][ngwl*(ij+6*ipr1)]; + const double *dt2 = &dtwnl[is][ngwl*(ij+6*ipr2)]; + const double *dt3 = &dtwnl[is][ngwl*(ij+6*ipr3)]; + for ( int ia = 0; ia < ia_block_size; ia++ ) + { + double* a1 = &anl_loc[2*(ia+ipr1*ia_block_size)*ngwl]; + double* a2 = &anl_loc[2*(ia+ipr2*ia_block_size)*ngwl]; + double* a3 = &anl_loc[2*(ia+ipr3*ia_block_size)*ngwl]; + const double* c = &cgr[ia*ngwl]; + const double* s = &sgr[ia*ngwl]; + for ( int ig = 0; ig < ngwl; ig++ ) + { + const double d1 = dt1[ig]; + const double d2 = dt2[ig]; + const double d3 = dt3[ig]; + // Next line: (-i)^l factor is -i + // Next line: -i * eigr + // -i * (a+i*b) = b - i*a + const double tc = -c[ig]; // -cosgr[ia][ig] + const double ts = s[ig]; // singr[ia][ig] + a1[2*ig] = d1 * ts; + a1[2*ig+1] = d1 * tc; + a2[2*ig] = d2 * ts; + a2[2*ig+1] = d2 * tc; + a3[2*ig] = d3 * ts; + a3[2*ig+1] = d3 * tc; + } + } + } + else if ( l == 2 ) + { + const int ipr4 = ipr; + const int ipr5 = ipr + 1; + const int ipr6 = ipr + 2; + const int ipr7 = ipr + 3; + const int ipr8 = ipr + 4; + // dtwnl[is][ipr][iquad][ij][ngwl] // index = ig + ngwl * ( ij + 6 * ( iquad + nquad[is] * ipr )) - const double *dt4 = &dtwnl[is][ngwl*(ij+6*ipr4)]; - const double *dt5 = &dtwnl[is][ngwl*(ij+6*ipr5)]; - const double *dt6 = &dtwnl[is][ngwl*(ij+6*ipr6)]; - const double *dt7 = &dtwnl[is][ngwl*(ij+6*ipr7)]; - const double *dt8 = &dtwnl[is][ngwl*(ij+6*ipr8)]; - for ( int ia = 0; ia < ia_block_size; ia++ ) - { - double* a4 = &anl_loc[2*(ia+ipr4*ia_block_size)*ngwl]; - double* a5 = &anl_loc[2*(ia+ipr5*ia_block_size)*ngwl]; - double* a6 = &anl_loc[2*(ia+ipr6*ia_block_size)*ngwl]; - double* a7 = &anl_loc[2*(ia+ipr7*ia_block_size)*ngwl]; - double* a8 = &anl_loc[2*(ia+ipr8*ia_block_size)*ngwl]; - const double* c = &cgr[ia*ngwl]; - const double* s = &sgr[ia*ngwl]; - - for ( int ig = 0; ig < ngwl; ig++ ) - { - const double d4 = dt4[ig]; - const double d5 = dt5[ig]; - const double d6 = dt6[ig]; - const double d7 = dt7[ig]; - const double d8 = dt8[ig]; - // Next lines: (-i)^2 * ( a + ib ) = - ( a + ib ) - const double tc = -c[ig]; // -cosgr[ia][ig] - const double ts = -s[ig]; // -singr[ia][ig] - a4[2*ig] = d4 * tc; - a4[2*ig+1] = d4 * ts; - a5[2*ig] = d5 * tc; - a5[2*ig+1] = d5 * ts; - a6[2*ig] = d6 * tc; - a6[2*ig+1] = d6 * ts; - a7[2*ig] = d7 * tc; - a7[2*ig+1] = d7 * ts; - a8[2*ig] = d8 * tc; - a8[2*ig+1] = d8 * ts; - } - } - } - else - { - assert(false); - } // l - ipr += 2*l+1; - } // while ipr - - // array anl_loc is complete - - // compute dfnl - // dfnl.gemm('t','n',2.0,anl,c_proxy,0.0); - // compute dfnl[npra][nstloc] = anl^T * c - double one=1.0; - char ct='t'; - const int twongwl = 2 * ngwl; - const int nprnaloc = ia_block_size * npr[is]; - const complex* c = sd_.c().cvalptr(); - dgemm(&ct,&cn,(int*)&nprnaloc,(int*)&nstloc,(int*)&twongwl,&one, - &anl_loc[0],(int*)&twongwl, (double*)c,(int*)&c_lda, - &zero,&dfnl_loc[0],(int*)&nprnaloc); - - // Note: no need to correct for double counting of the - // G=0 component which is always zero - - // factor 2.0 in next line is: counting G, -G - dfnl_loc *= 2.0; - - // accumulate non-local contributions to sigma_ij - for ( int n = 0; n < nstloc; n++ ) - { - // Factor 2.0 in next line from derivative of |Fnl|^2 - const double facn = 2.0 * occ[n + nbase]; - for ( int ipra = 0; ipra < npr[is]*ia_block_size; ipra++ ) - { - const int i = ipra + n * nprnaloc; - tsum[ij] += facn * fnl_loc[i] * dfnl_loc[i]; - } - } - } // ij - tmap["enl_sigma"].stop(); - } // compute_stress - - } // ia_block - + const double *dt4 = &dtwnl[is][ngwl*(ij+6*ipr4)]; + const double *dt5 = &dtwnl[is][ngwl*(ij+6*ipr5)]; + const double *dt6 = &dtwnl[is][ngwl*(ij+6*ipr6)]; + const double *dt7 = &dtwnl[is][ngwl*(ij+6*ipr7)]; + const double *dt8 = &dtwnl[is][ngwl*(ij+6*ipr8)]; + for ( int ia = 0; ia < ia_block_size; ia++ ) + { + double* a4 = &anl_loc[2*(ia+ipr4*ia_block_size)*ngwl]; + double* a5 = &anl_loc[2*(ia+ipr5*ia_block_size)*ngwl]; + double* a6 = &anl_loc[2*(ia+ipr6*ia_block_size)*ngwl]; + double* a7 = &anl_loc[2*(ia+ipr7*ia_block_size)*ngwl]; + double* a8 = &anl_loc[2*(ia+ipr8*ia_block_size)*ngwl]; + const double* c = &cgr[ia*ngwl]; + const double* s = &sgr[ia*ngwl]; + + for ( int ig = 0; ig < ngwl; ig++ ) + { + const double d4 = dt4[ig]; + const double d5 = dt5[ig]; + const double d6 = dt6[ig]; + const double d7 = dt7[ig]; + const double d8 = dt8[ig]; + // Next lines: (-i)^2 * ( a + ib ) = - ( a + ib ) + const double tc = -c[ig]; // -cosgr[ia][ig] + const double ts = -s[ig]; // -singr[ia][ig] + a4[2*ig] = d4 * tc; + a4[2*ig+1] = d4 * ts; + a5[2*ig] = d5 * tc; + a5[2*ig+1] = d5 * ts; + a6[2*ig] = d6 * tc; + a6[2*ig+1] = d6 * ts; + a7[2*ig] = d7 * tc; + a7[2*ig+1] = d7 * ts; + a8[2*ig] = d8 * tc; + a8[2*ig+1] = d8 * ts; + } + } + } + else + { + assert(false); + } // l + ipr += 2*l+1; + } // while ipr + + // array anl_loc is complete + + // compute dfnl + // dfnl.gemm('t','n',2.0,anl,c_proxy,0.0); + // compute dfnl[npra][nstloc] = anl^T * c + double one=1.0; + char ct='t'; + const int twongwl = 2 * ngwl; + const int nprnaloc = ia_block_size * npr[is]; + const complex* c = sd_.c().cvalptr(); + dgemm(&ct,&cn,(int*)&nprnaloc,(int*)&nstloc,(int*)&twongwl,&one, + &anl_loc[0],(int*)&twongwl, (double*)c,(int*)&c_lda, + &zero,&dfnl_loc[0],(int*)&nprnaloc); + + // Note: no need to correct for double counting of the + // G=0 component which is always zero + + // factor 2.0 in next line is: counting G, -G + dfnl_loc *= 2.0; + + // accumulate non-local contributions to sigma_ij + for ( int n = 0; n < nstloc; n++ ) + { + // Factor 2.0 in next line from derivative of |Fnl|^2 + const double facn = 2.0 * occ[n + nbase]; + for ( int ipra = 0; ipra < npr[is]*ia_block_size; ipra++ ) + { + const int i = ipra + n * nprnaloc; + tsum[ij] += facn * fnl_loc[i] * dfnl_loc[i]; + } + } + } // ij + tmap["enl_sigma"].stop(); + } // compute_stress + + } // ia_block + if ( compute_forces ) { ctxt_.dsum(3*na[is],1,&tmpfion[0],3*na[is]); @@ -1429,7 +1429,7 @@ double NonLocalPotential::energy(bool compute_hpsi, SlaterDet& dsd, } // is // reduction of enl across rows - ctxt_.dsum('r',1,1,&enl,1); + ctxt_.dsum('r',1,1,&enl,1); sigma_enl = 0.0; if ( compute_stress ) diff --git a/src/NonLocalPotential.h b/src/NonLocalPotential.h index aa23ca4..93227a4 100644 --- a/src/NonLocalPotential.h +++ b/src/NonLocalPotential.h @@ -3,7 +3,7 @@ // NonLocalPotential.h // //////////////////////////////////////////////////////////////////////////////// -// $Id: NonLocalPotential.h,v 1.6 2007-03-17 01:14:00 fgygi Exp $ +// $Id: NonLocalPotential.h,v 1.7 2007-10-19 16:24:04 fgygi Exp $ #ifndef NONLOCALPOTENTIAL_H #define NONLOCALPOTENTIAL_H @@ -17,7 +17,7 @@ class NonLocalPotential { private: - + const Context& ctxt_; const AtomSet& atoms_; const SlaterDet& sd_; @@ -25,7 +25,7 @@ class NonLocalPotential int nsp; // number of species int nspnl; // number of non-local species - + std::vector lmax; // lmax[is] std::vector lloc; // lloc[is] std::vector na; // na[is] @@ -35,25 +35,25 @@ class NonLocalPotential std::vector > wt; // wt[is][ipr] std::vector > twnl; // twnl[is][npr*ngwl] std::vector > dtwnl; // dtwnl[is][6*npr*ngwl],ij=0,..,5 - + std::vector nquad; // nquad[is] // rquad[is][iquad], iquad = 0, nquad[is]-1 - std::vector > rquad; + std::vector > rquad; // wquad[is][iquad], iquad = 0, nquad[is]-1 - std::vector > wquad; - + std::vector > wquad; + mutable TimerMap tmap; void init(void); - + public: - - NonLocalPotential(const AtomSet& as, const SlaterDet& sd) : + + NonLocalPotential(const AtomSet& as, const SlaterDet& sd) : ctxt_(sd.context()), atoms_(as), sd_(sd), basis_(sd.basis()) { init(); } ~NonLocalPotential(void); - + void update_twnl(void); - double energy(bool compute_hpsi, SlaterDet& dsd, - bool compute_forces, std::vector >& fion, + double energy(bool compute_hpsi, SlaterDet& dsd, + bool compute_forces, std::vector >& fion, bool compute_stress, std::valarray& sigma_enl); }; #endif diff --git a/src/Nrowmax.h b/src/Nrowmax.h index 8870149..814b9cb 100644 --- a/src/Nrowmax.h +++ b/src/Nrowmax.h @@ -3,7 +3,7 @@ // Nrowmax.h // //////////////////////////////////////////////////////////////////////////////// -// $Id: Nrowmax.h,v 1.2 2004-10-15 18:06:46 fgygi Exp $ +// $Id: Nrowmax.h,v 1.3 2007-10-19 16:24:04 fgygi Exp $ #ifndef NROWMAX_H #define NROWMAX_H @@ -31,7 +31,7 @@ class Nrowmax : public Var cout << " nrowmax takes only one value" << endl; return 1; } - + int v = atoi(argv[1]); if ( v <= 0 ) { @@ -47,7 +47,7 @@ class Nrowmax : public Var s->wfv->set_nrowmax(v); s->wfv->clear(); } - + return 0; } diff --git a/src/PBEFunctional.C b/src/PBEFunctional.C index 1b43add..ff691d0 100644 --- a/src/PBEFunctional.C +++ b/src/PBEFunctional.C @@ -3,7 +3,7 @@ // PBEFunctional.C // //////////////////////////////////////////////////////////////////////////////// -// $Id: PBEFunctional.C,v 1.5 2004-09-14 22:24:11 fgygi Exp $ +// $Id: PBEFunctional.C,v 1.6 2007-10-19 16:24:04 fgygi Exp $ #include "PBEFunctional.h" #include @@ -17,7 +17,7 @@ PBEFunctional::PBEFunctional(const vector > &rhoe) _nspin = rhoe.size(); if ( _nspin > 1 ) assert(rhoe[0].size() == rhoe[1].size()); _np = rhoe[0].size(); - + if ( _nspin == 1 ) { _exc.resize(_np); @@ -50,7 +50,7 @@ PBEFunctional::PBEFunctional(const vector > &rhoe) _grad_rho_dn[0].resize(_np); _grad_rho_dn[1].resize(_np); _grad_rho_dn[2].resize(_np); - + rho_up = &rhoe[0][0]; rho_dn = &rhoe[1][0]; grad_rho_up[0] = &_grad_rho_up[0][0]; @@ -70,7 +70,7 @@ PBEFunctional::PBEFunctional(const vector > &rhoe) } } -void PBEFunctional::setxc(void) +void PBEFunctional::setxc(void) { if ( _np == 0 ) return; if ( _nspin == 1 ) @@ -125,31 +125,31 @@ void PBEFunctional::setxc(void) } //////////////////////////////////////////////////////////////////////////////// -// -// excpbe: PBE exchange-correlation +// +// excpbe: PBE exchange-correlation // K.Burke's modification of PW91 codes, May 14, 1996. // Modified again by K.Burke, June 29, 1996, with simpler Fx(s) // Translated into C and modified by F.Gygi, Dec 9, 1996. -// +// // input: // rho: density // grad: abs(grad(rho)) // output: // exc: exchange-correlation energy per electron // vxc1, vxc2 : quantities such that the total exchange potential is: -// +// // vxc = vxc1 + div ( vxc2 * grad(n) ) -// +// // References: // [a] J.P.Perdew, K.Burke, and M.Ernzerhof, -// "Generalized gradient approximation made simple, +// "Generalized gradient approximation made simple, // Phys.Rev.Lett. 77, 3865, (1996). // [b] J.P.Perdew and Y.Wang, Phys.Rev. B33, 8800 (1986), // Phys.Rev. B40, 3399 (1989) (E). -// +// //////////////////////////////////////////////////////////////////////////////// - -void PBEFunctional::excpbe(double rho, double grad, + +void PBEFunctional::excpbe(double rho, double grad, double *exc, double *vxc1, double *vxc2) { const double third = 1.0 / 3.0; @@ -177,7 +177,7 @@ void PBEFunctional::excpbe(double rho, double grad, *vxc1 = 0.0; *vxc2 = 0.0; - if ( rho < 1.e-18 ) + if ( rho < 1.e-18 ) { return; } @@ -222,7 +222,7 @@ void PBEFunctional::excpbe(double rho, double grad, t = grad / ( twoks * rho ); rtrs = sqrt(rs); - gcor2 ( 0.0310907, 0.2137, 7.5957, 3.5876, 1.6382, 0.49294, + gcor2 ( 0.0310907, 0.2137, 7.5957, 3.5876, 1.6382, 0.49294, rtrs, &ec, &ecrs ); /* LSD potential from [c] (A1) */ @@ -264,7 +264,7 @@ void PBEFunctional::excpbe(double rho, double grad, //////////////////////////////////////////////////////////////////////////////// -void PBEFunctional::excpbe_sp(double rho_up, double rho_dn, +void PBEFunctional::excpbe_sp(double rho_up, double rho_dn, double grad_up, double grad_dn, double grad, double *exc_up, double *exc_dn, double *vxc1_up, double *vxc1_dn, double *vxc2_upup, double *vxc2_dndn, double *vxc2_updn, double *vxc2_dnup) @@ -300,7 +300,7 @@ void PBEFunctional::excpbe_sp(double rho_up, double rho_dn, *vxc2_dnup = 0.0; *vxc2_dndn = 0.0; - if ( rho_up < 1.e-18 && rho_dn < 1.e-18 ) + if ( rho_up < 1.e-18 && rho_dn < 1.e-18 ) { return; } @@ -310,11 +310,11 @@ void PBEFunctional::excpbe_sp(double rho_up, double rho_dn, ex_up = 0.0; vx1_up = 0.0; vx2_up = 0.0; - if ( rho_up > 1.e-18 ) + if ( rho_up > 1.e-18 ) { double tworho = 2.0 * rho_up; double gr = 2.0 * grad_up; - + double rh13 = pow ( tworho, third ); /* LDA exchange energy density */ double exunif = ax * rh13; @@ -339,11 +339,11 @@ void PBEFunctional::excpbe_sp(double rho_up, double rho_dn, ex_dn = 0.0; vx1_dn = 0.0; vx2_dn = 0.0; - if ( rho_dn > 1.e-18 ) + if ( rho_dn > 1.e-18 ) { double tworho = 2.0 * rho_dn; double gr = 2.0 * grad_dn; - + double rh13 = pow ( tworho, third ); /* LDA exchange energy density */ double exunif = ax * rh13; @@ -376,19 +376,19 @@ void PBEFunctional::excpbe_sp(double rho_up, double rho_dn, // construct ec, using [c] (8) double rhotot = rho_up + rho_dn; - + double rh13 = pow ( rhotot, third ); double zet = ( rho_up - rho_dn ) / rhotot; - double g = 0.5 * ( pow(1.0+zet, third2) + pow(1.0-zet, third2) ); + double g = 0.5 * ( pow(1.0+zet, third2) + pow(1.0-zet, third2) ); double fk = pi32third * rh13; double rs = alpha / fk; double twoksg = 2.0 * sqrt( four_over_pi * fk ) *g; double t = grad / ( twoksg * rhotot ); double rtrs = sqrt(rs); - gcor2 ( 0.0310907, 0.2137, 7.5957, 3.5876, 1.6382, 0.49294, + gcor2 ( 0.0310907, 0.2137, 7.5957, 3.5876, 1.6382, 0.49294, rtrs, &eu, &eurs ); - gcor2 ( 0.01554535, 0.20548, 14.1189, 6.1977, 3.3662, 0.62517, + gcor2 ( 0.01554535, 0.20548, 14.1189, 6.1977, 3.3662, 0.62517, rtrs, &ep, &eprs ); gcor2 ( 0.0168869, 0.11125, 10.357, 3.6231, 0.88026, 0.49671, rtrs, &alfm, &alfrsm ); @@ -438,9 +438,9 @@ void PBEFunctional::excpbe_sp(double rho_up, double rho_dn, double ccomm = h + hrs - t2 * ht * seven_sixth; double pref = hzed - gz * t2 * ht / g; - + ccomm -= pref * zet; - + vc1_up += ccomm + pref; vc1_dn += ccomm - pref; vc2 = - ht / ( rhotot * twoksg * twoksg ); @@ -456,11 +456,11 @@ void PBEFunctional::excpbe_sp(double rho_up, double rho_dn, } //////////////////////////////////////////////////////////////////////////////// -// +// // gcor2.c: Interpolate LSD correlation energy // as given by (10) of Perdew & Wang, Phys Rev B45 13244 (1992) // Translated into C by F.Gygi, Dec 9, 1996 -// +// //////////////////////////////////////////////////////////////////////////////// void PBEFunctional::gcor2(double a, double a1, double b1, double b2, double b3, diff --git a/src/PBEFunctional.h b/src/PBEFunctional.h index d2bfc99..535dd13 100644 --- a/src/PBEFunctional.h +++ b/src/PBEFunctional.h @@ -3,7 +3,7 @@ // PBEFunctional.h // //////////////////////////////////////////////////////////////////////////////// -// $Id: PBEFunctional.h,v 1.3 2007-03-17 01:14:00 fgygi Exp $ +// $Id: PBEFunctional.h,v 1.4 2007-10-19 16:24:04 fgygi Exp $ #ifndef PBEFUNCTIONAL_H #define PBEFUNCTIONAL_H @@ -14,31 +14,31 @@ class PBEFunctional : public XCFunctional { PBEFunctional(); - + std::vector _exc, _exc_up, _exc_dn; - std::vector _vxc1, _vxc1_up, _vxc1_dn, + std::vector _vxc1, _vxc1_up, _vxc1_dn, _vxc2, _vxc2_upup, _vxc2_updn, _vxc2_dnup, _vxc2_dndn; std::vector _grad_rho[3], _grad_rho_up[3], _grad_rho_dn[3]; - - void gcor2(double a, double a1, + + void gcor2(double a, double a1, double b1, double b2, double b3, double b4, double rtrs, double *gg, double *ggrs); - - void excpbe(double rho, double grad, + + void excpbe(double rho, double grad, double *exc, double *vxc1, double *vxc2); - - void excpbe_sp(double rho_up, double rho_dn, - double grad_up, double grad_dn, double grad, + + void excpbe_sp(double rho_up, double rho_dn, + double grad_up, double grad_dn, double grad, double *exc_up, double *exc_dn, double *vxc1_up, double *vxc1_dn, double *vxc2_upup, double *vxc2_dndn, double *vxc2_updn, double *vxc2_dnup); public: - + PBEFunctional(const std::vector > &rhoe); - + bool isGGA() { return true; }; std::string name() { return "PBE"; }; - void setxc(void); + void setxc(void); }; #endif diff --git a/src/PSDAWavefunctionStepper.C b/src/PSDAWavefunctionStepper.C index c4613e5..0c084bb 100644 --- a/src/PSDAWavefunctionStepper.C +++ b/src/PSDAWavefunctionStepper.C @@ -3,7 +3,7 @@ // PSDAWavefunctionStepper.C // //////////////////////////////////////////////////////////////////////////////// -// $Id: PSDAWavefunctionStepper.C,v 1.11 2007-01-27 23:46:31 fgygi Exp $ +// $Id: PSDAWavefunctionStepper.C,v 1.12 2007-10-19 16:24:04 fgygi Exp $ #include "PSDAWavefunctionStepper.h" #include "Wavefunction.h" @@ -13,9 +13,9 @@ using namespace std; //////////////////////////////////////////////////////////////////////////////// -PSDAWavefunctionStepper::PSDAWavefunctionStepper(Wavefunction& wf, - Preconditioner& p, TimerMap& tmap) : - WavefunctionStepper(wf,tmap), prec_(p), wf_last_(wf), dwf_last_(wf), +PSDAWavefunctionStepper::PSDAWavefunctionStepper(Wavefunction& wf, + Preconditioner& p, TimerMap& tmap) : + WavefunctionStepper(wf,tmap), prec_(p), wf_last_(wf), dwf_last_(wf), extrapolate_(false) {} @@ -31,32 +31,32 @@ void PSDAWavefunctionStepper::update(Wavefunction& dwf) if ( wf_.sdcontext(ispin,ikp)->active() ) { // compute A = V^T H V and descent direction HV - VA - + if ( wf_.sd(ispin,ikp)->basis().real() ) { // proxy real matrices c, cp DoubleMatrix c_proxy(wf_.sd(ispin,ikp)->c()); DoubleMatrix cp_proxy(dwf.sd(ispin,ikp)->c()); - + DoubleMatrix a(c_proxy.context(),c_proxy.n(),c_proxy.n(), c_proxy.nb(),c_proxy.nb()); - + tmap_["psda_residual"].start(); // factor 2.0 in next line: G and -G a.gemm('t','n',2.0,c_proxy,cp_proxy,0.0); // rank-1 update correction a.ger(-1.0,c_proxy,0,cp_proxy,0); - + // cp = cp - c * a cp_proxy.gemm('n','n',-1.0,c_proxy,a,1.0); tmap_["psda_residual"].stop(); - + // dwf.sd->c() now contains the descent direction (HV-VA) - + // Apply preconditioner K and store -K(HV-VA) in dwf tmap_["psda_prec"].start(); const valarray& diag = prec_.diag(ispin,ikp); - + double* c = (double*) wf_.sd(ispin,ikp)->c().valptr(); double* c_last = (double*) wf_last_.sd(ispin,ikp)->c().valptr(); double* dc = (double*) dwf.sd(ispin,ikp)->c().valptr(); @@ -64,11 +64,11 @@ void PSDAWavefunctionStepper::update(Wavefunction& dwf) const int mloc = wf_.sd(ispin,ikp)->c().mloc(); const int ngwl = wf_.sd(ispin,ikp)->basis().localsize(); const int nloc = wf_.sd(ispin,ikp)->c().nloc(); - + // next line: add enhancement factor to descent direction // since there is no instability of the Anderson iteration // This improves convergence in most cases - + const double psda_enhancement_factor = 2.0; for ( int n = 0; n < nloc; n++ ) { @@ -85,10 +85,10 @@ void PSDAWavefunctionStepper::update(Wavefunction& dwf) } } tmap_["psda_prec"].stop(); - + // dwf now contains the preconditioned descent // direction -K(HV-VA) - + tmap_["psda_update_wf"].start(); // Anderson extrapolation if ( extrapolate_ ) @@ -99,10 +99,10 @@ void PSDAWavefunctionStepper::update(Wavefunction& dwf) { const double f = dc[i]; const double delta_f = f - dc_last[i]; - + // accumulate partial sums of a and b // a = delta_F * F - + a += f * delta_f; b += delta_f * delta_f; } @@ -123,30 +123,30 @@ void PSDAWavefunctionStepper::update(Wavefunction& dwf) b -= delta_f0 * delta_f0 + delta_f1 * delta_f1; } } - + // a and b contain the partial sums of a and b double tmpvec[2] = { a, b }; wf_.sdcontext(ispin,ikp)->dsum(2,1,&tmpvec[0],1); a = tmpvec[0]; b = tmpvec[1]; - + // compute theta = - a / b if ( b != 0.0 ) theta = - a / b; - + if ( wf_.sdcontext(ispin,ikp)->onpe0() ) cout << " "<< endl; - + // extrapolation for ( int i = 0; i < 2*mloc*nloc; i++ ) { @@ -154,12 +154,12 @@ void PSDAWavefunctionStepper::update(Wavefunction& dwf) const double x = c[i]; const double xlast = c_last[i]; const double xbar = x + theta * ( x - xlast ); - + // f_bar = f + theta * ( f - flast ) (store in f) const double f = dc[i]; const double flast = dc_last[i]; const double fbar = f + theta * ( f - flast ); - + c[i] = xbar + fbar; c_last[i] = x; dc_last[i] = f; @@ -173,7 +173,7 @@ void PSDAWavefunctionStepper::update(Wavefunction& dwf) // x_ = x_ + f_ const double x = c[i]; const double f = dc[i]; - + c[i] = x + f; c_last[i] = x; dc_last[i] = f; @@ -181,12 +181,12 @@ void PSDAWavefunctionStepper::update(Wavefunction& dwf) } extrapolate_ = true; tmap_["psda_update_wf"].stop(); - + enum ortho_type { GRAM, LOWDIN, ORTHO_ALIGN, RICCATI }; //const ortho_type ortho = GRAM; //const ortho_type ortho = LOWDIN; const ortho_type ortho = ORTHO_ALIGN; - + switch ( ortho ) { case GRAM: @@ -194,19 +194,19 @@ void PSDAWavefunctionStepper::update(Wavefunction& dwf) wf_.sd(ispin,ikp)->gram(); tmap_["gram"].stop(); break; - + case LOWDIN: tmap_["lowdin"].start(); wf_.sd(ispin,ikp)->lowdin(); tmap_["lowdin"].stop(); break; - + case ORTHO_ALIGN: tmap_["ortho_align"].start(); wf_.sd(ispin,ikp)->ortho_align(*wf_last_.sd(ispin,ikp)); tmap_["ortho_align"].stop(); break; - + case RICCATI: tmap_["riccati"].start(); wf_.sd(ispin,ikp)->riccati(*wf_last_.sd(ispin,ikp)); diff --git a/src/PSDAWavefunctionStepper.h b/src/PSDAWavefunctionStepper.h index 3d2031d..a95233a 100644 --- a/src/PSDAWavefunctionStepper.h +++ b/src/PSDAWavefunctionStepper.h @@ -3,7 +3,7 @@ // PSDAWavefunctionStepper.h // //////////////////////////////////////////////////////////////////////////////// -// $Id: PSDAWavefunctionStepper.h,v 1.4 2007-01-27 23:46:31 fgygi Exp $ +// $Id: PSDAWavefunctionStepper.h,v 1.5 2007-10-19 16:24:04 fgygi Exp $ #ifndef PSDAWAVEFUNCTIONSTEPPER_H #define PSDAWAVEFUNCTIONSTEPPER_H @@ -21,7 +21,7 @@ class PSDAWavefunctionStepper : public WavefunctionStepper // Anderson acceleration flag bool extrapolate_; - + public: void update(Wavefunction& dwf); diff --git a/src/PSDWavefunctionStepper.C b/src/PSDWavefunctionStepper.C index 6c3ad9e..deb9c56 100644 --- a/src/PSDWavefunctionStepper.C +++ b/src/PSDWavefunctionStepper.C @@ -3,7 +3,7 @@ // PSDWavefunctionStepper.C // //////////////////////////////////////////////////////////////////////////////// -// $Id: PSDWavefunctionStepper.C,v 1.7 2007-01-27 23:46:31 fgygi Exp $ +// $Id: PSDWavefunctionStepper.C,v 1.8 2007-10-19 16:24:04 fgygi Exp $ #include "PSDWavefunctionStepper.h" #include "Wavefunction.h" @@ -13,8 +13,8 @@ using namespace std; //////////////////////////////////////////////////////////////////////////////// -PSDWavefunctionStepper::PSDWavefunctionStepper(Wavefunction& wf, - Preconditioner& p, TimerMap& tmap) : +PSDWavefunctionStepper::PSDWavefunctionStepper(Wavefunction& wf, + Preconditioner& p, TimerMap& tmap) : WavefunctionStepper(wf,tmap), prec_(p) {} @@ -30,21 +30,21 @@ void PSDWavefunctionStepper::update(Wavefunction& dwf) if ( wf_.sdcontext(ispin,ikp)->active() ) { // compute A = V^T H V and descent direction HV - VA - + tmap_["psd_residual"].start(); if ( wf_.sd(ispin,ikp)->basis().real() ) { // proxy real matrices c, cp DoubleMatrix c(wf_.sd(ispin,ikp)->c()); DoubleMatrix cp(dwf.sd(ispin,ikp)->c()); - + DoubleMatrix a(c.context(),c.n(),c.n(),c.nb(),c.nb()); - + // factor 2.0 in next line: G and -G a.gemm('t','n',2.0,c,cp,0.0); // rank-1 update correction a.ger(-1.0,c,0,cp,0); - + // cp = cp - c * a cp.gemm('n','n',-1.0,c,a,1.0); } @@ -54,12 +54,12 @@ void PSDWavefunctionStepper::update(Wavefunction& dwf) assert(false); } tmap_["psd_residual"].stop(); - + // dwf.sd->c() now contains the descent direction (HV-VA) - + tmap_["psd_update_wf"].start(); const valarray& diag = prec_.diag(ispin,ikp); - + double* coeff = (double*) wf_.sd(ispin,ikp)->c().valptr(); const double* dcoeff = (const double*) dwf.sd(ispin,ikp)->c().cvalptr(); @@ -82,7 +82,7 @@ void PSDWavefunctionStepper::update(Wavefunction& dwf) } } tmap_["psd_update_wf"].stop(); - + tmap_["gram"].start(); wf_.sd(ispin,ikp)->gram(); tmap_["gram"].stop(); diff --git a/src/PSDWavefunctionStepper.h b/src/PSDWavefunctionStepper.h index dbd35a0..0675abf 100644 --- a/src/PSDWavefunctionStepper.h +++ b/src/PSDWavefunctionStepper.h @@ -3,7 +3,7 @@ // PSDWavefunctionStepper.h // //////////////////////////////////////////////////////////////////////////////// -// $Id: PSDWavefunctionStepper.h,v 1.4 2007-01-27 23:46:31 fgygi Exp $ +// $Id: PSDWavefunctionStepper.h,v 1.5 2007-10-19 16:24:04 fgygi Exp $ #ifndef PSDWAVEFUNCTIONSTEPPER_H #define PSDWAVEFUNCTIONSTEPPER_H @@ -14,13 +14,13 @@ class Preconditioner; class PSDWavefunctionStepper : public WavefunctionStepper { private: - + Preconditioner& prec_; public: void update(Wavefunction& dwf); - + PSDWavefunctionStepper(Wavefunction& wf, Preconditioner& p, TimerMap& tmap); ~PSDWavefunctionStepper() {}; }; diff --git a/src/Preconditioner.C b/src/Preconditioner.C index fa280ed..de91423 100644 --- a/src/Preconditioner.C +++ b/src/Preconditioner.C @@ -3,7 +3,7 @@ // Preconditioner.C // //////////////////////////////////////////////////////////////////////////////// -// $Id: Preconditioner.C,v 1.4 2007-03-17 01:14:00 fgygi Exp $ +// $Id: Preconditioner.C,v 1.5 2007-10-19 16:24:04 fgygi Exp $ #include "Preconditioner.h" #include "EnergyFunctional.h" @@ -14,7 +14,7 @@ using namespace std; //////////////////////////////////////////////////////////////////////////////// -Preconditioner::Preconditioner(const Sample& s, const EnergyFunctional& ef) : +Preconditioner::Preconditioner(const Sample& s, const EnergyFunctional& ef) : s_(s), ef_(ef) { update(); @@ -28,7 +28,7 @@ void Preconditioner::update(void) const Wavefunction& wf = s_.wf; // If ecutprec is zero, use ecut const double ecutpr = s_.ctrl.ecutprec> 0.0 ? s_.ctrl.ecutprec : wf.ecut(); - + diag_.resize(wf.nspin()); for ( int ispin = 0; ispin < wf.nspin(); ispin++ ) { diff --git a/src/Preconditioner.h b/src/Preconditioner.h index 9417c3f..8d1f72b 100644 --- a/src/Preconditioner.h +++ b/src/Preconditioner.h @@ -3,7 +3,7 @@ // Preconditioner.h // //////////////////////////////////////////////////////////////////////////////// -// $Id: Preconditioner.h,v 1.2 2007-03-17 01:14:00 fgygi Exp $ +// $Id: Preconditioner.h,v 1.3 2007-10-19 16:24:04 fgygi Exp $ #ifndef PRECONDITIONER_H #define PRECONDITIONER_H @@ -17,7 +17,7 @@ class EnergyFunctional; class Preconditioner { private: - + const Sample& s_; const EnergyFunctional& ef_; std::vector > > diag_; // diag_[ispin][ikp][ig] @@ -25,7 +25,7 @@ class Preconditioner public: void update(void); - + const std::valarray& diag(int ispin, int ikp) const { return diag_[ispin][ikp]; } diff --git a/src/PrintCmd.h b/src/PrintCmd.h index 64c068f..04233e3 100644 --- a/src/PrintCmd.h +++ b/src/PrintCmd.h @@ -3,7 +3,7 @@ // PrintCmd.h: // //////////////////////////////////////////////////////////////////////////////// -// $Id: PrintCmd.h,v 1.1 2003-01-10 00:35:36 fgygi Exp $ +// $Id: PrintCmd.h,v 1.2 2007-10-19 16:24:04 fgygi Exp $ #ifndef PRINTCMD_H #define PRINTCMD_H @@ -27,7 +27,7 @@ class PrintCmd : public Cmd char *help_msg(void) const { - return + return "\n print\n\n" " syntax: print variable\n\n" " The print command prints the value of an interface variable.\n\n"; diff --git a/src/QuitCmd.h b/src/QuitCmd.h index b651137..5dee84d 100644 --- a/src/QuitCmd.h +++ b/src/QuitCmd.h @@ -3,7 +3,7 @@ // QuitCmd.h: // //////////////////////////////////////////////////////////////////////////////// -// $Id: QuitCmd.h,v 1.1 2003-01-10 00:35:36 fgygi Exp $ +// $Id: QuitCmd.h,v 1.2 2007-10-19 16:24:04 fgygi Exp $ #ifndef QUITCMD_H #define QUITCMD_H @@ -28,14 +28,14 @@ class QuitCmd : public Cmd char *help_msg(void) const { - return + return "\n quit\n\n" " syntax: quit\n\n" " The quit command exits without saving any data.\n\n"; } int action(int argc, char **argv) - { + { ui->terminate(); return 0; } diff --git a/src/RandomizeWfCmd.h b/src/RandomizeWfCmd.h index ac13d82..4233619 100644 --- a/src/RandomizeWfCmd.h +++ b/src/RandomizeWfCmd.h @@ -3,7 +3,7 @@ // RandomizeWfCmd.h: // //////////////////////////////////////////////////////////////////////////////// -// $Id: RandomizeWfCmd.h,v 1.2 2003-03-27 22:05:59 fgygi Exp $ +// $Id: RandomizeWfCmd.h,v 1.3 2007-10-19 16:24:04 fgygi Exp $ #ifndef RANDOMIZEWFCMD_H #define RANDOMIZEWFCMD_H @@ -24,7 +24,7 @@ class RandomizeWfCmd : public Cmd char *name(void) const { return "randomize_wf"; } char *help_msg(void) const { - return + return "\n randomize_wf\n\n" " syntax: randomize_wf [amplitude]\n\n" " The randomize_wf command adds random amplitudes to\n" diff --git a/src/RefCell.h b/src/RefCell.h index 0443c14..d2985f9 100644 --- a/src/RefCell.h +++ b/src/RefCell.h @@ -3,7 +3,7 @@ // RefCell.h // //////////////////////////////////////////////////////////////////////////////// -// $Id: RefCell.h,v 1.1 2004-02-04 19:52:27 fgygi Exp $ +// $Id: RefCell.h,v 1.2 2007-10-19 16:24:04 fgygi Exp $ #ifndef REFCELL_H #define REFCELL_H @@ -31,12 +31,12 @@ class RefCell : public Var cout << " ref_cell must be specified with 3 vectors (9 values)" << endl; return 1; } - + D3vector a0(atof(argv[1]),atof(argv[2]),atof(argv[3])); D3vector a1(atof(argv[4]),atof(argv[5]),atof(argv[6])); D3vector a2(atof(argv[7]),atof(argv[8]),atof(argv[9])); UnitCell ref_cell(a0,a1,a2); - + if ( ref_cell.volume() < 0.0 ) { if ( ui->onpe0() ) @@ -50,11 +50,11 @@ class RefCell : public Var s->wfv->resize(s->wf.cell(),s->wf.refcell(),s->wf.ecut()); s->wfv->clear(); } - + if ( ui->onpe0() ) { cout << " \n" - << s->wf.refcell() + << s->wf.refcell() << " " << endl; } return 0; diff --git a/src/ResetVcmCmd.h b/src/ResetVcmCmd.h index a070511..1756faf 100644 --- a/src/ResetVcmCmd.h +++ b/src/ResetVcmCmd.h @@ -3,7 +3,7 @@ // ResetVcmCmd.h: // //////////////////////////////////////////////////////////////////////////////// -// $Id: ResetVcmCmd.h,v 1.1 2006-09-06 00:34:24 fgygi Exp $ +// $Id: ResetVcmCmd.h,v 1.2 2007-10-19 16:24:04 fgygi Exp $ #ifndef RESETVCMCMD_H #define RESETVCMCMD_H @@ -27,7 +27,7 @@ class ResetVcmCmd : public Cmd char *name(void) const { return "reset_vcm"; } char *help_msg(void) const { - return + return "\n reset_vcm\n\n" " syntax: reset_vcm \n\n" " The reset_vcm command subtracts the velocity of the center\n" diff --git a/src/RunCmd.C b/src/RunCmd.C index c5108ef..6c3dd14 100644 --- a/src/RunCmd.C +++ b/src/RunCmd.C @@ -3,7 +3,7 @@ // RunCmd.C: // //////////////////////////////////////////////////////////////////////////////// -// $Id: RunCmd.C,v 1.5 2004-09-14 22:24:11 fgygi Exp $ +// $Id: RunCmd.C,v 1.6 2007-10-19 16:24:04 fgygi Exp $ #include "RunCmd.h" #include @@ -25,7 +25,7 @@ int RunCmd::action(int argc, char **argv) cout << " run niter nitscf nite" << endl; return 1; } - + if ( s->wf.nst() == 0 ) { if ( ui->onpe0() ) @@ -38,9 +38,9 @@ int RunCmd::action(int argc, char **argv) cout << " " << endl; return 1; } - + SampleStepper* stepper; - + int niter = atoi(argv[1]); int nite = 1; int nitscf = 1; @@ -59,13 +59,13 @@ int RunCmd::action(int argc, char **argv) stepper = new CPSampleStepper(*s); else stepper = new BOSampleStepper(*s,nitscf,nite); - + assert(stepper!=0); - + s->wf.info(cout,"wavefunction"); stepper->step(niter); - + delete stepper; - + return 0; } diff --git a/src/RunCmd.h b/src/RunCmd.h index 1c1bca2..76db540 100644 --- a/src/RunCmd.h +++ b/src/RunCmd.h @@ -3,7 +3,7 @@ // RunCmd.h: // //////////////////////////////////////////////////////////////////////////////// -// $Id: RunCmd.h,v 1.3 2007-03-17 01:14:00 fgygi Exp $ +// $Id: RunCmd.h,v 1.4 2007-10-19 16:24:04 fgygi Exp $ #ifndef RUNCMD_H #define RUNCMD_H @@ -25,7 +25,7 @@ class RunCmd : public Cmd char *name(void) const { return "run"; } char *help_msg(void) const { - return + return "\n run\n\n" " syntax: run n [nite]\n\n" " The run command runs n steps of simulation. Each step\n" diff --git a/src/SDAIonicStepper.C b/src/SDAIonicStepper.C index d9d6a71..022cd76 100644 --- a/src/SDAIonicStepper.C +++ b/src/SDAIonicStepper.C @@ -3,7 +3,7 @@ // SDAIonicStepper.C // //////////////////////////////////////////////////////////////////////////////// -// $Id: SDAIonicStepper.C,v 1.4 2005-06-27 22:21:32 fgygi Exp $ +// $Id: SDAIonicStepper.C,v 1.5 2007-10-19 16:24:04 fgygi Exp $ #include "SDAIonicStepper.h" #include @@ -14,12 +14,12 @@ void SDAIonicStepper::compute_r(double e0, const vector >& f0) { // Steepest descent step atoms_.get_positions(r0_); - + if ( first_step_ ) { rm_ = r0_; } - + // copy forces f0 in linear array f_ int k = 0; double sum = 0.0; @@ -32,14 +32,14 @@ void SDAIonicStepper::compute_r(double e0, const vector >& f0) } } if ( s_.ctxt_.onpe0() ) - cout << " " << sum + cout << " " << sum << "" << endl; - + mixer_.update(&f_[0],&theta_,&fbar_[0]); if ( s_.ctxt_.onpe0() ) - cout << " " << theta_ + cout << " " << theta_ << "" << endl; - + k = 0; for ( int is = 0; is < r0_.size(); is++ ) { diff --git a/src/SDAIonicStepper.h b/src/SDAIonicStepper.h index 832744f..09cdc0d 100644 --- a/src/SDAIonicStepper.h +++ b/src/SDAIonicStepper.h @@ -3,7 +3,7 @@ // SDAIonicStepper.h: // //////////////////////////////////////////////////////////////////////////////// -// $Id: SDAIonicStepper.h,v 1.7 2007-09-30 04:47:04 fgygi Exp $ +// $Id: SDAIonicStepper.h,v 1.8 2007-10-19 16:24:04 fgygi Exp $ #ifndef SDAIONICSTEPPER_H #define SDAIONICSTEPPER_H @@ -14,15 +14,15 @@ class SDAIonicStepper : public IonicStepper { private: - + std::vector f_; std::vector fbar_; double theta_; bool first_step_; AndersonMixer mixer_; - + public: - + SDAIonicStepper(Sample& s) : IonicStepper(s), first_step_(true), theta_(0), mixer_(3*atoms_.size(), 0) { diff --git a/src/SDCellStepper.C b/src/SDCellStepper.C index 01ee845..19ec05f 100644 --- a/src/SDCellStepper.C +++ b/src/SDCellStepper.C @@ -3,7 +3,7 @@ // SDCellStepper.C // //////////////////////////////////////////////////////////////////////////////// -// $Id: SDCellStepper.C,v 1.4 2007-03-17 01:14:00 fgygi Exp $ +// $Id: SDCellStepper.C,v 1.5 2007-10-19 16:24:04 fgygi Exp $ #include "SDCellStepper.h" using namespace std; @@ -14,10 +14,10 @@ void SDCellStepper::compute_new_cell(const valarray& sigma) //cout << " SDCellStepper::compute_new_cell" << endl; // multiply stress by A^T to get dE/da_ij valarray deda(9); - + const UnitCell& cell = s_.wf.cell(); const double cell_mass = s_.ctrl.cell_mass; - + if ( cell_mass <= 0.0 ) { if ( s_.ctxt_.onpe0() ) @@ -27,14 +27,14 @@ void SDCellStepper::compute_new_cell(const valarray& sigma) return; } } - + // deda = - omega * sigma * A^-T cell.compute_deda(sigma,deda); - + //cout << " SDCellStepper: cell derivatives before constraints" << endl; //for ( int i = 0; i < 9; i++ ) // cout << " deda[" << i << "] = " << deda[i] << endl; - + string cell_lock = s_.ctrl.cell_lock; if ( cell_lock != "OFF" ) { @@ -54,36 +54,36 @@ void SDCellStepper::compute_new_cell(const valarray& sigma) // vector C is locked deda[6] = deda[7] = deda[8] = 0.0; } - + // Check is cell shape should be preserved (if "S" is present in cell_lock) // The only changes allowed are renormalizations of a,b,c if ( cell_lock.find("S") != string::npos ) { // projection of d in the direction of e D3vector d,e; - + d = D3vector(deda[0],deda[1],deda[2]); e = cell.a(0) / length(cell.a(0)); d = (d * e) * e; deda[0] = d.x; deda[1] = d.y; deda[2] = d.z; - + d = D3vector(deda[3],deda[4],deda[5]); e = cell.a(1) / length(cell.a(1)); d = (d * e) * e; deda[3] = d.x; deda[4] = d.y; deda[5] = d.z; - + d = D3vector(deda[6],deda[7],deda[8]); e = cell.a(2) / length(cell.a(2)); d = (d * e) * e; deda[6] = d.x; deda[7] = d.y; deda[8] = d.z; } - + if ( cell_lock == "R" ) { // preserve aspect ratio // deda must be proportional to A // All vectors are rescaled by the same constant - // rescale cell by coefficient alpha, i.e. + // rescale cell by coefficient alpha, i.e. // deda = alpha * A // where alpha * A is the projection of dE/dA in the direction of A // alpha = tr (A^T * deda) / || A ||^2 (matrix scalar product) @@ -102,35 +102,35 @@ void SDCellStepper::compute_new_cell(const valarray& sigma) //for ( int i = 0; i < 9; i++ ) // cout << " deda[" << i << "] = " << deda[i] << endl; } - + const double dt = s_.ctrl.dt; const double dt2bym = dt*dt/cell_mass; - + // cellp = cell - deda * dt^2 / cell_mass D3vector a0p = cell.a(0) - dt2bym * D3vector(deda[0],deda[1],deda[2]); D3vector a1p = cell.a(1) - dt2bym * D3vector(deda[3],deda[4],deda[5]); D3vector a2p = cell.a(2) - dt2bym * D3vector(deda[6],deda[7],deda[8]); - + cellp = UnitCell(a0p,a1p,a2p); - + //cout << " SDCellStepper::compute_new_cell: cellp: " << endl; //cout << cellp; - + } //////////////////////////////////////////////////////////////////////////////// void SDCellStepper::update_cell(void) { const UnitCell& cell = s_.wf.cell(); - + // rescale atomic positions in AtomSet - + // r_new = A_new A_old^-1 r_old vector > r; s_.atoms.get_positions(r); const double* const ainv = cell.amat_inv(); const double* const ap = cellp.amat(); - + double tau[3]; for ( int is = 0; is < r.size(); is++ ) { @@ -145,9 +145,9 @@ void SDCellStepper::update_cell(void) } } s_.atoms.set_positions(r); - + // resize wavefunction and basis sets - + //cout << " SDCellStepper::update_cell" << endl; s_.wf.resize(cellp,s_.wf.refcell(),s_.wf.ecut()); if ( s_.wfv != 0 ) diff --git a/src/SDCellStepper.h b/src/SDCellStepper.h index e51c117..f389710 100644 --- a/src/SDCellStepper.h +++ b/src/SDCellStepper.h @@ -3,7 +3,7 @@ // SDCellStepper.h: // //////////////////////////////////////////////////////////////////////////////// -// $Id: SDCellStepper.h,v 1.2 2007-03-17 01:14:00 fgygi Exp $ +// $Id: SDCellStepper.h,v 1.3 2007-10-19 16:24:04 fgygi Exp $ #ifndef SDCELLSTEPPER_H #define SDCELLSTEPPER_H @@ -13,9 +13,9 @@ class SDCellStepper : public CellStepper { private: - + public: - + SDCellStepper(Sample& s) : CellStepper(s) {} void compute_new_cell(const std::valarray& sigma_eks); diff --git a/src/SDIonicStepper.h b/src/SDIonicStepper.h index 52c5a82..47ed876 100644 --- a/src/SDIonicStepper.h +++ b/src/SDIonicStepper.h @@ -3,7 +3,7 @@ // SDIonicStepper.h: // //////////////////////////////////////////////////////////////////////////////// -// $Id: SDIonicStepper.h,v 1.5 2007-03-17 01:14:00 fgygi Exp $ +// $Id: SDIonicStepper.h,v 1.6 2007-10-19 16:24:04 fgygi Exp $ #ifndef SDIONICSTEPPER_H #define SDIONICSTEPPER_H @@ -14,9 +14,9 @@ class SDIonicStepper : public IonicStepper { private: - + public: - + SDIonicStepper(Sample& s) : IonicStepper(s) {} void compute_r(double e0, const std::vector >& f0); diff --git a/src/SDWavefunctionStepper.C b/src/SDWavefunctionStepper.C index c6fbe79..9587d45 100644 --- a/src/SDWavefunctionStepper.C +++ b/src/SDWavefunctionStepper.C @@ -3,7 +3,7 @@ // SDWavefunctionStepper.C // //////////////////////////////////////////////////////////////////////////////// -// $Id: SDWavefunctionStepper.C,v 1.4 2007-01-27 23:46:31 fgygi Exp $ +// $Id: SDWavefunctionStepper.C,v 1.5 2007-10-19 16:24:04 fgygi Exp $ #include "SDWavefunctionStepper.h" #include "Wavefunction.h" @@ -14,7 +14,7 @@ using namespace std; //////////////////////////////////////////////////////////////////////////////// SDWavefunctionStepper::SDWavefunctionStepper(Wavefunction& wf, double alpha, - TimerMap& tmap) : + TimerMap& tmap) : alpha_(alpha), WavefunctionStepper(wf,tmap) {} diff --git a/src/Sample.h b/src/Sample.h index a52e4c1..18af30f 100644 --- a/src/Sample.h +++ b/src/Sample.h @@ -3,7 +3,7 @@ // Sample.h // //////////////////////////////////////////////////////////////////////////////// -// $Id: Sample.h,v 1.8 2007-01-27 23:48:28 fgygi Exp $ +// $Id: Sample.h,v 1.9 2007-10-19 16:24:04 fgygi Exp $ #ifndef SAMPLE_H #define SAMPLE_H @@ -18,9 +18,9 @@ class Context; class Sample { private: - + public: - + const Context& ctxt_; AtomSet atoms; diff --git a/src/SampleHandler.C b/src/SampleHandler.C index 2d9cf65..78e8337 100644 --- a/src/SampleHandler.C +++ b/src/SampleHandler.C @@ -3,7 +3,7 @@ // SampleHandler.C // //////////////////////////////////////////////////////////////////////////////// -// $Id: SampleHandler.C,v 1.6 2007-08-13 21:24:17 fgygi Exp $ +// $Id: SampleHandler.C,v 1.7 2007-10-19 16:24:04 fgygi Exp $ #if USE_XERCES @@ -18,8 +18,8 @@ using namespace xercesc; using namespace std; //////////////////////////////////////////////////////////////////////////////// -SampleHandler::SampleHandler(Sample& s, DoubleMatrix& gfdata, - Wavefunction& wfvtmp) : +SampleHandler::SampleHandler(Sample& s, DoubleMatrix& gfdata, + Wavefunction& wfvtmp) : s_(s), gfdata_(gfdata), read_wf(false), read_wfv(false), wfvtmp_(wfvtmp) {} //////////////////////////////////////////////////////////////////////////////// @@ -29,7 +29,7 @@ SampleHandler::~SampleHandler() {} void SampleHandler::startElement(const XMLCh* const uri, const XMLCh* const localname, const XMLCh* const qname, const Attributes& attributes) -{ +{ // cout << " SampleHandler::startElement " << StrX(qname) << endl; } @@ -44,13 +44,13 @@ void SampleHandler::endElement(const XMLCh* const uri, //////////////////////////////////////////////////////////////////////////////// StructureHandler* SampleHandler::startSubHandler(const XMLCh* const uri, - const XMLCh* const localname, const XMLCh* const qname, + const XMLCh* const localname, const XMLCh* const qname, const Attributes& attributes) { // check if element qname can be processed by another StructureHandler // If it can, return a pointer to the StructureHandler, otherwise return 0 // cout << " SampleHandler::startSubHandler " << StrX(qname) << endl; - + string qnm = XMLString::transcode(qname); if ( qnm == "atomset" ) { @@ -74,7 +74,7 @@ StructureHandler* SampleHandler::startSubHandler(const XMLCh* const uri, //////////////////////////////////////////////////////////////////////////////// void SampleHandler::endSubHandler(const XMLCh* const uri, - const XMLCh* const localname, const XMLCh* const qname, + const XMLCh* const localname, const XMLCh* const qname, const StructureHandler* const subHandler) { // cout << " SampleHandler::endSubHandler " << StrX(qname) << endl; diff --git a/src/SampleHandler.h b/src/SampleHandler.h index 780e344..d637ebc 100644 --- a/src/SampleHandler.h +++ b/src/SampleHandler.h @@ -3,7 +3,7 @@ // SampleHandler.h // //////////////////////////////////////////////////////////////////////////////// -// $Id: SampleHandler.h,v 1.5 2007-03-17 01:14:00 fgygi Exp $ +// $Id: SampleHandler.h,v 1.6 2007-10-19 16:24:04 fgygi Exp $ #ifndef SAMPLEHANDLER_H #define SAMPLEHANDLER_H @@ -17,31 +17,31 @@ class Wavefunction; class SampleHandler : public StructureHandler { private: - + Sample& s_; DoubleMatrix& gfdata_; Wavefunction& wfvtmp_; public: - + bool read_wf,read_wfv; - + // Start of the root element in the structure being handled virtual void startElement(const XMLCh* const uri,const XMLCh* const localname, const XMLCh* const qname, const Attributes& attributes); // End of the root element in the structure being handled - virtual void endElement(const XMLCh* const uri, const XMLCh* const localname, + virtual void endElement(const XMLCh* const uri, const XMLCh* const localname, const XMLCh* const qname, std::string& content); - + // start a subhandler virtual StructureHandler* startSubHandler(const XMLCh* const uri, - const XMLCh* const localname, const XMLCh* const qname, + const XMLCh* const localname, const XMLCh* const qname, const Attributes& attributes); - + // end a subhandler virtual void endSubHandler(const XMLCh* const uri, - const XMLCh* const localname, const XMLCh* const qname, + const XMLCh* const localname, const XMLCh* const qname, const StructureHandler* const subHandler); SampleHandler(Sample& s, DoubleMatrix& gfdata, Wavefunction& wfvtmp); diff --git a/src/SampleReader.C b/src/SampleReader.C index dbc49ad..f10f237 100644 --- a/src/SampleReader.C +++ b/src/SampleReader.C @@ -3,7 +3,7 @@ // SampleReader.C: // //////////////////////////////////////////////////////////////////////////////// -// $Id: SampleReader.C,v 1.18 2007-08-13 21:24:17 fgygi Exp $ +// $Id: SampleReader.C,v 1.19 2007-10-19 16:24:04 fgygi Exp $ #include "Sample.h" @@ -20,6 +20,7 @@ #include #include +#include #include #include @@ -54,11 +55,11 @@ void SampleReader::readSample (Sample& s, const string uri, bool serial) bool schemaFullChecking = true; bool namespacePrefixes = false; SAX2XMLReader* parser = 0; - + Wavefunction wfvtmp(s.wf); - + MemBufInputSource* memBufIS = 0; - + // XMLPlatformUtils initialization on task 0 only int ierr = 0; if ( ctxt_.onpe0() ) @@ -83,14 +84,14 @@ void SampleReader::readSample (Sample& s, const string uri, bool serial) //cout << ctxt_.mype() <<": SampleReader: ierr=" << ierr << endl; if ( ierr > 0 ) throw SampleReaderException("error in XMLPlatformUtils::Initialize"); - + // Determine if uri is a local file struct stat statbuf; bool read_from_file = !stat(uri.c_str(),&statbuf); - + // check for serial override read_from_file &= !serial; - + string xmlcontent; DoubleMatrix gfdata(ctxt_); if ( read_from_file ) @@ -100,25 +101,25 @@ void SampleReader::readSample (Sample& s, const string uri, bool serial) cout << " SampleReader: reading from file " << filename << " size: " << statbuf.st_size << endl; - + XMLGFPreprocessor xmlgfp; - + xmlgfp.process(filename,gfdata,xmlcontent); - + if ( ctxt_.onpe0() ) { - // cout << ctxt_.mype() << ": xmlcontent.size(): " << xmlcontent.size() + // cout << ctxt_.mype() << ": xmlcontent.size(): " << xmlcontent.size() // << endl; // cout << ctxt_.mype() << ": xmlcontent: " << xmlcontent << endl; memBufIS = new MemBufInputSource ( (const XMLByte*) &xmlcontent[0], xmlcontent.size(), "buf_id", false); } } - + bool read_wf = false; bool read_wfv = false; // initialize wavefunction_velocity in case it appears in the sample file - + if ( ctxt_.onpe0() ) { parser = XMLReaderFactory::createXMLReader(); @@ -146,7 +147,7 @@ void SampleReader::readSample (Sample& s, const string uri, bool serial) int errorCount = 0; SampleHandler* s_handler = new SampleHandler(s,gfdata,wfvtmp); - + try { StructuredDocumentHandler handler(s_handler); @@ -164,7 +165,7 @@ void SampleReader::readSample (Sample& s, const string uri, bool serial) else parser->parse(uri.c_str()); cout << " XML parsing done" << endl; - + errorCount = parser->getErrorCount(); } @@ -189,29 +190,29 @@ void SampleReader::readSample (Sample& s, const string uri, bool serial) //delete parser; //throw; } - + read_wf = s_handler->read_wf; if ( read_wf ) cout << " wavefunction was read" << endl; read_wfv = s_handler->read_wfv; if ( read_wfv ) cout << " wavefunction velocity was read" << endl; - + delete s_handler; delete parser; XMLPlatformUtils::Terminate(); - + // parsing of sample is complete, send end of sample tag to tasks > 0 int tag = 0; ctxt_.ibcast_send(1,1,&tag,1); - + } // onpe0 else { // tasks > 0 // listen for Sample events // cout << ctxt_.mype() << ": listening..." << endl; - + bool done = false; int tag = -1; while ( !done ) @@ -230,7 +231,7 @@ void SampleReader::readSample (Sample& s, const string uri, bool serial) SpeciesReader sp_reader(ctxt_); sp_reader.bcastSpecies(*sp); s.atoms.addSpecies(sp,curr_name); - } + } else if ( tag == 2 ) { // Atom @@ -261,7 +262,7 @@ void SampleReader::readSample (Sample& s, const string uri, bool serial) s.wf.set_nel(nel); s.wf.set_nspin(nspin); s.wf.set_nempty(nempty); - + // domain double buf[9]; ctxt_.dbcast_recv(9,1,buf,1,0,0); @@ -269,26 +270,26 @@ void SampleReader::readSample (Sample& s, const string uri, bool serial) D3vector b(buf[3],buf[4],buf[5]); D3vector c(buf[6],buf[7],buf[8]); UnitCell uc(a,b,c); - + // grid // receive only computed ecut double ecut; ctxt_.dbcast_recv(1,1,&ecut,1,0,0); - + // reference_domain ctxt_.dbcast_recv(9,1,buf,1,0,0); D3vector ar(buf[0],buf[1],buf[2]); D3vector br(buf[3],buf[4],buf[5]); D3vector cr(buf[6],buf[7],buf[8]); UnitCell ruc(ar,br,cr); - + s.wf.resize(uc,ruc,ecut); - + //cout << ctxt_.mype() << ": wf resized, ecut=" << ecut << endl; - + //!! nkpoint fixed = 1 const int nkpoint = 1; - + for ( int ispin = 0; ispin < nspin; ispin++ ) { for ( int ikp = 0; ikp < nkpoint; ikp++ ) @@ -300,7 +301,7 @@ void SampleReader::readSample (Sample& s, const string uri, bool serial) vector dmat_tmp(sd->nst()); sd->context().dbcast_recv(sd->nst(),1,&dmat_tmp[0],1,0,0); sd->set_occ(dmat_tmp); - + if ( !read_from_file ) { const Basis& basis = sd->basis(); @@ -322,7 +323,7 @@ void SampleReader::readSample (Sample& s, const string uri, bool serial) //cout << sd->context().mype() // << ": grid_function nloc=" << nloc // << "received" << endl; - + // copy to complex array for ( int i = 0; i < size; i++ ) { @@ -353,7 +354,7 @@ void SampleReader::readSample (Sample& s, const string uri, bool serial) wfvtmp.set_nel(nel); wfvtmp.set_nspin(nspin); wfvtmp.set_nempty(nempty); - + // domain double buf[9]; ctxt_.dbcast_recv(9,1,buf,1,0,0); @@ -361,26 +362,26 @@ void SampleReader::readSample (Sample& s, const string uri, bool serial) D3vector b(buf[3],buf[4],buf[5]); D3vector c(buf[6],buf[7],buf[8]); UnitCell uc(a,b,c); - + // grid // receive only computed ecut double ecut; ctxt_.dbcast_recv(1,1,&ecut,1,0,0); - + // reference_domain ctxt_.dbcast_recv(9,1,buf,1,0,0); D3vector ar(buf[0],buf[1],buf[2]); D3vector br(buf[3],buf[4],buf[5]); D3vector cr(buf[6],buf[7],buf[8]); UnitCell ruc(ar,br,cr); - + wfvtmp.resize(uc,ruc,ecut); - + //cout << ctxt_.mype() << ": wfv resized, ecut=" << ecut << endl; - + //!! nkpoint fixed = 1 const int nkpoint = 1; - + for ( int ispin = 0; ispin < nspin; ispin++ ) { for ( int ikp = 0; ikp < nkpoint; ikp++ ) @@ -392,7 +393,7 @@ void SampleReader::readSample (Sample& s, const string uri, bool serial) vector dmat_tmp(sd->nst()); sd->context().dbcast_recv(sd->nst(),1,&dmat_tmp[0],1,0,0); sd->set_occ(dmat_tmp); - + if ( !read_from_file ) { const Basis& basis = sd->basis(); @@ -414,7 +415,7 @@ void SampleReader::readSample (Sample& s, const string uri, bool serial) //cout << sd->context().mype() // << ": grid_function nloc=" << nloc // << "received" << endl; - + // copy to complex array for ( int i = 0; i < size; i++ ) { @@ -434,26 +435,29 @@ void SampleReader::readSample (Sample& s, const string uri, bool serial) } } // if-else onpe0 + cout << "SampleReader: after if-else onpe0" << endl; // This part is now executing on all tasks if ( read_from_file ) { if ( read_wf ) { + ofstream gffile("gf.dat"); + gffile << gfdata; // transfer data from the gfdata matrix to the SlaterDets - //cout << ctxt_.mype() << ": mapping gfdata matrix..." + //cout << ctxt_.mype() << ": mapping gfdata matrix..." // << endl; //cout << ctxt_.mype() << ": gfdata: (" << gfdata.m() << "x" << gfdata.n() //<< ") (" << gfdata.mb() << "x" << gfdata.nb() << ") blocks" << endl; //cout << ctxt_.mype() << ": gfdata.mloc()=" << gfdata.mloc() //<< " gfdata.nloc()=" << gfdata.nloc() << endl; - + //!! Next lines work for 1 kpoint, 1 spin only SlaterDet* sd = s.wf.sd(0,0); const Basis& basis = sd->basis(); FourierTransform ft(basis,basis.np(0),basis.np(1),basis.np(2)); //cout << ctxt_.mype() << ": ft.np012loc()=" << ft.np012loc() << endl; //cout << ctxt_.mype() << ": ft.context(): " << ft.context(); - + ComplexMatrix& c = sd->c(); DoubleMatrix wftmpr(sd->context(),ft.np012(),sd->nst(), ft.np012loc(0),c.nb()); @@ -462,16 +466,16 @@ void SampleReader::readSample (Sample& s, const string uri, bool serial) //cout << ctxt_.mype() << ": wftmpr.mloc()=" << wftmpr.mloc() //<< " wftmpr.nloc()=" << wftmpr.nloc() << endl; - vector > wftmp(ft.np012loc()); + vector > wftmp(ft.np012loc()); wftmpr.getsub(gfdata,ft.np012(),sd->nst(),0,0); - + #if 0 // Check orthogonality by computing overlap matrix DoubleMatrix smat(sd->context(),sd->nst(),sd->nst(),c.nb(),c.nb()); smat.syrk('l','t',1.0,wftmpr,0.0); cout << smat; #endif - + for ( int nloc = 0; nloc < sd->nstloc(); nloc++ ) { // copy to complex array @@ -481,24 +485,24 @@ void SampleReader::readSample (Sample& s, const string uri, bool serial) ft.forward(&wftmp[0],c.valptr(c.mloc()*nloc)); } } // if read_wf - + if ( read_wfv ) { // transfer wfv data from the gfdata matrix to the SlaterDets - //cout << ctxt_.mype() << ": mapping gfdata matrix..." + //cout << ctxt_.mype() << ": mapping gfdata matrix..." // << endl; //cout << ctxt_.mype() << ": gfdata: (" << gfdata.m() << "x" << gfdata.n() //<< ") (" << gfdata.mb() << "x" << gfdata.nb() << ") blocks" << endl; //cout << ctxt_.mype() << ": gfdata.mloc()=" << gfdata.mloc() //<< " gfdata.nloc()=" << gfdata.nloc() << endl; - + //!! Next lines work for 1 kpoint, 1 spin only SlaterDet* sd = wfvtmp.sd(0,0); const Basis& basis = sd->basis(); FourierTransform ft(basis,basis.np(0),basis.np(1),basis.np(2)); //cout << ctxt_.mype() << ": ft.np012loc()=" << ft.np012loc() << endl; //cout << ctxt_.mype() << ": ft.context(): " << ft.context(); - + ComplexMatrix& c = sd->c(); DoubleMatrix wftmpr(sd->context(),ft.np012(),sd->nst(), ft.np012loc(0),c.nb()); @@ -507,9 +511,9 @@ void SampleReader::readSample (Sample& s, const string uri, bool serial) //cout << ctxt_.mype() << ": wftmpr.mloc()=" << wftmpr.mloc() //<< " wftmpr.nloc()=" << wftmpr.nloc() << endl; - vector > wftmp(ft.np012loc()); + vector > wftmp(ft.np012loc()); wftmpr.getsub(gfdata,ft.np012(),sd->nst(),0,sd->nst()); - + for ( int nloc = 0; nloc < sd->nstloc(); nloc++ ) { // copy to complex array @@ -520,7 +524,7 @@ void SampleReader::readSample (Sample& s, const string uri, bool serial) } } } - + // check if wavefunction_velocity element was read, if not, delete wfvtmp if ( s.wfv != 0 ) { diff --git a/src/SampleReader.h b/src/SampleReader.h index c202b9e..dd78240 100644 --- a/src/SampleReader.h +++ b/src/SampleReader.h @@ -3,7 +3,7 @@ // SampleReader.h // //////////////////////////////////////////////////////////////////////////////// -// $Id: SampleReader.h,v 1.3 2007-03-17 01:14:00 fgygi Exp $ +// $Id: SampleReader.h,v 1.4 2007-10-19 16:24:05 fgygi Exp $ #ifndef SAMPLEREADER_H #define SAMPLEREADER_H @@ -15,7 +15,7 @@ class SampleReader private: const Context& ctxt_; - + public: SampleReader(const Context& ctxt); diff --git a/src/SampleStepper.C b/src/SampleStepper.C index 13fd3ff..c279237 100644 --- a/src/SampleStepper.C +++ b/src/SampleStepper.C @@ -3,7 +3,7 @@ // SampleStepper.C // //////////////////////////////////////////////////////////////////////////////// -// $Id: SampleStepper.C,v 1.21 2007-03-17 01:14:00 fgygi Exp $ +// $Id: SampleStepper.C,v 1.22 2007-10-19 16:24:05 fgygi Exp $ #include "SampleStepper.h" #include "Sample.h" @@ -19,7 +19,7 @@ SampleStepper::SampleStepper(Sample& s) : s_(s) fion.resize(s_.atoms.nsp()); for ( int is = 0; is < fion.size(); is++ ) fion[is].resize(3*s_.atoms.na(is)); - + sigma_eks.resize(6); sigma_kin.resize(6); sigma_ext.resize(6); @@ -133,18 +133,18 @@ void SampleStepper::compute_sigma(void) const double vx = v.x; const double vy = v.y; const double vz = v.z; - + sigma_kin[0] += mass * vx * vx; sigma_kin[1] += mass * vy * vy; sigma_kin[2] += mass * vz * vz; sigma_kin[3] += mass * vx * vy; sigma_kin[4] += mass * vy * vz; sigma_kin[5] += mass * vx * vz; - + i += 3; } } sigma_kin /= s_.wf.cell().volume(); - + sigma = sigma_eks + sigma_kin - sigma_ext; } diff --git a/src/SampleStepper.h b/src/SampleStepper.h index eca3324..fd8690b 100644 --- a/src/SampleStepper.h +++ b/src/SampleStepper.h @@ -3,7 +3,7 @@ // SampleStepper.h // //////////////////////////////////////////////////////////////////////////////// -// $Id: SampleStepper.h,v 1.10 2007-03-17 01:14:00 fgygi Exp $ +// $Id: SampleStepper.h,v 1.11 2007-10-19 16:24:05 fgygi Exp $ #ifndef SAMPLESTEPPER_H #define SAMPLESTEPPER_H @@ -20,9 +20,9 @@ typedef std::map TimerMap; class SampleStepper { protected: - + Sample& s_; - + std::vector > fion; std::valarray sigma_eks, sigma_kin, sigma_ext, sigma; @@ -32,7 +32,7 @@ class SampleStepper public: mutable TimerMap tmap; - + virtual void step(int niter) = 0; void print_stress(void); void compute_sigma(void); // compute kinetic contribution to stress diff --git a/src/SampleWriter.C b/src/SampleWriter.C index 0641bda..e2dd1ee 100644 --- a/src/SampleWriter.C +++ b/src/SampleWriter.C @@ -3,7 +3,7 @@ // SampleWriter.C: // //////////////////////////////////////////////////////////////////////////////// -// $Id: SampleWriter.C,v 1.1 2007-01-27 23:43:55 fgygi Exp $ +// $Id: SampleWriter.C,v 1.2 2007-10-19 16:24:05 fgygi Exp $ #include "SampleWriter.h" @@ -29,7 +29,7 @@ void SampleWriter::writeSample(const Sample& s, const string filename, // set default encoding string encoding = base64 ? "base64" : "text"; const char* filename_cstr = filename.c_str(); - + #if USE_CSTDIO_LFS // This section for compilers with broken large file support // As of 2003-09-30, this includes gcc-3.2, icc-7.0, pgCC-5.0 @@ -50,11 +50,11 @@ void SampleWriter::writeSample(const Sample& s, const string filename, header += string(" sample.xsd\">\n"); off_t len = header.size(); fwrite(header.c_str(),sizeof(char),len,outfile); - + string desc = string(" ") + description + string(" \n"); - + ostringstream ss(""); ss << desc; ss << s.atoms; @@ -63,14 +63,14 @@ void SampleWriter::writeSample(const Sample& s, const string filename, len = str.length(); fwrite(buf,sizeof(char),len,outfile); } - + if ( !atomsonly ) { s.wf.write(outfile,encoding,"wavefunction"); if ( s.wfv != 0 ) s.wfv->write(outfile,encoding,"wavefunction_velocity"); } - + if ( ctxt_.onpe0() ) { char *trailer = "\n"; @@ -82,24 +82,24 @@ void SampleWriter::writeSample(const Sample& s, const string filename, if ( ctxt_.onpe0() ) { os.open(filename_cstr); - cout << " " << endl; - - os + + os <<"\n" <<"" << endl; - os << " " << description + os << " " << description << " " << endl; os << s.atoms; } - + if ( !atomsonly ) { s.wf.print(os,encoding,"wavefunction"); @@ -108,7 +108,7 @@ void SampleWriter::writeSample(const Sample& s, const string filename, } if ( ctxt_.onpe0() ) - os << "" << endl; + os << "" << endl; os.close(); #endif diff --git a/src/SampleWriter.h b/src/SampleWriter.h index c238a6f..428d5f1 100644 --- a/src/SampleWriter.h +++ b/src/SampleWriter.h @@ -3,7 +3,7 @@ // SampleWriter.h // //////////////////////////////////////////////////////////////////////////////// -// $Id: SampleWriter.h,v 1.2 2007-03-17 01:14:00 fgygi Exp $ +// $Id: SampleWriter.h,v 1.3 2007-10-19 16:24:05 fgygi Exp $ #ifndef SAMPLEWRITER_H #define SAMPLEWRITER_H @@ -16,7 +16,7 @@ class SampleWriter private: const Context& ctxt_; - + public: SampleWriter(const Context& ctxt); diff --git a/src/SaveCmd.C b/src/SaveCmd.C index 5cc322c..29756d5 100644 --- a/src/SaveCmd.C +++ b/src/SaveCmd.C @@ -3,7 +3,7 @@ // SaveCmd.C: // //////////////////////////////////////////////////////////////////////////////// -// $Id: SaveCmd.C,v 1.11 2007-01-27 23:49:41 fgygi Exp $ +// $Id: SaveCmd.C,v 1.12 2007-10-19 16:24:05 fgygi Exp $ #include "SaveCmd.h" @@ -19,21 +19,21 @@ int SaveCmd::action(int argc, char **argv) if ( !(argc>=2 && argc<=4 ) ) { if ( ui->onpe0() ) - cout << " " + cout << " " << endl; return 1; } - + // set default encoding bool base64 = true; bool atomsonly = false; char* filename = 0; - + // check for -text or -base64 or -atomsonly arguments for ( int i = 1; i < argc; i++ ) { string arg(argv[i]); - + if ( arg=="-text" ) { base64 = false; @@ -49,16 +49,16 @@ int SaveCmd::action(int argc, char **argv) else { if ( ui->onpe0() ) - cout << " " + cout << " " << endl; return 1; } } - + if ( filename == 0 ) { if ( ui->onpe0() ) - cout << " " + cout << " " << endl; return 1; } diff --git a/src/SaveCmd.h b/src/SaveCmd.h index d597e63..78e89a1 100644 --- a/src/SaveCmd.h +++ b/src/SaveCmd.h @@ -3,7 +3,7 @@ // SaveCmd.h: // //////////////////////////////////////////////////////////////////////////////// -// $Id: SaveCmd.h,v 1.1 2003-03-27 22:05:59 fgygi Exp $ +// $Id: SaveCmd.h,v 1.2 2007-10-19 16:24:05 fgygi Exp $ #ifndef SAVECMD_H #define SAVECMD_H @@ -28,7 +28,7 @@ class SaveCmd : public Cmd char *help_msg(void) const { - return + return "\n save\n\n" " syntax: save filename \n\n" " The save command saves the sample to the file filename.\n\n"; diff --git a/src/SetCmd.h b/src/SetCmd.h index 6d6e24a..260be6b 100644 --- a/src/SetCmd.h +++ b/src/SetCmd.h @@ -3,7 +3,7 @@ // SetCmd.h: // //////////////////////////////////////////////////////////////////////////////// -// $Id: SetCmd.h,v 1.1 2003-01-10 00:35:36 fgygi Exp $ +// $Id: SetCmd.h,v 1.2 2007-10-19 16:24:05 fgygi Exp $ #ifndef SETCMD_H #define SETCMD_H @@ -28,7 +28,7 @@ class SetCmd : public Cmd char *help_msg(void) const { - return + return "\n set\n\n" " syntax: set variable value[s]\n\n" " The set command sets the value of an interface variable.\n\n"; @@ -44,7 +44,7 @@ class SetCmd : public Cmd Var* varptr = ui->findVar(argv[1]); - if ( varptr ) + if ( varptr ) { varptr->set(argc-1,&argv[1]); } diff --git a/src/SlaterDet.C b/src/SlaterDet.C index f80b586..882ecb2 100644 --- a/src/SlaterDet.C +++ b/src/SlaterDet.C @@ -3,7 +3,7 @@ // SlaterDet.C // //////////////////////////////////////////////////////////////////////////////// -// $Id: SlaterDet.C,v 1.38 2006-05-29 01:15:36 fgygi Exp $ +// $Id: SlaterDet.C,v 1.39 2007-10-19 16:24:05 fgygi Exp $ #include "SlaterDet.h" #include "FourierTransform.h" @@ -22,11 +22,11 @@ using namespace std; //////////////////////////////////////////////////////////////////////////////// -SlaterDet::SlaterDet(const Context& ctxt, D3vector kpoint) : ctxt_(ctxt), +SlaterDet::SlaterDet(const Context& ctxt, D3vector kpoint) : ctxt_(ctxt), c_(ctxt) { //cout << ctxt.mype() << ": SlaterDet::SlaterDet: ctxt.mycol=" - // << ctxt.mycol() << " basis_->context(): " + // << ctxt.mycol() << " basis_->context(): " // << basis_->context(); my_col_ctxt_ = 0; for ( int icol = 0; icol < ctxt_.npcol(); icol++ ) @@ -38,18 +38,18 @@ SlaterDet::SlaterDet(const Context& ctxt, D3vector kpoint) : ctxt_(ctxt), else delete col_ctxt; } - //cout << ctxt_.mype() << ": SlaterDet::SlaterDet: my_col_ctxt: " + //cout << ctxt_.mype() << ": SlaterDet::SlaterDet: my_col_ctxt: " // << *my_col_ctxt_; basis_ = new Basis(*my_col_ctxt_,kpoint); } //////////////////////////////////////////////////////////////////////////////// SlaterDet::SlaterDet(const SlaterDet& rhs) : ctxt_(rhs.context()), - basis_(new Basis(*(rhs.basis_))), + basis_(new Basis(*(rhs.basis_))), my_col_ctxt_(new Context(*(rhs.my_col_ctxt_))) , c_(rhs.c_){} - + //////////////////////////////////////////////////////////////////////////////// -SlaterDet::~SlaterDet() +SlaterDet::~SlaterDet() { delete basis_; delete my_col_ctxt_; @@ -57,7 +57,7 @@ SlaterDet::~SlaterDet() } //////////////////////////////////////////////////////////////////////////////// -void SlaterDet::resize(const UnitCell& cell, const UnitCell& refcell, +void SlaterDet::resize(const UnitCell& cell, const UnitCell& refcell, double ecut, int nst) { //!! Test in next line should be replaced by test on basis min/max indices @@ -69,24 +69,24 @@ void SlaterDet::resize(const UnitCell& cell, const UnitCell& refcell, //cout << " SlaterDet::resize: refcell=" << basis_->refcell(); //throw SlaterDetException("could not resize: cell not in refcell"); //} - + try { basis_->resize(cell,refcell,ecut); occ_.resize(nst); eig_.resize(nst); - + const int mb = basis_->maxlocalsize(); const int m = ctxt_.nprow() * mb; const int nb = nst/ctxt_.npcol() + (nst%ctxt_.npcol() > 0 ? 1 : 0); - + // Determine if plane wave coefficients must be reset after the resize // This is needed if the dimensions of the matrix c_ must be changed - const bool needs_reset = + const bool needs_reset = m!=c_.m() || nst!=c_.n() || mb!=c_.mb() || nb!=c_.nb(); - + c_.resize(m,nst,mb,nb); - + if ( needs_reset ) reset(); } @@ -105,7 +105,7 @@ void SlaterDet::reset(void) // initialize c_ c_.clear(); const double s2i = 1.0 / sqrt(2.0); - + // for each n, find the smallest g vector and initialize int ismallest = 0; // on each process, basis.isort(ismallest) is the index of the smallest @@ -115,14 +115,14 @@ void SlaterDet::reset(void) double value = 1.0; if ( basis().real() && n != 0 ) value = s2i; - + // find process row holding the smallest g vector - double g2 = basis_->g2(basis_->isort(ismallest)); - // cout << "smallest vector on proc " << ctxt_.mype() - // << " has norm " << g2 << endl; + double kpg2 = basis_->kpg2(basis_->isort(ismallest)); + // cout << "smallest vector k+G on proc " << ctxt_.mype() + // << " has norm " << kpg2 << endl; int minrow, mincol; - ctxt_.dmin('c',' ',1,1,&g2,1,&minrow,&mincol,1,-1,-1); - + ctxt_.dmin('c',' ',1,1,&kpg2,1,&minrow,&mincol,1,-1,-1); + // find column hosting state n int pc = c_.pc(n); int pr = minrow; @@ -137,7 +137,7 @@ void SlaterDet::reset(void) // << " vector " << basis_->idx(3*iii) << " " // << basis_->idx(3*iii+1) << " " // << basis_->idx(3*iii+2) << " norm=" - // << basis_->g2(iii) << " " + // << basis_->kpg2(iii) << " " // << value << endl; int jjj = c_.m(n) * c_.nb() + c_.y(n); int index = iii+c_.mloc()*jjj; @@ -149,18 +149,18 @@ void SlaterDet::reset(void) } //////////////////////////////////////////////////////////////////////////////// -void SlaterDet::compute_density(FourierTransform& ft, +void SlaterDet::compute_density(FourierTransform& ft, double weight, double* rho) const { //Timer tm_ft, tm_rhosum; // compute density of the states residing on my column of ctxt_ assert(occ_.size() == c_.n()); vector > tmp(ft.np012loc()); - + assert(basis_->cell().volume() > 0.0); const double omega_inv = 1.0 / basis_->cell().volume(); const int np012loc = ft.np012loc(); - + for ( int i = 0; i < np012loc; i++ ) rho[i] = 0.0; @@ -173,7 +173,7 @@ void SlaterDet::compute_density(FourierTransform& ft, const int nn = ctxt_.mycol() * c_.nb() + n; const double fac1 = omega_inv * occ_[nn]; const double fac2 = omega_inv * occ_[nn+1]; - + if ( fac1 + fac2 > 0.0 ) { //tm_ft.start(); @@ -199,7 +199,7 @@ void SlaterDet::compute_density(FourierTransform& ft, // global n index const int nn = ctxt_.mycol() * c_.nb() + n; const double fac1 = omega_inv * occ_[nn]; - + if ( fac1 > 0.0 ) { ft.backward(c_.cvalptr(n*c_.mloc()),&tmp[0]); @@ -222,7 +222,7 @@ void SlaterDet::compute_density(FourierTransform& ft, // global n index const int nn = ctxt_.mycol() * c_.nb() + n; const double fac = omega_inv * occ_[nn]; - + if ( fac > 0.0 ) { ft.backward(c_.cvalptr(n*c_.mloc()),&tmp[0]); @@ -231,23 +231,23 @@ void SlaterDet::compute_density(FourierTransform& ft, } } } - // cout << "SlaterDet: compute_density: ft_bwd time: " + // cout << "SlaterDet: compute_density: ft_bwd time: " // << tm_ft.real() << endl; - // cout << "SlaterDet: compute_density: rhosum time: " + // cout << "SlaterDet: compute_density: rhosum time: " // << tm_rhosum.real() << endl; } //////////////////////////////////////////////////////////////////////////////// -void SlaterDet::rs_mul_add(FourierTransform& ft, +void SlaterDet::rs_mul_add(FourierTransform& ft, const double* v, SlaterDet& sdp) const { // transform states to real space, multiply states by v[r] in real space // transform back to reciprocal space and add to sdp // sdp[n] += v * sd[n] - + vector > tmp(ft.np012loc()); vector > ctmp(2*c_.mloc()); - + const int np012loc = ft.np012loc(); const int mloc = c_.mloc(); double* p = (double*) &tmp[0]; @@ -311,7 +311,7 @@ void SlaterDet::rs_mul_add(FourierTransform& ft, daxpy(&len,&alpha,(double*)&ctmp[0],&inc1,&dcp[2*n*mloc],&inc1); } } - + } //////////////////////////////////////////////////////////////////////////////// @@ -323,7 +323,7 @@ void SlaterDet::gram(void) // create a DoubleMatrix proxy for c_ DoubleMatrix c_proxy(c_); DoubleMatrix s(ctxt_,c_.n(),c_.n(),c_.nb(),c_.nb()); - s.syrk('l','t',2.0,c_proxy,0.0); + s.syrk('l','t',2.0,c_proxy,0.0); s.syr('l',-1.0,c_proxy,0,'r'); #ifdef CHOLESKY_REMAP // create a square context for the Cholesky decomposition @@ -361,15 +361,15 @@ void SlaterDet::riccati(SlaterDet& sd) DoubleMatrix r(ctxt_,c_.n(),c_.n(),c_.nb(),c_.nb()); s.identity(); r.identity(); - + DoubleMatrix x(ctxt_,c_.n(),c_.n(),c_.nb(),c_.nb()); DoubleMatrix xm(ctxt_,c_.n(),c_.n(),c_.nb(),c_.nb()); DoubleMatrix t(ctxt_,c_.n(),c_.n(),c_.nb(),c_.nb()); - + // DoubleMatrix proxy for c_ and sd.c() DoubleMatrix c_proxy(c_); DoubleMatrix sdc_proxy(sd.c()); - + // Factor -1.0 in next line: -0.5 from definition of s, 2.0 for G and -G s.syrk('l','t',-1.0,c_proxy,0.5); // s = 0.5 * ( I - A ) // symmetric rank-1 update using first row of c_proxy @@ -378,18 +378,18 @@ void SlaterDet::riccati(SlaterDet& sd) r.gemm('t','n',-2.0,sdc_proxy,c_proxy,1.0); // r = ( I - B ) // rank-1 update using first row of sdc_proxy() and c_proxy r.ger(1.0,sdc_proxy,0,c_proxy,0); - + xm = s; xm.symmetrize('l'); - + s.syrk('l','t',0.5,r,1.0); // s = s + 0.5 * r^T * r s.symmetrize('l'); - + double diff = 1.0; const double epsilon = 1.e-10; const int maxiter = 20; int iter = 0; - + while ( iter < maxiter && diff > epsilon ) { // x = s - 0.5 * ( r - xm )^T * ( r - xm ) @@ -397,18 +397,18 @@ void SlaterDet::riccati(SlaterDet& sd) for ( int i = 0; i < t.size(); i++ ) t[i] = r[i] - xm[i]; - + x = s; x.syrk('l','t',-0.5,t,1.0); - + // get full matrix x x.symmetrize('l'); - + for ( int i = 0; i < t.size(); i++ ) t[i] = x[i] - xm[i]; - + diff = t.nrm2(); - + xm = x; iter++; } @@ -421,28 +421,28 @@ void SlaterDet::riccati(SlaterDet& sd) ComplexMatrix r(ctxt_,c_.n(),c_.n(),c_.nb(),c_.nb()); s.identity(); r.identity(); - + ComplexMatrix x(ctxt_,c_.n(),c_.n(),c_.nb(),c_.nb()); ComplexMatrix xm(ctxt_,c_.n(),c_.n(),c_.nb(),c_.nb()); ComplexMatrix t(ctxt_,c_.n(),c_.n(),c_.nb(),c_.nb()); - + // s = 0.5 * ( I - A ) s.herk('l','c',-0.5,c_,0.5); // r = ( I - B ) r.gemm('c','n',-1.0,sd.c(),c_,1.0); - + xm = s; xm.symmetrize('l'); - + // s = s + 0.5 * r^H * r s.herk('l','c',0.5,r,1.0); s.symmetrize('l'); - + double diff = 1.0; const double epsilon = 1.e-10; const int maxiter = 20; int iter = 0; - + while ( iter < maxiter && diff > epsilon ) { // x = s - 0.5 * ( r - xm )^H * ( r - xm ) @@ -450,23 +450,23 @@ void SlaterDet::riccati(SlaterDet& sd) for ( int i = 0; i < t.size(); i++ ) t[i] = r[i] - xm[i]; - + x = s; x.herk('l','c',-0.5,t,1.0); x.symmetrize('l'); - + for ( int i = 0; i < t.size(); i++ ) t[i] = x[i] - xm[i]; - + diff = t.nrm2(); - + xm = x; iter++; } c_.hemm('r','l',1.0,x,sd.c(),1.0); } } - + //////////////////////////////////////////////////////////////////////////////// void SlaterDet::lowdin(void) { @@ -480,75 +480,75 @@ void SlaterDet::lowdin(void) DoubleMatrix x(ctxt_,c_.n(),c_.n(),c_.nb(),c_.nb()); DoubleMatrix xp(ctxt_,c_.n(),c_.n(),c_.nb(),c_.nb()); DoubleMatrix t(ctxt_,c_.n(),c_.n(),c_.nb(),c_.nb()); - + l.clear(); - l.syrk('l','t',2.0,c_proxy,0.0); + l.syrk('l','t',2.0,c_proxy,0.0); l.syr('l',-1.0,c_proxy,0,'r'); - + //cout << "SlaterDet::lowdin: A=\n" << l << endl; - + // Cholesky decomposition of A=Y^T Y l.potrf('l'); // The lower triangle of l now contains the Cholesky factor of Y^T Y //cout << "SlaterDet::lowdin: L=\n" << l << endl; - + // Compute the polar decomposition of R = L^T x.transpose(1.0,l,0.0); // x now contains R //cout << "SlaterDet::lowdin: R=\n" << x << endl; - + double diff = 1.0; const double epsilon = 1.e-10; const int maxiter = 20; int iter = 0; - + while ( iter < maxiter && diff > epsilon ) { // t = X^T t.transpose(1.0,x,0.0); t.inverse(); - + // t now contains X^-T - + // xp = 0.5 * ( x + x^-T ); for ( int i = 0; i < x.size(); i++ ) xp[i] = 0.5 * ( x[i] + t[i] ); - - + + // Next lines: use t as temporary to compute || x - xp ||_F for ( int i = 0; i < t.size(); i++ ) t[i] = x[i] - xp[i]; - + diff = t.nrm2(); - + //cout << " SlaterDet::lowdin: diff=" << diff << endl; - + x = xp; //cout << "SlaterDet::lowdin: X=\n" << x << endl; - + iter++; } - - // x now contains the orthogonal polar factor U of the + + // x now contains the orthogonal polar factor U of the // polar decomposition R = UH - + //cout << " SlaterDet::lowdin: orthogonal polar factor=\n" << x << endl; - + // Compute L^-1 l.trtri('l','n'); // l now contains L^-1 - + // Form the product L^-T U t.gemm('t','n',1.0,l,x,0.0); - + // Multiply c by L^-T U c_proxy.gemm('n','n',1.0,c_tmp_proxy,t,0.0); - + } else - { + { // complex case: not implemented assert(false); } @@ -569,20 +569,20 @@ void SlaterDet::ortho_align(const SlaterDet& sd) DoubleMatrix x(ctxt_,c_.n(),c_.n(),c_.nb(),c_.nb()); DoubleMatrix xp(ctxt_,c_.n(),c_.n(),c_.nb(),c_.nb()); DoubleMatrix t(ctxt_,c_.n(),c_.n(),c_.nb(),c_.nb()); - + #if TIMING tmap["syrk"].reset(); tmap["syrk"].start(); #endif l.clear(); - l.syrk('l','t',2.0,c_proxy,0.0); + l.syrk('l','t',2.0,c_proxy,0.0); l.syr('l',-1.0,c_proxy,0,'r'); #if TIMING tmap["syrk"].stop(); #endif - + //cout << "SlaterDet::ortho_align: A=\n" << l << endl; - + // Cholesky decomposition of A=Y^T Y #if TIMING tmap["potrf"].reset(); @@ -595,10 +595,10 @@ void SlaterDet::ortho_align(const SlaterDet& sd) // The lower triangle of l now contains the Cholesky factor of Y^T Y //cout << "SlaterDet::ortho_align: L=\n" << l << endl; - + // Compute the polar decomposition of L^-1 B // where B = C^T sd.C - + // Compute B: store result in x #if TIMING tmap["gemm"].reset(); @@ -611,7 +611,7 @@ void SlaterDet::ortho_align(const SlaterDet& sd) #if TIMING tmap["gemm"].stop(); #endif - + // Form the product L^-1 B, store result in x // triangular solve: L X = B // trtrs: solve op(*this) * X = Z, output in Z @@ -626,13 +626,13 @@ void SlaterDet::ortho_align(const SlaterDet& sd) // x now contains L^-1 B //cout << "SlaterDet::ortho_align: L^-1 B=\n" << x << endl; - + // compute the polar decomposition of L^-1 B double diff = 1.0; const double epsilon = 1.e-10; const int maxiter = 20; int iter = 0; - + #if TIMING tmap["transpose"].reset(); tmap["inverse"].reset(); @@ -652,18 +652,18 @@ void SlaterDet::ortho_align(const SlaterDet& sd) #if TIMING tmap["inverse"].stop(); #endif - + // t now contains X^-T - + // xp = 0.5 * ( x + x^-T ); for ( int i = 0; i < x.size(); i++ ) xp[i] = 0.5 * ( x[i] + t[i] ); - - + + // Next lines: use t as temporary to compute || x - xp ||_F for ( int i = 0; i < t.size(); i++ ) t[i] = x[i] - xp[i]; - + #if TIMING tmap["nrm2"].start(); #endif @@ -671,21 +671,21 @@ void SlaterDet::ortho_align(const SlaterDet& sd) #if TIMING tmap["nrm2"].stop(); #endif - + //cout << " SlaterDet::ortho_align: diff=" << diff << endl; - + x = xp; //cout << "SlaterDet::ortho_align: X=\n" << x << endl; - + iter++; } - - // x now contains the orthogonal polar factor X of the + + // x now contains the orthogonal polar factor X of the // polar decomposition L^-1 B = XH - - //cout << " SlaterDet::ortho_align: orthogonal polar factor=\n" + + //cout << " SlaterDet::ortho_align: orthogonal polar factor=\n" // << x << endl; - + // Form the product L^-T Q // Solve trans(L) Z = X #if TIMING @@ -696,9 +696,9 @@ void SlaterDet::ortho_align(const SlaterDet& sd) #if TIMING tmap["trtrs2"].stop(); #endif - + // x now contains L^-T Q - + // Multiply c by L^-T Q #if TIMING tmap["gemm2"].reset(); @@ -708,10 +708,10 @@ void SlaterDet::ortho_align(const SlaterDet& sd) #if TIMING tmap["gemm2"].stop(); #endif - + } else - { + { // complex case: not implemented assert(false); } @@ -746,78 +746,78 @@ void SlaterDet::align(const SlaterDet& sd) DoubleMatrix x(ctxt_,c_.n(),c_.n(),c_.nb(),c_.nb()); DoubleMatrix xp(ctxt_,c_.n(),c_.n(),c_.nb(),c_.nb()); DoubleMatrix t(ctxt_,c_.n(),c_.n(),c_.nb(),c_.nb()); - - + + // Compute the polar decomposition of B // where B = C^T sd.C - + // Compute B: store result in x // factor -2.0 in next line: G and -G x.gemm('t','n',2.0,c_proxy,sdc_proxy,0.0); // rank-1 update using first row of sdc_proxy() and c_proxy x.ger(-1.0,c_proxy,0,sdc_proxy,0); - + // x now contains B //cout << "SlaterDet::align: B=\n" << x << endl; - + // Compute the distance | c - sdc | before alignment //for ( int i = 0; i < c_proxy.size(); i++ ) // c_tmp_proxy[i] = c_proxy[i] - sdc_proxy[i]; //cout << " SlaterDet::align: distance before: " // << c_tmp_proxy.nrm2() << endl; - + // compute the polar decomposition of B double diff = 1.0; const double epsilon = 1.e-10; const int maxiter = 20; int iter = 0; - + while ( iter < maxiter && diff > epsilon ) { // t = X^T t.transpose(1.0,x,0.0); t.inverse(); - + // t now contains X^-T - + // xp = 0.5 * ( x + x^-T ); for ( int i = 0; i < x.size(); i++ ) xp[i] = 0.5 * ( x[i] + t[i] ); - - + + // Next lines: use t as temporary to compute || x - xp ||_F //for ( int i = 0; i < t.size(); i++ ) // t[i] = x[i] - xp[i]; - + //diff = t.nrm2(); - + //cout << " SlaterDet::align: diff=" << diff << endl; - + x = xp; //cout << "SlaterDet::align: X=\n" << x << endl; - + iter++; } - - // x now contains the orthogonal polar factor X of the + + // x now contains the orthogonal polar factor X of the // polar decomposition B = XH - + //cout << " SlaterDet::align: orthogonal polar factor=\n" << x << endl; - + // Multiply c by X c_tmp_proxy = c_proxy; c_proxy.gemm('n','n',1.0,c_tmp_proxy,x,0.0); - + // Compute the distance | c - sdc | after alignment //for ( int i = 0; i < c_proxy.size(); i++ ) // c_tmp_proxy[i] = c_proxy[i] - sdc_proxy[i]; //cout << " SlaterDet::align: distance after: " // << c_tmp_proxy.nrm2() << endl; - + } else - { + { // complex case: not implemented assert(false); } @@ -834,7 +834,7 @@ double SlaterDet::dot(const SlaterDet& sd) const const DoubleMatrix sdc_proxy(sd.c()); // factor 2.0: G and -G double d = 2.0 * c_proxy.dot(sdc_proxy); - + // correct double counting of first element double sum = 0.0; if ( ctxt_.myrow() == 0 ) @@ -983,36 +983,36 @@ double SlaterDet::ortho_error(void) // k = 0 case // declare a proxy DoubleMatrix for c_ DoubleMatrix c_proxy(c_); - + DoubleMatrix s(ctxt_,c_.n(),c_.n(),c_.nb(),c_.nb()); - + // real symmetric rank-k update // factor 2.0 in next line: G and -G s.syrk('l','t',2.0,c_proxy,0.0); // compute real overlap matrix - + // correct for double counting of G=0 // symmetric rank-1 update using first row of c_proxy s.syr('l',-1.0,c_proxy,0,'r'); - + DoubleMatrix id(ctxt_,s.m(),s.n(),s.mb(),s.nb()); id.identity(); - + s -= id; // subtract identity matrix from S - + error = s.nrm2(); } else { // k != 0 case - + ComplexMatrix s(ctxt_,c_.n(),c_.n(),c_.nb(),c_.nb()); s.herk('l','c',1.0,c_,0.0); - + ComplexMatrix id(ctxt_,s.m(),s.n(),s.mb(),s.nb()); id.identity(); - + s -= id; // subtract identity matrix from S - + error = s.nrm2(); } return error; @@ -1042,11 +1042,11 @@ void SlaterDet::randomize(double amplitude) //////////////////////////////////////////////////////////////////////////////// void SlaterDet::cleanup(void) { - // set Im( c(G=0) ) to zero and + // set Im( c(G=0) ) to zero and // set the empty rows of the matrix c_ to zero - // The empty rows are located between i = basis_->localsize() and - // c_.mloc(). Empty rows are necessary to insure that the - // local size c_.mloc() is the same on all processes, while the + // The empty rows are located between i = basis_->localsize() and + // c_.mloc(). Empty rows are necessary to insure that the + // local size c_.mloc() is the same on all processes, while the // local basis size is not. for ( int n = 0; n < c_.nloc(); n++ ) { @@ -1060,7 +1060,7 @@ void SlaterDet::cleanup(void) izero = 0; else izero = basis_->rod_size(0)/2; - //cout << " izero = " << izero << " G = " << basis_->kv(3*izero) << " " + //cout << " izero = " << izero << " G = " << basis_->kv(3*izero) << " " // << basis_->kv(3*izero+1) << " " << basis_->kv(3*izero+2) << endl; p[izero] = complex ( p[izero].real(), 0.0); } @@ -1100,7 +1100,7 @@ void SlaterDet::print(ostream& os, string encoding) vector > wftmp(ft.np012loc()); vector wftmpr(ft.np012()); Base64Transcoder xcdr; - + if ( ctxt_.onpe0() ) { const double weight = 1.0; //!! fixed determinant weight to 1.0 @@ -1108,8 +1108,8 @@ void SlaterDet::print(ostream& os, string encoding) os << "kpoint() << "\"\n" << " weight=\"" << weight << "\"" << " size=\"" << nst() << "\">" << endl; - - os << "" + + os << "" << endl; os.setf(ios::fixed,ios::floatfield); os.setf(ios::right,ios::adjustfield); @@ -1123,31 +1123,31 @@ void SlaterDet::print(ostream& os, string encoding) os << endl; os << "" << endl; } - + for ( int n = 0; n < nst(); n++ ) { - // Barrier to limit the number of messages sent to task 0 + // Barrier to limit the number of messages sent to task 0 // that don't have a receive posted ctxt_.barrier(); - + // transform data on ctxt_.mycol() if ( c_.pc(n) == ctxt_.mycol() ) { - //cout << " state " << n << " is stored on column " + //cout << " state " << n << " is stored on column " // << ctxt_.mycol() << " local index: " << c_.y(n) << endl; int nloc = c_.y(n); // local index ft.backward(c_.cvalptr(c_.mloc()*nloc),&wftmp[0]); - + double *a = (double*) &wftmp[0]; for ( int i = 0; i < ft.np012loc(); i++ ) wftmpr[i] = a[2*i]; } - + // send blocks of wftmpr to pe0 for ( int i = 0; i < ctxt_.nprow(); i++ ) { bool iamsending = c_.pc(n) == ctxt_.mycol() && i == ctxt_.myrow(); - + // send size of wftmpr block int size=-1; if ( ctxt_.onpe0() ) @@ -1167,7 +1167,7 @@ void SlaterDet::print(ostream& os, string encoding) ctxt_.isend(1,1,&size,1,0,0); } } - + // send wftmpr block if ( ctxt_.onpe0() ) { @@ -1190,7 +1190,7 @@ void SlaterDet::print(ostream& os, string encoding) } } - // process the data + // process the data if ( ctxt_.onpe0() ) { // wftmpr is now complete on task 0 @@ -1250,7 +1250,7 @@ void SlaterDet::write(FILE* outfile, string encoding) vector wftmpr(ft.np012()); Base64Transcoder xcdr; ostringstream os; - + if ( ctxt_.onpe0() ) { const double weight = 1.0; //!! fixed determinant weight to 1.0 @@ -1258,8 +1258,8 @@ void SlaterDet::write(FILE* outfile, string encoding) os << "kpoint() << "\"\n" << " weight=\"" << weight << "\"" << " size=\"" << nst() << "\">" << endl; - - os << "" + + os << "" << endl; os.setf(ios::fixed,ios::floatfield); os.setf(ios::right,ios::adjustfield); @@ -1272,36 +1272,36 @@ void SlaterDet::write(FILE* outfile, string encoding) if ( nst()%10 != 0 ) os << endl; os << "" << endl; - + string str(os.str()); off_t len = str.length(); fwrite(str.c_str(),sizeof(char),len,outfile); } - + for ( int n = 0; n < nst(); n++ ) { - // Barrier to limit the number of messages sent to task 0 + // Barrier to limit the number of messages sent to task 0 // that don't have a receive posted ctxt_.barrier(); - + // transform data on ctxt_.mycol() if ( c_.pc(n) == ctxt_.mycol() ) { - //cout << " state " << n << " is stored on column " + //cout << " state " << n << " is stored on column " // << ctxt_.mycol() << " local index: " << c_.y(n) << endl; int nloc = c_.y(n); // local index ft.backward(c_.cvalptr(c_.mloc()*nloc),&wftmp[0]); - + double *a = (double*) &wftmp[0]; for ( int i = 0; i < ft.np012loc(); i++ ) wftmpr[i] = a[2*i]; } - + // send blocks of wftmpr to pe0 for ( int i = 0; i < ctxt_.nprow(); i++ ) { bool iamsending = c_.pc(n) == ctxt_.mycol() && i == ctxt_.myrow(); - + // send size of wftmpr block int size=-1; if ( ctxt_.onpe0() ) @@ -1321,7 +1321,7 @@ void SlaterDet::write(FILE* outfile, string encoding) ctxt_.isend(1,1,&size,1,0,0); } } - + // send wftmpr block if ( ctxt_.onpe0() ) { @@ -1343,7 +1343,7 @@ void SlaterDet::write(FILE* outfile, string encoding) } } } - + // process data if ( ctxt_.onpe0() ) { @@ -1354,27 +1354,27 @@ void SlaterDet::write(FILE* outfile, string encoding) #if PLT_BIG_ENDIAN xcdr.byteswap_double(ft.np012(),&wftmpr[0]); #endif - + int nbytes = ft.np012()*sizeof(double); int outlen = xcdr.nchars(nbytes); char* b = new char[outlen]; assert(b!=0); xcdr.encode(nbytes,(byte*) &wftmpr[0],b); - + // Note: optional x0,y0,z0 attributes not used, default is zero os.str(""); os << "" << endl; - + string str(os.str()); off_t len = str.length(); fwrite(str.c_str(),sizeof(char),len,outfile); - - // write buffer b inserting newlines + + // write buffer b inserting newlines xcdr.print(outlen, b, outfile); - + os.str(""); os << "\n"; str = os.str(); @@ -1422,7 +1422,7 @@ void SlaterDet::write(FILE* outfile, string encoding) } } - + if ( ctxt_.onpe0() ) { os.str(""); @@ -1436,7 +1436,7 @@ void SlaterDet::write(FILE* outfile, string encoding) //////////////////////////////////////////////////////////////////////////////// void SlaterDet::info(ostream& os) -{ +{ if ( ctxt_.onpe0() ) { const double weight = 1.0; //!! fixed determinant weight to 1.0 @@ -1451,7 +1451,7 @@ void SlaterDet::info(ostream& os) os << " " << endl; - os << " " + os << " " << endl; os << " " << endl; os << "" << endl; diff --git a/src/SlaterDet.h b/src/SlaterDet.h index 6e75e52..0cb27f1 100644 --- a/src/SlaterDet.h +++ b/src/SlaterDet.h @@ -3,7 +3,7 @@ // SlaterDet.h // //////////////////////////////////////////////////////////////////////////////// -// $Id: SlaterDet.h,v 1.19 2007-03-17 01:14:00 fgygi Exp $ +// $Id: SlaterDet.h,v 1.20 2007-10-19 16:24:05 fgygi Exp $ #ifndef SLATERDET_H #define SLATERDET_H @@ -35,12 +35,12 @@ class SlaterDet ComplexMatrix c_; std::vector occ_; std::vector eig_; - + void byteswap_double(size_t n, double* x); double fermi(double e, double mu, double fermitemp); public: - + mutable TimerMap tmap; SlaterDet(const Context& ctxt, D3vector kpoint); @@ -82,7 +82,7 @@ class SlaterDet void set_eig(std::vector& eig) { assert(eig_.size()==eig.size()); eig_ = eig; } void set_eig(std::valarray& eig) - { assert(eig_.size()==eig.size()); + { assert(eig_.size()==eig.size()); for ( int i = 0; i < eig.size(); i++ ) eig_[i] = eig[i]; } diff --git a/src/Species.C b/src/Species.C index ed2bf28..3a65d6e 100644 --- a/src/Species.C +++ b/src/Species.C @@ -3,7 +3,7 @@ // Species.C: // //////////////////////////////////////////////////////////////////////////////// -// $Id: Species.C,v 1.9 2007-09-30 04:46:11 fgygi Exp $ +// $Id: Species.C,v 1.10 2007-10-19 16:24:05 fgygi Exp $ #include "Species.h" #include "spline.h" @@ -26,7 +26,7 @@ static double simpsn ( int n, double *t ) c1 * ( t[1] + t[n-2] ) + c2 * ( t[2] + t[n-3] ) + c3 * ( t[3] + t[n-4] ); - + for ( int i = 4; i < n-4; i++ ) { sum += t[i]; @@ -36,19 +36,19 @@ static double simpsn ( int n, double *t ) //////////////////////////////////////////////////////////////////////////////// Species::Species(const Context& ctxt, string name) : ctxt_(ctxt), name_(name), -zval_(-1), mass_(0.0), lmax_(-1), deltar_(0.0), atomic_number_(0), +zval_(-1), mass_(0.0), lmax_(-1), deltar_(0.0), atomic_number_(0), llocal_(-1), nquad_(-1), rquad_(0.0), rcps_(0.0), uri_(""), description_("undefined"), symbol_("Undef") {} - + //////////////////////////////////////////////////////////////////////////////// bool Species::initialize(double rcpsval) { // initialize the Species rcps_ = rcpsval; - + assert(description_ != "undefined"); - + const double fpi = 4.0 * M_PI; const int np = vps_[0].size(); @@ -56,23 +56,23 @@ bool Species::initialize(double rcpsval) if (rcps_ < 0.0) throw SpeciesInitException("rcps_ < 0"); if (mass_ < 0.0) throw SpeciesInitException("mass_ < 0"); if (lmax_ < 0 || lmax_ > 3) throw SpeciesInitException("lmax_ <0 or lmax_ >3"); - + if (vps_.size() < lmax_+1) throw SpeciesInitException("vps_.size < lmax_+1"); - if (llocal_ < 0 || llocal_ > lmax_) + if (llocal_ < 0 || llocal_ > lmax_) throw SpeciesInitException("llocal_ < 0 || llocal_ > lmax_"); - + if ( nquad_ == 0 ) // KB potential { for ( int l = 0; l <= lmax_; l++ ) if ( l != llocal_ && phi_[l].size() == 0 ) throw SpeciesInitException("phi_[l] undefined for non-local projector"); } - + if ( nquad_ < 0 ) throw SpeciesInitException("nquad < 0"); - if ( nquad_ > 0 && rquad_ <= 0.0 ) + if ( nquad_ > 0 && rquad_ <= 0.0 ) throw SpeciesInitException("semilocal with rquad_ <= 0"); - + // compute number of non-local projectors nlm_ nlm_ = 0; for ( int l = 0; l <= lmax_; l++ ) @@ -82,7 +82,7 @@ bool Species::initialize(double rcpsval) nlm_ += 2 * l + 1; } } - + // compute ndft_: size of radial FFT array // ndft_ is the second power of 2 larger than np ndft_ = 1; @@ -97,14 +97,14 @@ bool Species::initialize(double rcpsval) } } ndft_ *= 2; - + rps_.resize(ndft_); for ( int i = 0; i < ndft_; i++ ) rps_[i] = i * deltar_; - + vps_spl_.resize(lmax_+1); phi_spl_.resize(lmax_+1); - + for ( int l = 0; l <= lmax_; l++ ) { vps_[l].resize(ndft_); @@ -112,31 +112,31 @@ bool Species::initialize(double rcpsval) vps_spl_[l].resize(ndft_); phi_spl_[l].resize(ndft_); } - + // extend rps and vps_ to full mesh (up to i==ndft_-1) - + vector fint(ndft_); - + wsg_.resize(lmax_+1); gspl_.resize(ndft_); vlocg_.resize(ndft_); vlocg_spl.resize(ndft_); - + vnlg_.resize(lmax_+1); vnlg_spl.resize(lmax_+1); - + vector vlocr(ndft_); vector > vnlr(lmax_+1); - + for ( int l = 0; l <= lmax_; l++ ) { vnlr[l].resize(ndft_); vnlg_[l].resize(ndft_+1); vnlg_spl[l].resize(ndft_+1); } - + // Extend vps_[l][i] up to ndft_ using -zv/r - + for ( int l = 0; l <= lmax_; l++ ) { for ( int i = np; i < ndft_; i++ ) @@ -158,7 +158,7 @@ bool Species::initialize(double rcpsval) spline(ndft_,&rps_[0],&phi_[l][0],0.0,0.0,0,1,&phi_spl_[l][0]); } } - + // local potential: subtract the long range part due to the smeared charge // Next line: constant is 2/sqrt(pi) // math.h: # define M_2_SQRTPI 1.12837916709551257390 /* 2/sqrt(pi) */ @@ -259,7 +259,7 @@ bool Species::initialize(double rcpsval) // w_2(G) = Ylm(G) i^-2 ( 3/G^3 \sum_r sin(Gr)/r vnlr - // 1/G \sum_r sin(Gr)*r vnlr - // 3/G^2 \sum_r cos(Gr) vnlr ) - + for ( int i = 0; i < ndft_; i++ ) { vnlr[l][i] = fpi * deltar_ * @@ -270,9 +270,9 @@ bool Species::initialize(double rcpsval) } // compute radial Fouri_er transforms of vnlr - + // Next line: vnlg_ is dimensioned ndft_+1 since it is passed to cosft1 - + // Non-local potentials // // w(G) = Ylm(G) i^l 4 pi \int r^2 phi_l(r) j_l(Gr) v_l(r) dr @@ -312,7 +312,7 @@ bool Species::initialize(double rcpsval) { vnlg_[l][i] = vnlr[l][i] * rps_[i]; } - + sinft(ndft_,&vnlg_[l][0]); vnlg_[l][0] = v0; @@ -363,7 +363,7 @@ bool Species::initialize(double rcpsval) // N.B. Next line: Initialize also vnlg_[l][ndft_] to zero // since it is used and modified by cosft1 // vnlg_ was dimensioned ndft_[is]+1 - + vnlg_[l][ndft_] = 0.0; cosft1(ndft_,&vnlg_[l][0]); @@ -433,7 +433,7 @@ bool Species::initialize(double rcpsval) // N.B. Next line: Initialize also vnlg_[l][ndft_] to zero // since it is used and modified by cosft1 // vnlg_ was dimensioned ndft_[is]+1 - + vnlg_[l][ndft_] = 0.0; cosft1(ndft_,&vnlg_[l][0]); @@ -443,7 +443,7 @@ bool Species::initialize(double rcpsval) { fint[i] += - 3.0 * vnlg_[l][i] / (gspl_[i] * gspl_[i]); } - + vnlg_[l][0] = v0; for ( int i = 1; i < ndft_; i++ ) { @@ -562,7 +562,7 @@ ostream& operator << ( ostream &os, Species &s ) // If the uri is known, use href to refer to it if ( s.uri() != "" ) { - os <<"" << endl; } else @@ -584,7 +584,7 @@ ostream& operator << ( ostream &os, Species &s ) for ( int l = 0; l <= s.lmax(); l++ ) { const int size = s.vps()[l].size(); - os << "" << endl; os << "\n"; for ( int i = 0; i < size; i++ ) @@ -602,7 +602,7 @@ ostream& operator << ( ostream &os, Species &s ) os << "" << endl; os << "" << endl; } - + return os; } @@ -632,13 +632,13 @@ void Species::info(ostream &os) os << " local (within 1.e-4) beyond r = " << rcut_loc(1.e-4) << endl; os << " local (within 1.e-3) beyond r = " << rcut_loc(1.e-3) << endl; } - + os << " valence charge = " << zval() << " / ionic mass_ = " << mass() << " (amu)" << endl; os << " lmax_ = " << lmax() << endl; os << " llocal_ = " << llocal() << endl; - os << " rcps_ = " << rcps() << endl; + os << " rcps_ = " << rcps() << endl; os.setf(ios::right,ios::adjustfield); } @@ -663,6 +663,6 @@ double Species::rcut_loc(double epsilon) } // adjust i so that delta_v[i] < epsilon if ( i < ndft_-1 ) i++; - + return rps_[i]; } diff --git a/src/Species.h b/src/Species.h index 5d3bfff..0e36e3c 100644 --- a/src/Species.h +++ b/src/Species.h @@ -3,7 +3,7 @@ // Species.h: // //////////////////////////////////////////////////////////////////////////////// -// $Id: Species.h,v 1.6 2007-09-30 04:46:11 fgygi Exp $ +// $Id: Species.h,v 1.7 2007-10-19 16:24:05 fgygi Exp $ #ifndef SPECIES_H #define SPECIES_H @@ -17,25 +17,25 @@ class Species { private: - + const Context& ctxt_; - int nlm_; // number of non-local projectors: + int nlm_; // number of non-local projectors: int ndft_; - + std::vector > vps_spl_, phi_spl_; std::vector gspl_, vlocg_, vlocg_spl; std::vector > vnlg_, vnlg_spl; std::vector wsg_; // wsg_[l] Kleinman-Bylander weight 1/ - + std::vector rps_; // radial linear mesh (same for all l) - + std::string name_; // name used to refer to species in current application std::string uri_; // uri of the resource defining the pseudopotential std::string symbol_; int atomic_number_; double mass_; // mass in a.m.u (Carbon = 12.0) - + std::string description_; // description of the pseudopotential int zval_; // valence charge int lmax_; // largest angular momentum @@ -46,11 +46,11 @@ class Species std::vector > vps_; // potentials for each l std::vector > phi_; // atomic wavefunctions for each l double rcps_; // cutoff radius of gaussian pseudocharge - + public: Species(const Context& ctxt, std::string name); - + const Context& context(void) const { return ctxt_; } const std::string& name(void) const { return name_; } const std::string& symbol(void) const { return symbol_; } @@ -68,14 +68,14 @@ class Species // number of non-local projectors sum_(l!=llocal) (2*l+1) int nlm(void) { return nlm_; } - + bool non_local(void) { return lmax_ > 0; }; double eself(void) { return zval_ * zval_ / ( sqrt ( 2.0 * M_PI ) * rcps_ ); }; void phi(int l, double r, double &val); // phi(l,r) in r space void vpsr(int l, double r, double &v); // Vps(l,r) in r space - void dvpsr(int l, double r, double &v, double &dv); // Vps and dVps/dr + void dvpsr(int l, double r, double &v, double &dv); // Vps and dVps/dr void vlocg(double q, double &v); // Vloc(g) void dvlocg(double q, double &v, double &dv); // Vloc(g) and dVloc/dg void vnlg(int l, double q, double &v); // Vnl(l,g) @@ -83,16 +83,16 @@ class Species double rhopsg(double q); // pseudocharge in g space double wsg(int l) { return wsg_[l]; }; double rcut_loc(double epsilon); // radius beyond which potential is local - + const std::vector >& vps(void) const { return vps_; } const std::vector >& phi(void) const { return phi_; } - + bool initialize(double rcps); void info(std::ostream& os); - + friend class SpeciesReader; friend class SpeciesHandler; - + }; std::ostream& operator << ( std::ostream &os, Species &a ); class SpeciesInitException diff --git a/src/SpeciesCmd.C b/src/SpeciesCmd.C index ffa0c1c..3274fb8 100644 --- a/src/SpeciesCmd.C +++ b/src/SpeciesCmd.C @@ -3,7 +3,7 @@ // SpeciesCmd.C // //////////////////////////////////////////////////////////////////////////////// -// $Id: SpeciesCmd.C,v 1.7 2005-09-16 23:08:11 fgygi Exp $ +// $Id: SpeciesCmd.C,v 1.8 2007-10-19 16:24:05 fgygi Exp $ #include "SpeciesCmd.h" #include "SpeciesReader.h" @@ -21,15 +21,15 @@ int SpeciesCmd::action(int argc, char **argv) cout << " " << endl; return 1; } - + if ( ui->onpe0() ) cout << " " << endl; SpeciesReader sp_reader(s->ctxt_); - + Species* sp = new Species(s->ctxt_,argv[1]); - + try { sp_reader.readSpecies(*sp,argv[2]); @@ -52,6 +52,6 @@ int SpeciesCmd::action(int argc, char **argv) { cout << " SpeciesCmd: cannot define Species" << endl; } - + return 0; } diff --git a/src/SpeciesCmd.h b/src/SpeciesCmd.h index 3a32680..8424ef0 100644 --- a/src/SpeciesCmd.h +++ b/src/SpeciesCmd.h @@ -3,7 +3,7 @@ // SpeciesCmd.h: // //////////////////////////////////////////////////////////////////////////////// -// $Id: SpeciesCmd.h,v 1.1 2003-03-27 22:05:59 fgygi Exp $ +// $Id: SpeciesCmd.h,v 1.2 2007-10-19 16:24:05 fgygi Exp $ #ifndef SPECIESCMD_H #define SPECIESCMD_H @@ -28,7 +28,7 @@ class SpeciesCmd : public Cmd char *help_msg(void) const { - return + return "\n species\n\n" " syntax: species name uri\n\n" " The species command defines a species name.\n\n"; diff --git a/src/SpeciesHandler.C b/src/SpeciesHandler.C index 893cbc6..f456270 100644 --- a/src/SpeciesHandler.C +++ b/src/SpeciesHandler.C @@ -3,7 +3,7 @@ // SpeciesHandler.C // //////////////////////////////////////////////////////////////////////////////// -// $Id: SpeciesHandler.C,v 1.3 2006-05-13 05:42:18 fgygi Exp $ +// $Id: SpeciesHandler.C,v 1.4 2007-10-19 16:24:05 fgygi Exp $ #if USE_XERCES @@ -17,7 +17,7 @@ using namespace xercesc; using namespace std; //////////////////////////////////////////////////////////////////////////////// -SpeciesHandler::SpeciesHandler(Species& sp) : +SpeciesHandler::SpeciesHandler(Species& sp) : sp_(sp) {} //////////////////////////////////////////////////////////////////////////////// @@ -27,11 +27,11 @@ SpeciesHandler::~SpeciesHandler() {} void SpeciesHandler::startElement(const XMLCh* const uri, const XMLCh* const localname, const XMLCh* const qname, const Attributes& attributes) -{ +{ // cout << " SpeciesHandler::startElement " << StrX(qname) << endl; - + string locname(XMLString::transcode(localname)); - + if ( locname == "species" ) { // check for the case where the species is a link to another uri @@ -78,7 +78,7 @@ void SpeciesHandler::endElement(const XMLCh* const uri, { string locname(XMLString::transcode(localname)); istringstream stst(content); - // cout << " SpeciesHandler::endElement " << StrX(qname) + // cout << " SpeciesHandler::endElement " << StrX(qname) // << " content=" << string(content,0,20) << endl; if ( locname == "description") @@ -86,7 +86,7 @@ void SpeciesHandler::endElement(const XMLCh* const uri, // reject ambiguous case where both the href and the definition are given if ( current_href != "" ) { - cout << " SpeciesHandler: ambiguous definition: uri=" + cout << " SpeciesHandler: ambiguous definition: uri=" << StrX(uri) << endl << " using local definition (href: " << current_href << " ignored)" << endl; @@ -150,7 +150,7 @@ void SpeciesHandler::endElement(const XMLCh* const uri, //////////////////////////////////////////////////////////////////////////////// StructureHandler* SpeciesHandler::startSubHandler(const XMLCh* const uri, - const XMLCh* const localname, const XMLCh* const qname, + const XMLCh* const localname, const XMLCh* const qname, const Attributes& attributes) { // check if element qname can be processed by another StructureHandler @@ -161,12 +161,12 @@ StructureHandler* SpeciesHandler::startSubHandler(const XMLCh* const uri, //////////////////////////////////////////////////////////////////////////////// void SpeciesHandler::endSubHandler(const XMLCh* const uri, - const XMLCh* const localname, const XMLCh* const qname, + const XMLCh* const localname, const XMLCh* const qname, const StructureHandler* const subHandler) { // cout << " SpeciesHandler::endSubHandler " << StrX(qname) << endl; // if any StructureHandler was created by startSubHandler, delete it // delete subHandler; } - + #endif diff --git a/src/SpeciesHandler.h b/src/SpeciesHandler.h index d8962a9..a498aae 100644 --- a/src/SpeciesHandler.h +++ b/src/SpeciesHandler.h @@ -3,7 +3,7 @@ // SpeciesHandler.h // //////////////////////////////////////////////////////////////////////////////// -// $Id: SpeciesHandler.h,v 1.2 2007-03-17 01:14:00 fgygi Exp $ +// $Id: SpeciesHandler.h,v 1.3 2007-10-19 16:24:05 fgygi Exp $ #ifndef SPECIESHANDLER_H #define SPECIESHANDLER_H @@ -15,30 +15,30 @@ class Species; class SpeciesHandler : public StructureHandler { private: - + Species& sp_; int current_l, current_size; std::string current_name, current_href; double current_interval; - + public: - + // Start of an element handled by SpeciesHandler virtual void startElement(const XMLCh* const uri,const XMLCh* const localname, const XMLCh* const qname, const Attributes& attributes); // End of an element handled by SpeciesHandler - virtual void endElement(const XMLCh* const uri, const XMLCh* const localname, + virtual void endElement(const XMLCh* const uri, const XMLCh* const localname, const XMLCh* const qname, std::string& content); - + // start a subHandler if possible virtual StructureHandler* startSubHandler(const XMLCh* const uri, - const XMLCh* const localname, const XMLCh* const qname, + const XMLCh* const localname, const XMLCh* const qname, const Attributes& attributes); - + // end subHandler virtual void endSubHandler(const XMLCh* const uri, - const XMLCh* const localname, const XMLCh* const qname, + const XMLCh* const localname, const XMLCh* const qname, const StructureHandler* const subHandler); SpeciesHandler(Species& sp); diff --git a/src/SpeciesReader.C b/src/SpeciesReader.C index 7ac9b74..c0fa100 100644 --- a/src/SpeciesReader.C +++ b/src/SpeciesReader.C @@ -3,7 +3,7 @@ // SpeciesReader.C: // //////////////////////////////////////////////////////////////////////////////// -// $Id: SpeciesReader.C,v 1.6 2007-03-17 01:14:00 fgygi Exp $ +// $Id: SpeciesReader.C,v 1.7 2007-10-19 16:24:05 fgygi Exp $ #include "Species.h" #include "SpeciesReader.h" @@ -46,7 +46,7 @@ void SpeciesReader::readSpecies (Species& sp, const string uri) bool schemaFullChecking = true; bool namespacePrefixes = false; SAX2XMLReader* parser = 0; - + int ierr = 0; try { @@ -83,10 +83,10 @@ void SpeciesReader::readSpecies (Species& sp, const string uri) parser->setFeature(XMLUni::fgSAX2CoreNameSpacePrefixes, namespacePrefixes); int errorCount = 0; - + int nlink = 0; string current_uri = uri; - + while ( sp.description() == "undefined" && nlink++ < 5 ) { try @@ -121,7 +121,7 @@ void SpeciesReader::readSpecies (Species& sp, const string uri) delete parser; throw; } - + if ( sp.description() == "undefined" ) current_uri = sp.uri(); } @@ -130,14 +130,14 @@ void SpeciesReader::readSpecies (Species& sp, const string uri) delete parser; XMLPlatformUtils::Terminate(); } - + #else // USE_XERCES is not defined // Simplified parsing not using Xerces // parse file uri - + if ( ctxt_.onpe0() ) { struct stat statbuf; @@ -164,7 +164,7 @@ void SpeciesReader::readSpecies (Species& sp, const string uri) string tag, start_tag, end_tag; string::size_type start, end, len; - + tag = "description"; start_tag = string("<") + tag + string(">"); end_tag = string(""); @@ -174,12 +174,12 @@ void SpeciesReader::readSpecies (Species& sp, const string uri) end = buf.find(end_tag); pos = buf.find(">",end)+1; len = end - start; - + sp.description_ = buf.substr(start,len); cout << " " << endl; - + tag = "symbol"; start_tag = string("<") + tag + string(">"); end_tag = string(""); @@ -196,7 +196,7 @@ void SpeciesReader::readSpecies (Species& sp, const string uri) cout << " " << endl; - + tag = "atomic_number"; start_tag = string("<") + tag + string(">"); end_tag = string(""); @@ -213,7 +213,7 @@ void SpeciesReader::readSpecies (Species& sp, const string uri) cout << " " << endl; - + tag = "mass"; start_tag = string("<") + tag + string(">"); end_tag = string(""); @@ -230,7 +230,7 @@ void SpeciesReader::readSpecies (Species& sp, const string uri) cout << " " << endl; - + tag = "valence_charge"; start_tag = string("<") + tag + string(">"); end_tag = string(""); @@ -247,7 +247,7 @@ void SpeciesReader::readSpecies (Species& sp, const string uri) cout << " " << endl; - + tag = "lmax"; start_tag = string("<") + tag + string(">"); end_tag = string(""); @@ -264,7 +264,7 @@ void SpeciesReader::readSpecies (Species& sp, const string uri) cout << " " << endl; - + tag = "llocal"; start_tag = string("<") + tag + string(">"); end_tag = string(""); @@ -281,7 +281,7 @@ void SpeciesReader::readSpecies (Species& sp, const string uri) cout << " " << endl; - + tag = "nquad"; start_tag = string("<") + tag + string(">"); end_tag = string(""); @@ -298,7 +298,7 @@ void SpeciesReader::readSpecies (Species& sp, const string uri) cout << " " << endl; - + tag = "rquad"; start_tag = string("<") + tag + string(">"); end_tag = string(""); @@ -315,7 +315,7 @@ void SpeciesReader::readSpecies (Species& sp, const string uri) cout << " " << endl; - + tag = "mesh_spacing"; start_tag = string("<") + tag + string(">"); end_tag = string(""); @@ -332,7 +332,7 @@ void SpeciesReader::readSpecies (Species& sp, const string uri) cout << " " << endl; - + for ( int l = 0; l < sp.lmax_ + 1; l++ ) { // read projector @@ -341,12 +341,12 @@ void SpeciesReader::readSpecies (Species& sp, const string uri) start_tag = string("<") + tag; start = buf.find(start_tag,pos); assert(start != string::npos ); - + pos = buf.find("l=",pos)+3; start = pos; end = buf.find("\"",start); len = end - start; - + { istringstream stst(buf.substr(start,len)); int lread; @@ -355,7 +355,7 @@ void SpeciesReader::readSpecies (Species& sp, const string uri) //cout << " l=" << l << endl; assert(l==lread); } - + pos = buf.find("size=",pos)+6; start = pos; end = buf.find("\"",start); @@ -366,10 +366,10 @@ void SpeciesReader::readSpecies (Species& sp, const string uri) // cout << " size=" << size << endl; } // read radial potential - + sp.vps_.resize(sp.vps_.size()+1); sp.vps_[l].resize(size); - + tag = "radial_potential"; start_tag = string("<") + tag + string(">"); end_tag = string(""); @@ -389,12 +389,12 @@ void SpeciesReader::readSpecies (Species& sp, const string uri) } cout << " " << endl; - + sp.phi_.resize(sp.phi_.size()+1); sp.phi_[l].resize(size); - + // read radial function only if the radial_function tag was found - + tag = "radial_function"; start_tag = string("<") + tag + string(">"); end_tag = string(""); @@ -404,7 +404,7 @@ void SpeciesReader::readSpecies (Species& sp, const string uri) // if l is not the local potential, there must be a radial function assert(start != string::npos ); } - + if ( start != string::npos ) { start = buf.find(">",start)+1; @@ -423,7 +423,7 @@ void SpeciesReader::readSpecies (Species& sp, const string uri) << l << " size=" << size << " -->" << endl; } } - + sp.uri_ = uri; } #endif @@ -454,15 +454,15 @@ void SpeciesReader::bcastSpecies(Species& sp) ctxt_.ibcast_recv(1,1,&sp.nquad_,1,0,0); ctxt_.dbcast_recv(1,1,&sp.rquad_,1,0,0); ctxt_.dbcast_recv(1,1,&sp.deltar_,1,0,0); - + sp.vps_.resize(sp.lmax_+1); sp.phi_.resize(sp.lmax_+1); } - + ctxt_.string_bcast(sp.symbol_,0); ctxt_.string_bcast(sp.description_,0); ctxt_.string_bcast(sp.uri_,0); - + for ( int l = 0; l <= sp.lmax_; l++ ) { int np_vps; diff --git a/src/SpeciesReader.h b/src/SpeciesReader.h index c07c0a2..f5ec76c 100644 --- a/src/SpeciesReader.h +++ b/src/SpeciesReader.h @@ -3,7 +3,7 @@ // SpeciesReader.h: // //////////////////////////////////////////////////////////////////////////////// -// $Id: SpeciesReader.h,v 1.4 2007-03-17 01:14:00 fgygi Exp $ +// $Id: SpeciesReader.h,v 1.5 2007-10-19 16:24:05 fgygi Exp $ #ifndef SPECIESREADER_H #define SPECIESREADER_H @@ -14,11 +14,11 @@ class SpeciesReader { private: - + const Context& ctxt_; - + std::string uri_; // uri from which Species is read - + public: SpeciesReader(const Context& ctxt); diff --git a/src/StatusCmd.h b/src/StatusCmd.h index 6c97616..07b71e8 100644 --- a/src/StatusCmd.h +++ b/src/StatusCmd.h @@ -3,7 +3,7 @@ // StatusCmd.h: // //////////////////////////////////////////////////////////////////////////////// -// $Id: StatusCmd.h,v 1.2 2006-08-22 15:12:56 fgygi Exp $ +// $Id: StatusCmd.h,v 1.3 2007-10-19 16:24:05 fgygi Exp $ #ifndef STATUSCMD_H #define STATUSCMD_H @@ -27,7 +27,7 @@ class StatusCmd : public Cmd char *name(void) const { return "status"; } char *help_msg(void) const { - return + return "\n run\n\n" " syntax: status \n\n" " The status command print information about the current\n" diff --git a/src/Stress.h b/src/Stress.h index ea34eb3..56b2550 100644 --- a/src/Stress.h +++ b/src/Stress.h @@ -3,7 +3,7 @@ // Stress.h // //////////////////////////////////////////////////////////////////////////////// -// $Id: Stress.h,v 1.1 2004-02-04 19:52:27 fgygi Exp $ +// $Id: Stress.h,v 1.2 2007-10-19 16:24:05 fgygi Exp $ #ifndef STRESS_H #define STRESS_H @@ -31,7 +31,7 @@ class Stress : public Var cout << " stress takes only one value" << endl; return 1; } - + string v = argv[1]; if ( !( v == "ON" || v == "OFF" ) ) { @@ -41,7 +41,7 @@ class Stress : public Var } s->ctrl.stress = v; - + return 0; } diff --git a/src/StructureFactor.C b/src/StructureFactor.C index 60c033e..5285b13 100644 --- a/src/StructureFactor.C +++ b/src/StructureFactor.C @@ -3,7 +3,7 @@ // StructureFactor.C // //////////////////////////////////////////////////////////////////////////////// -// $Id: StructureFactor.C,v 1.3 2007-03-17 01:14:00 fgygi Exp $ +// $Id: StructureFactor.C,v 1.4 2007-10-19 16:24:05 fgygi Exp $ #include "StructureFactor.h" #include "Basis.h" @@ -12,7 +12,7 @@ using namespace std; //////////////////////////////////////////////////////////////////////////////// -void StructureFactor::init(const vector >& tau, +void StructureFactor::init(const vector >& tau, const Basis& basis) { _k0min = basis.idxmin(0); @@ -24,12 +24,12 @@ void StructureFactor::init(const vector >& tau, _k0range = _k0max - _k0min + 1; _k1range = _k1max - _k1min + 1; _k2range = _k2max - _k2min + 1; - + // get dimensions of tau[nsp][3*na[is]] - + _nsp = tau.size(); _na.resize(_nsp); - + cos0.resize(_nsp); cos1.resize(_nsp); cos2.resize(_nsp); @@ -37,9 +37,9 @@ void StructureFactor::init(const vector >& tau, sin1.resize(_nsp); sin2.resize(_nsp); sfac.resize(_nsp); - + _ng = basis.localsize(); - + for ( int is = 0; is < _nsp; is++ ) { assert( tau[is].size() % 3 == 0 ); @@ -55,18 +55,18 @@ void StructureFactor::init(const vector >& tau, } //////////////////////////////////////////////////////////////////////////////// -void StructureFactor::update(const vector >& tau, +void StructureFactor::update(const vector >& tau, const Basis& basis) { - // it is assumed that the dimensions of tau and the basis have + // it is assumed that the dimensions of tau and the basis have // not changed since the last call to StructureFactor::init - - // check that number of species has not changed - assert(tau.size() == _nsp); + + // check that number of species has not changed + assert(tau.size() == _nsp); assert(basis.localsize() == _ng); - + const int * const idx = basis.idx_ptr(); - + const UnitCell& cell = basis.cell(); const D3vector b0 = cell.b(0); const D3vector b1 = cell.b(1); @@ -76,7 +76,7 @@ void StructureFactor::update(const vector >& tau, { assert( 3 * _na[is] == tau[is].size() ); memset( (void*)&sfac[is][0], 0, 2*_ng*sizeof(double) ); - + for ( int ia = 0; ia < _na[is]; ia++ ) { double *c0 = cos0_ptr(is,ia); @@ -85,11 +85,11 @@ void StructureFactor::update(const vector >& tau, double *s0 = sin0_ptr(is,ia); double *s1 = sin1_ptr(is,ia); double *s2 = sin2_ptr(is,ia); - + const double * const tauptr = &tau[is][3*ia]; - + const D3vector t(tauptr[0],tauptr[1],tauptr[2]); - + /* x direction */ const double fac0 = b0 * t; @@ -119,31 +119,31 @@ void StructureFactor::update(const vector >& tau, c2[i] = cos(arg); s2[i] = sin(arg); } - - // compute sfac[is][i] - + + // compute sfac[is][i] + for ( int i = 0; i < _ng; i++ ) { const int iii = i+i+i; const int kx = idx[iii]; const int ky = idx[iii+1]; const int kz = idx[iii+2]; - + const double cos_a = c0[kx]; const double cos_b = c1[ky]; const double cos_c = c2[kz]; - + const double sin_a = s0[kx]; const double sin_b = s1[ky]; const double sin_c = s2[kz]; - - // Next line: exp(-i*gr) = + + // Next line: exp(-i*gr) = // (cos_a - I sin_a)*(cos_b - I sin_b)*(cos_c - I sin_c) sfac[is][i] += complex( - cos_a*cos_b*cos_c - sin_a*sin_b*cos_c - + cos_a*cos_b*cos_c - sin_a*sin_b*cos_c - sin_a*cos_b*sin_c - cos_a*sin_b*sin_c, - sin_a*sin_b*sin_c - sin_a*cos_b*cos_c - - cos_a*sin_b*cos_c - cos_a*cos_b*sin_c ); + sin_a*sin_b*sin_c - sin_a*cos_b*cos_c - + cos_a*sin_b*cos_c - cos_a*cos_b*sin_c ); } } } diff --git a/src/StructureFactor.h b/src/StructureFactor.h index 791ba26..37ad144 100644 --- a/src/StructureFactor.h +++ b/src/StructureFactor.h @@ -3,7 +3,7 @@ // StructureFactor.h // //////////////////////////////////////////////////////////////////////////////// -// $Id: StructureFactor.h,v 1.2 2007-03-17 01:14:00 fgygi Exp $ +// $Id: StructureFactor.h,v 1.3 2007-10-19 16:24:05 fgygi Exp $ #ifndef STRUCTUREFACTOR_H #define STRUCTUREFACTOR_H @@ -17,36 +17,36 @@ class Basis; class StructureFactor { private: - + int _nsp, _ng; std::vector _na; - - int _k0max, _k1max, _k2max, + + int _k0max, _k1max, _k2max, _k0min, _k1min, _k2min, _k0range, _k1range, _k2range; - + public: - + // convenience pointer access functions: // double *c0 = cos0_ptr(is,ia); // c0[ kx ] == cos(-i gx*tau[is][ia].x) - - double *cos0_ptr(int is, int ia) + + double *cos0_ptr(int is, int ia) { return &cos0[is][ia*_k0range-_k0min]; } - - double *cos1_ptr(int is, int ia) + + double *cos1_ptr(int is, int ia) { return &cos1[is][ia*_k1range-_k1min]; } - - double *cos2_ptr(int is, int ia) + + double *cos2_ptr(int is, int ia) { return &cos2[is][ia*_k2range-_k2min]; } - - double *sin0_ptr(int is, int ia) + + double *sin0_ptr(int is, int ia) { return &sin0[is][ia*_k0range-_k0min]; } - - double *sin1_ptr(int is, int ia) + + double *sin1_ptr(int is, int ia) { return &sin1[is][ia*_k1range-_k1min]; } - - double *sin2_ptr(int is, int ia) + + double *sin2_ptr(int is, int ia) { return &sin2[is][ia*_k2range-_k2min]; } // kx in [k0min, k0max] @@ -60,7 +60,7 @@ class StructureFactor std::vector > sin1; // sin1[is][ia*k1range-k1min+ky] std::vector > sin2; // sin2[is][ia*k2range-k2min+ky] std::vector > > sfac; // sfac[is][ig] - + void init(const std::vector >& tau, const Basis& basis); void update(const std::vector >& tau, const Basis& basis); diff --git a/src/StructureHandler.h b/src/StructureHandler.h index 7787e67..74d4008 100644 --- a/src/StructureHandler.h +++ b/src/StructureHandler.h @@ -3,7 +3,7 @@ // StructureHandler.h // //////////////////////////////////////////////////////////////////////////////// -// $Id: StructureHandler.h,v 1.2 2007-03-17 01:14:00 fgygi Exp $ +// $Id: StructureHandler.h,v 1.3 2007-10-19 16:24:05 fgygi Exp $ #ifndef STRUCTUREHANDLER_H #define STRUCTUREHANDLER_H @@ -18,25 +18,25 @@ class StructureHandler private: public: - + // Start of an element handled by the StructureHandler virtual void startElement(const XMLCh* const uri,const XMLCh* const localname, const XMLCh* const qname, const Attributes& attributes) = 0; // End of an element handled by the StructureHandler - virtual void endElement(const XMLCh* const uri, const XMLCh* const localname, + virtual void endElement(const XMLCh* const uri, const XMLCh* const localname, const XMLCh* const qname, std::string& content) = 0; - + // start a subhandler virtual StructureHandler* startSubHandler(const XMLCh* const uri, - const XMLCh* const localname, const XMLCh* const qname, + const XMLCh* const localname, const XMLCh* const qname, const Attributes& attributes) = 0; - + // end a subhandler virtual void endSubHandler(const XMLCh* const uri, - const XMLCh* const localname, const XMLCh* const qname, + const XMLCh* const localname, const XMLCh* const qname, const StructureHandler* const subHandler) = 0; - + StructureHandler() {} virtual ~StructureHandler() {} }; diff --git a/src/StructuredDocumentHandler.C b/src/StructuredDocumentHandler.C index c882f5c..617fd48 100644 --- a/src/StructuredDocumentHandler.C +++ b/src/StructuredDocumentHandler.C @@ -3,7 +3,7 @@ // StructuredDocumentHandler.C // //////////////////////////////////////////////////////////////////////////////// -// $Id: StructuredDocumentHandler.C,v 1.5 2007-03-17 01:14:00 fgygi Exp $ +// $Id: StructuredDocumentHandler.C,v 1.6 2007-10-19 16:24:05 fgygi Exp $ #if USE_XERCES @@ -23,13 +23,13 @@ using namespace std; //////////////////////////////////////////////////////////////////////////////// void StructuredDocumentHandler::startElement(const XMLCh* const uri, - const XMLCh* const localname, const XMLCh* const qname, + const XMLCh* const localname, const XMLCh* const qname, const Attributes& attributes) { // cout << " StructuredDocumentHandler::startElement " << StrX(qname) << endl; // cout << " nestingDepth before: " << nestingDepth << endl; buffer = ""; - + // attempt to start a subhandler for this element StructureHandler* next = activeHandler->startSubHandler(uri,localname,qname, attributes); @@ -38,7 +38,7 @@ void StructuredDocumentHandler::startElement(const XMLCh* const uri, if ( next != 0 ) { contextStack.push(HandlerContext(activeHandler,contextDepth)); - + activeHandler = next; contextDepth = nestingDepth; } @@ -75,7 +75,7 @@ void StructuredDocumentHandler::endElement(const XMLCh* const uri, // cout << " nestingDepth before: " << nestingDepth << endl; nestingDepth--; activeHandler->endElement(uri,localname,qname,buffer); - + // Check if this element was processed by a subhandler // If yes, pop the previous context from the Context stack if ( nestingDepth != 0 && nestingDepth == contextDepth ) @@ -116,7 +116,7 @@ void StructuredDocumentHandler::error(const SAXParseException& e) << ", line " << e.getLineNumber() << ", char " << e.getColumnNumber() << "\n Message: " << StrX(e.getMessage()) << endl; - + throw(e); } diff --git a/src/StructuredDocumentHandler.h b/src/StructuredDocumentHandler.h index 3f79bef..c90a88e 100644 --- a/src/StructuredDocumentHandler.h +++ b/src/StructuredDocumentHandler.h @@ -3,7 +3,7 @@ // StructuredDocumentHandler.h // //////////////////////////////////////////////////////////////////////////////// -// $Id: StructuredDocumentHandler.h,v 1.2 2007-03-17 01:14:00 fgygi Exp $ +// $Id: StructuredDocumentHandler.h,v 1.3 2007-10-19 16:24:05 fgygi Exp $ #ifndef STRUCTUREDDOCUMENTHANDLER_H #define STRUCTUREDDOCUMENTHANDLER_H @@ -27,7 +27,7 @@ class StructuredDocumentHandler : public DefaultHandler }; protected: - + std::stack contextStack; int nestingDepth; int contextDepth; @@ -38,9 +38,9 @@ class StructuredDocumentHandler : public DefaultHandler StructuredDocumentHandler(StructureHandler* handler) : activeHandler(handler), contextDepth(0), nestingDepth(0) {} - + ~StructuredDocumentHandler() {} - + // ----------------------------------------------------------------------- // Implementations of the SAX DocumentHandler interface // ----------------------------------------------------------------------- @@ -63,7 +63,7 @@ class StructuredDocumentHandler : public DefaultHandler void warning(const SAXParseException& exception); void error(const SAXParseException& exception); void fatalError(const SAXParseException& exception); - + // ----------------------------------------------------------------------- // Implementation of the SAX DTDHandler interface // ----------------------------------------------------------------------- diff --git a/src/ThTemp.h b/src/ThTemp.h index ba44878..827444b 100644 --- a/src/ThTemp.h +++ b/src/ThTemp.h @@ -3,7 +3,7 @@ // ThTemp.h // //////////////////////////////////////////////////////////////////////////////// -// $Id: ThTemp.h,v 1.1 2003-08-28 00:28:51 fgygi Exp $ +// $Id: ThTemp.h,v 1.2 2007-10-19 16:24:05 fgygi Exp $ #ifndef THTEMP_H #define THTEMP_H @@ -31,7 +31,7 @@ class ThTemp : public Var cout << " th_temp takes only one value" << endl; return 1; } - + double v = atof(argv[1]); if ( v < 0.0 ) { diff --git a/src/ThTime.h b/src/ThTime.h index d8d946d..ce59e8d 100644 --- a/src/ThTime.h +++ b/src/ThTime.h @@ -3,7 +3,7 @@ // ThTime.h // //////////////////////////////////////////////////////////////////////////////// -// $Id: ThTime.h,v 1.1 2003-08-28 00:28:51 fgygi Exp $ +// $Id: ThTime.h,v 1.2 2007-10-19 16:24:05 fgygi Exp $ #ifndef THTIME_H #define THTIME_H @@ -31,7 +31,7 @@ class ThTime : public Var cout << " th_time takes only one value" << endl; return 1; } - + double v = atof(argv[1]); if ( v < 0.0 ) { diff --git a/src/ThWidth.h b/src/ThWidth.h index bb41ff0..52d1e12 100644 --- a/src/ThWidth.h +++ b/src/ThWidth.h @@ -3,7 +3,7 @@ // ThWidth.h // //////////////////////////////////////////////////////////////////////////////// -// $Id: ThWidth.h,v 1.1 2004-03-11 21:58:10 fgygi Exp $ +// $Id: ThWidth.h,v 1.2 2007-10-19 16:24:05 fgygi Exp $ #ifndef THWIDTH_H #define THWIDTH_H @@ -31,7 +31,7 @@ class ThWidth : public Var cout << " th_width takes only one value" << endl; return 1; } - + double v = atof(argv[1]); if ( v <= 0.0 ) { diff --git a/src/Thermostat.h b/src/Thermostat.h index 66e03ce..731276b 100644 --- a/src/Thermostat.h +++ b/src/Thermostat.h @@ -3,7 +3,7 @@ // Thermostat.h // //////////////////////////////////////////////////////////////////////////////// -// $Id: Thermostat.h,v 1.3 2006-11-05 02:06:15 fgygi Exp $ +// $Id: Thermostat.h,v 1.4 2007-10-19 16:24:05 fgygi Exp $ #ifndef THERMOSTAT_H #define THERMOSTAT_H @@ -31,18 +31,18 @@ class Thermostat : public Var cout << " thermostat takes only one value" << endl; return 1; } - + string v = argv[1]; if ( !( v == "SCALING" || v == "ANDERSEN" || v == "LOWE" || v == "OFF" ) ) { if ( ui->onpe0() ) - cout << " thermostat must be SCALING or ANDERSEN or LOWE or OFF" + cout << " thermostat must be SCALING or ANDERSEN or LOWE or OFF" << endl; return 1; } s->ctrl.thermostat = v; - + return 0; } diff --git a/src/Timer.h b/src/Timer.h index 9436b8c..cb52c51 100644 --- a/src/Timer.h +++ b/src/Timer.h @@ -3,7 +3,7 @@ // Timer.h // //////////////////////////////////////////////////////////////////////////////// -// $Id: Timer.h,v 1.1.1.1 2002-09-27 00:08:39 fgygi Exp $ +// $Id: Timer.h,v 1.2 2007-10-19 16:24:05 fgygi Exp $ #ifndef TIMER_H #define TIMER_H @@ -36,7 +36,7 @@ class Timer void stop() { - if ( running_ ) + if ( running_ ) { total_cpu += ((double)(clock()-clk))/CLOCKS_PER_SEC; total_real += gtod()-t; @@ -46,26 +46,26 @@ class Timer double cpu() { - if ( running_ ) + if ( running_ ) { return total_cpu + ((double)(clock()-clk))/CLOCKS_PER_SEC; } else { return total_cpu; - } + } }; double real() { - if ( running_ ) + if ( running_ ) { return total_real + gtod()-t; } else { return total_real; - } + } }; double gtod(void) diff --git a/src/TorsionCmd.h b/src/TorsionCmd.h index 67a9aaf..973e6c8 100644 --- a/src/TorsionCmd.h +++ b/src/TorsionCmd.h @@ -3,7 +3,7 @@ // TorsionCmd.h: // //////////////////////////////////////////////////////////////////////////////// -// $Id: TorsionCmd.h,v 1.1 2005-06-27 22:35:26 fgygi Exp $ +// $Id: TorsionCmd.h,v 1.2 2007-10-19 16:24:05 fgygi Exp $ #ifndef TORSIONCMD_H #define TORSIONCMD_H @@ -24,7 +24,7 @@ class TorsionCmd : public Cmd char *name(void) const { return "torsion"; } char *help_msg(void) const { - return + return "\n torsion\n\n" " syntax: torsion name1 name2 name3 name4\n\n" " The torsion command prints the dihedral defined by four atoms.\n\n"; @@ -40,17 +40,17 @@ class TorsionCmd : public Cmd } return 1; } - - string name1(argv[1]); - string name2(argv[2]); - string name3(argv[3]); - string name4(argv[4]); - Atom* a1 = s->atoms.findAtom(name1); - Atom* a2 = s->atoms.findAtom(name2); - Atom* a3 = s->atoms.findAtom(name3); - Atom* a4 = s->atoms.findAtom(name4); - if ( a1 == 0 || a2 == 0 || a3 == 0 || a4 == 0 ) - { + + string name1(argv[1]); + string name2(argv[2]); + string name3(argv[3]); + string name4(argv[4]); + Atom* a1 = s->atoms.findAtom(name1); + Atom* a2 = s->atoms.findAtom(name2); + Atom* a3 = s->atoms.findAtom(name3); + Atom* a4 = s->atoms.findAtom(name4); + if ( a1 == 0 || a2 == 0 || a3 == 0 || a4 == 0 ) + { if ( ui->onpe0() ) { if ( a1 == 0 ) @@ -68,39 +68,39 @@ class TorsionCmd : public Cmd } return 1; } - - if ( a1 == a2 || a1 == a3 || a1 == a4 || - a2 == a3 || a2 == a4 || a3 == a4 ) - { + + if ( a1 == a2 || a1 == a3 || a1 == a4 || + a2 == a3 || a2 == a4 || a3 == a4 ) + { if ( ui->onpe0() ) { - cout << " " << endl; + cout << " " << endl; } return 1; } - + D3vector r12(a1->position()-a2->position()); D3vector r32(a3->position()-a2->position()); D3vector r43(a4->position()-a3->position()); if ( norm(r12) == 0.0 || norm(r32) == 0.0 || norm(r43) == 0.0 ) - { + { if ( ui->onpe0() ) { cout << " " << endl; } return 1; } - + D3vector e12(normalized(r12)); D3vector e32(normalized(r32)); D3vector e23(-e32); D3vector e43(normalized(r43)); - + const double sin123 = length(e12^e32); const double sin234 = length(e23^e43); - + double a = 0; if ( sin123 != 0.0 && sin234 != 0.0 ) { @@ -110,14 +110,14 @@ class TorsionCmd : public Cmd double ss = max(min((e123^e234)*e32,1.0),-1.0); a = (180.0/M_PI) * atan2(ss,cc); } - + if ( ui->onpe0() ) { cout.setf(ios::fixed,ios::floatfield); - cout << " " << endl; + cout << " " << endl; } return 0; } diff --git a/src/TorsionConstraint.C b/src/TorsionConstraint.C index 485eb3e..9d4133a 100644 --- a/src/TorsionConstraint.C +++ b/src/TorsionConstraint.C @@ -3,7 +3,7 @@ // TorsionConstraint.C // //////////////////////////////////////////////////////////////////////////////// -// $Id: TorsionConstraint.C,v 1.2 2005-09-16 23:08:11 fgygi Exp $ +// $Id: TorsionConstraint.C,v 1.3 2007-10-19 16:24:05 fgygi Exp $ #include "TorsionConstraint.h" #include "AtomSet.h" @@ -26,7 +26,7 @@ void TorsionConstraint::setup(const AtomSet& atoms) m1_ = atoms.species_list[is1_]->mass() * 1822.89; assert(m1_>0.0); m1_inv_ = 1.0 / m1_; - + is2_ = atoms.is(name2_); ia2_ = atoms.ia(name2_); assert(is2_>=0); @@ -34,7 +34,7 @@ void TorsionConstraint::setup(const AtomSet& atoms) m2_ = atoms.species_list[is2_]->mass() * 1822.89; assert(m2_>0.0); m2_inv_ = 1.0 / m2_; - + is3_ = atoms.is(name3_); ia3_ = atoms.ia(name3_); assert(is3_>=0); @@ -42,7 +42,7 @@ void TorsionConstraint::setup(const AtomSet& atoms) m3_ = atoms.species_list[is3_]->mass() * 1822.89; assert(m3_>0.0); m3_inv_ = 1.0 / m3_; - + is4_ = atoms.is(name4_); ia4_ = atoms.ia(name4_); assert(is4_>=0); @@ -74,37 +74,37 @@ vector > &rp) const double* pr2p = &rp[is2_][3*ia2_]; double* pr3p = &rp[is3_][3*ia3_]; double* pr4p = &rp[is4_][3*ia4_]; - + D3vector r1(pr1); D3vector r2(pr2); D3vector r3(pr3); D3vector r4(pr4); - + D3vector r1p(pr1p); D3vector r2p(pr2p); D3vector r3p(pr3p); D3vector r4p(pr4p); - + const double h = 0.001; const double fac = 0.5 / h; D3vector dx(h,0,0), dy(0,h,0), dz(0,0,h); - + // compute gradient at r D3vector g1,g2,g3,g4; grad_sigma(r1,r2,r3,r4,g1,g2,g3,g4); const double a = torsion_angle(r1,r2,r3,r4); double ng = g1*g1 + g2*g2 + g3*g3 + g4*g4; assert(ng>=0.0); - + // compute gradient at rp D3vector g1p,g2p,g3p,g4p; grad_sigma(r1p,r2p,r3p,r4p,g1p,g2p,g3p,g4p); const double ap = torsion_angle(r1p,r2p,r3p,r4p); const double ngp = g1p*g1p + g2p*g2p + g3p*g3p + g4p*g4p; assert(ngp>=0.0); - + const double err = fabs(ap-angle_); - + if ( ng == 0.0 ) { // gradient is ill defined at r and is likely to change @@ -141,21 +141,21 @@ vector > &rp) const // no action necessary } } - + // test alignment of the gradient at r and at rp // compute scalar product of normalized gradients const double sp = ( g1*g1p + g2*g2p + g3*g3p + g4*g4p ) / sqrt( ng * ngp ); - + if ( fabs(sp) < 0.5*sqrt(3.0) ) { - g1 = g1p; - g2 = g2p; - g3 = g3p; - g4 = g4p; + g1 = g1p; + g2 = g2p; + g3 = g3p; + g4 = g4p; } #if DEBUG_CONSTRAINTS cout << " " << endl; #endif if ( err < tol_ ) return true; - + // make one shake iteration - const double den = m1_inv_ * g1 * g1p + + const double den = m1_inv_ * g1 * g1p + m2_inv_ * g2 * g2p + m3_inv_ * g3 * g3p + m4_inv_ * g4 * g4p; assert(fabs(den)>0.0); - + const double lambda = - sigma(r1p,r2p,r3p,r4p) / den; - + pr1p[0] += m1_inv_ * lambda * g1.x; pr1p[1] += m1_inv_ * lambda * g1.y; pr1p[2] += m1_inv_ * lambda * g1.z; - + pr2p[0] += m2_inv_ * lambda * g2.x; pr2p[1] += m2_inv_ * lambda * g2.y; pr2p[2] += m2_inv_ * lambda * g2.z; - + pr3p[0] += m3_inv_ * lambda * g3.x; pr3p[1] += m3_inv_ * lambda * g3.y; pr3p[2] += m3_inv_ * lambda * g3.z; - + pr4p[0] += m4_inv_ * lambda * g4.x; pr4p[1] += m4_inv_ * lambda * g4.y; pr4p[2] += m4_inv_ * lambda * g4.z; - + return false; } @@ -204,23 +204,23 @@ bool TorsionConstraint::enforce_v(const vector > &r0, double* pv2 = &v0[is2_][3*ia2_]; double* pv3 = &v0[is3_][3*ia3_]; double* pv4 = &v0[is4_][3*ia4_]; - + D3vector r1(pr1); D3vector r2(pr2); D3vector r3(pr3); D3vector r4(pr4); - + D3vector v1(pv1); D3vector v2(pv2); D3vector v3(pv3); D3vector v4(pv4); - + D3vector g1,g2,g3,g4; - + grad_sigma(r1,r2,r3,r4,g1,g2,g3,g4); - + const double norm2 = g1*g1 + g2*g2 + g3*g3 +g4*g4; - + // if the gradient is too small, do not attempt correction if ( norm2 < 1.e-6 ) return true; @@ -228,7 +228,7 @@ bool TorsionConstraint::enforce_v(const vector > &r0, const double err = fabs(proj)/sqrt(norm2); #if DEBUG_CONSTRAINTS cout << " " << endl; #endif if ( err < tol_ ) return true; - + // make one shake iteration - const double den = m1_inv_ * g1 * g1 + + const double den = m1_inv_ * g1 * g1 + m2_inv_ * g2 * g2 + m3_inv_ * g3 * g3 + m4_inv_ * g4 * g4; assert(den>0.0); - + const double eta = -proj / den; - + pv1[0] += m1_inv_ * eta * g1.x; pv1[1] += m1_inv_ * eta * g1.y; pv1[2] += m1_inv_ * eta * g1.z; - + pv2[0] += m2_inv_ * eta * g2.x; pv2[1] += m2_inv_ * eta * g2.y; pv2[2] += m2_inv_ * eta * g2.z; - + pv3[0] += m3_inv_ * eta * g3.x; pv3[1] += m3_inv_ * eta * g3.y; pv3[2] += m3_inv_ * eta * g3.z; - + pv4[0] += m4_inv_ * eta * g4.x; pv4[1] += m4_inv_ * eta * g4.y; pv4[2] += m4_inv_ * eta * g4.z; - + return false; } @@ -280,27 +280,27 @@ void TorsionConstraint::compute_force(const vector > &r0, const double* pf2 = &f[is2_][3*ia2_]; const double* pf3 = &f[is3_][3*ia3_]; const double* pf4 = &f[is4_][3*ia4_]; - + D3vector r1(pr1); D3vector r2(pr2); D3vector r3(pr3); D3vector r4(pr4); - + D3vector f1(pf1); D3vector f2(pf2); D3vector f3(pf3); D3vector f4(pf4); - + const double h = 0.001; const double fac = 0.5 / h; D3vector dx(h,0,0), dy(0,h,0), dz(0,0,h); - + // compute gradient at r - + D3vector g1,g2,g3,g4; - + grad_sigma(r1,r2,r3,r4,g1,g2,g3,g4); - + const double norm2 = g1*g1 + g2*g2 + g3*g3 +g4*g4; assert(norm2>0.0); const double proj = f1*g1 + f2*g2 + f3*g3 + f4*g4; @@ -311,7 +311,7 @@ void TorsionConstraint::compute_force(const vector > &r0, } force_ = -proj/norm2; // compute weight - const double z = m1_inv_ * g1 * g1 + + const double z = m1_inv_ * g1 * g1 + m2_inv_ * g2 * g2 + m3_inv_ * g3 * g3 + m4_inv_ * g4 * g4; @@ -337,7 +337,7 @@ ostream& TorsionConstraint::print( ostream &os ) } //////////////////////////////////////////////////////////////////////////////// -double TorsionConstraint::sigma(D3vector a, D3vector b, +double TorsionConstraint::sigma(D3vector a, D3vector b, D3vector c, D3vector d) const { // compute the constraint function @@ -345,33 +345,33 @@ double TorsionConstraint::sigma(D3vector a, D3vector b, } //////////////////////////////////////////////////////////////////////////////// -void TorsionConstraint::grad_sigma(const D3vector &r1, const D3vector &r2, +void TorsionConstraint::grad_sigma(const D3vector &r1, const D3vector &r2, const D3vector &r3, const D3vector &r4, D3vector &g1, D3vector &g2, D3vector &g3, D3vector &g4) const { const double h = 0.001; const double fac = 0.5 / h; D3vector dx(h,0,0), dy(0,h,0), dz(0,0,h); - + // compute gradient at r - + g1.x = fac * ( sigma(r1+dx,r2,r3,r4) - sigma(r1-dx,r2,r3,r4) ); g1.y = fac * ( sigma(r1+dy,r2,r3,r4) - sigma(r1-dy,r2,r3,r4) ); g1.z = fac * ( sigma(r1+dz,r2,r3,r4) - sigma(r1-dz,r2,r3,r4) ); - + g2.x = fac * ( sigma(r1,r2+dx,r3,r4) - sigma(r1,r2-dx,r3,r4) ); g2.y = fac * ( sigma(r1,r2+dy,r3,r4) - sigma(r1,r2-dy,r3,r4) ); g2.z = fac * ( sigma(r1,r2+dz,r3,r4) - sigma(r1,r2-dz,r3,r4) ); - + g3.x = fac * ( sigma(r1,r2,r3+dx,r4) - sigma(r1,r2,r3-dx,r4) ); g3.y = fac * ( sigma(r1,r2,r3+dy,r4) - sigma(r1,r2,r3-dy,r4) ); g3.z = fac * ( sigma(r1,r2,r3+dz,r4) - sigma(r1,r2,r3-dz,r4) ); - + g4.x = fac * ( sigma(r1,r2,r3,r4+dx) - sigma(r1,r2,r3,r4-dx) ); g4.y = fac * ( sigma(r1,r2,r3,r4+dy) - sigma(r1,r2,r3,r4-dy) ); g4.z = fac * ( sigma(r1,r2,r3,r4+dz) - sigma(r1,r2,r3,r4-dz) ); } - + //////////////////////////////////////////////////////////////////////////////// double TorsionConstraint::torsion_angle(D3vector a, D3vector b, D3vector c, D3vector d) const @@ -381,17 +381,17 @@ double TorsionConstraint::torsion_angle(D3vector a, D3vector b, D3vector e32(normalized(c-b)); D3vector e23(-e32); D3vector e43(normalized(d-c)); - const double sin123 = length(e12^e32); - const double sin234 = length(e23^e43); - - double an = 0; - if ( sin123 != 0.0 && sin234 != 0.0 ) - { - D3vector e123 = normalized(e12^e32); - D3vector e234 = normalized(e23^e43); - double cc = max(min(e123*e234,1.0),-1.0); - double ss = max(min((e123^e234)*e32,1.0),-1.0); - an = (180.0/M_PI) * atan2(ss,cc); - } + const double sin123 = length(e12^e32); + const double sin234 = length(e23^e43); + + double an = 0; + if ( sin123 != 0.0 && sin234 != 0.0 ) + { + D3vector e123 = normalized(e12^e32); + D3vector e234 = normalized(e23^e43); + double cc = max(min(e123*e234,1.0),-1.0); + double ss = max(min((e123^e234)*e32,1.0),-1.0); + an = (180.0/M_PI) * atan2(ss,cc); + } return an; } diff --git a/src/TorsionConstraint.h b/src/TorsionConstraint.h index 7ff527d..0eaa280 100644 --- a/src/TorsionConstraint.h +++ b/src/TorsionConstraint.h @@ -3,7 +3,7 @@ // TorsionConstraint.h // //////////////////////////////////////////////////////////////////////////////// -// $Id: TorsionConstraint.h,v 1.3 2007-03-17 01:14:00 fgygi Exp $ +// $Id: TorsionConstraint.h,v 1.4 2007-10-19 16:24:05 fgygi Exp $ #ifndef TORSIONCONSTRAINT_H #define TORSIONCONSTRAINT_H @@ -26,10 +26,10 @@ class TorsionConstraint : public Constraint D3vector &g1, D3vector &g2,D3vector &g3,D3vector &g4) const; double torsion_angle(D3vector a, D3vector b, D3vector c, D3vector d) const; - + public: - - TorsionConstraint(std::string name, std::string name1, std::string name2, + + TorsionConstraint(std::string name, std::string name1, std::string name2, std::string name3, std::string name4, double angle, double velocity, double tolerance): name1_(name1), name2_(name2), name3_(name3), name4_(name4), @@ -46,7 +46,7 @@ class TorsionConstraint : public Constraint force_ = 0.0; weight_ = 1.0; } - + std::string type(void) const { return "torsion"; } double value(void) const { return angle_; } double velocity(void) const { return velocity_; } @@ -65,7 +65,7 @@ class TorsionConstraint : public Constraint { velocity_ = velocity; } - + void setup(const AtomSet& atoms); void update(double dt); bool enforce_r(const std::vector > &r0, @@ -75,6 +75,6 @@ class TorsionConstraint : public Constraint void compute_force(const std::vector > &r0, const std::vector > &f); std::ostream& print( std::ostream& os ); - + }; #endif diff --git a/src/UnitCell.C b/src/UnitCell.C index 0491f4b..7e7b6de 100644 --- a/src/UnitCell.C +++ b/src/UnitCell.C @@ -3,7 +3,7 @@ // UnitCell.C // //////////////////////////////////////////////////////////////////////////////// -// $Id: UnitCell.C,v 1.12 2005-02-04 21:58:24 fgygi Exp $ +// $Id: UnitCell.C,v 1.13 2007-10-19 16:24:05 fgygi Exp $ #include "UnitCell.h" #include @@ -23,7 +23,7 @@ void UnitCell::set(const D3vector& a0, const D3vector& a1, const D3vector& a2) amat_[6] = a2.x; amat_[7] = a2.y; amat_[8] = a2.z; - + // volume = det(A) volume_ = a0 * ( a1 ^ a2 ); if ( volume_ > 0.0 ) @@ -33,7 +33,7 @@ void UnitCell::set(const D3vector& a0, const D3vector& a1, const D3vector& a2) D3vector amt0 = fac * a1 ^ a2; D3vector amt1 = fac * a2 ^ a0; D3vector amt2 = fac * a0 ^ a1; - + amat_inv_[0] = amt0.x; amat_inv_[1] = amt1.x; amat_inv_[2] = amt2.x; @@ -43,7 +43,7 @@ void UnitCell::set(const D3vector& a0, const D3vector& a1, const D3vector& a2) amat_inv_[6] = amt0.z; amat_inv_[7] = amt1.z; amat_inv_[8] = amt2.z; - + amat_inv_t_[0] = amt0.x; amat_inv_t_[1] = amt0.y; amat_inv_t_[2] = amt0.z; @@ -53,7 +53,7 @@ void UnitCell::set(const D3vector& a0, const D3vector& a1, const D3vector& a2) amat_inv_t_[6] = amt2.x; amat_inv_t_[7] = amt2.y; amat_inv_t_[8] = amt2.z; - + // B = 2 pi A^-T b_[0] = 2.0 * M_PI * amt0; b_[1] = 2.0 * M_PI * amt1; @@ -72,16 +72,16 @@ void UnitCell::set(const D3vector& a0, const D3vector& a1, const D3vector& a2) else { b_[0] = b_[1] = b_[2] = D3vector(0.0,0.0,0.0); - amat_inv_[0] = amat_inv_[1] = amat_inv_[2] = - amat_inv_[3] = amat_inv_[4] = amat_inv_[5] = + amat_inv_[0] = amat_inv_[1] = amat_inv_[2] = + amat_inv_[3] = amat_inv_[4] = amat_inv_[5] = amat_inv_[6] = amat_inv_[7] = amat_inv_[8] = 0.0; - bmat_[0] = bmat_[1] = bmat_[2] = - bmat_[3] = bmat_[4] = bmat_[5] = + bmat_[0] = bmat_[1] = bmat_[2] = + bmat_[3] = bmat_[4] = bmat_[5] = bmat_[6] = bmat_[7] = bmat_[8] = 0.0; } - - - + + + an_[0] = a_[0]; an_[1] = a_[1]; an_[2] = a_[2]; @@ -95,7 +95,7 @@ void UnitCell::set(const D3vector& a0, const D3vector& a1, const D3vector& a2) an_[10] = a_[0] - a_[1] - a_[2]; an_[11] = a_[0] + a_[1] - a_[2]; an_[12] = a_[0] - a_[1] + a_[2]; - + bn_[0] = b_[0]; bn_[1] = b_[1]; bn_[2] = b_[2]; @@ -109,14 +109,14 @@ void UnitCell::set(const D3vector& a0, const D3vector& a1, const D3vector& a2) bn_[10] = b_[0] - b_[1] - b_[2]; bn_[11] = b_[0] + b_[1] - b_[2]; bn_[12] = b_[0] - b_[1] + b_[2]; - + for ( int i = 0; i < 13; i++ ) { an2h_[i] = 0.5 * norm(an_[i]); bn2h_[i] = 0.5 * norm(bn_[i]); } } - + //////////////////////////////////////////////////////////////////////////////// bool UnitCell::in_ws(const D3vector& v) const { @@ -129,7 +129,7 @@ bool UnitCell::in_ws(const D3vector& v) const } return in; } - + //////////////////////////////////////////////////////////////////////////////// void UnitCell::fold_in_ws(D3vector& v) const { @@ -162,7 +162,7 @@ void UnitCell::fold_in_ws(D3vector& v) const } assert(iter < maxiter); } - + //////////////////////////////////////////////////////////////////////////////// bool UnitCell::in_bz(const D3vector& k) const { @@ -175,7 +175,7 @@ bool UnitCell::in_bz(const D3vector& k) const } return in; } - + //////////////////////////////////////////////////////////////////////////////// void UnitCell::fold_in_bz(D3vector& k) const { @@ -208,7 +208,7 @@ void UnitCell::fold_in_bz(D3vector& k) const } assert(iter < maxiter); } - + //////////////////////////////////////////////////////////////////////////////// bool UnitCell::encloses(const UnitCell& c) const { @@ -236,29 +236,29 @@ bool UnitCell::contains(D3vector v) const (p1 > 0.0) && (p1 <= 1.0) && (p2 > 0.0) && (p2 <= 1.0) ); } - + //////////////////////////////////////////////////////////////////////////////// void UnitCell::print(ostream& os) const { os.setf(ios::fixed,ios::floatfield); os << setprecision(8); - os << " " << setw(12) << a_[0].x << " " - << setw(12) << a_[0].y << " " + os << " " << setw(12) << a_[0].x << " " + << setw(12) << a_[0].y << " " << setw(12) << a_[0].z << " " << endl; - os << " " << setw(12) << a_[1].x << " " - << setw(12) << a_[1].y << " " + os << " " << setw(12) << a_[1].x << " " + << setw(12) << a_[1].y << " " << setw(12) << a_[1].z << " " << endl; - os << " " << setw(12) << a_[2].x << " " - << setw(12) << a_[2].y << " " + os << " " << setw(12) << a_[2].x << " " + << setw(12) << a_[2].y << " " << setw(12) << a_[2].z << " " << endl; } - + //////////////////////////////////////////////////////////////////////////////// bool UnitCell::operator==(const UnitCell& c) const { return ( a_[0]==c.a_[0] && a_[1]==c.a_[1] && a_[2]==c.a_[2] ); } - + //////////////////////////////////////////////////////////////////////////////// bool UnitCell::operator!=(const UnitCell& c) const { @@ -271,7 +271,7 @@ void UnitCell::vecmult3x3(const double* x, const double* y, double *z) const // | z0 | | x0 x3 x6 | | y0 | // | z1 | = | x1 x4 x7 | * | y1 | // | z2 | | x2 x5 x8 | | y2 | - + const double z0 = x[0]*y[0]+x[3]*y[1]+x[6]*y[2]; const double z1 = x[1]*y[0]+x[4]*y[1]+x[7]*y[2]; const double z2 = x[2]*y[0]+x[5]*y[1]+x[8]*y[2]; @@ -279,69 +279,69 @@ void UnitCell::vecmult3x3(const double* x, const double* y, double *z) const z[1] = z1; z[2] = z2; } - + //////////////////////////////////////////////////////////////////////////////// void UnitCell::matmult3x3(const double* x, const double* y, double *z) const { // | z0 z3 z6 | | x0 x3 x6 | | y0 y3 y6 | // | z1 z4 z7 | = | x1 x4 x7 | * | y1 y4 y7 | // | z2 z5 z8 | | x2 x5 x8 | | y2 y5 y8 | - + const double z00 = x[0]*y[0]+x[3]*y[1]+x[6]*y[2]; const double z10 = x[1]*y[0]+x[4]*y[1]+x[7]*y[2]; const double z20 = x[2]*y[0]+x[5]*y[1]+x[8]*y[2]; - + const double z01 = x[0]*y[3]+x[3]*y[4]+x[6]*y[5]; const double z11 = x[1]*y[3]+x[4]*y[4]+x[7]*y[5]; const double z21 = x[2]*y[3]+x[5]*y[4]+x[8]*y[5]; - + const double z02 = x[0]*y[6]+x[3]*y[7]+x[6]*y[8]; const double z12 = x[1]*y[6]+x[4]*y[7]+x[7]*y[8]; const double z22 = x[2]*y[6]+x[5]*y[7]+x[8]*y[8]; - + z[0] = z00; z[1] = z10; z[2] = z20; - + z[3] = z01; z[4] = z11; z[5] = z21; - + z[6] = z02; z[7] = z12; - z[8] = z22; + z[8] = z22; } - + //////////////////////////////////////////////////////////////////////////////// void UnitCell::smatmult3x3(const double* xs, const double* y, double *z) const { // | z0 z3 z6 | | xs0 xs3 xs5 | | y0 y3 y6 | // | z1 z4 z7 | = | xs3 xs1 xs4 | * | y1 y4 y7 | // | z2 z5 z8 | | xs5 xs4 xs2 | | y2 y5 y8 | - + const double z00 = xs[0]*y[0]+xs[3]*y[1]+xs[5]*y[2]; const double z10 = xs[3]*y[0]+xs[1]*y[1]+xs[4]*y[2]; const double z20 = xs[5]*y[0]+xs[4]*y[1]+xs[2]*y[2]; - + const double z01 = xs[0]*y[3]+xs[3]*y[4]+xs[5]*y[5]; const double z11 = xs[3]*y[3]+xs[1]*y[4]+xs[4]*y[5]; const double z21 = xs[5]*y[3]+xs[4]*y[4]+xs[2]*y[5]; - + const double z02 = xs[0]*y[6]+xs[3]*y[7]+xs[5]*y[8]; const double z12 = xs[3]*y[6]+xs[1]*y[7]+xs[4]*y[8]; const double z22 = xs[5]*y[6]+xs[4]*y[7]+xs[2]*y[8]; - + z[0] = z00; z[1] = z10; z[2] = z20; - + z[3] = z01; z[4] = z11; z[5] = z21; - + z[6] = z02; z[7] = z12; - z[8] = z22; + z[8] = z22; } //////////////////////////////////////////////////////////////////////////////// void UnitCell::compute_deda(const valarray& sigma, @@ -350,20 +350,20 @@ void UnitCell::compute_deda(const valarray& sigma, // Compute energy derivatives dE/da_ij from a symmetric stress tensor assert(sigma.size()==6); assert(deda.size()==9); - + //!! local copy of sigma to circumvent bug in icc compiler valarray sigma_loc(6); sigma_loc = sigma; - + // deda = - omega * sigma * A^-T smatmult3x3(&sigma_loc[0],&amat_inv_t_[0],&deda[0]); - + deda *= -volume_; } - + //////////////////////////////////////////////////////////////////////////////// ostream& operator<< ( ostream& os, const UnitCell& cell ) -{ - cell.print(os); +{ + cell.print(os); return os; } diff --git a/src/UnitCell.h b/src/UnitCell.h index e31160e..6430b13 100644 --- a/src/UnitCell.h +++ b/src/UnitCell.h @@ -3,7 +3,7 @@ // UnitCell.h // //////////////////////////////////////////////////////////////////////////////// -// $Id: UnitCell.h,v 1.5 2007-03-17 01:14:00 fgygi Exp $ +// $Id: UnitCell.h,v 1.6 2007-10-19 16:24:05 fgygi Exp $ #ifndef UNITCELL_H #define UNITCELL_H @@ -23,7 +23,7 @@ class UnitCell D3vector bn_[13]; double an2h_[13]; double bn2h_[13]; - + // 3x3 matrix forms double amat_[9]; double bmat_[9]; @@ -31,29 +31,29 @@ class UnitCell double amat_inv_[9]; // 3x3 matrix form of inverse transpose double amat_inv_t_[9]; - + public: const D3vector& a(int i) const { return a_[i]; } const D3vector& b(int i) const { return b_[i]; } - - UnitCell(void) { set(D3vector(0,0,0),D3vector(0,0,0),D3vector(0,0,0)); } + + UnitCell(void) { set(D3vector(0,0,0),D3vector(0,0,0),D3vector(0,0,0)); } explicit UnitCell(const D3vector& a0, const D3vector& a1, const D3vector& a2) { set(a0,a1,a2); } - + void set(const D3vector& a0, const D3vector& a1, const D3vector& a2); double volume(void) const { return volume_; } - + const double* amat(void) const { return &amat_[0]; } const double* bmat(void) const { return &bmat_[0]; } const double* amat_inv(void) const { return &amat_inv_[0]; } double amat(int ij) const { return amat_[ij]; } double bmat(int ij) const { return bmat_[ij]; } double amat_inv(int ij) const { return amat_inv_[ij]; } - + // 3x3 matrix vector multiply Z = X Y where X is a 3x3 matrix, Y,Z 3-vectors void vecmult3x3(const double* x, const double* y, double *z) const; - + // 3x3 matrix matrix multiply Z = X Y where X, Y are 3x3 matrices void matmult3x3(const double* x, const double* y, double *z) const; // Z = X Y where X is a symmetric 3x3 matrix and Y a general 3x3 matrix @@ -61,18 +61,18 @@ class UnitCell // where xs[0] = x00, xs[1] = x11, xs[2] = x22, // xs[3] = x10, xs[4] = x21, xs[5] = x20 void smatmult3x3(const double* xs, const double* y, double *z) const; - void compute_deda(const std::valarray& sigma, + void compute_deda(const std::valarray& sigma, std::valarray& deda) const; - + bool in_ws(const D3vector& v) const; void fold_in_ws(D3vector& v) const; bool in_bz(const D3vector& k) const; void fold_in_bz(D3vector& k) const; - + bool encloses(const UnitCell& c) const; bool contains(D3vector v) const; - - void print(std::ostream& os) const; + + void print(std::ostream& os) const; bool operator==(const UnitCell& c) const; bool operator!=(const UnitCell& c) const; }; diff --git a/src/UserInterface.C b/src/UserInterface.C index ad66752..029a8a6 100644 --- a/src/UserInterface.C +++ b/src/UserInterface.C @@ -3,7 +3,7 @@ // UserInterface.C: definition of readCmd and processCmds // //////////////////////////////////////////////////////////////////////////////// -// $Id: UserInterface.C,v 1.4 2007-03-17 01:14:00 fgygi Exp $ +// $Id: UserInterface.C,v 1.5 2007-10-19 16:24:05 fgygi Exp $ #include "UserInterface.h" #include @@ -63,10 +63,10 @@ char *UserInterface::readCmd(char *s, int max, istream &fp, bool echo) if ( !(ch == '\n' || ch == ';' || ch == '#') ) return NULL; /* return NULL for end of file */ - + // output command line if reading from a script if ( echo ) cout << s; - + if ( ch == '#' ) { if ( echo ) cout << '#'; @@ -77,7 +77,7 @@ char *UserInterface::readCmd(char *s, int max, istream &fp, bool echo) if ( !(ch == '\n') ) return NULL; /* return NULL for end of file */ } - + return s; } @@ -91,10 +91,10 @@ void UserInterface::processCmds ( istream &cmdstream, char *prompt, bool echo ) char *tok; const char *separators = " ;\t"; int i,done,status; - + if ( onpe0_ ) cout << "" << endl; - + // cmdline contains a string of tokens terminated by '\0' // cout << " command line is: " << cmdline << endl; @@ -159,7 +159,7 @@ void UserInterface::processCmds ( istream &cmdstream, char *prompt, bool echo ) av[i++] = *iarg++; } av[ntok] = 0; - + // write arguments // for ( i = 0; i < ac; i++ ) // { @@ -168,7 +168,7 @@ void UserInterface::processCmds ( istream &cmdstream, char *prompt, bool echo ) // search cmdlist for command - tok = av[0]; + tok = av[0]; // check for empty command line if ( tok != 0 ) @@ -231,10 +231,10 @@ void UserInterface::processCmds ( istream &cmdstream, char *prompt, bool echo ) } } delete [] av; - if ( onpe0_ ) + if ( onpe0_ ) cout << "" << endl << "" << endl; } diff --git a/src/UserInterface.h b/src/UserInterface.h index 8d2c379..76b6c2b 100644 --- a/src/UserInterface.h +++ b/src/UserInterface.h @@ -37,12 +37,12 @@ class Var class UserInterface { private: - + char *readCmd(char *s, int max, std::istream &fp, bool echo); bool terminate_; bool onpe0_; - public: + public: std::list cmdlist; std::list varlist; @@ -94,11 +94,11 @@ class UserInterface }; void processCmds(std::istream &cmdstream, char *prompt, bool echo); - + void terminate(void) { terminate_ = true; } - + bool onpe0(void) const { return onpe0_; } - + UserInterface(void); }; #endif diff --git a/src/Wavefunction.C b/src/Wavefunction.C index 3a5a308..2630a93 100644 --- a/src/Wavefunction.C +++ b/src/Wavefunction.C @@ -3,7 +3,7 @@ // Wavefunction.C // //////////////////////////////////////////////////////////////////////////////// -// $Id: Wavefunction.C,v 1.22 2007-01-27 23:52:34 fgygi Exp $ +// $Id: Wavefunction.C,v 1.23 2007-10-19 16:24:05 fgygi Exp $ #include "Wavefunction.h" #include "SlaterDet.h" @@ -17,8 +17,8 @@ using namespace std; //////////////////////////////////////////////////////////////////////////////// -Wavefunction::Wavefunction(const Context& ctxt) : ctxt_(ctxt), nel_(0), -nempty_(0), nspin_(1), deltaspin_(0), ecut_(0.0), nrowmax_(32) +Wavefunction::Wavefunction(const Context& ctxt) : ctxt_(ctxt), nel_(0), +nempty_(0), nspin_(1), deltaspin_(0), ecut_(0.0), nrowmax_(32) { // create a default wavefunction: one k point, k=0 kpoint_.resize(1); @@ -30,33 +30,33 @@ nempty_(0), nspin_(1), deltaspin_(0), ecut_(0.0), nrowmax_(32) } //////////////////////////////////////////////////////////////////////////////// -Wavefunction::Wavefunction(const Wavefunction& wf) : ctxt_(wf.ctxt_), -nel_(wf.nel_), nempty_(wf.nempty_), nspin_(wf.nspin_), -deltaspin_(wf.deltaspin_), nrowmax_(wf.nrowmax_), +Wavefunction::Wavefunction(const Wavefunction& wf) : ctxt_(wf.ctxt_), +nel_(wf.nel_), nempty_(wf.nempty_), nspin_(wf.nspin_), +deltaspin_(wf.deltaspin_), nrowmax_(wf.nrowmax_), cell_(wf.cell_), refcell_(wf.refcell_), ecut_(wf.ecut_), weight_(wf.weight_), kpoint_(wf.kpoint_) { // Create a Wavefunction using the dimensions of the argument - + compute_nst(); - - // Next lines: do special allocation of contexts to ensure that + + // Next lines: do special allocation of contexts to ensure that // contexts are same as those of wf - + // create sd contexts and SlaterDets const int nkp = kpoint_.size(); - + assert(ctxt_.active()); - + assert(nspin_ == 1); assert(nkp == 1); - + spincontext_.resize(1); sdcontext_.resize(1); sdcontext_[0].resize(1); sd_.resize(1); sd_[0].resize(1); - + spincontext_[0] = new Context(*wf.spincontext_[0]); sdcontext_[0][0] = 0; sd_[0][0] = 0; @@ -65,7 +65,7 @@ ecut_(wf.ecut_), weight_(wf.weight_), kpoint_(wf.kpoint_) sdcontext_[0][0] = new Context(*wf.spincontext_[0]); sd_[0][0] = new SlaterDet(*sdcontext_[0][0],kpoint_[0]); } - + resize(cell_,refcell_,ecut_); reset(); } @@ -81,12 +81,12 @@ void Wavefunction::allocate(void) { // create sd contexts and SlaterDets const int nkp = kpoint_.size(); - + assert(ctxt_.active()); - + assert(nspin_ == 1); assert(nkp == 1); - + // determine dimensions of sdcontext assert(nrowmax_>0); const int size = ctxt_.size(); @@ -100,7 +100,7 @@ void Wavefunction::allocate(void) sdcontext_[0].resize(1); sd_.resize(1); sd_[0].resize(1); - + spincontext_[0] = new Context(npr,npc); //cout << *spincontext_[0]; sdcontext_[0][0] = 0; @@ -150,14 +150,14 @@ void Wavefunction::clear(void) } } //////////////////////////////////////////////////////////////////////////////// -int Wavefunction::nkp(void) const { return kpoint_.size(); } +int Wavefunction::nkp(void) const { return kpoint_.size(); } //////////////////////////////////////////////////////////////////////////////// int Wavefunction::nel() const { return nel_; } // total number of electrons //////////////////////////////////////////////////////////////////////////////// int Wavefunction::nst() const -{ +{ if ( nspin_ == 1 ) return nst_[0]; else @@ -178,7 +178,7 @@ int Wavefunction::nempty() const { return nempty_; } // number of empty states int Wavefunction::nspin() const { return nspin_; } // number of empty states //////////////////////////////////////////////////////////////////////////////// -double Wavefunction::entropy(void) const +double Wavefunction::entropy(void) const { assert(nspin_==1); assert(kpoint_.size()==1); @@ -186,7 +186,7 @@ double Wavefunction::entropy(void) const } //////////////////////////////////////////////////////////////////////////////// -void Wavefunction::resize(const UnitCell& cell, const UnitCell& refcell, +void Wavefunction::resize(const UnitCell& cell, const UnitCell& refcell, double ecut) { try @@ -218,9 +218,9 @@ void Wavefunction::resize(const UnitCell& cell, const UnitCell& refcell, cout << " Wavefunction: insufficient memory for resize operation" << endl; return; } - + } - + //////////////////////////////////////////////////////////////////////////////// void Wavefunction::reset(void) { @@ -236,7 +236,7 @@ void Wavefunction::reset(void) } } } - + //////////////////////////////////////////////////////////////////////////////// void Wavefunction::compute_nst(void) { @@ -264,13 +264,13 @@ void Wavefunction::set_nel(int nel) cout << " Wavefunction::set_nel: nel < 0" << endl; return; } - + nel_ = nel; compute_nst(); resize(cell_,refcell_,ecut_); reset(); } - + //////////////////////////////////////////////////////////////////////////////// void Wavefunction::set_nempty(int nempty) { @@ -291,12 +291,12 @@ void Wavefunction::set_nspin(int nspin) { assert(nspin==1 || nspin==2); if ( nspin == nspin_ ) return; - + deallocate(); cout << " Wavefunction::set_nspin: " << nspin << " deallocate done" << endl; - + nspin_ = nspin; - + compute_nst(); allocate(); cout << " Wavefunction::set_nspin: " << nspin << " allocate done" << endl; @@ -312,7 +312,7 @@ void Wavefunction::set_nrowmax(int n) cout << " Wavefunction::set_nrowmax: nrowmax > ctxt_.size()" << endl; return; } - + deallocate(); nrowmax_ = n; compute_nst(); @@ -320,7 +320,7 @@ void Wavefunction::set_nrowmax(int n) resize(cell_,refcell_,ecut_); reset(); } - + //////////////////////////////////////////////////////////////////////////////// void Wavefunction::add_kpoint(D3vector kpoint, double weight) { @@ -328,18 +328,18 @@ void Wavefunction::add_kpoint(D3vector kpoint, double weight) { if ( kpoint == kpoint_[i] ) { - cout << " Wavefunction::add_kpoint: warning: kpoint already defined" + cout << " Wavefunction::add_kpoint: warning: kpoint already defined" << endl; //!! return; } } - + deallocate(); cout << " Wavefunction::add_kpoint: " << kpoint << " deallocate done" << endl; - + kpoint_.push_back(kpoint); weight_.push_back(weight); - + allocate(); cout << " Wavefunction::add_kpoint: " << kpoint << " allocate done" << endl; resize(cell_,refcell_,ecut_); @@ -408,7 +408,7 @@ void Wavefunction::update_occ(double temp) // finite temperature const double eVolt = 0.036749023; // 1 eV in Hartree const int maxiter = 500; - + // loop to find value of mu double mu = 0.0; double dmu = 2.0 * eVolt; @@ -433,7 +433,7 @@ void Wavefunction::update_occ(double temp) assert(kpoint_.size()==1); } } - + int niter = 0; while ( niter < maxiter && fabs(rhosum - nel_) > 1.e-10 ) { @@ -467,7 +467,7 @@ void Wavefunction::update_occ(double temp) } } } - + if ( niter == maxiter ) { cout << "Wavefunction::update_occ: mu did not converge in " @@ -485,7 +485,7 @@ void Wavefunction::update_occ(double temp) cout.setf(ios::right,ios::adjustfield); cout.setf(ios::fixed,ios::floatfield); - + cout << "