← Back to team overview

dolfin team mailing list archive

Re: Fwd: Re: Identity matrix

 

No, that won't work. What the set() function does is

for i < num_rows:
  for j < num_cols:
    A[rows[i], cols[j]] = vals[i*num_rows + j]

So, the length for vals needs to be num_rows*num_cols.

To create an identity matrix, it should be enough to do

Matrix A(N, N);
unsigned int rows[N];
for (unsigned int i = 0; i < N; i++)
    rows[i] = i;
A.ident(rows, N);
A.apply();

By the way, it looks like we need to change the order of arguments in the ident function. The size argument should come before the array argument (same as in PETSc and many other libraries). We have changed this for add(), set(), get() but forgot to fix it for ident(). So watch out for the change of order in parameters...

/Anders


Mads Hoel wrote:
I think so, but maybe the experts should answer. :P

Regards,
Mads Hoel

------- Forwarded message -------
From: jesperc <jesperc@xxxxxx>
To: "Mads Hoel" <mfhoel@xxxxxxxxxx>
Cc:
Subject: Re: [DOLFIN-dev] Identity matrix
Date: Wed, 18 Jul 2007 16:29:43 +0200

Hi,

Yes, I see that this has changed in the new version but I still use the
old one.
However, I see now that the number of columns and rows can be different
which indicates that set() may work in another way than I thought.
Doesn't val={1,2}, col={3,4}, row={5,6} mean that element (5,3) is 1 and
element (6,4) is 2?

Regards, Jesper

Mads Hoel skrev:
On Wed, 18 Jul 2007 15:56:48 +0200, jesperc <jesperc@xxxxxx> wrote:

A->set(vals, cols, n, rows, n);
void set (const real *block, uint m, const uint *rows, uint n, const uint *cols)
     Set block of values.

I think you need to rearrange the parameters

A->set(vals, cols, n, rows, n); to A->set(vals, n, rows, n, cols);

Regards,
Mads Hoel
_______________________________________________
DOLFIN-dev mailing list
DOLFIN-dev@xxxxxxxxxx
http://www.fenics.org/mailman/listinfo/dolfin-dev



Follow ups

References