@@ -865,10 +865,13 @@ def set_state(self, pressure, temperature, relaxed=True):
865865 :type relaxed: bool, optional
866866 """
867867 self .unrelaxed .set_state (pressure , temperature )
868+ Solution .set_state (self , pressure , temperature )
868869
869- if hasattr (self .unrelaxed , "molar_fractions" ) and relaxed :
870- self ._relax_at_PTX ()
871- Solution .set_state (self , pressure , temperature )
870+ if relaxed :
871+ try : # relax if composition has already been set
872+ self ._relax_at_PTX ()
873+ except AttributeError :
874+ pass
872875
873876 def set_composition (self , molar_fractions , q_initial = None , relaxed = True ):
874877 """
@@ -900,10 +903,12 @@ def set_composition(self, molar_fractions, q_initial=None, relaxed=True):
900903
901904 self .unrelaxed .set_composition (n )
902905
903- if self .unrelaxed .pressure is not None and relaxed :
904- Solution .set_composition (self , n )
905- self ._relax_at_PTX ()
906- self .unrelaxed .set_composition (self .molar_fractions )
906+ if relaxed :
907+ try : # relax if state has already been set
908+ Solution .set_composition (self , n )
909+ self ._relax_at_PTX ()
910+ except AttributeError :
911+ pass
907912
908913 def _relax_at_PTX (self ):
909914 """
@@ -926,6 +931,7 @@ def G_func(dq):
926931 n = n0 + np .einsum ("ij, j" , self .dndq , sol .x )
927932 self .unrelaxed .set_composition (n )
928933 Solution .set_composition (self , n )
934+ self .unrelaxed .set_composition (self .molar_fractions )
929935
930936 def set_state_with_volume (
931937 self , volume , temperature , pressure_guesses = [0.0e9 , 10.0e9 ]
0 commit comments