ansys / pymapdl

Pythonic interface to MAPDL
https://mapdl.docs.pyansys.com
MIT License
426 stars 120 forks source link

Allow iterables in `mapdl.cmsel` #3425

Open germa89 opened 1 month ago

germa89 commented 1 month ago

As the title.

germa89 commented 3 weeks ago

Mmhhh.. Now I think about it... it might not make much sense to have iterables.....

New selection S

mapdl.cmsel("s", ['cm1', 'cm2'])

you cannot have:

mapdl.cmsel( "s", cm1)
mapdl.cmsel( "s", cm2)

Because the last command overwrites all the previous selections (that's the point of S)

However, you could have:

mapdl.cmsel("s", cm1)
mapdl.cmsel("a", cm2)

Which is more useful.

Reselect R

The behaviour of multiple arguments here is a bit complicated. In the case we can have multiple R, I would expect that

mapdl.allsel()
mapdl.cmsel("R", ["cm1", "cm2"])

will mean something like either:

Anyways, I'm not too fond of this ambiguity.

Add selection A

I think this is quite easy, because mapdl.cmsel("a", ["cm1", "cm2"]) should mean:

# whatever selection you might have
mapdl.cmsel("a", "cm1")
mapdl.cmsel("a", "cm2")

Easy

Unselect U

I think this is quite easy as well, because mapdl.cmsel("U", ["cm1", "cm2"]) should mean:

# whatever selection you might have
mapdl.cmsel("u", "cm1")
mapdl.cmsel("u", "cm2")
germa89 commented 3 weeks ago

I am wondering if makes sense to overload the math operators for selections. Given:

# node selection 1
cm1 = mapdl.cm("cm1", "nodes")  # current implementation does not return anything
# node selection 2
cm2 = mapdl.cm("cm2", "nodes")

mapdl.select # imaginary function to select components

What the following operation will mean:

AND operator

What the following statement should mean:

mapdl.select(cm1 and cm2)

I guess it should mean to select both:

mapdl.cmsel("s", "cm1")
mapdl.cmsel("a", "cm2")

However, using R could make sense also:

mapdl.cmsel("s", "cm1")
mapdl.cmsel("R", "cm2")

OR operator

But then what about the or operator?

mapdl.select(cm1 or cm2)

probably here the only reasonable option will be to use A:

mapdl.cmsel("s", "cm1")
mapdl.cmsel("a", "cm2")

NOT operator

I guess this is easy, it should unselect:

mapdl.select(not cm1)

will be translated to:

mapdl.cmsel("U", "cm1")

Summary

So...

Python operator MAPDL operation Python example PyMAPDL command
and | Reselect R | mapdl.select(cm1 and cm2) | mapdl.cmsel("S", "cm1");mapdl.cmsel("R", "cm2")
or | Add A | mapdl.select(cm1 or cm2) | mapdl.cmsel("S", "cm1");mapdl.cmsel("A", "cm2")
not | Unselect U | mapdl.select(not cm1) | mapdl.cmsel("U", "cm1")
germa89 commented 3 weeks ago

Pinging @koubaa, @mcMunich, @mikerife and @pthieffry for feedback before considering it for future work.

pthieffry commented 2 weeks ago

@germa89 I much prefer the idea of logic operators than iterables. I concur with your assessment on the ambiguity iterables could introduce.