⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 libqdiagnose.bas

📁 本系统是给大庆油田做的一个示例程序
💻 BAS
字号:
Attribute VB_Name = "LibQDiagnose"
Option Explicit
Rem 计产主程序
Sub QDiagnose_Cal(QDiagnoseUnit As String, Lz As Single, pr_well As Single, Pb_Well As Single, SCrudeOil As Single, mu As Single, _
                nw As Single, sp As Single, lpump As Single, hmove As Single, poil As Single, _
                pcase As Single, dtubei As Single, S0 As Single, tanchor As String, twell As Single, _
                Spr_use As Single, rpm As Single, dpump As Single, FPump As Single, _
                nrod As Integer, drod() As Single, lrod() As Single, srod() As Single, ERod() As Single, _
                WellType As String, NcalWell As Integer, XWell() As Single, SetWell() As Single, FaiWell() As Single, _
                Ncal_MeasuringPoint As Integer, spr_card As Single, rpm_card As Single, _
                Pr_Card() As Single, Prl_Card() As Single, BreakdownKind As String, ParasOut() As Single, _
                Ncal As Integer, XPump() As Single, PPump() As Single)


    Rem Ncal--------------实测示功图扩展后的计算点数(数据采集点数)
    Rem Pr_Card(Ncal)-----悬点位移;
    Rem Prl_Card(Ncal)----悬点载荷;
    Rem PRLMax------------悬点最大载荷
    Rem PRLMin------------悬点最小载荷
    
    Rem WrBar-------------抽油杆柱在流体中的重量
    Rem Wr   -------------抽油杆柱在空气中的重量
    Rem UnitWrBar---------抽油杆柱在流体中的重量的规则化 WrBar/PRLMax
    
    Rem Q_Th--------------油井实际产液量
    Rem Alfa_Present------实际泵效
    
    Rem UnitPr_Card(Ncal)------规则化的悬点位移Pr_Card(i)/Spr_Use
    Rem UnitPRL_Card(Ncal)-----规则化的悬点载荷PrL_Card(i)/PRLMax
    
    Rem XPump(Ncal)-------柱塞位移
    Rem PPump(Ncal)-------柱塞载荷
    
    Rem Jcal--------------计算点数Jcal=Ncal
    Rem JcalU-------------柱塞上冲程计算点数
    Rem JcalD-------------柱塞上冲程计算点数
    
    Rem XPumpU(Ncal)------柱塞位移
    Rem PPumpU(Ncal)------柱塞载荷
    Rem XPumpD(Ncal)------柱塞上冲程位移
    Rem PPumpD(Ncal)------柱塞上冲程载荷
    
    Rem UnitXPump(Ncal)---规则化柱塞位移
    Rem UnitPPump(Ncal)---规则化柱塞载荷
    Rem UnitXPumpU(NcalU)-规则化柱塞上冲程位移
    Rem UnitPPumpU(NcalU)-规则化柱塞上冲程载荷
    Rem UnitXPumpD(NcalD)-规则化柱塞下冲程位移
    Rem UnitPPumpD(NcalD)-规则化柱塞下冲程载荷
    
    Rem XPumps(Ncal)------标准泵功图柱塞位移
    Rem PPumps(Ncal)------标准泵功图柱塞载荷
    Rem UnitPPump_Standard(Ncal)-----标准泵功图规则化的柱塞载荷
   
   
    Rem FU1(NcalU)--------柱塞上冲程载荷位移曲线1阶导数
    Rem FU2(NcalU)--------柱塞上冲程载荷位移曲线2阶导数
   
    Rem FD1(NcalD)--------柱塞下冲程载荷位移曲线1阶导数
    Rem FD2(NcalD)--------柱塞下冲程载荷位移曲线2阶导数
    
    Rem NBreakdowns-------故障特征参数的维数
    Rem DTBreakdowns()----故障特征参数
    Rem BreakdownCauses()-故障类型
    
    Dim vset0 As Single, VSetCal As Single
    Dim DeltT As Single
    Dim Ttime(2500) As Single, t_time(2500) As Single
    Dim Pr(2500) As Single, vpr(2500) As Single, prl(2500) As Single
    
    Dim swo As Single, soil As Single, swater As Single
    Dim wrbar As Single, wr As Single, UnitWrBar As Single
    
    Dim UnitPr_Card(2500) As Single, UnitPrl_Card(2500) As Single
    
    'Dim XPump(2500) As Single, PPump(2500) As Single
    Dim XPumpU(2500) As Single, PPumpU(2500) As Single, XPumpD(2500) As Single, PPumpD(2500) As Single
    Dim UnitXPump(2500) As Single, UnitPPump(2500) As Single
    Dim UnitXPumpU(2500) As Single, UnitPPumpU(2500) As Single
    Dim UnitXPumpD(2500) As Single, UnitPPumpD(2500) As Single
    
    Dim LPMaxDiagnose As Single, NPumpOut As Single '由泵示功图计算
    Dim DeltPdPs As Single, QFromNPumpOut As Single '由泵示功图计算
    Dim DeltLPmax As Single '因摩擦导致的泵附加载荷幅值
    
    Dim ps As Single, pd As Single
    Dim pb As Single
    Dim LPmax As Single
    Dim elsm As Single, lamdar As Single, lamdat As Single
    Dim SprPump As Single
    
    Dim i As Integer, j As Integer
    Dim k As Integer
    'Dim Ncal As Integer
    Dim jcal As Integer
    Dim JcalU As Integer, JcalD As Integer
    
    Dim FU(2500) As Single, FU1(2500) As Single, FU2(2500) As Single
    Dim FD(2500) As Single, FD1(2500) As Single, FD2(2500) As Single
    
    Dim PrlMax As Single, PrlMin As Single
    
    Dim SPump As Single, SPumpDischarge As Single, SPumpSuction As Single
    Dim QSpr As Single, QPump As Single, QPumpDischarge As Single, QPumpSuction As Single
    
    Dim Sp_Calculation As Single
    Dim Bogws As Single, Bogwd As Single
    
    Dim QDisDiagnose As Single, QSucDiagnose As Single
    Dim QDiagnose As Single, AlfaDiagnose As Single
    
    Dim PrPowerMeasured As Single, PowerPrlSimulated As Single, PrlMaxSimulated As Single
    Dim CoeffLeak1 As Single, CoeffLeak2 As Single '漏失影响系数
   
    Rem 计算混合液密度
    soil = SCrudeOil
    swater = 1000
    swo = nw * 1000 + (1 - nw) * soil
    
    Rem 计算杆管静变形
    Call PsCal(nw, lpump, hmove, pcase, SCrudeOil, ps)
    Call PdCal(lpump, poil, nw, sp, SCrudeOil, pd)
    LPmax = FPump * (pd - ps)
    Call Lamdat_Cal(nrod, drod, lrod, ERod, dtubei, tanchor, LPmax, lamdar, lamdat)
    Rem  抽油杆柱在油中的重量
    Call WRbarSum_Cal(nrod, drod, lrod, srod, nw, SCrudeOil, wrbar, wr)
    
    Rem 一个测试周期内,各离散测试点的时间
    VSetCal = 2 * pi / 60 * rpm_card
    DeltT = 60 / rpm_card / (Ncal_MeasuringPoint - 1)
    For j = 1 To Ncal_MeasuringPoint + 1
        Ttime(j) = (j - 1) * DeltT
    Next j
    
    Rem 在一个测试周期内,扩展时间点数,并确定各离散测试点的时间
    Ncal = Ncal_MeasuringPoint + 600
    DeltT = 60 / rpm_card / (Ncal - 1)
    
    For j = 1 To Ncal + 1
        t_time(j) = (j - 1) * DeltT
    Next j
    If t_time(Ncal) > Ttime(Ncal_MeasuringPoint) Then t_time(Ncal) = Ttime(Ncal_MeasuringPoint)
    
    Rem 测试功图扩展
    Call DataTreatd_Card(Ncal_MeasuringPoint, Ttime, Pr_Card, Prl_Card, Ncal, t_time)
    
    Rem 将悬点示功图转化成泵功图
    Call PumpDynyCards_Cal(Ncal, nrod, drod, lrod, srod, ERod, nw, SCrudeOil, VSetCal, t_time, _
                             Pr_Card, Prl_Card, XPump, PPump)
    
    Rem 计算柱塞有效冲程长度、泵输出功率、柱塞液体载荷
    Call PumpCard_Analysis(Ncal, rpm_card, FPump, XPump, PPump, SPump, LPMaxDiagnose, DeltPdPs, NPumpOut, QFromNPumpOut)
    
    Rem 考虑油管柱变形的影响,计算柱塞有效冲程长度
    If LPMaxDiagnose > LPmax Then
        lamdat = lamdat * LPMaxDiagnose / LPmax
    End If
    SPump = SPump - lamdat
    
    Rem  悬点示功图的规则化
    Call PrlCardNormalized(Ncal, Pr_Card, Prl_Card, UnitPr_Card, UnitPrl_Card, wrbar, UnitWrBar)
      
    Rem  泵示功图的规则化
    Call PumpCardNormalized(Ncal, XPump, PPump, UnitXPump, UnitPPump)
    
    Rem  上下冲程分别记数,上冲程泵规则化载荷-规则化位移、下冲程泵规则化载荷-规则化位移
    Call JcalUD_Cal(Ncal, XPump, PPump, UnitXPump, UnitPPump, _
                   JcalU, JcalD, UnitXPumpU, UnitPPumpU, UnitXPumpD, UnitPPumpD)
    
    Rem  线性光滑
    Call LinearSmoothing(JcalU, UnitXPumpU, UnitPPumpU)
    Call LinearSmoothing(JcalD, UnitXPumpD, UnitPPumpD)
    
    jcal = 101 '规范采样点,上下冲程均等位移均匀采样。数组由 1 开始记数
   
    Rem  上冲程等位移均匀采样后的载荷、1阶导数、2阶导数
    Call PumpCard_EqualSampling(jcal, JcalU, UnitXPumpU, UnitPPumpU, FU1, FU2)
    
    Rem  下冲程等位移均匀采样后的载荷、1阶导数、2阶导数。记数始点为上死点
    Call PumpCard_EqualSampling(jcal, JcalD, UnitXPumpD, UnitPPumpD, FD1, FD2)
   
    Rem  计算有效吸入行程、有效排出冲程
    Call SEqualDisSuc(jcal, UnitXPumpU, UnitPPumpU, FU1, FU2, _
                      UnitXPumpD, UnitPPumpD, FD1, FD2, SPumpDischarge, SPumpSuction)
   
    If SPumpDischarge >= 0.995 Then
        SPumpDischarge = 0.995
    End If
    
    Rem  按吸入或排出有效冲程长度,计算理论产液量,单位(m^3/d)
    QSpr = 1440 * FPump * spr_card * rpm_card
    QPump = 1440 * FPump * SPump * rpm_card
    QPumpDischarge = 1440 * FPump * SPump * SPumpDischarge * rpm_card
    QPumpSuction = 1440 * FPump * SPump * SPumpSuction * rpm_card
    
    Rem  根据有效排出冲程,计算实际气油比
    Call Sp_Cal(Pb_Well, SPump, ps, pd, S0, nw, SCrudeOil, twell, SPumpSuction, SPumpDischarge, Sp_Calculation)
    
    Rem  计算油气水的综合体积系数
    Call Bogw_Cal(Pb_Well, ps, pd, twell, nw, sp, SCrudeOil, Bogwd)
    Call Bogw_Cal(Pb_Well, ps, ps, twell, nw, sp, SCrudeOil, Bogws)
   
    Rem 计算正常间隙的漏失影响系数(3级泵)
    Call C_Leaking_Cal(3, SPump, dpump, FPump, mu, rpm_card, ps, pd, CoeffLeak1)
    
    Rem 考虑体积系数、正常漏失,实际产液量
    QDisDiagnose = QPumpDischarge * Bogwd * CoeffLeak1
    QSucDiagnose = QPumpSuction * Bogws * CoeffLeak1
    
