public void TestCreateGsaNodeRestrained() { // create new Bool6 GsaBool6 bool6 = new GsaBool6 { X = true, Y = false, Z = true, XX = false, YY = true, ZZ = false }; // create new node from point with bool6 restraint GsaNode node = new GsaNode(new Point3d(5.3, 9.9, 2017), bool6); Assert.AreEqual(5.3, node.Point.X); Assert.AreEqual(9.9, node.Point.Y); Assert.AreEqual(2017, node.Point.Z); Assert.IsTrue(node.Node.Restraint.X); Assert.IsFalse(node.Node.Restraint.Y); Assert.IsTrue(node.Node.Restraint.Z); Assert.IsFalse(node.Node.Restraint.XX); Assert.IsTrue(node.Node.Restraint.YY); Assert.IsFalse(node.Node.Restraint.ZZ); }
public static string ToNative(this Structural0DSpring spring) { if (string.IsNullOrEmpty(spring.ApplicationId) || spring.Value == null || string.IsNullOrEmpty(spring.PropertyRef)) { return(""); } return(Helper.ToNativeTryCatch(spring, () => { var propIndex = Initialiser.AppResources.Cache.LookupIndex(GsaRecord.GetKeyword <GsaPropSpr>(), spring.PropertyRef); if (propIndex == null) { //TO DO : add error message return ""; } var keyword = GsaRecord.GetKeyword <GsaNode>(); var streamId = Initialiser.AppResources.Cache.LookupStream(spring.ApplicationId); var index = Initialiser.AppResources.Proxy.NodeAt(spring.Value[0], spring.Value[1], spring.Value[2], Initialiser.AppResources.Settings.CoincidentNodeAllowance); var existingGwa = Initialiser.AppResources.Cache.GetGwa(keyword, index); GsaNode gsaNode; if (existingGwa == null || existingGwa.Count() == 0 || string.IsNullOrEmpty(existingGwa.First())) { gsaNode = new GsaNode() { Index = index, ApplicationId = spring.ApplicationId, Name = spring.Name, StreamId = streamId, X = spring.Value[0], Y = spring.Value[1], Z = spring.Value[2], SpringPropertyIndex = propIndex }; } else { gsaNode = new GsaNode(); if (!gsaNode.FromGwa(existingGwa.First())) { //TO DO: add error mesage return ""; } gsaNode.SpringPropertyIndex = propIndex; } //Yes, the Axis member of the Speckle StructuralSpringProperty object is not used if (gsaNode.Gwa(out var gwaLines, false)) { Initialiser.AppResources.Cache.Upsert(keyword, gsaNode.Index.Value, gwaLines.First(), streamId, gsaNode.ApplicationId, GsaRecord.GetGwaSetCommandType <GsaNode>()); } return ""; }
public static Node Read(GsaNode gsaNode) { Node bhomNode = new Node { Name = gsaNode.Name, Point = new BHoM.Geometry.Point(gsaNode.Coor[0], gsaNode.Coor[1], gsaNode.Coor[2]), Constraint = ReadNodeConstraint("", gsaNode.Restraint, gsaNode.Stiffness) }; bhomNode.CustomData[CustomKey] = gsaNode.Ref; return(bhomNode); }
public void TestDuplicateNode() { // create new node with some properties GsaNode node = new GsaNode(new Point3d(-3.3, 0, 1.5)); node.Colour = System.Drawing.Color.Red; node.LocalAxis = Plane.WorldYZ; node.ID = 3; node.Node.Name = "Mariam"; // duplicate node GsaNode duplicate = node.Duplicate(); // check that original and duplicate are the same Assert.AreEqual(node.Node.Position.X, duplicate.Node.Position.X); Assert.AreEqual(node.Node.Position.Y, duplicate.Node.Position.Y); Assert.AreEqual(node.Node.Position.Z, duplicate.Node.Position.Z); Assert.AreEqual(duplicate.LocalAxis.OriginX, node.LocalAxis.OriginX); Assert.AreEqual(duplicate.LocalAxis.OriginY, node.LocalAxis.OriginY); Assert.AreEqual(duplicate.LocalAxis.OriginZ, node.LocalAxis.OriginZ); Assert.AreEqual(duplicate.LocalAxis.Normal.X, node.LocalAxis.Normal.X); Assert.AreEqual(duplicate.LocalAxis.Normal.Y, node.LocalAxis.Normal.Y); Assert.AreEqual(duplicate.LocalAxis.Normal.Z, node.LocalAxis.Normal.Z); Assert.AreEqual(node.ID, duplicate.ID); Assert.AreEqual(node.Colour, duplicate.Colour); Assert.AreEqual(node.Node.Name, duplicate.Node.Name); // make changes to original node node.Point = new Point3d(3.3, 1, -1.5); node.LocalAxis = Plane.Unset; node.Colour = System.Drawing.Color.Blue; node.ID = 2; node.Node.Name = "Kristjan"; // check that original and duplicate are not the same Assert.AreNotEqual(node.Node.Position.X, duplicate.Node.Position.X); Assert.AreNotEqual(node.Node.Position.Y, duplicate.Node.Position.Y); Assert.AreNotEqual(node.Node.Position.Z, duplicate.Node.Position.Z); Assert.AreNotEqual(duplicate.LocalAxis.OriginX, node.LocalAxis.OriginX); Assert.AreNotEqual(duplicate.LocalAxis.OriginY, node.LocalAxis.OriginY); Assert.AreNotEqual(duplicate.LocalAxis.OriginZ, node.LocalAxis.OriginZ); Assert.AreNotEqual(duplicate.LocalAxis.Normal.X, node.LocalAxis.Normal.X); Assert.AreNotEqual(duplicate.LocalAxis.Normal.Y, node.LocalAxis.Normal.Y); Assert.AreNotEqual(duplicate.LocalAxis.Normal.Z, node.LocalAxis.Normal.Z); Assert.AreNotEqual(node.ID, duplicate.ID); Assert.AreNotEqual(node.Colour, duplicate.Colour); Assert.AreNotEqual(node.Node.Name, duplicate.Node.Name); }
public void TestCreateGsaNodeFromPt() { GsaNode node = new GsaNode(new Point3d(10, 15, 7.8)); Assert.AreEqual(10, node.Point.X); Assert.AreEqual(15, node.Point.Y); Assert.AreEqual(7.8, node.Point.Z); // node should maintain syncronisation of Point and Node.Position: Assert.AreEqual(10, node.Node.Position.X); Assert.AreEqual(15, node.Node.Position.Y); Assert.AreEqual(7.8, node.Node.Position.Z); }
//create a node public bool CreateNode(Point3d position, int restraint, out GsaNode node) { node = new GsaNode(); long nodeRef = gsaObject.Gen_NodeAt(position.X, position.Y, position.Z, tolerance); double[] pos = { (double)position.X, (double)position.Y, (double)position.Z }; double[] stiff = { 0, 0, 0, 0, 0, 0 }; node.Coor = pos; node.Stiffness = stiff; node.Restraint = restraint; node.Ref = (int)nodeRef; return(true); }
protected override void SolveInstance(IGH_DataAccess DA) { GH_Point ghpt = new GH_Point(); if (DA.GetData(0, ref ghpt)) { Point3d pt = new Point3d(); if (GH_Convert.ToPoint3d(ghpt, ref pt, GH_Conversion.Both)) { GH_Plane gH_Plane = new GH_Plane(); Plane localAxis = Plane.WorldXY; if (DA.GetData(1, ref gH_Plane)) { GH_Convert.ToPlane(gH_Plane, ref localAxis, GH_Conversion.Both); } GsaNode node = new GsaNode(pt); GsaBool6 bool6 = new GsaBool6(); if (DA.GetData(2, ref bool6)) { x = bool6.X; y = bool6.Y; z = bool6.Z; xx = bool6.XX; yy = bool6.YY; zz = bool6.ZZ; } GsaSpring spring = new GsaSpring(); if (DA.GetData(3, ref spring)) { node.Spring = spring; } node.LocalAxis = localAxis; node.Node.Restraint.X = x; node.Node.Restraint.Y = y; node.Node.Restraint.Z = z; node.Node.Restraint.XX = xx; node.Node.Restraint.YY = yy; node.Node.Restraint.ZZ = zz; DA.SetData(0, new GsaNodeGoo(node.Duplicate())); } } }
private static StructuralVectorBoolSix GetRestraint(GsaNode gsaNode) { if (gsaNode.NodeRestraint == NodeRestraint.Custom && gsaNode.Restraints != null && gsaNode.Restraints.Count() > 0) { return Helper.AxisDirDictToStructuralVectorBoolSix(gsaNode.Restraints); } else if (gsaNode.NodeRestraint == NodeRestraint.Fix) { return new StructuralVectorBoolSix(Enumerable.Repeat(true, 6)); } else if (gsaNode.NodeRestraint == NodeRestraint.Pin) { return new StructuralVectorBoolSix(Enumerable.Repeat(true, 3).Concat(Enumerable.Repeat(false, 3))); } return null; }
public static void ConvertNode(List <GsaNode> nodes, ref Dictionary <int, Node> existingNodes, ref Dictionary <int, Axis> existingAxes, GrasshopperAsyncComponent.WorkerInstance workerInstance = null, Action <string, double> ReportProgress = null) { int nodeidcounter = (existingNodes.Count > 0) ? existingNodes.Keys.Max() + 1 : 1; // Add/Set Nodes if (nodes != null) { if (nodes.Count > 0) { // update counter if new nodes have set ID higher than existing max int existingNodeMaxID = nodes.Max(x => x.ID); // max ID in new nodes if (existingNodeMaxID > nodeidcounter) { nodeidcounter = existingNodeMaxID + 1; } for (int i = 0; i < nodes.Count; i++) { // if method is called by a Async component check for cancellation and report progress if (workerInstance != null) { if (workerInstance.CancellationToken.IsCancellationRequested) { return; } ReportProgress("Nodes ", (double)i / (nodes.Count - 1)); } if (nodes[i] != null) { GsaNode node = nodes[i]; // Add / Set node in dictionary ConvertNode(node, ref existingNodes, ref existingAxes, ref nodeidcounter); } } } } if (workerInstance != null) { ReportProgress("Nodes assembled", -2); } }
public void TestCreateGsaNodeIdRestrainLocAxis() { // create new Bool6 GsaBool6 bool6 = new GsaBool6 { X = false, Y = true, Z = false, XX = true, YY = false, ZZ = true }; // create new rhino plane for local axis Plane pln = Plane.WorldZX; // set ID int id = 44; // create new node from point with id, bool6 restraint and plane local axis: GsaNode node = new GsaNode(new Point3d(-40, -3.654, -99), id, bool6, pln); Assert.AreEqual(-40, node.Point.X); Assert.AreEqual(-3.654, node.Point.Y); Assert.AreEqual(-99, node.Point.Z); Assert.AreEqual(44, node.ID); Assert.IsFalse(node.Node.Restraint.X); Assert.IsTrue(node.Node.Restraint.Y); Assert.IsFalse(node.Node.Restraint.Z); Assert.IsTrue(node.Node.Restraint.XX); Assert.IsFalse(node.Node.Restraint.YY); Assert.IsTrue(node.Node.Restraint.ZZ); // the local plane origin point should be moved to the node position Assert.AreEqual(-40, node.LocalAxis.OriginX); Assert.AreEqual(-3.654, node.LocalAxis.OriginY); Assert.AreEqual(-99, node.LocalAxis.OriginZ); Assert.AreEqual(0, node.LocalAxis.Normal.X); Assert.AreEqual(1, node.LocalAxis.Normal.Y); Assert.AreEqual(0, node.LocalAxis.Normal.Z); }
/// <summary> /// Method to import Nodes from a GSA model. /// Will output a list of GhSA GsaNodes. /// Filter nodes to import using nodeList input; /// "all" or empty string ("") will import all nodes /// </summary> /// <param name="model"></param> /// <param name="nodeList"></param> /// <returns></returns> public static List <GsaNode> GsaGetPoint(Model model, string nodeList) { // Create empty Gsa Node to work on: //Node node = new Node(); //GsaNode n = new GsaNode(); List <GsaNode> nodes = new List <GsaNode>(); // Create dictionary to read list of nodes: IReadOnlyDictionary <int, Node> nDict; nDict = model.Nodes(nodeList); // Loop through all nodes in Node dictionary and add points to Rhino point list for (int i = 0; i < nDict.Keys.Max(); i++) { if (nDict.TryGetValue(i + 1, out Node apinode)) //1-base numbering { var p = apinode.Position; GsaNode n = new GsaNode(new Point3d(p.X, p.Y, p.Z), i + 1) { Node = apinode }; if (apinode.SpringProperty > 0) { // to be implement. GsaAPI spring missing. // get spring property from model } nodes.Add(n.Duplicate()); } else { nodes.Add(null); } } //n.node.Dispose(); //node.Dispose(); return(nodes); }
protected override void SolveInstance(IGH_DataAccess DA) { GH_Brep ghbrep = new GH_Brep(); if (DA.GetData(0, ref ghbrep)) { if (ghbrep == null) { AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Brep input is null"); } Brep brep = new Brep(); if (GH_Convert.ToBrep(ghbrep, ref brep, GH_Conversion.Both)) { // 1 Points List <GH_ObjectWrapper> gh_types = new List <GH_ObjectWrapper>(); List <Point3d> pts = new List <Point3d>(); List <GsaNode> nodes = new List <GsaNode>(); if (DA.GetDataList(1, gh_types)) { for (int i = 0; i < gh_types.Count; i++) { Point3d pt = new Point3d(); if (gh_types[i].Value is GsaNodeGoo) { GsaNode gsanode = new GsaNode(); gh_types[i].CastTo(ref gsanode); nodes.Add(gsanode); } else if (GH_Convert.ToPoint3d(gh_types[i].Value, ref pt, GH_Conversion.Both)) { pts.Add(pt); } else { string type = gh_types[i].Value.GetType().ToString(); type = type.Replace("GhSA.Parameters.", ""); type = type.Replace("Goo", ""); AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Unable to convert incl. Point/Node input parameter of type " + type + " to point or node"); } } } // 2 Curves gh_types = new List <GH_ObjectWrapper>(); List <Curve> crvs = new List <Curve>(); List <GsaMember1d> mem1ds = new List <GsaMember1d>(); if (DA.GetDataList(2, gh_types)) { for (int i = 0; i < gh_types.Count; i++) { Curve crv = null; if (gh_types[i].Value is GsaMember1dGoo) { GsaMember1d gsamem1d = new GsaMember1d(); gh_types[i].CastTo(ref gsamem1d); mem1ds.Add(gsamem1d); } else if (GH_Convert.ToCurve(gh_types[i].Value, ref crv, GH_Conversion.Both)) { crvs.Add(crv); } else { string type = gh_types[i].Value.GetType().ToString(); type = type.Replace("GhSA.Parameters.", ""); type = type.Replace("Goo", ""); AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Unable to convert incl. Curve/Mem1D input parameter of type " + type + " to curve or 1D Member"); } } } // 4 mesh size GH_Number ghmsz = new GH_Number(); double meshSize = 0; if (DA.GetData(4, ref ghmsz)) { GH_Convert.ToDouble(ghmsz, out double m_size, GH_Conversion.Both); meshSize = m_size; } // build new element2d with brep, crv and pts GsaElement2d elem2d = new GsaElement2d(brep, crvs, pts, meshSize, mem1ds, nodes); // 3 section GH_ObjectWrapper gh_typ = new GH_ObjectWrapper(); GsaProp2d prop2d = new GsaProp2d(); if (DA.GetData(3, ref gh_typ)) { if (gh_typ.Value is GsaProp2dGoo) { gh_typ.CastTo(ref prop2d); } else { if (GH_Convert.ToInt32(gh_typ.Value, out int idd, GH_Conversion.Both)) { prop2d.ID = idd; } else { AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Unable to convert PA input to a 2D Property of reference integer"); return; } } } else { prop2d.ID = 1; } List <GsaProp2d> prop2Ds = new List <GsaProp2d>(); for (int i = 0; i < elem2d.Elements.Count; i++) { prop2Ds.Add(prop2d); } elem2d.Properties = prop2Ds; DA.SetData(0, new GsaElement2dGoo(elem2d)); }
public static string ToNative(this StructuralNode node) { if (string.IsNullOrEmpty(node.ApplicationId) || node.Value == null || node.Value.Count < 3) { return(""); } return(Helper.ToNativeTryCatch(node, () => { var keyword = GsaRecord.GetKeyword <GsaNode>(); var massKeyword = GsaRecord.GetKeyword <GsaPropMass>(); var index = Initialiser.AppResources.Proxy.NodeAt(node.Value[0], node.Value[1], node.Value[2], Initialiser.AppResources.Settings.CoincidentNodeAllowance); var streamId = Initialiser.AppResources.Cache.LookupStream(node.ApplicationId); var existingGwa = Initialiser.AppResources.Cache.GetGwa(keyword, index); GsaNode gsaNode; if (existingGwa == null || existingGwa.Count() == 0 || string.IsNullOrEmpty(existingGwa.First())) { gsaNode = new GsaNode() { Index = index, ApplicationId = node.ApplicationId, Name = node.Name, StreamId = streamId, X = node.Value[0], Y = node.Value[1], Z = node.Value[2], }; } else { gsaNode = new GsaNode(); if (!gsaNode.FromGwa(existingGwa.First())) { //TO DO: add error mesage return ""; } } if (node.Mass.HasValue && node.Mass.Value > 0) { int?massIndex = null; GsaPropMass gsaPropMass = null; //Assume the PROP_MASS has the same Application ID as this node //Check if the existing mass with the App ID still has the mass required by this StructuralNode massIndex = Initialiser.AppResources.Cache.LookupIndex(massKeyword, node.ApplicationId); if (massIndex.HasValue) { var massGwa = Initialiser.AppResources.Cache.GetGwa(massKeyword, massIndex.Value); if (massGwa != null && massGwa.Count() > 0 && !string.IsNullOrEmpty(massGwa.First())) { gsaPropMass = new GsaPropMass(); gsaPropMass.FromGwa(massGwa.First()); if (Math.Abs(gsaPropMass.Mass - node.Mass.Value) > massEpsilon) { gsaPropMass.Mass = node.Mass.Value; } } } if (gsaPropMass == null) { gsaPropMass = new GsaPropMass() { ApplicationId = gsaNode.ApplicationId, StreamId = streamId, Index = Initialiser.AppResources.Cache.ResolveIndex(massKeyword, gsaNode.ApplicationId), Mass = node.Mass.Value }; if (!string.IsNullOrEmpty(node.Name)) { gsaPropMass.Name = "Mass for " + node.Name; } } if (gsaPropMass.Gwa(out var massGwaLines, false)) { Initialiser.AppResources.Cache.Upsert(massKeyword, gsaPropMass.Index.Value, massGwaLines.First(), streamId, gsaPropMass.ApplicationId, GsaRecord.GetGwaSetCommandType <GsaPropMass>()); } }
/// <summary> /// Method to convert a GhSA GsaNode to GsaAPI.Node /// The method will look for existing nodes and avoid /// creating duplicates. the inputs for existing /// nodes, existing axes and the node id counter will /// be updated, input these with 'ref' keyword /// </summary> /// <param name="node">GsaNode to convert</param> /// <param name="existingNodes">Dictionary of existing GsaAPI nodes to add nodes to</param> /// <param name="existingAxes">Dictionary of existing GsaAPI axes to add local axis to</param> /// <param name="nodeidcounter">node id counter for </param> public static void ConvertNode(GsaNode node, ref Dictionary <int, Node> existingNodes, ref Dictionary <int, Axis> existingAxes, ref int nodeidcounter) { Node apiNode = node.Node; // Add spring to model if (node.Spring != null) { // Spring not implemented in GsaAPI //node.Node.SpringProperty = gsa.AddSpring(node.Spring); // assuming this will send back the spring ID in the model } // Add axis to model if (node.LocalAxis != null) { if (node.LocalAxis != Plane.WorldXY) { Axis ax = new Axis(); Plane pln = node.LocalAxis; ax.Origin.X = pln.OriginX; ax.Origin.Y = pln.OriginY; ax.Origin.Z = pln.OriginZ; ax.XVector.X = pln.XAxis.X; ax.XVector.Y = pln.XAxis.Y; ax.XVector.Z = pln.XAxis.Z; ax.XYPlane.X = pln.YAxis.X; ax.XYPlane.Y = pln.YAxis.Y; ax.XYPlane.Z = pln.YAxis.Z; // set Axis property in node apiNode.AxisProperty = 1; if (existingAxes.Count > 0) { apiNode.AxisProperty = existingAxes.Keys.Max() + 1; } existingAxes.Add(apiNode.AxisProperty, ax); } } if (node.ID > 0) // if the ID is larger than 0 than means the ID has been set and we sent it to the known list { existingNodes[node.ID] = apiNode; } else { // get existing node id if any: int id = GetExistingNodeID(existingNodes, apiNode); if (id > 0) // if within tolerance of existing node { // get GSA node Node gsaNode = new Node(); existingNodes.TryGetValue(id, out gsaNode); // combine restraints always picking true if (gsaNode.Restraint.X) { apiNode.Restraint.X = true; } if (gsaNode.Restraint.Y) { apiNode.Restraint.Y = true; } if (gsaNode.Restraint.Z) { apiNode.Restraint.Z = true; } if (gsaNode.Restraint.XX) { apiNode.Restraint.XX = true; } if (gsaNode.Restraint.YY) { apiNode.Restraint.YY = true; } if (gsaNode.Restraint.ZZ) { apiNode.Restraint.ZZ = true; } // set local axis if it is set in GH node if (node.LocalAxis != null) { if (gsaNode.SpringProperty > 0) { apiNode.SpringProperty = gsaNode.SpringProperty; } } // replace existing node with new merged node existingNodes[id] = apiNode; } else { existingNodes.Add(nodeidcounter, apiNode); nodeidcounter++; } } }
protected override void SolveInstance(IGH_DataAccess DA) { #region GetData Models = null; Nodes = null; Elem1ds = null; Elem2ds = null; Elem3ds = null; Mem1ds = null; Mem2ds = null; Mem3ds = null; Loads = null; Sections = null; Prop2Ds = null; GridPlaneSurfaces = null; // Get Model input List <GH_ObjectWrapper> gh_types = new List <GH_ObjectWrapper>(); if (DA.GetDataList(0, gh_types)) { List <GsaModel> in_models = new List <GsaModel>(); for (int i = 0; i < gh_types.Count; i++) { GH_ObjectWrapper gh_typ = gh_types[i]; if (gh_typ == null) { Params.Owner.AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Input is null"); return; } if (gh_typ.Value is GsaModelGoo) { GsaModel in_model = new GsaModel(); gh_typ.CastTo(ref in_model); in_models.Add(in_model); } else { string type = gh_typ.Value.GetType().ToString(); type = type.Replace("GhSA.Parameters.", ""); type = type.Replace("Goo", ""); Params.Owner.AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Unable to convert GSA input parameter of type " + type + " to GsaModel"); return; } } Models = in_models; } // Get Section Property input gh_types = new List <GH_ObjectWrapper>(); if (DA.GetDataList(1, gh_types)) { List <GsaSection> in_sect = new List <GsaSection>(); List <GsaProp2d> in_prop = new List <GsaProp2d>(); for (int i = 0; i < gh_types.Count; i++) { GH_ObjectWrapper gh_typ = gh_types[i]; if (gh_typ.Value is GsaSectionGoo) { GsaSection gsasection = new GsaSection(); gh_typ.CastTo(ref gsasection); in_sect.Add(gsasection.Duplicate()); } else if (gh_typ.Value is GsaProp2dGoo) { GsaProp2d gsaprop = new GsaProp2d(); gh_typ.CastTo(ref gsaprop); in_prop.Add(gsaprop.Duplicate()); } else { string type = gh_typ.Value.GetType().ToString(); type = type.Replace("GhSA.Parameters.", ""); type = type.Replace("Goo", ""); Params.Owner.AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Unable to convert Prop input parameter of type " + type + " to GsaSection or GsaProp2d"); return; } } if (in_sect.Count > 0) { Sections = in_sect; } if (in_prop.Count > 0) { Prop2Ds = in_prop; } } // Get Geometry input gh_types = new List <GH_ObjectWrapper>(); List <GsaNode> in_nodes = new List <GsaNode>(); List <GsaElement1d> in_elem1ds = new List <GsaElement1d>(); List <GsaElement2d> in_elem2ds = new List <GsaElement2d>(); List <GsaElement3d> in_elem3ds = new List <GsaElement3d>(); List <GsaMember1d> in_mem1ds = new List <GsaMember1d>(); List <GsaMember2d> in_mem2ds = new List <GsaMember2d>(); List <GsaMember3d> in_mem3ds = new List <GsaMember3d>(); if (DA.GetDataList(2, gh_types)) { for (int i = 0; i < gh_types.Count; i++) { GH_ObjectWrapper gh_typ = new GH_ObjectWrapper(); gh_typ = gh_types[i]; if (gh_typ.Value is GsaNodeGoo) { GsaNode gsanode = new GsaNode(); gh_typ.CastTo(ref gsanode); in_nodes.Add(gsanode.Duplicate()); } else if (gh_typ.Value is GsaElement1dGoo) { GsaElement1d gsaelem1 = new GsaElement1d(); gh_typ.CastTo(ref gsaelem1); in_elem1ds.Add(gsaelem1.Duplicate()); } else if (gh_typ.Value is GsaElement2dGoo) { GsaElement2d gsaelem2 = new GsaElement2d(); gh_typ.CastTo(ref gsaelem2); in_elem2ds.Add(gsaelem2.Duplicate()); } else if (gh_typ.Value is GsaElement3dGoo) { GsaElement3d gsaelem3 = new GsaElement3d(); gh_typ.CastTo(ref gsaelem3); in_elem3ds.Add(gsaelem3.Duplicate()); } else if (gh_typ.Value is GsaMember1dGoo) { GsaMember1d gsamem1 = new GsaMember1d(); gh_typ.CastTo(ref gsamem1); in_mem1ds.Add(gsamem1.Duplicate()); } else if (gh_typ.Value is GsaMember2dGoo) { GsaMember2d gsamem2 = new GsaMember2d(); gh_typ.CastTo(ref gsamem2); in_mem2ds.Add(gsamem2.Duplicate()); } else if (gh_typ.Value is GsaMember3dGoo) { GsaMember3d gsamem3 = new GsaMember3d(); gh_typ.CastTo(ref gsamem3); in_mem3ds.Add(gsamem3.Duplicate()); } else { string type = gh_typ.Value.GetType().ToString(); type = type.Replace("GhSA.Parameters.", ""); type = type.Replace("Goo", ""); Params.Owner.AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Unable to convert Geometry input parameter of type " + type + System.Environment.NewLine + " to Node, Element1D, Element2D, Element3D, Member1D, Member2D or Member3D"); return; } } if (in_nodes.Count > 0) { Nodes = in_nodes; } if (in_elem1ds.Count > 0) { Elem1ds = in_elem1ds; } if (in_elem2ds.Count > 0) { Elem2ds = in_elem2ds; } if (in_elem3ds.Count > 0) { Elem3ds = in_elem3ds; } if (in_mem1ds.Count > 0) { Mem1ds = in_mem1ds; } if (in_mem2ds.Count > 0) { Mem2ds = in_mem2ds; } if (in_mem3ds.Count > 0) { Mem3ds = in_mem3ds; } } // Get Loads input gh_types = new List <GH_ObjectWrapper>(); if (DA.GetDataList(3, gh_types)) { List <GsaLoad> in_loads = new List <GsaLoad>(); List <GsaGridPlaneSurface> in_gps = new List <GsaGridPlaneSurface>(); for (int i = 0; i < gh_types.Count; i++) { GH_ObjectWrapper gh_typ = gh_types[i]; if (gh_typ.Value is GsaLoadGoo) { GsaLoad gsaload = null; gh_typ.CastTo(ref gsaload); in_loads.Add(gsaload.Duplicate()); } else if (gh_typ.Value is GsaGridPlaneSurfaceGoo) { GsaGridPlaneSurface gsaGPS = new GsaGridPlaneSurface(); gh_typ.CastTo(ref gsaGPS); in_gps.Add(gsaGPS.Duplicate()); } else { string type = gh_typ.Value.GetType().ToString(); type = type.Replace("GhSA.Parameters.", ""); type = type.Replace("Goo", ""); Params.Owner.AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Unable to convert Load input parameter of type " + type + " to Load or GridPlaneSurface"); return; } } if (in_loads.Count > 0) { Loads = in_loads; } if (in_gps.Count > 0) { GridPlaneSurfaces = in_gps; } } // manually add a warning if no input is set, as all inputs are optional if (Models == null & Nodes == null & Elem1ds == null & Elem2ds == null & Mem1ds == null & Mem2ds == null & Mem3ds == null & Sections == null & Prop2Ds == null & Loads == null & GridPlaneSurfaces == null) { AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Input parameters failed to collect data"); return; } #endregion #region DoWork GsaModel analysisModel = null; if (Models != null) { if (Models.Count > 0) { if (Models.Count > 1) { analysisModel = Util.Gsa.ToGSA.Models.MergeModel(Models); } else { analysisModel = Models[0].Clone(); } } } if (analysisModel != null) { OutModel = analysisModel; } else { OutModel = new GsaModel(); } // Assemble model Model gsa = Util.Gsa.ToGSA.Assemble.AssembleModel(analysisModel, Nodes, Elem1ds, Elem2ds, Elem3ds, Mem1ds, Mem2ds, Mem3ds, Sections, Prop2Ds, Loads, GridPlaneSurfaces); //gsa.SaveAs(@"C:\Users\Kristjan.Nielsen\Desktop\test3.gwb"); #region meshing // Create elements from members gsa.CreateElementsFromMembers(); #endregion #region analysis //analysis IReadOnlyDictionary <int, AnalysisTask> gsaTasks = gsa.AnalysisTasks(); if (gsaTasks.Count < 1) { AddRuntimeMessage(GH_RuntimeMessageLevel.Remark, "Model contains no Analysis Tasks"); } foreach (KeyValuePair <int, AnalysisTask> task in gsaTasks) { if (!(gsa.Analyse(task.Key))) { AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Warning Analysis Case " + task.Key + " could not be analysed"); } } #endregion OutModel.Model = gsa; //gsa.SaveAs("C:\\Users\\Kristjan.Nielsen\\Desktop\\GsaGH_test.gwb"); #endregion #region SetData DA.SetData(0, new GsaModelGoo(OutModel)); #endregion }
public override void GetData(IGH_DataAccess DA, GH_ComponentParamServer Params) { #region GetData Models = null; Nodes = null; Elem1ds = null; Elem2ds = null; Elem3ds = null; Mem1ds = null; Mem2ds = null; Mem3ds = null; Loads = null; Sections = null; Prop2Ds = null; GridPlaneSurfaces = null; OutModel = null; component = Params.Owner; // Get Model input List <GH_ObjectWrapper> gh_types = new List <GH_ObjectWrapper>(); if (DA.GetDataList(0, gh_types)) { List <GsaModel> in_models = new List <GsaModel>(); for (int i = 0; i < gh_types.Count; i++) { if (gh_types[i] == null) { return; } GH_ObjectWrapper gh_typ = gh_types[i]; if (gh_typ.Value is GsaModelGoo) { GsaModel in_model = new GsaModel(); gh_typ.CastTo(ref in_model); in_models.Add(in_model); } else { string type = gh_typ.Value.GetType().ToString(); type = type.Replace("GhSA.Parameters.", ""); type = type.Replace("Goo", ""); Params.Owner.AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Unable to convert GSA input parameter of type " + type + " to GsaModel"); return; } } Models = in_models; } // Get Section Property input gh_types = new List <GH_ObjectWrapper>(); if (DA.GetDataList(1, gh_types)) { List <GsaSection> in_sect = new List <GsaSection>(); List <GsaProp2d> in_prop = new List <GsaProp2d>(); for (int i = 0; i < gh_types.Count; i++) { if (gh_types[i] == null) { return; } GH_ObjectWrapper gh_typ = gh_types[i]; if (gh_typ.Value is GsaSectionGoo) { GsaSection gsasection = new GsaSection(); gh_typ.CastTo(ref gsasection); in_sect.Add(gsasection.Duplicate()); } else if (gh_typ.Value is GsaProp2dGoo) { GsaProp2d gsaprop = new GsaProp2d(); gh_typ.CastTo(ref gsaprop); in_prop.Add(gsaprop.Duplicate()); } else { string type = gh_typ.Value.GetType().ToString(); type = type.Replace("GhSA.Parameters.", ""); type = type.Replace("Goo", ""); Params.Owner.AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Unable to convert Prop input parameter of type " + type + " to GsaSection or GsaProp2d"); return; } } if (in_sect.Count > 0) { Sections = in_sect; } if (in_prop.Count > 0) { Prop2Ds = in_prop; } } // Get Geometry input gh_types = new List <GH_ObjectWrapper>(); List <GsaNode> in_nodes = new List <GsaNode>(); List <GsaElement1d> in_elem1ds = new List <GsaElement1d>(); List <GsaElement2d> in_elem2ds = new List <GsaElement2d>(); List <GsaElement3d> in_elem3ds = new List <GsaElement3d>(); List <GsaMember1d> in_mem1ds = new List <GsaMember1d>(); List <GsaMember2d> in_mem2ds = new List <GsaMember2d>(); List <GsaMember3d> in_mem3ds = new List <GsaMember3d>(); if (DA.GetDataList(2, gh_types)) { for (int i = 0; i < gh_types.Count; i++) { if (gh_types[i] == null) { return; } GH_ObjectWrapper gh_typ = gh_types[i]; if (gh_typ.Value is GsaNodeGoo) { GsaNode gsanode = new GsaNode(); gh_typ.CastTo(ref gsanode); in_nodes.Add(gsanode.Duplicate()); } else if (gh_typ.Value is GsaElement1dGoo) { GsaElement1d gsaelem1 = new GsaElement1d(); gh_typ.CastTo(ref gsaelem1); in_elem1ds.Add(gsaelem1.Duplicate()); } else if (gh_typ.Value is GsaElement2dGoo) { GsaElement2d gsaelem2 = new GsaElement2d(); gh_typ.CastTo(ref gsaelem2); in_elem2ds.Add(gsaelem2.Duplicate()); } else if (gh_typ.Value is GsaElement3dGoo) { GsaElement3d gsaelem3 = new GsaElement3d(); gh_typ.CastTo(ref gsaelem3); in_elem3ds.Add(gsaelem3.Duplicate()); } else if (gh_typ.Value is GsaMember1dGoo) { GsaMember1d gsamem1 = new GsaMember1d(); gh_typ.CastTo(ref gsamem1); in_mem1ds.Add(gsamem1.Duplicate()); } else if (gh_typ.Value is GsaMember2dGoo) { GsaMember2d gsamem2 = new GsaMember2d(); gh_typ.CastTo(ref gsamem2); in_mem2ds.Add(gsamem2.Duplicate()); } else if (gh_typ.Value is GsaMember3dGoo) { GsaMember3d gsamem3 = new GsaMember3d(); gh_typ.CastTo(ref gsamem3); in_mem3ds.Add(gsamem3.Duplicate()); } else { string type = gh_typ.Value.GetType().ToString(); type = type.Replace("GhSA.Parameters.", ""); type = type.Replace("Goo", ""); Params.Owner.AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Unable to convert Geometry input parameter of type " + type + System.Environment.NewLine + " to Node, Element1D, Element2D, Element3D, Member1D, Member2D or Member3D"); return; } } if (in_nodes.Count > 0) { Nodes = in_nodes; } if (in_elem1ds.Count > 0) { Elem1ds = in_elem1ds; } if (in_elem2ds.Count > 0) { Elem2ds = in_elem2ds; } if (in_elem3ds.Count > 0) { Elem3ds = in_elem3ds; } if (in_mem1ds.Count > 0) { Mem1ds = in_mem1ds; } if (in_mem2ds.Count > 0) { Mem2ds = in_mem2ds; } if (in_mem3ds.Count > 0) { Mem3ds = in_mem3ds; } } // Get Loads input gh_types = new List <GH_ObjectWrapper>(); if (DA.GetDataList(3, gh_types)) { List <GsaLoad> in_loads = new List <GsaLoad>(); List <GsaGridPlaneSurface> in_gps = new List <GsaGridPlaneSurface>(); for (int i = 0; i < gh_types.Count; i++) { if (gh_types[i] == null) { return; } GH_ObjectWrapper gh_typ = gh_types[i]; if (gh_typ.Value is GsaLoadGoo) { GsaLoad gsaload = null; gh_typ.CastTo(ref gsaload); in_loads.Add(gsaload.Duplicate()); } else if (gh_typ.Value is GsaGridPlaneSurfaceGoo) { GsaGridPlaneSurface gsaGPS = new GsaGridPlaneSurface(); gh_typ.CastTo(ref gsaGPS); in_gps.Add(gsaGPS.Duplicate()); } else { string type = gh_typ.Value.GetType().ToString(); type = type.Replace("GhSA.Parameters.", ""); type = type.Replace("Goo", ""); Params.Owner.AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Unable to convert Load input parameter of type " + type + " to Load or GridPlaneSurface"); return; } } if (in_loads.Count > 0) { Loads = in_loads; } if (in_gps.Count > 0) { GridPlaneSurfaces = in_gps; } } #endregion // manually add a warning if no input is set, as all inputs are optional if (Models == null & Nodes == null & Elem1ds == null & Elem2ds == null & Mem1ds == null & Mem2ds == null & Mem3ds == null & Sections == null & Prop2Ds == null & Loads == null & GridPlaneSurfaces == null) { hasInput = false; Params.Owner.AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Input parameters failed to collect data"); return; } else { hasInput = true; } }
protected override void SolveInstance(IGH_DataAccess DA) { GsaNode gsaNode = new GsaNode(); if (!DA.GetData(0, ref gsaNode)) { gsaNode = new GsaNode(new Point3d(0, 0, 0)); } if (gsaNode != null) { // #### inputs #### GH_Integer ghInt = new GH_Integer(); if (DA.GetData(1, ref ghInt)) { if (GH_Convert.ToInt32(ghInt, out int id, GH_Conversion.Both)) { gsaNode.ID = id; } } GH_String ghStr = new GH_String(); if (DA.GetData(2, ref ghStr)) { if (GH_Convert.ToString(ghStr, out string name, GH_Conversion.Both)) { gsaNode.Node.Name = name; } } GH_Point ghPt = new GH_Point(); if (DA.GetData(3, ref ghPt)) { Point3d pt = new Point3d(); if (GH_Convert.ToPoint3d(ghPt, ref pt, GH_Conversion.Both)) { gsaNode.Point = pt; gsaNode.Node.Position.X = pt.X; gsaNode.Node.Position.Y = pt.Y; gsaNode.Node.Position.Z = pt.Z; } } GH_Plane ghPln = new GH_Plane(); if (DA.GetData(4, ref ghPln)) { Plane pln = new Plane(); if (GH_Convert.ToPlane(ghPln, ref pln, GH_Conversion.Both)) { pln.Origin = gsaNode.Point; gsaNode.LocalAxis = pln; } } GsaBool6 restraint = new GsaBool6(); if (DA.GetData(5, ref restraint)) { restraint.X = gsaNode.Node.Restraint.X; restraint.Y = gsaNode.Node.Restraint.Y; restraint.Z = gsaNode.Node.Restraint.Z; restraint.XX = gsaNode.Node.Restraint.XX; restraint.YY = gsaNode.Node.Restraint.YY; restraint.ZZ = gsaNode.Node.Restraint.ZZ; } GsaSpring spring = new GsaSpring(); if (DA.GetData(6, ref spring)) { if (gsaNode.Spring != null) { gsaNode.Spring = spring; } } // #### outputs #### DA.SetData(0, new GsaNodeGoo(gsaNode)); DA.SetData(1, gsaNode.ID); DA.SetData(2, gsaNode.Node.Name); DA.SetData(3, gsaNode.Point); DA.SetData(4, gsaNode.LocalAxis); GsaBool6 restraint1 = new GsaBool6 { X = gsaNode.Node.Restraint.X, Y = gsaNode.Node.Restraint.Y, Z = gsaNode.Node.Restraint.Z, XX = gsaNode.Node.Restraint.XX, YY = gsaNode.Node.Restraint.YY, ZZ = gsaNode.Node.Restraint.ZZ }; DA.SetData(5, restraint1); GsaSpring spring1 = new GsaSpring(); if (gsaNode.Spring != null) { spring1 = gsaNode.Spring.Duplicate(); } DA.SetData(6, new GsaSpringGoo(spring1)); try { DA.SetDataList(7, gsaNode.Node.ConnectedElements); } catch (Exception) { } try { DA.SetDataList(8, gsaNode.Node.ConnectedMembers); } catch (Exception) { } } }
protected override void SolveInstance(IGH_DataAccess DA) { GH_ObjectWrapper gh_typ = new GH_ObjectWrapper(); if (DA.GetData(0, ref gh_typ)) { GsaNode gsaNode = new GsaNode(); Point3d tempPt = new Point3d(); if (gh_typ.Value is GsaNodeGoo) { gh_typ.CastTo(ref gsaNode); if (gsaNode == null) { AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Node input is null"); } if (gsaNode.Node == null) { AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Node input is null"); } } else if (GH_Convert.ToPoint3d(gh_typ.Value, ref tempPt, GH_Conversion.Both)) { gsaNode = new GsaNode(tempPt); } else { AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Unable to convert input to Node"); return; } GsaNode node = gsaNode.Duplicate(); // #### inputs #### // 1 ID GH_Integer ghInt = new GH_Integer(); if (DA.GetData(1, ref ghInt)) { if (GH_Convert.ToInt32(ghInt, out int id, GH_Conversion.Both)) { node.ID = id; } } // 2 Point GH_Point ghPt = new GH_Point(); if (DA.GetData(2, ref ghPt)) { Point3d pt = new Point3d(); if (GH_Convert.ToPoint3d(ghPt, ref pt, GH_Conversion.Both)) { node.Point = pt; node.Node.Position.X = pt.X; node.Node.Position.Y = pt.Y; node.Node.Position.Z = pt.Z; } } // 3 plane GH_Plane ghPln = new GH_Plane(); if (DA.GetData(3, ref ghPln)) { Plane pln = new Plane(); if (GH_Convert.ToPlane(ghPln, ref pln, GH_Conversion.Both)) { pln.Origin = node.Point; node.LocalAxis = pln; } } // 4 Restraint GsaBool6 restraint = new GsaBool6(); if (DA.GetData(4, ref restraint)) { node.Node.Restraint.X = restraint.X; node.Node.Restraint.Y = restraint.Y; node.Node.Restraint.Z = restraint.Z; node.Node.Restraint.XX = restraint.XX; node.Node.Restraint.YY = restraint.YY; node.Node.Restraint.ZZ = restraint.ZZ; } // 5 Spring GsaSpring spring = new GsaSpring(); if (DA.GetData(5, ref spring)) { if (spring != null) { node.Spring = spring; } } // 6 Name GH_String ghStr = new GH_String(); if (DA.GetData(6, ref ghStr)) { if (GH_Convert.ToString(ghStr, out string name, GH_Conversion.Both)) { node.Node.Name = name; } } // 7 Colour GH_Colour ghcol = new GH_Colour(); if (DA.GetData(7, ref ghcol)) { if (GH_Convert.ToColor(ghcol, out System.Drawing.Color col, GH_Conversion.Both)) { node.Colour = col; } } // #### outputs #### DA.SetData(0, new GsaNodeGoo(node)); DA.SetData(1, node.ID); DA.SetData(2, node.Point); DA.SetData(3, node.LocalAxis); GsaBool6 restraint1 = new GsaBool6 { X = node.Node.Restraint.X, Y = node.Node.Restraint.Y, Z = node.Node.Restraint.Z, XX = node.Node.Restraint.XX, YY = node.Node.Restraint.YY, ZZ = node.Node.Restraint.ZZ }; DA.SetData(4, restraint1); GsaSpring spring1 = new GsaSpring(); if (node.Spring != null) { spring1 = node.Spring.Duplicate(); } DA.SetData(5, new GsaSpringGoo(spring1)); DA.SetData(6, node.Node.Name); DA.SetData(7, node.Colour); try { DA.SetDataList(8, node.Node.ConnectedElements); } catch (Exception) { } try { DA.SetDataList(9, node.Node.ConnectedMembers); } catch (Exception) { } } }
public static SpeckleObject ToSpeckle(this GsaNode dummyObject) { var nodeKw = GsaRecord.GetKeyword<GsaNode>(); var springKw = GsaRecord.GetKeyword<GsaPropSpr>(); var massKw = GsaRecord.GetKeyword<GsaPropMass>(); var loadTaskKw = GsaRecord.GetKeyword<GsaLoadCase>(); var comboKw = GsaRecord.GetKeyword<GsaCombination>(); var newNodeLines = Initialiser.AppResources.Cache.GetGwaToSerialise(nodeKw); var sendResults = GetNodeResultSettings(out var embedResults, out var resultTypes, out var resultCases); if (sendResults) { Initialiser.AppResources.Proxy.LoadResults(ResultGroup.Node, out int numErrorRows, resultCases, newNodeLines.Keys.ToList()); if (numErrorRows > 0) { Initialiser.AppResources.Messenger.Message(MessageIntent.Display, MessageLevel.Error, "Unable to process " + numErrorRows + " rows of node results"); Initialiser.AppResources.Messenger.Message(MessageIntent.TechnicalLog, MessageLevel.Error, "Unable to process " + numErrorRows + " rows of node results"); } } //This method produces two types of SpeckleStructural objects var structuralNodes = new List<StructuralNode>(); var structural0dSprings = new List<Structural0DSpring>(); int numToBeSent = 0; #if DEBUG foreach (var i in newNodeLines.Keys) #else Parallel.ForEach(newNodeLines.Keys, i => #endif { GsaNode gsaNode = null; var objNode = Helper.ToSpeckleTryCatch(nodeKw, i, () => { gsaNode = new GsaNode(); if (gsaNode.FromGwa(newNodeLines[i])) { var structuralNode = new StructuralNode() { Name = gsaNode.Name, ApplicationId = SpeckleStructuralGSA.Helper.GetApplicationId(nodeKw, i), Value = new List<double>() { gsaNode.X, gsaNode.Y, gsaNode.Z }, Restraint = GetRestraint(gsaNode) }; if (gsaNode.MeshSize.HasValue && gsaNode.MeshSize.Value > 0) { structuralNode.GSALocalMeshSize = gsaNode.MeshSize.Value; } if (gsaNode.MassPropertyIndex.HasValue && gsaNode.MassPropertyIndex.Value > 0) { var massGwas = Initialiser.AppResources.Cache.GetGwa(massKw, gsaNode.MassPropertyIndex.Value); if (massGwas != null && massGwas.Count() > 0 && !string.IsNullOrEmpty(massGwas.First())) { var gsaPropMass = new GsaPropMass(); if (gsaPropMass.FromGwa(massGwas.First()) && gsaPropMass.Mass > 0) { structuralNode.Mass = gsaPropMass.Mass; } } } return structuralNode; } return new SpeckleNull(); }); if (objNode !=null && !(objNode is SpeckleNull)) { var structuralNode = (StructuralNode)objNode; GSANodeResult gsaNodeResult = null; //Embed results if appropriate as the last thing to do to the new Speckle object before being added to the collection of objects to be sent if (sendResults) { if (Initialiser.AppResources.Proxy.GetResultHierarchy(ResultGroup.Node, i, out var results) && results != null) { var orderedLoadCases = results.Keys.OrderBy(k => k).ToList(); if (embedResults) { foreach (var loadCase in orderedLoadCases) { if (!Helper.FilterResults(results[loadCase], out Dictionary<string, object> sendableResults)) { continue; } var nodeResult = new StructuralNodeResult() { IsGlobal = !Initialiser.AppResources.Settings.ResultInLocalAxis, TargetRef = structuralNode.ApplicationId, Value = sendableResults }; var loadCaseRef = Helper.GsaCaseToRef(loadCase, loadTaskKw, comboKw); if (!string.IsNullOrEmpty(loadCaseRef)) { //nodeResult.LoadCaseRef = loadCaseRef; nodeResult.LoadCaseRef = loadCase; } if (structuralNode.Result == null) { //Can't just allocate an empty dictionary as the Result set property won't allow it structuralNode.Result = new Dictionary<string, object>() { { loadCase, nodeResult } }; } else { structuralNode.Result.Add(loadCase, nodeResult); } } } else { foreach (var loadCase in orderedLoadCases) { if (!Helper.FilterResults(results[loadCase], out Dictionary<string, object> sendableResults)) { continue; } var nodeResult = new StructuralNodeResult() { IsGlobal = !Initialiser.AppResources.Settings.ResultInLocalAxis, TargetRef = structuralNode.ApplicationId, Value = sendableResults }; var loadCaseRef = Helper.GsaCaseToRef(loadCase, loadTaskKw, comboKw); if (!string.IsNullOrEmpty(loadCaseRef)) { //nodeResult.LoadCaseRef = loadCaseRef; nodeResult.LoadCaseRef = loadCase; } gsaNodeResult = new GSANodeResult { Value = nodeResult, GSAId = i }; Initialiser.GsaKit.GSASenderObjects.Add(gsaNodeResult); } } } } var senderObjectGsaNode = new GSANode() { Value = structuralNode, GSAId = i }; if (gsaNodeResult != null) { senderObjectGsaNode.ForceSend = true; } Initialiser.GsaKit.GSASenderObjects.Add(senderObjectGsaNode); numToBeSent++; //Add spring object if appropriate if (gsaNode.SpringPropertyIndex.HasValue && gsaNode.SpringPropertyIndex.Value > 0) { var objSpring = Helper.ToSpeckleTryCatch(nodeKw, i, () => { var springPropRef = SpeckleStructuralGSA.Helper.GetApplicationId(springKw, gsaNode.SpringPropertyIndex.Value); if (!string.IsNullOrEmpty(springPropRef)) { var structural0dSpring = new Structural0DSpring() { //The application ID might need a better mechanism to allow a StructuralNode and Structural0DSpring previously received //that originally created the one node to be separated out again to produce the Application ID to use here for this spring //TO DO - review, for now just append a string to ensure the same Application ID value isn't used twice ApplicationId = gsaNode.ApplicationId + "_spring", Name = gsaNode.Name, Value = new List<double>() { gsaNode.X, gsaNode.Y, gsaNode.Z }, PropertyRef = springPropRef, Dummy = false }; return structural0dSpring; } return new SpeckleNull(); }); if (!(objSpring is SpeckleNull)) { Initialiser.GsaKit.GSASenderObjects.Add(new GSA0DSpring() { Value = (Structural0DSpring)objSpring, GSAId = i }); numToBeSent++; } } //if spring object needs to be added } //if node object was successfully created } #if !DEBUG ); #endif if (sendResults) { Initialiser.AppResources.Proxy.ClearResults(ResultGroup.Node); } return (numToBeSent > 0) ? new SpeckleObject() : new SpeckleNull(); }
public void GetGeometryComponentTest() { Assert.IsTrue(Rhino.RhinoApp.IsLicenseValidated, "Rhino must be licensed to run this test"); // ensure model has been opened: if (TestModel == null) { OpenComponentTest(); } // create the component var comp = new GhSA.Components.GetGeometry(); comp.CreateAttributes(); // input parameter GsaModelGoo modelGoo = new GsaModelGoo(TestModel); Component.SetInput(comp, modelGoo); // Get output from component GsaNodeGoo output00 = (GsaNodeGoo)Component.GetOutput(comp, 0, 0, 0); GsaNodeGoo output01 = (GsaNodeGoo)Component.GetOutput(comp, 0, 0, 1); GsaElement1dGoo output1 = (GsaElement1dGoo)Component.GetOutput(comp, 1); GsaMember1dGoo output3 = (GsaMember1dGoo)Component.GetOutput(comp, 4); //pManager.AddGenericParameter("Nodes", "No", "Nodes from GSA Model", GH_ParamAccess.list); //pManager.AddGenericParameter("1D Elements", "E1D", "1D Elements (Analysis Layer) from GSA Model", GH_ParamAccess.list); //pManager.AddGenericParameter("2D Elements", "E2D", "2D Elements (Analysis Layer) from GSA Model", GH_ParamAccess.list); //pManager.AddGenericParameter("3D Elements", "E3D", "3D Elements (Analysis Layer) from GSA Model", GH_ParamAccess.list); //pManager.AddGenericParameter("1D Members", "M1D", "1D Members (Design Layer) from GSA Model", GH_ParamAccess.list); //pManager.AddGenericParameter("2D Members", "M2D", "2D Members (Design Layer) from GSA Model", GH_ParamAccess.list); //pManager.AddGenericParameter("3D Members", "M3D", "3D Members (Design Layer) from GSA Model", GH_ParamAccess.list); // cast from -goo to Gsa-GH data type GsaNode node1 = new GsaNode(); GsaNode node2 = new GsaNode(); output00.CastTo(ref node1); output01.CastTo(ref node2); GsaElement1d elem = new GsaElement1d(); output1.CastTo(ref elem); GsaMember1d mem = new GsaMember1d(); output3.CastTo(ref mem); // test nodes are correct Assert.AreEqual(1, node1.ID); Assert.AreEqual(0, node1.Point.X, 1E-9); Assert.AreEqual(0, node1.Point.Y, 1E-9); Assert.AreEqual(0, node1.Point.Z, 1E-9); Assert.AreEqual(2, node2.ID); Assert.AreEqual(7.5, node2.Point.X, 1E-9); Assert.AreEqual(0, node2.Point.Y, 1E-9); Assert.AreEqual(0, node2.Point.Z, 1E-9); Assert.IsTrue(node1.Node.Restraint.X); Assert.IsTrue(node1.Node.Restraint.Y); Assert.IsTrue(node1.Node.Restraint.Z); Assert.IsTrue(node1.Node.Restraint.XX); Assert.IsFalse(node1.Node.Restraint.YY); Assert.IsFalse(node1.Node.Restraint.ZZ); Assert.IsFalse(node2.Node.Restraint.X); Assert.IsTrue(node2.Node.Restraint.Y); Assert.IsTrue(node2.Node.Restraint.Z); Assert.IsFalse(node2.Node.Restraint.XX); Assert.IsFalse(node2.Node.Restraint.YY); Assert.IsFalse(node2.Node.Restraint.ZZ); // test element and member Assert.AreEqual(1, elem.ID); Assert.AreEqual(0, elem.Line.PointAtStart.X, 1E-9); Assert.AreEqual(0, elem.Line.PointAtStart.Y, 1E-9); Assert.AreEqual(0, elem.Line.PointAtStart.Z, 1E-9); Assert.AreEqual(7.5, elem.Line.PointAtEnd.X, 1E-9); Assert.AreEqual(0, elem.Line.PointAtEnd.Y, 1E-9); Assert.AreEqual(0, elem.Line.PointAtEnd.Z, 1E-9); //Assert.AreEqual("CAT UB UB457x191x89", elem.Section.Section.Profile.Substring(0, 19)); Assert.AreEqual(1, mem.ID); Assert.AreEqual(0, mem.PolyCurve.PointAtStart.X, 1E-9); Assert.AreEqual(0, mem.PolyCurve.PointAtStart.Y, 1E-9); Assert.AreEqual(0, mem.PolyCurve.PointAtStart.Z, 1E-9); Assert.AreEqual(7.5, mem.PolyCurve.PointAtEnd.X, 1E-9); Assert.AreEqual(0, mem.PolyCurve.PointAtEnd.Y, 1E-9); Assert.AreEqual(0, mem.PolyCurve.PointAtEnd.Z, 1E-9); }
protected override void SolveInstance(IGH_DataAccess DA) { #region inputs // Get Member1d input GH_ObjectWrapper gh_typ = new GH_ObjectWrapper(); List <GH_ObjectWrapper> gh_types = new List <GH_ObjectWrapper>(); List <GsaNode> in_nodes = new List <GsaNode>(); if (DA.GetDataList(0, gh_types)) { for (int i = 0; i < gh_types.Count; i++) { gh_typ = gh_types[i]; if (gh_typ.Value is GsaNodeGoo) { GsaNode gsanode = new GsaNode(); gh_typ.CastTo(ref gsanode); in_nodes.Add(gsanode); } else { AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Error in Node input"); return; } } } List <GsaMember1d> in_mem1ds = new List <GsaMember1d>(); if (DA.GetDataList(1, gh_types)) { for (int i = 0; i < gh_types.Count; i++) { gh_typ = gh_types[i]; if (gh_typ.Value is GsaMember1dGoo) { GsaMember1d gsamem1 = new GsaMember1d(); gh_typ.CastTo(ref gsamem1); in_mem1ds.Add(gsamem1); } else { AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Error in Mem1D input"); return; } } } // Get Member2d input gh_types = new List <GH_ObjectWrapper>(); List <GsaMember2d> in_mem2ds = new List <GsaMember2d>(); if (DA.GetDataList(2, gh_types)) { for (int i = 0; i < gh_types.Count; i++) { gh_typ = gh_types[i]; if (gh_typ.Value is GsaMember2dGoo) { GsaMember2d gsamem2 = new GsaMember2d(); gh_typ.CastTo(ref gsamem2); in_mem2ds.Add(gsamem2); } else { AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Error in Mem2D input"); return; } } } // Get Member3d input gh_types = new List <GH_ObjectWrapper>(); List <GsaMember3d> in_mem3ds = new List <GsaMember3d>(); if (DA.GetDataList(3, gh_types)) { for (int i = 0; i < gh_types.Count; i++) { gh_typ = gh_types[i]; if (gh_typ.Value is GsaMember3dGoo) { GsaMember3d gsamem3 = new GsaMember3d(); gh_typ.CastTo(ref gsamem3); in_mem3ds.Add(gsamem3); } else { AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Error in Mem3D input"); return; } } } // manually add a warning if no input is set, as all three inputs are optional if (in_mem1ds.Count < 1 & in_mem2ds.Count < 1 & in_mem3ds.Count < 1) { AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Input parameters failed to collect data"); } #endregion // Assemble model Model gsa = Util.Gsa.ToGSA.Assemble.AssembleModel(null, in_nodes, null, null, null, in_mem1ds, in_mem2ds, in_mem3ds, null, null, null, null); #region meshing // Create elements from members gsa.CreateElementsFromMembers(); #endregion // extract nodes from model List <GsaNodeGoo> nodes = Util.Gsa.FromGSA.GetNodes(gsa.Nodes(), gsa); // extract elements from model Tuple <List <GsaElement1dGoo>, List <GsaElement2dGoo>, List <GsaElement3dGoo> > elementTuple = Util.Gsa.FromGSA.GetElements(gsa.Elements(), gsa.Nodes(), gsa.Sections(), gsa.Prop2Ds()); // expose internal model if anyone wants to use it GsaModel outModel = new GsaModel(); outModel.Model = gsa; DA.SetDataList(0, nodes); DA.SetDataList(1, elementTuple.Item1); DA.SetDataList(2, elementTuple.Item2); DA.SetDataList(3, elementTuple.Item3); DA.SetData(4, new GsaModelGoo(outModel)); // custom display settings for element2d mesh element2ds = elementTuple.Item2; }