# RocketCEA Functions

## CEA_Obj Functions

RocketCEA wraps the NASA FORTRAN CEA code and provides some useful tools.

RocketCEA makes direct calls to the FORTRAN CEA code in "rocket" mode to calculate Isp, Cstar, Tcham etc. and provides tools to help determine useful mixture ratio range, optimum MR and more.

See the NASA CEA code at: https://www.grc.nasa.gov/WWW/CEAWeb/

RocketCEA Copyright (C) 2005-2018 Applied Python

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.

class `rocketcea.cea_obj.``CEA_Obj`(propName='', oxName='', fuelName='', useFastLookup=0, makeOutput=0)

  RocketCEA wraps the NASA FORTRAN CEA code to calculate Isp, cstar, and Tcomb

  `estimate_Ambient_Isp`(Pc=100.0, MR=1.0, eps=40.0, Pamb=14.7, frozen=0, frozenAtThroat=0)

        #: return the tuple (IspAmb, mode)
        #: Use throat gam to run ideal separation calculations.
        #: mode is a string containing, UnderExpanded, OverExpanded, or Separated
        #: Pamb ambient pressure (e.g. sea level=14.7 psia)
        #: MR is only used for ox/fuel combos.
        #: frozen flag, 0=equilibrium, 1=frozen
        #: frozenAtThroat flag, 0=frozen in chamber, 1=frozen at throat

  `getFrozen_IvacCstrTc`(Pc=100.0, MR=1.0, eps=40.0, frozenAtThroat=0)

        #: Return the tuple (IspFrozen, Cstar, Tcomb).
        #: MR is only used for ox/fuel combos.
        #: frozenAtThroat flag, 0=frozen in chamber, 1=frozen at throat

  `getFrozen_PambCf`(Pamb=0.0, Pc=100.0, MR=1.0, eps=40.0, frozenAtThroat=0)

        #: Return the Thrust Coefficient (CF) for frozen chemistry and ambient pressure
        #: Pamb ambient pressure (e.g. sea level=14.7 psia)
        #: MR is only used for ox/fuel combos.
        #: frozenAtThroat flag, 0=frozen in chamber, 1=frozen at throat

  `getMRforER`(ERphi=None, ERr=None)

        #: return the value of mixture ratio that applies to the input equivalence ratio.
        #: Can be ERr or ERphi (valence basis and mass basis respectively)

  `get_Chamber_Cp`(Pc=100.0, MR=1.0, eps=40.0, frozen=0)

        #: Return the heat capacity in the chamber.
        #: MR is only used for ox/fuel combos.
        #: frozen flag (0=equilibrium, 1=frozen)

  `get_Chamber_Density`(Pc=100.0, MR=1.0, eps=40.0)

        #: Return the density in the chamber.
        #: MR is only used for ox/fuel combos.

  `get_Chamber_H`(Pc=100.0, MR=1.0, eps=40.0)

        #: Return the enthalpy in the chamber.
        #: MR is only used for ox/fuel combos.

  `get_Chamber_MolWt_gamma`(Pc=100.0, MR=1.0, eps=40.0)

        #: return the tuple (mw, gam) for the chamber
        #: MR is only used for ox/fuel combos.

  `get_Chamber_SonicVel`(Pc=100.0, MR=1.0, eps=40.0)

        #: Return the sonic velocity in the chamber.
        #: MR is only used for ox/fuel combos.

  `get_Chamber_Transport`(Pc=100.0, MR=1.0, eps=40.0, frozen=0)

        #: Return a list of heat capacity, viscosity, thermal conductivity and Prandtl number
        #: in the chamber. (units are default printout units)
        #: MR is only used for ox/fuel combos.
        #: eps has no effect on chamber properties
        #: frozen flag (0=equilibrium, 1=frozen)

  `get_Cstar`(Pc=100.0, MR=1.0)

        #: return Cstar.
        #: MR is only used for ox/fuel combos.

  `get_Densities`(Pc=100.0, MR=1.0, eps=40.0)

        #: Return a list of densities at the chamber, throat and exit.
        #: MR is only used for ox/fuel combos.

  `get_Enthalpies`(Pc=100.0, MR=1.0, eps=40.0)

        #: Return a list of enthalpies at the chamber, throat and exit.
        #: MR is only used for ox/fuel combos.

  `get_Exit_Transport`(Pc=100.0, MR=1.0, eps=40.0, frozen=0)

        #: Return a list of heat capacity, viscosity, thermal conductivity and Prandtl number
        #: at the exit. (units are default printout units)
        #: MR is only used for ox/fuel combos.
        #: eps is nozzle area ratio
        #: frozen flag (0=equilibrium, 1=frozen)

  `get_HeatCapacities`(Pc=100.0, MR=1.0, eps=40.0, frozen=0)

        #: Return a list of heat capacities at the chamber, throat and exit.
        #: MR is only used for ox/fuel combos.
        #: frozen flag (0=equilibrium, 1=frozen)

  `get_Isp`(Pc=100.0, MR=1.0, eps=40.0)

        #: return IspVac.
        #: MR is only used for ox/fuel combos.

  `get_IvacCstrTc`(Pc=100.0, MR=1.0, eps=40.0)

        #: Return the tuple (IspVac, Cstar, Tcomb).
        #: MR is only used for ox/fuel combos.

  `get_IvacCstrTc_ChmMwGam`(Pc=100.0, MR=1.0, eps=40.0)

        #: return the tuple (IspVac, Cstar, Tcomb, mw, gam)
        #: mw and gam apply to chamber.
        #: MR is only used for ox/fuel combos.

  `get_IvacCstrTc_ThtMwGam`(Pc=100.0, MR=1.0, eps=40.0)

        #: return the tuple (IspVac, Cstar, Tcomb, mw, gam)
        #: mw and gam apply to throat.
        #: MR is only used for ox/fuel combos.

  `get_IvacCstrTc_exitMwGam`(Pc=100.0, MR=1.0, eps=40.0)

        #: return the tuple (IspVac, Cstar, Tcomb, mw, gam)
        #: mw and gam apply to nozzle exit.
        #: MR is only used for ox/fuel combos.

  `get_MachNumber`(Pc=100.0, MR=1.0, eps=40.0)

        #: return nozzle exit mach number.
        #: MR is only used for ox/fuel combos.

  `get_PambCf`(Pamb=14.7, Pc=100.0, MR=1.0, eps=40.0)

        #: Return the Thrust Coefficient (CF) for equilibrium chemistry and ambient pressure
        #: Pamb ambient pressure (e.g. sea level=14.7 psia)
        #: MR is only used for ox/fuel combos.

  `get_PcOvPe`(Pc=100.0, MR=1.0, eps=40.0)

        #: return Pc / Pexit.
        #: MR is only used for ox/fuel combos.

  `get_SonicVelocities`(Pc=100.0, MR=1.0, eps=40.0)

        #: Return a list of sonic velocities at the chamber, throat and exit.
        #: MR is only used for ox/fuel combos.

  `get_SpeciesMassFractions`(Pc=100.0, MR=1.0, eps=40.0, frozen=0, frozenAtThroat=0)

        #: Returns species mass fractions at the chamber, throat and exit.
        #: MR is only used for ox/fuel combos.
        #: frozen flag (0=equilibrium, 1=frozen)
        #: frozenAtThroat flag, 0=frozen in chamber, 1=frozen at throat
        #: Returns 2 dictionaries
        #: molWtD dictionary: index=species: value=molecular weight
        #: massFracD dictionary: index=species: value=[massfrac_chm, massfrac_tht, massfrac_exit]

  `get_SpeciesMoleFractions`(Pc=100.0, MR=1.0, eps=40.0, frozen=0, frozenAtThroat=0)

        #: Returns species mole fractions at the chamber, throat and exit.
        #: MR is only used for ox/fuel combos.
        #: frozen flag (0=equilibrium, 1=frozen)
        #: frozenAtThroat flag, 0=frozen in chamber, 1=frozen at throat
        #: Returns 2 dictionaries
        #: molWtD dictionary: index=species: value=molecular weight
        #: moleFracD dictionary: index=species: value=[molefrac_chm, molefrac_tht, molefrac_exit]

  `get_Tcomb`(Pc=100.0, MR=1.0)

        #: return Tcomb.
        #: MR is only used for ox/fuel combos.

  `get_Temperatures`(Pc=100.0, MR=1.0, eps=40.0, frozen=0, frozenAtThroat=0)

        #: Return a list of temperatures at the chamber, throat and exit.
        #: (Note frozen flag determins whether Texit is equilibrium or Frozen temperature)
        #: MR is only used for ox/fuel combos.
        #: frozen flag (0=equilibrium, 1=frozen)
        #: frozenAtThroat flag, 0=frozen in chamber, 1=frozen at throat

  `get_Throat_Isp`(Pc=100.0, MR=1.0)

        #: Return the IspVac for the throat.
        #: MR is only used for ox/fuel combos.

  `get_Throat_MolWt_gamma`(Pc=100.0, MR=1.0, eps=40.0)

        #: return the tuple (mw, gam) for the throat
        #: MR is only used for ox/fuel combos.

  `get_Throat_PcOvPe`(Pc=100.0, MR=1.0)

        #: return Pc/Pexit at throat.
        #: MR is only used for ox/fuel combos.

  `get_Throat_Transport`(Pc=100.0, MR=1.0, eps=40.0, frozen=0)

        #: Return a list of heat capacity, viscosity, thermal conductivity and Prandtl number
        #: in the throat. (units are default printout units)
        #: MR is only used for ox/fuel combos.
        #: eps has no effect on throat properties
        #: frozen flag (0=equilibrium, 1=frozen)

  `get_description`()

    Return a string description of the propellant(s). e.g. 'LOX / MMH'

  `get_eps_at_PcOvPe`(Pc=100.0, MR=1.0, PcOvPe=1000.0)

        #: Given a Pc/Pexit, return the Area Ratio that applies.
        #: MR is only used for ox/fuel combos.

  `get_eqratio`(Pc=100.0, MR=1.0, eps=40.0)

    Returns BOTH ERr and ERphi (valence basis and mass basis respectively)

  `get_exit_MolWt_gamma`(Pc=100.0, MR=1.0, eps=40.0)

        #: return the tuple (mw, gam) for the nozzle exit
        #: MR is only used for ox/fuel combos.

  `get_full_cea_output`(Pc=100.0, MR=1.0, eps=40.0, subar=None, PcOvPe=None, frozen=0, frozenAtThroat=0, short_output=0, show_transport=1, pc_units='psia', output='calories')

    Get the full output file created by CEA. Return as a string. #: pc_units = 'psia', 'bar', 'atm', 'mmh'(mm of mercury) #: frozen flag (0=equilibrium, 1=frozen) #: frozenAtThroat flag, 0=frozen in chamber, 1=frozen at throat

  `setupCards`(Pc=100.0, MR=1.0, eps=40.0, subar=None, PcOvPe=None, frozen=0, ERphi=None, ERr=None, frozenAtThroat=0, short_output=0, show_transport=0, pc_units='psia', output='calories')

    Set up card deck and call CEA FORTRAN code.:

        #: if PcOvPe has a value, use it instead of eps to run case
        #: ERphi = Equivalence ratios in terms of fuel-to-oxidant weight ratios.
        #: ERr = Chemical equivalence ratios in terms of valences.
        #: pc_units = 'psia', 'bar', 'atm', 'mmh'(mm of mercury)
        #: frozen flag (0=equilibrium, 1=frozen)
        #: frozenAtThroat flag, 0=frozen in chamber, 1=frozen at throat

