/***************************************************/ /**** Private Methods ****/ /***************************************************/ private int DeleteLines(IEnumerable <object> ids) { int success = 1; if (ids != null) { List <int> indicies = ids.Cast <int>().ToList(); foreach (int index in indicies) { IFLine lusasLine = d_LusasData.getLineByNumber(index); if (lusasLine.getHOFs().Count() > 0) { //Engine.Base.Compute.RecordWarning(index + @" has higher order features(HOFs) //and cannot be deleted"); } else { d_LusasData.Delete(lusasLine); } } } else { d_LusasData.deleteLines(); } return(success); }
/***************************************************/ /**** Private Methods ****/ /***************************************************/ private static Edge GetEdge(IFSurface lusasSurf, int lineIndex, Dictionary <string, Edge> bars) { Edge edge; IFLine lusasEdge = lusasSurf.getLOFs()[lineIndex]; bars.TryGetValue(lusasEdge.getID().ToString(), out edge); return(edge); }
/***************************************************/ /**** Private Methods ****/ /***************************************************/ private static Node GetNode(IFLine lusasLine, int nodeIndex, Dictionary <string, Node> nodes) { Node node; IFPoint lusasPoint = lusasLine.getLOFs()[nodeIndex]; nodes.TryGetValue(lusasPoint.getID().ToString(), out node); return(node); }
/***************************************************/ /**** Private Methods ****/ /***************************************************/ private List <ILoad> ReadBarUniformTemperatureLoads(List <string> ids = null) { List <ILoad> barUniformTemperatureLoads = new List <ILoad>(); object[] lusasTemperatureLoads = d_LusasData.getAttributes("Temperature"); if (!(lusasTemperatureLoads.Count() == 0)) { List <Bar> barsList = ReadBars(); Dictionary <string, Bar> bars = barsList.ToDictionary( x => x.AdapterId <string>(typeof(LusasId))); List <IFLoadcase> allLoadcases = new List <IFLoadcase>(); for (int i = 0; i < lusasTemperatureLoads.Count(); i++) { IFLoading lusasTemperatureLoad = (IFLoading)lusasTemperatureLoads[i]; IEnumerable <IGrouping <string, IFAssignment> > groupedByLoadcases = GetLoadAssignments(lusasTemperatureLoad); foreach (IEnumerable <IFAssignment> groupedAssignment in groupedByLoadcases) { List <IFAssignment> assignments = new List <IFAssignment>(); foreach (IFAssignment assignment in groupedAssignment) { IFLine tryLine = assignment.getDatabaseObject() as IFLine; if (tryLine != null) { assignments.Add(assignment); } } List <string> analysisName = new List <string> { lusasTemperatureLoad.getAttributeType() }; if (assignments.Count != 0) { BarUniformTemperatureLoad barUniformTemperatureLoad = Adapter.Adapters.Lusas.Convert.ToBarUniformTemperatureLoad( lusasTemperatureLoad, groupedAssignment, bars); barUniformTemperatureLoad.Tags = new HashSet <string>(analysisName); barUniformTemperatureLoads.Add(barUniformTemperatureLoad); } } } } return(barUniformTemperatureLoads); }
/***************************************************/ /**** Private Methods ****/ /***************************************************/ private IFLocalCoord CreateLocalCoordinate(IFLine lusasLine) { object lineXAxis = null; object lineYAxis = null; object lineZAxis = null; object origin = null; lusasLine.getAxesAtNrmCrds(0, ref origin, ref lineXAxis, ref lineYAxis, ref lineZAxis); double[] localXAxis = Adapters.Lusas.Convert.ToDouble(lineXAxis); double[] localYAxis = Adapters.Lusas.Convert.ToDouble(lineYAxis); double[] localZAxis = Adapters.Lusas.Convert.ToDouble(lineZAxis); IF3dCoords barStart = lusasLine.getStartPositionCoords(); double[] worldXAxis = new double[] { 1, 0, 0 }; double[] worldYAxis = new double[] { 0, 1, 0 }; double[] worldZAxis = new double[] { 0, 0, 1 }; double[] barorigin = new double[] { barStart.getX(), barStart.getY(), barStart.getZ() }; double[] matrixCol0 = new double[] { worldXAxis.Zip(localXAxis, (d1, d2) => d1 * d2).Sum(), worldYAxis.Zip(localXAxis, (d1, d2) => d1 * d2).Sum(), worldZAxis.Zip(localXAxis, (d1, d2) => d1 * d2).Sum(), }; double[] matrixCol1 = new double[] { worldXAxis.Zip(localYAxis, (d1, d2) => d1 * d2).Sum(), worldYAxis.Zip(localYAxis, (d1, d2) => d1 * d2).Sum(), worldZAxis.Zip(localYAxis, (d1, d2) => d1 * d2).Sum(), }; double[] matrixCol2 = new double[] { worldXAxis.Zip(localZAxis, (d1, d2) => d1 * d2).Sum(), worldYAxis.Zip(localZAxis, (d1, d2) => d1 * d2).Sum(), worldZAxis.Zip(localZAxis, (d1, d2) => d1 * d2).Sum(), }; string lusasName = "L" + lusasLine.getID().ToString() + "/ Local Axis"; IFLocalCoord barLocalAxis = d_LusasData.createLocalCartesianAttr( lusasName, barorigin, matrixCol0, matrixCol1, matrixCol2); return(barLocalAxis); }
/***************************************************/ private bool CreateCollection(IEnumerable <Bar> bars) { if (bars != null) { CreateTags(bars); if (bars.Any(x => x.Fragments.Contains(typeof(MeshSettings1D)))) { var barGroups = bars.GroupBy(m => new { m.FEAType, m.Release?.Name }); BHoMObjectNameComparer comparer = new BHoMObjectNameComparer(); ReduceRuntime(true); foreach (var barGroup in barGroups) { List <MeshSettings1D> distinctMeshes = barGroup.Select(x => x.FindFragment <MeshSettings1D>()) .Distinct <MeshSettings1D>(comparer) .ToList(); foreach (MeshSettings1D mesh in distinctMeshes) { CreateMeshSettings1D(mesh, barGroup.First().FEAType, barGroup.First().Release); } foreach (Bar bar in barGroup) { bar.AddFragment(distinctMeshes.First(x => comparer.Equals(x, bar.FindFragment <MeshSettings1D>())), true); IFLine lusasLine = CreateLine(bar); } } ReduceRuntime(false); d_LusasData.resetMesh(); d_LusasData.updateMesh(); } else { ReduceRuntime(true); foreach (Bar bar in bars) { IFLine lusasLine = CreateLine(bar); } ReduceRuntime(false); } } return(true); }
public List <List <double[]> > getSurfaceCoordinatesFromLusas() { IFSelection userInp = lusas.getSelection(); //check if selection is at least one point if (userInp.countSurfaces() < 1) { MessageBox.Show("please select at least one point", "", MessageBoxButtons.OK); return(null); } //create collection to popoulate surfaces List <List <double[]> > surfaces = new List <List <double[]> >(); for (int i = 0; i < userInp.countSurfaces(); i++) { //gereate array of ids List <int> pointIds = new List <int>(); //generate collection for populating vertices List <double[]> vertexes = new List <double[]>(); IFSurface surface = userInp.getSurface(i); object[] lines = surface.getLOFs() as object[]; for (int l = 0; l < lines.Length; l++) { IFLine line = lines[l] as IFLine; object[] points = line.getLOFs() as object[]; for (int k = 0; k < points.Length; k++) { IFPoint point = points[k] as IFPoint; int id = point.getID(); if (!pointIds.Contains(id)) { pointIds.Add(id); double[] position = new double[3]; position[0] = point.getX(); position[1] = point.getY(); position[2] = point.getZ(); //point.getXYZ(position[0],position[1],position[2]); vertexes.Add(position); } } } surfaces.Add(vertexes); } return(surfaces); }
/***************************************************/ /**** Private Methods ****/ /***************************************************/ private List <Bar> ReadBars(List <string> ids = null) { object[] lusasLines = d_LusasData.getObjects("Line"); List <Bar> bars = new List <Bar>(); if (!(lusasLines.Count() == 0)) { IEnumerable <Node> nodesList = ReadNodes(); Dictionary <string, Node> nodes = nodesList.ToDictionary( x => x.AdapterId <string>(typeof(LusasId))); IEnumerable <Constraint4DOF> supportsList = Read4DOFConstraints(); Dictionary <string, Constraint4DOF> supports = supportsList.ToDictionary( x => x.Name); IEnumerable <IMaterialFragment> materialList = ReadMaterials(); Dictionary <string, IMaterialFragment> materials = materialList.ToDictionary( x => x.Name.ToString()); IEnumerable <ISectionProperty> sectionPropertiesList = ReadSectionProperties(); Dictionary <string, ISectionProperty> sectionProperties = sectionPropertiesList.ToDictionary( x => x.Name.ToString()); List <MeshSettings1D> meshesList = ReadMeshSettings1D(); Dictionary <string, MeshSettings1D> meshes = meshesList.ToDictionary( x => x.Name.ToString()); HashSet <string> groupNames = ReadTags(); for (int i = 0; i < lusasLines.Count(); i++) { IFLine lusasLine = (IFLine)lusasLines[i]; Bar bar = Adapters.Lusas.Convert.ToBar ( lusasLine, nodes, supports, groupNames, materials, sectionProperties, meshes ); bars.Add(bar); } } return(bars); }
/***************************************************/ /**** Private Methods ****/ /***************************************************/ private IFLine CreateEdge(Edge edge, IFPoint startPoint, IFPoint endPoint) { IFLine lusasLine = d_LusasData.createLineByPoints(startPoint, endPoint); int adapterIdName = lusasLine.getID(); edge.SetAdapterId(typeof(LusasId), adapterIdName); if (!(edge.Tags.Count == 0)) { AssignObjectSet(lusasLine, edge.Tags); } if (!(edge.Support == null)) { IFAttribute lusasSupport = d_LusasData.getAttribute("Support", edge.Support.AdapterId <int>(typeof(LusasId))); lusasSupport.assignTo(lusasLine); } return(lusasLine); }
/***************************************************/ /**** Private Methods ****/ /***************************************************/ private static IEnumerable <Bar> GetLineAssignments(IEnumerable <IFAssignment> lusasAssignments, Dictionary <string, Bar> bars) { List <Bar> assignedBars = new List <Bar>(); Bar bar; foreach (IFAssignment lusasAssignment in lusasAssignments) { if (lusasAssignment.getDatabaseObject() is IFLine) { IFLine lusasLine = (IFLine)lusasAssignment.getDatabaseObject(); bars.TryGetValue(lusasLine.getID().ToString(), out bar); assignedBars.Add(bar); } else { AssignmentWarning(lusasAssignment); } } return(assignedBars); }
/***************************************************/ /**** Private Methods ****/ /***************************************************/ public static Tuple <bool, double, BarRelease, BarFEAType> GetMeshProperties(IFLine lusasLine) { bool meshAssigned = true; double betaAngle = 0; BarRelease barRelease = null; BarFEAType barType = BarFEAType.Flexural; object[] meshAssignments = lusasLine.getAssignments("Mesh"); if (meshAssignments.Length > 0) { foreach (object assignment in meshAssignments) { IFAssignment lusasAssignment = (IFAssignment)assignment; IFAttribute lusasMesh = lusasAssignment.getAttribute(); IFMeshLine lusasLineMesh = (IFMeshLine)lusasMesh; betaAngle = lusasAssignment.getBetaAngle(); barRelease = GetBarRelease(lusasLineMesh); object[] barMeshName = lusasLineMesh.getElementNames(); foreach (object type in barMeshName) { barType = GetFEAType(type); } } } else { meshAssigned = false; } Tuple <bool, double, BarRelease, BarFEAType> lineMeshProperties = new Tuple <bool, double, BarRelease, BarFEAType>(meshAssigned, betaAngle, barRelease, barType); return(lineMeshProperties); }
/***************************************************/ /**** Private Methods ****/ /***************************************************/ private List <Edge> ReadEdges(List <string> ids = null) { object[] lusasLines = d_LusasData.getObjects("Line"); List <Edge> edges = new List <Edge>(); if (lusasLines.Count() != 0) { List <Node> nodesList = ReadNodes(); Dictionary <string, Node> nodes = nodesList.ToDictionary( x => x.AdapterId <string>(typeof(LusasId))); HashSet <string> groupNames = ReadTags(); for (int i = 0; i < lusasLines.Count(); i++) { IFLine lusasLine = (IFLine)lusasLines[i]; Edge edge = Adapters.Lusas.Convert.ToEdge(lusasLine, nodes, groupNames); edges.Add(edge); } } return(edges); }
/***************************************************/ /**** Public Methods ****/ /***************************************************/ public static Edge ToEdge(this IFLine lusasLine, Dictionary <string, Node> nodes, HashSet <string> groupNames) { Node startNode = GetNode(lusasLine, 0, nodes); Node endNode = GetNode(lusasLine, 1, nodes); Point startPoint = startNode.Position; Point endPoint = endNode.Position; HashSet <string> tags = new HashSet <string>(IsMemberOf(lusasLine, groupNames)); Line line = new Line { Start = startPoint, End = endPoint }; Edge edge = new Edge { Curve = line, Tags = tags }; string adapterID = lusasLine.getID().ToString(); edge.SetAdapterId(typeof(LusasId), adapterID); return(edge); }
/***************************************************/ /**** Private Methods ****/ /***************************************************/ private IFLine CreateLine(Bar bar) { if (!CheckPropertyError(bar, b => b.StartNode, true) || !CheckPropertyError(bar, b => b.EndNode, true) || !CheckPropertyError(bar, b => b.StartNode.Position, true) || !CheckPropertyError(bar, b => b.EndNode.Position, true)) { return(null); } if ( bar.FEAType == BarFEAType.CompressionOnly || bar.FEAType == BarFEAType.TensionOnly) { Engine.Base.Compute.RecordError("Lusas does not support " + bar.FEAType.ToString() + " Bars"); return(null); } string startNodeId = GetAdapterId <string>(bar.StartNode); string endNodeId = GetAdapterId <string>(bar.EndNode); if (string.IsNullOrEmpty(startNodeId) || string.IsNullOrEmpty(endNodeId)) { Engine.Base.Compute.RecordError("Could not find the ids for at least one end node for at least one Bar. Bar not created."); return(null); } IFPoint startPoint = d_LusasData.getPointByNumber(bar.StartNode.AdapterId <int>(typeof(LusasId))); IFPoint endPoint = d_LusasData.getPointByNumber(bar.EndNode.AdapterId <int>(typeof(LusasId))); IFLine lusasLine = d_LusasData.createLineByPoints(startPoint, endPoint); int adapterIdName = lusasLine.getID(); bar.SetAdapterId(typeof(LusasId), adapterIdName); if (bar.Tags.Count != 0) { AssignObjectSet(lusasLine, bar.Tags); } if (CheckPropertyWarning(bar, b => b.SectionProperty) && !Engine.Adapters.Lusas.Query.InvalidSectionProperty(bar.SectionProperty)) { if (!Engine.Adapters.Lusas.Query.InvalidSectionProfile(bar.SectionProperty)) { //Needed in case the SectionProfile is null and was not created if (d_LusasData.existsAttribute("Line Geometric", bar.SectionProperty.AdapterId <int>(typeof(LusasId)))) { IFAttribute lusasGeometricLine = d_LusasData.getAttribute("Line Geometric", bar.SectionProperty.AdapterId <int>(typeof(LusasId))); lusasGeometricLine.assignTo(lusasLine); } if (CheckPropertyWarning(bar, b => b.SectionProperty.Material)) { if (bar.SectionProperty.Material is IOrthotropic) { Engine.Base.Compute.RecordWarning($"Orthotropic Material {bar.SectionProperty.Material.DescriptionOrName()} cannot be assigned to Bar {bar.AdapterId<int>(typeof(LusasId))}, " + $"orthotropic materials can only be applied to 2D and 3D elements in Lusas."); } else if (bar.SectionProperty.Material is IIsotropic) { if (d_LusasData.existsAttribute("Material", bar.SectionProperty.Material.AdapterId <int>(typeof(LusasId)))) { IFAttribute lusasMaterial = d_LusasData.getAttribute("Material", bar.SectionProperty.Material.AdapterId <int>(typeof(LusasId))); lusasMaterial.assignTo(lusasLine); } } } } } if (bar.Support != null) { IFAttribute lusasSupport = d_LusasData.getAttribute("Support", System.Convert.ToInt32(bar.Support.AdapterId <int>(typeof(LusasId)))); lusasSupport.assignTo(lusasLine); IFLocalCoord barLocalAxis = CreateLocalCoordinate(lusasLine); barLocalAxis.assignTo(lusasLine); } if (bar.Fragments.Contains(typeof(MeshSettings1D))) { IFAssignment meshAssignment = m_LusasApplication.newAssignment(); meshAssignment.setAllDefaults(); if (bar.OrientationAngle != 0 && bar.FEAType == BarFEAType.Axial) { Engine.Base.Compute.RecordWarning( "Orientation angle not supported in Lusas for " + bar.FEAType + " element types, this information will be lost when pushed to Lusas"); } meshAssignment.setBetaAngle(bar.OrientationAngle); MeshSettings1D meshSettings1D = bar.FindFragment <MeshSettings1D>(); IFMeshAttr mesh = d_LusasData.getMesh( meshSettings1D.Name + "\\" + bar.FEAType.ToString() + "|" + CreateReleaseString(bar.Release)); mesh.assignTo(lusasLine, meshAssignment); } if (bar.Offset != null) { Engine.Base.Compute.RecordWarning("Offsets are currently unsupported."); } return(lusasLine); }
/***************************************************/ private bool CreateCollection(IEnumerable <Edge> edges) { if (edges != null) { List <Point> allPoints = new List <Point>(); //Check List<Curve> is not null and Curve is not invalid (i.e. not a Line) List <Edge> validEdges = edges.Where(x => CheckPropertyError(x, y => y.Curve)) .Where(x => !Engine.Adapters.Lusas.Query.InvalidEdge(x)).ToList(); List <Edge> distinctEdges = new List <Edge>(); //Check Curve is not a null foreach (Edge edge in validEdges) { if (!(edge.Curve == null)) { distinctEdges.Add(edge); } } distinctEdges = Engine.Adapters.Lusas.Query.GetDistinctEdges(distinctEdges); foreach (Edge edge in distinctEdges) { allPoints.Add(edge.Curve.IStartPoint()); allPoints.Add(edge.Curve.IEndPoint()); } List <Point> distinctPoints = Engine.Adapters.Lusas.Query.GetDistinctPoints(allPoints); List <Point> existingPoints = ReadPoints(); List <Point> pointsToPush = distinctPoints.Except( existingPoints, new PointDistanceComparer()).ToList(); ReduceRuntime(true); foreach (Point point in pointsToPush) { IFPoint lusasPoint = CreatePoint(point); } ReduceRuntime(false); List <IFPoint> lusasPoints = ReadLusasPoints(); List <Point> points = new List <Point>(); foreach (IFPoint point in lusasPoints) { points.Add(Adapters.Lusas.Convert.ToPoint(point)); } CreateTags(distinctEdges); ReduceRuntime(true); foreach (Edge edge in distinctEdges) { IFPoint startPoint = lusasPoints[points.FindIndex( m => m.Equals(edge.Curve.IStartPoint().ClosestPoint(points)))]; IFPoint endPoint = lusasPoints[points.FindIndex( m => m.Equals(edge.Curve.IEndPoint().ClosestPoint(points)))]; IFLine lusasLine = CreateEdge(edge, startPoint, endPoint); } ReduceRuntime(false); } return(true); }
/***************************************************/ /**** Public Methods ****/ /***************************************************/ public static Bar ToBar(this IFLine lusasLine, Dictionary <string, Node> nodes, Dictionary <string, Constraint4DOF> supports, HashSet <string> lusasGroups, Dictionary <string, IMaterialFragment> materials, Dictionary <string, ISectionProperty> sections, Dictionary <string, MeshSettings1D> meshes ) { Node startNode = GetNode(lusasLine, 0, nodes); Node endNode = GetNode(lusasLine, 1, nodes); HashSet <string> tags = new HashSet <string>(IsMemberOf(lusasLine, lusasGroups)); List <string> supportAssignments = GetAttributeAssignments(lusasLine, "Support"); Constraint4DOF barConstraint = null; if (!(supportAssignments.Count() == 0)) { supports.TryGetValue(supportAssignments[0], out barConstraint); } Bar bar = new Bar { StartNode = startNode, EndNode = endNode, Tags = tags, Support = barConstraint }; List <string> geometricAssignments = GetAttributeAssignments(lusasLine, "Geometric"); List <string> materialAssignments = GetAttributeAssignments(lusasLine, "Material"); IMaterialFragment lineMaterial; ISectionProperty lineSection; if (!(geometricAssignments.Count() == 0)) { sections.TryGetValue(geometricAssignments[0], out lineSection); if (lineSection != null) { if (!(materialAssignments.Count() == 0)) { materials.TryGetValue(materialAssignments[0], out lineMaterial); if (lineMaterial != null) { lineSection.Material = lineMaterial; } } bar.SectionProperty = lineSection; } } MeshSettings1D lineMesh; List <string> meshSettings = GetAttributeAssignments(lusasLine, "Mesh"); if (!(meshSettings.Count() == 0)) { meshes.TryGetValue(meshSettings[0], out lineMesh); bar.Fragments.Add(lineMesh); } Tuple <bool, double, BarRelease, BarFEAType> barMeshProperties = GetMeshProperties(lusasLine); if (barMeshProperties.Item1) { bar.OrientationAngle = barMeshProperties.Item2; bar.Release = barMeshProperties.Item3; bar.FEAType = barMeshProperties.Item4; } string adapterID = lusasLine.getID().ToString(); bar.SetAdapterId(typeof(LusasId), adapterID); return(bar); }