1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185
|
/////////////////////////////////////////////////////////////
// //
// Copyright (c) 2003-2014 by The University of Queensland //
// Centre for Geoscience Computing //
// http://earth.uq.edu.au/centre-geoscience-computing //
// //
// Primary Business: Brisbane, Queensland, Australia //
// Licensed under the Open Software License version 3.0 //
// http://www.apache.org/licenses/LICENSE-2.0 //
// //
/////////////////////////////////////////////////////////////
#ifndef __ROT_DAMPING_HPP
#define __ROT_DAMPING_HPP
template <class T>
double CRotDamping<T>::s_limit2=1e-12; // default error limit : 1e-6
template <class T>
int CRotDamping<T>::s_flops = 0;
/*!
Construct a rotational damping "interaction" for a particle
\param P the particle
\param param pointer to the parameters
*/
template <class T>
CRotDamping<T>::CRotDamping(T* P,CDampingIGP* param)
{
m_p=P;
m_vref=param->getVRef();
m_visc=param->getVisc();
m_dt=param->getTimeStep();
m_maxiter=param->getMaxIter();
}
/*!
destructor
*/
template <class T>
CRotDamping<T>::~CRotDamping()
{
}
template <class T>
void CRotDamping<T>::setTimeStepSize(double dt)
{
m_dt = dt;
}
/*!
Calculate the damping force.
25*count+8 flops
*/
template <class T>
void CRotDamping<T>::calcForces()
{
m_E_diss=0.0;// zero dissipated energy
Vec3 v=m_p->getAngVel();
Vec3 v_rel=Vec3(0.0,0.0,0.0);
Vec3 frc=m_p->getMoment();
double s=1.0/m_p->getInertRot();
double in=m_p->getInertRot();
double mass=m_p->getMass();
double error=1.0;
int count=0;
while((error*error>s_limit2) & (count<m_maxiter)){ // 1 flop
count++;
Vec3 v_old=v_rel;
v_rel=v-m_vref+s*m_dt*(frc-v_rel*m_visc*in); // 16 flops
error=(v_rel-v_old).norm2(); // 8 flops
}
if(count>=m_maxiter){
//console.Warning() << "damping diverges for particle " << m_p->getID() << "error= " << error << "\n";
v_rel=Vec3(0.0,0.0,0.0);
}
m_force=-1.0*m_visc*v_rel*mass;
m_p->applyMoment(-1.0*m_visc*v_rel*in); // 3 flops
m_E_diss=m_visc*v_rel*v*m_dt; // wrong
}
/*!
Get the particle member function which returns a scalar field of a given name.
\param name the name of the field
*/
template <class T>
typename CRotDamping<T>::ScalarFieldFunction CRotDamping<T>::getScalarFieldFunction(const string& name)
{
typename CRotDamping<T>::ScalarFieldFunction sf;
if(name=="dissipated_energy"){
sf=&CRotDamping<T>::getDissipatedEnergy;
} else {
sf=NULL;
cerr << "ERROR - invalid name for interaction scalar access function" << endl;
}
return sf;
}
/*!
Get the particle member function which returns a checked scalar field of a given name.
\param name the name of the field
*/
template <class T>
typename CRotDamping<T>::CheckedScalarFieldFunction CRotDamping<T>::getCheckedScalarFieldFunction(const string& name)
{
typename CRotDamping<T>::CheckedScalarFieldFunction sf;
sf=NULL;
cerr << "ERROR - invalid name for interaction scalar access function" << endl;
return sf;
}
/*!
Get the particle member function which returns a vector field of a given name.
\param name the name of the field
*/
template <class T>
typename CRotDamping<T>::VectorFieldFunction CRotDamping<T>::getVectorFieldFunction(const string& name)
{
typename CRotDamping<T>::VectorFieldFunction vf;
if (name=="force"){
vf=&CRotDamping<T>::getForce;
} else {
vf=NULL;
cerr << "ERROR - invalid name for interaction vector access function" << endl;
}
return vf;
}
/*!
return the amount of energy dissipated during the last time step
*/
template <class T>
double CRotDamping<T>::getDissipatedEnergy() const
{
return m_E_diss;
}
template <class T>
Vec3 CRotDamping<T>::getForce() const
{
return m_force;
}
/*!
check if any of the particles in the interaction fits tag & mask
\param tag the tag
\param mask the mask
*/
template <class T>
bool CRotDamping<T>::hasTag(int tag,int mask) const
{
int tag1=m_p->getTag();
return ((tag1 & mask)==(tag & mask));
}
/*!
return a vector of all particle IDs
*/
template <class T>
vector<int> CRotDamping<T>::getAllID() const
{
vector<int> res;
res.push_back(m_p->getID());
return res;
}
#endif // __ROT_DAMPING_HPP
|