Cantera  4.0.0a1
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_newSurfaceOfType(const char* model, int32_t phase, int32_t reactorsLen, const int32_t* reactors, int32_t clone, const char* name)
73 {
74 // constructor: shared_ptr<ReactorSurface> newReactorSurface(const string&, shared_ptr<Solution>, const vector<shared_ptr<ReactorBase>>&, bool, const string&)
75 try {
76 vector<shared_ptr<ReactorBase>> reactors_;
77 for (int i = 0; i < reactorsLen; i++) {
78 reactors_.push_back(ReactorBaseCabinet::at(reactors[i]));
79 }
80 bool clone_ = (clone != 0);
81 return ReactorBaseCabinet::add(newReactorSurface(model, SolutionCabinet::at(phase), reactors_, clone_, name));
82 } catch (...) {
83 return handleAllExceptions(-2, ERR);
84 }
85 }
86
87 int32_t reactor_type(int32_t handle, int32_t bufLen, char* buf)
88 {
89 // getter: virtual string ReactorBase::type()
90 try {
91 string out = ReactorBaseCabinet::at(handle)->type();
92 copyString(out, buf, bufLen);
93 return int(out.size()) + 1;
94 } catch (...) {
95 return handleAllExceptions(-1, ERR);
96 }
97 }
98
99 int32_t reactor_name(int32_t handle, int32_t bufLen, char* buf)
100 {
101 // getter: string ReactorBase::name()
102 try {
103 string out = ReactorBaseCabinet::at(handle)->name();
104 copyString(out, buf, bufLen);
105 return int(out.size()) + 1;
106 } catch (...) {
107 return handleAllExceptions(-1, ERR);
108 }
109 }
110
111 int32_t reactor_setName(int32_t handle, const char* name)
112 {
113 // setter: void ReactorBase::setName(const string&)
114 try {
115 ReactorBaseCabinet::at(handle)->setName(name);
116 return 0;
117 } catch (...) {
118 return handleAllExceptions(-1, ERR);
119 }
120 }
121
122 int32_t reactor_phase(int32_t handle)
123 {
124 // accessor: shared_ptr<Solution> ReactorBase::phase()
125 try {
126 return SolutionCabinet::add(ReactorBaseCabinet::at(handle)->phase());
127 } catch (...) {
128 return handleAllExceptions(-2, ERR);
129 }
130 }
131
132 int32_t reactor_setInitialVolume(int32_t handle, double vol)
133 {
134 // setter: virtual void ReactorBase::setInitialVolume(double)
135 try {
136 ReactorBaseCabinet::at(handle)->setInitialVolume(vol);
137 return 0;
138 } catch (...) {
139 return handleAllExceptions(-1, ERR);
140 }
141 }
142
143 double reactor_area(int32_t handle)
144 {
145 // getter: virtual double ReactorBase::area()
146 try {
147 return ReactorBaseCabinet::at(handle)->area();
148 } catch (...) {
149 return handleAllExceptions(DERR, DERR);
150 }
151 }
152
153 int32_t reactor_setArea(int32_t handle, double a)
154 {
155 // setter: virtual void ReactorBase::setArea(double)
156 try {
157 ReactorBaseCabinet::at(handle)->setArea(a);
158 return 0;
159 } catch (...) {
160 return handleAllExceptions(-1, ERR);
161 }
162 }
163
164 int32_t reactor_chemistryEnabled(int32_t handle)
165 {
166 // getter: virtual bool ReactorBase::chemistryEnabled()
167 try {
168 bool out = ReactorBaseCabinet::at(handle)->chemistryEnabled();
169 return int(out);
170 } catch (...) {
171 return handleAllExceptions(-1, ERR);
172 }
173 }
174
175 int32_t reactor_setChemistryEnabled(int32_t handle, int32_t cflag)
176 {
177 // setter: virtual void ReactorBase::setChemistryEnabled(bool)
178 try {
179 bool cflag_ = (cflag != 0);
180 ReactorBaseCabinet::at(handle)->setChemistryEnabled(cflag_);
181 return 0;
182 } catch (...) {
183 return handleAllExceptions(-1, ERR);
184 }
185 }
186
187 int32_t reactor_energyEnabled(int32_t handle)
188 {
189 // getter: virtual bool ReactorBase::energyEnabled()
190 try {
191 bool out = ReactorBaseCabinet::at(handle)->energyEnabled();
192 return int(out);
193 } catch (...) {
194 return handleAllExceptions(-1, ERR);
195 }
196 }
197
198 int32_t reactor_setEnergyEnabled(int32_t handle, int32_t eflag)
199 {
200 // setter: virtual void ReactorBase::setEnergyEnabled(bool)
201 try {
202 bool eflag_ = (eflag != 0);
203 ReactorBaseCabinet::at(handle)->setEnergyEnabled(eflag_);
204 return 0;
205 } catch (...) {
206 return handleAllExceptions(-1, ERR);
207 }
208 }
209
210 double reactor_mass(int32_t handle)
211 {
212 // getter: double ReactorBase::mass()
213 try {
214 return ReactorBaseCabinet::at(handle)->mass();
215 } catch (...) {
216 return handleAllExceptions(DERR, DERR);
217 }
218 }
219
220 double reactor_volume(int32_t handle)
221 {
222 // getter: double ReactorBase::volume()
223 try {
224 return ReactorBaseCabinet::at(handle)->volume();
225 } catch (...) {
226 return handleAllExceptions(DERR, DERR);
227 }
228 }
229
230 double reactor_density(int32_t handle)
231 {
232 // getter: double ReactorBase::density()
233 try {
234 return ReactorBaseCabinet::at(handle)->density();
235 } catch (...) {
236 return handleAllExceptions(DERR, DERR);
237 }
238 }
239
240 double reactor_temperature(int32_t handle)
241 {
242 // getter: double ReactorBase::temperature()
243 try {
244 return ReactorBaseCabinet::at(handle)->temperature();
245 } catch (...) {
246 return handleAllExceptions(DERR, DERR);
247 }
248 }
249
250 double reactor_enthalpy_mass(int32_t handle)
251 {
252 // getter: double ReactorBase::enthalpy_mass()
253 try {
254 return ReactorBaseCabinet::at(handle)->enthalpy_mass();
255 } catch (...) {
256 return handleAllExceptions(DERR, DERR);
257 }
258 }
259
260 double reactor_pressure(int32_t handle)
261 {
262 // getter: double ReactorBase::pressure()
263 try {
264 return ReactorBaseCabinet::at(handle)->pressure();
265 } catch (...) {
266 return handleAllExceptions(DERR, DERR);
267 }
268 }
269
270 double reactor_massFraction(int32_t handle, int32_t k)
271 {
272 // method: double ReactorBase::massFraction(size_t)
273 try {
274 return ReactorBaseCabinet::at(handle)->massFraction(k);
275 } catch (...) {
276 return handleAllExceptions(DERR, DERR);
277 }
278 }
279
280 int32_t reactor_massFractions(int32_t handle, int32_t bufLen, double* buf)
281 {
282 // getter: const double* ReactorBase::massFractions()
283 try {
284 auto out = ReactorBaseCabinet::at(handle)->massFractions();
285 std::copy(out, out + bufLen, buf);
286 return bufLen;
287 } catch (...) {
288 return handleAllExceptions(-1, ERR);
289 }
290 }
291
292 int32_t reactor_nSensParams(int32_t handle)
293 {
294 // size getter: virtual size_t ReactorBase::nSensParams()
295 try {
296 return static_cast<int32_t>(ReactorBaseCabinet::at(handle)->nSensParams());
297 } catch (...) {
298 return handleAllExceptions(ERR, ERR);
299 }
300 }
301
302 int32_t reactor_addSensitivityReaction(int32_t handle, int32_t rxn)
303 {
304 // setter: virtual void ReactorBase::addSensitivityReaction(size_t)
305 try {
306 ReactorBaseCabinet::at(handle)->addSensitivityReaction(rxn);
307 return 0;
308 } catch (...) {
309 return handleAllExceptions(-1, ERR);
310 }
311 }
312
313 double reactor_massFlowRate(int32_t handle)
314 {
315 // getter: double FlowReactor::massFlowRate()
316 try {
317 return ReactorBaseCabinet::as<FlowReactor>(handle)->massFlowRate();
318 } catch (...) {
319 return handleAllExceptions(DERR, DERR);
320 }
321 }
322
323 int32_t reactor_setMassFlowRate(int32_t handle, double mdot)
324 {
325 // setter: void FlowReactor::setMassFlowRate(double)
326 try {
327 ReactorBaseCabinet::as<FlowReactor>(handle)->setMassFlowRate(mdot);
328 return 0;
329 } catch (...) {
330 return handleAllExceptions(-1, ERR);
331 }
332 }
333
334 int32_t reactor_del(int32_t handle)
335 {
336 // destructor
337 try {
338 ReactorBaseCabinet::del(handle);
339 return 0;
340 } catch (...) {
341 return handleAllExceptions(-1, ERR);
342 }
343 }
344
346 {
347 // reserved CLib function: custom code
348 try {
349 // *************** begin custom code ***************
350 return ReactorBaseCabinet::size();
351 // **************** end custom code ****************
352 } catch (...) {
353 return handleAllExceptions(-1, ERR);
354 }
355 }
356
357} // extern "C"
Header file for class ReactorSurface.
Template for classes to hold pointers to objects.
Definition Cabinet.h:51
CTREACTOR - Generated CLib Cantera interface library.
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.
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.
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_newSurfaceOfType(const char *model, 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:72
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
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:87
int32_t reactor_name(int32_t handle, int32_t bufLen, char *buf)
Return the name of this reactor.
Definition ctreactor.cpp:99
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...
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.