#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<math.h>
#include<conio.h>
/*
@hey_超级巨星
*/
using namespace std;
#define R 8.314
//普维法求压强和体积 类
class puWei_PV
{
private :
 double T;//单位开尔文
 double V0;//钢瓶容积m3
 double P;//pa
 double g;//气体质量克
 double M;//相对分子质量M
 double Tc;//开尔文
 double Pc;//pa
 double Vc;//m3/mol
 double w;//因子
public:
 //构造函数
 //1.求压强重载
 puWei_PV(double T, double V0, double g, double M, double Tc, double Pc, double Vc, double w)
 {
  this->T = T;
  this->V0 = V0;
  this->g = g;
  this->M = M;
  this->Tc = Tc;
  this->Pc = Pc;
  this->Vc = Vc;
  this->w = w;
  puWei_P(T,V0,g,M,Tc,Pc,Vc,w);
 }
 //2.求体积重载
 puWei_PV(double T, double P, double M, double Tc, double Pc, double Vc, double w)
 {
  this->T = T;
  this->P = P;
  this->M = M;
  this->Tc = Tc;
  this->Pc = Pc;
  this->Vc = Vc;
  this->w = w;
  puWei_V(T,P,M,Tc,Pc,Vc,w);
 }
 //函数1:普维法求压强
 double puWei_P(double T, double V0, double g, double M, double Tc, double Pc, double Vc, double w);
 //函数2:普维法求体积
 double puWei_V(double T, double P, double M, double Tc, double Pc, double Vc, double w);
};
//*************************************
//函数1:普维法求压强
//依次输入开尔文温度,体积m3,质量g克,相对分子质量M,Tc,Pc(pa),Vc(立方米/mol),w
double puWei_PV::puWei_P(double T,double V0,double g,double M,double Tc,double Pc,double Vc,double w)
{
 //计算Tr
 double Tr;
 Tr = T / Tc;
 //计算B0,B'
 double Bo = 0.083 - (0.422 / (pow(Tr, 1.6)));
 double B1 = 0.139 - (0.172 / (pow(Tr, 4.2)));
 //带入数群求B
 double B;
 B = ((R * Tc) / Pc) * (Bo + (w * B1));
 //求V
 double V = (V0 / (g / M));
 //求Vr
 double Vr = (V / Vc);
 //求压强
 double P;
 P = (R * T) / (V - B);
 //显示求解过程
 cout << "Vr="<<Vr << endl;
 cout << "Bo = "<< Bo << endl;
 cout <<"B'="<< B1 << endl;
 cout <<"B="<< B <<"m3/mol"<< endl;
 cout << "P="<<P <<"pa" << endl;
 return P;
}
//函数2:普维法求体积
//依次输入开尔文温度,压强(pa),相对分子质量M,Tc,Pc(pa),Vc(立方米/mol),w
double puWei_PV::puWei_V(double T, double P, double M, double Tc, double Pc, double Vc, double w)
{
 //计算Tr
 double Tr;
 Tr = T / Tc;
 //计算B0,B'
 double Bo = 0.083 - (0.422 / (pow(Tr, 1.6)));
 double B1 = 0.139 - (0.172 / (pow(Tr, 4.2)));
 //带入数群求B
 double B;
 B = ((R * Tc) / Pc) * (Bo + (w * B1));
 //求V
 double V = (((R * T) / P) + B);
 //求Vr
 double Vr = (V / Vc);
 //显示求解过程
 cout<<"假设Vr>=2"<<endl;
 cout << "Vr=" << Vr << endl;
 cout << "Bo = " << Bo << endl;
 cout << "B'=" << B1 << endl;
 cout << "B=" << B << "m3/mol" << endl;
 cout << "V=" << V << "m3/mol" << endl;
 return V;
}
//状态方程和普维法求Hr 和Sr
class calculate_H_S
{
private:
 double T;//开尔文
 double P;//pa
 double Tc;//开尔文
 double Pc;//pa
 double Bo;
 double B1;
 double w;
 double Cp;//J/mol/K
 double T1;//开尔文
 double T2;//开尔文
 double P1;//pa
 double P2;//pa
public:
 //构造函数求Sr Hr
 calculate_H_S(){};
 calculate_H_S(double Tc, double Pc, double w, double T1, double T2, double Cp, double P1, double P2)
 {
  this->T1 = T1;
  this->T2 = T2;
  this->Cp = Cp;
  this->P1 = P1;
  this->P2 = P2;
  this->Tc = Tc;
  this->Pc = Pc;
  this->w = w;
  //puWei(T1,Tc,Pc,P1,w);
  //ideal_H_S(T1, T2, Cp, P1, P2);
  //puWei(T2, Tc, Pc, P2, w);
 }
 //普维法求焓变熵变
 void puWei(double T, double Tc, double Pc, double P, double w);
 //求理想焓变 熵变
 void ideal_H_S(double T1, double T2, double Cp, double P1, double P2);
};
void calculate_H_S::puWei(double T,double Tc,double Pc,double P,double w)
{
 //求Pr
 double Pr = P / Pc;
 //计算Tr
 double Tr;
 Tr = T / Tc;
 //计算B0,B'
 double Bo = 0.083 - (0.422 / (pow(Tr, 1.6)));
 double B1 = 0.139 - (0.172 / (pow(Tr, 4.2)));
 //计算 dBo/dTr(Rate0) 与dB1/dTr(Rate1)
 double Rate0, Rate1;
 Rate0 = (0.675 / (pow(Tr, 2.6)));
 Rate1 = (0.722/ (pow(Tr, 5.2)));
 //公式计算
 //Hr
 double HR = ((((-1) * Pr) * Tr) * ((Rate0 - (Bo / Tr)+(w*(Rate1-(B1/Tr))))))*(R*Tc);
 //Sr
 double SR = (((-1)*Pr)*(Rate0+(w*Rate1))) * R;
 //输出
 cout<<"*********************************"<<endl;
 cout << "从真实" << T << "K," << P << "pa到理想的焓变熵变" << endl;
 cout << "Bo = " << Bo << endl;
 cout << "B'=" << B1 << endl;
 cout << "Tr=" << Tr << endl;
 cout << "Pr=" << Pr << endl;
 cout << "焓变H^R=" << HR<<"J/mol" << endl;
 cout << "熵变S^R=" << SR <<"J/mol·K"<< endl;
}
void calculate_H_S::ideal_H_S(double T1,double T2,double Cp,double P1,double P2)
{
 //求H*
 double Hid = (Cp*4.18)*(T2 - T1);
 //求S*
 double Sid = (log((T2 / T1))-(R*((log(P2/P1)))));
 cout << "*************************************" << endl;
 cout <<"从"<<T1<<"K,"<<P1<<"pa到"<<T2<< "K," << P2<< "pa的理想焓变熵变" << endl;
 cout << "H*=" << Hid << "J/mol" << endl;
 cout << "S*=" << Sid << "J/mol·k" << endl;
}
//函数3 普维法求逸度和逸度系数、
class puWei_fugacity
{
private:
 double T;//开尔文
 double P;//pa
 double Tc;//开尔文
 double Pc;//pa
 double Bo;
 double B1;
 double w;
public:
 //构造函数
 puWei_fugacity() {};
 puWei_fugacity(double T,double P,double Tc,double Pc,double w)
 {
  this->T = T;
  this->P = P;
  this->Tc = Tc;
  this->Pc = Pc;
  this->w = w;
 }
 void calculate_f(double T, double P, double Tc, double Pc, double w);
};
//依次输入 T(K),P(pa),Tc(K),Pc(pa),w
void puWei_fugacity::calculate_f(double T, double P, double Tc, double Pc, double w)
{
 //求Pr
 double Pr = P / Pc;
 //计算Tr
 double Tr;
 Tr = T / Tc;
 //计算B0,B'
 double Bo = 0.083 - (0.422 / (pow(Tr, 1.6)));
 double B1 = 0.139 - (0.172 / (pow(Tr, 4.2)));
 //设lnQ=u(Q用来表示逸度系数表示)
 double u = ((Pr / Tr) * (Bo + (w*B1)));
 //求逸度系数
 double Q = exp(u);
 //求逸度f
 double f = (P * Q)/1000000;
 //输出
 cout << "****************普维法求逸度和逸度系数****************"<< endl;
 cout << "Vr>=2" << endl;
 cout <<"Pr="<< Pr << endl;
 cout <<"Tr=" <<Tr << endl;
 cout << "Bo="<<Bo << endl;
 cout << "B'="<<B1 << endl;
 cout << "lnΦ=" << u << endl;
 cout << "Φ=" << Q << endl;
 cout << "f=" << f <<"Mpa"<< endl;
}
//交互
class interact
{
private:
 double V0;//钢瓶容积m3
 double P;//pa
 double g;//气体质量克
 double M;//相对分子质量M
 double Tc;//开尔文
 double Pc;//pa
 double Vc;//m3/mol
 double T;//开尔文
 double Bo;
 double B1;
 double w;
 double Cp;//J/mol/K
 double T1;//开尔文
 double T2;//开尔文
 double P1;//pa
 double P2;//pa
public:
 int a;
 void interaction()
 {
  //普维法求压强
  //普维法求体积
  //普维法求剩余函数 Hr Sr
  //普维法求逸度和逸度系数
  while (1)
  {
   fflush(stdin);
   printf("****************你想使用下列哪种函数******************\n");
   printf("普维法求压力请按1\n普维法求体积请按2\n普维法求剩余函数 Hr Sr请按3\n普维法求逸度和逸度系数请按4\n请输入数字然后按回车\n");
   cin >> a;
   switch (a)
   {
   case 1:
    //double puWei_P(double T, double V0, double g, double M, double Tc, double Pc, double Vc, double w);
    //依次输入开尔文温度,体积m3,质量g克,相对分子质量M,Tc,Pc(pa),Vc(立方米/mol),w
    system("cls");
    printf("********************欢迎进入普维法求压力*******************\n\a");
    printf("请注意规定输入单位(输入完毕按回车)\n\n\n");
    cout << "请输入温度(单位K)" << endl;
    cin >> T;
    cout << "请输入体积(单位m3)" << endl;
    cin >> V0;
    cout << "请输入质量(单位 克)" << endl;
    cin >> g;
    cout << "请输入相对分子质量(单位 M)" << endl;
    cin >> M;
    cout << "请输入Tc(单位K)" << endl;
    cin >> Tc;
    cout << "请输入Pc(单位pa)" << endl;
    cin >> Pc;
    cout << "请输入Vc(单位m3/mol)" << endl;
    cin >> Vc;
    cout << "请输入w" << endl;
    cin >> w;
    {
     puWei_PV puwei1(T, V0, g, M, Tc, Pc, Vc, w);
    }
    getchar();
    printf("\n\n\n按任意键返回\n");
    getchar();
    system("cls");
    break;
   case 2:
    //函数2:普维法求体积
                //依次输入开尔文温度,压强(pa),相对分子质量M,Tc,Pc(pa),Vc(立方米/mol),w
    //double puWei_PV::puWei_V(double T, double P, double M, double Tc, double Pc, double Vc, double w)
    system("cls");
    printf("********************欢迎进入普维法求体积*******************\n\a");
    printf("请注意规定输入单位(输入完毕按回车)\n\n\n");
    cout << "请输入温度(单位K)" << endl;
    cin >> T;
    cout << "请输入压强(单位pa)" << endl;
    cin >> P;
    cout << "请输入相对分子质量(单位 M)" << endl;
    cin >> M;
    cout << "请输入Tc(单位K)" << endl;
    cin >> Tc;
    cout << "请输入Pc(单位pa)" << endl;
    cin >> Pc;
    cout << "请输入Vc(单位m3/mol)" << endl;
    cin >> Vc;
    cout << "请输入w" << endl;
    cin >> w;
    {
     puWei_PV puwei2(T, P, M, Tc, Pc, Vc, w);
    }
    getchar();
    printf("\n\n\n按任意键返回\n");
    getchar();
    system("cls");
    break;
   case 3:
    system("cls");
    printf("********************欢迎进入普维法求剩余性质*******************\n\a");
    printf("注意此函数只适用于无相变化 从真实->理想->理想->真实 四态\n");
    printf("如果想要计算有相变化 请自行计算相变部分 然后带入此函数\n");
    printf("如果初始态为理想气体,正常带入此函数,忽略结果显示的第一部分生成的H1 S1即可\n");
    printf("如果题目给的Cp为函数形式,请自行计算中间理想态,使用软件时随便输入一个Cp即可,然后忽略此软件生成的中间理想态\n");
    printf("请注意规定输入单位(输入完毕按回车)\n\n\n");
    cout << "请输入初始温度(单位K)" << endl;
    cin >> T1;
    cout << "请输入末温(单位K)" << endl;
    cin >> T2;
    cout << "请输入初始压强(单位pa)" << endl;
    cin >> P1;
    cout << "请输入末压强(单位pa)" << endl;
    cin >> P2;
    cout << "请输入Cp(单位cal/mol·K)" << endl;
    cin >> Cp;
    cout << "请输入Tc(单位K)" << endl;
    cin >> Tc;
    cout << "请输入Pc(单位pa)" << endl;
    cin >> Pc;
    cout << "请输入w" << endl;
    cin >> w;
    {
     calculate_H_S HS;
     HS.puWei(T1, Tc, Pc, P1, w);
     HS.ideal_H_S(T1, T2, Cp, P1, P2);
     HS.puWei(T2, Tc, Pc, P2, w);
    }
    getchar();
    printf("\n\n\n按任意键返回\n");
    getchar();
    system("cls");
    break;
   case 4:
    system("cls");
    printf("********************欢迎进入普维法求逸度逸度系数*******************\n\a");
    printf("请注意规定输入单位(输入完毕按回车)\n\n\n");
    cout << "请输入温度(单位K)" << endl;
    cin >> T;
    cout << "请输入压强(单位pa)" << endl;
    cin >> P;
    cout << "请输入Tc(单位K)" << endl;
    cin >> Tc;
    cout << "请输入Pc(单位pa)" << endl;
    cin >> Pc;
    cout << "请输入w" << endl;
    cin >> w;
    {
     puWei_fugacity F;
     F.calculate_f(T, P, Tc, Pc, w);
    }
    getchar();
    printf("\n\n\n按任意键返回\n");
    getchar();
    system("cls");
    break;
   }
  }
  }
};
int main()
{
 //测试
 //puWei_PV puwei1(755.15,0.02832,454,18,647.1,217.6,0.000056,0.348);
 //puWei_PV puwei2(673, 4053000, 16, 190.6, 4600000, 0.0000992, 0.008);
 //calculate_H_S* A = new calculate_H_S();
 //puWei_fugacity f1;
 //f1.calculate_f(323.15,500000,282.4,5040000,0.089);
 interact inta;
 inta.interaction();
 return 0;
}

Python算化工热力学 化工热力学软件_数学建模