Home

ModiaMedia.jl Documentation

ModiaMedia provides thermodynamic property models for use with Modia and other Julia packages. The initial goal is to achieve a similar functionality as Modelica.Media, the standard media library for Modelica models, but with improvements based on Julia features such as multiple dispatch.

This package is under development and it is planned to provide all thermodynamic property models from Modelica.Media in this package.

Installation

This package is currently under development and is not yet registered in METADATA. Julia 1.0 is required. Installation is performed via:

julia> ]add https://github.com/ModiaSim/ModiaMedia.jl

ModiaMedia uses PyPlot for plotting (via ModiaMath.plot). If PyPlot is not available in your current Julia environment an information message is printed and all plot(..) calls are ignored.

In order that plot windows are displayed, you need to add PyPlot to your current environment via ]add PyPlot. Often this automatic installation fails and it is recommended to follow the instructions Installing PyPlot in a robust way.

Use

  using ModiaMedia

  # Define thermodynamic property model to be used
  Medium = getMedium("N2");

  # Define the operating point where the medium shall be evaluated.
  p = 1e5    # in [Pa]
  T = 300.0  # in [K]

  # Set the medium-specific thermodynamic state from p and T
  # (could be also set from p,h, or p,s, or d,T, or
  # p,T,X, or p,h,X, or p,s,X, or d,T,X)
  state = setState_pT(Medium, p, T)

  # Update a state object with new values
  setState_pT!(state, p, T)

  # Call media functions (here to compute density and specific enthalpy)
  d = density(state)
  h = specificEnthalpy(state)

  # Print computed values
  println("data for p=$p, T=$T:")
  println("density          = ", d)
  println("specificEnthalpy = ", h)

  # List the available media
  listMedia()

  # Plot the most important characteristics of the medium
  standardPlot(Medium)

This example generates the following plot:

standardPlot

Available media

The available thermodynamic property models can be listed with listMedia() resulting in:

Rownametype
1ArSingleGasNasa
2C2H2_vinylideneSingleGasNasa
3C2H4SingleGasNasa
4C2H5OHSingleGasNasa
5C2H6SingleGasNasa
6C3H6_propyleneSingleGasNasa
7C3H8SingleGasNasa
8C4H10_n_butaneSingleGasNasa
9C4H8_1_buteneSingleGasNasa
10C5H10_1_penteneSingleGasNasa
11C5H12_n_pentaneSingleGasNasa
12C6H12_1_hexeneSingleGasNasa
13C6H14_n_hexaneSingleGasNasa
14C6H6SingleGasNasa
15C7H14_1_hepteneSingleGasNasa
16C7H16_n_heptaneSingleGasNasa
17C8H10_ethylbenzSingleGasNasa
18C8H18_n_octaneSingleGasNasa
19CH3OHSingleGasNasa
20CH4SingleGasNasa
21CL2SingleGasNasa
22COSingleGasNasa
23CO2SingleGasNasa
24ConstantPropertyLiquidWaterSimpleMedium
25F2SingleGasNasa
26H2SingleGasNasa
27H2OSingleGasNasa
28HeSingleGasNasa
29MoistAirMoistAir
30N2SingleGasNasa
31N2OSingleGasNasa
32NH3SingleGasNasa
33NOSingleGasNasa
34NO2SingleGasNasa
35NeSingleGasNasa
36O2SingleGasNasa
37SO2SingleGasNasa
38SO3SingleGasNasa
39SimpleAirSimpleIdealGasMedium

Structure of package

A thermodynamic property model is a struct of the following type:

mutable struct MediumName <: ModiaMedia.AbstractMedium  # or of a subtype of AbstractMedium
    infos::ModiaMedia.FluidInfos
    fluidConstants::Vector{ModiaMedia.AbstractFluidConstants}
    fluidLimits::ModiaMedia.FluidLimits
    data  # medium specific data
end

struct FluidInfos
    mediumName::AbstractString                   # "Name of the medium";
    substanceNames::Vector{AbstractString}       # "Names of the mixture substances. Set substanceNames=[mediumName] if only one substance.";
    extraPropertiesNames::Vector{AbstractString} # "Names of the additional (extra) transported properties. Set extraPropertiesNames=fill(\"\",0) if unused"
    ThermoStates::IndependentVariables           # "Enumeration type for independent variables";
    singleState::Bool                            # "= true, if u and d are not a function of pressure";
    reducedX::Bool                               # "= true if medium contains the equation sum(X) = 1.0; set reducedX=true if only one substance (see docu for details)";
    fixedX::Bool                                 # "= true if medium contains the equation X = reference_X";
    reference_p::Float64                         # "Reference pressure of Medium: default 1 atmosphere";
    reference_T::Float64                         # "Reference temperature of Medium: default 25 deg Celsius";
    reference_X::AbstractVector                  # "Default mass fractions of medium";
    p_default::Float64                           # "Default value for pressure of medium (for initialization)";
    T_default::Float64                           # "Default value for temperature of medium (for initialization)";
    h_default::Float64                           # "Default value for specific enthalpy of medium (for initialization)";
    X_default::Vector{Float64}                   # "Default value for specific enthalpy of medium (for initialization)";
    nS::Int                                      # "Number of substances"
    nX::Int                                      # "Number of mass fractions"
    nXi::Int                                     # "Default value for mass fractions of medium (for initialization)"
    nC::Int                                      # "Number of extra (outside of standard mass-balance) transported properties"
    C_nominal::Vector{Float64}                   # "Default for the nominal values for the extra properties"
end

struct BasicFluidConstants <: AbstractFluidConstants
    iupacName::AbstractString           # "Complete IUPAC name (or common name, if non-existent)";
    casRegistryNumber::AbstractString   # "Chemical abstracts sequencing number (if it exists)";
    chemicalFormula::AbstractString     # "Chemical formula, (brutto, nomenclature according to Hill";
    structureFormula::AbstractString    # "Chemical structure formula";
    molarMass::Float64                  # "Molar mass";
end

mutable struct FluidLimits
    TMIN::Float64  # "Minimum temperature";
    TMAX::Float64  # "Maximum temperature";
    DMIN::Float64  # "Minimum density";
    DMAX::Float64  # "Maximum density";
    PMIN::Float64  # "Minimum pressure";
    PMAX::Float64  # "Maximum pressure";
    HMIN::Float64  # "Minimum enthalpy";
    HMAX::Float64  # "Maximum enthalpy";
    SMIN::Float64  # "Minimum entropy";
    SMAX::Float64  # "Maximum entropy";
end

and all instances of this struct are stored in a dictionary. This dictionary is constructed in a preprocessing step by running "ModiaMedia/dict/GenerateMediumDict.jl". This module contains code that was mostly automatically converted from Modelica.Media to Julia. The resulting dictionary is serialized and stored in "ModiaMedia/src/Media/media.julia_serializer". When package ModiaMedia is compiled, this serialized dictionary is deserialized and included in the compiled package.

Function ModiaMedia.Medium(name) returns the MediumXXX instance stored in the medium dictionary with key name.

Main Developers

License: MIT (expat)

Release Notes

The ModiaMedia package development has just started and a lot has to be improved.

Version 0.1.0-dev

A version is not yet released.