`rocketcea.cea_obj.``add_new_card`(name, card_str, propD)

      #: Add or Replace a propellant.
      #: name = string name (e.g. oxName, fuelName or propName)
      #: card_str = a single multiline string containing CEA input card for new propellant
      #: propD = dictionary to receive new propellant (e.g. oxCards, fuelCards or propCards)

`rocketcea.cea_obj.``add_new_fuel`(name, card_str)

  Add a new Fuel Card

`rocketcea.cea_obj.``add_new_oxidizer`(name, card_str)

  Add a new Oxidizer Card

`rocketcea.cea_obj.``add_new_propellant`(name, card_str)

  Add a new Propellant Card

`rocketcea.cea_obj.``getCacheDict`()

  Returns internal cache of previously called calculations.

`rocketcea.cea_obj.``print_py_cea_vars`()

  Print all the interface variables to the FORTRAN pyd file. Normally used for debugging or verifying FORTRAN internal values.

`rocketcea.cea_obj.``set_py_cea_line`(N, line)

  make sure that trailing blanks are on added lines

## CEA_Obj With Units

class `rocketcea.cea_obj_w_units.``CEA_Obj`(propName='', oxName='', fuelName='', useFastLookup=0, makeOutput=0, isp_units='sec', cstar_units='ft/sec', pressure_units='psia', temperature_units='degR', sonic_velocity_units='ft/sec', enthalpy_units='BTU/lbm', density_units='lbm/cuft', specific_heat_units='BTU/lbm degR', viscosity_units='millipoise', thermal_cond_units='mcal/cm-K-s')

  RocketCEA wraps the NASA FORTRAN CEA code to calculate Isp, cstar, and Tcomb

  This object wraps the English unit version of CEA_Obj to enable desired user units.

  `__init__`(propName='', oxName='', fuelName='', useFastLookup=0, makeOutput=0, isp_units='sec', cstar_units='ft/sec', pressure_units='psia', temperature_units='degR', sonic_velocity_units='ft/sec', enthalpy_units='BTU/lbm', density_units='lbm/cuft', specific_heat_units='BTU/lbm degR', viscosity_units='millipoise', thermal_cond_units='mcal/cm-K-s')

        #: RocketCEA wraps the NASA FORTRAN CEA code to calculate Isp, cstar, and Tcomb
        #: This object wraps the English unit version of CEA_Obj to enable desired user units.
        #: Same as CEA_Obj with standard units except, input and output units can be specified.
        #:  parameter             default             options
        #: isp_units            = 'sec',         # N-s/kg, m/s, km/s
        #: cstar_units          = 'ft/sec',      # m/s
        #: pressure_units       = 'psia',        # MPa, KPa, Bar, Atm, Torr
        #: temperature_units    = 'degR',        # K, C, F
        #: sonic_velocity_units = 'ft/sec',      # m/s
        #: enthalpy_units       = 'BTU/lbm',     # J/g, kJ/kg, J/kg, kcal/kg, cal/g
        #: density_units        = 'lbm/cuft',    # g/cc, sg, kg/m^3
        #: specific_heat_units  = 'BTU/lbm degR' # kJ/kg-K, cal/g-C, J/kg-K (# note: cal/g K == BTU/lbm degR)
        #: viscosity_units      = 'millipoise'   # lbf-sec/sqin, lbf-sec/sqft, lbm/ft-sec, poise, centipoise
        #: thermal_cond_units   = 'mcal/cm-K-s'  # millical/cm-degK-sec, BTU/hr-ft-degF, BTU/s-in-degF, cal/s-cm-degC, W/cm-degC

