Cantera  4.0.0a1
Loading...
Searching...
No Matches
Wall.h
Go to the documentation of this file.
1//! @file Wall.h Header file for base class WallBase.
2
3// This file is part of Cantera. See License.txt in the top-level directory or
4// at https://cantera.org/license.txt for license and copyright information.
5
6#ifndef CT_WALL_H
7#define CT_WALL_H
8
11#include "ConnectorNode.h"
12#include "cantera/numerics/eigen_sparse.h"
13
14namespace Cantera
15{
16
17class Func1;
18
19/**
20 * Base class for 'walls' (walls, pistons, etc.) connecting reactors.
21 * @ingroup connectorGroup
22 */
23class WallBase : public ConnectorNode
24{
25public:
26 WallBase(shared_ptr<ReactorBase> r0, shared_ptr<ReactorBase> r1,
27 const string& name="(none)");
28 using ConnectorNode::ConnectorNode; // inherit constructors
29
30 string type() const override {
31 return "WallBase";
32 }
33
34 //! Rate of volume change (m^3/s) for the adjacent reactors at current reactor
35 //! network time.
36 /*!
37 * This method is called by Reactor::evalWalls(). Base class method
38 * does nothing (that is, constant volume), but may be overloaded.
39 * @since New in %Cantera 3.0.
40 */
41 virtual double expansionRate() {
42 return 0.0;
43 }
44
45 //! Heat flow rate through the wall (W) at current reactor network time.
46 /*!
47 * This method is called by Reactor::evalWalls(). Base class method
48 * does nothing (that is, an adiabatic wall), but may be overloaded.
49 * @since New in %Cantera 3.0.
50 */
51 virtual double heatRate() {
52 return 0.0;
53 }
54
55 //! Area in (m^2).
56 double area() {
57 return m_area;
58 }
59
60 //! Set the area [m^2].
61 virtual void setArea(double a);
62
63 //! Called just before the start of integration
64 virtual void initialize() {}
65
66 //! True if the wall is correctly configured and ready to use.
67 virtual bool ready() {
68 return (m_left != 0 && m_right != 0);
69 }
70
71 //! Return a reference to the Reactor or Reservoir to the left of the wall.
72 ReactorBase& left() const {
73 return *m_left;
74 }
75
76 //! Return a reference to the Reactor or Reservoir to the right of the wall.
78 return *m_right;
79 }
80
81 //! Set current reactor network time
82 /*!
83 * @since New in %Cantera 3.0.
84 */
85 void setSimTime(double time) {
86 m_time = time;
87 }
88
89 //! Add Jacobian terms proportional to derivatives of the wall expansion rate.
90 //!
91 //! Adds entries for `coeff * d(expansionRate)/dy_j` to the specified global row of
92 //! the reactor network Jacobian. The wall supplies scalar derivatives with
93 //! respect to left and right pressures, while adjacent reactors supply pressure
94 //! derivatives with respect to their state variables.
95 //!
96 //! @param[in,out] trips Sparse Jacobian entries. Implementations append entries
97 //! using global row and column indices in the reactor network.
98 //! @param row Global row index receiving these chain-rule terms.
99 //! @param coeff Multiplicative factor applied to `d(expansionRate)/dy_j`.
100 //! @param includePressureSpecies Include pressure derivatives with respect to
101 //! species state variables when pressure is a derived quantity. These terms
102 //! may be dense and are controlled by preconditioner sparsity settings.
103 //! @since New in %Cantera 4.0.
104 virtual void addExpansionRateJacobian(SparseTriplets& trips, size_t row,
105 double coeff, bool includePressureSpecies=true) {};
106
107 //! Add Jacobian terms proportional to derivatives of the wall heat rate.
108 //!
109 //! Adds entries for `coeff * d(heatRate)/dy_j` to the specified global row of the
110 //! reactor network Jacobian. The wall supplies scalar derivatives with respect to
111 //! left and right temperatures, while adjacent reactors supply temperature
112 //! derivatives with respect to their state variables.
113 //!
114 //! @param[in,out] trips Sparse Jacobian entries. Implementations append entries
115 //! using global row and column indices in the reactor network.
116 //! @param row Global row index receiving these chain-rule terms.
117 //! @param coeff Multiplicative factor applied to `d(heatRate)/dy_j`.
118 //! @since New in %Cantera 4.0.
119 virtual void addHeatRateJacobian(SparseTriplets& trips, size_t row, double coeff) {};
120
121protected:
122 ReactorBase* m_left = nullptr;
123 ReactorBase* m_right = nullptr;
124
125 //! current reactor network time
126 double m_time = 0.0;
127
128 double m_area = 1.0;
129};
130
131//! Represents a wall between between two ReactorBase objects.
132/*!
133 * Walls can move (changing the volume of the adjacent reactors) and allow heat
134 * transfer between reactors.
135 * @ingroup connectorGroup
136 */
137class Wall : public WallBase
138{
139public:
140 using WallBase::WallBase; // inherit constructors
141
142 //! String indicating the wall model implemented. Usually
143 //! corresponds to the name of the derived class.
144 string type() const override {
145 return "Wall";
146 }
147
148 //! Wall velocity @f$ v(t) @f$ at current reactor network time.
149 //! @since New in %Cantera 3.0.
150 double velocity() const;
151
152 //! Set the wall velocity to a specified function of time, @f$ v(t) @f$.
153 //! @since Changed in %Cantera 3.2. Previous version used a raw pointer.
154 void setVelocity(shared_ptr<Func1> f) {
155 if (f) {
156 m_vf = f.get();
157 }
158 }
159
160 //! Rate of volume change (m^3/s) for the adjacent reactors.
161 /*!
162 * The volume rate of change is given by
163 * @f[
164 * \dot V = K A (P_{left} - P_{right}) + F(t)
165 * @f]
166 * where *K* is the specified expansion rate coefficient, *A* is the wall area,
167 * and and *F(t)* is a specified function evaluated at the current network time.
168 * Positive values for `expansionRate` correspond to increases in the volume of
169 * reactor on left, and decreases in the volume of the reactor on the right.
170 * @since New in %Cantera 3.0.
171 */
172 double expansionRate() override;
173
174 //! Heat flux function @f$ q_0(t) @f$ evaluated at current reactor network time.
175 //! @since New in %Cantera 3.0.
176 double heatFlux() const;
177
178 //! Specify the heat flux function @f$ q_0(t) @f$.
179 //! @since Changed in %Cantera 3.2. Previous version used a raw pointer.
180 void setHeatFlux(shared_ptr<Func1> q) {
181 m_qf = q.get();
182 }
183
184 //! Heat flow rate through the wall (W).
185 /*!
186 * The heat flux is given by
187 * @f[
188 * Q = h A (T_{left} - T_{right}) + A G(t)
189 * @f]
190 * where *h* is the heat transfer coefficient, *A* is the wall area, and
191 * *G(t)* is a specified function of time evaluated at the current network
192 * time. Positive values denote a flux from left to right.
193 * @since New in %Cantera 3.0.
194 */
195 double heatRate() override;
196
197 //! Set the thermal resistance of the wall [K*m^2/W].
198 void setThermalResistance(double Rth) {
199 m_rrth = 1.0/Rth;
200 }
201
202 //! Set the overall heat transfer coefficient [W/m^2/K].
203 void setHeatTransferCoeff(double U) {
204 m_rrth = U;
205 }
206
207 //! Get the overall heat transfer coefficient [W/m^2/K].
208 double getHeatTransferCoeff() const {
209 return m_rrth;
210 }
211
212 //! Set the emissivity.
213 void setEmissivity(double epsilon) {
214 if (epsilon > 1.0 || epsilon < 0.0) {
215 throw CanteraError("WallBase::setEmissivity",
216 "emissivity must be between 0.0 and 1.0");
217 }
218 m_emiss = epsilon;
219 }
220
221 //! Get the emissivity.
222 double getEmissivity() const {
223 return m_emiss;
224 }
225
226 //! Set the expansion rate coefficient.
227 void setExpansionRateCoeff(double k) {
228 m_k = k;
229 }
230
231 //! Get the expansion rate coefficient
232 double getExpansionRateCoeff() const {
233 return m_k;
234 }
235
236 void addExpansionRateJacobian(SparseTriplets& trips, size_t row, double coeff,
237 bool includePressureSpecies=true) override;
238 void addHeatRateJacobian(SparseTriplets& trips, size_t row, double coeff) override;
239
240protected:
241
242 //! expansion rate coefficient
243 double m_k = 0.0;
244
245 //! heat transfer coefficient
246 double m_rrth = 0.0;
247
248 //! emissivity
249 double m_emiss = 0.0;
250
251 //! Velocity function
252 Func1* m_vf = nullptr;
253
254 //! Heat flux function
255 Func1* m_qf = nullptr;
256};
257
258}
259
260#endif
Base class for exceptions thrown by Cantera classes.
Base class for walls and flow devices connecting reactors.
string name() const
Retrieve connector name.
ConnectorNode(const string &name="(none)")
Transitional constructor.
Base class for 'functor' classes that evaluate a function of one variable.
Definition Func1.h:75
Base class for reactor objects.
Definition ReactorBase.h:51
Base class for 'walls' (walls, pistons, etc.) connecting reactors.
Definition Wall.h:24
virtual bool ready()
True if the wall is correctly configured and ready to use.
Definition Wall.h:67
virtual double expansionRate()
Rate of volume change (m^3/s) for the adjacent reactors at current reactor network time.
Definition Wall.h:41
virtual void addHeatRateJacobian(SparseTriplets &trips, size_t row, double coeff)
Add Jacobian terms proportional to derivatives of the wall heat rate.
Definition Wall.h:119
virtual void addExpansionRateJacobian(SparseTriplets &trips, size_t row, double coeff, bool includePressureSpecies=true)
Add Jacobian terms proportional to derivatives of the wall expansion rate.
Definition Wall.h:104
double m_time
current reactor network time
Definition Wall.h:126
ReactorBase & left() const
Return a reference to the Reactor or Reservoir to the left of the wall.
Definition Wall.h:72
void setSimTime(double time)
Set current reactor network time.
Definition Wall.h:85
string type() const override
String indicating the connector implemented.
Definition Wall.h:30
ReactorBase & right()
Return a reference to the Reactor or Reservoir to the right of the wall.
Definition Wall.h:77
virtual void initialize()
Called just before the start of integration.
Definition Wall.h:64
double area()
Area in (m^2).
Definition Wall.h:56
virtual void setArea(double a)
Set the area [m^2].
Definition Wall.cpp:26
virtual double heatRate()
Heat flow rate through the wall (W) at current reactor network time.
Definition Wall.h:51
Represents a wall between between two ReactorBase objects.
Definition Wall.h:138
void addHeatRateJacobian(SparseTriplets &trips, size_t row, double coeff) override
Add Jacobian terms proportional to derivatives of the wall heat rate.
Definition Wall.cpp:91
Func1 * m_vf
Velocity function.
Definition Wall.h:252
void addExpansionRateJacobian(SparseTriplets &trips, size_t row, double coeff, bool includePressureSpecies=true) override
Add Jacobian terms proportional to derivatives of the wall expansion rate.
Definition Wall.cpp:78
double getHeatTransferCoeff() const
Get the overall heat transfer coefficient [W/m^2/K].
Definition Wall.h:208
string type() const override
String indicating the wall model implemented.
Definition Wall.h:144
double heatFlux() const
Heat flux function evaluated at current reactor network time.
Definition Wall.cpp:51
void setExpansionRateCoeff(double k)
Set the expansion rate coefficient.
Definition Wall.h:227
void setEmissivity(double epsilon)
Set the emissivity.
Definition Wall.h:213
double heatRate() override
Heat flow rate through the wall (W).
Definition Wall.cpp:58
double m_rrth
heat transfer coefficient
Definition Wall.h:246
double getExpansionRateCoeff() const
Get the expansion rate coefficient.
Definition Wall.h:232
Func1 * m_qf
Heat flux function.
Definition Wall.h:255
void setVelocity(shared_ptr< Func1 > f)
Set the wall velocity to a specified function of time, .
Definition Wall.h:154
void setThermalResistance(double Rth)
Set the thermal resistance of the wall [K*m^2/W].
Definition Wall.h:198
double m_k
expansion rate coefficient
Definition Wall.h:243
double getEmissivity() const
Get the emissivity.
Definition Wall.h:222
double velocity() const
Wall velocity at current reactor network time.
Definition Wall.cpp:30
double expansionRate() override
Rate of volume change (m^3/s) for the adjacent reactors.
Definition Wall.cpp:37
double m_emiss
emissivity
Definition Wall.h:249
void setHeatTransferCoeff(double U)
Set the overall heat transfer coefficient [W/m^2/K].
Definition Wall.h:203
void setHeatFlux(shared_ptr< Func1 > q)
Specify the heat flux function .
Definition Wall.h:180
Definitions for the classes that are thrown when Cantera experiences an error condition (also contain...
Namespace for the Cantera kernel.
Definition AnyMap.cpp:595