Cantera  3.2.0a2
Loading...
Searching...
No Matches
ctsol.cpp
Go to the documentation of this file.
1/**
2 * CTSOL - Generated CLib %Cantera interface library.
3 *
4 * @file ctsol.cpp
5 *
6 * Generated CLib API for Cantera's Solution 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/ctsol.h"
20
29
30using namespace Cantera;
31
32//! @cond
33//! Cabinet type definitions will be ignored by Doxygen
34
35// Define Cabinet<Solution> (single-instance object)
36typedef Cabinet<Solution> SolutionCabinet;
37template<> SolutionCabinet* SolutionCabinet::s_storage = 0; // initialized here
38
39typedef Cabinet<Interface> InterfaceCabinet;
40template<> InterfaceCabinet* InterfaceCabinet::s_storage; // initialized elsewhere
41
42typedef Cabinet<Transport> TransportCabinet;
43template<> TransportCabinet* TransportCabinet::s_storage; // initialized elsewhere
44
45typedef Cabinet<ThermoPhase> ThermoPhaseCabinet;
46template<> ThermoPhaseCabinet* ThermoPhaseCabinet::s_storage; // initialized elsewhere
47
48typedef Cabinet<Kinetics> KineticsCabinet;
49template<> KineticsCabinet* KineticsCabinet::s_storage; // initialized elsewhere
50
51//! @endcond
52
53extern "C" {
54
55 int32_t sol_newSolution(const char* infile, const char* name, const char* transport)
56 {
57 // constructor: shared_ptr<Solution> newSolution(const string&, const string&, const string&)
58 try {
59 auto obj = newSolution(infile, name, transport);
60 int id = SolutionCabinet::add(obj);
61 if (obj->thermo()) {
62 ThermoPhaseCabinet::add(obj->thermo(), id);
63 }
64 if (obj->kinetics()) {
65 KineticsCabinet::add(obj->kinetics(), id);
66 }
67 if (obj->transport()) {
68 TransportCabinet::add(obj->transport(), id);
69 }
70 return id;
71 } catch (...) {
72 return handleAllExceptions(-2, ERR);
73 }
74 }
75
76 int32_t sol_newInterface(const char* infile, const char* name, int32_t adjacentLen, const int32_t* adjacent)
77 {
78 // constructor: shared_ptr<Interface> newInterface(const string&, const string&, const vector<shared_ptr<Solution>>&)
79 try {
80 vector<shared_ptr<Solution>> adjacent_;
81 for (int i = 0; i < adjacentLen; i++) {
82 adjacent_.push_back(SolutionCabinet::at(adjacent[i]));
83 }
84 auto obj = newInterface(infile, name, adjacent_);
85 int id = SolutionCabinet::add(obj);
86 if (obj->thermo()) {
87 ThermoPhaseCabinet::add(obj->thermo(), id);
88 }
89 if (obj->kinetics()) {
90 KineticsCabinet::add(obj->kinetics(), id);
91 }
92 return id;
93 } catch (...) {
94 return handleAllExceptions(-2, ERR);
95 }
96 }
97
98 int32_t sol_del(int32_t handle)
99 {
100 // destructor
101 try {
102 auto obj = SolutionCabinet::at(handle);
103 // remove all associated objects in reversed order
104 if (obj->transport()) {
105 int index = TransportCabinet::index(*(obj->transport()), handle);
106 if (index >= 0) {
107 TransportCabinet::del(index);
108 }
109 }
110 if (obj->kinetics()) {
111 int index = KineticsCabinet::index(*(obj->kinetics()), handle);
112 if (index >= 0) {
113 KineticsCabinet::del(index);
114 }
115 }
116 if (obj->thermo()) {
117 int index = ThermoPhaseCabinet::index(*(obj->thermo()), handle);
118 if (index >= 0) {
119 ThermoPhaseCabinet::del(index);
120 }
121 }
122 SolutionCabinet::del(handle);
123 return 0;
124 } catch (...) {
125 return handleAllExceptions(-1, ERR);
126 }
127 }
128
129 int32_t sol_name(int32_t handle, int32_t bufLen, char* buf)
130 {
131 // getter: string Solution::name()
132 try {
133 string out = SolutionCabinet::at(handle)->name();
134 copyString(out, buf, bufLen);
135 return int(out.size()) + 1;
136 } catch (...) {
137 return handleAllExceptions(-1, ERR);
138 }
139 }
140
141 int32_t sol_setName(int32_t handle, const char* name)
142 {
143 // setter: void Solution::setName(const string&)
144 try {
145 SolutionCabinet::at(handle)->setName(name);
146 return 0;
147 } catch (...) {
148 return handleAllExceptions(-1, ERR);
149 }
150 }
151
152 int32_t sol_thermo(int32_t handle)
153 {
154 // getter: shared_ptr<ThermoPhase> Solution::thermo()
155 try {
156 auto obj = SolutionCabinet::at(handle)->thermo();
157 return ThermoPhaseCabinet::index(*obj, handle);
158 } catch (...) {
159 return handleAllExceptions(-2, ERR);
160 }
161 }
162
163 int32_t sol_kinetics(int32_t handle)
164 {
165 // getter: shared_ptr<Kinetics> Solution::kinetics()
166 try {
167 auto obj = SolutionCabinet::at(handle)->kinetics();
168 return KineticsCabinet::index(*obj, handle);
169 } catch (...) {
170 return handleAllExceptions(-2, ERR);
171 }
172 }
173
174 int32_t sol_transport(int32_t handle)
175 {
176 // getter: shared_ptr<Transport> Solution::transport()
177 try {
178 auto obj = SolutionCabinet::at(handle)->transport();
179 return TransportCabinet::index(*obj, handle);
180 } catch (...) {
181 return handleAllExceptions(-2, ERR);
182 }
183 }
184
185 int32_t sol_transportModel(int32_t handle, int32_t bufLen, char* buf)
186 {
187 // getter: string Solution::transportModel()
188 try {
189 string out = SolutionCabinet::at(handle)->transportModel();
190 copyString(out, buf, bufLen);
191 return int(out.size()) + 1;
192 } catch (...) {
193 return handleAllExceptions(-1, ERR);
194 }
195 }
196
197 int32_t sol_setTransportModel(int32_t handle, const char* model)
198 {
199 // accessor: void Solution::setTransportModel(const string&)
200 try {
201 auto obj = SolutionCabinet::at(handle);
202 if (obj->transport()) {
203 TransportCabinet::del(
204 TransportCabinet::index(*(obj->transport()), handle));
205 }
206 obj->setTransportModel(model);
207 return TransportCabinet::add(obj->transport(), handle);
208 } catch (...) {
209 return handleAllExceptions(-1, ERR);
210 }
211 }
212
213 int32_t sol_nAdjacent(int32_t handle)
214 {
215 // getter: size_t Solution::nAdjacent()
216 try {
217 return SolutionCabinet::at(handle)->nAdjacent();
218 } catch (...) {
219 return handleAllExceptions(ERR, ERR);
220 }
221 }
222
223 int32_t sol_adjacent(int32_t handle, int32_t i)
224 {
225 // accessor: shared_ptr<Solution> Solution::adjacent(size_t)
226 try {
227 if (i < 0 || i >= SolutionCabinet::at(handle)->nAdjacent()) {
228 throw IndexError("sol_adjacent", "", i, SolutionCabinet::at(handle)->nAdjacent());
229 }
230 auto obj = SolutionCabinet::at(handle)->adjacent(i);
231 int id = SolutionCabinet::add(obj);
232 if (obj->thermo()) {
233 ThermoPhaseCabinet::add(obj->thermo(), id);
234 }
235 if (obj->kinetics()) {
236 KineticsCabinet::add(obj->kinetics(), id);
237 }
238 if (obj->transport()) {
239 TransportCabinet::add(obj->transport(), id);
240 }
241 return id;
242 } catch (...) {
243 return handleAllExceptions(-2, ERR);
244 }
245 }
246
247 int32_t sol_adjacentName(int32_t handle, int32_t i, int32_t bufLen, char* buf)
248 {
249 // method: string Solution::adjacentName(size_t)
250 try {
251 string out = SolutionCabinet::at(handle)->adjacentName(i);
252 copyString(out, buf, bufLen);
253 return int(out.size()) + 1;
254 } catch (...) {
255 return handleAllExceptions(-1, ERR);
256 }
257 }
258
259 int32_t sol_source(int32_t handle, int32_t bufLen, char* buf)
260 {
261 // getter: const string Solution::source()
262 try {
263 string out = SolutionCabinet::at(handle)->source();
264 copyString(out, buf, bufLen);
265 return int(out.size()) + 1;
266 } catch (...) {
267 return handleAllExceptions(-1, ERR);
268 }
269 }
270
272 {
273 // reserved CLib function: custom code
274 try {
275 // *************** begin custom code ***************
276 return SolutionCabinet::size();
277 // **************** end custom code ****************
278 } catch (...) {
279 return handleAllExceptions(-1, ERR);
280 }
281 }
282
283} // 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...
Header file defining class TransportFactory (see TransportFactory)
An array index is out of range.
CTSOL - Generated CLib Cantera interface library.
int32_t sol_adjacent(int32_t handle, int32_t i)
Get the Solution object for an adjacent phase by index.
Definition ctsol.cpp:223
int32_t sol_newInterface(const char *infile, const char *name, int32_t adjacentLen, const int32_t *adjacent)
Create and initialize a new Interface from an input file.
Definition ctsol.cpp:76
int32_t sol_adjacentName(int32_t handle, int32_t i, int32_t bufLen, char *buf)
Get the name of an adjacent phase by index.
Definition ctsol.cpp:247
int32_t sol_newSolution(const char *infile, const char *name, const char *transport)
Create and initialize a new Solution manager from an input file.
Definition ctsol.cpp:55
int32_t sol_source(int32_t handle, int32_t bufLen, char *buf)
Retrieve source used for object creation; usually an input file name.
Definition ctsol.cpp:259
int32_t sol_del(int32_t handle)
Delete Solution object.
Definition ctsol.cpp:98
int32_t sol_transport(int32_t handle)
Accessor for the Transport pointer.
Definition ctsol.cpp:174
int32_t sol_thermo(int32_t handle)
Accessor for the ThermoPhase pointer.
Definition ctsol.cpp:152
int32_t sol_transportModel(int32_t handle, int32_t bufLen, char *buf)
Retrieve transport model name.
Definition ctsol.cpp:185
int32_t sol_cabinetSize()
Return size of Solution storage.
Definition ctsol.cpp:271
int32_t sol_nAdjacent(int32_t handle)
Get the number of adjacent phases.
Definition ctsol.cpp:213
int32_t sol_kinetics(int32_t handle)
Accessor for the Kinetics pointer.
Definition ctsol.cpp:163
int32_t sol_name(int32_t handle, int32_t bufLen, char *buf)
Return the name of this Solution object.
Definition ctsol.cpp:129
int32_t sol_setTransportModel(int32_t handle, const char *model)
Set the Transport object by name.
Definition ctsol.cpp:197
int32_t sol_setName(int32_t handle, const char *name)
Set the name of this Solution object.
Definition ctsol.cpp:141
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< Solution > newSolution(const string &infile, const string &name, const string &transport, const vector< shared_ptr< Solution > > &adjacent)
Create and initialize a new Solution manager from an input file.
Definition Solution.cpp:191
shared_ptr< Interface > newInterface(const string &infile, const string &name, const vector< string > &adjacent)
Create and initialize a new Interface from an input file.
Definition Interface.cpp:35
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.