In my last question, Ilmari Karonen propose to me to solve the Laplace equation in discret mode. I'm using a grid and the four closest neighbours at each node to compute the unknown heights.
So the system to solve can be written with matrix :
A(matrix nxn) * U(vector n, unknowns) = b(vector n, settled)
last evening I looked around the web about linear algebra for C++. My choice is Armadillo. But for now "U" and "b" are std::map
:
std::map<std::pair<float,float>,float> b;
std::map<std::pair<float,float>,float> U;
.
.
.
if(g/*grid*/->getNode(r,c)->status == TO_COMPUTE){
U.insert(std::make_pair(std::make_pair(r,c),g->getNode(r,c)->y));
/*right*/ if(g->getNode(r+1,c)->status == SETTLED) b.at(std::make_pair(r,c)) += g >getNode(r+1,c)->y;
/*left */ if(g->getNode(r-1,c)->status == SETTLED) b.at(std::make_pair(r,c)) += g->getNode(r-1,c)->y;
/*down */ if(g->getNode(r,c+1)->status == SETTLED) b.at(std::make_pair(r,c)) += g->getNode(r,c+1)->y;
/*up */ if(g->getNode(r,c-1)->status == SETTLED) b.at(std::make_pair(r,c)) += g->getNode(r,c-1)->y;
}
and I think I will have then to get the size of "U" to create arma::vec
and to parse the whole map with an std::iterator
to transfer the values in my arma::vec
. So I would like to know how to grow a arma::vec
I'm looking for something like std::vector::push_back()
, then I will replace my std::map
. Also how can I get the size for a arma::vec
?
note1 : the picture shows the contours and the points where I will compute the values, the grid with unknow value is at y=0, when the lower contour is at y=-0.2 and the upper contour at y=0.8
note2 : when my little (LINUX) program will be ready I will release the code on my bitbucket as a very tiny example of use of discret Laplace operator
Update 26 Nov. 2013:
you can get the link to the code here