From 921ec22e8a07ed09f65afd68dd392fe9ddf00f48 Mon Sep 17 00:00:00 2001 From: Evgeny Redikultsev Date: Mon, 23 Dec 2024 21:38:47 +0500 Subject: [PATCH] Add trace force results --- .../ProgressViews/TraceDocumentVM.cs | 4 +- .../Models/Materials/TraceMaterialsFactory.cs | 94 +++++++++++++- .../Analyses/ByForces/ForceCalculatorLogic.cs | 14 ++ .../ByForces/TraceForcesResultLogic.cs | 120 ++++++++++++++++++ .../Primitives/TracePrimitiveFactory.cs | 10 +- 5 files changed, 232 insertions(+), 10 deletions(-) create mode 100644 StructureHelperLogics/NdmCalculations/Analyses/ByForces/TraceForcesResultLogic.cs diff --git a/StructureHelper/Windows/CalculationWindows/ProgressViews/TraceDocumentVM.cs b/StructureHelper/Windows/CalculationWindows/ProgressViews/TraceDocumentVM.cs index 8d6af9e..4de9745 100644 --- a/StructureHelper/Windows/CalculationWindows/ProgressViews/TraceDocumentVM.cs +++ b/StructureHelper/Windows/CalculationWindows/ProgressViews/TraceDocumentVM.cs @@ -155,7 +155,7 @@ namespace StructureHelper.Windows.CalculationWindows.ProgressViews private Table GetBlockByTableEntry(TableLogEntry tableEntry) { - const int columnWidth = 150; + const double defaultColumnWidth = 150d; var rows = tableEntry.Table.GetAllRows(); int columnCount = tableEntry.Table.RowSize; var table = new Table(); @@ -168,7 +168,7 @@ namespace StructureHelper.Windows.CalculationWindows.ProgressViews } else { - tableColumn.Width = new GridLength(columnWidth); + tableColumn.Width = new GridLength(defaultColumnWidth); } table.Columns.Add(tableColumn); } diff --git a/StructureHelperLogics/Models/Materials/TraceMaterialsFactory.cs b/StructureHelperLogics/Models/Materials/TraceMaterialsFactory.cs index a7eb8c6..c3e43a8 100644 --- a/StructureHelperLogics/Models/Materials/TraceMaterialsFactory.cs +++ b/StructureHelperLogics/Models/Materials/TraceMaterialsFactory.cs @@ -1,4 +1,5 @@ -using StructureHelper.Models.Materials; +using LoaderCalculator.Data.Materials; +using StructureHelper.Models.Materials; using StructureHelperCommon.Infrastructures.Exceptions; using StructureHelperCommon.Models; using StructureHelperCommon.Models.Materials.Libraries; @@ -9,6 +10,7 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using System.Windows.Documents; using System.Windows.Shapes; namespace StructureHelperLogics.Models.Materials @@ -49,6 +51,37 @@ namespace StructureHelperLogics.Models.Materials traceLoggerEntries.Add(table); } + private List> ProcessLibMaterial(ILibMaterial libMaterial) + { + List> rows = new(); + ShTableRow ndmRow; + ndmRow = new(rowSize); + ndmRow.Elements[0].Value = new StringLogEntry() + { + Message = "Material kind name", + Priority = Priority + }; + ndmRow.Elements[1].Value = new StringLogEntry() + { + Message = libMaterial.MaterialEntity.Name, + Priority = Priority + }; + rows.Add(ndmRow); + ndmRow = new(rowSize); + ndmRow.Elements[0].Value = new StringLogEntry() + { + Message = "Material logic name", + Priority = Priority + }; + ndmRow.Elements[1].Value = new StringLogEntry() + { + Message = libMaterial.MaterialLogic.Name, + Priority = Priority + }; + rows.Add(ndmRow); + return rows; + } + private void Check() { if (Collection is null) @@ -83,10 +116,65 @@ namespace StructureHelperLogics.Models.Materials return ndmRow; } - private List> GetCommonRows(IHeadMaterial headMaterial) + private List> GetCommonRows(IHeadMaterial headMateial) { List> rows = new(); - rows.AddRange(ProcessSafetyFactors(headMaterial.HelperMaterial.SafetyFactors)); + var helperMaterial = headMateial.HelperMaterial; + if (helperMaterial is not null) + { + if (helperMaterial is ILibMaterial libMaterial) + { + rows.AddRange(ProcessLibMaterial(libMaterial)); + } + if (helperMaterial is IElasticMaterial elastic) + { + rows.AddRange(ProcessElasticMaterial(elastic)); + } + } + rows.AddRange(ProcessSafetyFactors(headMateial.HelperMaterial.SafetyFactors)); + return rows; + } + + private IEnumerable> ProcessElasticMaterial(IElasticMaterial elastic) + { + List> rows = new(); + ShTableRow ndmRow; + ndmRow = new(rowSize); + ndmRow.Elements[0].Value = new StringLogEntry() + { + Message = "Initial Young's modulus, Pa", + Priority = Priority + }; + ndmRow.Elements[1].Value = new StringLogEntry() + { + Message = elastic.Modulus.ToString(), + Priority = Priority + }; + rows.Add(ndmRow); + ndmRow = new(rowSize); + ndmRow.Elements[0].Value = new StringLogEntry() + { + Message = "Compressive strength, Pa", + Priority = Priority + }; + ndmRow.Elements[1].Value = new StringLogEntry() + { + Message = elastic.CompressiveStrength.ToString(), + Priority = Priority + }; + rows.Add(ndmRow); + ndmRow = new(rowSize); + ndmRow.Elements[0].Value = new StringLogEntry() + { + Message = "Tensile strength, Pa", + Priority = Priority + }; + ndmRow.Elements[1].Value = new StringLogEntry() + { + Message = elastic.TensileStrength.ToString(), + Priority = Priority + }; + rows.Add(ndmRow); return rows; } diff --git a/StructureHelperLogics/NdmCalculations/Analyses/ByForces/ForceCalculatorLogic.cs b/StructureHelperLogics/NdmCalculations/Analyses/ByForces/ForceCalculatorLogic.cs index 68ffa08..5ca0999 100644 --- a/StructureHelperLogics/NdmCalculations/Analyses/ByForces/ForceCalculatorLogic.cs +++ b/StructureHelperLogics/NdmCalculations/Analyses/ByForces/ForceCalculatorLogic.cs @@ -34,9 +34,23 @@ namespace StructureHelperLogics.NdmCalculations.Analyses.ByForces TraceInputData(); GetCombinations(); CalculateResult(); + TraceResult(); return result; } + private void TraceResult() + { + TraceForcesResultLogic traceLogic = new() + { + Collection = result.ForcesResultList + }; + List traceEntries = traceLogic.GetTraceEntries(); + foreach (var item in traceEntries) + { + TraceLogger?.AddEntry(item); + } + } + private void TraceInputData() { TracePrimitiveFactory tracePrimitiveFactory = new() diff --git a/StructureHelperLogics/NdmCalculations/Analyses/ByForces/TraceForcesResultLogic.cs b/StructureHelperLogics/NdmCalculations/Analyses/ByForces/TraceForcesResultLogic.cs new file mode 100644 index 0000000..ae02072 --- /dev/null +++ b/StructureHelperLogics/NdmCalculations/Analyses/ByForces/TraceForcesResultLogic.cs @@ -0,0 +1,120 @@ +using StructureHelper.Models.Materials; +using StructureHelperCommon.Infrastructures.Exceptions; +using StructureHelperCommon.Models; +using StructureHelperCommon.Models.Tables; +using StructureHelperLogics.Models.Materials; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace StructureHelperLogics.NdmCalculations.Analyses.ByForces +{ + public class TraceForcesResultLogic : ITraceEntityFactory + { + const int rowSize = 4; + private List traceLoggerEntries; + public IEnumerable? Collection { get; set; } + public int Priority { get; set; } = LoggerService.GetPriorityByStatus(TraceLogStatuses.Info); + + public List GetTraceEntries() + { + Check(); + traceLoggerEntries = new(); + traceLoggerEntries.Add(new StringLogEntry() + { + Message = $"There are totally {Collection.Count()} result(s), {Collection.Count(x => x.IsValid == true)} valid result(s), {Collection.Count(x => x.IsValid == false)} invalid result(s)", + Priority = Priority + } + ); + ProcessCollection(); + return traceLoggerEntries; + } + + private void ProcessCollection() + { + var table = new TableLogEntry(rowSize) + { + Priority = Priority + }; + table.ColumnWidth[2] = 250; + table.ColumnWidth[3] = 250; + table.Table.AddRow(GetHeader()); + foreach (var item in Collection) + { + table.Table.AddRows(ProcessForceTupleResult(item)); + } + traceLoggerEntries.Add(table); + } + + private IEnumerable> ProcessForceTupleResult(IForcesTupleResult item) + { + List> rows = new(); + int priority = Priority; + if (item.IsValid == false) + { + priority = LoggerService.GetPriorityByStatus(TraceLogStatuses.Error); + } + ShTableRow ndmRow; + ndmRow = new(rowSize); + ndmRow.Elements[0].Value = new StringLogEntry() + { + Message = "Limit state: " + item.DesignForceTuple.LimitState.ToString() + ", Calculation term: " + item.DesignForceTuple.CalcTerm, + Priority = priority + }; + ndmRow.Elements[1].Value = new StringLogEntry() + { + Message = "Mx = " + item.DesignForceTuple.ForceTuple.Mx.ToString() + "N*m, My = " + item.DesignForceTuple.ForceTuple.My.ToString() + "N*m, Nz =" + item.DesignForceTuple.ForceTuple.Nz.ToString() + "N, ", + Priority = priority + }; + ndmRow.Elements[2].Value = new StringLogEntry() + { + Message = "Kx = " + item.LoaderResults.StrainMatrix.Kx + "(1/m), Ky = " + item.LoaderResults.StrainMatrix.Ky + "(1/m), EpsZ = " + item.LoaderResults.StrainMatrix.EpsZ + "(dimensionless)", + Priority = priority + }; + ndmRow.Elements[3].Value = new StringLogEntry() + { + Message = item.Description, + Priority = priority + }; + rows.Add(ndmRow); + return rows; + } + + private IShTableRow GetHeader() + { + const CellRole cellRole = CellRole.Header; + string[] ColumnList = new string[] + { + "Conditions", + "Forces", + "Curvatures", + "Description" + }; + var ndmRow = new ShTableRow(rowSize); + foreach (var item in ndmRow.Elements) + { + item.Role = cellRole; + } + + for (int i = 0; i < rowSize; i++) + { + ndmRow.Elements[i].Value = new StringLogEntry() + { + Message = ColumnList[i], + Priority = Priority + }; + } + return ndmRow; + } + + private void Check() + { + if (Collection is null) + { + throw new StructureHelperException(ErrorStrings.ParameterIsNull + ": Collection of primitives"); + } + } + } +} diff --git a/StructureHelperLogics/NdmCalculations/Primitives/TracePrimitiveFactory.cs b/StructureHelperLogics/NdmCalculations/Primitives/TracePrimitiveFactory.cs index e1a0c17..2185b4f 100644 --- a/StructureHelperLogics/NdmCalculations/Primitives/TracePrimitiveFactory.cs +++ b/StructureHelperLogics/NdmCalculations/Primitives/TracePrimitiveFactory.cs @@ -83,7 +83,7 @@ namespace StructureHelperLogics.NdmCalculations.Primitives }; ndmRow.Elements[1].Value = new StringLogEntry() { - Message = rectShape.Width.ToString(), + Message = rectShape.Width.ToString() + "(m)", Priority = Priority }; rows.Add(ndmRow); @@ -102,7 +102,7 @@ namespace StructureHelperLogics.NdmCalculations.Primitives }; ndmRow.Elements[1].Value = new StringLogEntry() { - Message = point.Area.ToString(), + Message = point.Area.ToString() + "(m^2)", Priority = Priority }; rows.Add(ndmRow); @@ -133,7 +133,7 @@ namespace StructureHelperLogics.NdmCalculations.Primitives }; ndmRow.Elements[1].Value = new StringLogEntry() { - Message = "X = " + ndmPrimitive.Center.X.ToString() + ", Y = " + ndmPrimitive.Center.Y.ToString(), + Message = "X = " + ndmPrimitive.Center.X.ToString() + "(m)" + ", Y = " + ndmPrimitive.Center.Y.ToString() + "(m)", Priority = Priority }; rows.Add(ndmRow); @@ -152,7 +152,7 @@ namespace StructureHelperLogics.NdmCalculations.Primitives }; ndmRow.Elements[1].Value = new StringLogEntry() { - Message = rectShape.Width.ToString(), + Message = rectShape.Height.ToString() + "(m)", Priority = Priority }; rows.Add(ndmRow); @@ -164,7 +164,7 @@ namespace StructureHelperLogics.NdmCalculations.Primitives }; ndmRow.Elements[1].Value = new StringLogEntry() { - Message = rectShape.Height.ToString(), + Message = rectShape.Width.ToString() + "(m)", Priority = Priority }; rows.Add(ndmRow);