2D vector. How can I properly assign values to the 2D vector?

I wrote a function GQ_3NT() which takes a 3x3 matrix array and modifies the array (called K_element). This runs fine.

The problem is when I want to put the values of the 3x3 matrix into a 427x427 matrix (the size of this matrix is different for every problem the program tries to solve)

My initial attempt was to use a 2D array (which is why K_element is an array as well), but it produced error message that said "K was unused"

I tried to "use" it in the elementToGlobal() function, and since I could not use 2D array of unspecified size, I changed K to a vector. The code compiles now, but when I run it, it just says "try.exe stopped working" and exits the program.

It works fine without the elementToGlobal() function, so I am 100% sure that is the problem. Can anybody be so kind and suggest what the problem is?


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43

int main()
{
    // A bunch of other stuff up here//
    .
    .
    .
    int coordSize = coord.size();
    double K_element[3][3];
    vector< vector<double> > K(coordSize, vector<double>(coordSize)); 
    double x1, x2, x3, y1, y2, y3;
    int nodei,nodej,nodek;

    //now, do the integral.
    for(int i=boundarySize;i<elementSize;i++){
        nodei = element[i].nodes[0]-1;
        nodej = element[i].nodes[1]-1;
        nodek = element[i].nodes[2]-1;
        x1 = coord[nodei].x;
        x2 = coord[nodej].x;
        x3 = coord[nodek].x;
        y1 = coord[nodei].y;
        y2 = coord[nodej].y;
        y3 = coord[nodek].y;
        GQ_3NT(x1,x2,x3,y1,y2,y3,K_element);
        elementToGlobal(K_element,K,nodei,nodej,nodek);
    }

    return 0;
}



void elementToGlobal(double K_element[3][3], vector< vector<double> > K, int nodei, int nodej, int nodek){
    int arr[3] = {nodei, nodej, nodek};
    for(int i=0;i<3;i++){
        for(int j=0;j<3;j++){
            K[arr[i]][arr[j]] = K_element[i][j];
        }
    }
}

Topic archived. No new replies allowed.