Interactin diagram was added

This commit is contained in:
Evgeny Redikultsev
2023-12-02 21:50:10 +05:00
parent 8de8c00182
commit 1b635cbf69
47 changed files with 619 additions and 146 deletions

View File

@@ -8,7 +8,7 @@ using System.Threading.Tasks;
namespace StructureHelperCommon.Models.Calculators
{
public class FindParameterCalculator : ICalculator
public class FindParameterCalculator : ICalculator, IHasActionByResult
{
FindParameterResult result;
public string Name { get; set; }
@@ -18,21 +18,20 @@ namespace StructureHelperCommon.Models.Calculators
public IAccuracy Accuracy {get;set;}
public IResult Result => result;
public Action<IResult> ActionToOutputResults { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
public Action<IResult> ActionToOutputResults { get; set; }
public FindParameterCalculator()
{
StartValue = 0d;
EndValue = 1d;
Accuracy = new Accuracy() { IterationAccuracy = 0.001, MaxIterationCount = 1000 };
Accuracy = new Accuracy() { IterationAccuracy = 0.001d, MaxIterationCount = 1000 };
}
public void Run()
{
result = new() { IsValid = true};
result = new();
try
{
result.Parameter = FindMinimumValue(StartValue, EndValue, Predicate);
result.Description = "Parameter was found succefully";
FindMinimumValue(StartValue, EndValue, Predicate);
}
catch(Exception ex)
{
@@ -45,7 +44,7 @@ namespace StructureHelperCommon.Models.Calculators
throw new NotImplementedException();
}
private double FindMinimumValue(double start, double end, Predicate<double> predicate)
private void FindMinimumValue(double start, double end, Predicate<double> predicate)
{
if (predicate(end) == false)
{
@@ -59,7 +58,7 @@ namespace StructureHelperCommon.Models.Calculators
int iterationNum = 0;
while (step > precision)
{
if (predicate(current))
if (predicate(current) == true)
{
end = current;
}
@@ -71,13 +70,23 @@ namespace StructureHelperCommon.Models.Calculators
current = (start + end) / 2;
step = (end - start) / 2;
iterationNum++;
result.IsValid = false;
result.IterationNumber = iterationNum;
result.CurrentAccuracy = step;
ActionToOutputResults?.Invoke(result);
if (iterationNum > maxIterationCount)
{
result.Description = "Parameter was not found succefully: \n";
throw new StructureHelperException(ErrorStrings.DataIsInCorrect + ": violation of iteration count");
}
}
return current;
result.Parameter = current;
result.Description = "Parameter was found succefully";
result.IsValid = true;
ActionToOutputResults?.Invoke(result);
}
}
}

View File

@@ -6,10 +6,12 @@ using System.Threading.Tasks;
namespace StructureHelperCommon.Models.Calculators
{
public class FindParameterResult : IResult
public class FindParameterResult : IResult, IiterationResult
{
public bool IsValid { get; set; }
public string Description { get; set; }
public double Parameter { get; set; }
public int IterationNumber { get; set; }
public double CurrentAccuracy { get; set; }
}
}

View File

@@ -20,6 +20,5 @@ namespace StructureHelperCommon.Models.Calculators
/// Result of Calculations
/// </summary>
IResult Result { get; }
Action<IResult> ActionToOutputResults { get; set; }
}
}

View File

@@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace StructureHelperCommon.Models.Calculators
{
public interface IHasActionByResult
{
Action<IResult> ActionToOutputResults { get; set; }
}
}

View File

@@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace StructureHelperCommon.Models.Calculators
{
public interface IiterationResult
{
int IterationNumber { get; set; }
}
}

View File

@@ -8,6 +8,12 @@ namespace StructureHelperCommon.Services.Forces
{
public static class ForceTupleService
{
/// <summary>
/// Copy properties from target to source
/// </summary>
/// <param name="source">Source tuple</param>
/// <param name="target">Target tuple</param>
/// <param name="factor">factor</param>
public static void CopyProperties(IForceTuple source, IForceTuple target, double factor = 1d)
{
CheckTuples(source, target);