FEVector/ExecuteTestProblems.cpp

Go to the documentation of this file.
00001 //@HEADER
00002 // ************************************************************************
00003 // 
00004 //               Epetra: Linear Algebra Services Package 
00005 //                 Copyright (2001) Sandia Corporation
00006 // 
00007 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
00008 // license for use of this work by or on behalf of the U.S. Government.
00009 // 
00010 // This library is free software; you can redistribute it and/or modify
00011 // it under the terms of the GNU Lesser General Public License as
00012 // published by the Free Software Foundation; either version 2.1 of the
00013 // License, or (at your option) any later version.
00014 //  
00015 // This library is distributed in the hope that it will be useful, but
00016 // WITHOUT ANY WARRANTY; without even the implied warranty of
00017 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00018 // Lesser General Public License for more details.
00019 //  
00020 // You should have received a copy of the GNU Lesser General Public
00021 // License along with this library; if not, write to the Free Software
00022 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
00023 // USA
00024 // Questions? Contact Michael A. Heroux (maherou@sandia.gov) 
00025 // 
00026 // ************************************************************************
00027 //@HEADER
00028 
00029 #include "Epetra_BLAS.h"
00030 #include "ExecuteTestProblems.h"
00031 #include "Epetra_Comm.h"
00032 #include "Epetra_Vector.h"
00033 #include "Epetra_IntSerialDenseVector.h"
00034 #include "Epetra_SerialDenseVector.h"
00035 
00036 int MultiVectorTests(const Epetra_BlockMap & Map, int NumVectors, bool verbose)
00037 {
00038   (void)NumVectors;
00039   const Epetra_Comm & Comm = Map.Comm();
00040   int ierr = 0;
00041   
00042   /* get number of processors and the name of this processor */
00043   
00044   // int NumProc = Comm.getNumProc();
00045   int MyPID   = Comm.MyPID();
00046   
00047   // Construct FEVector
00048   
00049   if (verbose&&MyPID==0) cout << "constructing Epetra_FEVector" << endl;
00050 
00051   Epetra_FEVector A(Map, 1);
00052  
00053   //For an extreme test, we'll have each processor sum-in a 1.0 for All
00054   //global ids.
00055 
00056   int minGID = Map.MinAllGID();
00057   int numGlobalIDs = Map.NumGlobalElements();
00058 
00059   //For now we're going to have just one point associated with
00060   //each GID (element).
00061 
00062   int* ptIndices = new int[numGlobalIDs];
00063   double* ptCoefs = new double[numGlobalIDs];
00064 
00065   Epetra_IntSerialDenseVector epetra_indices(View, ptIndices, numGlobalIDs);
00066   Epetra_SerialDenseVector epetra_coefs(View, ptCoefs, numGlobalIDs);
00067 
00068   {for(int i=0; i<numGlobalIDs; ++i) {
00069     ptIndices[i] = minGID+i;
00070     ptCoefs[i] = 1.0;
00071   }}
00072 
00073   if (verbose&&MyPID==0) {
00074     cout << "calling A.SumIntoGlobalValues with " << numGlobalIDs << " values"<<endl;
00075   }
00076   EPETRA_TEST_ERR( A.SumIntoGlobalValues(numGlobalIDs, ptIndices, ptCoefs), ierr);
00077 
00078   if (verbose&&MyPID==0) {
00079     cout << "calling A.SumIntoGlobalValues with " << numGlobalIDs << " values"<<endl;
00080   }
00081   EPETRA_TEST_ERR( A.SumIntoGlobalValues(epetra_indices, epetra_coefs), ierr);
00082 
00083   if (verbose&&MyPID==0) {
00084     cout << "calling A.GlobalAssemble()" << endl;
00085   }
00086 
00087   EPETRA_TEST_ERR( A.GlobalAssemble(), ierr );
00088 
00089   if (verbose&&MyPID==0) {
00090   cout << "after globalAssemble"<<endl;
00091   }
00092   if (verbose) {
00093   A.Print(cout);
00094   }
00095 
00096   //now do a quick test of the copy constructor
00097   Epetra_FEVector B(A);
00098 
00099   double nrm2a, nrm2b;
00100   A.Norm2(&nrm2a);
00101   B.Norm2(&nrm2b);
00102 
00103   if (nrm2a != nrm2b) {
00104     cerr << "copy-constructor test failed, norm of copy doesn't equal"
00105          << " norm of original."<<endl;
00106     return(-1);
00107   }
00108 
00109   delete [] ptIndices;
00110   delete [] ptCoefs;
00111 
00112   return(ierr);
00113 }
00114 
00115 int fevec0(Epetra_Comm& Comm, bool verbose)
00116 {
00117   int ierr = 0;
00118   int NumGlobalRows = 4;
00119   int indexBase = 0;
00120   Epetra_Map Map(NumGlobalRows, indexBase, Comm);
00121 
00122   int Numprocs = Comm.NumProc();
00123   int MyPID   = Comm.MyPID();
00124 
00125   if (Numprocs != 2) return(0);
00126 
00127 
00128   int NumCols = 3;
00129   int* Indices = new int[NumCols];
00130 
00131   double* Values = new double[NumCols];
00132 
00133 // Create vectors
00134 
00135   Epetra_FEVector b(Map, 1);
00136   Epetra_FEVector x0(Map, 1);
00137 
00138 // source terms
00139   NumCols = 2;
00140 
00141   if(MyPID==0)  // indices corresponding to element 0 on processor 0
00142   {
00143     Indices[0] = 0;
00144     Indices[1] = 3;
00145 
00146     Values[0] = 1./2.;
00147     Values[1] = 1./2.;
00148 
00149    }
00150    else
00151    {
00152     Indices[0] = 1;
00153     Indices[1] = 2;
00154 
00155     Values[0] = 0;
00156     Values[1] = 0;
00157    }
00158 
00159   EPETRA_TEST_ERR( b.SumIntoGlobalValues(NumCols, Indices, Values),
00160                    ierr);
00161 
00162   EPETRA_TEST_ERR( b.GlobalAssemble(), ierr);
00163 
00164   if (verbose&&MyPID==0) {
00165     cout << "b:"<<endl;
00166   }
00167 
00168   if (verbose) {
00169   b.Print(cout);
00170   }
00171 
00172   x0 = b;
00173 
00174   if (verbose&&MyPID==0) {
00175     cout << "x:"<<endl;
00176   }
00177 
00178   if (verbose) {
00179   x0.Print(cout);
00180   }
00181 
00182   delete [] Values;
00183   delete [] Indices;
00184 
00185   return(0);
00186 }
00187 
00188 int fevec1(Epetra_Comm& Comm, bool verbose)
00189 {
00190   int Numprocs = Comm.NumProc();
00191 
00192   if (Numprocs != 2) return(0);
00193   int MyPID   = Comm.MyPID();
00194 
00195   int ierr = 0;
00196   int NumGlobalRows = 6;
00197   const int NumVectors = 4;
00198   int indexBase = 0;
00199   Epetra_Map Map(NumGlobalRows, indexBase, Comm);
00200 
00201   const int Num = 4;
00202   int Indices[Num];
00203  
00204   double Values[Num];
00205  
00206 // Create vectors
00207 
00208   Epetra_FEVector b(Map, NumVectors);
00209   Epetra_FEVector x0(Map, NumVectors);
00210  
00211 // source terms
00212  
00213   if(MyPID==0)  // indices corresponding to element 0 on processor 0
00214   {
00215     Indices[0] = 0;
00216     Indices[1] = 1;
00217     Indices[2] = 4;
00218     Indices[3] = 5;
00219  
00220     Values[0] = 1./2.;
00221     Values[1] = 1./2.;
00222     Values[2] = 1./2.;
00223     Values[3] = 1./2.;
00224 
00225    }
00226    else
00227    {
00228     Indices[0] = 1;
00229     Indices[1] = 2;
00230     Indices[2] = 3;
00231     Indices[3] = 4;
00232  
00233     Values[0] = 0;
00234     Values[1] = 0;
00235     Values[2] = 0;
00236     Values[3] = 0;
00237    }
00238 
00239   for(int i=0; i<NumVectors; ++i) {
00240     EPETRA_TEST_ERR( b.SumIntoGlobalValues(Num, Indices, Values, i),
00241        ierr);
00242   }
00243 
00244   EPETRA_TEST_ERR( b.GlobalAssemble(), ierr);
00245 
00246   double nrm2[NumVectors];
00247 
00248   b.Norm2(nrm2);
00249 
00250   for(int i=1; i<NumVectors; ++i) {
00251     if (fabs(nrm2[i]-nrm2[0]) > 1.e-12) {
00252       EPETRA_TEST_ERR(-1, ierr);
00253       return(-1);
00254     }
00255   }
00256 
00257 
00258   //now sum-in again, to make sure the previous call to GlobalAssemble
00259   //didn't do something nasty to internal non-local data structures.
00260   //(This is a specific case that has bitten me. Hence this test...)
00261   for(int i=0; i<NumVectors; ++i) {
00262     EPETRA_TEST_ERR( b.SumIntoGlobalValues(Num, Indices, Values, i),
00263                    ierr);
00264   }
00265 
00266   //and now GlobalAssemble again...
00267   EPETRA_TEST_ERR( b.GlobalAssemble(), ierr);
00268 
00269 
00270   if (verbose&&MyPID==0) {
00271     cout << "b:"<<endl;
00272   }
00273 
00274   if (verbose) {
00275     b.Print(cout);
00276   }
00277 
00278   x0 = b;
00279 
00280   if (verbose&&MyPID==0) {
00281     cout << "x:"<<endl;
00282   }
00283 
00284   if (verbose) {
00285     x0.Print(cout);
00286   }
00287 
00288   return(0);
00289 }
00290 
00291 int fevec2(Epetra_Comm& Comm, bool verbose)
00292 {
00293   int ierr = 0;
00294   int NumGlobalElems = 4;
00295   int elemSize = 3;
00296   int indexBase = 0;
00297   Epetra_BlockMap Map(NumGlobalElems, elemSize, indexBase, Comm);
00298 
00299   int Numprocs = Comm.NumProc();
00300   int MyPID   = Comm.MyPID();
00301 
00302   if (Numprocs != 2) return(0);
00303 
00304   int NumCols = 3;
00305   int* Indices = new int[NumCols];
00306   int* numValuesPerID = new int[NumCols];
00307   for(int i=0; i<NumCols; ++i) {
00308     numValuesPerID[i] = elemSize;
00309   }
00310  
00311   double* Values = new double[NumCols*elemSize];
00312  
00313 // Create vectors
00314 
00315   Epetra_FEVector b(Map, 1);
00316   Epetra_FEVector x0(Map, 1);
00317  
00318 // source terms
00319   NumCols = 2;
00320  
00321   if(MyPID==0)  // indices corresponding to element 0 on processor 0
00322   {
00323     Indices[0] = 0;
00324     Indices[1] = 3;
00325  
00326     Values[0] = 1./2.;
00327     Values[1] = 1./2.;
00328     Values[2] = 1./2.;
00329     Values[3] = 1./2.;
00330     Values[4] = 1./2.;
00331     Values[5] = 1./2.;
00332 
00333    }
00334    else
00335    {
00336     Indices[0] = 1;
00337     Indices[1] = 2;
00338  
00339     Values[0] = 0;
00340     Values[1] = 0;
00341     Values[2] = 0;
00342     Values[3] = 0;
00343     Values[4] = 0;
00344     Values[5] = 0;
00345    }
00346 
00347   EPETRA_TEST_ERR( b.SumIntoGlobalValues(NumCols, Indices,
00348            numValuesPerID, Values),
00349        ierr);
00350 
00351   EPETRA_TEST_ERR( b.GlobalAssemble(), ierr);
00352 
00353   if (verbose&&MyPID==0) {
00354     cout << "b:"<<endl;
00355   }
00356 
00357   if (verbose) {
00358   b.Print(cout);
00359   }
00360 
00361   x0 = b;
00362 
00363   if (verbose&&MyPID==0) {
00364     cout << "x:"<<endl;
00365   }
00366 
00367   if (verbose) {
00368   x0.Print(cout);
00369   }
00370 
00371   delete [] Values;
00372   delete [] Indices;
00373   delete [] numValuesPerID;
00374 
00375   return(0);
00376 }
00377 
00378 int fevec3(Epetra_Comm& Comm, bool verbose)
00379 {
00380   int ierr = 0;
00381   int NumGlobalElems = 4;
00382   int elemSize = 40;
00383   int indexBase = 0;
00384   Epetra_BlockMap Map(NumGlobalElems, elemSize, indexBase, Comm);
00385 
00386   int Numprocs = Comm.NumProc();
00387   int MyPID   = Comm.MyPID();
00388 
00389   if (Numprocs != 2) return(0);
00390 
00391   int NumCols = 3;
00392   int* Indices = new int[NumCols];
00393   int* numValuesPerID = new int[NumCols];
00394   for(int i=0; i<NumCols; ++i) {
00395     numValuesPerID[i] = elemSize;
00396   }
00397  
00398   double* Values = new double[NumCols*elemSize];
00399  
00400 // Create vectors
00401 
00402   Epetra_FEVector b(Map, 1);
00403   Epetra_FEVector x0(Map, 1);
00404  
00405 // source terms
00406   NumCols = 2;
00407  
00408   if(MyPID==0)  // indices corresponding to element 0 on processor 0
00409   {
00410     Indices[0] = 0;
00411     Indices[1] = 3;
00412  
00413     for(int ii=0; ii<NumCols*elemSize; ++ii) {
00414       Values[ii] = 1./2.;
00415     }
00416 
00417   }
00418   else
00419   {
00420     Indices[0] = 1;
00421     Indices[1] = 2;
00422  
00423     for(int ii=0; ii<NumCols*elemSize; ++ii) {
00424       Values[ii] = 0.;
00425     }
00426 
00427   }
00428 
00429   EPETRA_TEST_ERR( b.SumIntoGlobalValues(NumCols, Indices,
00430            numValuesPerID, Values),
00431        ierr);
00432 
00433   EPETRA_TEST_ERR( b.GlobalAssemble(), ierr);
00434 
00435   if (verbose&&MyPID==0) {
00436     cout << "b:"<<endl;
00437   }
00438 
00439   if (verbose) {
00440   b.Print(cout);
00441   }
00442 
00443   x0 = b;
00444 
00445   if (verbose&&MyPID==0) {
00446     cout << "x:"<<endl;
00447   }
00448 
00449   if (verbose) {
00450   x0.Print(cout);
00451   }
00452 
00453   delete [] Values;
00454   delete [] Indices;
00455   delete [] numValuesPerID;
00456 
00457   return(0);
00458 }
00459 

Generated on Wed May 12 21:41:06 2010 for Epetra Package Browser (Single Doxygen Collection) by  doxygen 1.4.7