[1D] Move m_zfixed and m_tfixed variables from Domain1D to FreeFlame

FreeFlame is the only subclass of Domain1D where these variables are used.
This commit is contained in:
Ray Speth 2014-01-21 17:21:43 +00:00
parent f45e627745
commit cf0ff0c6fd
5 changed files with 90 additions and 68 deletions

View file

@ -601,9 +601,6 @@ public:
*/
virtual void _finalize(const doublereal* x) {}
doublereal m_zfixed;
doublereal m_tfixed;
bool m_adiabatic;
protected:

View file

@ -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;
};
/**

View file

@ -4,7 +4,7 @@
#include "cantera/oneD/Sim1D.h"
#include "cantera/oneD/MultiJac.h"
#include "cantera/oneD/StFlow.h"
#include <fstream>
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<FreeFlame*>(&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) && (value(n,2,m+1)>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) && (value(n,2,m+1)>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));

View file

@ -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<XML_Node*> 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

View file

@ -1,6 +1,7 @@
//! @file refine.cpp
#include "cantera/oneD/refine.h"
#include "cantera/oneD/Domain1D.h"
#include "cantera/oneD/StFlow.h"
#include <algorithm>
#include <limits>
@ -132,6 +133,8 @@ int Refiner::analyze(size_t n, const doublereal* z,
}
}
FreeFlame* fflame = dynamic_cast<FreeFlame*>(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;
}
}