/*--- leap: takes a leapfrog step ---*/ double leap(CHAIN * C, double h) { double dTdP[C->N-1][3], dUdQ[C->N-1][3], du1[C->N-1][3], du2[C->N-1][3], T, a1, a0, U, Pt = -(C->E); //set up to calculate Q_1/2 T = calc_T(C); a0 = 1/(2.0*(T + Pt)); calc_dT(C,dTdP); mat_scalar_mult(C->N-1,3,dTdP,h*a0,dTdP); //multiplied dTdP by scalar a mat_add(C->N-1,3,C->R,dTdP,C->R); //this has updated C->R to equal Q_1/2 //calculate P_1 calc_dU1(C,du1); calc_dU2(C,du2); mat_add(C->N-1,3,du1,du2,dUdQ); U = calc_U(C); mat_scalar_mult(C->N-1,3,dUdQ, -h/U ,dUdQ); //multiplied dUdQ by scalar -h/U mat_add(C->N-1,3,C->W,dUdQ,C->W); //this has updated C->W to equal P_1 //set up to calculate Q_1 T = calc_T(C); a1 = 1/(2.0*(T + Pt)); calc_dT(C,dTdP); mat_scalar_mult(C->N-1,3,dTdP,h*a1,dTdP); //multiplied dTdP by scalar a mat_add(C->N-1,3,C->R,dTdP,C->R); //this has updated C->R to equal Q_1/2 return h/2.0 * (a1 + a0); //returns update for time value, so use t += leap(C,h); }
double calc_time_derivs(double *de, double *x, double *y, double *gamma, double c[], double *vx, double *vy, double *dgamma, int np) { int j; double *xe, *ye, *se, *kappa, *dgamma_pre, *T, *U, *wx, *wy; xe = vector(np); ye = vector(np); se = vector(np); kappa = vector(np); dgamma_pre = vector(np); T = vector(np); U = vector(np); wx = vector(np); wy = vector(np); d1(x, de, 1.0, np, xe); d1(y, de, 0.0, np, ye); for(j = 0; j < np; j++) se[j] = sqrt(xe[j]*xe[j] + ye[j]*ye[j]); calc_curvature(de, x, y, xe, ye, se, np, kappa); birkhoff_integral(de, x, y, xe, ye, se, gamma, c[3], np, wx, wy); printf("\nU:\n"); for(j = 0; j < np; j++) { U[j] = (-ye[j]*wx[j] + xe[j]*wy[j])/se[j]; printf("%i: %e\n", j, U[j]); } calc_T(de, xe, ye, U, np, T); for(j = 0; j < np; j++) { dgamma_pre[j] = + (T[j] - (wx[j]*xe[j]+wy[j]*ye[j])/se[j])*gamma[j]/se[j] + c[0]*kappa[j] - c[1]*U[j] - c[2]*y[j]; vx[j] = (-ye[j]*U[j] + xe[j]*T[j])/se[j]; vy[j] = ( xe[j]*U[j] + ye[j]*T[j])/se[j]; } d1(dgamma_pre, de, 0.0, np, dgamma); free(xe); free(ye); free(se); free(kappa); free(dgamma_pre); free(T); free(U); free(wx); free(wy); return 0.0; }
matrix calc_H(int l, double R, double M) { matrix H = matrix_add(calc_V(l, R), calc_T(l, M, R)); return H; }