Create bar elements from node ID list
I want to automatically create bar elements from a list of node IDs.
set bar_list [open "Bar_List.csv"]
set node_ids [read -nonewline $bar_list]
close $bar_list
foreach line [split $node_ids "\n"] {
lassign [split $line {;}] name NodeA NodeB VectorID
*barelement $NodeA $NodeB $VectorID
}
This is my code for this part but when I run the script it says "Node A and node B are the same."
This is what my CSV File looks like:
Can anyone help with this?
Answers
-
Could you try this modified version?
set bar_list [open "Bar_List.csv"]
set node_ids [read -nonewline $bar_list]
close $bar_list#loop over, except line of index 0 (1 to the end)
foreach line [lrange [split $node_ids "\n"] 1 end] {
lassign [split $line {,}] NodeA NodeB VectorID
#puts "linha: $line"#create an internal vector entity for HyperMesh, not directly a vector.
set vector_orient [hm_getvalue vector id=$VectorID dataname=components]
eval "*createvector 1 $vector_orient"
#create the bar element using the internal vector
*barelement $NodeA $NodeB 1 0
#puts "$NodeA $NodeB $VectorID"
}My CSV file was:
NodeA,NodeB,VectorID
1,2,1
1,3,1
1,4,2
1,5,11 -
Hey Adriano,
thanks for your reply. It is now working that the bar elements are created but I still have a problem considering the vectors.
#loop over, except line of index 0 (1 to the end)
foreach line [lrange [split $node_ids "\n"] 1 end] {
lassign [split $line {;}] NodeA NodeB
#puts "linha: $line"#create an internal vector entity for HyperMesh, not directly a vector.
*createmark vectors 1 [*vectorcreate_twonode $NodeA $NodeB]#create the bar element using the internal vector
*barelement $NodeA $NodeB 1 0
#puts "$NodeA $NodeB $VectorID"
}I changed the creation of the vectors to be created individually for every bar element because I want the vectors to point along the bar element.
As you can see the vectors are pointing from the middle node to the respective outside node.
But when I try to simulate it I get this message:
So I guess the created vector is defined as the y-axis of the element but it should be the z-axis that points along the element.
Is there a way to define the created vector as the z-axis?
Or do I misunderstand the error notice?
0 -
HGH said:
Hey Adriano,
thanks for your reply. It is now working that the bar elements are created but I still have a problem considering the vectors.
#loop over, except line of index 0 (1 to the end)
foreach line [lrange [split $node_ids "\n"] 1 end] {
lassign [split $line {;}] NodeA NodeB
#puts "linha: $line"#create an internal vector entity for HyperMesh, not directly a vector.
*createmark vectors 1 [*vectorcreate_twonode $NodeA $NodeB]#create the bar element using the internal vector
*barelement $NodeA $NodeB 1 0
#puts "$NodeA $NodeB $VectorID"
}I changed the creation of the vectors to be created individually for every bar element because I want the vectors to point along the bar element.
As you can see the vectors are pointing from the middle node to the respective outside node.
But when I try to simulate it I get this message:
So I guess the created vector is defined as the y-axis of the element but it should be the z-axis that points along the element.
Is there a way to define the created vector as the z-axis?
Or do I misunderstand the error notice?
It is not allowed to have neither Y or Z local axis aligned with the bar element.
X-axis always points along the bar element direction. That's why you got this error, because you're defining orientation (V orientation vector, which defines the Y axis) parallel to your X direction.
Y and Z should always be perpendicular to X.
1 -
Thanks, that's helpful to know.
So do I have to create the needed y-vector from the vector resulting between the nodes or is there an easier way to just define it as the x-vector of the element?
0 -
Or asking differently:
How can I derive a perpendicular vector to the given vector along the bar axis?
0 -
HGH said:
Or asking differently:
How can I derive a perpendicular vector to the given vector along the bar axis?
What is your section? If it is a non-axisymmetric section, then you will need to accurately define your Y and Z vectors to have the right Inertia.
If it is a circular section, for example, where inertias will be the same in Y and Zm then you could just give some very unique vector, such as 10000,10000,10000 (except if you have a beam exactly oriented along 1,1,1 direction).
Of course this is valid in terms of stiffness. But if you intend to extract forces in specific directions you will need again to take care of your orientation.
Answering your question, to get a perpendicular vector, you would need to use cross (vector) product of 2 vectors, being one of them your beam x-axis vector. The resultant product will be orthogonal to the x-axis.
HM has some other commands that calculate automatically an orientation vector. This might be useful, in replacing your original *barelement command.
1 -
The section is circular so the orientation of Y and Z is not important.
But the script shall work for more complex (e.g. bend/circular) structures later on so I would like to make sure that the Y-axis gets correctly (perpendicular) orientated for every bar element.
My idea is to take the given bar axis and derive the perpendicular y-axis always in the same way for all elements so that the individual coordinate systems are aligned comparably.
To your last part:
Do you mean replacing the *barelement command with *linemesh commands?
0 -
HGH said:
The section is circular so the orientation of Y and Z is not important.
But the script shall work for more complex (e.g. bend/circular) structures later on so I would like to make sure that the Y-axis gets correctly (perpendicular) orientated for every bar element.
My idea is to take the given bar axis and derive the perpendicular y-axis always in the same way for all elements so that the individual coordinate systems are aligned comparably.
To your last part:
Do you mean replacing the *barelement command with *linemesh commands?
Y and Z directions are important even for a circular section if force needs to be computed separately (shear1, shear2).
For general sections you will need to provide the vector direction accordingly. As you're bringing the vector from your CSV, it should be already in the correct orientation from the beginning.
It might not be a direct replacement of the commands, but yes. the Line Mesh command calculates automatically perperdincular orientation, if I recall correctly, so it might be very helpful for your pruposes.
1 -
Hey Adriano,
First of all thanks for your help so far and happy new year.
Back to my problem:
I thought I had solved it, I implemented the calculation of a point that lies above the centre node so that a perpendicular vector between those two nodes can be created.
The coordinates of that point are also in the csv-file
foreach line [lrange [split $node_ids "\n"] 1 end] {
lassign [split $line {;}] NodeA NodeB P_Perp_X P_Perp_Y P_Perp_Z
#Create y-axis Vector from Perpendicular Node
*createnode $P_Perp_X $P_Perp_Y $P_Perp_Z
*createmark nodes 1 -1
set Perp_Node_ID [hm_getmark nodes 1]
*createmark vectors 1 [*vectorcreate_twonode $NodeA $Perp_Node_ID]
*barelement $NodeA $NodeB 1 0
}And when I tried that yesterday it worked:
Every bar had a perpendicular y-axis and after applying some forces and constraints it was possible to solve this model.
But when I ran the script again today it came out the following way:
All vectors are just straightly pointing in the global y-direction.
In the command files I only found the following difference in what was executed:
Correct vectors:
*createnode 2.59175171 2.59175171 3.81649658 0 0 0
*vectorcreate_twonode 28 36
*createvector 1 -0.40824829 -0.40824829 0.816496581
*barelement 28 1 1 0 0 0 0 ""...
Incorrect vectors:
*createnode 2.59175171 2.59175171 3.81649658 0 0 0
*vectorcreate_twonode 28 36
*createvector 1 0 0 0
*barelement 28 1 1 0 0 0 0 ""...
So the vector that is created is suddenly 0/0/0 although I didn't change the code and the correct nodes and vectors are created. But somehow that newly created vector isn't used.
Do you have an idea why it worked one day and the other it didn't anymore or am I overlooking something in my code?
0 -
HGH said:
Hey Adriano,
First of all thanks for your help so far and happy new year.
Back to my problem:
I thought I had solved it, I implemented the calculation of a point that lies above the centre node so that a perpendicular vector between those two nodes can be created.
The coordinates of that point are also in the csv-file
foreach line [lrange [split $node_ids "\n"] 1 end] {
lassign [split $line {;}] NodeA NodeB P_Perp_X P_Perp_Y P_Perp_Z
#Create y-axis Vector from Perpendicular Node
*createnode $P_Perp_X $P_Perp_Y $P_Perp_Z
*createmark nodes 1 -1
set Perp_Node_ID [hm_getmark nodes 1]
*createmark vectors 1 [*vectorcreate_twonode $NodeA $Perp_Node_ID]
*barelement $NodeA $NodeB 1 0
}And when I tried that yesterday it worked:
Every bar had a perpendicular y-axis and after applying some forces and constraints it was possible to solve this model.
But when I ran the script again today it came out the following way:
All vectors are just straightly pointing in the global y-direction.
In the command files I only found the following difference in what was executed:
Correct vectors:
*createnode 2.59175171 2.59175171 3.81649658 0 0 0
*vectorcreate_twonode 28 36
*createvector 1 -0.40824829 -0.40824829 0.816496581
*barelement 28 1 1 0 0 0 0 ""...
Incorrect vectors:
*createnode 2.59175171 2.59175171 3.81649658 0 0 0
*vectorcreate_twonode 28 36
*createvector 1 0 0 0
*barelement 28 1 1 0 0 0 0 ""...
So the vector that is created is suddenly 0/0/0 although I didn't change the code and the correct nodes and vectors are created. But somehow that newly created vector isn't used.
Do you have an idea why it worked one day and the other it didn't anymore or am I overlooking something in my code?
maybe you need to use 'eval' command for creating your vector.
eval "*createmark vectors 1 [*vectorcreate_twonode $NodeA $Perp_Node_ID]"
can you try it?
0 -
It didn't work, it still gave me vectors in the global y-direction.
0 -
HGH said:
It didn't work, it still gave me vectors in the global y-direction.
Are you sure this works?
*createmark nodes 1 -1
set Perp_Node_ID [hm_getmark nodes 1]
*createmark vectors 1 [*vectorcreate_twonode $NodeA $Perp_Node_ID]I couldn't find this command *vectorcreate_twonode
Also, have you tried the '1d mesh' commands? Did they work?
One thing you could try is to create a vector with a very specific orientation, that is unlikely to be aligned with any of your bars, such as 1,1,1 or 1,1,0.001
0 -
Adriano A. Koga_21884 said:
Are you sure this works?
*createmark nodes 1 -1
set Perp_Node_ID [hm_getmark nodes 1]
*createmark vectors 1 [*vectorcreate_twonode $NodeA $Perp_Node_ID]I couldn't find this command *vectorcreate_twonode
Also, have you tried the '1d mesh' commands? Did they work?
One thing you could try is to create a vector with a very specific orientation, that is unlikely to be aligned with any of your bars, such as 1,1,1 or 1,1,0.001
No I haven't tried the 1D mesh commands yet, that will be the next thing I do.
Deprecated Tcl Modify Commands (altair.com) I found it here but there it also says that the *createnode command is outdated yet it does work.
Also the correct nodes and vectors are actually created:
But somehow they are not used.
0 -
I found a way that apparently works:
#Create y-axis Vector from Perpendicular Node
*createnode $P_Perp_X $P_Perp_Y $P_Perp_Z
*createmark nodes 1 -1
set Perp_Node_ID [hm_getmark nodes 1]
# *createmark vectors 1 [*vectorcreate_twonode $NodeA $Perp_Node_ID]
*barelement $NodeA $NodeB 0 $Perp_Node_ID 1I took out the *vectorcreate part and gave the ID of the perpendicular node as the orientation node for the y-axis of the bar element.
That creates perpendicular coordinate systems for every bar element oriented like shown in the picture.
0 -
HGH said:
I found a way that apparently works:
#Create y-axis Vector from Perpendicular Node
*createnode $P_Perp_X $P_Perp_Y $P_Perp_Z
*createmark nodes 1 -1
set Perp_Node_ID [hm_getmark nodes 1]
# *createmark vectors 1 [*vectorcreate_twonode $NodeA $Perp_Node_ID]
*barelement $NodeA $NodeB 0 $Perp_Node_ID 1I took out the *vectorcreate part and gave the ID of the perpendicular node as the orientation node for the y-axis of the bar element.
That creates perpendicular coordinate systems for every bar element oriented like shown in the picture.
nice
0 -
Adriano A. Koga_21884 said:
nice
Thanks again for your input, that really helped me develop my solution.
0