Пример #1
0
        /*
         * protected override void CalculateBoundingBox(CalculateBoundingBoxEventArgs e)
         * {
         *  base.CalculateBoundingBox(e);
         *  e.IncludeBoundingBox();
         * }
         */
        protected override void PostDrawObjects(DrawEventArgs e)
        {
            base.PreDrawObjects(e);

            var xColor = Rhino.ApplicationSettings.AppearanceSettings.GridXAxisLineColor;
            var yColor = Rhino.ApplicationSettings.AppearanceSettings.GridYAxisLineColor;
            var zColor = Rhino.ApplicationSettings.AppearanceSettings.GridZAxisLineColor;

            e.Display.EnableDepthWriting(false);
            e.Display.EnableDepthTesting(false);

            if (_projectPlugIn.CurrentBeam != null)
            {
                Beam beam = _projectPlugIn.CurrentBeam;

                Point3d     c      = beam.CrossSec.Centroid();
                BoundingBox bb     = beam.CrossSec.GetBoundingBox(Plane.WorldXY);
                double      length = bb.Diagonal.Length;

                //Create neutral axis
                int index = beam.LoadCases.FindIndex(o => o.IsDisplayed);
                if (index != -1)
                {
                    SimpleLoadCase slc      = (SimpleLoadCase)beam.LoadCases[index];
                    Point3d        p        = slc.NeutralAxis.Origin;
                    Plane          pl       = slc.NeutralAxis;
                    Point3d        startPt  = p - pl.XAxis * length / 2;
                    double         distance = new Vector3d((p + pl.XAxis * length / 2) - (p - pl.XAxis * length / 2)).Length;
                    int            totNum   = 20;

                    List <Line> ll = new List <Line>();
                    for (int i = 0; i < totNum; i = i + 2)
                    {
                        ll.Add(new Line(startPt + pl.XAxis * distance * (i) / totNum, startPt + pl.XAxis * distance * (i + 1) / totNum));
                    }

                    ll.ToArray();

                    Plane textPlane = new Plane(pl);
                    textPlane.Translate(new Vector3d(pl.XAxis * length / 1.9));
                    e.Display.DrawArrow(new Line(c, pl.ZAxis * length / 12), xColor);
                    e.Display.DrawArrow(new Line(c, pl.YAxis * length / 12), yColor);
                    e.Display.DrawArrow(new Line(c, pl.XAxis * length / 12), zColor);
                    e.Display.DrawLines(ll, System.Drawing.Color.Aquamarine);
                    e.Display.Draw3dText(new Text3d("N.A", textPlane, length / 30), System.Drawing.Color.Aquamarine);
                }
            }

            e.Display.EnableDepthWriting(false);
            e.Display.EnableDepthTesting(false);
        }
        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);
        }
Пример #4
0
        private void CalculateStresses()
        {
            var watch = System.Diagnostics.Stopwatch.StartNew();
            // the code that you want to measure comes here

            LimitState ls = GetLimitState();

            bool r;

            try
            {
                LoadCase lc;
                if (_projectPlugIn.CurrentBeam.LoadCases.TrueForAll(o => o.Name != "SampleLoadCase"))
                {
                    lc = new SimpleLoadCase(double.Parse(textBoxForce.Text) * 1000, double.Parse(textBoxMz.Text) * 1000
                                            , double.Parse(textBoxMy.Text) * 1000, _projectPlugIn.CurrentBeam, "SampleLoadCase", ls);
                    _projectPlugIn.CurrentBeam.LoadCases.Add(lc);
                }
                else
                {
                    int i = _projectPlugIn.CurrentBeam.LoadCases.FindIndex(o => o.Name == "SampleLoadCase");
                    lc    = _projectPlugIn.CurrentBeam.LoadCases[i];
                    lc.Ls = ls;
                }

                r = _projectPlugIn.CurrentBeam.CrossSec.CalculateStresses(double.Parse(textBoxForce.Text) * 1000,
                                                                          double.Parse(textBoxMz.Text) * 1000, double.Parse(textBoxMy.Text) * 1000, "SampleLoadCase", ls);

                if (r)
                {
                    if (radioButtonSteel.Checked)
                    {
                        _projectPlugIn.CurrentBeam.CrossSec.CreateResultDisplay(true, lc);
                    }
                    else
                    {
                        _projectPlugIn.CurrentBeam.CrossSec.CreateResultDisplay(false, lc);
                    }
                    //brepsAndStrains.ForEach(o => RhinoDoc.ActiveDoc.Objects.AddBrep(o.Item1));

                    textBox_cs_min.Enabled = true;
                    textBox_cs_max.Enabled = true;
                    textBox_cs_min.Text    = (Math.Round(_projectPlugIn.CurrentBeam.CrossSec.MinAndMaxStress.Item1 * Math.Pow(10, -6), 0)).ToString();
                    textBox_cs_max.Text    = (Math.Round(_projectPlugIn.CurrentBeam.CrossSec.MinAndMaxStress.Item2 * Math.Pow(10, -6), 0)).ToString();

                    //Turns on local axis

                    lc.IsDisplayed = true;
                    checkBoxShowStresses.Checked   = true;
                    checkBoxShowCrackWidth.Checked = true;
                    ShowStressResults(true);
                }

                RhinoDoc.ActiveDoc.Views.Redraw();
                watch.Stop();
                var elapsedMs = watch.ElapsedMilliseconds;
                RhinoApp.WriteLine("Time elapsed:" + elapsedMs.ToString() + "ms");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, ex.Source, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            //}
        }