26 namespace VCSnonideal {
27 static int basisOptMax1(
const double *
const molNum,
31 for (
int i = 0; i < n; ++i) {
33 if (molNum[i] > -1.0E200 && fabs(molNum[i]) > 1.0E-13) {
37 for (
int i = 0; i < n; ++i) {
39 if (molNum[i] > -1.0E200) {
46 int VCS_SOLVE::vcs_rank(
const double * awtmp,
size_t numSpecies,
const double matrix[],
size_t numElemConstraints,
47 std::vector<size_t> &compRes, std::vector<size_t>& elemComp,
int *
const usedZeroedSpecies)
const
51 size_t j, k, jl, i, l, ml;
52 int numComponents = 0;
56 vector<double> sm(numElemConstraints*numSpecies);
57 vector<double> sa(numSpecies);
58 vector<double> ss(numSpecies);
60 double test = -0.2512345E298;
62 if (m_debug_print_lvl >= 2) {
64 plogf(
" --- Subroutine vcs_rank called to ");
65 plogf(
"calculate the rank and independent rows /colums of the following matrix\n");
66 if (m_debug_print_lvl >= 5) {
67 plogf(
" --- Species | ");
68 for (j = 0; j < numElemConstraints; j++) {
73 plogf(
" --- -----------");
74 for (j = 0; j < numElemConstraints; j++) {
78 for (k = 0; k < numSpecies; k++) {
82 for (j = 0; j < numElemConstraints; j++) {
83 plogf(
" %8.2g", matrix[j*numSpecies + k]);
98 int ncTrial = std::min(numElemConstraints, numSpecies);
99 numComponents = ncTrial;
100 *usedZeroedSpecies =
false;
105 std::vector<double> aw(numSpecies);
106 for (j = 0; j < numSpecies; j++) {
128 if ((aw[k] != test) && fabs(aw[k]) == 0.0) {
129 *usedZeroedSpecies =
true;
151 for (j = 0; j < numElemConstraints; ++j) {
152 sm[j + jr*numElemConstraints] = matrix[j*numSpecies + k];
161 for (j = 0; j < jl; ++j) {
163 for (i = 0; i < numElemConstraints; ++i) {
164 ss[j] += sm[i + jr* numElemConstraints] * sm[i + j* numElemConstraints];
172 for (j = 0; j < jl; ++j) {
173 for (l = 0; l < numElemConstraints; ++l) {
174 sm[l + jr*numElemConstraints] -= ss[j] * sm[l + j*numElemConstraints];
183 for (ml = 0; ml < numElemConstraints; ++ml) {
184 sa[jr] += SQUARE(sm[ml + jr * numElemConstraints]);
189 if (sa[jr] < 1.0e-6) lindep =
true;
195 compRes.push_back(k);
196 elemComp.push_back(jr);
198 }
while (jr < (ncTrial-1));
202 if (numComponents == ncTrial && numElemConstraints == numSpecies) {
203 return numComponents;
207 int numComponentsR = numComponents;
209 ss.resize(numElemConstraints);
210 sa.resize(numElemConstraints);
215 aw.resize(numElemConstraints);
216 for (j = 0; j < numSpecies; j++) {
237 for (j = 0; j < numSpecies; ++j) {
238 sm[j + jr*numSpecies] = matrix[k*numSpecies + j];
242 for (j = 0; j < jl; ++j) {
244 for (i = 0; i < numSpecies; ++i) {
245 ss[j] += sm[i + jr* numSpecies] * sm[i + j* numSpecies];
250 for (j = 0; j < jl; ++j) {
251 for (l = 0; l < numSpecies; ++l) {
252 sm[l + jr*numSpecies] -= ss[j] * sm[l + j*numSpecies];
258 for (ml = 0; ml < numSpecies; ++ml) {
259 sa[jr] += SQUARE(sm[ml + jr * numSpecies]);
262 if (sa[jr] < 1.0e-6) lindep =
true;
266 elemComp.push_back(k);
268 }
while (jr < (ncTrial-1));
273 if (m_debug_print_lvl >= 2) {
274 plogf(
" --- vcs_rank found rank %d\n", numComponents);
275 if (m_debug_print_lvl >= 5) {
276 if (compRes.size() == elemComp.size()) {
277 printf(
" --- compRes elemComp\n");
278 for (
int i = 0; i < (int) compRes.size(); i++) {
279 printf(
" --- %d %d \n", (
int) compRes[i], (
int) elemComp[i]);
282 for (
int i = 0; i < (int) compRes.size(); i++) {
283 printf(
" --- compRes[%d] = %d \n", (
int) i, (
int) compRes[i]);
285 for (
int i = 0; i < (int) elemComp.size(); i++) {
286 printf(
" --- elemComp[%d] = %d \n", (
int) i, (
int) elemComp[i]);
293 if (numComponentsR != numComponents) {
294 printf(
"vcs_rank ERROR: number of components are different: %d %d\n", numComponentsR, numComponents);
296 " logical inconsistency");
299 return numComponents;
Declarations for a simple class that implements an Ansi C wall clock timer (see Cantera::clockWC).
#define VCS_DATA_PTR(vvv)
Points to the data in a std::vector<> object.
Header file for the internal object that holds the vcs equilibrium problem (see Class VCS_SOLVE and E...
Header for the object representing each phase within vcs.
Internal declarations for the VCSnonideal package.
Header for the Interface class for the vcs thermo equilibrium solver package,.
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...