diff --git a/work/week8/particles/starting_point/CMakeLists.txt b/work/week8/particles/starting_point/CMakeLists.txt index b73cea7..448732a 100644 --- a/work/week8/particles/starting_point/CMakeLists.txt +++ b/work/week8/particles/starting_point/CMakeLists.txt @@ -1,28 +1,28 @@ -cmake_minimum_required (VERSION 2.6) -project (Particles) - -#set(CMAKE_CXX_STANDARD 14) +cmake_minimum_required(VERSION 2.6) set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14") +#add_subdirectory(src) # directory you want to add or contains executable files + + + add_executable(particles main.cc vector.cc compute_boundary.cc compute_verlet_integration.cc particle.cc planet.cc compute_gravity.cc csv_reader.cc particles_factory_interface.cc planets_factory.cc compute_contact.cc compute_kinetic_energy.cc csv_writer.cc system.cc compute_energy.cc compute_potential_energy.cc ping_pong_ball.cc system_evolution.cc ping_pong_balls_factory.cc compute_interaction.cc) - diff --git a/work/week8/particles/starting_point/compute_gravity.cc b/work/week8/particles/starting_point/compute_gravity.cc index 0d6c5db..1cf7b2c 100644 --- a/work/week8/particles/starting_point/compute_gravity.cc +++ b/work/week8/particles/starting_point/compute_gravity.cc @@ -1,40 +1,46 @@ #include #include "compute_gravity.hh" /* -------------------------------------------------------------------------- */ void ComputeGravity::compute(System& system) { // Get the total number of particles int nparticles = system.getNbParticles(); - // Loop over all the particles and gets each one's parameters + //Initialize types Vector v_ij; Real r2_ij = 0.; Real r_ij = 0; Vector force; + Vector nv_ij; + // Loop over all the particles and gets each one's parameters for (int pi = 0; pi < nparticles; ++pi) { Particle & PI = system.getParticle(pi); + //loop over all next interacting particles for (int pj = pi+1; pj < nparticles; ++pj) { Particle & PJ = system.getParticle(pj); // Gets the vector between the two particles positions v_ij = PJ.getPosition() - PI.getPosition(); // Squared distance (obtained via vector class) r2_ij = v_ij.squaredNorm(); // Obtained distance r_ij = sqrt(r2_ij); - // compute the pair force - force = v_ij / r_ij * PI.getMass() * PJ.getMass() * G / r2_ij; + //Obtained corresponding normed vector + nv_ij=v_ij / r_ij; + + // compute the gravity force vector interaction on i with j + force = nv_ij* PI.getMass() * PJ.getMass() * G / r2_ij; - // add up the force for both concerned particles + //F_ij=-F_ji Particles have opposite forces PJ.getForce() -= force; PI.getForce() += force; } } }