<commit_before>
#ifndef HELMHOLTZEOSMIXTUREBACKEND_H_
#define HELMHOLTZEOSMIXTUREBACKEND_H_

#include "AbstractState.h"
#include "CoolPropFluid.h"
#include "ReducingFunctions.h"
#include "ExcessHEFunction.h"
#include "Solvers.h"
#include "PhaseEnvelope.h"
#include "DataStructures.h"
#include "Configuration.h"

#include <vector>

namespace CoolProp {

class FlashRoutines;

class ResidualHelmholtz;

class HelmholtzEOSMixtureBackend : public AbstractState {
    
protected:
    void pre_update(CoolProp::input_pairs &input_pair, CoolPropDbl &value1, CoolPropDbl &value2 );
    void post_update(bool optional_checks = true);
    std::vector<shared_ptr<HelmholtzEOSMixtureBackend> > linked_states; ///< States that are linked to this one, and should be updated (BIP, reference state, etc.)
    shared_ptr<HelmholtzEOSMixtureBackend> transient_pure_state; ///< A temporary state used for calculations of pure fluid properties
    shared_ptr<HelmholtzEOSMixtureBackend> TPD_state; ///< A temporary state used for calculations of the tangent-plane-distance
    shared_ptr<HelmholtzEOSMixtureBackend> critical_state; ///< A temporary state used for calculations of the critical point(s)
    /// Update the state class used to calculate the tangent-plane-distance
    virtual void add_TPD_state(){
        if (TPD_state.get() == NULL){ bool sat_states = false; TPD_state.reset(get_copy(sat_states)); linked_states.push_back(TPD_state);
	    }
    };
    /// Update the state class used to calculate the critical point(s)
    virtual void add_critical_state(){
        if (critical_state.get() == NULL){ bool sat_states = true; critical_state.reset(get_copy(sat_states)); linked_states.push_back(critical_state);
        }
    };
    /// Update the state class used to calculate the critical point(s)
    virtual void add_transient_pure_state(){
        if (transient_pure_state.get() == NULL){ bool sat_states = true; transient_pure_state.reset(get_copy(sat_states)); linked_states.push_back(transient_pure_state);
        }
    };
    
    std::vector<CoolPropFluid> components; ///< The components that are in use
    bool is_pure_or_pseudopure; ///< A flag for whether the substance is a pure or pseudo-pure fluid (true) or a mixture (false)
    std::vector<CoolPropDbl> mole_fractions; ///< The bulk mole fractions of the mixture
    std::vector<double> mole_fractions_double; ///< A copy of the bulk mole fractions of the mixture stored as doubles
    std::vector<CoolPropDbl> K, ///< The K factors for the components
                             lnK; ///< The natural logarithms of the K factors of the components

    SimpleState _crit;
    std::size_t N; ///< Number of components
    
    /// This overload is protected because it doesn't follow the base class definition, since this function is needed for constructing spinodals
    std::vector<CoolProp::CriticalState> _calc_all_critical_points(bool find_critical_points = true);

    static void set_fluid_enthalpy_entropy_offset(CoolPropFluid& component, double delta_a1, double delta_a2, const std::string &ref);

public:
    HelmholtzEOSMixtureBackend();
    HelmholtzEOSMixtureBackend(const std::vector<CoolPropFluid> &components, bool generate_SatL_and_SatV = true);
    HelmholtzEOSMixtureBackend(const std::vector<std::string> &component_names, bool generate_SatL_and_SatV = true);
    virtual HelmholtzEOSMixtureBackend * get_copy(bool generate_SatL_and_SatV = true);
    virtual ~HelmholtzEOSMixtureBackend(){};
    std::string backend_name(void) { return get_backend_string(HEOS_BACKEND_MIX); }
    shared_ptr<ReducingFunction> Reducing;
    shared_ptr<ResidualHelmholtz> residual_helmholtz;
    PhaseEnvelopeData PhaseEnvelope;
    SimpleState hsat_max;
    SsatSimpleState ssat_max;
    SpinodalData spinodal_values;

    bool clear(){
        // Clear the locally cached values for the derivatives of the residual Helmholtz energy
        // in each component
        for (std::vector<CoolPropFluid>::iterator it = components.begin(); it != components.end(); ++it){
            (*it).EOS().alphar.clear();
        }
        return AbstractState::clear();
    };

