alpha1[1][i] = pdeData2.getAlpha(0, x);
beta1[1][i] = pdeData2.getBeta(0, x);
}
final boolean first = true;
DecompositionResult decompRes = null;
for (int n = 1; n < tNodes; n++) {
t1 = grid.getTimeNode(n - 1);
t2 = grid.getTimeNode(n);
dt = grid.getTimeStep(n - 1);
for (int i = 0; i < xNodes; i++) {
x = grid.getSpaceNode(i);
alpha2[0][i] = pdeData1.getAlpha(t2, x);
beta2[0][i] = pdeData1.getBeta(t2, x);
alpha2[1][i] = pdeData2.getAlpha(t2, x);
beta2[1][i] = pdeData2.getBeta(t2, x);
}
for (int i = 1; i < xNodes - 1; i++) {
x = grid.getSpaceNode(i);
x1st = grid.getFirstDerivativeCoefficients(i);
x2nd = grid.getSecondDerivativeCoefficients(i);
q[i] = f[i];
q[i] -= (1 - theta) * dt * (x2nd[0] * a1[0][i - 1] * alpha1[0][i - 1] + x1st[0] * b1[0][i - 1] * beta1[0][i - 1]) * f[i - 1];
q[i] -= (1 - theta) * dt * (x2nd[1] * a1[0][i - 1] * alpha1[0][i] + x1st[1] * b1[0][i - 1] * beta1[0][i] + c1[0][i - 1]) * f[i];
q[i] -= (1 - theta) * dt * (x2nd[2] * a1[0][i - 1] * alpha1[0][i + 1] + x1st[2] * b1[0][i - 1] * beta1[0][i + 1]) * f[i + 1];
q[i] -= (1 - theta) * dt * lambda1 * f[i + xNodes];
q[xNodes + i] = f[xNodes + i];
q[xNodes + i] -= (1 - theta) * dt * (x2nd[0] * a1[1][i - 1] * alpha1[1][i - 1] + x1st[0] * b1[1][i - 1] * beta1[1][i - 1]) * f[xNodes + i - 1];
q[xNodes + i] -= (1 - theta) * dt * (x2nd[1] * a1[1][i - 1] * alpha1[1][i] + x1st[1] * b1[1][i - 1] * beta1[1][i] + c1[1][i - 1]) * f[xNodes + i];
q[xNodes + i] -= (1 - theta) * dt * (x2nd[2] * a1[1][i - 1] * alpha1[1][i + 1] + x1st[2] * b1[1][i - 1] * beta1[1][i + 1]) * f[xNodes + i + 1];
q[xNodes + i] -= (1 - theta) * dt * lambda2 * f[i];
a2[0][i - 1] = pdeData1.getA(t2, x);
b2[0][i - 1] = pdeData1.getB(t2, x);
c2[0][i - 1] = pdeData1.getC(t2, x);
a2[1][i - 1] = pdeData2.getA(t2, x);
b2[1][i - 1] = pdeData2.getB(t2, x);
c2[1][i - 1] = pdeData2.getC(t2, x);
m[i][i - 1] = theta * dt * (x2nd[0] * a2[0][i - 1] * alpha2[0][i - 1] + x1st[0] * b2[0][i - 1] * beta2[0][i - 1]);
m[i][i] = 1 + theta * dt * (x2nd[1] * a2[0][i - 1] * alpha2[0][i] + x1st[1] * b2[0][i - 1] * beta2[0][i] + c2[0][i - 1]);
m[i][i + 1] = theta * dt * (x2nd[2] * a2[0][i - 1] * alpha2[0][i + 1] + x1st[2] * b2[0][i - 1] * beta2[0][i + 1]);
m[i][i + xNodes] = dt * theta * lambda1;
m[xNodes + i][xNodes + i - 1] = theta * dt * (x2nd[0] * a2[1][i - 1] * alpha2[1][i - 1] + x1st[0] * b2[1][i - 1] * beta2[1][i - 1]);
m[xNodes + i][xNodes + i] = 1 + theta * dt * (x2nd[1] * a2[1][i - 1] * alpha2[1][i] + x1st[1] * b2[1][i - 1] * beta2[1][i] + c2[1][i - 1]);
m[xNodes + i][xNodes + i + 1] = theta * dt * (x2nd[2] * a2[1][i - 1] * alpha2[1][i + 1] + x1st[2] * b2[1][i - 1] * beta2[1][i + 1]);
m[xNodes + i][i] = dt * theta * lambda2;
}
double[] temp = lowerBoundary1.getLeftMatrixCondition(null, grid, t2);
for (int k = 0; k < temp.length; k++) {
m[0][k] = temp[k];
}
temp = upperBoundary1.getLeftMatrixCondition(null, grid, t2);
for (int k = 0; k < temp.length; k++) {
m[xNodes - 1][xNodes - temp.length + k] = temp[k];
}
temp = lowerBoundary2.getLeftMatrixCondition(null, grid, t2);
for (int k = 0; k < temp.length; k++) {
m[xNodes][xNodes + k] = temp[k];
}
temp = upperBoundary2.getLeftMatrixCondition(null, grid, t2);
for (int k = 0; k < temp.length; k++) {
m[2 * xNodes - 1][2 * xNodes - temp.length + k] = temp[k];
}
temp = lowerBoundary1.getRightMatrixCondition(null, grid, t1);
double sum = 0;
for (int k = 0; k < temp.length; k++) {
sum += temp[k] * f[k];
}
q[0] = sum + lowerBoundary1.getConstant(null, t2);
temp = upperBoundary1.getRightMatrixCondition(null, grid, t1);
sum = 0;
for (int k = 0; k < temp.length; k++) {
sum += temp[k] * f[xNodes - 1 - k];
}
q[xNodes - 1] = sum + upperBoundary1.getConstant(null, t2);
temp = lowerBoundary2.getRightMatrixCondition(null, grid, t1);
sum = 0;
for (int k = 0; k < temp.length; k++) {
sum += temp[k] * f[k];
}
q[xNodes] = sum + lowerBoundary2.getConstant(null, t2);
temp = upperBoundary2.getRightMatrixCondition(null, grid, t1);
sum = 0;
for (int k = 0; k < temp.length; k++) {
sum += temp[k] * f[xNodes - 1 - k];
}
q[2 * xNodes - 1] = sum + upperBoundary2.getConstant(null, t2);
if (first) {
final DoubleMatrix2D mM = new DoubleMatrix2D(m);
decompRes = dcomp.evaluate(mM);
// first = false;
}
f = decompRes.solve(q);
a1[0] = Arrays.copyOf(a2[0], xNodes - 2);
b1[0] = Arrays.copyOf(b2[0], xNodes - 2);
c1[0] = Arrays.copyOf(c2[0], xNodes - 2);
alpha1[0] = Arrays.copyOf(alpha2[0], xNodes);