def get_parameters(folder): parameters = {} for xml_file in glob.glob(os.path.join(folder, "*.xml")): if 'report' in xml_file: continue try: config = read_config(xml_file) initial_data_parameters = get_xml_node( config, "config.fvm.initialData.parameters") for initial_data_parameter in initial_data_parameters.getElementsByTagName( "parameter"): name = get_in_xml(initial_data_parameter, "name") length = int(get_in_xml(initial_data_parameter, "length")) if length == 1: value = float(get_in_xml(initial_data_parameter, "value")) parameters[name] = value print(parameters) except Exception as e: print(e) return parameters
number_of_config_files = int(samples) // args.number_of_samples_per_run for n in range(number_of_config_files): sample_start = n * args.number_of_samples_per_run sample_end = (n + 1) * args.number_of_samples_per_run outfolder = f"sample_{sample_start}_{sample_end}" os.mkdir(outfolder) set_in_xml(config, "config.uq.samples", args.number_of_samples_per_run) try: set_in_xml(config, "config.uq.sampleStart", sample_start) except: uq_node = get_xml_node(config, 'config.uq') sample_start_node = config.createElement("sampleStart") sample_start_text = config.createTextNode(str(sample_start)) sample_start_node.appendChild(sample_start_text) uq_node.appendChild(sample_start_node) python_file = get_in_xml(config, "config.initialData.python") shutil.copyfile( os.path.join(os.path.dirname(args.config), python_file), os.path.join(outfolder, python_file)) with open(os.path.join(outfolder, os.path.basename(args.config)),
os.makedirs(perturbation_folder, exist_ok=True) for m, resolution in enumerate(args.resolutions): config = read_config(args.config) resolution_folder = f"{perturbation_folder}/N{resolution}" os.makedirs(resolution_folder, exist_ok=True) sample = samples[m] set_in_xml(config, "config.uq.samples", str(sample)) set_in_xml(config, "config.fvm.grid.dimension", f"{resolution} {resolution} 1") python_file = get_in_xml(config, "config.initialData.python") initial_data_parameters = get_xml_node( config, "config.initialData.parameters") for initial_data_parameter in initial_data_parameters.getElementsByTagName( "parameter"): name = get_in_xml(initial_data_parameter, "name") if name == "epsilon": set_in_xml(initial_data_parameter, "value", perturbation) shutil.copyfile( os.path.join(os.path.dirname(args.config), python_file), os.path.join(resolution_folder, python_file)) stats = get_xml_node(config, "config.uq.stats") if not args.do_not_compute_structure: number_of_h = int(resolution * 32 / 1024)
perturbation_folder = "p{}".format(perturbation.replace(".", "_")) os.mkdir(perturbation_folder) for m, resolution in enumerate(args.resolutions): resolution_folder = f"{perturbation_folder}/N{resolution}" os.mkdir(resolution_folder) samples = args.samples[m] set_in_xml(config, "config.uq.samples", samples) set_in_xml(config, "config.fvm.grid.dimension", f"{resolution} {resolution} {resolution}") python_file = get_in_xml(config, "config.initialData.python") initial_data_parameters = get_xml_node( config, "config.initialData.parameters") for initial_data_parameter in initial_data_parameters.getElementsByTagName( "parameter"): name = get_in_xml(initial_data_parameter, "name") if name == "epsilon": set_in_xml(initial_data_parameter, "value", perturbation) shutil.copyfile( os.path.join(os.path.dirname(args.config), python_file), os.path.join(resolution_folder, python_file)) with open( os.path.join(resolution_folder, os.path.basename(args.config)), 'w') as f:
perturbation_folder = "H{}".format(hurst_index.replace(".", "_")) os.makedirs(perturbation_folder, exist_ok=True) for m, resolution in enumerate(args.resolutions): resolution_folder = f"{perturbation_folder}/N{resolution}" os.makedirs(resolution_folder, exist_ok=True) samples = args.samples[m] set_in_xml(config, "config.uq.samples", samples) set_in_xml(config, "config.fvm.grid.dimension", f"{resolution} {resolution} {resolution}") python_file = get_in_xml(config, "config.fvm.initialData.python") initial_data_parameters = get_xml_node( config, "config.fvm.initialData.parameters") for initial_data_parameter in initial_data_parameters.getElementsByTagName( "parameter"): name = get_in_xml(initial_data_parameter, "name") if name == "hurst_index": set_in_xml(initial_data_parameter, "value", hurst_index) elif name == "X": # We need a total of nx**3*3 random samples, but we will always generate the maximum number of samples set_in_xml(initial_data_parameter, "length", 3 * (512 - 1)**3) uq_parameters = get_xml_node(config, "config.uq.parameters") for uq_parameter in uq_parameters.getElementsByTagName(