ansys / pymechanical

Pythonic interface to Ansys Mechanical ™
https://mechanical.docs.pyansys.com/
MIT License
38 stars 19 forks source link

Setting quantity in embedded mode #96

Closed pmaroneh closed 1 year ago

pmaroneh commented 1 year ago

🔍 Before submitting the issue

🐞 Description of the bug

In the GUI, this works: pressure = analysis.AddPressure() pressure.Location = ExtAPI.DataModel.GetObjectsByName("NSInsideFaces")[0] pressure.Magnitude.Inputs[0].DiscreteValues = [Quantity("0 [s]"), Quantity("1 [s]")] pressure.Magnitude.Output.DiscreteValues = [Quantity("0 [Pa]"), Quantity("15 [MPa]")]

But in embedded mode, the following error message is returned: image

📝 Steps to reproduce

See above.

💻 Which operating system are you using?

Windows

🐍 Which Python version are you using?

3.7

📦 Installed packages

ansys-api-platform-instancemanagement==1.0.0b3
-e git+https://github.com/pyansys/pymechanical.git@a7bb62749e64b43373fb4fa9b620cc642613d5ed#egg=ansys_mechanical_core
ansys-platform-instancemanagement==1.0.2
ansys-pythonnet==3.1.0rc1
anyio==3.6.2
appdirs==1.4.4
argon2-cffi==21.3.0
argon2-cffi-bindings==21.2.0
arrow==1.2.3
asttokens @ file:///opt/conda/conda-bld/asttokens_1646925590279/work
attrs==22.2.0
Babel==2.11.0
backcall @ file:///home/ktietz/src/ci/backcall_1611930011877/work
beautifulsoup4==4.11.1
bleach==5.0.1
cachetools==5.2.1
certifi @ file:///C:/b/abs_4f5wo627a3/croots/recipe/certifi_1663615677642/work/certifi
cffi==1.15.1
chardet==5.1.0
charset-normalizer==3.0.1
cloudpickle @ file:///tmp/build/80754af9/cloudpickle_1632508026186/work
clr-loader==0.2.5
colorama==0.4.6
debugpy @ file:///C:/ci/debugpy_1637091961445/work
decorator @ file:///opt/conda/conda-bld/decorator_1643638310831/work
defusedxml==0.7.1
distlib==0.3.6
docutils==0.19
entrypoints==0.4
executing @ file:///opt/conda/conda-bld/executing_1646925071911/work
fastjsonschema==2.16.2
filelock==3.9.0
flit==3.8.0
flit_core==3.8.0
fqdn==1.5.1
googleapis-common-protos==1.56.4
grpcio==1.49.1
idna==3.4
importlib-metadata==5.0.0
ipykernel @ file:///C:/b/abs_21ykzkm7y_/croots/recipe/ipykernel_1662361803478/work
ipython @ file:///C:/ci/ipython_1657634415474/work
ipython-genutils==0.2.0
isoduration==20.11.0
jedi @ file:///C:/ci/jedi_1644315428289/work
Jinja2==3.1.2
json5==0.9.11
jsonpointer==2.3
jsonschema==4.17.3
jupyter-events==0.6.3
jupyter_client==7.4.9
jupyter_core==5.1.3
jupyter_server==2.1.0
jupyter_server_terminals==0.4.4
jupyterlab==3.5.2
jupyterlab-pygments==0.2.2
jupyterlab_server==2.19.0
MarkupSafe==2.1.1
matplotlib-inline @ file:///C:/ci/matplotlib-inline_1661915841596/work
mistune==2.0.4
nbclassic==0.4.8
nbclient==0.7.2
nbconvert==7.2.8
nbformat==5.7.3
nest-asyncio @ file:///C:/ci/nest-asyncio_1649829929390/work
notebook==6.5.2
notebook_shim==0.2.2
packaging==23.0
pandocfilters==1.5.0
parso @ file:///opt/conda/conda-bld/parso_1641458642106/work
pickleshare @ file:///tmp/build/80754af9/pickleshare_1606932040724/work
platformdirs==2.6.2
pluggy==1.0.0
prometheus-client==0.15.0
prompt-toolkit @ file:///tmp/build/80754af9/prompt-toolkit_1633440160888/work
protobuf==3.20.3
protoc-gen-swagger==0.1.0
psutil @ file:///C:/Windows/Temp/abs_b2c2fd7f-9fd5-4756-95ea-8aed74d0039flsd9qufz/croots/recipe/psutil_1656431277748/work
pure-eval @ file:///opt/conda/conda-bld/pure_eval_1646925070566/work
pycparser==2.21
Pygments @ file:///opt/conda/conda-bld/pygments_1644249106324/work
pyparsing @ file:///C:/Users/BUILDE~1/AppData/Local/Temp/abs_7f_7lba6rl/croots/recipe/pyparsing_1661452540662/work
pyproject_api==1.4.0
pyrsistent==0.19.3
python-dateutil @ file:///tmp/build/80754af9/python-dateutil_1626374649649/work
python-json-logger==2.0.4
pytz==2022.7.1
pywin32==302
pywinpty==2.0.10
PyYAML==6.0
pyzmq==25.0.0
requests==2.28.2
rfc3339-validator==0.1.4
rfc3986-validator==0.1.1
Send2Trash==1.8.0
six @ file:///tmp/build/80754af9/six_1644875935023/work
sniffio==1.3.0
soupsieve==2.3.2.post1
spyder-kernels @ file:///C:/ci/spyder-kernels_1634237096710/work
stack-data @ file:///opt/conda/conda-bld/stack_data_1646927590127/work
terminado==0.17.1
tinycss2==1.2.1
tomli==2.0.1
tomli_w==1.0.0
tornado @ file:///C:/ci/tornado_1662458743919/work
tox==4.3.1
tqdm==4.64.1
traitlets==5.8.1
uri-template==1.2.0
urllib3==1.26.14
virtualenv==20.17.1
wcwidth @ file:///Users/ktietz/demo/mc3/conda-bld/wcwidth_1629357192024/work
webcolors==1.12
webencodings==0.5.1
websocket-client==1.4.2
wincertstore==0.2
zipp==3.8.1
koubaa commented 1 year ago

