Cantera  3.2.0a5
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 // size getter: size_t MultiPhase::nElements()
88 try {
89 return static_cast<int32_t>(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: custom code
98 try {
99 // *************** begin custom code ***************
100 return static_cast<int32_t>(MultiPhaseCabinet::at(handle)->elementIndex(name, true));
101 // **************** end custom code ****************
102 } catch (...) {
103 return handleAllExceptions(-1, ERR);
104 }
105 }
106
107 int32_t mix_nSpecies(int32_t handle)
108 {
109 // size getter: size_t MultiPhase::nSpecies()
110 try {
111 return static_cast<int32_t>(MultiPhaseCabinet::at(handle)->nSpecies());
112 } catch (...) {
113 return handleAllExceptions(ERR, ERR);
114 }
115 }
116
117 int32_t mix_speciesIndex(int32_t handle, int32_t k, int32_t p)
118 {
119 // size getter: size_t MultiPhase::speciesIndex(size_t, size_t)
120 try {
121 return static_cast<int32_t>(MultiPhaseCabinet::at(handle)->speciesIndex(k, p));
122 } catch (...) {
123 return handleAllExceptions(ERR, ERR);
124 }
125 }
126
127 double mix_temperature(int32_t handle)
128 {
129 // getter: double MultiPhase::temperature()
130 try {
131 return MultiPhaseCabinet::at(handle)->temperature();
132 } catch (...) {
133 return handleAllExceptions(DERR, DERR);
134 }
135 }
136
137 int32_t mix_setTemperature(int32_t handle, const double T)
138 {
139 // setter: void MultiPhase::setTemperature(const double)
140 try {
141 MultiPhaseCabinet::at(handle)->setTemperature(T);
142 return 0;
143 } catch (...) {
144 return handleAllExceptions(-1, ERR);
145 }
146 }
147
148 double mix_minTemp(int32_t handle)
149 {
150 // getter: double MultiPhase::minTemp()
151 try {
152 return MultiPhaseCabinet::at(handle)->minTemp();
153 } catch (...) {
154 return handleAllExceptions(DERR, DERR);
155 }
156 }
157
158 double mix_maxTemp(int32_t handle)
159 {
160 // getter: double MultiPhase::maxTemp()
161 try {
162 return MultiPhaseCabinet::at(handle)->maxTemp();
163 } catch (...) {
164 return handleAllExceptions(DERR, DERR);
165 }
166 }
167
168 double mix_charge(int32_t handle)
169 {
170 // getter: double MultiPhase::charge()
171 try {
172 return MultiPhaseCabinet::at(handle)->charge();
173 } catch (...) {
174 return handleAllExceptions(DERR, DERR);
175 }
176 }
177
178 double mix_phaseCharge(int32_t handle, int32_t p)
179 {
180 // method: double MultiPhase::phaseCharge(size_t)
181 try {
182 return MultiPhaseCabinet::at(handle)->phaseCharge(p);
183 } catch (...) {
184 return handleAllExceptions(DERR, DERR);
185 }
186 }
187
188 double mix_pressure(int32_t handle)
189 {
190 // getter: double MultiPhase::pressure()
191 try {
192 return MultiPhaseCabinet::at(handle)->pressure();
193 } catch (...) {
194 return handleAllExceptions(DERR, DERR);
195 }
196 }
197
198 int32_t mix_setPressure(int32_t handle, double P)
199 {
200 // setter: void MultiPhase::setPressure(double)
201 try {
202 MultiPhaseCabinet::at(handle)->setPressure(P);
203 return 0;
204 } catch (...) {
205 return handleAllExceptions(-1, ERR);
206 }
207 }
208
209 double mix_nAtoms(int32_t handle, const int32_t kGlob, const int32_t mGlob)
210 {
211 // method: double MultiPhase::nAtoms(const size_t, const size_t)
212 try {
213 return MultiPhaseCabinet::at(handle)->nAtoms(kGlob, mGlob);
214 } catch (...) {
215 return handleAllExceptions(DERR, DERR);
216 }
217 }
218
219 int32_t mix_nPhases(int32_t handle)
220 {
221 // size getter: size_t MultiPhase::nPhases()
222 try {
223 return static_cast<int32_t>(MultiPhaseCabinet::at(handle)->nPhases());
224 } catch (...) {
225 return handleAllExceptions(ERR, ERR);
226 }
227 }
228
229 double mix_phaseMoles(int32_t handle, const int32_t n)
230 {
231 // method: double MultiPhase::phaseMoles(const size_t)
232 try {
233 return MultiPhaseCabinet::at(handle)->phaseMoles(n);
234 } catch (...) {
235 return handleAllExceptions(DERR, DERR);
236 }
237 }
238
239 int32_t mix_setPhaseMoles(int32_t handle, const int32_t n, const double moles)
240 {
241 // method: void MultiPhase::setPhaseMoles(const size_t, const double)
242 try {
243 MultiPhaseCabinet::at(handle)->setPhaseMoles(n, moles);
244 return 0;
245 } catch (...) {
246 return handleAllExceptions(-1, ERR);
247 }
248 }
249
250 int32_t mix_setMoles(int32_t handle, int32_t nLen, const double* n)
251 {
252 // array setter: void MultiPhase::setMoles(const double*)
253 try {
254 auto& obj = MultiPhaseCabinet::at(handle);
255 // no size checking specified
256 obj->setMoles(n);
257 return 0;
258 } catch (...) {
259 return handleAllExceptions(-1, ERR);
260 }
261 }
262
263 int32_t mix_setMolesByName(int32_t handle, const char* x)
264 {
265 // setter: void MultiPhase::setMolesByName(const string&)
266 try {
267 MultiPhaseCabinet::at(handle)->setMolesByName(x);
268 return 0;
269 } catch (...) {
270 return handleAllExceptions(-1, ERR);
271 }
272 }
273
274 double mix_speciesMoles(int32_t handle, int32_t kGlob)
275 {
276 // method: double MultiPhase::speciesMoles(size_t)
277 try {
278 return MultiPhaseCabinet::at(handle)->speciesMoles(kGlob);
279 } catch (...) {
280 return handleAllExceptions(DERR, DERR);
281 }
282 }
283
284 double mix_elementMoles(int32_t handle, int32_t m)
285 {
286 // method: double MultiPhase::elementMoles(size_t)
287 try {
288 return MultiPhaseCabinet::at(handle)->elementMoles(m);
289 } catch (...) {
290 return handleAllExceptions(DERR, DERR);
291 }
292 }
293
294 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)
295 {
296 // method: void MultiPhase::equilibrate(const string&, const string&, double, int, int, int)
297 try {
298 MultiPhaseCabinet::at(handle)->equilibrate(XY, solver, rtol, max_steps, max_iter, estimate_equil);
299 return 0;
300 } catch (...) {
301 return handleAllExceptions(-1, ERR);
302 }
303 }
304
305 int32_t mix_getChemPotentials(int32_t handle, int32_t muLen, double* mu)
306 {
307 // array getter: void MultiPhase::getChemPotentials(double*)
308 try {
309 auto& obj = MultiPhaseCabinet::at(handle);
310 // no size checking specified
311 obj->getChemPotentials(mu);
312 return 0;
313 } catch (...) {
314 return handleAllExceptions(-1, ERR);
315 }
316 }
317
318 double mix_enthalpy(int32_t handle)
319 {
320 // getter: double MultiPhase::enthalpy()
321 try {
322 return MultiPhaseCabinet::at(handle)->enthalpy();
323 } catch (...) {
324 return handleAllExceptions(DERR, DERR);
325 }
326 }
327
328 double mix_entropy(int32_t handle)
329 {
330 // getter: double MultiPhase::entropy()
331 try {
332 return MultiPhaseCabinet::at(handle)->entropy();
333 } catch (...) {
334 return handleAllExceptions(DERR, DERR);
335 }
336 }
337
338 double mix_gibbs(int32_t handle)
339 {
340 // getter: double MultiPhase::gibbs()
341 try {
342 return MultiPhaseCabinet::at(handle)->gibbs();
343 } catch (...) {
344 return handleAllExceptions(DERR, DERR);
345 }
346 }
347
348 double mix_cp(int32_t handle)
349 {
350 // getter: double MultiPhase::cp()
351 try {
352 return MultiPhaseCabinet::at(handle)->cp();
353 } catch (...) {
354 return handleAllExceptions(DERR, DERR);
355 }
356 }
357
358 double mix_volume(int32_t handle)
359 {
360 // getter: double MultiPhase::volume()
361 try {
362 return MultiPhaseCabinet::at(handle)->volume();
363 } catch (...) {
364 return handleAllExceptions(DERR, DERR);
365 }
366 }
367
368 int32_t mix_speciesPhaseIndex(int32_t handle, const int32_t kGlob)
369 {
370 // size getter: size_t MultiPhase::speciesPhaseIndex(const size_t)
371 try {
372 return static_cast<int32_t>(MultiPhaseCabinet::at(handle)->speciesPhaseIndex(kGlob));
373 } catch (...) {
374 return handleAllExceptions(ERR, ERR);
375 }
376 }
377
378 double mix_moleFraction(int32_t handle, const int32_t kGlob)
379 {
380 // method: double MultiPhase::moleFraction(const size_t)
381 try {
382 return MultiPhaseCabinet::at(handle)->moleFraction(kGlob);
383 } catch (...) {
384 return handleAllExceptions(DERR, DERR);
385 }
386 }
387
388 int32_t mix_del(int32_t handle)
389 {
390 // destructor
391 try {
392 MultiPhaseCabinet::del(handle);
393 return 0;
394 } catch (...) {
395 return handleAllExceptions(-1, ERR);
396 }
397 }
398
400 {
401 // reserved CLib function: custom code
402 try {
403 // *************** begin custom code ***************
404 return MultiPhaseCabinet::size();
405 // **************** end custom code ****************
406 } catch (...) {
407 return handleAllExceptions(-1, ERR);
408 }
409 }
410
411} // 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,...
Template for classes to hold pointers to objects.
Definition Cabinet.h:51
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:378
int32_t mix_setTemperature(int32_t handle, const double T)
Set the temperature [K].
Definition ctmix.cpp:137
double mix_minTemp(int32_t handle)
Minimum temperature for which all solution phases have valid thermo data.
Definition ctmix.cpp:148
int32_t mix_setMoles(int32_t handle, int32_t nLen, const double *n)
Sets all of the global species mole numbers.
Definition ctmix.cpp:250
int32_t mix_del(int32_t handle)
Delete MultiPhase object.
Definition ctmix.cpp:388
int32_t mix_getChemPotentials(int32_t handle, int32_t muLen, double *mu)
Returns a vector of Chemical potentials.
Definition ctmix.cpp:305
double mix_volume(int32_t handle)
The total mixture volume [m^3].
Definition ctmix.cpp:358
int32_t mix_setMolesByName(int32_t handle, const char *x)
Set the moles via a string containing their names.
Definition ctmix.cpp:263
double mix_cp(int32_t handle)
Heat capacity at constant pressure [J/K].
Definition ctmix.cpp:348
double mix_phaseCharge(int32_t handle, int32_t p)
Charge (Coulombs) of phase with index p.
Definition ctmix.cpp:178
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 p with local index k within the phas...
Definition ctmix.cpp:117
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:219
int32_t mix_nSpecies(int32_t handle)
Number of species, summed over all phases.
Definition ctmix.cpp:107
double mix_maxTemp(int32_t handle)
Maximum temperature for which all solution phases have valid thermo data.
Definition ctmix.cpp:158
int32_t mix_cabinetSize()
Return size of MultiPhase storage.
Definition ctmix.cpp:399
double mix_charge(int32_t handle)
Total charge summed over all phases (Coulombs).
Definition ctmix.cpp:168
int32_t mix_speciesPhaseIndex(int32_t handle, const int32_t kGlob)
Returns the phase index of the Kth "global" species.
Definition ctmix.cpp:368
int32_t mix_setPressure(int32_t handle, double P)
Set the pressure [Pa].
Definition ctmix.cpp:198
double mix_gibbs(int32_t handle)
The Gibbs function of the mixture [J].
Definition ctmix.cpp:338
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 mGlob in global species kGlob.
Definition ctmix.cpp:209
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:239
double mix_pressure(int32_t handle)
Pressure [Pa].
Definition ctmix.cpp:188
double mix_enthalpy(int32_t handle)
The enthalpy of the mixture [J].
Definition ctmix.cpp:318
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:294
double mix_speciesMoles(int32_t handle, int32_t kGlob)
Returns the moles of global species k.
Definition ctmix.cpp:274
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:328
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 m, summed over all phases.
Definition ctmix.cpp:284
double mix_phaseMoles(int32_t handle, const int32_t n)
Return the number of moles in phase n.
Definition ctmix.cpp:229
double mix_temperature(int32_t handle)
Temperature [K].
Definition ctmix.cpp:127
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