static void Main() { // PRACTICAL EXAMPLE: PARAMETRIC STUDY - SENSITIVITY ANALYSIS // In this example, we will analyse how different stiffness values on a support // will affect a bridge (modelled simply as a beam). // This example was last updated 2022-05-03, using the ver. 21.1.0 FEM-Design API. // FILE PATH SETUP // Set the different paths and folders relevant to the example string struxmlPath = "Bridge Model.struxml"; string bscPath = Path.GetFullPath("eigenfreq.bsc"); List <string> bscPaths = new List <string>(); bscPaths.Add(bscPath); // READ MODEL AND GET SUPPORTS Model model = Model.DeserializeFromFilePath(struxmlPath); //Read point support number and its stiffness properties var support1 = model.Entities.Supports.PointSupport.FirstOrDefault(p => p.Name == "S.1"); var support2 = model.Entities.Supports.PointSupport.FirstOrDefault(p => p.Name == "S.2"); double alpha = 0.5; // ITERATION AND ANALYSIS PROCESS // Iterate over model using different stiffness value for the the rotational spring cy int N = 20; for (int i = 1; i <= N; i++) { // Change stiffness of support cy support1.Rotations.YPos = Math.Pow(10, alpha); support1.Rotations.YNeg = Math.Pow(10, alpha); support2.Rotations.YPos = Math.Pow(10, alpha); support2.Rotations.YNeg = Math.Pow(10, alpha); var supports = new List <Supports.PointSupport>() { support1, support2 }; model.AddElements(supports); // Save struxml string outPathIndividual = Path.GetFullPath("Bridge Model_out" + Convert.ToString(alpha, System.Globalization.CultureInfo.InvariantCulture) + ".struxml"); model.SerializeModel(outPathIndividual); // Run analysis var freq = new Calculate.Freq(5, 0, false, false, true, -0.01); Calculate.Analysis analysis = new Calculate.Analysis(null, null, freq, null, true, false, false, false, false, false, true, false, false, false, false, false, false); FemDesign.Calculate.FdScript fdScript = FemDesign.Calculate.FdScript.Analysis(outPathIndividual, analysis, bscPaths, "", true); Calculate.Application app = new Calculate.Application(); app.RunFdScript(fdScript, false, true, true); // Read results from csv file (general method) { Console.WriteLine(""); Console.WriteLine(string.Format("Alpha: {0}", alpha)); string text = System.IO.File.ReadAllText(fdScript.CmdListGen[0].OutFile); Console.WriteLine(text); } alpha = alpha + 0.5; } // ENDING THE PROGRAM Console.WriteLine("\nPress any key to close console."); Console.ReadKey(); }
static void Main() { // EXAMPLE 2: ANALYSING A MODEL // This example will show you how to run an analyse // with a given model from within a C# script. // This example was last updated 2022-05-03, using the ver. 21.1.0 FEM-Design API. // LOADING UP THE MODEL string struxmlPath = "exbeam.struxml"; Model model = Model.DeserializeFromFilePath(struxmlPath); // SETUP BY LOAD CALCULATION SETTINGS // These settings are found in the FEM-Design calculation window. bool NLE = true; bool PL = true; bool NLS = false; bool Cr = false; bool _2nd = false; // SETTING UP LOAD COMBINATIONS // In this example, we use the same settings (CombItem) // for all load combinations, applied with a simple loop. var combItem = new FemDesign.Calculate.CombItem(0, 0, NLE, PL, NLS, Cr, _2nd); int numLoadCombs = model.Entities.Loads.LoadCombinations.Count; var combItems = new List <Calculate.CombItem>(); for (int i = 0; i < numLoadCombs; i++) { combItems.Add(combItem); } Calculate.Comb comb = new Calculate.Comb(); comb.CombItem = combItems.ToList(); // CHOOSING THE ANALYSIS SETTINGS // These dictate which calculations to run. FemDesign.Calculate.Analysis analysis = new FemDesign.Calculate.Analysis( stage: null, comb: comb, freq: null, footfall: null, calcCase: true, calcCStage: false, calcImpf: false, calcComb: true, calcGMax: false, calcStab: false, calcFreq: false, calcSeis: false, calcDesign: false, calcFootfall: false, elemFine: false, diaphragm: false, peakSmoothing: false ); // RUN THE ANALYSIS VIA AN FDSCRIPT var bscPath = new List <string> { @"C:\GitHub\femdesign-api\FemDesign.Examples\C#\Example 2 - Analysing a model\bin\Debug\pointsupportreactions.bsc" }; FemDesign.Calculate.FdScript fdScript = FemDesign.Calculate.FdScript.Analysis(Path.GetFullPath(struxmlPath), analysis, bscPath, "", true); Calculate.Application app = new Calculate.Application(); app.RunFdScript(fdScript, false, true, true); }
static void Main() { // PRACTICAL EXAMPLE: PARAMETRIC STUDY - REACTIONS // In this example, we will analyse how different E-modules will result // in different reaction forces in the supports holding a concrete plate. // This example was last updated 2022-05-03, using the ver. 21.1.0 FEM-Design API. // FILE PATH SETUP // Set the different paths and folders relevant to the example string struxmlPath = "sample_slab.struxml"; string outFolder = "output/"; if (!Directory.Exists(outFolder)) { Directory.CreateDirectory(outFolder); } string bscPath = Path.GetFullPath("pointsupportreactions.bsc"); List <string> bscPaths = new List <string>(); bscPaths.Add(bscPath); // READ MODEL Model model = Model.DeserializeFromFilePath(struxmlPath); // READ SLAB TO ANALYSE // In this example, the slab is card-coded to no. 5; if you make any personal applications, // it is probably better to look for a slab with a certain name, eg. P.1, to avoid confusion. Shells.Slab slab = model.Entities.Slabs[4]; Materials.Material material = model.Entities.Slabs[4].Material; double Ecm = Convert.ToDouble(material.Concrete.Ecm); // ITERATION & ANALYSIS PROCESS // Iterate over model using different E-modulus for the slab for (int i = 1; i < 6; i++) { // Change E-modulus double new_Ecm = Math.Round(0.2 * i * Ecm); material.Concrete.Ecm = Convert.ToString(new_Ecm); // Save struxml string outPathIndividual = Path.GetFullPath(outFolder + "sample_slab_out" + Convert.ToString(new_Ecm) + ".struxml"); model.SerializeModel(outPathIndividual); // Run analysis Calculate.Analysis analysis = new Calculate.Analysis(null, null, null, null, calcCase: true, false, false, false, false, false, false, false, false, false, false, false, false); FemDesign.Calculate.FdScript fdScript = FemDesign.Calculate.FdScript.Analysis(outPathIndividual, analysis, bscPaths, "", true); Calculate.Application app = new Calculate.Application(); app.RunFdScript(fdScript, false, true, true); string pointSupportReactionsPath = Path.Combine(outFolder, "pointsupportreactions.csv"); // Reading results (This method is only available for some result types as of now, but more will be added) var results = Results.ResultsReader.Parse(pointSupportReactionsPath); var pointSupportReactions = results.Cast <Results.PointSupportReaction>().ToList(); // Print results Console.WriteLine(); Console.WriteLine($"Emean: {new_Ecm}"); Console.WriteLine("Id | Reaction "); foreach (var reaction in pointSupportReactions) { Console.WriteLine($"{reaction.Id,10} | {reaction.Fz,10}"); } } // ENDING THE PROGRAM Console.WriteLine("\nPress any key to close console."); Console.ReadKey(); }