<commit_before>import numpy as np
import CoolProp as CP
from copy import copy
from scipy.optimize import newton
from prf.state import *


__all__ = ['Point', 'n_exp', 'head_pol', 'eff_pol', 'head_isen',
           'eff_isen', 'schultz_f', 'head_pol_schultz', 'eff_pol_schultz',
           'convert_to_base_units']


class Point:
    @convert_to_base_units
    def __init__(self, *args, **kwargs):
        # TODO create dictionary with optional inputs
        self.suc = kwargs.get('suc')

        try:
            self.speed = kwargs['speed']
            if 'flow_m' not in kwargs:
                self.flow_v = kwargs['flow_v']
                self.flow_m = self.flow_v * self.suc.rhomass()
            else:
                self.flow_m = kwargs['flow_m']
                self.flow_v = self.flow_m / self.suc.rhomass()
        except KeyError as err:
            raise Exception('Argument not provided', err.args[0]) from err

        self.disch = kwargs.get('disch')
        self.head = kwargs.get('head')
        self.eff = kwargs.get('eff')
        self.power = kwargs.get('power')
        self.volume_ratio = kwargs.get('volume_ratio')

        if self.suc and self.disch is not None:
            self.calc_from_suc_disch(self.suc, self.disch)
        elif self.suc and self.head and self.eff is not None:
            self.calc_from_suc_head_eff(self.suc, self.head, self.eff)
        elif self.suc and self.head and self.power is not None:
            self.calc_from_suc_head_power(self.suc, self.head, self.power)
        elif self.suc and self.eff and self.volume_ratio is not None:
            self.calc_from_suc_eff_vol_ratio(self.suc, self.eff, self.volume_ratio)
        else:
            raise KeyError('Argument not provided')

        if self.volume_ratio is None:
            self.volume_ratio = self.suc.rhomass() / self.disch.rhomass()

        self.mach_comparison = kwargs.get('mach_comparison')
        self.reynolds_comparison = kwargs.get('reynolds_comparison')
        self.volume_ratio_comparison = kwargs.get('volume_ratio_comparison')

    def __repr__(self):
        return (
            'Point: '
            + '\nVolume flow: {:10.5} m^3 / kg'.format(self.flow_v)
            + '\nHead       : {:10.5} J / kg.K'.format(self.head)
            + '\nEfficiency : {:10.5} %'.format(100 * self.eff)
        )

    def calc_from_suc_disch(self, suc, disch):
        self.head = head_pol_schultz(suc, disch)
        self.eff = eff_pol_schultz(suc, disch)
        self.power = power(self.flow_m, self.head, self.eff)

    def calc_from_suc_head_eff(self, suc, head, eff):
        """Point from suction, head and efficiency.

        This function will construct a point given its suction, head and
        efficiency. Discharge state is calculated by an iterative process
        where the discharge pressure is initially defined based on an
        isentropic compression. After defining the pressure, polytropic
        head is calculated and compared with the given head. A new pressure
        is defined and the process is repeated.

        Parameters
        ----------
        suc : state
            Suction state.
        head : float
            Polytropic head.
        eff : float
            Polytropic efficiency.

        Returns
        -------

        """<commit_msg>Refact.<commit_after>import numpy as np
import CoolProp as CP
from copy import copy
from scipy.optimize import newton
from prf.state import *


__all__ = ['Point', 'n_exp', 'head_pol', 'eff_pol', 'head_isen',
           'eff_isen', 'schultz_f', 'head_pol_schultz', 'eff_pol_schultz',
           'convert_to_base_units']


class Point:
    @convert_to_base_units
    def __init__(self, *args, **kwargs):
        # TODO create dictionary with optional inputs
        self.suc = kwargs.get('suc')

        try:
            self.speed = kwargs['speed']
            if 'flow_m' not in kwargs:
                self.flow_v = kwargs['flow_v']
                self.flow_m = self.flow_v * self.suc.rhomass()
            else:
                self.flow_m = kwargs['flow_m']
                self.flow_v = self.flow_m / self.suc.rhomass()
        except KeyError as err:
            raise Exception('Argument not provided', err.args[0]) from err

        self.disch = kwargs.get('disch')
        self.head = kwargs.get('head')
        self.eff = kwargs.get('eff')
        self.power = kwargs.get('power')
        self.volume_ratio = kwargs.get('volume_ratio')

        if self.suc and self.disch is not None:
            self.calc_from_suc_disch(self.suc, self.disch)
        elif self.suc and self.head and self.eff is not None:
            self.calc_from_suc_head_eff(self.suc, self.head, self.eff)
        elif self.suc and self.head and self.power is not None:
            self.calc_from_suc_head_power(self.suc, self.head, self.power)
        elif self.suc and self.eff and self.volume_ratio is not None:
            self.calc_from_suc_eff_vol_ratio(self.suc, self.eff, self.volume_ratio)
        else:
            raise KeyError('Argument not provided')

        if self.volume_ratio is None:
            self.volume_ratio = self.suc.rhomass() / self.disch.rhomass()

        self.mach_comparison = kwargs.get('mach_comparison')
        self.reynolds_comparison = kwargs.get('reynolds_comparison')
        self.volume_ratio_comparison = kwargs.get('volume_ratio_comparison')

    def __repr__(self):
        return (
            'Point: '
            + '\n Volume flow: {:10.5} m^3 / kg'.format(self.flow_v)
            + '\n Head       : {:10.5} J / kg.K'.format(self.head)
            + '\n Efficiency : {:10.5} %'.format(100 * self.eff)
        )

    def calc_from_suc_disch(self, suc, disch):
        self.head = head_pol_schultz(suc, disch)
        self.eff = eff_pol_schultz(suc, disch)
        self.power = power(self.flow_m, self.head, self.eff)

    def calc_from_suc_head_eff(self, suc, head, eff):
        """Point from suction, head and efficiency.

        This function will construct a point given its suction, head and
        efficiency. Discharge state is calculated by an iterative process
        where the discharge pressure is initially defined based on an
        isentropic compression. After defining the pressure, polytropic
        head is calculated and compared with the given head. A new pressure
        is defined and the process is repeated.

        Parameters
        ----------
        suc : state
            Suction state.
        head : float
            Polytropic head.
        eff : float
            Polytropic efficiency.

        Returns
        -------

        """
{'fraction_non_alphanumeric': 0.10388628459095721, 'fraction_numerical': 0.004234084379252987, 'mean_word_length': 2.148024750118991, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '290185', 'n_tokens_mistral': 2075, 'n_tokens_neox': 1973, 'n_words': 523}