@@ -607,29 +607,48 @@ def get_equilibration_parameters(assemblage, composition, free_compositional_vec
607607 degrees of freedom for the equilibrium problem.
608608 :type free_compositional_vectors: list of dictionaries
609609
610- :returns: A tuple with attributes n_parameters
611- (the number of parameters for the current equilibrium problem)
612- and phase_amount_indices (the indices of the parameters that
613- correspond to phase amounts).
610+ :returns: A tuple with attributes:
611+ - parameter_names: list of strings, the names of the parameters
612+ for the current equilibrium problem
613+ - default_tolerances: numpy.array, the default tolerances for each parameter
614+ - n_parameters: int, the number of parameters for the current equilibrium problem
615+ - phase_amount_indices: list of int, the indices of the parameters that
616+ correspond to phase amounts
617+ - bulk_composition_vector: numpy.array, the bulk composition vector
618+ - free_compositional_vectors: 2D numpy.array, the free compositional vectors
619+ - reduced_composition_vector: numpy.array, the bulk composition vector
620+ reduced to the independent elements
621+ - reduced_free_composition_vectors: 2D numpy.array, the free compositional vectors
622+ reduced to the independent elements
623+ - constraint_vector: numpy.array, vector for the linear constraints bounding the
624+ valid parameter space (b in Ax + b < eps)
625+ - constraint_matrix: 2D numpy.array, matrix for the linear constraints bounding the
626+ valid parameter space (A in Ax + b < eps)
614627 :rtype: namedtuple
615628 """
616629 # Initialize a named tuple for the equilibration parameters
617630 prm = namedtuple ("assemblage_parameters" , [])
618631
619632 # Process parameter names
620633 prm .parameter_names = ["Pressure (Pa)" , "Temperature (K)" ]
634+ prm .default_tolerances = [1.0 , 1.0e-3 ]
621635 for i , n in enumerate (assemblage .endmembers_per_phase ):
622636 prm .parameter_names .append ("x({0})" .format (assemblage .phases [i ].name ))
637+ prm .default_tolerances .append (1.0e-6 )
623638 if n > 1 :
624639 p_names = [
625640 "p({0} in {1})" .format (n , assemblage .phases [i ].name )
626641 for n in assemblage .phases [i ].endmember_names [1 :]
627642 ]
628643 prm .parameter_names .extend (p_names )
644+ prm .default_tolerances .extend ([1.0e-6 ] * len (p_names ))
629645
630646 n_free_compositional_vectors = len (free_compositional_vectors )
631647 for i in range (n_free_compositional_vectors ):
632648 prm .parameter_names .append (f"v_{ i } " )
649+ prm .default_tolerances .append (1.0e-6 )
650+
651+ prm .default_tolerances = np .array (prm .default_tolerances )
633652
634653 prm .n_parameters = len (prm .parameter_names )
635654 prm .phase_amount_indices = [
@@ -797,7 +816,7 @@ def equilibrate(
797816 assemblage ,
798817 equality_constraints ,
799818 free_compositional_vectors = [],
800- tol = 1.0e-3 ,
819+ tol = None ,
801820 store_iterates = False ,
802821 store_assemblage = True ,
803822 max_iterations = 100.0 ,
@@ -866,8 +885,16 @@ def equilibrate(
866885 Vector given in atomic (molar) units of elements.
867886 :type free_compositional_vectors: list of dict
868887
869- :param tol: The tolerance for the nonlinear solver.
870- :type tol: float
888+ :param tol: The tolerance for the nonlinear solver. This can be a single float,
889+ which is then applied to all parameters, or a numpy array with the
890+ same length as the number of parameters in the solve (2 + number of
891+ phases + number of free compositional vectors). The default is None,
892+ which sets the tolerances to 1 Pa for pressure, 1e-3 K for temperature,
893+ 1e-6 for phase amounts and 1e-6 for free compositional vectors.
894+ One of the termination criteria for the nonlinear solver is that
895+ the absolute change in each parameter is less than the corresponding
896+ tolerance.
897+ :type tol: float or numpy.array
871898
872899 :param store_iterates: Whether to store the parameter values for
873900 each iteration in each solution object.
@@ -932,6 +959,10 @@ def equilibrate(
932959 assemblage , composition , free_compositional_vectors
933960 )
934961
962+ # Set default tolerances if not provided
963+ if tol is None :
964+ tol = prm .default_tolerances
965+
935966 # Check equality constraints have the correct structure
936967 # Convert into the format readable by the function and jacobian functions
937968 eq_constraint_lists = process_eq_constraints (equality_constraints , assemblage , prm )
0 commit comments