From 0a453c5a957f8f266b2e532be896d253e71a5b2c Mon Sep 17 00:00:00 2001 From: Evgeny Redikultsev Date: Fri, 8 Mar 2024 17:16:00 +0500 Subject: [PATCH] Force calculator was repaired for buckling calculations --- .../UI/Resources/ButtonStyles.xaml | 14 +++ .../CalculatorsViews/CrackDiagramLogic.cs | 29 +++-- .../ForceResultLogic/LabelsFactory.cs | 8 +- .../ForceResultLogic/ShowDiagramLogic.cs | 57 +++++----- .../ShowValuePointDiagramLogic.cs | 87 ++++++++++++++- .../ForcesResultsView.xaml | 20 ++-- .../ForcesResultsViewModel.cs | 18 +-- .../Windows/UserControls/MultiplyDouble.xaml | 22 +++- .../Infrastructures/Exceptions/ErrorString.cs | 2 + .../Interfaces/ILongProcessLogic.cs | 4 +- .../Models/Loggers/LoggerStrings.cs | 3 + .../Models/Parameters/ArrayParameter.cs | 1 + .../Logics/AccidentalEccentricityLogic.cs | 11 +- .../Services/Units/CommonOperation.cs | 22 +++- .../Analyses/ByForces/ForceCalculator.cs | 104 ++++++++++++------ .../Analyses/ByForces/ForceTupleCalculator.cs | 31 +++--- .../Buckling/ConcreteBucklingCalculator.cs | 51 +++++---- .../Services/TraceService.cs | 44 ++++++++ 18 files changed, 382 insertions(+), 146 deletions(-) create mode 100644 StructureHelperLogics/Services/TraceService.cs diff --git a/StructureHelper/Infrastructure/UI/Resources/ButtonStyles.xaml b/StructureHelper/Infrastructure/UI/Resources/ButtonStyles.xaml index 90a84a8..deaeb92 100644 --- a/StructureHelper/Infrastructure/UI/Resources/ButtonStyles.xaml +++ b/StructureHelper/Infrastructure/UI/Resources/ButtonStyles.xaml @@ -51,6 +51,20 @@ + diff --git a/StructureHelper/Windows/CalculationWindows/CalculatorsViews/CrackDiagramLogic.cs b/StructureHelper/Windows/CalculationWindows/CalculatorsViews/CrackDiagramLogic.cs index 9b681d9..b514987 100644 --- a/StructureHelper/Windows/CalculationWindows/CalculatorsViews/CrackDiagramLogic.cs +++ b/StructureHelper/Windows/CalculationWindows/CalculatorsViews/CrackDiagramLogic.cs @@ -61,21 +61,27 @@ namespace StructureHelper.Windows.CalculationWindows.CalculatorsViews public void ShowCracks() { - var unitForce = CommonOperation.GetUnit(UnitTypes.Force, "kN"); - var unitMoment = CommonOperation.GetUnit(UnitTypes.Moment, "kNm"); - var unitCurvature = CommonOperation.GetUnit(UnitTypes.Curvature, "1/m"); - - List labels = GetCrackLabels(unitForce, unitMoment, unitCurvature); - arrayParameter = new ArrayParameter(ValidTupleList.Count(), labels.Count(), labels); - CalculateWithCrack(ValidTupleList, NdmPrimitives, unitForce, unitMoment, unitCurvature); + List labels = GetCrackLabels(); + arrayParameter = new ArrayParameter(ValidTupleList.Count(), labels); + CalculateWithCrack(ValidTupleList, + NdmPrimitives, + CommonOperation.GetUnit(UnitTypes.Force), + CommonOperation.GetUnit(UnitTypes.Moment), + CommonOperation.GetUnit(UnitTypes.Curvature)); } public void ShowWindow() { SafetyProcessor.RunSafeProcess(() => { - var series = new Series(arrayParameter) { Name = "Forces and curvatures" }; - var vm = new GraphViewModel(new List() { series }); + var series = new Series(arrayParameter) + { + Name = "Forces and curvatures" + }; + var vm = new GraphViewModel(new List() + { + series + }); var wnd = new GraphView(vm); wnd.ShowDialog(); }, @@ -132,11 +138,12 @@ namespace StructureHelper.Windows.CalculationWindows.CalculatorsViews } } - private static List GetCrackLabels(IUnit unitForce, IUnit unitMoment, IUnit unitCurvature) + private static List GetCrackLabels() { const string crc = "Crc"; const string crcFactor = "CrcSofteningFactor"; - var labels = LabelsFactory.GetLabels(); + var labels = LabelsFactory.GetCommonLabels(); + IUnit unitCurvature = CommonOperation.GetUnit(UnitTypes.Curvature); var crclabels = new List { $"{crc}{GeometryNames.CurvFstName}, {unitCurvature.Name}", diff --git a/StructureHelper/Windows/CalculationWindows/CalculatorsViews/ForceCalculatorViews/ForceResultLogic/LabelsFactory.cs b/StructureHelper/Windows/CalculationWindows/CalculatorsViews/ForceCalculatorViews/ForceResultLogic/LabelsFactory.cs index 2e4827b..db6552e 100644 --- a/StructureHelper/Windows/CalculationWindows/CalculatorsViews/ForceCalculatorViews/ForceResultLogic/LabelsFactory.cs +++ b/StructureHelper/Windows/CalculationWindows/CalculatorsViews/ForceCalculatorViews/ForceResultLogic/LabelsFactory.cs @@ -11,11 +11,11 @@ namespace StructureHelper.Windows.CalculationWindows.CalculatorsViews { public static class LabelsFactory { - private static IUnit unitForce = CommonOperation.GetUnit(UnitTypes.Force, "kN"); - private static IUnit unitMoment = CommonOperation.GetUnit(UnitTypes.Moment, "kNm"); - private static IUnit unitCurvature = CommonOperation.GetUnit(UnitTypes.Curvature, "1/m"); + private static IUnit unitForce = CommonOperation.GetUnit(UnitTypes.Force); + private static IUnit unitMoment = CommonOperation.GetUnit(UnitTypes.Moment); + private static IUnit unitCurvature = CommonOperation.GetUnit(UnitTypes.Curvature); private static GeometryNames GeometryNames => ProgramSetting.GeometryNames; - public static List GetLabels() + public static List GetCommonLabels() { var labels = new List { diff --git a/StructureHelper/Windows/CalculationWindows/CalculatorsViews/ForceCalculatorViews/ForceResultLogic/ShowDiagramLogic.cs b/StructureHelper/Windows/CalculationWindows/CalculatorsViews/ForceCalculatorViews/ForceResultLogic/ShowDiagramLogic.cs index 8a8dc12..8e42820 100644 --- a/StructureHelper/Windows/CalculationWindows/CalculatorsViews/ForceCalculatorViews/ForceResultLogic/ShowDiagramLogic.cs +++ b/StructureHelper/Windows/CalculationWindows/CalculatorsViews/ForceCalculatorViews/ForceResultLogic/ShowDiagramLogic.cs @@ -1,6 +1,7 @@ using StructureHelper.Windows.Graphs; using StructureHelper.Windows.ViewModels.Errors; using StructureHelperCommon.Infrastructures.Enums; +using StructureHelperCommon.Infrastructures.Exceptions; using StructureHelperCommon.Infrastructures.Interfaces; using StructureHelperCommon.Infrastructures.Settings; using StructureHelperCommon.Models; @@ -17,12 +18,12 @@ namespace StructureHelper.Windows.CalculationWindows.CalculatorsViews.ForceCalcu { internal class ShowDiagramLogic : ILongProcessLogic { - ArrayParameter arrayParameter; - private IEnumerable TupleList; - private IEnumerable NdmPrimitives; - private List ValidTupleList; + private ArrayParameter arrayParameter; + private IEnumerable tupleList; + private IEnumerable ndmPrimitives; + private List validTupleList; - public int StepCount => ValidTupleList.Count(); + public int StepCount => validTupleList.Count(); public Action SetProgress { get; set; } public bool Result { get; set; } @@ -48,37 +49,33 @@ namespace StructureHelper.Windows.CalculationWindows.CalculatorsViews.ForceCalcu SafetyProcessor.RunSafeProcess(() => { var series = new Series(arrayParameter) { Name = "Forces and curvatures" }; - var vm = new GraphViewModel(new List() { series}); + var vm = new GraphViewModel(new List() { series }); var wnd = new GraphView(vm); wnd.ShowDialog(); - }, - "Errors appeared during showing a graph, see detailed information"); + }, ErrorStrings.ErrorDuring("building chart")); } private void Show() { - ValidTupleList = TupleList.Where(x => x.IsValid == true).ToList(); - var unitForce = CommonOperation.GetUnit(UnitTypes.Force, "kN"); - var unitMoment = CommonOperation.GetUnit(UnitTypes.Moment, "kNm"); - var unitCurvature = CommonOperation.GetUnit(UnitTypes.Curvature, "1/m"); + validTupleList = tupleList.Where(x => x.IsValid == true).ToList(); - var labels = LabelsFactory.GetLabels(); - arrayParameter = new ArrayParameter(ValidTupleList.Count(), labels.Count(), labels); - CalculateWithoutCrack(ValidTupleList, unitForce, unitMoment, unitCurvature); + var labels = LabelsFactory.GetCommonLabels(); + arrayParameter = new ArrayParameter(validTupleList.Count(), labels); + Calculate(); } public ShowDiagramLogic(IEnumerable tupleList, IEnumerable ndmPrimitives) { - TupleList = tupleList; - NdmPrimitives = ndmPrimitives; - ValidTupleList = TupleList.Where(x => x.IsValid == true).ToList(); + this.tupleList = tupleList; + this.ndmPrimitives = ndmPrimitives; + validTupleList = tupleList.Where(x => x.IsValid == true).ToList(); } - private void CalculateWithoutCrack(List resultList, IUnit unitForce, IUnit unitMoment, IUnit unitCurvature) + private void Calculate() { var data = arrayParameter.Data; - for (int i = 0; i < resultList.Count(); i++) + for (int i = 0; i < validTupleList.Count(); i++) { - var valueList = ProcessResultWithouCrack(resultList, unitForce, unitMoment, unitCurvature, i); + var valueList = ProcessResult(i); for (int j = 0; j < valueList.Count; j++) { data[i, j] = valueList[j]; @@ -88,16 +85,20 @@ namespace StructureHelper.Windows.CalculationWindows.CalculatorsViews.ForceCalcu } - private static List ProcessResultWithouCrack(List resultList, IUnit unitForce, IUnit unitMoment, IUnit unitCurvature, int i) + private List ProcessResult(int i) { + var unitForce = CommonOperation.GetUnit(UnitTypes.Force); + var unitMoment = CommonOperation.GetUnit(UnitTypes.Moment); + var unitCurvature = CommonOperation.GetUnit(UnitTypes.Curvature); + return new List { - resultList[i].DesignForceTuple.ForceTuple.Mx * unitMoment.Multiplyer, - resultList[i].DesignForceTuple.ForceTuple.My * unitMoment.Multiplyer, - resultList[i].DesignForceTuple.ForceTuple.Nz * unitForce.Multiplyer, - resultList[i].LoaderResults.ForceStrainPair.StrainMatrix.Kx * unitCurvature.Multiplyer, - resultList[i].LoaderResults.ForceStrainPair.StrainMatrix.Ky * unitCurvature.Multiplyer, - resultList[i].LoaderResults.ForceStrainPair.StrainMatrix.EpsZ + validTupleList[i].DesignForceTuple.ForceTuple.Mx * unitMoment.Multiplyer, + validTupleList[i].DesignForceTuple.ForceTuple.My * unitMoment.Multiplyer, + validTupleList[i].DesignForceTuple.ForceTuple.Nz * unitForce.Multiplyer, + validTupleList[i].LoaderResults.ForceStrainPair.StrainMatrix.Kx * unitCurvature.Multiplyer, + validTupleList[i].LoaderResults.ForceStrainPair.StrainMatrix.Ky * unitCurvature.Multiplyer, + validTupleList[i].LoaderResults.ForceStrainPair.StrainMatrix.EpsZ }; } } diff --git a/StructureHelper/Windows/CalculationWindows/CalculatorsViews/ForceCalculatorViews/ForceResultLogic/ShowValuePointDiagramLogic.cs b/StructureHelper/Windows/CalculationWindows/CalculatorsViews/ForceCalculatorViews/ForceResultLogic/ShowValuePointDiagramLogic.cs index 8332973..f527fcc 100644 --- a/StructureHelper/Windows/CalculationWindows/CalculatorsViews/ForceCalculatorViews/ForceResultLogic/ShowValuePointDiagramLogic.cs +++ b/StructureHelper/Windows/CalculationWindows/CalculatorsViews/ForceCalculatorViews/ForceResultLogic/ShowValuePointDiagramLogic.cs @@ -1,21 +1,102 @@ -using StructureHelper.Windows.Forces; +using StructureHelper.Infrastructure.UI.DataContexts; +using StructureHelper.Services.ResultViewers; +using StructureHelper.Windows.Forces; +using StructureHelper.Windows.Graphs; +using StructureHelper.Windows.ViewModels.Errors; +using StructureHelperCommon.Infrastructures.Exceptions; +using StructureHelperCommon.Infrastructures.Interfaces; +using StructureHelperCommon.Models; +using StructureHelperCommon.Models.Parameters; +using StructureHelperCommon.Models.Shapes; using StructureHelperLogics.NdmCalculations.Analyses.ByForces; +using StructureHelperLogics.NdmCalculations.Primitives; using System; using System.Collections.Generic; +using System.ComponentModel; using System.Linq; using System.Text; using System.Threading.Tasks; namespace StructureHelper.Windows.CalculationWindows.CalculatorsViews { - public class ShowValuePointDiagramLogic + public class ShowValuePointDiagramLogic : ILongProcessLogic { + private ArrayParameter arrayParameter; + private IEnumerable tupleList; + private IEnumerable ndmPrimitives; + private List validTupleList; + private List<(PrimitiveBase PrimitiveBase, List>)> valuePoints; + private List resultFuncList; + public ForceCalculator Calculator { get; set; } public PointPrimitiveLogic PrimitiveLogic { get; set; } public ValueDelegatesLogic ValueDelegatesLogic { get; set; } - public void ShowGraph() + + public int StepCount => throw new NotImplementedException(); + + public Action SetProgress { get; set; } + public bool Result { get; set; } + public IShiftTraceLogger? TraceLogger { get; set; } + public ShowValuePointDiagramLogic(IEnumerable tupleList, IEnumerable ndmPrimitives) + { + this.tupleList = tupleList; + this.ndmPrimitives = ndmPrimitives; + validTupleList = this.tupleList.Where(x => x.IsValid == true).ToList(); + valuePoints = new List<(PrimitiveBase PrimitiveBase, List>)>(); + foreach (var item in PrimitiveLogic.Collection.CollectionItems) + { + var pointsCount = item.Item.ValuePoints.SelectedCount; + if (pointsCount > 0) + { + var points = item.Item.ValuePoints.SelectedItems.ToList(); + var primitive = item.Item.PrimitiveBase; + valuePoints.Add((primitive, points)); + } + } + } + public void ShowWindow() + { + SafetyProcessor.RunSafeProcess(() => + { + var series = new Series(arrayParameter) + { + Name = "Forces and curvatures" + }; + var vm = new GraphViewModel(new List() + { + series + }); + var wnd = new GraphView(vm); + wnd.ShowDialog(); + }, ErrorStrings.ErrorDuring("building chart")); + } + + public void WorkerDoWork(object sender, DoWorkEventArgs e) + { + Show(); + Result = true; + } + + public void WorkerProgressChanged(object sender, ProgressChangedEventArgs e) + { + //Nothing to do + } + + public void WorkerRunWorkCompleted(object sender, RunWorkerCompletedEventArgs e) + { + //Nothing to do + } + + private void Show() { } + + private List GetColumnNames() + { + var columnNames = LabelsFactory.GetCommonLabels(); + + return columnNames; + } } } diff --git a/StructureHelper/Windows/CalculationWindows/CalculatorsViews/ForceCalculatorViews/ForcesResultsView.xaml b/StructureHelper/Windows/CalculationWindows/CalculatorsViews/ForceCalculatorViews/ForcesResultsView.xaml index 2d6bd83..4b48b33 100644 --- a/StructureHelper/Windows/CalculationWindows/CalculatorsViews/ForceCalculatorViews/ForcesResultsView.xaml +++ b/StructureHelper/Windows/CalculationWindows/CalculatorsViews/ForceCalculatorViews/ForcesResultsView.xaml @@ -10,20 +10,20 @@ - - - - - diff --git a/StructureHelper/Windows/CalculationWindows/CalculatorsViews/ForceCalculatorViews/ForcesResultsViewModel.cs b/StructureHelper/Windows/CalculationWindows/CalculatorsViews/ForceCalculatorViews/ForcesResultsViewModel.cs index 6008109..cac1378 100644 --- a/StructureHelper/Windows/CalculationWindows/CalculatorsViews/ForceCalculatorViews/ForcesResultsViewModel.cs +++ b/StructureHelper/Windows/CalculationWindows/CalculatorsViews/ForceCalculatorViews/ForcesResultsViewModel.cs @@ -176,8 +176,7 @@ namespace StructureHelper.Windows.CalculationWindows.CalculatorsViews.ForceCalcu }; showProgressLogic.Show(); } - }, o => SelectedResult != null && SelectedResult.IsValid - ); + }, o => SelectedResult != null); } public ICommand ShowCrackGraphsCommand { @@ -282,11 +281,16 @@ namespace StructureHelper.Windows.CalculationWindows.CalculatorsViews.ForceCalcu private void InterpolateValuePoints() { + if (SelectedResult is null) + { + throw new StructureHelperException(ErrorStrings.NullReference + ": Nothing is selected"); + } + var tuple = SelectedResult.DesignForceTuple ?? throw new StructureHelperException(ErrorStrings.NullReference + ": Design force combination"); var inputData = new ValuePointsInterpolationInputData() { - FinishDesignForce = SelectedResult.DesignForceTuple.Clone() as IDesignForceTuple, - LimitState = SelectedResult.DesignForceTuple.LimitState, - CalcTerm = SelectedResult.DesignForceTuple.CalcTerm, + FinishDesignForce = tuple.Clone() as IDesignForceTuple, + LimitState = tuple.LimitState, + CalcTerm = tuple.CalcTerm, }; inputData.PrimitiveBases.AddRange(PrimitiveOperations.ConvertNdmPrimitivesToPrimitiveBase(ndmPrimitives)); var viewModel = new ValuePointsInterpolateViewModel(inputData); @@ -294,7 +298,7 @@ namespace StructureHelper.Windows.CalculationWindows.CalculatorsViews.ForceCalcu wnd.ShowDialog(); if (wnd.DialogResult != true) { return; } var interpolationLogic = new InterpolationProgressLogic(forceCalculator, viewModel.ForceInterpolationViewModel.Result); - ShowValuePointDiagramLogic pointGraphLogic = new() + ShowValuePointDiagramLogic pointGraphLogic = new(ForcesResults.ForcesResultList, ndmPrimitives) { Calculator = interpolationLogic.InterpolateCalculator, PrimitiveLogic = viewModel.PrimitiveLogic, @@ -303,7 +307,7 @@ namespace StructureHelper.Windows.CalculationWindows.CalculatorsViews.ForceCalcu progressLogic = interpolationLogic; showProgressLogic = new(interpolationLogic) { - ShowResult = pointGraphLogic.ShowGraph + ShowResult = pointGraphLogic.ShowWindow }; showProgressLogic.Show(); } diff --git a/StructureHelper/Windows/UserControls/MultiplyDouble.xaml b/StructureHelper/Windows/UserControls/MultiplyDouble.xaml index d505bde..032e96e 100644 --- a/StructureHelper/Windows/UserControls/MultiplyDouble.xaml +++ b/StructureHelper/Windows/UserControls/MultiplyDouble.xaml @@ -6,7 +6,27 @@ xmlns:local="clr-namespace:StructureHelper.Windows.UserControls" mc:Ignorable="d" d:DesignHeight="25" d:DesignWidth="120"> - + + + + + + + + + + + + + + + + + diff --git a/StructureHelperCommon/Infrastructures/Exceptions/ErrorString.cs b/StructureHelperCommon/Infrastructures/Exceptions/ErrorString.cs index ed940fd..a0491f4 100644 --- a/StructureHelperCommon/Infrastructures/Exceptions/ErrorString.cs +++ b/StructureHelperCommon/Infrastructures/Exceptions/ErrorString.cs @@ -25,5 +25,7 @@ public static string ExpectedWas(System.Type expected, object obj) => ExpectedWas(expected, obj.GetType()); public static string NullReference => "#0018: Null reference"; public static string ObjectNotFound => "#0018: Object not found"; + public static string ErrorDuring(string operation) => string.Format("Errors appeared during {0}, see detailed information", operation); + public static string CalculationError => "#0019: Error of calculation"; } } diff --git a/StructureHelperCommon/Infrastructures/Interfaces/ILongProcessLogic.cs b/StructureHelperCommon/Infrastructures/Interfaces/ILongProcessLogic.cs index e255ccf..75819c6 100644 --- a/StructureHelperCommon/Infrastructures/Interfaces/ILongProcessLogic.cs +++ b/StructureHelperCommon/Infrastructures/Interfaces/ILongProcessLogic.cs @@ -10,14 +10,12 @@ using System.Windows.Forms; namespace StructureHelperCommon.Infrastructures.Interfaces { - public interface ILongProcessLogic + public interface ILongProcessLogic : ILogic { int StepCount { get; } Action SetProgress { get; set; } bool Result { get; set; } - IShiftTraceLogger? TraceLogger { get; set; } - void WorkerDoWork(object sender, DoWorkEventArgs e); void WorkerProgressChanged(object sender, ProgressChangedEventArgs e); void WorkerRunWorkCompleted(object sender, RunWorkerCompletedEventArgs e); diff --git a/StructureHelperCommon/Models/Loggers/LoggerStrings.cs b/StructureHelperCommon/Models/Loggers/LoggerStrings.cs index 3aef8ea..60f5776 100644 --- a/StructureHelperCommon/Models/Loggers/LoggerStrings.cs +++ b/StructureHelperCommon/Models/Loggers/LoggerStrings.cs @@ -11,6 +11,9 @@ namespace StructureHelperCommon.Models.Loggers public static string DimensionLess => "(dimensionless)"; public static string MethodBasedOn => "Method of calculation based on "; public static string CalculationHasDone => "Calculation has done succesfully"; + public static string Summary => "Summary"; + public static string Maximum => "Maximum"; + public static string Minimum => "Minimum"; public static string CalculatorType(object obj) => string.Format("Calculator type: {0}", obj.GetType()); } } diff --git a/StructureHelperCommon/Models/Parameters/ArrayParameter.cs b/StructureHelperCommon/Models/Parameters/ArrayParameter.cs index 0195c18..0b3df4f 100644 --- a/StructureHelperCommon/Models/Parameters/ArrayParameter.cs +++ b/StructureHelperCommon/Models/Parameters/ArrayParameter.cs @@ -42,5 +42,6 @@ namespace StructureHelperCommon.Models.Parameters ColumnLabels = columnLabels; } } + public ArrayParameter(int rowCount, List columnLabels) : this(rowCount, columnLabels.Count, columnLabels) { } } } diff --git a/StructureHelperCommon/Models/Sections/Logics/AccidentalEccentricityLogic.cs b/StructureHelperCommon/Models/Sections/Logics/AccidentalEccentricityLogic.cs index 3ae93dc..f90df30 100644 --- a/StructureHelperCommon/Models/Sections/Logics/AccidentalEccentricityLogic.cs +++ b/StructureHelperCommon/Models/Sections/Logics/AccidentalEccentricityLogic.cs @@ -5,6 +5,9 @@ using System.Linq; using System.Text; using System.Threading.Tasks; +//Copyright (c) 2023 Redikultsev Evgeny, Ekaterinburg, Russia +//All rights reserved. + namespace StructureHelperCommon.Models.Sections { public class AccidentalEccentricityLogic : IAccidentalEccentricityLogic @@ -64,10 +67,10 @@ namespace StructureHelperCommon.Models.Sections minEccentricity, yEccentricity, yFullEccentricity); TraceLogger?.AddMessage(mesEy); - var xSign = InitialForceTuple.Mx == 0 ? 1 : Math.Sign(InitialForceTuple.Mx); - var ySign = InitialForceTuple.My == 0 ? 1 : Math.Sign(InitialForceTuple.My); - var mx = InitialForceTuple.Nz * yFullEccentricity * xSign; - var my = InitialForceTuple.Nz * xFullEccentricity * ySign; + var xSign = InitialForceTuple.Mx == 0d ? -1d : Math.Sign(InitialForceTuple.Mx); + var ySign = InitialForceTuple.My == 0d ? -1d : Math.Sign(InitialForceTuple.My); + var mx = (-1d) * InitialForceTuple.Nz * yFullEccentricity * xSign; + var my = (-1d) * InitialForceTuple.Nz * xFullEccentricity * ySign; TraceLogger?.AddMessage(string.Format("Bending moment arbitrary X-axis Mx = {0} * {1} = {2}", InitialForceTuple.Nz, yFullEccentricity, mx), TraceLogStatuses.Debug); TraceLogger?.AddMessage(string.Format("Bending moment arbitrary Y-axis My = {0} * {1} = {2}", InitialForceTuple.Nz, xFullEccentricity, my), TraceLogStatuses.Debug); diff --git a/StructureHelperCommon/Services/Units/CommonOperation.cs b/StructureHelperCommon/Services/Units/CommonOperation.cs index 1a88a7e..3e91fde 100644 --- a/StructureHelperCommon/Services/Units/CommonOperation.cs +++ b/StructureHelperCommon/Services/Units/CommonOperation.cs @@ -6,6 +6,7 @@ using System.Collections.Generic; using System.Globalization; using System.Linq; using System.Text.RegularExpressions; +using System.Windows.Documents; namespace StructureHelperCommon.Services.Units { @@ -47,11 +48,30 @@ namespace StructureHelperCommon.Services.Units throw new StructureHelperException(ErrorStrings.DataIsInCorrect); } - public static IUnit GetUnit(UnitTypes unitType, string unitName) + public static IUnit GetUnit(UnitTypes unitType, string unitName = null) { + if (unitName is null) + { + var boolResult = DefaultUnitNames.TryGetValue(unitType, out unitName); + if (boolResult == false) + { + throw new StructureHelperException(ErrorStrings.DataIsInCorrect + $": unit type{unitType} is unknown"); + } + } return units.Where(u => u.UnitType == unitType & u.Name == unitName).Single(); } + public static Dictionary DefaultUnitNames => new() + { + { UnitTypes.Length, "m"}, + { UnitTypes.Area, "m2"}, + { UnitTypes.Force, "kN" }, + { UnitTypes.Moment, "kNm"}, + { UnitTypes.Stress, "MPa"}, + { UnitTypes.Curvature, "1/m"}, + }; + + public static string Convert(IUnit unit, string unitName, object value) { double val; diff --git a/StructureHelperLogics/NdmCalculations/Analyses/ByForces/ForceCalculator.cs b/StructureHelperLogics/NdmCalculations/Analyses/ByForces/ForceCalculator.cs index 5c18af6..93e7fc2 100644 --- a/StructureHelperLogics/NdmCalculations/Analyses/ByForces/ForceCalculator.cs +++ b/StructureHelperLogics/NdmCalculations/Analyses/ByForces/ForceCalculator.cs @@ -1,5 +1,6 @@ using LoaderCalculator.Data.Ndms; using StructureHelperCommon.Infrastructures.Enums; +using StructureHelperCommon.Infrastructures.Exceptions; using StructureHelperCommon.Models; using StructureHelperCommon.Models.Calculators; using StructureHelperCommon.Models.Forces; @@ -17,6 +18,8 @@ namespace StructureHelperLogics.NdmCalculations.Analyses.ByForces { static readonly ForceCalculatorUpdateStrategy updateStrategy = new(); private readonly IForceTupleCalculator forceTupleCalculator; + private ForcesResults result; + public string Name { get; set; } public List LimitStatesList { get; private set; } public List CalcTermsList { get; private set; } @@ -50,7 +53,10 @@ namespace StructureHelperLogics.NdmCalculations.Analyses.ByForces private void CalculateResult() { - var ndmResult = new ForcesResults() { IsValid = true }; + result = new ForcesResults() + { + IsValid = true + }; foreach (var combination in ForceCombinationLists) { foreach (var tuple in combination.DesignForces) @@ -59,15 +65,34 @@ namespace StructureHelperLogics.NdmCalculations.Analyses.ByForces var calcTerm = tuple.CalcTerm; if (LimitStatesList.Contains(limitState) & CalcTermsList.Contains(calcTerm)) { - ProcessNdmResult(ndmResult, combination, tuple, limitState, calcTerm); + + IForcesTupleResult tupleResult; + try + { + tupleResult = ProcessNdmResult(combination, tuple); + } + catch(Exception ex) + { + tupleResult = new ForcesTupleResult() + { + IsValid = false, + Description = string.Empty + ex, + DesignForceTuple = tuple + }; + } + result.ForcesResultList.Add(tupleResult); + ActionToOutputResults?.Invoke(result); } } } - Result = ndmResult; + Result = result; } - private void ProcessNdmResult(ForcesResults ndmResult, IForceCombinationList combination, IDesignForceTuple tuple, LimitStates limitState, CalcTerms calcTerm) + private IForcesTupleResult ProcessNdmResult(IForceCombinationList combination, IDesignForceTuple tuple) { + IForcesTupleResult tupleResult; + LimitStates limitState = tuple.LimitState; + CalcTerms calcTerm = tuple.CalcTerm; var ndms = NdmPrimitivesService.GetNdms(Primitives, limitState, calcTerm); IPoint2D point2D; if (combination.SetInGravityCenter == true) @@ -89,9 +114,22 @@ namespace StructureHelperLogics.NdmCalculations.Analyses.ByForces { TraceLogger?.AddMessage("Get eccentricity for full load"); newTuple = ProcessAccEccentricity(ndms, newTuple); - newTuple = GetForceTupleByBuckling(ndmResult, combination, limitState, calcTerm, ndms, newTuple); + var buckResult = GetForceTupleByBuckling(combination, limitState, calcTerm, ndms, newTuple); + if (buckResult.isValid == true) + { + newTuple = buckResult.tuple; + } + else + { + return new ForcesTupleResult() + { + IsValid = false, + DesignForceTuple = tuple, + Description = buckResult.description, + }; + } } - GetForceResult(ndmResult, limitState, calcTerm, ndms, newTuple); + tupleResult = GetForceResult(limitState, calcTerm, ndms, newTuple); } else { @@ -100,12 +138,14 @@ namespace StructureHelperLogics.NdmCalculations.Analyses.ByForces string message = string.Format("Second order effect is not considered, despite force Nz={0}", newTuple.Nz); TraceLogger?.AddMessage(message, TraceLogStatuses.Warning); } - GetForceResult(ndmResult, limitState, calcTerm, ndms, newTuple); + tupleResult = GetForceResult(limitState, calcTerm, ndms, newTuple); } + return tupleResult; } - private IForceTuple GetForceTupleByBuckling(ForcesResults ndmResult, IForceCombinationList combination, LimitStates limitState, CalcTerms calcTerm, List ndms, IForceTuple newTuple) + private (bool isValid, IForceTuple tuple, string description) GetForceTupleByBuckling(IForceCombinationList combination, LimitStates limitState, CalcTerms calcTerm, List ndms, IForceTuple newTuple) { + var tuple = newTuple.Clone() as IForceTuple; var inputData = new BucklingInputData() { Combination = combination, @@ -119,41 +159,31 @@ namespace StructureHelperLogics.NdmCalculations.Analyses.ByForces if (bucklingResult.IsValid != true) { TraceLogger?.AddMessage(bucklingResult.Description, TraceLogStatuses.Error); - var result = new ForcesTupleResult - { - IsValid = false, - Description = $"Buckling result:\n{bucklingResult.Description}\n", - DesignForceTuple = new DesignForceTuple() - { - ForceTuple = newTuple, - LimitState = limitState, - CalcTerm = calcTerm - } - }; - ndmResult.ForcesResultList.Add(result); + return (false, tuple, $"Buckling result:\n{bucklingResult.Description}"); } else { - newTuple = CalculateBuckling(newTuple, bucklingResult); - TraceLogger?.AddMessage($"Force combination with considering of second order effects"); - TraceLogger?.AddEntry(new TraceTablesFactory().GetByForceTuple(newTuple)); + tuple = CalculateBuckling(tuple, bucklingResult); + TraceLogger?.AddMessage(string.Intern("Force combination with considering of second order effects")); + TraceLogger?.AddEntry(new TraceTablesFactory().GetByForceTuple(tuple)); } - return newTuple; + return (true, tuple, string.Empty); } - private void GetForceResult(ForcesResults ndmResult, LimitStates limitState, CalcTerms calcTerm, List ndms, IForceTuple newTuple) + private IForcesTupleResult GetForceResult(LimitStates limitState, CalcTerms calcTerm, List ndms, IForceTuple newTuple) { - var result = GetPrimitiveStrainMatrix(ndms, newTuple, Accuracy); - result.DesignForceTuple.LimitState = limitState; - result.DesignForceTuple.CalcTerm = calcTerm; - result.DesignForceTuple.ForceTuple = newTuple; - ndmResult.ForcesResultList.Add(result); - ActionToOutputResults?.Invoke(ndmResult); + var tupleResult = GetPrimitiveStrainMatrix(ndms, newTuple, Accuracy); + tupleResult.DesignForceTuple.LimitState = limitState; + tupleResult.DesignForceTuple.CalcTerm = calcTerm; + tupleResult.DesignForceTuple.ForceTuple = newTuple; + return tupleResult; + } - private IForceTuple ProcessAccEccentricity(List ndms, IForceTuple newTuple) + private IForceTuple ProcessAccEccentricity(List ndms, IForceTuple tuple) { + var newTuple = tuple.Clone() as IForceTuple; var accLogic = new AccidentalEccentricityLogic() { Length = CompressedMember.GeometryLength, @@ -161,7 +191,10 @@ namespace StructureHelperLogics.NdmCalculations.Analyses.ByForces SizeY = ndms.Max(x => x.CenterY) - ndms.Min(x => x.CenterY), InitialForceTuple = newTuple, }; - if (TraceLogger is not null) { accLogic.TraceLogger = TraceLogger.GetSimilarTraceLogger(50); } + if (TraceLogger is not null) + { + accLogic.TraceLogger = TraceLogger.GetSimilarTraceLogger(50); + } newTuple = accLogic.GetForceTuple(); return newTuple; } @@ -196,7 +229,10 @@ namespace StructureHelperLogics.NdmCalculations.Analyses.ByForces IForceTuple longTuple; try { - longTuple = designForces.Where(x => x.LimitState == limitState & x.CalcTerm == CalcTerms.LongTerm).First().ForceTuple; + longTuple = designForces + .Where(x => x.LimitState == limitState & x.CalcTerm == CalcTerms.LongTerm) + .Single() + .ForceTuple; } catch (Exception) { diff --git a/StructureHelperLogics/NdmCalculations/Analyses/ByForces/ForceTupleCalculator.cs b/StructureHelperLogics/NdmCalculations/Analyses/ByForces/ForceTupleCalculator.cs index cb60f1f..db90dcc 100644 --- a/StructureHelperLogics/NdmCalculations/Analyses/ByForces/ForceTupleCalculator.cs +++ b/StructureHelperLogics/NdmCalculations/Analyses/ByForces/ForceTupleCalculator.cs @@ -9,6 +9,7 @@ using StructureHelperCommon.Models.Calculators; using StructureHelperCommon.Models.Forces; using StructureHelperCommon.Models.Loggers; using StructureHelperCommon.Models.Shapes; +using StructureHelperLogics.Services; namespace StructureHelperLogics.NdmCalculations.Analyses.ByForces { @@ -33,18 +34,16 @@ namespace StructureHelperLogics.NdmCalculations.Analyses.ByForces private IForcesTupleResult CalculateResult() { - TraceLogger?.AddMessage($"Calculator type: {GetType()}", TraceLogStatuses.Service); - TraceLogger?.AddMessage($"Calculator logic based on calculating strain in plain section by elementary parts of finished size"); + TraceLogger?.AddMessage(string.Intern($"Calculator type: {GetType()}"), TraceLogStatuses.Service); + TraceLogger?.AddMessage(string.Intern("Calculator logic based on calculating strain in plain section by elementary parts of finished size")); var ndmCollection = InputData.NdmCollection; - TraceLogger?.AddMessage($"Collection of elementary parts contains {ndmCollection.Count()} parts"); - TraceLogger?.AddMessage($"Summary area of elementary part collection = {ndmCollection.Sum(x => x.Area * x.StressScale)}", TraceLogStatuses.Service); - TraceLogger?.AddMessage($"Minimum x = {ndmCollection.Min(x => x.CenterX)}", TraceLogStatuses.Debug); - TraceLogger?.AddMessage($"Maximum x = {ndmCollection.Max(x => x.CenterX)}", TraceLogStatuses.Debug); - TraceLogger?.AddMessage($"Minimum y = {ndmCollection.Min(x => x.CenterY)}", TraceLogStatuses.Debug); - TraceLogger?.AddMessage($"Maximum y = {ndmCollection.Max(x => x.CenterY)}", TraceLogStatuses.Debug); + if (TraceLogger is not null) + { + TraceService.TraceNdmCollection(TraceLogger, ndmCollection); + } var tuple = InputData.Tuple; var accuracy = InputData.Accuracy; - TraceLogger?.AddMessage($"Input force combination"); + TraceLogger?.AddMessage(string.Intern("Input force combination")); TraceLogger?.AddEntry(new TraceTablesFactory().GetByForceTuple(tuple)); var mx = tuple.Mx; var my = tuple.My; @@ -65,9 +64,9 @@ namespace StructureHelperLogics.NdmCalculations.Analyses.ByForces NdmCollection = ndmCollection }; var calculator = new Calculator(); - TraceLogger?.AddMessage($"Calculation is started", TraceLogStatuses.Debug); + TraceLogger?.AddMessage(string.Intern("Calculation is started"), TraceLogStatuses.Debug); calculator.Run(loaderData, new CancellationToken()); - TraceLogger?.AddMessage($"Calculation result is obtained", TraceLogStatuses.Debug); + TraceLogger?.AddMessage(string.Intern("Calculation result is obtained"), TraceLogStatuses.Debug); var calcResult = calculator.Result; if (calcResult.AccuracyRate <= accuracy.IterationAccuracy) { @@ -77,18 +76,18 @@ namespace StructureHelperLogics.NdmCalculations.Analyses.ByForces Description = LoggerStrings.CalculationHasDone, LoaderResults = calcResult }; - forceTupleTraceResultLogic = new ForceTupleTraceResultLogic(ndmCollection) { TraceLogger = TraceLogger}; + forceTupleTraceResultLogic = new ForceTupleTraceResultLogic(ndmCollection) { TraceLogger = TraceLogger }; forceTupleTraceResultLogic.TraceResult(result); return result; } else { - TraceLogger?.AddMessage($"Required accuracy rate has not achieved", TraceLogStatuses.Error); + TraceLogger?.AddMessage(string.Intern("Required accuracy rate has not achieved"), TraceLogStatuses.Error); TraceLogger?.AddMessage($"Current accuracy {calcResult.AccuracyRate}, {calcResult.IterationCounter} iteration has done", TraceLogStatuses.Warning); return new ForcesTupleResult() { IsValid = false, - Description = "Required accuracy rate has not achieved", + Description = string.Intern("Required accuracy rate has not achieved"), LoaderResults = calcResult }; } @@ -103,8 +102,8 @@ namespace StructureHelperLogics.NdmCalculations.Analyses.ByForces }; if (ex.Message == "Calculation result is not valid: stiffness matrix is equal to zero") { - TraceLogger?.AddMessage($"Stiffness matrix is equal to zero\nProbably section was collapsed", TraceLogStatuses.Error); - result.Description = "Stiffness matrix is equal to zero\nProbably section was collapsed"; + TraceLogger?.AddMessage(string.Intern("Stiffness matrix is equal to zero\nProbably section was collapsed"), TraceLogStatuses.Error); + result.Description = string.Intern("Stiffness matrix is equal to zero\nProbably section was collapsed"); } else { diff --git a/StructureHelperLogics/NdmCalculations/Buckling/ConcreteBucklingCalculator.cs b/StructureHelperLogics/NdmCalculations/Buckling/ConcreteBucklingCalculator.cs index 79cb4f3..a0b557a 100644 --- a/StructureHelperLogics/NdmCalculations/Buckling/ConcreteBucklingCalculator.cs +++ b/StructureHelperLogics/NdmCalculations/Buckling/ConcreteBucklingCalculator.cs @@ -1,4 +1,5 @@ -using LoaderCalculator.Data.Ndms; +using LoaderCalculator.Data.Materials; +using LoaderCalculator.Data.Ndms; using LoaderCalculator.Logics; using LoaderCalculator.Logics.Geometry; using StructureHelperCommon.Models; @@ -9,6 +10,7 @@ using StructureHelperCommon.Models.Shapes; using StructureHelperLogics.Models.Materials; using StructureHelperLogics.NdmCalculations.Analyses.ByForces; using StructureHelperLogics.NdmCalculations.Primitives; +using StructureHelperLogics.Services; using StructureHelperLogics.Services.NdmPrimitives; namespace StructureHelperLogics.NdmCalculations.Buckling @@ -28,7 +30,7 @@ namespace StructureHelperLogics.NdmCalculations.Buckling public IResult Result { get; private set; } public IAccuracy Accuracy { get; set; } - public Action ActionToOutputResults { get => throw new NotImplementedException(); set => throw new NotImplementedException(); } + public Action ActionToOutputResults { get; set; } public IShiftTraceLogger? TraceLogger { get; set; } private (double EtaAlongX, double EtaAlongY) GetBucklingCoefficients() @@ -50,11 +52,9 @@ namespace StructureHelperLogics.NdmCalculations.Buckling Accuracy = accuracy; var allPrimitives = options.Primitives; - var concretePrimitives = GetConcretePrimitives(); - var otherPrimitives = allPrimitives.Except(concretePrimitives); ndmCollection = NdmPrimitivesService.GetNdms(allPrimitives, options.LimitState, options.CalcTerm); - concreteNdms = NdmPrimitivesService.GetNdms(concretePrimitives, options.LimitState, options.CalcTerm); - otherNdms = NdmPrimitivesService.GetNdms(otherPrimitives, options.LimitState, options.CalcTerm); + concreteNdms = ndmCollection.Where(x => x.Material is ICrackMaterial).ToList(); + otherNdms = ndmCollection.Except(concreteNdms).ToList(); } private (IConcreteDeltaELogic DeltaLogicX, IConcreteDeltaELogic DeltaLogicY) GetDeltaLogics() @@ -78,35 +78,38 @@ namespace StructureHelperLogics.NdmCalculations.Buckling return (DeltaElogicAboutX, DeltaElogicAboutY); } - private IEnumerable GetConcretePrimitives() - { - var primitives = options.Primitives.Where(x => x.HeadMaterial.HelperMaterial is IConcreteLibMaterial); - return primitives; - } - private (double DX, double DY) GetStiffness() { + const string sumStif = "Summary stiffness"; var gravityCenter = GeometryOperations.GetGravityCenter(ndmCollection); string message = string.Format("Gravity center, x = {0}, y = {1}", gravityCenter.Cx, gravityCenter.Cy); TraceLogger?.AddMessage(message); + if (TraceLogger is not null) + { + TraceLogger.AddMessage(string.Intern("Concrete elementary parts")); + TraceService.TraceNdmCollection(TraceLogger, concreteNdms); + TraceLogger.AddMessage(string.Intern("Nonconcrete elementary parts")); + TraceService.TraceNdmCollection(TraceLogger, otherNdms); + } + var (EIx, EIy) = GeometryOperations.GetReducedMomentsOfInertia(concreteNdms, gravityCenter); - TraceLogger.AddMessage(string.Format("Summary stiffness of concrete parts EIx,c = {0}", EIx)); - TraceLogger.AddMessage(string.Format("Summary stiffness of concrete parts EIy,c = {0}", EIy)); + TraceLogger?.AddMessage(string.Format("{0} of concrete parts EIx,c = {1}", sumStif, EIx)); + TraceLogger?.AddMessage(string.Format("{0} of concrete parts EIy,c = {1}", sumStif, EIy)); var otherInertia = GeometryOperations.GetReducedMomentsOfInertia(otherNdms, gravityCenter); - TraceLogger.AddMessage(string.Format("Summary stiffness of nonconcrete parts EIx,s = {0}", otherInertia.EIy)); - TraceLogger.AddMessage(string.Format("Summary stiffness of nonconcrete parts EIy,s = {0}", otherInertia.EIy)); + TraceLogger?.AddMessage(string.Format("{0} of nonconcrete parts EIx,s = {1}", sumStif, otherInertia.EIx)); + TraceLogger?.AddMessage(string.Format("{0} of nonconcrete parts EIy,s = {1}", sumStif, otherInertia.EIy)); var (Kc, Ks) = stiffnessLogicX.GetStiffnessCoeffitients(); var dX = Kc * EIx + Ks * otherInertia.EIx; - string mesDx = string.Format("Summary stiffness Dx = Kc * EIx,c + Ks * EIx,s = {0} * {1} + {2} * {3} = {4}", - Kc, EIx, Ks, otherInertia.EIx, dX); - TraceLogger.AddMessage(mesDx); + string mesDx = string.Format("{0} Dx = Kc * EIx,c + Ks * EIx,s = {1} * {2} + {3} * {4} = {5}", + sumStif, Kc, EIx, Ks, otherInertia.EIx, dX); + TraceLogger?.AddMessage(mesDx); var stiffnessY = stiffnessLogicY.GetStiffnessCoeffitients(); var dY = stiffnessY.Kc * EIy + stiffnessY.Ks * otherInertia.EIy; - string mesDy = string.Format("Summary stiffness Dy = Kc * EIy,c + Ks * EIy,s = {0} * {1} + {2} * {3} = {4}", - stiffnessY.Kc, EIy, stiffnessY.Ks, otherInertia.EIy, dY); - TraceLogger.AddMessage(mesDy); + string mesDy = string.Format("{0} Dy = Kc * EIy,c + Ks * EIy,s = {1} * {2} + {3} * {4} = {5}", + sumStif, stiffnessY.Kc, EIy, stiffnessY.Ks, otherInertia.EIy, dY); + TraceLogger?.AddMessage(mesDy); return (dX, dY); } @@ -132,8 +135,8 @@ namespace StructureHelperLogics.NdmCalculations.Buckling point = new Point2D() { X = item.CenterX, Y = item.CenterY }; } } - TraceLogger.AddMessage(string.Format("Most tensioned (minimum compressed) point: x = {0}, y = {1}", point.X, point.Y)); - TraceLogger.AddMessage(string.Format("Strain: epsilon = {0}", maxStrain), TraceLogStatuses.Debug); + TraceLogger?.AddMessage(string.Format("Most tensioned (minimum compressed) point: x = {0}, y = {1}", point.X, point.Y)); + TraceLogger?.AddMessage(string.Format("Strain: epsilon = {0}", maxStrain), TraceLogStatuses.Debug); return point; } diff --git a/StructureHelperLogics/Services/TraceService.cs b/StructureHelperLogics/Services/TraceService.cs new file mode 100644 index 0000000..b782d71 --- /dev/null +++ b/StructureHelperLogics/Services/TraceService.cs @@ -0,0 +1,44 @@ +using LoaderCalculator.Data.Ndms; +using StructureHelperCommon.Infrastructures.Exceptions; +using StructureHelperCommon.Models; +using StructureHelperCommon.Models.Loggers; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace StructureHelperLogics.Services +{ + internal static class TraceService + { + public static void TraceNdmCollection(ITraceLogger traceLogger, IEnumerable ndmCollection) + { + if (traceLogger is null) + { + throw new StructureHelperException(ErrorStrings.NullReference + ": trace logger"); + } + if (ndmCollection is null) + { + traceLogger.AddMessage(string.Intern("Collection of elementary parts is null"), TraceLogStatuses.Error); + throw new StructureHelperException(ErrorStrings.NullReference + ": collection of elementary parts"); + } + if (!ndmCollection.Any()) + { + traceLogger.AddMessage("Collection of elementary parts is empty", TraceLogStatuses.Warning); + } + traceLogger.AddMessage(string.Format("Collection of elementary parts contains {0} parts", ndmCollection.Count())); + var mes = "area of elementary part collection "; + traceLogger.AddMessage(string.Format("{0} {1} A = {2}, {0} reduced {1} Ared = {3}", + LoggerStrings.Summary, + mes, + ndmCollection.Sum(x => x.Area), + ndmCollection.Sum(x => x.Area * x.StressScale)), + TraceLogStatuses.Service); + traceLogger.AddMessage($"Minimum x = {ndmCollection.Min(x => x.CenterX)}", TraceLogStatuses.Debug); + traceLogger.AddMessage($"Maximum x = {ndmCollection.Max(x => x.CenterX)}", TraceLogStatuses.Debug); + traceLogger.AddMessage($"Minimum y = {ndmCollection.Min(x => x.CenterY)}", TraceLogStatuses.Debug); + traceLogger.AddMessage($"Maximum y = {ndmCollection.Max(x => x.CenterY)}", TraceLogStatuses.Debug); + } + } +}