public static double[,] CalcAstr_s(SapFrameElement elem, double[] qsArr, int nbranches)
        {//astr (cross sectional area of one branch in mm2)
         // s(mm) must be (100 - 200 mm)
         // fy in N/mm2

            double AsMin_s240 = Math.Max(((elem.MyRectSec.B * 1000 * (0.4 / 240)) / nbranches), ((elem.MyRectSec.B * 1000 * (0.15 / 100)) / nbranches));
            double AsMin_s360 = Math.Max(((elem.MyRectSec.B * 1000 * (0.4 / 360)) / nbranches), ((elem.MyRectSec.B * 1000 * (0.10 / 100)) / nbranches));
            double AsMin_s400 = Math.Max(((elem.MyRectSec.B * 1000 * (0.4 / 400)) / nbranches), ((elem.MyRectSec.B * 1000 * (0.10 / 100)) / nbranches));


            double[,] Astr_s = new double[2, 3];
            for (int i = 0; i < Astr_s.GetLength(0) /*2*/; i++)
            {
                Astr_s[i, 0] = Math.Max((qsArr[i] * elem.MyRectSec.B * 1000) / (nbranches * (240 / 1.15)), AsMin_s240);
                Astr_s[i, 1] = Math.Max((qsArr[i] * elem.MyRectSec.B * 1000) / (nbranches * (360 / 1.15)), AsMin_s360);
                Astr_s[i, 2] = Math.Max((qsArr[i] * elem.MyRectSec.B * 1000) / (nbranches * (400 / 1.15)), AsMin_s400);
                if (qsArr[i] == -2)
                {
                    Astr_s[i, 0] = -2;
                    Astr_s[i, 1] = -2;
                    Astr_s[i, 2] = -2;
                }
            }
            return(Astr_s);
        }
        public static double[] getqsArr(SapFrameElement elem, double qcu, double qmax, double[] quArr /*applied shear stress*/)
        {//shear stress carried by stirrups in(N/mm2)
            double[] qsArr = new double[2];

            for (int i = 0; i < qsArr.Length; i++)
            {
                if (qcu >= quArr[i])
                {
                    //string s = "Use minimum stirrups";
                    //elem.FrameResults.ElementAt(0).StatusShear[i] = s;
                    qsArr[i] = -1; //use min stirrups(Y8@200mm)
                }
                else if (quArr[i] > qmax)
                {
                    //elem.FrameResults.ElementAt(0).StatusShear[i] = "increase Section Dims";
                    qsArr[i] = -2; //not safe
                }
                else
                {
                    double qsValue = elem.FrameResults.ElementAt(0).Qu[i] - (qcu / 2);
                    if (qsValue < 0)
                    {
                        qsValue = 0;
                    }
                    qsArr[i] = qsValue;
                    //elem.FrameResults.ElementAt(0).StatusShear[i] = "OK!";
                }
            }
            return(qsArr);
        }
        public static double[] ManualCalcAstr_s(SapFrameElement elem, double[] qsArr, int nbranches, double fystr)
        {//astr (cross sectional area of one branch in mm2)
            // s(mm) must be (100 - 200 mm)
            // fy in N/mm2
            double AsMin_s = 0;

            if (fystr == 240)
            {
                AsMin_s = Math.Max(((elem.MyRectSec.B * 1000 * (0.4 / fystr)) / nbranches), ((elem.MyRectSec.B * 1000 * (0.15 / 100)) / nbranches));
            }
            else if (fystr == 360 || fystr == 400)
            {
                AsMin_s = Math.Max(((elem.MyRectSec.B * 1000 * (0.4 / fystr)) / nbranches), ((elem.MyRectSec.B * 1000 * (0.10 / 100)) / nbranches));
            }
            double[] Astr_s = new double[2];
            for (int i = 0; i < Astr_s.Length; i++)
            {
                Astr_s[i] = Math.Max((qsArr[i] * elem.MyRectSec.B * 1000) / (nbranches * (fystr / 1.15)), AsMin_s);
                if (qsArr[i] == -2)
                {
                    Astr_s[i] = -2;
                }
            }
            return(Astr_s);
        }
        /*-------------------------------------Shear Design-------------------------------------*/
        public static double[] getS22Arr(SapFrameElement elem)
        {// applied shear force in KN (S22)
            double[] S22Arr = new double[2];

            S22Arr[0] = Math.Abs(elem.FrameResults.ElementAt(0).V2.First());
            S22Arr[1] = Math.Abs(elem.FrameResults.ElementAt(0).V2.Last());

            return(S22Arr);
        }
        public static double[] getquArr(SapFrameElement elem, double[] S22Arr)
        {// applied shear stress in N/mm2
            double[] quArr = new double[2];

            quArr[0] = (S22Arr[0] * 1000) / (elem.MyRectSec.B * 1000 * elem.MyRectSec.T * 1000);
            quArr[1] = (S22Arr[1] * 1000) / (elem.MyRectSec.B * 1000 * elem.MyRectSec.T * 1000);

            return(quArr);
        }
 public static double[] calcC(SapFrameElement elem, double[] c1Arr)
 {
     double[] cVals = new double[3]; //For Solving the Quadratic Equation
     for (int i = 0; i < cVals.Length; i++)
     {
         cVals[i] = 1 / (0.3573 * Math.Pow(c1Arr[i], 2));
     }
     return(cVals);
 }
 public static int[] CalcMaxNRebarinLayer(double[] diameters, SapFrameElement elem)
 {
     int[] maxnRebarInLayer = new int[diameters.Length];
     for (int i = 0; i < maxnRebarInLayer.Length; i++)
     {
         maxnRebarInLayer[i] = Convert.ToInt32(Math.Floor((elem.MyRectSec.B * 1000 + 0.25) / (diameters[i] + 25)));
     }
     return(maxnRebarInLayer);
 }
 public static double[] calcC1(SapFrameElement elem, double[] m33Arr /*KN.m*/, double cover /*mm*/, double fcu)
 {
     double[] c1Arr = new double[3];
     for (int i = 0; i < c1Arr.Length; i++)
     {
         c1Arr[i] = Math.Abs((elem.MyRectSec.T * 1000 - cover) / Math.Pow(((m33Arr[i] * 1000000 /*N.mm*/)
                                                                           / (fcu /*fcu N/mm2*/ * elem.MyRectSec.B * 1000)), 0.50));
     }
     return(c1Arr);
 }
        /*-------------------------------------Flexural Design-------------------------------------*/
        public static double[] getM33Arr(SapFrameElement elem)
        {
            double[] m33Arr = new double[3];
            m33Arr[0] = Math.Abs(elem.FrameResults.ElementAt(0).M3.First());
            m33Arr[1] = Math.Abs(elem.FrameResults.ElementAt(0).M3.Max());
            m33Arr[2] = Math.Abs(elem.FrameResults.ElementAt(0).M3.Last());


            return(m33Arr);
        }
 public static double[] calcJ(SapFrameElement elem, double[] cdArr, double[] c1Arr)
 {
     double[] jArr = new double[3];
     for (int i = 0; i < jArr.Length; i++)
     {
         if (c1Arr[i] >= 4.85)
         {
             jArr[i] = 0.826;
         }
         else
         {
             jArr[i] = (1 / 1.15) * (1 - 0.4 * cdArr[i]);
         }
     }
     return(jArr);
 }
        public static double[] calcCd(SapFrameElement elem, double[] cVals)
        {
            double[] cdArr = new double[3];
            for (int i = 0; i < cdArr.Length; i++)
            {
                double x = Math.Min(((1 + Math.Pow((1 - 4 * 0.40 * cVals[i]), 0.50)) / 0.80)
                                    , ((1 - Math.Pow((1 - 4 * 0.40 * cVals[i]), 0.50)) / 0.80));
                cdArr[i] = Math.Max(x, 0.125);

                //if (cdArr[i] > 0.44)
                //{
                //    cdArr[i] = 0.44;
                //}
            }
            return(cdArr);
        }
 public static double[] calcAs(SapFrameElement elem, double[] jArr, double[] c1Arr, double[] m33Arr, double cover, double fy, double fcu)
 {                                   // Flexural Steel Area
     double[] AsArr = new double[3]; //As in cm2
     for (int i = 0; i < AsArr.Length; i++)
     {
         double asValue;
         double asMin = (0.225 * (Math.Pow(fcu, 0.50) / fy) *
                         (elem.MyRectSec.B * 1000 * (elem.MyRectSec.T * 1000 - cover))) / 100;
         if (c1Arr[i] < 2.78) //if true, increase dimensions.
         {
             asValue = -1;    //increase dims
         }
         else
         {
             asValue = (((m33Arr[i]) * 1000000) / (fy * jArr[i] * (elem.MyRectSec.T * 1000 - cover))) / 100;
             if (asValue < asMin)
             {
                 asValue = asMin;
             }
         }
         AsArr[i] = asValue;
     }
     return(AsArr);
 }