Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix automatic flame solving when Soret diffusion is enabled #511

Merged
merged 4 commits into from
Mar 13, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 12 additions & 8 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,23 +20,27 @@ addons:
- libboost-dev
before_script: |
echo TRAVIS_OS_NAME: $TRAVIS_OS_NAME
pip2 install --user --install-option="--no-cython-compile" cython
pip2 install --user 3to2
if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then
brew update
brew install scons
brew update > /dev/null
brew upgrade python # Installs Python 3
brew install python@2 # Installs Python 2
brew install scons # Install SCons which *should* use Python 3
pip3 install numpy cython # Install numpy and Cython for Python 3
pip2 install numpy 3to2 # Install numpy and 3to2 for Python 2
brew install boost
brew install python3
pip3 install numpy
else
pip2 install --user --install-option="--no-cython-compile" cython
pip2 install --user 3to2
fi
rm -f cantera.conf
script: |
if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then
scons build -j2 VERBOSE=y python2_package=full python3_package=full python3_cmd=/usr/bin/python3 blas_lapack_libs=lapack,blas optimize=n coverage=y
scons test
else
scons build -j2 VERBOSE=y python2_package=full python3_package=full blas_lapack_libs=lapack,blas optimize=n coverage=y
python3 `which scons` build -j2 VERBOSE=y python2_package=full python3_package=full python2_cmd=/usr/local/opt/python@2/bin/python2 blas_lapack_libs=lapack,blas optimize=n coverage=y
python3 `which scons` test
fi
scons test
after_success: |
if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then
bash <(curl -s https://codecov.io/bash)
Expand Down
7 changes: 6 additions & 1 deletion include/cantera/oneD/StFlow.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,12 @@ class StFlow : public Domain1D
//! set the transport manager
void setTransport(Transport& trans);

void enableSoret(bool withSoret);
//! Enable thermal diffusion, also known as Soret diffusion.
//! Requires that multicomponent transport properties be
//! enabled to carry out calculations.
void enableSoret(bool withSoret) {
m_do_soret = withSoret;
}
bool withSoret() const {
return m_do_soret;
}
Expand Down
2 changes: 1 addition & 1 deletion interfaces/cython/cantera/_cantera.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -748,7 +748,7 @@ cdef extern from "cantera/oneD/Sim1D.h":
void setMaxGridPoints(int, size_t) except +translate_exception
size_t maxGridPoints(size_t) except +translate_exception
void setGridMin(int, double) except +translate_exception
void setFixedTemperature(double)
void setFixedTemperature(double) except +translate_exception
void setInterrupt(CxxFunc1*) except +translate_exception
void setTimeStepCallback(CxxFunc1*)
void setSteadyCallback(CxxFunc1*)
Expand Down
12 changes: 11 additions & 1 deletion interfaces/cython/cantera/onedim.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -875,6 +875,11 @@ cdef class Sim1D:
dom.set_steady_tolerances(default=(1e-4, 1e-9))
dom.set_transient_tolerances(default=(1e-4, 1e-11))

# Do initial steps without Soret diffusion
soret_doms = [dom for dom in self.domains if getattr(dom, 'soret_enabled', False)]
for dom in soret_doms:
dom.soret_enabled = False

# Do initial solution steps without multicomponent transport
solve_multi = self.gas.transport_model == 'Multi'
if solve_multi:
Expand Down Expand Up @@ -963,6 +968,11 @@ cdef class Sim1D:
if isinstance(dom, _FlowBase):
dom.set_transport(self.gas)

if soret_doms:
log('Solving with Soret diffusion')
for dom in soret_doms:
dom.soret_enabled = True

if have_user_tolerances:
log('Solving with user-specifed tolerances')
for i in range(len(self.domains)):
Expand All @@ -972,7 +982,7 @@ cdef class Sim1D:
rel=rtol_ts_final[i])

# Final call with expensive options enabled
if have_user_tolerances or solve_multi:
if have_user_tolerances or solve_multi or soret_doms:
self.sim.solve(loglevel, <cbool>True)


Expand Down
27 changes: 26 additions & 1 deletion interfaces/cython/cantera/test/test_onedim.py
Original file line number Diff line number Diff line change
Expand Up @@ -292,13 +292,38 @@ def test_multicomponent(self):
self.assertNear(Su_multi, Su_soret, 2e-1)
self.assertNotEqual(Su_multi, Su_soret)

def test_soret_flag(self):
def test_soret_with_mix(self):
# Test that enabling Soret diffusion without
# multicomponent transport results in an error

self.create_sim(101325, 300, 'H2:1.0, O2:1.0')
self.assertFalse(self.sim.soret_enabled)
self.assertFalse(self.sim.transport_model == 'Multi')

with self.assertRaises(ct.CanteraError):
self.sim.soret_enabled = True
self.sim.solve(loglevel=0, auto=False)

def test_soret_with_auto(self):
# Test that auto solving with Soret enabled works
self.create_sim(101325, 300, 'H2:2.0, O2:1.0')
self.sim.soret_enabled = True
self.sim.transport_model = 'Multi'
self.sim.solve(loglevel=0, auto=True)

def test_set_soret_multi_mix(self):
# Test that the transport model and Soret diffusion
# can be set in any order without raising errors

self.create_sim(101325, 300, 'H2:1.0, O2:1.0')
self.sim.transport_model = 'Multi'
self.sim.soret_enabled = True

self.sim.transport_model = 'Mix'
self.sim.soret_enabled = False

self.sim.soret_enabled = True
self.sim.transport_model = 'Multi'

def test_prune(self):
reactants = 'H2:1.1, O2:1, AR:5'
Expand Down
19 changes: 7 additions & 12 deletions src/oneD/StFlow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ void StFlow::setupGrid(size_t n, const doublereal* z)
}
}

void StFlow::resetBadValues(double* xg)
void StFlow::resetBadValues(double* xg)
{
double* x = xg + loc();
for (size_t j = 0; j < m_points; j++) {
Expand All @@ -154,17 +154,6 @@ void StFlow::setTransport(Transport& trans)
}
}

void StFlow::enableSoret(bool withSoret)
{
if (m_do_multicomponent) {
m_do_soret = withSoret;
} else {
throw CanteraError("setTransport",
"Thermal diffusion (the Soret effect) "
"requires using a multicomponent transport model.");
}
}

void StFlow::_getInitialSoln(double* x)
{
for (size_t j = 0; j < m_points; j++) {
Expand Down Expand Up @@ -195,6 +184,12 @@ void StFlow::setGasAtMidpoint(const doublereal* x, size_t j)

void StFlow::_finalize(const doublereal* x)
{
if (!m_do_multicomponent && m_do_soret) {
throw CanteraError("_finalize",
"Thermal diffusion (the Soret effect) is enabled, and requires "
"using a multicomponent transport model.");
}

size_t nz = m_zfix.size();
bool e = m_do_energy[0];
for (size_t j = 0; j < m_points; j++) {
Expand Down