# -*- coding: cp1250 -*-
## databaze_materialu

import numpy as np

class materialy:
    def tyce(self, Temp, material, tloustka):
        tloustka_materialu = []
        #SA-307, ASME II Part D - 2010:
        if material == "SA-307":
            teploty = [0, 65, 100, 125, 150, 175, 200, 225, 250]
            S_ = [48.3, 48.3, 48.3, 48.3, 48.3, 48.3, 48.3, 48.3, 48.3]
            material_info = ["SA-307 tyc(sroub)","ASME II Part D - 2010"]
            tloustka_materialu.append(True)
            tloustka_materialu.append("tloustka materialu tyce")

        #SA-320, ASME II Part D - 2010:
        elif material == "SA-320":
            teploty = [0, 65, 100, 125, 150, 175, 200, 225, 250, 275]
            if tloustka < 64.:
                S_ = [172, 172, 172, 172, 172, 172, 172, 172, 172, 172] # Rp02 pro material do 60 mm
                tloustka_materialu.append(True)
                tloustka_materialu.append("tloustka materialu tyce")
            else:
                tloustka_materialu.append(False)
                tloustka_materialu.append("tloustka materialu tyce")
                
            material_info = ["SA-320 L7A tyc(sroub)","ASME II Part D - 2010"]

        #SA-540, ASME II Part D - 2010:
        elif material == "SA-540":
            teploty = [0, 65, 100, 125, 150, 175, 200, 225, 250, 275]
            if tloustka < 100.:
                S_ = [159, 159, 159, 159, 159, 159, 159, 159, 159, 159] # Rp02 pro material do 60 mm
                tloustka_materialu.append(True)
                tloustka_materialu.append("tloustka materialu tyce")
            else:
                tloustka_materialu.append(False)
                tloustka_materialu.append("tloustka materialu tyce")

            material_info = ["SA-540 B22 tyc(sroub)","ASME II Part D - 2010"]

        else:
            pass
            
        Sb = np.interp(Temp, teploty, S_) # lineární interpolace
        material_info_sroubu = material_info
        
        return Sb, material_info_sroubu, tloustka_materialu           

    def plast(self, Temp, material, tloustka):
        tloustka_materialu = []
        #SA-285, ASME II Part D - 2010:
        if material == "SA-285":
            teploty = [0, 65, 100, 125, 150, 200, 250, 300, 325]
            S_ = [108., 108., 108., 108., 108., 108., 108., 107., 104.]
            material_info = ["SA-334-C plech","ASME II Part D - 2010"]
            tloustka_materialu.append(True)
            tloustka_materialu.append("tloustka materialu plaste")

        #SA-334, ASME II Part D - 2010:
        if material == "SA-334":
            teploty = [0, 65, 100, 125, 150, 200, 250, 300, 325]
            S_ = [92.4, 92.4, 92.4, 92.4, 92.4, 92.4, 92.4, 90.8, 88.7]
            material_info = ["SA-334-1 plech","ASME II Part D - 2010"]
            tloustka_materialu.append(True)
            tloustka_materialu.append("tloustka materialu plaste")
            
        #SA-515, ASME II Part D - 2010:
        if material == "SA-515":
            teploty = [0, 65, 100, 125, 150, 200, 250, 300, 325]
            S_ = [128, 128, 128, 128, 128, 128, 128, 125, 122]
            material_info = ["SA-515-65 plech","ASME II Part D - 2010"]
            tloustka_materialu.append(True)
            tloustka_materialu.append("tloustka materialu plaste")
            
        #SA-662, ASME II Part D - 2010:
        if material == "SA-662":
            teploty = [0, 65, 100, 125, 150, 200, 250, 300, 325]
            S_ = [138, 138, 138, 138, 138, 138, 138, 138, 138]
            material_info = ["SA-662-C plech","ASME II Part D - 2010"]
            tloustka_materialu.append(True)
            tloustka_materialu.append("tloustka materialu plaste")
            
        Sn = np.interp(Temp, teploty, S_) # lineární interpolace
        material_info_sroubu = material_info
        
        return Sn, material_info_sroubu, tloustka_materialu
    
    def priruba(self, Temp, material, tloustka):
        tloustka_materialu = []

        #SA-105, ASME II Part D - 2010:
        if material == "SA-105":
            teploty = [0, 65, 100, 125, 150, 200, 250, 300, 325]
            S_ = [135, 135, 135, 135, 135, 137, 132, 126, 122]
            material_info = ["SA-662-C forging","ASME II Part D - 2010"]
            tloustka_materialu.append(True)
            tloustka_materialu.append("tloustka materialu priruby")

        #SA-182, ASME II Part D - 2010:
        if material == "SA-182":
            teploty = [0, 65, 100, 125, 150, 200, 250, 300, 325]
            S_ = [118, 118, 115, 114, 114, 114, 114, 113, 112]
            material_info = ["SA-182-F2 forging","ASME II Part D - 2010"]
            tloustka_materialu.append(True)
            tloustka_materialu.append("tloustka materialu priruby")

        #SA-351, ASME II Part D - 2010:
        if material == "SA-351":
            teploty = [0, 65, 100, 125, 150, 200, 250, 300, 325]
            S_ = [138, 134, 130, 126, 122, 119, 118, 115, 114]
            material_info = ["SA-351-CF3 forging","ASME II Part D - 2010"]
            tloustka_materialu.append(True)
            tloustka_materialu.append("tloustka materialu priruby")
            
        Sf = np.interp(Temp, teploty, S_) # lineární interpolace
        material_info_sroubu = material_info
        
        return Sf, material_info_sroubu, tloustka_materialu

    def tesneni(self, material_tesneni):
        beta_2 = 0 # if beta_2 = 1 -> b = w/8
        w_min = 0.
        if material_tesneni == "pryz_bez_tkaniva_pod_75" or material_tesneni == "pryz_bez_podilu_azbest_vlakna_pod_75":
            typ_tesneni = 1
            m = 0.5
            y = 0.
        elif material_tesneni == "pryz_bez_tkaniva_nad_75" or material_tesneni == "pryz_bez_podilu_azbest_vlakna_nad_75":
            typ_tesneni = 1
            m = 1.
            y = 1.4
        elif material_tesneni == "azbest_s_pojivem_tl3.2":
            typ_tesneni = 3 # azbest obsahuje oxidy železa + křemík atd.
            m = 2.0
            y = 11.0
        elif material_tesneni == "azbest_s_pojivem_tl1.6":
            typ_tesneni = 3 # azbest obsahuje oxidy železa + křemík atd.
            m = 2.75
            y = 25.5
        elif material_tesneni == "azbest_s_pojivem_tl0.8":
            typ_tesneni = 3 # azbest obsahuje oxidy železa + křemík atd.
            m = 3.5
            y = 44.8
        elif material_tesneni == "pryz_s_bavlnenou_vlozkou":
            typ_tesneni = 1
            m = 1.25
            y = 2.8
        elif material_tesneni == "pryz_s_azbest_tkanivem_trivrstvy":
            typ_tesneni = 3
            m = 2.25
            y = 15.2
        elif material_tesneni == "pryz_s_azbest_tkanivem_dvouvrstvy":
            typ_tesneni = 3
            m = 2.5
            y = 20.0
        elif material_tesneni == "pryz_s_azbest_tkanivem_jednovrstvy":
            typ_tesneni = 3
            m = 2.75
            y = 25.5
        elif material_tesneni == "rostlina_vlakna":
            typ_tesneni = 1
            m = 1.75
            y = 7.6
            w_min = 10.
        elif material_tesneni == "spir_vinute_kovove_uhlikova":
            typ_tesneni = 2
            m = 2.5
            y = 69.0
        elif material_tesneni == "spir_vinute_kovove_korozivzdorna/monel":
            typ_tesneni = 2
            m = 3.
            y = 69.
        elif material_tesneni == "vlnity_kov_mekky_hlinik":
            typ_tesneni = 2
            m = 2.5
            y = 20.
        elif material_tesneni == "vlnity_kov_mekka_med/mosaz":
            typ_tesneni = 2
            m = 2.75
            y = 25.5
        elif material_tesneni == "vlnity_kov_zelezo/mekka_ocel":
            typ_tesneni = 2
            m = 3.
            y = 31.
        elif material_tesneni == "vlnity_kov_monel/ocel4-6%chromu":
            typ_tesneni = 2
            m = 3.25
            y = 37.9
        elif material_tesneni == "vlnity_kov_korozivzdorna":
            typ_tesneni = 2
            m = 3.5
            y = 44.8
        elif material_tesneni == "vlnity_kov_obal_mekky_hlinik":
            typ_tesneni = 2
            m = 2.75
            y = 25.5
        elif material_tesneni == "vlnity_kov_obal_mekka_med/mosaz":
            typ_tesneni = 2
            m = 3.
            y = 31.
        elif material_tesneni == "vlnity_kov_obal_zelezo/mekka_ocel":
            typ_tesneni = 2
            m = 3.25
            y = 37.9
        elif material_tesneni == "vlnity_kov_obal_monel/ocel4-6%chromu":
            typ_tesneni = 2
            m = 3.5
            y = 44.8
        elif material_tesneni == "vlnity_kov_obal_korozivzdorna":
            typ_tesneni = 2
            m = 3.75
            y = 52.4
        elif material_tesneni == "ploche_kovove_mekky_hlinik":
            typ_tesneni = 3
            m = 3.25
            y = 37.9
        elif material_tesneni == "ploche_kovove_mekka_med/mosaz":
            typ_tesneni = 3
            m = 3.5
            y = 44.8
        elif material_tesneni == "ploche_kovove_zelezo/mekka_ocel":
            typ_tesneni = 3
            m = 3.75
            y = 52.4
        elif material_tesneni == "ploche_kovove_monel":
            typ_tesneni = 3
            m = 3.5
            y = 55.1
        elif material_tesneni == "ploche_kovove_ocel4-6%chromu":
            typ_tesneni = 3
            m = 3.75
            y = 62.0
        elif material_tesneni == "ploche_kovove_korozivzdorna":
            typ_tesneni = 3
            m = 3.75
            y = 62.0
        elif material_tesneni == "hrebenove_mekky_hlinik":
            typ_tesneni = 2
            m = 3.25
            y = 37.9
        elif material_tesneni == "hrebenove_mekka_med/mosaz":
            typ_tesneni = 2
            m = 3.5
            y = 44.8
        elif material_tesneni == "hrebenove_zelezo/mekka_ocel":
            typ_tesneni = 2
            m = 3.75
            y = 52.4
        elif material_tesneni == "hrebenove_monel/ocel4-6%chromu":
            typ_tesneni = 2
            m = 3.75
            y = 62.0
        elif material_tesneni == "hrebenove_korozivzdorna":
            typ_tesneni = 2
            m = 4.25
            y = 69.5
            w_min = 10.
        elif material_tesneni == "plne_ploche_kovove_mekka_med/mosaz":
            typ_tesneni = 3
            m = 4.0
            y = 60.6
        elif material_tesneni == "plne_ploche_kovove_zelezo/mekka_ocel":
            typ_tesneni = 3
            m = 4.75
            y = 89.5
            w_min = 6.
        elif material_tesneni == "plne_ploche_kovove_monel":
            typ_tesneni = 3
            m = 5.5
            y = 124.
        elif material_tesneni == "plne_ploche_kovove_ocel4-6%chromu":
            typ_tesneni = 3
            m = 5.0
            y = 150.
        elif material_tesneni == "plne_ploche_kovove_korozivzdorna":
            typ_tesneni = 3
            m = 6.5
            y = 179.
        elif material_tesneni == "prstencove_zelezo/mekka_ocel":
            typ_tesneni = 4
            m = 5.5
            y = 124.
            beta_2 = 1
        elif material_tesneni == "prstencove_monel/ocel4-6%chromu":
            typ_tesneni = 4
            m = 6.0
            y = 150.
            beta_2 = 1
        elif material_tesneni == "prstencove_korozivzdorna":
            typ_tesneni = 4
            m = 6.5
            y = 179.
            beta_2 = 1
        elif material_tesneni == "pryz_0kr_pod_75":
            typ_tesneni = 4
            m = 0.25
            y = 0.7
        elif material_tesneni == "pryz_0kr_nad_75":
            typ_tesneni = 4
            m = 0.25
            y = 1.4
        elif material_tesneni == "pryz_pravouhle_pod_75":
            typ_tesneni = 4
            m = 0.25
            y = 1.0
        elif material_tesneni == "pryz_pravouhle_nad_75":
            typ_tesneni = 4
            m = 0.25
            y = 2.8
        elif material_tesneni == "pryz_T_pod_75":
            typ_tesneni = 4
            m = 0.25
            y = 1.0
        elif material_tesneni == "pryz_T_nad_75":
            typ_tesneni = 4
            m = 0.25
            y = 2.8
        else:
            pass
        
        return m, y, w_min, beta_2
