Cantera  4.0.0a1
Loading...
Searching...
No Matches
ctkin.cpp
Go to the documentation of this file.
1/**
2 * CTKIN - Generated CLib %Cantera interface library.
3 *
4 * @file ctkin.cpp
5 *
6 * Generated CLib API for Cantera's Kinetics 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"
19#include "cantera_clib/ctkin.h"
20
27
28using namespace Cantera;
29
30//! @cond
31//! Cabinet type definitions will be ignored by Doxygen
32
33// Define Cabinet<Kinetics> (single-instance object)
34typedef Cabinet<Kinetics> KineticsCabinet;
35template<> KineticsCabinet* KineticsCabinet::s_storage = 0; // initialized here
36
37typedef Cabinet<ThermoPhase> ThermoPhaseCabinet;
38template<> ThermoPhaseCabinet* ThermoPhaseCabinet::s_storage; // initialized elsewhere
39
40typedef Cabinet<Reaction> ReactionCabinet;
41template<> ReactionCabinet* ReactionCabinet::s_storage; // initialized elsewhere
42
43//! @endcond
44
45extern "C" {
46
47 int32_t kin_kineticsType(int32_t handle, int32_t bufLen, char* buf)
48 {
49 // getter: virtual string Kinetics::kineticsType()
50 try {
51 string out = KineticsCabinet::at(handle)->kineticsType();
52 copyString(out, buf, bufLen);
53 return int(out.size()) + 1;
54 } catch (...) {
55 return handleAllExceptions(-1, ERR);
56 }
57 }
58
59 int32_t kin_nReactions(int32_t handle)
60 {
61 // size getter: size_t Kinetics::nReactions()
62 try {
63 return static_cast<int32_t>(KineticsCabinet::at(handle)->nReactions());
64 } catch (...) {
65 return handleAllExceptions(ERR, ERR);
66 }
67 }
68
69 int32_t kin_reaction(int32_t handle, int32_t i)
70 {
71 // accessor: shared_ptr<Reaction> Kinetics::reaction(size_t)
72 try {
73 if (i < 0 || static_cast<size_t>(i) >= KineticsCabinet::at(handle)->nReactions()) {
74 throw IndexError("kin_reaction", "", i, KineticsCabinet::at(handle)->nReactions());
75 }
76 return ReactionCabinet::add(KineticsCabinet::at(handle)->reaction(i));
77 } catch (...) {
78 return handleAllExceptions(-2, ERR);
79 }
80 }
81
82 int32_t kin_nPhases(int32_t handle)
83 {
84 // size getter: size_t Kinetics::nPhases()
85 try {
86 return static_cast<int32_t>(KineticsCabinet::at(handle)->nPhases());
87 } catch (...) {
88 return handleAllExceptions(ERR, ERR);
89 }
90 }
91
92 int32_t kin_phase(int32_t handle, int32_t n)
93 {
94 // accessor: shared_ptr<ThermoPhase> Kinetics::phase(size_t)
95 try {
96 if (n < 0 || static_cast<size_t>(n) >= KineticsCabinet::at(handle)->nPhases()) {
97 throw IndexError("kin_phase", "", n, KineticsCabinet::at(handle)->nPhases());
98 }
99 return ThermoPhaseCabinet::add(KineticsCabinet::at(handle)->phase(n));
100 } catch (...) {
101 return handleAllExceptions(-2, ERR);
102 }
103 }
104
105 int32_t kin_reactionPhase(int32_t handle)
106 {
107 // accessor: shared_ptr<ThermoPhase> Kinetics::reactionPhase()
108 try {
109 return ThermoPhaseCabinet::add(KineticsCabinet::at(handle)->reactionPhase());
110 } catch (...) {
111 return handleAllExceptions(-2, ERR);
112 }
113 }
114
115 int32_t kin_phaseIndex(int32_t handle, const char* ph)
116 {
117 // method: custom code
118 try {
119 // *************** begin custom code ***************
120 return static_cast<int32_t>(KineticsCabinet::at(handle)->phaseIndex(ph, true));
121 // **************** end custom code ****************
122 } catch (...) {
123 return handleAllExceptions(-1, ERR);
124 }
125 }
126
127 int32_t kin_nTotalSpecies(int32_t handle)
128 {
129 // size getter: size_t Kinetics::nTotalSpecies()
130 try {
131 return static_cast<int32_t>(KineticsCabinet::at(handle)->nTotalSpecies());
132 } catch (...) {
133 return handleAllExceptions(ERR, ERR);
134 }
135 }
136
137 double kin_reactantStoichCoeff(int32_t handle, int32_t k, int32_t i)
138 {
139 // method: virtual double Kinetics::reactantStoichCoeff(size_t, size_t)
140 try {
141 return KineticsCabinet::at(handle)->reactantStoichCoeff(k, i);
142 } catch (...) {
143 return handleAllExceptions(DERR, DERR);
144 }
145 }
146
147 double kin_productStoichCoeff(int32_t handle, int32_t k, int32_t i)
148 {
149 // method: virtual double Kinetics::productStoichCoeff(size_t, size_t)
150 try {
151 return KineticsCabinet::at(handle)->productStoichCoeff(k, i);
152 } catch (...) {
153 return handleAllExceptions(DERR, DERR);
154 }
155 }
156
157 int32_t kin_getFwdRatesOfProgress(int32_t handle, int32_t fwdROPLen, double* fwdROP)
158 {
159 // array getter: virtual void Kinetics::getFwdRatesOfProgress(span<double>)
160 try {
161 auto& obj = KineticsCabinet::at(handle);
162 // no size checking specified
163 span<double> fwdROP_(fwdROP, fwdROPLen);
164 obj->getFwdRatesOfProgress(fwdROP_);
165 return 0;
166 } catch (...) {
167 return handleAllExceptions(-1, ERR);
168 }
169 }
170
171 int32_t kin_getRevRatesOfProgress(int32_t handle, int32_t revROPLen, double* revROP)
172 {
173 // array getter: virtual void Kinetics::getRevRatesOfProgress(span<double>)
174 try {
175 auto& obj = KineticsCabinet::at(handle);
176 // no size checking specified
177 span<double> revROP_(revROP, revROPLen);
178 obj->getRevRatesOfProgress(revROP_);
179 return 0;
180 } catch (...) {
181 return handleAllExceptions(-1, ERR);
182 }
183 }
184
185 int32_t kin_getNetRatesOfProgress(int32_t handle, int32_t netROPLen, double* netROP)
186 {
187 // array getter: virtual void Kinetics::getNetRatesOfProgress(span<double>)
188 try {
189 auto& obj = KineticsCabinet::at(handle);
190 // no size checking specified
191 span<double> netROP_(netROP, netROPLen);
192 obj->getNetRatesOfProgress(netROP_);
193 return 0;
194 } catch (...) {
195 return handleAllExceptions(-1, ERR);
196 }
197 }
198
199 int32_t kin_getEquilibriumConstants(int32_t handle, int32_t kcLen, double* kc)
200 {
201 // array getter: virtual void Kinetics::getEquilibriumConstants(span<double>)
202 try {
203 auto& obj = KineticsCabinet::at(handle);
204 // no size checking specified
205 span<double> kc_(kc, kcLen);
206 obj->getEquilibriumConstants(kc_);
207 return 0;
208 } catch (...) {
209 return handleAllExceptions(-1, ERR);
210 }
211 }
212
213 int32_t kin_getFwdRateConstants(int32_t handle, int32_t kfwdLen, double* kfwd)
214 {
215 // array getter: virtual void Kinetics::getFwdRateConstants(span<double>)
216 try {
217 auto& obj = KineticsCabinet::at(handle);
218 // no size checking specified
219 span<double> kfwd_(kfwd, kfwdLen);
220 obj->getFwdRateConstants(kfwd_);
221 return 0;
222 } catch (...) {
223 return handleAllExceptions(-1, ERR);
224 }
225 }
226
227 int32_t kin_getRevRateConstants(int32_t handle, int32_t krevLen, double* krev, int32_t doIrreversible)
228 {
229 // method: virtual void Kinetics::getRevRateConstants(span<double>, bool)
230 try {
231 span<double> krev_(krev, krevLen);
232 bool doIrreversible_ = (doIrreversible != 0);
233 KineticsCabinet::at(handle)->getRevRateConstants(krev_, doIrreversible_);
234 return 0;
235 } catch (...) {
236 return handleAllExceptions(-1, ERR);
237 }
238 }
239
240 int32_t kin_getCreationRates(int32_t handle, int32_t cdotLen, double* cdot)
241 {
242 // array getter: virtual void Kinetics::getCreationRates(span<double>)
243 try {
244 auto& obj = KineticsCabinet::at(handle);
245 // no size checking specified
246 span<double> cdot_(cdot, cdotLen);
247 obj->getCreationRates(cdot_);
248 return 0;
249 } catch (...) {
250 return handleAllExceptions(-1, ERR);
251 }
252 }
253
254 int32_t kin_getDestructionRates(int32_t handle, int32_t ddotLen, double* ddot)
255 {
256 // array getter: virtual void Kinetics::getDestructionRates(span<double>)
257 try {
258 auto& obj = KineticsCabinet::at(handle);
259 // no size checking specified
260 span<double> ddot_(ddot, ddotLen);
261 obj->getDestructionRates(ddot_);
262 return 0;
263 } catch (...) {
264 return handleAllExceptions(-1, ERR);
265 }
266 }
267
268 int32_t kin_getNetProductionRates(int32_t handle, int32_t wdotLen, double* wdot)
269 {
270 // array getter: virtual void Kinetics::getNetProductionRates(span<double>)
271 try {
272 auto& obj = KineticsCabinet::at(handle);
273 // no size checking specified
274 span<double> wdot_(wdot, wdotLen);
275 obj->getNetProductionRates(wdot_);
276 return 0;
277 } catch (...) {
278 return handleAllExceptions(-1, ERR);
279 }
280 }
281
282 double kin_multiplier(int32_t handle, int32_t i)
283 {
284 // method: double Kinetics::multiplier(size_t)
285 try {
286 return KineticsCabinet::at(handle)->multiplier(i);
287 } catch (...) {
288 return handleAllExceptions(DERR, DERR);
289 }
290 }
291
292 int32_t kin_setMultiplier(int32_t handle, int32_t i, double f)
293 {
294 // method: virtual void Kinetics::setMultiplier(size_t, double)
295 try {
296 KineticsCabinet::at(handle)->setMultiplier(i, f);
297 return 0;
298 } catch (...) {
299 return handleAllExceptions(-1, ERR);
300 }
301 }
302
303 int32_t kin_isReversible(int32_t handle, int32_t i)
304 {
305 // method: bool Kinetics::isReversible(size_t)
306 try {
307 bool out = KineticsCabinet::at(handle)->isReversible(i);
308 return int(out);
309 } catch (...) {
310 return handleAllExceptions(-1, ERR);
311 }
312 }
313
314 int32_t kin_kineticsSpeciesIndex(int32_t handle, const char* nm)
315 {
316 // method: custom code
317 try {
318 // *************** begin custom code ***************
319 return static_cast<int32_t>(KineticsCabinet::at(handle)->kineticsSpeciesIndex(nm, true));
320 // **************** end custom code ****************
321 } catch (...) {
322 return handleAllExceptions(-1, ERR);
323 }
324 }
325
326 int32_t kin_advanceCoverages(int32_t handle, double tstep)
327 {
328 // setter: void InterfaceKinetics::advanceCoverages(double)
329 try {
330 KineticsCabinet::as<InterfaceKinetics>(handle)->advanceCoverages(tstep);
331 return 0;
332 } catch (...) {
333 return handleAllExceptions(-1, ERR);
334 }
335 }
336
337 int32_t kin_getDeltaEnthalpy(int32_t handle, int32_t deltaHLen, double* deltaH)
338 {
339 // array getter: virtual void Kinetics::getDeltaEnthalpy(span<double>)
340 try {
341 auto& obj = KineticsCabinet::at(handle);
342 // no size checking specified
343 span<double> deltaH_(deltaH, deltaHLen);
344 obj->getDeltaEnthalpy(deltaH_);
345 return 0;
346 } catch (...) {
347 return handleAllExceptions(-1, ERR);
348 }
349 }
350
351 int32_t kin_getDeltaGibbs(int32_t handle, int32_t deltaGLen, double* deltaG)
352 {
353 // array getter: virtual void Kinetics::getDeltaGibbs(span<double>)
354 try {
355 auto& obj = KineticsCabinet::at(handle);
356 // no size checking specified
357 span<double> deltaG_(deltaG, deltaGLen);
358 obj->getDeltaGibbs(deltaG_);
359 return 0;
360 } catch (...) {
361 return handleAllExceptions(-1, ERR);
362 }
363 }
364
365 int32_t kin_getDeltaEntropy(int32_t handle, int32_t deltaSLen, double* deltaS)
366 {
367 // array getter: virtual void Kinetics::getDeltaEntropy(span<double>)
368 try {
369 auto& obj = KineticsCabinet::at(handle);
370 // no size checking specified
371 span<double> deltaS_(deltaS, deltaSLen);
372 obj->getDeltaEntropy(deltaS_);
373 return 0;
374 } catch (...) {
375 return handleAllExceptions(-1, ERR);
376 }
377 }
378
379 int32_t kin_getDeltaSSEnthalpy(int32_t handle, int32_t deltaHLen, double* deltaH)
380 {
381 // array getter: virtual void Kinetics::getDeltaSSEnthalpy(span<double>)
382 try {
383 auto& obj = KineticsCabinet::at(handle);
384 // no size checking specified
385 span<double> deltaH_(deltaH, deltaHLen);
386 obj->getDeltaSSEnthalpy(deltaH_);
387 return 0;
388 } catch (...) {
389 return handleAllExceptions(-1, ERR);
390 }
391 }
392
393 int32_t kin_getDeltaSSGibbs(int32_t handle, int32_t deltaGLen, double* deltaG)
394 {
395 // array getter: virtual void Kinetics::getDeltaSSGibbs(span<double>)
396 try {
397 auto& obj = KineticsCabinet::at(handle);
398 // no size checking specified
399 span<double> deltaG_(deltaG, deltaGLen);
400 obj->getDeltaSSGibbs(deltaG_);
401 return 0;
402 } catch (...) {
403 return handleAllExceptions(-1, ERR);
404 }
405 }
406
407 int32_t kin_getDeltaSSEntropy(int32_t handle, int32_t deltaSLen, double* deltaS)
408 {
409 // array getter: virtual void Kinetics::getDeltaSSEntropy(span<double>)
410 try {
411 auto& obj = KineticsCabinet::at(handle);
412 // no size checking specified
413 span<double> deltaS_(deltaS, deltaSLen);
414 obj->getDeltaSSEntropy(deltaS_);
415 return 0;
416 } catch (...) {
417 return handleAllExceptions(-1, ERR);
418 }
419 }
420
421 int32_t kin_del(int32_t handle)
422 {
423 // destructor
424 try {
425 KineticsCabinet::del(handle);
426 return 0;
427 } catch (...) {
428 return handleAllExceptions(-1, ERR);
429 }
430 }
431
433 {
434 // reserved CLib function: custom code
435 try {
436 // *************** begin custom code ***************
437 return KineticsCabinet::size();
438 // **************** end custom code ****************
439 } catch (...) {
440 return handleAllExceptions(-1, ERR);
441 }
442 }
443
444} // extern "C"
Header for a simple thermodynamics model of a surface phase derived from ThermoPhase,...
Headers for the factory class that can create known ThermoPhase objects (see Thermodynamic Properties...
Template for classes to hold pointers to objects.
Definition Cabinet.h:51
An array index is out of range.
CTKIN - Generated CLib Cantera interface library.
int32_t kin_getDeltaGibbs(int32_t handle, int32_t deltaGLen, double *deltaG)
Return the vector of values for the reaction Gibbs free energy change.
Definition ctkin.cpp:351
int32_t kin_setMultiplier(int32_t handle, int32_t i, double f)
Set the multiplier for reaction i to f.
Definition ctkin.cpp:292
int32_t kin_del(int32_t handle)
Delete Kinetics object.
Definition ctkin.cpp:421
int32_t kin_reaction(int32_t handle, int32_t i)
Return the Reaction object for reaction i.
Definition ctkin.cpp:69
int32_t kin_nPhases(int32_t handle)
The number of phases participating in the reaction mechanism.
Definition ctkin.cpp:82
int32_t kin_reactionPhase(int32_t handle)
Return pointer to phase where the reactions occur.
Definition ctkin.cpp:105
double kin_productStoichCoeff(int32_t handle, int32_t k, int32_t i)
Stoichiometric coefficient of species k as a product in reaction i.
Definition ctkin.cpp:147
int32_t kin_getEquilibriumConstants(int32_t handle, int32_t kcLen, double *kc)
Return a vector of Equilibrium constants.
Definition ctkin.cpp:199
int32_t kin_getRevRatesOfProgress(int32_t handle, int32_t revROPLen, double *revROP)
Return the Reverse rates of progress of the reactions.
Definition ctkin.cpp:171
int32_t kin_getDestructionRates(int32_t handle, int32_t ddotLen, double *ddot)
Species destruction rates [kmol/m^3/s or kmol/m^2/s].
Definition ctkin.cpp:254
int32_t kin_advanceCoverages(int32_t handle, double tstep)
Advance the surface coverages in time.
Definition ctkin.cpp:326
int32_t kin_phase(int32_t handle, int32_t n)
Return pointer to phase associated with Kinetics by index.
Definition ctkin.cpp:92
int32_t kin_getRevRateConstants(int32_t handle, int32_t krevLen, double *krev, int32_t doIrreversible)
Return the reverse rate constants.
Definition ctkin.cpp:227
int32_t kin_getDeltaEntropy(int32_t handle, int32_t deltaSLen, double *deltaS)
Return the vector of values for the reactions change in entropy.
Definition ctkin.cpp:365
int32_t kin_getDeltaEnthalpy(int32_t handle, int32_t deltaHLen, double *deltaH)
Return the vector of values for the reactions change in enthalpy.
Definition ctkin.cpp:337
int32_t kin_kineticsType(int32_t handle, int32_t bufLen, char *buf)
Identifies the Kinetics manager type.
Definition ctkin.cpp:47
int32_t kin_getCreationRates(int32_t handle, int32_t cdotLen, double *cdot)
Species creation rates [kmol/m^3/s or kmol/m^2/s].
Definition ctkin.cpp:240
int32_t kin_phaseIndex(int32_t handle, const char *ph)
Return the phase index of a phase in the list of phases defined within the object.
Definition ctkin.cpp:115
int32_t kin_getDeltaSSEnthalpy(int32_t handle, int32_t deltaHLen, double *deltaH)
Return the vector of values for the change in the standard state enthalpies of reaction.
Definition ctkin.cpp:379
int32_t kin_getDeltaSSGibbs(int32_t handle, int32_t deltaGLen, double *deltaG)
Return the vector of values for the reaction standard state Gibbs free energy change.
Definition ctkin.cpp:393
int32_t kin_getNetProductionRates(int32_t handle, int32_t wdotLen, double *wdot)
Species net production rates [kmol/m^3/s or kmol/m^2/s].
Definition ctkin.cpp:268
double kin_reactantStoichCoeff(int32_t handle, int32_t k, int32_t i)
Stoichiometric coefficient of species k as a reactant in reaction i.
Definition ctkin.cpp:137
int32_t kin_getFwdRatesOfProgress(int32_t handle, int32_t fwdROPLen, double *fwdROP)
Return the forward rates of progress of the reactions.
Definition ctkin.cpp:157
int32_t kin_getDeltaSSEntropy(int32_t handle, int32_t deltaSLen, double *deltaS)
Return the vector of values for the change in the standard state entropies for each reaction.
Definition ctkin.cpp:407
int32_t kin_getNetRatesOfProgress(int32_t handle, int32_t netROPLen, double *netROP)
Net rates of progress.
Definition ctkin.cpp:185
int32_t kin_isReversible(int32_t handle, int32_t i)
True if reaction i has been declared to be reversible.
Definition ctkin.cpp:303
int32_t kin_nTotalSpecies(int32_t handle)
The total number of species in all phases participating in the kinetics mechanism.
Definition ctkin.cpp:127
int32_t kin_nReactions(int32_t handle)
Number of reactions in the reaction mechanism.
Definition ctkin.cpp:59
int32_t kin_kineticsSpeciesIndex(int32_t handle, const char *nm)
Return the index of a species within the phases participating in this kinetic mechanism.
Definition ctkin.cpp:314
int32_t kin_getFwdRateConstants(int32_t handle, int32_t kfwdLen, double *kfwd)
Return the forward rate constants.
Definition ctkin.cpp:213
int32_t kin_cabinetSize()
Return size of Kinetics storage.
Definition ctkin.cpp:432
double kin_multiplier(int32_t handle, int32_t i)
The current value of the multiplier for reaction i.
Definition ctkin.cpp:282
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.
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.