From cf0ff0c6fd1c8247e3cd76cdb8efb0c5750a1509 Mon Sep 17 00:00:00 2001 From: Ray Speth Date: Tue, 21 Jan 2014 17:21:43 +0000 Subject: [PATCH] [1D] Move m_zfixed and m_tfixed variables from Domain1D to FreeFlame FreeFlame is the only subclass of Domain1D where these variables are used. --- include/cantera/oneD/Domain1D.h | 3 -- include/cantera/oneD/StFlow.h | 17 ++++--- src/oneD/Sim1D.cpp | 46 ++++++++--------- src/oneD/StFlow.cpp | 87 ++++++++++++++++++++------------- src/oneD/refine.cpp | 5 +- 5 files changed, 90 insertions(+), 68 deletions(-) diff --git a/include/cantera/oneD/Domain1D.h b/include/cantera/oneD/Domain1D.h index 4ba4e2844..ff533f99d 100644 --- a/include/cantera/oneD/Domain1D.h +++ b/include/cantera/oneD/Domain1D.h @@ -601,9 +601,6 @@ public: */ virtual void _finalize(const doublereal* x) {} - doublereal m_zfixed; - doublereal m_tfixed; - bool m_adiabatic; protected: diff --git a/include/cantera/oneD/StFlow.h b/include/cantera/oneD/StFlow.h index 226f8a1f9..85a75c5df 100644 --- a/include/cantera/oneD/StFlow.h +++ b/include/cantera/oneD/StFlow.h @@ -530,12 +530,7 @@ public: class FreeFlame : public StFlow { public: - FreeFlame(IdealGasPhase* ph = 0, size_t nsp = 1, size_t points = 1) : - StFlow(ph, nsp, points) { - m_dovisc = false; - setID("flame"); - } - + FreeFlame(IdealGasPhase* ph = 0, size_t nsp = 1, size_t points = 1); virtual void evalRightBoundary(doublereal* x, doublereal* res, integer* diag, doublereal rdt); virtual void evalContinuity(size_t j, doublereal* x, doublereal* r, @@ -547,6 +542,16 @@ public: virtual bool fixed_mdot() { return false; } + virtual void _finalize(const doublereal* x); + virtual void restore(const XML_Node& dom, doublereal* soln, int loglevel); + + virtual XML_Node& save(XML_Node& o, const doublereal* const sol); + + //! Location of the point where temperature is fixed + doublereal m_zfixed; + + //! Temperature at the point used to fix the flame location + doublereal m_tfixed; }; /** diff --git a/src/oneD/Sim1D.cpp b/src/oneD/Sim1D.cpp index 76c221253..f05dda112 100644 --- a/src/oneD/Sim1D.cpp +++ b/src/oneD/Sim1D.cpp @@ -4,7 +4,7 @@ #include "cantera/oneD/Sim1D.h" #include "cantera/oneD/MultiJac.h" - +#include "cantera/oneD/StFlow.h" #include using namespace std; @@ -451,34 +451,34 @@ int Sim1D::setFixedTemperature(doublereal t) size_t comp = d.nComponents(); // loop over points in the current grid to determine where new point is needed. + FreeFlame* d_free = dynamic_cast(&domain(n)); size_t npnow = d.nPoints(); size_t nstart = znew.size(); - for (m = 0; m < npnow-1; m++) { - if (value(n,2,m) == t) { - zfixed = d.grid(m); - //set d.zfixed, d.ztemp - d.m_zfixed = zfixed; - d.m_tfixed = t; - addnewpt = false; - break; - } else if ((value(n,2,m)t)) { - z1 = d.grid(m); - m1 = m; - z2 = d.grid(m+1); - t1 = value(n,2,m); - t2 = value(n,2,m+1); + if (d_free) { + for (m = 0; m < npnow-1; m++) { + if (value(n,2,m) == t) { + zfixed = d.grid(m); + d_free->m_zfixed = zfixed; + d_free->m_tfixed = t; + addnewpt = false; + break; + } else if ((value(n,2,m)t)) { + z1 = d.grid(m); + m1 = m; + z2 = d.grid(m+1); + t1 = value(n,2,m); + t2 = value(n,2,m+1); - zfixed = (z1-z2)/(t1-t2)*(t-t2)+z2; - //set d.zfixed, d.ztemp; - d.m_zfixed = zfixed; - d.m_tfixed = t; - addnewpt = true; - break; - //copy solution domain and push back values + zfixed = (z1-z2)/(t1-t2)*(t-t2)+z2; + d_free->m_zfixed = zfixed; + d_free->m_tfixed = t; + addnewpt = true; + break; + //copy solution domain and push back values + } } } - for (m = 0; m < npnow; m++) { // add the current grid point to the new grid znew.push_back(d.grid(m)); diff --git a/src/oneD/StFlow.cpp b/src/oneD/StFlow.cpp index 1a5aadea1..a0c8f9d2d 100644 --- a/src/oneD/StFlow.cpp +++ b/src/oneD/StFlow.cpp @@ -96,9 +96,6 @@ StFlow::StFlow(IdealGasPhase* ph, size_t nsp, size_t points) : m_points = points; m_thermo = ph; - m_zfixed = Undef; - m_tfixed = Undef; - if (ph == 0) { return; // used to create a dummy object } @@ -276,30 +273,6 @@ void StFlow::_finalize(const doublereal* x) if (e) { solveEnergyEqn(); } - - // If the domain contains the temperature fixed point, make sure that it - // is correctly set. This may be necessary when the grid has been modified - // externally. - if (m_tfixed != Undef) { - bool found_zfix = false; - for (size_t j = 0; j < m_points; j++) { - if (z(j) == m_zfixed) { - found_zfix = true; - break; - } - } - if (!found_zfix) { - for (size_t j = 0; j < m_points - 1; j++) { - // Find where the temperature profile crosses the current - // fixed temperature. - if ((T(x, j) - m_tfixed) * (T(x, j+1) - m_tfixed) <= 0.0) { - m_tfixed = T(x, j+1); - m_zfixed = z(j+1); - break; - } - } - } - } } void StFlow::eval(size_t jg, doublereal* xg, @@ -687,9 +660,6 @@ void StFlow::restore(const XML_Node& dom, doublereal* soln, int loglevel) pp = getFloat(dom, "pressure", "pressure"); setPressure(pp); - getOptionalFloat(dom, "t_fixed", m_tfixed); - getOptionalFloat(dom, "z_fixed", m_zfixed); - vector d; dom.child("grid_data").getChildren("floatArray",d); size_t nd = d.size(); @@ -857,11 +827,6 @@ XML_Node& StFlow::save(XML_Node& o, const doublereal* const sol) XML_Node& gv = flow.addChild("grid_data"); addFloat(flow, "pressure", m_press, "Pa", "pressure"); - if (m_zfixed != Undef) { - addFloat(flow, "z_fixed", m_zfixed, "m"); - addFloat(flow, "t_fixed", m_tfixed, "K"); - } - addFloatArray(gv,"z",m_z.size(),DATA_PTR(m_z), "m","length"); vector_fp x(soln.nColumns()); @@ -956,6 +921,15 @@ void AxiStagnFlow::evalContinuity(size_t j, doublereal* x, doublereal* rsd, diag[index(c_offset_U, j)] = 0; } +FreeFlame::FreeFlame(IdealGasPhase* ph, size_t nsp, size_t points) : + StFlow(ph, nsp, points), + m_zfixed(Undef), + m_tfixed(Undef) +{ + m_dovisc = false; + setID("flame"); +} + void FreeFlame::evalRightBoundary(doublereal* x, doublereal* rsd, integer* diag, doublereal rdt) { @@ -1012,4 +986,47 @@ void FreeFlame::evalContinuity(size_t j, doublereal* x, doublereal* rsd, diag[index(c_offset_U, j)] = 0; } +void FreeFlame::_finalize(const doublereal* x) +{ + StFlow::_finalize(x); + // If the domain contains the temperature fixed point, make sure that it + // is correctly set. This may be necessary when the grid has been modified + // externally. + if (m_tfixed != Undef) { + for (size_t j = 0; j < m_points; j++) { + if (z(j) == m_zfixed) { + return; // fixed point is already set correctly + } + } + + for (size_t j = 0; j < m_points - 1; j++) { + // Find where the temperature profile crosses the current + // fixed temperature. + if ((T(x, j) - m_tfixed) * (T(x, j+1) - m_tfixed) <= 0.0) { + m_tfixed = T(x, j+1); + m_zfixed = z(j+1); + return; + } + } + } +} + + +void FreeFlame::restore(const XML_Node& dom, doublereal* soln, int loglevel) +{ + StFlow::restore(dom, soln, loglevel); + getOptionalFloat(dom, "t_fixed", m_tfixed); + getOptionalFloat(dom, "z_fixed", m_zfixed); +} + +XML_Node& FreeFlame::save(XML_Node& o, const doublereal* const sol) +{ + XML_Node& flow = StFlow::save(o, sol); + if (m_zfixed != Undef) { + addFloat(flow, "z_fixed", m_zfixed, "m"); + addFloat(flow, "t_fixed", m_tfixed, "K"); + } + return flow; +} + } // namespace diff --git a/src/oneD/refine.cpp b/src/oneD/refine.cpp index a1809d622..bed9828bf 100644 --- a/src/oneD/refine.cpp +++ b/src/oneD/refine.cpp @@ -1,6 +1,7 @@ //! @file refine.cpp #include "cantera/oneD/refine.h" #include "cantera/oneD/Domain1D.h" +#include "cantera/oneD/StFlow.h" #include #include @@ -132,6 +133,8 @@ int Refiner::analyze(size_t n, const doublereal* z, } } + FreeFlame* fflame = dynamic_cast(m_domain); + // Refine based on properties of the grid itself for (size_t j = 1; j < n-1; j++) { // Add a new point if the ratio with left interval is too large @@ -167,7 +170,7 @@ int Refiner::analyze(size_t n, const doublereal* z, } // Keep the point where the temperature is fixed - if (z[j] == m_domain->m_zfixed) { + if (fflame && z[j] == fflame->m_zfixed) { m_keep[j] = 1; } }