From 09c1d78e98e01881f5abec85b75b52149b9b35f8 Mon Sep 17 00:00:00 2001
From: lx <ex_lixiang17@cols.com.cn>
Date: 星期五, 08 八月 2025 02:55:01 +0800
Subject: [PATCH] upload

---
 ErrorAnalysis.Service/ErrorRatioCalc.cs |  174 +++++++++++++++++++++++++++++++++------------------------
 1 files changed, 101 insertions(+), 73 deletions(-)

diff --git a/ErrorAnalysis.Service/ErrorRatioCalc.cs b/ErrorAnalysis.Service/ErrorRatioCalc.cs
index 3adf1d7..7b8d892 100644
--- a/ErrorAnalysis.Service/ErrorRatioCalc.cs
+++ b/ErrorAnalysis.Service/ErrorRatioCalc.cs
@@ -1,4 +1,5 @@
 锘縰sing ErrorAnalysis.Repository;
+using ErrorAnalysis.Service;
 using ErrorAnalysis.Service.Model;
 using System;
 using System.Collections.Generic;
@@ -10,7 +11,7 @@
 {
     public class ErrorRatioCalc
     {
-        public static ErrorRatioResult GetErrorRatioResult(string modelID, double porosity, double sw, double depth, bool lockSpeed, double speed, double targetErrorRatio, int pass = 0)
+        public static ErrorRatioResult GetErrorRatioResult(string modelID, double porosity, double sw, double depth, bool lockSpeed, double speed, double yieldCounting, double targetErrorRatio, out double testSpeed, int pass = 0, double nearCofe = 0.65, double farCofe = 0.35)
         {
             var result = new ErrorRatioResult
             {
@@ -24,16 +25,17 @@
             {
                 List<double[]> cWOL;
                 List<double[]> oWOL;
-                var firsErrorPass = GetFirstErrorRatio(modelID, porosity, sw, speed, depth, out cWOL, out oWOL);
+                var firstErrorPassM = GetFirstErrorRatio(modelID, porosity, sw, speed, depth, yieldCounting, nearCofe, farCofe);
+                (cWOL, oWOL) = GetOilWaterLine(modelID);
                 result.CWOL = cWOL;
                 result.OWOL = oWOL;
-                result.ErrorRatios.Add(firsErrorPass);
-                if (firsErrorPass.ErrorRatioValue > targetErrorRatio)
+                result.ErrorRatios.Add(firstErrorPassM);
+                if (firstErrorPassM.ErrorRatioValue > targetErrorRatio)
                 {
-                    var targetPass = Convert.ToInt32(Math.Ceiling(Math.Pow(firsErrorPass.ErrorRatioValue / targetErrorRatio, 2)));
+                    var targetPass = Convert.ToInt32(Math.Ceiling(Math.Pow(firstErrorPassM.ErrorRatioValue / targetErrorRatio, 2)));
                     for (int i = 2; i <= targetPass; i++)
                     {
-                        result.ErrorRatios.Add(new ErrorRatio { Pass = i, ErrorRatioValue = firsErrorPass.ErrorRatioValue / Math.Sqrt(i) });
+                        result.ErrorRatios.Add(new ErrorRatio { Pass = i, ErrorRatioValue = firstErrorPassM.ErrorRatioValue / Math.Sqrt(i) });
                     }
                 }
             }
@@ -42,98 +44,124 @@
                 var firstTargetErrorRatio = targetErrorRatio * Math.Sqrt(pass);
                 List<double[]> cWOL;
                 List<double[]> oWOL;
-                var firstErrorPass = new ErrorRatio();
-                speed = 0.6;
-                while (firstErrorPass.ErrorRatioValue != 0 && firstErrorPass.ErrorRatioValue > firstTargetErrorRatio)
+                (cWOL, oWOL) = GetOilWaterLine(modelID);
+                result.CWOL = cWOL;
+                result.OWOL = oWOL;
+
+                var nearCROR = COMergeCalcService.GetNearCOORResult(modelID, porosity, sw);
+                var farCROR = COMergeCalcService.GetFarCOORResult(modelID, porosity, sw);
+                var mDelta = GetMDelta(modelID, porosity);
+
+                speed = Math.Pow(firstTargetErrorRatio /
+                    (Math.Sqrt(160 / (0.0762 * depth * 36d * yieldCounting)) *
+                    1d / mDelta) /
+                    Math.Sqrt((Math.Pow(nearCofe, 2) * (Math.Pow(nearCROR.Item1 / nearCROR.Item2, 2)) * (1 / nearCROR.Item1 + 1 / nearCROR.Item2)) + (Math.Pow(farCofe, 2) * (Math.Pow(farCROR.Item1 / farCROR.Item2, 2)) * (1 / farCROR.Item1 + 1 / farCROR.Item2)))
+                    , 2);
+
+                var firstErrorPass = new ErrorRatio { Pass = 1, ErrorRatioValue = firstTargetErrorRatio };
+
+                //var firstErrorPass = new ErrorRatio();
+                //speed = 0.05;
+                //do
+                //{
+                //    firstErrorPass = GetFirstErrorRatio(modelID, porosity, sw, speed, depth, yieldCounting, nearCofe, farCofe);
+                //    result.CWOL = cWOL;
+                //    result.OWOL = oWOL;
+                //    speed -= 0.0001;
+                //} while (firstErrorPass.ErrorRatioValue != 0 && firstErrorPass.ErrorRatioValue > firstTargetErrorRatio);
+                result.ErrorRatios.Clear();
+                result.ErrorRatios.Add(firstErrorPass);
+                for (int i = 2; i <= pass; i++)
                 {
-                    firstErrorPass = GetFirstErrorRatio(modelID, porosity, sw, speed, depth, out cWOL, out oWOL);
-                    result.CWOL = cWOL;
-                    result.OWOL = oWOL;
-                    speed -= 0.01;
+                    result.ErrorRatios.Add(new ErrorRatio { Pass = i, ErrorRatioValue = firstErrorPass.ErrorRatioValue / Math.Sqrt(i) });
                 }
             }
+            testSpeed = speed;
 
             return result;
 
         }
 
-        private static ErrorRatio GetFirstErrorRatio(string modelID, double porosity, double sw, double speed, double depth, out List<double[]> cWOL, out List<double[]> oWOL)
+        private static ErrorRatio GetFirstErrorRatio(string modelID, double porosity, double sw, double speed, double depth, double yieldCounting, double nearCofe, double farCofe)
         {
             if (porosity > 40)
                 throw new InvalidDataException("Porosity value out of range!");
 
-            cWOL = new List<double[]>();
-            oWOL = new List<double[]>();
-
-            var cWolRes = RepositoryInstance.Instance.COWOLRepository?.GetWOL(modelID, 0);
-            var oWolRes = RepositoryInstance.Instance.COWOLRepository?.GetWOL(modelID, 100);
-
-            var mergePDEV = PDEVCalcService.GetMergePDEV(modelID, porosity, sw, speed, depth);
-
-            var wolResType = cWolRes?.GetType();
             try
             {
-                if (sw > 0 && sw < 100)
-                {
-                    foreach (var wolProperty in wolResType.GetProperties())
-                    {
-                        if (wolProperty.Name.Contains("WLPu"))
-                        {
-                            var interC = Utility.Interpolate(sw, 100, 0, 0, (double)wolProperty.GetValue(cWolRes));
-                            var interO = Utility.Interpolate(sw, 0, 0, 100, (double)wolProperty.GetValue(oWolRes));
-                            wolProperty.SetValue(cWolRes, interC);
-                            wolProperty.SetValue(oWolRes, interO);
-                        }
-                    }
-                }
+                var mDelta = GetMDelta(modelID, porosity);
 
-                foreach (var wolProperty in wolResType.GetProperties())
-                {
-                    if (wolProperty.Name.Contains("WLPu"))
-                    {
-                        cWOL.Add([Convert.ToDouble(wolProperty.Name.Replace("WLPu", "")), Convert.ToDouble(wolProperty.GetValue(cWolRes))]);
-                        oWOL.Add([Convert.ToDouble(wolProperty.Name.Replace("WLPu", "")), Convert.ToDouble(wolProperty.GetValue(oWolRes))]);
-                    }
-                }
+                //var mergePDEVOld = PDEVCalcService.GetMergePDEV(modelID, porosity, sw, speed, depth, yieldCounting, nearCofe, farCofe);
 
-                double cRes = 0;
-                double oRes = 0;
+                var nearCROR = COMergeCalcService.GetNearCOORResult(modelID, porosity, sw);
+                var farCROR = COMergeCalcService.GetFarCOORResult(modelID, porosity, sw);
 
-                if (porosity % 5 == 0)
-                {
-                    var poroFiledName = $"WLPu" + porosity;
-                    var property = wolResType.GetProperty(poroFiledName);
+                var mergePDEV = Math.Sqrt(160 * speed / (0.0762 * 36 * depth * yieldCounting)) * Math.Sqrt((Math.Pow(nearCofe, 2) * (Math.Pow(nearCROR.Item1 / nearCROR.Item2, 2)) * (1 / nearCROR.Item1 + 1 / nearCROR.Item2)) + (Math.Pow(farCofe, 2) * (Math.Pow(farCROR.Item1 / farCROR.Item2, 2)) * (1 / farCROR.Item1 + 1 / farCROR.Item2)));
 
-                    cRes = Convert.ToDouble(property.GetValue(cWolRes));
-                    oRes = Convert.ToDouble(property.GetValue(oWolRes));
-                }
-                else
-                {
-                    var ceilingPorosity = Math.Ceiling(porosity / 5) * 5;
-                    var ceilingProperty = wolResType.GetProperty($"WLPu" + ceilingPorosity);
-                    var ceilingC = Convert.ToDouble(ceilingProperty.GetValue(cWolRes));
-                    var ceilingO = Convert.ToDouble(ceilingProperty.GetValue(oWolRes));
-
-
-                    var floorPorosity = Math.Floor(porosity / 5) * 5;
-                    var floorProperty = wolResType.GetProperty($"WLPu" + floorPorosity);
-                    var floorC = Convert.ToDouble(floorProperty.GetValue(cWolRes));
-                    var floorO = Convert.ToDouble(floorProperty.GetValue(oWolRes));
-
-                    cRes = Utility.Interpolate(porosity, floorPorosity, floorC, ceilingPorosity, ceilingC);
-                    oRes = Utility.Interpolate(porosity, floorPorosity, floorO, ceilingPorosity, ceilingO);
-                }
-
-                var errorRatio = mergePDEV / (cRes - oRes);
+                var errorRatio = mergePDEV / mDelta;
 
                 return new ErrorRatio { Pass = 1, ErrorRatioValue = errorRatio };
             }
             catch
             {
-                cWOL = null;
-                oWOL = null;
                 return new ErrorRatio { Pass = 0, ErrorRatioValue = 0 };
             }
         }
+
+        private static double GetMDelta(string modelID, double porosity)
+        {
+            var cWolRes = RepositoryInstance.Instance.COWOLRepository?.GetWOL(modelID, 0);
+            var oWolRes = RepositoryInstance.Instance.COWOLRepository?.GetWOL(modelID, 100);
+            var wolResType = cWolRes?.GetType();
+
+            double cRes = 0;
+            double oRes = 0;
+
+            if (porosity % 5 == 0)
+            {
+                var poroFiledName = $"WLPu" + porosity;
+                var property = wolResType.GetProperty(poroFiledName);
+
+                cRes = Convert.ToDouble(property.GetValue(cWolRes));
+                oRes = Convert.ToDouble(property.GetValue(oWolRes));
+            }
+            else
+            {
+                var ceilingPorosity = Math.Ceiling(porosity / 5) * 5;
+                var ceilingProperty = wolResType.GetProperty($"WLPu" + ceilingPorosity);
+                var ceilingC = Convert.ToDouble(ceilingProperty.GetValue(cWolRes));
+                var ceilingO = Convert.ToDouble(ceilingProperty.GetValue(oWolRes));
+
+
+                var floorPorosity = Math.Floor(porosity / 5) * 5;
+                var floorProperty = wolResType.GetProperty($"WLPu" + floorPorosity);
+                var floorC = Convert.ToDouble(floorProperty.GetValue(cWolRes));
+                var floorO = Convert.ToDouble(floorProperty.GetValue(oWolRes));
+
+                cRes = Utility.Interpolate(porosity, floorPorosity, floorC, ceilingPorosity, ceilingC);
+                oRes = Utility.Interpolate(porosity, floorPorosity, floorO, ceilingPorosity, ceilingO);
+            }
+            return cRes - oRes;
+        }
+
+        private static (List<double[]>, List<double[]>) GetOilWaterLine(string modelID)
+        {
+            var cWOL = new List<double[]>();
+            var oWOL = new List<double[]>();
+
+            var cWolRes = RepositoryInstance.Instance.COWOLRepository?.GetWOL(modelID, 0);
+            var oWolRes = RepositoryInstance.Instance.COWOLRepository?.GetWOL(modelID, 100);
+            var wolResType = cWolRes?.GetType();
+
+            foreach (var wolProperty in wolResType.GetProperties())
+            {
+                if (wolProperty.Name.Contains("WLPu"))
+                {
+                    cWOL.Add([Convert.ToDouble(wolProperty.Name.Replace("WLPu", "")), Convert.ToDouble(wolProperty.GetValue(cWolRes))]);
+                    oWOL.Add([Convert.ToDouble(wolProperty.Name.Replace("WLPu", "")), Convert.ToDouble(wolProperty.GetValue(oWolRes))]);
+                }
+            }
+            return (cWOL, oWOL);
+        }
     }
 }
\ No newline at end of file

--
Gitblit v1.9.3