This repository has been archived on 2024-09-21. You can view files and clone it, but cannot push or open issues or pull requests.
Optica.Rods.Calculation/Program.cs
2024-09-03 17:32:14 +07:00

261 lines
11 KiB
C#

using System.ComponentModel.DataAnnotations;
using System.Globalization;
using System.Numerics;
using System.Runtime.InteropServices;
using System.Security.Cryptography;
using System.Xml.XPath;
using RealCoordinatesCalculation;
using RealCoordinatesCalculation.Models;
// | TODO |
// =================
// Подгрузка M1, M2
// Подгрузка PA.TA.HA.TC.PC
// ДИАПАЗОНЫ ВЫЧИСЛЕНИЙ
const double NG_PREDEL_LOW = 1.494452;
const double NG_PREDEL_HIGHT = 1.506247;
const double BETA_PREDEL_LOW = -15;
const double BETA_PREDEL_HIGHT = 15;
// ПРЕДОПРЕДЕЛЕННЫЕ КОНСТАНТЫ ВЫЧИСЛЕНИЙ
const double LAMBDA = 1.550;
const double ALPHA = 0.001383;
const double DGM = 60.00;
// КОЛИЧЕСТВО ЭКСПЕРИМЕНТОВ
const int COUNT_EXPERIMENTS = 6;
var L0_J1_12=449.322;
var L0_J1_23=449.939;
var L0_J1_13=899.261;
var L0_J2_12=450.150;
var L0_J2_23=449.513;
var L0_J2_13=899.663;
var L0_J3_12=449.531;
var L0_J3_23=449.856;
var L0_J3_13=899.387;
Console.WriteLine("[*] Start process of calculation");
// Console.WriteLine("[2] Layer 2 :: Calculate Distance is resolved");
// Console.WriteLine("[3] Layer 3 :: Calculate DELTA is ended");
// Display the command line arguments using the args variable.
System.Console.ReadLine();
StartCalc();
// Запуск процесса вычислений
void StartCalc() {
var STEP_NG = (NG_PREDEL_HIGHT - NG_PREDEL_LOW) / 30;
var STEP_BETA = (NG_PREDEL_HIGHT - NG_PREDEL_LOW) / 30;
var filepath = "/home/moxitech/Загрузки/ЦСМ/CALCULATION_INPUT.csv";
List<Measurement> measurements = CsvParser.Parse(filepath);
List<Measurement> ClearedMeasurements = new List<Measurement>();
List<MeasurementMX> M1M2Measurements = new List<MeasurementMX>();
List<DeltaStore> Store = new List<DeltaStore>();
var CorrectedCoords = new List<Vector3D>();
foreach (var measurement in measurements)
{
// Console.WriteLine(measurement);
if (measurement.Point == "M1" || measurement.Point == "M2") {
M1M2Measurements.Add(new MeasurementMX{
Point = measurement.Point,
Iteration = measurement.Iteration,
X = measurement.X,
Y = measurement.Y,
Z = measurement.Y
});
continue;
}
else {
ClearedMeasurements.Add(measurement);
}
}
Dictionary<string, List<Measurement>> CalculatedResultsL1 = new Dictionary<string, List<Measurement>>();
for (int i = 1; i < COUNT_EXPERIMENTS + 1; i++) {
foreach (var m in ClearedMeasurements)
{
var m1 = M1M2Measurements.Where(x => x.Point == "M1" && x.Iteration == m.Iteration).Last();
var m2 = M1M2Measurements.Where(x => x.Point == "M2" && x.Iteration == m.Iteration).Last();
var res = RunDivergenceCorrectForCoordinate(NG_PREDEL_LOW + (STEP_NG * i), (int)(BETA_PREDEL_LOW + (STEP_BETA * i)), m.PressurePa, m.TemperatureTa, m.HumidityHa, m.PressurePc, m.TemperatureTc,
new Vector3D(m1.X, m1.Y, m1.Z),
new Vector3D(m2.X, m2.Y, m2.Z),
new Vector3D(m.X, m.Y, m.Z)
);
m.FixedX = (double)res.X;
m.FixedY = (double)res.Y;
m.FixedZ = (double)res.Z;
}
Console.WriteLine($"[1] Partial results step {i} :: ");
foreach (var m in ClearedMeasurements)
{
Console.WriteLine($" [ {m.Iteration} |{m.Point}] ({m.X}, {m.Y}, {m.Z}) | Calculated ({m.FixedX}, {m.FixedY}, {m.FixedZ})");
}
CalculatedResultsL1.Add(i.ToString(), ClearedMeasurements);
}
Console.WriteLine("[1] Layer 1 :: Correcting coordinate with Math model is ended, Iterations: " + CalculatedResultsL1.Keys.Count + " Values in iterations: " + CalculatedResultsL1["1"].Count * CalculatedResultsL1.Keys.Count);
Console.Write("∆ | NG | BETA \n");
for (int i = 1; i < COUNT_EXPERIMENTS + 1; i++) {
// Console.WriteLine(CalculatedResultsL1[i.ToString()].Count);
// === Считаем искомые расстояния
var J1_12 = CalculateDistance(GetMeasurementByPoint(CalculatedResultsL1[i.ToString()],"J1.1", 1), GetMeasurementByPoint(CalculatedResultsL1[i.ToString()] ,"J1.2", 1));
// System.Console.WriteLine("J1_12: " + J1_12);
var J1_23 = CalculateDistance(GetMeasurementByPoint(CalculatedResultsL1[i.ToString()] ,"J1.2", 1), GetMeasurementByPoint(CalculatedResultsL1[i.ToString()] ,"J1.3", 1));
//System.Console.WriteLine("J1_23: " + J1_23);
var J1_13 = CalculateDistance(GetMeasurementByPoint(CalculatedResultsL1[i.ToString()] ,"J1.1", 1), GetMeasurementByPoint(CalculatedResultsL1[i.ToString()] ,"J1.3", 1));
// System.Console.WriteLine("J1_13: " + J1_13);
var J2_12 = CalculateDistance(GetMeasurementByPoint(CalculatedResultsL1[i.ToString()] ,"J2.1", 1), GetMeasurementByPoint(CalculatedResultsL1[i.ToString()] ,"J2.2", 1));
// System.Console.WriteLine("J2_12: " + J2_12);
var J2_23 = CalculateDistance(GetMeasurementByPoint(CalculatedResultsL1[i.ToString()] ,"J2.2", 1), GetMeasurementByPoint(CalculatedResultsL1[i.ToString()] ,"J2.3", 1));
// System.Console.WriteLine("J2_12: " + J2_23);
var J2_13 = CalculateDistance(GetMeasurementByPoint(CalculatedResultsL1[i.ToString()] ,"J2.1", 1), GetMeasurementByPoint(CalculatedResultsL1[i.ToString()] ,"J2.3", 1));
// System.Console.WriteLine("J2_12: " + J2_13);
var J3_12 = CalculateDistance(GetMeasurementByPoint(CalculatedResultsL1[i.ToString()] ,"J3.1", 1), GetMeasurementByPoint(CalculatedResultsL1[i.ToString()] ,"J3.2", 1));
// System.Console.WriteLine("J3_12: " + J3_12);
var J3_23 = CalculateDistance(GetMeasurementByPoint(CalculatedResultsL1[i.ToString()] ,"J3.2", 1), GetMeasurementByPoint(CalculatedResultsL1[i.ToString()] ,"J3.3", 1));
// System.Console.WriteLine("J3_12: " + J3_23);
var J3_13 = CalculateDistance(GetMeasurementByPoint(CalculatedResultsL1[i.ToString()] ,"J3.1", 1), GetMeasurementByPoint(CalculatedResultsL1[i.ToString()] ,"J3.3", 1));
// System.Console.WriteLine("J3_12: " + J3_13);
double delta =
Math.Pow(J1_12 - L0_J1_12, 2) +
Math.Pow(J1_23 - L0_J1_23, 2) +
Math.Pow(J1_13 - L0_J1_13, 2) +
Math.Pow(J2_12 - L0_J2_12, 2) +
Math.Pow(J2_23 - L0_J2_23, 2) +
Math.Pow(J2_13 - L0_J2_13, 2) +
Math.Pow(J3_12 - L0_J3_12, 2) +
Math.Pow(J3_23 - L0_J3_23, 2) +
Math.Pow(J3_13 - L0_J3_13, 2);
System.Console.WriteLine(delta + " | " + (NG_PREDEL_LOW + (STEP_NG * i)) + " | " + (BETA_PREDEL_LOW + (STEP_BETA * i)));
Store.Add(new DeltaStore{
DELTA = delta, BETA = NG_PREDEL_LOW + (STEP_NG * i), NG = BETA_PREDEL_LOW + (STEP_BETA * i)
});
}
Console.WriteLine("[2] Layer 2 is completed, start calculate gradient");
// var ng_min =
}
// Корректировка координат для 1 вектора
Vector3D RunDivergenceCorrectForCoordinate(double NG, int BETA, double PA, double TA, double HA, double PC, double TC, Vector3D M1, Vector3D M2, Vector3D XYZ) {
var option = new CalculationSettings
{
NA = null,
NC = null,
NG = (decimal)NG,
Alpha = (decimal)ALPHA,
Dgm = (decimal)DGM,
PA = (decimal)PA,
TA = (decimal)TA,
HA = (decimal)HA,
Lambda = (decimal)LAMBDA,
Beta = BETA,
TC = (decimal)TC,
PC = (decimal)PC,
};
var calcLogger = new CalculateVectorCore(option);
var CALCULATED = calcLogger.CalculateData(
XYZ,
M1,
M2
);
return CALCULATED;
}
// Вычисление длинны вектора
double CalculateDistance(Vector3D JI_1, Vector3D JI_2) {
return (double)Vector3D.Length(JI_1, JI_2);
}
Vector3D GetMeasurementByPoint(List<Measurement> measurements, string point, int iteration)
{
var Partial = measurements.FirstOrDefault(m => m.Point == point && m.Iteration == iteration);
if (Partial == null) {
throw new Exception("Ошибка поиска " + point + " на итерации " + iteration);
}
return new Vector3D(Partial.FixedX, Partial.FixedY, Partial.FixedZ);
}
public class CsvParser
{
public static List<Measurement> Parse(string filePath)
{
var measurements = new List<Measurement>();
var lines = File.ReadAllLines(filePath);
for (int i = 1; i < lines.Length; i++) // Пропускаем заголовок
{
var values = lines[i].Split(';');
var measurement = new Measurement
{
Iteration = int.Parse(values[0]),
Point = values[1],
X = double.Parse(values[2].Replace(',', '.'), CultureInfo.InvariantCulture),
Y = double.Parse(values[3].Replace(',', '.'), CultureInfo.InvariantCulture),
Z = double.Parse(values[4].Replace(',', '.'), CultureInfo.InvariantCulture),
PressurePa = double.Parse(values[5].Replace(',', '.'), CultureInfo.InvariantCulture),
TemperatureTa = double.Parse(values[6].Replace(',', '.'), CultureInfo.InvariantCulture),
HumidityHa = double.Parse(values[7].Replace(',', '.'), CultureInfo.InvariantCulture),
PressurePc = double.Parse(values[8].Replace(',', '.'), CultureInfo.InvariantCulture),
TemperatureTc = double.Parse(values[9].Replace(',', '.'), CultureInfo.InvariantCulture),
HumidityHc = double.Parse(values[10].Replace(',', '.'), CultureInfo.InvariantCulture)
};
measurements.Add(measurement);
}
return measurements;
}
}
class DeltaStore {
public double BETA {get;set;}
public double NG {get;set;}
public double DELTA {get;set;}
}
public class MeasurementMX {
public int Iteration { get; set; }
public string Point { get; set; }
public double X { get; set; }
public double Y { get; set; }
public double Z { get; set; }
}
public class Measurement
{
public int Iteration { get; set; }
public string Point { get; set; }
public double X { get; set; }
public double Y { get; set; }
public double Z { get; set; }
public double PressurePa { get; set; }
public double TemperatureTa { get; set; }
public double HumidityHa { get; set; }
public double PressurePc { get; set; }
public double TemperatureTc { get; set; }
public double HumidityHc { get; set; }
public double FixedX { get; set; }
public double FixedY { get; set; }
public double FixedZ { get; set; }
public override string ToString()
{
return $"Iteration: {Iteration}, Point: {Point}, X: {X}, Y: {Y}, Z: {Z}, PressurePa: {PressurePa}, TemperatureTa: {TemperatureTa}, HumidityHa: {HumidityHa}, PressurePc: {PressurePc}, TemperatureTc: {TemperatureTc}, HumidityHc: {HumidityHc}";
}
}