Skip to content

Commit 8e7eb2d

Browse files
committed
refactor: Invalidate colvar total force from a function used also by GPU scheduler
1 parent ddd8277 commit 8e7eb2d

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

src/colvar.cpp

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1407,6 +1407,10 @@ int colvar::calc()
14071407
error_code |= update_cvc_flags();
14081408
if (error_code != COLVARS_OK) return error_code;
14091409
error_code |= calc_cvcs();
1410+
if (!cvm::main()->proxy->total_forces_valid()) {
1411+
// Zero out the colvar total force when atomic total forces are not available
1412+
ft.reset();
1413+
}
14101414
if (error_code != COLVARS_OK) return error_code;
14111415
error_code |= collect_cvc_data();
14121416
}
@@ -1427,9 +1431,13 @@ int colvar::calc_cvcs(int first_cvc, size_t num_cvcs)
14271431
return error_code;
14281432
}
14291433

1430-
if ((cvm::step_relative() > 0) && (!is_enabled(f_cv_total_force_current_step))){
1431-
// Use Jacobian derivative from previous timestep
1434+
if (cvm::main()->proxy->total_forces_valid() && (!is_enabled(f_cv_total_force_current_step))) {
1435+
// Use Jacobian derivative computed at previous timestep and the total forces from the same
1436+
// step, collected just now from the engine
14321437
error_code |= calc_cvc_total_force(first_cvc, num_cvcs);
1438+
} else {
1439+
// Zero out the colvar total force when atomic total forces are not available
1440+
ft.reset();
14331441
}
14341442
// atom coordinates are updated by the next line
14351443
error_code |= calc_cvc_values(first_cvc, num_cvcs);
@@ -1644,13 +1652,8 @@ int colvar::collect_cvc_gradients()
16441652

16451653
int colvar::calc_cvc_total_force(int first_cvc, size_t num_cvcs)
16461654
{
1647-
auto *proxy = cvm::main()->proxy;
1648-
if (!proxy->total_forces_valid()) {
1649-
if (cvm::debug()) {
1650-
cvm::log("Skipping total force computation for colvar \"" + name +
1651-
"\", because we do not have up to date total forces at this step.");
1652-
}
1653-
ft.reset();
1655+
if (!cvm::main()->proxy->total_forces_valid()) {
1656+
// This is not a step when valid total forces are available
16541657
return COLVARS_OK;
16551658
}
16561659

0 commit comments

Comments
 (0)