Comments (3)
Hi @Rookiefrog ,
I don't know if you have solved your problem or not. But at least, I tried modifying my old code to your problem and it works fine.
class BridgeTruss_b():
def __init__(self, p, w_tri = 4, h_tri=2, num_tri=6) -> None:
"""
Calculate displacement of middle point in bridge truss
Args:
p (list): list of force applied on the top nodes (N)
num_tri (int): number of triangles
disp (bool): display image or not
"""
self.structure = SystemElements()
# Triangle coord
self.x_base = np.arange(0,num_tri+1) * w_tri
self.x_top = np.arange(0,num_tri) * w_tri + h_tri
self.y = np.ones(num_tri) * h_tri
# Create num_tri triangles
for i in range(num_tri):
p1 = [self.x_base[i],0]
p2 = [self.x_top[i], self.y[i]]
p3 = [self.x_base[i+1],0]
self.structure.add_element(location=[p1, p2])
self.structure.add_element(location=[p2, p3])
self.structure.add_element(location=[p1, p3])
# Create 5 horizontal trusses
for i in range(num_tri-1):
self.structure.add_element(location=[[self.x_top[i],self.y[i]], [self.x_top[i+1],self.y[i+1]]])
# Create support
self.structure.add_support_fixed(node_id=1) # Pin support
self.structure.add_support_fixed(node_id= 2*num_tri+1) # Roller support
# Create Load
loadnode = [4]
for index, point in enumerate(loadnode):
self.structure.point_load(node_id=point,Fy=p)
def solve(self, disp=True):
"""solving the truss system
Args:
disp (bool, optional): Add option to display the whole results or not. Defaults to True.
"""
# Solve the truss system
self.structure.solve()
if disp is True:
self.structure.show_axial_force()
self.structure.show_displacement(factor=1)
if __name__ == "__main__":
aa = BridgeTruss_b(-1000, num_tri=3)
aa.solve()
ps: sorry for the dirty code and some hard-coded variables 😬
from anastruct.
@Rookiefrog : I'll add some error handling here, as that's an awful error message you received, but the reason is because the node_id
on this line of your script isn't resolving to an int
data type (and note that mathematically, it's equal to 6, but just about as soon as you have a division sign in Python, it converts your number to a float
- which is not a valid array index 🙄 ):
ss.point_load(node_id=num_triangles+1+(num_triangles+1)/2, Fx=10, rotation=90)
If I run this in a Python console, you can see what I mean:
$ python3
>>> num_triangles=3
>>> num_triangles+1+(num_triangles+1)
8
>>> num_triangles+1+(num_triangles+1)/2
6.0
>>> int(num_triangles+1+(num_triangles+1)/2)
6
What you want here is to wrap your equation for the node_id
in an int()
casting:
ss.point_load(node_id=int(num_triangles+1+(num_triangles+1)/2), Fx=10, rotation=90)
from anastruct.
@Rookiefrog : And I'd add that, if you update to the new version v1.4.3 of anaStruct, even your original script should now work. I added some checking for if a non-integer float can be non-destructively cast to an integer (as in your case), where it will now just automatically do the integer casting.
It'll also throw a meaningful error message if you try to pass it a node or element id that can't be converted to an integer (e.g. node_id=6.5
will throw an error actually telling you what's wrong now 🙂 ).
from anastruct.
Related Issues (20)
- Overhanging members fail constitutive matrix
- Overlaying displacement plots HOT 1
- find_node_id function error HOT 2
- Point loads on elements
- Partial distributed q_load on elements
- Elastic ground
- Model support in between element length HOT 1
- Clean up meaning of "y" vs "z" coordinates HOT 1
- Create a `toVertex()` function, use throughout
- problem with plotting the results HOT 2
- Bearings with clearance
- The last link in the README Page is dead
- Pinned supports issue HOT 2
- Shear Force Diagrams sign conventions reversed. HOT 2
- plot displacements in mm instead of m
- Error
- unexpected keyword argument 'plot_backend'
- title and labels not in figure
- EZstruct
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from anastruct.