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, const char* component, int32_t p, int32_t reactor)
185 {
186 // method: double ReactorNet::sensitivity(const string&, size_t, int)
187 try {
188 return ReactorNetCabinet::at(handle)->sensitivity(component, p, reactor);
189 } catch (...) {
190 return handleAllExceptions(DERR, DERR);
191 }
192 }
193
194 int32_t reactornet_neq(int32_t handle)
195 {
196 // size getter: size_t ReactorNet::neq()
197 try {
198 return static_cast<int32_t>(ReactorNetCabinet::at(handle)->neq());
199 } catch (...) {
200 return handleAllExceptions(ERR, ERR);
201 }
202 }
203
204 int32_t reactornet_getState(int32_t handle, int32_t yLen, double* y)
205 {
206 // array getter: void ReactorNet::getState(span<double>)
207 try {
208 auto& obj = ReactorNetCabinet::at(handle);
209 // no size checking specified
210 span<double> y_(y, yLen);
211 obj->getState(y_);
212 return 0;
213 } catch (...) {
214 return handleAllExceptions(-1, ERR);
215 }
216 }
217
218 int32_t reactornet_componentName(int32_t handle, int32_t i, int32_t bufLen, char* buf)
219 {
220 // method: string ReactorNet::componentName(size_t)
221 try {
222 string out = ReactorNetCabinet::at(handle)->componentName(i);
223 copyString(out, buf, bufLen);
224 return int(out.size()) + 1;
225 } catch (...) {
226 return handleAllExceptions(-1, ERR);
227 }
228 }
229
230 int32_t reactornet_del(int32_t handle)
231 {
232 // destructor
233 try {
234 ReactorNetCabinet::del(handle);
235 return 0;
236 } catch (...) {
237 return handleAllExceptions(-1, ERR);
238 }
239 }
240
242 {
243 // reserved CLib function: custom code
244 try {
245 // *************** begin custom code ***************
246 return ReactorNetCabinet::size();
247 // **************** end custom code ****************
248 } catch (...) {
249 return handleAllExceptions(-1, ERR);
250 }
251 }
252
253} // 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).
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.
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_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.
double reactornet_sensitivity(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_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.