MFEM v2.0
|
00001 // Copyright (c) 2010, Lawrence Livermore National Security, LLC. Produced at 00002 // the Lawrence Livermore National Laboratory. LLNL-CODE-443211. All Rights 00003 // reserved. See file COPYRIGHT for details. 00004 // 00005 // This file is part of the MFEM library. For more information and source code 00006 // availability see http://mfem.googlecode.com. 00007 // 00008 // MFEM is free software; you can redistribute it and/or modify it under the 00009 // terms of the GNU Lesser General Public License (as published by the Free 00010 // Software Foundation) version 2.1 dated February 1999. 00011 00012 #ifndef MFEM_TABLE 00013 #define MFEM_TABLE 00014 00015 // Data types for Table. 00016 00017 #include "mem_alloc.hpp" 00018 00022 class Table 00023 { 00024 protected: 00025 00027 int size; 00028 00032 int *I, *J; 00033 00034 public: 00036 Table() { size = -1; I = J = NULL; } 00037 00039 explicit Table (int dim, int connections_per_row = 3); 00040 00043 Table (int nrows, int *partitioning); 00044 00046 void MakeI (int nrows); 00047 void AddAColumnInRow (int r) { I[r]++; } 00048 void AddColumnsInRow (int r, int ncol) { I[r] += ncol; } 00049 void MakeJ(); 00050 void AddConnection (int r, int c) { J[I[r]++] = c; } 00051 void AddConnections (int r, int *c, int nc); 00052 void ShiftUpI(); 00053 00055 void SetSize(int dim, int connections_per_row); 00056 00059 void SetDims(int rows, int nnz); 00060 00062 inline int Size() const { return size; } 00063 00068 inline int Size_of_connections() const { return I[size]; } 00069 00073 int operator() (int i, int j) const; 00074 00076 void GetRow(int i, Array<int> &row) const; 00077 00078 int RowSize(int i) const { return I[i+1]-I[i]; } 00079 00080 const int *GetRow(int i) const { return J+I[i]; } 00081 int *GetRow(int i) { return J+I[i]; } 00082 00083 int *GetI() { return I; }; 00084 int *GetJ() { return J; }; 00085 const int *GetI() const { return I; }; 00086 const int *GetJ() const { return J; }; 00087 00088 void SetIJ(int *newI, int *newJ, int newsize = -1); 00089 00095 int Push( int i, int j ); 00096 00102 void Finalize(); 00103 00105 int Width() const; 00106 00108 void LoseData() { size = -1; I = J = NULL; } 00109 00111 void Print(ostream & out = cout, int width = 4) const; 00112 00113 void Save(ostream & out) const; 00114 00116 ~Table(); 00117 }; 00118 00120 void Transpose (const Table &A, Table &At, int _ncols_A = -1); 00121 00123 void Transpose(const Array<int> &A, Table &At, int _ncols_A = -1); 00124 00126 void Mult (const Table &A, const Table &B, Table &C); 00127 00128 00133 class STable : public Table 00134 { 00135 public: 00137 STable (int dim, int connections_per_row = 3); 00138 00142 int operator() (int i, int j) const; 00143 00149 int Push( int i, int j ); 00150 00152 ~STable() {} 00153 }; 00154 00155 00156 class DSTable 00157 { 00158 private: 00159 class Node 00160 { 00161 public: 00162 Node *Prev; 00163 int Column, Index; 00164 }; 00165 00166 int NumRows, NumEntries; 00167 Node **Rows; 00168 #ifdef MFEM_USE_MEMALLOC 00169 MemAlloc <Node, 1024> NodesMem; 00170 #endif 00171 00172 int Push_(int r, int c); 00173 int Index(int r, int c) const; 00174 00175 public: 00176 DSTable(int nrows); 00177 int NumberOfRows() const { return(NumRows); } 00178 int NumberOfEntries() const { return(NumEntries); } 00179 int Push(int a, int b) 00180 { return((a <= b) ? Push_(a, b) : Push_(b, a)); } 00181 int operator()(int a, int b) const 00182 { return((a <= b) ? Index(a, b) : Index(b, a)); } 00183 ~DSTable(); 00184 00185 class RowIterator 00186 { 00187 private: 00188 Node *n; 00189 public: 00190 RowIterator (const DSTable &t, int r) { n = t.Rows[r]; } 00191 int operator!() { return(n != NULL); } 00192 void operator++() { n = n->Prev; } 00193 int Column() { return(n->Column); } 00194 int Index() { return(n->Index); } 00195 }; 00196 }; 00197 00198 #endif