Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
132 changes: 66 additions & 66 deletions K2Engineering/K2Engineering/Bar.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
using System;
using System;
using System.Collections.Generic;
using KangarooSolver;
using Grasshopper.Kernel;
using Rhino.Geometry;
using K2Engineering.Goals;

namespace K2Engineering
{
Expand Down Expand Up @@ -61,78 +62,13 @@ protected override void SolveInstance(IGH_DataAccess DA)
DA.SetData(0, barElement);
}


public class BarGoal : GoalObject
{
double restLenght;
bool isCompressionMember;
double area;

public BarGoal(Line L, double E, double A)
{
restLenght = L.From.DistanceTo(L.To);
isCompressionMember = true;
area = A;

PPos = new Point3d[2] { L.From, L.To };
Move = new Vector3d[2];
Weighting = new double[2] { (2 * E * A) / restLenght, (2 * E * A) / restLenght }; // Units: [N/m]
}

public override void Calculate(List<KangarooSolver.Particle> p)
{
Point3d ptStart = p[PIndex[0]].Position;
Point3d ptEnd = p[PIndex[1]].Position;

//Calculate force direction
Vector3d forceDir = new Vector3d(ptEnd - ptStart); //force direction pointing from start of line to end
double currentLength = forceDir.Length;
forceDir.Unitize();

//Calculate extension
double extension = currentLength - restLenght;

if (extension > 0.0)
{
isCompressionMember = false;
}
else if (extension < 0.0)
{
isCompressionMember = true;
}

//Set vector direction and magnitude
Move[0] = forceDir * (extension / 2); //has to point to exact point according to Hooke's Law. Divide by 2 as the bar is extended in both directions with the same amount
Move[1] = -forceDir * (extension / 2);
}

//Output geometry and force in bar. Force in [kN] and stress in [MPa]
public override object Output(List<KangarooSolver.Particle> p)
{
double factor = 1.0;
if (isCompressionMember)
{
factor = -1.0;
}

double force = factor * Weighting[0] * Move[0].Length; //Units: [N]

//Create bar data object to store output information
DataTypes.BarData barData = new DataTypes.BarData(new Line(p[PIndex[0]].Position, p[PIndex[1]].Position), force / 1000.0, force / area);
return barData;
}

}

/// <summary>
/// Provides an Icon for the component.
/// </summary>
protected override System.Drawing.Bitmap Icon
{
get
{
//You can add image files to your project resources and access them like this:
// return Resources.IconForThisComponent;
return Properties.Resources.Bar;
}
}
Expand All @@ -145,4 +81,68 @@ public override Guid ComponentGuid
get { return new Guid("{ccf6dc32-7c3c-4836-94c2-e43e1e3c4f0d}"); }
}
}
}

namespace K2Engineering.Goals
{
public class BarGoal : GoalObject
{
double restLenght;
bool isCompressionMember;
double area;

public BarGoal(Line L, double E, double A)
{
restLenght = L.From.DistanceTo(L.To);
isCompressionMember = true;
area = A;

PPos = new Point3d[2] { L.From, L.To };
Move = new Vector3d[2];
Weighting = new double[2] { (2 * E * A) / restLenght, (2 * E * A) / restLenght }; // Units: [N/m]
}
Comment on lines +88 to +103

public override void Calculate(List<KangarooSolver.Particle> p)
{
Point3d ptStart = p[PIndex[0]].Position;
Point3d ptEnd = p[PIndex[1]].Position;

//Calculate force direction
Vector3d forceDir = new Vector3d(ptEnd - ptStart); //force direction pointing from start of line to end
double currentLength = forceDir.Length;
forceDir.Unitize();

//Calculate extension
double extension = currentLength - restLenght;

if (extension > 0.0)
{
isCompressionMember = false;
}
else if (extension < 0.0)
{
isCompressionMember = true;
}

//Set vector direction and magnitude
Move[0] = forceDir * (extension / 2); //has to point to exact point according to Hooke's Law. Divide by 2 as the bar is extended in both directions with the same amount
Move[1] = -forceDir * (extension / 2);
}

//Output geometry and force in bar. Force in [kN] and stress in [MPa]
public override object Output(List<KangarooSolver.Particle> p)
{
double factor = 1.0;
if (isCompressionMember)
{
factor = -1.0;
}

double force = factor * Weighting[0] * Move[0].Length; //Units: [N]

//Create bar data object to store output information
DataTypes.BarData barData = new DataTypes.BarData(new Line(p[PIndex[0]].Position, p[PIndex[1]].Position), force / 1000.0, force / area);
return barData;
}
}
}
Loading