Memosa-FVM  0.2
KSConnectivity< T > Class Template Reference

#include <KSConnectivity.h>

Collaboration diagram for KSConnectivity< T >:

Public Types

typedef Array< int > IntArray
 
typedef Array< T > TArray
 
typedef pair< IntArray
*, TArray * > 
CouplingPair
 
typedef vector< CouplingPair * > SelfToOther
 
typedef vector< CouplingPair * > SelfToSelf
 

Public Member Functions

 KSConnectivity (const int selfLength, const int otherLength)
 
void emptyConnections ()
 
void initSelfCount ()
 
void initOtherCount ()
 
void addCountSelf (const int index, const int count)
 
void addCountOther (const int index, const int count)
 
void finishCountSelf ()
 
void finishCountOther ()
 
void addSelf (const int i, const int j, const T val)
 
void addOther (const int i, const int j, const T val)
 
void finishAddSelf ()
 
void finishAddOther ()
 
int getSelfCount (const int i)
 
int getOtherCount (const int i)
 
const IntArraygetSelfRow ()
 
const IntArraygetOtherRow ()
 
const IntArraygetSelfCol ()
 
const IntArraygetOtherCol ()
 
const TArraygetSelfCoeffs ()
 
const TArraygetOtherCoeffs ()
 
TArraygetNonConstOtherCoeffs ()
 
int getSelfNNZ ()
 
int getOtherNNZ ()
 
void multiplySelf (const TArray &x, TArray &b, const T scale) const
 
void multiplyOther (const TArray &x, TArray &b, const T scale) const
 
int getSelfSize ()
 
int getOtherSize ()
 
void copyFrom (KSConnectivity &from)
 
void multiplySelf (const T x)
 
void multiplyOther (const T x)
 
void addToSelf (KSConnectivity &added)
 
void addToOther (KSConnectivity &added)
 
void expandMySelfSelf (const int i, TArray &ExpCoeff)
 
void expandMySelfOther (const int i, TArray &ExpCoeff)
 

Private Member Functions

 KSConnectivity (const KSConnectivity &)
 

Private Attributes

StorageSite _selfSite
 
StorageSite _otherSite
 
TArray _SelfToOtherCoeffs
 
TArray _SelfToSelfCoeffs
 
CRConnectivity _SelfToOtherConn
 
CRConnectivity _SelfToSelfConn
 
int _selfNNZ
 
int _otherNNZ
 

Detailed Description

template<class T>
class KSConnectivity< T >

Definition at line 11 of file KSConnectivity.h.

Member Typedef Documentation

template<class T>
typedef pair<IntArray*,TArray*> KSConnectivity< T >::CouplingPair

Definition at line 17 of file KSConnectivity.h.

template<class T>
typedef Array<int> KSConnectivity< T >::IntArray

Definition at line 15 of file KSConnectivity.h.

template<class T>
typedef vector<CouplingPair*> KSConnectivity< T >::SelfToOther

Definition at line 18 of file KSConnectivity.h.

template<class T>
typedef vector<CouplingPair*> KSConnectivity< T >::SelfToSelf

Definition at line 19 of file KSConnectivity.h.

template<class T>
typedef Array<T> KSConnectivity< T >::TArray

Definition at line 16 of file KSConnectivity.h.

Constructor & Destructor Documentation

template<class T>
KSConnectivity< T >::KSConnectivity ( const int  selfLength,
const int  otherLength 
)
inline

Definition at line 21 of file KSConnectivity.h.

21  :
22  _selfSite(selfLength),
23  _otherSite(otherLength),
28  _selfNNZ(0),
29  _otherNNZ(0)
30  {}
StorageSite _otherSite
TArray _SelfToOtherCoeffs
CRConnectivity _SelfToOtherConn
CRConnectivity _SelfToSelfConn
TArray _SelfToSelfCoeffs
StorageSite _selfSite
template<class T>
KSConnectivity< T >::KSConnectivity ( const KSConnectivity< T > &  )
private

Member Function Documentation

