def get_stages(project_path, n_stages): """ Gets all construction stages :param project_path: :param n_stages: :return: """ parameter_file_names = [ os.path.join(project_path, 'ProjectParameters_stage' + str(i + 1) + '.json') for i in range(n_stages) ] # set stage parameters parameters_stages = [None] * n_stages os.chdir(project_path) for idx, parameter_file_name in enumerate(parameter_file_names): with open(parameter_file_name, 'r') as parameter_file: parameters_stages[idx] = Kratos.Parameters(parameter_file.read()) model = Kratos.Model() stages = [ analysis.GeoMechanicsAnalysis(model, stage_parameters) for stage_parameters in parameters_stages ] return stages
def run_kratos(file_path): """ Runs 1 stage in kratos :param file_path: :return: """ parameter_file_name = os.path.join(file_path, 'ProjectParameters.json') os.chdir(file_path) with open(parameter_file_name, 'r') as parameter_file: parameters = Kratos.Parameters(parameter_file.read()) model = Kratos.Model() simulation = analysis.GeoMechanicsAnalysis(model, parameters) simulation.Run() return simulation
def test_benchmark1_4(self): """ test 1D consolidation on elastic soil. :return: """ from analytical_solutions import calculate_1D_consolidation # define number of stages n_stages = 11 # get the parameter file names for all stages test_name = '1D-Consolidation_all_stages' file_path = test_helper.get_file_path(os.path.join('.', test_name)) parameter_file_names = [ os.path.join(file_path, 'ProjectParameters_stage' + str(i + 1) + '.json') for i in range(n_stages) ] # set stage parameters parameters_stages = [None] * n_stages os.chdir(file_path) for idx, parameter_file_name in enumerate(parameter_file_names): with open(parameter_file_name, 'r') as parameter_file: parameters_stages[idx] = Kratos.Parameters( parameter_file.read()) model = Kratos.Model() stages = [ analysis.GeoMechanicsAnalysis(model, stage_parameters) for stage_parameters in parameters_stages ] # run stages and get water pressure results per stage stage_water_pressure = [None] * n_stages for idx, stage in enumerate(stages): stage.Run() stage_water_pressure[idx] = test_helper.get_water_pressure(stage) # get y coords of all the nodes coords = test_helper.get_nodal_coordinates(stages[0]) y_coords = [coord[1] + 1 for coord in coords] # calculate analytical solution for all stages and calculate the error sample_height = 1 t_vs = [0.01, 0.02, 0.05, 0.1, 0.2, 0.5, 1.0, 2.0, 5.0, 10.0] rmse_stages = [None] * (n_stages - 1) for idx, t_v in enumerate(t_vs): rel_p_stages = [ calculate_1D_consolidation(y_coord, sample_height, t_v) * -1 for y_coord in y_coords ] errors_stage = [ stage_water_pressure[idx + 1][node_idx] - rel_p for node_idx, rel_p in enumerate(rel_p_stages) ] rmse_stages[idx] = (sum([error**2 for error in errors_stage]) / len(errors_stage))**0.5 # assert if average error in all stages is below 1 percent accuracy = 0.01 for rmse_stage in rmse_stages: self.assertLess(rmse_stage, accuracy)