Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
1ad1292
Fix EnergyAndForces tests (#277)
jeanlucf22 Sep 26, 2024
8ac6cd6
Move factor 4pi out og linear solvers (#278)
jeanlucf22 Sep 30, 2024
a2ece1a
Move some code into PoissonSolverFactory (#279)
jeanlucf22 Sep 30, 2024
8b577ea
Clean up class Potentials (#280)
jeanlucf22 Oct 3, 2024
7ac691c
Clean up class Ions, add test for it (#281)
jeanlucf22 Oct 12, 2024
c05ba7f
Add test MD_MVP (#290)
jeanlucf22 Nov 25, 2024
bb8051d
Clean up code related to DM restart data (#292)
jeanlucf22 Dec 2, 2024
a227c04
Write dm (#291)
jeanlucf22 Dec 2, 2024
b263532
Remove unused function in Control (#294)
jeanlucf22 Dec 23, 2024
3eb52d6
Change symlink to restart in tests (#295)
jeanlucf22 Jan 3, 2025
c1d46bc
Extract number empty orbitals from restart file (#296)
jeanlucf22 Jan 7, 2025
eb53963
Clean up MD_IonicStepper restart data write (#297)
jeanlucf22 Jan 16, 2025
857673f
Clean up code based on compiler warnings (#299)
jeanlucf22 Jan 17, 2025
f294d3c
Add getForces for evaluateDMandEnergyAndForces (#300)
siuwuncheung Jan 23, 2025
98a79de
Add check for compatibility MVP/Mehrstellen (#301)
jeanlucf22 Jan 24, 2025
8eda83e
Add support for Br atom (#302)
jeanlucf22 Feb 3, 2025
f298d43
Clean up some HDFrestart functions (#303)
jeanlucf22 Feb 11, 2025
c690bc5
Fix and test restart single hdf5 file (#305)
jeanlucf22 Feb 17, 2025
9f1fc20
Save Hartree potential for write in restart file (#306)
jeanlucf22 Feb 17, 2025
8a1cf05
Speed-up recently added tests (#309)
jeanlucf22 Feb 19, 2025
8a26879
Encapsulate some functions in Potentials (#310)
jeanlucf22 Feb 20, 2025
59b79e7
Remove confusing 0 in naming restart files (#308)
jeanlucf22 Feb 20, 2025
16a818a
Add functionalities for extra info in restart file (#312)
jeanlucf22 Feb 20, 2025
77bd87e
MPI abort (#313)
jeanlucf22 Feb 21, 2025
8b84de4
Rho and VH restart (#311)
jeanlucf22 Feb 24, 2025
8003d70
Strenghten testIons (#315)
jeanlucf22 Mar 4, 2025
4efb34c
More clean up in class Potentials (#316)
jeanlucf22 Mar 4, 2025
2f511b7
Misc code fixes (#317)
jeanlucf22 Mar 14, 2025
45a2c80
Use unique restart filenames in test HDF5single (#318)
jeanlucf22 Mar 14, 2025
b6cf162
Swap ions in existing test (#319)
jeanlucf22 Mar 15, 2025
7fbfe13
Code clean up (#320)
jeanlucf22 Mar 17, 2025
14eb43f
Added functionalities to set local forces (#321)
jeanlucf22 Mar 21, 2025
c61b48d
Update mixed precision code (#322)
jeanlucf22 Mar 24, 2025
e37983b
Clean up and fixes Ions (#326)
jeanlucf22 Mar 26, 2025
89630b3
Fixes for build without HDF5P (#324)
jeanlucf22 Mar 26, 2025
e80193b
Fix testRhoVhRestart (#325)
jeanlucf22 Mar 26, 2025
bcad112
Fix a few more issues with class Ions (#328)
jeanlucf22 Mar 26, 2025
a78e260
Introduce new constructor for class Ions (#330)
jeanlucf22 Mar 27, 2025
c4817b8
Add cleanup and MGmolInterface (#331)
siuwuncheung Mar 27, 2025
a5f6f3a
Add function to set local forces (#333)
jeanlucf22 Mar 28, 2025
ac6b4fe
Merge branch 'release' into merge_release_20250328
siuwuncheung Mar 28, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions src/Ions.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1324,6 +1324,39 @@ void Ions::setLocalForces(
}
}

void Ions::setLocalForces(
const std::vector<double>& forces, const std::vector<double>& coords)
{
assert(forces.size() == coords.size());

// tolerance can be pretty loose, as long as it does not allow mix up
// with coordinates of other atoms
const double tol = 1.e-2;

// loop over global list of forces and coordinates
std::vector<double>::const_iterator cit = coords.begin();
for (auto fit = forces.begin(); fit != forces.end(); fit += 3)
{
// find possible matching ion
for (auto& ion : local_ions_)
{
double p[3];
ion->getPosition(&p[0]);
double d2 = (p[0] - (*cit)) * (p[0] - (*cit))
+ (p[1] - (*(cit + 1))) * (p[0] - (*(cit + 1)))
+ (p[2] - (*(cit + 2))) * (p[0] - (*(cit + 2)));
double d = std::sqrt(d2);
if (d < tol)
{
ion->set_force(0, *fit);
ion->set_force(1, *(fit + 1));
ion->set_force(2, *(fit + 2));
}
}
cit += 3;
}
}

// Writes out the postions of the ions and the current forces on them by root
void Ions::printForcesGlobal(std::ostream& os, const int root) const
{
Expand Down
6 changes: 6 additions & 0 deletions src/Ions.h
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,12 @@ class Ions
void setLocalForces(const std::vector<double>& forces,
const std::vector<std::string>& names);

/*!
* set forces for ions in local_ions_ based on coordinates matching
*/
void setLocalForces(
const std::vector<double>& forces, const std::vector<double>& coords);

void syncData(const std::vector<Species>& sp);
// void syncNames(const int nions, std::vector<std::string>& local_names,
// std::vector<std::string>& names);
Expand Down
2 changes: 0 additions & 2 deletions src/MGmol.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1503,8 +1503,6 @@ double MGmol<OrbitalsType>::evaluateDMandEnergyAndForces(Orbitals* orbitals,

ions.getForces(forces);

ions_->getForces(forces);

return eks;
}

Expand Down
1 change: 1 addition & 0 deletions src/MGmolInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class MGmolInterface
virtual int setupConstraintsFromInput(const std::string input_file) = 0;
virtual void setup() = 0;
virtual void run() = 0;
virtual void cleanup() = 0;

virtual double evaluateEnergyAndForces(const std::vector<double>& tau,
const std::vector<short>& atnumbers, std::vector<double>& forces)
Expand Down
1 change: 1 addition & 0 deletions tests/WFEnergyAndForces/testWFEnergyAndForces.cc
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ int main(int argc, char** argv)
}
}

mgmol->cleanup();
delete mgmol;

} // close main scope
Expand Down
58 changes: 45 additions & 13 deletions tests/testIons.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,29 @@

#include <random>

// check that all forces components have integer values larger than 0
// and differ from each other
int checkForces(std::vector<double>& forces)
{
const double tol = 1.e-14;

for (auto f0 = forces.begin(); f0 != forces.end(); f0++)
{
std::cout << "f0 = " << *f0 << std::endl;
for (auto f1 = f0 + 1; f1 != forces.end(); f1++)
{
// make sure each force component is different
if (std::abs(*f0 - *f1) < tol || *f1 < tol || *f0 < tol)
{
std::cerr << "f0 = " << *f0 << ", f1 = " << *f1 << std::endl;
return 1;
}
}
}

return 0;
}

int main(int argc, char** argv)
{
int status = 0;
Expand Down Expand Up @@ -164,7 +187,7 @@ int main(int argc, char** argv)

std::vector<double> forces(3 * na);
// set forces to a different arbitrary value for each component
int i = 0;
int i = 1;
for (auto& f : forces)
{
f = (double)i;
Expand All @@ -189,20 +212,29 @@ int main(int argc, char** argv)

ions.getForces(forces);
if (myrank == 0)
for (auto f0 = forces.begin(); f0 != forces.end(); f0++)
{
int status = checkForces(forces);
if (status > 0) MPI_Abort(MPI_COMM_WORLD, EXIT_FAILURE);
}

// test Ions::setLocalForces based on coordinates matching
{
std::vector<double> positions;
std::vector<short> anumbers;
ions.getPositions(positions);

ions.setLocalForces(forces, positions);

ions.printForcesGlobal(std::cout);

ions.getForces(forces);
if (myrank == 0)
{
std::cout << "f0 = " << *f0 << std::endl;
for (auto f1 = f0 + 1; f1 != forces.end(); f1++)
{
// make sure each force component is different
if (std::abs(*f0 - *f1) < 1.e-14)
{
std::cerr << "f0 = " << *f0 << ", f1 = " << *f1
<< std::endl;
MPI_Abort(MPI_COMM_WORLD, EXIT_FAILURE);
}
}
int status = checkForces(forces);
if (status > 0) MPI_Abort(MPI_COMM_WORLD, EXIT_FAILURE);
}
}

mpirc = MPI_Finalize();
if (mpirc != MPI_SUCCESS)
{
Expand Down
Loading