Go to the documentation of this file.00001 #ifndef OPENTISSUE_DYNAMICS_MBD_UTIL_STEPPERS_MBD_CONSTRAINT_BASED_SHOCK_PROPAGATION_STEPPER_H
00002 #define OPENTISSUE_DYNAMICS_MBD_UTIL_STEPPERS_MBD_CONSTRAINT_BASED_SHOCK_PROPAGATION_STEPPER_H
00003
00004
00005
00006
00007
00008
00009
00010 #include <OpenTissue/configuration.h>
00011
00012 #include <OpenTissue/dynamics/mbd/interfaces/mbd_stepper_interface.h>
00013
00014 #include <OpenTissue/dynamics/mbd/steppers/mbd_dynamics_stepper.h>
00015 #include <OpenTissue/dynamics/mbd/steppers/mbd_first_order_stepper.h>
00016 #include <OpenTissue/dynamics/mbd/mbd_stack_propagation.h>
00017
00018 namespace OpenTissue
00019 {
00020 namespace mbd
00021 {
00025 template< typename mbd_types, typename solver_type >
00026 class ConstraintBasedShockPropagationStepper
00027 : public StepperInterface<mbd_types>
00028 {
00029 protected:
00030
00031 typedef typename mbd_types::math_policy::real_type real_type;
00032 typedef typename mbd_types::math_policy::value_traits value_traits;
00033 typedef typename mbd_types::group_type group_type;
00034 typedef StackPropagation<mbd_types> propagation_algorithm;
00035 typedef DynamicsStepper<mbd_types,solver_type> dynamics_algorithm;
00036 typedef FirstOrderStepper<mbd_types,solver_type> correction_algorithm;
00037
00038 public:
00039
00040 class node_traits
00041 : public dynamics_algorithm::node_traits
00042 , public correction_algorithm::node_traits
00043 , public propagation_algorithm::node_traits
00044 {};
00045
00046 class edge_traits
00047 : public dynamics_algorithm::edge_traits
00048 , public correction_algorithm::edge_traits
00049 , public propagation_algorithm::edge_traits
00050 {};
00051
00052 class constraint_traits
00053 : public dynamics_algorithm::constraint_traits
00054 , public correction_algorithm::constraint_traits
00055 , public propagation_algorithm::constraint_traits
00056 {};
00057
00058 protected:
00059
00060 struct StepperFunctor
00061 {
00062 dynamics_algorithm m_dynamics;
00063 correction_algorithm m_correction;
00064 real_type m_h;
00065
00066 StepperFunctor()
00067 {
00068 m_dynamics.warm_starting() = false;
00069 m_dynamics.use_stabilization() = false;
00070 m_dynamics.use_friction() = true;
00071 m_dynamics.use_bounce() = true;
00072 m_dynamics.get_solver()->set_max_iterations(10);
00073
00074 m_correction.warm_starting() = false;
00075 m_correction.use_external_forces() = false;
00076 m_correction.use_erp() = false;
00077 m_correction.get_solver()->set_max_iterations(10);
00078 }
00079
00080 void operator()(group_type & layer)
00081 {
00082 if(mbd::is_all_bodies_sleepy(layer))
00083 return;
00084 m_correction.error_correction(layer);
00085 m_dynamics.run(layer,m_h);
00086 }
00087 };
00088
00089 protected:
00090
00091 propagation_algorithm m_propagation;
00092 StepperFunctor m_stepper_functor;
00093 real_type m_fraction;
00094
00095 public:
00096
00097 ConstraintBasedShockPropagationStepper()
00098 : m_fraction(value_traits::zero())
00099 {}
00100
00101 virtual ~ConstraintBasedShockPropagationStepper(){};
00102
00103 public:
00104
00110 void set_fraction(real_type const & fraction)
00111 {
00112 if(m_fraction< value_traits::zero())
00113 throw std::invalid_argument("ConstraintBasedShockPropagationStepper::set_fraction(): value was negtaive");
00114
00115 if(m_fraction> value_traits::one())
00116 throw std::invalid_argument("ConstraintBasedShockPropagationStepper::set_fraction(): value larger then one");
00117
00118 m_fraction = fraction;
00119 }
00120
00121 public:
00122
00123
00124 void run(group_type & group,real_type const & time_step)
00125 {
00126 if(time_step<=value_traits::zero())
00127 throw std::invalid_argument( "ConstraintBasedShockPropagationStepper::run() time step was non-positive" );
00128 if(m_fraction< value_traits::zero())
00129 throw std::invalid_argument("ConstraintBasedShockPropagationStepper::run() m_fraction was non-positive");
00130
00131 m_stepper_functor.m_dynamics.run(group,m_fraction*time_step);
00132
00133 m_stepper_functor.m_h = (value_traits::one()-m_fraction)*time_step;
00134
00135 m_propagation.run(
00136 group
00137 , m_stepper_functor
00138 , typename propagation_algorithm::fixate_tag()
00139 , typename propagation_algorithm::upward_tag()
00140 );
00141
00142
00143 }
00144
00145 void resolve_collisions(group_type & group)
00146 {
00147 m_stepper_functor.m_dynamics.resolve_collisions(group);
00148 }
00149
00150 void error_correction(group_type & group)
00151 {
00152 m_stepper_functor.m_correction.error_correction(group);
00153 }
00154
00155 };
00156
00157 }
00158 }
00159
00160 #endif