Tsinuel_ESDS_1_0/SRC/ESADS.Mechanics.Design.Column/ESADS.Mechanics.Design.Column/eAs.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ESADS.Mechanics.Design.Column
{
    /// <summary>
    /// Represents Area of steel in a column containing all the neccessary properties required.
    /// </summary>
    public struct eAs
    {
        #region Fields

        private double As;
        private double Es;
        private double x;
        private double y;
        private double mx;
        private double Ns;
        private double my;
        private double z;
        private double h;
        private double b;
        private double nx;
        private double Ecc;
        private double Ecb;
        private eSteel S;
        private double m;
        private double c;
        private double teta;

        #endregion

        #region Constructors

        public eAs(double b, double h,double x, double y, double Ecc, double Ecb, eSteel steel)
        {
            this.b = b;
            this.h = h;
            this.S = steel;
            this.As = 0;
            this.Es = 0;
            this.x = x;
            this.y = y;
            this.mx = 0;
            this.Ns = 0;
            this.my = 0;
            this.z = 0;
            this.nx = 0;
            this.Ecc = Ecc;
            this.Ecb = Ecb;
            this.m = 0;
            this.c = 0;
            this.teta = 0;
        }

        #endregion

        #region Properties

        /// <summary>
        /// Gets or sets the area of the reinforcement.
        /// </summary>
        public double Area
        {
            get
            {
                return As;
            }
            set
            {
                As = value;
            }
        }

        /// <summary>
        /// Gets the strain in the steel.
        /// </summary>
        public double ES
        {
            get
            {
                return Es;
            }
        }

        /// <summary>
        /// Gets the force in the steel.
        /// </summary>
        public double NS
        {
            get
            {
                return Ns;
            }
        }

        /// <summary>
        /// Gets the moment generated by the steel with respect to centroid of the corss section in x direction..
        /// </summary>
        public double Mx
        {
            get
            {
                return mx;
            }
        }

        /// <summary>
        /// Gets the moment generated by the steel with respect to centroid of the corss section in y direction.
        /// </summary>
        public double My
        {
            get 
            { 
                return my; 
            }
        }

        /// <summary>
        /// Gets or sets the location of the centroid of the steel with respect to the centroid of the cross section in y-direction.
        /// </summary>
        public double Y
        {
            get
            {
                return y;
            }
            set
            {
                y = value;
            }
        }

        /// <summary>
        /// Gets or sets the location of the centroid of the steel with respect to the centroid of the cross section.
        /// </summary>
        public double X
        {
            get
            {
                return x;
            }
            set
            {
                x = value;
            }
        }

        #endregion

        #region Methods

        /// <summary>
        /// Fills all the properties of the steel for a given parameters.
        /// </summary>
        /// <param name="m">The slop the line which is used as nutral axis.</param>
        /// <param name="c">The Y-intercept of the line which is used as nutral axis.</param>
        /// <param name="x">Depth of nutral axis from top compresion fiber.</param>
        public void FillParameters(double x, double teta)
        {
            if (x == 0)
            {
                Es = 0;
                Ns = 0;
                my = 0;
                mx = 0;
                return;
            }
            this.nx = x;
            this.teta = teta;
            this.m = Math.Tan(this.teta);
            this.c = h / 2 + this.m * b / 2 - nx / Math.Cos(this.teta);
            FillZ();
            Es = z / nx * GetEcu();
            Ns = Math.Abs(Es )< S.εs ? S.E * Es * As : S.fyd * As * Math.Sign(Es);
            my = Ns * this.x;
            mx = Ns * this.y;
        }

        /// <summary>
        /// Fills the perpendicular depth from steel centoid upt to the nutral axis.
        /// </summary>
        private void FillZ()
        {
            if (teta == 0)
            {
                z = y - c;
                return;
            }
            if (Math.Round(teta, 12) == Math.Round(Math.PI / 2, 12))
            {
                z = b / 2 + x - nx;
                return;
            }
            double Xo = (y + x / m - c) / (m + 1 / m);
            double Dy = y - GetY( Xo);
            z = Math.Sqrt(Math.Pow(Xo - x, 2) + Math.Pow(Dy, 2)) * Math.Sign(Dy);
        }

        /// <summary>
        /// Returns the value of Y on the nutral axis for a given values of X.
        /// </summary>
        /// <param name="x">X location  with respect to the centroid of the the cross section.</param>
        /// <returns></returns>
        private double GetY(double x)
        {
            return m * x + c;
        }

        /// <summary>
        /// Returns the value of X on the nutral axis for a given values of Y.
        /// </summary>
        /// <param name="y">Y location  with respect to the centroid of the the cross section.</param>
        /// <returns></returns>
        private double GetX(double y)
        {
            if (Math.Round(teta, 12) == Math.Round(Math.PI / 2, 12))
                return nx - b / 2;
            return (y - c) / m;
        }

        /// <summary>
        /// Returns the strain in concrete.
        /// </summary>
        /// <returns></returns>
        private double GetEcu()
        {
            double hh;
            hh = b * Math.Sin(teta) + h * Math.Cos(teta);

            if (nx > hh)
                return Ecc * nx / (nx - 3 * hh / 7);
            else
                return Ecb;
        }

        /// <summary>
        /// Checks if the centroid of the steel is above 0.8 times the neutral axis(0.8*x).
        /// </summary>
        /// <returns>Returns true if it is above the neutral axis and false otherwise.</returns>
        public bool IsAboveNA()
        {
            if (x < GetX(y) && y > GetY(x))
                return true;
            else
                return false;
        }

        #endregion
    }
}
