Cantera  4.0.0a2
Loading...
Searching...
No Matches
Domain1D.h
Go to the documentation of this file.
1 //! @file Domain1D.h
2
3// This file is part of Cantera. See License.txt in the top-level directory or
4// at https://cantera.org/license.txt for license and copyright information.
5
6#ifndef CT_DOMAIN1D_H
7#define CT_DOMAIN1D_H
8
10#include "cantera/base/global.h"
11
12namespace Cantera
13{
14
15class MultiJac;
16class OneDim;
17class Refiner;
18class AnyMap;
19class Kinetics;
20class Transport;
21class Solution;
22class SolutionArray;
23class SystemJacobian;
24
25/**
26 * Base class for one-dimensional domains.
27 * @ingroup flowGroup
28 */
30{
31protected:
32 /**
33 * Constructor.
34 * @param nv Number of variables at each grid point.
35 * @param points Number of grid points.
36 * @param time (unused)
37 */
38 explicit Domain1D(size_t nv=1, size_t points=1, double time=0.0);
39
40public:
41 virtual ~Domain1D();
42 Domain1D(const Domain1D&) = delete;
43 Domain1D& operator=(const Domain1D&) = delete;
44
45 //! Domain type flag.
46 //! @since Starting in %Cantera 3.1, the return type is a `string`.
47 virtual string domainType() const { return "domain"; }
48
49 //! The left-to-right location of this domain.
50 size_t domainIndex() {
51 return m_index;
52 }
53
54 //! True if the domain is a connector domain.
55 virtual bool isConnector() {
56 return false;
57 }
58
59 //! Set transport model by name.
60 //! @param model String specifying model name.
61 //! @since New in %Cantera 3.2.
62 virtual void setTransportModel(const string& model) {
63 throw NotImplementedError("Domain1D::setTransportModel");
64 }
65
66protected:
67 //! Update transport model to existing instance
68 //! @since New in %Cantera 3.2.
69 virtual void _setKinetics(shared_ptr<Kinetics> kin) {
70 throw NotImplementedError("Domain1D::_setKinetics");
71 }
72
73 //! Update transport model to existing instance
74 //! @since New in %Cantera 3.2.
75 virtual void _setTransport(shared_ptr<Transport> trans) {
76 throw NotImplementedError("Domain1D::_setTransport");
77 }
78
79public:
80 //! The container holding this domain.
81 const OneDim& container() const {
82 return *m_container;
83 }
84
85 //! Specify the container object for this domain, and the position of this
86 //! domain in the list.
87 void setContainer(OneDim* c, size_t index) {
88 m_container = c;
89 m_index = index;
90 }
91
92 //! Set the Jacobian bandwidth. See the discussion of method bandwidth().
93 void setBandwidth(int bw = -1) {
94 m_bw = bw;
95 }
96
97 //! Set the Jacobian bandwidth for this domain.
98 /**
99 * When class OneDim computes the bandwidth of the overall multi-domain
100 * problem (in OneDim::resize()), it calls this method for the bandwidth
101 * of each domain. If setBandwidth has not been called, then a negative
102 * bandwidth is returned, in which case OneDim assumes that this domain is
103 * dense -- that is, at each point, all components depend on the value of
104 * all other components at that point. In this case, the bandwidth is bw =
105 * 2*nComponents() - 1. However, if this domain contains some components
106 * that are uncoupled from other components at the same point, then this
107 * default bandwidth may greatly overestimate the true bandwidth, with a
108 * substantial penalty in performance. For such domains, use method
109 * setBandwidth to specify the bandwidth before passing this domain to the
110 * Sim1D or OneDim constructor.
111 */
112 size_t bandwidth() {
113 return m_bw;
114 }
115
116 /**
117 * Initialize. This method is called by OneDim::init() for each domain once
118 * at the beginning of a simulation. Base class method does nothing, but may
119 * be overloaded.
120 */
121 virtual void init() { }
122
123 /**
124 * When called, this function should reset "bad" values in the state vector
125 * such as negative species concentrations. This function may be called
126 * after a failed solution attempt.
127 */
128 virtual void resetBadValues(span<double> x) {}
129
130 /**
131 * Resize the domain to have nv components and np grid points. This method
132 * is virtual so that subclasses can perform other actions required to
133 * resize the domain.
134 */
135 virtual void resize(size_t nv, size_t np);
136
137 //! Return a reference to the grid refiner.
139 return *m_refiner;
140 }
141
142 //! Number of components at each grid point.
143 size_t nComponents() const {
144 return m_nv;
145 }
146
147 //! Number of grid points in this domain.
148 size_t nPoints() const {
149 return m_points;
150 }
151
152 //! Name of component `n`. May be overloaded.
153 virtual string componentName(size_t n) const;
154
155 //! Set the name of the component `n` to `name`.
156 void setComponentName(size_t n, const string& name) {
157 m_name[n] = name;
158 }
159
160 /**
161 * Index of component with name `name`.
162 * @param name name of component
163 * @param checkAlias if `true` (default), check alias mapping
164 */
165 virtual size_t componentIndex(const string& name, bool checkAlias=true) const;
166
167 /**
168 * Check whether the Domain contains a component.
169 * @param name name of component
170 * @param checkAlias if `true` (default), check alias mapping
171 *
172 * @since New in %Cantera 3.2.
173 */
174 virtual bool hasComponent(const string& name, bool checkAlias=true) const;
175
176 //! Index of component `name` at grid point `j` within the global solution
177 //! vector of the containing OneDim/Sim1D object.
178 //! @since New in %Cantera 4.0.
179 size_t globalComponentIndex(const string& name, size_t j) const {
180 return loc() + index(componentIndex(name), j);
181 }
182
183 /**
184 * Update state at given location to state of associated Solution object.
185 */
186 virtual void updateState(size_t loc) {
187 throw NotImplementedError("Domain1D::updateState",
188 "Not implemented for domain type '{}'.", domainType());
189 }
190
191 /**
192 * Set the upper and lower bounds for a solution component, n.
193 *
194 * @param n solution component index
195 * @param lower lower bound on component n
196 * @param upper upper bound on component n
197 */
198 void setBounds(size_t n, double lower, double upper) {
199 m_min[n] = lower;
200 m_max[n] = upper;
201 }
202
203 //! Set tolerances for time-stepping mode
204 /*!
205 * @param rtol Relative tolerance
206 * @param atol Absolute tolerance
207 * @param n component index these tolerances apply to. If set to -1 (the
208 * default), these tolerances will be applied to all solution
209 * components.
210 */
211 void setTransientTolerances(double rtol, double atol, size_t n=npos);
212
213 //! Set tolerances for steady-state mode
214 /*!
215 * @param rtol Relative tolerance
216 * @param atol Absolute tolerance
217 * @param n component index these tolerances apply to. If set to -1 (the
218 * default), these tolerances will be applied to all solution
219 * components.
220 */
221 void setSteadyTolerances(double rtol, double atol, size_t n=npos);
222
223 //! Relative tolerance of the nth component.
224 double rtol(size_t n) {
225 return (m_rdt == 0.0 ? m_rtol_ss[n] : m_rtol_ts[n]);
226 }
227
228 //! Absolute tolerance of the nth component.
229 double atol(size_t n) {
230 return (m_rdt == 0.0 ? m_atol_ss[n] : m_atol_ts[n]);
231 }
232
233 //! Steady relative tolerance of the nth component
234 double steady_rtol(size_t n) {
235 return m_rtol_ss[n];
236 }
237
238 //! Steady absolute tolerance of the nth component
239 double steady_atol(size_t n) {
240 return m_atol_ss[n];
241 }
242
243 //! Transient relative tolerance of the nth component
244 double transient_rtol(size_t n) {
245 return m_rtol_ts[n];
246 }
247
248 //! Transient absolute tolerance of the nth component
249 double transient_atol(size_t n) {
250 return m_atol_ts[n];
251 }
252
253 //! Upper bound on the nth component.
254 double upperBound(size_t n) const {
255 return m_max[n];
256 }
257
258 //! Lower bound on the nth component
259 double lowerBound(size_t n) const {
260 return m_min[n];
261 }
262
263 //! Set the method used to evaluate this domain's Jacobian columns.
264 //! @param mode One of `"auto"` (default), `"analytic"`, or
265 //! `"finite-difference"`. In `"auto"` mode the domain uses analytic
266 //! Jacobian columns where supported (see hasAnalyticJacobian()) and
267 //! silently falls back to finite differences otherwise. `"analytic"`
268 //! additionally raises a CanteraError if analytic evaluation was
269 //! requested but cannot be used because the kinetics object lacks the
270 //! required composition derivatives or multicomponent transport is
271 //! active. `"finite-difference"` always uses finite differences.
272 //! @since New in %Cantera 4.0.
273 void setJacobianMode(const string& mode) {
274 if (mode != "finite-difference" && mode != "analytic" && mode != "auto") {
275 throw CanteraError("Domain1D::setJacobianMode",
276 "Unknown Jacobian mode '{}'", mode);
277 }
278 m_jacobianMode = mode;
279 }
280
281 //! Get the method used to evaluate this domain's Jacobian columns.
282 //! @since New in %Cantera 4.0.
283 const string& jacobianMode() const {
284 return m_jacobianMode;
285 }
286
287 //! Returns `true` if this domain computes the Jacobian column for
288 //! component `n` at (domain-local) grid point `j` analytically, in which
289 //! case the finite-difference evaluation of that column is skipped and the
290 //! domain must provide all entries of the column in evalJacobianAnalytic().
291 //! @since New in %Cantera 4.0.
292 virtual bool hasAnalyticJacobian(size_t j, size_t n) const {
293 return false;
294 }
295
296 //! Add this domain's analytic Jacobian entries (for columns claimed by
297 //! hasAnalyticJacobian()) to `jac` via SystemJacobian::setValue(), using
298 //! global row/column indices (domain-local index + loc()). Entries must be
299 //! the steady-state Jacobian; transient diagonal terms are handled
300 //! separately. Base class implementation does nothing.
301 //! @since New in %Cantera 4.0.
302 virtual void evalJacobianAnalytic(span<const double> x, SystemJacobian& jac) {}
303
304 //! Validate that an explicitly requested analytic Jacobian
305 //! (`jacobian_mode == "analytic"`) can be used for the current
306 //! configuration, throwing CanteraError otherwise. Called once per
307 //! Jacobian evaluation before the finite-difference column loop. The base
308 //! implementation does nothing; the `"auto"` and `"finite-difference"`
309 //! modes never raise.
310 //! @since New in %Cantera 4.0.
311 virtual void checkAnalyticJacobian() const {}
312
313 /**
314 * Set grid refinement criteria. @see Refiner::setCriteria.
315 * @since New in %Cantera 3.2
316 */
317 void setRefineCriteria(double ratio = 10.0,
318 double slope = 0.8, double curve = 0.8,
319 double prune = -0.1);
320
321 /**
322 * Get the grid refinement criteria. @see Refiner::getCriteria
323 * @since New in %Cantera 3.2
324 */
325 vector<double> getRefineCriteria();
326
327 /**
328 * Performs the setup required before starting a time-stepping solution.
329 * Stores the solution provided in `x0` to the internal storage, and sets
330 * the reciprocal of the time step to `1/dt`.
331 *
332 * @param[in] dt Time step
333 * @param[in] x0 Array to store the solution at the last time step
334 */
335 void initTimeInteg(double dt, span<const double> x0) {
336 auto local = x0.subspan(loc(), size());
337 std::copy(local.begin(), local.end(), m_slast.begin());
338 m_rdt = 1.0/dt;
339 }
340
341 /**
342 * Set the internally-stored reciprocal of the time step to 0.0, which is
343 * used to indicate that the problem is in steady-state mode.
344 */
346 m_rdt = 0.0;
347 }
348
349 //! True if in steady-state mode
350 bool steady() {
351 return (m_rdt == 0.0);
352 }
353
354 //! True if not in steady-state mode
355 bool transient() {
356 return (m_rdt != 0.0);
357 }
358
359 /**
360 * Set this if something has changed in the governing
361 * equations (for example, the value of a constant has been changed,
362 * so that the last-computed Jacobian is no longer valid.
363 */
364 void needJacUpdate();
365
366 //! Evaluate the residual function at point j. If j == npos,
367 //! evaluate the residual function at all points.
368 /*!
369 * This function must be implemented in classes derived from Domain1D.
370 *
371 * @param[in] j Grid point at which to update the residual
372 * @param[in] x State vector
373 * @param[out] r residual vector
374 * @param[out] mask Boolean mask indicating whether each solution
375 * component has a time derivative (1) or not (0).
376 * @param[in] rdt Reciprocal of the timestep (`rdt=0` implies steady-state.)
377 */
378 virtual void eval(size_t j, span<const double> x, span<double> r, span<int> mask,
379 double rdt=0.0) {
380 throw NotImplementedError("Domain1D::eval");
381 }
382
383 /**
384 * Returns the index of the solution vector, which corresponds to component
385 * n at grid point j.
386 *
387 * @param n component index
388 * @param j grid point index
389 */
390 size_t index(size_t n, size_t j) const {
391 return m_nv*j + n;
392 }
393
394 /**
395 * Set a single component value at a boundary.
396 * @param component Name of the component.
397 *
398 * @since New in %Cantera 3.2.
399 */
400 virtual double value(const string& component) const {
401 throw NotImplementedError("Domain1D::value",
402 "Not implemented for domain type '{}'.", domainType());
403 }
404
405 /**
406 * Set a single component value in a flow domain or at a boundary.
407 * @param component Name of the component.
408 * @param value Value of the component.
409 *
410 * @since New in %Cantera 3.2.
411 */
412 virtual void setValue(const string& component, double value) {
413 throw NotImplementedError("Domain1D::setValue",
414 "Not implemented for domain type '{}'.", domainType());
415 }
416
417 /**
418 * Retrieve component values.
419 * @param component Name of the component.
420 * @returns Vector of length nPoints() containing values at grid points.
421 *
422 * @since New in %Cantera 3.2.
423 */
424 vector<double> values(const string& component) const {
425 vector<double> data(nPoints());
426 getValues(component, data);
427 return data;
428 }
429
430 /**
431 * Retrieve component values.
432 * @param component Name of the component.
433 * @param[out] values Vector of length nPoints() containing values at grid points.
434 *
435 * @since New in %Cantera 3.2.
436 */
437 virtual void getValues(const string& component, span<double> values) const {
438 throw NotImplementedError("Domain1D::getValues",
439 "Not implemented for domain type '{}'.", domainType());
440 }
441
442 /**
443 * Specify component values.
444 * @param component Name of the component.
445 * @param[in] values Vector of length nPoints() containing values at grid points.
446 *
447 * @since New in %Cantera 3.2.
448 */
449 virtual void setValues(const string& component, span<const double> values) {
450 throw NotImplementedError("Domain1D::setValues",
451 "Not implemented for domain type '{}'.", domainType());
452 }
453
454 /**
455 * Retrieve internal work array values for a component.
456 * After calling Sim1D::eval(), this array contains the values of the residual
457 * function.
458 * @param component Name of the component.
459 * @returns Vector of length nPoints() containing residuals at grid points.
460 *
461 * @since New in %Cantera 3.2.
462 */
463 vector<double> residuals(const string& component) const {
464 vector<double> data(nPoints());
465 getResiduals(component, data);
466 return data;
467 }
468
469 /**
470 * Retrieve internal work array values for a component.
471 * After calling Sim1D::eval(), this array contains the values of the residual
472 * function.
473 * @param component Name of the component.
474 * @param[out] values Vector of length nPoints() containing residuals at grid
475 * points.
476 *
477 * @since New in %Cantera 3.2.
478 */
479 virtual void getResiduals(const string& component, span<double> values) const {
480 throw NotImplementedError("Domain1D::getResiduals",
481 "Not applicable or not implemented for domain type '{}'.", domainType());
482 }
483
484 /**
485 * Specify a profile for a component.
486 * @param component Name of the component.
487 * @param[in] pos A vector of relative positions, beginning with 0.0 at the
488 * left of the domain, and ending with 1.0 at the right of the domain.
489 * @param[in] values A vector of values corresponding to the relative position
490 * locations.
491 *
492 * Note that the vector pos and values can have lengths different than the
493 * number of grid points, but their lengths must be equal. The values at
494 * the grid points will be linearly interpolated based on the (pos,
495 * values) specification.
496 *
497 * @since New in %Cantera 3.2.
498 */
499 virtual void setProfile(const string& component,
500 span<const double> pos, span<const double> values) {
501 throw NotImplementedError("Domain1D::setProfile",
502 "Not implemented for domain type '{}'.", domainType());
503 }
504
505 /**
506 * Specify a flat profile for a component.
507 * @param component Name of the component.
508 * @param value Constant value.
509 *
510 * @since New in %Cantera 3.2.
511 */
512 virtual void setFlatProfile(const string& component, double value) {
513 throw NotImplementedError("Domain1D::setFlatProfile",
514 "Not implemented for domain type '{}'.", domainType());
515 }
516
517 //! Save the state of this domain to a SolutionArray.
518 /*!
519 * This method serves as an external interface for high-level API's; it does not
520 * provide direct access to memory.
521 * @param normalize If true, normalize concentrations (default=false)
522 *
523 * @since New in %Cantera 3.0.
524 */
525 virtual shared_ptr<SolutionArray> toArray(bool normalize=false) {
526 throw NotImplementedError("Domain1D::toArray", "Needs to be overloaded.");
527 }
528
529 //! Restore the solution for this domain from a SolutionArray.
530 /*!
531 * This method serves as an external interface for high-level API's.
532 * @param arr SolutionArray defining the state of this domain
533 * @since New in %Cantera 3.0.
534 */
535 virtual void fromArray(const shared_ptr<SolutionArray>& arr) {
536 throw NotImplementedError("Domain1D::fromArray", "Needs to be overloaded.");
537 }
538
539 /**
540 * Return a concise summary of a Domain.
541 * @see SolutionArray.info()
542 * @param keys List of components to be displayed; if empty, all components are
543 * considered.
544 * @param rows Maximum number of rendered rows.
545 * @param width Maximum width of rendered output.
546 * @since New in %Cantera 3.2
547 */
548 string info(const vector<string>& keys, int rows=10, int width=80);
549
550 /**
551 * Return a concise summary of a Domain.
552 * Skips keys input while `vector<string>` is not implemented in sourcegen.
553 * @see SolutionArray.info()
554 * @param rows Maximum number of rendered rows.
555 * @param width Maximum width of rendered output.
556 * @since New in %Cantera 3.2
557 */
558 string _info(int rows=10, int width=80) {
559 return info({}, rows, width);
560 }
561
562 //! Return thermo/kinetics/transport manager used in the domain
563 //! @since New in %Cantera 3.2.
564 shared_ptr<Solution> phase() const {
565 return m_solution;
566 }
567
568 //! Return the size of the solution vector (the product of #m_nv and #m_points).
569 size_t size() const {
570 return m_nv*m_points;
571 }
572
573 /**
574 * Find the index of the first grid point in this domain, and
575 * the start of its variables in the global solution vector.
576 */
577 void locate();
578
579 //! Location of the start of the local solution vector in the global solution vector
580 virtual size_t loc(size_t j = 0) const {
581 return m_iloc;
582 }
583
584 //! The index of the first (that is, left-most) grid point belonging to this domain.
585 size_t firstPoint() const {
586 return m_jstart;
587 }
588
589 //! The index of the last (that is, right-most) grid point belonging to this domain.
590 size_t lastPoint() const {
591 return m_jstart + m_points - 1;
592 }
593
594 /**
595 * Set the left neighbor to domain 'left.' Method 'locate' is called to
596 * update the global positions of this domain and all those to its right.
597 */
599 m_left = left;
600 locate();
601 }
602
603 //! Set the right neighbor to domain 'right.'
605 m_right = right;
606 }
607
608 //! Append domain 'right' to this one, and update all links.
611 right->linkLeft(this);
612 }
613
614 //! Return a pointer to the left neighbor.
615 Domain1D* left() const {
616 return m_left;
617 }
618
619 //! Return a pointer to the right neighbor.
620 Domain1D* right() const {
621 return m_right;
622 }
623
624 //! Value of component n at point j in the previous solution.
625 double prevSoln(size_t n, size_t j) const {
626 return m_slast[m_nv*j + n];
627 }
628
629 //! Specify an identifying tag for this domain.
630 void setID(const string& s) {
631 m_id = s;
632 }
633
634 //! Returns the identifying tag for this domain.
635 string id() const {
636 if (m_id != "") {
637 return m_id;
638 } else {
639 return fmt::format("domain {}", m_index);
640 }
641 }
642
643 //! Print the solution.
644 //! @param x Pointer to the local portion of the system state vector
645 virtual void show(span<const double> x);
646
647 //! Get the coordinate [m] of the point with local index `jlocal`
648 double z(size_t jlocal) const {
649 return m_z[jlocal];
650 }
651
652 //! Get the coordinate [m] of the first (leftmost) grid point in this domain
653 double zmin() const {
654 return m_z[0];
655 }
656
657 //! Get the coordinate [m] of the last (rightmost) grid point in this domain
658 double zmax() const {
659 return m_z[m_points - 1];
660 }
661
662 //! Access the array of grid coordinates [m]
663 span<double> grid() {
664 return m_z;
665 }
666
667 //! Access the array of grid coordinates [m]
668 span<const double> grid() const {
669 return m_z;
670 }
671
672 //! Set up initial grid.
673 //! @since New in %Cantera 3.2.
674 //! called to set up initial grid, and after grid refinement
675 virtual void setupGrid(span<const double> z);
676
677 //! Set up uniform grid.
678 //! @param points Number of grid points
679 //! @param length Length of domain
680 //! @param start Start position of domain (default=0.)
681 //! @since New in %Cantera 3.2.
682 void setupUniformGrid(size_t points, double length, double start=0.);
683
684 /**
685 * Writes some or all initial solution values into the global solution
686 * array, beginning at the location pointed to by x. This method is called
687 * by the Sim1D constructor, and allows default values or ones that have
688 * been set locally prior to installing this domain into the container to be
689 * written to the global solution vector.
690 */
691 virtual void _getInitialSoln(span<double> x);
692
693 //! Initial value of solution component @e n at grid point @e j.
694 virtual double initialValue(size_t n, size_t j);
695
696 /**
697 * In some cases, a domain may need to set parameters that depend on the
698 * initial solution estimate. In such cases, the parameters may be set in
699 * method _finalize. This method is called just before the Newton solver is
700 * called, and the x array is guaranteed to be the local solution vector for
701 * this domain that will be used as the initial guess. If no such parameters
702 * need to be set, then method _finalize does not need to be overloaded.
703 */
704 virtual void _finalize(span<const double> x) {}
705
706 /**
707 * In some cases, for computational efficiency some properties (such as
708 * transport coefficients) may not be updated during Jacobian evaluations.
709 * Set this to `true` to force these properties to be updated even while
710 * calculating Jacobian elements.
711 */
712 void forceFullUpdate(bool update) {
713 m_force_full_update = update;
714 }
715
716 //! Set shared data pointer
717 void setData(shared_ptr<vector<double>>& data) {
718 m_state = data;
719 }
720
721protected:
722 //! Retrieve meta data
723 virtual AnyMap getMeta() const;
724
725 //! Retrieve meta data
726 virtual void setMeta(const AnyMap& meta);
727
728 double m_press = -1.0; //!< pressure [Pa]
729
730 shared_ptr<vector<double>> m_state; //!< data pointer shared from OneDim
731
732 double m_rdt = 0.0; //!< Reciprocal of the time step
733 size_t m_nv = 0; //!< Number of solution components
734 size_t m_points; //!< Number of grid points
735 vector<double> m_slast; //!< Solution vector at the last time step
736 vector<double> m_max; //!< Upper bounds on solution components
737 vector<double> m_min; //!< Lower bounds on solution components
738 vector<double> m_rtol_ss; //!< Relative tolerances for steady mode
739 vector<double> m_rtol_ts; //!< Relative tolerances for transient mode
740 vector<double> m_atol_ss; //!< Absolute tolerances for steady mode
741 vector<double> m_atol_ts; //!< Absolute tolerances for transient mode
742 vector<double> m_z; //!< 1D spatial grid coordinates
743
744 //! Parent OneDim simulation containing this and adjacent domains
745 OneDim* m_container = nullptr;
746
747 size_t m_index; //!< Left-to-right location of this domain
748
749 //! Starting location within the solution vector for unknowns that
750 //! correspond to this domain
751 /*!
752 * Remember there may be multiple domains associated with this problem
753 */
754 size_t m_iloc = 0;
755
756 //! Index of the first point in this domain in the global point list.
757 //! @see firstPoint(), lastPoint()
758 size_t m_jstart = 0;
759
760 Domain1D* m_left = nullptr; //!< Pointer to the domain to the left
761 Domain1D* m_right = nullptr; //!< Pointer to the domain to the right
762
763 //! Identity tag for the domain
764 string m_id;
765 unique_ptr<Refiner> m_refiner; //!< Refiner object used for placing grid points
766 vector<string> m_name; //!< Names of solution components
767 int m_bw = -1; //!< See bandwidth()
768 bool m_force_full_update = false; //!< see forceFullUpdate()
769 string m_jacobianMode = "auto"; //!< see setJacobianMode()
770
771 //! Composite thermo/kinetics/transport handler
772 shared_ptr<Solution> m_solution;
773};
774}
775
776#endif
A map of string keys to values whose type can vary at runtime.
Definition AnyMap.h:431
Base class for exceptions thrown by Cantera classes.
Base class for one-dimensional domains.
Definition Domain1D.h:30
virtual void setValues(const string &component, span< const double > values)
Specify component values.
Definition Domain1D.h:449
void setTransientTolerances(double rtol, double atol, size_t n=npos)
Set tolerances for time-stepping mode.
Definition Domain1D.cpp:93
size_t lastPoint() const
The index of the last (that is, right-most) grid point belonging to this domain.
Definition Domain1D.h:590
size_t m_iloc
Starting location within the solution vector for unknowns that correspond to this domain.
Definition Domain1D.h:754
size_t domainIndex()
The left-to-right location of this domain.
Definition Domain1D.h:50
virtual void _getInitialSoln(span< double > x)
Writes some or all initial solution values into the global solution array, beginning at the location ...
Definition Domain1D.cpp:268
shared_ptr< Solution > m_solution
Composite thermo/kinetics/transport handler.
Definition Domain1D.h:772
Domain1D * m_left
Pointer to the domain to the left.
Definition Domain1D.h:760
OneDim * m_container
Parent OneDim simulation containing this and adjacent domains.
Definition Domain1D.h:745
void initTimeInteg(double dt, span< const double > x0)
Performs the setup required before starting a time-stepping solution.
Definition Domain1D.h:335
bool transient()
True if not in steady-state mode.
Definition Domain1D.h:355
void setComponentName(size_t n, const string &name)
Set the name of the component n to name.
Definition Domain1D.h:156
virtual void setupGrid(span< const double > z)
Set up initial grid.
Definition Domain1D.cpp:207
virtual void resetBadValues(span< double > x)
When called, this function should reset "bad" values in the state vector such as negative species con...
Definition Domain1D.h:128
size_t nComponents() const
Number of components at each grid point.
Definition Domain1D.h:143
size_t bandwidth()
Set the Jacobian bandwidth for this domain.
Definition Domain1D.h:112
double rtol(size_t n)
Relative tolerance of the nth component.
Definition Domain1D.h:224
void setJacobianMode(const string &mode)
Set the method used to evaluate this domain's Jacobian columns.
Definition Domain1D.h:273
vector< double > m_atol_ss
Absolute tolerances for steady mode.
Definition Domain1D.h:740
void setupUniformGrid(size_t points, double length, double start=0.)
Set up uniform grid.
Definition Domain1D.cpp:214
vector< double > m_rtol_ts
Relative tolerances for transient mode.
Definition Domain1D.h:739
size_t size() const
Return the size of the solution vector (the product of m_nv and m_points).
Definition Domain1D.h:569
vector< double > m_atol_ts
Absolute tolerances for transient mode.
Definition Domain1D.h:741
virtual void updateState(size_t loc)
Update state at given location to state of associated Solution object.
Definition Domain1D.h:186
virtual bool isConnector()
True if the domain is a connector domain.
Definition Domain1D.h:55
string _info(int rows=10, int width=80)
Return a concise summary of a Domain.
Definition Domain1D.h:558
virtual void evalJacobianAnalytic(span< const double > x, SystemJacobian &jac)
Add this domain's analytic Jacobian entries (for columns claimed by hasAnalyticJacobian()) to jac via...
Definition Domain1D.h:302
virtual void _setKinetics(shared_ptr< Kinetics > kin)
Update transport model to existing instance.
Definition Domain1D.h:69
virtual void setMeta(const AnyMap &meta)
Retrieve meta data.
Definition Domain1D.cpp:155
size_t globalComponentIndex(const string &name, size_t j) const
Index of component name at grid point j within the global solution vector of the containing OneDim/Si...
Definition Domain1D.h:179
size_t m_index
Left-to-right location of this domain.
Definition Domain1D.h:747
Domain1D * left() const
Return a pointer to the left neighbor.
Definition Domain1D.h:615
vector< double > residuals(const string &component) const
Retrieve internal work array values for a component.
Definition Domain1D.h:463
string id() const
Returns the identifying tag for this domain.
Definition Domain1D.h:635
double zmin() const
Get the coordinate [m] of the first (leftmost) grid point in this domain.
Definition Domain1D.h:653
span< double > grid()
Access the array of grid coordinates [m].
Definition Domain1D.h:663
size_t m_jstart
Index of the first point in this domain in the global point list.
Definition Domain1D.h:758
shared_ptr< Solution > phase() const
Return thermo/kinetics/transport manager used in the domain.
Definition Domain1D.h:564
size_t m_nv
Number of solution components.
Definition Domain1D.h:733
virtual void eval(size_t j, span< const double > x, span< double > r, span< int > mask, double rdt=0.0)
Evaluate the residual function at point j.
Definition Domain1D.h:378
virtual bool hasAnalyticJacobian(size_t j, size_t n) const
Returns true if this domain computes the Jacobian column for component n at (domain-local) grid point...
Definition Domain1D.h:292
void setContainer(OneDim *c, size_t index)
Specify the container object for this domain, and the position of this domain in the list.
Definition Domain1D.h:87
size_t nPoints() const
Number of grid points in this domain.
Definition Domain1D.h:148
vector< string > m_name
Names of solution components.
Definition Domain1D.h:766
double m_rdt
Reciprocal of the time step.
Definition Domain1D.h:732
virtual string domainType() const
Domain type flag.
Definition Domain1D.h:47
bool m_force_full_update
see forceFullUpdate()
Definition Domain1D.h:768
string info(const vector< string > &keys, int rows=10, int width=80)
Return a concise summary of a Domain.
Definition Domain1D.cpp:31
double lowerBound(size_t n) const
Lower bound on the nth component.
Definition Domain1D.h:259
virtual void setTransportModel(const string &model)
Set transport model by name.
Definition Domain1D.h:62
virtual size_t componentIndex(const string &name, bool checkAlias=true) const
Index of component with name name.
Definition Domain1D.cpp:71
shared_ptr< vector< double > > m_state
data pointer shared from OneDim
Definition Domain1D.h:730
void linkLeft(Domain1D *left)
Set the left neighbor to domain 'left.
Definition Domain1D.h:598
span< const double > grid() const
Access the array of grid coordinates [m].
Definition Domain1D.h:668
string m_jacobianMode
see setJacobianMode()
Definition Domain1D.h:769
const string & jacobianMode() const
Get the method used to evaluate this domain's Jacobian columns.
Definition Domain1D.h:283
vector< double > values(const string &component) const
Retrieve component values.
Definition Domain1D.h:424
virtual void resize(size_t nv, size_t np)
Resize the domain to have nv components and np grid points.
Definition Domain1D.cpp:36
double z(size_t jlocal) const
Get the coordinate [m] of the point with local index jlocal
Definition Domain1D.h:648
virtual void setValue(const string &component, double value)
Set a single component value in a flow domain or at a boundary.
Definition Domain1D.h:412
double upperBound(size_t n) const
Upper bound on the nth component.
Definition Domain1D.h:254
Refiner & refiner()
Return a reference to the grid refiner.
Definition Domain1D.h:138
Domain1D * right() const
Return a pointer to the right neighbor.
Definition Domain1D.h:620
vector< double > m_rtol_ss
Relative tolerances for steady mode.
Definition Domain1D.h:738
double m_press
pressure [Pa]
Definition Domain1D.h:728
vector< double > m_slast
Solution vector at the last time step.
Definition Domain1D.h:735
virtual double value(const string &component) const
Set a single component value at a boundary.
Definition Domain1D.h:400
virtual void fromArray(const shared_ptr< SolutionArray > &arr)
Restore the solution for this domain from a SolutionArray.
Definition Domain1D.h:535
Domain1D * m_right
Pointer to the domain to the right.
Definition Domain1D.h:761
double steady_atol(size_t n)
Steady absolute tolerance of the nth component.
Definition Domain1D.h:239
void setSteadyTolerances(double rtol, double atol, size_t n=npos)
Set tolerances for steady-state mode.
Definition Domain1D.cpp:106
virtual string componentName(size_t n) const
Name of component n. May be overloaded.
Definition Domain1D.cpp:59
virtual void getResiduals(const string &component, span< double > values) const
Retrieve internal work array values for a component.
Definition Domain1D.h:479
double transient_atol(size_t n)
Transient absolute tolerance of the nth component.
Definition Domain1D.h:249
virtual void _setTransport(shared_ptr< Transport > trans)
Update transport model to existing instance.
Definition Domain1D.h:75
virtual void init()
Initialize.
Definition Domain1D.h:121
double atol(size_t n)
Absolute tolerance of the nth component.
Definition Domain1D.h:229
void setID(const string &s)
Specify an identifying tag for this domain.
Definition Domain1D.h:630
vector< double > m_z
1D spatial grid coordinates
Definition Domain1D.h:742
void forceFullUpdate(bool update)
In some cases, for computational efficiency some properties (such as transport coefficients) may not ...
Definition Domain1D.h:712
const OneDim & container() const
The container holding this domain.
Definition Domain1D.h:81
size_t m_points
Number of grid points.
Definition Domain1D.h:734
virtual void checkAnalyticJacobian() const
Validate that an explicitly requested analytic Jacobian (jacobian_mode == "analytic") can be used for...
Definition Domain1D.h:311
bool steady()
True if in steady-state mode.
Definition Domain1D.h:350
virtual void show(span< const double > x)
Print the solution.
Definition Domain1D.cpp:224
void setBandwidth(int bw=-1)
Set the Jacobian bandwidth. See the discussion of method bandwidth().
Definition Domain1D.h:93
double steady_rtol(size_t n)
Steady relative tolerance of the nth component.
Definition Domain1D.h:234
string m_id
Identity tag for the domain.
Definition Domain1D.h:764
vector< double > m_max
Upper bounds on solution components.
Definition Domain1D.h:736
unique_ptr< Refiner > m_refiner
Refiner object used for placing grid points.
Definition Domain1D.h:765
void setBounds(size_t n, double lower, double upper)
Set the upper and lower bounds for a solution component, n.
Definition Domain1D.h:198
vector< double > m_min
Lower bounds on solution components.
Definition Domain1D.h:737
void setData(shared_ptr< vector< double > > &data)
Set shared data pointer.
Definition Domain1D.h:717
virtual void setProfile(const string &component, span< const double > pos, span< const double > values)
Specify a profile for a component.
Definition Domain1D.h:499
void append(Domain1D *right)
Append domain 'right' to this one, and update all links.
Definition Domain1D.h:609
void setSteadyMode()
Set the internally-stored reciprocal of the time step to 0.0, which is used to indicate that the prob...
Definition Domain1D.h:345
virtual double initialValue(size_t n, size_t j)
Initial value of solution component n at grid point j.
Definition Domain1D.cpp:277
double prevSoln(size_t n, size_t j) const
Value of component n at point j in the previous solution.
Definition Domain1D.h:625
double zmax() const
Get the coordinate [m] of the last (rightmost) grid point in this domain.
Definition Domain1D.h:658
size_t firstPoint() const
The index of the first (that is, left-most) grid point belonging to this domain.
Definition Domain1D.h:585
virtual shared_ptr< SolutionArray > toArray(bool normalize=false)
Save the state of this domain to a SolutionArray.
Definition Domain1D.h:525
void needJacUpdate()
Set this if something has changed in the governing equations (for example, the value of a constant ha...
Definition Domain1D.cpp:119
void linkRight(Domain1D *right)
Set the right neighbor to domain 'right.'.
Definition Domain1D.h:604
virtual void getValues(const string &component, span< double > values) const
Retrieve component values.
Definition Domain1D.h:437
size_t index(size_t n, size_t j) const
Returns the index of the solution vector, which corresponds to component n at grid point j.
Definition Domain1D.h:390
vector< double > getRefineCriteria()
Get the grid refinement criteria.
Definition Domain1D.cpp:263
double transient_rtol(size_t n)
Transient relative tolerance of the nth component.
Definition Domain1D.h:244
int m_bw
See bandwidth()
Definition Domain1D.h:767
virtual size_t loc(size_t j=0) const
Location of the start of the local solution vector in the global solution vector.
Definition Domain1D.h:580
void locate()
Find the index of the first grid point in this domain, and the start of its variables in the global s...
Definition Domain1D.cpp:187
virtual void _finalize(span< const double > x)
In some cases, a domain may need to set parameters that depend on the initial solution estimate.
Definition Domain1D.h:704
virtual AnyMap getMeta() const
Retrieve meta data.
Definition Domain1D.cpp:127
virtual bool hasComponent(const string &name, bool checkAlias=true) const
Check whether the Domain contains a component.
Definition Domain1D.cpp:82
void setRefineCriteria(double ratio=10.0, double slope=0.8, double curve=0.8, double prune=-0.1)
Set grid refinement criteria.
Definition Domain1D.cpp:258
virtual void setFlatProfile(const string &component, double value)
Specify a flat profile for a component.
Definition Domain1D.h:512
An error indicating that an unimplemented function has been called.
Container class for multiple-domain 1D problems.
Definition OneDim.h:25
Refine Domain1D grids so that profiles satisfy adaptation tolerances.
Definition refine.h:17
Abstract base class representing Jacobian matrices and preconditioners used in nonlinear solvers.
Definitions for the classes that are thrown when Cantera experiences an error condition (also contain...
This file contains definitions for utility functions and text for modules, inputfiles and logging,...
Namespace for the Cantera kernel.
Definition AnyMap.cpp:595
const size_t npos
index returned by functions to indicate "no position"
Definition ct_defs.h:183