So i have 11 tubes and 8 nodes. The lenght is the distance from node 1 to node 2. Have a look at this picture for more information
8 //nodes
11 //tubes
0 0 -50 //node_x, node_y, flow
1000 0 -50 //node_x, node_y, flow
2000 0 0 //node_x, node_y, flow
0 500 0 //node_x, node_y, flow
500 500 0 //node_x, node_y, flow // NODES
0 1000 -50 //node_x, node_y, flow
1000 1000 0 //node_x, node_y, flow
2000 1000 150 //node_x, node_y, flow
1 2 0.5 //Node_1, Node_2, Diameter
2 3 0.5 //Node_1, Node_2, Diameter
1 4 0.5 //Node_1, Node_2, Diameter
4 5 0.5 //Node_1, Node_2, Diameter
2 5 0.5 //Node_1, Node_2, Diameter
2 8 0.5 //Node_1, Node_2, Diameter // TUBES
3 8 0.5 //Node_1, Node_2, Diameter
4 6 0.5 //Node_1, Node_2, Diameter
6 7 0.5 //Node_1, Node_2, Diameter
5 7 0.5 //Node_1, Node_2, Diameter
7 8 0.5 //Node_1, Node_2, Diameter
As seen the text file above we have 8 data for nodes with node x,y,flow values and 11 data for tubes with its node 1,2 id and diameter.
which means the first data of tube which is id 1 and id 2 = to 0 0 -50 and 1000 0 -50 so the length is 1000. As shown in picture we need the x value here so x is returned in the c++.
My code right now is hard coded which is like this:
for (int i = 0; i < 11; i++)
{
//1
if (node1_[i].id() == 0 && node2_[i].id() == 1)
{
return node2_->x();
}
//2
if (node1_[i].id() == 1 && node2_[i].id() == 2)
{
return node1_->x();
}
//3
if (node1_[i].id() == 0 && node2_[i].id() == 3)
{
return node2_->y();
}
//4
if (node1_[i].id() == 3 && node2_[i].id() == 4)
{
return node2_->x();
}
//5
if (node1_[i].id() == 1 && node2_[i].id() == 4)
{
return std::sqrt((node2_->x()) * (node2_->x()) + (node2_->y()) * (node2_->y()));
}
//6
if (node1_[i].id() == 1 && node2_[i].id() == 7)
{
return std::sqrt((node1_->x()) * (node1_->x()) + (node2_->y()) * (node2_->y()));
}
//7
if (node1_[i].id() == 2 && node2_[i].id() == 7)
{
return node2_->y();
}
//8
if (node1_[i].id() == 3 && node2_[i].id() == 5)
{
return node1_->y();
}
//9
if (node1_[i].id() == 5 && node2_[i].id() == 6)
{
return node2_->x();
}
//10
if (node1_[i].id() == 4 && node2_[i].id() == 6)
{
return std::sqrt((node1_->x()) * (node1_->y()) + (node1_->x()) * (node1_->y()));
}
//11
if (node1_[i].id() == 6 && node2_[i].id() == 7)
{
return node1_->x();
}
}
How can i remove the manually written ids and make it data driven so it knows which id to pick itself
length[0] = 1000
length[1] = 1000
length[2] = 500
length[3] = 500
length[4] = 707.107
length[5] = 1414.21
length[6] = 1000
length[7] = 500
length[8] = 1000
length[9] = 707.107
length[10] = 1000
these are values which i am getting which are correct. but i would like to change the way i am doing it. change the hard coded method to a data driven way.
Aucun commentaire:
Enregistrer un commentaire