    friend class FlashRoutines; // Allows the static methods in the FlashRoutines class to have access to all the protected members and methods of this class
    friend class TransportRoutines; // Allows the static methods in the TransportRoutines class to have access to all the protected members and methods of this class
    friend class MixtureDerivatives; // Allows the static methods in the MixtureDerivatives class to have access to all the protected members and methods of this class
    friend class PhaseEnvelopeRoutines; // Allows the static methods in the PhaseEnvelopeRoutines class to have access to all the protected members and methods of this class
    friend class MixtureParameters; // Allows the static methods in the MixtureParameters class to have access to all the protected members and methods of this class
    friend class CorrespondingStatesTerm; // // Allows the methods in the CorrespondingStatesTerm class to have access to all the protected members and methods of this class

    // Helmholtz EOS backend uses mole fractions
    bool using_mole_fractions(){return true;}
    bool using_mass_fractions(){return false;}
    bool using_volu_fractions(){return false;}
    bool is_pure(){ return components.size() == 1 && !components[0].EOS().pseudo_pure; }
    bool has_melting_line(){ return is_pure_or_pseudopure && components[0].ancillaries.melting_line.enabled();};
    CoolPropDbl calc_melting_line(int param, int given, CoolPropDbl value);
    /// Return a string from the backend for the mixture/fluid
    std::string fluid_param_string(const std::string &);
    
    /// brief Set the reference state based on a string representation
    virtual void set_reference_stateS(const std::string &reference_state);

    /// Set the reference state based on a thermodynamic state point specified by temperature and molar density
    virtual void set_reference_stateD(double T, double rhomolar, double hmolar0, double smolar0);

    /// Set binary mixture floating point parameter
    virtual void set_binary_interaction_double(const std::size_t i, const std::size_t j, const std::string &parameter, const double value);<commit_msg>Clear alpha0 just like alphar<commit_after>
#ifndef HELMHOLTZEOSMIXTUREBACKEND_H_
#define HELMHOLTZEOSMIXTUREBACKEND_H_

#include "AbstractState.h"
#include "CoolPropFluid.h"
#include "ReducingFunctions.h"
#include "ExcessHEFunction.h"
#include "Solvers.h"
#include "PhaseEnvelope.h"
#include "DataStructures.h"
#include "Configuration.h"

#include <vector>

namespace CoolProp {

class FlashRoutines;

class ResidualHelmholtz;

class HelmholtzEOSMixtureBackend : public AbstractState {
    
protected:
    void pre_update(CoolProp::input_pairs &input_pair, CoolPropDbl &value1, CoolPropDbl &value2 );
    void post_update(bool optional_checks = true);
    std::vector<shared_ptr<HelmholtzEOSMixtureBackend> > linked_states; ///< States that are linked to this one, and should be updated (BIP, reference state, etc.)
    shared_ptr<HelmholtzEOSMixtureBackend> transient_pure_state; ///< A temporary state used for calculations of pure fluid properties
    shared_ptr<HelmholtzEOSMixtureBackend> TPD_state; ///< A temporary state used for calculations of the tangent-plane-distance
    shared_ptr<HelmholtzEOSMixtureBackend> critical_state; ///< A temporary state used for calculations of the critical point(s)
    /// Update the state class used to calculate the tangent-plane-distance
    virtual void add_TPD_state(){
        if (TPD_state.get() == NULL){ bool sat_states = false; TPD_state.reset(get_copy(sat_states)); linked_states.push_back(TPD_state);
	    }
    };
    /// Update the state class used to calculate the critical point(s)
    virtual void add_critical_state(){
        if (critical_state.get() == NULL){ bool sat_states = true; critical_state.reset(get_copy(sat_states)); linked_states.push_back(critical_state);
        }
    };
    /// Update the state class used to calculate the critical point(s)
    virtual void add_transient_pure_state(){
        if (transient_pure_state.get() == NULL){ bool sat_states = true; transient_pure_state.reset(get_copy(sat_states)); linked_states.push_back(transient_pure_state);
        }
    };
    
