各位前辈好!
本人最近在做一个关于输气管网计算界面的项目,要用到Flex与java通信。我在java里面定义了static变量,然后在flex里面向java传值(传的值有数组类型,也有double类型),然后在java里面实现计算并返回(能不能返回数组?如何做到?在flex里输入到什么组件比较好?)到flex。现在我经过测试发现传值的过程没什么问题,但是返回到flex里老出问题,百思不得其解,请求各位援助。
下面是我的调用的java类:
(注:程序运行没有什么问题的,只是没法被flex调用返回值,我是想调用Final()或者calculation()来返回getP()等)
package danxiang;
import java.sql.ResultSet;
import com.sun.xml.internal.bind.v2.schemagen.xmlschema.List;
import domain.Model;
import domain.Result;
import flex.messaging.io.ArrayList;
public class SectionCalculationwj {
static double d[];
static int start[];
public static double deta ;
public static double Z;
static int end[];
static double l[];
static double qq[];
static double Q0[];
static double section[];
public static int point;
public static int ss;
static double P0[] ;
static double T0[];
public static double Th ;
static double K[] ;
public static double rog ;
public static double cpg ;
public static double Di;
//下面这一部分是在flex里面调用的,从flex里面往这传值
public String initiateqq(double init[])
{
qq=init;
return "qq";
}
public String initiatepoint(int i)
{
point=i;
return "point";
}
public String initiateSection(double init[])
{
section=init;
return "section";
}
public String initiateStart(int init[])
{
start=init;
return "start";
}
public String initiateEnd(int init[])
{
end=init;
return "end::"+end[1];
}
public String initiated(double init[])
{
d=init;
return "D:::"+d[1];
}
public String initiatel(double init[])
{
l=init;
return "L:::"+l[1];
}
public String initiateT0(double init[])
{
T0=init;
return "T0";
}
public String initiateQ0(double init[])
{
Q0=init;
return "Q0";
}
public String initiateP(double init[])
{
P0=init;
return "P0";
}
public String initiateK(double init[])
{
K=init;
return "K";
}
public double initiatedeta(double DETA)
{
deta=DETA;
return deta;
}
public double initiatess(int S)
{
ss=S;
return ss;
}
public double initiaterog(double ROG)
{
rog=ROG;
return rog;
}
public double initiatecpg(double C)
{
cpg=C;
return cpg;
}
public double initiateDi(double di)
{
Di=di;
return Di;
}
public double initiateTh(double th)
{
Th=th;
return Th;
}
public double initiateZ(double zz)
{
Z=zz;
return Z;
}
//
//
//下面是我希望调用的,并返回到flex里面。。
// public String Final() {
// SectionCalculationwj aa = new SectionCalculationwj();
// aa.calculation();
// return "Hello,成功了!";
//
// }
public double[] calculation() {
int step = 0;
Result result = new Result();
//第一步,取初值
Model model = getInitValue();
//节点数
int n = model.getPoint();
//管道数
int m = model.getSection().length;
//计算出A,Azz
result.setA(A(model));
result.setAzz(Azz(result.getA()));
result.setP(model.getP0());
result.setAverageP(averageP(model, result));
double condition;
result.setQx(model.getQ0());
result.setT(model.getT0());
result.setBw(bw(result));
do {
result.setSj(Sj(model, result));
double[] tempQ = {};
//算AGA之前先求出G
result.setG(G(result.getSj(), result.getQx()));
result.setAGA(AGA(result));
fenkuai kf = new fenkuai();
result.setP(kf.fk(result.getAGA(), model.getSs(), result.getP(), model.getQq()));
result.setAverageP(averageP(model, result));
result.setDetap(detap(result));
tempQ = Qnew(result);
condition = condition(tempQ, result.getQx());
for (int k = 0; k < tempQ.length; k++) {
tempQ[k] = (result.getQx()[k] + tempQ[k]) / 2;
}
result.setQx(tempQ);
// 温降 水
result.setAa(aa(model, result));
result.setT(resetT(model, result));
// 水的析出
result.setBw(bw(result));
result.setDetabw(detabw(model,result));
step += 1;
} while (condition > 0.001);
System.out.println(step);
for (int i = 0; i < 12; i++) {
System.out.println("" + result.getP()[i]);
}
for (int i = 0; i < 12; i++) {
System.out.println("" + result.getT()[i]);
}
for (int i = 0; i < 11; i++) {
System.out.println("" + result.getDetabw()[i]);
}
return result.getP();
}
public double[][] A(Model model) {
int[] start = model.getStart();
int[] end = model.getEnd();
double[] section = model.getSection();
int n = model.getPoint();
int m = section.length;
double[][] A = new double[n][m];
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
if (i + 1 == start[j]) {
A[i][j] = -1;
}
if (i + 1 == end[j]) {
A[i][j] = 1;
} else if (i + 1 != start[j] && i + 1 != end[j]) {
A[i][j] = 0;
}
}
}
return A;
}
//将A矩阵转置
public double[][] Azz(double[][] A) {
int n = A.length;
int m = A[0].length;
double[][] Azz = new double[m][n];
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
Azz[j][i] = A[i][j];
}
}
return Azz;
}
// 计算Sj
public double[] Sj(Model model, Result result) {
double[] section = model.getSection();
double[] D = model.getD();
double[] L = model.getL();
double[] T = result.getT();
double deta = model.getDeta();
double Z = model.getZ();
double[] averageP = result.getAverageP();
//第一步,计算lam的值
int m = section.length;
double[] lam = new double[m];
double[] Sj = new double[m];
for (int i = 0; i < m; i++) {
lam[i] = 0.009407 / Math.pow(D[i], (1.0 / 3));
}
//第二步,计算Sj
for (int i = 0; i < m; i++) {
Sj[i] = -675.3515 * lam[i] * deta * Z * T[i] * L[i] / Math.pow(D[i], 5) / (2 * averageP[i]);
}
return Sj;
}
// 计算G
public double[][] G(double[] Sj, double[] Q) {
int m = Sj.length;
double[][] G = new double[m][m];
for (int i = 0; i < m; i++) {
for (int j = 0; j < m; j++) {
if (i == j) {
G[i][j] = 1 / Sj[i] / Math.abs(Q[i]);
} else {
G[i][j] = 0;
}
}
}
return G;
}
//计算AGA
public double[][] AGA(Result result) {
double[][] G = result.getG();
double[][] A = result.getA();
double[][] Azz = result.getAzz();
int n = A.length;
int m = A[0].length;
double AG[][] = new double[n][m];
double AGA[][] = new double[n][n];
for (int i = 0; i < A.length; i++) {
for (int j = 0; j < G[0].length; j++) {
for (int k = 0; k < G.length; k++) {
AG[i][j] += A[i][k] * G[k][j];
}
}
}
for (int i = 0; i < AG.length; i++) {
for (int j = 0; j < Azz[0].length; j++) {
for (int k = 0; k < Azz.length; k++) {
AGA[i][j] += AG[i][k] * Azz[k][j];
}
}
}
return AGA;
}
public double[] detap(Result result) {
double[][] Azz = result.getAzz();
double[] p = result.getP();
int m = Azz.length;
int n = Azz[0].length;
double[] detap = new double[m];
//计算压力降
for (int i = 0; i < m; i++) {
for (int j = 0; j < n; j++) {
detap[i] += Azz[i][j] * p[j];
}
}
return detap;
}
public double[] averageP(Model model, Result result) {
double[] P = result.getP();
int[] start = model.getStart();
int[] end = model.getEnd();
int m = start.length;
double[] averageP = new double[m];
for (int j = 0; j < m; j++) {
averageP[j] = 0.5 * (P[start[j] - 1] + P[end[j] - 1]);
}
return averageP;
}
public double[] Qnew(Result result) {
//计算新流量
double[][] G = result.getG();
double[] detap = result.getDetap();
int m = G.length;
double[] Qnew = new double[m];
for (int i = 0; i < m; i++) {
for (int j = 0; j < m; j++) {
Qnew[i] += G[i][j] * detap[j];
}
}
return Qnew;
}
public double condition(double[] tempQ, double[] Q) {
int m = tempQ.length;
double condition = 0.0;
for (int i = 0; i < m; i++) {
condition += Math.pow((tempQ[i] - Q[i]), 2);
}
condition = Math.pow(condition, 0.5);
return condition;
}
//单相温降计算
public double[] aa(Model model, Result result) {
double[] Q = result.getQx();
double[] D = model.getD();
double[] K = model.getK();
double rog = model.getRog();
double cpg = model.getCpg();
double[] bw=result.getBw();
int m = Q.length;
double[] aa = new double[m];
for (int i = 0; i < m; i++) {
aa[i] = K[i] * Math.PI * D[i] / ((rog+bw[i]) * Q[i] * cpg )/1000000;
}
return aa;
}
public double[] resetT(Model model, Result result) {
double Th = model.getTh();
int[] start = model.getStart();
int[] end = model.getEnd();
double[] T = result.getT();
double[] aa = result.getAa();
double[] l = model.getL();
double Di = model.getDi();
double[] detap = result.getDetap();
int m = aa.length;
for (int i = 0; i < m; i++) {
T[end[i] - 1] = Th + ((T[start[i] - 1]) - Th) * Math.exp(-aa[i] * l[i]) + Di * detap[i] / 1000000 * (1 - Math.exp(-aa[i] * l[i])) / aa[i] / l[i];
}
return T;
}
//饱和水的计算kg/m3直接加在气体密度上
public double[] bw(Result result) {
double[] T = result.getT();
double[] P=result.getP();
int m = P.length;
double[] pb=new double[m];//饱和蒸汽压
double[] bw = new double[m];
// y = 0.06233 x3 + 0.60057 x2 + 46.27664 x + 643.34653 xOC,ypa
for (int j = 0; j < m; j++) {
pb[j] = 0.06233*Math.pow(T[j]-273.15,3)+0.60057*Math.pow(T[j]-273.15,2)+46.27664*(T[j]-273.15)+643.34653;
bw[j]=803*pb[j]/(P[j]-pb[j])*0.001;
}
return bw;
}
//起终点水量变化计算 >0进水,<0析出水 单位kg
public double[] detabw(Model model,Result result) {
double[] bw = result.getBw();
int[] start=model.getStart();
int[] end=model.getEnd();
double[]d=model.getD();
double[]L=model.getL();
int m = start.length;
double[] detabw = new double[m];
for (int j = 0; j < m; j++) {
detabw[j] = (bw[end[j]-1] - bw[start[j]-1])*(Math.PI*Math.pow(d[j], 2)/4)*L[j];
}
return detabw;
}
}