Epetra_Util.h

Go to the documentation of this file.
00001 
00002 //@HEADER
00003 /*
00004 ************************************************************************
00005 
00006               Epetra: Linear Algebra Services Package 
00007                 Copyright (2001) Sandia Corporation
00008 
00009 Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
00010 license for use of this work by or on behalf of the U.S. Government.
00011 
00012 This library is free software; you can redistribute it and/or modify
00013 it under the terms of the GNU Lesser General Public License as
00014 published by the Free Software Foundation; either version 2.1 of the
00015 License, or (at your option) any later version.
00016  
00017 This library is distributed in the hope that it will be useful, but
00018 WITHOUT ANY WARRANTY; without even the implied warranty of
00019 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00020 Lesser General Public License for more details.
00021  
00022 You should have received a copy of the GNU Lesser General Public
00023 License along with this library; if not, write to the Free Software
00024 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
00025 USA
00026 Questions? Contact Michael A. Heroux (maherou@sandia.gov) 
00027 
00028 ************************************************************************
00029 */
00030 //@HEADER
00031 
00032 #ifndef EPETRA_UTIL_H
00033 #define EPETRA_UTIL_H
00034 
00035 #include "Epetra_Object.h"
00036 class Epetra_Map;
00037 class Epetra_BlockMap;
00038 class Epetra_CrsMatrix;
00039 class Epetra_MultiVector;
00040 
00042 
00064 class Epetra_Util {
00065     
00066   public:
00068 
00070   Epetra_Util();
00071 
00072 
00074 
00076   Epetra_Util(const Epetra_Util& Util);
00077 
00079   virtual ~Epetra_Util();
00080 
00082 
00083 
00085   unsigned int RandomInt();
00086 
00088   double RandomDouble();
00089 
00091 
00094   unsigned int Seed() const;
00095 
00097 
00103   int SetSeed(unsigned int Seed_in);
00104 
00106   
00108 
00131   static void Sort(bool SortAscending, int NumKeys, int * Keys, 
00132        int NumDoubleCompanions,double ** DoubleCompanions, 
00133        int NumIntCompanions, int ** IntCompanions);
00134 
00136 
00142   static Epetra_Map Create_Root_Map(const Epetra_Map & usermap,
00143           int root = 0);
00144 
00146 
00150   static Epetra_Map Create_OneToOne_Map(const Epetra_Map& usermap,
00151           bool high_rank_proc_owns_shared=false);
00152 
00154 
00158   static Epetra_BlockMap Create_OneToOne_BlockMap(const Epetra_BlockMap& usermap,
00159               bool high_rank_proc_owns_shared=false);
00160 
00162   static double Chop(const double & Value){
00163     if (std::abs(Value) < chopVal_) return 0;
00164     return Value;
00165   };
00166 
00167   static const double chopVal_;
00168 
00169  private:
00170   unsigned int Seed_;
00171 };
00172 
00173 
00174 // Epetra_Util constructor
00175 inline Epetra_Util::Epetra_Util() : Seed_(std::rand()) {}
00176 // Epetra_Util constructor
00177 inline Epetra_Util::Epetra_Util(const Epetra_Util& Util) : Seed_(Util.Seed_) {}
00178 // Epetra_Util destructor
00179 inline Epetra_Util::~Epetra_Util(){}
00180 
00193 int Epetra_Util_binary_search(int item,
00194                               const int* list,
00195                               int len,
00196                               int& insertPoint);
00197 
00198 template<class T>
00199 int Epetra_Util_insert_empty_positions(T*& array, int& usedLength,
00200                                        int& allocatedLength,
00201                                        int insertOffset, int numPositions,
00202                                        int allocChunkSize=32)
00203 {
00204   if (insertOffset < 0 || insertOffset > usedLength ||
00205       usedLength > allocatedLength) {
00206     return(-1);
00207   }
00208 
00209   if ((usedLength+numPositions) < allocatedLength) {
00210     for(int i=usedLength-1; i>=insertOffset; --i) {
00211       array[i+numPositions] = array[i];
00212     }
00213     usedLength += numPositions;
00214     return(0);
00215   }
00216 
00217   allocatedLength += allocChunkSize;
00218   //what if allocatedLength is still not large enough?
00219   //loop until it is large enough:
00220   while(allocatedLength < usedLength+numPositions) {
00221     allocatedLength += allocChunkSize;
00222   }
00223 
00224   T* newlist = new T[allocatedLength];
00225 
00226   for(int i=0; i<insertOffset; ++i) {
00227     newlist[i] = array[i];
00228   }
00229 
00230   for(int i=insertOffset; i<usedLength; ++i) {
00231     newlist[i+numPositions] = array[i];
00232   }
00233 
00234   usedLength += numPositions;
00235   delete [] array;
00236   array = newlist;
00237   return(0);
00238 }
00239 
00255 template<class T>
00256 int Epetra_Util_insert(T item, int offset, T*& list,
00257                         int& usedLength,
00258                         int& allocatedLength,
00259                         int allocChunkSize=32)
00260 {
00261   int code = Epetra_Util_insert_empty_positions<T>(list, usedLength,
00262                                                 allocatedLength, offset, 1,
00263                                                 allocChunkSize);
00264   if (code != 0) {
00265     return(code);
00266   }
00267 
00268   list[offset] = item;
00269 
00270   return(0);
00271 }
00272 
00274 
00298 int Epetra_Util_ExtractHbData(Epetra_CrsMatrix * A, Epetra_MultiVector * LHS,
00299             Epetra_MultiVector * RHS,
00300             int & M, int & N, int & nz, int * & ptr,
00301             int * & ind, double * & val, int & Nrhs,
00302             double * & rhs, int & ldrhs,
00303             double * & lhs, int & ldlhs);
00304 
00305 
00306 #endif /* EPETRA_UTIL_H */

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