19 static int basisOptMax1(
const double *
const molNum,
23 for (
int i = 0; i < n; ++i) {
25 if (molNum[i] > -1.0E200 && fabs(molNum[i]) > 1.0E-13) {
29 for (
int i = 0; i < n; ++i) {
31 if (molNum[i] > -1.0E200) {
38 int VCS_SOLVE::vcs_rank(
const double * awtmp,
size_t numSpecies,
const double matrix[],
size_t numElemConstraints,
39 std::vector<size_t> &compRes, std::vector<size_t>& elemComp,
int *
const usedZeroedSpecies)
const
41 warn_deprecated(
"VCS_SOLVE::vcs_rank",
"To be removed after Cantera 2.2");
43 size_t j, k, jl, i, l, ml;
44 int numComponents = 0;
48 vector<double> sm(numElemConstraints*numSpecies);
49 vector<double> sa(numSpecies);
50 vector<double> ss(numSpecies);
52 double test = -0.2512345E298;
53 if (DEBUG_MODE_ENABLED && m_debug_print_lvl >= 2) {
55 plogf(
" --- Subroutine vcs_rank called to ");
56 plogf(
"calculate the rank and independent rows /colums of the following matrix\n");
57 if (m_debug_print_lvl >= 5) {
58 plogf(
" --- Species | ");
59 for (j = 0; j < numElemConstraints; j++) {
64 plogf(
" --- -----------");
65 for (j = 0; j < numElemConstraints; j++) {
69 for (k = 0; k < numSpecies; k++) {
73 for (j = 0; j < numElemConstraints; j++) {
74 plogf(
" %8.2g", matrix[j*numSpecies + k]);
87 int ncTrial =
static_cast<int>(std::min(numElemConstraints, numSpecies));
88 numComponents = ncTrial;
89 *usedZeroedSpecies =
false;
94 std::vector<double> aw(numSpecies);
95 for (j = 0; j < numSpecies; j++) {
115 k = basisOptMax1(
VCS_DATA_PTR(aw), static_cast<int>(numSpecies));
117 if ((aw[k] != test) && fabs(aw[k]) == 0.0) {
118 *usedZeroedSpecies =
true;
140 for (j = 0; j < numElemConstraints; ++j) {
141 sm[j + jr*numElemConstraints] = matrix[j*numSpecies + k];
150 for (j = 0; j < jl; ++j) {
152 for (i = 0; i < numElemConstraints; ++i) {
153 ss[j] += sm[i + jr* numElemConstraints] * sm[i + j* numElemConstraints];
161 for (j = 0; j < jl; ++j) {
162 for (l = 0; l < numElemConstraints; ++l) {
163 sm[l + jr*numElemConstraints] -= ss[j] * sm[l + j*numElemConstraints];
172 for (ml = 0; ml < numElemConstraints; ++ml) {
173 sa[jr] += pow(sm[ml + jr * numElemConstraints], 2);
178 if (sa[jr] < 1.0e-6) lindep =
true;
184 compRes.push_back(k);
185 elemComp.push_back(jr);
187 }
while (jr < (ncTrial-1));
191 if (numComponents == ncTrial && numElemConstraints == numSpecies) {
192 return numComponents;
196 int numComponentsR = numComponents;
198 ss.resize(numElemConstraints);
199 sa.resize(numElemConstraints);
204 aw.resize(numElemConstraints);
205 for (j = 0; j < numSpecies; j++) {
216 k = basisOptMax1(
VCS_DATA_PTR(aw), static_cast<int>(numElemConstraints));
226 for (j = 0; j < numSpecies; ++j) {
227 sm[j + jr*numSpecies] = matrix[k*numSpecies + j];
231 for (j = 0; j < jl; ++j) {
233 for (i = 0; i < numSpecies; ++i) {
234 ss[j] += sm[i + jr* numSpecies] * sm[i + j* numSpecies];
239 for (j = 0; j < jl; ++j) {
240 for (l = 0; l < numSpecies; ++l) {
241 sm[l + jr*numSpecies] -= ss[j] * sm[l + j*numSpecies];
247 for (ml = 0; ml < numSpecies; ++ml) {
248 sa[jr] += pow(sm[ml + jr * numSpecies], 2);
251 if (sa[jr] < 1.0e-6) lindep =
true;
255 elemComp.push_back(k);
257 }
while (jr < (ncTrial-1));
261 if (DEBUG_MODE_ENABLED && m_debug_print_lvl >= 2) {
262 plogf(
" --- vcs_rank found rank %d\n", numComponents);
263 if (m_debug_print_lvl >= 5) {
264 if (compRes.size() == elemComp.size()) {
265 printf(
" --- compRes elemComp\n");
266 for (
int i = 0; i < (int) compRes.size(); i++) {
267 printf(
" --- %d %d \n", (
int) compRes[i], (
int) elemComp[i]);
270 for (
int i = 0; i < (int) compRes.size(); i++) {
271 printf(
" --- compRes[%d] = %d \n", (
int) i, (
int) compRes[i]);
273 for (
int i = 0; i < (int) elemComp.size(); i++) {
274 printf(
" --- elemComp[%d] = %d \n", (
int) i, (
int) elemComp[i]);
280 if (numComponentsR != numComponents) {
281 printf(
"vcs_rank ERROR: number of components are different: %d %d\n", numComponentsR, numComponents);
283 " logical inconsistency");
286 return numComponents;
#define VCS_DATA_PTR(vvv)
Points to the data in a std::vector<> object.
void warn_deprecated(const std::string &method, const std::string &extra)
Print a warning indicating that method is deprecated.
Header file for the internal object that holds the vcs equilibrium problem (see Class VCS_SOLVE and E...
Base class for exceptions thrown by Cantera classes.
#define plogendl()
define this Cantera function to replace cout << endl;
#define plogf
define this Cantera function to replace printf
Definitions for the classes that are thrown when Cantera experiences an error condition (also contain...