Cantera
Loading...
Searching...
No Matches
ctreactornet.cpp
Go to the documentation of this file.
1/**
2 * CTREACTORNET - Generated CLib %Cantera interface library.
3 *
4 * @file ctreactornet.cpp
5 *
6 * Generated CLib API for Cantera's ReactorNet 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
25
26using namespace Cantera;
27
28//! @cond
29//! Cabinet type definitions will be ignored by Doxygen
30
31// Define Cabinet<ReactorNet> (single-instance object)
32typedef Cabinet<ReactorNet> ReactorNetCabinet;
33template<> ReactorNetCabinet* ReactorNetCabinet::s_storage = 0; // initialized here
34
35typedef Cabinet<ReactorBase> ReactorBaseCabinet;
36template<> ReactorBaseCabinet* ReactorBaseCabinet::s_storage; // initialized elsewhere
37
38//! @endcond
39
40extern "C" {
41
42 int32_t reactornet_new(int32_t reactorsLen, int32_t* reactors)
43 {
44 // constructor: shared_ptr<ReactorNet> newReactorNet(span<shared_ptr<ReactorBase>>)
45 try {
46 vector<shared_ptr<ReactorBase>> reactors_;
47 for (int i = 0; i < reactorsLen; i++) {
48 reactors_.push_back(ReactorBaseCabinet::at(reactors[i]));
49 }
50 return ReactorNetCabinet::add(newReactorNet(reactors_));
51 } catch (...) {
52 return handleAllExceptions(-2, ERR);
53 }
54 }
55
56 int32_t reactornet_setInitialTime(int32_t handle, double time)
57 {
58 // setter: void ReactorNet::setInitialTime(double)
59 try {
60 ReactorNetCabinet::at(handle)->setInitialTime(time);
61 return 0;
62 } catch (...) {
63 return handleAllExceptions(-1, ERR);
64 }
65 }
66
67 int32_t reactornet_setMaxTimeStep(int32_t handle, double maxstep)
68 {
69 // setter: void ReactorNet::setMaxTimeStep(double)
70 try {
71 ReactorNetCabinet::at(handle)->setMaxTimeStep(maxstep);
72 return 0;
73 } catch (...) {
74 return handleAllExceptions(-1, ERR);
75 }
76 }
77
78 int32_t reactornet_setRelativeTolerance(int32_t handle, double rtol)
79 {
80 // setter: void ReactorNet::setRelativeTolerance(double)
81 try {
82 ReactorNetCabinet::at(handle)->setRelativeTolerance(rtol);
83 return 0;
84 } catch (...) {
85 return handleAllExceptions(-1, ERR);
86 }
87 }
88
89 int32_t reactornet_setAbsoluteTolerance(int32_t handle, double atol)
90 {
91 // setter: void ReactorNet::setAbsoluteTolerance(double)
92 try {
93 ReactorNetCabinet::at(handle)->setAbsoluteTolerance(atol);
94 return 0;
95 } catch (...) {
96 return handleAllExceptions(-1, ERR);
97 }
98 }
99
100 int32_t reactornet_clearAbsoluteTolerance(int32_t handle)
101 {
102 // method: void ReactorNet::clearAbsoluteTolerance()
103 try {
104 ReactorNetCabinet::at(handle)->clearAbsoluteTolerance();
105 return 0;
106 } catch (...) {
107 return handleAllExceptions(-1, ERR);
108 }
109 }
110
111 int32_t reactornet_setTolerances(int32_t handle, double rtol, double atol)
112 {
113 // method: void ReactorNet::setTolerances(double, double)
114 try {
115 ReactorNetCabinet::at(handle)->setTolerances(rtol, atol);
116 return 0;
117 } catch (...) {
118 return handleAllExceptions(-1, ERR);
119 }
120 }
121
122 int32_t reactornet_setSensitivityTolerances(int32_t handle, double rtol, double atol)
123 {
124 // method: void ReactorNet::setSensitivityTolerances(double, double)
125 try {
126 ReactorNetCabinet::at(handle)->setSensitivityTolerances(rtol, atol);
127 return 0;
128 } catch (...) {
129 return handleAllExceptions(-1, ERR);
130 }
131 }
132
133 int32_t reactornet_advance(int32_t handle, double t)
134 {
135 // setter: void ReactorNet::advance(double)
136 try {
137 ReactorNetCabinet::at(handle)->advance(t);
138 return 0;
139 } catch (...) {
140 return handleAllExceptions(-1, ERR);
141 }
142 }
143
144 double reactornet_step(int32_t handle)
145 {
146 // getter: double ReactorNet::step()
147 try {
148 return ReactorNetCabinet::at(handle)->step();
149 } catch (...) {
150 return handleAllExceptions(DERR, DERR);
151 }
152 }
153
154 double reactornet_time(int32_t handle)
155 {
156 // getter: double ReactorNet::time()
157 try {
158 return ReactorNetCabinet::at(handle)->time();
159 } catch (...) {
160 return handleAllExceptions(DERR, DERR);
161 }
162 }
163
164 double reactornet_rtol(int32_t handle)
165 {
166 // getter: double ReactorNet::rtol()
167 try {
168 return ReactorNetCabinet::at(handle)->rtol();
169 } catch (...) {
170 return handleAllExceptions(DERR, DERR);
171 }
172 }
173
174 double reactornet_atol(int32_t handle)
175 {
176 // getter: double ReactorNet::atol()
177 try {
178 return ReactorNetCabinet::at(handle)->atol();
179 } catch (...) {
180 return handleAllExceptions(DERR, DERR);
181 }
182 }
183
184 double reactornet_sensitivity(int32_t handle, int32_t k, int32_t p)
185 {
186 // method: double ReactorNet::sensitivity(size_t, size_t)
187 try {
188 return ReactorNetCabinet::at(handle)->sensitivity(k, p);
189 } catch (...) {
190 return handleAllExceptions(DERR, DERR);
191 }
192 }
193
194 double reactornet_sensitivityByName(int32_t handle, const char* component, int32_t p, int32_t reactor)
195 {
196 // method: double ReactorNet::sensitivity(const string&, size_t, int)
197 try {
198 return ReactorNetCabinet::at(handle)->sensitivity(component, p, reactor);
199 } catch (...) {
200 return handleAllExceptions(DERR, DERR);
201 }
202 }
203
204 int32_t reactornet_neq(int32_t handle)
205 {
206 // size getter: size_t ReactorNet::neq()
207 try {
208 return static_cast<int32_t>(ReactorNetCabinet::at(handle)->neq());
209 } catch (...) {
210 return handleAllExceptions(ERR, ERR);
211 }
212 }
213
214 int32_t reactornet_getState(int32_t handle, int32_t yLen, double* y)
215 {
216 // array getter: void ReactorNet::getState(span<double>)
217 try {
218 auto& obj = ReactorNetCabinet::at(handle);
219 // no size checking specified
220 span<double> y_(y, yLen);
221 obj->getState(y_);
222 return 0;
223 } catch (...) {
224 return handleAllExceptions(-1, ERR);
225 }
226 }
227
228 int32_t reactornet_componentName(int32_t handle, int32_t i, int32_t bufLen, char* buf)
229 {
230 // method: string ReactorNet::componentName(size_t)
231 try {
232 string out = ReactorNetCabinet::at(handle)->componentName(i);
233 copyString(out, buf, bufLen);
234 return int(out.size()) + 1;
235 } catch (...) {
236 return handleAllExceptions(-1, ERR);
237 }
238 }
239
240 int32_t reactornet_globalComponentIndex(int32_t handle, const char* component, int32_t reactor)
241 {
242 // size getter: size_t ReactorNet::globalComponentIndex(const string&, size_t)
243 try {
244 return static_cast<int32_t>(ReactorNetCabinet::at(handle)->globalComponentIndex(component, reactor));
245 } catch (...) {
246 return handleAllExceptions(ERR, ERR);
247 }
248 }
249
250 int32_t reactornet_del(int32_t handle)
251 {
252 // destructor
253 try {
254 ReactorNetCabinet::del(handle);
255 return 0;
256 } catch (...) {
257 return handleAllExceptions(-1, ERR);
258 }
259 }
260
262 {
263 // reserved CLib function: custom code
264 try {
265 // *************** begin custom code ***************
266 return ReactorNetCabinet::size();
267 // **************** end custom code ****************
268 } catch (...) {
269 return handleAllExceptions(-1, ERR);
270 }
271 }
272
273} // extern "C"
Template for classes to hold pointers to objects.
Definition Cabinet.h:51
CTREACTORNET - Generated CLib Cantera interface library.
int32_t reactornet_advance(int32_t handle, double t)
Advance the state of all reactors in the independent variable (time or space).
double reactornet_sensitivity(int32_t handle, int32_t k, int32_t p)
Return the sensitivity of the k-th solution component with respect to the p-th sensitivity parameter.
int32_t reactornet_setSensitivityTolerances(int32_t handle, double rtol, double atol)
Set the relative and absolute tolerances for integrating the sensitivity equations.
int32_t reactornet_setRelativeTolerance(int32_t handle, double rtol)
Set the relative tolerance for the integrator.
int32_t reactornet_clearAbsoluteTolerance(int32_t handle)
Clear the user-specified scalar absolute tolerance.
int32_t reactornet_setAbsoluteTolerance(int32_t handle, double atol)
Set the scalar absolute tolerance for the integrator.
double reactornet_time(int32_t handle)
Current value of the simulation time [s], for reactor networks that are solved in the time domain.
double reactornet_sensitivityByName(int32_t handle, const char *component, int32_t p, int32_t reactor)
Return the sensitivity of the component named component with respect to the p-th sensitivity paramete...
int32_t reactornet_cabinetSize()
Return size of ReactorNet storage.
int32_t reactornet_del(int32_t handle)
Delete ReactorNet object.
double reactornet_rtol(int32_t handle)
Relative tolerance.
double reactornet_step(int32_t handle)
Advance the state of all reactors with respect to the independent variable (time or space).
int32_t reactornet_neq(int32_t handle)
Number of equations.
int32_t reactornet_new(int32_t reactorsLen, int32_t *reactors)
Create a reactor network containing one or more coupled reactors.
int32_t reactornet_setTolerances(int32_t handle, double rtol, double atol)
Set the relative and scalar absolute tolerances for the integrator.
int32_t reactornet_setInitialTime(int32_t handle, double time)
Set the initial value of the independent variable (typically time).
double reactornet_atol(int32_t handle)
Scalar absolute integration tolerance.
int32_t reactornet_getState(int32_t handle, int32_t yLen, double *y)
Fill in the vector y with the current state of the system.
int32_t reactornet_globalComponentIndex(int32_t handle, const char *component, int32_t reactor)
Return the index corresponding to the component named component in the reactor with index reactor in ...
int32_t reactornet_componentName(int32_t handle, int32_t i, int32_t bufLen, char *buf)
Return the name of the i-th component of the global state vector.
int32_t reactornet_setMaxTimeStep(int32_t handle, double maxstep)
Set the maximum integrator step.
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
shared_ptr< ReactorNet > newReactorNet(span< shared_ptr< ReactorBase > > reactors)
Create a reactor network containing one or more coupled reactors.
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.