public static void Progress_rk2(LeapFrogState state, double dt) { var N = state.N; var old_pos = state.position.Select(p => new Vector3(p)).ToList(); var a0 = state.EulerState_ComputeAccelerationVectorDirect(); var half_vel = new Vector3[N]; Parallel.For(0, N, i => //for (int i = 0; i < N; i++) { half_vel[i] = state.velocity[i] + a0[i] * 0.5 * dt; state.position[i] += state.velocity[i] * 0.5 * dt; }); var a1 = state.EulerState_ComputeAccelerationVectorDirect(); Parallel.For(0, N, i => //for (int i = 0; i < N; i++) { state.velocity[i] += a1[i] * dt; state.position[i] = old_pos[i] + half_vel[i] * dt; }); state.currentTime += dt; }
public static void Progress_rk2(LeapFrogState state, double dt) { var N = state.N; var old_pos = state.position.Select(p => new Vector3(p)).ToList(); var a0 = state.EulerState_ComputeAccelerationVectorDirect(); var half_vel = new Vector3[N]; Parallel.For(0, N, i => //for (int i = 0; i < N; i++) { half_vel[i] = state.velocity[i] + a0[i] * 0.5 * dt; state.position[i] += state.velocity[i] * 0.5 * dt; }); var a1 = state.EulerState_ComputeAccelerationVectorDirect(); Parallel.For(0, N, i => //for (int i = 0; i < N; i++) { state.velocity[i] += a1[i] * dt; state.position[i] = old_pos[i] + half_vel[i] * dt; }); state.currentTime += dt; }
public static void Progress_rk4(LeapFrogState state, double dt) { var po = new ParallelOptions { MaxDegreeOfParallelism = System.Environment.ProcessorCount }; var N = state.N; var old_pos = state.position.AsParallel().Select(oldpos => new Vector3(oldpos)).ToList(); var a0 = state.EulerState_ComputeAccelerationVectorDirect(); Parallel.For(0, N, po, i => //for (int i = 0; i < N; i++) { state.position[i] = old_pos[i] + state.velocity[i] * 0.5 * dt + a0[i] * 0.125 * dt * dt; }); var a1 = state.EulerState_ComputeAccelerationVectorDirect(); Parallel.For(0, N, po, i => //for (int i = 0; i < N; i++) { state.position[i] = old_pos[i] + state.velocity[i] * dt + a0[i] * 0.5 * dt * dt; }); var a2 = state.EulerState_ComputeAccelerationVectorDirect(); Parallel.For(0, N, po, i => //for (int i = 0; i < N; i++) { state.position[i] = old_pos[i] + state.velocity[i] * dt + (a0[i] + a1[i] * 2.0) * (1.0 / 6.0) * dt * dt; state.velocity[i] += (a0[i] + a1[i] * 4.0 + a2[i]) * (1.0 / 6.0) * dt; }); state.currentTime += dt; }
public static void Progress_LeapFrog(LeapFrogState lfState, double dt) { var N = lfState.N; var deltaTimeHalf = dt * 0.5; Vector3[] acceleration1; if (lfState.currentTime == lfState.m_timeOfAccelerationCalculated && lfState.m_accelerations != null) // && length matches, in case we merge or split particles { acceleration1 = lfState.m_accelerations; } else { acceleration1 = lfState.EulerState_ComputeAccelerationVectorDirect(); } Parallel.For(0, N, i => //for (int i = 0; i < N; i++) { lfState.velocity[i] += acceleration1[i] * deltaTimeHalf; lfState.position[i] += lfState.velocity[i] * dt; }); var acceleration2 = lfState.EulerState_ComputeAccelerationVectorDirect(); Parallel.For(0, N, i => //for (int i = 0; i < N; i++) { lfState.velocity[i] += acceleration2[i] * deltaTimeHalf; }); lfState.currentTime += dt; lfState.m_timeOfAccelerationCalculated = lfState.currentTime; lfState.m_accelerations = acceleration2; }
public static void Progress_LeapFrog(LeapFrogState lfState, double dt) { var N = lfState.N; var deltaTimeHalf = dt * 0.5; Vector3[] acceleration1; if (lfState.currentTime == lfState.m_timeOfAccelerationCalculated && lfState.m_accelerations != null) // && length matches, in case we merge or split particles acceleration1 = lfState.m_accelerations; else acceleration1 = lfState.EulerState_ComputeAccelerationVectorDirect(); Parallel.For(0, N, i => //for (int i = 0; i < N; i++) { lfState.velocity[i] += acceleration1[i] * deltaTimeHalf; lfState.position[i] += lfState.velocity[i] * dt; }); var acceleration2 = lfState.EulerState_ComputeAccelerationVectorDirect(); Parallel.For(0, N, i => //for (int i = 0; i < N; i++) { lfState.velocity[i] += acceleration2[i] * deltaTimeHalf; }); lfState.currentTime += dt; lfState.m_timeOfAccelerationCalculated = lfState.currentTime; lfState.m_accelerations = acceleration2; }
public static void Progress_rk4(LeapFrogState state, double dt) { var po = new ParallelOptions { MaxDegreeOfParallelism = System.Environment.ProcessorCount }; var N = state.N; var old_pos = state.position.AsParallel().Select(oldpos => new Vector3(oldpos)).ToList(); var a0 = state.EulerState_ComputeAccelerationVectorDirect(); Parallel.For(0, N, po, i => //for (int i = 0; i < N; i++) { state.position[i] = old_pos[i] + state.velocity[i] * 0.5 * dt + a0[i] * 0.125 * dt * dt; }); var a1 = state.EulerState_ComputeAccelerationVectorDirect(); Parallel.For(0, N, po, i => //for (int i = 0; i < N; i++) { state.position[i] = old_pos[i] + state.velocity[i] * dt + a0[i] * 0.5 * dt * dt; }); var a2 = state.EulerState_ComputeAccelerationVectorDirect(); Parallel.For(0, N, po, i => //for (int i = 0; i < N; i++) { state.position[i] = old_pos[i] + state.velocity[i] * dt + (a0[i] + a1[i] * 2.0) * (1.0 / 6.0) * dt * dt; state.velocity[i] += (a0[i] + a1[i] * 4.0 + a2[i]) * (1.0 / 6.0) * dt; }); state.currentTime += dt; }