コード例 #1
0
void MolecularDynamics::propagate_coordinates(const ParticleIndexes &ps,
                                              double ts) {
  for (unsigned int i = 0; i < ps.size(); ++i) {
    Float invmass = 1.0 / Mass(get_model(), ps[i]).get_mass();
    core::XYZ d(get_model(), ps[i]);
    LinearVelocity v(get_model(), ps[i]);
    algebra::Vector3D coord = d.get_coordinates();
    algebra::Vector3D dcoord = d.get_derivatives();
    // calculate velocity at t+(delta t/2) from that at t
    algebra::Vector3D velocity = v.get_velocity();
    velocity += 0.5 * dcoord * deriv_to_acceleration * invmass * ts;
    for (unsigned int j = 0; j < 3; ++j) {
      cap_velocity_component(velocity[j]);
    }
    v.set_velocity(velocity);

    // calculate position at t+(delta t) from that at t
    coord += velocity * ts;
    d.set_coordinates(coord);
  }
}
コード例 #2
0
ファイル: MolecularDynamics.cpp プロジェクト: drussel/imp
void MolecularDynamics::propagate_coordinates(const ParticleIndexes &ps,
                                              double ts)
{
  for (unsigned int i=0; i< ps.size(); ++i) {
    Float invmass = 1.0 / Mass(get_model(), ps[i]).get_mass();
    for (unsigned j = 0; j < 3; ++j) {
      core::XYZ d(get_model(), ps[i]);

      Float coord = d.get_coordinate(j);
      Float dcoord = d.get_derivative(j);

      // calculate velocity at t+(delta t/2) from that at t
      Float velocity = get_model()->get_attribute(vs_[j], ps[i]);
      velocity += 0.5 * dcoord * deriv_to_acceleration * invmass * ts;

      cap_velocity_component(velocity);
      get_model()->set_attribute(vs_[j], ps[i], velocity);

      // calculate position at t+(delta t) from that at t
      coord += velocity * ts;
      d.set_coordinate(j, coord);
    }
  }
}