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);
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 fevec1(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);
00136   Epetra_FEVector x0(Map);
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 fevec2(Epetra_Comm& Comm, bool verbose)
00189 {
00190   int ierr = 0;
00191   int NumGlobalRows = 12;
00192   int elemSize = 3;
00193   int indexBase = 0;
00194   Epetra_BlockMap Map(NumGlobalRows, elemSize, indexBase, Comm);
00195 
00196   int Numprocs = Comm.NumProc();
00197   int MyPID   = Comm.MyPID();
00198 
00199   if (Numprocs != 2) return(0);
00200 
00201   int NumCols = 3;
00202   int* Indices = new int[NumCols];
00203   int* numValuesPerID = new int[NumCols];
00204   for(int i=0; i<NumCols; ++i) {
00205     numValuesPerID[i] = elemSize;
00206   }
00207  
00208   double* Values = new double[NumCols*elemSize];
00209  
00210 // Create vectors
00211 
00212   Epetra_FEVector b(Map);
00213   Epetra_FEVector x0(Map);
00214  
00215 // source terms
00216   NumCols = 2;
00217  
00218   if(MyPID==0)  // indices corresponding to element 0 on processor 0
00219   {
00220     Indices[0] = 0;
00221     Indices[1] = 3;
00222  
00223     Values[0] = 1./2.;
00224     Values[1] = 1./2.;
00225     Values[2] = 1./2.;
00226     Values[3] = 1./2.;
00227     Values[4] = 1./2.;
00228     Values[5] = 1./2.;
00229 
00230    }
00231    else
00232    {
00233     Indices[0] = 1;
00234     Indices[1] = 2;
00235  
00236     Values[0] = 0;
00237     Values[1] = 0;
00238     Values[2] = 0;
00239     Values[3] = 0;
00240     Values[4] = 0;
00241     Values[5] = 0;
00242    }
00243 
00244   EPETRA_TEST_ERR( b.SumIntoGlobalValues(NumCols, Indices,
00245            numValuesPerID, Values),
00246        ierr);
00247 
00248   EPETRA_TEST_ERR( b.GlobalAssemble(), ierr);
00249 
00250   if (verbose&&MyPID==0) {
00251     cout << "b:"<<endl;
00252   }
00253 
00254   if (verbose) {
00255   b.Print(cout);
00256   }
00257 
00258   x0 = b;
00259 
00260   if (verbose&&MyPID==0) {
00261     cout << "x:"<<endl;
00262   }
00263 
00264   if (verbose) {
00265   x0.Print(cout);
00266   }
00267 
00268   delete [] Values;
00269   delete [] Indices;
00270   delete [] numValuesPerID;
00271 
00272   return(0);
00273 }

Generated on Thu Sep 18 12:37:58 2008 for Epetra Package Browser (Single Doxygen Collection) by doxygen 1.3.9.1