Exemple #1
0
        public static List <string> BscPathFromResultTypes(IEnumerable <Results.ResultType> resultTypes, string strPath, Results.UnitResults units = null)
        {
            // Create Bsc files from resultTypes
            var listProcs = resultTypes.Select(r => Results.ResultAttributeExtentions.ListProcs[r]);


            var dir      = System.IO.Path.GetDirectoryName(strPath);
            var fileName = System.IO.Path.GetFileNameWithoutExtension(strPath);

            // Create \data folder to store output
            string dataDir = System.IO.Path.Combine(dir, fileName, "scripts");

            // If directory does not exist, create it
            if (!System.IO.Directory.Exists(dataDir))
            {
                System.IO.Directory.CreateDirectory(dataDir);
            }

            if (units == null)
            {
                units = Results.UnitResults.Default();
            }

            var batchResults            = listProcs.SelectMany(lp => lp.Select(l => new Calculate.Bsc(l, $"{dataDir}\\{l}.bsc", units)));
            var bscPathsFromResultTypes = batchResults.Select(bsc => bsc.BscPath).ToList();

            return(bscPathsFromResultTypes);
        }
Exemple #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 }
            });
        }