Cantera  3.2.0a2
Loading...
Searching...
No Matches
ctmix.cpp
Go to the documentation of this file.
1/**
2 * CTMIX - Generated CLib %Cantera interface library.
3 *
4 * @file ctmix.cpp
5 *
6 * Generated CLib API for Cantera's MultiPhase 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/ctmix.h"
20
25
26using namespace Cantera;
27
28//! @cond
29//! Cabinet type definitions will be ignored by Doxygen
30
31// Define Cabinet<MultiPhase> (single-instance object)
32typedef Cabinet<MultiPhase> MultiPhaseCabinet;
33template<> MultiPhaseCabinet* MultiPhaseCabinet::s_storage = 0; // initialized here
34
35typedef Cabinet<ThermoPhase> ThermoPhaseCabinet;
36template<> ThermoPhaseCabinet* ThermoPhaseCabinet::s_storage; // initialized elsewhere
37
38//! @endcond
39
40extern "C" {
41
42 int32_t mix_new()
43 {
44 // constructor: default constructor for MultiPhase
45 try {
46 return MultiPhaseCabinet::add(make_shared<MultiPhase>());
47 } catch (...) {
48 return handleAllExceptions(-1, ERR);
49 }
50 }
51
52 int32_t mix_addPhase(int32_t handle, int32_t p, double moles)
53 {
54 // method: void MultiPhase::addPhase(shared_ptr<ThermoPhase>, double)
55 try {
56 MultiPhaseCabinet::at(handle)->addPhase(ThermoPhaseCabinet::at(p), moles);
57 return 0;
58 } catch (...) {
59 return handleAllExceptions(-1, ERR);
60 }
61 }
62
63 int32_t mix_init(int32_t handle)
64 {
65 // method: void MultiPhase::init()
66 try {
67 MultiPhaseCabinet::at(handle)->init();
68 return 0;
69 } catch (...) {
70 return handleAllExceptions(-1, ERR);
71 }
72 }
73
74 int32_t mix_updatePhases(int32_t handle)
75 {
76 // method: void MultiPhase::updatePhases()
77 try {
78 MultiPhaseCabinet::at(handle)->updatePhases();
79 return 0;
80 } catch (...) {
81 return handleAllExceptions(-1, ERR);
82 }
83 }
84
85 int32_t mix_nElements(int32_t handle)
86 {
87 // getter: size_t MultiPhase::nElements()
88 try {
89 return MultiPhaseCabinet::at(handle)->nElements();
90 } catch (...) {
91 return handleAllExceptions(ERR, ERR);
92 }
93 }
94
95 int32_t mix_elementIndex(int32_t handle, const char* name)
96 {
97 // method: size_t MultiPhase::elementIndex(const string&)
98 try {
99 return MultiPhaseCabinet::at(handle)->elementIndex(name);
100 } catch (...) {
101 return handleAllExceptions(ERR, ERR);
102 }
103 }
104
105 int32_t mix_nSpecies(int32_t handle)
106 {
107 // getter: size_t MultiPhase::nSpecies()
108 try {
109 return MultiPhaseCabinet::at(handle)->nSpecies();
110 } catch (...) {
111 return handleAllExceptions(ERR, ERR);
112 }
113 }
114
115 int32_t mix_speciesIndex(int32_t handle, int32_t k, int32_t p)
116 {
117 // method: size_t MultiPhase::speciesIndex(size_t, size_t)
118 try {
119 return MultiPhaseCabinet::at(handle)->speciesIndex(k, p);
120 } catch (...) {
121 return handleAllExceptions(ERR, ERR);
122 }
123 }
124
125 double mix_temperature(int32_t handle)
126 {
127 // getter: double MultiPhase::temperature()
128 try {
129 return MultiPhaseCabinet::at(handle)->temperature();
130 } catch (...) {
131 return handleAllExceptions(DERR, DERR);
132 }
133 }
134
135 int32_t mix_setTemperature(int32_t handle, const double T)
136 {
137 // setter: void MultiPhase::setTemperature(const double)
138 try {
139 MultiPhaseCabinet::at(handle)->setTemperature(T);
140 return 0;
141 } catch (...) {
142 return handleAllExceptions(-1, ERR);
143 }
144 }
145
146 double mix_minTemp(int32_t handle)
147 {
148 // getter: double MultiPhase::minTemp()
149 try {
150 return MultiPhaseCabinet::at(handle)->minTemp();
151 } catch (...) {
152 return handleAllExceptions(DERR, DERR);
153 }
154 }
155
156 double mix_maxTemp(int32_t handle)
157 {
158 // getter: double MultiPhase::maxTemp()
159 try {
160 return MultiPhaseCabinet::at(handle)->maxTemp();
161 } catch (...) {
162 return handleAllExceptions(DERR, DERR);
163 }
164 }
165
166 double mix_charge(int32_t handle)
167 {
168 // getter: double MultiPhase::charge()
169 try {
170 return MultiPhaseCabinet::at(handle)->charge();
171 } catch (...) {
172 return handleAllExceptions(DERR, DERR);
173 }
174 }
175
176 double mix_phaseCharge(int32_t handle, int32_t p)
177 {
178 // method: double MultiPhase::phaseCharge(size_t)
179 try {
180 return MultiPhaseCabinet::at(handle)->phaseCharge(p);
181 } catch (...) {
182 return handleAllExceptions(DERR, DERR);
183 }
184 }
185
186 double mix_pressure(int32_t handle)
187 {
188 // getter: double MultiPhase::pressure()
189 try {
190 return MultiPhaseCabinet::at(handle)->pressure();
191 } catch (...) {
192 return handleAllExceptions(DERR, DERR);
193 }
194 }
195
196 int32_t mix_setPressure(int32_t handle, double P)
197 {
198 // setter: void MultiPhase::setPressure(double)
199 try {
200 MultiPhaseCabinet::at(handle)->setPressure(P);
201 return 0;
202 } catch (...) {
203 return handleAllExceptions(-1, ERR);
204 }
205 }
206
207 double mix_nAtoms(int32_t handle, const int32_t kGlob, const int32_t mGlob)
208 {
209 // method: double MultiPhase::nAtoms(const size_t, const size_t)
210 try {
211 return MultiPhaseCabinet::at(handle)->nAtoms(kGlob, mGlob);
212 } catch (...) {
213 return handleAllExceptions(DERR, DERR);
214 }
215 }
216
217 int32_t mix_nPhases(int32_t handle)
218 {
219 // getter: size_t MultiPhase::nPhases()
220 try {
221 return MultiPhaseCabinet::at(handle)->nPhases();
222 } catch (...) {
223 return handleAllExceptions(ERR, ERR);
224 }
225 }
226
227 double mix_phaseMoles(int32_t handle, const int32_t n)
228 {
229 // method: double MultiPhase::phaseMoles(const size_t)
230 try {
231 return MultiPhaseCabinet::at(handle)->phaseMoles(n);
232 } catch (...) {
233 return handleAllExceptions(DERR, DERR);
234 }
235 }
236
237 int32_t mix_setPhaseMoles(int32_t handle, const int32_t n, const double moles)
238 {
239 // method: void MultiPhase::setPhaseMoles(const size_t, const double)
240 try {
241 MultiPhaseCabinet::at(handle)->setPhaseMoles(n, moles);
242 return 0;
243 } catch (...) {
244 return handleAllExceptions(-1, ERR);
245 }
246 }
247
248 int32_t mix_setMoles(int32_t handle, int32_t nLen, const double* n)
249 {
250 // setter: void MultiPhase::setMoles(const double*)
251 try {
252 auto& obj = MultiPhaseCabinet::at(handle);
253 // no size checking specified
254 obj->setMoles(n);
255 return 0;
256 } catch (...) {
257 return handleAllExceptions(-1, ERR);
258 }
259 }
260
261 int32_t mix_setMolesByName(int32_t handle, const char* x)
262 {
263 // setter: void MultiPhase::setMolesByName(const string&)
264 try {
265 MultiPhaseCabinet::at(handle)->setMolesByName(x);
266 return 0;
267 } catch (...) {
268 return handleAllExceptions(-1, ERR);
269 }
270 }
271
272 double mix_speciesMoles(int32_t handle, int32_t kGlob)
273 {
274 // method: double MultiPhase::speciesMoles(size_t)
275 try {
276 return MultiPhaseCabinet::at(handle)->speciesMoles(kGlob);
277 } catch (...) {
278 return handleAllExceptions(DERR, DERR);
279 }
280 }
281
282 double mix_elementMoles(int32_t handle, int32_t m)
283 {
284 // method: double MultiPhase::elementMoles(size_t)
285 try {
286 return MultiPhaseCabinet::at(handle)->elementMoles(m);
287 } catch (...) {
288 return handleAllExceptions(DERR, DERR);
289 }
290 }
291
292 int32_t mix_equilibrate(int32_t handle, const char* XY, const char* solver, double rtol, int32_t max_steps, int32_t max_iter, int32_t estimate_equil)
293 {
294 // method: void MultiPhase::equilibrate(const string&, const string&, double, int, int, int)
295 try {
296 MultiPhaseCabinet::at(handle)->equilibrate(XY, solver, rtol, max_steps, max_iter, estimate_equil);
297 return 0;
298 } catch (...) {
299 return handleAllExceptions(-1, ERR);
300 }
301 }
302
303 int32_t mix_getChemPotentials(int32_t handle, int32_t muLen, double* mu)
304 {
305 // getter: void MultiPhase::getChemPotentials(double*)
306 try {
307 auto& obj = MultiPhaseCabinet::at(handle);
308 // no size checking specified
309 obj->getChemPotentials(mu);
310 return 0;
311 } catch (...) {
312 return handleAllExceptions(-1, ERR);
313 }
314 }
315
316 double mix_enthalpy(int32_t handle)
317 {
318 // getter: double MultiPhase::enthalpy()
319 try {
320 return MultiPhaseCabinet::at(handle)->enthalpy();
321 } catch (...) {
322 return handleAllExceptions(DERR, DERR);
323 }
324 }
325
326 double mix_entropy(int32_t handle)
327 {
328 // getter: double MultiPhase::entropy()
329 try {
330 return MultiPhaseCabinet::at(handle)->entropy();
331 } catch (...) {
332 return handleAllExceptions(DERR, DERR);
333 }
334 }
335
336 double mix_gibbs(int32_t handle)
337 {
338 // getter: double MultiPhase::gibbs()
339 try {
340 return MultiPhaseCabinet::at(handle)->gibbs();
341 } catch (...) {
342 return handleAllExceptions(DERR, DERR);
343 }
344 }
345
346 double mix_cp(int32_t handle)
347 {
348 // getter: double MultiPhase::cp()
349 try {
350 return MultiPhaseCabinet::at(handle)->cp();
351 } catch (...) {
352 return handleAllExceptions(DERR, DERR);
353 }
354 }
355
356 double mix_volume(int32_t handle)
357 {
358 // getter: double MultiPhase::volume()
359 try {
360 return MultiPhaseCabinet::at(handle)->volume();
361 } catch (...) {
362 return handleAllExceptions(DERR, DERR);
363 }
364 }
365
366 int32_t mix_speciesPhaseIndex(int32_t handle, const int32_t kGlob)
367 {
368 // method: size_t MultiPhase::speciesPhaseIndex(const size_t)
369 try {
370 return MultiPhaseCabinet::at(handle)->speciesPhaseIndex(kGlob);
371 } catch (...) {
372 return handleAllExceptions(ERR, ERR);
373 }
374 }
375
376 double mix_moleFraction(int32_t handle, const int32_t kGlob)
377 {
378 // method: double MultiPhase::moleFraction(const size_t)
379 try {
380 return MultiPhaseCabinet::at(handle)->moleFraction(kGlob);
381 } catch (...) {
382 return handleAllExceptions(DERR, DERR);
383 }
384 }
385
386 int32_t mix_del(int32_t handle)
387 {
388 // destructor
389 try {
390 MultiPhaseCabinet::del(handle);
391 return 0;
392 } catch (...) {
393 return handleAllExceptions(-1, ERR);
394 }
395 }
396
398 {
399 // reserved CLib function: custom code
400 try {
401 // *************** begin custom code ***************
402 return MultiPhaseCabinet::size();
403 // **************** end custom code ****************
404 } catch (...) {
405 return handleAllExceptions(-1, ERR);
406 }
407 }
408
409 int32_t mix_parentHandle(int32_t handle)
410 {
411 // reserved CLib function: custom code
412 try {
413 // *************** begin custom code ***************
414 return MultiPhaseCabinet::parent(handle);
415 // **************** end custom code ****************
416 } catch (...) {
417 return handleAllExceptions(-1, ERR);
418 }
419 }
420
421} // extern "C"
Headers for the MultiPhase object that is used to set up multiphase equilibrium problems (see Chemica...
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 for class ThermoPhase, the base class for phases with thermodynamic properties,...
CTMIX - Generated CLib Cantera interface library.
int32_t mix_nElements(int32_t handle)
Number of elements.
Definition ctmix.cpp:85
double mix_moleFraction(int32_t handle, const int32_t kGlob)
Returns the mole fraction of global species k.
Definition ctmix.cpp:376
int32_t mix_setTemperature(int32_t handle, const double T)
Set the temperature [K].
Definition ctmix.cpp:135
double mix_minTemp(int32_t handle)
Minimum temperature for which all solution phases have valid thermo data.
Definition ctmix.cpp:146
int32_t mix_setMoles(int32_t handle, int32_t nLen, const double *n)
Sets all of the global species mole numbers.
Definition ctmix.cpp:248
int32_t mix_del(int32_t handle)
Delete MultiPhase object.
Definition ctmix.cpp:386
int32_t mix_getChemPotentials(int32_t handle, int32_t muLen, double *mu)
Returns a vector of Chemical potentials.
Definition ctmix.cpp:303
double mix_volume(int32_t handle)
The total mixture volume [m^3].
Definition ctmix.cpp:356
int32_t mix_setMolesByName(int32_t handle, const char *x)
Set the moles via a string containing their names.
Definition ctmix.cpp:261
double mix_cp(int32_t handle)
Heat capacity at constant pressure [J/K].
Definition ctmix.cpp:346
double mix_phaseCharge(int32_t handle, int32_t p)
Charge (Coulombs) of phase with index.
Definition ctmix.cpp:176
int32_t mix_updatePhases(int32_t handle)
Set the states of the phase objects to the locally-stored state within this MultiPhase object.
Definition ctmix.cpp:74
int32_t mix_speciesIndex(int32_t handle, int32_t k, int32_t p)
Return the global index of the species belonging to phase number.
Definition ctmix.cpp:115
int32_t mix_init(int32_t handle)
Process phases and build atomic composition array.
Definition ctmix.cpp:63
int32_t mix_nPhases(int32_t handle)
Number of phases.
Definition ctmix.cpp:217
int32_t mix_nSpecies(int32_t handle)
Number of species, summed over all phases.
Definition ctmix.cpp:105
double mix_maxTemp(int32_t handle)
Maximum temperature for which all solution phases have valid thermo data.
Definition ctmix.cpp:156
int32_t mix_cabinetSize()
Return size of MultiPhase storage.
Definition ctmix.cpp:397
double mix_charge(int32_t handle)
Total charge summed over all phases (Coulombs).
Definition ctmix.cpp:166
int32_t mix_speciesPhaseIndex(int32_t handle, const int32_t kGlob)
Returns the phase index of the Kth "global" species.
Definition ctmix.cpp:366
int32_t mix_setPressure(int32_t handle, double P)
Set the pressure [Pa].
Definition ctmix.cpp:196
double mix_gibbs(int32_t handle)
The Gibbs function of the mixture [J].
Definition ctmix.cpp:336
int32_t mix_new()
Instantiate MultiPhase object using default constructor.
Definition ctmix.cpp:42
double mix_nAtoms(int32_t handle, const int32_t kGlob, const int32_t mGlob)
Returns the Number of atoms of global element.
Definition ctmix.cpp:207
int32_t mix_setPhaseMoles(int32_t handle, const int32_t n, const double moles)
Set the number of moles of phase with index n.
Definition ctmix.cpp:237
double mix_pressure(int32_t handle)
Pressure [Pa].
Definition ctmix.cpp:186
double mix_enthalpy(int32_t handle)
The enthalpy of the mixture [J].
Definition ctmix.cpp:316
int32_t mix_parentHandle(int32_t handle)
Return handle to parent of MultiPhase object.
Definition ctmix.cpp:409
int32_t mix_equilibrate(int32_t handle, const char *XY, const char *solver, double rtol, int32_t max_steps, int32_t max_iter, int32_t estimate_equil)
Equilibrate a ThermoPhase object.
Definition ctmix.cpp:292
double mix_speciesMoles(int32_t handle, int32_t kGlob)
Returns the moles of global species.
Definition ctmix.cpp:272
int32_t mix_elementIndex(int32_t handle, const char *name)
Returns the index of the element with name.
Definition ctmix.cpp:95
double mix_entropy(int32_t handle)
The entropy of the mixture [J/K].
Definition ctmix.cpp:326
int32_t mix_addPhase(int32_t handle, int32_t p, double moles)
Add a phase to the mixture.
Definition ctmix.cpp:52
double mix_elementMoles(int32_t handle, int32_t m)
Total moles of global element.
Definition ctmix.cpp:282
double mix_phaseMoles(int32_t handle, const int32_t n)
Return the number of moles in phase n.
Definition ctmix.cpp:227
double mix_temperature(int32_t handle)
Temperature [K].
Definition ctmix.cpp:125
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