def perform_mesh_convergence_study(a_usr_input: dict): study_result = dict() print('Performing mesh convergence study --- START.') for rho_gamma in a_usr_input['rho']: print('rho_gamma = ' + str(rho_gamma)) i = 0 for mesh in a_usr_input['cv_y']: i = i+1 print('mesh = ' + str(i)) # Prepare. current_study = {'mesh': None, 'fields': None, 'coeffs': None, 'solver': None} current_study_name = 'rho_gamma' + str(rho_gamma) + '_' + 'mesh' + str(i) current_study_user_input = a_usr_input.copy() current_study_user_input['rho'] = rho_gamma current_study_user_input['cv_y'] = mesh current_study_user_input['cv_x'] = 2*mesh # For Smith-Hutton problem, to keep the mesh constant, as the domain is twice as long as high. current_study_user_input['number_of_nodes'] = mesh * (2 * mesh) # Perform. current_study['mesh'] = Mesher(current_study_user_input) current_study['mesh'].build_mesh() current_study['fields'] = Fields(current_study_user_input, current_study['mesh']) current_study['fields'].build_velocity() current_study['fields'].build_phi() current_study['fields'].build_convection_strength() current_study['fields'].build_diffusion_strength() current_study['fields'].build_peclet_number() current_study['coeffs'] = DiscretCoeffs(current_study_user_input, current_study['mesh'], current_study['fields']) current_study['coeffs'].build_coeffs() current_study['solver'] = SolverGaussSeidelPhi(current_study_user_input, current_study['mesh'], current_study['fields'], current_study['coeffs']) tic('Solving') current_study['solver'].solve_phi(p_verbose_level=0) toc('Solving') current_study['solver'].timer = timer.copy() if (current_study['solver'].solution_divergence): print(current_study_name + ' - Solution has diverged.') # Save the current study. study_result[current_study_name] = current_study print('Performing mesh convergence study --- END.') return study_result
def perform_numerical_scheme_study(a_usr_input): study_result = dict() print('Performing numerical scheme study --- START.') for scheme in a_usr_input['numerical_scheme']: print('Numerical scheme = ' + scheme) for rho_gamma in a_usr_input['rho']: print('rho_gamma = ' + str(rho_gamma)) # Prepare. current_study = {'mesh': None, 'fields': None, 'coeffs': None, 'solver': None} current_study_name = 'rho_gamma_' + str(rho_gamma) + '_scheme_' + scheme current_study_user_input = a_usr_input.copy() current_study_user_input['numerical_scheme'] = scheme current_study_user_input['rho'] = rho_gamma # Perform. current_study['mesh'] = Mesher(current_study_user_input) current_study['mesh'].build_mesh() current_study['fields'] = Fields(current_study_user_input, current_study['mesh']) current_study['fields'].build_velocity() current_study['fields'].build_phi() current_study['fields'].build_convection_strength() current_study['fields'].build_diffusion_strength() current_study['fields'].build_peclet_number() current_study['coeffs'] = DiscretCoeffs(current_study_user_input, current_study['mesh'], current_study['fields']) current_study['coeffs'].build_coeffs() current_study['solver'] = SolverGaussSeidelPhi(current_study_user_input, current_study['mesh'], current_study['fields'], current_study['coeffs']) tic('Solving') current_study['solver'].solve_phi(p_verbose_level=0) toc('Solving') current_study['solver'].timer = timer.copy() if (current_study['solver'].solution_divergence): print(current_study_name + ' - Solution has diverged.') # Save the current study. study_result[current_study_name] = current_study print('Performing numerical scheme study --- END.') return study_result
from SolverGaussSeidelPsi import SolverGaussSeidelPsi from SolverPhysicalQuantities import SolverPhysicalQuantities from Plotter import Plotter from SolverAnalyticalPsi import SolverAnalyticalPsi from CFDUtils import timer, tic, toc import numpy as np """ Main code for the 1st assignment: Potential flow around a static cylinder. Physical units in International System. """ # Simulation settings. epsilon = 1e-6 # Convergence criteria. phys_prop = PhysicProp('air') tic('Preprocessing') # Build the mesh. mesh = Mesher() mesh.set_control_volumes(a_cv_y=78, a_cv_x=158) mesh.set_cylinder(a_R=1) output_files_name = 'CaseStudy_' n_lengths = 2 mesh.set_domain_size(a_n_Radius_west=-10 * n_lengths, a_n_Radius_east=10 * n_lengths, a_n_Radius_north=5 * n_lengths, a_n_Radius_south=-5 * n_lengths) mesh.build_mesh() # Initialize velocity, pressure, temperature, density, and stream function fields. fields = Fields(mesh, phys_prop) fields.build_v()