コード例 #1
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            //
            string mode = null;

            FemDesign.Model model    = null;
            string          filePath = null;

            FemDesign.Calculate.Analysis analysis = null;
            FemDesign.Calculate.Design   design   = null;
            List <string> resultTypes             = new List <string>();
            string        docxTemplatePath        = "";
            bool          endSession       = false;
            bool          closeOpenWindows = false;
            bool          runNode          = false;


            // get data
            if (!DA.GetData(0, ref mode))
            {
                return;
            }
            if (!DA.GetData(1, ref model))
            {
                return;
            }
            if (!DA.GetData(2, ref filePath))
            {
                return;
            }
            if (!DA.GetData(3, ref analysis))
            {
                return;
            }
            if (!DA.GetData(4, ref design))
            {
                return;
            }
            if (!DA.GetDataList(5, resultTypes))
            {
                // pass
            }

            var units = Results.UnitResults.Default();

            DA.GetData(6, ref units);

            if (!DA.GetData(7, ref docxTemplatePath))
            {
                // pass
            }
            if (!DA.GetData(8, ref endSession))
            {
                // pass
            }
            if (!DA.GetData(9, ref closeOpenWindows))
            {
                // pass
            }
            if (!DA.GetData(10, ref runNode))
            {
                // pass
            }
            if (mode == null || model == null || filePath == null || analysis == null)
            {
                return;
            }

            // It needs to check if model has been runned
            // Always Return the FeaNode Result
            resultTypes.Insert(0, "FeaNode");
            resultTypes.Insert(1, "FeaBar");
            resultTypes.Insert(2, "FeaShell");


            var _resultTypes = resultTypes.Select(r => GenericClasses.EnumParser.Parse <Results.ResultType>(r));

            var bscPathsFromResultTypes = Calculate.Bsc.BscPathFromResultTypes(_resultTypes, filePath, units);

            bool rtn         = false;
            var  resultsTree = new DataTree <object>();

            Results.FDfea fdFeaModel = null;



            //
            if (runNode)
            {
                model.SerializeModel(filePath);
                analysis.SetLoadCombinationCalculationParameters(model);
                rtn = model.FdApp.RunDesign(mode, filePath, analysis, design, bscPathsFromResultTypes, docxTemplatePath, endSession, closeOpenWindows);


                // Create FdScript
                var fdScript = FemDesign.Calculate.FdScript.ReadStr(filePath, bscPathsFromResultTypes);

                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 i = 0;
                foreach (var resGroup in resultGroups)
                {
                    resultsTree.AddRange(resGroup.AsEnumerable(), new GH_Path(i));
                    i++;
                }
            }
            else
            {
                this.AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "RunNode is set to false!");
            }

            // Set output
            DA.SetData("FdModel", model);
            DA.SetData("FdFeaModel", fdFeaModel);
            DA.SetDataTree(2, resultsTree);
            DA.SetData(3, rtn);
        }
コード例 #2
0
        public static Dictionary <string, object> RunAnalysis(Model fdModel, string struxmlPath, Calculate.Analysis analysis, [DefaultArgument("[]")] List <Results.ResultType> resultTypes, [DefaultArgument("[]")] Results.UnitResults units, string docxTemplatePath = "", bool endSession = true, bool closeOpenWindows = false, bool runNode = true)
        {
            if (!runNode)
            {
                throw new System.ArgumentException("runNode is set to false!");
            }
            fdModel.SerializeModel(struxmlPath);
            analysis.SetLoadCombinationCalculationParameters(fdModel);

            units = Results.UnitResults.Default();
            // 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(1, Results.ResultType.FeaShell);

            // Create Bsc files from resultTypes
            var listProcs = resultTypes.Select(r => Results.ResultAttributeExtentions.ListProcs[r]);
            var bscPathsFromResultTypes = Calculate.Bsc.BscPathFromResultTypes(resultTypes, struxmlPath, units);
            var rtn = fdModel.FdApp.RunAnalysis(struxmlPath, analysis, bscPathsFromResultTypes, docxTemplatePath, endSession, closeOpenWindows);


            // Create FdScript
            var fdScript = FemDesign.Calculate.FdScript.ReadStr(struxmlPath, bscPathsFromResultTypes);

            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);
                    }
                }
            }

            var fdFeaModel = new FemDesign.Results.FDfea(feaNodeRes, feaBarRes, feaShellRes);

            var resultGroups = results.GroupBy(t => t.GetType()).ToList();

            // Convert Data in NestedList structure
            var resultsTree = new List <List <Results.IResult> >();
            var i           = 0;

            foreach (var resGroup in resultGroups)
            {
                resultsTree.Add(resGroup.ToList());
                i++;
            }

            return(new Dictionary <string, object>
            {
                { "FdModel", fdModel },
                { "FdFeaModel", fdFeaModel },
                { "Results", resultsTree },
                { "HasExited", rtn }
            });
        }
コード例 #3
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            // Get input
            string        filePath    = null;
            List <string> resultTypes = new List <string>();


            Results.FDfea fdFeaModel = null;

            DA.GetData("StrPath", ref filePath);
            if (filePath == null)
            {
                return;
            }
            DA.GetDataList("ResultTypes", resultTypes);

            bool runNode = true;

            if (!DA.GetData("RunNode", ref runNode))
            {
                // pass
            }

            // Units
            var units = Results.UnitResults.Default();

            DA.GetData("Units", ref units);

            // RunNode
            if (runNode)
            {
                // It needs to check if model has been runned
                // Always Return the FeaNode Result
                resultTypes.Insert(0, "FeaNode");
                resultTypes.Insert(1, "FeaBar");
                resultTypes.Insert(2, "FeaShell");


                var _resultTypes = resultTypes.Select(r => GenericClasses.EnumParser.Parse <Results.ResultType>(r));


                // Create Bsc files from resultTypes
                var bscPathsFromResultTypes = Calculate.Bsc.BscPathFromResultTypes(_resultTypes, filePath, units);

                // Create FdScript
                var fdScript = FemDesign.Calculate.FdScript.ReadStr(filePath, 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 DataTree <object>();

                var i = 0;
                foreach (var resGroup in resultGroups)
                {
                    resultsTree.AddRange(resGroup.AsEnumerable(), new GH_Path(i));
                    i++;
                }

                // Set output
                DA.SetData("FdModel", model);
                DA.SetData("FdFeaModel", fdFeaModel);
                DA.SetDataTree(2, resultsTree);
            }
            else
            {
                this.AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "RunNode is set to false!");
            }
        }
コード例 #4
0
ファイル: Model.cs プロジェクト: strusoft/femdesign-api
        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 }
            });
        }