add post_constructor() method to computes for symmetry with fixes

This commit is contained in:
Axel Kohlmeyer
2025-03-24 22:59:36 -04:00
parent 15026cfa56
commit 3ed03c4044
2 changed files with 13 additions and 1 deletions

View File

@ -115,6 +115,7 @@ class Compute : protected Pointers {
void modify_params(int, char **);
virtual int modify_param(int, char **) { return 0; }
virtual void reset_extra_dof();
virtual void post_constructor() {}
void init_flags();
virtual void init() = 0;

View File

@ -1293,7 +1293,18 @@ Compute *Modify::add_compute(int narg, char **arg, int trysuffix)
error->all(FLERR, utils::check_packages_for_style("compute", arg[2], lmp));
compute_list = std::vector<Compute *>(compute, compute + ncompute + 1);
return compute[ncompute++];
// post_constructor() can call virtual methods in parent or child
// which would otherwise not yet be visible in child class
// post_constructor() allows new compute to create other computes
// ncompute increment must come first so recursive call to add_compute within
// post_constructor() will see updated ncompute
auto *newcompute = compute[ncompute];
++ncompute;
newcompute->post_constructor();
return newcompute;
}
/* ----------------------------------------------------------------------