Cantera  2.3.0
vcs_util.cpp
Go to the documentation of this file.
1 /**
2  * @file vcs_util.cpp
3  * Internal definitions for utility functions for the VCSnonideal package
4  */
5 
6 // This file is part of Cantera. See License.txt in the top-level directory or
7 // at http://www.cantera.org/license.txt for license and copyright information.
8 
10 #include "cantera/equil/vcs_defs.h"
13 #include <cassert>
14 #include <cstring>
15 
16 using namespace std;
17 
18 namespace Cantera
19 {
20 
21 double vcs_l2norm(const vector_fp& vec)
22 {
23  if (vec.empty()) {
24  return 0.0;
25  }
26  double sum = 0.0;
27  for (const auto& val : vec) {
28  sum += val * val;
29  }
30  return std::sqrt(sum / vec.size());
31 }
32 
33 size_t vcs_optMax(const double* x, const double* xSize, size_t j, size_t n)
34 {
35  size_t largest = j;
36  double big = x[j];
37  if (xSize) {
38  assert(xSize[j] > 0.0);
39  big *= xSize[j];
40  for (size_t i = j + 1; i < n; ++i) {
41  assert(xSize[i] > 0.0);
42  if ((x[i] * xSize[i]) > big) {
43  largest = i;
44  big = x[i] * xSize[i];
45  }
46  }
47  } else {
48  for (size_t i = j + 1; i < n; ++i) {
49  if (x[i] > big) {
50  largest = i;
51  big = x[i];
52  }
53  }
54  }
55  return largest;
56 }
57 
58 const char* vcs_speciesType_string(int speciesStatus, int length)
59 {
60  switch (speciesStatus) {
62  return "Component Species";
63  case VCS_SPECIES_MAJOR:
64  return "Major Species";
65  case VCS_SPECIES_MINOR:
66  return "Minor Species";
68  if (length < 48) {
69  return "Set Zeroed-Phase";
70  } else {
71  return "Purposely Zeroed-Phase Species (not in problem)";
72  }
74  if (length < 23) {
75  return "Zeroed-MS Phase";
76  } else {
77  return "Zeroed-MS Phase Species";
78  }
80  if (length < 23) {
81  return "Zeroed-SS Phase";
82  } else {
83  return "Zeroed-SS Phase Species";
84  }
86  if (length < 22) {
87  return "Deleted Species";
88  } else if (length < 40) {
89  return "Deleted-Small Species";
90  } else {
91  return "Deleted-Small Species in a MS phase";
92  }
94  if (length < 47) {
95  return "Tmp Zeroed in MS";
96  } else {
97  return "Zeroed Species in an active MS phase (tmp)";
98  }
100  if (length < 56) {
101  return "Stoich Zeroed in MS";
102  } else {
103  return "Zeroed Species in an active MS phase (Stoich Constraint)";
104  }
106  if (length < 29) {
107  return "InterfaceVoltage";
108  } else {
109  return "InterfaceVoltage Species";
110  }
111  default:
112  return "unknown species type";
113  }
114 }
115 
116 bool vcs_doubleEqual(double d1, double d2)
117 {
118  double denom = fabs(d1) + fabs(d2) + 1.0;
119  double fac = fabs(d1 - d2) / denom;
120  if (fac > 1.0E-10) {
121  return false;
122  }
123  return true;
124 }
125 
126 }
bool vcs_doubleEqual(double d1, double d2)
Simple routine to check whether two doubles are equal up to roundoff error.
Definition: vcs_util.cpp:116
#define VCS_SPECIES_ZEROEDMS
Species lies in a multicomponent phase with concentration zero.
Definition: vcs_defs.h:143
#define VCS_SPECIES_MINOR
Species is a major species.
Definition: vcs_defs.h:129
STL namespace.
#define VCS_SPECIES_INTERFACIALVOLTAGE
Species refers to an electron in the metal.
Definition: vcs_defs.h:165
#define VCS_SPECIES_ZEROEDSS
Species is a SS phase, that is currently zeroed out.
Definition: vcs_defs.h:149
Defines and definitions within the vcs package.
#define VCS_SPECIES_ZEROEDPHASE
Species lies in a multicomponent phase that is zeroed atm.
Definition: vcs_defs.h:173
Internal declarations for the VCSnonideal package.
#define VCS_SPECIES_ACTIVEBUTZERO
Species lies in a multicomponent phase that is active, but species concentration is zero...
Definition: vcs_defs.h:183
#define VCS_SPECIES_MAJOR
Species is a major species.
Definition: vcs_defs.h:122
#define VCS_SPECIES_STOICHZERO
Species lies in a multicomponent phase that is active, but species concentration is zero due to stoic...
Definition: vcs_defs.h:195
double vcs_l2norm(const vector_fp &vec)
determine the l2 norm of a vector of doubles
Definition: vcs_util.cpp:21
std::vector< double > vector_fp
Turn on the use of stl vectors for the basic array type within cantera Vector of doubles.
Definition: ct_defs.h:157
size_t vcs_optMax(const double *x, const double *xSize, size_t j, size_t n)
Finds the location of the maximum component in a double vector.
Definition: vcs_util.cpp:33
Contains declarations for string manipulation functions within Cantera.
const char * vcs_speciesType_string(int speciesStatus, int length)
Returns a const char string representing the type of the species given by the first argument...
Definition: vcs_util.cpp:58
#define VCS_SPECIES_COMPONENT
Species is a component which can be nonzero.
Definition: vcs_defs.h:115
Namespace for the Cantera kernel.
Definition: application.cpp:29
#define VCS_SPECIES_DELETED
Species has such a small mole fraction it is deleted even though its phase may possibly exist...
Definition: vcs_defs.h:158
Definitions for the classes that are thrown when Cantera experiences an error condition (also contain...