Value point diagram was repaired

This commit is contained in:
Evgeny Redikultsev
2024-03-23 20:27:37 +05:00
parent f2f6840ffb
commit f11b97de38
14 changed files with 428 additions and 231 deletions

View File

@@ -10,12 +10,18 @@ using System.Threading.Tasks;
namespace StructureHelper.Windows.CalculationWindows.CalculatorsViews
{
/// <summary>
/// Create array of common values
/// </summary>
public class DiagramFactory
{
private ArrayParameter<double> arrayParameter;
/// <summary>
/// Collection of force results
/// </summary>
public List<IForcesTupleResult> TupleList { get; set; }
public Action<int> SetProgress { get; set; }
//public Action<int> SetProgress { get; set; }
public ArrayParameter<double> GetCommonArray()
{
@@ -35,7 +41,7 @@ namespace StructureHelper.Windows.CalculationWindows.CalculatorsViews
{
data[i, j] = valueList[j];
}
SetProgress?.Invoke(i);
//SetProgress?.Invoke(i);
}
}

View File

@@ -0,0 +1,18 @@
using StructureHelper.Windows.Forces;
using StructureHelperCommon.Models.Calculators;
using StructureHelperCommon.Models.Parameters;
using StructureHelperLogics.NdmCalculations.Analyses.ByForces;
using System.Collections.Generic;
namespace StructureHelper.Windows.CalculationWindows.CalculatorsViews.ForceCalculatorViews.ForceResultLogic
{
public interface IValuePointDiagramLogic
{
ForceCalculator Calculator { get; set; }
PointPrimitiveLogic PrimitiveLogic { get; set; }
IEnumerable<IForcesTupleResult> TupleList { get; set; }
ValueDelegatesLogic ValueDelegatesLogic { get; set; }
GenericResult<ArrayParameter<double>> GetArrayParameter();
}
}

View File

@@ -0,0 +1,86 @@
using StructureHelper.Windows.Forces;
using StructureHelperCommon.Infrastructures.Exceptions;
using StructureHelperCommon.Models.Forces;
using StructureHelperLogics.NdmCalculations.Analyses.ByForces.Logics;
using StructureHelperLogics.NdmCalculations.Analyses.ByForces;
using StructureHelperLogics.NdmCalculations.Primitives;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using StructureHelper.Infrastructure.UI.DataContexts;
using StructureHelperCommon.Infrastructures.Interfaces;
using StructureHelperCommon.Models.Calculators;
namespace StructureHelper.Windows.CalculationWindows.CalculatorsViews.ForceCalculatorViews.ForceResultLogic
{
public class InterpolateValuePointsLogic
{
private InterpolationProgressLogic interpolationLogic;
private ValuePointsInterpolateViewModel viewModel;
private IResult result;
private ValuePointsInterpolationInputData inputData;
public ForcesTupleResult SelectedResult { get; set; }
public IEnumerable<INdmPrimitive> NdmPrimitives { get; set; }
public ForceCalculator ForceCalculator { get; set; }
public ILongProcessLogic ProgressLogic { get; set; }
public ShowProgressLogic ShowProgressLogic { get; set; }
public void InterpolateValuePoints()
{
var tuple = SelectedResult.DesignForceTuple ?? throw new StructureHelperException(ErrorStrings.NullReference + ": Design force combination");
PrepareInputData(tuple);
viewModel = new ValuePointsInterpolateViewModel(inputData);
if (ShowDialog() == false) { return; };
ShowDiagram(result);
}
private void PrepareInputData(IDesignForceTuple tuple)
{
inputData = new ValuePointsInterpolationInputData()
{
FinishDesignForce = tuple.Clone() as IDesignForceTuple,
LimitState = tuple.LimitState,
CalcTerm = tuple.CalcTerm,
};
inputData.PrimitiveBases.AddRange(PrimitiveOperations.ConvertNdmPrimitivesToPrimitiveBase(NdmPrimitives));
}
private bool ShowDialog()
{
var wnd = new ValuePointsInterpolateView(viewModel);
wnd.ShowDialog();
if (wnd.DialogResult != true) { return false; }
interpolationLogic = new InterpolationProgressLogic(ForceCalculator, viewModel.ForceInterpolationViewModel.Result);
ProgressLogic = interpolationLogic;
ShowProgressLogic = new(interpolationLogic)
{
WindowTitle = "Interpolate forces",
};
ShowProgressLogic.Show();
result = interpolationLogic.InterpolateCalculator.Result;
return true;
}
private void ShowDiagram(IResult result)
{
if (result.IsValid == false) { return; }
if (result is not IForcesResults)
{
throw new StructureHelperException(ErrorStrings.ExpectedWas(typeof(IForcesResults), result));
}
var tupleResult = result as IForcesResults;
var pointGraphLogic = new ShowValuePointDiagramLogic()
{
Calculator = interpolationLogic.InterpolateCalculator,
PrimitiveLogic = viewModel.PrimitiveLogic,
ValueDelegatesLogic = viewModel.ValueDelegatesLogic,
TupleList = tupleResult.ForcesResultList
};
pointGraphLogic.ShowWindow();
}
}
}

View File

@@ -61,7 +61,7 @@ namespace StructureHelper.Windows.CalculationWindows.CalculatorsViews.ForceCalcu
var factory = new DiagramFactory()
{
TupleList = validTupleList,
SetProgress = SetProgress,
//SetProgress = SetProgress,
};
arrayParameter = factory.GetCommonArray();
}

View File

@@ -12,7 +12,7 @@ using System.Windows.Forms;
namespace StructureHelper.Windows.CalculationWindows.CalculatorsViews.ForceCalculatorViews
{
internal class ShowProgressLogic
public class ShowProgressLogic
{
private ShowProgressViewModel progressViewModel;
private ShowProgressView wndProgress;

View File

@@ -1,6 +1,8 @@
using LoaderCalculator.Data.Ndms;
using LoaderCalculator.Data.Materials.MaterialBuilders;
using LoaderCalculator.Data.Ndms;
using StructureHelper.Infrastructure.UI.DataContexts;
using StructureHelper.Services.ResultViewers;
using StructureHelper.Windows.CalculationWindows.CalculatorsViews.ForceCalculatorViews.ForceResultLogic;
using StructureHelper.Windows.Forces;
using StructureHelper.Windows.Graphs;
using StructureHelper.Windows.ViewModels.Errors;
@@ -8,6 +10,7 @@ using StructureHelperCommon.Infrastructures.Enums;
using StructureHelperCommon.Infrastructures.Exceptions;
using StructureHelperCommon.Infrastructures.Interfaces;
using StructureHelperCommon.Models;
using StructureHelperCommon.Models.Calculators;
using StructureHelperCommon.Models.Forces;
using StructureHelperCommon.Models.Parameters;
using StructureHelperCommon.Models.Shapes;
@@ -20,128 +23,43 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
//Copyright (c) 2023 Redikultsev Evgeny, Ekaterinburg, Russia
//All rights reserved.
namespace StructureHelper.Windows.CalculationWindows.CalculatorsViews
{
public class ShowValuePointDiagramLogic : ILongProcessLogic
public class ShowValuePointDiagramLogic //: ILongProcessLogic
{
private ArrayParameter<double> arrayParameter;
private IEnumerable<IForcesTupleResult> tupleList;
private IEnumerable<INdmPrimitive> ndmPrimitives;
private List<IForcesTupleResult> validTupleList;
private List<(PrimitiveBase PrimitiveBase, List<INamedAreaPoint> namedPoints)> valuePoints;
private List<IResultFunc> resultFuncList;
private IValuePointDiagramLogic pointDiagramLogic;
public IEnumerable<IForcesTupleResult> TupleList { get; set; }
public ForceCalculator Calculator { get; set; }
public PointPrimitiveLogic PrimitiveLogic { get; set; }
public ValueDelegatesLogic ValueDelegatesLogic { get; set; }
public int StepCount => throw new NotImplementedException();
//public int StepCount => throw new NotImplementedException();
public Action<int> SetProgress { get; set; }
public bool Result { get; set; }
public IShiftTraceLogger? TraceLogger { get; set; }
public ShowValuePointDiagramLogic(IEnumerable<IForcesTupleResult> tupleList, IEnumerable<INdmPrimitive> ndmPrimitives)
//public Action<int> SetProgress { get; set; }
//public bool Result { get; set; }
//public IShiftTraceLogger? TraceLogger { get; set; }
public ShowValuePointDiagramLogic(IValuePointDiagramLogic pointDiagramLogic)
{
this.tupleList = tupleList;
this.ndmPrimitives = ndmPrimitives;
validTupleList = this.tupleList.Where(x => x.IsValid == true).ToList();
valuePoints = new List<(PrimitiveBase PrimitiveBase, List<INamedAreaPoint>)>();
this.pointDiagramLogic = pointDiagramLogic;
}
public void SetParameters()
public ShowValuePointDiagramLogic() : this(new ValuePointDiagramLogic())
{
var factory = new DiagramFactory()
{
TupleList = validTupleList,
SetProgress = SetProgress,
};
arrayParameter = factory.GetCommonArray();
foreach (var item in PrimitiveLogic.Collection.CollectionItems)
{
var pointsCount = item.Item.ValuePoints.SelectedCount;
if (pointsCount > 0)
{
var points = item.Item.ValuePoints.SelectedItems.ToList();
var primitive = item.Item.PrimitiveBase;
valuePoints.Add((primitive, points));
}
}
var selectedDelegates = ValueDelegatesLogic.ResultFuncs.SelectedItems;
if (selectedDelegates.Count() == 0) { return; }
var labels = GetLabels(valuePoints, selectedDelegates);
var pointCount = valuePoints.Sum(x => x.namedPoints.Count());
List<double> values = new();
var tuplesList = tupleList
.Where(x => x.IsValid == true)
.ToList();
var newArray = new ArrayParameter<double>(tuplesList.Count(), labels);
for (int i = 0; i < tuplesList.Count(); i++)
{
var strainMatrix = tuplesList[i].LoaderResults.ForceStrainPair.StrainMatrix;
values.Clear();
foreach (var valuePoint in valuePoints)
{
foreach (var point in valuePoint.namedPoints)
{
var limitState = tuplesList[i].DesignForceTuple.LimitState;
var calcTerm = tuplesList[i].DesignForceTuple.CalcTerm;
var ndm = GetNdm(valuePoint, point, limitState, calcTerm);
foreach (var valDelegate in selectedDelegates)
{
double val = valDelegate.ResultFunction.Invoke(strainMatrix, ndm) * valDelegate.UnitFactor;
values.Add(val);
}
}
}
newArray.AddRow(i, values);
}
arrayParameter.AddArray(newArray);
}
private List<string> GetLabels(List<(PrimitiveBase PrimitiveBase, List<INamedAreaPoint> namedPoints)> valuePoints, IEnumerable<IResultFunc> selectedDelegates)
{
List<string> strings = new();
foreach (var valuePoint in valuePoints)
{
foreach (var item in valuePoint.namedPoints)
{
foreach (var deleg in selectedDelegates)
{
string s = valuePoint.PrimitiveBase.Name;
s += "_" + item.Name;
s += "_" + deleg.Name + ", " + deleg.UnitName;
strings.Add(s);
}
}
}
return strings;
}
private static RebarNdm GetNdm((PrimitiveBase PrimitiveBase, List<INamedAreaPoint> namedPoints) valuePoint, INamedAreaPoint point, LimitStates limitState, CalcTerms calcTerm)
{
var ndmPrimitive = valuePoint.PrimitiveBase.GetNdmPrimitive();
var material = ndmPrimitive.HeadMaterial.GetLoaderMaterial(limitState, calcTerm);
var userPrestrain = ndmPrimitive.UsersPrestrain;
var autoPrestrain = ndmPrimitive.AutoPrestrain;
var ndm = new RebarNdm()
{
Area = point.Area,
CenterX = point.Point.X,
CenterY = point.Point.Y,
Material = material,
};
ndm.Prestrain = (userPrestrain.Mx + autoPrestrain.Mx) * point.Point.Y
+ (userPrestrain.My + autoPrestrain.My) * point.Point.X
+ userPrestrain.Nz + autoPrestrain.Nz;
return ndm;
}
public void ShowWindow()
{
var result = GetResult();
if (result.IsValid != true)
{
SafetyProcessor.ShowMessage(ErrorStrings.DataIsInCorrect, result.Description);
return;
}
arrayParameter = result.Value;
SafetyProcessor.RunSafeProcess(() =>
{
var series = new Series(arrayParameter)
@@ -157,39 +75,14 @@ namespace StructureHelper.Windows.CalculationWindows.CalculatorsViews
}, ErrorStrings.ErrorDuring("building chart"));
}
public void WorkerDoWork(object sender, DoWorkEventArgs e)
private GenericResult<ArrayParameter<double>> GetResult()
{
Show();
Result = true;
}
public void WorkerProgressChanged(object sender, ProgressChangedEventArgs e)
{
//Nothing to do
}
public void WorkerRunWorkCompleted(object sender, RunWorkerCompletedEventArgs e)
{
//Nothing to do
}
private void Show()
{
validTupleList = tupleList.Where(x => x.IsValid == true).ToList();
var factory = new DiagramFactory()
{
TupleList = validTupleList,
SetProgress = SetProgress,
};
arrayParameter = factory.GetCommonArray();
}
private List<string> GetColumnNames()
{
var columnNames = LabelsFactory.GetCommonLabels();
return columnNames;
pointDiagramLogic.TupleList = TupleList;
pointDiagramLogic.PrimitiveLogic = PrimitiveLogic;
pointDiagramLogic.Calculator = Calculator;
pointDiagramLogic.ValueDelegatesLogic = ValueDelegatesLogic;
var results = pointDiagramLogic.GetArrayParameter();
return results;
}
}
}

View File

@@ -0,0 +1,173 @@
using LoaderCalculator.Data.Ndms;
using StructureHelper.Infrastructure.UI.DataContexts;
using StructureHelper.Services.ResultViewers;
using StructureHelper.Windows.Forces;
using StructureHelperCommon.Infrastructures.Exceptions;
using StructureHelperCommon.Models.Calculators;
using StructureHelperCommon.Models.Parameters;
using StructureHelperLogics.NdmCalculations.Analyses.ByForces;
using StructureHelperLogics.NdmCalculations.Primitives;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Media;
namespace StructureHelper.Windows.CalculationWindows.CalculatorsViews.ForceCalculatorViews.ForceResultLogic
{
public class ValuePointDiagramLogic : IValuePointDiagramLogic
{
private ArrayParameter<double> arrayParameter;
private List<(INamedAreaPoint areaPoint, INdmPrimitive ndmPrimitive)> pointCollection;
private List<IForcesTupleResult> validTuplesList;
private ArrayParameter<double> arrayOfValuesByPoint;
private IEnumerable<IResultFunc> selectedDelegates;
private string exceptionMessage;
public IEnumerable<IForcesTupleResult> TupleList { get; set; }
public ForceCalculator Calculator { get; set; }
public PointPrimitiveLogic PrimitiveLogic { get; set; }
public ValueDelegatesLogic ValueDelegatesLogic { get; set; }
public GenericResult<ArrayParameter<double>> GetArrayParameter()
{
SetParameters();
var checkResult = CheckParameters();
if (checkResult != true)
{
return GetFalseResult();
}
PrepareArray();
return GetValidResult();
}
private GenericResult<ArrayParameter<double>> GetValidResult()
{
int i = 0;
foreach (var tuple in validTuplesList)
{
ProcessPointByTuple(tuple, i);
i++;
}
arrayParameter.AddArray(arrayOfValuesByPoint);
return new GenericResult<ArrayParameter<double>>()
{
IsValid = true,
Value = arrayParameter
};
}
private GenericResult<ArrayParameter<double>> GetFalseResult()
{
return new GenericResult<ArrayParameter<double>>()
{
IsValid = false,
Description = exceptionMessage
};
}
private void SetParameters()
{
GetPointCollection();
selectedDelegates = ValueDelegatesLogic.ResultFuncs.SelectedItems;
validTuplesList = TupleList
.Where(x => x.IsValid == true)
.ToList();
}
private bool CheckParameters()
{
var result = true;
exceptionMessage = ErrorStrings.DataIsInCorrect;
if (pointCollection.Any() == false)
{
exceptionMessage += ", point collection is null";
result = false;
}
if (selectedDelegates.Any() == false)
{
exceptionMessage += ", value expression collection is null";
result = false;
}
if (validTuplesList.Any() == false)
{
exceptionMessage += ", force list is empty";
result = false;
}
return result;
}
private void GetPointCollection()
{
pointCollection = new();
foreach (var primitiveValuePoint in PrimitiveLogic.Collection.CollectionItems)
{
foreach (var selectedPoint in primitiveValuePoint.Item.ValuePoints.SelectedItems)
{
var newPoint = (selectedPoint, primitiveValuePoint.Item.PrimitiveBase.GetNdmPrimitive());
pointCollection.Add(newPoint);
}
}
}
private void ProcessPointByTuple(IForcesTupleResult tuple, int i)
{
var values = new List<double>();
var strainMatrix = tuple.LoaderResults.ForceStrainPair.StrainMatrix;
foreach (var valuePoint in pointCollection)
{
var ndm = GetMockNdm(valuePoint, tuple);
foreach (var valDelegate in selectedDelegates)
{
double val = valDelegate.ResultFunction.Invoke(strainMatrix, ndm) * valDelegate.UnitFactor;
values.Add(val);
}
}
arrayOfValuesByPoint.AddRow(i, values);
}
private void PrepareArray()
{
var factory = new DiagramFactory()
{
TupleList = validTuplesList,
//SetProgress = SetProgress,
};
arrayParameter = factory.GetCommonArray();
var labels = GetValueLabels(selectedDelegates);
arrayOfValuesByPoint = new ArrayParameter<double>(validTuplesList.Count(), labels);
}
private INdm GetMockNdm((INamedAreaPoint areaPoint, INdmPrimitive ndmPrimitive) valuePoint, IForcesTupleResult tuple)
{
var limitState = tuple.DesignForceTuple.LimitState;
var calcTerm = tuple.DesignForceTuple.CalcTerm;
var material = valuePoint.ndmPrimitive.HeadMaterial.GetLoaderMaterial(limitState, calcTerm);
var userPrestrain = valuePoint.ndmPrimitive.UsersPrestrain;
var autoPrestrain = valuePoint.ndmPrimitive.AutoPrestrain;
var ndm = new RebarNdm()
{
Area = valuePoint.areaPoint.Area,
CenterX = valuePoint.areaPoint.Point.X,
CenterY = valuePoint.areaPoint.Point.Y,
Material = material,
};
ndm.Prestrain = (userPrestrain.Mx + autoPrestrain.Mx) * valuePoint.areaPoint.Point.Y
+ (userPrestrain.My + autoPrestrain.My) * valuePoint.areaPoint.Point.X
+ userPrestrain.Nz + autoPrestrain.Nz;
return ndm;
}
private List<string> GetValueLabels(IEnumerable<IResultFunc> selectedDelegates)
{
List<string> strings = new();
foreach (var valuePoint in pointCollection)
{
foreach (var deleg in selectedDelegates)
{
string s = valuePoint.ndmPrimitive.Name;
s += "_" + valuePoint.areaPoint.Name;
s += "_" + deleg.Name + ", " + deleg.UnitName;
strings.Add(s);
}
}
return strings;
}
}
}

View File

@@ -285,40 +285,15 @@ namespace StructureHelper.Windows.CalculationWindows.CalculatorsViews.ForceCalcu
{
throw new StructureHelperException(ErrorStrings.NullReference + ": Nothing is selected");
}
var tuple = SelectedResult.DesignForceTuple ?? throw new StructureHelperException(ErrorStrings.NullReference + ": Design force combination");
var inputData = new ValuePointsInterpolationInputData()
var logic = new InterpolateValuePointsLogic()
{
FinishDesignForce = tuple.Clone() as IDesignForceTuple,
LimitState = tuple.LimitState,
CalcTerm = tuple.CalcTerm,
SelectedResult = SelectedResult,
ForceCalculator = forceCalculator,
NdmPrimitives = ndmPrimitives,
ProgressLogic = progressLogic,
ShowProgressLogic = showProgressLogic
};
inputData.PrimitiveBases.AddRange(PrimitiveOperations.ConvertNdmPrimitivesToPrimitiveBase(ndmPrimitives));
var viewModel = new ValuePointsInterpolateViewModel(inputData);
var wnd = new ValuePointsInterpolateView(viewModel);
wnd.ShowDialog();
if (wnd.DialogResult != true) { return; }
var interpolationLogic = new InterpolationProgressLogic(forceCalculator, viewModel.ForceInterpolationViewModel.Result);
progressLogic = interpolationLogic;
showProgressLogic = new(interpolationLogic)
{
WindowTitle = "Interpolate forces",
};
showProgressLogic.Show();
var result = interpolationLogic.InterpolateCalculator.Result;
if (result.IsValid == false) { return; }
if (result is IForcesResults)
{
var tupleResult = result as IForcesResults;
var pointGraphLogic = new ShowValuePointDiagramLogic(tupleResult.ForcesResultList, ndmPrimitives)
{
Calculator = interpolationLogic.InterpolateCalculator,
PrimitiveLogic = viewModel.PrimitiveLogic,
ValueDelegatesLogic = viewModel.ValueDelegatesLogic
};
pointGraphLogic.SetParameters();
pointGraphLogic.ShowWindow();
}
logic.InterpolateValuePoints();
}
private void ShowInterpolationWindow(out InterpolateTuplesViewModel interploateTuplesViewModel, out InterpolateTuplesView wndTuples)