/// <summary> /// This is the method that actually does the work. /// </summary> /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param> protected override void SolveInstance(IGH_DataAccess DA) { FemDesign.Results.FDfea fdFeaModel = null; DA.GetData("FdfeaModel", ref fdFeaModel); if (fdFeaModel == null) { return; } // Read Result from Abstract Method var result = FemDesign.Results.FeaNode.DeconstructFeaNode(fdFeaModel.FeaNode); var nodeId = (List <int>)result["NodeId"]; var feaNodePoint = (List <FemDesign.Geometry.FdPoint3d>)result["Position"]; // Convert the FdPoint to Rhino var ofeaNodePoint = feaNodePoint.Select(x => x.ToRhino()); // Set output DA.SetDataList("NodeId", nodeId); DA.SetDataList("Point", ofeaNodePoint); }
/// <summary> /// This is the method that actually does the work. /// </summary> /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param> protected override void SolveInstance(IGH_DataAccess DA) { FemDesign.Results.FDfea fdFeaModel = null; DA.GetData("FdFeaModel", ref fdFeaModel); if (fdFeaModel == null) { return; } // Read the Shell Result var result = FemDesign.Results.FeaShell.DeconstructFeaShell(fdFeaModel.FeaShell); // Extract the results from the Dictionary var id = (List <string>)result["Identifier"]; var elementId = (List <int>)result["ElementId"]; var feaShellFaces = (List <FemDesign.Geometry.Face>)result["Face"]; // Convert the FDface to Rhino var oFeaShellFaces = feaShellFaces.Select(x => x.ToRhino()); // Read the Node Results var nodeData = FemDesign.Results.FeaNode.DeconstructFeaNode(fdFeaModel.FeaNode); // Extract the results from the Dictionary var nodeId = (List <int>)nodeData["NodeId"]; var feaNodePoint = (List <FemDesign.Geometry.FdPoint3d>)nodeData["Position"]; // Create Rhino Mesh var rhinoPoint = feaNodePoint.Select(x => x.ToRhino()); var oMesh = new Rhino.Geometry.Mesh(); oMesh.Vertices.AddVertices(rhinoPoint); foreach (var obj in feaShellFaces) { if (obj.IsTriangle()) { oMesh.Faces.AddFace(obj.Node1 - 1, obj.Node2 - 1, obj.Node3 - 1); } else { oMesh.Faces.AddFace(obj.Node1 - 1, obj.Node2 - 1, obj.Node3 - 1, obj.Node4 - 1); } } // Set output DA.SetDataList("Identifier", id); DA.SetDataList("ElementId", elementId); DA.SetDataList("FaceIndex", oFeaShellFaces); DA.SetData("Mesh", oMesh); }
public static Dictionary <string, object> Deconstruct(FDfea FdFeaModel) { // Read Result from Abstract Method var result = FemDesign.Results.FeaNode.DeconstructFeaNode(FdFeaModel.FeaNode); var nodeId = (List <int>)result["NodeId"]; var feaNodePoint = (List <FemDesign.Geometry.FdPoint3d>)result["Position"]; // Convert the FdPoint to Rhino var ofeaNodePoint = feaNodePoint.Select(x => x.ToDynamo()); return(new Dictionary <string, object> { { "NodeId", nodeId }, { "Position", ofeaNodePoint } }); }
/// <summary> /// This is the method that actually does the work. /// </summary> /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param> protected override void SolveInstance(IGH_DataAccess DA) { FemDesign.Results.FDfea fdFeaModel = null; DA.GetData("FdFeaModel", ref fdFeaModel); if (fdFeaModel == null) { return; } // Read the Shell Result var result = FemDesign.Results.FeaBar.DeconstructFeaBar(fdFeaModel.FeaBar); // Extract the results from the Dictionary var id = (List <string>)result["Identifier"]; var elementId = (List <int>)result["ElementId"]; var nodei = (List <int>)result["Nodei"]; var nodej = (List <int>)result["Nodej"]; // clean Identifier List // some of the elements are null int i = 0; int j = 0; string currentId = null; var uniqueId = id.Where(x => x != "").ToList(); var identifier = new List <string>(); for (i = 0; i < id.Count(); i++) { if (id.ElementAt(i) != "") { identifier.Add(uniqueId.ElementAt(j)); currentId = uniqueId.ElementAt(j); j++; } else { identifier.Add(currentId); } } var lines = new List <Rhino.Geometry.LineCurve>(); for (i = 0; i < nodei.Count(); i++) { var posStartX = fdFeaModel.FeaNode.ElementAt(nodei.ElementAt(i) - 1).X; var posStartY = fdFeaModel.FeaNode.ElementAt(nodei.ElementAt(i) - 1).Y; var posStartZ = fdFeaModel.FeaNode.ElementAt(nodei.ElementAt(i) - 1).Z; var pointi = new Rhino.Geometry.Point3d(posStartX, posStartY, posStartZ); var posEndX = fdFeaModel.FeaNode.ElementAt(nodej.ElementAt(i) - 1).X; var posEndY = fdFeaModel.FeaNode.ElementAt(nodej.ElementAt(i) - 1).Y; var posEndZ = fdFeaModel.FeaNode.ElementAt(nodej.ElementAt(i) - 1).Z; var pointj = new Rhino.Geometry.Point3d(posEndX, posEndY, posEndZ); var line = new Rhino.Geometry.LineCurve(pointi, pointj); lines.Add(line); } var identifierTree = new DataTree <object>(); var nodeiTree = new DataTree <object>(); var nodejTree = new DataTree <object>(); var elementIdTree = new DataTree <object>(); var lineTree = new DataTree <object>(); i = 0; foreach (var ids in uniqueId) { identifierTree.Add(ids); var indexes = identifier.Select((value, index) => new { value, index }) .Where(a => string.Equals(a.value, ids)) .Select(a => a.index); foreach (int index in indexes) { //loadCasesTree.Add(loadCases.ElementAt(index), new GH_Path(i)); nodeiTree.Add(nodei.ElementAt(index), new GH_Path(i)); nodejTree.Add(nodej.ElementAt(index), new GH_Path(i)); elementIdTree.Add(elementId.ElementAt(index), new GH_Path(i)); lineTree.Add(lines.ElementAt(index), new GH_Path(i)); } i++; } // Set output DA.SetDataTree(0, identifierTree); DA.SetDataTree(1, elementIdTree); DA.SetDataTree(2, nodeiTree); DA.SetDataTree(3, nodejTree); DA.SetDataTree(4, lineTree); }
public static Dictionary <string, object> ReadStr(string strPath, List <Results.ResultType> resultTypes, Results.UnitResults units) { Results.FDfea fdFeaModel = null; // It needs to check if model has been runned // Always Return the FeaNode Result resultTypes.Insert(0, Results.ResultType.FeaNode); resultTypes.Insert(1, Results.ResultType.FeaBar); resultTypes.Insert(2, Results.ResultType.FeaShell); // Create Bsc files from resultTypes var bscPathsFromResultTypes = Calculate.Bsc.BscPathFromResultTypes(resultTypes, strPath, units); // Create FdScript var fdScript = FemDesign.Calculate.FdScript.ReadStr(strPath, bscPathsFromResultTypes); // Run FdScript var app = new FemDesign.Calculate.Application(); bool hasExited = app.RunFdScript(fdScript, false, true, false); // Read model and results var model = Model.DeserializeFromFilePath(fdScript.StruxmlPath); IEnumerable <Results.IResult> results = Enumerable.Empty <Results.IResult>(); List <Results.FeaNode> feaNodeRes = new List <Results.FeaNode>(); List <Results.FeaBar> feaBarRes = new List <Results.FeaBar>(); List <Results.FeaShell> feaShellRes = new List <Results.FeaShell>(); if (resultTypes != null && resultTypes.Any()) { foreach (var cmd in fdScript.CmdListGen) { string path = cmd.OutFile; try { if (path.Contains("FeaNode")) { feaNodeRes = Results.ResultsReader.Parse(path).Cast <Results.FeaNode>().ToList(); } else if (path.Contains("FeaBar")) { feaBarRes = Results.ResultsReader.Parse(path).Cast <Results.FeaBar>().ToList(); } else if (path.Contains("FeaShell")) { feaShellRes = Results.ResultsReader.Parse(path).Cast <Results.FeaShell>().ToList(); } else { var _results = Results.ResultsReader.Parse(path); results = results.Concat(_results); } } catch (Exception e) { throw new Exception(e.InnerException.Message); } } } fdFeaModel = new FemDesign.Results.FDfea(feaNodeRes, feaBarRes, feaShellRes); var resultGroups = results.GroupBy(t => t.GetType()).ToList(); // Convert Data in DataTree structure var resultsTree = new List <List <Results.IResult> >(); var i = 0; foreach (var resGroup in resultGroups) { resultsTree.Add(resGroup.ToList()); i++; } // Output return(new Dictionary <string, object> { { "Model", model }, { "FdFeaModel", fdFeaModel }, { "Results", results } }); }