fast-aircraft-design / FAST-OAD

FAST-OAD: An open source framework for rapid Overall Aircraft Design
GNU General Public License v3.0
48 stars 25 forks source link

Error within xfoil_polar.py using parser and particular input_template_path #204

Closed areysset closed 4 years ago

areysset commented 4 years ago

For some input_template_path like mine (C:\Users\ABF4A~1.REY\AppData\Local\Temp\x0s8v337u\in), some mark anchor can, unfortunately, appear and generate wrong input file (here RE appears and Reynolds number will be inserted in a wrong place).

Correction: path should be replaced at the end of the process.

polar_session.txt

areysset commented 4 years ago

In fact, with parser process, correction should be: parser.set_template_file(input_template_path) parser.set_generated_file(self.stdin) parser.mark_anchor("LOAD") parser.transfer_var(tmp_profile_file_path, 1, 1) parser.mark_anchor("PLOP") parser.transfer_var("g", 1, 1) parser.mark_anchor("RE") parser.transfer_var(float(reynolds), 1, 1) parser.mark_anchor("M") parser.transfer_var(float(mach), 1, 1) parser.mark_anchor("ITER") parser.transfer_var(self.options[OPTION_ITER_LIMIT], 1, 1) parser.mark_anchor("PACC") parser.transfer_var(tmp_result_file_path, 1, 1) parser.mark_anchor("ASEQ") parser.transfer_var(self.options[OPTION_ALPHA_START], 1, 1) parser.transfer_var(self.options[OPTION_ALPHA_END], 2, 1) parser.generate()

christophe-david commented 4 years ago

Thanks for this report and for providing the solution 😉 As you may have figured out by now, transfer_var replaces the path immediately, which prevents from applying your first suggestion. And since it is OpenMDAO's API, we cannot change this behavior, but using additional mark_anchor as you suggest should do the trick (not sure we have to do the additional transfer_var, though).

areysset commented 4 years ago

Yes, you also have this workarround (that I used on FAST-GA): _parser.set_template_file(input_template_path) parser.set_generated_file(self.stdin) parser.mark_anchor("RE") parser.transfer_var(float(reynolds), 1, 1) parser.mark_anchor("M") parser.transfer_var(float(mach), 1, 1) parser.mark_anchor("ITER") parser.transfer_var(self.options[OPTION_ITER_LIMIT], 1, 1) parser.mark_anchor("PACC") parser.transfer_var(tmp_result_file_path, 1, 1) parser.mark_anchor("ASEQ") parser.transfer_var(self.options[OPTION_ALPHA_START], 1, 1) parser.transfer_var(self.options[OPTION_ALPHA_END], 2, 1) parser.reset_anchor() parser.mark_anchor("LOAD") parser.transfer_var(tmp_profile_filepath, 1, 1) parser.generate()

christophe-david commented 4 years ago

