using FeMM.Common.Models;
using FeMM.Grasshopper.Components.Parameters;
using FeMM.Grasshopper.DataTypes;
using FeMM.Grasshopper.DataTypes.MeCheck2;
using FeMM.Grasshopper.Helpers;
using Grasshopper.Kernel;
using Maffeis.Checkers.Concrete.Attributes;
using Maffeis.Checkers.Concrete.Checkers;
using Maffeis.Checkers.Concrete.SectionSolvers;
using Maffeis.Geometry;
using Maffeis.Model.Materials;
using Maffeis.Model.Sections.Concrete;
using Maffeis.Model.Standards;
using System;
using System.Linq;

namespace FeMM.Grasshopper.Components.MeCheck2
{
    public class CompositeBeamSelfTensionComponent : GH_Component
    {
        /// <summary>
        /// Initializes a new instance of the MeshRemap class.
        /// </summary>
        public CompositeBeamSelfTensionComponent()
          : base("Composite Section Self Tension", "CSST", "Composite Section Linear Tension Analysis", CategoryNameConstants.CATEGORY_CHECKS, CategoryNameConstants.SUBCATEGORY_MECHECK2)
        {
        }

        /// <summary>
        /// Registers all the input parameters for this component.
        /// </summary>
        protected override void RegisterInputParams(GH_InputParamManager pManager)
        {
            pManager.AddGenericParameter("Composite Beam Property", "CBP", "Composite Section Property", GH_ParamAccess.item);
            pManager.AddNumberParameter("Homogenization coefficient", "HC", "Load homogenization coefficient for load case", GH_ParamAccess.item, 0);
            pManager.AddNumberParameter("Strain", "ε", "The strain applicated to the concrete slab", GH_ParamAccess.item, 0);
        }

        /// <summary>
        /// Registers all the output parameters for this component.
        /// </summary>
        protected override void RegisterOutputParams(GH_OutputParamManager pManager)
        {
            pManager.AddParameter(new StressAnalysisResultMeCheckParam(), "Result", "R", "Analysis results", GH_ParamAccess.item);
        }

        /// <summary>
        /// This is the method that actually does the work.
        /// </summary>
        /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param>
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            GH_CompositeBeamProperty gH_CompositeBeamProperty = null;
            double n = 0;
            double strain = 0;

            if (!DA.GetData(0, ref gH_CompositeBeamProperty))
                return;
            if (!DA.GetData(1, ref n))
                return;
            if (!DA.GetData(2, ref strain))
                return;

            CompositeBeamPropertyModel compositeBeamPropertyModel = gH_CompositeBeamProperty.Value;
            ReinforcedConcreteSection reinforcedConcreteSection = compositeBeamPropertyModel.GetReinforcedConcreteSection();

            double phi = ReinforcedConcreteSection.CalculateHomogenizedFactorPhi(n, reinforcedConcreteSection.SteelSections.First().Section.SteelMaterial, reinforcedConcreteSection.ConcreteMaterial);
            var cs = GetCoordinateSystem(reinforcedConcreteSection, phi);

            var options = new SectionCheckerModelCode2010.SectionOptionsModelCode2010(cs,
                SectionSolver.FailureAnalysisTypes.ConstantN, SectionSolver.FailureDomainTypes.Plastic, SectionSolver.StressAnalysisTypes.Linear, phi, 0, false, 64, true);

            var standardEC2 = new StandardEN1992p11();
            var standardEC3 = new StandardEN1993p11();

            var sectionCheckerAttribute = new SectionCheckerAttribute(reinforcedConcreteSection, null, null);
            var sectionCheckerMC2010 = new SectionCheckerModelCode2010(sectionCheckerAttribute, options, standardEC2, false, -1, standardEC3);

            var result = sectionCheckerMC2010.GetSelfTension(strain, phi);

            DA.SetData(0, new GH_StressAnalysisResultMeCheck(result.MeCheckResults));
        }

        protected static CoordinateSystem GetCoordinateSystem(ReinforcedConcreteSection reinforcedConcreteSection, double phi)
        {
            return new CoordinateSystem(reinforcedConcreteSection.GetHomogenizedCentroid(phi, out double _, out double _), new Vector3d(-1, 0, 0), new Vector3d(0, -1, 0));
        }

        public override GH_Exposure Exposure => GH_Exposure.secondary;

        /// <summary>
        /// Provides an Icon for the component.
        /// </summary>
        protected override System.Drawing.Bitmap Icon => Properties.Resources.AutoTensionIcon;

        /// <summary>
        /// Gets the unique ID for this component. Do not change this ID after release.
        /// </summary>
        public override Guid ComponentGuid => new("a25576bf-e159-401c-a355-b54060b57471");
    }
}
303 files24 directories