Trace logger calls were adde in limit curve calculator
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
using StructureHelperCommon.Infrastructures.Interfaces;
|
||||
using StructureHelperCommon.Models.Calculators;
|
||||
using StructureHelperCommon.Models.Loggers;
|
||||
using StructureHelperLogics.NdmCalculations.Analyses.ByForces;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@@ -18,6 +19,8 @@ namespace StructureHelper.Models.Calculators
|
||||
|
||||
public IResult Result => result;
|
||||
|
||||
public ITraceLogger? TraceLogger { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
|
||||
|
||||
public void Run()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
|
||||
@@ -4,6 +4,7 @@ using StructureHelper.Windows.ViewModels.Errors;
|
||||
using StructureHelperCommon.Infrastructures.Enums;
|
||||
using StructureHelperCommon.Infrastructures.Interfaces;
|
||||
using StructureHelperCommon.Infrastructures.Settings;
|
||||
using StructureHelperCommon.Models.Loggers;
|
||||
using StructureHelperCommon.Models.Parameters;
|
||||
using StructureHelperCommon.Services.Units;
|
||||
using StructureHelperLogics.NdmCalculations.Analyses.ByForces;
|
||||
@@ -35,6 +36,8 @@ namespace StructureHelper.Windows.CalculationWindows.CalculatorsViews
|
||||
|
||||
public int StepCount => ValidTupleList.Count();
|
||||
|
||||
public ITraceLogger? TraceLogger { get; set; }
|
||||
|
||||
public CrackDiagramLogic(IEnumerable<IForcesTupleResult> tupleList, IEnumerable<INdmPrimitive> ndmPrimitives)
|
||||
{
|
||||
TupleList = tupleList;
|
||||
|
||||
@@ -5,6 +5,7 @@ using StructureHelperCommon.Infrastructures.Exceptions;
|
||||
using StructureHelperCommon.Infrastructures.Interfaces;
|
||||
using StructureHelperCommon.Infrastructures.Settings;
|
||||
using StructureHelperCommon.Models.Calculators;
|
||||
using StructureHelperCommon.Models.Loggers;
|
||||
using StructureHelperCommon.Models.Parameters;
|
||||
using StructureHelperCommon.Models.Shapes;
|
||||
using StructureHelperCommon.Services.Units;
|
||||
@@ -40,6 +41,7 @@ namespace StructureHelper.Windows.CalculationWindows.CalculatorsViews.ForceCalcu
|
||||
|
||||
public Action<int> SetProgress { get; set; }
|
||||
public bool Result { get; set; }
|
||||
public ITraceLogger? TraceLogger { get; set; }
|
||||
|
||||
public InteractionDiagramLogic(LimitCurveInputData inputData)
|
||||
{
|
||||
@@ -57,8 +59,9 @@ namespace StructureHelper.Windows.CalculationWindows.CalculatorsViews.ForceCalcu
|
||||
var convertLogic = InputData.SurroundData.ConvertLogicEntity;
|
||||
var calculator = new LimitCurvesCalculator()
|
||||
{
|
||||
InputData = InputData
|
||||
InputData = InputData,
|
||||
};
|
||||
if (TraceLogger is not null) { calculator.TraceLogger = TraceLogger; }
|
||||
calculator.ActionToOutputResults = SetProgressByResult;
|
||||
SafetyProcessor.RunSafeProcess(() =>
|
||||
{
|
||||
|
||||
@@ -3,6 +3,7 @@ using StructureHelper.Windows.ViewModels.Errors;
|
||||
using StructureHelperCommon.Infrastructures.Enums;
|
||||
using StructureHelperCommon.Infrastructures.Interfaces;
|
||||
using StructureHelperCommon.Infrastructures.Settings;
|
||||
using StructureHelperCommon.Models.Loggers;
|
||||
using StructureHelperCommon.Models.Parameters;
|
||||
using StructureHelperCommon.Services.Units;
|
||||
using StructureHelperLogics.NdmCalculations.Analyses.ByForces;
|
||||
@@ -27,6 +28,7 @@ namespace StructureHelper.Windows.CalculationWindows.CalculatorsViews.ForceCalcu
|
||||
|
||||
public Action<int> SetProgress { get; set; }
|
||||
public bool Result { get; set; }
|
||||
public ITraceLogger? TraceLogger { get; set; }
|
||||
|
||||
public void WorkerDoWork(object sender, DoWorkEventArgs e)
|
||||
{
|
||||
|
||||
@@ -6,6 +6,7 @@ using StructureHelper.Windows.ViewModels.Calculations.Calculators;
|
||||
using StructureHelper.Windows.ViewModels.Errors;
|
||||
using StructureHelperCommon.Infrastructures.Exceptions;
|
||||
using StructureHelperCommon.Models.Calculators;
|
||||
using StructureHelperCommon.Models.Loggers;
|
||||
using StructureHelperLogics.Models.CrossSections;
|
||||
using StructureHelperLogics.NdmCalculations.Analyses.ByForces;
|
||||
using StructureHelperLogics.NdmCalculations.Analyses.ByForces.LimitCurve;
|
||||
@@ -33,7 +34,8 @@ namespace StructureHelper.Windows.ViewModels.NdmCrossSections
|
||||
{
|
||||
NewItem = new ForceCalculator()
|
||||
{
|
||||
Name = "New force calculator"
|
||||
Name = "New force calculator",
|
||||
TraceLogger = new TraceLogger(),
|
||||
};
|
||||
}
|
||||
else if (parameterType == CalculatorTypes.LimitCurveCalculator)
|
||||
@@ -42,7 +44,8 @@ namespace StructureHelper.Windows.ViewModels.NdmCrossSections
|
||||
NewItem = new LimitCurvesCalculator()
|
||||
{
|
||||
Name = "New interaction diagram calculator",
|
||||
InputData = inputData
|
||||
InputData = inputData,
|
||||
TraceLogger = new TraceLogger(),
|
||||
};
|
||||
}
|
||||
else
|
||||
@@ -133,7 +136,7 @@ namespace StructureHelper.Windows.ViewModels.NdmCrossSections
|
||||
{
|
||||
var calculator = SelectedItem as LimitCurvesCalculator;
|
||||
var inputData = calculator.InputData;
|
||||
ShowInteractionDiagramByInputData(inputData);
|
||||
ShowInteractionDiagramByInputData(calculator);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -151,9 +154,10 @@ namespace StructureHelper.Windows.ViewModels.NdmCrossSections
|
||||
}
|
||||
}
|
||||
|
||||
private void ShowInteractionDiagramByInputData(LimitCurveInputData inputData)
|
||||
private void ShowInteractionDiagramByInputData(LimitCurvesCalculator calculator)
|
||||
{
|
||||
interactionDiagramLogic = new(inputData);
|
||||
interactionDiagramLogic = new(calculator.InputData);
|
||||
interactionDiagramLogic.TraceLogger = calculator.TraceLogger;
|
||||
showProgressLogic = new(interactionDiagramLogic)
|
||||
{
|
||||
WindowTitle = "Diagram creating...",
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using StructureHelperCommon.Models.Calculators;
|
||||
using StructureHelperCommon.Models.Loggers;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
@@ -15,6 +16,8 @@ namespace StructureHelperCommon.Infrastructures.Interfaces
|
||||
Action<int> SetProgress { get; set; }
|
||||
bool Result { get; set; }
|
||||
|
||||
ITraceLogger? TraceLogger { get; set; }
|
||||
|
||||
void WorkerDoWork(object sender, DoWorkEventArgs e);
|
||||
void WorkerProgressChanged(object sender, ProgressChangedEventArgs e);
|
||||
void WorkerRunWorkCompleted(object sender, RunWorkerCompletedEventArgs e);
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using StructureHelperCommon.Infrastructures.Exceptions;
|
||||
using StructureHelperCommon.Models.Loggers;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
@@ -19,6 +20,7 @@ namespace StructureHelperCommon.Models.Calculators
|
||||
public IResult Result => result;
|
||||
|
||||
public Action<IResult> ActionToOutputResults { get; set; }
|
||||
public ITraceLogger? TraceLogger { get; set; }
|
||||
|
||||
public FindParameterCalculator()
|
||||
{
|
||||
@@ -58,6 +60,7 @@ namespace StructureHelperCommon.Models.Calculators
|
||||
int iterationNum = 0;
|
||||
while (step > precision)
|
||||
{
|
||||
TraceLogger?.AddMessage($"Iteration number {iterationNum}", TraceLoggerStatuses.Debug);
|
||||
if (predicate(current) == true)
|
||||
{
|
||||
end = current;
|
||||
@@ -66,8 +69,8 @@ namespace StructureHelperCommon.Models.Calculators
|
||||
{
|
||||
start = current;
|
||||
}
|
||||
|
||||
current = (start + end) / 2;
|
||||
TraceLogger?.AddMessage($"Current value {current}", TraceLoggerStatuses.Debug);
|
||||
step = (end - start) / 2;
|
||||
iterationNum++;
|
||||
|
||||
@@ -78,11 +81,12 @@ namespace StructureHelperCommon.Models.Calculators
|
||||
|
||||
if (iterationNum > maxIterationCount)
|
||||
{
|
||||
TraceLogger?.AddMessage($"Recuired precision was not achieved, current step {step}, required precision {precision}", TraceLoggerStatuses.Error);
|
||||
result.Description = "Parameter was not found succefully: \n";
|
||||
throw new StructureHelperException(ErrorStrings.DataIsInCorrect + ": violation of iteration count");
|
||||
}
|
||||
}
|
||||
|
||||
TraceLogger?.AddMessage($"Parameter value {current} was obtained");
|
||||
result.Parameter = current;
|
||||
result.Description = "Parameter was found succefully";
|
||||
result.IsValid = true;
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using LoaderCalculator.Data.ResultData;
|
||||
using StructureHelperCommon.Models.Loggers;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
@@ -11,6 +12,7 @@ namespace StructureHelperCommon.Models.Calculators
|
||||
{
|
||||
public interface ICalculator : ICloneable
|
||||
{
|
||||
ITraceLogger? TraceLogger { get; set; }
|
||||
string Name { get; set; }
|
||||
/// <summary>
|
||||
/// Method for calculating
|
||||
|
||||
13
StructureHelperCommon/Models/Loggers/ILogger.cs
Normal file
13
StructureHelperCommon/Models/Loggers/ILogger.cs
Normal file
@@ -0,0 +1,13 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StructureHelperCommon.Models.Loggers
|
||||
{
|
||||
public interface ILogger
|
||||
{
|
||||
void Fatal(string message);
|
||||
}
|
||||
}
|
||||
14
StructureHelperCommon/Models/Loggers/ITraceLogger.cs
Normal file
14
StructureHelperCommon/Models/Loggers/ITraceLogger.cs
Normal file
@@ -0,0 +1,14 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StructureHelperCommon.Models.Loggers
|
||||
{
|
||||
public interface ITraceLogger
|
||||
{
|
||||
List<ITraceLoggerEntry> TraceLoggerEntries { get; }
|
||||
void AddMessage(string message, TraceLoggerStatuses status = TraceLoggerStatuses.Info);
|
||||
}
|
||||
}
|
||||
14
StructureHelperCommon/Models/Loggers/ITraceLoggerEntry.cs
Normal file
14
StructureHelperCommon/Models/Loggers/ITraceLoggerEntry.cs
Normal file
@@ -0,0 +1,14 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StructureHelperCommon.Models.Loggers
|
||||
{
|
||||
public interface ITraceLoggerEntry
|
||||
{
|
||||
DateTime TimeStamp { get;}
|
||||
int Priority { get; set; }
|
||||
}
|
||||
}
|
||||
20
StructureHelperCommon/Models/Loggers/StringLoggerEntry.cs
Normal file
20
StructureHelperCommon/Models/Loggers/StringLoggerEntry.cs
Normal file
@@ -0,0 +1,20 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StructureHelperCommon.Models.Loggers
|
||||
{
|
||||
public class StringLoggerEntry : ITraceLoggerEntry
|
||||
{
|
||||
public DateTime TimeStamp { get;}
|
||||
public string Message { get; set; }
|
||||
public int Priority { get; set; }
|
||||
|
||||
public StringLoggerEntry()
|
||||
{
|
||||
TimeStamp = DateTime.Now;
|
||||
}
|
||||
}
|
||||
}
|
||||
57
StructureHelperCommon/Models/Loggers/TraceLogger.cs
Normal file
57
StructureHelperCommon/Models/Loggers/TraceLogger.cs
Normal file
@@ -0,0 +1,57 @@
|
||||
using StructureHelperCommon.Infrastructures.Exceptions;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StructureHelperCommon.Models.Loggers
|
||||
{
|
||||
public class TraceLogger : ITraceLogger
|
||||
{
|
||||
const int fatal = 0;
|
||||
const int error = 1000;
|
||||
const int warning = 200;
|
||||
const int info = 300;
|
||||
const int service = 400;
|
||||
const int debug = 500;
|
||||
|
||||
public List<ITraceLoggerEntry> TraceLoggerEntries { get; }
|
||||
|
||||
public TraceLogger()
|
||||
{
|
||||
TraceLoggerEntries = new();
|
||||
}
|
||||
|
||||
public void AddMessage(string message, TraceLoggerStatuses status = TraceLoggerStatuses.Info)
|
||||
{
|
||||
TraceLoggerEntries.Add(new StringLoggerEntry()
|
||||
{
|
||||
Message = message,
|
||||
Priority = GetPriorityByStatus(status)
|
||||
});
|
||||
}
|
||||
public void AddMessage(string message, int priority)
|
||||
{
|
||||
TraceLoggerEntries.Add(new StringLoggerEntry()
|
||||
{
|
||||
Message = message,
|
||||
Priority = priority
|
||||
});
|
||||
}
|
||||
|
||||
public static int GetPriorityByStatus(TraceLoggerStatuses status)
|
||||
{
|
||||
if (status == TraceLoggerStatuses.Fatal) { return fatal; }
|
||||
else if (status == TraceLoggerStatuses.Error) { return error; }
|
||||
else if (status == TraceLoggerStatuses.Warning) { return warning; }
|
||||
else if (status == TraceLoggerStatuses.Info) { return info; }
|
||||
else if (status == TraceLoggerStatuses.Service) { return service; }
|
||||
else if (status == TraceLoggerStatuses.Debug) { return debug; }
|
||||
else
|
||||
{
|
||||
throw new StructureHelperException(ErrorStrings.ObjectTypeIsUnknownObj(status));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
18
StructureHelperCommon/Models/Loggers/TraceLoggerStatuses.cs
Normal file
18
StructureHelperCommon/Models/Loggers/TraceLoggerStatuses.cs
Normal file
@@ -0,0 +1,18 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StructureHelperCommon.Models.Loggers
|
||||
{
|
||||
public enum TraceLoggerStatuses
|
||||
{
|
||||
Fatal,
|
||||
Error,
|
||||
Warning,
|
||||
Info,
|
||||
Service,
|
||||
Debug
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
using StructureHelperCommon.Infrastructures.Exceptions;
|
||||
using StructureHelperCommon.Models.Calculators;
|
||||
using StructureHelperCommon.Models.Loggers;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
@@ -20,6 +21,7 @@ namespace StructureHelperCommon.Models.Soils
|
||||
public IResult Result => result;
|
||||
|
||||
public Action<IResult> ActionToOutputResults { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
|
||||
public ITraceLogger? TraceLogger { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
|
||||
|
||||
public AnchorCalculator(SoilAnchor soilAnchor, IAnchorSoilProperties anchorSoilProperties)
|
||||
{
|
||||
|
||||
@@ -9,6 +9,10 @@
|
||||
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="NLog" Version="5.2.8" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Reference Include="LoaderCalculator">
|
||||
<HintPath>..\StructureHelper\Libraries\LoaderCalculator.dll</HintPath>
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
using StructureHelperCommon.Infrastructures.Enums;
|
||||
using StructureHelperCommon.Models.Calculators;
|
||||
using StructureHelperCommon.Models.Forces;
|
||||
using StructureHelperCommon.Models.Loggers;
|
||||
using StructureHelperCommon.Models.Sections;
|
||||
using StructureHelperCommon.Models.Shapes;
|
||||
using StructureHelperCommon.Services.Forces;
|
||||
@@ -25,6 +26,7 @@ namespace StructureHelperLogics.NdmCalculations.Analyses.ByForces
|
||||
public IAccuracy Accuracy { get; set; }
|
||||
public List<IForceCombinationList> ForceCombinationLists { get; private set; }
|
||||
public Action<IResult> ActionToOutputResults { get; set; }
|
||||
public ITraceLogger? TraceLogger { get; set; }
|
||||
|
||||
public void Run()
|
||||
{
|
||||
|
||||
@@ -3,6 +3,7 @@ using LoaderCalculator.Data.Matrix;
|
||||
using LoaderCalculator.Data.ResultData;
|
||||
using LoaderCalculator.Data.SourceData;
|
||||
using StructureHelperCommon.Models.Calculators;
|
||||
using StructureHelperCommon.Models.Loggers;
|
||||
|
||||
namespace StructureHelperLogics.NdmCalculations.Analyses.ByForces
|
||||
{
|
||||
@@ -13,6 +14,7 @@ namespace StructureHelperLogics.NdmCalculations.Analyses.ByForces
|
||||
public IResult Result { get; private set; }
|
||||
|
||||
public Action<IResult> ActionToOutputResults { get; set; }
|
||||
public ITraceLogger? TraceLogger { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
|
||||
|
||||
public ForceTupleCalculator(IForceTupleInputData inputData)
|
||||
{
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using LoaderCalculator.Data.Ndms;
|
||||
using StructureHelperCommon.Models.Calculators;
|
||||
using StructureHelperCommon.Models.Loggers;
|
||||
using StructureHelperCommon.Models.Shapes;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@@ -14,6 +15,8 @@ namespace StructureHelperLogics.NdmCalculations.Analyses.ByForces.LimitCurve.Fac
|
||||
public IEnumerable<INdm> Ndms { get; set; }
|
||||
public PredicateTypes PredicateType { get; set; }
|
||||
public IConvert2DPointTo3DPointLogic ConvertLogic { get; set; }
|
||||
public string Name { get; set; }
|
||||
public ITraceLogger? TraceLogger { get; set; }
|
||||
|
||||
public Predicate<IPoint2D> GetPredicate()
|
||||
{
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
using StructureHelperCommon.Models.Shapes;
|
||||
using StructureHelperCommon.Models.Loggers;
|
||||
using StructureHelperCommon.Models.Shapes;
|
||||
|
||||
namespace StructureHelperLogics.NdmCalculations.Analyses.ByForces.LimitCurve.Factories
|
||||
{
|
||||
public interface IGetPredicateLogic
|
||||
{
|
||||
string Name { get; set; }
|
||||
Predicate<IPoint2D> GetPredicate();
|
||||
ITraceLogger? TraceLogger { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
using StructureHelperCommon.Models.Calculators;
|
||||
using StructureHelperCommon.Models.Loggers;
|
||||
using StructureHelperCommon.Models.Shapes;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@@ -22,5 +23,6 @@ namespace StructureHelperLogics.NdmCalculations.Analyses.ByForces
|
||||
/// <param name="points"></param>
|
||||
/// <returns></returns>
|
||||
List<IPoint2D> GetPoints(IEnumerable<IPoint2D> points);
|
||||
ITraceLogger? TraceLogger { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using StructureHelperCommon.Models.Calculators;
|
||||
using StructureHelperCommon.Models.Loggers;
|
||||
using StructureHelperCommon.Models.Shapes;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@@ -8,10 +9,14 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace StructureHelperLogics.NdmCalculations.Analyses.ByForces
|
||||
{
|
||||
/// <summary>
|
||||
/// Find parameter by point and predicate
|
||||
/// </summary>
|
||||
public interface ILimitCurveParameterLogic : IHasActionByResult, ICloneable
|
||||
{
|
||||
Predicate<Point2D> LimitPredicate { get; set; }
|
||||
IPoint2D CurrentPoint { get; set; }
|
||||
double GetParameter();
|
||||
ITraceLogger? TraceLogger { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using StructureHelperCommon.Infrastructures.Exceptions;
|
||||
using StructureHelperCommon.Models.Calculators;
|
||||
using StructureHelperCommon.Models.Loggers;
|
||||
using StructureHelperCommon.Models.Shapes;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@@ -25,6 +26,7 @@ namespace StructureHelperLogics.NdmCalculations.Analyses.ByForces
|
||||
public IResult Result => result;
|
||||
|
||||
public Action<IResult> ActionToOutputResults { get; set; }
|
||||
public ITraceLogger? TraceLogger { get; set; }
|
||||
|
||||
public LimitCurveCalculator(ILimitCurveLogic limitCurveLogic)
|
||||
{
|
||||
@@ -45,20 +47,27 @@ namespace StructureHelperLogics.NdmCalculations.Analyses.ByForces
|
||||
|
||||
public void Run()
|
||||
{
|
||||
if (TraceLogger is not null) { limitCurveLogic.TraceLogger = TraceLogger; }
|
||||
TraceLogger?.AddMessage($"Calculator type: {GetType()}", TraceLoggerStatuses.Service);
|
||||
TraceLogger?.AddMessage($"Start solution in calculator {Name}");
|
||||
result = new LimitCurveResult();
|
||||
result.IsValid = true;
|
||||
result.Name = Name;
|
||||
SurroundProcLogic.SurroundData = SurroundData;
|
||||
SurroundProcLogic.PointCount = PointCount;
|
||||
TraceLogger?.AddMessage($"Point count {PointCount}");
|
||||
surroundList = SurroundProcLogic.GetPoints();
|
||||
TraceLogger?.AddMessage($"There are {surroundList.Count()} point prepared for calculation");
|
||||
try
|
||||
{
|
||||
limitCurveLogic.ActionToOutputResults = GetCurrentStepNumber;
|
||||
factoredList = limitCurveLogic.GetPoints(surroundList);
|
||||
TraceLogger?.AddMessage($"Solution was successfully obtained for {factoredList.Count()} point");
|
||||
result.Points = factoredList;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
TraceLogger?.AddMessage($"Calculation result is not valid: {ex.Message}", TraceLoggerStatuses.Error);
|
||||
result.IsValid = false;
|
||||
result.Description += ex.Message;
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using StructureHelperCommon.Models.Calculators;
|
||||
using StructureHelperCommon.Models.Loggers;
|
||||
using StructureHelperCommon.Models.Shapes;
|
||||
using StructureHelperLogics.NdmCalculations.Analyses.ByForces.LimitCurve.Factories;
|
||||
|
||||
@@ -17,6 +18,7 @@ namespace StructureHelperLogics.NdmCalculations.Analyses.ByForces
|
||||
|
||||
private object lockObject = new object();
|
||||
public Action<IResult> ActionToOutputResults { get; set; }
|
||||
public ITraceLogger? TraceLogger { get; set; }
|
||||
|
||||
public LimitCurveLogic(ILimitCurveParameterLogic parameterLogic)
|
||||
{
|
||||
@@ -30,22 +32,25 @@ namespace StructureHelperLogics.NdmCalculations.Analyses.ByForces
|
||||
/// <inheritdoc/>
|
||||
public List<IPoint2D> GetPoints(IEnumerable<IPoint2D> points)
|
||||
{
|
||||
if (TraceLogger is not null) { ParameterLogic.TraceLogger = TraceLogger; }
|
||||
result = new();
|
||||
resultList = new();
|
||||
TraceLogger?.AddMessage($"Predicate name is {GetPredicateLogic.Name}");
|
||||
Predicate<IPoint2D> limitPredicate = GetPredicateLogic.GetPredicate();
|
||||
//if predicate is true for point (0,0), then check other point is pointless
|
||||
if (limitPredicate(new Point2D()) == true)
|
||||
{
|
||||
var range = points.Select(point => new Point2D { X = point.X * 0d, Y = point.Y * 0d }).ToList();
|
||||
TraceLogger?.AddMessage($"Predicate is true for point (0d, 0d). All point will be skiped", TraceLoggerStatuses.Warning);
|
||||
var range = points.Select(point => new Point2D { X = 0d, Y = 0d }).ToList();
|
||||
resultList.AddRange(range);
|
||||
return resultList;
|
||||
}
|
||||
pointCount = 0;
|
||||
MultyThreadProc(points);
|
||||
//MonoThreadProc(points);
|
||||
MultiThreadProc(points);
|
||||
return resultList;
|
||||
}
|
||||
|
||||
private void MultyThreadProc(IEnumerable<IPoint2D> points)
|
||||
private void MultiThreadProc(IEnumerable<IPoint2D> points)
|
||||
{
|
||||
Task<IPoint2D>[] tasks = new Task<IPoint2D>[points.Count()];
|
||||
for (int i = 0; i < points.Count(); i++)
|
||||
@@ -63,40 +68,33 @@ namespace StructureHelperLogics.NdmCalculations.Analyses.ByForces
|
||||
}
|
||||
}
|
||||
|
||||
private void MonoThreadProc(IEnumerable<IPoint2D> points)
|
||||
private Point2D FindResultPoint(IPoint2D point)
|
||||
{
|
||||
foreach (var point in points)
|
||||
Predicate<IPoint2D> limitPredicate;
|
||||
lock (lockObject)
|
||||
{
|
||||
FindParameter(point);
|
||||
limitPredicate = GetPredicateLogic.GetPredicate();
|
||||
}
|
||||
}
|
||||
|
||||
private void FindParameter(IPoint2D point)
|
||||
{
|
||||
IPoint2D resultPoint = FindResultPoint(point);
|
||||
resultList.Add(resultPoint);
|
||||
var resultPoint = FindResultPointByPredicate(point, limitPredicate);
|
||||
lock (lockObject)
|
||||
{
|
||||
pointCount++;
|
||||
}
|
||||
result.IterationNumber = pointCount;
|
||||
ActionToOutputResults?.Invoke(result);
|
||||
return resultPoint;
|
||||
}
|
||||
|
||||
private Point2D FindResultPoint(IPoint2D point)
|
||||
private Point2D FindResultPointByPredicate(IPoint2D point, Predicate<IPoint2D> limitPredicate)
|
||||
{
|
||||
double parameter;
|
||||
var locCurrentPoint = point.Clone() as IPoint2D;
|
||||
Predicate<IPoint2D> limitPredicate;
|
||||
lock (lockObject)
|
||||
{
|
||||
limitPredicate = GetPredicateLogic.GetPredicate();
|
||||
}
|
||||
var localCurrentPoint = point.Clone() as IPoint2D;
|
||||
var logic = ParameterLogic.Clone() as ILimitCurveParameterLogic;
|
||||
logic.CurrentPoint = locCurrentPoint;
|
||||
logic.TraceLogger = new TraceLogger();
|
||||
logic.CurrentPoint = localCurrentPoint;
|
||||
logic.LimitPredicate = limitPredicate;
|
||||
double parameter;
|
||||
|
||||
if (limitPredicate(locCurrentPoint) == false)
|
||||
if (limitPredicate(localCurrentPoint) == false)
|
||||
{
|
||||
parameter = 1d;
|
||||
}
|
||||
@@ -107,17 +105,17 @@ namespace StructureHelperLogics.NdmCalculations.Analyses.ByForces
|
||||
|
||||
var resultPoint = new Point2D()
|
||||
{
|
||||
X = locCurrentPoint.X * parameter,
|
||||
Y = locCurrentPoint.Y * parameter
|
||||
X = localCurrentPoint.X * parameter,
|
||||
Y = localCurrentPoint.Y * parameter
|
||||
};
|
||||
lock (lockObject)
|
||||
{
|
||||
pointCount++;
|
||||
TraceLogger?.AddMessage($"Source point (X = {localCurrentPoint.X}, Y = {localCurrentPoint.Y})");
|
||||
TraceLogger?.TraceLoggerEntries.AddRange(logic.TraceLogger.TraceLoggerEntries);
|
||||
TraceLogger?.AddMessage($"Parameter value {parameter} was obtained");
|
||||
TraceLogger?.AddMessage($"Calculated point (X={localCurrentPoint.X} * {parameter} = {resultPoint.X}, Y={localCurrentPoint.Y} * {parameter} = {resultPoint.Y})");
|
||||
}
|
||||
result.IterationNumber = pointCount;
|
||||
ActionToOutputResults?.Invoke(result);
|
||||
return resultPoint;
|
||||
//}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using StructureHelperCommon.Infrastructures.Exceptions;
|
||||
using StructureHelperCommon.Models.Calculators;
|
||||
using StructureHelperCommon.Models.Loggers;
|
||||
using StructureHelperCommon.Models.Shapes;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@@ -15,6 +16,7 @@ namespace StructureHelperLogics.NdmCalculations.Analyses.ByForces
|
||||
public Predicate<Point2D> LimitPredicate { get; set; }
|
||||
public IPoint2D CurrentPoint { get; set; }
|
||||
public Action<IResult> ActionToOutputResults { get; set; }
|
||||
public ITraceLogger? TraceLogger { get; set; }
|
||||
|
||||
public LimitCurveParameterLogic()
|
||||
{
|
||||
@@ -27,6 +29,7 @@ namespace StructureHelperLogics.NdmCalculations.Analyses.ByForces
|
||||
{
|
||||
Predicate = GetFactorPredicate,
|
||||
};
|
||||
if (TraceLogger is not null) { parameterCalculator.TraceLogger = TraceLogger; }
|
||||
parameterCalculator.Accuracy.IterationAccuracy = 0.001d;
|
||||
parameterCalculator.Run();
|
||||
if (parameterCalculator.Result.IsValid == false)
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using LoaderCalculator.Data.Ndms;
|
||||
using StructureHelperCommon.Infrastructures.Interfaces;
|
||||
using StructureHelperCommon.Models.Calculators;
|
||||
using StructureHelperCommon.Models.Loggers;
|
||||
using StructureHelperCommon.Models.Shapes;
|
||||
using StructureHelperLogics.Models.Calculations.CalculationsResults;
|
||||
using StructureHelperLogics.NdmCalculations.Analyses.ByForces.LimitCurve.Factories;
|
||||
@@ -29,6 +30,8 @@ namespace StructureHelperLogics.NdmCalculations.Analyses.ByForces
|
||||
public IResult Result => result;
|
||||
|
||||
public Action<IResult> ActionToOutputResults { get; set; }
|
||||
public ITraceLogger? TraceLogger { get; set; }
|
||||
|
||||
public LimitCurvesCalculator()
|
||||
{
|
||||
Name = "New calculator";
|
||||
@@ -36,6 +39,8 @@ namespace StructureHelperLogics.NdmCalculations.Analyses.ByForces
|
||||
}
|
||||
public void Run()
|
||||
{
|
||||
TraceLogger?.AddMessage($"Calculator type: {GetType()}", TraceLoggerStatuses.Service);
|
||||
TraceLogger?.AddMessage($"Start solution in calculator {Name}");
|
||||
GetNewResult();
|
||||
try
|
||||
{
|
||||
@@ -46,7 +51,10 @@ namespace StructureHelperLogics.NdmCalculations.Analyses.ByForces
|
||||
item.Run();
|
||||
var locResult = item.Result as LimitCurveResult;
|
||||
result.LimitCurveResults.Add(locResult);
|
||||
if (locResult.IsValid == false) { result.Description += locResult.Description; }
|
||||
if (locResult.IsValid == false)
|
||||
{
|
||||
result.Description += locResult.Description;
|
||||
}
|
||||
result.IterationNumber = curvesIterationCount * InputData.PointCount + locResult.IterationNumber;
|
||||
ActionToOutputResults?.Invoke(result);
|
||||
curvesIterationCount++;
|
||||
@@ -54,6 +62,7 @@ namespace StructureHelperLogics.NdmCalculations.Analyses.ByForces
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
TraceLogger?.AddMessage($"Calculation result is not valid: {ex.Message}", TraceLoggerStatuses.Error);
|
||||
result.IsValid = false;
|
||||
result.Description += ex;
|
||||
}
|
||||
@@ -81,6 +90,7 @@ namespace StructureHelperLogics.NdmCalculations.Analyses.ByForces
|
||||
{
|
||||
string calcName = $"{primitiveSeries.Name}_{predicateEntry.Name}_{limitState}_{calcTerm}";
|
||||
LimitCurveCalculator calculator = GetCalculator(ndms, predicateEntry.PredicateType, calcName);
|
||||
if (TraceLogger is not null) { calculator.TraceLogger = TraceLogger; }
|
||||
calculators.Add(calculator);
|
||||
}
|
||||
}
|
||||
@@ -91,18 +101,14 @@ namespace StructureHelperLogics.NdmCalculations.Analyses.ByForces
|
||||
|
||||
private LimitCurveCalculator GetCalculator(List<INdm> ndms, PredicateTypes predicateType, string calcName)
|
||||
{
|
||||
var factory = new PredicateFactory()
|
||||
{
|
||||
Ndms = ndms,
|
||||
ConvertLogic = InputData.SurroundData.ConvertLogicEntity.ConvertLogic
|
||||
};
|
||||
var predicate = factory.GetPredicate(predicateType);
|
||||
var getPredicateLogic = new GetPredicateLogic()
|
||||
{
|
||||
Name = calcName,
|
||||
Ndms = ndms,
|
||||
ConvertLogic = InputData.SurroundData.ConvertLogicEntity.ConvertLogic,
|
||||
PredicateType = predicateType
|
||||
};
|
||||
if (TraceLogger is not null) { getPredicateLogic.TraceLogger = TraceLogger; }
|
||||
var logic = new LimitCurveLogic(getPredicateLogic);
|
||||
var calculator = new LimitCurveCalculator(logic)
|
||||
{
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using StructureHelperCommon.Models.Calculators;
|
||||
using StructureHelperCommon.Models.Loggers;
|
||||
using StructureHelperCommon.Models.Shapes;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@@ -11,6 +12,7 @@ namespace StructureHelperLogics.NdmCalculations.Analyses.ByForces
|
||||
public class StabLimitCurveLogic : ILimitCurveLogic
|
||||
{
|
||||
public Action<IResult> ActionToOutputResults { get; set; }
|
||||
public ITraceLogger? TraceLogger { get; set; }
|
||||
|
||||
public List<IPoint2D> GetPoints(IEnumerable<IPoint2D> points)
|
||||
{
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using StructureHelperCommon.Infrastructures.Interfaces;
|
||||
using StructureHelperCommon.Models.Calculators;
|
||||
using StructureHelperCommon.Models.Forces;
|
||||
using StructureHelperCommon.Models.Loggers;
|
||||
using StructureHelperLogics.Services.NdmCalculations;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@@ -23,6 +24,8 @@ namespace StructureHelperLogics.NdmCalculations.Analyses.ByForces.Logics
|
||||
|
||||
public int StepCount => interpolateTuplesResult.StepCount + 1;
|
||||
|
||||
public ITraceLogger? TraceLogger { get; set; }
|
||||
|
||||
public void WorkerDoWork(object sender, DoWorkEventArgs e)
|
||||
{
|
||||
InterpolateCalculator = InterpolateService.InterpolateForceCalculator(forceCalculator, interpolateTuplesResult);
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using LoaderCalculator.Data.Matrix;
|
||||
using LoaderCalculator.Data.Ndms;
|
||||
using StructureHelperCommon.Models.Calculators;
|
||||
using StructureHelperCommon.Models.Loggers;
|
||||
using StructureHelperLogics.Services.NdmPrimitives;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@@ -19,6 +20,7 @@ namespace StructureHelperLogics.NdmCalculations.Analyses.Geometry
|
||||
public IResult Result => geometryResult;
|
||||
|
||||
public Action<IResult> ActionToOutputResults { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
|
||||
public ITraceLogger? TraceLogger { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
|
||||
|
||||
public GeometryCalculator(IEnumerable<INdm> ndms, IStrainMatrix strainMatrix)
|
||||
{
|
||||
|
||||
@@ -3,6 +3,7 @@ using LoaderCalculator.Logics;
|
||||
using LoaderCalculator.Logics.Geometry;
|
||||
using StructureHelperCommon.Models.Calculators;
|
||||
using StructureHelperCommon.Models.Forces;
|
||||
using StructureHelperCommon.Models.Loggers;
|
||||
using StructureHelperCommon.Models.Shapes;
|
||||
using StructureHelperLogics.Models.Materials;
|
||||
using StructureHelperLogics.NdmCalculations.Analyses;
|
||||
@@ -28,6 +29,7 @@ namespace StructureHelperLogics.NdmCalculations.Buckling
|
||||
|
||||
public IAccuracy Accuracy { get; set; }
|
||||
public Action<IResult> ActionToOutputResults { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
|
||||
public ITraceLogger? TraceLogger { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
|
||||
|
||||
private (double EtaAlongX, double EtaAlongY) GetBucklingCoefficients()
|
||||
{
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
using StructureHelperCommon.Infrastructures.Exceptions;
|
||||
using StructureHelperCommon.Models.Calculators;
|
||||
using StructureHelperCommon.Models.Forces;
|
||||
using StructureHelperCommon.Models.Loggers;
|
||||
using StructureHelperCommon.Services;
|
||||
using StructureHelperCommon.Services.Forces;
|
||||
using StructureHelperLogics.NdmCalculations.Analyses.ByForces;
|
||||
@@ -30,6 +31,8 @@ namespace StructureHelperLogics.NdmCalculations.Cracking
|
||||
public Accuracy Accuracy {get;set; }
|
||||
public IResult Result => result;
|
||||
|
||||
public ITraceLogger? TraceLogger { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
|
||||
|
||||
public CrackForceCalculator(IForceTupleCalculator forceTupleCalculator)
|
||||
{
|
||||
StartTuple ??= new ForceTuple();
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
using StructureHelperCommon.Infrastructures.Exceptions;
|
||||
using StructureHelperCommon.Models.Calculators;
|
||||
using StructureHelperCommon.Models.Forces;
|
||||
using StructureHelperCommon.Models.Loggers;
|
||||
using StructureHelperCommon.Services.Forces;
|
||||
using StructureHelperLogics.NdmCalculations.Analyses.ByForces;
|
||||
using StructureHelperLogics.NdmCalculations.Primitives;
|
||||
@@ -24,6 +25,8 @@ namespace StructureHelperLogics.NdmCalculations.Cracking
|
||||
public CrackWidthCalculatorInputData InputData { get; set; }
|
||||
public IResult Result => result;
|
||||
|
||||
public ITraceLogger? TraceLogger { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
|
||||
|
||||
public void Run()
|
||||
{
|
||||
result = new() { IsValid = true, Description = ""};
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using StructureHelperCommon.Models.Calculators;
|
||||
using StructureHelperCommon.Models.Loggers;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
@@ -16,6 +17,7 @@ namespace StructureHelperLogics.NdmCalculations.Cracking
|
||||
public IResult Result => result;
|
||||
|
||||
public Action<IResult> ActionToOutputResults { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
|
||||
public ITraceLogger? TraceLogger { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
|
||||
|
||||
public void Run()
|
||||
{
|
||||
|
||||
@@ -16,6 +16,7 @@ namespace StructureHelperTests.UnitTests.Calcuators
|
||||
var calculator = new LimitCurveCalculator(new StabLimitCurveLogic())
|
||||
{
|
||||
};
|
||||
calculator.PointCount = 12;
|
||||
calculator.SurroundData.XMax = xmax;
|
||||
calculator.SurroundData.XMin = -xmax;
|
||||
calculator.SurroundData.YMax = ymax;
|
||||
|
||||
@@ -14,9 +14,6 @@ namespace StructureHelperTests.UnitTests.Calcuators
|
||||
public void GetPoints_ValidPoints_ReturnsTransformedPoints()
|
||||
{
|
||||
// Arrange
|
||||
var parameterLogicMock = new Mock<ILimitCurveParameterLogic>();
|
||||
parameterLogicMock.Setup(p => p.GetParameter()).Returns(2.0); // Mocking the GetParameter method
|
||||
|
||||
var getPredicateLogic = new Mock<IGetPredicateLogic>();
|
||||
getPredicateLogic.Setup(p => p.GetPredicate()).Returns(point => point.X >= 0.5d);//
|
||||
|
||||
@@ -39,34 +36,9 @@ namespace StructureHelperTests.UnitTests.Calcuators
|
||||
|
||||
for (int i = 0; i < inputPoints.Count; i++)
|
||||
{
|
||||
Assert.AreEqual(inputPoints[i].X * 0.5, result[i].X);
|
||||
Assert.AreEqual(inputPoints[i].Y * 0.5, result[i].Y);
|
||||
}
|
||||
|
||||
// Verify that GetParameter was called
|
||||
parameterLogicMock.Verify(p => p.GetParameter(), Times.Exactly(inputPoints.Count));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetPoints_InvalidPredicate_ThrowsException()
|
||||
{
|
||||
// Arrange
|
||||
var parameterLogicMock = new Mock<ILimitCurveParameterLogic>();
|
||||
parameterLogicMock.Setup(p => p.GetParameter()).Returns(2.0);
|
||||
|
||||
var getPredicateLogic = new Mock<IGetPredicateLogic>();
|
||||
getPredicateLogic.Setup(p => p.GetPredicate()).Returns(point => point.X >= 0.5d);//
|
||||
|
||||
var limitCurveLogic = new LimitCurveLogic(getPredicateLogic.Object);
|
||||
|
||||
var inputPoints = new List<IPoint2D>
|
||||
{
|
||||
new Point2D { X = 1, Y = 2 },
|
||||
new Point2D { X = 3, Y = 4 }
|
||||
};
|
||||
|
||||
// Act & Assert
|
||||
Assert.Throws<StructureHelperException>(() => limitCurveLogic.GetPoints(inputPoints));
|
||||
Assert.AreEqual(0.5d, result[i].X, 0.01d);
|
||||
Assert.AreEqual(inputPoints[i].Y / inputPoints[i].X * 0.5d, result[i].Y, 0.01d);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user