Cantera  3.2.0b1
Loading...
Searching...
No Matches
ctonedim.cpp
Go to the documentation of this file.
1/**
2 * CTONEDIM - Generated CLib %Cantera interface library.
3 *
4 * @file ctonedim.cpp
5 *
6 * Generated CLib API for Cantera's Sim1D 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"
20
21#include "cantera/oneD/Sim1D.h"
23
24using namespace Cantera;
25
26//! @cond
27//! Cabinet type definitions will be ignored by Doxygen
28
29// Define Cabinet<Sim1D> (single-instance object)
30typedef Cabinet<Sim1D> Sim1DCabinet;
31template<> Sim1DCabinet* Sim1DCabinet::s_storage = 0; // initialized here
32
33typedef Cabinet<Domain1D> Domain1DCabinet;
34template<> Domain1DCabinet* Domain1DCabinet::s_storage; // initialized elsewhere
35
36//! @endcond
37
38extern "C" {
39
40 int32_t sim1D_newSim1D(int32_t domainsLen, int32_t* domains)
41 {
42 // constructor: shared_ptr<Sim1D> newSim1D(vector<shared_ptr<Domain1D>>&)
43 try {
44 vector<shared_ptr<Domain1D>> domains_;
45 for (int i = 0; i < domainsLen; i++) {
46 domains_.push_back(Domain1DCabinet::at(domains[i]));
47 }
48 return Sim1DCabinet::add(newSim1D(domains_));
49 } catch (...) {
50 return handleAllExceptions(-2, ERR);
51 }
52 }
53
54 int32_t sim1D_setValue(int32_t handle, int32_t dom, int32_t comp, int32_t localPoint, double value)
55 {
56 // method: void Sim1D::setValue(size_t, size_t, size_t, double)
57 try {
58 Sim1DCabinet::at(handle)->setValue(dom, comp, localPoint, value);
59 return 0;
60 } catch (...) {
61 return handleAllExceptions(-1, ERR);
62 }
63 }
64
65 int32_t sim1D_setProfile(int32_t handle, int32_t dom, int32_t comp, int32_t posLen, const double* pos, int32_t valuesLen, const double* values)
66 {
67 // method: void Sim1D::setProfile(size_t, size_t, const vector<double>&, const vector<double>&)
68 try {
69 const vector<double> pos_(pos, pos + posLen);
70 const vector<double> values_(values, values + valuesLen);
71 Sim1DCabinet::at(handle)->setProfile(dom, comp, pos_, values_);
72 return 0;
73 } catch (...) {
74 return handleAllExceptions(-1, ERR);
75 }
76 }
77
78 int32_t sim1D_setFlatProfile(int32_t handle, int32_t dom, int32_t comp, double v)
79 {
80 // method: void Sim1D::setFlatProfile(size_t, size_t, double)
81 try {
82 Sim1DCabinet::at(handle)->setFlatProfile(dom, comp, v);
83 return 0;
84 } catch (...) {
85 return handleAllExceptions(-1, ERR);
86 }
87 }
88
89 int32_t sim1D_setInitialGuess(int32_t handle, const char* component, int32_t locsLen, double* locs, int32_t valsLen, double* vals)
90 {
91 // method: void Sim1D::setInitialGuess(const string&, vector<double>&, vector<double>&)
92 try {
93 vector<double> locs_(locs, locs + locsLen);
94 vector<double> vals_(vals, vals + valsLen);
95 Sim1DCabinet::at(handle)->setInitialGuess(component, locs_, vals_);
96 std::copy(locs_.begin(), locs_.end(), locs);
97 std::copy(vals_.begin(), vals_.end(), vals);
98 return 0;
99 } catch (...) {
100 return handleAllExceptions(-1, ERR);
101 }
102 }
103
104 int32_t sim1D_show(int32_t handle)
105 {
106 // method: void Sim1D::show()
107 try {
108 Sim1DCabinet::at(handle)->show();
109 return 0;
110 } catch (...) {
111 return handleAllExceptions(-1, ERR);
112 }
113 }
114
115 int32_t sim1D_setTimeStep(int32_t handle, double stepSize, int32_t tStepsLen, const int32_t* tSteps)
116 {
117 // method: void SteadyStateSystem::setTimeStep(double, const vector<int>&)
118 try {
119 const vector<int> tSteps_(tSteps, tSteps + tStepsLen);
120 Sim1DCabinet::as<SteadyStateSystem>(handle)->setTimeStep(stepSize, tSteps_);
121 return 0;
122 } catch (...) {
123 return handleAllExceptions(-1, ERR);
124 }
125 }
126
127 int32_t sim1D_getInitialSoln(int32_t handle)
128 {
129 // method: void Sim1D::getInitialSoln()
130 try {
131 Sim1DCabinet::at(handle)->getInitialSoln();
132 return 0;
133 } catch (...) {
134 return handleAllExceptions(-1, ERR);
135 }
136 }
137
138 int32_t sim1D_solve(int32_t handle, int32_t loglevel, int32_t refine_grid)
139 {
140 // method: void Sim1D::solve(int, bool)
141 try {
142 bool refine_grid_ = (refine_grid != 0);
143 Sim1DCabinet::at(handle)->solve(loglevel, refine_grid_);
144 return 0;
145 } catch (...) {
146 return handleAllExceptions(-1, ERR);
147 }
148 }
149
150 int32_t sim1D_refine(int32_t handle, int32_t loglevel)
151 {
152 // method: int Sim1D::refine(int)
153 try {
154 return Sim1DCabinet::at(handle)->refine(loglevel);
155 } catch (...) {
156 return handleAllExceptions(ERR, ERR);
157 }
158 }
159
160 int32_t sim1D_setRefineCriteria(int32_t handle, int32_t dom, double ratio, double slope, double curve, double prune)
161 {
162 // method: void Sim1D::setRefineCriteria(int, double, double, double, double)
163 try {
164 Sim1DCabinet::at(handle)->setRefineCriteria(dom, ratio, slope, curve, prune);
165 return 0;
166 } catch (...) {
167 return handleAllExceptions(-1, ERR);
168 }
169 }
170
171 int32_t sim1D_setGridMin(int32_t handle, int32_t dom, double gridmin)
172 {
173 // method: void Sim1D::setGridMin(int, double)
174 try {
175 Sim1DCabinet::at(handle)->setGridMin(dom, gridmin);
176 return 0;
177 } catch (...) {
178 return handleAllExceptions(-1, ERR);
179 }
180 }
181
182 int32_t sim1D_save(int32_t handle, const char* fname, const char* name, const char* desc, int32_t overwrite)
183 {
184 // method: void Sim1D::save(const string&, const string&, const string&, bool)
185 try {
186 bool overwrite_ = (overwrite != 0);
187 Sim1DCabinet::at(handle)->save(fname, name, desc, overwrite_);
188 return 0;
189 } catch (...) {
190 return handleAllExceptions(-1, ERR);
191 }
192 }
193
194 int32_t sim1D_restore(int32_t handle, const char* fname, const char* name)
195 {
196 // method: void Sim1D::_restore(const string&, const string&)
197 try {
198 Sim1DCabinet::at(handle)->_restore(fname, name);
199 return 0;
200 } catch (...) {
201 return handleAllExceptions(-1, ERR);
202 }
203 }
204
205 int32_t sim1D_writeStats(int32_t handle, int32_t printTime)
206 {
207 // setter: void OneDim::writeStats(int)
208 try {
209 Sim1DCabinet::as<OneDim>(handle)->writeStats(printTime);
210 return 0;
211 } catch (...) {
212 return handleAllExceptions(-1, ERR);
213 }
214 }
215
216 int32_t sim1D_domainIndex(int32_t handle, const char* name)
217 {
218 // size getter: size_t OneDim::domainIndex(const string&)
219 try {
220 return static_cast<int32_t>(Sim1DCabinet::as<OneDim>(handle)->domainIndex(name));
221 } catch (...) {
222 return handleAllExceptions(ERR, ERR);
223 }
224 }
225
226 double sim1D_value(int32_t handle, int32_t dom, int32_t comp, int32_t localPoint)
227 {
228 // method: double Sim1D::value(size_t, size_t, size_t)
229 try {
230 return Sim1DCabinet::at(handle)->value(dom, comp, localPoint);
231 } catch (...) {
232 return handleAllExceptions(DERR, DERR);
233 }
234 }
235
236 double sim1D_workValue(int32_t handle, int32_t dom, int32_t comp, int32_t localPoint)
237 {
238 // method: double Sim1D::workValue(size_t, size_t, size_t)
239 try {
240 return Sim1DCabinet::at(handle)->workValue(dom, comp, localPoint);
241 } catch (...) {
242 return handleAllExceptions(DERR, DERR);
243 }
244 }
245
246 int32_t sim1D_eval(int32_t handle, int32_t xLen, double* x, int32_t rLen, double* r, double rdt, int32_t count)
247 {
248 // method: void Sim1D::eval(double*, double*, double, int)
249 try {
250 Sim1DCabinet::at(handle)->eval(x, r, rdt, count);
251 return 0;
252 } catch (...) {
253 return handleAllExceptions(-1, ERR);
254 }
255 }
256
257 int32_t sim1D_setMaxJacAge(int32_t handle, int32_t ss_age, int32_t ts_age)
258 {
259 // method: void SteadyStateSystem::setJacAge(int, int)
260 try {
261 Sim1DCabinet::as<SteadyStateSystem>(handle)->setJacAge(ss_age, ts_age);
262 return 0;
263 } catch (...) {
264 return handleAllExceptions(-1, ERR);
265 }
266 }
267
268 int32_t sim1D_setFixedTemperature(int32_t handle, double t)
269 {
270 // method: int Sim1D::setFixedTemperature(double)
271 try {
272 return Sim1DCabinet::at(handle)->setFixedTemperature(t);
273 } catch (...) {
274 return handleAllExceptions(ERR, ERR);
275 }
276 }
277
278 int32_t sim1D_del(int32_t handle)
279 {
280 // destructor
281 try {
282 Sim1DCabinet::del(handle);
283 return 0;
284 } catch (...) {
285 return handleAllExceptions(-1, ERR);
286 }
287 }
288
290 {
291 // reserved CLib function: custom code
292 try {
293 // *************** begin custom code ***************
294 return Sim1DCabinet::size();
295 // **************** end custom code ****************
296 } catch (...) {
297 return handleAllExceptions(-1, ERR);
298 }
299 }
300
301} // extern "C"
Template for classes to hold pointers to objects.
Definition Cabinet.h:51
int32_t sim1D_setTimeStep(int32_t handle, double stepSize, int32_t tStepsLen, const int32_t *tSteps)
Set the number of time steps to try when the steady Newton solver is unsuccessful.
Definition ctonedim.cpp:115
int32_t sim1D_restore(int32_t handle, const char *fname, const char *name)
Retrieve data from a previously saved simulation.
Definition ctonedim.cpp:194
int32_t sim1D_setValue(int32_t handle, int32_t dom, int32_t comp, int32_t localPoint, double value)
Set a single value in the solution vector.
Definition ctonedim.cpp:54
int32_t sim1D_getInitialSoln(int32_t handle)
Get the initial value of the system state from each domain in the simulation.
Definition ctonedim.cpp:127
int32_t sim1D_writeStats(int32_t handle, int32_t printTime)
Write statistics about the number of iterations and Jacobians at each grid level.
Definition ctonedim.cpp:205
int32_t sim1D_del(int32_t handle)
Delete Sim1D object.
Definition ctonedim.cpp:278
double sim1D_workValue(int32_t handle, int32_t dom, int32_t comp, int32_t localPoint)
Get an entry in the work vector, which may contain either a new system state or the current residual ...
Definition ctonedim.cpp:236
int32_t sim1D_cabinetSize()
Return size of Sim1D storage.
Definition ctonedim.cpp:289
int32_t sim1D_save(int32_t handle, const char *fname, const char *name, const char *desc, int32_t overwrite)
Save current simulation data to a container file or CSV format.
Definition ctonedim.cpp:182
int32_t sim1D_setInitialGuess(int32_t handle, const char *component, int32_t locsLen, double *locs, int32_t valsLen, double *vals)
Set initial guess for one component for all domains.
Definition ctonedim.cpp:89
int32_t sim1D_eval(int32_t handle, int32_t xLen, double *x, int32_t rLen, double *r, double rdt, int32_t count)
Evaluate the residual function.
Definition ctonedim.cpp:246
int32_t sim1D_setProfile(int32_t handle, int32_t dom, int32_t comp, int32_t posLen, const double *pos, int32_t valuesLen, const double *values)
Specify a profile for one component of one domain.
Definition ctonedim.cpp:65
int32_t sim1D_setRefineCriteria(int32_t handle, int32_t dom, double ratio, double slope, double curve, double prune)
Set grid refinement criteria.
Definition ctonedim.cpp:160
int32_t sim1D_show(int32_t handle)
Show logging information on current solution for all domains.
Definition ctonedim.cpp:104
int32_t sim1D_setGridMin(int32_t handle, int32_t dom, double gridmin)
Set the minimum grid spacing in the specified domain(s).
Definition ctonedim.cpp:171
int32_t sim1D_refine(int32_t handle, int32_t loglevel)
Refine the grid in all domains.
Definition ctonedim.cpp:150
int32_t sim1D_setFixedTemperature(int32_t handle, double t)
Add node for fixed temperature point of freely propagating flame.
Definition ctonedim.cpp:268
int32_t sim1D_newSim1D(int32_t domainsLen, int32_t *domains)
Create a Sim1D object with a list of domains.
Definition ctonedim.cpp:40
double sim1D_value(int32_t handle, int32_t dom, int32_t comp, int32_t localPoint)
Get one entry in the solution vector.
Definition ctonedim.cpp:226
int32_t sim1D_setFlatProfile(int32_t handle, int32_t dom, int32_t comp, double v)
Set component 'comp' of domain 'dom' to value 'v' at all points.
Definition ctonedim.cpp:78
int32_t sim1D_solve(int32_t handle, int32_t loglevel, int32_t refine_grid)
Performs the hybrid Newton steady/time-stepping solution.
Definition ctonedim.cpp:138
int32_t sim1D_domainIndex(int32_t handle, const char *name)
Get the index of the domain named name.
Definition ctonedim.cpp:216
int32_t sim1D_setMaxJacAge(int32_t handle, int32_t ss_age, int32_t ts_age)
Set the maximum number of steps that can be taken using the same Jacobian before it must be re-evalua...
Definition ctonedim.cpp:257
CTONEDIM - Generated CLib Cantera interface library.
Namespace for the Cantera kernel.
Definition AnyMap.cpp:595
shared_ptr< Sim1D > newSim1D(vector< shared_ptr< Domain1D > > &domains)
Create a Sim1D object with a list of domains.
Definition Sim1D.cpp:858
T handleAllExceptions(T ctErrorCode, T otherErrorCode)
Exception handler used at language interface boundaries.
Definition clib_utils.h:32