Rem 诊断故障与计算非正常漏失影响系数
    Rem 利用仿真方法,计算抽油杆在泵处断脱时的光杆功率
    Call Card_Simulation(WellType, NcalWell, XWell, SetWell, FaiWell, twell, _
                    nrod, drod, lrod, Spr_use, rpm, dpump, lpump, SCrudeOil, sp, nw, mu, _
                    dtubei, poil, pcase, hmove, tanchor, PowerPrlSimulated, PrlMaxSimulated)
    
    Rem 诊断故障与计算漏失影响系数
    Call BreakDowns_Diagnose(rpm, dpump, lpump - hmove, nw, PowerPrlSimulated, Ncal_MeasuringPoint, Pr_Card, Prl_Card, _
                             jcal, UnitXPumpU, UnitPPumpU, FU1, UnitXPumpD, UnitPPumpD, FD1, _
                             SPumpSuction, SPumpDischarge, wrbar, LPmax, LPMaxDiagnose, BreakdownKind, CoeffLeak2)
   
    Rem 考虑非正常漏失的影响,计算实际产液量
    QDisDiagnose = QDisDiagnose * CoeffLeak2
    QSucDiagnose = QSucDiagnose * CoeffLeak2
    
    Rem  当产量单位为(t/d)时,计算实际产液量
    If QDiagnoseUnit = "吨/日" Then
        QSpr = QSpr * swo / 1000
        QDisDiagnose = QDisDiagnose * swo / 1000
        QSucDiagnose = QSucDiagnose * swo / 1000
    End If
    
    QDiagnose = Int(QDisDiagnose * 100) / 100
    AlfaDiagnose = Int(QDisDiagnose / QSpr * 100 * 100) / 100
    
    ParasOut(1) = Int(spr_card * 100) / 100
    ParasOut(2) = Int(rpm_card * 100) / 100
    ParasOut(3) = Int(QSpr * 100) / 100
    
    ParasOut(4) = Int(SPump * 100) / 100
    
    ParasOut(5) = QDiagnose
    ParasOut(6) = AlfaDiagnose
    ParasOut(7) = Int(CoeffLeak1 * CoeffLeak2 * 100 * 100) / 100
End Sub

Rem  泵示功图上下死点序号;上、下冲程数据点数;泵最大、最小位移;泵冲程长度
Rem 上下冲程载荷位移分别记数,上冲程位移零点为下死点,下冲程位移零点为上死点
Sub JcalUD_Cal(Ncal As Integer, XPump() As Single, PPump() As Single, _
           UnitXPump() As Single, UnitPPump() As Single, JcalU As Integer, JcalD As Integer, _
           UnitXPumpU() As Single, UnitPPumpU() As Single, UnitXPumpD() As Single, UnitPPumpD() As Single)
    
    Dim j As Integer
    Dim XPumpMin As Single, XPumpMax As Single
    Dim JMin As Single, JMax As Single
    
    XPumpMin = XPump(1)
    XPumpMax = XPump(1)
    JMin = 1
    JMax = 1
    
    For j = 1 To Ncal
        If XPump(j) < XPumpMin Then
            JMin = j
            XPumpMin = XPump(j)
        End If
        
        If XPump(j) > XPumpMax Then
            JMax = j
            XPumpMax = XPump(j)
        End If
    Next j
    
    If JMin > JMax Then
        JMin = 1
    End If
    
    JcalU = JMax - JMin + 1
    JcalD = JMin + Ncal - JMax + 1
    
    
    Rem  泵示功图进一步规范化处理(上下冲程分别记数)
    Rem  上冲程泵载荷、位移序列(j=1,2,3,.....,JcalU)
    For j = 1 To JcalU
        UnitXPumpU(j) = UnitXPump(JMin + j - 1)
        UnitPPumpU(j) = UnitPPump(JMin + j - 1)
    Next j

    Rem  下冲程泵载荷位移(上死点为位移零点,向下为正,(j=1,2,3,.....,JcalD))
    For j = 1 To JcalD
        If j <= JMin Then
            UnitXPumpD(j) = UnitXPump(JMin - j + 1)
            UnitPPumpD(j) = UnitPPump(JMin - j + 1)
        End If
        If j > JMin Then
            UnitXPumpD(j) = UnitXPump(Ncal + JMin - j + 1)
            UnitPPumpD(j) = UnitPPump(Ncal + JMin - j + 1)
        End If
    Next j
    
    Rem  载荷位移曲线局部振荡点处理(死点附近)
    For j = 2 To JcalU
        If UnitXPumpU(j) <= UnitXPumpU(j - 1) Then
            UnitXPumpU(j) = (UnitXPumpU(j - 1) + UnitXPumpU(j + 1)) / 2
        End If
    Next j
    
    For j = 2 To JcalD
        If UnitXPumpD(j) <= UnitXPumpD(j - 1) Then
            UnitXPumpD(j) = (UnitXPumpD(j - 1) + UnitXPumpD(j + 1)) / 2
        End If
    Next j
End Sub
Rem 计算固定阀与游动阀的开启点
Sub SEqualDisSuc(jcal As Integer, UnitXPumpU() As Single, UnitPPumpU() As Single, FU1() As Single, FU2() As Single, _
                 UnitXPumpD() As Single, UnitPPumpD() As Single, FD1() As Single, FD2() As Single, _
                 SPumpDischarge As Single, SPumpSuction As Single)
    Dim j As Integer
    Dim UnitPPumpD1(500) As Single
    Dim UnitXPumpD0 As Single
    
    SPumpDischarge = 0.95
    SPumpSuction = 0.1
End Sub


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -