Creating a interface phase in StFlow.cpp

77 views
Skip to first unread message

ET

unread,
May 5, 2014, 5:12:09 PM5/5/14
to canter...@googlegroups.com
Hi Cantera Users,

I am trying to add a routine to StFlow.cpp that calculates surface reactions.  For security reasons, I am not allowed to install/change the installed version of Cantera.  

Anyway, the modification (mods are in bold) that I made below works like I intend it to.  However, the command     Interface surface("ptcombust.cti", "Pt_surf", phases);  in equil_demo slows things down quite a bit.  My intention is to create the surface earlier. In fact, I would like to do this right after the line vector<ThermoPhase*> phases;  .  When I try this, though, I get an error message that says the supplied phase is not found.   

Can anyone out there please tell me how I can create this phase prior to the subroutine (or refer me to an example that does this)?

Thanks a lot!


/**
 * @file StFlow.cpp
 */
// Copyright 2002  California Institute of Technology

#include <stdlib.h>
#include <time.h>

#include "cantera/oneD/StFlow.h"
#include "cantera/base/ctml.h"
#include "cantera/oneD/MultiJac.h"
#include "cantera/IdealGasMix.h"                         // ADDING DEFINING INTERFACE TO CREATE GAS PHASE TO CREATE SUBSEQUENT INTERFACE
#include "cantera/Interface.h"                           // ADDING DEFINING INTERFACE FOR SURFACE REACTIONS

#include "cantera/equilibrium.h"                         // ADDING...TRYING TO ADD A SIMPLE ROUTINE
#include "cantera/thermo.h"                              // ADDING...TRYING TO ADD A SIMPLE ROUTINE

#include <cmath>                                         // ADDING MATH FUNCTION TO HANDLE pow(x,y)
#include <cstdio>                                        // ADDING TO PRINT/DEBUG

using namespace ctml;
using namespace std;

namespace Cantera
{
  ThermoPhase* wall = newPhase("h2o2.cti","ohmech");          //ADDING...CREATING A NEAR WALL GAS PHASE
  vector<ThermoPhase*> phases;                                            // ADDING...CREATIGN A VECTOR OF PHASES FOR INTERFACE
  vector_fp surfdot(14);


  // ADDING...THIS SECTION BORROWS HEAVILY FROM surfdemo.cpp.
  //THE IDEA IS TO SET GAS PHASE AT THE WALL THEN FIND THE SURFACE
  //PRODUCTION RATES.  

  void equil_demo(const doublereal* x, size_t j)
  {
    int nsp;
    nsp = 9;
    doublereal press = OneAtm;
    doublereal ywall[nsp];

    doublereal twall;
    twall =  x[(nsp+c_offset_Y+1)+(c_offset_Y+2*nsp+1)*j-1];

    for(int k=0; k<nsp; k++){
      ywall[k] = x[(nsp+c_offset_Y+1)+(c_offset_Y+2*nsp+1)*j+k];
    }

    wall->setTemperature(twall);
    wall->setMassFractions(ywall);
    wall->setPressure(press);

    phases.push_back(wall);

    doublereal cov[5];
    cov[0]=0.2; cov[1]=0.2;  cov[2]=0.2;  cov[3]=0.2;  cov[4]=0.2;

    Interface surface("ptcombust.cti", "Pt_surf", phases);
    surface.solvePseudoSteadyStateProblem();
    surface.getNetProductionRates(DATA_PTR(surfdot));
  }


...the remainder of StFlow.cpp

Ray Speth

unread,
May 5, 2014, 6:38:02 PM5/5/14
to canter...@googlegroups.com
Erik,

It's unclear what you're trying to do here. Cantera already has functionality for modeling surface reactions in 1D flows (ReactingSurf1D). But if that class does not implement the model you want, what I would recommend is that you try to implement that behavior by creating one or more new classes derived from other Cantera classes (e.g. StFlow) in a separate source file. Adding new global variables (e.g. 'wall', 'phases' and 'surfdot' here) is almost certainly not going to do what you want, and mixing your code with Cantera is just going to make things confusing for you later.

Regards,
Ray

ET

unread,
May 6, 2014, 10:53:21 AM5/6/14
to canter...@googlegroups.com
Thanks, Ray!  I am looking into ReactingSurf1D right now.  I am having a little trouble understanding it, but I am working on it. 

Does anyone have an example that uses ReactingSurf1D?
Reply all
Reply to author
Forward
0 new messages