nasa / cape

Computational Aerosciences Productivity & Execution
Other
21 stars 9 forks source link

sampling_parameters not Writing Correctly #19

Closed rbreslavsky closed 1 year ago

rbreslavsky commented 1 year ago

I noticed an issue that’s causing a sampling_parameters namelist read error in FUN3D as of the latest CAPE release (1.0.2). Previously, I would specify a three-component tuple for a plane using a "hook". In Python, the dictionary defining the fifth plane’s normal vector would be: {"plane_normal(1:3, 5)": (1.0 0.0 0.0)}

With the sampling_parameters key of my namelist dictionary populated with planes in this manner, I would then use the ApplyDict method (i.e., cntl.Namelist.ApplyDict()) to populate the CAPE namelist class. The resultant namelist entry would be written as:

plane_normal(1:3, 5) = 1.0 0.0 0.0

With CAPE 1.0.2, the same approach now results in:

plane_normal(1:3, 5)(1) = 1.0
plane_normal(1:3, 5)(2) = 0.0
plane_normal(1:3, 5)(3) = 0.0

This results in an error in FUN3D:

Invalid input in namelist:     plane_normal(1:3, 5)(1) = 1.0
  Probable incomplete read of namelist: &sampling_parameters iostat2=        5010

Any thoughts on the best way to move forward? With the current framework, I think I’d now have to express my dictionary as: {"plane_normal(1, 5)": 1.0, "plane_normal(2, 5)": 1.0, "plane_normal(3, 5)": 1.0}

nasa-ddalle commented 1 year ago

This ApplyDict() function is going to be the end of me.... I'll be happy when CAPE 1.1 works well for everyone and the completely new approach to namelists avoids these problems with processing the text instead of processing the implied values. But I do want to keep CAPE 1.0.x functional for some time because of its Python 2.7 support.

I think I understand what's happening here and why my update broke it. To clarify, I think you're using the following Python inputs:

{"plane_normal(1:3, 5)":  (1.0, 0.0, 0.0)}

(All I did was add some quotes to your example.)

If this is correct, I think it's a relatively easy fix. I never thought of including the indices directly on the left-hand side... pretty smart.

rbreslavsky commented 1 year ago

Ah, yes, thanks for including the quotes (I fixed my original message to include them).

Understood. For now, I implemented the workaround I mentioned above. Thanks!

nasa-ddalle commented 1 year ago

Fixed as of https://github.com/nasa/cape/commit/3abc1cb4962975c4465f6df0a0a2acf99891127e

Thanks for this issue; I understand a lot of previously unanswered questions now.

FYI CAPE 1.1 is going to break your hook again slightly (Hooks or other API uses are allowed to break b/w minor versions under the current paradigm, but not JSON files), but it will be easier to use overall. You'll just set nml["sampling_parameters"]["plane_normal"] to whatever Nx3 array you want and let it worry about indices when it writes the file.