MC_particle_engine.cpp
Go to the documentation of this file.00001
00002 #include <MC_particle_engine.hpp>
00003
00004 namespace mesh_conv
00005 {
00006
00007 unsigned int MC_particle_engine::id_max=0;
00008
00009 MC_particle_engine::MC_particle_engine()
00010 :particles(),time_step(1e-2),dim_spatial_hash(10),dim_spatial_hash_proximity(10)
00011 {
00012 spatial_hash=MC_grid_index_spatial_hashing(MC_int_vector(dim_spatial_hash,dim_spatial_hash,dim_spatial_hash));
00013 spatial_hash_proximity=MC_grid_index_spatial_hashing(MC_int_vector(dim_spatial_hash_proximity,dim_spatial_hash_proximity,dim_spatial_hash_proximity));
00014 }
00015
00016 void MC_particle_engine::add(const MC_sphere_physic& new_particle)
00017 {
00018 particles.insert(std::make_pair(id_max++,new_particle));
00019 }
00020
00021 void MC_particle_engine::evolve(const bool& is_collision_detection,const bool& is_potential)
00022 {
00023 MC_v3d gravity=MC_v3d(0,0,-9.81);
00024
00025
00026 if(is_collision_detection==true)
00027 spatial_hash.clear();
00028 if(is_potential==true)
00029 spatial_hash_proximity.clear();
00030
00031
00032
00033 for(std::map<unsigned int,MC_sphere_physic>::iterator it=particles.begin(),it_end=particles.end();it!=it_end;++it)
00034 {
00035 MC_sphere_physic& current_particle=it->second;
00036 current_particle.force().set_zero();
00037
00038
00039
00040
00041
00042
00043 }
00044
00045 for(std::map<unsigned int,MC_sphere_physic>::iterator it=particles.begin(),it_end=particles.end();it!=it_end;++it)
00046 {
00047 MC_sphere_physic& current_particle=it->second;
00048 current_particle.force() = gravity;
00049 std::set<int> neighboor_index;
00050 std::set<int> neighboor_index_proximity;
00051 if(is_collision_detection==true)
00052 {
00053
00054
00055
00056
00057 }
00058 if(is_potential==true)
00059 {
00060
00061
00062
00063
00064 }
00065
00066
00067 if(is_potential==true)
00068 {
00069
00070
00071
00072
00073
00074 }
00075
00076
00077
00078 current_particle.evolve(time_step);
00079
00080
00081
00082
00083
00084 if(is_collision_detection==true)
00085 {
00086
00087
00088
00089
00090
00091
00092
00093 }
00094
00095
00096 current_particle.constraint_in_unit_cube();
00097
00098 }
00099
00100 }
00101
00102 const std::map<unsigned int,MC_sphere_physic>& MC_particle_engine::particle_system() const
00103 {
00104 return particles;
00105 }
00106
00107 }