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

📄 scjjdfx.cpp

📁 这是本人两年前兼职为某个公司做的石油钻进设计软件
💻 CPP
📖 第 1 页 / 共 4 页
字号:
// scjjdfx.cpp : implementation file
//

#include "stdafx.h"
#include "CVenus.h"
#include "scjjdfx.h"

#include "yqsxz.h"
#include "math.h"
#include "qjyljs.h"
#include "LZXJD.h"
#include "direct.h"//用于得到系统路径

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// scjjdfx
/*extern CSpreadSheet m_grid;
extern CButton	m_check4;
extern CButton	m_check3;
extern CButton	m_check2;
extern CButton	m_check1;
*/
extern	int	g_iProgress ;	// 计算进度
extern	bool	bFinishThread;
extern	char  cGraphColor[][16];
extern	int   iGraphColorNum;

scjjdfx::scjjdfx()
{
}

scjjdfx::~scjjdfx()
{
}


/////////////////////////////////////////////////////////////////////////////
// scjjdfx message handlers
void scjjdfx::scjjdfxjs() 
{
	CF1Book*	m_pGrid;
	m_pGrid = &(((CCVenusApp*)AfxGetApp())->m_pMainDlg->m_grid);
	  int		iColorIndex = 0; // 颜色索引 lzj
	  //结果               [[[[   jieguo[20][200]
      //参数               [[[[   canshu[4][5]
	  //分析参数个数       [[[[   fxcsgs[4]
	  //计算总数           [[[[   jszs
	  //C井口压力          [[[[   cjkyl
	  //C地层压力		   [[[[   cdcyl
	  //C油管尺寸          [[[[   cygcc
	  //C油嘴尺寸          [[[[   cyzcc
	  //T井口              [[[[   tjingkou
	  //T地层              [[[[   tdiceng
	  //P地层              [[[[   pdiceng
	  //P地层00            [[[[   pdiceng00
	  //D地层深度          [[[[   ddcsd
	  //地层有效厚度       [[[[   dcyxhd
	  //气井供给边界半径   [[[[   qjggbjbj
	  //井底半径           [[[[   jdbj
	  //有效渗透率         [[[[   yxstl
	  //视表皮系数         [[[[   sbpxs
	  //N计算点数          [[[[   njsds
	  //Q气量增值          [[[[   qqlzz
	  //百分比累计         [[[[   bfblj
	  //Q气量              [[[[   qqiliang
	  //P井口0             [[[[   pjingkou0
	  //D深度              [[[[   dshendu
	  //P上流压力          [[[[   pslyl
	  //P下流压力          [[[[   pxlyl
	  //P回压              [[[[   phuiya
	  //P压力增减          [[[[   pylzj
	  //D压力比            [[[[   dylb
	  //Q油嘴气量          [[[[   qyzql
	  //G压力X             [[[[   gylx
	  //G压力              [[[[   gyali
	  //P井口              [[[[   pjingkou
	  CString fileDialogFilter2,fileDialogExt2;
      CString A,B,templs1,templs2,A1,A2,A6,A7;
      char w[5],temptp[100],temptp1[100];
	  int J,i,K;
	  double jieguo[40][210],canshu[8][8],fxcsgs[6];
	  double jszs,tjingkou,pdiceng;
	  double ddcsd,dcyxhd,qjggbjbj,jdbj,yxstl,sbpxs,njsds,qqlzz;
	  double qqiliang,pjingkou0,dshendu,pslyl,pxlyl,phuiya;
	  double pylzj,dylb,qyzql,gylx,gyali,pjingkou;
      double tdiceng,AF,BF,CF,NF,Qtest,Ptest,Qgmax,DIC,DIT1,DVT1,DIT2;
	  double DVT2,RR,HCh,DCH,GG,CO2,H2S,N2,LGR,GL,LC,TG,PC,TC,PD;
	  double Qgmax1,Qgmax2,Qgmax3,QG,TR,PR,UG,Z,BT,BAC,PWF;
	  double P1,Tun,P2,P3,P,Q,Q1,Q2,PI1,PI2,PO1,PO2;
      int cjkyl,cdcyl,cygcc,cyzcc,JK;
	  double Pmax,DX,DIT10,DVT10,DVT20,DVT30,DIT20,DIC0,Doc;
	  yqsxz csjs;
	  qjyljs qjyljsz;
	  LZXJD jslzjd;

	  w[5]='g';

	CString str;

	str = m_pGrid->GetTextRC(1, 5);
	ddcsd=atof(str);

	str = m_pGrid->GetTextRC(2, 5);
	pdiceng=atof(str);
	str = m_pGrid->GetTextRC(3, 5);
	tdiceng=atof(str);
	str = m_pGrid->GetTextRC(4, 5);
	pjingkou=atof(str);
	str = m_pGrid->GetTextRC(5, 5);
	tjingkou=atof(str);
	str = m_pGrid->GetTextRC(6, 5);
	phuiya=atof(str);
	str = m_pGrid->GetTextRC(7, 5);
	AF=atof(str);
	str = m_pGrid->GetTextRC(8, 5);
	BF=atof(str);
	str = m_pGrid->GetTextRC(9, 5);
	CF=atof(str);
	str = m_pGrid->GetTextRC(10, 5);
	NF=atof(str);
	str = m_pGrid->GetTextRC(11, 5);
	dcyxhd=atof(str);
	str = m_pGrid->GetTextRC(12, 5);
	qjggbjbj=atof(str);
	str = m_pGrid->GetTextRC(13, 5);
	jdbj=atof(str);
	str = m_pGrid->GetTextRC(14, 5);
	sbpxs=atof(str);
	str = m_pGrid->GetTextRC(15, 5);   
	yxstl=atof(str);
	str = m_pGrid->GetTextRC(16, 5);;   
	Qtest=atof(str);
	str = m_pGrid->GetTextRC(17, 5);   
	Ptest=atof(str);
	  str = m_pGrid->GetTextRC(18, 5);   
	  Qgmax=atof(str);
	  str = m_pGrid->GetTextRC(19, 5);   
	  DIC=atof(str);
      str = m_pGrid->GetTextRC(20, 5);   
	  DIT1=atof(str);
	  str = m_pGrid->GetTextRC(21, 5);   
	  DVT1=atof(str);
	  str = m_pGrid->GetTextRC(22, 5);   
	  DIT2=atof(str);
	  str = m_pGrid->GetTextRC(23, 5);   
	  DVT2=atof(str);
	  str = m_pGrid->GetTextRC(24, 5);   
	  RR=atof(str);
	  str = m_pGrid->GetTextRC(25, 5);   
	  HCh=atof(str);
	  str = m_pGrid->GetTextRC(26, 5);   
	  DCH=atof(str);
	  str = m_pGrid->GetTextRC(27, 5);   
	  GG=atof(str);
	  str = m_pGrid->GetTextRC(28, 5);   
	  CO2=atof(str);
	  str = m_pGrid->GetTextRC(29, 5);   
	  H2S=atof(str);
	  str = m_pGrid->GetTextRC(30, 5);   
	  N2=atof(str);
	  str = m_pGrid->GetTextRC(31, 5);   
	  LGR=atof(str);
	  str = m_pGrid->GetTextRC(32, 5);   
	  GL=atof(str);
	  str = m_pGrid->GetTextRC(33, 5);   
	  canshu[1][1]=atof(str);
	  str = m_pGrid->GetTextRC(34, 5);   
	  canshu[1][2]=atof(str);
	  str = m_pGrid->GetTextRC(35, 5);   
	  canshu[1][3]=atof(str);
	  str = m_pGrid->GetTextRC(36, 5);   
	  canshu[1][4]=atof(str);
	  str = m_pGrid->GetTextRC(37, 5);   
	  canshu[1][5]=atof(str);
	  str = m_pGrid->GetTextRC(38, 5);   
	  canshu[2][1]=atof(str);
	  str = m_pGrid->GetTextRC(39, 5);   
	  canshu[2][2]=atof(str);
	  str = m_pGrid->GetTextRC(40, 5);   
	  canshu[2][3]=atof(str);
	  str = m_pGrid->GetTextRC(41, 5);   
	  canshu[2][4]=atof(str);
	  str = m_pGrid->GetTextRC(42, 5);   
	  canshu[2][5]=atof(str);
	  str = m_pGrid->GetTextRC(43, 5);   
	  canshu[3][1]=atof(str);
	  str = m_pGrid->GetTextRC(44, 5);   
	  canshu[3][2]=atof(str);
	  str = m_pGrid->GetTextRC(45, 5);   
	  canshu[3][3]=atof(str);
	  str = m_pGrid->GetTextRC(46, 5);   
	  canshu[3][4]=atof(str);
	  str = m_pGrid->GetTextRC(47, 5);   
	  canshu[3][5]=atof(str);
	  str = m_pGrid->GetTextRC(48, 5);   
	  canshu[4][1]=atof(str);
	  str = m_pGrid->GetTextRC(49, 5);   
	  canshu[4][2]=atof(str);
	  str = m_pGrid->GetTextRC(50, 5);   
	  canshu[4][3]=atof(str);
	  str = m_pGrid->GetTextRC(51, 5);   
	  canshu[4][4]=atof(str);
	  str = m_pGrid->GetTextRC(52, 5);   
	  canshu[4][5]=atof(str);

	  cjkyl = ((CButton*)((CCVenusApp*)AfxGetApp())->m_pMainDlg->m_Page15.GetDlgItem(IDC_CHECK1))->GetCheck();
	  cdcyl = ((CButton*)((CCVenusApp*)AfxGetApp())->m_pMainDlg->m_Page15.GetDlgItem(IDC_CHECK2))->GetCheck();
	  cygcc = ((CButton*)((CCVenusApp*)AfxGetApp())->m_pMainDlg->m_Page15.GetDlgItem(IDC_CHECK3))->GetCheck();
	  cyzcc  = ((CButton*)((CCVenusApp*)AfxGetApp())->m_pMainDlg->m_Page15.GetDlgItem(IDC_CHECK4))->GetCheck();
	  
	g_iProgress = 5;	// 计算进度
	ENDCOMPUTE;
	  
	   //打开保存数据结果的文件
       CStdioFile f3;
	   CFileException exception3;
	   BOOL status1;	 
/*	   fileDialogFilter2 ="Data files (*.RGN)|*.RGN|All files (*.*)|*.*||";
	   fileDialogExt2 = "RGN";
	   CFileDialog fileDialog2( FALSE, 
			fileDialogExt2, NULL,
			0, fileDialogFilter2 );
	   if( fileDialog2.DoModal() == IDCANCEL )
	   {
           return;
	   }	 			  
*/
	   
	   templs1 = ((CCVenusApp*)AfxGetApp())->GetMyAppPath();
	   templs1  += "\\tempfile.txt";	
	   
	   //status1 = f3.Open(fileDialog2.GetPathName(),CFile::modeCreate|CFile::modeWrite);
	   status1 = f3.Open(templs1,CFile::modeCreate|CFile::modeWrite);

	   if (!status1)
		{
			char s[100];
			sprintf(s, "Error opening file for reading. Code:%d",
				exception3.m_cause);
			AfxMessageBox(s);
			return;
		}
	  //打开保存计算的图形结果的文件
       CStdioFile f4;
	   CFileException exception4;

	   templs1 = ((CCVenusApp*)AfxGetApp())->GetMyAppPath();
	   templs1  += "\\tempfile.gra";
	   
	   status1 = f4.Open(templs1,CFile::modeCreate|CFile::modeWrite);	
	   if (!status1)
		{
			char s[100];
			sprintf(s, "Error opening file for reading. Code:%d",
				exception4.m_cause);
			AfxMessageBox(s);
			return;
		}
      
	  for(i=1;i<=4;i++)
	  {
	  	for(J=1;J<=4;J++)
		{
		  if( int(canshu[i][J]) == 0)
		  {
			for(K=J+1;K<=5;K++)
			{
			  if( canshu[i][K] >= 0)
			  {
				  canshu[i][J] = canshu[i][K];
				  canshu[i][K] = 0;
				  break;
			}
		  }
		}
	  }
  
	  for(i=1;i<=4;i++)
	  {
		fxcsgs[i] = 0;
		for(J=1;J<=5;J++)
		{
		  if( canshu[i][J] > 0 )
		  {
			  fxcsgs[i] = fxcsgs[i] + 1;
		  }
		}
	  }
  
	  jszs = 0;
	  if( cjkyl == 1)
	  {
		  jszs = jszs + fxcsgs[1];
	  }
	  if( cdcyl == 1)
	  {
		  jszs = jszs + 2 * fxcsgs[2];
	  }
	  if( cygcc == 1)
	  {
		  jszs = jszs + 2 * fxcsgs[3];
	  }
	  if( cyzcc == 1)
	  {
		  jszs = jszs + fxcsgs[4];
	  }
  
	  //参数变换及计算有关参数
	  tjingkou = tjingkou + 273.15;
	  tdiceng = tdiceng + 273.15;
	  H2S = H2S / 100;
	  CO2 = CO2 / 100;
	  N2 = N2 / 100;
	  LGR = LGR / 10000;
	  pdiceng = pdiceng;
	  DIT1 = DIT1 / 1000;
	  DIT2 = DIT2 / 1000;
	  DIC = DIC / 1000;
	  LC = ddcsd - DVT1 - DVT2;
	  TG = (tdiceng - tjingkou) / ddcsd;
	  //计算临界参数
      csjs.trqnjcs(GG, H2S, CO2,1);//临界参数
	  PC=csjs.Pc;//对比压力
	  TC=csjs.Tc;//对比温度

	  if(fabs(AF * BF) > 0)
	  {
		Qgmax = (-AF + pow((pow(AF,2) + 4 * BF * (pow(pdiceng,2) - pow(0.0101,2))),0.5)) / 2 / BF;
	  }
	  else if( Qtest * Ptest > 0)
	  {
		if( Qgmax <= 0)
		{
		  PD = (pow(pdiceng,2) - pow(Ptest,2)) / pow(pdiceng,2);
		  Qgmax1 = Qtest / (1.8 * PD - 0.8 * pow(PD,2));
		  Qgmax2 = 6 * Qtest / (pow((1 + 48 * PD),0.5) - 1);
		  Qgmax3 = Qtest / 1.0434 / pow(PD,0.6594);
		  Qgmax = (Qgmax1 + Qgmax2 + Qgmax3) / 3;
		}
		Qgmax = Qgmax;
		BF = ((pow(pdiceng,2) - pow(0.1,2)) / Qgmax - (pow(pdiceng,2) - pow(Ptest,2)) / QG) / (Qgmax - Qtest);
		AF = (pow(pdiceng,2) - pow(Ptest,2) - BF * pow(Qtest,2)) / Qtest;
	  }
	  else if( CF * NF > 0)
	  {
		Qgmax = CF * pow((pow(pdiceng,2) - pow(0.1,2)),NF);
	  }
	  else if( dcyxhd * qjggbjbj * jdbj * yxstl > 0)
	  {
		TR = tdiceng / TC;
		PR = pdiceng / PC;
        UG=csjs.trqnd(PR, TR, CO2, H2S, N2, GG, tdiceng-273.15);//天然气粘度  	
        Z=csjs.trqpcxs(PR, TR);//天然气偏差因子
		AF = 0.000127 * UG * Z * tdiceng * (log(qjggbjbj / jdbj) / log(10) + sbpxs) / yxstl / dcyxhd;
		BT = 76440000000 / pow(yxstl,1.5);
		BF = 2.3336*pow(10,(-21)) * BT * GG * tdiceng * Z * (1 / jdbj - 1 / qjggbjbj) / pow(dcyxhd,2);
		Qgmax = (-AF + pow((pow(AF,2) + 4 * BF * (pow(pdiceng,2) - pow(0.0101,2))),0.5)) / 2 / BF;
	  }
	  else
	  {
		AfxMessageBox("生产气井节点分析IPR参数错误,请更正后再计算!");
		return;
	  }
	  Qgmax = int(1000 * Qgmax);
	  Qgmax=Qgmax/ 1000;
	  njsds = 100;
	  qqlzz = int(1000 * Qgmax / njsds);
	  qqlzz=qqlzz/ 1000;
	  njsds = 1 + int(Qgmax / qqlzz);

		try
		{
			CString kg="\n";
			f3.WriteString(kg);
//			templs1=fileDialog2.GetFileTitle();
			templs1="\t\t$$节点分析计算结果$0\n";
			f3.WriteString(templs1);
		    f3.WriteString(kg);
		}
		catch (CFileException exception3)
		{
			AfxMessageBox("Error reading file");
			return;
		}

  
//	  bfblj = 5;
	  //主窗口.SSPanel1.FloodPercent = 3
	 //井口压力  
	  if( cjkyl == 1)
	  {
			try
			{
				templs1="$$井口压力分析[井底流压~产气量]\n";
				f4.WriteString(templs1);
				f4.WriteString("节点压力最小值,MPa:\n");
				f4.WriteString("节点压力最大值,MPa:\n");
				f4.WriteString("产气量最小值,10^4m^3/d:\n");
				f4.WriteString("产气量最大值,10^4m^3/d:\n");
				f4.WriteString("Pn\n");
				f4.WriteString("Qg\n");
				f4.WriteString("Pn__MPa\n");
				f4.WriteString("Qg__10^4m^3/d\n");
				f4.WriteString(" 1\n");
			}
			catch (CFileException exception4)
			{
				AfxMessageBox("Error reading file");
				return;
			}
			for(i=0;i<=10;i++)
			{
			   for(J=0;J<=njsds;J++)
			   {
        		  jieguo[i][J] = 0;
			   }
			}
			//流入关系计算
			BAC = 98 * fxcsgs[1] / jszs / (fxcsgs[1] + 1) / njsds;
			for(J=0;J<=njsds;J++)
			{
	//		  主窗口.SSPanel1.FloodPercent = Int(bfblj + 0.5 * BAC * (J + 1));
			  QG = int(1000 * qqlzz * J);
			  QG=QG/ 1000;
			  if( AF * BF > 0)
			  {
				PWF = pow(pdiceng,2) - AF * QG - BF * pow(QG,2);
			  }
			  else if( CF * NF > 0)
			  {
				PWF = pow(pdiceng,2) - pow((QG / CF),(1 / NF));
			  }
			  if( PWF > 0)
			  {
				PWF = int(1000 * pow(PWF,0.5));
				PWF=PWF/ 1000; //井底流压
				jieguo[0][J] = QG;
				jieguo[1][J] = PWF;

				gcvt(QG,30,temptp);
				templs1=temptp;
				gcvt(PWF,30,temptp1);
				templs2=temptp1;
				templs1=" "+templs1+"\t"+templs2+"\n";
				try
				{
					f4.WriteString(templs1);         
				}
				catch (CFileException exception4)
				{
					AfxMessageBox("Error reading file");
					return;
				}
			  }
			  else
			  {
				jieguo[0][J] = QG;
				jieguo[1][J] = 0;

				gcvt(Qgmax,30,temptp);
				templs1=temptp;
				gcvt(0,30,temptp1);
				templs2=temptp1;
				templs1=" "+templs1+"\t"+templs2+"\n";
				try
				{
					f4.WriteString(templs1);         
				}
				catch (CFileException exception4)
				{
					AfxMessageBox("Error reading file");
					return;
				}
				break;
			  }
			}
			try
			{
				f4.WriteString("-1\t -1\n");
			f4.WriteString(cGraphColor[iColorIndex++]);
			iColorIndex %= iGraphColorNum;
				f4.WriteString("IPR\n");
			}
			catch (CFileException exception4)
			{
				AfxMessageBox("Error reading file");
				return;
			}
	g_iProgress = 10;	// 计算进度
	ENDCOMPUTE;

			//流出关系计算
			for(i=1;i<=5;i++)
			{
				  pjingkou0 = canshu[1][i]; //分析的井口压力值
				  if( pjingkou0 == 0)
				  {
					  break;
				  }
				  for(J=0;J<=njsds;J++)
				  {
			/*		  	百分比 = Int(bfblj + BAC * ((i - 0.5) * njsds + J + 1));
						if( 主窗口.SSPanel1.FloodPercent < 百分比)
						{
							主窗口.SSPanel1.FloodPercent = 百分比;
						}*/
						QG = int(1000 * qqlzz * J);
						QG=QG/ 1000;
						qqiliang = QG * 10000;

						P1=qjyljsz.qjyl(pjingkou0, tjingkou, TG, DVT1, DIT1, 0, RR, qqiliang, GG, LGR, GL, H2S, N2, CO2, 0, 0, 1, 1);
						Tun = tjingkou + TG * DVT1;
						P2=qjyljsz.qjyl(P1, Tun, TG, DVT2, DIT2, 0, RR, qqiliang, GG, LGR, GL, H2S, N2, CO2, 0, 0, 1, 1);
						Tun = tjingkou + TG * (DVT1 + DVT2);
						P3=qjyljsz.qjyl(P2, Tun, TG, LC, DIC, 0, RR, qqiliang, GG, LGR, GL, H2S, N2, CO2, 0, 0, 1, 1);
						if( P3 > int(pdiceng / 10 + 0.999) * 10)
						{
							break;
						}
						gcvt(QG,30,temptp);
						templs1=temptp;
						gcvt(P3,30,temptp1);
						templs2=temptp1;
						templs1=" "+templs1+"\t"+templs2+"\n";
						try
						{
							f4.WriteString(templs1);         
						}
						catch (CFileException exception4)
						{
							AfxMessageBox("Error reading file");
							return;
						}
						jieguo[i + 1][J] = int(1000 * P3);
						jieguo[i + 1][J]=jieguo[i + 1][J]/ 1000;
				  }
				  try
				  {
						f4.WriteString("-1\t-1\n");
			f4.WriteString(cGraphColor[iColorIndex++]);
			iColorIndex %= iGraphColorNum;
						gcvt(canshu[1][i],30,temptp);
						templs1=temptp;
						templs1.TrimLeft();
						templs1.TrimRight();
						templs1="Ptf="+templs1+"(MPa)"+"\n";
						f4.WriteString(templs1);
				  }
				  catch (CFileException exception4)
				  {
						AfxMessageBox("Error reading file");
						return;
				  }
			}
			
			try
			{
			   f4.WriteString("-10\t-10\n");
			}
			catch (CFileException exception4)
			{
				AfxMessageBox("Error reading file");
				return;
			}
	g_iProgress = 25;	// 计算进度
	ENDCOMPUTE;
			
			//写入计算的数据结果
			templs1="\t\t";
			templs1=templs1+"  [井口压力分析]$0"+"\n";
			templs2=" 气 量$7";
			templs2=templs2+ "\t" + "井底流压$7" + "\t" + "    在下列井口压力下的节点压力,MPa$13" + "\t" + "$12" + "\t" + "$12" + "\t" + "$12" + "\t" + "$14"+"\n";
			try
			{
			   f3.WriteString(templs1);
			   f3.WriteString(templs2);
			}
			catch (CFileException exception3)
			{
				AfxMessageBox("Error reading file");
				return;
			}
			A="万方/天$11";
			A = A + "\t" + "  MPa$11";
			for(i=1;i<=5;i++)
			{
				gcvt(canshu[1][i],30,temptp);
				templs1=temptp;
				templs1.TrimLeft();
				templs1.TrimRight();
				A = A + "\t" + templs1;
			}
			A =A + "\n";
			try
			{
			   f3.WriteString(A);
			}
			catch (CFileException exception3)
			{
				AfxMessageBox("Error reading file");
				return;
			}
			for(J=0;J<=njsds;J++)
			{
			  if( J > 0 && (jieguo[0][J] == 0 || (jieguo[1][J] + jieguo[2][J] + jieguo[3][J] + jieguo[4][J] + jieguo[5][J] + jieguo[6][J]) == 0))
			  {
				  break;
			  }
			  for(i=0;i<=6;i++)
			  {
				gcvt(jieguo[i][J],30,temptp);
				templs1=temptp;
				templs1.TrimLeft();
				templs1.TrimRight();
		  		B = templs1;
				if( i ==0)
				{
					A = B;
				}
				else
				{
					A = A + "\t" + B;
				}
			  }
			  A=A+"\n";
			  try
			  {
				 f3.WriteString(A);
			  }
			  catch (CFileException exception3)
			  {
				 AfxMessageBox("Error reading file");
				 return;
			  }
			}
			A1 = "节点压力$13";

⌨️ 快捷键说明

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