File: RotThermParticle.cpp

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 (579 lines) | stat: -rw-r--r-- 13,974 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
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
/////////////////////////////////////////////////////////////
//                                                         //
// 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          //
//                                                         //
/////////////////////////////////////////////////////////////

#include <mpi.h>
#include "Model/RotThermParticle.h"
#include "Geometry/SimpleParticleData.h"
#include "Foundation/console.h"

// --- TML includes ---
#include "tml/message/packed_message_interface.h"

CRotThermParticle::CRotThermParticle() : CRotParticleVi(),CThermParticle()
{
 // m_global_id=-1;
//  flag=false;
}


CRotThermParticle::CRotThermParticle(
  const esys::lsm::SimpleParticleData &particleData
)
  : CRotParticleVi(particleData),
    CThermParticle(particleData.getRadius())
{// ????
}

CRotThermParticle::CRotThermParticle(const CRotParticleVi &p)
  : CRotParticleVi(p),
    CThermParticle(p.getRad())
{
}

CRotThermParticle::CRotThermParticle(const CParticle &p)
  : CRotParticleVi(p),
    CThermParticle(p.getRad())
{
}

CRotThermParticle::CRotThermParticle(
  double rad,
  double mass,
  const Vec3& pos,
  const Vec3& vel,
  const Vec3& force,
  int id,
  bool is_dyn
) :
    CRotParticleVi(rad, mass, pos, vel, force, id, is_dyn),
    CThermParticle(rad)
{
}

/*!
  Construct particle. Old and initial position are assumed to be identical to current position. 

  \param rad radius
  \param mass mass
  \param pos current position
  \param vel current velocity
  \param force currently applied force
  \param id particle id
  \param quat particel quaternion
  \param inertRot inert of rotation
  \param moment currently applied tarque
  \param angvel current angular velocity  
*/

CRotThermParticle::CRotThermParticle(
  double rad,
  double mass,
  const Vec3& pos,
  const Vec3& vel,
  const Vec3& force,
  int id,
  Quaternion & quat,
  double inertRot,
  const Vec3& moment,
  const Vec3& angvel,
  const Vec3& angvel_t,
  double temperature,
  double temperature_ini,
  double Cp,
  double heat_frict,
  double heat_trans,
  double therm_expansion0,
  double therm_expansion1,
  double therm_expansion2
) :
  CRotParticleVi(
    rad,
    mass,
    pos,
    vel,
    force,
    id,
    quat,
    inertRot,
    moment,
    angvel,
    angvel_t
  ),
  CThermParticle(
    temperature,
    temperature_ini,
    Cp,
    heat_frict,
    heat_trans,
    therm_expansion0,
    therm_expansion1,
    therm_expansion2,
    rad
  )
{
}

CRotThermParticle::CRotThermParticle(
  double rad,
  double mass,
  const Vec3& pos,
  const Vec3& oldpos,
  const Vec3& initpos,
  const Vec3& vel,
  const Vec3& force,
  int id,
  const Quaternion & quat,
  const Quaternion & initquat,
  double inertRot,
  const Vec3& moment,
  const Vec3& angvel,
  const Vec3& angvel_t,
  double temperature,
  double temperature_ini,
  double Cp,
  double heat_frict,
  double heat_trans,
  double therm_expansion0,
  double therm_expansion1,
  double therm_expansion2
)
  :
    CRotParticleVi(
      rad,
      mass,
      pos,
      oldpos,
      initpos,
      vel,
      force,
      id,
      quat,
      initquat,
      inertRot,
      moment,
      angvel,
      angvel_t
  ),
  CThermParticle(
    temperature,
    temperature_ini,
    Cp,
    heat_frict,
    heat_trans,
    therm_expansion0,
    therm_expansion1,
    therm_expansion2,
    rad
  )
{
}


