From f2384090263556be44f01000671d42197fd40be0 Mon Sep 17 00:00:00 2001 From: Dave Goodwin Date: Tue, 9 Sep 2003 19:33:36 +0000 Subject: [PATCH] *** empty log message *** --- Cantera/clib/src/ctonedim.cpp | 8 ++ Cantera/clib/src/ctonedim.h | 1 + Cantera/matlab/cantera/examples/catcomb.m | 2 +- Cantera/matlab/cantera/examples/flame1.m | 9 +- Cantera/python/Cantera/OneD/BurnerFlame.py | 1 + Cantera/python/Cantera/OneD/CounterFlame.py | 2 +- Cantera/python/Cantera/OneD/StagnationFlow.py | 24 ++++-- Cantera/python/examples/rxnpath2.py | 6 +- Cantera/python/examples/stflame2.py | 84 ------------------- Cantera/python/src/ctonedim_methods.cpp | 12 +++ Cantera/python/src/methods.h | 1 + Cantera/src/CVode.h | 12 +-- Cantera/src/Integrator.h | 2 + Cantera/src/ct2ctml.cpp | 2 +- Cantera/src/oneD/Inlet1D.h | 2 +- Cantera/src/oneD/MultiNewton.cpp | 10 +-- Cantera/src/oneD/OneDim.h | 1 - Cantera/src/oneD/Sim1D.cpp | 7 +- Cantera/src/oneD/Sim1D.h | 1 + 19 files changed, 66 insertions(+), 121 deletions(-) delete mode 100644 Cantera/python/examples/stflame2.py diff --git a/Cantera/clib/src/ctonedim.cpp b/Cantera/clib/src/ctonedim.cpp index 0166761b3..d05a78102 100644 --- a/Cantera/clib/src/ctonedim.cpp +++ b/Cantera/clib/src/ctonedim.cpp @@ -447,6 +447,14 @@ extern "C" { catch (CanteraError) { return -1; } } + int DLL_EXPORT sim1D_getInitialSoln(int i) { + try { + _sim1D(i)->getInitialSoln(); + return 0; + } + catch (CanteraError) { return -1; } + } + int DLL_EXPORT sim1D_solve(int i, int loglevel, int refine_grid) { try { bool r = (refine_grid == 0 ? false : true); diff --git a/Cantera/clib/src/ctonedim.h b/Cantera/clib/src/ctonedim.h index 5ce22657b..4cfd42747 100644 --- a/Cantera/clib/src/ctonedim.h +++ b/Cantera/clib/src/ctonedim.h @@ -58,6 +58,7 @@ extern "C" { int DLL_IMPORT sim1D_setFlatProfile(int i, int dom, int comp, double v); int DLL_IMPORT sim1D_showSolution(int i, char* fname); int DLL_IMPORT sim1D_setTimeStep(int i, double stepsize, int ns, int* nsteps); + int DLL_IMPORT sim1D_getInitialSoln(int i); int DLL_IMPORT sim1D_solve(int i, int loglevel, int refine_grid); int DLL_IMPORT sim1D_refine(int i, int loglevel); int DLL_IMPORT sim1D_setRefineCriteria(int i, int dom, double ratio, diff --git a/Cantera/matlab/cantera/examples/catcomb.m b/Cantera/matlab/cantera/examples/catcomb.m index a6685af6a..a9155c4c8 100644 --- a/Cantera/matlab/cantera/examples/catcomb.m +++ b/Cantera/matlab/cantera/examples/catcomb.m @@ -191,7 +191,7 @@ set(inlt,'X',comp2); setRefineCriteria(sim1D, 2, 100.0, 0.15, 0.2); % solve the problem for the final time -solve(sim1D, 1, refine_grid); +solve(sim1D, loglevel, refine_grid); %refine_grid); % show the solution sim1D diff --git a/Cantera/matlab/cantera/examples/flame1.m b/Cantera/matlab/cantera/examples/flame1.m index 481005dc7..e4498a9cb 100644 --- a/Cantera/matlab/cantera/examples/flame1.m +++ b/Cantera/matlab/cantera/examples/flame1.m @@ -21,16 +21,16 @@ comp = 'H2:1.8, O2:1, AR:7'; % premixed gas composition initial_grid = [0.0 0.02 0.04 0.06 0.08 0.1 ... 0.15 0.2 0.4 0.49 0.5]; % m -tol_ss = [1.0e-5 1.0e-9]; % [rtol atol] for steady-state +tol_ss = [1.0e-5 1.0e-13]; % [rtol atol] for steady-state % problem -tol_ts = [1.0e-3 1.0e-4]; % [rtol atol] for time stepping +tol_ts = [1.0e-4 1.0e-9]; % [rtol atol] for time stepping loglevel = 1; % amount of diagnostic output (0 % to 5) refine_grid = 1; % 1 to enable refinement, 0 to % disable - +max_jacobian_age = [5, 10]; %%%%%%%%%%%%%%%% create the gas object %%%%%%%%%%%%%%%%%%%%%%%% % @@ -78,12 +78,13 @@ s = Outlet('out'); % to create the flame object. % fl = flame(gas, burner, f, s); +setMaxJacAge(fl, max_jacobian_age(1), max_jacobian_age(2)); % if the starting solution is to be read from a previously-saved % solution, uncomment this line and edit the file name and solution id. %restore(fl,'h2flame2.xml', 'energy') -solve(fl, 1, refine_grid); +solve(fl, loglevel, refine_grid); %%%%%%%%%%%% enable the energy equation %%%%%%%%%%%%%%%%%%%%% % diff --git a/Cantera/python/Cantera/OneD/BurnerFlame.py b/Cantera/python/Cantera/OneD/BurnerFlame.py index 5dc2d474c..55101d61c 100644 --- a/Cantera/python/Cantera/OneD/BurnerFlame.py +++ b/Cantera/python/Cantera/OneD/BurnerFlame.py @@ -25,6 +25,7 @@ class BurnerFlame(Stack): def init(self): """Set the initial guess for the solution.""" + self.getInitialSoln() gas = self.gas nsp = gas.nSpecies() yin = Numeric.zeros(nsp, 'd') diff --git a/Cantera/python/Cantera/OneD/CounterFlame.py b/Cantera/python/Cantera/OneD/CounterFlame.py index 9e9301638..4480beacd 100644 --- a/Cantera/python/Cantera/OneD/CounterFlame.py +++ b/Cantera/python/Cantera/OneD/CounterFlame.py @@ -51,7 +51,7 @@ class CounterFlame(Stack): The initial guess is generated by assuming infinitely-fast chemistry.""" - + self.getInitialSoln() gas = self.gas nsp = gas.nSpecies() wt = gas.molecularWeights() diff --git a/Cantera/python/Cantera/OneD/StagnationFlow.py b/Cantera/python/Cantera/OneD/StagnationFlow.py index 25941a47d..b66c14811 100644 --- a/Cantera/python/Cantera/OneD/StagnationFlow.py +++ b/Cantera/python/Cantera/OneD/StagnationFlow.py @@ -17,8 +17,7 @@ class StagnationFlow(Stack): self.setRefineCriteria() self._initialized = 0 - - def init(self): + def init(self, products = 'inlet'): """Set the initial guess for the solution.""" self.getInitialSoln() gas = self.gas @@ -36,13 +35,24 @@ class StagnationFlow(Stack): zz = self.flow.grid() dz = zz[-1] - zz[0] - - locs = Numeric.array([0.0, 1.0],'d') + if products == 'equil': + gas.equilibrate('HP') + teq = gas.temperature() + yeq = gas.massFractions() + locs = Numeric.array([0.0, 0.3, 0.7, 1.0],'d') + self.setProfile('T', locs, [t0, teq, teq, tsurf]) + for n in range(nsp): + self.setProfile(gas.speciesName(n), locs, [yin[n], yeq[n], yeq[n], yeq[n]]) + else: + locs = Numeric.array([0.0, 1.0],'d') + self.setProfile('T', locs, [t0, tsurf]) + for n in range(nsp): + self.setProfile(gas.speciesName(n), locs, [yin[n], yin[n]]) + + locs = Numeric.array([0.0, 1.0],'d') self.setProfile('u', locs, [u0, 0.0]) self.setProfile('V', locs, [V0, V0]) - self.setProfile('T', locs, [t0, tsurf]) - for n in range(nsp): - self.setProfile(gas.speciesName(n), locs, [yin[n], yin[n]]) + self._initialized = 1 diff --git a/Cantera/python/examples/rxnpath2.py b/Cantera/python/examples/rxnpath2.py index 419c738cd..ae5132b8f 100755 --- a/Cantera/python/examples/rxnpath2.py +++ b/Cantera/python/examples/rxnpath2.py @@ -60,8 +60,8 @@ fmt = 'svg' print 'writing dot file',output_file+'...' #rxnpath.write(gas, element, join(output_dir, output_file), d) rxnpath.write(gas, element, output_file, d) -os.system('scp '+output_file+' blue:/var/www/html') -print 'generating browser view...' -rxnpath.view(url, fmt) +#os.system('scp '+output_file+' blue:/var/www/html') +#print 'generating browser view...' +#rxnpath.view(url, fmt) diff --git a/Cantera/python/examples/stflame2.py b/Cantera/python/examples/stflame2.py deleted file mode 100644 index e1b444abf..000000000 --- a/Cantera/python/examples/stflame2.py +++ /dev/null @@ -1,84 +0,0 @@ -""" - A stagnation-point flame using GRI-Mech 3.0. - - In this script, a hydrogen / oxygen / argon flame is first solved, - and then used as the starting estimate for a methane / oxygen / argon - flame. - -""" - -from Cantera.flame import * -from Cantera import units - -# start with only a hydrogen/oxygen mechanism -gas = IdealGasMix('h2o2.cti') - -flame = StagnationFlame( - domain = (0, 0.02), - fuel = 'H2:1', - oxidizer = 'O2:1, AR:4', - gas = gas, - grid = [0.0, 0.0025, 0.005, 0.0075, 0.01, 0.016, 0.02] - ) - -flame.set(mdot = 0.4, - equiv_ratio = 0.9, - T_burner = 373.7, - T_surface = 600.0, - pressure = 1.0 * units.atm, - tol = (1.e-7, 1.e-11), - timesteps = ([1,2,5,10,20], 1.e-5), - refine = (10.0, 1.0, 1.0), - jac_age = (50, 50), - ) - -# first solve the fixed-temperature problem -flame.set(energy = 'off') -flame.solve(1) - -# now enable the energy equation, and specify that rough -# grid refinement should be done -flame.set(energy = 'on', refine = (3.0, 0.9, 0.9)) -flame.solve(1) - -flame.save('energy','h2/o2 soln with energy equation', 'h2.xml') - - -#----------------------------------------------------------- - -# Now construct the methane flame using GRI-Mech 3.0 -gas2 = GRI30(transport = 'Mix') - -flame2 = StagnationFlame( - domain = (0, 0.02), - fuel = 'CH4:1', - oxidizer = 'O2:1, AR:4', - gas = gas2, - grid = [0.0, 0.0025, 0.005, 0.0075, 0.01, 0.016, 0.02] - ) - -flame2.set(mdot = 0.8, - equiv_ratio = 0.9, - T_burner = 373.7, - T_surface = 600.0, - pressure = 1.0 * units.atm, - tol = (1.e-7, 1.e-11), - timesteps = ([1,2,5], 1.e-5), - refine = (2.0, 0.1, 0.2), - jac_age = (50, 50), - ) - -# Use the hydrogen results as the starting guess. -flame2.restore(src = 'h2.xml', solution = 'energy') - -flame2.set(energy = 'on') -flame2.solve(1) -flame2.show() - -# write plot files -flame2.plot(plotfile = 'stflame2.dat', title = 'methane/air flame', - fmt = 'TECPLOT') -flame2.plot(plotfile = 'stflame2.csv', fmt = 'EXCEL') -print 'Solution written to TECPLOT file stflame2.dat and Excel CSV file stflame2.csv' -flame2.showStatistics() - diff --git a/Cantera/python/src/ctonedim_methods.cpp b/Cantera/python/src/ctonedim_methods.cpp index 8f087f9bd..0478fd3b0 100644 --- a/Cantera/python/src/ctonedim_methods.cpp +++ b/Cantera/python/src/ctonedim_methods.cpp @@ -721,6 +721,18 @@ py_sim1D_setRefineCriteria(PyObject *self, PyObject *args) } +static PyObject * +py_sim1D_getInitialSoln(PyObject *self, PyObject *args) +{ + int i, iok; + if (!PyArg_ParseTuple(args, "i:sim1D_getInitialSoln", &i)) + return NULL; + + iok = sim1D_getInitialSoln(i); + if (iok == -1) return reportCanteraError(); + return Py_BuildValue("i",iok); +} + static PyObject * py_sim1D_save(PyObject *self, PyObject *args) { diff --git a/Cantera/python/src/methods.h b/Cantera/python/src/methods.h index 6e4b94bb5..3548a013a 100644 --- a/Cantera/python/src/methods.h +++ b/Cantera/python/src/methods.h @@ -169,6 +169,7 @@ static PyMethodDef ct_methods[] = { {"sim1D_setFlatProfile", py_sim1D_setFlatProfile, METH_VARARGS}, {"sim1D_showSolution", py_sim1D_showSolution, METH_VARARGS}, {"sim1D_setTimeStep", py_sim1D_setTimeStep, METH_VARARGS}, + {"sim1D_getInitialSoln", py_sim1D_getInitialSoln, METH_VARARGS}, {"sim1D_solve", py_sim1D_solve, METH_VARARGS}, {"sim1D_refine", py_sim1D_refine, METH_VARARGS}, {"sim1D_setRefineCriteria", py_sim1D_setRefineCriteria, METH_VARARGS}, diff --git a/Cantera/src/CVode.h b/Cantera/src/CVode.h index 65cf59465..a1eed0145 100755 --- a/Cantera/src/CVode.h +++ b/Cantera/src/CVode.h @@ -23,11 +23,6 @@ #include "ctexceptions.h" #include "ct_defs.h" -// cvode includes -//#include "cvode/nvector.h" -//#include "cvode/cvode.h" - - namespace Cantera { /** @@ -74,8 +69,7 @@ namespace Cantera { int m_neq; void* m_cvode_mem; double m_t0; - void *m_y, *m_abstol; //N_Vector m_y; - //N_Vector m_abstol; + void *m_y, *m_abstol; int m_type; int m_itol; int m_method; @@ -87,9 +81,7 @@ namespace Cantera { double m_hmax; vector_fp m_ropt; - //vector_int m_iopt; - long int* m_iopt; //[OPT_SIZE]; - //N_Vector m_yprime; + long int* m_iopt; void* m_data; }; diff --git a/Cantera/src/Integrator.h b/Cantera/src/Integrator.h index c02597013..823954160 100755 --- a/Cantera/src/Integrator.h +++ b/Cantera/src/Integrator.h @@ -62,6 +62,8 @@ namespace Cantera { public: + virtual ~Integrator() {} + /** Set or reset the number of equations. */ //virtual void resize(int n)=0; diff --git a/Cantera/src/ct2ctml.cpp b/Cantera/src/ct2ctml.cpp index 2e33d9531..d2ceb3143 100644 --- a/Cantera/src/ct2ctml.cpp +++ b/Cantera/src/ct2ctml.cpp @@ -57,7 +57,7 @@ namespace ctml { "The Cantera Python interface is required in order to process\n" "Cantera input files, but it does not seem to be correctly installed.\n\n" "Check that you can invoke the Python interpreter with \n" - "the command \"python\", and that typing \"from Cantera import *\"\n" + "the command \"python\", and that typing \"from Cantera import *\" \n" "at the Python prompt does not produce an error. If Python on your system\n" "is invoked with some other command, set environment variable PYTHON_CMD\n" "to the full path to the Python interpreter. \n\n" diff --git a/Cantera/src/oneD/Inlet1D.h b/Cantera/src/oneD/Inlet1D.h index 73f400484..d24a32bbd 100644 --- a/Cantera/src/oneD/Inlet1D.h +++ b/Cantera/src/oneD/Inlet1D.h @@ -354,7 +354,7 @@ namespace Cantera { virtual void showSolution(const doublereal* x) { char buf[80]; - sprintf(buf, " Temperature: %10.4g K \n", m_temp); + sprintf(buf, " Temperature: %10.4g K \n", x[0]); writelog(buf); writelog(" Coverages: \n"); for (int k = 0; k < m_nsp; k++) { diff --git a/Cantera/src/oneD/MultiNewton.cpp b/Cantera/src/oneD/MultiNewton.cpp index e6826cd12..3007033ad 100644 --- a/Cantera/src/oneD/MultiNewton.cpp +++ b/Cantera/src/oneD/MultiNewton.cpp @@ -121,9 +121,9 @@ namespace Cantera { step[n] = -step[n]; } //try { - jac.solve(sz, step, step); - //} - //catch (CanteraError) { + jac.solve(sz, step, step); + //} + //catch (CanteraError) { #undef DEBUG_STEP #ifdef DEBUG_STEP bool ok = false; @@ -141,7 +141,7 @@ namespace Cantera { } #endif //throw CanteraError("step","step error"); - //} + // } } @@ -272,7 +272,6 @@ namespace Cantera { int MultiNewton::solve(doublereal* x0, doublereal* x1, OneDim& r, MultiJac& jac, int loglevel) { clock_t t0 = clock(); - int m = 0; bool forceNewJac = false; doublereal s1=1.e30; @@ -308,7 +307,6 @@ namespace Cantera { // increment the Jacobian age jac.incrementAge(); - //cout << jac.age() << endl; // damp the Newton step m = dampStep(x, stp, x1, stp1, s1, r, jac, loglevel-1, frst); diff --git a/Cantera/src/oneD/OneDim.h b/Cantera/src/oneD/OneDim.h index f76dca868..6bff3256f 100644 --- a/Cantera/src/oneD/OneDim.h +++ b/Cantera/src/oneD/OneDim.h @@ -146,7 +146,6 @@ namespace Cantera { void setMaxTimeStep(doublereal tmax) { m_tmax = tmax; } void setTimeStepFactor(doublereal tfactor) { m_tfactor = tfactor; } void setJacAge(int ss_age, int ts_age=-1) { - cout << "setting jac age " << ss_age << " " << ts_age << endl; m_ss_jac_age = ss_age; if (ts_age > 0) m_ts_jac_age = ts_age; diff --git a/Cantera/src/oneD/Sim1D.cpp b/Cantera/src/oneD/Sim1D.cpp index 242236ab9..53ba565ab 100644 --- a/Cantera/src/oneD/Sim1D.cpp +++ b/Cantera/src/oneD/Sim1D.cpp @@ -26,9 +26,7 @@ namespace Cantera { m_x.resize(size(), 0.0); m_xnew.resize(size(), 0.0); for (int n = 0; n < m_nd; n++) { - // writelog("calling domain "+int2str(n)+" _getInitialSoln\n"); domain(n)._getInitialSoln(m_x.begin() + start(n)); - // writelog("ret\n"); } // set some defaults @@ -178,6 +176,11 @@ namespace Cantera { } } + void Sim1D::getInitialSoln() { + for (int n = 0; n < m_nd; n++) { + domain(n)._getInitialSoln(m_x.begin() + start(n)); + } + } void Sim1D::finalize() { for (int n = 0; n < m_nd; n++) { diff --git a/Cantera/src/oneD/Sim1D.h b/Cantera/src/oneD/Sim1D.h index ec76f4cb5..cc64648a5 100644 --- a/Cantera/src/oneD/Sim1D.h +++ b/Cantera/src/oneD/Sim1D.h @@ -90,6 +90,7 @@ namespace Cantera { doublereal slope = 0.8, doublereal curve = 0.8, doublereal prune = -0.1); void restore(string fname, string id); + void getInitialSoln(); protected: