17 static void sim1D_drawline()
38 m_x.resize(
size(), 0.0);
39 m_xnew.resize(
size(), 0.0);
40 for (
size_t n = 0; n <
m_nd; n++) {
42 domain(n).m_adiabatic=
false;
51 m_steps.push_back(10);
59 for (
size_t dom=0; dom<
m_nd; dom++) {
62 for (
size_t comp=0; comp<ncomp; comp++) {
79 void Sim1D::setValue(
size_t dom,
size_t comp,
size_t localPoint, doublereal value)
92 doublereal
Sim1D::value(
size_t dom,
size_t comp,
size_t localPoint)
const
96 int j =
static_cast<int>(iloc);
100 if (j >= (
int) m_x.size()) {
108 doublereal Sim1D::workValue(
size_t dom,
size_t comp,
size_t localPoint)
const
134 doublereal z0 = d.zmin();
135 doublereal z1 = d.zmax();
136 doublereal zpt, frac, v;
137 for (
size_t n = 0; n < d.
nPoints(); n++) {
139 frac = (zpt - z0)/(z1 - z0);
146 void Sim1D::save(
string fname,
string id,
string desc)
148 OneDim::save(fname,
id, desc,
DATA_PTR(m_x));
156 ifstream s(fname.c_str());
160 "could not open input file "+fname);
168 throw CanteraError(
"Sim1D::restore",
"No solution with id = "+
id);
171 vector<XML_Node*> xd;
172 size_t sz = 0, np, m;
173 for (m = 0; m <
m_nd; m++) {
188 for (m = 0; m <
m_nd; m++) {
202 for (n = 0; n < np; n++) {
208 void Sim1D::showSolution(ostream& s)
210 for (
size_t n = 0; n <
m_nd; n++) {
211 if (
domain(n).domainType() != cEmptyType) {
217 void Sim1D::showSolution()
219 for (
size_t n = 0; n <
m_nd; n++) {
220 if (
domain(n).domainType() != cEmptyType) {
222 +
" <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\n\n");
228 void Sim1D::getInitialSoln()
230 for (
size_t n = 0; n <
m_nd; n++) {
237 for (
size_t n = 0; n <
m_nd; n++) {
243 void Sim1D::setTimeStep(doublereal stepsize,
size_t n, integer* tsteps)
247 for (
size_t i = 0; i < n; i++) {
248 m_steps[i] = tsteps[i];
257 copy(m_xnew.begin(), m_xnew.end(), m_x.begin());
259 }
else if (m > -10) {
263 "ERROR: OneDim::solve returned m = " +
int2str(m) +
"\n");
268 void Sim1D::solve(
int loglevel,
bool refine_grid)
272 doublereal dt = m_tstep;
273 int soln_number = -1;
276 while (new_points > 0) {
278 nsteps = m_steps[istep];
284 writelog(
"\nAttempt Newton solution of steady-state problem...");
292 for (
size_t mm = 1; mm <
nDomains(); mm+=2) {
313 sprintf(buf,
" %10.4g %10.4g \n", dt,
318 if (istep >= m_steps.size()) {
319 nsteps = m_steps.back();
321 nsteps = m_steps[istep];
333 new_points =
refine(loglevel);
334 if (new_points < 0) {
335 writelog(
"Maximum number of grid points reached.");
340 writelog(
"grid refinement disabled.\n");
353 int ianalyze, np = 0;
355 doublereal xmid, zmid;
356 std::vector<size_t> dsize;
358 for (
size_t n = 0; n <
m_nd; n++) {
363 ianalyze = r.analyze(d.grid().size(),
373 np += r.nNewPoints();
378 size_t nstart = znew.size();
379 for (
size_t m = 0; m < npnow; m++) {
381 if (r.keepPoint(m)) {
383 znew.push_back(d.grid(m));
386 for (
size_t i = 0; i < comp; i++) {
387 xnew.push_back(
value(n, i, m));
394 if (r.newPointNeeded(m) && m + 1 < npnow) {
397 zmid = 0.5*(d.grid(m) + d.grid(m+1));
398 znew.push_back(zmid);
404 for (
size_t i = 0; i < comp; i++) {
405 xmid = 0.5*(
value(n, i, m) +
value(n, i, m+1));
406 xnew.push_back(xmid);
410 writelog(
string(
"refine: discarding point at ")+
fp2str(d.grid(m))+
"\n");
414 dsize.push_back(znew.size() - nstart);
422 size_t gridstart = 0, gridsize;
423 for (
size_t n = 0; n <
m_nd; n++) {
427 d.setupGrid(gridsize,
DATA_PTR(znew) + gridstart);
428 gridstart += gridsize;
432 m_x.resize(xnew.size());
433 copy(xnew.begin(), xnew.end(), m_x.begin());
436 m_xnew.resize(xnew.size());
454 doublereal zfixed,interp_factor;
455 doublereal z1 = 0.0, z2 = 0.0, t1,t2;
458 std::vector<size_t> dsize;
461 for (n = 0; n <
m_nd; n++) {
469 size_t nstart = znew.size();
470 for (m = 0; m < npnow-1; m++) {
472 if (
value(n,2,m) == t) {
477 cout <<
"T already fixed at " << d.grid(m) << endl;
480 }
else if ((
value(n,2,m)<t) && (
value(n,2,m+1)>t)) {
481 cout <<
"T in between "<<
value(n,2,m)<<
" and "<<
value(n,2,m+1)<<endl;
488 zfixed = (z1-z2)/(t1-t2)*(t-t2)+z2;
500 for (m = 0; m < npnow; m++) {
502 znew.push_back(d.grid(m));
505 for (i = 0; i < comp; i++) {
506 xnew.push_back(
value(n, i, m));
508 if (m==m1 && addnewpt) {
510 znew.push_back(zfixed);
512 interp_factor = (zfixed-z2) / (z1-z2);
515 for (i = 0; i < comp; i++) {
516 xmid = interp_factor*(
value(n, i, m) -
value(n, i, m+1)) +
value(n,i,m+1);
517 xnew.push_back(xmid);
523 dsize.push_back(znew.size() - nstart);
531 size_t gridstart = 0, gridsize;
532 for (n = 0; n <
m_nd; n++) {
536 d.setupGrid(gridsize,
DATA_PTR(znew) + gridstart);
537 gridstart += gridsize;
541 m_x.resize(xnew.size());
542 copy(xnew.begin(), xnew.end(), m_x.begin());
545 m_xnew.resize(xnew.size());
547 copy(xnew.begin(), xnew.end(), m_xnew.begin());
554 void Sim1D::setAdiabaticFlame(
void)
556 for (
size_t n = 0; n <
m_nd; n++) {
568 doublereal slope, doublereal curve, doublereal prune)
572 r.setCriteria(ratio, slope, curve, prune);
574 for (
size_t n = 0; n <
m_nd; n++) {
576 r.setCriteria(ratio, slope, curve, prune);
585 r.setGridMin(gridmin);
587 for (
size_t n = 0; n <
m_nd; n++) {
589 r.setGridMin(gridmin);
595 void Sim1D::setMaxGridPoints(
int dom,
int npoints)
599 r.setMaxPoints(npoints);
601 for (
size_t n = 0; n <
m_nd; n++) {
603 r.setMaxPoints(npoints);
613 void Sim1D::evalSSJacobian()