/*!
  Pack a CParticle into a TML packed message

  \param p the particle
  \todo BasicParticle data should be handled by pack<Basicparticle>
*/
template<>
void TML_PackedMessageInterface::pack<CRotThermParticle>(const CRotThermParticle& p)
{
  append(p.m_tag);
  append(p.m_pos.X()) ;
  append(p.m_pos.Y()) ;
  append(p.m_pos.Z()) ;
  append(p.m_oldpos.X());
  append(p.m_oldpos.Y());
  append(p.m_oldpos.Z());
  append(p.m_initpos.X());
  append(p.m_initpos.Y());
  append(p.m_initpos.Z());
  append(p.m_circular_shift.X());
  append(p.m_circular_shift.Y());
  append(p.m_circular_shift.Z());
  append(p.m_vel.X());
  append(p.m_vel.Y());
  append(p.m_vel.Z());
  append(p.m_force.X());
  append(p.m_force.Y());
  append(p.m_force.Z());
  append(p.m_rad);
  append(p.m_mass);
//  append(p.m_global_id);
 
// wyc added !

  append(p.m_inertRot);
  append(p.m_moment.X()) ;
  append(p.m_moment.Y()) ;
  append(p.m_moment.Z()) ;
  append(p.m_angVel.X()) ;
  append(p.m_angVel.Y()) ;
  append(p.m_angVel.Z()) ;  
  append(p.m_quat.return_sca()) ;
  append(p.m_quat.return_vec().X()) ;
  append(p.m_quat.return_vec().Y()) ;
  append(p.m_quat.return_vec().Z()) ; 
  append(p.m_initquat.return_sca()) ;
  append(p.m_initquat.return_vec().X()) ;
  append(p.m_initquat.return_vec().Y()) ;
  append(p.m_initquat.return_vec().Z()) ; 
  append(p.m_angVel_t.X()) ;
  append(p.m_angVel_t.Y()) ;
  append(p.m_angVel_t.Z()) ;

  append(p.m_temperature);
  append(p.m_temperature_ini);
  append(p.m_Cp) ;
  append(p.m_heat_frict);
  append(p.m_heat_trans); 
  append(p.m_therm_expansion0);
  append(p.m_therm_expansion1);
  append(p.m_therm_expansion2);
  append(p.m_rad_ini);

  append(p.m_global_id); // original one here
}


/*!
  Unpack a CParticle from a TML packed message

  \param p the particle
*/

template<>
void TML_PackedMessageInterface::unpack<CRotThermParticle>(CRotThermParticle& p)
{
  const int numElems = 47 ; //????
  double db[numElems] ;

  p.m_tag=pop_int();
  pop_doubles(db, numElems);
  p.m_pos            = Vec3(db[0],db[1],db[2]) ;
  p.m_oldpos         = Vec3(db[3],db[4],db[5]) ;
  p.m_initpos        = Vec3(db[6],db[7],db[8]) ;
  p.m_circular_shift = Vec3(db[9],db[10],db[11]) ;
  p.m_vel            = Vec3(db[12],db[13],db[14]) ;
  p.m_force          = Vec3(db[15],db[16],db[17]) ;
  p.m_rad            = db[18];
  p.m_mass           = db[19];
  p.m_div_mass = 1.0/p.m_mass;

  p.m_inertRot   = db[20];
  p.m_div_inertRot = (p.m_inertRot!=0.0) ? 1.0/p.m_inertRot : 0.0;
  p.m_moment     = Vec3(db[21],db[22],db[23]);
  p.m_angVel     = Vec3(db[24],db[25],db[26]);
  p.m_quat       = Quaternion(db[27],Vec3(db[28],db[29],db[30])); 
  p.m_initquat   = Quaternion(db[31],Vec3(db[32],db[33],db[34]));
  p.m_angVel_t = Vec3(db[35],db[36],db[37]) ;

  p.m_temperature = db[38] ;
  p.m_temperature_ini = db[39] ;
  p.m_Cp = db[40];
  p.m_heat_frict = db[41];
  p.m_heat_trans= db[42];
  p.m_therm_expansion0 =db[43] ;
  p.m_therm_expansion1 =db[44] ;
  p.m_therm_expansion2 =db[45] ;
  p.m_rad_ini = db[46] ;
 
  p.m_global_id=pop_int();
}

  
map<string,AField*> CRotThermParticle::generateFields(ParallelParticleArray<CRotThermParticle>* particles)
{
  map<string,AField*> res;

  return res;
}



