Cantera 2.6.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 https://cantera.org/license.txt for license and copyright information.
8
13#include <cassert>
14#include <cstring>
15
16using namespace std;
17
18namespace Cantera
19{
20
21double 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
33const char* vcs_speciesType_string(int speciesStatus, int length)
34{
35 switch (speciesStatus) {
37 return "Component Species";
39 return "Major Species";
41 return "Minor Species";
43 if (length < 48) {
44 return "Set Zeroed-Phase";
45 } else {
46 return "Purposely Zeroed-Phase Species (not in problem)";
47 }
49 if (length < 23) {
50 return "Zeroed-MS Phase";
51 } else {
52 return "Zeroed-MS Phase Species";
53 }
55 if (length < 23) {
56 return "Zeroed-SS Phase";
57 } else {
58 return "Zeroed-SS Phase Species";
59 }
61 if (length < 22) {
62 return "Deleted Species";
63 } else if (length < 40) {
64 return "Deleted-Small Species";
65 } else {
66 return "Deleted-Small Species in a MS phase";
67 }
69 if (length < 47) {
70 return "Tmp Zeroed in MS";
71 } else {
72 return "Zeroed Species in an active MS phase (tmp)";
73 }
75 if (length < 56) {
76 return "Stoich Zeroed in MS";
77 } else {
78 return "Zeroed Species in an active MS phase (Stoich Constraint)";
79 }
81 if (length < 29) {
82 return "InterfaceVoltage";
83 } else {
84 return "InterfaceVoltage Species";
85 }
86 default:
87 return "unknown species type";
88 }
89}
90
91bool vcs_doubleEqual(double d1, double d2)
92{
93 double denom = fabs(d1) + fabs(d2) + 1.0;
94 double fac = fabs(d1 - d2) / denom;
95 if (fac > 1.0E-10) {
96 return false;
97 }
98 return true;
99}
100
101}
Definitions for the classes that are thrown when Cantera experiences an error condition (also contain...
Namespace for the Cantera kernel.
Definition: AnyMap.h:29
const char * vcs_speciesType_string(int speciesStatus, int length=100)
Returns a const char string representing the type of the species given by the first argument.
Definition: vcs_util.cpp:33
bool vcs_doubleEqual(double d1, double d2)
Simple routine to check whether two doubles are equal up to roundoff error.
Definition: vcs_util.cpp:91
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:184
double vcs_l2norm(const vector_fp &vec)
determine the l2 norm of a vector of doubles
Definition: vcs_util.cpp:21
Contains declarations for string manipulation functions within Cantera.
Defines and definitions within the vcs package.
#define VCS_SPECIES_INTERFACIALVOLTAGE
Species refers to an electron in the metal.
Definition: vcs_defs.h:149
#define VCS_SPECIES_COMPONENT
Species is a component which can be nonzero.
Definition: vcs_defs.h:99
#define VCS_SPECIES_MAJOR
Species is a major species.
Definition: vcs_defs.h:106
#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:179
#define VCS_SPECIES_ZEROEDMS
Species lies in a multicomponent phase with concentration zero.
Definition: vcs_defs.h:127
#define VCS_SPECIES_ZEROEDPHASE
Species lies in a multicomponent phase that is zeroed atm.
Definition: vcs_defs.h:157
#define VCS_SPECIES_ACTIVEBUTZERO
Species lies in a multicomponent phase that is active, but species concentration is zero.
Definition: vcs_defs.h:167
#define VCS_SPECIES_ZEROEDSS
Species is a SS phase, that is currently zeroed out.
Definition: vcs_defs.h:133
#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:142
#define VCS_SPECIES_MINOR
Species is a major species.
Definition: vcs_defs.h:113
Internal declarations for the VCSnonideal package.