### get values from dolfin::Matrix

361
views
0
10 months ago by
Hi all,
I'm Valerio and I'm using FEniCS  fenics/2016.1.0 in C++. I need something that extracts the coefficients in a row of a dolfin::Matrix  and allocates them in a std::vector<double> or in a pointer to double. Is there a simple way to do it? something like:
A.get_row(my_vector, row)​
with A object of the class dolfin::Matrix, my_vector a pointer to double or a object of the class vector, and row an int value that identifies the row. I know that there is the function:
void get(double *block, std::size_t m, const dolfin::la_index *rows, std::size_t n, const dolfin::la_index *cols) const​
but i don't understand what it takes as input. Could you give me a practical example?
Community: FEniCS Project
Hello, does anybody have any Idea of how I can mutliply  u.split()[0]*u.split()[0]

Thanks very much,
written 10 months ago by N A

3
10 months ago by
There is even a method
virtual void getrow(std::size_t row, std::vector<std::size_t>& columns, std::vector<double>& values) const​

In order to find out what the arguments mean have look at some implementation of the method, e.g. in file PETScMatrix.cpp. You'll find out it calls
MatGetRow of petsc library. There row is the index of the row you are interested in, columns and values will be filled with columns indices and actual values in that row respectively.

Hi, I'm using getrow but I get an unexpected output. In fact a part of my code is:
Matrix AA;
Vector ff;
auto f = std::make_shared<Source>();
auto g = std::make_shared<dUdN>();
L.f = f;
L.g = g;
assemble_system(AA,ff,a,L,bc2);

cout<<"AA rows are "<<AA.size(0)<<endl;
cout<<"AA column are "<<AA.size(1)<<endl;
cout<<"test 1"<<endl;
std::vector<std::size_t> columns(AA.size(1));
std::vector<double> values(AA.size(1));
cout<<"the dimension of values before the function is "<< values.size()<<endl;
cout<<"test 2"<<endl;
AA.getrow(1, columns,values);
cout<<"test 3"<<endl;
cout<<"the dimension of values after the function is "<< values.size();
double new_number=values[8];
cout<<"new_number is"<<new_number;​

and the output is

AA rows are 1089
AA column are 1089
test 1
the dimension of values are before the function is 1089
test 2
test 3
​
as you can see there aren't these cout:
cout<<"the dimension of values after the function is "<< values.size();
cout<<"new_number is"<<new_number;​
written 10 months ago by Valerio
I'm testing, I changed a bit the code and now it seems works better, I don't know if the results are right, I need more time. Thank you for your help.
written 10 months ago by Valerio