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
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 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 const char* vcs_speciesType_string(int speciesStatus, int length)
34{
35 switch (speciesStatus) {
36 case VCS_SPECIES_COMPONENT:
37 return "Component Species";
38 case VCS_SPECIES_MAJOR:
39 return "Major Species";
40 case VCS_SPECIES_MINOR:
41 return "Minor Species";
42 case VCS_SPECIES_ZEROEDPHASE:
43 if (length < 48) {
44 return "Set Zeroed-Phase";
45 } else {
46 return "Purposely Zeroed-Phase Species (not in problem)";
47 }
48 case VCS_SPECIES_ZEROEDMS:
49 if (length < 23) {
50 return "Zeroed-MS Phase";
51 } else {
52 return "Zeroed-MS Phase Species";
53 }
54 case VCS_SPECIES_ZEROEDSS:
55 if (length < 23) {
56 return "Zeroed-SS Phase";
57 } else {
58 return "Zeroed-SS Phase Species";
59 }
60 case VCS_SPECIES_DELETED:
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 }
68 case VCS_SPECIES_ACTIVEBUTZERO:
69 if (length < 47) {
70 return "Tmp Zeroed in MS";
71 } else {
72 return "Zeroed Species in an active MS phase (tmp)";
73 }
74 case VCS_SPECIES_STOICHZERO:
75 if (length < 56) {
76 return "Stoich Zeroed in MS";
77 } else {
78 return "Zeroed Species in an active MS phase (Stoich Constraint)";
79 }
80 case VCS_SPECIES_INTERFACIALVOLTAGE:
81 if (length < 29) {
82 return "InterfaceVoltage";
83 } else {
84 return "InterfaceVoltage Species";
85 }
86 default:
87 return "unknown species type";
88 }
89}
90
91 bool 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}
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:557
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:33
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:91
Cantera::vector_fp
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
Cantera::vcs_l2norm
double vcs_l2norm(const vector_fp &vec)
determine the l2 norm of a vector of doubles
Definition: vcs_util.cpp:21
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:149
VCS_SPECIES_COMPONENT
#define VCS_SPECIES_COMPONENT
Species is a component which can be nonzero.
Definition: vcs_defs.h:99
VCS_SPECIES_MAJOR
#define VCS_SPECIES_MAJOR
Species is a major species.
Definition: vcs_defs.h:106
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:179
VCS_SPECIES_ZEROEDMS
#define VCS_SPECIES_ZEROEDMS
Species lies in a multicomponent phase with concentration zero.
Definition: vcs_defs.h:127
VCS_SPECIES_ZEROEDPHASE
#define VCS_SPECIES_ZEROEDPHASE
Species lies in a multicomponent phase that is zeroed atm.
Definition: vcs_defs.h:157
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:167
VCS_SPECIES_ZEROEDSS
#define VCS_SPECIES_ZEROEDSS
Species is a SS phase, that is currently zeroed out.
Definition: vcs_defs.h:133
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:142
VCS_SPECIES_MINOR
#define VCS_SPECIES_MINOR
Species is a major species.
Definition: vcs_defs.h:113
vcs_internal.h
Internal declarations for the VCSnonideal package.