## User Units

`rocketcea.units.``add_default_unit`(name='psia', akaL=None)

  Initialize unitsConvFactD for various default units.

`rocketcea.units.``add_user_units`(default_units, user_units, multiplier, offset=0)

  Add new units to dictionary of default_units.

`rocketcea.units.``get_conv_factor`(default_units, user_units)

  Get multiplier and offset for user_units.

class `rocketcea.units.``Units`(default_units='psia', user_units='MPa', user_over_default=0.0068947572, user_offset=0)
  `dval_to_uval`(def_value)

    Given a value in RockeCEA default units, return value in user units.

  `show_dval_to_uval`(def_value)

    Given a value in RockeCEA default units, print conversion user units.

  `show_uval_to_dval`(user_value)

    Given a value in user units, print conversion to RockeCEA default units.

  `uval_to_dval`(user_value)

    Given a value in user units, return a value in RockeCEA default units.

## Blend Functions

Handle propellant blends. Make new input cards for various ox and fuel blends.

`rocketcea.blends.``addFLOX_Blend`(oxName, cea_deck)

  Add new add FLOX oxidizer to the CEA_Obj.cea_deck FLOX70, for example, represents 70% F2 and 30% LOX

`rocketcea.blends.``addHYD_AmmoniaBlend`(name, cea_deck)

  Add new N2H4 + undissociated Ammonia (UA) Blend to the CEA_Obj.cea_deck. Use name like "HYD30" to represent hydrazine with 30% dissociated ammonia.

`rocketcea.blends.``addMMH_N2H4_Blend`(fuelName, cea_deck)

  Add new MMH + N2H4 Blend to the CEA_Obj.cea_deck Use name like M10 to represent 10% MMH and 90% N2H4

`rocketcea.blends.``addMON_Blend`(oxName, cea_deck)

  Add new MON oxidizer Blend to the CEA_Obj.cea_deck MON15 and MON25 are in standard deck, however can make MON20, MON30 etc. "on-the-fly"

`rocketcea.blends.``addPeroxideBlend`(oxName, cea_deck)

  Add new Peroxide Blend to the CEA_Obj.cea_deck. Use name like Peroxide95 to represent 95% Peroxide and 5% water.

`rocketcea.blends.``all_in_dict`(nameL, D)

  If all members of nameL are keys in D, then return True, otherwise False.

`rocketcea.blends.``getFloatTokenFromCards`(cardL, token='t(k)')

  Get the float value of the desired token. (e.g. 't(k)' )

`rocketcea.blends.``getFuelHfCalPerMole`(name)

  Get the fuel float value of the reference temperature 'h,cal'

`rocketcea.blends.``getFuelRefTempDegK`(name)

  Get the fuel float value of the reference temperature 't(k)'

`rocketcea.blends.``getOxHfCalPerMole`(name)

  Get the ox float value of the reference temperature 'h,cal'

