using System;
using Nature;
using Nature.Data;

namespace Examples
{
    class Program
    {
        static void Main(string[] args)
        {
           ModelObject model = CkUtil.LoadModel(
                    "http://www.me.berkeley.edu/gri_mech/version30/files30/thermo30.dat",
                    "http://www.me.berkeley.edu/gri_mech/version30/files30/transport.dat"
                );

            IIdealGasMixture mixture;
            
            /*
             * Example 1: Creating a mixture consisting of a single chemical species
             * Note: The default temperature and pressure are 300 [K] and 1 [atm] respectively
             */
            mixture = model.CreateIdealGasMixture("ch4");
            Console.WriteLine(mixture.Temperature.Convert( TemperatureUnits.Celsius) );


            /*
             * Example 2: Creating a mixture consisting of equal amounts of
             * methane and oxygen
             * Note: the '?' sign assigned to the oxygen component delegates 
             * computing of the actual concentration to the GMix engine
             * Note: The default temperature and pressure are 300 [K] and 1 [atm] respectively
             */
            mixture = model.CreateIdealGasMixture(@"
                ch4 = 0.5
                o2  = ?
            ");
            Console.WriteLine(mixture.Viscosity);

            /*
             * Example 3: Creating the stoichiometrically balanced mixture of 
             * methane and oxygen (equivalence ratio = 1)
             * Note: the '?' sign delegates computing the actual concentrations of 
             * methane and oxygen to the GMix engine
             * Note: The default temperature and pressure are 300 [K] and 1 [atm] respectively
             */
            mixture = model.CreateIdealGasMixture(@"
                ch4 = ?
                o2  = ?    
                [equivalence ratio] = 1
            ");
            Console.WriteLine(mixture.ThermalConductivity.Convert( EnergyUnits.Calorie, LengthUnits.CentiMeter, TemperatureUnits.Fahrenheit, TimeUnits.MilliSecond).Value);

            /*
             * Example 4: Creating the stoichiometrically balanced mixture of 
             * propane and air (equivalence ratio = 1)
             * Note: the '?' sign delegates computing the actual concentrations of 
             * propane, air and nitrogen to the GMix engine
             * Note: The default temperature and pressure are 300 [K] and 1 [atm] respectively
             */
            mixture = model.CreateIdealGasMixture(@"
                *main
                {
                    c3h8 = ?
                    [air] = ?
                    [equivalence ratio] = 1
                }

                [air] { o2 = 0.21   n2 = ? }
            ");
            Console.WriteLine(mixture.Diffusivity);


            /*
             * Example 5: Creating the lean mixture of 
             * composite fuel and air (equivalence ratio = 0.9)
             * Note: The default temperature and pressure are 300 [K] and 1 [atm] respectively
             */
            mixture = model.CreateIdealGasMixture(@"
                *main
                {
                    [fuel] = ?
                    [air] = ?
                    [equivalence ratio] = 0.9
                }
                [fuel] { c2h6 = 0.85  c3h8 = 0.1   co = ? }
                [air]  { o2 = 0.21   n2 = ? }
            ");
            Console.WriteLine(mixture.Diffusivity.Convert( LengthUnits.CentiMeter, TimeUnits.MilliSecond).Value);

            /*
             * Example 6: Creating the ideal gas mixtures for a range of the 
             * equivalence ration (from 0.1 (lean) to 10.0 (rich))
             * between composite fuel and air
             * Note: The temperature is computed based on the given temperatures of the fuel and 
             * the air components
             */
            foreach (var mixtureDefinition in model.ParseMixtureDefinition(@"
                        *main
                        {
                            [fuel] = ?
                            [air] = ?
                            [pressure] = 1
                            [temperature] = ?
                            [equivalence ratio] = @parameter[eqratio]( from 0.1 to 10.0 step 3% )
                        }
                        [fuel] { [temperature] = 300 [pressure] = 1    c2h6 = 0.85  c3h8 = 0.1   co = ? }
                        [air]  { [temperature] = 500 [pressure] = 1    o2 = 0.21   n2 = ? }
            "))
            {
                mixture.Update(mixtureDefinition);
                Console.WriteLine(mixture.SpeedOfSound);
            }

            /*
             * Example 7: Creating the ideal gas mixtures for a range of the 
             * equivalence ration (from 0.1 (lean) to 10.0 (rich))
             * between composite fuel and air. The final Pressure/Temperature conditions
             * are reached by the shock wave compression. The shock wave intensity
             * is defined with the given mach number of 2
             */
            foreach (var mixtureDefinition in model.ParseMixtureDefinition(@"
                        *main
                        {
                            [fuel] = ?
                            [air] = ?
                            [temperature] = ?
                            [pressure] = ?
                            [mach number] = 2
                            [base temperature] = 300.0
                            [base pressure] = 1.0
                            [equivalence ratio] = @parameter[eqratio]( from 0.1 to 10.0 step 3% )
                        }
                        [fuel] { c2h6 = 0.85  c3h8 = 0.1   co = ? }
                        [air]  { o2 = 0.21   n2 = ? }
            "))
            {
                mixture.Update(mixtureDefinition);
                Console.WriteLine(mixture.SpeedOfSound.Convert( LengthUnits.KiloMeter, TimeUnits.Hour).Value);
            }

            /*
             * Example 8: Creating the ideal gas mixtures for a range of the 
             * equivalence ration (from 0.1 (lean) to 10.0 (rich))
             * between composite fuel and air. The final Pressure/Temperature conditions
             * are reached by the shock wave compression. The shock wave intensity
             * is defined with the range of the mach numbers (from 1.1 to 8.0 )
             */
            foreach (var mixtureDefinition in model.ParseMixtureDefinition(@"
                        *main
                        {
                            [fuel] = ?
                            [air] = ?
                            [temperature] = ?
                            [pressure] = ?
                            [base temperature] = 300.0
                            [base pressure] = 1.0
                            [mach number]       = @parameter[mach]( from 1.1 to 8.0 step 10% )
                            [equivalence ratio] = @parameter[eqratio]( from 0.1 to 10.0 step 3% )
                        }
                        [fuel] { c2h6 = 0.85  c3h8 = 0.1   co = ? }
                        [air]  { o2 = 0.21   n2 = ? }
            "))
            {
                mixture.Update(mixtureDefinition);
                Console.WriteLine(mixture.SpeedOfSound);
            }


            /*
             * Example 9: Creating the ideal gas mixtures for a range of the 
             * propane additions to the complex fuel (from 0% to 15%). The intensity
             * of the shock wave is determined based on the given value of the
             * temperature behind the wave front
             */
            foreach (var mixtureDefinition in model.ParseMixtureDefinition(@"
                        *main
                        {
                            [fuel] = ?
                            [air] = ?                            
                            [pressure] = ?
                            [mach number] = ?
                            [temperature] = 2500.0      ! temperature behind the shock wave                             
                            [base temperature] = 300.0  ! temperature in front of the shock wave
                            [base pressure] = 1.0       ! pressure in front of the shock wave
                            [mixture fraction] = 0.06
                        }
                        [fuel] 
                        { 
                            c2h6 = 0.85  
                            c3h8 = @parameter[xc3h8]( from 0.0 to 0.15 step 0.01 )  
                            co = ? 
                        }
                        [air]  { o2 = 0.21   n2 = ? }
            "))
            {
                mixture.Update(mixtureDefinition);
                var compositionObject = mixtureDefinition as Nature.Toolkit.GMix.CompositionObject;
                Console.WriteLine("Mach Number = {0}, Equivalence Ratio = {1}, Pressure = {2} [atm]", 
                    compositionObject.MachNumber, 
                    compositionObject.EquivalenceRatio,
                    compositionObject.Pressure[PressureUnits.Atmosphere]);
            }

            /*
             * Example 10: Specifying units
             */

            var idealGasMixture 
                = model.CreateIdealGasMixture(@"
                *main
                {
                    [units] = (Atmosphere)
                    [air] = 0.1
                    [inert] = ?
                    [pressure] = 1
                    [temperature] = ?
                }
               [air]
               {
                    [units] = (Celsius, Atmosphere, x)
                    [pressure] = 1
                    [temperature] = 20
                    n2 = 0.79
                    o2 = ?
               }
               [inert]
               {
                    [units] = (Kelvin, Atmosphere, y)
                    [pressure] = 1
                    [temperature] = 500
                    ar = 0.7
                    n2 = ?
               }
            ") as IdealGasMixture;
            var binaryDiffusivities = idealGasMixture.SpeciesDiffusivities;
        }
      }
}

Last edited Apr 21, 2013 at 11:18 AM by AlexeyE, version 1

Comments

No comments yet.