CRotThermParticle::exchangeType CRotThermParticle::getExchangeValues()
{
  return 
    exchangeType(
      m_pos     - m_circular_shift,
      m_initpos - m_circular_shift,
      m_vel,
      m_angVel,
      m_angVel_t,
      m_quat,
      m_temperature,
      m_temperature_ini
    );
}

/*!
  Set pos, vel and angular vel from exchangeType
                                                                                
  \param E the exchanged values
*/
void CRotThermParticle::setExchangeValues(const exchangeType& E)
{
   m_pos        = E.m_pos     + m_circular_shift;
   m_initpos    = E.m_initPos + m_circular_shift;
   m_vel        = E.m_vel;
   m_angVel = E.m_angVel;
   m_angVel_t = E.m_angVel_t;
   m_quat       = E.m_quat;
   m_temperature= E.m_temperature;
   m_temperature_ini= E.m_temperature_ini;
}

template<>
void TML_PackedMessageInterface::pack<CRotThermParticle::exchangeType>(const CRotThermParticle::exchangeType& p)
{
  append(p.m_pos.X());
  append(p.m_pos.Y());
  append(p.m_pos.Z());
  append(p.m_initPos.X());
  append(p.m_initPos.Y());
  append(p.m_initPos.Z());
  append(p.m_vel.X());
  append(p.m_vel.Y());
  append(p.m_vel.Z());
  append(p.m_angVel.X());
  append(p.m_angVel.Y());
  append(p.m_angVel.Z());
  append(p.m_angVel_t.X());
  append(p.m_angVel_t.Y());
  append(p.m_angVel_t.Z());  
  append(p.m_quat.return_sca());
  append(p.m_quat.return_vec().X());
  append(p.m_quat.return_vec().Y());
  append(p.m_quat.return_vec().Z());
  append(p.m_temperature) ;
  append(p.m_temperature_ini) ;
}

/*!
  Unpack an exchangeType from a TML packed message
*/
template<>
void TML_PackedMessageInterface::unpack<CRotThermParticle::exchangeType>(CRotThermParticle::exchangeType& p)
{
  const int numDoubles = 21 ;
  double db[numDoubles];

  pop_doubles(db, numDoubles);
  p.m_pos        = Vec3(db[0],db[1],db[2]);
  p.m_initPos    = Vec3(db[3],db[4],db[5]);
  p.m_vel        = Vec3(db[6],db[7],db[8]);
  p.m_angVel     = Vec3(db[9],db[10],db[11]);
  p.m_angVel_t     = Vec3(db[12],db[13],db[14]);
  p.m_quat       = Quaternion(db[15],Vec3(db[16],db[17],db[18]));
  p.m_temperature = db[19] ;
  p.m_temperature_ini = db[20] ;
}

CRotThermParticle::ScalarFieldFunction CRotThermParticle::getScalarFieldFunction(const string& name)
{
  CRotThermParticle::ScalarFieldFunction sf;
                                                                                
  if(name=="id"){
    sf=&CRotThermParticle::getIDField;
  } else if(name=="sigma_xx_2d"){
    sf=&CRotThermParticle::sigma_xx_2D;
  } else if(name=="sigma_xy_2d"){
    sf=&CRotThermParticle::sigma_xy_2D;
  } else if(name=="sigma_yy_2d"){
    sf=&CRotThermParticle::sigma_yy_2D;
  } else if(name=="sigma_d"){
    sf=&CRotThermParticle::sigma_d;
  } else if(name=="e_kin"){
    sf=&CRotThermParticle::getKineticEnergy;
  } else if(name=="radius"){
    sf=&CRotThermParticle::getRad;
  } else if(name=="temperature"){
    sf=&CRotThermParticle::getTemperature;

  } else {
    sf=NULL;
    cerr << "ERROR - invalid name for particle scalar  access function" << endl;                                                                                
  }

  return sf;
}


CRotThermParticle::VectorFieldFunction CRotThermParticle::getVectorFieldFunction(const string& name)
{
  CRotThermParticle::VectorFieldFunction sf;
                                                                                
  if(name=="displacement"){
    sf=&CRotThermParticle::getTotalDisplacement;
  } else if(name=="velocity"){
    sf=&CRotThermParticle::getVel;
  } else if(name=="ang_velocity"){
    sf=&CRotThermParticle::getAngVelNR;
  } else if(name=="position"){
    sf=&CRotThermParticle::getPos;
  } else if(name=="force"){
    sf=&CRotThermParticle::getForce;
  } else if(name=="anglevector"){
    sf=&CRotParticleVi::getAngVector;
  } else {
    sf=NULL;
    cerr << "ERROR - invalid name for particle vector access function" << endl;
  }
                                                                                
  return sf;
}

