CS838_28_Sep_2011

Setkinematicpositionstimelayoutparticlesx

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: particle positions and velocities layout.particles.V+=dV; void Simulate_Frame(const int frame); layout.Set_Kinematic_Positions(time+dt,layout.particles.X); void Simulate_Time_Step(const T time,const T dt); layout.Set_Kinematic_Velocities(time+dt,layout.particles.V); }; } } 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 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 main() effectively becomes a stub function CS838 Advanced Modeling and Simulation #include <PhysBAM_Geometry/Geometry_Particles/REGISTER_GEOMETRY_READ_WRITE.h> #include <PhysBAM_Geometry/Solids_Geometry/DEFORMABLE_GEOMETRY_COLLECTION.h> #include <PhysBAM_Geometry/Topology_Based_Geometry/SEGMENTED_CURVE.h> #include <PhysBAM_Geometry/Topology_Based_Geometry/FREE_PARTICLES.h> #include "SIMULATION_LAYOUT.h" #include "SIMULATION_DRIVER.h" using namespace PhysBAM; int main(int argc,char* argv) { typedef float T;typedef float RW;typedef VECTOR<T,3> TV; RW rw=RW();STREAM_TYPE stream_type(rw); LOG::Initialize_Logging(); SIMULATION_LAYOUT<T> layout(stream_type); SIMULATION_DRIVER<T> driver(layout); driver.Run(); LOG::Finish_Logging(); } CS838 Advanced Modeling and Simulation Implementation of time integration methods • Swapping out Forward Euler for a different integration method • e.g. • or, for a mass spring system xn+1 v n+1 xn+1 v n+1 • = = which leads to: = = xn + vn + dt n (v + v n+1 ) 2 dt f (xn , v n+1 ) m xn + dt (v n + v n+1 ) ￿ el 2 n ￿ v n + dt f (x ) + G(xn )v n+1 m ￿ ￿ dt dt n n+1 n I − G( x ) v = v + f ( xn ) m m CS838 Advanced Modeling and Simulation namespace PhysBAM{ template<class T> class SIMULATION_LAYOUT { public: typedef VECTOR<T,3> TV; const STREAM_TYPE stream_type; template<class T> T onst int n; c SIMULATION_LAYOUT<T>::Maximum_Dt() // Number of particles in wire mesh { onst T youngs_modulus,damping_coefficient // Elasticity and damping coefficients c const maximum_dt=frame_time; T T wire_mass,wire_restlength; // Mass and length for entire wire ARRAY<T> mass,restlength; // Mass (per for(int s=1;s<=wire_curve->mesh.elements.m;s++){ each particle), restlength (per each spring) int p1,p2;wire_curve->mesh.elements(s).Get(p1,p2); GEOMETRY_PARTICLES<TV> particles; T spring_mass=1./(1./mass(p1)+1./mass(p2)); DEFORMABLE_GEOMETRY_COLLECTION<TV> collection; maximum_dt=std::min(maximum_dt,2*damping_coefficient*restlength(s)/youngs_modulus); } con...
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