template<class T>
void KSConnectivity< T >::addCountOther ( const int  index,
const int  count 
)
inline
template<class T>
void KSConnectivity< T >::addCountSelf ( const int  index,
const int  count 
)
inline
template<class T>
void KSConnectivity< T >::addOther ( const int  i,
const int  j,
const T  val 
)
inline
template<class T>
void KSConnectivity< T >::addSelf ( const int  i,
const int  j,
const T  val 
)
inline
template<class T>
void KSConnectivity< T >::addToOther ( KSConnectivity< T > &  added)
inline

Definition at line 237 of file KSConnectivity.h.

References KSConnectivity< T >::addCountOther(), KSConnectivity< T >::addOther(), KSConnectivity< T >::copyFrom(), KSConnectivity< T >::expandMySelfOther(), fabs(), KSConnectivity< T >::finishAddOther(), KSConnectivity< T >::finishCountOther(), KSConnectivity< T >::getOtherSize(), KSConnectivity< T >::getSelfSize(), and KSConnectivity< T >::initOtherCount().

238  {
239  const int selfSize=getSelfSize();
240  if(selfSize==added.getSelfSize())
241  {
242  if(getOtherSize()==added.getOtherSize())
243  {
245  myCopy.copyFrom(*this);
246  //start the counting
247  initOtherCount();
248  for(int i=0;i<selfSize;i++)
249  {
250  TArray myExpand(1);
251  myCopy.expandMySelfOther(i, myExpand);
252 
253  TArray addExpand(1);
254  added.expandMySelfOther(i, addExpand);
255 
256  myExpand+=addExpand;
257 
258  int newSize(0);
259  for(int j=0;j<getOtherSize();j++)
260  {
261  if(fabs(myExpand[j])>0.)
262  newSize++;
263  }
264  addCountOther(i,newSize);
265  }
267 
268  //put in values
269  for(int i=0;i<selfSize;i++)
270  {
271  TArray myExpand(1);
272  myCopy.expandMySelfOther(i, myExpand);
273 
274  TArray addExpand(1);
275  added.expandMySelfOther(i, addExpand);
276 
277  myExpand+=addExpand;
278 
279  for(int j=0;j<getOtherSize();j++)
280  {
281  if(fabs(myExpand[j])>0.)
282  addOther(i,j,myExpand[j]);
283  }
284  }
285  finishAddOther();
286  }
287  else
288  throw CException("addToOther: Columns not the same size!");
289  }
290  else
291  throw CException("addToOther: Rows not the same size!");
292  }
void addCountOther(const int index, const int count)
void initOtherCount()
void finishAddOther()
Tangent fabs(const Tangent &a)
Definition: Tangent.h:312
void finishCountOther()
void addOther(const int i, const int j, const T val)
Array< T > TArray
void expandMySelfOther(const int i, TArray &ExpCoeff)
template<class T>
void KSConnectivity< T >::addToSelf ( KSConnectivity< T > &  added)
inline

Definition at line 184 of file KSConnectivity.h.

References KSConnectivity< T >::addCountSelf(), KSConnectivity< T >::addSelf(), KSConnectivity< T >::copyFrom(), KSConnectivity< T >::expandMySelfSelf(), fabs(), KSConnectivity< T >::finishAddSelf(), KSConnectivity< T >::finishCountSelf(), KSConnectivity< T >::getSelfSize(), and KSConnectivity< T >::initSelfCount().

