Skip to content

Commit c554b54

Browse files
siuwuncheungjeanlucf22dreamer2368
authored
Merge release (#332)
* Fix EnergyAndForces tests (#277) * have them work in debug mode too * Move factor 4pi out og linear solvers (#278) * Move some code into PoissonSolverFactory (#279) * Clean up class Potentials (#280) * Clean up class Ions, add test for it (#281) * Add test MD_MVP (#290) * Clean up code related to DM restart data (#292) * Write dm (#291) * Update use of DM in restart * Remove unused function in Control (#294) * Change symlink to restart in tests (#295) * enable tests when old link present * Extract number empty orbitals from restart file (#296) * Clean up MD_IonicStepper restart data write (#297) * Clean up code based on compiler warnings (#299) * Add getForces for evaluateDMandEnergyAndForces (#300) * Add check for compatibility MVP/Mehrstellen (#301) * Add support for Br atom (#302) * Clean up some HDFrestart functions (#303) * Fix and test restart single hdf5 file (#305) * Save Hartree potential for write in restart file (#306) * Speed-up recently added tests (#309) * simply use a smaller domain/mesh * Encapsulate some functions in Potentials (#310) * some functions were called at random places and confusing * Remove confusing 0 in naming restart files (#308) * use added integer only in case of fail/retry * Add functionalities for extra info in restart file (#312) * MPI abort (#313) * Fix error code used by MPI_Abort * Rho and VH restart (#311) * enable restart with consistent rho and VHartree --------- Co-authored-by: Seung Whan Chung <[email protected]> * Strenghten testIons (#315) * More clean up in class Potentials (#316) * remove some unused functions * make use of class MGmol_MPI * change some function names for clarity * fix some minor bug in iterative indexes * Misc code fixes (#317) * exposed by porting on new environment * Use unique restart filenames in test HDF5single (#318) * Swap ions in existing test (#319) * strengthen testing by swapping ions in testRestartEnergyAndForces * Code clean up (#320) * use more const * use initNuc() instead of moveVnuc() * remove incorrect assert * use MGmol_MPI in more cases * setup g_kbpsi_ inside initNuc() * rename initNuc() into setupPotentials() * Added functionalities to set local forces (#321) * Update mixed precision code (#322) * enable cmake build with mixed precision * enable use of BLIS * isolate blas3 loop rewrite in separate files * fix misc issues with mixed precision code * Clean up and fixes Ions (#326) * reset static index counter ion Ion when needed * simplify some loops * make Ions copy constructor private * Fixes for build without HDF5P (#324) * Fix testRhoVhRestart (#325) * Fix a few more issues with class Ions (#328) * Introduce new constructor for class Ions (#330) * modify various functions to use argument of type Ions instead of MGmol::ions_ --------- Co-authored-by: Jean-Luc Fattebert <[email protected]> Co-authored-by: Seung Whan Chung <[email protected]>
1 parent 58990e5 commit c554b54

17 files changed

+184
-183
lines changed

src/ABPG.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ void ABPG<T>::setup(T& orbitals)
3838
//
3939
// orthof=true: wants orthonormalized updated wave functions
4040
template <class T>
41-
int ABPG<T>::updateWF(T& orbitals, Ions& /*ions*/, const double precond_factor,
41+
int ABPG<T>::updateWF(T& orbitals, Ions& ions, const double precond_factor,
4242
const bool /*orthof*/, T& work_orbitals, const bool accelerate,
4343
const bool print_res, const double atol)
4444
{
@@ -51,8 +51,8 @@ int ABPG<T>::updateWF(T& orbitals, Ions& /*ions*/, const double precond_factor,
5151
T res("Residual", orbitals, false);
5252

5353
const bool check_res = (atol > 0.);
54-
double normRes = mgmol_strategy_->computeResidual(
55-
orbitals, work_orbitals, res, (print_res || check_res), check_res);
54+
double normRes = mgmol_strategy_->computeResidual(orbitals, work_orbitals,
55+
ions, res, (print_res || check_res), check_res);
5656
if (normRes < atol && check_res)
5757
{
5858
abpg_nl_update_tm_.stop();

src/DFTsolver.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -196,8 +196,8 @@ double DFTsolver<OrbitalsType>::evaluateEnergy(
196196

197197
// Get the new total energy
198198
const double ts = 0.5 * proj_matrices_->computeEntropy(); // in [Ha]
199-
eks_history_[0]
200-
= energy_->evaluateTotal(ts, proj_matrices_, orbitals, print_flag, os_);
199+
eks_history_[0] = energy_->evaluateTotal(
200+
ts, proj_matrices_, ions_, orbitals, print_flag, os_);
201201

202202
sum_eig_[1] = sum_eig_[0];
203203
sum_eig_[0] = 2. * proj_matrices_->getEigSum(); // 2.*sum in [Ry]

src/DavidsonSolver.cc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -500,7 +500,7 @@ int DavidsonSolver<OrbitalsType, MatrixType>::solve(
500500

501501
ts0 = evalEntropy(projmatrices, (ct.verbose > 1), os_);
502502
e0 = energy_->evaluateTotal(
503-
ts0, projmatrices, orbitals, printE, os_);
503+
ts0, projmatrices, ions_, orbitals, printE, os_);
504504

505505
retval = checkConvergence(e0, outer_it, ct.conv_tol);
506506
if (retval == 0 || (outer_it == ct.max_electronic_steps))
@@ -549,7 +549,7 @@ int DavidsonSolver<OrbitalsType, MatrixType>::solve(
549549

550550
ts0 = evalEntropy(proj_mat2N_.get(), (ct.verbose > 1), os_);
551551
e0 = energy_->evaluateTotal(
552-
ts0, proj_mat2N_.get(), orbitals, printE, os_);
552+
ts0, proj_mat2N_.get(), ions_, orbitals, printE, os_);
553553
}
554554

555555
// 2N x 2N target...
@@ -621,8 +621,8 @@ int DavidsonSolver<OrbitalsType, MatrixType>::solve(
621621

622622
const double ts1
623623
= evalEntropy(proj_mat2N_.get(), (ct.verbose > 2), os_);
624-
const double e1 = energy_->evaluateTotal(
625-
ts1, proj_mat2N_.get(), orbitals, ct.verbose - 1, os_);
624+
const double e1 = energy_->evaluateTotal(ts1, proj_mat2N_.get(),
625+
ions_, orbitals, ct.verbose - 1, os_);
626626

627627
// line minimization
628628
beta = minQuadPolynomial(e0, e1, de0, (ct.verbose > 2), os_);

src/Energy.cc

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,10 @@
2525
#define RY2HA 0.5
2626

2727
template <class T>
28-
Energy<T>::Energy(const pb::Grid& mygrid, const Ions& ions,
29-
const Potentials& pot, const Electrostatic& es, const Rho<T>& rho,
30-
const XConGrid& xc, SpreadPenaltyInterface<T>* spread_penalty)
28+
Energy<T>::Energy(const pb::Grid& mygrid, const Potentials& pot,
29+
const Electrostatic& es, const Rho<T>& rho, const XConGrid& xc,
30+
SpreadPenaltyInterface<T>* spread_penalty)
3131
: mygrid_(mygrid),
32-
ions_(ions),
3332
pot_(pot),
3433
es_(es),
3534
rho_(rho),
@@ -59,7 +58,7 @@ double Energy<T>::getEVrhoRho() const
5958
}
6059

6160
template <class T>
62-
double Energy<T>::evaluateEnergyIonsInVext()
61+
double Energy<T>::evaluateEnergyIonsInVext(Ions& ions)
6362
{
6463
double energy = 0.;
6564

@@ -69,12 +68,12 @@ double Energy<T>::evaluateEnergyIonsInVext()
6968
//(*MPIdata::sout)<<"Energy<T>::evaluateEnergyIonsInVext()"<<std::endl;
7069
double position[3];
7170
std::vector<double> positions;
72-
positions.reserve(3 * ions_.local_ions().size());
71+
positions.reserve(3 * ions.local_ions().size());
7372

7473
// loop over ions
7574
int nions = 0;
76-
std::vector<Ion*>::const_iterator ion = ions_.local_ions().begin();
77-
while (ion != ions_.local_ions().end())
75+
std::vector<Ion*>::const_iterator ion = ions.local_ions().begin();
76+
while (ion != ions.local_ions().end())
7877
{
7978
(*ion)->getPosition(position);
8079
positions.push_back(position[0]);
@@ -88,9 +87,9 @@ double Energy<T>::evaluateEnergyIonsInVext()
8887
pot_.getValVext(positions, val);
8988

9089
// loop over ions again
91-
ion = ions_.local_ions().begin();
90+
ion = ions.local_ions().begin();
9291
int ion_index = 0;
93-
while (ion != ions_.local_ions().end())
92+
while (ion != ions.local_ions().end())
9493
{
9594
const double z = (*ion)->getZion();
9695
// int ion_index=(*ion)->index();
@@ -112,16 +111,16 @@ double Energy<T>::evaluateEnergyIonsInVext()
112111

113112
template <class T>
114113
double Energy<T>::evaluateTotal(const double ts, // in [Ha]
115-
ProjectedMatricesInterface* projmatrices, const T& phi, const int verbosity,
116-
std::ostream& os)
114+
ProjectedMatricesInterface* projmatrices, Ions& ions, const T& phi,
115+
const int verbosity, std::ostream& os)
117116
{
118117
eval_te_tm_.start();
119118

120119
Control& ct = *(Control::instance());
121120

122-
const double eself = ions_.energySelf();
123-
const double ediff = ions_.energyDiff(ct.bcPoisson);
124-
const double eipot = evaluateEnergyIonsInVext();
121+
const double eself = ions.energySelf();
122+
const double ediff = ions.energyDiff(ct.bcPoisson);
123+
const double eipot = evaluateEnergyIonsInVext(ions);
125124

126125
const double eigsum = 0.5 * projmatrices->getExpectationH();
127126

src/Energy.h

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#define MGMOL_ENERGY_H
1212

1313
#include "Grid.h"
14+
#include "Ions.h"
1415
#include "Rho.h"
1516
#include "SpreadPenaltyInterface.h"
1617
#include "Timer.h"
@@ -20,7 +21,6 @@
2021
#include <vector>
2122

2223
class Potentials;
23-
class Ions;
2424
class Electrostatic;
2525
class ProjectedMatricesInterface;
2626
class XConGrid;
@@ -29,7 +29,6 @@ template <class T>
2929
class Energy
3030
{
3131
const pb::Grid& mygrid_;
32-
const Ions& ions_;
3332
const Potentials& pot_;
3433
const Electrostatic& es_;
3534
const Rho<T>& rho_;
@@ -45,16 +44,15 @@ class Energy
4544
double getEVrhoRho() const;
4645

4746
public:
48-
Energy(const pb::Grid&, const Ions&, const Potentials&,
49-
const Electrostatic&, const Rho<T>&, const XConGrid&,
50-
SpreadPenaltyInterface<T>*);
47+
Energy(const pb::Grid&, const Potentials&, const Electrostatic&,
48+
const Rho<T>&, const XConGrid&, SpreadPenaltyInterface<T>*);
5149

5250
static Timer eval_te_tm() { return eval_te_tm_; }
5351

54-
double evaluateTotal(const double ts, ProjectedMatricesInterface*,
52+
double evaluateTotal(const double ts, ProjectedMatricesInterface*, Ions&,
5553
const T& phi, const int, std::ostream&);
5654

57-
double evaluateEnergyIonsInVext();
55+
double evaluateEnergyIonsInVext(Ions&);
5856

5957
void saveVofRho();
6058
};

src/GrassmanLineMinimization.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ Timer GrassmanLineMinimization<T>::update_states_tm_("Grassman_update_states");
2929
//
3030
// orthof=true: wants orthonormalized updated wave functions
3131
template <class T>
32-
int GrassmanLineMinimization<T>::updateWF(T& orbitals, Ions& /*ions*/,
32+
int GrassmanLineMinimization<T>::updateWF(T& orbitals, Ions& ions,
3333
const double precond_factor, const bool orthof, T& work_orbitals,
3434
const bool accelerate, const bool print_res, const double atol)
3535
{
@@ -61,7 +61,7 @@ int GrassmanLineMinimization<T>::updateWF(T& orbitals, Ions& /*ions*/,
6161
// Update wavefunctions
6262
const bool check_res = (atol > 0.);
6363
double normRes = mgmol_strategy_->computeResidual(orbitals, work_orbitals,
64-
*new_grad_, (print_res || check_res), check_res);
64+
ions, *new_grad_, (print_res || check_res), check_res);
6565
if (normRes < atol && check_res)
6666
{
6767
nl_update_tm_.stop();

src/HamiltonianMVPSolver.cc

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -160,8 +160,8 @@ int HamiltonianMVPSolver<MatrixType, ProjMatrixType, OrbitalsType>::solve(
160160

161161
// compute energy at origin
162162
const int printE = (ct.verbose > 1) ? 1 : 0;
163-
double e0
164-
= energy_->evaluateTotal(ts0, projmatrices, orbitals, printE, os_);
163+
double e0 = energy_->evaluateTotal(
164+
ts0, projmatrices, ions_, orbitals, printE, os_);
165165

166166
//
167167
// compute energy at end for new H
@@ -189,8 +189,8 @@ int HamiltonianMVPSolver<MatrixType, ProjMatrixType, OrbitalsType>::solve(
189189
projmatrices->setHB2H();
190190

191191
// compute energy at end (beta=1.)
192-
double e1
193-
= energy_->evaluateTotal(ts1, projmatrices, orbitals, printE, os_);
192+
double e1 = energy_->evaluateTotal(
193+
ts1, projmatrices, ions_, orbitals, printE, os_);
194194

195195
//
196196
// evaluate energy at mid-point
@@ -226,8 +226,8 @@ int HamiltonianMVPSolver<MatrixType, ProjMatrixType, OrbitalsType>::solve(
226226
projmatrices->setHB2H();
227227

228228
// compute energy at midpoint
229-
double ei
230-
= energy_->evaluateTotal(tsi, projmatrices, orbitals, printE, os_);
229+
double ei = energy_->evaluateTotal(
230+
tsi, projmatrices, ions_, orbitals, printE, os_);
231231

232232
// line minimization
233233
double beta
@@ -285,7 +285,7 @@ int HamiltonianMVPSolver<MatrixType, ProjMatrixType, OrbitalsType>::solve(
285285

286286
// compute energy at end (beta=1.)
287287
ei = energy_->evaluateTotal(
288-
tsi, projmatrices, orbitals, printE, os_);
288+
tsi, projmatrices, ions_, orbitals, printE, os_);
289289

290290
// line minimization
291291
beta = minQuadPolynomialFrom3values(

0 commit comments

Comments
 (0)