Crack Calculator was added
This commit is contained in:
@@ -18,5 +18,6 @@
|
||||
public static string LongitudinalForceMustBeLessThanCriticalForce => "#0013: Absolute value of longitudinal force must be greater than critical force";
|
||||
public static string SizeMustBeGreaterThanZero => "#0014: Size must be greater than zero";
|
||||
public static string ParameterIsNull => "#0015: Parameter is null";
|
||||
public static string ResultIsNotValid => "#0016: Result is not valid";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,81 @@
|
||||
using StructureHelperCommon.Infrastructures.Exceptions;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StructureHelperCommon.Models.Calculators
|
||||
{
|
||||
public class FindParameterCalculator : ICalculator
|
||||
{
|
||||
FindParameterResult result;
|
||||
public string Name { get; set; }
|
||||
public double StartValue { get; set; }
|
||||
public double EndValue { get; set; }
|
||||
public Predicate<double> Predicate { get; set; }
|
||||
public IAccuracy Accuracy {get;set;}
|
||||
public IResult Result => result;
|
||||
|
||||
public FindParameterCalculator()
|
||||
{
|
||||
StartValue = 0d;
|
||||
EndValue = 1d;
|
||||
Accuracy = new Accuracy() { IterationAccuracy = 0.001, MaxIterationCount = 1000 };
|
||||
}
|
||||
public void Run()
|
||||
{
|
||||
result = new() { IsValid = true};
|
||||
try
|
||||
{
|
||||
result.Parameter = FindMinimumValue(StartValue, EndValue, Predicate);
|
||||
result.Description = "Parameter was found succefully";
|
||||
}
|
||||
catch(Exception ex)
|
||||
{
|
||||
result.IsValid = false;
|
||||
result.Description += ex;
|
||||
}
|
||||
}
|
||||
public object Clone()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
private double FindMinimumValue(double start, double end, Predicate<double> predicate)
|
||||
{
|
||||
if (predicate(end) == false)
|
||||
{
|
||||
throw new StructureHelperException(ErrorStrings.DataIsInCorrect + ": pridicate for end value must be true");
|
||||
|
||||
}
|
||||
double precision = Accuracy.IterationAccuracy;
|
||||
int maxIterationCount = Accuracy.MaxIterationCount;
|
||||
double current = start;
|
||||
double step = (end - start) / 2;
|
||||
int iterationNum = 0;
|
||||
while (step > precision)
|
||||
{
|
||||
if (predicate(current))
|
||||
{
|
||||
end = current;
|
||||
}
|
||||
else
|
||||
{
|
||||
start = current;
|
||||
}
|
||||
|
||||
current = (start + end) / 2;
|
||||
step = (end - start) / 2;
|
||||
iterationNum++;
|
||||
if (iterationNum > maxIterationCount)
|
||||
{
|
||||
throw new StructureHelperException(ErrorStrings.DataIsInCorrect + ": violation of iteration count");
|
||||
}
|
||||
}
|
||||
|
||||
return current;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StructureHelperCommon.Models.Calculators
|
||||
{
|
||||
public class FindParameterResult : IResult
|
||||
{
|
||||
public bool IsValid { get; set; }
|
||||
public string Description { get; set; }
|
||||
public double Parameter { get; set; }
|
||||
}
|
||||
}
|
||||
23
StructureHelperCommon/Models/Calculators/ICalculator.cs
Normal file
23
StructureHelperCommon/Models/Calculators/ICalculator.cs
Normal file
@@ -0,0 +1,23 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using TaskManager;
|
||||
|
||||
namespace StructureHelperCommon.Models.Calculators
|
||||
{
|
||||
public interface ICalculator : ICloneable
|
||||
{
|
||||
string Name { get; set; }
|
||||
/// <summary>
|
||||
/// Method for calculating
|
||||
/// </summary>
|
||||
void Run();
|
||||
/// <summary>
|
||||
/// Result of Calculations
|
||||
/// </summary>
|
||||
IResult Result { get; }
|
||||
}
|
||||
}
|
||||
17
StructureHelperCommon/Models/Calculators/IResult.cs
Normal file
17
StructureHelperCommon/Models/Calculators/IResult.cs
Normal file
@@ -0,0 +1,17 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StructureHelperCommon.Models.Calculators
|
||||
{
|
||||
public interface IResult
|
||||
{
|
||||
/// <summary>
|
||||
/// True if result of calculation is valid
|
||||
/// </summary>
|
||||
bool IsValid { get; set; }
|
||||
string Description { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
using StructureHelperCommon.Infrastructures.Interfaces;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StructureHelperCommon.Models.Calculators
|
||||
{
|
||||
public class AccuracyUpdateStrategy : IUpdateStrategy<IAccuracy>
|
||||
{
|
||||
public void Update(IAccuracy targetObject, IAccuracy sourceObject)
|
||||
{
|
||||
targetObject.IterationAccuracy = sourceObject.IterationAccuracy;
|
||||
targetObject.MaxIterationCount = sourceObject.MaxIterationCount;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -13,7 +13,7 @@ namespace StructureHelperCommon.Models.Forces
|
||||
{
|
||||
public class ForceActionUpdateStrategy : IUpdateStrategy<IForceAction>
|
||||
{
|
||||
private readonly IUpdateStrategy<IPoint2D> pointStrategy = new PointUpdateStrategy();
|
||||
private readonly IUpdateStrategy<IPoint2D> pointStrategy = new PointShapeUpdateStrategy();
|
||||
private readonly IUpdateStrategy<IDesignForcePair> forcePairUpdateStrategy = new ForcePairUpdateStrategy();
|
||||
private readonly IUpdateStrategy<IForceCombinationByFactor> factorUpdateStrategy = new FactorCombinationUpdateStrategy();
|
||||
private readonly IUpdateStrategy<IForceCombinationList> forceListUpdateStrategy = new ForceCombinationListUpdateStrategy();
|
||||
|
||||
@@ -9,7 +9,7 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace StructureHelperCommon.Models.Forces
|
||||
{
|
||||
internal class ForceTupleUpdateStrategy : IUpdateStrategy<IForceTuple>
|
||||
public class ForceTupleUpdateStrategy : IUpdateStrategy<IForceTuple>
|
||||
{
|
||||
public void Update(IForceTuple targetObject, IForceTuple sourceObject)
|
||||
{
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
using StructureHelperCommon.Services.Sections;
|
||||
|
||||
namespace StructureHelperCommon.Models.Sections
|
||||
namespace StructureHelperCommon.Models.Sections
|
||||
{
|
||||
public class CompressedMember : ICompressedMember
|
||||
{
|
||||
static readonly CompressedMemberUpdateStrategy updateStrategy = new();
|
||||
public bool Buckling { get; set; }
|
||||
public double GeometryLength { get; set; }
|
||||
public double LengthFactorX { get; set; }
|
||||
@@ -24,9 +23,9 @@ namespace StructureHelperCommon.Models.Sections
|
||||
|
||||
public object Clone()
|
||||
{
|
||||
var target = new CompressedMember();
|
||||
CompressedMemberServices.CopyProperties(this, target);
|
||||
return target;
|
||||
var newItem = new CompressedMember();
|
||||
updateStrategy.Update(newItem, this);
|
||||
return newItem;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
using StructureHelperCommon.Infrastructures.Interfaces;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StructureHelperCommon.Models.Sections
|
||||
{
|
||||
public class CompressedMemberUpdateStrategy : IUpdateStrategy<ICompressedMember>
|
||||
{
|
||||
public void Update(ICompressedMember targetObject, ICompressedMember sourceObject)
|
||||
{
|
||||
targetObject.Buckling = sourceObject.Buckling;
|
||||
targetObject.GeometryLength = sourceObject.GeometryLength;
|
||||
targetObject.LengthFactorX = sourceObject.LengthFactorX;
|
||||
targetObject.DiagramFactorX = sourceObject.DiagramFactorX;
|
||||
targetObject.LengthFactorY = sourceObject.LengthFactorY;
|
||||
targetObject.DiagramFactorY = sourceObject.DiagramFactorY;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
using StructureHelperCommon.Infrastructures.Interfaces;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StructureHelperCommon.Models.Shapes
|
||||
{
|
||||
public class CircleShapeUpdateStrategy : IUpdateStrategy<ICircleShape>
|
||||
{
|
||||
public void Update(ICircleShape targetObject, ICircleShape sourceObject)
|
||||
{
|
||||
targetObject.Diameter = sourceObject.Diameter;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
using StructureHelperCommon.Infrastructures.Interfaces;
|
||||
using StructureHelperCommon.Models.Shapes.Logics;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StructureHelperCommon.Models.Shapes
|
||||
{
|
||||
public class LineShapeUpdateStrategy : IUpdateStrategy<ILineShape>
|
||||
{
|
||||
readonly PointShapeUpdateStrategy pointUpdateStrategy = new();
|
||||
public void Update(ILineShape targetObject, ILineShape sourceObject)
|
||||
{
|
||||
pointUpdateStrategy.Update(targetObject.StartPoint, sourceObject.StartPoint);
|
||||
pointUpdateStrategy.Update(targetObject.EndPoint, sourceObject.EndPoint);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -8,7 +8,7 @@ using System.Threading.Tasks;
|
||||
namespace StructureHelperCommon.Models.Shapes.Logics
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public class PointUpdateStrategy : IUpdateStrategy<IPoint2D>
|
||||
public class PointShapeUpdateStrategy : IUpdateStrategy<IPoint2D>
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public void Update(IPoint2D targetObject, IPoint2D sourceObject)
|
||||
@@ -0,0 +1,19 @@
|
||||
using StructureHelperCommon.Infrastructures.Interfaces;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StructureHelperCommon.Models.Shapes
|
||||
{
|
||||
public class RectangleShapeUpdateStrategy : IUpdateStrategy<IRectangleShape>
|
||||
{
|
||||
public void Update(IRectangleShape targetObject, IRectangleShape sourceObject)
|
||||
{
|
||||
targetObject.Width = sourceObject.Width;
|
||||
targetObject.Height = sourceObject.Height;
|
||||
targetObject.Angle = sourceObject.Angle;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -7,7 +7,7 @@ namespace StructureHelperCommon.Models.Shapes
|
||||
/// <inheritdoc />
|
||||
public class Point2D : IPoint2D
|
||||
{
|
||||
private readonly IUpdateStrategy<IPoint2D> updateStrategy = new PointUpdateStrategy();
|
||||
private readonly IUpdateStrategy<IPoint2D> updateStrategy = new PointShapeUpdateStrategy();
|
||||
/// <inheritdoc />
|
||||
public Guid Id { get; }
|
||||
/// <inheritdoc />
|
||||
|
||||
@@ -1,13 +0,0 @@
|
||||
using StructureHelperCommon.Models.Calculators;
|
||||
|
||||
namespace StructureHelperCommon.Services.Calculations
|
||||
{
|
||||
public static class AccuracyService
|
||||
{
|
||||
public static void CopyProperties(IAccuracy source, IAccuracy target)
|
||||
{
|
||||
target.IterationAccuracy = source.IterationAccuracy;
|
||||
target.MaxIterationCount = source.MaxIterationCount;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
using StructureHelperCommon.Models.Sections;
|
||||
|
||||
namespace StructureHelperCommon.Services.Sections
|
||||
{
|
||||
public static class CompressedMemberServices
|
||||
{
|
||||
public static void CopyProperties(ICompressedMember source, ICompressedMember target)
|
||||
{
|
||||
target.Buckling = source.Buckling;
|
||||
target.GeometryLength = source.GeometryLength;
|
||||
target.LengthFactorX = source.LengthFactorX;
|
||||
target.DiagramFactorX = source.DiagramFactorX;
|
||||
target.LengthFactorY = source.LengthFactorY;
|
||||
target.DiagramFactorY = source.DiagramFactorY;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,27 +0,0 @@
|
||||
using StructureHelperCommon.Models.Shapes;
|
||||
|
||||
namespace StructureHelperCommon.Services.ShapeServices
|
||||
{
|
||||
public static class ShapeService
|
||||
{
|
||||
public static void CopyLineProperties(ILineShape source, ILineShape target)
|
||||
{
|
||||
target.StartPoint.X = source.StartPoint.X;
|
||||
target.StartPoint.Y = source.StartPoint.Y;
|
||||
target.EndPoint.X = source.EndPoint.X;
|
||||
target.EndPoint.Y = source.EndPoint.Y;
|
||||
}
|
||||
|
||||
public static void CopyRectangleProperties(IRectangleShape source, IRectangleShape target)
|
||||
{
|
||||
target.Width = source.Width;
|
||||
target.Height = source.Height;
|
||||
target.Angle = source.Angle;
|
||||
}
|
||||
|
||||
public static void CopyCircleProperties(ICircleShape source, ICircleShape target)
|
||||
{
|
||||
target.Diameter = source.Diameter;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user