Same root cause as #93.

pmaroneh commented 1 year ago

I'm sorry if I'm missing the obvious here or did a mistake but I can't make the workaround work in this situation:

pressure = analysis.AddPressure()
pressure.Location = ExtAPI.DataModel.GetObjectsByName("NSInsideFaces")[0]
inputs_quantities = [Quantity("0 [s]"), Quantity("1 [s]")]  
inputs_quantities_2 = System.Collections.Generic.List[System.Int32]()
[inputs_quantities_2.Add(item) for item in inputs_quantities]

returns: image What's weird is that dir(input_quantities_2) does have a .Add() method: image But maybe the issue here is that I'm trying to deal with quantities (so value + unit) and not just some standard items in a standard list?

pmaroneh commented 1 year ago

Realized I was missing the obvious. Type of list needs to be adapted, as follows:


pressure.Location = ExtAPI.DataModel.GetObjectsByName("NSInsideFaces")[0]

inputs_quantities = [Quantity("0 [s]"), Quantity("1 [s]")]  
output_quantities = [Quantity("0 [Pa]"), Quantity("15 [MPa]")]  

inputs_quantities_2 = System.Collections.Generic.List[Ansys.Core.Units.Quantity]()
[inputs_quantities_2.Add(item) for item in inputs_quantities]

output_quantities_2 = System.Collections.Generic.List[Ansys.Core.Units.Quantity]()
[output_quantities_2.Add(item) for item in output_quantities]

pressure.Magnitude.Inputs[0].DiscreteValues = inputs_quantities_2
pressure.Magnitude.Output.DiscreteValues = output_quantities_2```
pmaroneh commented 1 year ago

This is resolved in 0.7.dev3.