ESyS-Particle  2.2
EWallInteractionGroup.hpp
Go to the documentation of this file.
1 
2 // //
3 // Copyright (c) 2003-2013 by The University of Queensland //
4 // Earth Systems Science Computational Centre (ESSCC) //
5 // http://www.uq.edu.au/esscc //
6 // //
7 // Primary Business: Brisbane, Queensland, Australia //
8 // Licensed under the Open Software License version 3.0 //
9 // http://www.opensource.org/licenses/osl-3.0.php //
10 // //
12 
13 //----------------------------------------------
14 // CEWallInteractionGroup functions
15 //----------------------------------------------
16 
17 #include "Foundation/console.h"
18 #include <iostream>
19 
20 template<class T>
22 {}
23 
31 template<class T>
33  :AWallInteractionGroup<T>(comm)
34 {
35  console.XDebug() << "making CEWallInteractionGroup \n";
36 
37  m_k=I->getSpringConst();
38  this->m_wall=wallp;
39 }
40 
41 template<class T>
43 {
44 
45  console.XDebug() << "calculating " << m_interactions.size() << " elastic wall forces\n" ;
46 
47  for(
48  typename vector<CElasticWallInteraction<T> >::iterator it=m_interactions.begin();
49  it != m_interactions.end();
50  it++
51  ){
52  it->calcForces();
53  }
54 }
55 
56 template<class T>
58 {
59 
60  console.XDebug() << "CEWallInteractionGroup::Update()\n" ;
61 
62  console.XDebug()
63  << "CEWallInteractionGroup::Update: wall origin = " << this->m_wall->getOrigin()
64  << ", wall normal = " << this->m_wall->getNormal() << "\n" ;
65 
66  k_local=0.0;
67  // empty particle list first
68  m_interactions.erase(m_interactions.begin(),m_interactions.end());
69  this->m_inner_count=0;
70  // build new particle list
72  PPA->getParticlesAtPlane(this->m_wall->getOrigin(),this->m_wall->getNormal());
73  for(typename ParallelParticleArray<T>::ParticleListIterator iter=plh->begin();
74  iter!=plh->end();
75  iter++){
76  bool iflag=PPA->isInInner((*iter)->getPos());
77  m_interactions.push_back(CElasticWallInteraction<T>(*iter,this->m_wall,m_k,iflag));
78  this->m_inner_count+=(iflag ? 1 : 0);
79  }
80 
81  console.XDebug() << "end CEWallInteractionGroup::Update()\n";
82 }
83 
84 
92 template<class T>
94 {
95  // warn if trying to apply non-perpendicular force
96  double par=F.unit()*this->m_wall->getNormal().unit(); // should be 1 if parallel
97  if(par<1.0){
98  console.Warning() << "Force not parallel to wall normal in CEWallInteractionGroup::applyForce : " << F << " vs. " << this->m_wall->getNormal() << "\n";
99  }
100 
101  int it=0;
102  double d; // distance to move
103  double df; // force difference
104  double ef; // relative force error (df/|F|)
105  Vec3 O_f=F.unit(); // direction of the applied force
106  do{
107  //std::cerr << "iteration: " << it << std::endl;
108  // calculate local stiffness
109  k_local=0.0;
110  for(typename vector<CElasticWallInteraction<T> >::iterator iter=m_interactions.begin();
111  iter!=m_interactions.end();
112  iter++){
113  k_local+=iter->getStiffness();
114  }
115  //std::cerr << "local stiffness: " << k_local << std::endl;
116  // get global K
117  m_k_global=this->m_comm->sum_all(k_local);
118  //std::cerr << "global stiffness: " << m_k_global << std::endl;
119  if(m_k_global>0){
120  // calculate local F
121  Vec3 F_local=Vec3(0.0,0.0,0.0);
122  for (
123  typename vector<CElasticWallInteraction<T> >::iterator iter=m_interactions.begin();
124  iter!=m_interactions.end();
125  iter++
126  ){
127  if(iter->isInner()){
128  Vec3 f_i=iter->getForce();
129  F_local+=(f_i*O_f)*O_f; // add component of f_i in O_f direction
130  }
131  }
132  //std::cerr << "local Force: " << F_local << std::endl;
133  // get global F
134  // by component (hack - fix later,i.e. sum_all for Vec3)
135  double fgx=this->m_comm->sum_all(F_local.X());
136  double fgy=this->m_comm->sum_all(F_local.Y());
137  double fgz=this->m_comm->sum_all(F_local.Z());
138  Vec3 F_global=Vec3(fgx,fgy,fgz);
139  //std::cerr << "global Force: " << F_global << std::endl;
140 
141  // calc necessary wall movement
142  df=(F+F_global)*O_f;
143  d=df/m_k_global;
144  ef=df/F.norm();
145  // move the wall
146  this->m_wall->moveBy(d*O_f);
147  it++;
148  } else {
149  d=1e-5;
150  ef=1;
151  // move the wall
152  this->m_wall->moveBy(d*O_f);
153  it++;
154  }
155  } while((it<50)&&(ef>1e-3)); // check for convergence
156  // warning message if no contact or high error after iteration
157  if(ef>1e-3){
158  console.Warning() << "applyForce doesn't converge, global stiffness: " << m_k_global << " applied force: " << F << " wall normal: " << this->m_wall->getNormal() << "\n";
159  }
160 }
161 
162 
163 template<class T>
164 ostream& operator<<(ostream& ost,const CEWallInteractionGroup<T>& IG)
165 {
166  ost << "CEWallInteractionGroup" << endl << flush;
167  ost << *(IG.m_wall) << endl << flush;
168 
169  return ost;
170 }