[1D] Add bounds checks to setRefineCriteria
This commit is contained in:
parent
18c756b499
commit
5b77bbb719
4 changed files with 41 additions and 8 deletions
|
|
@ -31,12 +31,8 @@ public:
|
|||
void setCriteria(doublereal ratio = 10.0,
|
||||
doublereal slope = 0.8,
|
||||
doublereal curve = 0.8,
|
||||
doublereal prune = -0.1) {
|
||||
m_ratio = ratio;
|
||||
m_slope = slope;
|
||||
m_curve = curve;
|
||||
m_prune = prune;
|
||||
}
|
||||
doublereal prune = -0.1);
|
||||
|
||||
void setActive(int comp, bool state = true) {
|
||||
m_active[comp] = state;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -449,7 +449,7 @@ cdef extern from "cantera/oneD/Sim1D.h":
|
|||
void getInitialSoln() except +
|
||||
void solve(int, cbool) except +translate_exception
|
||||
void refine(int) except +
|
||||
void setRefineCriteria(size_t, double, double, double, double)
|
||||
void setRefineCriteria(size_t, double, double, double, double) except +
|
||||
void save(string, string, string, int) except +
|
||||
void restore(string, string, int) except +
|
||||
void writeStats(int) except +
|
||||
|
|
|
|||
|
|
@ -297,7 +297,6 @@ class TestFreeFlame(utilities.CanteraTest):
|
|||
k2 = gas2.species_index(species)
|
||||
self.assertArrayNear(Y1[k1], Y2[k2])
|
||||
|
||||
|
||||
def test_save_restore_remove_species(self):
|
||||
reactants= 'H2:1.1, O2:1, AR:5'
|
||||
p = 2 * ct.one_atm
|
||||
|
|
@ -326,6 +325,18 @@ class TestFreeFlame(utilities.CanteraTest):
|
|||
k1 = gas1.species_index(species)
|
||||
self.assertArrayNear(Y1[k1], Y2[k2])
|
||||
|
||||
def test_refine_criteria_boundscheck(self):
|
||||
self.create_sim(ct.one_atm, 300.0, 'H2:1.1, O2:1, AR:5')
|
||||
good = [3.0, 0.1, 0.2, 0.05]
|
||||
bad = [1.2, 1.1, -2, 0.3]
|
||||
|
||||
self.sim.set_refine_criteria(*good)
|
||||
for i in range(4):
|
||||
with self.assertRaises(Exception):
|
||||
vals = list(good)
|
||||
vals[i] = bad[i]
|
||||
self.sim.set_refine_criteria(*vals)
|
||||
|
||||
|
||||
class TestDiffusionFlame(utilities.CanteraTest):
|
||||
referenceFile = '../data/DiffusionFlameTest-h2-mix.csv'
|
||||
|
|
|
|||
|
|
@ -27,6 +27,32 @@ Refiner::Refiner(Domain1D& domain) :
|
|||
m_thresh = std::sqrt(std::numeric_limits<double>::epsilon());
|
||||
}
|
||||
|
||||
void Refiner::setCriteria(doublereal ratio, doublereal slope,
|
||||
doublereal curve, doublereal prune)
|
||||
{
|
||||
if (ratio < 2.0) {
|
||||
throw CanteraError("Refiner::setCriteria",
|
||||
"'ratio' must be greater than 2.0 (" + fp2str(ratio) +
|
||||
" was specified).");
|
||||
} else if (slope < 0.0 || slope > 1.0) {
|
||||
throw CanteraError("Refiner::setCriteria",
|
||||
"'slope' must be between 0.0 and 1.0 (" + fp2str(slope) +
|
||||
" was specified).");
|
||||
} else if (curve < 0.0 || curve > 1.0) {
|
||||
throw CanteraError("Refiner::setCriteria",
|
||||
"'curve' must be between 0.0 and 1.0 (" + fp2str(curve) +
|
||||
" was specified).");
|
||||
} else if (prune > curve || prune > slope) {
|
||||
throw CanteraError("Refiner::setCriteria",
|
||||
"'prune' must be less than 'curve' and 'slope' (" + fp2str(prune) +
|
||||
" was specified).");
|
||||
}
|
||||
m_ratio = ratio;
|
||||
m_slope = slope;
|
||||
m_curve = curve;
|
||||
m_prune = prune;
|
||||
}
|
||||
|
||||
int Refiner::analyze(size_t n, const doublereal* z,
|
||||
const doublereal* x)
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue