def create_pit_branch_entries(cls, net, branch_wo_internals_pit, node_name): """ Function which creates pit branch entries with a specific table. :param net: The pandapipes network :type net: pandapipesNet :param branch_wo_internals_pit: :type branch_wo_internals_pit: :param node_name: :type node_name: :return: No Output. """ branch_wo_internals_pit, node_pit, from_nodes, to_nodes \ = super().create_pit_branch_entries(net, branch_wo_internals_pit, node_name) branch_wo_internals_pit[:, ELEMENT_IDX] = net[ cls.table_name()].index.values branch_wo_internals_pit[:, FROM_NODE] = from_nodes branch_wo_internals_pit[:, TO_NODE] = to_nodes branch_wo_internals_pit[:, TINIT] = (node_pit[from_nodes, TINIT_NODE] + node_pit[to_nodes, TINIT_NODE]) / 2 fluid = get_fluid(net) branch_wo_internals_pit[:, RHO] = fluid.get_density( branch_wo_internals_pit[:, TINIT]) branch_wo_internals_pit[:, ETA] = fluid.get_viscosity( branch_wo_internals_pit[:, TINIT]) branch_wo_internals_pit[:, CP] = fluid.get_heat_capacity( branch_wo_internals_pit[:, TINIT]) branch_wo_internals_pit[:, ACTIVE] = net[cls.table_name()][ cls.active_identifier()].values return branch_wo_internals_pit
def create_pit_node_entries(cls, net, node_pit, node_name): """ Function which creates pit node entries. :param net: The pandapipes network :type net: pandapipesNet :param node_pit: :type node_pit: :return: No Output. """ ft_lookup = get_lookup(net, "node", "from_to") table_nr = get_table_number(get_lookup(net, "node", "table"), cls.table_name()) f, t = ft_lookup[cls.table_name()] junctions = net[cls.table_name()] junction_pit = node_pit[f:t, :] junction_pit[:, :] = np.array([table_nr, 0, L] + [0] * (node_cols - 3)) junction_pit[:, ELEMENT_IDX] = junctions.index.values junction_pit[:, HEIGHT] = junctions.height_m.values junction_pit[:, PINIT] = junctions.pn_bar.values junction_pit[:, TINIT] = junctions.tfluid_k.values junction_pit[:, RHO] = get_fluid(net).get_density(junction_pit[:, TINIT]) junction_pit[:, PAMB] = p_correction_height_air(junction_pit[:, HEIGHT]) junction_pit[:, ACTIVE_ND] = junctions.in_service.values
def create_pit_branch_entries(cls, net, branch_winternals_pit, node_name): """ Function which creates pit branch entries. :param net: The pandapipes network :type net: pandapipesNet :param branch_pit: :type branch_pit: :return: No Output. """ branch_winternals_pit, node_pit, from_nodes, to_nodes\ = super().create_pit_branch_entries(net, branch_winternals_pit, node_name) internal_pipe_number = cls.get_internal_pipe_number(net) node_ft_lookups = get_lookup(net, "node", "from_to") if cls.internal_node_name() in node_ft_lookups: pipe_nodes_from, pipe_nodes_to = node_ft_lookups[cls.internal_node_name()] pipe_nodes_idx = np.arange(pipe_nodes_from, pipe_nodes_to) insert_places = np.repeat(np.arange(len(from_nodes)), internal_pipe_number - 1) from_nodes = np.insert(from_nodes, insert_places + 1, pipe_nodes_idx) to_nodes = np.insert(to_nodes, insert_places, pipe_nodes_idx) branch_winternals_pit[:, ELEMENT_IDX] = np.repeat(net[cls.table_name()].index.values, internal_pipe_number) branch_winternals_pit[:, FROM_NODE] = from_nodes branch_winternals_pit[:, TO_NODE] = to_nodes branch_winternals_pit[:, TINIT] = (node_pit[from_nodes, TINIT_NODE] + node_pit[to_nodes, TINIT_NODE]) / 2 fluid = get_fluid(net) branch_winternals_pit[:, RHO] = fluid.get_density(branch_winternals_pit[:, TINIT]) branch_winternals_pit[:, ETA] = fluid.get_viscosity(branch_winternals_pit[:, TINIT]) branch_winternals_pit[:, CP] = fluid.get_heat_capacity(branch_winternals_pit[:, TINIT]) branch_winternals_pit[:, ACTIVE] = np.repeat(net[cls.table_name()][cls.active_identifier()].values, internal_pipe_number) return branch_winternals_pit, internal_pipe_number
def extract_results(cls, net, options, node_name): placement_table, branch_pit, res_table = cls.prepare_result_tables( net, options, node_name) node_pit = net["_active_pit"]["node"] node_active_idx_lookup = get_lookup(net, "node", "index_active")[node_name] junction_idx_lookup = get_lookup(net, "node", "index")[node_name] from_junction_nodes = node_active_idx_lookup[junction_idx_lookup[net[ cls.table_name()]["from_junction"].values[placement_table]]] to_junction_nodes = node_active_idx_lookup[junction_idx_lookup[net[ cls.table_name()]["to_junction"].values[placement_table]]] from_nodes = branch_pit[:, FROM_NODE].astype(np.int32) to_nodes = branch_pit[:, TO_NODE].astype(np.int32) p_scale = get_net_option(net, "p_scale") fluid = get_fluid(net) v_mps = branch_pit[:, VINIT] t0 = node_pit[from_nodes, TINIT_NODE] t1 = node_pit[to_nodes, TINIT_NODE] mf = branch_pit[:, LOAD_VEC_NODES] vf = branch_pit[:, LOAD_VEC_NODES] / get_fluid(net).get_density( (t0 + t1) / 2) idx_active = branch_pit[:, ELEMENT_IDX] _, v_sum, mf_sum, vf_sum, internal_pipes = \ _sum_by_group(idx_active, v_mps, mf, vf, np.ones_like(idx_active)) if fluid.is_gas: # derived from the ideal gas law p_from = node_pit[from_nodes, PAMB] + node_pit[from_nodes, PINIT] * p_scale p_to = node_pit[to_nodes, PAMB] + node_pit[to_nodes, PINIT] * p_scale numerator = NORMAL_PRESSURE * branch_pit[:, TINIT] normfactor_from = numerator * fluid.get_property("compressibility", p_from) \ / (p_from * NORMAL_TEMPERATURE) normfactor_to = numerator * fluid.get_property("compressibility", p_to) \ / (p_to * NORMAL_TEMPERATURE) v_gas_from = v_mps * normfactor_from v_gas_to = v_mps * normfactor_to mask = ~np.isclose(p_from, p_to) p_mean = np.empty_like(p_to) p_mean[~mask] = p_from[~mask] p_mean[mask] = 2 / 3 * (p_from[mask] ** 3 - p_to[mask] ** 3) \ / (p_from[mask] ** 2 - p_to[mask] ** 2) normfactor_mean = numerator * fluid.get_property("compressibility", p_mean) \ / (p_mean * NORMAL_TEMPERATURE) v_gas_mean = v_mps * normfactor_mean _, _, _, v_gas_mean_sum, nf_from_sum, nf_to_sum, \ internal_pipes = _sum_by_group(idx_active, v_gas_from, v_gas_to, v_gas_mean, normfactor_from, normfactor_to, np.ones_like(idx_active)) v_gas_from_ordered = select_from_pit(from_nodes, from_junction_nodes, v_gas_from) v_gas_to_ordered = select_from_pit(to_nodes, to_junction_nodes, v_gas_to) res_table["v_from_m_per_s"].values[ placement_table] = v_gas_from_ordered res_table["v_to_m_per_s"].values[ placement_table] = v_gas_to_ordered res_table["v_mean_m_per_s"].values[ placement_table] = v_gas_mean_sum / internal_pipes res_table["normfactor_from"].values[ placement_table] = nf_from_sum / internal_pipes res_table["normfactor_to"].values[ placement_table] = nf_to_sum / internal_pipes else: res_table["v_mean_m_per_s"].values[ placement_table] = v_sum / internal_pipes res_table["p_from_bar"].values[placement_table] = node_pit[ from_junction_nodes, PINIT] res_table["p_to_bar"].values[placement_table] = node_pit[ to_junction_nodes, PINIT] res_table["t_from_k"].values[placement_table] = node_pit[ from_junction_nodes, TINIT_NODE] res_table["t_to_k"].values[placement_table] = node_pit[ to_junction_nodes, TINIT_NODE] res_table["mdot_to_kg_per_s"].values[ placement_table] = -mf_sum / internal_pipes res_table["mdot_from_kg_per_s"].values[ placement_table] = mf_sum / internal_pipes res_table["vdot_norm_m3_per_s"].values[ placement_table] = vf_sum / internal_pipes idx_pit = branch_pit[:, ELEMENT_IDX] _, lambda_sum, reynolds_sum, = \ _sum_by_group(idx_pit, branch_pit[:, LAMBDA], branch_pit[:, RE]) res_table["lambda"].values[ placement_table] = lambda_sum / internal_pipes res_table["reynolds"].values[ placement_table] = reynolds_sum / internal_pipes
def calculate_derivatives_hydraulic(cls, net, branch_pit, node_pit, idx_lookups, options): """ Function which creates derivatives. :param net: The pandapipes network :type net: pandapipesNet :param branch_component_pit: :type branch_component_pit: :param node_pit: :type node_pit: :param idx_lookups: :type idx_lookups: :param options: :type options: :return: No Output. """ f, t = idx_lookups[cls.table_name()] branch_component_pit = branch_pit[f:t, :] if branch_component_pit.size == 0: return fluid = get_fluid(net) gas_mode = fluid.is_gas friction_model = options["friction_model"] g_const = GRAVITATION_CONSTANT rho = branch_component_pit[:, RHO] eta = branch_component_pit[:, ETA] d = branch_component_pit[:, D] k = branch_component_pit[:, K] length = branch_component_pit[:, LENGTH] from_nodes = branch_component_pit[:, FROM_NODE].astype(np.int32) to_nodes = branch_component_pit[:, TO_NODE].astype(np.int32) loss_coef = branch_component_pit[:, LC] t_init = (node_pit[from_nodes, TINIT_NODE] + node_pit[to_nodes, TINIT_NODE]) / 2 branch_component_pit[:, TINIT] = t_init v_init = branch_component_pit[:, VINIT] p_init_i = node_pit[from_nodes, PINIT] p_init_i1 = node_pit[to_nodes, PINIT] p_init_i_abs = p_init_i + node_pit[from_nodes, PAMB] p_init_i1_abs = p_init_i1 + node_pit[to_nodes, PAMB] v_init2 = v_init * np.abs(v_init) height_difference = node_pit[from_nodes, HEIGHT] - node_pit[to_nodes, HEIGHT] dummy = length != 0 lambda_pipe, re = calc_lambda(v_init, eta, rho, d, k, gas_mode, friction_model, dummy, options) der_lambda_pipe = calc_der_lambda(v_init, eta, rho, d, k, friction_model, lambda_pipe) branch_component_pit[:, RE] = re branch_component_pit[:, LAMBDA] = lambda_pipe cls.calculate_pressure_lift(net, branch_component_pit, node_pit) pl = branch_component_pit[:, PL] if not gas_mode: branch_component_pit[:, JAC_DERIV_DV] = \ rho / (P_CONVERSION * 2) * (length / d * (der_lambda_pipe * v_init2 + 2 * lambda_pipe * np.abs(v_init)) + 2 * loss_coef * np.abs( v_init)) branch_component_pit[:, LOAD_VEC_BRANCHES] = \ - (-p_init_i_abs + p_init_i1_abs - pl - rho * g_const * height_difference / P_CONVERSION + (length * lambda_pipe / d + loss_coef) / (P_CONVERSION * 2) * rho * v_init2) branch_component_pit[:, JAC_DERIV_DP] = -1 branch_component_pit[:, JAC_DERIV_DP1] = 1 else: # Formulas for gas pressure loss according to laminar version described in STANET 10 # manual, page 1623 # compressibility settings p_m = np.empty_like(p_init_i_abs) mask = p_init_i_abs != p_init_i1_abs p_m[~mask] = p_init_i_abs[~mask] p_m[mask] = 2 / 3 * (p_init_i_abs[mask] ** 3 - p_init_i1_abs[mask] ** 3) \ / (p_init_i_abs[mask] ** 2 - p_init_i1_abs[mask] ** 2) comp_fact = get_fluid(net).get_property("compressibility", p_m) const_lambda = NORMAL_PRESSURE * rho * comp_fact * t_init \ / (NORMAL_TEMPERATURE * P_CONVERSION) const_height = rho * NORMAL_TEMPERATURE / (2 * NORMAL_PRESSURE * t_init * P_CONVERSION) branch_component_pit[:, LOAD_VEC_BRANCHES] = \ -(-p_init_i_abs + p_init_i1_abs - pl + const_lambda * v_init2 * ( lambda_pipe * length / d + loss_coef) * (p_init_i_abs + p_init_i1_abs) ** (-1) - const_height * (p_init_i_abs + p_init_i1_abs) * g_const * height_difference) branch_component_pit[:, JAC_DERIV_DP] = \ -1. - const_lambda * v_init2 * (lambda_pipe * length / d + loss_coef) \ * (p_init_i_abs + p_init_i1_abs) ** (-2) \ - const_height * g_const * height_difference branch_component_pit[:, JAC_DERIV_DP1] = \ 1. - const_lambda * v_init2 * (lambda_pipe * length / d + loss_coef) \ * (p_init_i_abs + p_init_i1_abs) ** (-2) \ - const_height * g_const * height_difference branch_component_pit[:, JAC_DERIV_DV] = \ 2 * const_lambda * (p_init_i_abs + p_init_i1_abs) ** (-1) \ * np.abs(v_init) * lambda_pipe * length / d \ + const_lambda * (p_init_i_abs + p_init_i1_abs) ** (-1) * v_init2 \ * der_lambda_pipe * length / d \ + 2 * const_lambda * (p_init_i_abs + p_init_i1_abs) ** (-1) * np.abs(v_init) \ * loss_coef mass_flow_dv = rho * branch_component_pit[:, AREA] branch_component_pit[:, JAC_DERIV_DV_NODE] = mass_flow_dv branch_component_pit[:, LOAD_VEC_NODES] = mass_flow_dv * v_init
def init_options(net, local_parameters): """ Initializes physical and mathematical constants included in pandapipes. In addition, options for the nonlinear and time-dependent solver are also set. Those are the options that can be set and their default values: - **iter** (int): 10 - If the simulation is terminated after a certain amount of iterations,\ this is the number of iterations. - **tol_p** (float): 1e-4 - The relative tolerance for the pressure. A result is accepted \ if the relative error is smaller than this factor. - **tol_v** (float): 1e-4 - The relative tolerance for the velocity. A result is accepted \ if the relative error is smaller than this factor. - **tol_T** (float): 1e-4 - The relative tolerance for the temperature. A result is \ accepted if the relative error is smaller than this factor. - **tol_res** (float): 1e-3 - The relative tolerance for the residual. A result is accepted\ if the relative error is smaller than this factor. - **ambient_temperature** (float): 293.0 - The assumed ambient temperature for the\ calculation of the barometric formula - **friction_model** (str): "nikuradse" - The friction model that shall be used to identify\ the value for lambda (can be "nikuradse" or "colebrook") - **alpha** (float): 1 - The step width for the Newton iterations. If the Newton steps \ shall be damped, **alpha** can be reduced. See also the **nonlinear_method** \ parameter. - **nonlinear_method** (str): "constant" - The option of how the damping factor **alpha** \ is determined in each iteration. It can be "constant" (i.e. **alpha** is always the\ same in each iteration) or "automatic", in which case **alpha** is adapted \ automatically with respect to the convergence behaviour. - **gas_impl** (str): "pandapipes" - Implementation of the gas model. It can be set to\ "pandapipes" with calculations according to "Handbuch der Gasversorgungstechnik"\ or to "STANET" with calculations according to the STANET reference. - **heat_transfer** (bool): False - Flag to determine if the heat transfer shall be\ calculated. - **only_update_hydraulic_matrix** (bool): False - If True, the system matrix is not \ created in every iteration, but only the data is updated according to a lookup that\ is identified in the first iteration. This speeds up calculation, but has not yet\ been tested extensively. - **check_connectivity** (bool): True - If True, a connectivity check is performed at the\ beginning of the pipeflow and parts of the net that are not connected to external\ grids are set inactive. - **quit_on_inconsistency_connectivity** (bool): False - If True, inconsistencies in the\ connectivity check raise an error, otherwise they are handled. Inconsistencies mean\ that out of service nodes are connected to in service branches. If that is the case\ and the flag is set to False, the connected nodes are activated. :param net: The pandapipesNet for which the options are initialized :type net: pandapipesNet :param local_parameters: Dictionary with local parameters that were passed to the pipeflow call. :type local_parameters: dict :return: No output :Example: >>> init_options(net) """ from pandapipes.pipeflow import pipeflow # the base layer of the options consists of the default options net["_options"] = copy.deepcopy(default_options) excluded_params = {"net", "interactive_plotting", "t_start", "sol_vec", "kwargs"} # the base layer is overwritten and extended by options given by the default parameters of the # pipeflow function definition args_pf = inspect.getfullargspec(pipeflow) pf_func_options = dict(zip(args_pf.args[-len(args_pf.defaults):], args_pf.defaults)) pf_func_options = {k: pf_func_options[k] for k in set(pf_func_options.keys()) - excluded_params} net["_options"].update(pf_func_options) # the third layer is the user defined pipeflow options if "user_pf_options" in net and len(net.user_pf_options) > 0: net["_options"].update(net.user_pf_options) # the last layer is the layer of passeed parameters by the user, it is defined as the local # existing parameters during the pipeflow call which diverges from the default parameters of the # function definition in the second layer params = dict() for k, v in local_parameters.items(): if k in excluded_params or (k in pf_func_options and pf_func_options[k] == v): continue params[k] = v params.update(local_parameters["kwargs"]) net["_options"].update(params) net["_options"]["fluid"] = get_fluid(net).name
def pipeflow_openmodelica_comparison(net, log_results=True, friction_model='colebrook', only_update_hydraulic_matrix=False): pp.pipeflow(net, stop_condition="tol", iter=100, tol_p=1e-7, tol_v=1e-7, friction_model=friction_model, only_update_hydraulic_matrix=only_update_hydraulic_matrix) p_om = net.junction.p_om p_valid = pd.notnull(p_om) p_om = p_om.loc[p_valid] if get_fluid(net).is_gas: if 'pipe' in net: v_diff_from_pipe, v_diff_to_pipe, v_diff_mean_pipe, v_diff_abs_pipe, \ v_mean_pandapipes_pipe, v_om_pipe = retrieve_velocity_gas(net, 'pipe') else: v_diff_abs_pipe = pd.Series() v_om_pipe = pd.Series() v_mean_pandapipes_pipe = pd.Series() v_diff_from_pipe = pd.Series() v_diff_to_pipe = pd.Series() v_diff_mean_pipe = pd.Series() diff_results_v_pipe = pd.DataFrame({ "diff_v_from_pipe": v_diff_from_pipe, "diff_v_to_pipe": v_diff_to_pipe, "diff_v_mean_pipe": v_diff_mean_pipe, "diff_v_abs_pipe": v_diff_abs_pipe }) if 'valve' in net: v_diff_from_valve, v_diff_to_valve, v_diff_mean_valve, v_diff_abs_valve, \ v_mean_pandapipes_valve, v_om_valve = retrieve_velocity_gas(net, 'valve') else: v_diff_abs_valve = pd.Series() v_om_valve = pd.Series() v_mean_pandapipes_valve = pd.Series() v_diff_from_valve = pd.Series() v_diff_to_valve = pd.Series() v_diff_mean_valve = pd.Series() diff_results_v_valve = pd.DataFrame({ "diff_v_from_valve": v_diff_from_valve, "diff_v_to_valve": v_diff_to_valve, "diff_v_mean_valve": v_diff_mean_valve, "diff_v_abs_valve": v_diff_abs_valve }) else: if 'pipe' in net: v_diff_mean_pipe, v_diff_abs_pipe, v_mean_pandapipes_pipe, v_om_pipe = \ retrieve_velocity_liquid(net, element = "pipe") else: v_diff_abs_pipe = pd.Series() v_om_pipe = pd.Series() v_mean_pandapipes_pipe = pd.Series() v_diff_mean_pipe = pd.Series() if 'valve' in net: v_diff_mean_valve, v_diff_abs_valve, v_mean_pandapipes_valve, v_om_pipe = \ retrieve_velocity_liquid(net, element = "valve") else: v_diff_abs_valve = pd.Series() v_om_valve = pd.Series() v_mean_pandapipes_valve = pd.Series() v_diff_mean_valve = pd.Series() diff_results_v_pipe = pd.DataFrame({ "diff_v_mean_pipe": v_diff_mean_pipe, "diff_v_abs_pipe": v_diff_abs_pipe }) diff_results_v_valve = pd.DataFrame({ "diff_v_mean_valve": v_diff_mean_valve, "diff_v_abs_valve": v_diff_abs_valve }) v_diff_abs = v_diff_abs_pipe.append(v_diff_abs_valve, ignore_index=True) v_diff_abs.dropna(inplace=True) p_pandapipes = net.res_junction.p_bar.loc[p_valid].values.astype( np.float64).round(4) p_diff = np.abs(1 - p_pandapipes / p_om) p_diff = pd.Series(p_diff, range(len(p_diff))) v_diff_abs = pd.Series(v_diff_abs, range(len(v_diff_abs))) ''' print("\n p_diff = \n", p_diff) print("\n v_diff_abs = \n", v_diff_abs) print("\n p_diff < 0.01 = \n", p_diff < 0.01) print("\n v_diff_abs < 0.05 = \n", v_diff_abs < 0.05) ''' if log_results: logger.info("p_OM %s" % p_om) logger.info("p_PP %s" % p_pandapipes) logger.info("v_OM_pipe %s" % v_om_pipe) logger.info("v_PP_valve %s" % v_om_valve) logger.info("v_PP_pipe %s" % v_mean_pandapipes_pipe) logger.info("v_PP_valve %s" % v_mean_pandapipes_valve) logger.info("Druckdifferenz: %s" % p_diff) logger.info("Geschwindigkeitsdifferenz Rohr: \n %s" % diff_results_v_pipe) logger.info("Geschwindigkeitsdifferenz Ventil: \n %s" % diff_results_v_valve) return p_diff, v_diff_abs
def pipeflow_openmodelica_comparison(net, log_results=True, friction_model='colebrook', mode='hydraulics', only_update_hydraulic_matrix=False): """ Comparison of the calculations of OpenModelica and pandapipes. :param net: converted OpenModelica network :type net: pandapipesNet :param log_results: :type log_results: bool, True :param friction_model: :type friction_model: str, "colebrook" :param mode: :type mode: str, "nomral" :param only_update_hydraulic_matrix: :type only_update_hydraulic_matrix: bool, False :return: p_diff, v_diff_abs :rtype: one-dimensional ndarray with axis labels """ pp.pipeflow(net, stop_condition="tol", iter=100, tol_p=1e-7, tol_v=1e-7, friction_model=friction_model, mode=mode, only_update_hydraulic_matrix=only_update_hydraulic_matrix) print(net.res_junction) print(net.res_pipe) p_om = net.junction.p_om p_valid = pd.notnull(p_om) p_om = p_om.loc[p_valid] if get_fluid(net).is_gas: if 'pipe' in net: v_diff_from_pipe, v_diff_to_pipe, v_diff_mean_pipe, v_diff_abs_pipe, \ v_mean_pandapipes_pipe, v_om_pipe = retrieve_velocity_gas(net, 'pipe') else: v_diff_abs_pipe = pd.Series() v_om_pipe = pd.Series() v_mean_pandapipes_pipe = pd.Series() v_diff_from_pipe = pd.Series() v_diff_to_pipe = pd.Series() v_diff_mean_pipe = pd.Series() diff_results_v_pipe = pd.DataFrame({ "diff_v_from_pipe": v_diff_from_pipe, "diff_v_to_pipe": v_diff_to_pipe, "diff_v_mean_pipe": v_diff_mean_pipe, "diff_v_abs_pipe": v_diff_abs_pipe }) if 'valve' in net: v_diff_from_valve, v_diff_to_valve, v_diff_mean_valve, v_diff_abs_valve, \ v_mean_pandapipes_valve, v_om_valve = retrieve_velocity_gas(net, 'valve') else: v_diff_abs_valve = pd.Series() v_om_valve = pd.Series() v_mean_pandapipes_valve = pd.Series() v_diff_from_valve = pd.Series() v_diff_to_valve = pd.Series() v_diff_mean_valve = pd.Series() diff_results_v_valve = pd.DataFrame({ "diff_v_from_valve": v_diff_from_valve, "diff_v_to_valve": v_diff_to_valve, "diff_v_mean_valve": v_diff_mean_valve, "diff_v_abs_valve": v_diff_abs_valve }) else: if 'pipe' in net: v_diff_mean_pipe, v_diff_abs_pipe, v_mean_pandapipes_pipe, v_om_pipe = \ retrieve_velocity_liquid(net, element="pipe") if mode != "hydraulics": T_diff_mean_pipe, T_diff_abs_pipe, T_mean_pandapipes_pipe, T_om_pipe = \ retrieve_temperature_liquid(net) else: v_diff_abs_pipe = pd.Series() v_om_pipe = pd.Series() v_mean_pandapipes_pipe = pd.Series() v_diff_mean_pipe = pd.Series() if mode != "hydraulics": T_diff_abs_pipe = pd.Series() T_om_pipe = pd.Series() T_mean_pandapipes_pipe = pd.Series() T_diff_mean_pipe = pd.Series() if 'valve' in net: v_diff_mean_valve, v_diff_abs_valve, v_mean_pandapipes_valve, v_om_valve = \ retrieve_velocity_liquid(net, element="valve") else: v_diff_abs_valve = pd.Series() v_om_valve = pd.Series() v_mean_pandapipes_valve = pd.Series() v_diff_mean_valve = pd.Series() diff_results_v_pipe = pd.DataFrame({ "diff_v_mean_pipe": v_diff_mean_pipe, "diff_v_abs_pipe": v_diff_abs_pipe }) diff_results_v_valve = pd.DataFrame({ "diff_v_mean_valve": v_diff_mean_valve, "diff_v_abs_valve": v_diff_abs_valve }) v_diff_abs = v_diff_abs_pipe.append(v_diff_abs_valve, ignore_index=True) v_diff_abs.dropna(inplace=True) p_pandapipes = net.res_junction.p_bar.loc[p_valid].values.astype( np.float64).round(4) p_diff = np.abs(1 - p_pandapipes / p_om) p_diff = pd.Series(p_diff, range(len(p_diff))) v_diff_abs = pd.Series(v_diff_abs, range(len(v_diff_abs))) ''' print("\n p_diff = \n", p_diff) print("\n v_diff_abs = \n", v_diff_abs) print("\n p_diff < 0.01 = \n", p_diff < 0.01) print("\n v_diff_abs < 0.05 = \n", v_diff_abs < 0.05) ''' if log_results: logger.info("p_om %s" % p_om) logger.info("p_PP %s" % p_pandapipes) logger.info("v_om_pipe %s" % v_om_pipe) logger.info("v_PP_valve %s" % v_om_valve) logger.info("v_PP_pipe %s" % v_mean_pandapipes_pipe) logger.info("v_PP_valve %s" % v_mean_pandapipes_valve) logger.info("pressure difference: %s" % p_diff) logger.info("velocity difference pipe: \n %s" % diff_results_v_pipe) logger.info("velocity difference valve: \n %s" % diff_results_v_valve) if mode == "hydraulics": return p_diff, v_diff_abs else: return p_diff, v_diff_abs, T_diff_mean_pipe
def pipeflow_stanet_comparison(net, log_results=True, friction_model='nikuradse', only_update_hydraulic_matrix=False, **kwargs): """ :param net: :type net: :param log_results: :type log_results: :param plot_net: :type plot_net: :param friction_model: :type friction_model: :param only_update_hydraulic_matrix: :type only_update_hydraulic_matrix: :return: :rtype: """ pandapipes.pipeflow( net, mode='hydraulics', stop_condition="tol", iter=100, tol_p=1e-7, tol_v=1e-7, friction_model=friction_model, only_update_hydraulic_matrix=only_update_hydraulic_matrix, **kwargs) p_stanet = net.junction.p_stanet p_valid = pd.notnull(p_stanet) p_stanet = p_stanet.loc[p_valid] if get_fluid(net).is_gas: if 'pipe' in net: v_diff_from_pipe, v_diff_to_pipe, v_diff_mean_pipe, v_diff_abs_pipe, \ v_mean_pandapipes_pipe, v_stanet_pipe = retrieve_velocity_gas(net, 'pipe') else: v_diff_abs_pipe = pd.Series(dtype="float64") v_stanet_pipe = pd.Series(dtype="float64") v_mean_pandapipes_pipe = pd.Series(dtype="float64") v_diff_from_pipe = pd.Series(dtype="float64") v_diff_to_pipe = pd.Series(dtype="float64") v_diff_mean_pipe = pd.Series(dtype="float64") diff_results_v_pipe = pd.DataFrame({ "diff_v_from_pipe": v_diff_from_pipe, "diff_v_to_pipe": v_diff_to_pipe, "diff_v_mean_pipe": v_diff_mean_pipe, "diff_v_abs_pipe": v_diff_abs_pipe }) if 'valve' in net: v_diff_from_valve, v_diff_to_valve, v_diff_mean_valve, v_diff_abs_valve, \ v_mean_pandapipes_valve, v_stanet_valve = retrieve_velocity_gas(net, 'valve') else: v_diff_abs_valve = pd.Series(dtype="float64") v_stanet_valve = pd.Series(dtype="float64") v_mean_pandapipes_valve = pd.Series(dtype="float64") v_diff_from_valve = pd.Series(dtype="float64") v_diff_to_valve = pd.Series(dtype="float64") v_diff_mean_valve = pd.Series(dtype="float64") diff_results_v_valve = pd.DataFrame({ "diff_v_from_valve": v_diff_from_valve, "diff_v_to_valve": v_diff_to_valve, "diff_v_mean_valve": v_diff_mean_valve, "diff_v_abs_valve": v_diff_abs_valve }) else: if 'pipe' in net: v_diff_mean_pipe, v_diff_abs_pipe, v_mean_pandapipes_pipe, v_stanet_pipe = \ retrieve_velocity_liquid(net, 'pipe') else: v_diff_abs_pipe = pd.Series(dtype="float64") v_stanet_pipe = pd.Series(dtype="float64") v_mean_pandapipes_pipe = pd.Series(dtype="float64") v_diff_mean_pipe = pd.Series(dtype="float64") if 'valve' in net: v_diff_mean_valve, v_diff_abs_valve, v_mean_pandapipes_valve, v_stanet_valve = \ retrieve_velocity_liquid(net, 'valve') else: v_diff_abs_valve = pd.Series(dtype="float64") v_stanet_valve = pd.Series(dtype="float64") v_mean_pandapipes_valve = pd.Series(dtype="float64") v_diff_mean_valve = pd.Series(dtype="float64") diff_results_v_pipe = pd.DataFrame({ "diff_v_mean_pipe": v_diff_mean_pipe, "diff_v_abs_pipe": v_diff_abs_pipe }) diff_results_v_valve = pd.DataFrame({ "diff_v_mean_valve": v_diff_mean_valve, "diff_v_abs_valve": v_diff_abs_valve }) p_pandapipes = net.res_junction.p_bar.loc[p_valid].values p_diff = np.abs(1 - p_pandapipes / p_stanet) v_diff_abs = v_diff_abs_pipe.append(v_diff_abs_valve, ignore_index=True) v_diff_abs.dropna(inplace=True) # Avoiding division by zero if log_results: logger.info("p_sta %s" % p_stanet) logger.info("p_PP %s" % p_pandapipes) logger.info("v_sta_pipe %s" % v_stanet_pipe) logger.info("v_sta_valve %s" % v_stanet_valve) logger.info("v_PP_pipe %s" % v_mean_pandapipes_pipe) logger.info("v_PP_valve %s" % v_mean_pandapipes_valve) logger.info("Druckdifferenz: %s" % p_diff) logger.info("Geschwindigkeitsdifferenz Rohr: \n %s" % diff_results_v_pipe) logger.info("Geschwindigkeitsdifferenz Ventil: \n %s" % diff_results_v_valve) return p_diff, v_diff_abs