CS838_28_Sep_2011

Initializelayoutwriteoutput0time0 forint

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: layout.n;p++) dV(p)=(dt/layout.mass(p))*force(p); // Compute velocity change layout.Clear_Values_Of_Kinematic_Particles(dX); layout.Clear_Values_Of_Kinematic_Particles(dV); layout.particles.X+=dX; layout.particles.V+=dV; // Update particle positions and velocities layout.Set_Kinematic_Positions(time+dt,layout.particles.X); layout.Set_Kinematic_Velocities(time+dt,layout.particles.V);} layout.Write_Output(frame);} LOG::Finish_Logging(); } CS838 Advanced Modeling and Simulation [...] int main(int argc,char* argv) { [...] for(int frame=1;frame<=layout.number_of_frames;frame++){ T frame_end_time=layout.frame_time*(T)frame; for(;time<frame_end_time;time+=dt){ dt=std::min(dt_max,(T)1.001*(frame_end_time-time)); layout.Set_Kinematic_Positions(time,layout.particles.X); layout.Set_Kinematic_Velocities(time,layout.particles.V); ARRAY<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); layout.Add_External_Forces(force); // Apply the Forward Euler method dX=dt*layout.particles.V; // Compute position change for(int p=1;p<=layout.n;p++) dV(p)=(dt/layout.mass(p))*force(p); // Compute velocity change layout.Clear_Values_Of_Kinematic_Particles(dX); layout.Clear_Values_Of_Kinematic_Particles(dV); layout.particles.X+=dX; layout.particles.V+=dV; // Update particle positions and velocities layout.Set_Kinematic_Positions(time+dt,layout.particles.X); layout.Set_Kinematic_Velocities(time+dt,layout.particles.V);} layout.Write_Output(frame);} LOG::Finish_Logging(); } CS838 Advanced Modeling and Simulation Implementation of time integration methods • Improvement : Factor out a “Driver” class • DRIVER contains all the functionality for advancing the simulation forward in time • • DRIVER does NOT contain the state of the system DRIVER is reusable, and scene-independent 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);} } vo...
View Full Document

This note was uploaded on 09/04/2012 for the course CS 838 taught by Professor Staff during the Fall '08 term at Wisconsin.

Ask a homework question - tutors are online