-
Notifications
You must be signed in to change notification settings - Fork 124
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: apdl
submodule
#3385
base: feat/main_commands
Are you sure you want to change the base?
feat: apdl
submodule
#3385
Conversation
Thanks for opening a Pull Request. If you want to perform a review write a comment saying: @ansys-reviewer-bot review |
I am setting this PR as draft because I think it is still not ready until you fix the line length thing. Ping us and switch this PR to non-draft when you feel it is ready for it. |
I can rework on it if docstring length is a priority. I already fixed some issues related in ansys/pyconverter-xml2py#222 but not all of them as you can see. Also, I had to comment the |
Wiz Scan Summary
To detect these findings earlier in the dev lifecycle, try using Wiz Code VS Code Extension. |
ac7b46a
to
04dac45
Compare
btw, this was fixed. CICD is "stable" again. |
For the commands with non-pythonic MAPDL commands (i.e. SECMODIF) where the MAPDL command signature might change depending on the argument: additional_arguments option@clatapie suggested an extra string argument such as: def secmodif(self, secid="", Keyword="", additional_arguments="", **kwargs):
# implementation
return self.run(f"SECMODIF,{secid}, {keyword},{additional_arguments}") So you can do: mapdl.secmodif(1, "NORM", "NX=2,NY=3, NZ=2, KCN=2") This effectively injects all the additional arguments as an string. CaveatsWhile this method might work, it delegates to the user all the responsability of building the command, and additionally it forces you to specify all the intermediate arguments (or commas). For instance if you only wants to use KCN, you will have to: mapdl.secmodif(1, "NORM", ", , , KCN=2") which looks rather weird. The
|
With respect to the arguments that have the same exact description, I will refer to the current discussion #3385 (comment) |
Answering @germa89's comment: additional_arguments option
mapdl.secmodif(1, "NORM", "2,3,2,2") Thus, This is due to the Python source code as reminded by @germa89: def secmodif(self, secid="", kywrd="", additional_arguments="", **kwargs):
# implementation
command = f"SECMODIF,{secid},{kywrd},{additional_arguments}"
return self.run(command) With previous example, command == SECMODIF,1,NORM,2,3,2,2 I agree the API is not ideal this way but it enables passing all the needed values.
|
My 2 cents... the problem with the |
I agree with your approach too @clatapie. The ROI seems low for now regarding the automation. It could even be difficult to maintain at first. |
@RobPasMue @MaxJPRey @clatapie since the MAPDL commands are pretty stable, I do not think we will be expecting many changes in the custom functions, so I would say that priorities should be:
There is always time to break the API, I guess? |
I might be missing something. What are you proposing with this priority list? I think I got lost somewhere... BTW - I do not agree on having Maintainability the last element of a priority list anyway 😄 maintainability should be at the core of whatever we decide, because it will make our lives easier in the future. |
(I was still building on my previous comment, I hit enter too fast) I think we have a choice to make here... maintainability (leave everything as the converter gives it) or user experience (better docs, better arguments handling). While I have always priorised both, I rarely had to choose one or another. So I think for this specific context, I am priorizing the list of items in my previous comment. I do understand that PyAnsys core team might be more interested in maintainability because you manage way too many things. But I think PyMAPDL developers should focus on MAPDL and PyMAPDL users and their user experience, and since the MAPDL commands are not expected to change much, I rather do the initial work in detrimental of automation. I am still not sure what is the best as the I would love to see something like this for def secmodif(self, secid, keyword, nx="", ny="", nz="", kcn="", name="", name_new="", option="", dispPnltVal="", RotPnltVal="", **kwargs):
"""Modifies a pretension section
APDL Command: SECMODIF
This command have specific signature depending on the values of the given
arguments.
- If `Keyword = NORM`:
SECMODIF,SECID, NORM, NX, NY, NZ, KCN
- If `Keyword = NAME`:
SECMODIF,SECID, NAME, Name
- If `Keyword = JOIN`:
SECMODIF,SECID, JOIN, Option, dispPnltVal, RotPnltVal
Parameters
----------
secid
Unique section number. This number must already be assigned to a
section.
norm
Keyword specifying that the command will modify the pretension
section normal direction.
nx, ny, nz
Specifies the individual normal components to modify.
kcn
Coordinate system number. This can be either 0 (Global Cartesian),
1 (Global Cylindrical) 2 (Global Spherical), 4 (Working Plane), 5
(Global Y Axis Cylindrical) or an arbitrary reference number
assigned to a coordinate system.
name
Change the name of the specified pretension section.
name_new
The new name to be assigned to the pretension section.
join
Set command actions to apply to joint sections only.
option
PNLT -- Modify penalty factors for the specified section.
dispPnltVal
Penalty value for displacement-based constraints:
- `> 0` -- The number is used as a scaling factor to scale the
internally calculated penalty values.
- `< 0` -- The absolute value of the number is used as the penalty
factor in calculations.
RotPnltVal
Penalty value for rotation-based constraints.
- `> 0` -- The number is used as a scaling factor to scale the
internally calculated penalty values.
- `< 0` -- The absolute value of the number is used as the penalty
factor in calculations.
Notes
-----
The SECMODIF command either modifies the normal for a specified
pretension section, or changes the name of the specified pretension
surface.
"""
# Sanity checks
if keyword.upper() not in ["NORM", "NAME", "JOIN"]:
raise ValueError(f"The given argument 'keyword' ({keyword}) is not valid.")
if keyword == "NORM":
cmd = f"SECMODIF, {secid}, NORM, {nx}, {ny}, {nz}, {kcn}"
elif keyword == "NAME":
cmd = f"SECMODIF, {secid}, NAME, {name or nx}, {name_new or ny}"
elif keyword == "JOIN":
cmd = f"SECMODIF, {secid}, JOIN, {option or nx},{dispPnltVal or ny},{RotPnltVal or nz}"
else:
raise ValueError("We couldn't map the arguments given....")
self.run(cmd, **kwargs) The doc string is slightly modified, just adding some info about the signatures in the extended summary part (before parameters). |
I would leave it up to @clatapie to decide since she is doing the work mostly, but for me I would keep any kind of custom function to the minimum (i.e. reduce their number as much as possible). Mostly because they will go outdated and it will be on the maintainers to keep them up to date. The whole point of automating the API generation process (which was the initial purpose of all these efforts) was to free up time for maintainers and developers to work on actual problems inside PyMAPDL. Not to generate more work on the long run IMO. In any case, we need to make progress with this. We have been iterating for too long and we don't have anything merged or close to be merged yet. We should be doing more iterations rather than trying to get it 100% right in the first shot. |
This PR is the first one in order to automate the PyMAPDL
_commands
documentation.The changes have been generated using
pyconverter-xml2py
.This PR focus on the
apdl
submodule.Pinging @ansys/pymapdl-developers for visibility. Feel free to provide any feedback on the way the docstrings and the source code generation are handled.
Note
This PR is meant to be merged within the feat/main_commands branch. The latter will gather all the submodule changes, one by one, prior to be merged to the main branch.
Checklist
draft
if it is not ready to be reviewed yet.feat: adding new MAPDL command
)