dolfin team mailing list archive
-
dolfin team
-
Mailing list archive
-
Message #08349
Re: Matrix assignment
On Sun, Jun 22, 2008 at 10:46:48PM -0400, Hatef Monajemi wrote:
>
>
> On Sun, 2008-06-22 at 23:51 +0200, Anders Logg wrote:
> > On Sat, Jun 21, 2008 at 05:29:14AM -0400, Hatef Monajemi wrote:
> > >
> > > Hi
> > > Isn't this code supposed to work? It gives me "invalid lvalue in
> > > assignment" error while compiling. How should I assign the elements of
> > > a Matrix???
> > >
> > > //-------------------------------
> > > int main()
> > > {
> > >
> > >
> > > for(i=0; i<nens; i++)
> > > .
> > > .
> > > .
> > > real* values = new real[nstat];
> > > u1.interpolate(values);
> > >
> > > Matrix S(nstat,nens);
> > >
> > > for(int j=0;j<nstat;j++)
> > > {
> > > S(j,i)=values[j];
> > > }
> > >
> > > }
> >
> > Sorry, this doesn't work yet.
> >
> > We can easily fix this in the GenericMatrix interface by adding an
> > auxiliary class MatrixEntry (which just holds (i, j) and a reference
> > to the matrix) and have operator() return that, then overload
> > operator= in MatrixEntry to assign to the matrix.
> >
> > We had this in DOLFIN 2-3 years back but the linear algebra has gone
> > through several reimplementations since then...
> >
> > Until this has been implemented, you can use the setitem() function.
>
> Well, I am trying setitem() and as I can get from the GenericMatrix.h it
> should have a form like :
> -----------------------
> Matrix S(nstat, nens);
> S.zero();
> for(i=0; i<nens; i++)
> for(int j=0;j<nstat;j++)
> {
> S.setitem(ji, values[j]);
> }
You have not declared ji, try something like
std::pair<uint, uint> ij(i, j);
S.setitem(ij, values[j]);
--
Anders
> -------------------------
> But it is not working either. am I doing a stupid mistake using
> setitem() function? it gives me "ji was not declared in this scope".
> sorry for bothering you.
>
> > And please file a bug report for this. Mark it as "enhancement".
>
> I did it. I also have the same problem when using "Vector" class. I can
> not assign values to the vector. does it have the same bug?
>
> > __________________________
> > DOLFIN-dev mailing list
> > DOLFIN-dev@xxxxxxxxxx
> > http://www.fenics.org/mailman/listinfo/dolfin-dev
>
Attachment:
signature.asc
Description: Digital signature
References