Multi coupling point masses
Example of generating complex coupling between many nodes. In this example, many nodes are constructed in parallel using name generators (#n3, #n22). Using the same generator syntax, edges can be quickly created between many nodes, in this case bidirectional coupling (spring) between the left and right nodes (#n33).
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 |
g = 9.81 node "n{1:5}{r,l}" { m = 1.5 # Generator syntax also applies to variable names "{x,y}" = "rand(-5, 5)" x'' = 0 # External force implementing damping (due to friction) Dy = 0.5 Fy = "-Dy * dy" # Acceleration due to gravity plus external force y'' = "-g + Fy / m" } # We can open up existing nodes and modify them. Here # we will add a simple fixed spring to the first node on # both left and right sides node "n1{r,l}" { Ky = 10 # Set external force to damping plus a spring force # pulling back the point mass to 0 Fy = "-Dy * dy + Ky * -y" } # This generates full coupling between the left and right # nodes <bidirectional> edge from "n{1:5}r" to "n{1:5}l" { Kx = "5" Ky = "20" dx' += "Kx * (input.x - output.x) / output.m" dy' += "Ky * (input.y - output.y) / output.m" } |