public LocalAxisConduit(ProjectPlugIn projectPlugin) { _projectPlugIn = projectPlugin; }
public static void TestCalculation1() { ProjectPlugIn ppi = ProjectPlugIn.Instance; CrossSection cs = ppi.CurrentBeam.CrossSec; Random rand = new Random(); LoadCase lc = new SimpleLoadCase(0, 0, 0, ppi.CurrentBeam, "sampleLoadCase", Enumerates.LimitState.Ultimate); //Connect to excel Application oXL; Excel._Workbook oWB; Excel._Worksheet oSheet; try { //Start Excel and get Application object. try { oXL = (Excel.Application) System.Runtime.InteropServices.Marshal.GetActiveObject("Excel.Application"); } catch { oXL = new Application(); } LimitState ls = LimitState.Ultimate; oXL.Visible = true; //Get a new workbook. oWB = oXL.Workbooks.Add(); oXL.ScreenUpdating = false; oSheet = (Excel._Worksheet)oWB.ActiveSheet; oSheet.Cells[1, 1].Value = "n"; oSheet.Cells[1, 2].Value = "my"; oSheet.Cells[1, 3].Value = "mz"; oSheet.Cells[1, 4].Value = "iterations"; oSheet.Cells[1, 5].Value = "resets"; int[] iterationBoxes = Enumerable.Repeat(0, 10).ToArray(); int[] repeatBoxes = Enumerable.Repeat(0, 10).ToArray(); int iterationSpace = 10; int repeatSpace = 1; int failures = 0; for (int i = 0; i < 1000; i++) { int iterations = 0; int resets = 0; double topStrain = rand.NextDouble() * (0.01 + cs.ConcreteMaterial.Epscu1) + cs.ConcreteMaterial.Epscu1; double bottomStrain; if (topStrain < cs.ConcreteMaterial.Epsc2) { bottomStrain = rand.NextDouble() * (0.01); } else if (topStrain < 0) { bottomStrain = rand.NextDouble() * (0.01 + cs.ConcreteMaterial.Epsc2) + cs.ConcreteMaterial.Epsc2; } else { bottomStrain = rand.NextDouble() * (0.01 + cs.ConcreteMaterial.Epscu1) + cs.ConcreteMaterial.Epscu1; } double angle = Math.PI * rand.NextDouble(); Plane pl = Plane.WorldXY; pl.Rotate(angle, Vector3d.ZAxis); Point3d loading = cs.CalculateLoading(bottomStrain, topStrain, pl, ls); bool success = cs.CalculateStresses(loading.X, loading.Z, loading.Y, "sampleLoadCase", ref iterations, ref resets, ls); if (!success) { failures++; } oSheet.Cells[i + 2, 1].Value = loading.X; oSheet.Cells[i + 2, 2].Value = loading.Y; oSheet.Cells[i + 2, 3].Value = loading.Z; oSheet.Cells[i + 2, 4].Value = iterations; oSheet.Cells[i + 2, 5].Value = resets; oSheet.Cells[i + 2, 6].value = success; if (iterations / iterationSpace < 9) { iterationBoxes[iterations / iterationSpace]++; } else { iterationBoxes[9]++; } if (resets / repeatSpace < 9) { repeatBoxes[resets / repeatSpace]++; } else { repeatBoxes[9]++; } } oSheet.Range[oSheet.Cells[5, 8], oSheet.Cells[14, 8]].NumberFormat = "@"; oSheet.Cells[1, 8].Value = "failures"; oSheet.Cells[1, 9].Value = failures; oSheet.Cells[3, 8].Value = "Iterations"; oSheet.Cells[4, 8].Value = "Range"; oSheet.Cells[4, 9].Value = "Count"; for (int i = 0; i < iterationBoxes.Length; i++) { oSheet.Cells[i + 5, 8] = $"{i*iterationSpace}-{(i+1)*iterationSpace}"; oSheet.Cells[i + 5, 9] = iterationBoxes[i]; } Excel.Range r = oSheet.Range[oSheet.Cells[3, 8], oSheet.Cells[14, 9]]; //Creating chart for iterations Excel.ChartObjects xlCharts = (Excel.ChartObjects)oSheet.ChartObjects(Type.Missing); Excel.ChartObject myChart = xlCharts.Add(10, 80, 300, 250); Excel.Chart c = myChart.Chart; c.ChartType = Excel.XlChartType.xlColumnClustered; c.SetSourceData(r); oSheet.Range[oSheet.Cells[17, 8], oSheet.Cells[28, 8]].NumberFormat = "@"; oSheet.Cells[17, 8].Value = "Resets"; oSheet.Cells[18, 8].Value = "Range"; oSheet.Cells[18, 9].Value = "Count"; for (int i = 0; i < iterationBoxes.Length; i++) { oSheet.Cells[i + 19, 8] = $"{ i* repeatSpace}-{( i + 1 )* repeatSpace}"; oSheet.Cells[i + 19, 9] = repeatBoxes[i]; } r = oSheet.Range[oSheet.Cells[17, 8], oSheet.Cells[28, 9]]; myChart = xlCharts.Add(390, 80, 300, 250); c = myChart.Chart; c.ChartType = Excel.XlChartType.xlColumnClustered; c.SetSourceData(r); oXL.ScreenUpdating = true; } catch (Exception theException) { string errorMessage; errorMessage = "Error: "; errorMessage = string.Concat(errorMessage, theException.Message); errorMessage = string.Concat(errorMessage, " Line: "); errorMessage = string.Concat(errorMessage, theException.Source); MessageBox.Show(errorMessage, "Error"); } }
public static List <double> GetUtilizations(Classes_and_structures.Column col, List <int> memberNumbs) { //Create new Columns for each of the imported column foreach (int no in memberNumbs) { ProjectPlugIn.Instance.Beams.Add(col.ShallowCopy(no.ToString())); } List <double> utilzTot = new List <double>(); OpenConnection(); try { Dictionary <int, Tuple <int, double> > utilz = new Dictionary <int, Tuple <int, double> >(); foreach (int numb in memberNumbs) { utilz.Add(numb, Tuple.Create(0, 0.0)); } ICalculation calc = RModel.GetCalculation(); IModelData data = RModel.GetModelData(); ILoads loads = RModel.GetLoads(); LoadCombination[] lc = loads.GetLoadCombinations(); //int[] numbs = lc.Select(o => o.Loading.No).ToArray(); //numbs = Array.FindAll(numbs, o => o > 100 || o < 200); List <int> numbs = new List <int>() { 149, 150, 153, 154, 157, 158, 159, 160, 166 }; int k = 0; foreach (int number in numbs) { IResults res = calc.GetResultsInFeNodes(LoadingType.LoadCombinationType, number); MemberForces[] mfs = res.GetMembersInternalForces(true); ProjectPlugIn ppi = ProjectPlugIn.Instance; SimpleLoadCase slc; for (int i = 0; i < mfs.Length; i++) { if (memberNumbs.Contains(mfs[i].MemberNo)) { slc = new SimpleLoadCase(mfs[i].Forces.X, mfs[i].Moments.Z, mfs[i].Moments.Y, col, number.ToString(), LimitState.Ultimate); if (slc.Utilization > utilz[mfs[i].MemberNo].Item2) { utilz[mfs[i].MemberNo] = Tuple.Create(i, slc.Utilization); } } } foreach (int key in utilz.Keys) { Classes_and_structures.Column tempCol = (Classes_and_structures.Column)ProjectPlugIn.Instance.Beams .Find(o => o.Name == key.ToString()); tempCol.LoadCases.Add(new SimpleLoadCase(mfs[utilz[key].Item1].Forces.X, mfs[utilz[key].Item1].Moments.Z, mfs[utilz[key].Item1].Moments.Y, tempCol, number.ToString(), LimitState.Ultimate)); } mfs = null; k++; } foreach (int memberNo in memberNumbs) { Classes_and_structures.Column tempCol = (Classes_and_structures.Column)ProjectPlugIn.Instance.Beams .Find(o => o.Name == memberNo.ToString()); SimpleLoadCase[] temp = tempCol.LoadCases.Select(o => o as SimpleLoadCase).ToArray(); utilzTot.Add(temp.MaxBy(o => o.Utilization).Utilization); } } catch (Exception ex) { MessageBox.Show(ex.Message, ex.Source, MessageBoxButtons.OK, MessageBoxIcon.Error); //Cleans Garbage collector for releasing all COM interfaces and objects System.GC.Collect(); System.GC.WaitForPendingFinalizers(); } finally { CloseConnection(); } return(utilzTot); }