From 710b8615a7d9dd67afff9c8d1bf608a9eb97efe8 Mon Sep 17 00:00:00 2001 From: Ian Bell Date: Tue, 3 Oct 2023 20:23:28 -0400 Subject: [PATCH] Only apply the newton method for mixtures Use the default method normally --- PDSim/core/core.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/PDSim/core/core.py b/PDSim/core/core.py index a5633bc..d324f2b 100644 --- a/PDSim/core/core.py +++ b/PDSim/core/core.py @@ -1264,11 +1264,16 @@ def OBJECTIVE_CYCLE(self, Td_Tlumps0, X, epsilon_cycle = 0.003, epsilon_energy_b # value for it h_target = hdnew - # Iterate to solve the H, P flash calculation - def objective(T): - self.Tubes.Nodes[self.key_outlet].update(dict(T=T, P=self.Tubes.Nodes[self.key_outlet].p)) - return self.Tubes.Nodes[self.key_outlet].h - h_target - scipy.optimize.newton(objective, self.Tubes.Nodes[self.key_outlet].T) + if hasattr(self.Tubes.Nodes[self.key_outlet],'pAS') and len(self.Tubes.Nodes[self.key_outlet].pAS.fluid_names()) == 1: + self.Tubes.Nodes[self.key_outlet].update_ph(self.Tubes.Nodes[self.key_outlet].p, h_target) + else: + # Iterate to solve the H, P flash calculation + def objective(T): + self.Tubes.Nodes[self.key_outlet].update(dict(T=T, P=self.Tubes.Nodes[self.key_outlet].p)) + residual = self.Tubes.Nodes[self.key_outlet].h - h_target + print(T, residual) + return residual + scipy.optimize.newton(objective, self.Tubes.Nodes[self.key_outlet].T) print(self.solvers.hdisc_history)