Cantera 2.6.0

TransportBase.cpp
Go to the documentation of this file.
1/**
2 * @file TransportBase.cpp
3 * Mixture-averaged transport properties for ideal gas mixtures.
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/transport/TransportBase.h"
10#include "cantera/thermo/ThermoPhase.h"
11#include "cantera/transport/TransportFactory.h"
12
13 using namespace std;
14
15 namespace Cantera
16{
17 Transport::Transport(ThermoPhase* thermo, size_t ndim) :
18 m_thermo(thermo),
19 m_ready(false),
20 m_nsp(0),
21 m_nDim(ndim),
22 m_velocityBasis(VB_MASSAVG)
23{
24}
25
26 bool Transport::ready()
27{
28 return m_ready;
29}
30
31 void Transport::setNDim(const int ndim)
32{
33 m_nDim = ndim;
34}
35
36 void Transport::checkSpeciesIndex(size_t k) const
37{
38 if (k >= m_nsp) {
39 throw IndexError("Transport::checkSpeciesIndex", "species", k, m_nsp-1);
40 }
41}
42
43 void Transport::checkSpeciesArraySize(size_t kk) const
44{
45 if (m_nsp > kk) {
46 throw ArraySizeError("Transport::checkSpeciesArraySize", kk, m_nsp);
47 }
48}
49
50 AnyMap Transport::parameters() const
51{
52 AnyMap out;
53 string name = TransportFactory::factory()->canonicalize(transportType());
54 if (name != "") {
55 out["transport"] = name;
56 }
57 return out;
58}
59
60 void Transport::setThermo(ThermoPhase& thermo)
61{
62 if (!ready()) {
63 m_thermo = &thermo;
64 m_nsp = m_thermo->nSpecies();
65 } else {
66 size_t newNum = thermo.nSpecies();
67 size_t oldNum = m_thermo->nSpecies();
68 if (newNum != oldNum) {
69 throw CanteraError("Transport::setThermo",
70 "base object cannot be changed after "
71 "the transport manager has been constructed because num species isn't the same.");
72 }
73 for (size_t i = 0; i < newNum; i++) {
74 std::string newS0 = thermo.speciesName(i);
75 std::string oldS0 = m_thermo->speciesName(i);
76 if (newNum != oldNum) {
77 throw CanteraError("Transport::setThermo",
78 "base object cannot be changed after "
79 "the transport manager has been constructed because species names are not the same");
80 }
81 }
82 m_thermo = &thermo;
83 }
84}
85
86 void Transport::setRoot(std::shared_ptr<Solution> root)
87{
88 m_root = root;
89}
90
91 void Transport::finalize()
92{
93 if (!ready()) {
94 m_ready = true;
95 } else {
96 throw CanteraError("Transport::finalize",
97 "finalize has already been called.");
98 }
99}
100}
ThermoPhase.h
Header file for class ThermoPhase, the base class for phases with thermodynamic properties,...
TransportBase.h
Headers for the Transport object, which is the virtual base class for all transport property evaluato...
TransportFactory.h
Header file defining class TransportFactory (see TransportFactory)
Cantera::AnyMap
A map of string keys to values whose type can vary at runtime.
Definition: AnyMap.h:399
Cantera::ArraySizeError
Array size error.
Definition: ctexceptions.h:128
Cantera::CanteraError
Base class for exceptions thrown by Cantera classes.
Definition: ctexceptions.h:61
Cantera::Factory::canonicalize
std::string canonicalize(const std::string &name)
Get the canonical name registered for a type.
Definition: FactoryBase.h:95
Cantera::IndexError
An array index is out of range.
Definition: ctexceptions.h:158
Cantera::Phase::nSpecies
size_t nSpecies() const
Returns the number of species in the phase.
Definition: Phase.h:273
Cantera::Phase::speciesName
std::string speciesName(size_t k) const
Name of the species with index k.
Definition: Phase.cpp:200
Cantera::ThermoPhase
Base class for a phase with thermodynamic properties.
Definition: ThermoPhase.h:102
Cantera::TransportFactory::factory
static TransportFactory * factory()
Return a pointer to a TransportFactory instance.
Definition: TransportFactory.h:45
Cantera::Transport::setThermo
virtual void setThermo(ThermoPhase &thermo)
Specifies the ThermoPhase object.
Definition: TransportBase.cpp:60
Cantera::Transport::m_thermo
ThermoPhase * m_thermo
pointer to the object representing the phase
Definition: TransportBase.h:773
Cantera::Transport::setNDim
void setNDim(const int ndim)
Set the number of dimensions to be expected in flux expressions.
Definition: TransportBase.cpp:31
Cantera::Transport::m_nDim
size_t m_nDim
Number of dimensions used in flux expressions.
Definition: TransportBase.h:782
Cantera::Transport::checkSpeciesIndex
void checkSpeciesIndex(size_t k) const
Check that the specified species index is in range.
Definition: TransportBase.cpp:36
Cantera::Transport::m_ready
bool m_ready
true if finalize has been called
Definition: TransportBase.h:776
Cantera::Transport::finalize
void finalize()
Enable the transport object for use.
Definition: TransportBase.cpp:91
Cantera::Transport::setRoot
virtual void setRoot(std::shared_ptr< Solution > root)
Set root Solution holding all phase information.
Definition: TransportBase.cpp:86
Cantera::Transport::parameters
AnyMap parameters() const
Return the parameters for a phase definition which are needed to reconstruct an identical object usin...
Definition: TransportBase.cpp:50
Cantera::Transport::transportType
virtual std::string transportType() const
Identifies the Transport object type.
Definition: TransportBase.h:160
Cantera::Transport::m_root
std::weak_ptr< Solution > m_root
reference to Solution
Definition: TransportBase.h:789
Cantera::Transport::Transport
Transport(ThermoPhase *thermo=0, size_t ndim=1)
Constructor.
Definition: TransportBase.cpp:17
Cantera::Transport::m_nsp
size_t m_nsp
Number of species.
Definition: TransportBase.h:779
Cantera::Transport::thermo
ThermoPhase & thermo()
Definition: TransportBase.h:170
Cantera::Transport::checkSpeciesArraySize
void checkSpeciesArraySize(size_t kk) const
Check that an array size is at least nSpecies().
Definition: TransportBase.cpp:43
Cantera::Transport::ready
bool ready()
Definition: TransportBase.cpp:26
Cantera::VB_MASSAVG
const VelocityBasis VB_MASSAVG
Definition: TransportBase.h:69
Cantera
Namespace for the Cantera kernel.
Definition: AnyMap.cpp:557