// GibbsEquationSolve.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include "Data.h"
#include <vector>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <fstream>
#include <iostream>
using namespace std;
const double PI = 3.14159;
const int k = 144;
double C;
double W; //曲柄角速度
double Pr; //抽油杆密度
double A; //速度
double E; //钢杆弹性模量
double Ar; //抽油杆截面积
double EA;
double p; //液体粘度
double L; //抽油杆长度
double Dt;
double Dr;
double x;
int iCountT;
vector<double> vecD(DataDArray, DataDArray + 144);
vector<double> vecU(DataUArray, DataUArray + 144);
vector<double> vecOutputU;
vector<double> vecOutputF;
vector<int> vecT;
vector<double> Param1(11, 0.0);
vector<double> Param2(11, 0.0);
vector<double> Param3(11, 0.0);
vector<double> Param4(11, 0.0);
vector<double> vecA;
vector<double> vecB;
vector<double> vecK;
vector<double> vecP;
/*
double Param1[11];
double Param2[11];
double Param3[11];
double Param4[11];
double vecA[11];
double vecB[11];
double vecK[11];
double vecP[11];
*/
void ReadFile()
{
int i;
int temp;
fstream inStream("inputdata.txt", ios::in);
if (!inStream)
{
cout << "Error" << endl;
return;
}
if (!inStream.eof())
{
inStream >> Dt;
inStream >> Dr;
inStream >> Ar;
inStream >> p;
inStream >> L;
inStream >> Pr;
inStream >> W;
inStream >> A;
inStream >> E;
inStream >> iCountT;
inStream >> x;
for (i = 0; i != iCountT; ++i)
{
inStream >> temp;
vecT.push_back(temp);
}
}
EA = E * Ar;
inStream.close();
}
//
void WriteFile()
{
int i;
ofstream outStreamU("outputdataU.txt", ios::out | ios::app);
ofstream outStreamF("outputdataF.txt", ios::out | ios::app);
if (!outStreamU || !outStreamF)
{
cout << "Error!" << endl;
return;
}
/*
if (vecOutputF.empty() || vecOutputU.empty())
{
return;
}
*/
for (i = 0; i != vecOutputU.size(); ++i)
{
outStreamF << vecOutputF[i] << '\t';
outStreamU << vecOutputU[i] << '\t';
}
outStreamF.close();
outStreamU.close();
}
//Calculate Parameter C
void FuncCalcC()
{
double m = Dt / Dr;
double B1 = (pow(m, 2) - 1) / 2 / log(m) - 1;
double B2 = (pow(m, 4) - 1 - pow((pow(m, 2) - 1), 2)) / log(m);
C = 2 * PI * p / Pr / Ar * (1 / log(m) + 2 / B2 * (B1 + 1) * (B1 + 2 /
(W * L / A / sin(W * L / A) + cos(W * L / A))));
}
//Calculate Parameter σ
void CalcParam1()
{
Param1[0] = accumulate(vecD.begin(), vecD.end(), 0) * 2 / k;
for (int n = 1; n != 11; ++n)
{
double temp = 0.0;
for (int p = 1; p != k + 1; ++p)
{
temp += vecD[p-1] * cos(2 * n * PI * p / k);
}
Param1[n] = temp * 2 / k;
}
}
//Calculate Parameter τ
void CalcParam2()
{
for (int n = 1; n != 11; ++n)
{
for (int p = 1; p != k + 1; ++p)
{
Param2[n] += vecD[p-1] * sin(2 * n * PI * p / k);
}
Param2[n] = Param2[n] * 2 / k;
}
}
//Calculate Parameter ν
void CalcParam3()
{
Param3[0] = accumulate(vecU.begin(), vecU.end(), 0) * 2 / k;
for (int n = 1; n != 11; ++n)
{
for (int p = 1; p != k + 1; ++p)
{
Param3[n] += vecU[p-1] * cos(2 * n * PI * p / k);
}
Param3[n] = Param3[n] * 2 / k;
}
}
//Calculate Parameter δ
void CalcParam4()
{
for (int n = 1; n != 11; ++n)
{
for (int p = 1; p != k + 1; ++p)
{
Param4[n] += vecD[p-1] * sin(2 * n * PI * p / k);
}
Param4[n] = Param4[n] * 2 / k;
}
}
//Calculate Parameter α
void CalcParamA()
{
double tempA = 0.0;
vecA.push_back(tempA);
for (int n = 1; n != 11; ++n)
{
double temp = sqrt(1 + pow(C / n / W, 2));
tempA = n * W / A / sqrt(2.0) * sqrt(1 + temp);
vecA.push_back(tempA);
}
}
//Calculate Parameter β
void CalcParamB()
{
double tempB = 0.0;
vecB.push_back(tempB);
for (int n = 1; n != 11; ++n)
{
double temp = sqrt(1 + pow(C / n / W, 2));
tempB = n * W / A / sqrt(2.0) * sqrt(-1 + temp);
vecB.push_back(tempB);
}
}
//Calculate Parameter κand μ
void CalcParamKandParamP()
{
double tempK = 0.0;
vecK.push_back(tempK);
double tempP = 0.0;
vecP.push_back(tempP);
for (int n = 1; n != 11; ++n)
{
double temp = EA * (pow(vecA[n], 2) + pow(vecB[n], 2));
tempK = (Param1[n] * vecA[n] + Param2[n] * vecB[n]) / temp;
vecK.push_back(tempK);
tempP = (Param1[n] * vecB[n] - Param2[n] * vecA[n]) / temp;
vecP.push_back(tempP);
}
}
//
double FuncQ(const double &x, const int &n)
{
double temp;
temp = (vecK[n] * cosh(vecB[n] * x) + Param4[n] * sinh(vecB[n] * x)) * sin(vecA[n] * x) +
(vecP[n] * cosh(vecB[n] * x) + Param3[n] * cosh(vecB[n] * x)) * cos(vecA[n] * x);
return temp;
}
//
double FuncP(const double &x, const int &n)
{
double temp;
temp = (vecK[n] * cosh(vecB[n] * x) + Param4[n] * cosh(vecB[n] * x)) * cos(vecA[n] * x) +
(vecP[n] * cosh(vecB[n] * x) + Param3[n] * sinh(vecB[n] * x)) * sin(vecA[n] * x);
return temp;
}
//
double FuncDeriQ(const double &x, const int &n)
{
double temp;
temp = ((Param2[n] * sinh(vecB[n] * x) / EA) + (Param4[n] * vecB[n] - Param3[n] * vecA[n]) * cosh(vecB[n] * x)) * sin(vecA[n] * x) +
((Param4[n] * cosh(vecB[n] * x) / EA) + (Param3[n] * vecB[n] - Param4[n] * vecA[n]) * sinh(vecB[n] * x)) * cos(vecA[n] * x);
return temp;
}
//
double FuncDeriP(const double &x, const int &n)
{
double temp;
temp = ((Param2[n] * cosh(vecB[n] * x) / EA) + (Param4[n] * vecB[n] - Param3[n] * vecA[n]) * sinh(vecB[n] * x)) * cos(vecA[n] * x) +
((Param1[n] * sinh(vecB[n] * x) / EA) + (Param3[n] * vecB[n] - Param4[n] * vecA[n]) * cosh(vecB[n] * x)) * sin(vecA[n] * x);
return temp;
}
//U(x, t)
void FuncU(const double &x, const vector<int> &vecT)
{
for (int i = 0; i != vecT.size(); ++i)
{
double temp = 0.0;
double temp2;
for (int n = 1; n != 11; ++n)
{
temp += FuncQ(x, n) * cos(n * W * vecT[i]) + FuncP(x, n) * sin(n * W * vecT[i]);
}
temp2 = Param1[0] / (2 * EA) * x + Param3[0] / 2 + temp;
vecOutputU.push_back(temp2);
}
}
//F(x, t)
void FuncF(const double &x, const vector<int> &vecT)
{
for (int i = 0; i != vecT.size(); ++i)
{
double temp = 0.0;
double temp2;
for (int n = 1; n != 11; ++n)
{
temp += FuncDeriQ(x, n) * cos(n * W * vecT[i]) + FuncDeriP(x, n) * sin(n * W * vecT[i]);
}
temp2 = Param4[0] / 2 + EA * temp;
vecOutputF.push_back(temp2);
}
}
int _tmain(int argc, _TCHAR* argv[])
{/*
vector<int> vecT;
int iCountT;
int x;
int i = 0;
ifstream inStream("inputdataT.txt", ios::in);
if (!inStream)
{
cout << "Error!" << endl;
return -1;
}
cout << "this is " << endl;
inStream >> iCountT;
inStream >> x;
while (!inStream.eof() && i != iCountT)
{
inStream >> vecT[i];
++i;
}
inStream.close();
*/
ReadFile();
FuncCalcC();
CalcParam1();
CalcParam2();
CalcParam3();
CalcParam4();
CalcParamA();
CalcParamB();
CalcParamKandParamP();
FuncU(x, vecT);
FuncF(x, vecT);
WriteFile();
return 0;
}
inputdate.txt
0.07
0.022
0.00001042
30000
792.5
7850
0.7959
5172
210000000000
200
793
0.0000 0.0397 0.0793 0.1190 0.1587 0.1984 0.2380 0.2777 0.3174 0.3570 0.3967 0.4364 0.4761 0.5157 0.5554 0.5951 0.6347 0.6744 0.7141 0.7538 0.7934 0.8331 0.8728 0.9125 0.9521 0.9918 1.0315 1.0711 1.1108 1.1505 1.1902 1.2298 1.2695 1.3092 1.3488 1.3885 1.4282 1.4679 1.5075 1.5472 1.5869 1.6265 1.6662 1.7059 1.7456 1.7852 1.8249 1.8646 1.9042 1.9439 1.9836 2.0233 2.0629 2.1026 2.1423 2.1820 2.2216 2.2613 2.3010 2.3406 2.3803 2.4200 2.4597 2.4993 2.5390 2.5787 2.6183 2.6580 2.6977 2.7374 2.7770 2.8167 2.8564 2.8960 2.9357 2.9754 3.0151 3.0547 3.0944 3.1341 3.1737 3.2134 3.2531 3.2928 3.3324 3.3721 3.4118 3.4515 3.4911 3.5308 3.5705 3.6101 3.6498 3.6895 3.7292 3.7688 3.8085 3.8482 3.8878 3.9275 3.9672 4.0069 4.0465 4.0862 4.1259 4.1655 4.2052 4.2449 4.2846 4.3242 4.3639 4.4036 4.4432 4.4829 4.5226 4.5623 4.6019 4.6416 4.6813 4.7210 4.7606 4.8003 4.8400 4.8796 4.9193 4.9590 4.9987 5.0383 5.0780 5.1177 5.1573 5.1970 5.2367 5.2764 5.3160 5.3557 5.3954 5.4350 5.4747 5.5144 5.5541 5.5937 5.6334 5.6731 5.7127 5.7524 5.7921 5.8318 5.8714 5.9111 5.9508 5.9905 6.0301 6.0698 6.1095 6.1491 6.1888 6.2285 6.2682 6.3078 6.3475 6.3872 6.4268 6.4665 6.5062 6.5459 6.5855 6.6252 6.6649 6.7045 6.7442 6.7839 6.8236 6.8632 6.9029 6.9426 6.9822 7.0219 7.0616 7.1013 7.1409 7.1806 7.2203 7.2600 7.2996 7.3393 7.3790 7.4186 7.4583 7.4980 7.5377 7.5773 7.6170 7.6567 7.6963 7.7360 7.7757 7.8154 7.8550 7.8947
希望大家帮忙看一下哈?