Force crack calculator was fixed
This commit is contained in:
@@ -1,7 +1,10 @@
|
||||
using StructureHelperCommon.Infrastructures.Interfaces;
|
||||
using StructureHelperCommon.Infrastructures.Exceptions;
|
||||
using StructureHelperCommon.Infrastructures.Interfaces;
|
||||
using StructureHelperCommon.Infrastructures.Settings;
|
||||
using StructureHelperCommon.Models;
|
||||
using StructureHelperCommon.Models.Calculators;
|
||||
using StructureHelperCommon.Models.Forces;
|
||||
using StructureHelperLogics.NdmCalculations.Cracking;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
@@ -10,46 +13,77 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace StructureHelperLogics.NdmCalculations.Analyses.ByForces
|
||||
{
|
||||
internal class CheckForceCalculatorInputData : ICheckInputDataLogic<ForceInputData>
|
||||
internal class CheckForceCalculatorInputData : ICheckInputDataLogic<IForceInputData>
|
||||
{
|
||||
|
||||
public ForceInputData InputData { get; set; }
|
||||
private bool result;
|
||||
private string checkResult;
|
||||
private ICheckEntityLogic<IAccuracy> checkAccuracyLogic;
|
||||
|
||||
public string CheckResult { get; private set; }
|
||||
public IForceInputData InputData { get; set; }
|
||||
|
||||
public string CheckResult => checkResult;
|
||||
|
||||
public IShiftTraceLogger? TraceLogger { get; set; }
|
||||
|
||||
public CheckForceCalculatorInputData(ForceInputData inputData)
|
||||
public CheckForceCalculatorInputData(ICheckEntityLogic<IAccuracy> checkAccuracyLogic)
|
||||
{
|
||||
InputData = inputData;
|
||||
CheckResult = string.Empty;
|
||||
this.checkAccuracyLogic = checkAccuracyLogic;
|
||||
}
|
||||
|
||||
public CheckForceCalculatorInputData() : this(new CheckAccuracyLogic())
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public bool Check()
|
||||
{
|
||||
bool result = true;
|
||||
CheckResult = string.Empty;
|
||||
if (!InputData.Primitives.Any())
|
||||
result = true;
|
||||
checkResult = string.Empty;
|
||||
if (InputData is null)
|
||||
{
|
||||
CheckResult += "Calculator does not contain any primitives \n";
|
||||
string errorString = ErrorStrings.ParameterIsNull + ": input data";
|
||||
TraceMessage(errorString);
|
||||
throw new StructureHelperException(errorString);
|
||||
}
|
||||
if (InputData.Primitives is null || !InputData.Primitives.Any())
|
||||
{
|
||||
TraceMessage("Calculator does not contain any primitives");
|
||||
result = false;
|
||||
}
|
||||
if (!InputData.ForceActions.Any())
|
||||
if (InputData.ForceActions is null || !InputData.ForceActions.Any())
|
||||
{
|
||||
CheckResult += "Calculator does not contain any forces \n";
|
||||
TraceMessage("Calculator does not contain any forces");
|
||||
result = false;
|
||||
}
|
||||
if (!InputData.LimitStatesList.Any())
|
||||
if (InputData.LimitStatesList is null || !InputData.LimitStatesList.Any())
|
||||
{
|
||||
CheckResult += "Calculator does not contain any limit states \n";
|
||||
TraceMessage("Calculator does not contain any limit states");
|
||||
result = false;
|
||||
}
|
||||
if (!InputData.CalcTermsList.Any())
|
||||
if (InputData.CalcTermsList is null || !InputData.CalcTermsList.Any())
|
||||
{
|
||||
CheckResult += "Calculator does not contain any calc term \n";
|
||||
TraceMessage("Calculator does not contain any calc term");
|
||||
result = false;
|
||||
}
|
||||
CheckAccuracy();
|
||||
return result;
|
||||
}
|
||||
|
||||
private void CheckAccuracy()
|
||||
{
|
||||
checkAccuracyLogic.Entity = InputData.Accuracy;
|
||||
checkAccuracyLogic.TraceLogger = TraceLogger;
|
||||
if (checkAccuracyLogic.Check() == false)
|
||||
{
|
||||
result = false;
|
||||
}
|
||||
TraceMessage(checkAccuracyLogic.CheckResult);
|
||||
}
|
||||
|
||||
private void TraceMessage(string errorString)
|
||||
{
|
||||
checkResult += errorString + "\n";
|
||||
TraceLogger?.AddMessage(errorString, TraceLogStatuses.Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,8 +8,8 @@ namespace StructureHelperLogics.NdmCalculations.Analyses.ByForces
|
||||
{
|
||||
public class ForceCalculator : ICalculator, IHasActionByResult
|
||||
{
|
||||
private IUpdateStrategy<ForceCalculator> updateStrategy = new ForceCalculatorUpdateStrategy();
|
||||
private ICheckInputDataLogic<ForceInputData> checkInputDataLogic;
|
||||
private IUpdateStrategy<ForceCalculator> updateStrategy;
|
||||
private ICheckInputDataLogic<IForceInputData> checkInputDataLogic;
|
||||
private IForceCalculatorLogic forceCalculatorLogic;
|
||||
|
||||
|
||||
@@ -19,11 +19,30 @@ namespace StructureHelperLogics.NdmCalculations.Analyses.ByForces
|
||||
public IShiftTraceLogger? TraceLogger { get; set; }
|
||||
public IResult Result { get; private set; }
|
||||
|
||||
public ForceCalculator(ICheckInputDataLogic<IForceInputData> checkInputDataLogic,
|
||||
IForceCalculatorLogic forceCalculatorLogic,
|
||||
IUpdateStrategy<ForceCalculator> updateStrategy
|
||||
)
|
||||
{
|
||||
this.checkInputDataLogic = checkInputDataLogic;
|
||||
this.forceCalculatorLogic = forceCalculatorLogic;
|
||||
this.updateStrategy = updateStrategy;
|
||||
|
||||
InputData = new ForceInputData();
|
||||
}
|
||||
|
||||
public ForceCalculator() :
|
||||
this(new CheckForceCalculatorInputData(),
|
||||
new ForceCalculatorLogic(),
|
||||
new ForceCalculatorUpdateStrategy())
|
||||
{
|
||||
}
|
||||
|
||||
public void Run()
|
||||
{
|
||||
TraceLogger?.AddMessage(LoggerStrings.CalculatorType(this), TraceLogStatuses.Service);
|
||||
checkInputDataLogic = new CheckForceCalculatorInputData(InputData);
|
||||
checkInputDataLogic.TraceLogger?.GetSimilarTraceLogger(50);
|
||||
checkInputDataLogic.InputData = InputData;
|
||||
checkInputDataLogic.TraceLogger = TraceLogger;
|
||||
if (checkInputDataLogic.Check() != true)
|
||||
{
|
||||
Result = new ForcesResults()
|
||||
@@ -33,6 +52,7 @@ namespace StructureHelperLogics.NdmCalculations.Analyses.ByForces
|
||||
};
|
||||
return;
|
||||
}
|
||||
forceCalculatorLogic.InputData = InputData;
|
||||
if (ActionToOutputResults is not null)
|
||||
{
|
||||
forceCalculatorLogic.ActionToOutputResults = ActionToOutputResults;
|
||||
@@ -46,31 +66,9 @@ namespace StructureHelperLogics.NdmCalculations.Analyses.ByForces
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public ForceCalculator(ForceInputData inputData,
|
||||
ICheckInputDataLogic<ForceInputData> checkInputDataLogic,
|
||||
IForceCalculatorLogic forceCalculatorLogic,
|
||||
IUpdateStrategy<ForceCalculator> updateStrategy
|
||||
)
|
||||
{
|
||||
this.InputData = inputData;
|
||||
this.checkInputDataLogic = checkInputDataLogic;
|
||||
this.forceCalculatorLogic = forceCalculatorLogic;
|
||||
this.updateStrategy = updateStrategy;
|
||||
}
|
||||
|
||||
public ForceCalculator(ForceInputData inputData) :
|
||||
this(inputData,
|
||||
new CheckForceCalculatorInputData(inputData),
|
||||
new ForceCalculatorLogic(inputData),
|
||||
new ForceCalculatorUpdateStrategy())
|
||||
{
|
||||
}
|
||||
|
||||
public ForceCalculator() : this(new ForceInputData()) { }
|
||||
|
||||
public object Clone()
|
||||
{
|
||||
var newCalculator = new ForceCalculator(new ForceInputData());
|
||||
var newCalculator = new ForceCalculator();
|
||||
updateStrategy.Update(newCalculator, this);
|
||||
return newCalculator;
|
||||
}
|
||||
|
||||
@@ -18,14 +18,11 @@ namespace StructureHelperLogics.NdmCalculations.Analyses.ByForces
|
||||
private IProcessorLogic<IForceTuple> eccentricityLogic;
|
||||
private ForceTupleBucklingLogic bucklingLogic;
|
||||
private ITriangulatePrimitiveLogic triangulateLogic;
|
||||
public ForceInputData InputData { get; set; }
|
||||
public IForceInputData InputData { get; set; }
|
||||
public IShiftTraceLogger? TraceLogger { get; set; }
|
||||
public Action<IResult> ActionToOutputResults { get; set; }
|
||||
|
||||
public ForceCalculatorLogic(ForceInputData inputData)
|
||||
{
|
||||
InputData = inputData;
|
||||
}
|
||||
|
||||
public ForcesResults GetForcesResults()
|
||||
{
|
||||
TraceLogger?.AddMessage(LoggerStrings.CalculatorType(this), TraceLogStatuses.Service);
|
||||
|
||||
@@ -13,7 +13,7 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace StructureHelperLogics.NdmCalculations.Analyses.ByForces
|
||||
{
|
||||
public class ForceInputData : IInputData, IHasPrimitives, IHasForceCombinations
|
||||
public class ForceInputData : IForceInputData
|
||||
{
|
||||
public List<LimitStates> LimitStatesList { get; private set; }
|
||||
public List<CalcTerms> CalcTermsList { get; private set; }
|
||||
|
||||
@@ -4,6 +4,7 @@ using LoaderCalculator.Data.Ndms;
|
||||
using LoaderCalculator.Data.ResultData;
|
||||
using LoaderCalculator.Data.SourceData;
|
||||
using LoaderCalculator.Logics;
|
||||
using StructureHelperCommon.Infrastructures.Interfaces;
|
||||
using StructureHelperCommon.Models;
|
||||
using StructureHelperCommon.Models.Calculators;
|
||||
using StructureHelperCommon.Models.Forces;
|
||||
@@ -13,122 +14,78 @@ using StructureHelperLogics.Services;
|
||||
|
||||
namespace StructureHelperLogics.NdmCalculations.Analyses.ByForces
|
||||
{
|
||||
public class ForceTupleCalculator : IForceTupleCalculator, IHasActionByResult
|
||||
public class ForceTupleCalculator : IForceTupleCalculator
|
||||
{
|
||||
IForceTupleTraceResultLogic forceTupleTraceResultLogic;
|
||||
IForcesTupleResult result;
|
||||
private ICheckInputDataLogic<IForceTupleInputData> checkInputDataLogic;
|
||||
private IForceTupleCalcLogic calcLogic;
|
||||
|
||||
public IForceTupleInputData InputData { get; set; }
|
||||
public string Name { get; set; }
|
||||
public IResult Result { get; private set; }
|
||||
public IResult Result => result;
|
||||
|
||||
public Action<IResult> ActionToOutputResults { get; set; }
|
||||
public IShiftTraceLogger? TraceLogger { get; set; }
|
||||
|
||||
public ForceTupleCalculator()
|
||||
public ForceTupleCalculator(ICheckInputDataLogic<IForceTupleInputData> checkInputDataLogic, IForceTupleCalcLogic calcLogic)
|
||||
{
|
||||
this.checkInputDataLogic = checkInputDataLogic;
|
||||
this.calcLogic = calcLogic;
|
||||
}
|
||||
|
||||
public ForceTupleCalculator() : this(new CheckForceTupleInputDataLogic(), new ForceTupleCalcLogic())
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public void Run()
|
||||
{
|
||||
Result = CalculateResult();
|
||||
PrepareNewResult();
|
||||
if (CheckInputData() == false)
|
||||
{
|
||||
return;
|
||||
}
|
||||
CalculateResult();
|
||||
}
|
||||
|
||||
private IForcesTupleResult CalculateResult()
|
||||
{
|
||||
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;
|
||||
if (TraceLogger is not null)
|
||||
{
|
||||
TraceService.TraceNdmCollection(TraceLogger, ndmCollection);
|
||||
}
|
||||
var tuple = InputData.Tuple;
|
||||
var accuracy = InputData.Accuracy;
|
||||
TraceLogger?.AddMessage(string.Intern("Input force combination"));
|
||||
TraceLogger?.AddEntry(new TraceTablesFactory().GetByForceTuple(tuple));
|
||||
var mx = tuple.Mx;
|
||||
var my = tuple.My;
|
||||
var nz = tuple.Nz;
|
||||
TraceLogger?.AddMessage($"Required accuracy rate {accuracy.IterationAccuracy}");
|
||||
TraceLogger?.AddMessage($"Maximum iteration count {accuracy.MaxIterationCount}");
|
||||
try
|
||||
{
|
||||
var loaderData = new LoaderOptions
|
||||
{
|
||||
Preconditions = new Preconditions
|
||||
{
|
||||
ConditionRate = accuracy.IterationAccuracy,
|
||||
MaxIterationCount = accuracy.MaxIterationCount,
|
||||
StartForceMatrix = new ForceMatrix { Mx = mx, My = my, Nz = nz }
|
||||
},
|
||||
ActionToOutputResults = ShowResultToTrace,
|
||||
NdmCollection = ndmCollection
|
||||
};
|
||||
var calculator = new Calculator();
|
||||
TraceLogger?.AddMessage(string.Intern("Calculation is started"), TraceLogStatuses.Debug);
|
||||
calculator.Run(loaderData, new CancellationToken());
|
||||
TraceLogger?.AddMessage(string.Intern("Calculation result is obtained"), TraceLogStatuses.Debug);
|
||||
var calcResult = calculator.Result;
|
||||
if (calcResult.AccuracyRate <= accuracy.IterationAccuracy)
|
||||
{
|
||||
var result = new ForcesTupleResult()
|
||||
{
|
||||
IsValid = true,
|
||||
Description = LoggerStrings.CalculationHasDone,
|
||||
LoaderResults = calcResult
|
||||
};
|
||||
forceTupleTraceResultLogic = new ForceTupleTraceResultLogic(ndmCollection) { TraceLogger = TraceLogger };
|
||||
forceTupleTraceResultLogic.TraceResult(result);
|
||||
return result;
|
||||
}
|
||||
else
|
||||
{
|
||||
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 = string.Intern("Required accuracy rate has not achieved"),
|
||||
LoaderResults = calcResult
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
TraceLogger?.AddMessage($"Critical error ocured during calculation\n{ex}", TraceLogStatuses.Error);
|
||||
var result = new ForcesTupleResult()
|
||||
{
|
||||
IsValid = false
|
||||
};
|
||||
if (ex.Message == "Calculation result is not valid: stiffness matrix is equal to zero")
|
||||
{
|
||||
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
|
||||
{
|
||||
result.Description = $"Error is appeared due to analysis. Error: {ex}";
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
public object Clone()
|
||||
{
|
||||
var newItem = new ForceTupleCalculator();
|
||||
return newItem;
|
||||
}
|
||||
|
||||
private static void ShowResultToConsole(ILoaderResults result)
|
||||
private void CalculateResult()
|
||||
{
|
||||
var strain = result.StrainMatrix;
|
||||
//MessageBox.Show($" Текущие результаты в {result.IterationCounter} итерации:");
|
||||
calcLogic.InputData = InputData;
|
||||
calcLogic.ActionToOutputResults = ActionToOutputResults;
|
||||
calcLogic.TraceLogger = TraceLogger;
|
||||
calcLogic.Calculate();
|
||||
result = calcLogic.Result;
|
||||
}
|
||||
|
||||
private void ShowResultToTrace(ILoaderResults result)
|
||||
private void PrepareNewResult()
|
||||
{
|
||||
var strain = result.StrainMatrix;
|
||||
TraceLogger?.AddMessage($"Iteration {result.IterationCounter}, current accuracy rate {result.AccuracyRate}", TraceLogStatuses.Debug,100);
|
||||
result = new ForcesTupleResult()
|
||||
{
|
||||
IsValid = true,
|
||||
Description = string.Empty,
|
||||
};
|
||||
}
|
||||
|
||||
private bool CheckInputData()
|
||||
{
|
||||
checkInputDataLogic.InputData = InputData;
|
||||
checkInputDataLogic.TraceLogger = TraceLogger;
|
||||
if (checkInputDataLogic.Check() == false)
|
||||
{
|
||||
result.IsValid = false;
|
||||
result.Description += checkInputDataLogic.CheckResult;
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ namespace StructureHelperLogics.NdmCalculations.Analyses.ByForces
|
||||
{
|
||||
public interface IForceCalculatorLogic : ILogic, IHasActionByResult
|
||||
{
|
||||
ForceInputData InputData { get; set; }
|
||||
IForceInputData InputData { get; set; }
|
||||
ForcesResults GetForcesResults();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
using StructureHelperCommon.Infrastructures.Enums;
|
||||
using StructureHelperCommon.Infrastructures.Interfaces;
|
||||
using StructureHelperCommon.Models.Calculators;
|
||||
using StructureHelperCommon.Models.Forces;
|
||||
using StructureHelperCommon.Models.Sections;
|
||||
using StructureHelperLogics.NdmCalculations.Primitives;
|
||||
|
||||
namespace StructureHelperLogics.NdmCalculations.Analyses.ByForces
|
||||
{
|
||||
public interface IForceInputData : IInputData, IHasPrimitives, IHasForceCombinations
|
||||
{
|
||||
IAccuracy Accuracy { get; set; }
|
||||
List<CalcTerms> CalcTermsList { get; }
|
||||
ICompressedMember CompressedMember { get; set; }
|
||||
List<IForceCombinationList> ForceCombinationLists { get; set; }
|
||||
List<LimitStates> LimitStatesList { get; }
|
||||
}
|
||||
}
|
||||
@@ -7,7 +7,7 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace StructureHelperLogics.NdmCalculations.Analyses.ByForces
|
||||
{
|
||||
public interface IForceTupleCalculator : ICalculator
|
||||
public interface IForceTupleCalculator : ICalculator, IHasActionByResult
|
||||
{
|
||||
IForceTupleInputData InputData {get;set;}
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace StructureHelperLogics.NdmCalculations.Analyses.ByForces
|
||||
{
|
||||
public interface IForceTupleInputData
|
||||
public interface IForceTupleInputData : IInputData
|
||||
{
|
||||
IEnumerable<INdm> NdmCollection { get; set; }
|
||||
IForceTuple Tuple { get; set; }
|
||||
|
||||
@@ -83,7 +83,7 @@ namespace StructureHelperLogics.NdmCalculations.Analyses.ByForces
|
||||
private bool IsSectionCracked(IPoint2D point2D)
|
||||
{
|
||||
logger?.TraceLoggerEntries.Clear();
|
||||
var logic = new SectionCrackedLogic();
|
||||
var logic = new IsSectionCrackedByForceLogic();
|
||||
var point3D = ConvertLogic.GetPoint3D(point2D);
|
||||
tuple = new()
|
||||
{
|
||||
|
||||
@@ -20,10 +20,8 @@ namespace StructureHelperLogics.NdmCalculations.Analyses.ByForces
|
||||
|
||||
public double GetParameter()
|
||||
{
|
||||
var parameterCalculator = new FindParameterCalculator()
|
||||
{
|
||||
Predicate = GetFactorPredicate,
|
||||
};
|
||||
var parameterCalculator = new FindParameterCalculator();
|
||||
parameterCalculator.InputData.Predicate = GetFactorPredicate;
|
||||
if (TraceLogger is not null)
|
||||
{
|
||||
parameterCalculator.TraceLogger = TraceLogger;
|
||||
|
||||
@@ -0,0 +1,84 @@
|
||||
using StructureHelperCommon.Infrastructures.Exceptions;
|
||||
using StructureHelperCommon.Infrastructures.Interfaces;
|
||||
using StructureHelperCommon.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StructureHelperLogics.NdmCalculations.Analyses.ByForces
|
||||
{
|
||||
public class CheckForceTupleInputDataLogic : ICheckInputDataLogic<IForceTupleInputData>
|
||||
{
|
||||
private bool result;
|
||||
private string checkResult;
|
||||
|
||||
public IForceTupleInputData InputData { get; set; }
|
||||
|
||||
public string CheckResult => checkResult;
|
||||
|
||||
public IShiftTraceLogger? TraceLogger { get; set; }
|
||||
|
||||
public CheckForceTupleInputDataLogic(IForceTupleInputData inputData, IShiftTraceLogger traceLogger)
|
||||
{
|
||||
InputData = inputData;
|
||||
TraceLogger = traceLogger;
|
||||
}
|
||||
|
||||
public CheckForceTupleInputDataLogic()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public bool Check()
|
||||
{
|
||||
result = true;
|
||||
checkResult = string.Empty;
|
||||
if (InputData is null)
|
||||
{
|
||||
string errorString = ErrorStrings.ParameterIsNull + ": Input data";
|
||||
TraceLogger?.AddMessage(errorString);
|
||||
throw new StructureHelperException(errorString);
|
||||
}
|
||||
if (InputData.NdmCollection is null || ! InputData.NdmCollection.Any())
|
||||
{
|
||||
result = false;
|
||||
string errorString = "\nNdm collection is null or empty";
|
||||
TraceMessage(errorString);
|
||||
}
|
||||
if (InputData.Tuple is null)
|
||||
{
|
||||
result = false;
|
||||
string errorString = "\nForce tuple is null";
|
||||
TraceMessage(errorString);
|
||||
}
|
||||
if (InputData.Accuracy is null)
|
||||
{
|
||||
result = false;
|
||||
string errorString = "\nAccuracy requirements is not assigned";
|
||||
TraceMessage(errorString);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (InputData.Accuracy.IterationAccuracy <= 0)
|
||||
{
|
||||
result = false;
|
||||
TraceMessage($"\nValue of accuracy {InputData.Accuracy.IterationAccuracy} must be grater than zero");
|
||||
}
|
||||
if (InputData.Accuracy.MaxIterationCount <= 0)
|
||||
{
|
||||
result = false;
|
||||
TraceMessage($"\nMax number of iteration {InputData.Accuracy.MaxIterationCount} must be grater than zero");
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private void TraceMessage(string errorString)
|
||||
{
|
||||
checkResult += errorString;
|
||||
TraceLogger?.AddMessage(errorString);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,155 @@
|
||||
using LoaderCalculator.Data.Matrix;
|
||||
using LoaderCalculator;
|
||||
using LoaderCalculator.Data.ResultData;
|
||||
using LoaderCalculator.Data.SourceData;
|
||||
using StructureHelperCommon.Models;
|
||||
using StructureHelperCommon.Models.Calculators;
|
||||
using StructureHelperCommon.Models.Loggers;
|
||||
using StructureHelperLogics.Services;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StructureHelperLogics.NdmCalculations.Analyses.ByForces
|
||||
{
|
||||
public class ForceTupleCalcLogic : IForceTupleCalcLogic
|
||||
{
|
||||
private IForcesTupleResult result;
|
||||
private ForceTupleTraceResultLogic forceTupleTraceResultLogic;
|
||||
private LoaderOptions loaderData;
|
||||
private Calculator calculator;
|
||||
private ILoaderResults calcResult;
|
||||
|
||||
public IForceTupleInputData InputData { get; set; }
|
||||
|
||||
public IForcesTupleResult Result => result;
|
||||
|
||||
public IShiftTraceLogger? TraceLogger { get; set; }
|
||||
public Action<IResult> ActionToOutputResults { get; set; }
|
||||
|
||||
public void Calculate()
|
||||
{
|
||||
PrepareNewResult();
|
||||
CalculateResult();
|
||||
}
|
||||
|
||||
private void PrepareNewResult()
|
||||
{
|
||||
result = new ForcesTupleResult()
|
||||
{
|
||||
IsValid = true,
|
||||
Description = string.Empty,
|
||||
};
|
||||
}
|
||||
|
||||
private void CalculateResult()
|
||||
{
|
||||
TraceStartOfCalculation();
|
||||
try
|
||||
{
|
||||
GetLoaderResult();
|
||||
ProcessLoaderResult();
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
ProcessCalculationException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
private void TraceStartOfCalculation()
|
||||
{
|
||||
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"));
|
||||
if (TraceLogger is not null)
|
||||
{
|
||||
TraceService.TraceNdmCollection(TraceLogger, InputData.NdmCollection);
|
||||
}
|
||||
TraceLogger?.AddMessage(string.Intern("Input force combination"));
|
||||
TraceLogger?.AddEntry(new TraceTablesFactory().GetByForceTuple(InputData.Tuple));
|
||||
TraceLogger?.AddMessage($"Required accuracy rate {InputData.Accuracy.IterationAccuracy}");
|
||||
TraceLogger?.AddMessage($"Maximum iteration count {InputData.Accuracy.MaxIterationCount}");
|
||||
}
|
||||
|
||||
private void ProcessCalculationException(Exception ex)
|
||||
{
|
||||
TraceLogger?.AddMessage($"Critical error ocured during calculation\n{ex}", TraceLogStatuses.Error);
|
||||
result.IsValid = false;
|
||||
if (ex.Message == "Calculation result is not valid: stiffness matrix is equal to zero")
|
||||
{
|
||||
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
|
||||
{
|
||||
result.Description = $"Error is appeared due to analysis. Error: {ex}";
|
||||
}
|
||||
}
|
||||
|
||||
private void ProcessLoaderResult()
|
||||
{
|
||||
if (calcResult.AccuracyRate <= InputData.Accuracy.IterationAccuracy)
|
||||
{
|
||||
ProcessCorrectLoaderResult();
|
||||
}
|
||||
else
|
||||
{
|
||||
ProcessInCorrectLoaderResult();
|
||||
}
|
||||
}
|
||||
|
||||
private void ProcessInCorrectLoaderResult()
|
||||
{
|
||||
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);
|
||||
result.IsValid = false;
|
||||
result.Description = string.Intern("Required accuracy rate has not achieved");
|
||||
result.LoaderResults = calcResult;
|
||||
}
|
||||
|
||||
private void ProcessCorrectLoaderResult()
|
||||
{
|
||||
result.IsValid = true;
|
||||
result.Description = LoggerStrings.CalculationHasDone;
|
||||
result.LoaderResults = calcResult;
|
||||
forceTupleTraceResultLogic = new ForceTupleTraceResultLogic(InputData.NdmCollection)
|
||||
{
|
||||
TraceLogger = TraceLogger
|
||||
};
|
||||
forceTupleTraceResultLogic.TraceResult(result);
|
||||
}
|
||||
|
||||
private void GetLoaderResult()
|
||||
{
|
||||
loaderData = new LoaderOptions
|
||||
{
|
||||
Preconditions = new Preconditions
|
||||
{
|
||||
ConditionRate = InputData.Accuracy.IterationAccuracy,
|
||||
MaxIterationCount = InputData.Accuracy.MaxIterationCount,
|
||||
StartForceMatrix = new ForceMatrix
|
||||
{
|
||||
Mx = InputData.Tuple.Mx,
|
||||
My = InputData.Tuple.My,
|
||||
Nz = InputData.Tuple.Nz
|
||||
}
|
||||
},
|
||||
ActionToOutputResults = ShowResultToTrace,
|
||||
NdmCollection = InputData.NdmCollection
|
||||
};
|
||||
calculator = new Calculator();
|
||||
TraceLogger?.AddMessage(string.Intern("Calculation is started"), TraceLogStatuses.Debug);
|
||||
calculator.Run(loaderData, new CancellationToken());
|
||||
TraceLogger?.AddMessage(string.Intern("Calculation result is obtained"), TraceLogStatuses.Debug);
|
||||
calcResult = calculator.Result;
|
||||
}
|
||||
|
||||
private void ShowResultToTrace(ILoaderResults result)
|
||||
{
|
||||
var strain = result.StrainMatrix;
|
||||
TraceLogger?.AddMessage($"Iteration {result.IterationCounter}, current accuracy rate {result.AccuracyRate}", TraceLogStatuses.Debug, 100);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
using StructureHelperCommon.Infrastructures.Interfaces;
|
||||
using StructureHelperCommon.Models.Calculators;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StructureHelperLogics.NdmCalculations.Analyses.ByForces
|
||||
{
|
||||
public interface IForceTupleCalcLogic: ILogic, IHasActionByResult
|
||||
{
|
||||
IForceTupleInputData InputData { get; set; }
|
||||
IForcesTupleResult Result { get; }
|
||||
void Calculate();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user