Skip to content

Commit c3858e2

Browse files
committed
Mv _Scales to dimensions.Scales
1 parent be0c3dc commit c3858e2

File tree

3 files changed

+101
-91
lines changed

3 files changed

+101
-91
lines changed

stagpy/dimensions.py

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
from __future__ import annotations
2+
3+
import typing
4+
from functools import cached_property
5+
6+
if typing.TYPE_CHECKING:
7+
from .parfile import StagyyPar
8+
from .stagyydata import StagyyData
9+
10+
11+
class Scales:
12+
"""Dimensional scales.
13+
14+
Args:
15+
sdat: the StagyyData instance owning the :class:`_Scales` instance.
16+
"""
17+
18+
def __init__(self, sdat: StagyyData):
19+
self._sdat = sdat
20+
21+
@property
22+
def par(self) -> StagyyPar:
23+
return self._sdat.par
24+
25+
@cached_property
26+
def length(self) -> float:
27+
"""Length in m."""
28+
thick = self.par.get("geometry", "d_dimensional", 2890e3)
29+
if self.par.get("boundaries", "air_layer", False):
30+
thick += self.par.nml["boundaries"]["air_thickness"]
31+
return thick
32+
33+
@property
34+
def temperature(self) -> float:
35+
"""Temperature in K."""
36+
return self.par.nml["refstate"]["deltaT_dimensional"]
37+
38+
@property
39+
def density(self) -> float:
40+
"""Density in kg/m3."""
41+
return self.par.nml["refstate"]["dens_dimensional"]
42+
43+
@property
44+
def th_cond(self) -> float:
45+
"""Thermal conductivity in W/(m.K)."""
46+
return self.par.nml["refstate"]["tcond_dimensional"]
47+
48+
@property
49+
def sp_heat(self) -> float:
50+
"""Specific heat capacity in J/(kg.K)."""
51+
return self.par.nml["refstate"]["Cp_dimensional"]
52+
53+
@property
54+
def dyn_visc(self) -> float:
55+
"""Dynamic viscosity in Pa.s."""
56+
return self.par.nml["viscosity"]["eta0"]
57+
58+
@property
59+
def th_diff(self) -> float:
60+
"""Thermal diffusivity in m2/s."""
61+
return self.th_cond / (self.density * self.sp_heat)
62+
63+
@property
64+
def time(self) -> float:
65+
"""Time in s."""
66+
return self.length**2 / self.th_diff
67+
68+
@property
69+
def velocity(self) -> float:
70+
"""Velocity in m/s."""
71+
return self.length / self.time
72+
73+
@property
74+
def acceleration(self) -> float:
75+
"""Acceleration in m/s2."""
76+
return self.length / self.time**2
77+
78+
@property
79+
def power(self) -> float:
80+
"""Power in W."""
81+
return self.th_cond * self.temperature * self.length
82+
83+
@property
84+
def heat_flux(self) -> float:
85+
"""Local heat flux in W/m2."""
86+
return self.power / self.length**2
87+
88+
@property
89+
def heat_production(self) -> float:
90+
"""Local heat production in W/m3."""
91+
return self.power / self.length**3
92+
93+
@property
94+
def stress(self) -> float:
95+
"""Stress in Pa."""
96+
return self.dyn_visc / self.time

stagpy/phyvars.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@
1919

2020
from ._step import Step
2121
from .datatypes import Field, Rprof, Tseries
22-
from .stagyydata import StagyyData, _Scales
22+
from .dimensions import Scales
23+
from .stagyydata import StagyyData
2324

2425

2526
FIELD: Mapping[str, Varf] = MappingProxyType(
@@ -327,7 +328,7 @@
327328
}
328329
)
329330

330-
SCALES: Mapping[str, Callable[[_Scales], float]] = MappingProxyType(
331+
SCALES: Mapping[str, Callable[[Scales], float]] = MappingProxyType(
331332
{
332333
"m": attrgetter("length"),
333334
"kg/m3": attrgetter("density"),

stagpy/stagyydata.py

Lines changed: 2 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
from . import _helpers, _step, conf, error, phyvars, stagyyparsers
2323
from ._step import Step
2424
from .datatypes import Rprof, Tseries, Vart
25+
from .dimensions import Scales
2526
from .parfile import StagyyPar
2627
from .stagyyparsers import FieldXmf, TracersXmf
2728

@@ -73,94 +74,6 @@ def _as_view_item(
7374
return None
7475

7576

76-
class _Scales:
77-
"""Dimensional scales.
78-
79-
Args:
80-
sdat: the StagyyData instance owning the :class:`_Scales` instance.
81-
"""
82-
83-
def __init__(self, sdat: StagyyData):
84-
self._sdat = sdat
85-
86-
@property
87-
def par(self) -> StagyyPar:
88-
return self._sdat.par
89-
90-
@cached_property
91-
def length(self) -> float:
92-
"""Length in m."""
93-
thick = self.par.get("geometry", "d_dimensional", 2890e3)
94-
if self.par.get("boundaries", "air_layer", False):
95-
thick += self.par.nml["boundaries"]["air_thickness"]
96-
return thick
97-
98-
@property
99-
def temperature(self) -> float:
100-
"""Temperature in K."""
101-
return self.par.nml["refstate"]["deltaT_dimensional"]
102-
103-
@property
104-
def density(self) -> float:
105-
"""Density in kg/m3."""
106-
return self.par.nml["refstate"]["dens_dimensional"]
107-
108-
@property
109-
def th_cond(self) -> float:
110-
"""Thermal conductivity in W/(m.K)."""
111-
return self.par.nml["refstate"]["tcond_dimensional"]
112-
113-
@property
114-
def sp_heat(self) -> float:
115-
"""Specific heat capacity in J/(kg.K)."""
116-
return self.par.nml["refstate"]["Cp_dimensional"]
117-
118-
@property
119-
def dyn_visc(self) -> float:
120-
"""Dynamic viscosity in Pa.s."""
121-
return self.par.nml["viscosity"]["eta0"]
122-
123-
@property
124-
def th_diff(self) -> float:
125-
"""Thermal diffusivity in m2/s."""
126-
return self.th_cond / (self.density * self.sp_heat)
127-
128-
@property
129-
def time(self) -> float:
130-
"""Time in s."""
131-
return self.length**2 / self.th_diff
132-
133-
@property
134-
def velocity(self) -> float:
135-
"""Velocity in m/s."""
136-
return self.length / self.time
137-
138-
@property
139-
def acceleration(self) -> float:
140-
"""Acceleration in m/s2."""
141-
return self.length / self.time**2
142-
143-
@property
144-
def power(self) -> float:
145-
"""Power in W."""
146-
return self.th_cond * self.temperature * self.length
147-
148-
@property
149-
def heat_flux(self) -> float:
150-
"""Local heat flux in W/m2."""
151-
return self.power / self.length**2
152-
153-
@property
154-
def heat_production(self) -> float:
155-
"""Local heat production in W/m3."""
156-
return self.power / self.length**3
157-
158-
@property
159-
def stress(self) -> float:
160-
"""Stress in Pa."""
161-
return self.dyn_visc / self.time
162-
163-
16477
class _Refstate:
16578
"""Reference state profiles.
16679
@@ -765,7 +678,7 @@ def __init__(self, path: PathLike):
765678
self._parpath = Path(path)
766679
if not self._parpath.is_file():
767680
self._parpath /= "par"
768-
self.scales = _Scales(self)
681+
self.scales = Scales(self)
769682
self.refstate = _Refstate(self)
770683
self.tseries = _Tseries(self)
771684
self.steps = _Steps(self)

0 commit comments

Comments
 (0)