Skip to content

Commit

Permalink
create Atmosphere model to wrap ambiance calls (#84)
Browse files Browse the repository at this point in the history
  • Loading branch information
adriendelsalle committed Feb 20, 2023
1 parent e925628 commit 135f189
Show file tree
Hide file tree
Showing 8 changed files with 128 additions and 36 deletions.
12 changes: 11 additions & 1 deletion pyturbo/systems/__init__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
# Copyright (C) 2022, twiinIT
# SPDX-License-Identifier: BSD-3-Clause

from pyturbo.systems.atmosphere import Atmosphere
from pyturbo.systems.combustor import Combustor, CombustorAero
from pyturbo.systems.compressor import HPC, Booster, CompressorGeom, CompressorMftAero, Fan
from pyturbo.systems.compressor import (
HPC,
Booster,
Compressor,
CompressorGeom,
CompressorMftAero,
Fan,
)
from pyturbo.systems.inlet import Inlet, InletAero, InletGeom
from pyturbo.systems.nacelle import Nacelle, NacelleGeom, Plug, PlugGeom
from pyturbo.systems.nozzle import Nozzle, NozzleAero, NozzleGeom
Expand All @@ -19,7 +27,9 @@


__all__ = [
"Atmosphere",
"Combustor",
"Compressor",
"CombustorAero",
"CompressorAero",
"CompressorGeom",
Expand Down
3 changes: 3 additions & 0 deletions pyturbo/systems/atmosphere/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from .atmosphere import Atmosphere

__all__ = ["Atmosphere"]
50 changes: 50 additions & 0 deletions pyturbo/systems/atmosphere/atmosphere.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import ambiance
from cosapp.systems import System

from pyturbo.thermo import IdealDryAir


class Atmosphere(System):
"""Standard atmosphere model.
Inputs
------
gas: Gas, default=IdealDryAir()
gas model
altitude[m]: float, default=0.0
altitude
mach[]: float, default=0.0
Mach number
dtamb[K]: float, default=0.0
ambient temperature delta to standard atmosphere
Outputs
-------
pamb[Pa]: float
static ambient pressure
Pt[Pa]: float
total pressure
Tt[K]: float
total temperature
"""

def setup(self):
self.add_inward("gas", IdealDryAir(), desc="gas model")
self.add_inward("altitude", 0.0, unit="m", desc="altitude")
self.add_inward("mach", 0.0, unit="", desc="Mach number")
self.add_inward(
"dtamb", 0.0, unit="K", desc="ambient temperature delta to standard atmosphere"
)

self.add_outward("pamb", 101325.0, unit="Pa", desc="ambient pressure")
self.add_outward("Pt", 101325.0, unit="Pa", desc="Total pressure")
self.add_outward("Tt", 288.15, unit="K", desc="Total temperature")

def compute(self):
atm = ambiance.Atmosphere(self.altitude)
pamb = atm.pressure[0]
tamb = atm.temperature[0] + self.dtamb

self.pamb = pamb
self.Tt = self.gas.total_t(tamb, self.mach)
self.Pt = self.gas.total_p(pamb, tamb, self.Tt)
6 changes: 2 additions & 4 deletions pyturbo/systems/combustor/combustor_aero.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,8 @@ class CombustorAero(System):
Inputs
------
gas: Class, default is IdealDryAir
class provided the characteristics of gas as a simplistic air without fuel
gas.h: to get enthalpy from temperature
gas.t_from_h: to get temperature from enthapie
gas: Gas, default=IdealDryAir()
gas model
fl_in: FluidPort
fluid going into the combustor
Expand Down
12 changes: 10 additions & 2 deletions pyturbo/systems/compressor/__init__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
# Copyright (C) 2022, twiinIT
# SPDX-License-Identifier: BSD-3-Clause

from pyturbo.systems.compressor.compressor import HPC, Booster, CompressorAero, Fan
from pyturbo.systems.compressor.compressor import HPC, Booster, Compressor, CompressorAero, Fan
from pyturbo.systems.compressor.compressor_geom import CompressorGeom
from pyturbo.systems.compressor.compressor_mft_aero import CompressorMftAero

__all__ = ["CompressorAero", "HPC", "Booster", "Fan", "CompressorGeom", "CompressorMftAero"]
__all__ = [
"Compressor",
"CompressorAero",
"HPC",
"Booster",
"Fan",
"CompressorGeom",
"CompressorMftAero",
]
49 changes: 25 additions & 24 deletions pyturbo/systems/turbofan/turbofan.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
from typing import Dict

import numpy as np
from ambiance import Atmosphere
from cosapp.systems import System
from OCC.Core.TopoDS import TopoDS_Shape

from pyturbo.systems.atmosphere import Atmosphere
from pyturbo.systems.fan_module import FanModule
from pyturbo.systems.gas_generator import GasGenerator
from pyturbo.systems.inlet import Inlet
Expand All @@ -24,6 +24,8 @@ class Turbofan(System, JupyterViewable):
Sub-systems
-----------
atmosphere: Atmosphere
evaluate Pt and Tt from altitude, mach and dtamb
inlet: Inlet
inlet before the fan
fanmodule: FanModule
Expand All @@ -50,11 +52,12 @@ class Turbofan(System, JupyterViewable):
Inputs
------
fl_in: FluidPort
inlet fluid as seen by engine
pamb[Pa]: float
ambiant pressure
altitude[m]: float
engine altitude
mach[-]: float
engine speed
dtamb[K]: float
atmosphere dtamb
fan_diameter[m]: float
diameter of the fan
Expand All @@ -64,6 +67,8 @@ class Turbofan(System, JupyterViewable):
Outputs
-------
pamb[Pa]: float
ambiant pressure
ipps_weight[kg]: float
ipps weight
thrust[N]: float
Expand All @@ -86,22 +91,22 @@ class Turbofan(System, JupyterViewable):
"""

def setup(self):
# atmosphere
self.add_child(Atmosphere("atmosphere"), pulling=["altitude", "mach", "dtamb", "pamb"])

# physics
self.add_child(TurbofanGeom("geom"), pulling=["fan_diameter", "frd_mount", "aft_mount"])

# component
self.add_child(Inlet("inlet"), pulling=["fl_in", "pamb"])
self.add_child(Inlet("inlet"))
self.add_child(FanModule("fan_module"), pulling={"bpr": "bpr", "N": "N1"})
self.add_child(FanDuct("fan_duct"))
self.add_child(GasGenerator("core"), pulling={"fuel_W": "fuel_W", "N": "N2"})
self.add_child(Channel("tcf"))
self.add_child(LPT("turbine"))
self.add_child(Channel("trf"))
self.add_child(Nozzle("primary_nozzle"), pulling=["pamb"])
self.add_child(
Nozzle("secondary_nozzle"),
pulling=["pamb"],
)
self.add_child(Nozzle("primary_nozzle"))
self.add_child(Nozzle("secondary_nozzle"))
self.add_child(Nacelle("nacelle"))
self.add_child(Plug("plug"))
self.add_child(CoreCowl("core_cowl"))
Expand All @@ -113,10 +118,16 @@ def setup(self):
)
self.add_child(TurbofanWeight("weight"), pulling=["ipps_weight"])

# atmosphere connectors
self.connect(self.atmosphere.outwards, self.inlet.inwards, "pamb")
self.connect(self.atmosphere.outwards, self.primary_nozzle.inwards, "pamb")
self.connect(self.atmosphere.outwards, self.secondary_nozzle.inwards, "pamb")

# shaft connectors
self.connect(self.turbine.sh_out, self.fan_module.sh_in)

# fluid connectors
self.connect(self.atmosphere.outwards, self.inlet.fl_in, ["Pt", "Tt"])
self.connect(self.inlet.fl_out, self.fan_module.fl_in)
self.connect(self.fan_module.fl_bypass, self.fan_duct.fl_in)
self.connect(self.fan_duct.fl_out, self.secondary_nozzle.fl_in)
Expand Down Expand Up @@ -188,7 +199,7 @@ def setup(self):
self.connect(self.geom, self.weight, {"engine_length": "length"})

# solver
self.add_unknown("fl_in.W")
self.add_unknown("inlet.fl_in.W")

# default value : CFM56-7

Expand Down Expand Up @@ -217,7 +228,7 @@ def setup(self):
self.geom.sec_nozzle_area_ratio = 0.6

# init unknowns
self.fl_in.W = 300.0
self.inlet.fl_in.W = 300.0
self.fan_module.splitter_shaft.power_fractions = np.r_[0.8]
self.fan_module.splitter_fluid.fluid_fractions = np.r_[0.8]

Expand Down Expand Up @@ -309,13 +320,3 @@ def _to_occt(self) -> Dict[str, TopoDS_Shape]:
plug=self.plug.geom._to_occt(),
core_cowl=self.core_cowl._to_occt(),
)

def init_environment(self, alt, mach, dtamb):
gas = IdealDryAir()
atm = Atmosphere(alt)
pamb = atm.pressure[0]
tamb = atm.temperature[0] + dtamb

self.pamb = pamb
self.fl_in.Tt = gas.total_t(tamb, mach)
self.fl_in.Pt = gas.total_p(pamb, tamb, self.fl_in.Tt)
22 changes: 22 additions & 0 deletions tests/test_atmosphere.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import pytest
from cosapp.drivers import NonLinearSolver

from pyturbo.systems import Atmosphere


class TestAtmosphere:
"""Tests for the Atmosphere model."""

atm = Atmosphere("atm")

def test_sea_level_static(self):
atm = self.atm

atm.altitude = 0.0
atm.mach = 0.0
atm.dtamb = 0.0
atm.run_drivers()

assert atm.Pt == 101325.0
assert atm.Tt == 288.15
assert atm.pamb == 101325.0
10 changes: 5 additions & 5 deletions tests/test_turbofan.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ def test_system_setup(self):
# default constructor
sys = self.sys

data_input = ["fl_in"]
data_input = []
data_output = []
data_inward = ["fan_diameter", "pamb", "fuel_W"]
data_outward = ["thrust", "bpr", "opr", "sfc"]
data_inward = ["fan_diameter", "fuel_W", "altitude", "mach", "dtamb"]
data_outward = ["thrust", "pamb", "bpr", "opr", "sfc"]

for data in data_input:
assert data in sys.inputs
Expand All @@ -30,7 +30,7 @@ def test_system_setup(self):
def test_run_once(self):
sys = self.sys

sys.fl_in.W = 300.0
sys.inlet.fl_in.W = 300.0
sys.fuel_W = 1.0
sys.fan_module.splitter_fluid.fluid_fractions[0] = 0.8

Expand All @@ -47,7 +47,7 @@ def test_run_solver(self):
sys.pamb = 1e5

sys.fan_diameter = 1.8
run.add_unknown("fl_in.W")
run.add_unknown("inlet.fl_in.W")

sys.run_drivers()

Expand Down

0 comments on commit 135f189

Please sign in to comment.