185  {
186  const int selfSize=getSelfSize();
187  if(selfSize==added.getSelfSize())
188  {
190  myCopy.copyFrom(*this);
191  //start the counting
192  initSelfCount();
193  for(int i=0;i<selfSize;i++)
194  {
195  TArray myExpand(1);
196  myCopy.expandMySelfSelf(i, myExpand);
197 
198  TArray addExpand(1);
199  added.expandMySelfSelf(i, addExpand);
200 
201  myExpand+=addExpand;
202 
203  int newSize(0);
204  for(int j=0;j<selfSize;j++)
205  {
206  if(fabs(myExpand[j])>0.)
207  newSize++;
208  }
209  addCountSelf(i,newSize);
210  }
211  finishCountSelf();
212 
213  //put in values
214  for(int i=0;i<selfSize;i++)
215  {
216  TArray myExpand(1);
217  myCopy.expandMySelfSelf(i, myExpand);
218 
219  TArray addExpand(1);
220  added.expandMySelfSelf(i, addExpand);
221 
222  myExpand+=addExpand;
223 
224  for(int j=0;j<selfSize;j++)
225  {
226  if(fabs(myExpand[j])>0.)
227  addSelf(i,j,myExpand[j]);
228  }
229  }
230  finishAddSelf();
231 
232  }
233  else
234  throw CException("addToSelf: Rows not the same size!");
235  }
void addSelf(const int i, const int j, const T val)
void finishCountSelf()
void addCountSelf(const int index, const int count)
void initSelfCount()
Tangent fabs(const Tangent &a)
Definition: Tangent.h:312
void finishAddSelf()
void expandMySelfSelf(const int i, TArray &ExpCoeff)
Array< T > TArray
template<class T>
void KSConnectivity< T >::copyFrom ( KSConnectivity< T > &  from)
inline

Definition at line 121 of file KSConnectivity.h.

References KSConnectivity< T >::addCountOther(), KSConnectivity< T >::addCountSelf(), KSConnectivity< T >::addOther(), KSConnectivity< T >::addSelf(), KSConnectivity< T >::finishAddOther(), KSConnectivity< T >::finishAddSelf(), KSConnectivity< T >::finishCountOther(), KSConnectivity< T >::finishCountSelf(), KSConnectivity< T >::getOtherCoeffs(), KSConnectivity< T >::getOtherCol(), KSConnectivity< T >::getOtherCount(), KSConnectivity< T >::getOtherRow(), KSConnectivity< T >::getSelfCoeffs(), KSConnectivity< T >::getSelfCol(), KSConnectivity< T >::getSelfCount(), KSConnectivity< T >::getSelfRow(), KSConnectivity< T >::getSelfSize(), KSConnectivity< T >::initOtherCount(), and KSConnectivity< T >::initSelfCount().

Referenced by KSConnectivity< T >::addToOther(), KSConnectivity< T >::addToSelf(), and COMETInterface< T >::makeCoarseCoeffs().

122  {
123  //Copy SelfToSelf connections first
124 
125  initSelfCount();
126  int Arows=from.getSelfSize();
127  for(int i=0;i<Arows;i++)
128  addCountSelf(i,from.getSelfCount(i));
129 
130  finishCountSelf();
131 
132  for(int i=0;i<Arows;i++)
133  {
134  const IntArray& row=from.getSelfRow();
135  const IntArray& col=from.getSelfCol();
136  const TArray& coeff=from.getSelfCoeffs();
137  for(int pos=row[i];pos<row[i+1];pos++)
138  {
139  const T fromCoeff=coeff[pos];
140  const int j=col[pos];
141  addSelf(i,j,fromCoeff);
142  }
143  }
144 
145  finishAddSelf();
146 
147  //Copy SelfToOther connections now
148 
149  initOtherCount();
150  for(int i=0;i<Arows;i++)
151  addCountOther(i,from.getOtherCount(i));
152 
154 
155  for(int i=0;i<Arows;i++)
156  {
157  const IntArray& row=from.getOtherRow();
158  const IntArray& col=from.getOtherCol();
159  const TArray& coeff=from.getOtherCoeffs();
160  for(int pos=row[i];pos<row[i+1];pos++)
161  {
162  const T fromCoeff=coeff[pos];
163  const int j=col[pos];
164  addOther(i,j,fromCoeff);
165  }
166  }
167 
168  finishAddOther();
169 
170  }
void addCountOther(const int index, const int count)
const TArray & getSelfCoeffs()
void addSelf(const int i, const int j, const T val)
Array< int > IntArray
void finishCountSelf()
const IntArray & getOtherRow()
void initOtherCount()
void addCountSelf(const int index, const int count)
void initSelfCount()
const IntArray & getOtherCol()
const IntArray & getSelfCol()
int getOtherCount(const int i)
void finishAddOther()
void finishAddSelf()
void finishCountOther()
int getSelfCount(const int i)
void addOther(const int i, const int j, const T val)
const TArray & getOtherCoeffs()
const IntArray & getSelfRow()
Array< T > TArray
template<class T>
void KSConnectivity< T >::emptyConnections ( )
inline

Definition at line 32 of file KSConnectivity.h.

References KSConnectivity< T >::_SelfToOtherCoeffs, KSConnectivity< T >::_SelfToSelfCoeffs, and Array< T >::zero().

33  {
36  }
virtual void zero()
Definition: Array.h:281
TArray _SelfToOtherCoeffs
TArray _SelfToSelfCoeffs
template<class T>
void KSConnectivity< T >::expandMySelfOther ( const int  i,
TArray ExpCoeff 
)
inline

Definition at line 310 of file KSConnectivity.h.

References KSConnectivity< T >::_SelfToOtherCoeffs, KSConnectivity< T >::_SelfToOtherConn, CRConnectivity::getCol(), KSConnectivity< T >::getOtherSize(), CRConnectivity::getRow(), Array< T >::resize(), and Array< T >::zero().

Referenced by KSConnectivity< T >::addToOther().

311  {
312  const int mysize=getOtherSize();
313  ExpCoeff.resize(mysize);
314  ExpCoeff.zero();
315  const IntArray& row=_SelfToOtherConn.getRow();
316  const IntArray& col=_SelfToOtherConn.getCol();
317 
318  for(int pos=row[i];pos<row[i+1];pos++)
319  {
320  const int j=col[pos];
321  ExpCoeff[j]=_SelfToOtherCoeffs[pos];
322  }
323 
324  }
const Array< int > & getCol() const
const Array< int > & getRow() const
TArray _SelfToOtherCoeffs
CRConnectivity _SelfToOtherConn
Array< int > IntArray
template<class T>
void KSConnectivity< T >::expandMySelfSelf ( const int  i,
TArray ExpCoeff 
)
inline

Definition at line 294 of file KSConnectivity.h.

References KSConnectivity< T >::_SelfToSelfCoeffs, KSConnectivity< T >::_SelfToSelfConn, CRConnectivity::getCol(), CRConnectivity::getRow(), KSConnectivity< T >::getSelfSize(), Array< T >::resize(), and Array< T >::zero().

Referenced by KSConnectivity< T >::addToSelf().

295  {
296  const int mysize=getSelfSize();
297  ExpCoeff.resize(mysize);
298  ExpCoeff.zero();
299  const IntArray& row=_SelfToSelfConn.getRow();
300  const IntArray& col=_SelfToSelfConn.getCol();
301 
302  for(int pos=row[i];pos<row[i+1];pos++)
303  {
304  const int j=col[pos];
305  ExpCoeff[j]=_SelfToSelfCoeffs[pos];
306  }
307 
308  }
const Array< int > & getCol() const
const Array< int > & getRow() const
Array< int > IntArray
CRConnectivity _SelfToSelfConn
TArray _SelfToSelfCoeffs
template<class T>
TArray& KSConnectivity< T >::getNonConstOtherCoeffs ( )
inline

Definition at line 76 of file KSConnectivity.h.

References KSConnectivity< T >::_SelfToOtherCoeffs.

76 {return _SelfToOtherCoeffs;}
TArray _SelfToOtherCoeffs
template<class T>
const TArray& KSConnectivity< T >::getOtherCoeffs ( )
inline

Definition at line 75 of file KSConnectivity.h.

References KSConnectivity< T >::_SelfToOtherCoeffs.

Referenced by KSConnectivity< T >::copyFrom().

75 {return _SelfToOtherCoeffs;}
TArray _SelfToOtherCoeffs
template<class T>
const IntArray& KSConnectivity< T >::getOtherCol ( )
inline

Definition at line 73 of file KSConnectivity.h.

References KSConnectivity< T >::_SelfToOtherConn, and CRConnectivity::getCol().

Referenced by KSConnectivity< T >::copyFrom().

73 {return _SelfToOtherConn.getCol();}
const Array< int > & getCol() const
CRConnectivity _SelfToOtherConn
template<class T>
int KSConnectivity< T >::getOtherCount ( const int  i)
inline

Definition at line 69 of file KSConnectivity.h.

References KSConnectivity< T >::_SelfToOtherConn, and CRConnectivity::getCount().

Referenced by KSConnectivity< T >::copyFrom().

69 {return _SelfToOtherConn.getCount(i);}
int getCount(const int i) const
CRConnectivity _SelfToOtherConn
template<class T>
int KSConnectivity< T >::getOtherNNZ ( )
inline

Definition at line 78 of file KSConnectivity.h.

References KSConnectivity< T >::_otherNNZ.

78 {return _otherNNZ;}
template<class T>
const IntArray& KSConnectivity< T >::getOtherRow ( )
inline

Definition at line 71 of file KSConnectivity.h.

References KSConnectivity< T >::_SelfToOtherConn, and CRConnectivity::getRow().

Referenced by KSConnectivity< T >::copyFrom().

71 {return _SelfToOtherConn.getRow();}
const Array< int > & getRow() const
CRConnectivity _SelfToOtherConn
template<class T>
int KSConnectivity< T >::getOtherSize ( )
inline
template<class T>
const TArray& KSConnectivity< T >::getSelfCoeffs ( )
inline

Definition at line 74 of file KSConnectivity.h.

References KSConnectivity< T >::_SelfToSelfCoeffs.

Referenced by KSConnectivity< T >::copyFrom().

74 {return _SelfToSelfCoeffs;}
TArray _SelfToSelfCoeffs
template<class T>
const IntArray& KSConnectivity< T >::getSelfCol ( )
inline

Definition at line 72 of file KSConnectivity.h.

References KSConnectivity< T >::_SelfToSelfConn, and CRConnectivity::getCol().

Referenced by KSConnectivity< T >::copyFrom().

72 {return _SelfToSelfConn.getCol();}
const Array< int > & getCol() const
CRConnectivity _SelfToSelfConn
template<class T>
int KSConnectivity< T >::getSelfCount ( const int  i)
inline

Definition at line 68 of file KSConnectivity.h.

References KSConnectivity< T >::_SelfToSelfConn, and CRConnectivity::getCount().

Referenced by KSConnectivity< T >::copyFrom().

68 {return _SelfToSelfConn.getCount(i);}
int getCount(const int i) const
CRConnectivity _SelfToSelfConn
template<class T>
int KSConnectivity< T >::getSelfNNZ ( )
inline

Definition at line 77 of file KSConnectivity.h.

References KSConnectivity< T >::_selfNNZ.

77 {return _selfNNZ;}
template<class T>
const IntArray& KSConnectivity< T >::getSelfRow ( )
inline

Definition at line 70 of file KSConnectivity.h.

References KSConnectivity< T >::_SelfToSelfConn, and CRConnectivity::getRow().

Referenced by KSConnectivity< T >::copyFrom().

70 {return _SelfToSelfConn.getRow();}
const Array< int > & getRow() const
CRConnectivity _SelfToSelfConn
template<class T>
void KSConnectivity< T >::multiplyOther ( const TArray x,
TArray b,
const T  scale 
) const
inline

Definition at line 99 of file KSConnectivity.h.

References KSConnectivity< T >::_otherSite, KSConnectivity< T >::_SelfToOtherCoeffs, KSConnectivity< T >::_SelfToOtherConn, CRConnectivity::getCol(), Array< T >::getLength(), CRConnectivity::getRow(), StorageSite::getSelfCount(), and Array< T >::zero().

Referenced by COMETInterface< T >::makeCoarseCoeffs(), COMETInterface< T >::updateOtherGhost(), and COMETInterface< T >::updateResid().

100  {//b=this*x
101  const int Arows=_otherSite.getSelfCount();
102  b.zero();
103  if(Arows==x.getLength() && Arows==b.getLength())
104  {
105  for(int i=0;i<Arows;i++)
106  {
107  const IntArray& row=_SelfToOtherConn.getRow();
108  const IntArray& col=_SelfToOtherConn.getCol();
109  for(int pos=row[i];pos<row[i+1];pos++)
110  b[i]+=(x[col[pos]]*_SelfToOtherCoeffs[pos])/scale;
111  b[i]*=scale;
112  }
113  }
114  else
115  throw CException("Matrix size does not agree with vectors!");
116  }
const Array< int > & getCol() const
const Array< int > & getRow() const
int getSelfCount() const
Definition: StorageSite.h:40
StorageSite _otherSite
TArray _SelfToOtherCoeffs
CRConnectivity _SelfToOtherConn
Array< int > IntArray
template<class T>
void KSConnectivity< T >::multiplyOther ( const T  x)
inline

Definition at line 178 of file KSConnectivity.h.

References KSConnectivity< T >::_SelfToOtherCoeffs, and Array< T >::getLength().

179  {
180  for(int i=0;i<_SelfToOtherCoeffs.getLength();i++)
181  _SelfToOtherCoeffs[i]*=x;
182  }
TArray _SelfToOtherCoeffs
int getLength() const
Definition: Array.h:87
template<class T>
void KSConnectivity< T >::multiplySelf ( const TArray x,
TArray b,
const T  scale 
) const
inline

Definition at line 80 of file KSConnectivity.h.

References KSConnectivity< T >::_selfSite, KSConnectivity< T >::_SelfToSelfCoeffs, KSConnectivity< T >::_SelfToSelfConn, CRConnectivity::getCol(), Array< T >::getLength(), CRConnectivity::getRow(), StorageSite::getSelfCount(), and Array< T >::zero().

Referenced by COMETDiscretizer< T >::correctInterface(), COMETInterface< T >::makeCoarseCoeffs(), COMETInterface< T >::updateOtherGhost(), and COMETInterface< T >::updateResid().

81  {//b=this*x
82  const int Arows=_selfSite.getSelfCount();
83  b.zero();
84  if(Arows==x.getLength() && Arows==b.getLength())
85  {
86  const IntArray& row=_SelfToSelfConn.getRow();
87  const IntArray& col=_SelfToSelfConn.getCol();
88  for(int i=0;i<Arows;i++)
89  {
90  for(int pos=row[i];pos<row[i+1];pos++)
91  b[i]+=(x[col[pos]]*_SelfToSelfCoeffs[pos])/scale;
92  b[i]*=scale;
93  }
94  }
95  else
96  throw CException("Matrix size does not agree with vectors!");
97  }
const Array< int > & getCol() const
const Array< int > & getRow() const
int getSelfCount() const
Definition: StorageSite.h:40
Array< int > IntArray
CRConnectivity _SelfToSelfConn
TArray _SelfToSelfCoeffs
StorageSite _selfSite
template<class T>
void KSConnectivity< T >::multiplySelf ( const T  x)
inline

Definition at line 172 of file KSConnectivity.h.

References KSConnectivity< T >::_SelfToSelfCoeffs, and Array< T >::getLength().

173  {
174  for(int i=0;i<_SelfToSelfCoeffs.getLength();i++)
175  _SelfToSelfCoeffs[i]*=x;
176  }
TArray _SelfToSelfCoeffs
int getLength() const
Definition: Array.h:87

Member Data Documentation

template<class T>
int KSConnectivity< T >::_otherNNZ
private
template<class T>
StorageSite KSConnectivity< T >::_otherSite
private
template<class T>
int KSConnectivity< T >::_selfNNZ
private
template<class T>
StorageSite KSConnectivity< T >::_selfSite
private

The documentation for this class was generated from the following file: