orch:Usage

From orch
Revision as of 21:17, 2 July 2020 by Barnaudc (Talk | contribs) (Common Errors)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Reduce chemistry

  • All the information necessary to run the subsequent steps of the reduction process are to be entered in the file: "conditions.cpp"
 new_mixing = 'False' or 'True'  
- if 'False': the stochastic mixing will follow the same pattern during trajectories (i.e. the same time history of random numbers are used along the composition space trajectories);
- if 'True': the time history of the stochastic mixing differs from the previous run;
This parameter must be 'True' for the first simulation of the composition space trajectories, then one may decide to perform the reduction and optimisation with the same, or a new, time history of random numbers controlling the stochastic mixing. So far, ORCh produced good results using 'False', but for the first run where it must be set to 'True'.
  • Chemical scheme files:
The reference detailed scheme is entered here:
 mech_ref = "mechanisms/gri12.xml";  
Intermediate scheme from which the reduction should be pursued (after completing one of the steps), it must be updated at every stage:
  mech = "./outputs/mechanisms/drgepSpecies17.xml";  
If first run, use the same as the reference detailed mechanism:
    mech = "mechanisms/gri12.xml"; 
Always provide a cantera id for the chemical scheme (you can choose any, but it must be there and agrees between files, i.e. do not change it during the whole optimisation process):
  mech_desc = "gri12"; 

For instance, you may find it in the "gri12.xml" file <phase dim="3" id="gri12">


  • Targeted species
The species that you wish to reproduce with accuracy in the reduced scheme should be given in 'conditions.cpp' following the format:
 listTargets.push_back("H2");
 listTargets.push_back("O2");
 listTargets.push_back("H2O");
 listTargets.push_back("CH4");
 listTargets.push_back("CO");
 listTargets.push_back("CO2"); 


These target species will have the highest DRGEP coefficient (=1) and the hight weight during optimisation (note that for the DRGEP steps the species into reactant are automatically preserved, i.e. their DRGEP coefficient is also set to 1 so they can't be suppressed)

  • Inlet of composition space trajectories
You can prescribe as many inlets as you wish. For every inlet, you need to provide all these parameters: Temperature, Pressure, Mass flow rate (note that the number of particles per inlet is 1000 times the mass flow inlet in kg/s), and then directly the composition, either in mole fractions (first set, see below), or mass fractions if you prefer those, the code will understand anyway.
The last inlet must be composed of burnt gases, in which you need to give in addition: the mixing time, the time step and the number of iterations.
Of course, it will then be needed to check that, for these parameters, the solution is well captured and that you have reached the chemical equilibrium condition.
 
 //-- Temp, Pressure, number of particles, "moles fractions" or "mass fractions" leave empty the other one --//
 listInlets.push_back(new MultipleInlet(320, 1E+05, NbParticles1,
                       "O2:0.15, N2:0.52, H2O:0.0029, CH4:0.33", ""));
  //Inlet 2 //
  listInlets.push_back(new MultipleInlet(1350, 1E+05, NbParticles2,
                       "O2:0.12, N2:0.73, H2O:0.15, CH4:0.0003", ""));
  //-- The very last inlet must be burnt gases --//
  //-- Same as other inlet + mixing time tau_t, delta_t, number of iterations --//
  //BurnedGases
  double tau_t = 2e-03;
  double delta_t = 5e-05;
  bool BurnedGases = true;
  listInlets.push_back(new Characteristics_MultipleInlet(2290, 1E+05, NbParticlesBurnedGases,
                       "N2:0.682, H2O:0.236, CO2:0.0539, CO:0.00823, H2:0.00647, O2:0.00516, OH:0.00431", "",
                       tau_t, delta_t, 400, BurnedGases)); 
  • After any modification in 'conditions.cpp', the code must be re-compile, therefore this must be done between every step and sub-steps of the method
 make clean 
 make 
  • DRGEP is the first stage to run: it includes the computation of the trajectories with detailed chemistry and the DRGEP analysis to reduce the number of species and reactions:
First sub-step - select in 'conditions.cpp':
 step = "DRGEP_Species"; 
This first step provides a series of chemical schemes whose number of species ranges between the initial number of species of the mechanism and 10 species (this limit can be changed in main/mainDRGEPSpecies.cpp).
Here schemes will be built with a total number of species ranging between 20 and 15. Notice that the control of the threshold, TS, of Jaouen et al. (see references above) is automatically computed from 'nbSpeciesToKeep' and 'nbSpeciesToKeep>' in 'ORCh/main.cpp'.
Run
 ./main 
Once done, you need to go into the 'outputs' directory, there you can examine the trajectories (Premixed or Stochastic) of the species you previously set in conditions.cpp:
 speciesToPlot.push_back("H2O"); 
To find the positions of species in the files, you need to go into the reference and reduced mechanisms, which are stored in '../mechanisms/' and './outputs/mechanisms'
Select the best mechanism you like and put his name in 'conditions.cpp':
  mech = "./outputs/mechanisms/yourbestmechname.xml"; 
'yourbestmechname.xml' is found in './outputs/mechanisms' and it looks like './outputs/mechanisms/drgepSpecies17.xml', here 17 means that this is a mechanism with 17 species.
Then, it is time for further reducing the number of reactions:
Make sure that in 'conditions.cpp':
 new_mixing = 'False'  
Second sub-step - select in 'conditions.cpp':
 step = "DRGEP_Reactions"; 
This second step provides a series of chemical schemes whose number of reactions ranges between the initial reaction number and 10 reactions (limit that can be changed in main/mainDRGEPReactions.cpp):


Once done, you need to go into the 'outputs' directory, there you can examine the trajectories.
To find the positions of species in the files, you need to go into the reference and reduced mechanisms, which are stored in '../mechanisms/' and './outputs/mechanisms'
Select the best mechanism you like and put his name in 'conditions.cpp':
  mech = "./outputs/mechanisms/yourbestmechname.xml"; 
'yourbestmechname.xml' is found in './outputs/mechanisms' and it looks like './outputs/mechanisms/drgepReactions36.xml', here 36 means that this is a mechanism with 36 reactions.
  • Automated quasi-steady state is the second stage to run: it includes the determination of species in quasi-steady state and the building of the needed relations:

First sub-step - select in 'conditions.cpp'

 step = "computeQSSCriteria"; 
The code will rerun trajectories from the specified mechanism and compute the QSS criteria, to provide in an online output an evaluation of the QSS criterion for every species, i.e. the ratio between the integral over the trajectory of the net variation rate of a species and the integral of the maximum between the production rate and the consumption rate of that given species.
In addition, the output provides the list of species which are related in a non-linear manner, to decide which species can be put in QSS.

Second sub-step - select in 'conditions.cpp'

 step = "getQSSfile"; 
The user choose a set of QSS scenarios he wants to try, this information should be put in 'conditions.cpp' (information which can be left there or not for all runs, but which is mandatory for this step):
  string array1[1] {"CH3O"};
  vector<string> vec(array1, array1 + sizeof(array1) /sizeof(array1[0]));
 string array2[3] {"CH3O", "HCO", "HO2"};  
 vector<string> vec2(array2, array2 + sizeof(array2) /sizeof(array2[0])); 
 listQSSscenarios.push_back(new QSSscenario(vec2));
For every QSS scenarios you wish to examine, the code will do two things for you:
  1. Generate the analytical relations between the species and write them ready for their use in a CFD software in the file 'analytic_schemes/RefQSSAnalysis0/mech_QSS.h', for the conditions you entered.
  2. Rerun the trajectories for these conditions, so that you can have a look and check which QSS hypotheses are best. The results for visualisation are in 'analytic_schemes/RefQSSAnalysis0', 'analytic_schemes/RefQSSAnalysis1', etc.
If you need the QSS relations in fortran, after running as above (step = "getQSSfile"), you can run with the option:
 step = "getQSSfileFORTRAN"; 
Notice that the trajectories will not be computed and that only the first QSS scenario is applied.
  • Optimisation of the rates is the last stage to run:

Preliminary step - select in 'conditions.cpp'

 step = "Optimisation"; 
The optimisation will proceed with the QSS conditions with the first QSS scenario given in 'conditions.cpp'. If one scenario exists, a QSS-step (above) must have been completed before. If none, the optimisation proceed for the full scheme without QSS.
The corresponding mechanism mut be given in 'conditions.cpp' (if you have run the previous run with various scenario, make sure to put here the mechanism corresponding to the one you prefer)
  mech = "./outputs/mechanisms/yourbestmechname.xml"; 
'yourbestmechname.xml' is found in './outputs/mechanisms' and it looks like './outputs/mechanisms/drgepReactions36.xml', here 36 means that this is a mechanism with 36 reactions.
The parameters of the Genetic Algorithm must be given
  int PopSize = 100;
  int MaxAllowableGenerations = 150;
  int NbElitism = 1;
  double CrossoverRate = 0.75;
  double MutationRate = 0.02;
  double AllowedVariation_A = 0.03;
  double AllowedVariation_b = 0.03;
  double AllowedVariation_E = 0.03; 
'PopSize' is the number of chromosomes >= 100 is advised
'MaxAllowableGenerations' number of generation to be examined >= 150 is advised
'NbElitism' number of solution copied from previous generation to secure elitism, 1 is best choice
'CrossoverRate' % of crossover, 0.75 is best choice
'MutationRate' % of mutation, 0.02 is best choice
'AllowedVariation_A' % of variation for pre-exponential constant
'AllowedVariation_b' % of variation for temperature coefficient
'AllowedVariation_E' % of variation for activation energy
This last step may be run in parallel, the number of processors used should be chosen so that PopSize/n_proc is an integer
 mpirun -np n_proc main 
During the run, temporary directories are created in 'tool/analytic_schemes/Ref#nbproc' to store all information concerning one chromosome (i.e. a trajectory obtained for one set of chemical parameters), with possibility to check corresponding trajectories.
In 'analytic_schemes/PLOTS' .eps files are automatically generated to visualise these trajectories, for each chromosomes. The evolution of the best scheme fitness at each generation is also computed in the "fitnessEvolution.eps" file.
These .eps file read 'GEN#nb_POP0_FIT#value.eps', where #nb is the generation number and #value is the fitness value. Looking at the latest generation gives an idea of the quality of the parameters.
At each iteration (generation) in 'analytic_schemes/Ref', the best chemical scheme is in 'chemistry_for_restart.xml'.
In case of QSS the relations are in: 'best_mech_QSS.h'
  • The procedure to run the GA is as follow:
  1. Run for a given number of generation
  2. Check 'GEN#nb_POP0_FIT#value.eps' to evaluate the quality of the result. The evolution of the best fitness also indicates if the optimisation reached an optimum.
  3. If more generation are needed (i.e. continue the optimisation):
    1. Move the 'analytic_schemes/Ref/chemistry_for_restart.xml' into 'outputs/mechanism' and modify the name of 'mech=' in 'conditions.cpp'
    2. Decrease the 'Allowed variation' to narrow the research parameters area
    3. Relaunch
This can be repeated up to a solution that suits you.
Then, you may rerun the trajectory only, with the optimised mechanism, in order to plot all the variables, in 'conditions.cpp':


  • Computation of the trajectories is an independant stage:
 step = "ComputeTrajectories"; 

and provides the computation of the mechanism defined in 'mech =' in 'conditions.cpp' in the current configuration. This is not a part of the reduction process.

in 'outputs/Premixed' or 'outputs/Stochastic' the name of the file is either Premixed_.dat or Trajectory_i, i : number of the inlet for the stochastic configuration.

Common Errors

If you get on your screen this kind of error :

 Cantera Error 

or

...terminate called after throwing an instance of 'Cantera::CanteraError'  what():  
***********************************************************************
CanteraError thrown by ct2ctml_string:
Error converting input file "./" to CTML.
Python command was: 'python'
The exit code was: 1

Usually, it's due to the input_ini file : Cantera isn't able to find and read your scheme.

  • To be sure of your error, check theses points first :
  1. Check every path in condition.cpp and in your Makefile
  2. Check and spell every name of folder/files you entered in the program (condition.cpp).
  3. Don't let "mech_ref" in input_ini empty, write "mech_ref = None" instead
  4. Check the path of "trajectory_ref =", if you don't want to use it, leave it empty.