Cantera  3.2.0a4
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<Transport> TransportCabinet;
40template<> TransportCabinet* TransportCabinet::s_storage; // initialized elsewhere
41
42typedef Cabinet<Interface> InterfaceCabinet;
43template<> InterfaceCabinet* InterfaceCabinet::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 return SolutionCabinet::add(newSolution(infile, name, transport));
60 } catch (...) {
61 return handleAllExceptions(-2, ERR);
62 }
63 }
64
65 int32_t sol_newInterface(const char* infile, const char* name, int32_t adjacentLen, const int32_t* adjacent)
66 {
67 // constructor: shared_ptr<Interface> newInterface(const string&, const string&, const vector<shared_ptr<Solution>>&)
68 try {
69 vector<shared_ptr<Solution>> adjacent_;
70 for (int i = 0; i < adjacentLen; i++) {
71 adjacent_.push_back(SolutionCabinet::at(adjacent[i]));
72 }
73 return SolutionCabinet::add(newInterface(infile, name, adjacent_));
74 } catch (...) {
75 return handleAllExceptions(-2, ERR);
76 }
77 }
78
79 int32_t sol_name(int32_t handle, int32_t bufLen, char* buf)
80 {
81 // getter: string Solution::name()
82 try {
83 string out = SolutionCabinet::at(handle)->name();
84 copyString(out, buf, bufLen);
85 return int(out.size()) + 1;
86 } catch (...) {
87 return handleAllExceptions(-1, ERR);
88 }
89 }
90
91 int32_t sol_setName(int32_t handle, const char* name)
92 {
93 // setter: void Solution::setName(const string&)
94 try {
95 SolutionCabinet::at(handle)->setName(name);
96 return 0;
97 } catch (...) {
98 return handleAllExceptions(-1, ERR);
99 }
100 }
101
102 int32_t sol_thermo(int32_t handle)
103 {
104 // accessor: shared_ptr<ThermoPhase> Solution::thermo()
105 try {
106 return ThermoPhaseCabinet::add(SolutionCabinet::at(handle)->thermo());
107 } catch (...) {
108 return handleAllExceptions(-2, ERR);
109 }
110 }
111
112 int32_t sol_kinetics(int32_t handle)
113 {
114 // accessor: shared_ptr<Kinetics> Solution::kinetics()
115 try {
116 return KineticsCabinet::add(SolutionCabinet::at(handle)->kinetics());
117 } catch (...) {
118 return handleAllExceptions(-2, ERR);
119 }
120 }
121
122 int32_t sol_transport(int32_t handle)
123 {
124 // accessor: shared_ptr<Transport> Solution::transport()
125 try {
126 return TransportCabinet::add(SolutionCabinet::at(handle)->transport());
127 } catch (...) {
128 return handleAllExceptions(-2, ERR);
129 }
130 }
131
132 int32_t sol_transportModel(int32_t handle, int32_t bufLen, char* buf)
133 {
134 // getter: string Solution::transportModel()
135 try {
136 string out = SolutionCabinet::at(handle)->transportModel();
137 copyString(out, buf, bufLen);
138 return int(out.size()) + 1;
139 } catch (...) {
140 return handleAllExceptions(-1, ERR);
141 }
142 }
143
144 int32_t sol_setTransportModel(int32_t handle, const char* model)
145 {
146 // setter: void Solution::setTransportModel(const string&)
147 try {
148 SolutionCabinet::at(handle)->setTransportModel(model);
149 return 0;
150 } catch (...) {
151 return handleAllExceptions(-1, ERR);
152 }
153 }
154
155 int32_t sol_nAdjacent(int32_t handle)
156 {
157 // getter: size_t Solution::nAdjacent()
158 try {
159 return SolutionCabinet::at(handle)->nAdjacent();
160 } catch (...) {
161 return handleAllExceptions(ERR, ERR);
162 }
163 }
164
165 int32_t sol_adjacent(int32_t handle, int32_t i)
166 {
167 // accessor: shared_ptr<Solution> Solution::adjacent(size_t)
168 try {
169 if (i < 0 || i >= SolutionCabinet::at(handle)->nAdjacent()) {
170 throw IndexError("sol_adjacent", "", i, SolutionCabinet::at(handle)->nAdjacent());
171 }
172 return SolutionCabinet::add(SolutionCabinet::at(handle)->adjacent(i));
173 } catch (...) {
174 return handleAllExceptions(-2, ERR);
175 }
176 }
177
178 int32_t sol_adjacentName(int32_t handle, int32_t i, int32_t bufLen, char* buf)
179 {
180 // method: string Solution::adjacentName(size_t)
181 try {
182 string out = SolutionCabinet::at(handle)->adjacentName(i);
183 copyString(out, buf, bufLen);
184 return int(out.size()) + 1;
185 } catch (...) {
186 return handleAllExceptions(-1, ERR);
187 }
188 }
189
190 int32_t sol_source(int32_t handle, int32_t bufLen, char* buf)
191 {
192 // getter: const string Solution::source()
193 try {
194 string out = SolutionCabinet::at(handle)->source();
195 copyString(out, buf, bufLen);
196 return int(out.size()) + 1;
197 } catch (...) {
198 return handleAllExceptions(-1, ERR);
199 }
200 }
201
202 int32_t sol_del(int32_t handle)
203 {
204 // destructor
205 try {
206 SolutionCabinet::del(handle);
207 return 0;
208 } catch (...) {
209 return handleAllExceptions(-1, ERR);
210 }
211 }
212
214 {
215 // reserved CLib function: custom code
216 try {
217 // *************** begin custom code ***************
218 return SolutionCabinet::size();
219 // **************** end custom code ****************
220 } catch (...) {
221 return handleAllExceptions(-1, ERR);
222 }
223 }
224
225} // 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)
Template for classes to hold pointers to objects.
Definition Cabinet.h:51
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:165
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:65
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:178
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:190
int32_t sol_del(int32_t handle)
Delete Solution object.
Definition ctsol.cpp:202
int32_t sol_transport(int32_t handle)
Accessor for the Transport pointer.
Definition ctsol.cpp:122
int32_t sol_thermo(int32_t handle)
Accessor for the ThermoPhase pointer.
Definition ctsol.cpp:102
int32_t sol_transportModel(int32_t handle, int32_t bufLen, char *buf)
Retrieve transport model name.
Definition ctsol.cpp:132
int32_t sol_cabinetSize()
Return size of Solution storage.
Definition ctsol.cpp:213
int32_t sol_nAdjacent(int32_t handle)
Get the number of adjacent phases.
Definition ctsol.cpp:155
int32_t sol_kinetics(int32_t handle)
Accessor for the Kinetics pointer.
Definition ctsol.cpp:112
int32_t sol_name(int32_t handle, int32_t bufLen, char *buf)
Return the name of this Solution object.
Definition ctsol.cpp:79
int32_t sol_setTransportModel(int32_t handle, const char *model)
Set the Transport object by name.
Definition ctsol.cpp:144
int32_t sol_setName(int32_t handle, const char *name)
Set the name of this Solution object.
Definition ctsol.cpp:91
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:242
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.