|
73 | 73 |
|
74 | 74 | % Remove elements with zero atoms from the stoichiometric matrix A0 |
75 | 75 | A0 = A0(:, indexElements); |
| 76 | + A0_T = A0'; |
76 | 77 |
|
77 | 78 | % Update temp values |
78 | 79 | if ~isempty(indexRemoveSpecies) |
79 | 80 | [index, indexCondensed, indexGas, indexIons, NG, NS] = obj.updateTemp(N, indexRemoveSpecies, indexCondensed, indexGas, indexIons, NP, NG, NS, SIZE); |
80 | 81 | end |
81 | 82 |
|
| 83 | + % Remove ionized species below the configured temperature threshold |
| 84 | + if FLAG_E && ~isempty(indexIons) && T < obj.temperatureIons |
| 85 | + removeIons(); |
| 86 | + end |
| 87 | + |
82 | 88 | % Remove condensed species with temperature out of bounds |
83 | 89 | indexCondensed = system.filterSpeciesTemperatureRange(T, indexCondensed, NS - NG, false); |
84 | 90 |
|
|
106 | 112 | % Dimensionless chemical potential |
107 | 113 | muRT = g0RT; |
108 | 114 |
|
109 | | - % Construction of part of matrix J |
110 | | - A0_T = A0'; |
111 | | - |
112 | 115 | % Initialize composition matrix N [mol, FLAG_CONDENSED] |
113 | 116 | [N, NP] = obj.equilibriumGuess(N, NP, A0_T(:, index0), muRT(index0), NatomE, index0, indexGas_0, indexIons, NG, molesGuess); |
114 | 117 |
|
|
172 | 175 |
|
173 | 176 | % Check residual of charge balance |
174 | 177 | if max( [norm(J(ind_E, :), 1), norm(J(:, ind_E), 1), abs(b(ind_E))] ) < obj.tolE |
175 | | - % Remove element E from matrix |
176 | | - removeElementElectron(); |
| 178 | + % Remove ionized species and element E from matrix |
| 179 | + removeIons(); |
177 | 180 | continue |
178 | 181 | end |
179 | 182 |
|
|
253 | 256 | return |
254 | 257 | end |
255 | 258 |
|
256 | | - % Remove element E from matrix |
257 | | - removeElementElectron(); |
| 259 | + % Remove ionized species and element E from matrix |
| 260 | + removeIons(); |
258 | 261 |
|
259 | 262 | % Recompute chemical equilibrium without ions |
260 | 263 | x = equilibriumLoop; |
|
370 | 373 |
|
371 | 374 | end |
372 | 375 |
|
373 | | - function removeElementElectron() |
374 | | - % Remove element E from matrix |
375 | | - A0(:, ind_E) = []; A0_T(ind_E, :) = []; |
376 | | - indexIons = []; indexElements(ind_E) = []; |
377 | | - NatomE(ind_E) = []; |
378 | | - NE = NE - 1; |
| 376 | + function removeIons() |
| 377 | + % Remove ionized species and the electron element from the active set |
| 378 | + if ~isempty(indexIons) |
| 379 | + N(indexIons) = 0; |
| 380 | + indexGas(ismember(indexGas, indexIons)) = []; |
| 381 | + indexIons = []; |
| 382 | + end |
379 | 383 |
|
380 | | - % Update FLAG_E |
381 | | - FLAG_E = false; |
| 384 | + if FLAG_E |
| 385 | + A0(:, ind_E) = []; A0_T(ind_E, :) = []; |
| 386 | + indexElements(ind_E) = []; |
| 387 | + NatomE(ind_E) = []; |
| 388 | + NE = NE - 1; |
| 389 | + FLAG_E = false; |
| 390 | + end |
382 | 391 |
|
383 | | - % Update indeces |
384 | | - [~, indexCondensed, indexGas, indexIons, NG, NS] = obj.updateTemp(N, index, indexCondensed, indexGas, indexIons, NP, NG, NS, SIZE); |
| 392 | + index = [indexGas, indexCondensed]; |
| 393 | + NG = length(indexGas); |
| 394 | + NS = length(index); |
385 | 395 | end |
386 | 396 |
|
387 | 397 | end |
|
0 commit comments