Cantera  2.1.2
TransportBase.cpp
Go to the documentation of this file.
1 /**
2  * @file TransportBase.cpp
3  * Mixture-averaged transport properties for ideal gas mixtures.
4  */
8 
13 
15 
16 using namespace std;
17 
18 namespace Cantera
19 {
20 Transport::Transport(thermo_t* thermo, size_t ndim) :
21  m_thermo(thermo),
22  m_ready(false),
23  m_nsp(0),
24  m_nDim(ndim),
25  m_velocityBasis(VB_MASSAVG)
26 {
27 }
28 
29 Transport::Transport(const Transport& right)
30 {
31  m_thermo = right.m_thermo;
32  m_ready = right.m_ready;
33  m_nsp = right.m_nsp;
34  m_nDim = right.m_nDim;
36 }
37 
38 
39 Transport& Transport::operator=(const Transport& right)
40 {
41  if (&right != this) {
42  return *this;
43  }
44  m_thermo = right.m_thermo;
45  m_ready = right.m_ready;
46  m_nsp = right.m_nsp;
47  m_nDim = right.m_nDim;
48  m_velocityBasis = right.m_velocityBasis;
49  return *this;
50 }
51 
53 {
54  return new Transport(*this);
55 }
56 
57 Transport::~Transport()
58 {
59 }
60 
62 {
63  return m_ready;
64 }
65 
66 void Transport::setNDim(const int ndim)
67 {
68  m_nDim = ndim;
69 }
70 
71 void Transport::checkSpeciesIndex(size_t k) const
72 {
73  if (k >= m_nsp) {
74  throw IndexError("checkSpeciesIndex", "species", k, m_nsp-1);
75  }
76 }
77 
78 void Transport::checkSpeciesArraySize(size_t kk) const
79 {
80  if (m_nsp > kk) {
81  throw ArraySizeError("checkSpeciesArraySize", kk, m_nsp);
82  }
83 }
84 
85 void Transport::setParameters(const int type, const int k,
86  const doublereal* const p)
87 {
88  err("setParameters");
89 }
90 
92 {
93  if (!ready()) {
94  m_thermo = &thermo;
95  m_nsp = m_thermo->nSpecies();
96  } else {
97  int newNum = thermo.nSpecies();
98  int oldNum = m_thermo->nSpecies();
99  if (newNum != oldNum) {
100  throw CanteraError("Transport::setThermo",
101  "base object cannot be changed after "
102  "the transport manager has been constructed because num species isn't the same.");
103  }
104  for (int i = 0; i < newNum; i++) {
105  std::string newS0 = thermo.speciesName(i);
106  std::string oldS0 = m_thermo->speciesName(i);
107  if (newNum != oldNum) {
108  throw CanteraError("Transport::setThermo",
109  "base object cannot be changed after "
110  "the transport manager has been constructed because species names are not the same");
111  }
112  }
113  m_thermo = &thermo;
114  }
115 }
116 
117 doublereal Transport::err(const std::string& msg) const
118 {
119 
120  throw CanteraError("Transport Base Class",
121  "\n\n\n**** Method "+ msg +" not implemented in model "
122  + int2str(model()) + " ****\n"
123  "(Did you forget to specify a transport model?)\n\n\n");
124 
125  return 0.0;
126 }
127 
129 {
130  if (!ready()) {
131  m_ready = true;
132  } else
133  throw CanteraError("Transport::finalize",
134  "finalize has already been called.");
135 }
136 
137 void Transport::getSpeciesFluxes(size_t ndim, const doublereal* const grad_T,
138  size_t ldx, const doublereal* const grad_X,
139  size_t ldf, doublereal* const fluxes)
140 {
141  err("getSpeciesFluxes");
142 }
143 }
Array size error.
Definition: ctexceptions.h:123
std::string int2str(const int n, const std::string &fmt)
Convert an int to a string using a format converter.
Definition: stringUtils.cpp:40
void checkSpeciesIndex(size_t k) const
Check that the specified species index is in range Throws an exception if k is greater than nSpecies(...
Transport(thermo_t *thermo=0, size_t ndim=1)
Constructor.
virtual int model() const
Transport model.
Various templated functions that carry out common vector operations (see Templated Utility Functions)...
size_t m_nDim
Number of dimensions used in flux expressions.
thermo_t * m_thermo
pointer to the object representing the phase
Base class for transport property managers.
Header file defining class TransportFactory (see TransportFactory)
void finalize()
Enable the transport object for use.
Base class for a phase with thermodynamic properties.
Definition: ThermoPhase.h:101
Header file defining class LiquidTransportParams.
doublereal err(const std::string &msg) const
Error routine.
void checkSpeciesArraySize(size_t kk) const
Check that an array size is at least nSpecies() Throws an exception if kk is less than nSpecies()...
Base class for exceptions thrown by Cantera classes.
Definition: ctexceptions.h:68
virtual void setParameters(const int type, const int k, const doublereal *const p)
Set model parameters for derived classes.
void setNDim(const int ndim)
Set the number of dimensions to be expected in flux expressions.
thermo_t & thermo()
size_t nSpecies() const
Returns the number of species in the phase.
Definition: Phase.h:252
bool m_ready
true if finalize has been called
Header file defining class LiquidTransport.
Contains declarations for string manipulation functions within Cantera.
size_t m_nsp
Number of species.
const VelocityBasis VB_MASSAVG
Diffusion velocities are based on the mass averaged velocity.
Definition: TransportBase.h:91
virtual void setThermo(thermo_t &thermo)
Specifies the ThermoPhase object.
An array index is out of range.
Definition: ctexceptions.h:153
virtual Transport * duplMyselfAsTransport() const
Duplication routine for objects which inherit from Transport.
Header file for class ThermoPhase, the base class for phases with thermodynamic properties, and the text for the Module thermoprops (see Thermodynamic Properties and class ThermoPhase).
virtual void getSpeciesFluxes(size_t ndim, const doublereal *const grad_T, size_t ldx, const doublereal *const grad_X, size_t ldf, doublereal *const fluxes)
Get the species diffusive mass fluxes wrt to the specified solution averaged velocity, given the gradients in mole fraction and temperature.
int m_velocityBasis
Velocity basis from which diffusion velocities are computed.
std::string speciesName(size_t k) const
Name of the species with index k.
Definition: Phase.cpp:246
Definitions for the classes that are thrown when Cantera experiences an error condition (also contain...