Skip to content

Commit 2f5eb1b

Browse files
committed
Scaling introduced to construct A-matrix of linear equation system to improve numerics
1 parent 8ca09e0 commit 2f5eb1b

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

src/EquationAndStateInfo.jl

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -301,29 +301,29 @@ function LinearEquationsIteration(leq::LinearEquations{FloatType}, isInitial::Bo
301301
b[i] = -residuals[i]
302302
end
303303
leq.mode = 1
304-
x[1] = convert(FloatType, 1)
304+
x[1] = max(FloatType(1e-3), abs(b[1])) #convert(FloatType, 1)
305305
return true
306306
end
307307

308-
# residuals = A*x - b -> A[:,j] = residuals + b)
309-
j = mode
308+
# residuals = A*e_j*x_j - b -> A[:,j] = (residuals + b)/x[j]
309+
j = mode
310310
for i = 1:nx
311-
A[i,j] = residuals[i] + b[i]
312-
end
311+
A[i,j] = (residuals[i] + b[i])/x[j]
312+
end
313313
x[j] = 0
314314

315315
if j < nx
316316
leq.mode += 1
317-
x[leq.mode] = convert(FloatType, 1)
317+
x[leq.mode] = max(FloatType(1e-3), abs(b[leq.mode])) # convert(FloatType, 1)
318318
return true
319319
end
320320

321321
# Solve linear equation system
322-
if nx == 1
322+
if nx == 1
323323
x[1] = b[1]/A[1,1]
324324
if !isfinite(x[1])
325325
error("Linear scalar equation system is singular resulting in: ", leq.vTear_names[1], " = ", x[1])
326-
end
326+
end
327327
else
328328
x .= b
329329
if leq.useRecursiveFactorization

0 commit comments

Comments
 (0)