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
|
/////////////////////////////////////////////////////////////
// //
// 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 "pis/pi_storage.h"
//----------------------------------------------
// CElasticInteractionGroup functions
//----------------------------------------------
template<class T>
CElasticInteractionGroup<T>::CElasticInteractionGroup()
{
m_exIG=NULL;
this->m_update_timestamp=0;
}
template<class T>
CElasticInteractionGroup<T>::CElasticInteractionGroup(const CElasticIGP* Param)
{
m_exIG=NULL;
m_k=Param->getSpringConst();
this->m_update_timestamp=0;
}
template<class T>
void CElasticInteractionGroup<T>::setParam(const CElasticIGP* Param)
{
m_k=Param->getSpringConst();
}
template<class T>
void CElasticInteractionGroup<T>::calcForces()
{
console.Debug() << "calculating " << m_interactions.size() << " elastic forces\n" ;
for(vector<CElasticInteraction>::iterator it=m_interactions.begin();it!=m_interactions.end();it++){
it->calcForces();
}
}
/*!
Update the interactions from the neighbortable. If the ParallelParticleArray has been rebuild since the last update, the interactiongroup is cleared and rebuild from scratch. Otherwise only new interactions are added.
*/
template<class T>
void CElasticInteractionGroup<T>::Update(ParallelParticleArray<T>* PPA)
{
console.XDebug() << "CElasticInteractionGroup::Update\n";
int count_l=0;
if(this->m_update_timestamp!=PPA->getTimeStamp()){// PPA rebuild since last update
// clean out old interactions
m_interactions.erase(m_interactions.begin(),m_interactions.end());
this->m_set.erase(this->m_set.begin(),this->m_set.end());
// get list of pairs from PPA
typename ParallelParticleArray<T>::PairListHandle plh=PPA->getFullPairList();
// generate interactions from pairs
for(typename ParallelParticleArray<T>::PairListIterator iter=plh->begin();
iter!=plh->end();
iter++){
// check vs. ExIG
vector<int> tv;
tv.push_back(iter->first->getID());
tv.push_back(iter->second->getID());
if(m_exIG!=NULL){
if(!m_exIG->isIn(tv)){
m_interactions.push_back(CElasticInteraction(iter->first,iter->second,m_k));
this->m_set.insert(pair<int,int>(iter->first->getID(),iter->second->getID()));
console.XDebug()<<"adding pair: " << iter->first->getID() << " - "
<< iter->second->getID() << "\n";
count_l++;
} else {
console.XDebug()<<"not adding pair: " << iter->first->getID() << " - "
<< iter->second->getID() << "\n";
}
} else {
m_interactions.push_back(CElasticInteraction(iter->first,iter->second,m_k));
this->m_set.insert(pair<int,int>(iter->first->getID(),iter->second->getID()));
console.XDebug()<<"adding pair: " << iter->first->getID() << " - "
<< iter->second->getID() << "\n";
}
}
} else { // PPA not rebuild since last update -> just get additional interactions
// get list of pairs from PPA
typename ParallelParticleArray<T>::PairListHandle plh=PPA->getNewPairList();
for(typename ParallelParticleArray<T>::PairListIterator iter=plh->begin();
iter!=plh->end();
iter++){
// check vs. ExIG
vector<int> tv;
tv.push_back(iter->first->getID());
tv.push_back(iter->second->getID());
if(m_exIG!=NULL){
if(!m_exIG->isIn(tv)){
m_interactions.push_back(CElasticInteraction(iter->first,iter->second,m_k));
this->m_set.insert(pair<int,int>(iter->first->getID(),iter->second->getID()));
console.XDebug()<<"adding pair: " << iter->first->getID() << " - "
<< iter->second->getID() << "\n";
count_l++;
} else {
console.XDebug()<<"not adding pair: " << iter->first->getID() << " - "
<< iter->second->getID() << "\n";
}
} else {
m_interactions.push_back(CElasticInteraction(iter->first,iter->second,m_k));
this->m_set.insert(pair<int,int>(iter->first->getID(),iter->second->getID()));
console.XDebug()<<"adding pair: " << iter->first->getID() << " - "
<< iter->second->getID() << "\n";
}
}
}
this->m_update_timestamp=PPA->getTimeStamp();
console.XDebug() << "added " << count_l << " pairs to EIG\n";
console.XDebug() << "end CElasticInteractionGroup::Update\n";
}
template<class T>
ostream& operator<<(ostream& ost,const CElasticInteractionGroup<T>& E)
{
ost << "CElasticInteractionGroup : \n";
for(vector<CElasticInteraction>::const_iterator it=E.m_interactions.begin();it!=E.m_interactions.end();it++){
ost << *it << " , " ;
}
ost << "exchange list: \n";
for(set<pair<int,int> >::const_iterator vit=E.m_exchg_list.begin();vit!=E.m_exchg_list.end();vit++){
ost << "[ " << vit->first << " from " << vit->second << " ] , ";
}
return ost;
}
|