File: RotLocalDamping.hpp

package info (click to toggle)
esys-particle 2.3.4%2Bdfsg1-4
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 13,036 kB
  • ctags: 10,805
  • sloc: cpp: 80,009; python: 5,872; makefile: 1,243; sh: 313; perl: 225
file content (218 lines) | stat: -rw-r--r-- 4,851 bytes parent folder | download
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
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
/////////////////////////////////////////////////////////////
//                                                         //
// 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 MODEL_ROTLOCALDAMPING_HPP
#define MODEL_ROTLOCALDAMPING_HPP

#include "Model/RotLocalDamping.h"

/*!
  Construct a local rotational damping "interaction" for a particle

  \param P the particle
  \param visc the damping coefficient
  \param dt the time step
*/
template <class T>
CRotLocalDamping<T>::CRotLocalDamping(T* P,double visc, double dt)
{
  m_p=P;
  m_visc=visc;
  m_dt=dt;
  m_force=Vec3(0.0,0.0,0.0);
}

/*!
  Construct a local rotational damping "interaction" for a particle

  \param P the particle
  \param param the parameters
*/
template <class T>
CRotLocalDamping<T>::CRotLocalDamping(T* P,const CLocalDampingIGP& param)
{
  m_p=P;
  m_visc=param.getVisc();
  m_dt=param.getTimeStep();
  m_force=Vec3(0.0,0.0,0.0);
}

/*!
  Construct a local rotational damping "interaction" for a particle

  \param P the particle
  \param param pointer to the parameters
*/
template <class T>
CRotLocalDamping<T>::CRotLocalDamping(T* P,CLocalDampingIGP* param)
{
  m_p=P;
  m_visc=param->getVisc();
  m_dt=param->getTimeStep();
  m_force=Vec3(0.0,0.0,0.0);
}

/*!
  destructor
*/
template <class T>
CRotLocalDamping<T>::~CRotLocalDamping()
{}

template <class T>
void CRotLocalDamping<T>::setTimeStepSize(double dt)
{
  m_dt = dt;
}

/*!
  Calculate the local damping moment.
*/
template <class T>
void CRotLocalDamping<T>::calcForces()
{
  m_E_diss=0.0;// zero dissipated energy
  Vec3 v=m_p->getAngVel();
  Vec3 frc=m_p->getMoment();

  double dampFx, dampFy, dampFz;

  dampFx = fabs(frc.X());
  if (v.X() < 0) {
     dampFx *= -1.;
  }
  if (v.X() == 0) {
     dampFx = 0.0;
  }
  dampFy = fabs(frc.Y());
  if (v.Y() < 0) {
     dampFy *= -1.;
  }
  if (v.Y() == 0) {
     dampFy = 0.0;
  }
  dampFz = fabs(frc.Z());
  if (v.Z() < 0) {
     dampFz *= -1.;
  }
  if (v.Z() == 0) {
     dampFz = 0.0;
  }

  m_force=-1.0*m_visc*Vec3(dampFx, dampFy, dampFz);

  m_p->applyMoment(m_force);

  m_E_diss=m_visc*m_force.norm()*v.norm()*m_dt;
}

/*!
  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 CRotLocalDamping<T>::ScalarFieldFunction CRotLocalDamping<T>::getScalarFieldFunction(const string& name)
{
  typename CRotLocalDamping<T>::ScalarFieldFunction sf;

  if(name=="dissipated_energy"){
    sf=&CRotLocalDamping<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 CRotLocalDamping<T>::CheckedScalarFieldFunction CRotLocalDamping<T>::getCheckedScalarFieldFunction(const string& name)
{
  typename CRotLocalDamping<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 CRotLocalDamping<T>::VectorFieldFunction CRotLocalDamping<T>::getVectorFieldFunction(const string& name)
{
  typename CRotLocalDamping<T>::VectorFieldFunction vf;

  if (name=="force"){
    vf=&CRotLocalDamping<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 CRotLocalDamping<T>::getDissipatedEnergy() const
{
  return m_E_diss;
}

template <class T>
Vec3 CRotLocalDamping<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 CRotLocalDamping<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> CRotLocalDamping<T>::getAllID() const
{
  vector<int> res;

  res.push_back(m_p->getID());

  return res;
}

#endif