diff --git a/FemDesign.Core/Bars/Bar.cs b/FemDesign.Core/Bars/Bar.cs index 557f58a2..cb9e3793 100644 --- a/FemDesign.Core/Bars/Bar.cs +++ b/FemDesign.Core/Bars/Bar.cs @@ -2,6 +2,7 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Runtime.CompilerServices; using System.Text.RegularExpressions; using System.Xml.Serialization; using FemDesign.GenericClasses; @@ -88,6 +89,9 @@ public Geometry.Edge Edge } } + [XmlAttribute("shell_model")] + public ShellModelType ShellModel = ShellModelType.None; + [XmlAttribute("type")] public BarType Type { get; set; } @@ -391,7 +395,6 @@ public Bar(Geometry.Edge edge, BarType type, Composites.CompositeSection composi this.BarPart = new BarPart(edge, this.Type, compositeSection, startEccentricity, endEccentricity, startConnectivity, endConnectivity, identifier); } - /// /// Construct a truss element. /// @@ -411,6 +414,21 @@ public static Bar Truss(Geometry.Edge edge, Materials.Material material, Section return truss; } + /// + /// Change the analytical model of the bar into a shell model. + /// + /// + /// + public void ToShellModel(ShellModelType type) + { + if (this.Type == BarType.Truss) + throw new ArgumentException("Analytical models of Truss objects cannot be altered into shell models!"); + if (this.BarPart.HasComplexCompositeRef || this.BarPart.HasDeltaBeamComplexSectionRef) + throw new ArgumentException("Analytical models of composite bars or bars with Deltabeam sections cannot be altered into shell models!"); + + this.ShellModel = type; + } + public void UpdateSection(Sections.Section section) { if(this.Type == BarType.Truss) @@ -528,4 +546,29 @@ public override string ToString() } } } + + [System.Serializable] + public enum ShellModelType + { + /// + /// Bar model. + /// + [Parseable("none", "None", "NONE")] + [XmlEnum("none")] + None, + + /// + /// Shell model. Contains only shell elements. + /// + [Parseable("simple", "Simple", "SIMPLE")] + [XmlEnum("simple")] + Simple, + + /// + /// Shell model. Fictitious bars on the boundary of the shell model. + /// + [Parseable("complex", "Complex", "COMPLEX")] + [XmlEnum("complex")] + Complex + } } \ No newline at end of file diff --git a/FemDesign.Grasshopper/Bars/BarDeconstructModify.cs b/FemDesign.Grasshopper/Bars/BarDeconstructModify.cs index 292a2db3..36d91397 100644 --- a/FemDesign.Grasshopper/Bars/BarDeconstructModify.cs +++ b/FemDesign.Grasshopper/Bars/BarDeconstructModify.cs @@ -2,7 +2,11 @@ using System; using System.Collections.Generic; using System.Linq; +using FemDesign.Bars; +using FemDesign.Grasshopper.Extension.ComponentExtension; +using FemDesign.Loads; using Grasshopper.Kernel; +using Grasshopper.Kernel.Special; using Rhino.Geometry; namespace FemDesign.Grasshopper @@ -14,33 +18,41 @@ public BarDeconstructModify(): base("Bar.Deconstruct.Modify", "Deconstruct.Modif { } + + protected override void BeforeSolveInstance() + { + ValueListUtils.UpdateValueLists(this, 12, Enum.GetNames(typeof(Bars.ShellModelType)).ToList(), null, GH_ValueListMode.DropDown); + } protected override void RegisterInputParams(GH_InputParamManager pManager) { - pManager.AddGenericParameter("Bar", "Bar", "Bar element", GH_ParamAccess.item); - pManager.AddBooleanParameter("NewGuid", "NewGuid", "Generate a new guid for this bar?", GH_ParamAccess.item); - pManager[pManager.ParamCount - 1].Optional = true; - pManager.AddCurveParameter("Curve", "Curve", "LineCurve or ArcCurve", GH_ParamAccess.item); - pManager[pManager.ParamCount - 1].Optional = true; - pManager.AddGenericParameter("Material", "Material", "Material.", GH_ParamAccess.item); - pManager[pManager.ParamCount - 1].Optional = true; - pManager.AddGenericParameter("Section", "Section", "Section. If 1 item this item defines both start and end. If two items the first item defines the start and the last item defines the end.", GH_ParamAccess.list); - pManager[pManager.ParamCount - 1].Optional = true; - pManager.AddGenericParameter("Connectivity", "Connectivity", "Connectivity. If 1 item this item defines both start and end. If two items the first item defines the start and the last item defines the end. Optional, default value if undefined.", GH_ParamAccess.list); - pManager[pManager.ParamCount - 1].Optional = true; - pManager.AddGenericParameter("Eccentricity", "Eccentricity", "Eccentricity. If 1 item this item defines both start and end. If two items the first item defines the start and the last item defines the end. Optional, default value if undefined.", GH_ParamAccess.list); - pManager[pManager.ParamCount - 1].Optional = true; - pManager.AddVectorParameter("LocalY", "LocalY", "Set local y-axis. Vector must be perpendicular to Curve mid-point local x-axis. This parameter overrides OrientLCS", GH_ParamAccess.item); - pManager[pManager.ParamCount - 1].Optional = true; - pManager.AddGenericParameter("Stirrups", "Stirrups", "Stirrups to add to bar. Item or list. New reinforcement will overwrite the original.", GH_ParamAccess.list); - pManager[pManager.ParamCount - 1].Optional = true; - pManager.AddGenericParameter("LongitudinalBars", "LongBars", "Longitudinal reinforcement to add to bar. Item or list. New reinforcement will overwrite the original.", GH_ParamAccess.list); - pManager[pManager.ParamCount - 1].Optional = true; - pManager.AddGenericParameter("PTC", "PTC", "Post-tensioning cables. New PTC will overwrite the original.", GH_ParamAccess.list); - pManager[pManager.ParamCount - 1].Optional = true; - pManager.AddGenericParameter("StiffnessModifier", "StiffnessModifier", "", GH_ParamAccess.item); - pManager[pManager.ParamCount - 1].Optional = true; - pManager.AddTextParameter("Identifier", "Identifier", "Identifier. Optional, default value if undefined.", GH_ParamAccess.item); - pManager[pManager.ParamCount - 1].Optional = true; + pManager.AddGenericParameter("Bar", "Bar", "Bar element", GH_ParamAccess.item); + pManager.AddBooleanParameter("NewGuid", "NewGuid", "Generate a new guid for this bar?", GH_ParamAccess.item); + pManager[pManager.ParamCount - 1].Optional = true; + pManager.AddCurveParameter("Curve", "Curve", "LineCurve or ArcCurve", GH_ParamAccess.item); + pManager[pManager.ParamCount - 1].Optional = true; + pManager.AddGenericParameter("Material", "Material", "Material.", GH_ParamAccess.item); + pManager[pManager.ParamCount - 1].Optional = true; + pManager.AddGenericParameter("Section", "Section", "Section. If 1 item this item defines both start and end. If two items the first item defines the start and the last item defines the end.", GH_ParamAccess.list); + pManager[pManager.ParamCount - 1].Optional = true; + pManager.AddGenericParameter("Connectivity", "Connectivity", "Connectivity. If 1 item this item defines both start and end. If two items the first item defines the start and the last item defines the end. Optional, default value if undefined.", GH_ParamAccess.list); + pManager[pManager.ParamCount - 1].Optional = true; + pManager.AddGenericParameter("Eccentricity", "Eccentricity", "Eccentricity. If 1 item this item defines both start and end. If two items the first item defines the start and the last item defines the end. Optional, default value if undefined.", GH_ParamAccess.list); + pManager[pManager.ParamCount - 1].Optional = true; + pManager.AddVectorParameter("LocalY", "LocalY", "Set local y-axis. Vector must be perpendicular to Curve mid-point local x-axis. This parameter overrides OrientLCS", GH_ParamAccess.item); + pManager[pManager.ParamCount - 1].Optional = true; + pManager.AddGenericParameter("Stirrups", "Stirrups", "Stirrups to add to bar. Item or list. New reinforcement will overwrite the original.", GH_ParamAccess.list); + pManager[pManager.ParamCount - 1].Optional = true; + pManager.AddGenericParameter("LongitudinalBars", "LongBars", "Longitudinal reinforcement to add to bar. Item or list. New reinforcement will overwrite the original.", GH_ParamAccess.list); + pManager[pManager.ParamCount - 1].Optional = true; + pManager.AddGenericParameter("PTC", "PTC", "Post-tensioning cables. New PTC will overwrite the original.", GH_ParamAccess.list); + pManager[pManager.ParamCount - 1].Optional = true; + pManager.AddGenericParameter("StiffnessModifier", "StiffnessModifier", "", GH_ParamAccess.item); + pManager[pManager.ParamCount - 1].Optional = true; + pManager.AddTextParameter("ShellModel", "ShellModel", "Analytical model of the bar. Optional, default value is 'None'.\nConnect 'ValueList' to get the options:\nNone\nSimple\nComplex\n\n" + + "Note:\n'None' = Bar model;\n'Simple = Shell model. Contains only shell elements;\n'Complex = Shell model. Fictitious bars on the boundary of the shell model;", GH_ParamAccess.item); + pManager[pManager.ParamCount - 1].Optional = true; + pManager.AddTextParameter("Identifier", "Identifier", "Identifier. Optional, default value if undefined.", GH_ParamAccess.item); + pManager[pManager.ParamCount - 1].Optional = true; } protected override void RegisterOutputParams(GH_OutputParamManager pManager) @@ -57,6 +69,7 @@ protected override void RegisterOutputParams(GH_OutputParamManager pManager) pManager.AddGenericParameter("LongitudinalBars", "LongBars", "Longitudinal reinforcement for bar.", GH_ParamAccess.list); pManager.AddGenericParameter("PTC", "PTC", "Post-tensioning cables.", GH_ParamAccess.list); pManager.AddGenericParameter("StiffnessModifier", "StiffnessModifier", "", GH_ParamAccess.item); + pManager.AddTextParameter("ShellModel", "ShellModel", "Analytical model of the bar.", GH_ParamAccess.item); pManager.AddTextParameter("Identifier", "Identifier", "Structural element ID.", GH_ParamAccess.item); } protected override void SolveInstance(IGH_DataAccess DA) @@ -210,8 +223,14 @@ protected override void SolveInstance(IGH_DataAccess DA) bar.BarPart.StiffnessModifiers = new List() { stiffnessFactors }; } + string shellModel = ShellModelType.None.ToString(); + if (DA.GetData(12, ref shellModel)) + { + bar.ShellModel = FemDesign.GenericClasses.EnumParser.Parse(shellModel); + } + string identifier = null; - if (DA.GetData(12, ref identifier)) + if (DA.GetData(13, ref identifier)) { bar.Identifier = identifier; } @@ -278,7 +297,8 @@ protected override void SolveInstance(IGH_DataAccess DA) DA.SetDataList(10, bar.Ptc); DA.SetData(11, bar.BarPart.StiffnessModifiers); - DA.SetData(12, bar.Name); + DA.SetData(12, bar.ShellModel); + DA.SetData(13, bar.Name); } protected override System.Drawing.Bitmap Icon { @@ -289,7 +309,7 @@ protected override System.Drawing.Bitmap Icon } public override Guid ComponentGuid { - get { return new Guid("3A6FD9BA-6EBB-4822-B1A8-B3E3E297ED99"); } + get { return new Guid("{CF1E80D0-6236-4BCC-A8FB-6EBD8DA76CBF}"); } } public override GH_Exposure Exposure => GH_Exposure.secondary; diff --git a/FemDesign.Grasshopper/Bars/BarDeconstructModify_OBSOLETE2307.cs b/FemDesign.Grasshopper/Bars/BarDeconstructModify_OBSOLETE2307.cs new file mode 100644 index 00000000..37e4c3ee --- /dev/null +++ b/FemDesign.Grasshopper/Bars/BarDeconstructModify_OBSOLETE2307.cs @@ -0,0 +1,297 @@ +// https://strusoft.com/ +using System; +using System.Collections.Generic; +using System.Linq; +using Grasshopper.Kernel; +using Rhino.Geometry; + +namespace FemDesign.Grasshopper +{ + public class BarDeconstructModify_OBSOLETE2307 : FEM_Design_API_Component + { + public BarDeconstructModify_OBSOLETE2307() : base("Bar.Deconstruct.Modify", "Deconstruct.Modify", "Deconstruct and modify properties of an exiting bar element of any type.", CategoryName.Name(), + SubCategoryName.Cat2a()) + { + + } + protected override void RegisterInputParams(GH_InputParamManager pManager) + { + pManager.AddGenericParameter("Bar", "Bar", "Bar element", GH_ParamAccess.item); + pManager.AddBooleanParameter("NewGuid", "NewGuid", "Generate a new guid for this bar?", GH_ParamAccess.item); + pManager[pManager.ParamCount - 1].Optional = true; + pManager.AddCurveParameter("Curve", "Curve", "LineCurve or ArcCurve", GH_ParamAccess.item); + pManager[pManager.ParamCount - 1].Optional = true; + pManager.AddGenericParameter("Material", "Material", "Material.", GH_ParamAccess.item); + pManager[pManager.ParamCount - 1].Optional = true; + pManager.AddGenericParameter("Section", "Section", "Section. If 1 item this item defines both start and end. If two items the first item defines the start and the last item defines the end.", GH_ParamAccess.list); + pManager[pManager.ParamCount - 1].Optional = true; + pManager.AddGenericParameter("Connectivity", "Connectivity", "Connectivity. If 1 item this item defines both start and end. If two items the first item defines the start and the last item defines the end. Optional, default value if undefined.", GH_ParamAccess.list); + pManager[pManager.ParamCount - 1].Optional = true; + pManager.AddGenericParameter("Eccentricity", "Eccentricity", "Eccentricity. If 1 item this item defines both start and end. If two items the first item defines the start and the last item defines the end. Optional, default value if undefined.", GH_ParamAccess.list); + pManager[pManager.ParamCount - 1].Optional = true; + pManager.AddVectorParameter("LocalY", "LocalY", "Set local y-axis. Vector must be perpendicular to Curve mid-point local x-axis. This parameter overrides OrientLCS", GH_ParamAccess.item); + pManager[pManager.ParamCount - 1].Optional = true; + pManager.AddGenericParameter("Stirrups", "Stirrups", "Stirrups to add to bar. Item or list. New reinforcement will overwrite the original.", GH_ParamAccess.list); + pManager[pManager.ParamCount - 1].Optional = true; + pManager.AddGenericParameter("LongitudinalBars", "LongBars", "Longitudinal reinforcement to add to bar. Item or list. New reinforcement will overwrite the original.", GH_ParamAccess.list); + pManager[pManager.ParamCount - 1].Optional = true; + pManager.AddGenericParameter("PTC", "PTC", "Post-tensioning cables. New PTC will overwrite the original.", GH_ParamAccess.list); + pManager[pManager.ParamCount - 1].Optional = true; + pManager.AddGenericParameter("StiffnessModifier", "StiffnessModifier", "", GH_ParamAccess.item); + pManager[pManager.ParamCount - 1].Optional = true; + pManager.AddTextParameter("Identifier", "Identifier", "Identifier. Optional, default value if undefined.", GH_ParamAccess.item); + pManager[pManager.ParamCount - 1].Optional = true; + + } + protected override void RegisterOutputParams(GH_OutputParamManager pManager) + { + pManager.AddGenericParameter("Bar", "Bar", "Bar.", GH_ParamAccess.item); + pManager.AddTextParameter("Guid", "Guid", "Guid.", GH_ParamAccess.item); + pManager.AddCurveParameter("Curve", "Curve", "LineCurve or ArcCurve [m]", GH_ParamAccess.item); + pManager.AddGenericParameter("Material", "Material", "Material", GH_ParamAccess.item); + pManager.AddGenericParameter("Section", "Section", "Section", GH_ParamAccess.list); + pManager.AddGenericParameter("Connectivity", "Connectivity", "Connectivity", GH_ParamAccess.list); + pManager.AddGenericParameter("Eccentricity", "Eccentricity", "Eccentricity", GH_ParamAccess.list); + pManager.AddGenericParameter("LocalY", "LocalY", "LocalY", GH_ParamAccess.item); + pManager.AddGenericParameter("Stirrups", "Stirrups", "Stirrup bar reinforcement.", GH_ParamAccess.list); + pManager.AddGenericParameter("LongitudinalBars", "LongBars", "Longitudinal reinforcement for bar.", GH_ParamAccess.list); + pManager.AddGenericParameter("PTC", "PTC", "Post-tensioning cables.", GH_ParamAccess.list); + pManager.AddGenericParameter("StiffnessModifier", "StiffnessModifier", "", GH_ParamAccess.item); + pManager.AddTextParameter("Identifier", "Identifier", "Structural element ID.", GH_ParamAccess.item); + } + protected override void SolveInstance(IGH_DataAccess DA) + { + // get input + Bars.Bar bar = null; + if (!DA.GetData(0, ref bar)) + { + return; + } + else if (bar == null) + { + return; + } + else + { + if (bar.BarPart.HasComplexCompositeRef || bar.BarPart.HasDeltaBeamComplexSectionRef) + { + AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "The bar has a Composite Section. The object has not been implemented yet. Please, get in touch if needed."); + return; + } + + bar = bar.DeepClone(); + } + + bool newGuid = false; + if (DA.GetData(1, ref newGuid)) + { + if (newGuid) + { + bar.EntityCreated(); + bar.BarPart.EntityCreated(); + + for (int i = 0; i < bar.Reinforcement.Count; i++) + { + bar.Reinforcement[i].BaseBar.Guid = bar.BarPart.Guid; + } + for (int i = 0; i < bar.Ptc.Count; i++) + { + bar.Ptc[i].BaseObject = bar.BarPart.Guid; + } + } + } + + Curve curve = null; + if (DA.GetData(2, ref curve)) + { + // convert geometry + FemDesign.Geometry.Edge edge = Convert.FromRhinoLineOrArc2(curve); + + // update edge + bar.BarPart.Edge = edge; + } + + FemDesign.Materials.Material material = null; + if (DA.GetData(3, ref material)) + { + if (material.Family != bar.BarPart.ComplexMaterialObj.Family) + { + if (bar.BarPart.BucklingData != null && bar.BarPart.BucklingData.BucklingLength != null) + { + + AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "The bar's buckling data was created for another material and might not correspond to the new material. If you change the material you need to change the buckling length's properties."); + } + if (bar.Reinforcement.Any() || bar.Ptc.Any()) + { + AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "The bar already has reinforcement or PTC. Material has changed. The reinforcement and PTC have been removed."); + bar.Reinforcement.Clear(); + bar.Ptc.Clear(); + } + } + + bar.BarPart.ComplexMaterialObj = material; + } + + List sections = new List(); + if (DA.GetDataList(4, sections)) + { + if (bar.Type != Bars.BarType.Truss) + { + bar.BarPart.ComplexSectionObj.Sections = sections.ToArray(); + } + else + { + bar.BarPart.TrussUniformSectionObj = sections[0]; + if (sections.Count > 1) + { + AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "In FEM-Design, it is not possible to set a variable cross section for truss. The first value will be selected."); + } + } + } + + List connectivities = new List(); + if (DA.GetDataList(5, connectivities)) + { + bar.BarPart.Connectivity = connectivities.ToArray(); + } + + List eccentricities = new List(); + if (DA.GetDataList(6, eccentricities)) + { + if (bar.Type != Bars.BarType.Truss) + { + bar.BarPart.ComplexSectionObj.Eccentricities = eccentricities.ToArray(); + } + else + { + throw new System.Exception("Truss has no eccentricity."); + } + } + + Vector3d v = Vector3d.Zero; + if (DA.GetData(7, ref v)) + { + bar.BarPart.LocalY = v.FromRhino(); + } + + List stirrups = new List(); + List longBars = new List(); + DA.GetDataList(8, stirrups); + DA.GetDataList(9, longBars); + List barReinf = new List(); + if (stirrups.Count != 0) + { + var clonedStirrups = stirrups.Select(x => x.DeepClone()).ToList(); + clonedStirrups.ForEach(s => barReinf.Add(s)); + bar.Reinforcement.RemoveAll(x => x.IsStirrups); + } + if (longBars.Count != 0) + { + var clonedLongBars = longBars.Select(x => x.DeepClone()).ToList(); + clonedLongBars.ForEach(l => barReinf.Add(l)); + bar.Reinforcement.RemoveAll(x => !x.IsStirrups); + } + if (barReinf.Any()) + { + bar = FemDesign.Reinforcement.BarReinforcement.AddReinforcementToBar(bar, barReinf, true); + } + + List ptc = new List(); + if (DA.GetDataList(10, ptc)) + { + var clonedPtc = ptc.Select(x => x.DeepClone()).ToList(); + bar.Ptc.Clear(); + bar = FemDesign.Reinforcement.Ptc.AddPtcToBar(bar, clonedPtc, true); + } + + Bars.BarStiffnessFactors stiffnessFactors = null; + if (DA.GetData(11, ref stiffnessFactors)) + { + bar.BarPart.StiffnessModifiers = new List() { stiffnessFactors }; + } + + string identifier = null; + if (DA.GetData(12, ref identifier)) + { + bar.Identifier = identifier; + } + + + // output + + // The following code is to convert 'item' to 'list object' + // It is required to construct the bar without graftening the data + var materialList = new List() { bar.BarPart.ComplexMaterialObj }; + + DA.SetData(0, bar); + DA.SetData(1, bar.Guid); + DA.SetData(2, bar.GetRhinoCurve()); + DA.SetDataList(3, materialList); + + if (bar.BarPart.ComplexSectionObj != null) + { + DA.SetDataList(4, bar.BarPart.ComplexSectionObj.Sections); + } + else if (bar.BarPart.HasComplexCompositeRef || bar.BarPart.HasDeltaBeamComplexSectionRef) + { + AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "The bar has a Composite Section. The object has not been implemented yet. Please, get in touch if needed."); + DA.SetDataList(4, null); + } + else if (bar.BarPart.Type == Bars.BarType.Truss) + { + var truss = new List { bar.BarPart.TrussUniformSectionObj }; + DA.SetDataList(4, truss); + } + else + { + DA.SetDataList(4, null); + } + + DA.SetDataList(5, bar.BarPart.Connectivity); + + var result = (bar.BarPart.ComplexSectionObj != null) ? bar.BarPart.ComplexSectionObj.Eccentricities : null; + DA.SetDataList(6, result); + + DA.SetData(7, bar.BarPart.LocalY.ToRhino()); + + List stirrupsOut = new List(); + List longBarOut = new List(); + foreach (Reinforcement.BarReinforcement reinf in bar.Reinforcement) + { + if (reinf.IsStirrups) + { + stirrupsOut.Add(new Reinforcement.StirrupReinforcement(reinf)); + } + else + { + longBarOut.Add(new Reinforcement.LongitudinalBarReinforcement(reinf)); + } + } + DA.SetDataList(8, stirrupsOut); + DA.SetDataList(9, longBarOut); + + + if ((bar.Type != FemDesign.Bars.BarType.Truss) && (bar.BarPart.ComplexSectionObj.Sections[0] != bar.BarPart.ComplexSectionObj.Sections[1]) && bar.Reinforcement.Any()) + { + AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "In FEM-Design, it is not possible to create reinforcement for bars with variable cross sections."); + } + + DA.SetDataList(10, bar.Ptc); + DA.SetData(11, bar.BarPart.StiffnessModifiers); + DA.SetData(12, bar.Name); + } + protected override System.Drawing.Bitmap Icon + { + get + { + return FemDesign.Properties.Resources.BarModify; + } + } + public override Guid ComponentGuid + { + get { return new Guid("3A6FD9BA-6EBB-4822-B1A8-B3E3E297ED99"); } + } + public override GH_Exposure Exposure => GH_Exposure.hidden; + + } +} \ No newline at end of file diff --git a/FemDesign.Grasshopper/FemDesign.Grasshopper.csproj b/FemDesign.Grasshopper/FemDesign.Grasshopper.csproj index 682b85bd..0eaa798d 100644 --- a/FemDesign.Grasshopper/FemDesign.Grasshopper.csproj +++ b/FemDesign.Grasshopper/FemDesign.Grasshopper.csproj @@ -69,6 +69,7 @@ Properties\GlobalAssemblyInfo.cs +