本文主要是介绍水环境学——显式差分 计算均匀河段各断面BOD变化,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
#include "stdafx.h"
#include <iostream>
#include <fstream>
#include <iomanip>
#include <cmath>
void main()
{using namespace std;const int Nx = 8, //等于x/dxNt = 10;//等于t/dtconst double dx = 1.0, dt = 0.1, //要保证dt<=dx/u,E*dt<=dx*dx/2x = 8.0,//均匀河段长t = 1.0,//排污断面持续时间u = 5,//流速E = 2,//离散系数K1 = 0.015,//BOD降解系数C0 = 20;//排污断面持续时间内保持的BOD浓度double alpha = E*dt/pow(dx, 2),beta = u*dt/dx - 2*alpha - K1*dt,gamma = 1 - u*dt/dx + alpha, C[Nx + 2][Nt + 1] = {0};ofstream outfile;outfile.open("output.txt");outfile<<"alpha = "<<alpha<<endl<<"beta = "<<beta<<endl<<"gamma = "<<gamma<<endl;for(int i = 0; i < 2; i++)for(int j = 0; j<Nt + 1; j++)C[i][j] = C0;for(int i = 2; i < Nx + 2; i++)for(int j = 1; j<Nt + 1; j++)C[i][j] = alpha*C[i - 2][j - 1] +beta*C[i - 1][j - 1] + gamma*C[i][j - 1];for(int j = 0; j<Nt + 1; j++){for(int i = 1; i < Nx + 2; i++)outfile<<setw(10)<<C[i][j];outfile<<endl;}outfile.close();
}
这篇关于水环境学——显式差分 计算均匀河段各断面BOD变化的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!