Skip to content

Commit

Permalink
Merge branch 'master' into alpha
Browse files Browse the repository at this point in the history
  • Loading branch information
EthanBullVulpe committed Aug 16, 2024
2 parents 59222b7 + 693a599 commit 8a24799
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 24 deletions.
46 changes: 23 additions & 23 deletions plugins/lammps/USER-MBX/pair_mbx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,29 @@ void PairMBX::compute(int eflag, int vflag) {
#endif
}

if (mbx_parallel) {
#ifdef _DEBUG
printf("[MBX] (%i) -- Computing electrostatics parallel\n", me);
#endif

fix_mbx->mbxt_start(MBXT_ELE);
mbx_ele = ptr_mbx_local->ElectrostaticsMPIlocal(true, true);
fix_mbx->mbxt_stop(MBXT_ELE);
accumulate_f_local(true);

} else {
#ifdef _DEBUG
printf("[MBX] (%i) -- Computing electrostatics serial\n", me);
#endif

// compute energy+gradients in serial on rank 0 for full system

fix_mbx->mbxt_start(MBXT_ELE);
if (comm->me == 0) mbx_ele = ptr_mbx_full->Electrostatics(true);
fix_mbx->mbxt_stop(MBXT_ELE);
accumulate_f_full(true);
}

if (mbx_parallel) {
#ifdef _DEBUG
printf("[MBX] (%i) -- Computing disp parallel\n", me);
Expand Down Expand Up @@ -229,29 +252,6 @@ void PairMBX::compute(int eflag, int vflag) {

mbx_disp = mbx_disp_real + mbx_disp_pme;

if (mbx_parallel) {
#ifdef _DEBUG
printf("[MBX] (%i) -- Computing electrostatics parallel\n", me);
#endif

fix_mbx->mbxt_start(MBXT_ELE);
mbx_ele = ptr_mbx_local->ElectrostaticsMPIlocal(true, true);
fix_mbx->mbxt_stop(MBXT_ELE);
accumulate_f_local(true);

} else {
#ifdef _DEBUG
printf("[MBX] (%i) -- Computing electrostatics serial\n", me);
#endif

// compute energy+gradients in serial on rank 0 for full system

fix_mbx->mbxt_start(MBXT_ELE);
if (comm->me == 0) mbx_ele = ptr_mbx_full->Electrostatics(true);
fix_mbx->mbxt_stop(MBXT_ELE);
accumulate_f_full(true);
}

mbx_total_energy = mbx_e1b + mbx_e2b + mbx_disp + mbx_buck + mbx_e3b + mbx_e4b + mbx_ele;

for (int i = 0; i < 6; ++i) virial[i] += mbx_virial[i];
Expand Down
49 changes: 48 additions & 1 deletion src/bblock/system.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -755,6 +755,53 @@ void System::SetPBC(std::vector<double> box) {
SetPolfacs();
}


void System::SetPBCElectrostaticsMPIlocal(std::vector<double> box) {

Check warning on line 759 in src/bblock/system.cpp

View check run for this annotation

Codecov / codecov/patch

src/bblock/system.cpp#L759

Added line #L759 was not covered by tests
// Check that the box has 0 or 9 components
if (box.size() != 9 && box.size() != 6 && box.size() != 0) {
std::string text = "Box size of " + std::to_string(box.size()) + " is not acceptable.";
throw CUException(__func__, __FILE__, __LINE__, text);
}

Check warning on line 764 in src/bblock/system.cpp

View check run for this annotation

Codecov / codecov/patch

src/bblock/system.cpp#L761-L764

Added lines #L761 - L764 were not covered by tests

#ifdef DEBUG
std::cerr << "Entered SetPBC():\n";
std::cerr << "Coordinate before fixing monomers:\n";
for (size_t i = 0; i < xyz_.size(); i++) {
std::cerr << xyz_[i] << " , ";
}
std::cerr << std::endl;
#endif

// Set the box and the bool to use or not pbc
use_pbc_ = box.size();
if (use_pbc_) simcell_periodic_ = true;

Check warning on line 777 in src/bblock/system.cpp

View check run for this annotation

Codecov / codecov/patch

src/bblock/system.cpp#L776-L777

Added lines #L776 - L777 were not covered by tests

box_ = box;
if (box.size() == 9) {
box_ = box;
box_ABCabc_ = BoxVecToBoxABCabc(box);
} else if (box.size() == 6) {
box_ABCabc_ = box;
box_ = BoxABCabcToBoxVec(box);

Check warning on line 785 in src/bblock/system.cpp

View check run for this annotation

Codecov / codecov/patch

src/bblock/system.cpp#L779-L785

Added lines #L779 - L785 were not covered by tests
}

box_inverse_ = InvertUnitCell(box_);

Check warning on line 788 in src/bblock/system.cpp

View check run for this annotation

Codecov / codecov/patch

src/bblock/system.cpp#L788

Added line #L788 was not covered by tests

#ifdef DEBUG
std::cerr << "Coordinate after fixing monomers:\n";
for (size_t i = 0; i < xyz_.size(); i++) {
std::cerr << xyz_[i] << " , ";
}
std::cerr << std::endl;
#endif

// Reset the virtual site positions, charges, pols and polfacs
SetVSites();
SetCharges();
SetPols();
SetPolfacs();
}

Check warning on line 803 in src/bblock/system.cpp

View check run for this annotation

Codecov / codecov/patch

src/bblock/system.cpp#L799-L803

Added lines #L799 - L803 were not covered by tests

void System::SetXyz(std::vector<double> xyz) {
// Make sure that the xyz of input has the right size
if (xyz.size() != 3 * numsites_) {
Expand Down Expand Up @@ -3444,7 +3491,7 @@ double System::ElectrostaticsMPIlocal(bool do_grads, bool use_ghost) {
if (islocal_.size() > 0) std::fill(grad_.begin(), grad_.end(), 0.0);
std::fill(virial_.begin(), virial_.end(), 0.0);

SetPBC(box_);
SetPBCElectrostaticsMPIlocal(box_);

Check warning on line 3494 in src/bblock/system.cpp

View check run for this annotation

Codecov / codecov/patch

src/bblock/system.cpp#L3494

Added line #L3494 was not covered by tests

energy_ = GetElectrostaticsMPIlocal(do_grads, use_ghost);

Expand Down
13 changes: 13 additions & 0 deletions src/bblock/system.h
Original file line number Diff line number Diff line change
Expand Up @@ -908,6 +908,19 @@ class System {
*/
void SetPBC(std::vector<double> box = {});


/**
* Tells the system if we are in Periodic Boundary Conditions (PBC)
* or not. If the box is not passed as argument, it is set to
* a cubic box of 1000 Angstrom of side length
* @param[in] use_pbc Boolean setting if we use PBC (true) or not (false)
* @param[in] box Optional argument. Is a 9 component vector of double with
* the three main vectors of the cell: {v1x v1y v1z v2x v2y v2z v3x v3y v3z}
*
* this function differs from SetPBC, because it does systools::FixMonomerCoordinates.
*/
void SetPBCElectrostaticsMPIlocal(std::vector<double> box = {});

/**
* Sets the values for alpha, the grid density and the spline order when using PME to get the reciprocal space
* contribution. Sets both the parameters for dispersion and electorstatics to be the same.
Expand Down

0 comments on commit 8a24799

Please sign in to comment.