Epetra Package Browser (Single Doxygen Collection) Development
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 the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
00008 // the U.S. Government retains certain rights in this software.
00009 //
00010 // Redistribution and use in source and binary forms, with or without
00011 // modification, are permitted provided that the following conditions are
00012 // met:
00013 //
00014 // 1. Redistributions of source code must retain the above copyright
00015 // notice, this list of conditions and the following disclaimer.
00016 //
00017 // 2. Redistributions in binary form must reproduce the above copyright
00018 // notice, this list of conditions and the following disclaimer in the
00019 // documentation and/or other materials provided with the distribution.
00020 //
00021 // 3. Neither the name of the Corporation nor the names of the
00022 // contributors may be used to endorse or promote products derived from
00023 // this software without specific prior written permission.
00024 //
00025 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
00026 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00027 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
00028 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
00029 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00030 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00031 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00032 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
00033 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
00034 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00035 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00036 //
00037 // Questions? Contact Michael A. Heroux (maherou@sandia.gov) 
00038 // 
00039 // ************************************************************************
00040 //@HEADER
00041 
00042 
00043 #include "Epetra_BLAS.h"
00044 #include "ExecuteTestProblems.h"
00045 #include "Epetra_Comm.h"
00046 #include "Epetra_Vector.h"
00047 #include "Epetra_IntSerialDenseVector.h"
00048 #include "Epetra_SerialDenseVector.h"
00049 
00050 int MultiVectorTests(const Epetra_BlockMap & Map, int NumVectors, bool verbose)
00051 {
00052   (void)NumVectors;
00053   const Epetra_Comm & Comm = Map.Comm();
00054   int ierr = 0;
00055   
00056   /* get number of processors and the name of this processor */
00057   
00058   // int NumProc = Comm.getNumProc();
00059   int MyPID   = Comm.MyPID();
00060   
00061   // Construct FEVector
00062   
00063   if (verbose&&MyPID==0) cout << "constructing Epetra_FEVector" << endl;
00064 
00065   Epetra_FEVector A(Map, 1);
00066  
00067   //For an extreme test, we'll have each processor sum-in a 1.0 for All
00068   //global ids.
00069 
00070   int minGID = Map.MinAllGID();
00071   int numGlobalIDs = Map.NumGlobalElements();
00072 
00073   //For now we're going to have just one point associated with
00074   //each GID (element).
00075 
00076   int* ptIndices = new int[numGlobalIDs];
00077   double* ptCoefs = new double[numGlobalIDs];
00078 
00079   Epetra_IntSerialDenseVector epetra_indices(View, ptIndices, numGlobalIDs);
00080   Epetra_SerialDenseVector epetra_coefs(View, ptCoefs, numGlobalIDs);
00081 
00082   {for(int i=0; i<numGlobalIDs; ++i) {
00083     ptIndices[i] = minGID+i;
00084     ptCoefs[i] = 1.0;
00085   }}
00086 
00087   if (verbose&&MyPID==0) {
00088     cout << "calling A.SumIntoGlobalValues with " << numGlobalIDs << " values"<<endl;
00089   }
00090   EPETRA_TEST_ERR( A.SumIntoGlobalValues(numGlobalIDs, ptIndices, ptCoefs), ierr);
00091 
00092   if (verbose&&MyPID==0) {
00093     cout << "calling A.SumIntoGlobalValues with " << numGlobalIDs << " values"<<endl;
00094   }
00095   EPETRA_TEST_ERR( A.SumIntoGlobalValues(epetra_indices, epetra_coefs), ierr);
00096 
00097   if (verbose&&MyPID==0) {
00098     cout << "calling A.GlobalAssemble()" << endl;
00099   }
00100 
00101   EPETRA_TEST_ERR( A.GlobalAssemble(), ierr );
00102 
00103   if (verbose&&MyPID==0) {
00104   cout << "after globalAssemble"<<endl;
00105   }
00106   if (verbose) {
00107   A.Print(cout);
00108   }
00109 
00110   //now do a quick test of the copy constructor
00111   Epetra_FEVector B(A);
00112 
00113   double nrm2a, nrm2b;
00114   A.Norm2(&nrm2a);
00115   B.Norm2(&nrm2b);
00116 
00117   if (nrm2a != nrm2b) {
00118     cerr << "copy-constructor test failed, norm of copy doesn't equal"
00119          << " norm of original."<<endl;
00120     return(-1);
00121   }
00122 
00123   delete [] ptIndices;
00124   delete [] ptCoefs;
00125 
00126   return(ierr);
00127 }
00128 
00129 int fevec0(Epetra_Comm& Comm, bool verbose)
00130 {
00131   int ierr = 0;
00132   int NumGlobalRows = 4;
00133   int indexBase = 0;
00134   Epetra_Map Map(NumGlobalRows, indexBase, Comm);
00135 
00136   int Numprocs = Comm.NumProc();
00137   int MyPID   = Comm.MyPID();
00138 
00139   if (Numprocs != 2) return(0);
00140 
00141 
00142   int NumCols = 3;
00143   int* Indices = new int[NumCols];
00144 
00145   double* Values = new double[NumCols];
00146 
00147 // Create vectors
00148 
00149   Epetra_FEVector b(Map, 1);
00150   Epetra_FEVector x0(Map, 1);
00151 
00152 // source terms
00153   NumCols = 2;
00154 
00155   if(MyPID==0)  // indices corresponding to element 0 on processor 0
00156   {
00157     Indices[0] = 0;
00158     Indices[1] = 3;
00159 
00160     Values[0] = 1./2.;
00161     Values[1] = 1./2.;
00162 
00163    }
00164    else
00165    {
00166     Indices[0] = 1;
00167     Indices[1] = 2;
00168 
00169     Values[0] = 0;
00170     Values[1] = 0;
00171    }
00172 
00173   EPETRA_TEST_ERR( b.SumIntoGlobalValues(NumCols, Indices, Values),
00174                    ierr);
00175 
00176   EPETRA_TEST_ERR( b.GlobalAssemble(), ierr);
00177 
00178   if (verbose&&MyPID==0) {
00179     cout << "b:"<<endl;
00180   }
00181 
00182   if (verbose) {
00183   b.Print(cout);
00184   }
00185 
00186   x0 = b;
00187 
00188   if (verbose&&MyPID==0) {
00189     cout << "x:"<<endl;
00190   }
00191 
00192   if (verbose) {
00193   x0.Print(cout);
00194   }
00195 
00196   delete [] Values;
00197   delete [] Indices;
00198 
00199   return(0);
00200 }
00201 
00202 int fevec1(Epetra_Comm& Comm, bool verbose)
00203 {
00204   int Numprocs = Comm.NumProc();
00205 
00206   if (Numprocs != 2) return(0);
00207   int MyPID   = Comm.MyPID();
00208 
00209   int ierr = 0;
00210   int NumGlobalRows = 6;
00211   const int NumVectors = 4;
00212   int indexBase = 0;
00213   Epetra_Map Map(NumGlobalRows, indexBase, Comm);
00214 
00215   const int Num = 4;
00216   int Indices[Num];
00217  
00218   double Values[Num];
00219  
00220 // Create vectors
00221 
00222   Epetra_FEVector b(Map, NumVectors);
00223   Epetra_FEVector x0(Map, NumVectors);
00224  
00225 // source terms
00226  
00227   if(MyPID==0)  // indices corresponding to element 0 on processor 0
00228   {
00229     Indices[0] = 0;
00230     Indices[1] = 1;
00231     Indices[2] = 4;
00232     Indices[3] = 5;
00233  
00234     Values[0] = 1./2.;
00235     Values[1] = 1./2.;
00236     Values[2] = 1./2.;
00237     Values[3] = 1./2.;
00238 
00239    }
00240    else
00241    {
00242     Indices[0] = 1;
00243     Indices[1] = 2;
00244     Indices[2] = 3;
00245     Indices[3] = 4;
00246  
00247     Values[0] = 0;
00248     Values[1] = 0;
00249     Values[2] = 0;
00250     Values[3] = 0;
00251    }
00252 
00253   for(int i=0; i<NumVectors; ++i) {
00254     EPETRA_TEST_ERR( b.SumIntoGlobalValues(Num, Indices, Values, i),
00255        ierr);
00256   }
00257 
00258   EPETRA_TEST_ERR( b.GlobalAssemble(), ierr);
00259 
00260   double nrm2[NumVectors];
00261 
00262   b.Norm2(nrm2);
00263 
00264   for(int i=1; i<NumVectors; ++i) {
00265     if (fabs(nrm2[i]-nrm2[0]) > 1.e-12) {
00266       EPETRA_TEST_ERR(-1, ierr);
00267       return(-1);
00268     }
00269   }
00270 
00271 
00272   //now sum-in again, to make sure the previous call to GlobalAssemble
00273   //didn't do something nasty to internal non-local data structures.
00274   //(This is a specific case that has bitten me. Hence this test...)
00275   for(int i=0; i<NumVectors; ++i) {
00276     EPETRA_TEST_ERR( b.SumIntoGlobalValues(Num, Indices, Values, i),
00277                    ierr);
00278   }
00279 
00280   //and now GlobalAssemble again...
00281   EPETRA_TEST_ERR( b.GlobalAssemble(), ierr);
00282 
00283 
00284   if (verbose&&MyPID==0) {
00285     cout << "b:"<<endl;
00286   }
00287 
00288   if (verbose) {
00289     b.Print(cout);
00290   }
00291 
00292   x0 = b;
00293 
00294   if (verbose&&MyPID==0) {
00295     cout << "x:"<<endl;
00296   }
00297 
00298   if (verbose) {
00299     x0.Print(cout);
00300   }
00301 
00302   return(0);
00303 }
00304 
00305 int fevec2(Epetra_Comm& Comm, bool verbose)
00306 {
00307   int ierr = 0;
00308   int NumGlobalElems = 4;
00309   int elemSize = 3;
00310   int indexBase = 0;
00311   Epetra_BlockMap Map(NumGlobalElems, elemSize, indexBase, Comm);
00312 
00313   int Numprocs = Comm.NumProc();
00314   int MyPID   = Comm.MyPID();
00315 
00316   if (Numprocs != 2) return(0);
00317 
00318   int NumCols = 3;
00319   int* Indices = new int[NumCols];
00320   int* numValuesPerID = new int[NumCols];
00321   for(int i=0; i<NumCols; ++i) {
00322     numValuesPerID[i] = elemSize;
00323   }
00324  
00325   double* Values = new double[NumCols*elemSize];
00326  
00327 // Create vectors
00328 
00329   Epetra_FEVector b(Map, 1);
00330   Epetra_FEVector x0(Map, 1);
00331  
00332 // source terms
00333   NumCols = 2;
00334  
00335   if(MyPID==0)  // indices corresponding to element 0 on processor 0
00336   {
00337     Indices[0] = 0;
00338     Indices[1] = 3;
00339  
00340     Values[0] = 1./2.;
00341     Values[1] = 1./2.;
00342     Values[2] = 1./2.;
00343     Values[3] = 1./2.;
00344     Values[4] = 1./2.;
00345     Values[5] = 1./2.;
00346 
00347    }
00348    else
00349    {
00350     Indices[0] = 1;
00351     Indices[1] = 2;
00352  
00353     Values[0] = 0;
00354     Values[1] = 0;
00355     Values[2] = 0;
00356     Values[3] = 0;
00357     Values[4] = 0;
00358     Values[5] = 0;
00359    }
00360 
00361   EPETRA_TEST_ERR( b.SumIntoGlobalValues(NumCols, Indices,
00362            numValuesPerID, Values),
00363        ierr);
00364 
00365   EPETRA_TEST_ERR( b.GlobalAssemble(), ierr);
00366 
00367   if (verbose&&MyPID==0) {
00368     cout << "b:"<<endl;
00369   }
00370 
00371   if (verbose) {
00372   b.Print(cout);
00373   }
00374 
00375   x0 = b;
00376 
00377   if (verbose&&MyPID==0) {
00378     cout << "x:"<<endl;
00379   }
00380 
00381   if (verbose) {
00382   x0.Print(cout);
00383   }
00384 
00385   delete [] Values;
00386   delete [] Indices;
00387   delete [] numValuesPerID;
00388 
00389   return(0);
00390 }
00391 
00392 int fevec3(Epetra_Comm& Comm, bool verbose)
00393 {
00394   int ierr = 0;
00395   int NumGlobalElems = 4;
00396   int elemSize = 40;
00397   int indexBase = 0;
00398   Epetra_BlockMap Map(NumGlobalElems, elemSize, indexBase, Comm);
00399 
00400   int Numprocs = Comm.NumProc();
00401   int MyPID   = Comm.MyPID();
00402 
00403   if (Numprocs != 2) return(0);
00404 
00405   int NumCols = 3;
00406   int* Indices = new int[NumCols];
00407   int* numValuesPerID = new int[NumCols];
00408   for(int i=0; i<NumCols; ++i) {
00409     numValuesPerID[i] = elemSize;
00410   }
00411  
00412   double* Values = new double[NumCols*elemSize];
00413  
00414 // Create vectors
00415 
00416   Epetra_FEVector b(Map, 1);
00417   Epetra_FEVector x0(Map, 1);
00418  
00419 // source terms
00420   NumCols = 2;
00421  
00422   if(MyPID==0)  // indices corresponding to element 0 on processor 0
00423   {
00424     Indices[0] = 0;
00425     Indices[1] = 3;
00426  
00427     for(int ii=0; ii<NumCols*elemSize; ++ii) {
00428       Values[ii] = 1./2.;
00429     }
00430 
00431   }
00432   else
00433   {
00434     Indices[0] = 1;
00435     Indices[1] = 2;
00436  
00437     for(int ii=0; ii<NumCols*elemSize; ++ii) {
00438       Values[ii] = 0.;
00439     }
00440 
00441   }
00442 
00443   EPETRA_TEST_ERR( b.SumIntoGlobalValues(NumCols, Indices,
00444            numValuesPerID, Values),
00445        ierr);
00446 
00447   EPETRA_TEST_ERR( b.GlobalAssemble(), ierr);
00448 
00449   if (verbose&&MyPID==0) {
00450     cout << "b:"<<endl;
00451   }
00452 
00453   if (verbose) {
00454   b.Print(cout);
00455   }
00456 
00457   x0 = b;
00458 
00459   if (verbose&&MyPID==0) {
00460     cout << "x:"<<endl;
00461   }
00462 
00463   if (verbose) {
00464   x0.Print(cout);
00465   }
00466 
00467   delete [] Values;
00468   delete [] Indices;
00469   delete [] numValuesPerID;
00470 
00471   return(0);
00472 }
00473 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines