31 const int nnz = table.
I[size];
34 memcpy(I, table.
I,
sizeof(
int)*(size+1));
35 memcpy(J, table.
J,
sizeof(
int)*nnz);
55 int i, j, sum = dim * connections_per_row;
62 for (i = 1; i <= size; i++)
64 I[i] = I[i-1] + connections_per_row;
65 for (j = I[i-1]; j < I[i]; j++) { J[j] = -1; }
76 for (
int i = 0; i < size; i++)
79 J[i] = partitioning[i];
88 for (
int i = 0; i <= nrows; i++)
98 for (k = i = 0; i < size; i++)
100 j = I[i], I[i] = k, k += j;
103 J =
new int[I[size]=k];
110 for (
int i = 0; i < nc; i++)
119 for (
int i = size; i > 0; i--)
128 SetDims (dim, dim * connections_per_row);
133 for (
int i = 0, j = 0; i < size; i++)
135 int end = I[i] + connections_per_row;
137 for ( ; j < end; j++) { J[j] = -1; }
146 j = (I) ? (I[size]) : (0);
150 if (I) {
delete [] I; }
151 I = (rows >= 0) ? (
new int[rows+1]) : (NULL);
156 if (J) {
delete [] J; }
157 J = (nnz > 0) ? (
new int[nnz]) : (NULL);
169 if ( i>=size || i<0 )
175 for (k = I[i]; k < end; k++)
191 MFEM_ASSERT(i >= 0 && i < size,
"Row index " << i <<
" is out of range [0,"
200 for (
int r = 0; r < size; r++)
202 std::sort(J + I[r], J + I[r+1]);
220 MFEM_ASSERT( i >=0 && i<size,
"Index out of bounds. i = "<<i);
222 for (
int k = I[i], end = I[i+1]; k < end; k++)
233 MFEM_ABORT(
"Reached end of loop unexpectedly: (i,j) = (" << i <<
", " << j
241 int i, j, end, sum = 0, n = 0, newI = 0;
243 for (i=0; i<I[size]; i++)
251 int *NewJ =
new int[sum];
253 for (i=0; i<size; i++)
256 for (j=I[i]; j<end; j++)
258 if (J[j] == -1) {
break; }
270 MFEM_ASSERT(sum == n,
"sum = " << sum <<
", n = " << n);
279 int nnz = list.
Size();
284 for (
int i = 0, k = 0; i <= size; i++)
287 while (k < nnz && list[k].from == i)
297 int width = -1, nnz = (size >= 0) ? I[size] : 0;
298 for (
int k = 0; k < nnz; k++)
300 if (J[k] > width) { width = J[k]; }
309 for (i = 0; i < size; i++)
311 out <<
"[row " << i <<
"]\n";
312 for (j = I[i]; j < I[i+1]; j++)
314 out << setw(5) << J[j];
315 if ( !((j+1-I[i]) % width) )
320 if ((j-I[i]) % width)
331 for (i = 0; i < size; i++)
332 for (j = I[i]; j < I[i+1]; j++)
334 out << i <<
" " << J[j] <<
" 1. \n";
344 for (
int i = 0; i <= size; i++)
348 for (
int i = 0, nnz = I[size]; i < nnz; i++)
361 for (
int i = 0; i <= size; i++)
367 for (
int j = 0; j < nnz; j++)
385 int * i_copy =
new int[size+1];
386 int * j_copy =
new int[I[size]];
388 memcpy(i_copy, I,
sizeof(
int)*(size+1));
389 memcpy(j_copy, J,
sizeof(
int)*I[size]);
391 copy.
SetIJ(i_copy, j_copy, size);
408 if (size < 0 || I == NULL) {
return 0; }
409 return (size+1 + I[size]) *
sizeof(int);
414 if (I) {
delete [] I; }
415 if (J) {
delete [] J; }
420 const int *i_A = A.
GetI();
421 const int *j_A = A.
GetJ();
422 const int nrows_A = A.
Size();
423 const int ncols_A = (_ncols_A < 0) ? A.
Width() : _ncols_A;
424 const int nnz_A = i_A[nrows_A];
428 int *i_At = At.
GetI();
429 int *j_At = At.
GetJ();
431 for (
int i = 0; i <= ncols_A; i++)
435 for (
int i = 0; i < nnz_A; i++)
439 for (
int i = 1; i < ncols_A; i++)
441 i_At[i+1] += i_At[i];
444 for (
int i = 0; i < nrows_A; i++)
445 for (
int j = i_A[i]; j < i_A[i+1]; j++)
447 j_At[i_At[j_A[j]]++] = i;
449 for (
int i = ncols_A; i > 0; i--)
465 At.
MakeI((_ncols_A < 0) ? (A.
Max() + 1) : _ncols_A);
466 for (
int i = 0; i < A.
Size(); i++)
471 for (
int i = 0; i < A.
Size(); i++)
481 const int *i_A = A.
GetI();
482 const int *j_A = A.
GetJ();
483 const int *i_B = B.
GetI();
484 const int *j_B = B.
GetJ();
485 const int nrows_A = A.
Size();
486 const int nrows_B = B.
Size();
487 const int ncols_A = A.
Width();
488 const int ncols_B = B.
Width();
490 MFEM_VERIFY( ncols_A <= nrows_B,
"Table size mismatch: ncols_A = " << ncols_A
491 <<
", nrows_B = " << nrows_B);
495 for (i = 0; i < ncols_B; i++)
501 for (i = 0; i < nrows_A; i++)
503 for (j = i_A[i]; j < i_A[i+1]; j++)
506 for (l = i_B[k]; l < i_B[k+1]; l++)
509 if (B_marker[m] != i)
520 for (i = 0; i < ncols_B; i++)
528 for (i = 0; i < nrows_A; i++)
531 for (j = i_A[i]; j < i_A[i+1]; j++)
534 for (l = i_B[k]; l < i_B[k+1]; l++)
537 if (B_marker[m] != i)
557 Table(dim, connections_per_row)
587 Rows =
new Node*[nrows];
588 for (
int i = 0; i < nrows; i++)
596 int DSTable::Push_(
int r,
int c)
598 MFEM_ASSERT(r >= 0 && r < NumRows,
599 "Row out of bounds: r = " << r <<
", NumRows = " << NumRows);
601 for (n = Rows[r]; n != NULL; n = n->Prev)
608 #ifdef MFEM_USE_MEMALLOC
609 n = NodesMem.
Alloc ();
614 n->Index = NumEntries;
617 return (NumEntries++);
620 int DSTable::Index(
int r,
int c)
const
622 MFEM_ASSERT( r>=0,
"Row index must be non-negative, not "<<r);
627 for (Node *n = Rows[r]; n != NULL; n = n->Prev)
639 #ifdef MFEM_USE_MEMALLOC
642 for (
int i = 0; i < NumRows; i++)
644 Node *na, *nb = Rows[i];
int Size() const
Logical size of the array.
void SetSize(int dim, int connections_per_row)
Set the size and the number of connections for the table.
int operator()(int i, int j) const
void MakeI(int nrows)
Next 7 methods are used together with the default constructor.
void SortRows()
Sort the column (TYPE II) indices in each row.
void Mult(const Table &A, const Table &B, Table &C)
C = A * B (as boolean matrices)
void SetDims(int rows, int nnz)
void GetRow(int i, Array< int > &row) const
Return row i in array row (the Table must be finalized)
void Save(std::ostream &out) const
void AddConnections(int r, const int *c, int nc)
int Width() const
Returns the number of TYPE II elements (after Finalize() is called).
int operator()(int i, int j) const
void Print(std::ostream &out=mfem::out, int width=4) const
Prints the table to stream out.
void MakeFromList(int nrows, const Array< Connection > &list)
Table & operator=(const Table &rhs)
Assignment operator: deep copy.
void AddConnection(int r, int c)
T Max() const
Find the maximal element in the array, using the comparison operator < for class T.
void Transpose(const Table &A, Table &At, int _ncols_A)
Transpose a Table.
void Assign(const T *)
Copy data from a pointer. Size() elements are copied.
int Size() const
Returns the number of TYPE I elements.
void PrintMatlab(std::ostream &out) const
STable(int dim, int connections_per_row=3)
Creates table with fixed number of connections.
void Swap(Array< T > &, Array< T > &)
int size
size is the number of TYPE I elements.
void AddAColumnInRow(int r)
void SetSize(int nsize)
Change logical size of the array, keep existing entries.
void Load(std::istream &in)
void SetIJ(int *newI, int *newJ, int newsize=-1)
OutStream out(std::cout)
Global stream used by the library for standard output. Initially it uses the same std::streambuf as s...
void Copy(Table ©) const
Table()
Creates an empty table.