turboflow.axial_turbine.performance_analysis module
- class turboflow.axial_turbine.performance_analysis.CascadesNonlinearSystemProblem(geometry, simulation_options)[source]
Bases:
NonlinearSystemProblem
A class representing a nonlinear system problem for cascade analysis.
This class is designed for solving nonlinear systems of equations related to cascade analysis. Derived classes must implement the residual method to evaluate the system of equations for a given set of decision variables.
Additionally, specific problem classes can define the get_jacobian method to compute Jacobians. If this method is not present in the derived class, the solver will revert to using forward finite differences for Jacobian calculations.
Examples
Here’s an example of how to derive from CascadesNonlinearSystemProblem:
class MyCascadeProblem(CascadesNonlinearSystemProblem): def get_values(self, x): # Implement evaluation logic here pass
- Attributes:
- fluidFluidCoolProp_2Phase
An instance of the FluidCoolProp_2Phase class representing the fluid properties.
- resultsdict
A dictionary to store results.
- boundary_conditionsdict
A dictionary containing boundary condition data.
- geometrydict
A dictionary containing geometry-related data.
- model_optionsdict
A dictionary containing options related to the analysis model.
- reference_valuesdict
A dictionary containing reference values for calculations.
- vars_scaled
A dicionary of scaled variables used to evaluate turbine performance.
- vars_real
A dicionary of real variables used to evaluate turbine performance.
Methods
get_values(x)
Evaluate the system of equations for a given set of decision variables.
update_boundary_conditions(operation_point)
Update the boundary conditions of the problem with the provided operation point.
scale_values(variables, to_normalized = False)
Convert values between normalized and real values.
get_initial_guess(initial_guess = None)
Determine the initial guess for the performance analysis based on the given parameters or default values.
compute_heuristic_initial_guess(enthalpy_loss_fractions, eta_tt, eta_ts, Ma_crit)
Compute the heuristic initial guess for the performance analysis based on the given parameters.
print_simulation_summary(solvers)
Print a formatted footer summarizing the performance of all operation points.
print_boundary_conditions(BC)
Print the boundary conditions.
print_operation_points(operation_points)
Prints a summary table of operation points scheduled for simulation.
- residual(x)[source]
Evaluate the system of equations for a given set of decision variables.
- Parameters:
- xarray-like
Vector of decision variables.
- Returns:
- numpy nd.array
An array containing residual values.
- scale_values(variables, to_normalized=True)[source]
Convert values between normalized and real values.
- Parameters:
- variables: dict
A dictionary containing values to be scaled.
- to_real: bool
If True, scale to real values; if False, scale to normalized values.
- Returns:
- An array of values converted between scales.
- update_boundary_conditions(operation_point)[source]
Update the boundary conditions of the problem with the provided operation point.
This method updates the boundary conditions attributes used to evaluate the turbine performance. It also initializes a Fluid object using the ‘fluid_name’ specified in the operation point. The method computes additional properties and reference values like stagnation properties at the inlet, exit static properties, spouting velocity, and reference mass flow rate. These are stored in the object’s internal state for further use in calculations.
- Parameters:
- operation_pointdict
A dictionary containing the boundary conditions defining the operation point. It must include the following keys:
fluid_name (str) : The name of the fluid to be used in the Fluid object.
T0_in (float): The inlet temperature (in Kelvin).
p0_in (float): The inlet pressure (in Pascals).
p_out (float): The outlet pressure (in Pascals).
omega (float): The rotational speed (in rad/s).
alpha_in (float): The inlet flow angle (in degrees).
- Returns:
- None
This method does not return a value but updates the internal state of the object.
- turboflow.axial_turbine.performance_analysis.SOLVER_MAP = {'hybr': "Powell's hybrid", 'lm': 'Lavenberg-Marquardt'}
Available solvers for performance analysis.
- turboflow.axial_turbine.performance_analysis.calculate_enthalpy_residual_1(prop1, scale, h0, Ma, fluid, call, prop2)[source]
- turboflow.axial_turbine.performance_analysis.compute_performance(operation_points, config, out_filename=None, out_dir='output', stop_on_failure=False, export_results=True, logger=None)[source]
Compute and export the performance of each specified operation point to an Excel file.
This function handles two types of input for operation points:
An explicit list of dictionaries, each detailing a specific operation point.
A dictionary where each key has a range of values, representing the cross-product of all possible operation points. It generates the Cartesian product of these ranges internally.
For each operation point, it computes performance based on the provided case data and compiles the results into an Excel workbook with multiple sheets for various data sections.
The function validates the input operation points, and if they are given as ranges, it generates all possible combinations. Performance is computed for each operation point, and the results are then stored in a structured Excel file with separate sheets for each aspect of the data (e.g., overall, plane, cascade, stage, solver, and solution data).
The initial guess variable is used for the first operation point. If given, it must be a dictionary with the following keys:
enthalpy_loss_fractions, which is a list containing the assumed fractions of enthalpy loss that occurs for each cascade.
eta_ts, which is the assumed total-to-static efficiency.
eta_tt, which is the assumed total-to-total efficiency.
Ma_crit, which is the assumed critical mash number.
It can also be a dictionary containing the full set of initial guess that is provided directly to the solver. This require care as the user must have a complete knowledge of the different variables, and setup, of the initial guess that must be given that corresponds with the rest of the configuration file. If the initial guess is not given, it is set to a default value. For subsequent operation points, the function employs a strategy to use the closest previously computed operation point’s solution as the initial guess. This approach is based on the heuristic that similar operation points have similar performance characteristics, which can improve convergence speed and robustness of the solution process. If the solution fails to converge, a set of initial guesses is provided to try other guesses (see get_heuristic_guess_input).
The function returns a list of solver object for each operation point. This contain information on both solver related performance (see psv.NonlinearSystemSolver) and the object of the performance analysis problem (see CascadesNonlinearSystemProblem).
- Parameters:
- operation_pointslist of dict or dict
A list of operation points where each is a dictionary of parameters, or a dictionary of parameter ranges from which operation points will be generated.
- configdict
A dictionary containing necessary configuration options for computing performance at each operation point.
- initial_guessoptional
A dictionary with the required elements to generate an initial guess (see description above).
- out_filenamestr, optional
The name for the output Excel file. If not provided, a default name with a timestamp is generated.
- out_dirstr, optional
The directory where the Excel file will be saved. Defaults to ‘output’.
- stop_on_failure: bool, optional
If true, the analysis stops if the solution fails to converge for an operating point.
- export_resultbool, optional
If true, the result is exported to an excel file.
- Returns:
- list
A List of solver object for each operation point.
- turboflow.axial_turbine.performance_analysis.compute_single_operation_point(operating_point, initial_guess, geometry, simulation_options, solver_options, logger=None)[source]
Compute an operation point for a given set of boundary conditions using multiple solver methods and initial guesses.
The initial guess make take three forms:
None, which generate a default initial guess
A dictionary which generates an initial guess through compute_heuristic_initial_guess. Required elements are:
enthalpy_loss_fractions, which is a list containing the assumed fractions of enthalpy loss that occurs for each cascade.
eta_ts, which is the assumed total-to-static efficiency.
eta_tt, which is the assumed total-to-total efficiency.
Ma_crit, which is the assumed critical mash number.
A dictionary containing the full set of variables needed to evaluate turbine performance. This option require that the user has complete knowledge of what are the required variables, and the setup of the inital guess dictionary for the given configuration.
- Parameters:
- boundary_conditionsdict
A dictionary containing boundary conditions for the operation point.
- initial_guessdict, optional
A dictionary with the required elements to generate an initial guess (see description above).
- configdict
A dictionary containing necessary configuration options for computing performance at the operational point.
- Returns:
- psv.NonlinearSystemSolver
The solution object containing the results of the operation point calculation.
- turboflow.axial_turbine.performance_analysis.find_closest_operation_point(current_op_point, operation_points, solution_data)[source]
Find the solution vector and index of the closest operation point in the historical data.
- Parameters:
- current_op_pointdict
The current operation point we want to compare.
- operation_pointslist of dict
A list of historical operation points to search through.
- solution_datalist
A list of solution vectors corresponding to each operation point.
- Returns:
- tuple
A tuple containing the closest solution vector and the one-based index of the closest operation point.
- turboflow.axial_turbine.performance_analysis.generate_operation_points(performance_map)[source]
Generates a list of dictionaries representing all possible combinations of operation points from a given performance map. The performance map is a dictionary where keys represent parameter names and values are the ranges of values for those parameters. The function ensures that the combinations are generated such that the parameters related to pressure (‘p0_in’ and ‘p_out’) are the last ones to vary, effectively making them the first parameters to sweep through in the operation points.
- Parameters:
- - performance_map (dict): A dictionary with parameter names as keys and
lists of parameter values as values.
- Returns:
- operation_points (list of dict): A list of dictionaries, each representing
a unique combination of parameters from the performance_map.
- turboflow.axial_turbine.performance_analysis.get_heuristic_guess(efficiency_tt, efficiency_ke, mach, boundary_conditions, geometry, fluid, deviation_model)[source]
- turboflow.axial_turbine.performance_analysis.get_initial_guess(initial_guess, problem, boundary_conditions, geometry, fluid, choking_criterion, deviation_model)[source]
- turboflow.axial_turbine.performance_analysis.get_operation_point_distance(point_1, point_2, delta=1e-08)[source]
Calculate the normalized distance between two operation points, with special consideration for angle measurements and prevention of division by zero for very small values.
- Parameters:
- point_1dict
First operation point with numeric values.
- point_2dict
Second operation point with numeric values.
- deltafloat, optional
A small constant to prevent division by zero. Default is 1e-8.
- Returns:
- float
The calculated normalized distance.
- turboflow.axial_turbine.performance_analysis.get_unkown(prop1, scale, h0, Ma, fluid, call, prop2)[source]
call is either cp.DmassP_INPUTS (find Dmass based on a pressure) or cp.PSmass_INPUTS (find p based on a Smass)
- turboflow.axial_turbine.performance_analysis.latin_hypercube_sampling(bounds, n_samples)[source]
Generates samples using Latin Hypercube Sampling.
Parameters: bounds (list of tuples): A list of (min, max) bounds for each variable. n_samples (int): The number of samples to generate.
Returns: np.ndarray: An array of shape (n_samples, n_variables) containing the samples.
- turboflow.axial_turbine.performance_analysis.print_boundary_conditions(BC)[source]
Print the boundary conditions.
This function prints the boundary conditions in a formatted manner. It takes a dictionary BC containing the following keys:
fluid_name (str): Name of the fluid.
alpha_in (float): Flow angle at inlet in degrees.
T0_in (float): Total temperature at inlet in Kelvin.
p0_in (float): Total pressure at inlet in Pascal.
p_out (float): Static pressure at outlet in Pascal.
omega (float): Angular speed in radians per second.
- Parameters:
- BCdict
A dictionary containing the boundary conditions.
- turboflow.axial_turbine.performance_analysis.print_operation_points(operation_points)[source]
Prints a summary table of operation points scheduled for simulation.
This function takes a list of operation point dictionaries, formats them according to predefined specifications, applies unit conversions where necessary, and prints them in a neatly aligned table with headers and units.
- Parameters:
- - operation_points (list of dict): A list where each dictionary contains
key-value pairs representing operation parameters and their corresponding values.
Notes
This function assumes that all necessary keys exist within each operation point dictionary.
The function directly prints the output; it does not return any value.
Unit conversions are hardcoded and specific to known parameters.
If the units of the parameters change or if different parameters are added, the unit conversion logic and field_specs need to be updated accordingly.
- turboflow.axial_turbine.performance_analysis.print_simulation_summary(solvers, logger)[source]
Print a formatted footer summarizing the performance of all operation points.
This function processes a list of solver objects to provide a summary of the performance analysis calculations. It calculates and displays the number of successful points and a summary of simulation tme statistics. Additionally, it lists the indices of failed operation points, if any.
The function is robust against solvers that failed and lack certain attributes like ‘elapsed_time’. In such cases, these solvers are included in the count of failed operation points, but not in the calculation time statistics.
- Parameters:
- solverslist
A list of solver objects. Each solver object should contain attributes related to the calculation of an operation point, such as ‘elapsed_time’ and the ‘solution’ status.
- turboflow.axial_turbine.performance_analysis.validate_operation_point(op_point)[source]
Validates that an operation point has exactly the required fields: ‘fluid_name’, ‘p0_in’, ‘T0_in’, ‘p_out’, ‘alpha_in’, ‘omega’.
- Parameters:
- op_point: dict
A dictionary representing an operation point.
- Returns:
- ValueError: If the dictionary does not contain the required fields or contains extra fields.