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);
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 
00215 template<class T>
00216 int Epetra_Util_insert(T item, int offset, T*& list,
00217                         int& usedLength,
00218                         int& allocatedLength,
00219                         int allocChunkSize=32)
00220 {
00221   if (offset < 0 || offset > usedLength) {
00222     return(-1);
00223   }
00224 
00225   if (usedLength < allocatedLength) {
00226     for(int i=usedLength; i>offset; --i) {
00227       list[i] = list[i-1];
00228     }
00229     list[offset] = item;
00230     ++usedLength;
00231     return(0);
00232   }
00233 
00234   T* newlist = new T[allocatedLength+allocChunkSize];
00235   if (newlist == NULL) {
00236     return(-1);
00237   }
00238 
00239   allocatedLength += allocChunkSize;
00240   int i;
00241   for(i=0; i<offset; ++i) {
00242     newlist[i] = list[i];
00243   }
00244 
00245   newlist[offset] = item;
00246 
00247   for(i=offset+1; i<=usedLength; ++i) {
00248     newlist[i] = list[i-1];
00249   }
00250 
00251   ++usedLength;
00252   delete [] list;
00253   list = newlist;
00254   return(0);
00255 }
00256 
00258 
00282 int Epetra_Util_ExtractHbData(Epetra_CrsMatrix * A, Epetra_MultiVector * LHS,
00283             Epetra_MultiVector * RHS,
00284             int & M, int & N, int & nz, int * & ptr,
00285             int * & ind, double * & val, int & Nrhs,
00286             double * & rhs, int & ldrhs,
00287             double * & lhs, int & ldlhs);
00288 
00289 
00290 #endif /* EPETRA_UTIL_H */

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