`rocketcea.blends.``getOxRefTempDegK`(name)

  Get the oxidizer float value of the reference temperature 't(k)'

`rocketcea.blends.``getPropHfCalPerMole`(name)

  Get the propellant float value of the reference temperature 'h,cal'

`rocketcea.blends.``getPropRefTempDegK`(name)

  Get the propellant float value of the reference temperature 't(k)'

`rocketcea.blends.``get_propellant_name`(Name=None, PcentL=None)

      #: Return the name of the blend defined by "Name". (string or list of strings)
      #: Might be a defined blend such as MON25 or FLOX80.
      #: Might be in the library such as "MMH" or "CLF5"
      #: Might need to create a long name from percentages Name=["N2H4","NH3"], PcentL=[90,10]
      #:   (if new name, add card to oxCards, fuelCards or propCards)

`rocketcea.blends.``giveCardMassPercent`(card, fuelPcent)

  set the value of mass percentage (wt%) on propellant card.

`rocketcea.blends.``giveCardNewHfAndTref`(card, newHfCalPerMole, newTrefDegR)

  Change the values of "h,cal" and "t(k)" on propellant cards.

`rocketcea.blends.``isAPeroxide_Blend`(name)

  check if name is for a blend of peroxide and water. Peroxide98 and Peroxide90 are in standard deck, however can make Peroxide95 etc. "on-the-fly"

`rocketcea.blends.``isAnMMH_N2H4_Blend`(name)

  check if name is for a blend of MMH + N2H4 M20 is in standard deck, however can make M10, M30 etc. "on-the-fly"

`rocketcea.blends.``isFLOX_Ox_Blend`(name)

  check for FLOX oxidizer (e.g. FLOX70 or FLOX82.5) No FLOX blends are in standard deck, however can make FLOX70, FLOX82.5 etc. "on-the-fly"

`rocketcea.blends.``isMON_Ox_Blend`(name)

  check for MON oxidizer (MON1 to MON40) 48% is theoretical max MON15 and MON25 are in standard deck, however can make MON20, MON30 etc. "on-the-fly"

`rocketcea.blends.``is_HYD_Ammonia_Blend`(name)

  check if name is for a blend of N2H4 and undissociated Ammonia (UA) HYD40 is in standard deck, however can make HYD30, HYD50 etc. "on-the-fly"

`rocketcea.blends.``makeCardForNewTemperature`(ceaName='CH4', newTdegR=536.0, CpAve=0.791, MolWt=16.04)

  Create a new propellant card that reflects a change in temperature of the propellant from the original reference temperature on the original card to the new input value of temperature, newTdegR.

  CpAve = BTU/lbm degR

`rocketcea.blends.``newFuelBlend`(fuelL=None, fuelPcentL=None)

  create fuel blends such as M20 given the fuel names and weight percentages. e.g. fuelL=["MMH","N2H4"], fuelPcentL=[20,80]

`rocketcea.blends.``newFuelWithNewState`(name, newHfCalPerMole, newTrefDegR)

  Take name as it exists in fuelCards and change Hf and Tref to be the input values newHfCalPerMole and newTrefDegR

`rocketcea.blends.``newOxBlend`(oxL=None, oxPcentL=None)

  create ox blends such as MON25 given the oxidizer names and weight percentages. e.g. oxL=["N2O4","N2O3"], oxPcentL=[36.67,63.33]

`rocketcea.blends.``newOxWithNewState`(name, newHfCalPerMole, newTrefDegR)

  Take name as it exists in oxCards and change Hf and Tref to be the input values newHfCalPerMole and newTrefDegR

`rocketcea.blends.``newPropWithNewState`(cardDict, name, newHfCalPerMole, newTrefDegR)

  Take name as it exists in fuelCards or oxCards and change Hf and Tref to be the input values newHfCalPerMole and newTrefDegR

`rocketcea.blends.``renamePropIfNewHfOrTrefInName`(cardDict, name)

  Look for "h,cal OR "t(k)"" in name. If present, then create new modified name and create new card in cardDict if necessary

  for example to tweak LH2 run might look like: "LH2 h,cal=-2155.0 t(k)=21.0"

`rocketcea.blends.``tightenUpEquals`(card)

  make sure there's no spaces around equal signs.

`rocketcea.blends.``turnCardsIntoTokenL`(cardL)

  turn the card list into one long list of tokens