Cantera  3.1.0a1
Loading...
Searching...
No Matches
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
16namespace Cantera
17{
18
19double vcs_l2norm(const vector<double>& vec)
20{
21 if (vec.empty()) {
22 return 0.0;
23 }
24 double sum = 0.0;
25 for (const auto& val : vec) {
26 sum += val * val;
27 }
28 return std::sqrt(sum / vec.size());
29}
30
31const char* vcs_speciesType_string(int speciesStatus, int length)
32{
33 switch (speciesStatus) {
35 return "Component Species";
37 return "Major Species";
39 return "Minor Species";
41 if (length < 48) {
42 return "Set Zeroed-Phase";
43 } else {
44 return "Purposely Zeroed-Phase Species (not in problem)";
45 }
47 if (length < 23) {
48 return "Zeroed-MS Phase";
49 } else {
50 return "Zeroed-MS Phase Species";
51 }
53 if (length < 23) {
54 return "Zeroed-SS Phase";
55 } else {
56 return "Zeroed-SS Phase Species";
57 }
59 if (length < 22) {
60 return "Deleted Species";
61 } else if (length < 40) {
62 return "Deleted-Small Species";
63 } else {
64 return "Deleted-Small Species in a MS phase";
65 }
67 if (length < 47) {
68 return "Tmp Zeroed in MS";
69 } else {
70 return "Zeroed Species in an active MS phase (tmp)";
71 }
73 if (length < 56) {
74 return "Stoich Zeroed in MS";
75 } else {
76 return "Zeroed Species in an active MS phase (Stoich Constraint)";
77 }
79 if (length < 29) {
80 return "InterfaceVoltage";
81 } else {
82 return "InterfaceVoltage Species";
83 }
84 default:
85 return "unknown species type";
86 }
87}
88
89bool vcs_doubleEqual(double d1, double d2)
90{
91 double denom = fabs(d1) + fabs(d2) + 1.0;
92 double fac = fabs(d1 - d2) / denom;
93 if (fac > 1.0E-10) {
94 return false;
95 }
96 return true;
97}
98
99}
Definitions for the classes that are thrown when Cantera experiences an error condition (also contain...
Namespace for the Cantera kernel.
Definition AnyMap.cpp:564
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:31
bool vcs_doubleEqual(double d1, double d2)
Simple routine to check whether two doubles are equal up to roundoff error.
Definition vcs_util.cpp:89
double vcs_l2norm(const vector< double > &vec)
determine the l2 norm of a vector of doubles
Definition vcs_util.cpp:19
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:147
#define VCS_SPECIES_COMPONENT
Species is a component which can be nonzero.
Definition vcs_defs.h:97
#define VCS_SPECIES_MAJOR
Species is a major species.
Definition vcs_defs.h:104
#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:177
#define VCS_SPECIES_ZEROEDMS
Species lies in a multicomponent phase with concentration zero.
Definition vcs_defs.h:125
#define VCS_SPECIES_ZEROEDPHASE
Species lies in a multicomponent phase that is zeroed atm.
Definition vcs_defs.h:155
#define VCS_SPECIES_ACTIVEBUTZERO
Species lies in a multicomponent phase that is active, but species concentration is zero.
Definition vcs_defs.h:165
#define VCS_SPECIES_ZEROEDSS
Species is a SS phase, that is currently zeroed out.
Definition vcs_defs.h:131
#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:140
#define VCS_SPECIES_MINOR
Species is a major species.
Definition vcs_defs.h:111
Internal declarations for the VCSnonideal package.