| Cantera 3.0.0

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
9#include "cantera/equil/vcs_internal.h"
10#include "cantera/equil/vcs_defs.h"
11#include "cantera/base/stringUtils.h"
12#include "cantera/base/ctexceptions.h"
13#include <cassert>
14#include <cstring>
15
16 namespace Cantera
17{
18
19 double 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
31 const char* vcs_speciesType_string(int speciesStatus, int length)
32{
33 switch (speciesStatus) {
34 case VCS_SPECIES_COMPONENT:
35 return "Component Species";
36 case VCS_SPECIES_MAJOR:
37 return "Major Species";
38 case VCS_SPECIES_MINOR:
39 return "Minor Species";
40 case VCS_SPECIES_ZEROEDPHASE:
41 if (length < 48) {
42 return "Set Zeroed-Phase";
43 } else {
44 return "Purposely Zeroed-Phase Species (not in problem)";
45 }
46 case VCS_SPECIES_ZEROEDMS:
47 if (length < 23) {
48 return "Zeroed-MS Phase";
49 } else {
50 return "Zeroed-MS Phase Species";
51 }
52 case VCS_SPECIES_ZEROEDSS:
53 if (length < 23) {
54 return "Zeroed-SS Phase";
55 } else {
56 return "Zeroed-SS Phase Species";
57 }
58 case VCS_SPECIES_DELETED:
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 }
66 case VCS_SPECIES_ACTIVEBUTZERO:
67 if (length < 47) {
68 return "Tmp Zeroed in MS";
69 } else {
70 return "Zeroed Species in an active MS phase (tmp)";
71 }
72 case VCS_SPECIES_STOICHZERO:
73 if (length < 56) {
74 return "Stoich Zeroed in MS";
75 } else {
76 return "Zeroed Species in an active MS phase (Stoich Constraint)";
77 }
78 case VCS_SPECIES_INTERFACIALVOLTAGE:
79 if (length < 29) {
80 return "InterfaceVoltage";
81 } else {
82 return "InterfaceVoltage Species";
83 }
84 default:
85 return "unknown species type";
86 }
87}
88
89 bool 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}
ctexceptions.h
Definitions for the classes that are thrown when Cantera experiences an error condition (also contain...
Cantera
Namespace for the Cantera kernel.
Definition AnyMap.cpp:564
Cantera::vcs_speciesType_string
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
Cantera::vcs_doubleEqual
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
Cantera::vcs_l2norm
double vcs_l2norm(const vector< double > &vec)
determine the l2 norm of a vector of doubles
Definition vcs_util.cpp:19
stringUtils.h
Contains declarations for string manipulation functions within Cantera.
vcs_defs.h
Defines and definitions within the vcs package.
VCS_SPECIES_INTERFACIALVOLTAGE
#define VCS_SPECIES_INTERFACIALVOLTAGE
Species refers to an electron in the metal.
Definition vcs_defs.h:147
VCS_SPECIES_COMPONENT
#define VCS_SPECIES_COMPONENT
Species is a component which can be nonzero.
Definition vcs_defs.h:97
VCS_SPECIES_MAJOR
#define VCS_SPECIES_MAJOR
Species is a major species.
Definition vcs_defs.h:104
VCS_SPECIES_STOICHZERO
#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
VCS_SPECIES_ZEROEDMS
#define VCS_SPECIES_ZEROEDMS
Species lies in a multicomponent phase with concentration zero.
Definition vcs_defs.h:125
VCS_SPECIES_ZEROEDPHASE
#define VCS_SPECIES_ZEROEDPHASE
Species lies in a multicomponent phase that is zeroed atm.
Definition vcs_defs.h:155
VCS_SPECIES_ACTIVEBUTZERO
#define VCS_SPECIES_ACTIVEBUTZERO
Species lies in a multicomponent phase that is active, but species concentration is zero.
Definition vcs_defs.h:165
VCS_SPECIES_ZEROEDSS
#define VCS_SPECIES_ZEROEDSS
Species is a SS phase, that is currently zeroed out.
Definition vcs_defs.h:131
VCS_SPECIES_DELETED
#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
VCS_SPECIES_MINOR
#define VCS_SPECIES_MINOR
Species is a major species.
Definition vcs_defs.h:111
vcs_internal.h
Internal declarations for the VCSnonideal package.