This project is read-only.

What is Nature

Nature is a lightweight .NET library for computing thermo chemical properties of individual chemical species and complex multi-component mixtures. In its core, the library takes away the concern of utilizing extensive sets of parameters required when working with realistic physical models, thus resulting in tremendous reduction of the efforts required for building numerical simulators.

The following demo program shows a basic example of the library usage (for the Powershell examples see Using Nature from within Powershell)

using System;
using System.Linq;
using Nature;
using Nature.Data;

namespace Examples
    public class GEqu
        public static void Exec()
            // Step 1: Create the model setup object
            ModelSetupInfo setupInfo = new ModelSetupInfo()
                // Reduce the model by including only the following species
                //     n2, ch4, o2, co2, co, n2,  h2o, h, oh
                ChemicalSpeciesFilter = (species) =>
                    (new string[] { "n2", "c3h8", "c2h4", "h2", "o2", "co2", "co", "n2", "h2o", "h", "oh" })

            // Step 2:  Load the reduced GRI thermochemical model
            ModelObject model = CkUtil.LoadModel(

            // Step 3:  Define the collection of mixture initial states
            var initialCompositions = model.ParseMixtureDefinition(@"
                    [fuel]   = ?   
                    [air] = ?   
                    [temperature] = ?
                    [pressure] = 1 !atm
                    [equivalence ratio] = @parameter[er](from 0.8 till 1.2 step 1%)
                    c3h8 = 0.1
                    c2h4 = 0.3
                    h2 = ?
                    [temperature] = 300 !K
                    [pressure]    = 1 !atm
                    [temperature] = 1100 !K
                    [pressure]    = 1 !atm
                    o2 = 0.21
                    n2 = ?

            // Step 4:  Define the conversion to the equilibrium state
            Func<IMixtureDefinition, IdealGasMixture> equilibrate =
                (mixtureDefinition) => 
                    var mixture = model.CreateIdealGasMixture(mixtureDefinition);
                    return mixture;

            // Step 5:  Get the computed equilibrium points
            var listOfPoints =
                (from composition in initialCompositions
                let equilibriumMixture = equilibrate(composition)
                let equivalenceRatio = composition.EquivalenceRatio.Value       
                let mixtureFraction = composition.MixtureFraction.Value
                select new 
                    EquilibriumTemperature = equilibriumMixture.Temperature,
                    EquivalenceRatio = equivalenceRatio,
                    MixtureFraction = mixtureFraction,
                    Mixture = equilibriumMixture

            // Step 6:  Get the point with the highest temperature
            var maxTemperaturePoint = listOfPoints
                .OrderByDescending(i => i.EquilibriumTemperature)

            // Step 7:  Print the result 
            Console.WriteLine("Maximum temperature of {0}[K] is reached at \r\nthe equivalence ratio of {1} [~] (the mixture fraction of {2} [~])"



Using Nature in practice means
- importing the required data
- accessing the computed values via the class properties
The following describes both steps and the two main classes involved, namely ModelObject and IdealGasMixture.

Importing data

The key type representing the physical/thermo-chemical model in Nature is the ModelObject class located in the Nature namespace. This class encapsulates a number of settings defining the model aspects as well as the set of the required parameters.
Using Nature in the code starts from building an instance of this class from a set of input data and, if necessary, from additional configuration settings.
In its core Nature is designed to be extendable towards supporting any kind of data source whether it is Web Service, Relational Database or a well formed markup language. However, due to its wide acceptance, the CHEMKIN data format is chosen to be the default type of data import used with Nature.
A new instance of the ModelObject class constructed from a given CHEMKIN formatted data, can be obtained using the CkUtil utility class found in the Nature.Data namespace. The following example demonstrates creating the ModelObject instance using the thermodynamic and molecular transport data URIs of the GRI3 model.
ModelObject model = CkUtil.LoadModel(
Note that if the model files are stored on the local file system, the file paths can be supplied instead. When required, the model data can be reduced with the lambda expression operators as shown below
string[] speciesIDs = new string[] { "ch4", "o2", "co2", "h2o" };
ModelSetupInfo setupInfo = new ModelSetupInfo()
   ChemicalSpeciesFilter = (species) => speciesIDs.Contains(species.SpeciesID)
ModelObject model = CkUtil.LoadModel(setupInfo,
In this example the GRI3 model is filtered such that only the specified four chemical species are included into the materialized ModelObject.
Once an instance of the ModelObject is available, the actual computing can be started.

Computing thermo-chemical properties

The second most important type in Nature is IdealGasMixture. Objects of this type represent a particular state of the ideal gas mixture. In Nature the state is not limited to only the thermodynamic characteristics like temperature, pressure, molar concentration etc., but it includes all other (secondary) gas properties such as thermodynamic potentials (e.g. entropy, enthalpy etc), molecular transport properties (e.g. individual species and mixture averaged viscosities, diffusivities etc.) and more. The following example demonstrates creating a new object of the IdealGasMixture type by calling the CreateIdealGasMixture method of the ModelObject class.
IdealGasMixture mixture = model.CreateIdealGasMixture(@"
   ch4 = 0.5
    o2  = ?
Here the gas composition (50% if methane and 50% of oxygen at the default temperature and pressure of 300K and 1atm respectively) is defined with the string given in the GMix format (for more information see examples of creating the IdealGasMixture).
Once the ideal gas mixture object is obtained, any property of the mixture can be obtained by simply accessing the corresponding C# property. For example the following code
double diffusivity = mixture.Diffusivity;
double speedOfSound = mixture.SpeedOfSound;
gets computed values of the mixture diffusivity and the speed of sound. Note that there is no need to call a method computing these properties. The get property accessor takes care that the requested value will be computed if it is not yet. The computing is triggered only once on the first call to the C# property. All the following accesses will simple return the cached result.
By employing the Lazy Loading pattern in Nature, the library API is simplified such that there is no learning curve involved to start using Nature in practical modeling.

Last edited Nov 8, 2013 at 6:50 PM by AlexeyE, version 4


No comments yet.