    std::vector<CoolPropFluid> components; ///< The components that are in use
    bool is_pure_or_pseudopure; ///< A flag for whether the substance is a pure or pseudo-pure fluid (true) or a mixture (false)
    std::vector<CoolPropDbl> mole_fractions; ///< The bulk mole fractions of the mixture
    std::vector<double> mole_fractions_double; ///< A copy of the bulk mole fractions of the mixture stored as doubles
    std::vector<CoolPropDbl> K, ///< The K factors for the components
                             lnK; ///< The natural logarithms of the K factors of the components

    SimpleState _crit;
    std::size_t N; ///< Number of components
    
    /// This overload is protected because it doesn't follow the base class definition, since this function is needed for constructing spinodals
    std::vector<CoolProp::CriticalState> _calc_all_critical_points(bool find_critical_points = true);

    static void set_fluid_enthalpy_entropy_offset(CoolPropFluid& component, double delta_a1, double delta_a2, const std::string &ref);

public:
    HelmholtzEOSMixtureBackend();
    HelmholtzEOSMixtureBackend(const std::vector<CoolPropFluid> &components, bool generate_SatL_and_SatV = true);
    HelmholtzEOSMixtureBackend(const std::vector<std::string> &component_names, bool generate_SatL_and_SatV = true);
    virtual HelmholtzEOSMixtureBackend * get_copy(bool generate_SatL_and_SatV = true);
    virtual ~HelmholtzEOSMixtureBackend(){};
    std::string backend_name(void) { return get_backend_string(HEOS_BACKEND_MIX); }
    shared_ptr<ReducingFunction> Reducing;
    shared_ptr<ResidualHelmholtz> residual_helmholtz;
    PhaseEnvelopeData PhaseEnvelope;
    SimpleState hsat_max;
    SsatSimpleState ssat_max;
    SpinodalData spinodal_values;

    bool clear(){
        // Clear the locally cached values for the derivatives of the Helmholtz energy
        // in each component
        for (std::vector<CoolPropFluid>::iterator it = components.begin(); it != components.end(); ++it){
            (*it).EOS().alphar.clear();
            (*it).EOS().alpha0.clear();
        }
        return AbstractState::clear();
    };

    friend class FlashRoutines; // Allows the static methods in the FlashRoutines class to have access to all the protected members and methods of this class
    friend class TransportRoutines; // Allows the static methods in the TransportRoutines class to have access to all the protected members and methods of this class
    friend class MixtureDerivatives; // Allows the static methods in the MixtureDerivatives class to have access to all the protected members and methods of this class
    friend class PhaseEnvelopeRoutines; // Allows the static methods in the PhaseEnvelopeRoutines class to have access to all the protected members and methods of this class
    friend class MixtureParameters; // Allows the static methods in the MixtureParameters class to have access to all the protected members and methods of this class
    friend class CorrespondingStatesTerm; // // Allows the methods in the CorrespondingStatesTerm class to have access to all the protected members and methods of this class

    // Helmholtz EOS backend uses mole fractions
    bool using_mole_fractions(){return true;}
    bool using_mass_fractions(){return false;}
    bool using_volu_fractions(){return false;}
    bool is_pure(){ return components.size() == 1 && !components[0].EOS().pseudo_pure; }
    bool has_melting_line(){ return is_pure_or_pseudopure && components[0].ancillaries.melting_line.enabled();};
    CoolPropDbl calc_melting_line(int param, int given, CoolPropDbl value);
    /// Return a string from the backend for the mixture/fluid
    std::string fluid_param_string(const std::string &);
    
    /// brief Set the reference state based on a string representation
    virtual void set_reference_stateS(const std::string &reference_state);

    /// Set the reference state based on a thermodynamic state point specified by temperature and molar density
    virtual void set_reference_stateD(double T, double rhomolar, double hmolar0, double smolar0);

    /// Set binary mixture floating point parameter
    virtual void set_binary_interaction_double(const std::size_t i, const std::size_t j, const std::string &parameter, const double value);
{'fraction_non_alphanumeric': 0.08083287150661073, 'fraction_numerical': 0.0015834059061040297, 'mean_word_length': 4.402908468776732, 'pattern_counts': {'":': 0, '<': 57, '<?xml version=': 0, '>': 35, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5390327', 'n_tokens_mistral': 3713, 'n_tokens_neox': 3479, 'n_words': 1173}