From: edgar <edg...@cr...> - 2021-08-11 00:34:08
|
Hello! I am trying to do something like this (systems of equations, example 6): DenseSubMatrix<Number> Ke_var[3][3] = { {DenseSubMatrix<Number>(Ke), DenseSubMatrix<Number>(Ke), DenseSubMatrix<Number>(Ke)}, {DenseSubMatrix<Number>(Ke), DenseSubMatrix<Number>(Ke), DenseSubMatrix<Number>(Ke)}, {DenseSubMatrix<Number>(Ke), DenseSubMatrix<Number>(Ke), DenseSubMatrix<Number>(Ke)} }; Except that I would like to do it like this (does not work): const unsigned int mesh_dim = mesh.mesh_dimension (); DenseSubMatrix<Number> Ke_var[mesh_dim][mesh_dim]; for (unsigned int i=0; i<mesh_dim; i++) for (unsigned int j=0; j<mesh_dim; i++) Ke_var[i][j] = DenseSubMatrix<Number>(Ke); - One of the reasons for which this does not work is that there is no empty constructor defined for =DenseSubMatrix<T>=. In other words, the second line in the above code requires parametrized initialization. - I considered using double pointers (**) and =new= (dynamic allocation), but that would be a bomb for memory. - Since =mesh_dim= is =const=, I think that even the ISO C++ would be fine with =Ke_var[mesh_dim][mesh_dim]=. - I also thought of playing with =new_m= and =new_n= from the definition of the constructor (something like =DenseSubMatrix<Number> Ke_var (Ke, 0, 0, mesh_dim, mesh_dim)=), but I don't know how I would do that. The point is to be able to generate the matrix with specific dimensions. Can you help me, please? Thanks! |