using StructureHelperCommon.Infrastructures.Exceptions; using StructureHelperCommon.Models; using StructureHelperCommon.Models.Calculators; namespace StructureHelperLogics.Models.BeamShears { internal class StirrupBySearchLogic : IBeamShearStrenghLogic { private ConcreteStrengthLogic concreteLogic; private StirrupStrengthLogic stirrupLogic; public IShiftTraceLogger? TraceLogger { get; set; } public IBeamShearSectionLogicInputData InputData { get; internal set; } public ISectionEffectiveness SectionEffectiveness { get; internal set; } public StirrupBySearchLogic(IShiftTraceLogger? traceLogger) { TraceLogger = traceLogger; } public double GetShearStrength() { double parameter = GetCrackLengthRatio(); BeamShearSectionLogicInputData newInputData = GetNewInputDataByCrackLengthRatio(parameter); TraceLogger?.AddMessage($"New value of dangerous inclinated crack has been obtained: start point Xstart = {newInputData.InclinedSection.StartCoord}(m), end point Xend = {newInputData.InclinedSection.EndCoord}(m)"); stirrupLogic = new(newInputData, TraceLogger); double stirrupStrength = stirrupLogic.GetShearStrength(); return stirrupStrength; } /// /// Calculates ratio of inclined crack length to inclined section length /// /// /// private double GetCrackLengthRatio() { var parameterCalculator = new FindParameterCalculator(); parameterCalculator.InputData.Predicate = GetPredicate; parameterCalculator.Accuracy.IterationAccuracy = 0.0001d; parameterCalculator.Accuracy.MaxIterationCount = 1000; parameterCalculator.Run(); if (parameterCalculator.Result.IsValid == false) { throw new StructureHelperException(ErrorStrings.DataIsInCorrect + $": predicate error"); } var result = parameterCalculator.Result as FindParameterResult; var crackLengthRatio = result.Parameter; while (GetPredicate(crackLengthRatio) == false) { crackLengthRatio += 0.0001; } crackLengthRatio = Math.Max(crackLengthRatio, 0); return crackLengthRatio; } /// /// Predicate of comparing of stirrup strength and concrete strength /// /// Ratio of inclined crack length and inclined section length /// Is true when stirrup strength is greate than concrete strength private bool GetPredicate(double crackLengthRatio) { BeamShearSectionLogicInputData newInputData = GetNewInputDataByCrackLengthRatio(crackLengthRatio); concreteLogic = new(SectionEffectiveness, newInputData.InclinedSection, null); stirrupLogic = new(newInputData, null); double concreteStrength = concreteLogic.GetShearStrength(); double stirrupStrength = stirrupLogic.GetShearStrength(); return stirrupStrength > concreteStrength; } private BeamShearSectionLogicInputData GetNewInputDataByCrackLengthRatio(double crackLengthRatio) { double sourceCrackLength = InputData.InclinedSection.EndCoord - InputData.InclinedSection.StartCoord; double newCrackLength = sourceCrackLength * crackLengthRatio; double newStartCoord = InputData.InclinedSection.EndCoord - newCrackLength; InclinedSection newSection = new(); var updateStrategy = new InclinedSectionUpdateStrategy(); updateStrategy.Update(newSection, InputData.InclinedSection); newSection.StartCoord = newStartCoord; BeamShearSectionLogicInputData newInputData = new(Guid.Empty) { InclinedSection = newSection, LimitState = InputData.LimitState, CalcTerm = InputData.CalcTerm, Stirrup = InputData.Stirrup, ForceTuple = InputData.ForceTuple }; return newInputData; } } }