@@ -100,8 +100,7 @@ impl<U: EosUnit> VaporPressure<U> {
100100 ) -> Result < Self , FitError > {
101101 let datapoints = target. len ( ) ;
102102 let max_temperature = temperature
103- . to_reduced ( U :: reference_temperature ( ) )
104- . unwrap ( )
103+ . to_reduced ( U :: reference_temperature ( ) ) ?
105104 . into_iter ( )
106105 . reduce ( |a, b| a. max ( b) )
107106 . unwrap ( )
@@ -147,10 +146,13 @@ impl<U: EosUnit, E: EquationOfState> DataSet<U, E> for VaporPressure<U> {
147146 where
148147 QuantityScalar < U > : std:: fmt:: Display + std:: fmt:: LowerExp ,
149148 {
150- let tc =
151- State :: critical_point ( eos, None , Some ( self . max_temperature ) , SolverOptions :: default ( ) )
152- . unwrap ( )
153- . temperature ;
149+ let tc = State :: critical_point (
150+ eos,
151+ None ,
152+ Some ( self . max_temperature ) ,
153+ SolverOptions :: default ( ) ,
154+ ) ?
155+ . temperature ;
154156
155157 let unit = self . target . get ( 0 ) ;
156158 let mut prediction = Array1 :: zeros ( self . datapoints ) * unit;
@@ -160,12 +162,12 @@ impl<U: EosUnit, E: EquationOfState> DataSet<U, E> for VaporPressure<U> {
160162 if let Some ( pvap) =
161163 PhaseEquilibrium :: vapor_pressure ( eos, self . temperature . get ( i) ) [ 0 ]
162164 {
163- prediction. try_set ( i, pvap) . unwrap ( ) ;
165+ prediction. try_set ( i, pvap) ? ;
164166 } else {
165- prediction. try_set ( i, f64:: NAN * unit) . unwrap ( ) ;
167+ prediction. try_set ( i, f64:: NAN * unit) ? ;
166168 }
167169 } else {
168- prediction. try_set ( i, f64:: NAN * unit) . unwrap ( ) ;
170+ prediction. try_set ( i, f64:: NAN * unit) ? ;
169171 }
170172 }
171173 Ok ( prediction)
@@ -176,14 +178,18 @@ impl<U: EosUnit, E: EquationOfState> DataSet<U, E> for VaporPressure<U> {
176178 QuantityScalar < U > : std:: fmt:: Display + std:: fmt:: LowerExp ,
177179 {
178180 let tc_inv = 1.0
179- / State :: critical_point ( eos, None , Some ( self . max_temperature ) , SolverOptions :: default ( ) )
180- . unwrap ( )
181- . temperature ;
182-
183- let reduced_temperatures = ( 0 ..self . datapoints )
184- . map ( |i| ( self . temperature . get ( i) * tc_inv) . into_value ( ) . unwrap ( ) )
181+ / State :: critical_point (
182+ eos,
183+ None ,
184+ Some ( self . max_temperature ) ,
185+ SolverOptions :: default ( ) ,
186+ ) ?
187+ . temperature ;
188+
189+ let reduced_temperatures: Result < _ , _ > = ( 0 ..self . datapoints )
190+ . map ( |i| ( self . temperature . get ( i) * tc_inv) . into_value ( ) )
185191 . collect ( ) ;
186- let mut weights = self . weight_from_std ( & reduced_temperatures) ;
192+ let mut weights = self . weight_from_std ( & reduced_temperatures? ) ;
187193 weights /= weights. sum ( ) ;
188194
189195 let prediction = & self . predict ( eos) ?;
@@ -193,8 +199,7 @@ impl<U: EosUnit, E: EquationOfState> DataSet<U, E> for VaporPressure<U> {
193199 cost[ i] = weights[ i]
194200 * 5.0
195201 * ( self . temperature . get ( i) - 1.0 / tc_inv)
196- . to_reduced ( U :: reference_temperature ( ) )
197- . unwrap ( ) ;
202+ . to_reduced ( U :: reference_temperature ( ) ) ?;
198203 } else {
199204 cost[ i] = weights[ i]
200205 * ( ( self . target . get ( i) - prediction. get ( i) ) / self . target . get ( i) )
@@ -275,9 +280,9 @@ impl<U: EosUnit, E: EquationOfState + MolarWeight<U>> DataSet<U, E> for LiquidDe
275280 DensityInitialization :: Liquid ,
276281 ) ;
277282 if let Ok ( s) = state {
278- prediction. try_set ( i, s. mass_density ( ) ) . unwrap ( ) ;
283+ prediction. try_set ( i, s. mass_density ( ) ) ? ;
279284 } else {
280- prediction. try_set ( i, 1.0e10 * unit) . unwrap ( ) ;
285+ prediction. try_set ( i, 1.0e10 * unit) ? ;
281286 }
282287 }
283288 Ok ( prediction)
@@ -322,8 +327,7 @@ impl<U: EosUnit> EquilibriumLiquidDensity<U> {
322327 ) -> Result < Self , FitError > {
323328 let datapoints = target. len ( ) ;
324329 let max_temperature = temperature
325- . to_reduced ( U :: reference_temperature ( ) )
326- . unwrap ( )
330+ . to_reduced ( U :: reference_temperature ( ) ) ?
327331 . into_iter ( )
328332 . reduce ( |a, b| a. max ( b) )
329333 . unwrap ( )
@@ -362,23 +366,24 @@ impl<U: EosUnit, E: EquationOfState + MolarWeight<U>> DataSet<U, E>
362366 where
363367 QuantityScalar < U > : std:: fmt:: Display + std:: fmt:: LowerExp ,
364368 {
365- let tc =
366- State :: critical_point ( eos, None , Some ( self . max_temperature ) , SolverOptions :: default ( ) )
367- . unwrap ( )
368- . temperature ;
369+ let tc = State :: critical_point (
370+ eos,
371+ None ,
372+ Some ( self . max_temperature ) ,
373+ SolverOptions :: default ( ) ,
374+ ) ?
375+ . temperature ;
369376
370377 let unit = self . target . get ( 0 ) ;
371378 let mut prediction = Array1 :: zeros ( self . datapoints ) * unit;
372379 for i in 0 ..self . datapoints {
373380 let t: QuantityScalar < U > = self . temperature . get ( i) ;
374381 if t < tc {
375382 let state: PhaseEquilibrium < U , E , 2 > =
376- PhaseEquilibrium :: pure_t ( eos, t, None , SolverOptions :: default ( ) ) . unwrap ( ) ;
377- prediction
378- . try_set ( i, state. liquid ( ) . mass_density ( ) )
379- . unwrap ( ) ;
383+ PhaseEquilibrium :: pure_t ( eos, t, None , SolverOptions :: default ( ) ) ?;
384+ prediction. try_set ( i, state. liquid ( ) . mass_density ( ) ) ?;
380385 } else {
381- prediction. try_set ( i, f64:: NAN * unit) . unwrap ( ) ;
386+ prediction. try_set ( i, f64:: NAN * unit) ? ;
382387 }
383388 }
384389 Ok ( prediction)
@@ -388,20 +393,21 @@ impl<U: EosUnit, E: EquationOfState + MolarWeight<U>> DataSet<U, E>
388393 where
389394 QuantityScalar < U > : std:: fmt:: Display + std:: fmt:: LowerExp ,
390395 {
391- let tc =
392- State :: critical_point ( eos, None , Some ( self . max_temperature ) , SolverOptions :: default ( ) )
393- . unwrap ( )
394- . temperature ;
396+ let tc = State :: critical_point (
397+ eos,
398+ None ,
399+ Some ( self . max_temperature ) ,
400+ SolverOptions :: default ( ) ,
401+ ) ?
402+ . temperature ;
395403 let n_inv = 1.0 / self . datapoints as f64 ;
396404 let prediction = & self . predict ( eos) ?;
397405 let mut cost = Array1 :: zeros ( self . datapoints ) ;
398406 for i in 0 ..self . datapoints {
399407 if prediction. get ( i) . is_nan ( ) {
400408 cost[ i] = n_inv
401409 * 5.0
402- * ( self . temperature . get ( i) - tc)
403- . to_reduced ( U :: reference_temperature ( ) )
404- . unwrap ( ) ;
410+ * ( self . temperature . get ( i) - tc) . to_reduced ( U :: reference_temperature ( ) ) ?;
405411 } else {
406412 cost[ i] = n_inv
407413 * ( ( self . target . get ( i) - prediction. get ( i) ) / self . target . get ( i) )
0 commit comments