Ok, now I understand your initial point (I used the API of InputFileGenerator too long ago, I didn't remember reset_anchor... ) Thanks.

christophe-david commented 4 years ago

Hey wait, if someone has "ASEQ" in his tmp folder path, we get the same problem after having provided tmp_result_file_path. Ok, that's less likely than just "RE", but still...

Then I think the really safe solution would be a mix of your two suggestions:

parser.set_template_file(input_template_path)
parser.set_generated_file(self.stdin)

parser.mark_anchor("RE")
parser.transfer_var(float(reynolds), 1, 1)
parser.mark_anchor("M")
parser.transfer_var(float(mach), 1, 1)
parser.mark_anchor("ITER")
parser.transfer_var(self.options[OPTION_ITER_LIMIT], 1, 1)
parser.mark_anchor("ASEQ")
parser.transfer_var(self.options[OPTION_ALPHA_START], 1, 1)
parser.transfer_var(self.options[OPTION_ALPHA_END], 2, 1)

parser.reset_anchor()
parser.mark_anchor("LOAD")
parser.transfer_var(tmp_profile_file_path, 1, 1)
parser.mark_anchor("PLOP")  # in case there is "PACC" in tmp_profile_file_path
parser.mark_anchor("PACC")
parser.transfer_var(tmp_result_file_path, 1, 1)

parser.generate()

Your opinion?

areysset commented 4 years ago

I did not see the second file path ^^. Then we can do that (because / char is forbidden in both linux/windows path): parser.set_template_file(input_template_path) parser.set_generated_file(self.stdin) parser.mark_anchor("RE") parser.transfer_var(float(reynolds), 1, 1) parser.mark_anchor("M") parser.transfer_var(float(mach), 1, 1) parser.mark_anchor("ITER") parser.transfer_var(self.options[OPTION_ITER_LIMIT], 1, 1) parser.mark_anchor("ASEQ") parser.transfer_var(self.options[OPTION_ALPHA_START], 1, 1) parser.transfer_var(self.options[OPTION_ALPHA_END], 2, 1) parser.reset_anchor() parser.mark_anchor("/profile.txt") parser.transfer_var(tmp_profile_file_path, 0, 1) parser.mark_anchor("/polar_result.txt") parser.transfer_var(tmp_result_file_path, 0, 1) parser.generate()

polar_session.txt

christophe-david commented 4 years ago

That might work, except that I don't get your point about "/" char being forbidden in linux paths.

Anyway, initially, I was fond of being able to rely only on keywords of the file, not on its values. I will go with this solution:

parser.set_template_file(input_template_path)
parser.set_generated_file(self.stdin)

parser.mark_anchor("RE")
parser.transfer_var(float(reynolds), 1, 1)
parser.mark_anchor("M")
parser.transfer_var(float(mach), 1, 1)
parser.mark_anchor("ITER")
parser.transfer_var(self.options[OPTION_ITER_LIMIT], 1, 1)
parser.mark_anchor("ASEQ")
parser.transfer_var(self.options[OPTION_ALPHA_START], 1, 1)
parser.transfer_var(self.options[OPTION_ALPHA_END], 2, 1)

parser.reset_anchor()
parser.mark_anchor("LOAD")
parser.transfer_var(tmp_profile_file_path, 1, 1)
parser.mark_anchor("PACC", -2)
parser.transfer_var(tmp_result_file_path, 1, 1)

parser.generate()
areysset commented 4 years ago

The idea using forbiden parameter for path into the mark anchor is to avoid to found it in the path name because PACC or PLOP can be in the file path if we are not lucky. For both windows and Linux / is forbidden, therefore we are sure /polar_result.txt cannot be in path name (even if I agree to find polar_result.txt in path is very unluky).

Le mer. 2 sept. 2020 à 14:33, Christophe DAVID notifications@github.com a écrit :

That might work, except that I don't get your point about "/" char being forbidden in linux paths.

Anyway, initially, I was fond of being able to rely only on keywords of the file, not on its values. I will go with this solution:

parser.set_template_file(input_template_path)parser.set_generated_file(self.stdin) parser.mark_anchor("RE")parser.transfer_var(float(reynolds), 1, 1)parser.mark_anchor("M")parser.transfer_var(float(mach), 1, 1)parser.mark_anchor("ITER")parser.transfer_var(self.options[OPTION_ITER_LIMIT], 1, 1)parser.mark_anchor("ASEQ")parser.transfer_var(self.options[OPTION_ALPHA_START], 1, 1)parser.transfer_var(self.options[OPTION_ALPHA_END], 2, 1) parser.reset_anchor()parser.mark_anchor("LOAD")parser.transfer_var(tmp_profile_file_path, 1, 1)parser.mark_anchor("PACC", -2)parser.transfer_var(tmp_result_file_path, 1, 1) parser.generate()

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/fast-aircraft-design/FAST-OAD/issues/204#issuecomment-685703560, or unsubscribe https://github.com/notifications/unsubscribe-auth/ALCJXK3SPQVARW7POLWJTMDSDY3S5ANCNFSM4QRT62YQ .

--