From 678023ef9452a38bc2ad5f1c506b33b5519ad5df Mon Sep 17 00:00:00 2001 From: LUCIE BERTHON Date: Fri, 7 Sep 2018 17:08:11 +0200 Subject: [PATCH] Ecriture des writerXML et INI globaux --- .../mesScripts_MAPIDENTIFICATION.py | 27 ++++++++++++------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/MapIdentification/mesScripts_MAPIDENTIFICATION.py b/MapIdentification/mesScripts_MAPIDENTIFICATION.py index 86ed8777..ac116032 100644 --- a/MapIdentification/mesScripts_MAPIDENTIFICATION.py +++ b/MapIdentification/mesScripts_MAPIDENTIFICATION.py @@ -10,16 +10,20 @@ MAP_KEYS =["output_directory", "constitutive_law_parameters", "user_defined_mfront_file_directory", "exp_filename_list", - "mtest_options", - "interface"] + "mtest_options", "interface"] def comm2MAPinput(input_filename): # Saving my input file by converting comm file into ini + print("on rentre dans comm2MAPinput pour " + input_filename) + with open(input_filename) as input_file: - lines = input_file.readlines() + data = input_file.read() + + data = data.replace("=\n", "=").replace("=\t", "=") + data = re.sub(' +', ' ',data).split("\n") - string = "[c_solver_constitutive_law0d]\n" - for line in lines: + string = "[c_solver_constitutive_law_0d]\n" + for line in data: for key in MAP_KEYS: if key + "=" in line: string += key + "=" + line.split("'")[1] + "\n" @@ -36,10 +40,10 @@ def writeMAPinput(dictValeur, filename): """ print("je rentre dans writeMAPinput") config = RawConfigParser() - config.add_section("c_solver_constitutive_law0d") + config.add_section("c_solver_constitutive_law_0d") for key, value in dictValeur.iteritems(): if key in MAP_KEYS: - config.set("c_solver_constitutive_law0d", key, value) + config.set("c_solver_constitutive_law_0d", key, value) filename = os.path.abspath(os.path.splitext(filename)[0] + ".input") with open(filename,'w') as f_out : config.write(f_out) @@ -89,6 +93,7 @@ def writeXMLexperiences(exp_xml, filename): iel += 1 writeXML(root, filename) + def writeXML(xml_structure, filename): # Make the output easier to follow for human readers print("je rentre dans writeXML") @@ -96,11 +101,12 @@ def writeXML(xml_structure, filename): filename = os.path.splitext(filename)[0] + ".xml" xmlstr = minidom.parseString(ET.tostring(xml_structure)).toprettyxml(indent=" ") - print xmlstr + #print xmlstr with open(filename,'w') as f_out : f_out.write(xmlstr) print("je sauvegarde les info dans " + filename) + def add_param(param_xml, root, ind=""): param = ET.SubElement(root, "Parameter") param.set("name", param_xml["Name" + ind]) @@ -114,6 +120,7 @@ def add_param(param_xml, root, ind=""): value.set("sup", str(param_xml["Upper_bound" + ind])) return param_xml + def add_exp(exp_xml, root, ind=""): exp = ET.SubElement(root, "Experience") exp.set("name", exp_xml["ExperienceName" + ind]) @@ -179,9 +186,11 @@ def add_exp(exp_xml, root, ind=""): #elem.set("name", _name) def run(listeParam): + print "on rentre dans run" command_file=listeParam[0].fichier command_file = comm2MAPinput(command_file) - command = "map -r sappli run -n C_solver_constitutive_law0d -i " + command_file + command = "map -r sappli run -n c_solver_constitutive_law_0d -i " + command_file + print(command) os.system(command) print "calcul fini, youpi !" -- 2.39.2