Help me identify algorithm

I am a novice programmer, and I am trying to implement a finite element solution. I think I am trying to solve a common algorithm, but I am not sure what it is called. I will try my best to describe it.

The problem:

We are given a steel cross section. The section is discretized into elements. Each element has two nodes, start of 'i' and end of 'j'.
This is the example I am working with:

https://imgur.com/gNCNICN



I am trying to describe the "Element Area" at each node, I'm calling this W[i]. W[i] stores the area at each node, from node 1 to n.

Each element has a variation of "Element Area", I'm calling it Delta_W[i].Delta_W[i] stores the variation for each element, from element 1 to n

We know Delta_W[i] (the variation) for each element. However, I don't know the W[i] at each particular node.


By definition the start node(i) of the first element has area of 0: W[0]=0;
Since the variation of W is known for the first element, the area at the end node j can be calculated: W[1] = W[0]+Delta_W[0];

Now, I want to try and calculate the "Element Area" at each node. However, some nodes depend on the values of previous end nodes of previous elements.

I was able to draw this logic flow diagram based on the example above:
https://imgur.com/vjgTUxz

Is there an algorithm I can study to help translate what I want into code?

Thank you.

By the way, this is what I originally had:

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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
void TorsionalProperties::Sectorial_Element_Variation() {

	//Establish variation in sectorial area
	for (int i = 0; i < Number_Elements; i++) {

		int Node_m = Ji[i] - 1; //Returns the first node of the element
		int Node_n = Jj[i] - 1; //Returns the second node of the element

			//Use node coordinates with respect to center of gravity.
		double Node_m_X = X[Node_m];
		double Node_n_X = X[Node_n];
		double Node_m_Y = Y[Node_m];
		double Node_n_Y = Y[Node_n];

		Delta_W[i] = Node_m_X * Node_n_Y - Node_m_Y * Node_n_X;

		//If xi to xj increases, then we are going CW (So positive Delta W)
		//If xi to xj decreases, then we are going CCW (So negative Delta W)
		//If yi to yj increases, then we are going CCW (So negative Delta W)
		//If yi to ji decreases, then we are going CW (So positive Delta W)

		if (Node_n_X > Node_m_Y)
			Delta_W[i] = abs(Delta_W[i]) * -1;
		else Delta_W[i] = abs(Delta_W[i]);

		if (Node_n_Y > Node_m_Y)
			Delta_W[i] = abs(Delta_W[i]) * -1;
		else Delta_W[i] = abs(Delta_W[i]);


	}

}


void TorsionalProperties::Sectorial_Node_Diagram(){

	for (int i = 0; i < Number_Elements; i++) {
			int Node_m = Ji[i] ; //Returns the first node of element i
			int Node_n = Jj[i] ; //Returns the second node value of element i

			if (i == 0) {
				W[i] = 0;
				W[i + 1] = W[i] + Delta_W[i];
			}

			for (int x = 0; x < Number_Elements; x++) {

				int Connecting_Next_Node = Ji[x] ; //Returns the second node value of element i

				if (Connecting_Next_Node == Node_n) {
					W[Node_n-1] = W[i+1];
					W[Node_n] = W[Node_n - 1] + Delta_W[x];
				}
			}
				
		}
}



Last edited on
> Is there an algorithm I can study to help translate what I want into code?
¿what do you want?
i don't understand your drawing

> By the way, this is what I originally had:
¿and what's the problem with that?
My drawing was basically trying to represent a flow chart map. You start at point (1) and then take road [1] to arrive at point (2) and so on.

I hope this makes sense.

I updated my code, and I was able to model this flowchart, however now I am running into a very weird run time error. For some reason, the compiler is assigning a huge negative number to one of my arrays after 80% execution.

The variable that "blows up" is Element_Index[] and I'm not sure why that happens. And, the error occurs the 4th iteration (so on loop 5 of 7).

EDIT:
The error is so random. I only assign integer value to Element_Index in one place simply as: Element_Index[Index] = i;.
I don't see how something can go wrong and assign a value of -3356956232 etc.

EDIT #2: I fixed it. I had initialized w[] incorrectly.
The new code:

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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
int TorsionalProperties::Next_Element(int Preceeding_Node, int Preceeding_Element) {

	int Num_Elements = 0;
	int Index = 0;

	cout << "Preceeding element and Node j (end node): " << Preceeding_Element << " , " << Preceeding_Node << endl;

	for (int y = 0; y < Number_Elements; y++) {
		Element_Index[y] = 0;
	}

	for (int i = 0; i < Number_Elements; i++) {
	
		int Node_m = Ji[i]; //Returns the first node of element i
		int Node_n = Jj[i]; //Returns the second node value of element i

		if (Node_m == Preceeding_Node) {
			cout << "Connecting Element and Node i: " << i << " , "<< Ji[i] << endl;
			Num_Elements++;
			Element_Index[Index] = i;
			Index++;
		}
	
	}

	return Num_Elements;
}


void TorsionalProperties::Sectorial_Node_Diagram(){
	
		//Element matrix must be in order of 1 to n 
		for (int i = 0; i < Number_Elements; i++) {

			cout << "Main Loop Counter , i : " << i << endl;
			int Node_m = Ji[i]; //Returns the first node of element i
			int Node_n = Jj[i]; //Returns the second node value of element i

			//Initializes the values of the first element node's
			if (i == 0) {
				W[Node_m - 1] = 0;
				W[Node_n - 1] =  Delta_W[i];
			}

			int counter = Next_Element(Node_n,i); //Returns the number of elements connecting to element i. 
												// Element index stored in Element_Index[]
												  
			//To update end element nodes								 
			if (counter == 0) {
				W[Node_n] = W[Node_m] + Delta_W[i];
				cout << "Updated Node value" << endl;

			}
				for (int x = 0; x < counter; x++) {
					cout << "x loop value: " << x << endl;
					int hold = Element_Index[x];
					cout << "Element_Index: " << Element_Index[x] << endl;
					int M = Ji[hold]; //Returns the first node of element i
					int N = Jj[hold]; //Returns the second node value of element i

						W[N] = W[M] + Delta_W[hold];
						cout << "Updated Node value" << endl;
				}
		

			
		}

}
Last edited on
Topic archived. No new replies allowed.