espresso
espresso copied to clipboard
Turn interaction parameter setters into constructor and separate storage selection from setter
Depends on #3036 for non-bonded, #3019 for bonded.
Currently the functions setting the interaction parameters also select on which interaction struct they operate, e.g. they take the types and the use globals to access the interaction parameters struct, same for bonds where the global data is accessed by bond id. The data selection can be separated from the parameter setting to get better separation of concerns and reusability. E.g. this would allow to reuse the same interaction implementation as bonded and non-bonded IA.
This can work by turning the set_parameters function into a constructor for the corresponding type and let the caller decide what data to operate on. E.g. for the harmonic bond, which currently looks like this:
int harmonic_set_params(int bond_type, double k, double r, double r_cut) {
if (bond_type < 0)
return ES_ERROR;
make_bond_type_exist(bond_type);
bonded_ia_params[bond_type].p.harmonic.k = k;
bonded_ia_params[bond_type].p.harmonic.r = r;
bonded_ia_params[bond_type].p.harmonic.r_cut = r_cut;
bonded_ia_params[bond_type].type = BONDED_IA_HARMONIC;
bonded_ia_params[bond_type].num = 1;
/* broadcast interaction parameters */
mpi_bcast_ia_params(bond_type, -1);
return ES_OK;
}
could be turned into
struct Harmonic {
Harmonic(double k, double r, double r_cut);
};
and there could common function for all bonds that does the data selection and broadcasting like
template<class Bond>
void set_bond_params(int bond_type, Bond bond) {
make_bond_type_exist(bond_type);
bonded_ia_params.at(bond_type).p = bond;
/* broadcast interaction parameters */
mpi_bcast_ia_params(bond_type, -1);
}