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