Settings API improvement suggestion #545
Replies: 4 comments 1 reply
-
Another option: return the same object instead of the parent object.
Multiple keywords may also be specified: For primitive types: |
Beta Was this translation helpful? Give feedback.
-
@h-krishnan thanks for opening this topic Whatever we do needs to follow the principle of least astonishment. Obviously nothing surprising about the current assignment syntax. Any new syntax style should be something that's obvious, natural and ideally used across PyAnsys/Ansys. As we know, OnScale has its own niche syntax. If every other product/library comes up with something new and different, that won't be good for users. Even if it's something uniform across PyAnsys/Ansys (say adopted from OnScale) but different from ordinary Python patterns, that's still potentially an issue. One question about chained assignments is: when does the state get sent to the server? There's nothing in
to say 'done' so each setting would be sent individually. If changing many remote settings, we might want a simple syntax that allows the user to express when they're done and wants to send all the settings. A simple approach might be not to think about chaining and just to pass keyword arguments in a single call:
or if we should be more explicit about the operations, something like:
|
Beta Was this translation helpful? Give feedback.
-
This seems like a useful idea to make things a bit more compact. |
Beta Was this translation helpful? Give feedback.
-
This is the main capability to try to add
once that is done, adding the following could be relatively easy, but let's omit it from the initial work:
The code is in flobject.py. See set_state. Take a look at this unit test:
Those assignments like |
Beta Was this translation helpful? Give feedback.
-
At present, the option to set a value via the settings API is via attribute assignment:
setup.models.energy.enabled = True
This is not amenable to chaining.
We could support the following additional syntax:
setup.models.energy.enabled(True)
This could return the parent object and so one could do something like:
setup.models.energy.enabled(True).viscous_dissipation(False)
results.graphics.contour.create('c1').field('velocity-magnitude').surfaces_list(['wall1', 'wall2']).display()
.[ Will this be a bit confusing when supported at Group/NamedObject level, because the parent object is being returned?
setup.models.energy({'enabled' : True}).viscous({'model' : 'k-epsilon'})
]We can support keyword-based assignment for container objects:
setup.models.energy(enabled = True, viscous_dissipation = False)
Beta Was this translation helpful? Give feedback.
All reactions