Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Turn interaction parameter setters into constructor and separate storage selection from setter #3037

Open
fweik opened this issue Jul 31, 2019 · 0 comments
Labels

Comments

@fweik
Copy link
Contributor

fweik commented Jul 31, 2019

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);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant