EpetraExt  Development
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
EpetraExt_BlockDiagMatrix.cpp
Go to the documentation of this file.
1 /*
2 //@HEADER
3 // ***********************************************************************
4 //
5 // EpetraExt: Epetra Extended - Linear Algebra Services Package
6 // Copyright (2011) Sandia Corporation
7 //
8 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
9 // the U.S. Government retains certain rights in this software.
10 //
11 // Redistribution and use in source and binary forms, with or without
12 // modification, are permitted provided that the following conditions are
13 // met:
14 //
15 // 1. Redistributions of source code must retain the above copyright
16 // notice, this list of conditions and the following disclaimer.
17 //
18 // 2. Redistributions in binary form must reproduce the above copyright
19 // notice, this list of conditions and the following disclaimer in the
20 // documentation and/or other materials provided with the distribution.
21 //
22 // 3. Neither the name of the Corporation nor the names of the
23 // contributors may be used to endorse or promote products derived from
24 // this software without specific prior written permission.
25 //
26 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
27 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
30 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
31 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
32 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
33 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
34 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
35 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
36 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 //
38 // Questions? Contact Michael A. Heroux (maherou@sandia.gov)
39 //
40 // ***********************************************************************
41 //@HEADER
42 */
43 
45 #include "Epetra_MultiVector.h"
46 #include "Epetra_Comm.h"
47 #include "Epetra_LAPACK.h"
48 #include "Epetra_Distributor.h"
49 
50 #define AM_MULTIPLY 0
51 #define AM_INVERT 1
52 #define AM_FACTOR 2
53 
54 //=========================================================================
55 // Constructor
56 EpetraExt_BlockDiagMatrix::EpetraExt_BlockDiagMatrix(const Epetra_BlockMap& Map,bool zero_out)
57  : Epetra_DistObject(Map, "EpetraExt::BlockDiagMatrix"),
58  HasComputed_(false),
59  ApplyMode_(AM_MULTIPLY),
60  DataMap_(0),
61  Values_(0),
62  Pivots_(0)
63 {
64  Allocate();
65  if(zero_out) PutScalar(0.0);
66 }
67 
68 
69 //=========================================================================
70 // Destructor
72  if(DataMap_) delete DataMap_;
73  if(Pivots_) delete [] Pivots_;
74  if(Values_) delete [] Values_;
75 }
76 
77 
78 //=========================================================================
79 // Copy constructor.
81  : Epetra_DistObject(Source),
82  HasComputed_(false),
83  ApplyMode_(AM_MULTIPLY),
84  Values_(0),
85  Pivots_(0)
86 {
87  DataMap_=new Epetra_BlockMap(*Source.DataMap_);
88  Pivots_=new int[NumMyUnknowns()];
89  Values_=new double[DataMap_->NumMyPoints()];
90  DoCopy(Source);
91 }
92 
93 //=========================================================================
94 // Allocate
95 void EpetraExt_BlockDiagMatrix::Allocate(){
96 
97  int DataSize=0, NumBlocks=NumMyBlocks();
98  Pivots_=new int[NumMyUnknowns()];
99  int *ElementSize=new int[NumBlocks];
100 
101  for(int i=0;i<NumBlocks;i++) {
102  ElementSize[i]=BlockSize(i)*BlockSize(i);
103  DataSize+=ElementSize[i];
104  }
105 
106  DataMap_=new Epetra_BlockMap(-1,Map().NumMyElements(),Map().MyGlobalElements(),ElementSize,0,Map().Comm());
107  Values_=new double[DataSize];
108  delete [] ElementSize;
109 }
110 
111 
112 //=========================================================================
114 int EpetraExt_BlockDiagMatrix::SetParameters(Teuchos::ParameterList & List){
115  List_=List;
116 
117  // Inverse storage mode
118  string dummy("multiply");
119  string ApplyMode=List_.get("apply mode",dummy);
120  if(ApplyMode==string("multiply")) ApplyMode_=AM_MULTIPLY;
121  else if(ApplyMode==string("invert")) ApplyMode_=AM_INVERT;
122  else if(ApplyMode==string("factor")) ApplyMode_=AM_FACTOR;
123  else EPETRA_CHK_ERR(-1);
124 
125  return 0;
126 }
127 
128 
129 //=========================================================================
131  int MaxData=NumData();
132  for (int i=0;i<MaxData;i++) Values_[i]=value;
133 }
134 
135 //=========================================================================
136 // Assignment operator: Needs the same maps
138  DoCopy(Source);
139  return(*this);
140 }
141 //=========================================================================
142 int EpetraExt_BlockDiagMatrix::DoCopy(const EpetraExt_BlockDiagMatrix& Source){
143  // Need the same map
144  if(!Map().SameAs(Source.Map()) || !DataMap_->SameAs(*Source.DataMap_))
145  throw ReportError("Maps of DistBlockMatrices incompatible in assignment",-1);
146 
147  int MaxData=Source.NumData();
148 
149  for(int i=0;i<MaxData;i++) Values_[i]=Source.Values_[i];
150  for(int i=0;i<Source.NumMyUnknowns();i++) Pivots_[i]=Source.Pivots_[i];
151 
152  List_=Source.List_;
153  ApplyMode_=Source.ApplyMode_;
154  HasComputed_=Source.HasComputed_;
155 
156  return 0;
157 }
158 
159 
160 //=========================================================================
163  int info;
164 
165  if(ApplyMode_==AM_MULTIPLY)
166  // Multiply mode - noop
167  return 0;
168  else {
169  // Factorization - Needed for both 'factor' and 'invert' modes
170  int NumBlocks=NumMyBlocks();
171  for(int i=0;i<NumBlocks;i++){
172  int Nb=BlockSize(i);
173  if(Nb==1) {
174  // Optimize for Block Size 1
175  Values_[DataMap_->FirstPointInElement(i)]=1.0/Values_[DataMap_->FirstPointInElement(i)];
176  }
177  else if(Nb==2) {
178  // Optimize for Block Size 2
179  double * v=&Values_[DataMap_->FirstPointInElement(i)];
180  double d=1/(v[0]*v[3]-v[1]*v[2]);
181  double v0old=v[0];
182  v[0]=v[3]*d;
183  v[1]=-v[1]*d;
184  v[2]=-v[2]*d;
185  v[3]=v0old*d;
186  }
187  else{
188  // "Large" Block - Use LAPACK
189  LAPACK.GETRF(Nb,Nb,&Values_[DataMap_->FirstPointInElement(i)],Nb,&Pivots_[Map().FirstPointInElement(i)],&info);
190  if(info) EPETRA_CHK_ERR(-2);
191  }
192  }
193 
194  if(ApplyMode_==AM_INVERT){
195  // Invert - Use the factorization and invert the blocks in-place
196  int lwork=3*DataMap_->MaxMyElementSize();
197  std::vector<double> work(lwork);
198  for(int i=0;i<NumBlocks;i++){
199  int Nb=BlockSize(i);
200  if(Nb==1 || Nb==2){
201  // Optimize for Block Size 1 and 2
202  // No need to do anything - factorization has already inverted the value
203  }
204  else{
205  // "Large" Block - Use LAPACK
206  LAPACK.GETRI(Nb,&Values_[DataMap_->FirstPointInElement(i)],Nb,&Pivots_[Map().FirstPointInElement(i)],&work[0],&lwork,&info);
207  if(info) EPETRA_CHK_ERR(-3);
208  }
209  }
210  }
211  }
212  HasComputed_=true;
213  return 0;
214 }
215 
216 
217 //=========================================================================
218 int EpetraExt_BlockDiagMatrix::ApplyInverse(const Epetra_MultiVector& X, Epetra_MultiVector& Y) const{
219  int info;
220  // Sanity Checks
221  int NumVectors=X.NumVectors();
222  if(NumVectors!=Y.NumVectors())
223  EPETRA_CHK_ERR(-1);
224  if(!HasComputed_ && (ApplyMode_==AM_INVERT || ApplyMode_==AM_FACTOR))
225  EPETRA_CHK_ERR(-2);
226 
227  //NTS: MultiVector's MyLength and [] Operators are "points" level operators
228  //not a "block/element" level operators.
229 
230  const int *vlist=DataMap_->FirstPointInElementList();
231  const int *xlist=Map().FirstPointInElementList();
232  const int *blocksize=Map().ElementSizeList();
233 
234  if(ApplyMode_==AM_MULTIPLY || ApplyMode_==AM_INVERT){
235  // Multiply & Invert mode have the same apply
236  int NumBlocks=NumMyBlocks();
237  for(int i=0;i<NumBlocks;i++){
238  int Nb=blocksize[i];
239  int vidx0=vlist[i];
240  int xidx0=xlist[i];
241  for(int j=0;j<NumVectors;j++){
242  if(Nb==1) {
243  // Optimize for size = 1
244  Y[j][xidx0]=Values_[vidx0]*X[j][xidx0];
245  }
246  else if(Nb==2){
247  // Optimize for size = 2
248  Y[j][xidx0 ]=Values_[vidx0 ]*X[j][xidx0] + Values_[vidx0+2]*X[j][xidx0+1];
249  Y[j][xidx0+1]=Values_[vidx0+1]*X[j][xidx0] + Values_[vidx0+3]*X[j][xidx0+1];
250  }
251  else{
252  // "Large" Block - Use BLAS
253  //void GEMV (const char TRANS, const int M, const int N, const double ALPHA, const double *A, const int LDA, const double *X, const double BETA, double *Y, const int INCX=1, const int INCY=1) const
254  GEMV('N',Nb,Nb,1.0,&Values_[vidx0],Nb,&X[j][xidx0],0.0,&Y[j][xidx0]);
255  }
256  }
257  }
258  }
259  else{
260  // Factorization mode has a different apply
261  int NumBlocks=NumMyBlocks();
262  for(int i=0;i<NumBlocks;i++){
263  int Nb=blocksize[i];
264  int vidx0=vlist[i];
265  int xidx0=xlist[i];
266  for(int j=0;j<NumVectors;j++){
267  if(Nb==1) {
268  // Optimize for size = 1 - use the inverse
269  Y[j][xidx0]=Values_[vidx0]*X[j][xidx0];
270  }
271  else if(Nb==2){
272  // Optimize for size = 2 - use the inverse
273  Y[j][xidx0 ]=Values_[vidx0 ]*X[j][xidx0] + Values_[vidx0+2]*X[j][xidx0+1];
274  Y[j][xidx0+1]=Values_[vidx0+1]*X[j][xidx0] + Values_[vidx0+3]*X[j][xidx0+1];
275  }
276  else{
277  // "Large" Block - use LAPACK
278  // void GETRS (const char TRANS, const int N, const int NRHS, const double *A, const int LDA, const int *IPIV, double *X, const int LDX, int *INFO) const
279  for(int k=0;k<Nb;k++) Y[j][xidx0+k]=X[j][xidx0+k];
280  LAPACK.GETRS('N',Nb,1,&Values_[vidx0],Nb,&Pivots_[xidx0],&Y[j][xidx0],Nb,&info);
281  if(info) EPETRA_CHK_ERR(info);
282  }
283  }
284  }
285  }
286  return 0;
287 }
288 
289 
290 
291 
292 //=========================================================================
293 // Print method
294 void EpetraExt_BlockDiagMatrix::Print(ostream & os) const{
295  int MyPID = DataMap_->Comm().MyPID();
296  int NumProc = DataMap_->Comm().NumProc();
297 
298  for (int iproc=0; iproc < NumProc; iproc++) {
299  if (MyPID==iproc) {
300  int NumMyElements1 =DataMap_->NumMyElements();
301  int MaxElementSize1 = DataMap_->MaxElementSize();
302  int * MyGlobalElements1 = DataMap_->MyGlobalElements();
303  int * FirstPointInElementList1;
304  if (MaxElementSize1!=1) FirstPointInElementList1 = DataMap_->FirstPointInElementList();
305 
306  if (MyPID==0) {
307  os.width(8);
308  os << " MyPID"; os << " ";
309  os.width(12);
310  if (MaxElementSize1==1)
311  os << "GID ";
312  else
313  os << " GID/Point";
314  os.width(20);
315  os << "Values ";
316  os << endl;
317  }
318  for (int i=0; i < NumMyElements1; i++) {
319  for (int ii=0; ii< DataMap_->ElementSize(i); ii++) {
320  int iii;
321  os.width(10);
322  os << MyPID; os << " ";
323  os.width(10);
324  if (MaxElementSize1==1) {
325  os << MyGlobalElements1[i] << " ";
326  iii = i;
327  }
328  else {
329  os << MyGlobalElements1[i]<< "/" << ii << " ";
330  iii = FirstPointInElementList1[i]+ii;
331  }
332  os.width(20);
333  os << Values_[iii];
334  os << endl;
335  }
336  }
337  os << flush;
338  }
339 
340  // Do a few global ops to give I/O a chance to complete
341  Map().Comm().Barrier();
342  Map().Comm().Barrier();
343  Map().Comm().Barrier();
344  }
345  return;
346 }
347 
348 
349 //=========================================================================
350 // Allows the source and target (\e this) objects to be compared for compatibility, return nonzero if not.
351 int EpetraExt_BlockDiagMatrix::CheckSizes(const Epetra_SrcDistObject& Source){
352  return &Map() == &Source.Map();
353 }
354 
355 
356  //=========================================================================
357 // Perform ID copies and permutations that are on processor.
358 int EpetraExt_BlockDiagMatrix::CopyAndPermute(const Epetra_SrcDistObject& Source,
359  int NumSameIDs,
360  int NumPermuteIDs,
361  int * PermuteToLIDs,
362  int * PermuteFromLIDs,
363  const Epetra_OffsetIndex * Indexor){
364  (void)Indexor;
365 
366  const EpetraExt_BlockDiagMatrix & A = dynamic_cast<const EpetraExt_BlockDiagMatrix &>(Source);
367 
368  double *From=A.Values();
369  double *To = Values_;
370 
371  int * ToFirstPointInElementList = 0;
372  int * FromFirstPointInElementList = 0;
373  int * FromElementSizeList = 0;
374  int MaxElementSize = DataMap().MaxElementSize();
375  bool ConstantElementSize = DataMap().ConstantElementSize();
376 
377  if (!ConstantElementSize) {
378  ToFirstPointInElementList = DataMap().FirstPointInElementList();
379  FromFirstPointInElementList = A.DataMap().FirstPointInElementList();
380  FromElementSizeList = A.DataMap().ElementSizeList();
381  }
382  int j, jj, jjj, k;
383 
384  int NumSameEntries;
385 
386  bool Case1 = false;
387  bool Case2 = false;
388  // bool Case3 = false;
389 
390  if (MaxElementSize==1) {
391  Case1 = true;
392  NumSameEntries = NumSameIDs;
393  }
394  else if (ConstantElementSize) {
395  Case2 = true;
396  NumSameEntries = NumSameIDs * MaxElementSize;
397  }
398  else {
399  // Case3 = true;
400  NumSameEntries = FromFirstPointInElementList[NumSameIDs];
401  }
402 
403  // Short circuit for the case where the source and target vector is the same.
404  if (To==From) NumSameEntries = 0;
405 
406  // Do copy first
407  if (NumSameIDs>0)
408  if (To!=From) {
409  for (j=0; j<NumSameEntries; j++)
410  To[j] = From[j];
411  }
412  // Do local permutation next
413  if (NumPermuteIDs>0) {
414 
415  // Point entry case
416  if (Case1) {
417 
418  for (j=0; j<NumPermuteIDs; j++)
419  To[PermuteToLIDs[j]] = From[PermuteFromLIDs[j]];
420  }
421  // constant element size case
422  else if (Case2) {
423 
424  for (j=0; j<NumPermuteIDs; j++) {
425  jj = MaxElementSize*PermuteToLIDs[j];
426  jjj = MaxElementSize*PermuteFromLIDs[j];
427  for (k=0; k<MaxElementSize; k++)
428  To[jj+k] = From[jjj+k];
429  }
430  }
431 
432  // variable element size case
433  else {
434 
435  for (j=0; j<NumPermuteIDs; j++) {
436  jj = ToFirstPointInElementList[PermuteToLIDs[j]];
437  jjj = FromFirstPointInElementList[PermuteFromLIDs[j]];
438  int ElementSize = FromElementSizeList[PermuteFromLIDs[j]];
439  for (k=0; k<ElementSize; k++)
440  To[jj+k] = From[jjj+k];
441  }
442  }
443  }
444  return(0);
445 }
446 
447 //=========================================================================
448 // Perform any packing or preparation required for call to DoTransfer().
449 int EpetraExt_BlockDiagMatrix::PackAndPrepare(const Epetra_SrcDistObject& Source,
450  int NumExportIDs,
451  int* ExportLIDs,
452  int& LenExports,
453  char*& Exports,
454  int& SizeOfPacket,
455  int* Sizes,
456  bool & VarSizes,
457  Epetra_Distributor& Distor){
458  (void)Sizes;
459  (void)VarSizes;
460  (void)Distor;
461  const EpetraExt_BlockDiagMatrix & A = dynamic_cast<const EpetraExt_BlockDiagMatrix &>(Source);
462 
463  int j, jj, k;
464 
465  double *From=A.Values();
466  int MaxElementSize = DataMap().MaxElementSize();
467  bool ConstantElementSize = DataMap().ConstantElementSize();
468 
469  int * FromFirstPointInElementList = 0;
470  int * FromElementSizeList = 0;
471 
472  if (!ConstantElementSize) {
473  FromFirstPointInElementList = A.DataMap().FirstPointInElementList();
474  FromElementSizeList = A.DataMap().ElementSizeList();
475  }
476 
477  SizeOfPacket = MaxElementSize * (int)sizeof(double);
478 
479  if(NumExportIDs*SizeOfPacket>LenExports) {
480  if (LenExports>0) delete [] Exports;
481  LenExports = NumExportIDs*SizeOfPacket;
482  Exports = new char[LenExports];
483  }
484 
485  double * ptr;
486 
487  if (NumExportIDs>0) {
488  ptr = (double *) Exports;
489 
490  // Point entry case
491  if (MaxElementSize==1) for (j=0; j<NumExportIDs; j++) *ptr++ = From[ExportLIDs[j]];
492 
493  // constant element size case
494  else if (ConstantElementSize) {
495  for (j=0; j<NumExportIDs; j++) {
496  jj = MaxElementSize*ExportLIDs[j];
497  for (k=0; k<MaxElementSize; k++)
498  *ptr++ = From[jj+k];
499  }
500  }
501 
502  // variable element size case
503  else {
504  SizeOfPacket = MaxElementSize;
505  for (j=0; j<NumExportIDs; j++) {
506  ptr = (double *) Exports + j*SizeOfPacket;
507  jj = FromFirstPointInElementList[ExportLIDs[j]];
508  int ElementSize = FromElementSizeList[ExportLIDs[j]];
509  for (k=0; k<ElementSize; k++)
510  *ptr++ = From[jj+k];
511  }
512  }
513  }
514 
515  return(0);
516 }
517 
518 
519 //=========================================================================
520 // Perform any unpacking and combining after call to DoTransfer().
521 int EpetraExt_BlockDiagMatrix::UnpackAndCombine(const Epetra_SrcDistObject& Source,
522  int NumImportIDs,
523  int* ImportLIDs,
524  int LenImports,
525  char* Imports,
526  int& SizeOfPacket,
527  Epetra_Distributor& Distor,
528  Epetra_CombineMode CombineMode,
529  const Epetra_OffsetIndex * Indexor){
530  (void)Source;
531  (void)LenImports;
532  (void)Distor;
533  (void)Indexor;
534  int j, jj, k;
535 
536  if( CombineMode != Add
537  && CombineMode != Zero
538  && CombineMode != Insert
539  && CombineMode != Average
540  && CombineMode != AbsMax )
541  EPETRA_CHK_ERR(-1); //Unsupported CombinedMode, will default to Zero
542 
543  if (NumImportIDs<=0) return(0);
544 
545  double * To = Values_;
546  int MaxElementSize = DataMap().MaxElementSize();
547  bool ConstantElementSize = DataMap().ConstantElementSize();
548 
549  int * ToFirstPointInElementList = 0;
550  int * ToElementSizeList = 0;
551 
552  if (!ConstantElementSize) {
553  ToFirstPointInElementList = DataMap().FirstPointInElementList();
554  ToElementSizeList = DataMap().ElementSizeList();
555  }
556 
557  double * ptr;
558  // Unpack it...
559 
560  ptr = (double *) Imports;
561 
562  // Point entry case
563  if (MaxElementSize==1) {
564 
565  if (CombineMode==Add)
566  for (j=0; j<NumImportIDs; j++) To[ImportLIDs[j]] += *ptr++; // Add to existing value
567  else if(CombineMode==Insert)
568  for (j=0; j<NumImportIDs; j++) To[ImportLIDs[j]] = *ptr++;
569  else if(CombineMode==AbsMax)
570  for (j=0; j<NumImportIDs; j++) {
571  To[ImportLIDs[j]] = EPETRA_MAX( To[ImportLIDs[j]],std::abs(*ptr));
572  ptr++;
573  }
574  // Note: The following form of averaging is not a true average if more that one value is combined.
575  // This might be an issue in the future, but we leave this way for now.
576  else if(CombineMode==Average)
577  for (j=0; j<NumImportIDs; j++) {To[ImportLIDs[j]] += *ptr++; To[ImportLIDs[j]] /= 2;}
578  }
579 
580  // constant element size case
581 
582  else if (ConstantElementSize) {
583 
584  if (CombineMode==Add) {
585  for (j=0; j<NumImportIDs; j++) {
586  jj = MaxElementSize*ImportLIDs[j];
587  for (k=0; k<MaxElementSize; k++)
588  To[jj+k] += *ptr++; // Add to existing value
589  }
590  }
591  else if(CombineMode==Insert) {
592  for (j=0; j<NumImportIDs; j++) {
593  jj = MaxElementSize*ImportLIDs[j];
594  for (k=0; k<MaxElementSize; k++)
595  To[jj+k] = *ptr++;
596  }
597  }
598  else if(CombineMode==AbsMax) {
599  for (j=0; j<NumImportIDs; j++) {
600  jj = MaxElementSize*ImportLIDs[j];
601  for (k=0; k<MaxElementSize; k++) {
602  To[jj+k] = EPETRA_MAX( To[jj+k], std::abs(*ptr));
603  ptr++;
604  }
605  }
606  }
607  // Note: The following form of averaging is not a true average if more that one value is combined.
608  // This might be an issue in the future, but we leave this way for now.
609  else if(CombineMode==Average) {
610  for (j=0; j<NumImportIDs; j++) {
611  jj = MaxElementSize*ImportLIDs[j];
612  for (k=0; k<MaxElementSize; k++)
613  { To[jj+k] += *ptr++; To[jj+k] /= 2;}
614  }
615  }
616  }
617 
618  // variable element size case
619 
620  else {
621 
622  SizeOfPacket = MaxElementSize;
623 
624  if (CombineMode==Add) {
625  for (j=0; j<NumImportIDs; j++) {
626  ptr = (double *) Imports + j*SizeOfPacket;
627  jj = ToFirstPointInElementList[ImportLIDs[j]];
628  int ElementSize = ToElementSizeList[ImportLIDs[j]];
629  for (k=0; k<ElementSize; k++)
630  To[jj+k] += *ptr++; // Add to existing value
631  }
632  }
633  else if(CombineMode==Insert){
634  for (j=0; j<NumImportIDs; j++) {
635  ptr = (double *) Imports + j*SizeOfPacket;
636  jj = ToFirstPointInElementList[ImportLIDs[j]];
637  int ElementSize = ToElementSizeList[ImportLIDs[j]];
638  for (k=0; k<ElementSize; k++)
639  To[jj+k] = *ptr++;
640  }
641  }
642  else if(CombineMode==AbsMax){
643  for (j=0; j<NumImportIDs; j++) {
644  ptr = (double *) Imports + j*SizeOfPacket;
645  jj = ToFirstPointInElementList[ImportLIDs[j]];
646  int ElementSize = ToElementSizeList[ImportLIDs[j]];
647  for (k=0; k<ElementSize; k++) {
648  To[jj+k] = EPETRA_MAX( To[jj+k], std::abs(*ptr));
649  ptr++;
650  }
651  }
652  }
653  // Note: The following form of averaging is not a true average if more that one value is combined.
654  // This might be an issue in the future, but we leave this way for now.
655  else if(CombineMode==Average) {
656  for (j=0; j<NumImportIDs; j++) {
657  ptr = (double *) Imports + j*SizeOfPacket;
658  jj = ToFirstPointInElementList[ImportLIDs[j]];
659  int ElementSize = ToElementSizeList[ImportLIDs[j]];
660  for (k=0; k<ElementSize; k++)
661  { To[jj+k] += *ptr++; To[jj+k] /= 2;}
662  }
663  }
664  }
665 
666  return(0);
667 }
668 
virtual const Epetra_BlockMap & DataMap() const
Returns the Epetra_BlockMap object with the distribution of underlying values.
virtual int ApplyInverse(const Epetra_MultiVector &X, Epetra_MultiVector &Y) const
Returns the result of a Epetra_Operator inverse applied to an Epetra_MultiVector X in Y...
int NumMyBlocks() const
Returns the number of local blocks.
double * Values() const
Returns a pointer to the array containing the blocks.
virtual const Epetra_Comm & Comm() const
Returns a pointer to the Epetra_Comm communicator associated with this operator.
int NumMyUnknowns() const
Returns the number of local unknowns.
EpetraExt_BlockDiagMatrix & operator=(const EpetraExt_BlockDiagMatrix &Source)
= Operator.
virtual ~EpetraExt_BlockDiagMatrix()
Destructor.
EpetraExt_BlockDiagMatrix: A class for storing distributed block matrices.
virtual void Print(ostream &os) const
Print method.
int BlockSize(int LID) const
Returns the size of the given block.
int NumData() const
Returns the size of the total Data block.
EpetraExt_BlockDiagMatrix(const Epetra_BlockMap &Map, bool zero_out=true)
Constructor - This map is the map of the vector this can be applied to.
#define AM_MULTIPLY
#define AM_FACTOR
virtual int Compute()
Computes the inverse / factorization if such is set on the list.
virtual int SetParameters(Teuchos::ParameterList &List)
SetParameters.
#define AM_INVERT
int DataSize(int LID) const
Returns the size of the data in the given block.
void PutScalar(double value)
PutScalar function.