Go to the documentation of this file.00001 #ifndef OPENTISSUE_DYNAMICS_SPH_SOLVERS_SPH_PRESSURE_H
00002 #define OPENTISSUE_DYNAMICS_SPH_SOLVERS_SPH_PRESSURE_H
00003
00004
00005
00006
00007
00008
00009
00010 #include <OpenTissue/configuration.h>
00011
00012 #include <OpenTissue/dynamics/sph/sph_solver.h>
00013 #include <OpenTissue/dynamics/sph/sph_particle.h>
00014
00015 namespace OpenTissue
00016 {
00017 namespace sph
00018 {
00019
00023 template< typename Types >
00024 class Pressure : Solver< Types, typename Types::real_type >
00025 {
00026 public:
00027 typedef Solver<Types, typename Types::real_type> base_type;
00028 typedef typename base_type::value value;
00029 typedef typename Types::real_type real_type;
00030 typedef typename Types::particle particle;
00031 typedef typename Types::particle_cptr_container::const_iterator particle_cptr_container_citerator;
00032
00033 public:
00038 Pressure(const real_type& gas_constant, const real_type& rest_density)
00039 : base_type()
00040 , m_k(gas_constant)
00041 , m_r0(rest_density)
00042 {
00043 }
00044
00048 ~Pressure()
00049 {
00050 }
00051
00055 Pressure& operator=(const Pressure&)
00056 {
00057 return *this;
00058 }
00059
00060 public:
00066 virtual value apply(const particle& par, particle_cptr_container_citerator, particle_cptr_container_citerator) const
00067 {
00068 #if 1
00069 return value(m_k*(par.density()-m_r0));
00070 #elif 1
00071 using std::sqrt;
00072 const value diff = par.density()-m_r0;
00073 return value(diff*(diff>1?sqrt(diff):1));
00074 #else
00075 using std::pow;
00076 return value(m_r0*(pow(par.density()/m_r0, m_k)-1));
00077 #endif
00078 }
00079
00080
00086 value apply(const particle& par, const particle&) const
00087 {
00088 return value(m_k*(par.density()-m_r0));
00089 }
00090
00091 private:
00092 const real_type m_k;
00093 const real_type m_r0;
00094
00095 };
00096
00097
00101 template< typename Types, typename KernelPolicy >
00102 class PressureForce : Solver< Types, typename Types::vector >
00103 {
00104 public:
00105 typedef Solver<Types, typename Types::vector> base_type;
00106 typedef KernelPolicy smoothing_kernel;
00107 typedef typename base_type::value value;
00108 typedef typename Types::real_type real_type;
00109 typedef typename Types::particle particle;
00110 typedef typename Types::particle_cptr_container::const_iterator particle_cptr_container_citerator;
00111
00112 public:
00116 PressureForce() : base_type()
00117 {
00118 }
00119
00123 ~PressureForce()
00124 {
00125 }
00126
00130 PressureForce& operator=(const PressureForce&)
00131 {
00132 return *this;
00133 }
00134
00135 public:
00139 #if 0
00140 value apply(const particle& par, const particle_cptr_container& pars) const
00141 {
00142 value res(0);
00143 typename particle_cptr_container::const_iterator end = pars.end();
00144 for (typename particle_cptr_container::const_iterator p_ = pars.begin(); p_ != end; ++p_) {
00145 const particle* p = *p_;
00146 if (&par == p) continue;
00147 res += p->mass()*((par.pressure()+p->pressure())/(2*p->density()))*m_W.gradient(par.position()-p->position());
00148 }
00149 return value(-1*res);
00150 }
00151 #else
00152
00155 virtual value apply(const particle& par, particle_cptr_container_citerator begin, particle_cptr_container_citerator end) const
00156 {
00157 value res(0);
00158 const real_type P_rho2 = par.pressure()/(par.density()*par.density());
00159 for (particle_cptr_container_citerator p_ = begin; p_ != end; ++p_) {
00160 const particle* p = *p_;
00161 if (&par == p) continue;
00162 res += p->mass()*(P_rho2+(p->pressure()/(p->density()*p->density())))*m_W.gradient(par.position()-p->position());
00163 }
00164 return value(-par.density()*res);
00165 }
00166 #endif
00167
00173 value apply(const particle& par, const particle& p) const
00174 {
00175 return value(-p.mass()*((par.pressure()+p.pressure())/(2*p.density()))*m_W.gradient(par.position()-p.position()));
00176 }
00177
00178 private:
00179 const smoothing_kernel m_W;
00180
00181 };
00182
00183 }
00184 }
00185
00186
00187 #endif