Cantera  3.2.0a5
Loading...
Searching...
No Matches
ctreactor.cpp
Go to the documentation of this file.
1/**
2 * CTREACTOR - Generated CLib %Cantera interface library.
3 *
4 * @file ctreactor.cpp
5 *
6 * Generated CLib API for Cantera's ReactorBase class.
7 *
8 * This file was generated by sourcegen. It will be re-generated by the
9 * %Cantera build process. Do not manually edit.
10 *
11 * @warning This module is an experimental part of the %Cantera API and
12 * may be changed without notice.
13 */
14
15// This file is part of Cantera. See License.txt in the top-level directory or
16// at https://cantera.org/license.txt for license and copyright information.
17
18#include "clib_utils.h"
20
26
27using namespace Cantera;
28
29//! @cond
30//! Cabinet type definitions will be ignored by Doxygen
31
32// Define Cabinet<ReactorBase> (single-instance object)
33typedef Cabinet<ReactorBase> ReactorBaseCabinet;
34template<> ReactorBaseCabinet* ReactorBaseCabinet::s_storage = 0; // initialized here
35
36typedef Cabinet<Solution> SolutionCabinet;
37template<> SolutionCabinet* SolutionCabinet::s_storage; // initialized elsewhere
38
39typedef Cabinet<ReactorSurface> ReactorSurfaceCabinet;
40template<> ReactorSurfaceCabinet* ReactorSurfaceCabinet::s_storage; // initialized elsewhere
41
42//! @endcond
43
44extern "C" {
45
46 int32_t reactor_new(const char* model, int32_t phase, int32_t clone, const char* name)
47 {
48 // constructor: shared_ptr<ReactorBase> newReactorBase(const string&, shared_ptr<Solution>, bool, const string&)
49 try {
50 bool clone_ = (clone != 0);
51 return ReactorBaseCabinet::add(newReactorBase(model, SolutionCabinet::at(phase), clone_, name));
52 } catch (...) {
53 return handleAllExceptions(-2, ERR);
54 }
55 }
56
57 int32_t reactor_newSurface(int32_t phase, int32_t reactorsLen, const int32_t* reactors, int32_t clone, const char* name)
58 {
59 // constructor: shared_ptr<ReactorSurface> newReactorSurface(shared_ptr<Solution>, const vector<shared_ptr<ReactorBase>>&, bool, const string&)
60 try {
61 vector<shared_ptr<ReactorBase>> reactors_;
62 for (int i = 0; i < reactorsLen; i++) {
63 reactors_.push_back(ReactorBaseCabinet::at(reactors[i]));
64 }
65 bool clone_ = (clone != 0);
66 return ReactorBaseCabinet::add(newReactorSurface(SolutionCabinet::at(phase), reactors_, clone_, name));
67 } catch (...) {
68 return handleAllExceptions(-2, ERR);
69 }
70 }
71
72 int32_t reactor_type(int32_t handle, int32_t bufLen, char* buf)
73 {
74 // getter: virtual string ReactorBase::type()
75 try {
76 string out = ReactorBaseCabinet::at(handle)->type();
77 copyString(out, buf, bufLen);
78 return int(out.size()) + 1;
79 } catch (...) {
80 return handleAllExceptions(-1, ERR);
81 }
82 }
83
84 int32_t reactor_name(int32_t handle, int32_t bufLen, char* buf)
85 {
86 // getter: string ReactorBase::name()
87 try {
88 string out = ReactorBaseCabinet::at(handle)->name();
89 copyString(out, buf, bufLen);
90 return int(out.size()) + 1;
91 } catch (...) {
92 return handleAllExceptions(-1, ERR);
93 }
94 }
95
96 int32_t reactor_setName(int32_t handle, const char* name)
97 {
98 // setter: void ReactorBase::setName(const string&)
99 try {
100 ReactorBaseCabinet::at(handle)->setName(name);
101 return 0;
102 } catch (...) {
103 return handleAllExceptions(-1, ERR);
104 }
105 }
106
107 int32_t reactor_phase(int32_t handle)
108 {
109 // accessor: shared_ptr<Solution> ReactorBase::phase()
110 try {
111 return SolutionCabinet::add(ReactorBaseCabinet::at(handle)->phase());
112 } catch (...) {
113 return handleAllExceptions(-2, ERR);
114 }
115 }
116
117 int32_t reactor_setInitialVolume(int32_t handle, double vol)
118 {
119 // setter: virtual void ReactorBase::setInitialVolume(double)
120 try {
121 ReactorBaseCabinet::at(handle)->setInitialVolume(vol);
122 return 0;
123 } catch (...) {
124 return handleAllExceptions(-1, ERR);
125 }
126 }
127
128 double reactor_area(int32_t handle)
129 {
130 // getter: virtual double ReactorBase::area()
131 try {
132 return ReactorBaseCabinet::at(handle)->area();
133 } catch (...) {
134 return handleAllExceptions(DERR, DERR);
135 }
136 }
137
138 int32_t reactor_setArea(int32_t handle, double a)
139 {
140 // setter: virtual void ReactorBase::setArea(double)
141 try {
142 ReactorBaseCabinet::at(handle)->setArea(a);
143 return 0;
144 } catch (...) {
145 return handleAllExceptions(-1, ERR);
146 }
147 }
148
149 int32_t reactor_chemistryEnabled(int32_t handle)
150 {
151 // getter: virtual bool ReactorBase::chemistryEnabled()
152 try {
153 bool out = ReactorBaseCabinet::at(handle)->chemistryEnabled();
154 return int(out);
155 } catch (...) {
156 return handleAllExceptions(-1, ERR);
157 }
158 }
159
160 int32_t reactor_setChemistryEnabled(int32_t handle, int32_t cflag)
161 {
162 // setter: virtual void ReactorBase::setChemistryEnabled(bool)
163 try {
164 bool cflag_ = (cflag != 0);
165 ReactorBaseCabinet::at(handle)->setChemistryEnabled(cflag_);
166 return 0;
167 } catch (...) {
168 return handleAllExceptions(-1, ERR);
169 }
170 }
171
172 int32_t reactor_energyEnabled(int32_t handle)
173 {
174 // getter: virtual bool ReactorBase::energyEnabled()
175 try {
176 bool out = ReactorBaseCabinet::at(handle)->energyEnabled();
177 return int(out);
178 } catch (...) {
179 return handleAllExceptions(-1, ERR);
180 }
181 }
182
183 int32_t reactor_setEnergyEnabled(int32_t handle, int32_t eflag)
184 {
185 // setter: virtual void ReactorBase::setEnergyEnabled(bool)
186 try {
187 bool eflag_ = (eflag != 0);
188 ReactorBaseCabinet::at(handle)->setEnergyEnabled(eflag_);
189 return 0;
190 } catch (...) {
191 return handleAllExceptions(-1, ERR);
192 }
193 }
194
195 double reactor_mass(int32_t handle)
196 {
197 // getter: double ReactorBase::mass()
198 try {
199 return ReactorBaseCabinet::at(handle)->mass();
200 } catch (...) {
201 return handleAllExceptions(DERR, DERR);
202 }
203 }
204
205 double reactor_volume(int32_t handle)
206 {
207 // getter: double ReactorBase::volume()
208 try {
209 return ReactorBaseCabinet::at(handle)->volume();
210 } catch (...) {
211 return handleAllExceptions(DERR, DERR);
212 }
213 }
214
215 double reactor_density(int32_t handle)
216 {
217 // getter: double ReactorBase::density()
218 try {
219 return ReactorBaseCabinet::at(handle)->density();
220 } catch (...) {
221 return handleAllExceptions(DERR, DERR);
222 }
223 }
224
225 double reactor_temperature(int32_t handle)
226 {
227 // getter: double ReactorBase::temperature()
228 try {
229 return ReactorBaseCabinet::at(handle)->temperature();
230 } catch (...) {
231 return handleAllExceptions(DERR, DERR);
232 }
233 }
234
235 double reactor_enthalpy_mass(int32_t handle)
236 {
237 // getter: double ReactorBase::enthalpy_mass()
238 try {
239 return ReactorBaseCabinet::at(handle)->enthalpy_mass();
240 } catch (...) {
241 return handleAllExceptions(DERR, DERR);
242 }
243 }
244
245 double reactor_intEnergy_mass(int32_t handle)
246 {
247 // getter: double ReactorBase::intEnergy_mass()
248 try {
249 return ReactorBaseCabinet::at(handle)->intEnergy_mass();
250 } catch (...) {
251 return handleAllExceptions(DERR, DERR);
252 }
253 }
254
255 double reactor_pressure(int32_t handle)
256 {
257 // getter: double ReactorBase::pressure()
258 try {
259 return ReactorBaseCabinet::at(handle)->pressure();
260 } catch (...) {
261 return handleAllExceptions(DERR, DERR);
262 }
263 }
264
265 double reactor_massFraction(int32_t handle, int32_t k)
266 {
267 // method: double ReactorBase::massFraction(size_t)
268 try {
269 return ReactorBaseCabinet::at(handle)->massFraction(k);
270 } catch (...) {
271 return handleAllExceptions(DERR, DERR);
272 }
273 }
274
275 int32_t reactor_massFractions(int32_t handle, int32_t bufLen, double* buf)
276 {
277 // getter: const double* ReactorBase::massFractions()
278 try {
279 auto out = ReactorBaseCabinet::at(handle)->massFractions();
280 std::copy(out, out + bufLen, buf);
281 return bufLen;
282 } catch (...) {
283 return handleAllExceptions(-1, ERR);
284 }
285 }
286
287 int32_t reactor_nSensParams(int32_t handle)
288 {
289 // size getter: virtual size_t ReactorBase::nSensParams()
290 try {
291 return static_cast<int32_t>(ReactorBaseCabinet::at(handle)->nSensParams());
292 } catch (...) {
293 return handleAllExceptions(ERR, ERR);
294 }
295 }
296
297 int32_t reactor_addSensitivityReaction(int32_t handle, int32_t rxn)
298 {
299 // setter: virtual void ReactorBase::addSensitivityReaction(size_t)
300 try {
301 ReactorBaseCabinet::at(handle)->addSensitivityReaction(rxn);
302 return 0;
303 } catch (...) {
304 return handleAllExceptions(-1, ERR);
305 }
306 }
307
308 int32_t reactor_addSurface(int32_t handle, int32_t surf)
309 {
310 // setter: void ReactorBase::addSurface(shared_ptr<ReactorBase>)
311 try {
312 ReactorBaseCabinet::at(handle)->addSurface(ReactorBaseCabinet::at(surf));
313 return 0;
314 } catch (...) {
315 return handleAllExceptions(-1, ERR);
316 }
317 }
318
319 double reactor_massFlowRate(int32_t handle)
320 {
321 // getter: double FlowReactor::massFlowRate()
322 try {
323 return ReactorBaseCabinet::as<FlowReactor>(handle)->massFlowRate();
324 } catch (...) {
325 return handleAllExceptions(DERR, DERR);
326 }
327 }
328
329 int32_t reactor_setMassFlowRate(int32_t handle, double mdot)
330 {
331 // setter: void FlowReactor::setMassFlowRate(double)
332 try {
333 ReactorBaseCabinet::as<FlowReactor>(handle)->setMassFlowRate(mdot);
334 return 0;
335 } catch (...) {
336 return handleAllExceptions(-1, ERR);
337 }
338 }
339
340 int32_t reactor_del(int32_t handle)
341 {
342 // destructor
343 try {
344 ReactorBaseCabinet::del(handle);
345 return 0;
346 } catch (...) {
347 return handleAllExceptions(-1, ERR);
348 }
349 }
350
352 {
353 // reserved CLib function: custom code
354 try {
355 // *************** begin custom code ***************
356 return ReactorBaseCabinet::size();
357 // **************** end custom code ****************
358 } catch (...) {
359 return handleAllExceptions(-1, ERR);
360 }
361 }
362
363} // extern "C"
Header file for class ReactorSurface.
Template for classes to hold pointers to objects.
Definition Cabinet.h:51
int32_t reactor_nSensParams(int32_t handle)
Number of sensitivity parameters associated with this reactor.
int32_t reactor_phase(int32_t handle)
Access the Solution object used to represent the contents of this reactor.
double reactor_volume(int32_t handle)
Returns the current volume (m^3) of the reactor.
int32_t reactor_setName(int32_t handle, const char *name)
Set the name of this reactor.
Definition ctreactor.cpp:96
int32_t reactor_del(int32_t handle)
Delete ReactorBase object.
double reactor_massFlowRate(int32_t handle)
Mass flow rate through the reactor [kg/s].
double reactor_enthalpy_mass(int32_t handle)
Returns the current enthalpy (J/kg) of the reactor's contents.
int32_t reactor_energyEnabled(int32_t handle)
Returns true if solution of the energy equation is enabled.
int32_t reactor_setArea(int32_t handle, double a)
Set an area associated with a reactor [m²].
double reactor_pressure(int32_t handle)
Returns the current pressure (Pa) of the reactor.
int32_t reactor_addSurface(int32_t handle, int32_t surf)
Add a ReactorSurface object to a Reactor object.
double reactor_mass(int32_t handle)
Returns the mass (kg) of the reactor's contents.
int32_t reactor_new(const char *model, int32_t phase, int32_t clone, const char *name)
Create a ReactorBase object of the specified type and contents.
Definition ctreactor.cpp:46
int32_t reactor_massFractions(int32_t handle, int32_t bufLen, double *buf)
Return the vector of species mass fractions.
int32_t reactor_setMassFlowRate(int32_t handle, double mdot)
Set the mass flow rate through the reactor [kg/s].
int32_t reactor_setEnergyEnabled(int32_t handle, int32_t eflag)
Set the energy equation on or off.
int32_t reactor_chemistryEnabled(int32_t handle)
Returns true if changes in the reactor composition due to chemical reactions are enabled.
double reactor_area(int32_t handle)
Returns an area associated with a reactor [m²].
int32_t reactor_setInitialVolume(int32_t handle, double vol)
Set the initial reactor volume.
double reactor_temperature(int32_t handle)
Returns the current temperature (K) of the reactor's contents.
double reactor_massFraction(int32_t handle, int32_t k)
Return the mass fraction of the k-th species.
int32_t reactor_newSurface(int32_t phase, int32_t reactorsLen, const int32_t *reactors, int32_t clone, const char *name)
Create a ReactorSurface object with the specified contents and adjacent reactors participating in sur...
Definition ctreactor.cpp:57
double reactor_intEnergy_mass(int32_t handle)
Returns the current internal energy (J/kg) of the reactor's contents.
int32_t reactor_addSensitivityReaction(int32_t handle, int32_t rxn)
Add a sensitivity parameter associated with the reaction number rxn
double reactor_density(int32_t handle)
Returns the current density (kg/m^3) of the reactor's contents.
int32_t reactor_type(int32_t handle, int32_t bufLen, char *buf)
String indicating the reactor model implemented.
Definition ctreactor.cpp:72
int32_t reactor_name(int32_t handle, int32_t bufLen, char *buf)
Return the name of this reactor.
Definition ctreactor.cpp:84
int32_t reactor_setChemistryEnabled(int32_t handle, int32_t cflag)
Enable or disable changes in reactor composition due to chemical reactions.
int32_t reactor_cabinetSize()
Return size of ReactorBase storage.
size_t copyString(const string &source, char *dest, size_t length)
Copy the contents of a string into a char array of a given length.
shared_ptr< ReactorBase > newReactorBase(const string &model, shared_ptr< Solution > phase, bool clone, const string &name)
Create a ReactorBase object of the specified type and contents.
shared_ptr< ReactorSurface > newReactorSurface(shared_ptr< Solution > phase, const vector< shared_ptr< ReactorBase > > &reactors, bool clone, const string &name)
Create a ReactorSurface object with the specified contents and adjacent reactors participating in sur...
CTREACTOR - Generated CLib Cantera interface library.
Namespace for the Cantera kernel.
Definition AnyMap.cpp:595
T handleAllExceptions(T ctErrorCode, T otherErrorCode)
Exception handler used at language interface boundaries.
Definition clib_utils.h:32
Contains declarations for string manipulation functions within Cantera.