1 /**
2  *  @file ct.cpp
3  *   Cantera interface library. This library of functions is designed
4  *   to encapsulate Cantera functionality and make it available for
5  *   use in languages and applications other than C++. A set of
6  *   library functions is provided that are declared "extern C". All
7  *   Cantera objects are stored and referenced by integers - no
8  *   pointers are passed to or from the calling application.
9  */
10 
11 // This file is part of Cantera. See License.txt in the top-level directory or
12 // at https://cantera.org/license.txt for license and copyright information.
13 
14 #define CANTERA_USE_INTERNAL
15 #include "cantera/clib/ct.h"
16 
17 // Cantera includes
18 #include "cantera/kinetics/KineticsFactory.h"
19 #include "cantera/transport/TransportFactory.h"
20 #include "cantera/base/ctml.h"
21 #include "cantera/base/stringUtils.h"
22 #include "cantera/kinetics/importKinetics.h"
23 #include "cantera/thermo/ThermoFactory.h"
24 #include "Cabinet.h"
25 #include "cantera/kinetics/InterfaceKinetics.h"
26 #include "cantera/thermo/PureFluidPhase.h"
27 
28 using namespace std;
29 using namespace Cantera;
30 
31 typedef Cabinet<ThermoPhase> ThermoCabinet;
32 typedef Cabinet<Kinetics> KineticsCabinet;
33 typedef Cabinet<Transport> TransportCabinet;
34 typedef Cabinet<XML_Node, false> XmlCabinet;
35 
36 template<> ThermoCabinet* ThermoCabinet::s_storage = 0;
37 template<> KineticsCabinet* KineticsCabinet::s_storage = 0;
38 template<> TransportCabinet* TransportCabinet::s_storage = 0;
39 
40 /**
41  * Exported functions.
42  */
43 extern "C" {
44 
ct_appdelete()45     int ct_appdelete()
46     {
47         try {
48             appdelete();
49             return 0;
50         } catch (...) {
51             return handleAllExceptions(-1, ERR);
52         }
53     }
54 
55     //--------------- Phase ---------------------//
56 
thermo_nElements(int n)57     size_t thermo_nElements(int n)
58     {
59         try {
60             return ThermoCabinet::item(n).nElements();
61         } catch (...) {
62             return handleAllExceptions(npos, npos);
63         }
64     }
65 
thermo_nSpecies(int n)66     size_t thermo_nSpecies(int n)
67     {
68         try {
69             return ThermoCabinet::item(n).nSpecies();
70         } catch (...) {
71             return handleAllExceptions(npos, npos);
72         }
73     }
74 
thermo_temperature(int n)75     doublereal thermo_temperature(int n)
76     {
77         try {
78             return ThermoCabinet::item(n).temperature();
79         } catch (...) {
80             return handleAllExceptions(DERR, DERR);
81         }
82     }
83 
thermo_setTemperature(int n,double t)84     int thermo_setTemperature(int n, double t)
85     {
86         try {
87             ThermoCabinet::item(n).setTemperature(t);
88         } catch (...) {
89             return handleAllExceptions(-1, ERR);
90         }
91         return 0;
92     }
93 
thermo_density(int n)94     doublereal thermo_density(int n)
95     {
96         try {
97             return ThermoCabinet::item(n).density();
98         } catch (...) {
99             return handleAllExceptions(DERR, DERR);
100         }
101     }
102 
thermo_setDensity(int n,double rho)103     int thermo_setDensity(int n, double rho)
104     {
105         if (rho < 0.0) {
106             return -1;
107         }
108         try {
109             ThermoCabinet::item(n).setDensity(rho);
110         } catch (...) {
111             return handleAllExceptions(-1, ERR);
112         }
113         return 0;
114     }
115 
thermo_molarDensity(int n)116     doublereal thermo_molarDensity(int n)
117     {
118         try {
119             return ThermoCabinet::item(n).molarDensity();
120         } catch (...) {
121             return handleAllExceptions(DERR, DERR);
122         }
123     }
124 
thermo_setMolarDensity(int n,double ndens)125     int thermo_setMolarDensity(int n, double ndens)
126     {
127         if (ndens < 0.0) {
128             return -1;
129         }
130         try {
131             ThermoCabinet::item(n).setMolarDensity(ndens);
132         } catch (...) {
133             return handleAllExceptions(-1, ERR);
134         }
135         return 0;
136     }
137 
thermo_meanMolecularWeight(int n)138     doublereal thermo_meanMolecularWeight(int n)
139     {
140         try {
141             return ThermoCabinet::item(n).meanMolecularWeight();
142         } catch (...) {
143             return handleAllExceptions(DERR, DERR);
144         }
145     }
146 
thermo_elementIndex(int n,const char * nm)147     size_t thermo_elementIndex(int n, const char* nm)
148     {
149         try {
150             return ThermoCabinet::item(n).elementIndex(nm);
151         } catch (...) {
152             return handleAllExceptions(npos, npos);
153         }
154     }
155 
thermo_speciesIndex(int n,const char * nm)156     size_t thermo_speciesIndex(int n, const char* nm)
157     {
158         try {
159             return ThermoCabinet::item(n).speciesIndex(nm);
160         } catch (...) {
161             return handleAllExceptions(npos, npos);
162         }
163     }
164 
thermo_getMoleFractions(int n,size_t lenx,double * x)165     int thermo_getMoleFractions(int n, size_t lenx, double* x)
166     {
167         try {
168             ThermoPhase& p = ThermoCabinet::item(n);
169             p.checkSpeciesArraySize(lenx);
170             p.getMoleFractions(x);
171             return 0;
172         } catch (...) {
173             return handleAllExceptions(-1, ERR);
174         }
175     }
176 
thermo_moleFraction(int n,size_t k)177     doublereal thermo_moleFraction(int n, size_t k)
178     {
179         try {
180             return ThermoCabinet::item(n).moleFraction(k);
181         } catch (...) {
182             return handleAllExceptions(DERR, DERR);
183         }
184     }
185 
thermo_getMassFractions(int n,size_t leny,double * y)186     int thermo_getMassFractions(int n, size_t leny, double* y)
187     {
188         try {
189             ThermoPhase& p = ThermoCabinet::item(n);
190             p.checkSpeciesArraySize(leny);
191             p.getMassFractions(y);
192             return 0;
193         } catch (...) {
194             return handleAllExceptions(-1, ERR);
195         }
196     }
197 
thermo_massFraction(int n,size_t k)198     doublereal thermo_massFraction(int n, size_t k)
199     {
200         try {
201             return ThermoCabinet::item(n).massFraction(k);
202         } catch (...) {
203             return handleAllExceptions(DERR, DERR);
204         }
205     }
206 
thermo_setMoleFractions(int n,size_t lenx,double * x,int norm)207     int thermo_setMoleFractions(int n, size_t lenx, double* x, int norm)
208     {
209         try {
210             ThermoPhase& p = ThermoCabinet::item(n);
211             p.checkSpeciesArraySize(lenx);
212             if (norm) {
213                 p.setMoleFractions(x);
214             } else {
215                 p.setMoleFractions_NoNorm(x);
216             }
217             return 0;
218         } catch (...) {
219             return handleAllExceptions(-1, ERR);
220         }
221     }
222 
thermo_setMoleFractionsByName(int n,const char * x)223     int thermo_setMoleFractionsByName(int n, const char* x)
224     {
225         try {
226             ThermoPhase& p = ThermoCabinet::item(n);
227             p.setMoleFractionsByName(x);
228             return 0;
229         } catch (...) {
230             return handleAllExceptions(-1, ERR);
231         }
232     }
233 
thermo_setMassFractions(int n,size_t leny,double * y,int norm)234     int thermo_setMassFractions(int n, size_t leny,
235                                double* y, int norm)
236     {
237         try {
238             ThermoPhase& p = ThermoCabinet::item(n);
239             p.checkSpeciesArraySize(leny);
240             if (norm) {
241                 p.setMassFractions(y);
242             } else {
243                 p.setMassFractions_NoNorm(y);
244             }
245             return 0;
246         } catch (...) {
247             return handleAllExceptions(-1, ERR);
248         }
249     }
250 
thermo_setMassFractionsByName(int n,const char * y)251     int thermo_setMassFractionsByName(int n, const char* y)
252     {
253         try {
254             ThermoPhase& p = ThermoCabinet::item(n);
255             p.setMassFractionsByName(y);
256             return 0;
257         } catch (...) {
258             return handleAllExceptions(-1, ERR);
259         }
260     }
261 
thermo_getAtomicWeights(int n,size_t lenm,double * atw)262     int thermo_getAtomicWeights(int n, size_t lenm, double* atw)
263     {
264         try {
265             ThermoPhase& p = ThermoCabinet::item(n);
266             p.checkElementArraySize(lenm);
267             const vector_fp& wt = p.atomicWeights();
268             copy(wt.begin(), wt.end(), atw);
269             return 0;
270         } catch (...) {
271             return handleAllExceptions(-1, ERR);
272         }
273     }
274 
thermo_getMolecularWeights(int n,size_t lenm,double * mw)275     int thermo_getMolecularWeights(int n, size_t lenm, double* mw)
276     {
277         try {
278             ThermoPhase& p = ThermoCabinet::item(n);
279             p.checkSpeciesArraySize(lenm);
280             const vector_fp& wt = p.molecularWeights();
281             copy(wt.begin(), wt.end(), mw);
282             return 0;
283         } catch (...) {
284             return handleAllExceptions(-1, ERR);
285         }
286     }
287 
thermo_getCharges(int n,size_t lenm,double * sc)288     int thermo_getCharges(int n, size_t lenm, double* sc)
289     {
290         try {
291             ThermoPhase& p = ThermoCabinet::item(n);
292             p.checkSpeciesArraySize(lenm);
293             p.getCharges(sc);
294             return 0;
295         } catch (...) {
296             return handleAllExceptions(-1, ERR);
297         }
298     }
299 
thermo_getName(int n,size_t lennm,char * nm)300     int thermo_getName(int n, size_t lennm, char* nm)
301     {
302         try {
303             return static_cast<int>(copyString(ThermoCabinet::item(n).name(), nm, lennm));
304         } catch (...) {
305             return handleAllExceptions(-1, ERR);
306         }
307     }
308 
thermo_setName(int n,const char * nm)309     int thermo_setName(int n, const char* nm)
310     {
311         try {
312             ThermoCabinet::item(n).setName(nm);
313             return 0;
314         } catch (...) {
315             return handleAllExceptions(-1, ERR);
316         }
317     }
318 
thermo_getSpeciesName(int n,size_t k,size_t lennm,char * nm)319     int thermo_getSpeciesName(int n, size_t k, size_t lennm, char* nm)
320     {
321         try {
322             return static_cast<int>(copyString(ThermoCabinet::item(n).speciesName(k), nm, lennm));
323         } catch (...) {
324             return handleAllExceptions(-1, ERR);
325         }
326     }
327 
thermo_getElementName(int n,size_t m,size_t lennm,char * nm)328     int thermo_getElementName(int n, size_t m, size_t lennm, char* nm)
329     {
330         try {
331             return static_cast<int>(copyString(ThermoCabinet::item(n).elementName(m), nm, lennm));
332         } catch (...) {
333             return handleAllExceptions(-1, ERR);
334         }
335     }
336 
337 
thermo_nAtoms(int n,size_t k,size_t m)338     doublereal thermo_nAtoms(int n, size_t k, size_t m)
339     {
340         try {
341             return ThermoCabinet::item(n).nAtoms(k,m);
342         } catch (...) {
343             return handleAllExceptions(ERR, ERR);
344         }
345     }
346 
thermo_addElement(int n,const char * name,doublereal weight)347     int thermo_addElement(int n, const char* name, doublereal weight)
348     {
349         try {
350             ThermoCabinet::item(n).addElement(name, weight);
351             return 0;
352         } catch (...) {
353             return handleAllExceptions(-1, ERR);
354         }
355     }
356 
357     //-------------- Thermo --------------------//
358 
thermo_newFromFile(const char * filename,const char * phasename)359     int thermo_newFromFile(const char* filename, const char* phasename) {
360         try {
361             return ThermoCabinet::add(newPhase(filename, phasename));
362         } catch (...) {
363             return handleAllExceptions(-1, ERR);
364         }
365     }
366 
thermo_newFromXML(int mxml)367     int thermo_newFromXML(int mxml)
368     {
369         try {
370             XML_Node& x = XmlCabinet::item(mxml);
371             ThermoPhase* th = newPhase(x);
372             return ThermoCabinet::add(th);
373         } catch (...) {
374             return handleAllExceptions(-1, ERR);
375         }
376     }
377 
thermo_getEosType(int n,size_t leneos,char * eos)378     int thermo_getEosType(int n, size_t leneos, char* eos)
379     {
380         try {
381             return static_cast<int>(copyString(ThermoCabinet::item(n).type(), eos, leneos));
382         } catch (...) {
383             return handleAllExceptions(-1, ERR);
384         }
385     }
386 
thermo_enthalpy_mole(int n)387     double thermo_enthalpy_mole(int n)
388     {
389         try {
390             return ThermoCabinet::item(n).enthalpy_mole();
391         } catch (...) {
392             return handleAllExceptions(DERR, DERR);
393         }
394     }
395 
thermo_intEnergy_mole(int n)396     double thermo_intEnergy_mole(int n)
397     {
398         try {
399             return ThermoCabinet::item(n).intEnergy_mole();
400         } catch (...) {
401             return handleAllExceptions(DERR, DERR);
402         }
403     }
404 
thermo_entropy_mole(int n)405     double thermo_entropy_mole(int n)
406     {
407         try {
408             return ThermoCabinet::item(n).entropy_mole();
409         } catch (...) {
410             return handleAllExceptions(DERR, DERR);
411         }
412     }
413 
thermo_gibbs_mole(int n)414     double thermo_gibbs_mole(int n)
415     {
416         try {
417             return ThermoCabinet::item(n).gibbs_mole();
418         } catch (...) {
419             return handleAllExceptions(DERR, DERR);
420         }
421     }
422 
thermo_cp_mole(int n)423     double thermo_cp_mole(int n)
424     {
425         try {
426             return ThermoCabinet::item(n).cp_mole();
427         } catch (...) {
428             return handleAllExceptions(DERR, DERR);
429         }
430     }
431 
thermo_cv_mole(int n)432     double thermo_cv_mole(int n)
433     {
434         try {
435             return ThermoCabinet::item(n).cv_mole();
436         } catch (...) {
437             return handleAllExceptions(DERR, DERR);
438         }
439     }
440 
thermo_pressure(int n)441     double thermo_pressure(int n)
442     {
443         try {
444             return ThermoCabinet::item(n).pressure();
445         } catch (...) {
446             return handleAllExceptions(DERR, DERR);
447         }
448     }
449 
thermo_enthalpy_mass(int n)450     double thermo_enthalpy_mass(int n)
451     {
452         try {
453             return ThermoCabinet::item(n).enthalpy_mass();
454         } catch (...) {
455             return handleAllExceptions(DERR, DERR);
456         }
457     }
458 
thermo_intEnergy_mass(int n)459     double thermo_intEnergy_mass(int n)
460     {
461         try {
462             return ThermoCabinet::item(n).intEnergy_mass();
463         } catch (...) {
464             return handleAllExceptions(DERR, DERR);
465         }
466     }
467 
thermo_entropy_mass(int n)468     double thermo_entropy_mass(int n)
469     {
470         try {
471             return ThermoCabinet::item(n).entropy_mass();
472         } catch (...) {
473             return handleAllExceptions(DERR, DERR);
474         }
475     }
476 
thermo_gibbs_mass(int n)477     double thermo_gibbs_mass(int n)
478     {
479         try {
480             return ThermoCabinet::item(n).gibbs_mass();
481         } catch (...) {
482             return handleAllExceptions(DERR, DERR);
483         }
484     }
485 
thermo_cp_mass(int n)486     double thermo_cp_mass(int n)
487     {
488         try {
489             return ThermoCabinet::item(n).cp_mass();
490         } catch (...) {
491             return handleAllExceptions(DERR, DERR);
492         }
493     }
494 
thermo_cv_mass(int n)495     double thermo_cv_mass(int n)
496     {
497         try {
498             return ThermoCabinet::item(n).cv_mass();
499         } catch (...) {
500             return handleAllExceptions(DERR, DERR);
501         }
502     }
503 
thermo_electricPotential(int n)504     double thermo_electricPotential(int n)
505     {
506         try {
507             return ThermoCabinet::item(n).electricPotential();
508         } catch (...) {
509             return handleAllExceptions(DERR, DERR);
510         }
511     }
512 
thermo_chemPotentials(int n,size_t lenm,double * murt)513     int thermo_chemPotentials(int n, size_t lenm, double* murt)
514     {
515         try {
516             ThermoPhase& thrm = ThermoCabinet::item(n);
517             thrm.checkSpeciesArraySize(lenm);
518             thrm.getChemPotentials(murt);
519             return 0;
520         } catch (...) {
521             return handleAllExceptions(-1, ERR);
522         }
523     }
524 
thermo_setPressure(int n,double p)525     int thermo_setPressure(int n, double p)
526     {
527         try {
528             if (p < 0.0) throw CanteraError("thermo_setPressure",
529                                                 "pressure cannot be negative");
530             ThermoCabinet::item(n).setPressure(p);
531             return 0;
532         } catch (...) {
533             return handleAllExceptions(-1, ERR);
534         }
535     }
536 
thermo_set_RP(int n,double * vals)537     int thermo_set_RP(int n, double* vals)
538     {
539         try{
540             ThermoCabinet::item(n).setState_RP(vals[0], vals[1]);
541             return 0;
542         } catch (...) {
543             return handleAllExceptions(-1, ERR);
544         }
545     }
546 
thermo_set_HP(int n,double * vals)547     int thermo_set_HP(int n, double* vals)
548     {
549         try {
550             if (vals[1] < 0.0) {
551                 throw CanteraError("thermo_set_HP",
552                                    "pressure cannot be negative");
553             }
554             ThermoCabinet::item(n).setState_HP(vals[0],vals[1]);
555             if (ThermoCabinet::item(n).temperature() < 0.0) {
556                 throw CanteraError("thermo_set_HP",
557                                    "temperature cannot be negative");
558             }
559             return 0;
560         } catch (...) {
561             return handleAllExceptions(-1, ERR);
562         }
563     }
564 
thermo_set_UV(int n,double * vals)565     int thermo_set_UV(int n, double* vals)
566     {
567         try {
568             if (vals[1] < 0.0) {
569                 throw CanteraError("thermo_set_UV",
570                                    "specific volume cannot be negative");
571             }
572             ThermoCabinet::item(n).setState_UV(vals[0],vals[1]);
573             if (ThermoCabinet::item(n).temperature() < 0.0) {
574                 throw CanteraError("thermo_set_UV",
575                                    "temperature cannot be negative");
576             }
577             return 0;
578         } catch (...) {
579             return handleAllExceptions(-1, ERR);
580         }
581     }
582 
thermo_set_SV(int n,double * vals)583     int thermo_set_SV(int n, double* vals)
584     {
585         try {
586             ThermoCabinet::item(n).setState_SV(vals[0],vals[1]);
587             return 0;
588         } catch (...) {
589             return handleAllExceptions(-1, ERR);
590         }
591     }
592 
thermo_set_SP(int n,double * vals)593     int thermo_set_SP(int n, double* vals)
594     {
595         try {
596             ThermoCabinet::item(n).setState_SP(vals[0],vals[1]);
597             return 0;
598         } catch (...) {
599             return handleAllExceptions(-1, ERR);
600         }
601     }
602 
thermo_set_ST(int n,double * vals)603     int thermo_set_ST(int n, double* vals)
604     {
605         try {
606             ThermoCabinet::item(n).setState_ST(vals[0],vals[1]);
607             return 0;
608         } catch (...) {
609             return handleAllExceptions(-1, ERR);
610         }
611     }
612 
thermo_set_TV(int n,double * vals)613     int thermo_set_TV(int n, double* vals)
614     {
615         try {
616             ThermoCabinet::item(n).setState_TV(vals[0],vals[1]);
617             return 0;
618         } catch (...) {
619             return handleAllExceptions(-1, ERR);
620         }
621     }
622 
thermo_set_PV(int n,double * vals)623     int thermo_set_PV(int n, double* vals)
624     {
625         try {
626             ThermoCabinet::item(n).setState_PV(vals[0],vals[1]);
627             return 0;
628         } catch (...) {
629             return handleAllExceptions(-1, ERR);
630         }
631     }
632 
thermo_set_UP(int n,double * vals)633     int thermo_set_UP(int n, double* vals)
634     {
635         try {
636             ThermoCabinet::item(n).setState_UP(vals[0],vals[1]);
637             return 0;
638         } catch (...) {
639             return handleAllExceptions(-1, ERR);
640         }
641     }
642 
thermo_set_VH(int n,double * vals)643     int thermo_set_VH(int n, double* vals)
644     {
645         try {
646             ThermoCabinet::item(n).setState_VH(vals[0],vals[1]);
647             return 0;
648         } catch (...) {
649             return handleAllExceptions(-1, ERR);
650         }
651     }
652 
thermo_set_TH(int n,double * vals)653     int thermo_set_TH(int n, double* vals)
654     {
655         try {
656             ThermoCabinet::item(n).setState_TH(vals[0],vals[1]);
657             return 0;
658         } catch (...) {
659             return handleAllExceptions(-1, ERR);
660         }
661     }
662 
thermo_set_SH(int n,double * vals)663     int thermo_set_SH(int n, double* vals)
664     {
665         try {
666             ThermoCabinet::item(n).setState_SH(vals[0],vals[1]);
667             return 0;
668         } catch (...) {
669             return handleAllExceptions(-1, ERR);
670         }
671     }
672 
thermo_equilibrate(int n,const char * XY,int solver,double rtol,int maxsteps,int maxiter,int loglevel)673     int thermo_equilibrate(int n, const char* XY, int solver,
674                            double rtol, int maxsteps, int maxiter, int loglevel)
675     {
676         try {
677             string ssolver;
678             if (solver < 0) {
679                 ssolver = "auto";
680             } else if (solver == 0) {
681                 ssolver = "element_potential";
682             } else if (solver == 1) {
683                 ssolver = "gibbs";
684             } else if (solver == 2) {
685                 ssolver = "vcs";
686             } else {
687                 throw CanteraError("thermo_equilibrate",
688                     "Invalid equilibrium solver specified.");
689             }
690             ThermoCabinet::item(n).equilibrate(XY, ssolver, rtol, maxsteps,
691                                                maxiter, 0, loglevel);
692             return 0;
693         } catch (...) {
694             return handleAllExceptions(-1, ERR);
695         }
696     }
697 
thermo_refPressure(int n)698     doublereal thermo_refPressure(int n)
699     {
700         try {
701             return ThermoCabinet::item(n).refPressure();
702         } catch (...) {
703             return handleAllExceptions(DERR, DERR);
704         }
705     }
706 
thermo_minTemp(int n,int k)707     doublereal thermo_minTemp(int n, int k)
708     {
709         try {
710             ThermoPhase& ph = ThermoCabinet::item(n);
711             if (k != -1) {
712                 ph.checkSpeciesIndex(k);
713                 return ph.minTemp(k);
714             } else {
715                 return ph.minTemp();
716             }
717         } catch (...) {
718             return handleAllExceptions(DERR, DERR);
719         }
720     }
721 
thermo_maxTemp(int n,int k)722     doublereal thermo_maxTemp(int n, int k)
723     {
724         try {
725             ThermoPhase& ph = ThermoCabinet::item(n);
726             if (k != -1) {
727                 ph.checkSpeciesIndex(k);
728                 return ph.maxTemp(k);
729             } else {
730                 return ph.maxTemp();
731             }
732         } catch (...) {
733             return handleAllExceptions(DERR, DERR);
734         }
735     }
736 
737 
thermo_getEnthalpies_RT(int n,size_t lenm,double * h_rt)738     int thermo_getEnthalpies_RT(int n, size_t lenm, double* h_rt)
739     {
740         try {
741             ThermoPhase& thrm = ThermoCabinet::item(n);
742             thrm.checkSpeciesArraySize(lenm);
743             thrm.getEnthalpy_RT_ref(h_rt);
744             return 0;
745         } catch (...) {
746             return handleAllExceptions(-1, ERR);
747         }
748     }
749 
thermo_getEntropies_R(int n,size_t lenm,double * s_r)750     int thermo_getEntropies_R(int n, size_t lenm, double* s_r)
751     {
752         try {
753             ThermoPhase& thrm = ThermoCabinet::item(n);
754             thrm.checkSpeciesArraySize(lenm);
755             thrm.getEntropy_R_ref(s_r);
756             return 0;
757         } catch (...) {
758             return handleAllExceptions(-1, ERR);
759         }
760     }
761 
thermo_getCp_R(int n,size_t lenm,double * cp_r)762     int thermo_getCp_R(int n, size_t lenm, double* cp_r)
763     {
764         try {
765             ThermoPhase& thrm = ThermoCabinet::item(n);
766             thrm.checkSpeciesArraySize(lenm);
767             thrm.getCp_R_ref(cp_r);
768             return 0;
769         } catch (...) {
770             return handleAllExceptions(-1, ERR);
771         }
772     }
773 
thermo_setElectricPotential(int n,double v)774     int thermo_setElectricPotential(int n, double v)
775     {
776         try {
777             ThermoCabinet::item(n).setElectricPotential(v);
778             return 0;
779         } catch (...) {
780             return handleAllExceptions(-1, ERR);
781         }
782     }
783 
thermo_thermalExpansionCoeff(int n)784     doublereal thermo_thermalExpansionCoeff(int n)
785     {
786         try {
787             return ThermoCabinet::item(n).thermalExpansionCoeff();
788         } catch (...) {
789             return handleAllExceptions(DERR, DERR);
790         }
791     }
792 
thermo_isothermalCompressibility(int n)793     doublereal thermo_isothermalCompressibility(int n)
794     {
795         try {
796             return ThermoCabinet::item(n).isothermalCompressibility();
797         } catch (...) {
798             return handleAllExceptions(DERR, DERR);
799         }
800     }
801 
802     //-------------- pure fluids ---------------//
803 
thermo_critTemperature(int n)804     double thermo_critTemperature(int n)
805     {
806         try {
807             return ThermoCabinet::item(n).critTemperature();
808         } catch (...) {
809             return handleAllExceptions(DERR, DERR);
810         }
811     }
812 
thermo_critPressure(int n)813     double thermo_critPressure(int n)
814     {
815         try {
816             return ThermoCabinet::item(n).critPressure();
817         } catch (...) {
818             return handleAllExceptions(DERR, DERR);
819         }
820     }
821 
thermo_critDensity(int n)822     double thermo_critDensity(int n)
823     {
824         try {
825             return ThermoCabinet::item(n).critDensity();
826         } catch (...) {
827             return handleAllExceptions(DERR, DERR);
828         }
829     }
830 
thermo_vaporFraction(int n)831     double thermo_vaporFraction(int n)
832     {
833         try {
834             return ThermoCabinet::get<PureFluidPhase>(n).vaporFraction();
835         } catch (...) {
836             return handleAllExceptions(DERR, DERR);
837         }
838     }
839 
thermo_satTemperature(int n,double p)840     double thermo_satTemperature(int n, double p)
841     {
842         try {
843             return ThermoCabinet::item(n).satTemperature(p);
844         } catch (...) {
845             return handleAllExceptions(DERR, DERR);
846         }
847     }
848 
thermo_satPressure(int n,double t)849     double thermo_satPressure(int n, double t)
850     {
851         try {
852             return ThermoCabinet::item(n).satPressure(t);
853         } catch (...) {
854             return handleAllExceptions(DERR, DERR);
855         }
856     }
857 
thermo_setState_Psat(int n,double p,double x)858     int thermo_setState_Psat(int n, double p, double x)
859     {
860         try {
861             ThermoCabinet::get<PureFluidPhase>(n).setState_Psat(p, x);
862             return 0;
863         } catch (...) {
864             return handleAllExceptions(-1, ERR);
865         }
866     }
867 
thermo_setState_Tsat(int n,double t,double x)868     int thermo_setState_Tsat(int n, double t, double x)
869     {
870         try {
871             ThermoCabinet::get<PureFluidPhase>(n).setState_Tsat(t, x);
872             return 0;
873         } catch (...) {
874             return handleAllExceptions(-1, ERR);
875         }
876     }
877 
878     //-------------- Kinetics ------------------//
879 
kin_newFromFile(const char * filename,const char * phasename,int reactingPhase,int neighbor1,int neighbor2,int neighbor3,int neighbor4)880     int kin_newFromFile(const char* filename, const char* phasename,
881                         int reactingPhase, int neighbor1, int neighbor2,
882                         int neighbor3, int neighbor4)
883     {
884         try {
885             vector<ThermoPhase*> phases;
886             phases.push_back(&ThermoCabinet::item(reactingPhase));
887             if (neighbor1 >= 0) {
888                 phases.push_back(&ThermoCabinet::item(neighbor1));
889                 if (neighbor2 >= 0) {
890                     phases.push_back(&ThermoCabinet::item(neighbor2));
891                     if (neighbor3 >= 0) {
892                         phases.push_back(&ThermoCabinet::item(neighbor3));
893                         if (neighbor4 >= 0) {
894                             phases.push_back(&ThermoCabinet::item(neighbor4));
895                         }
896                     }
897                 }
898             }
899             unique_ptr<Kinetics> kin = newKinetics(phases, filename, phasename);
900             return KineticsCabinet::add(kin.release());
901         } catch (...) {
902             return handleAllExceptions(-1, ERR);
903         }
904     }
905 
kin_newFromXML(int mxml,int iphase,int neighbor1,int neighbor2,int neighbor3,int neighbor4)906     int kin_newFromXML(int mxml, int iphase,
907                        int neighbor1, int neighbor2, int neighbor3,
908                        int neighbor4)
909     {
910         try {
911             XML_Node& x = XmlCabinet::item(mxml);
912             vector<ThermoPhase*> phases;
913             phases.push_back(&ThermoCabinet::item(iphase));
914             if (neighbor1 >= 0) {
915                 phases.push_back(&ThermoCabinet::item(neighbor1));
916                 if (neighbor2 >= 0) {
917                     phases.push_back(&ThermoCabinet::item(neighbor2));
918                     if (neighbor3 >= 0) {
919                         phases.push_back(&ThermoCabinet::item(neighbor3));
920                         if (neighbor4 >= 0) {
921                             phases.push_back(&ThermoCabinet::item(neighbor4));
922                         }
923                     }
924                 }
925             }
926             Kinetics* kin = newKineticsMgr(x, phases);
927             if (kin) {
928                 return KineticsCabinet::add(kin);
929             } else {
930                 return 0;
931             }
932         } catch (...) {
933             return handleAllExceptions(-1, ERR);
934         }
935     }
936 
937     //-------------------------------------
kin_getType(int n,size_t lennm,char * nm)938     int kin_getType(int n, size_t lennm, char* nm)
939     {
940         try {
941             return static_cast<int>(copyString(KineticsCabinet::item(n).kineticsType(), nm, lennm));
942         } catch (...) {
943             return handleAllExceptions(-1, ERR);
944         }
945     }
946 
kin_start(int n,int p)947     size_t kin_start(int n, int p)
948     {
949         try {
950             return KineticsCabinet::item(n).kineticsSpeciesIndex(0,p);
951         } catch (...) {
952             return handleAllExceptions(npos, npos);
953         }
954     }
955 
kin_speciesIndex(int n,const char * nm,const char * ph)956     size_t kin_speciesIndex(int n, const char* nm, const char* ph)
957     {
958         try {
959             return KineticsCabinet::item(n).kineticsSpeciesIndex(nm, ph);
960         } catch (...) {
961             return handleAllExceptions(npos, npos);
962         }
963     }
964 
965     //---------------------------------------
966 
kin_nSpecies(int n)967     size_t kin_nSpecies(int n)
968     {
969         try {
970             return KineticsCabinet::item(n).nTotalSpecies();
971         } catch (...) {
972             return handleAllExceptions(npos, npos);
973         }
974     }
975 
kin_nReactions(int n)976     size_t kin_nReactions(int n)
977     {
978         try {
979             return KineticsCabinet::item(n).nReactions();
980         } catch (...) {
981             return handleAllExceptions(npos, npos);
982         }
983     }
984 
kin_nPhases(int n)985     size_t kin_nPhases(int n)
986     {
987         try {
988             return KineticsCabinet::item(n).nPhases();
989         } catch (...) {
990             return handleAllExceptions(npos, npos);
991         }
992     }
993 
kin_phaseIndex(int n,const char * ph)994     size_t kin_phaseIndex(int n, const char* ph)
995     {
996         try {
997             return KineticsCabinet::item(n).phaseIndex(ph);
998         } catch (...) {
999             return handleAllExceptions(npos, npos);
1000         }
1001     }
1002 
kin_reactionPhaseIndex(int n)1003     size_t kin_reactionPhaseIndex(int n)
1004     {
1005         try {
1006             return KineticsCabinet::item(n).reactionPhaseIndex();
1007         } catch (...) {
1008             return handleAllExceptions(npos, npos);
1009         }
1010     }
1011 
kin_reactantStoichCoeff(int n,int k,int i)1012     double kin_reactantStoichCoeff(int n, int k, int i)
1013     {
1014         try {
1015             Kinetics& kin = KineticsCabinet::item(n);
1016             kin.checkSpeciesIndex(k);
1017             kin.checkReactionIndex(i);
1018             return kin.reactantStoichCoeff(k,i);
1019         } catch (...) {
1020             return handleAllExceptions(DERR, DERR);
1021         }
1022     }
1023 
kin_productStoichCoeff(int n,int k,int i)1024     double kin_productStoichCoeff(int n, int k, int i)
1025     {
1026         try {
1027             Kinetics& kin = KineticsCabinet::item(n);
1028             kin.checkSpeciesIndex(k);
1029             kin.checkReactionIndex(i);
1030             return kin.productStoichCoeff(k,i);
1031         } catch (...) {
1032             return handleAllExceptions(DERR, DERR);
1033         }
1034     }
1035 
kin_reactionType(int n,int i)1036     int kin_reactionType(int n, int i)
1037     {
1038         try {
1039             Kinetics& kin = KineticsCabinet::item(n);
1040             kin.checkReactionIndex(i);
1041             return kin.reactionType(i);
1042         } catch (...) {
1043             return handleAllExceptions(-1, ERR);
1044         }
1045     }
1046 
kin_getFwdRatesOfProgress(int n,size_t len,double * fwdROP)1047     int kin_getFwdRatesOfProgress(int n, size_t len, double* fwdROP)
1048     {
1049         try {
1050             Kinetics& k = KineticsCabinet::item(n);
1051             k.checkReactionArraySize(len);
1052             k.getFwdRatesOfProgress(fwdROP);
1053             return 0;
1054         } catch (...) {
1055             return handleAllExceptions(-1, ERR);
1056         }
1057     }
1058 
kin_getRevRatesOfProgress(int n,size_t len,double * revROP)1059     int kin_getRevRatesOfProgress(int n, size_t len, double* revROP)
1060     {
1061         try {
1062             Kinetics& k = KineticsCabinet::item(n);
1063             k.checkReactionArraySize(len);
1064             k.getRevRatesOfProgress(revROP);
1065             return 0;
1066         } catch (...) {
1067             return handleAllExceptions(-1, ERR);
1068         }
1069     }
1070 
kin_isReversible(int n,int i)1071     int kin_isReversible(int n, int i)
1072     {
1073         try {
1074             Kinetics& kin = KineticsCabinet::item(n);
1075             kin.checkReactionIndex(i);
1076             return (int) kin.isReversible(i);
1077         } catch (...) {
1078             return handleAllExceptions(-1, ERR);
1079         }
1080     }
1081 
kin_getNetRatesOfProgress(int n,size_t len,double * netROP)1082     int kin_getNetRatesOfProgress(int n, size_t len, double* netROP)
1083     {
1084         try {
1085             Kinetics& k = KineticsCabinet::item(n);
1086             k.checkReactionArraySize(len);
1087             k.getNetRatesOfProgress(netROP);
1088             return 0;
1089         } catch (...) {
1090             return handleAllExceptions(-1, ERR);
1091         }
1092     }
1093 
kin_getFwdRateConstants(int n,size_t len,double * kfwd)1094     int kin_getFwdRateConstants(int n, size_t len, double* kfwd)
1095     {
1096         try {
1097             Kinetics& k = KineticsCabinet::item(n);
1098             k.checkReactionArraySize(len);
1099             k.getFwdRateConstants(kfwd);
1100             return 0;
1101         } catch (...) {
1102             return handleAllExceptions(-1, ERR);
1103         }
1104     }
1105 
kin_getRevRateConstants(int n,int doIrreversible,size_t len,double * krev)1106     int kin_getRevRateConstants(int n, int doIrreversible, size_t len, double* krev)
1107     {
1108         try {
1109             Kinetics& k = KineticsCabinet::item(n);
1110             k.checkReactionArraySize(len);
1111             k.getRevRateConstants(krev, doIrreversible != 0);
1112             return 0;
1113         } catch (...) {
1114             return handleAllExceptions(-1, ERR);
1115         }
1116     }
1117 
kin_getDelta(int n,int job,size_t len,double * delta)1118     int kin_getDelta(int n, int job, size_t len, double* delta)
1119     {
1120         try {
1121             Kinetics& k = KineticsCabinet::item(n);
1122             k.checkReactionArraySize(len);
1123             switch (job) {
1124             case 0:
1125                 k.getDeltaEnthalpy(delta);
1126                 break;
1127             case 1:
1128                 k.getDeltaGibbs(delta);
1129                 break;
1130             case 2:
1131                 k.getDeltaEntropy(delta);
1132                 break;
1133             case 3:
1134                 k.getDeltaSSEnthalpy(delta);
1135                 break;
1136             case 4:
1137                 k.getDeltaSSGibbs(delta);
1138                 break;
1139             case 5:
1140                 k.getDeltaSSEntropy(delta);
1141                 break;
1142             default:
1143                 return ERR;
1144             }
1145             return 0;
1146         } catch (...) {
1147             return handleAllExceptions(-1, ERR);
1148         }
1149     }
1150 
kin_getCreationRates(int n,size_t len,double * cdot)1151     int kin_getCreationRates(int n, size_t len, double* cdot)
1152     {
1153         try {
1154             Kinetics& k = KineticsCabinet::item(n);
1155             k.checkSpeciesArraySize(len);
1156             k.getCreationRates(cdot);
1157             return 0;
1158         } catch (...) {
1159             return handleAllExceptions(-1, ERR);
1160         }
1161     }
1162 
kin_getDestructionRates(int n,size_t len,double * ddot)1163     int kin_getDestructionRates(int n, size_t len, double* ddot)
1164     {
1165         try {
1166             Kinetics& k = KineticsCabinet::item(n);
1167             k.checkSpeciesArraySize(len);
1168             k.getDestructionRates(ddot);
1169             return 0;
1170         } catch (...) {
1171             return handleAllExceptions(-1, ERR);
1172         }
1173     }
1174 
kin_getNetProductionRates(int n,size_t len,double * wdot)1175     int kin_getNetProductionRates(int n, size_t len, double* wdot)
1176     {
1177         try {
1178             Kinetics& k = KineticsCabinet::item(n);
1179             k.checkSpeciesArraySize(len);
1180             k.getNetProductionRates(wdot);
1181             return 0;
1182         } catch (...) {
1183             return handleAllExceptions(-1, ERR);
1184         }
1185     }
1186 
kin_getSourceTerms(int n,size_t len,double * ydot)1187     int kin_getSourceTerms(int n, size_t len, double* ydot)
1188     {
1189         try {
1190             // @todo This function only works for single phase kinetics
1191             Kinetics& k = KineticsCabinet::item(n);
1192             ThermoPhase& p = k.thermo();
1193             size_t nsp = p.nSpecies();
1194             k.checkSpeciesArraySize(len);
1195             k.checkSpeciesArraySize(nsp);
1196             k.getNetProductionRates(ydot);
1197             double rho_inv = 1.0 / p.density();
1198             for (size_t k = 0; k < nsp; k++) {
1199                 ydot[k] *= p.molecularWeight(k) * rho_inv;
1200             }
1201             return 0;
1202         } catch (...) {
1203             return handleAllExceptions(-1, ERR);
1204         }
1205     }
1206 
kin_multiplier(int n,int i)1207     double kin_multiplier(int n, int i)
1208     {
1209         try {
1210             Kinetics& kin = KineticsCabinet::item(n);
1211             kin.checkReactionIndex(i);
1212             return kin.multiplier(i);
1213         } catch (...) {
1214             return handleAllExceptions(DERR, DERR);
1215         }
1216     }
1217 
kin_phase(int n,size_t i)1218     size_t kin_phase(int n, size_t i)
1219     {
1220         try {
1221             Kinetics& kin = KineticsCabinet::item(n);
1222             kin.checkPhaseIndex(i);
1223             return ThermoCabinet::index(kin.thermo(i));
1224         } catch (...) {
1225             return handleAllExceptions(npos, npos);
1226         }
1227     }
1228 
kin_getEquilibriumConstants(int n,size_t len,double * kc)1229     int kin_getEquilibriumConstants(int n, size_t len, double* kc)
1230     {
1231         try {
1232             Kinetics& k = KineticsCabinet::item(n);
1233             k.checkReactionArraySize(len);
1234             k.getEquilibriumConstants(kc);
1235             return 0;
1236         } catch (...) {
1237             return handleAllExceptions(-1, ERR);
1238         }
1239     }
1240 
kin_getReactionString(int n,int i,int len,char * buf)1241     int kin_getReactionString(int n, int i, int len, char* buf)
1242     {
1243         try {
1244             Kinetics& k = KineticsCabinet::item(n);
1245             k.checkReactionIndex(i);
1246             return static_cast<int>(copyString(k.reactionString(i), buf, len));
1247         } catch (...) {
1248             return handleAllExceptions(-1, ERR);
1249         }
1250     }
1251 
kin_setMultiplier(int n,int i,double v)1252     int kin_setMultiplier(int n, int i, double v)
1253     {
1254         try {
1255             if (v >= 0.0) {
1256                 Kinetics& kin = KineticsCabinet::item(n);
1257                 kin.checkReactionIndex(i);
1258                 kin.setMultiplier(i,v);
1259                 return 0;
1260             } else {
1261                 return ERR;
1262             }
1263         } catch (...) {
1264             return handleAllExceptions(-1, ERR);
1265         }
1266     }
1267 
kin_advanceCoverages(int n,double tstep)1268     int kin_advanceCoverages(int n, double tstep)
1269     {
1270         try {
1271             KineticsCabinet::get<InterfaceKinetics>(n).advanceCoverages(tstep);
1272             return 0;
1273         } catch (...) {
1274             return handleAllExceptions(-1, ERR);
1275         }
1276     }
1277 
1278     //------------------- Transport ---------------------------
1279 
trans_newDefault(int ith,int loglevel)1280     int trans_newDefault(int ith, int loglevel)
1281     {
1282         try {
1283             Transport* tr = newDefaultTransportMgr(&ThermoCabinet::item(ith),
1284                                                    loglevel);
1285             return TransportCabinet::add(tr);
1286         } catch (...) {
1287             return handleAllExceptions(-1, ERR);
1288         }
1289     }
1290 
trans_new(const char * model,int ith,int loglevel)1291     int trans_new(const char* model, int ith, int loglevel)
1292     {
1293         try {
1294             Transport* tr = newTransportMgr(model, &ThermoCabinet::item(ith),
1295                                             loglevel);
1296             return TransportCabinet::add(tr);
1297         } catch (...) {
1298             return handleAllExceptions(-1, ERR);
1299         }
1300     }
1301 
trans_viscosity(int n)1302     double trans_viscosity(int n)
1303     {
1304         try {
1305             return TransportCabinet::item(n).viscosity();
1306         } catch (...) {
1307             return handleAllExceptions(-1, ERR);
1308         }
1309     }
1310 
trans_electricalConductivity(int n)1311     double trans_electricalConductivity(int n)
1312     {
1313         try {
1314             return TransportCabinet::item(n).electricalConductivity();
1315         } catch (...) {
1316             return handleAllExceptions(-1, ERR);
1317         }
1318     }
1319 
trans_thermalConductivity(int n)1320     double trans_thermalConductivity(int n)
1321     {
1322         try {
1323             return TransportCabinet::item(n).thermalConductivity();
1324         } catch (...) {
1325             return handleAllExceptions(-1, ERR);
1326         }
1327     }
1328 
trans_getThermalDiffCoeffs(int n,int ldt,double * dt)1329     int trans_getThermalDiffCoeffs(int n, int ldt, double* dt)
1330     {
1331         try {
1332             Transport& tr = TransportCabinet::item(n);
1333             tr.checkSpeciesArraySize(ldt);
1334             tr.getThermalDiffCoeffs(dt);
1335             return 0;
1336         } catch (...) {
1337             return handleAllExceptions(-1, ERR);
1338         }
1339     }
1340 
trans_getMixDiffCoeffs(int n,int ld,double * d)1341     int trans_getMixDiffCoeffs(int n, int ld, double* d)
1342     {
1343         try {
1344             Transport& tr = TransportCabinet::item(n);
1345             tr.checkSpeciesArraySize(ld);
1346             tr.getMixDiffCoeffs(d);
1347             return 0;
1348         } catch (...) {
1349             return handleAllExceptions(-1, ERR);
1350         }
1351     }
1352 
trans_getBinDiffCoeffs(int n,int ld,double * d)1353     int trans_getBinDiffCoeffs(int n, int ld, double* d)
1354     {
1355         try {
1356             // @todo length of d should be passed for bounds checking
1357             Transport& tr = TransportCabinet::item(n);
1358             tr.checkSpeciesArraySize(ld);
1359             tr.getBinaryDiffCoeffs(ld,d);
1360             return 0;
1361         } catch (...) {
1362             return handleAllExceptions(-1, ERR);
1363         }
1364     }
1365 
trans_getMultiDiffCoeffs(int n,int ld,double * d)1366     int trans_getMultiDiffCoeffs(int n, int ld, double* d)
1367     {
1368         try {
1369             // @todo length of d should be passed for bounds checking
1370             Transport& tr = TransportCabinet::item(n);
1371             tr.checkSpeciesArraySize(ld);
1372             tr.getMultiDiffCoeffs(ld,d);
1373             return 0;
1374         } catch (...) {
1375             return handleAllExceptions(-1, ERR);
1376         }
1377     }
1378 
trans_setParameters(int n,int type,int k,double * d)1379     int trans_setParameters(int n, int type, int k, double* d)
1380     {
1381         try {
1382             TransportCabinet::item(n).setParameters(type, k, d);
1383             return 0;
1384         } catch (...) {
1385             return handleAllExceptions(-1, ERR);
1386         }
1387     }
1388 
trans_getMolarFluxes(int n,const double * state1,const double * state2,double delta,double * fluxes)1389     int trans_getMolarFluxes(int n, const double* state1,
1390                              const double* state2, double delta, double* fluxes)
1391     {
1392         try {
1393             TransportCabinet::item(n).getMolarFluxes(state1, state2, delta, fluxes);
1394             return 0;
1395         } catch (...) {
1396             return handleAllExceptions(-1, ERR);
1397         }
1398     }
1399 
trans_getMassFluxes(int n,const double * state1,const double * state2,double delta,double * fluxes)1400     int trans_getMassFluxes(int n, const double* state1,
1401                             const double* state2, double delta, double* fluxes)
1402     {
1403         try {
1404             TransportCabinet::item(n).getMassFluxes(state1, state2, delta, fluxes);
1405             return 0;
1406         } catch (...) {
1407             return handleAllExceptions(-1, ERR);
1408         }
1409     }
1410 
1411     //-------------------- Functions ---------------------------
1412 
thermo_report(int nth,int ibuf,char * buf,int show_thermo)1413     int thermo_report(int nth, int ibuf, char* buf, int show_thermo)
1414     {
1415         try {
1416             bool stherm = (show_thermo != 0);
1417             string s = ThermoCabinet::item(nth).report(stherm);
1418             if (int(s.size()) > ibuf - 1) {
1419                 return -(static_cast<int>(s.size()) + 1);
1420             }
1421             copyString(s, buf, ibuf);
1422             return 0;
1423         } catch (...) {
1424             return handleAllExceptions(-1, ERR);
1425         }
1426     }
1427 
thermo_print(int nth,int show_thermo,double threshold)1428     int thermo_print(int nth, int show_thermo, double threshold)
1429     {
1430         try {
1431             bool stherm = (show_thermo != 0);
1432             writelog(ThermoCabinet::item(nth).report(stherm, threshold)+"\n");
1433             return 0;
1434         } catch (...) {
1435             return handleAllExceptions(-1, ERR);
1436         }
1437     }
1438 
ct_getCanteraError(int buflen,char * buf)1439     int ct_getCanteraError(int buflen, char* buf)
1440     {
1441         try {
1442             string e = Application::Instance()->lastErrorMessage();
1443             copyString(e, buf, buflen);
1444             return int(e.size());
1445         } catch (...) {
1446             return handleAllExceptions(-1, ERR);
1447         }
1448     }
1449 
ct_addCanteraDirectory(size_t buflen,const char * buf)1450     int ct_addCanteraDirectory(size_t buflen, const char* buf)
1451     {
1452         try {
1453             addDirectory(buf);
1454             return 0;
1455         } catch (...) {
1456             return handleAllExceptions(-1, ERR);
1457         }
1458     }
1459 
ct_getDataDirectories(int buflen,char * buf,const char * sep)1460     int ct_getDataDirectories(int buflen, char* buf, const char* sep)
1461     {
1462         try {
1463             return static_cast<int>(copyString(getDataDirectories(sep), buf, buflen));
1464         } catch (...) {
1465             return handleAllExceptions(-1, ERR);
1466         }
1467     }
1468 
ct_getCanteraVersion(int buflen,char * buf)1469     int ct_getCanteraVersion(int buflen, char* buf)
1470     {
1471         try {
1472             return static_cast<int>(copyString(CANTERA_VERSION, buf, buflen));
1473         } catch (...) {
1474             return handleAllExceptions(-1, ERR);
1475         }
1476     }
1477 
ct_getGitCommit(int buflen,char * buf)1478     int ct_getGitCommit(int buflen, char* buf)
1479     {
1480         try {
1481             return static_cast<int>(copyString(gitCommit(), buf, buflen));
1482         } catch (...) {
1483             return handleAllExceptions(-1, ERR);
1484         }
1485     }
1486 
ct_suppress_thermo_warnings(int suppress)1487     int ct_suppress_thermo_warnings(int suppress)
1488     {
1489         try {
1490             suppress_thermo_warnings(suppress != 0);
1491             return 0;
1492         } catch (...) {
1493             return handleAllExceptions(-1, ERR);
1494         }
1495     }
1496 
ct_use_legacy_rate_constants(int legacy)1497     int ct_use_legacy_rate_constants(int legacy)
1498     {
1499         try {
1500             use_legacy_rate_constants(legacy != 0);
1501             return 0;
1502         } catch (...) {
1503             return handleAllExceptions(-1, ERR);
1504         }
1505     }
1506 
ct_setLogWriter(void * logger)1507     int ct_setLogWriter(void* logger)
1508     {
1509         try {
1510             Logger* logwriter = (Logger*)logger;
1511             setLogger(logwriter);
1512             return 0;
1513         } catch (...) {
1514             return handleAllExceptions(-1, ERR);
1515         }
1516     }
1517 
ct_clearStorage()1518     int ct_clearStorage()
1519     {
1520         try {
1521             ThermoCabinet::clear();
1522             KineticsCabinet::clear();
1523             TransportCabinet::clear();
1524             return 0;
1525         } catch (...) {
1526             return handleAllExceptions(-1, ERR);
1527         }
1528     }
1529 
thermo_del(int n)1530     int thermo_del(int n)
1531     {
1532         try {
1533             ThermoCabinet::del(n);
1534             return 0;
1535         } catch (...) {
1536             return handleAllExceptions(-1, ERR);
1537         }
1538     }
1539 
kin_del(int n)1540     int kin_del(int n)
1541     {
1542         try {
1543             KineticsCabinet::del(n);
1544             return 0;
1545         } catch (...) {
1546             return handleAllExceptions(-1, ERR);
1547         }
1548     }
1549 
trans_del(int n)1550     int trans_del(int n)
1551     {
1552         try {
1553             TransportCabinet::del(n);
1554             return 0;
1555         } catch (...) {
1556             return handleAllExceptions(-1, ERR);
1557         }
1558     }
1559 
ct_ck2cti(const char * in_file,const char * db_file,const char * tr_file,const char * id_tag,int debug,int validate)1560     int ct_ck2cti(const char* in_file, const char* db_file, const char* tr_file,
1561                   const char* id_tag, int debug, int validate)
1562     {
1563         try {
1564             ck2cti(in_file, db_file, tr_file, id_tag);
1565             return 0;
1566         } catch (...) {
1567             return handleAllExceptions(-1, ERR);
1568         }
1569     }
1570 }
1571