Skip to content

Commit

Permalink
Merge pull request #571 from dlohmeier/fluid_lib_global
Browse files Browse the repository at this point in the history
made list of liquids and gases global in fluids.py
  • Loading branch information
SimonRubenDrauz authored Dec 19, 2023
2 parents e4895bc + c904b41 commit 6743b12
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 28 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# source: linear approximation based on CoolProp (http://www.coolprop.org/)
# slope in 1/bar, offset for linear property
-0.0024789428559189412, 0.9962776221466679
-0.0024789428559189412 0.9962776221466679
2 changes: 1 addition & 1 deletion pandapipes/properties/biomethane_treated/heat_capacity.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#source CoolProp (http://www.coolprop.org/)
# temperature in Kelvin, isobaric heat capacity in J/(kg K)
263.151976.8823234072695
263.15 1976.8823234072695
265.15 1980.6134982832095
267.15 1984.416050463013
269.15 1988.2894370033634
Expand Down

This file was deleted.

49 changes: 25 additions & 24 deletions pandapipes/properties/fluids.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@

logger = logging.getLogger(__name__)

_LIQUIDS = ["water"]
_GASES = ["air", "lgas", "hgas", "hydrogen", "methane", "biomethane_pure", "biomethane_treated"]


class Fluid(JSONSerializableClass):
"""
Expand Down Expand Up @@ -668,36 +671,34 @@ def linear_property(prop):
return FluidPropertyLinear.from_path(
os.path.join(pp_dir, "properties", fluid_name, prop + ".txt"))

liquids = ["water"]
gases = ["air", "lgas", "hgas", "hydrogen", "methane", "biomethane_pure", "biomethane_treated"]

if fluid_name == "natural_gas":
logger.error("'natural_gas' is ambigious. Please choose 'hgas' or 'lgas' "
"(high- or low calorific natural gas)")
if fluid_name not in liquids and fluid_name not in gases:
if fluid_name not in _LIQUIDS and fluid_name not in _GASES:
raise AttributeError("Fluid '%s' not found in the fluid library. It might not be "
"implemented yet." % fluid_name)

phase = "liquid" if fluid_name in liquids else "gas"

density = interextra_property("density")
viscosity = interextra_property("viscosity")
heat_capacity = interextra_property("heat_capacity")
molar_mass = constant_property("molar_mass")
der_compr = constant_property("der_compressibility")
compr = linear_property("compressibility")

if (phase == 'gas') & (fluid_name != 'air'):
lhv = constant_property("lower_heating_value")
hhv = constant_property("higher_heating_value")

return Fluid(fluid_name, phase, density=density, viscosity=viscosity,
heat_capacity=heat_capacity, molar_mass=molar_mass,
compressibility=compr, der_compressibility=der_compr, lhv=lhv, hhv=hhv)
else:
return Fluid(fluid_name, phase, density=density, viscosity=viscosity,
heat_capacity=heat_capacity, molar_mass=molar_mass, compressibility=compr,
der_compressibility=der_compr)
phase = "liquid" if fluid_name in _LIQUIDS else "gas"

properties = dict()
properties["density"] = interextra_property("density")
properties["viscosity"] = interextra_property("viscosity")
properties["heat_capacity"] = interextra_property("heat_capacity")
properties["molar_mass"] = constant_property("molar_mass")
properties["der_compressibility"] = constant_property("der_compressibility")
properties["compressibility"] = linear_property("compressibility")

if phase == 'gas':
for entry, name in [("lhv", "lower_heating_value"), ("hhv", "higher_heating_value")]:
try:
properties[entry] = constant_property(name)
except FileNotFoundError:
logger.warning(
f"Unable to find {' '.join([n.capitalize() for n in name.split('_')])} for "
f"{fluid_name}"
)

return Fluid(fluid_name, phase, **properties)


def get_fluid(net):
Expand Down

0 comments on commit 6743b12

Please sign in to comment.