#include "gravity_support.h"



void CreateZeroVector (VECTOR Vresult)
{
  int d;

  for (d=0; d<NDIMS; d++) {
    Vresult[d] = 0.0;
  }/*endfor*/
}



double lengthsquared (VECTOR V)
{
  double total;
  int    d;

  total = 0.0;
  for (d=0; d<NDIMS; d++) {
    total += V[d] * V[d];
  }/*endfor*/;
  return total;
}



void copy_state (STATE *state1, STATE *state2)
{
  int i,d;

  state2->Time = state1->Time;

  for (i=0; i<state1->n; i++) {
    for (d=0; d<NDIMS; d++) {
      state2->bodydata[i].position[d] = state1->bodydata[i].position[d];
    }/*endfor*/
    for (d=0; d<NDIMS; d++) {
      state2->bodydata[i].velocity[d] = state1->bodydata[i].velocity[d];
    }/*endfor*/
  }/*endfor*/
}



void incr_state (STATE *state, double delta_t, STATE_DOT *speed)
{
  int i,d;

  if (delta_t != 0.0) {
    state->Time += delta_t;

    for (i=0; i<state->n; i++) {
      for (d=0; d<NDIMS; d++) {
        state->bodydata[i].position[d] +=
         delta_t * speed->bodydata[i].position_dot[d];
      }/*endfor*/
      for (d=0; d<NDIMS; d++) {
        state->bodydata[i].velocity[d] +=
         delta_t * speed->bodydata[i].velocity_dot[d];
      }/*endfor*/
    }/*endfor*/
  }/*endif*/
}