// used in 2D to output rotated angle
/*
Vec3 CRotParticleVi::getAngVector() const
{
 double half_cos, half_sin,s_in, c_os  ;
 Vec3 AngVector ;
  half_sin = getQuat().return_vec().Z() ;
  half_cos = getQuat().return_sca();
 s_in = 2.0*half_cos*half_sin ;
 c_os = half_cos*half_cos -half_sin*half_sin ;
 AngVector = Vec3(getRad()*c_os,getRad()*s_in,0.0) ;

 return AngVector ;
}
*/

//3D case: direction--- q1,q2,q3, size --- angle
/*
Vec3 CRotParticleVi::getAngVector() const
{
 double half_cos, half_sin, c_os, angle  ;
 Vec3 AngVector,direction ;
  half_cos = getQuat().return_sca();
  half_sin = sqrt(abs(1-half_cos*half_cos));
  c_os = half_cos*half_cos -half_sin*half_sin ;
  if(c_os>=1.0) angle =0.0;
  else angle = acos(c_os);

 direction = Vec3(getQuat().return_vec().X(),getQuat().return_vec().Y(),getQuat().return_vec().Z() ) ;

 if(direction.norm()==0.0) direction = Vec3(0.0,0.0,0.0) ;
 else  direction = direction/direction.norm() ;

  AngVector = angle*direction ;

 return AngVector ;
}
*/




/*!
  set circular shift vector
                                                                                
  \param cv the circular shift vector
*/
void CRotThermParticle::setCircular(const Vec3& cv)
{
  CRotParticleVi::setCircular(cv);
}

/**
 * Save check-point data.
 */
/*void CRotThermParticle::saveCheckPointData(std::ostream& oStream)
{
  CParticle::saveCheckPointData(oStream);
  const char delim = ' ';
  oStream
    << delim
    << getQuat()
    << delim
    << getAngVel();
}

void CRotThermParticle::loadCheckPointData(std::istream &iStream)
{
  CParticle::loadCheckPointData(iStream);
  iStream >> m_quat;
  iStream >> m_angVel_t;
}
*/

void CRotThermParticle::zeroHeat()
{
  m_heat_frict = 0.0 ;
  m_heat_trans = 0.0 ;

}

void CRotThermParticle::applyHeatTrans(const double heat_trans)
{
  m_heat_trans += heat_trans ; 

}

void CRotThermParticle::applyHeatFrict(const double heat_frict)
{
  m_heat_frict += heat_frict ;

}



void CRotThermParticle::integrateTherm(double dt)
{
  m_temperature += m_heat_frict/(getMass()*getCp()) + dt*m_heat_trans ;
}

void CRotThermParticle::integrate(double dt)
{
  CRotParticleVi::integrate(dt) ;
}

void CRotThermParticle::thermExpansion() 
{
#if 0
  /*
   * non-linear expansion.
   */
  m_rad =
    m_rad_ini*(
      1.0 + 
      m_therm_expansion0 +
      m_therm_expansion1*(m_temperature- m_temperature_ini) +
      m_therm_expansion2*
        (m_temperature- m_temperature_ini)*
        (m_temperature- m_temperature_ini)
    ) ;
#else
  /*
   * linear expansion.
   */

  m_rad =
    m_rad_ini*
    (
      1.0
      +
      m_therm_expansion1*(m_temperature- m_temperature_ini)
    );
#endif
}

ostream& operator<<(ostream& ost, const CRotThermParticle& CP)
{//????
  ost << "--CParticle " << CP.m_global_id << "  --\n";
  ost << "Radius : " << CP.m_rad << " Mass : " << CP.m_mass << "\n";
  ost << "Position : " << CP.m_pos << "\n";
  ost << "Velocity : " << CP.m_vel << "\n";
  ost << "Force    : " << CP.m_force << "\n";
  return ost;
}