1212from scipy import integrate
1313
1414from .error import NotAvailableError
15- from .datatypes import Field , Varf
15+ from .datatypes import Field , Varf , Rprof , Varr
1616
1717if typing .TYPE_CHECKING :
1818 from typing import Tuple
@@ -94,16 +94,17 @@ def mobility(sdat: StagyyData) -> Tuple[ndarray, ndarray]:
9494 return np .array (mob ), np .array (time )
9595
9696
97- def delta_r (step : Step ) -> Tuple [ ndarray , ndarray ] :
98- """Cells thickness .
97+ def delta_r (step : Step ) -> Rprof :
98+ """Compute cell thicknesses .
9999
100100 Args:
101101 step: a :class:`~stagpy._step.Step` of a StagyyData instance.
102102 Returns:
103103 the thickness of the cells and radius.
104104 """
105105 edges = step .rprofs .walls
106- return (edges [1 :] - edges [:- 1 ]), step .rprofs .centers
106+ meta = Varr ("Cell thickness" , 'dr' , 'm' )
107+ return Rprof ((edges [1 :] - edges [:- 1 ]), step .rprofs .centers , meta )
107108
108109
109110def _scale_prof (step : Step , rprof : ndarray , rad : ndarray = None ) -> ndarray :
@@ -116,8 +117,8 @@ def _scale_prof(step: Step, rprof: ndarray, rad: ndarray = None) -> ndarray:
116117 return rprof * (2 * rad / (rtop + rbot ))** 2
117118
118119
119- def diff_prof (step : Step ) -> Tuple [ ndarray , ndarray ] :
120- """Diffusion .
120+ def diff_prof (step : Step ) -> Rprof :
121+ """Compute diffusion flux .
121122
122123 Args:
123124 step: a :class:`~stagpy._step.Step` of a StagyyData instance.
@@ -132,11 +133,12 @@ def diff_prof(step: Step) -> Tuple[ndarray, ndarray]:
132133 diff = np .insert (diff , 0 , (1 - tprof [0 ]) / (rad [0 ] - rbot ))
133134 # assume ttop = 0
134135 diff = np .append (diff , tprof [- 1 ] / (rtop - rad [- 1 ]))
135- return diff , step .rprofs .walls
136+ meta = Varr ("Diffusion" , 'Heat flux' , 'W/m2' )
137+ return Rprof (diff , step .rprofs .walls , meta )
136138
137139
138- def diffs_prof (step : Step ) -> Tuple [ ndarray , ndarray ] :
139- """Scaled diffusion.
140+ def diffs_prof (step : Step ) -> Rprof :
141+ """Compute scaled diffusion flux .
140142
141143 This computation takes sphericity into account if necessary.
142144
@@ -145,12 +147,13 @@ def diffs_prof(step: Step) -> Tuple[ndarray, ndarray]:
145147 Returns:
146148 the diffusion and radius.
147149 """
148- diff , rad = diff_prof (step )
149- return _scale_prof (step , diff , rad ), rad
150+ diff , rad , _ = diff_prof (step )
151+ meta = Varr ("Scaled diffusion" , 'Heat flux' , 'W/m2' )
152+ return Rprof (_scale_prof (step , diff , rad ), rad , meta )
150153
151154
152- def advts_prof (step : Step ) -> Tuple [ ndarray , ndarray ] :
153- """Scaled advection.
155+ def advts_prof (step : Step ) -> Rprof :
156+ """Compute scaled advection flux .
154157
155158 This computation takes sphericity into account if necessary.
156159
@@ -159,11 +162,13 @@ def advts_prof(step: Step) -> Tuple[ndarray, ndarray]:
159162 Returns:
160163 the scaled advection and radius.
161164 """
162- return _scale_prof (step , step .rprofs ['advtot' ].values ), step .rprofs .centers
165+ return Rprof (_scale_prof (step , step .rprofs ['advtot' ].values ),
166+ step .rprofs .centers ,
167+ Varr ("Scaled advection" , 'Heat flux' , 'W/m2' ))
163168
164169
165- def advds_prof (step : Step ) -> Tuple [ ndarray , ndarray ] :
166- """Scaled downward advection.
170+ def advds_prof (step : Step ) -> Rprof :
171+ """Compute scaled downward advection flux .
167172
168173 This computation takes sphericity into account if necessary.
169174
@@ -172,12 +177,13 @@ def advds_prof(step: Step) -> Tuple[ndarray, ndarray]:
172177 Returns:
173178 the scaled downward advection and radius.
174179 """
175- return (_scale_prof (step , step .rprofs ['advdesc' ].values ),
176- step .rprofs .centers )
180+ return Rprof (_scale_prof (step , step .rprofs ['advdesc' ].values ),
181+ step .rprofs .centers ,
182+ Varr ("Scaled downward advection" , 'Heat flux' , 'W/m2' ))
177183
178184
179- def advas_prof (step : Step ) -> Tuple [ ndarray , ndarray ] :
180- """Scaled upward advection.
185+ def advas_prof (step : Step ) -> Rprof :
186+ """Compute scaled upward advection flux .
181187
182188 This computation takes sphericity into account if necessary.
183189
@@ -186,11 +192,13 @@ def advas_prof(step: Step) -> Tuple[ndarray, ndarray]:
186192 Returns:
187193 the scaled upward advection and radius.
188194 """
189- return _scale_prof (step , step .rprofs ['advasc' ].values ), step .rprofs .centers
195+ return Rprof (_scale_prof (step , step .rprofs ['advasc' ].values ),
196+ step .rprofs .centers ,
197+ Varr ("Scaled upward advection" , 'Heat flux' , 'W/m2' ))
190198
191199
192- def energy_prof (step : Step ) -> Tuple [ ndarray , ndarray ] :
193- """Energy flux.
200+ def energy_prof (step : Step ) -> Rprof :
201+ """Compute total heat flux.
194202
195203 This computation takes sphericity into account if necessary.
196204
@@ -199,13 +207,14 @@ def energy_prof(step: Step) -> Tuple[ndarray, ndarray]:
199207 Returns:
200208 the energy flux and radius.
201209 """
202- diff , rad = diffs_prof (step )
203- adv , _ = advts_prof (step )
204- return (diff + np .append (adv , 0 )), rad
210+ diff , rad , _ = diffs_prof (step )
211+ adv , _ , _ = advts_prof (step )
212+ return Rprof (diff + np .append (adv , 0 ), rad ,
213+ Varr ("Total heat flux" , 'Heat flux' , 'W/m2' ))
205214
206215
207- def advth (step : Step ) -> Tuple [ ndarray , ndarray ] :
208- """Theoretical advection.
216+ def advth (step : Step ) -> Rprof :
217+ """Compute theoretical advection.
209218
210219 This compute the theoretical profile of total advection as function of
211220 radius.
@@ -225,11 +234,12 @@ def advth(step: Step) -> Tuple[ndarray, ndarray]:
225234 th_adv = rad - rtop
226235 th_adv *= radio
227236 th_adv += step .timeinfo ['Nutop' ]
228- return th_adv , rad
237+ return Rprof (th_adv , rad ,
238+ Varr ("Theoretical advection" , 'Heat flux' , 'W/m2' ))
229239
230240
231- def init_c_overturn (step : Step ) -> Tuple [ ndarray , ndarray ] :
232- """Initial concentration.
241+ def init_c_overturn (step : Step ) -> Rprof :
242+ """Compute concentration before overturn .
233243
234244 This compute the resulting composition profile if fractional
235245 crystallization of a SMO is assumed.
@@ -257,11 +267,12 @@ def initprof(rpos):
257267
258268 rad = np .linspace (rbot , rtop , 500 )
259269 initprof = np .vectorize (initprof )
260- return initprof (rad ), rad
270+ return Rprof (initprof (rad ), rad ,
271+ Varr ("Concentration before overturn" , 'Concentration' , '1' ))
261272
262273
263- def c_overturned (step : Step ) -> Tuple [ ndarray , ndarray ] :
264- """Theoretical overturned concentration.
274+ def c_overturned (step : Step ) -> Rprof :
275+ """Compute theoretical overturned concentration.
265276
266277 This compute the resulting composition profile if fractional
267278 crystallization of a SMO is assumed and then a purely radial
@@ -273,9 +284,10 @@ def c_overturned(step: Step) -> Tuple[ndarray, ndarray]:
273284 the composition and radius.
274285 """
275286 rbot , rtop = step .rprofs .bounds
276- cinit , rad = init_c_overturn (step )
277- radf = (rtop ** 3 + rbot ** 3 - rad ** 3 )** (1 / 3 )
278- return cinit , radf
287+ cinit = init_c_overturn (step )
288+ radf = (rtop ** 3 + rbot ** 3 - cinit .rad ** 3 )** (1 / 3 )
289+ return Rprof (cinit .values , radf ,
290+ Varr ("Overturned concentration" , 'Concentration' , '1' ))
279291
280292
281293def stream_function (step : Step ) -> Field :
0 commit comments