CS838_28_Sep_2011

Writeoutputframe void simulateframeconst int frame

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: id Simulate_Frame(const int frame); void Simulate_Time_Step(const T time,const T dt); }; } CS838 Advanced Modeling and Simulation namespace PhysBAM{ template<class T> class SIMULATION_LAYOUT; template<class T> class SIMULATION_DRIVER { public: typedef VECTOR<T,3> TV; SIMULATION_LAYOUT<T>& layout; T time; SIMULATION_DRIVER(SIMULATION_LAYOUT<T>& layout_input) :layout(layout_input) {} void Run() { layout.Initialize();layout.Write_Output(0);time=0; for(int frame=1;frame<=layout.number_of_frames;frame++){ Simulate_Frame(frame);layout.Write_Output(frame);} } void Simulate_Frame(const int frame); void Simulate_Time_Step(const T time,const T dt); }; } CS838 Advanced Modeling and Simulation namespace PhysBAM{ template<class T> class SIMULATION_LAYOUT; template<class T> class SIMULATION_DRIVER { public: typedef VECTOR<T,3> TV; SIMULATION_LAYOUT<T>& layout; T time; SIMULATION_DRIVER(SIMULATION_LAYOUT<T>& layout_input) :layout(layout_input) {} void Run() { layout.Initialize();layout.Write_Output(0);time=0; for(int frame=1;frame<=layout.number_of_frames;frame++){ Simulate_Frame(frame);layout.Write_Output(frame);} } void Simulate_Frame(const int frame); void Simulate_Time_Step(const T time,const T dt); }; } CS838 Advanced Modeling and Simulation namespace PhysBAM{ template<class T> class SIMULATION_LAYOUT; template<class T> class SIMULATION_DRIVER template<class T> { void SIMULATION_DRIVER<T>::Simulate_Frame(const int frame) public: { typedef VECTOR<T,3> TV; T frame_end_time=layout.frame_time*(T)frame,dt_max,dt; SIMULATION_LAYOUT<T>& layout; f T time; or(;time<frame_end_time;time+=dt){ dt_max=layout.Maximum_Dt(); SIMULATION_DRIVER(SIMULATION_LAYOUT<T>& layout_input) dt=std::min(dt_max,(T)1.001*(frame_end_time-time)); :layout(layout_input) {} Simulate_Time_Step(time,dt);} } void Run() { layout.Initialize();layout.Write_Output(0);time=0; for(int frame=1;frame<=layout.number_of_frames;frame++){ Simulate_Frame(frame);layout.Write_Output(frame);} } void Simulate_Frame(const int frame); void Simulate_Time_Step(const T time,const T dt); }; } CS838 Advanced Modeling and Simulation namespace PhysBAM{ template<class T> template<classvoidclass SIMULATION_LAYOUT; T> SIMULATION_DRIVER<T>::Simulate_Time_Step(const T time,const T dt) { template<class T> layout.Set_Kinematic_Positions(time,layout.particles.X); class SIMULATION_DRIVER layout.Set_Kinematic_Velocities(time,layout.particles.V); { public: ARRAY<TV> typedef VECTOR<T,3> TV; force(layout.n),dX(layout.n),dV(layout.n); layout.Add_Elastic_Forces(layout.particles.X,force); layout.Add_Damping_Forces(layout.particles.X,layout.particles.V,force); SIMULATION_LAYOUT<T>& layout; layout.Add_External_Forces(force); T time; // Apply the Forward Euler method SIMULATION_DRIVER(SIMULATION_LAYOUT<T>& layout_input) dX=dt*layout.particles.V; :layout(layout_input) {} // Compute position change for(int p=1;p<=layout.n;p++) dV(p)=(dt/layout.mass(p))*force(p); // Compute velocity change void Run() { layout.Initialize();layout.Write_Output(0);time=0; layout.Clear_Values_Of_Kinematic_Particles(dX); layout.Clear_Values_Of_Kinematic_Particles(dV); } for(int frame=1;frame<=layout.number_of_frames;frame++){ Simulate_Frame(frame);layout.Write_Output(frame);} layout.particles.X+=dX; // Update...
View Full Document

Ask a homework question - tutors are online