<jupyter_start><jupyter_text>Define functions<jupyter_code>def res_dict_to_df(d, problem):
    """ Transform result dictionary from SALib to Pandas Dataframe"""
    ind_names = list(d.keys())[:4]
    data = list(d.values())[:4]
    col_names = problem["names"]
    df = pd.DataFrame(data=data, index=ind_names, columns=col_names)
    return df

def get_q(params):
    q = model(**params)[0]
    return q

def get_modelresults(params):
    """ calculate alpha from model output """
    if "deltaT_sub" in params:
        raise BaseException("deltaT_sub cannot be varied when calculating alpha")
    q = []
    bond = []
    deltaT_subs = [1, 10]
    for deltaT_sub in deltaT_subs:
        q.append(model(deltaT_sub=deltaT_sub, **params)[0])
        bond.append(model(deltaT_sub=deltaT_sub, **params)[9]["Bo"])
    grad = np.gradient(q, deltaT_subs)
    alpha = grad.mean()
    bond = sum(bond) / len(bond)
    return alpha, bond

def sensitivity(input_ranges, n_samples=1000):
    """ run the actual sensitivity analysis using sobol/satelli method"""
    # create martrix with input parameters
    problem = {
        "num_vars": len(input_ranges),
        "names": list(input_ranges.keys()),
        "bounds": list(input_ranges.values())
    }

    param_samples = saltelli.sample(problem, n_samples)
    print("Number of Samples, number of input parameters:", param_samples.shape)
    # calculate results vector
    Y = np.zeros([param_samples.shape[0]])
    bond = np.zeros([param_samples.shape[0]])
    for i, X in enumerate(param_samples):
        params = {list(input_ranges.keys())[j] : X[j] for j in range(len(X))}
        modelresults = get_modelresults(params)
        Y[i] = modelresults[0]
        bond[i] = modelresults[1]
    # analyse input matrix and results vector
    d_results = sobol.analyze(problem, Y)
    df = res_dict_to_df(d_results, problem)
    df = df.sort_values("S1", axis=1, ascending=False)
    return param_samples, Y, df, bond

def save_results(scen_name, df, df_samples):
    """ saves results as .pkl and .csv files """
    df.to_pickle("data//pickle//" + scen_name + "_indices.pkl")
    df_samples.to_pickle("data//pickle//" + scen_name + "_samples.pkl")
    df.to_csv("data//" + scen_name + "_indices.csv")
    df_samples.to_csv("data//" + scen_name + "_samples.csv")<jupyter_output><empty_output><jupyter_text>Sensitivity analysis Scenario 1* large input parameter space based on physical plausibility* no coating<jupyter_code>scenario = {"p_steam": [50, 5000],                  # pressure in mbar
            "Theta": [5, 175],                      # contact angle in deg
            "CAH": [1, 90],                         # contact angle hysteresis in deg
            "N_s": [1, 1e6]                         # number of Nucleation sites in 10^9 1/m² 
               }

scen_name = "s1"

param_samples, alphas, df, bond = sensitivity(scenario)

# combine input parameters and results into one dataframe
df_samples = pd.DataFrame(data=param_samples, columns=scenario.keys())
df_samples["alpha"] = alphas
df_samples["bond"] = bond

save_results(scen_name, df, df_samples)<jupyter_output>Number of Samples, number of input parameters: (10000, 4)<jupyter_text>Scenario 2* large input parameter space based on physical plausibility* consider coating<jupyter_code>scenario = {"p_steam": [50, 5000],                  # pressure in mbar
            "Theta": [5, 175],                      # contact angle in deg
            "CAH": [1, 90],                         # contact angle hysteresis in deg
            "k_coat": [0.20, 10],                   # thermal conductivity of the coating in W/(mK)
            "delta_coat": [0.1e-6, 50e-6],          # thickness of the coating in m
            "N_s": [1, 1e6]                         # number of Nucleation sites in 10^9 1/m² 
               }

scen_name = "s2"

param_samples, alphas, df, bond = sensitivity(scenario)

# combine input parameters and results into one dataframe
df_samples = pd.DataFrame(data=param_samples, columns=scenario.keys())
df_samples["alpha"] = alphas
df_samples["bond"] = bond

save_results(scen_name, df, df_samples)<jupyter_output>Number of Samples, number of input parameters: (14000, 6)<jupyter_text>Scenario 3* narrow input parameter space based on rough estimates of measurement uncertainty* no coating<jupyter_code>scenario = {"p_steam": [110, 130],                  # pressure in mbar
            "Theta": [83, 93],                      # contact angle in deg
            "CAH": [24, 44],                        # contact angle hysteresis in deg
            "N_s": [1 , 1e6]                        # number of Nucleation sites in 10^9 1/m² 
               }

scen_name = "s3"

param_samples, alphas, df, bond = sensitivity(scenario)

# combine input parameters and results into one dataframe
df_samples = pd.DataFrame(data=param_samples, columns=scenario.keys())
df_samples["alpha"] = alphas
df_samples["bond"] = bond

save_results(scen_name, df, df_samples)<jupyter_output>Number of Samples, number of input parameters: (10000, 4)<jupyter_text>Scenario 4* narrow input parameter space based on rough estimates of measurement uncertainty* consider good coating (thin, high thermal conductivity)<jupyter_code>scenario = {"p_steam": [110, 130],                  # pressure in mbar
            "Theta": [83, 93],                      # contact angle in deg
            "CAH": [24, 44],                        # contact angle hysteresis in deg
            "k_coat": [5, 10],                      # thermal conductivity of the coating in W/(mK)
            "delta_coat": [0.1e-6, 1e-6],           # thickness of the coating in m
            "N_s": [1, 1e6]                         # number of Nucleation sites in 10^9 1/m² 
               }

scen_name = "s4"

param_samples, alphas, df, bond = sensitivity(scenario)

# combine input parameters and results into one dataframe
df_samples = pd.DataFrame(data=param_samples, columns=scenario.keys())
df_samples["alpha"] = alphas
df_samples["bond"] = bond

save_results(scen_name, df, df_samples)<jupyter_output>Number of Samples, number of input parameters: (14000, 6)
{'fraction_non_alphanumeric': 0.1149200130590924, 'fraction_numerical': 0.02464903689193601, 'mean_word_length': 2.838972431077694, 'pattern_counts': {'":': 23, '<': 17, '<?xml version=': 0, '>': 17, '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}}
{'chain_length': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '474669', 'license': 'MIT', 'n_tokens_mistral': 2048, 'n_tokens_neox': 1876, 'n_words': 528, 'path': 'Sensitivity_DWCmod_calc.ipynb', 'repo_name': 'JSablowski/DWCsensitivity', 'size': '6126'}