ansys / pydpf-core

Data Processing Framework - Python Core
http://dpf.docs.pyansys.com/
MIT License
68 stars 25 forks source link

Scoping does not apply correcty the desired set #544

Open germa89 opened 2 years ago

germa89 commented 2 years ago

Before submitting the issue

Description of the bug

It seems that the scoping operator does not return the correct cumulative index in some cases.

Steps To Reproduce

Use the attached RST file.

file.zip

Open it, and run:

from ansys.dpf import core as dpf

rst_file = r"C:\Users\gayuso\AppData\Local\Temp\pytest-of-gayuso\pytest-1344\ansys0\file.rst"
model = dpf.Model(rst_file)

set_ = (1, 10)
cum_set = model.metadata.time_freq_support.get_cumulative_index(set_[0], set_[1])

scop = dpf.Scoping()
scop.location = "time_freq_steps"
scop.ids = [cum_set]

op = model.results.displacement()
op.inputs.time_scoping.connect(scop)

output = op.outputs.fields_container()[0].data

where output is:

DPFArray([[ 0.        , -0.02314378,  0.        ],
          [ 0.        ,  0.        ,  0.        ],
          [ 0.        ,  0.        ,  0.        ]])

However, using MAPDL, and running:

post1
set,1,10
prnsol,u

I get:

PRINT U    NODAL SOLUTION PER NODE
   *****MAPDL VERIFICATION RUN ONLY*****
     DO NOT USE RESULTS FOR PRODUCTION

  ***** POST1 NODAL DEGREE OF FREEDOM LISTING *****                            

  LOAD STEP=     1  SUBSTEP=    10                                             
   TIME=   0.10000E-02  LOAD CASE=   0                                         

  THE FOLLOWING DEGREE OF FREEDOM RESULTS ARE IN THE GLOBAL COORDINATE SYSTEM  

    NODE       UX           UY           UZ           USUM  
       1   0.0000     -0.17485E-003  0.0000      0.17485E-003
       2   0.0000       0.0000       0.0000       0.0000     
       3   0.0000       0.0000       0.0000       0.0000     

 MAXIMUM ABSOLUTE VALUES
 NODE          0            0            0            0
 VALUE    0.0000     -0.17485E-003  0.0000      0.17485E-003

I believe the issue is related to get_cumulative_index, because it retuns cum_set= 11, whereas MAPDL when issued set,list returns 10.

*****  INDEX OF DATA SETS ON RESULTS FILE  *****

   SET   TIME/FREQ    LOAD STEP   SUBSTEP  CUMULATIVE
     1 0.10000E-02         1        10        10                  
     2 0.20000E-02         2         1        11                  
     3 0.30000E-02         2         2        12                  
     4 0.40000E-02         2         3        13                  
     5 0.50000E-02         2         4        14                  
     6 0.60000E-02         2         5        15                  
     7 0.70000E-02         2         6        16                  
     8 0.80000E-02         2         7        17                  
     9 0.90000E-02         2         8        18                  
    10 0.10000E-01         2         9        19                  
    11 0.11000E-01         2        10        20                  
    12 0.12000E-01         2        11        21                  
    13 0.13000E-01         2        12        22                  
    14 0.14000E-01         2        13        23                  
    15 0.15000E-01         2        14        24                  
    16 0.16000E-01         2        15        25                  
    17 0.17000E-01         2        16        26                  
    18 0.18000E-01         2        17        27                  
    19 0.19000E-01         2        18        28                  
    20 0.20000E-01         2        19        29                  
    21 0.21000E-01         2        20        30                  
    22 0.22000E-01         2        21        31                  
    23 0.23000E-01         2        22        32                  
    24 0.24000E-01         2        23        33                  
    25 0.25000E-01         2        24        34                  
    26 0.26000E-01         2        25        35                  
    27 0.27000E-01         2        26        36                  
    28 0.28000E-01         2        27        37                  
    29 0.29000E-01         2        28        38                  
    30 0.30000E-01         2        29        39                  
    31 0.31000E-01         2        30        40                  
    32 0.32000E-01         2        31        41                  
    33 0.33000E-01         2        32        42                  
    34 0.34000E-01         2        33        43                  
    35 0.35000E-01         2        34        44                  
    36 0.36000E-01         2        35        45                  
    37 0.37000E-01         2        36        46                  
    38 0.38000E-01         2        37        47                  
    39 0.39000E-01         2        38        48                  
    40 0.40000E-01         2        39        49                  
    41 0.41000E-01         2        40        50                  
    42 0.42000E-01         2        41        51                  
    43 0.43000E-01         2        42        52                  
    44 0.44000E-01         2        43        53                  
    45 0.45000E-01         2        44        54                  
    46 0.46000E-01         2        45        55                  
    47 0.47000E-01         2        46        56                  
    48 0.48000E-01         2        47        57                  
    49 0.49000E-01         2        48        58                  
    50 0.50000E-01         2        49        59                  
    51 0.51000E-01         2        50        60                  
    52 0.52000E-01         2        51        61                  
    53 0.53000E-01         2        52        62                  
    54 0.54000E-01         2        53        63                  
    55 0.55000E-01         2        54        64                  
    56 0.56000E-01         2        55        65                  
    57 0.57000E-01         2        56        66                  
    58 0.58000E-01         2        57        67                  
    59 0.59000E-01         2        58        68                  
    60 0.60000E-01         2        59        69                  
    61 0.61000E-01         2        60        70                  
    62 0.62000E-01         2        61        71                  
    63 0.63000E-01         2        62        72                  
    64 0.64000E-01         2        63        73                  
    65 0.65000E-01         2        64        74                  
    66 0.66000E-01         2        65        75                  
    67 0.67000E-01         2        66        76                  
    68 0.68000E-01         2        67        77                  
    69 0.69000E-01         2        68        78                  
    70 0.70000E-01         2        69        79                  
    71 0.71000E-01         2        70        80                  
    72 0.72000E-01         2        71        81                  
    73 0.73000E-01         2        72        83                  
    74 0.74000E-01         2        73        84                  
    75 0.75000E-01         2        74        85                  
    76 0.76000E-01         2        75        86                  
    77 0.77000E-01         2        76        87                  
    78 0.78000E-01         2        77        88                  
    79 0.79000E-01         2        78        89                  
    80 0.80000E-01         2        79        90                  
    81 0.81000E-01         2        80        91                  
    82 0.82000E-01         2        81        92                  
    83 0.83000E-01         2        82        93                  
    84 0.84000E-01         2        83        94                  
    85 0.85000E-01         2        84        95                  
    86 0.86000E-01         2        85        96                  
    87 0.87000E-01         2        86        97                  
    88 0.88000E-01         2        87        98                  
    89 0.89000E-01         2        88        99                  
    90 0.90000E-01         2        89       100                  
    91 0.91000E-01         2        90       101                  
    92 0.92000E-01         2        91       102                  
    93 0.93000E-01         2        92       103                  
    94 0.94000E-01         2        93       104                  
    95 0.95000E-01         2        94       105                  
    96 0.96000E-01         2        95       106                  
    97 0.97000E-01         2        96       107                  
    98 0.98000E-01         2        97       108                  
    99 0.99000E-01         2        98       109                  
   100 0.10000             2        99       110                  
   101 0.10100             2       100       111                  
   102 0.10200             2       101       112                  
   103 0.10300             2       102       113                  
   104 0.10400             2       103       114                  
   105 0.10500             2       104       115                  
   106 0.10600             2       105       116                  
   107 0.10700             2       106       117                  
   108 0.10800             2       107       118                  
   109 0.10900             2       108       119                  
   110 0.11000             2       109       120

If I run with cum_set equals 1, I do get the expected result:

DPFArray([[ 0.        , -0.00017485,  0.        ],
          [ 0.        ,  0.        ,  0.        ],
          [ 0.        ,  0.        ,  0.        ]])

Which Operating System are you using?

Windows

Which Python version are you using?

3.9

Installed packages

Toggle me! ```text aiohttp==3.8.1 aiosignal==1.2.0 alabaster==0.7.12 ansys-api-mapdl==0.5.1 ansys-api-platform-instancemanagement==1.0.0b3 -e git+https://github.com/pyansys/pydpf-core.git@e03ab109e225bba5c7452c86d0ceb1be6939ce5f#egg=ansys_dpf_core ansys-dpf-gate==0.2.1 ansys-dpf-gatebin==0.2.1 -e git+https://github.com/pyansys/pydpf-post.git@f9a6412f906a0e70c1a3a7fe19b88248124933d7#egg=ansys_dpf_post ansys-grpc-dpf==0.4.0 -e git+https://github.com/pyansys/pymapdl.git@1274686a65b3815ce02b45c139d321fc8a598cb5#egg=ansys_mapdl_core ansys-mapdl-reader==0.52.0 ansys-platform-instancemanagement==1.0.2 ansys-sphinx-theme==0.5.2 anyio==3.5.0 appdirs==1.4.4 argcomplete==2.0.0 argon2-cffi==21.3.0 argon2-cffi-bindings==21.2.0 asttokens==2.0.5 async-timeout==4.0.2 atomicwrites==1.4.0 attrs==21.4.0 autobahn==22.2.2 Automat==20.2.0 autopep8==1.6.0 Babel==2.9.1 backcall==0.2.0 beautifulsoup4==4.11.1 black==22.1.0 bleach==4.1.0 build==0.8.0 cachetools==5.0.0 certifi==2021.10.8 cffi==1.15.0 cfgv==3.3.1 charset-normalizer==2.0.12 click==8.0.4 colorama==0.4.4 commonmark==0.9.1 constantly==15.1.0 coverage==6.3.2 cryptography==36.0.1 cycler==0.11.0 debugpy==1.5.1 decorator==5.1.1 defusedxml==0.7.1 distlib==0.3.4 dnspython==2.2.0 docopt==0.6.2 docutils==0.17.1 entrypoints==0.3 esbonio==0.11.0 executing==0.8.2 fett==0.3.2 filelock==3.6.0 flake8 @ file:///opt/conda/conda-bld/flake8_1648129545443/work fonttools==4.29.1 frozenlist==1.3.0 geomdl==5.3.1 google==3.0.0 google-api-core==2.5.0 google-api-python-client==2.37.0 google-auth==2.6.0 google-auth-httplib2==0.1.0 googleapis-common-protos==1.54.0 grpcio==1.43.0 httplib2==0.20.4 hyperlink==21.0.0 identify==2.4.11 idna==3.3 imageio==2.21.3 imageio-ffmpeg==0.4.7 imagesize==1.3.0 importlib-metadata @ file:///C:/ci/importlib-metadata_1648562621412/work incremental==21.3.0 iniconfig==1.1.1 ipycanvas==0.12.0 ipydatawidgets==4.2.0 ipyevents==2.0.1 ipykernel==6.9.1 ipython==8.0.1 ipython-genutils==0.2.0 ipyvtklink==0.2.2 ipywidgets==7.6.5 jedi==0.18.1 Jinja2==3.1.2 json5==0.9.6 jsonschema==4.4.0 jupyter==1.0.0 jupyter-client==7.1.1 jupyter-console==6.4.0 jupyter-core==4.9.1 jupyter-server==1.13.5 jupyter-sphinx==0.4.0 jupyterlab==3.3.3 jupyterlab-pygments==0.1.2 jupyterlab-server==2.10.3 jupyterlab-widgets==1.0.2 keyring==23.6.0 kiwisolver==1.3.2 livereload==2.6.3 mapdl @ file:///C:/Program%20Files/ANSYS%20Inc/v212/ANSYS/syslib/ansGRPC/User/mapdl-pyupf.tar.gz MarkupSafe==2.1.1 matplotlib==3.5.3 matplotlib-inline==0.1.3 mccabe @ file:///opt/conda/conda-bld/mccabe_1644221741721/work mistune==0.8.4 mpmath==1.2.1 multidict==6.0.2 mypy-extensions==0.4.3 nbclassic==0.3.5 nbclient==0.5.10 nbconvert==6.5.0 nbformat==5.2.0 nbsphinx==0.8.8 nest-asyncio==1.5.4 networkx==2.6.3 nodeenv==1.6.0 nose==1.3.7 notebook==6.4.7 numpy==1.22.2 numpydoc==1.4.0 packaging==21.3 pandas==1.4.4 pandocfilters==1.5.0 parso==0.8.3 pathspec==0.9.0 pep517==0.12.0 pickleshare==0.7.5 Pillow==9.0.1 pipx==1.0.0 pkginfo==1.8.3 platformdirs==2.5.1 plotly==5.10.0 pluggy==1.0.0 pre-commit==2.17.0 progressbar2==4.0.0 prometheus-client==0.12.0 prompt-toolkit==3.0.28 protobuf==3.19.4 protoc-gen-swagger==0.1.0 psutil==5.9.1 pure-eval==0.2.2 py==1.11.0 pyansys-sphinx-theme==0.2.3 pyansys-tools-report==0.2.2 pyasn1==0.4.8 pyasn1-modules==0.2.8 pycodestyle @ file:///tmp/build/80754af9/pycodestyle_1636635402688/work pycparser==2.21 pydantic==1.8.2 pydata-sphinx-theme==0.9.0 pyflakes @ file:///tmp/build/80754af9/pyflakes_1636644436481/work pygls==0.11.3 Pygments==2.11.2 pyiges==0.2.1 pymongo==3.12.3 pypandoc==1.8.1 pyparsing==3.0.7 pyrsistent==0.18.1 pyspellchecker==0.6.3 pytest==7.0.1 pytest-cov==3.0.0 pytest-sphinx==0.5.0 python-dateutil==2.8.2 python-jsonrpc-server==0.3.4 python-utils==3.3.3 pythreejs==2.4.1 pytz==2021.3 pyvista==0.36.1 pywin32==303 pywin32-ctypes==0.2.0 pywinpty==1.1.6 PyYAML==5.4.1 pyzmq==22.3.0 qtconsole==5.2.2 QtPy==2.0.0 readme-renderer==35.0 requests==2.27.1 requests-toolbelt==0.9.1 rfc3986==2.0.0 rich==12.4.4 rsa==4.8 rstcheck==3.3.1 scipy==1.8.0 scooby==0.5.12 Send2Trash==1.8.0 six==1.16.0 sniffio==1.2.0 snooty-lextudio==1.12.0 snowballstemmer==2.2.0 soupsieve==2.3.2.post1 Sphinx==5.1.1 sphinx-autobuild==2021.3.14 sphinx-autodoc-typehints==1.19.2 sphinx-copybutton==0.5.0 sphinx-gallery==0.11.1 sphinx-notfound-page==0.8.3 sphinxcontrib-applehelp==1.0.2 sphinxcontrib-devhelp==1.0.2 sphinxcontrib-htmlhelp==2.0.0 sphinxcontrib-jsmath==1.0.1 sphinxcontrib-qthelp==1.0.3 sphinxcontrib-serializinghtml==1.1.5 sphinxcontrib-websupport==1.2.4 sphinxemoji==0.2.0 stack-data==0.2.0 sympy==1.9 tenacity==8.0.1 terminado==0.12.1 testpath==0.5.0 tinycss2==1.1.1 toml==0.10.2 tomli==2.0.1 tornado==6.1 tox==3.25.0 tqdm==4.62.3 traitlets==5.1.1 traittypes==0.2.1 twine==4.0.1 Twisted==22.1.0 twisted-iocpsupport==1.0.2 txaio==22.2.1 typeguard==2.13.3 typing_extensions==4.1.1 uritemplate==4.1.1 urllib3==1.26.8 userpath==1.8.0 virtualenv==20.13.2 vtk==9.0.3 watchdog==1.0.2 wcwidth==0.2.5 webencodings==0.5.1 websocket-client==1.3.1 widgetsnbextension==3.5.2 wincertstore==0.2 wslink==1.4.1 xlrd==2.0.1 yarl==1.7.2 zipp @ file:///opt/conda/conda-bld/zipp_1641824620731/work zope.interface==5.4.0 ```
germa89 commented 2 years ago

Solved issue

It seems that DPF uses the SETs for the Scoping method when using time_freq_steps location.

I couldn't find a way to use LOAD STEP, SUBSTEP or CUMULATIVE in the Scoping operator. Although most of the times SET and CUMULATIVE are the same, we have seen in this VM that it might not be the case.

Notes to admins:

I found out the solution to my problem hence for me, this issue can be closed. However, I still believe some changes should be implemented to correctly handle this case in the future.

I would recommend then:

Pinging @pyansys/pydpf-admins for visibility.

PProfizi commented 2 years ago

Hi @germa89.

I tried replicating and managed to, yet one thing I noticed is you set the scoping to "time_freq_steps", which is not a valid scoping. So I modified your code and got another error. I Think it is basically because if you print the model you'll see that the substep 10 of step 1 is marked as "1".

from ansys.dpf import core as dpf

rst_file = r"D:\ANSYSDev\Sandbox\pydpf-core\Issues\Issue544\file.rst"
model = dpf.Model(rst_file)
print(model)

set_ = (1, 10)
cum_set = model.metadata.time_freq_support.get_cumulative_index(set_[0], set_[1])
print(f"Cumulative set for {set_}: {cum_set}")

scop = dpf.Scoping()
scop.location = dpf.common.locations.time_freq_step
scop.ids = [cum_set]
print(scop)

op = model.results.displacement()
op.inputs.time_scoping.connect(scop)

output = op.outputs.fields_container()[0].data
print(output)

Output obtained:

DPF Model
------------------------------
Static analysis
Unit system: SI: m, kg, s, V, A, K
Physics Type: Mechanical
Available results:
     -  displacement: Nodal Displacement
     -  velocity: Nodal Velocity      
     -  acceleration: Nodal Acceleration
     -  reaction_force: Nodal Force   
     -  element_nodal_forces: ElementalNodal Element nodal Forces
     -  elemental_volume: Elemental Volume
     -  stiffness_matrix_energy: Elemental Energy-stiffness matrix
     -  artificial_hourglass_energy: Elemental Hourglass Energy
     -  thermal_dissipation_energy: Elemental thermal dissipation energy
     -  kinetic_energy: Elemental Kinetic Energy
     -  co_energy: Elemental co-energy
     -  incremental_energy: Elemental incremental energy
     -  structural_temperature: ElementalNodal Temperature
------------------------------
DPF  Meshed Region: 
  3 nodes 
  3 elements 
  Unit:  
  With 
------------------------------
DPF  Time/Freq Support: 
  Number of sets: 110 
Cumulative     Time (s)       LoadStep       Substep         
1              0.001000       1              1               
2              0.002000       2              1               
3              0.003000       2              2               
4              0.004000       2              3               
5              0.005000       2              4               
6              0.006000       2              5               
7              0.007000       2              6               
8              0.008000       2              7               
9              0.009000       2              8               
10             0.010000       2              9               
11             0.011000       2              10              
12             0.012000       2              11              
13             0.013000       2              12              
14             0.014000       2              13              
15             0.015000       2              14              
16             0.016000       2              15              
17             0.017000       2              16              
18             0.018000       2              17              
19             0.019000       2              18              
20             0.020000       2              19              
21             0.021000       2              20              
22             0.022000       2              21              
23             0.023000       2              22              
24             0.024000       2              23              
25             0.025000       2              24              
26             0.026000       2              25              
27             0.027000       2              26              
28             0.028000       2              27              
29             0.029000       2              28              
30             0.030000       2              29              
31             0.031000       2              30              
32             0.032000       2              31              
33             0.033000       2              32              
34             0.034000       2              33              
35             0.035000       2              34              
36             0.036000       2              35              
37             0.037000       2              36              
38             0.038000       2              37              
39             0.039000       2              38              
40             0.040000       2              39              
41             0.041000       2              40              
42             0.042000       2              41              
43             0.043000       2              42              
44             0.044000       2              43              
45             0.045000       2              44              
46             0.046000       2              45              
47             0.047000       2              46              
48             0.048000       2              47              
49             0.049000       2              48              
50             0.050000       2              49              
51             0.051000       2              50              
52             0.052000       2              51              
53             0.053000       2              52              
54             0.054000       2              53              
55             0.055000       2              54              
56             0.056000       2              55              
57             0.057000       2              56              
58             0.058000       2              57              
59             0.059000       2              58              
60             0.060000       2              59              
61             0.061000       2              60              
62             0.062000       2              61              
63             0.063000       2              62              
64             0.064000       2              63              
65             0.065000       2              64              
66             0.066000       2              65              
67             0.067000       2              66              
68             0.068000       2              67              
69             0.069000       2              68              
70             0.070000       2              69              
71             0.071000       2              70              
72             0.072000       2              71              
73             0.073000       2              72              
74             0.074000       2              73              
75             0.075000       2              74              
76             0.076000       2              75              
77             0.077000       2              76              
78             0.078000       2              77              
79             0.079000       2              78              
80             0.080000       2              79              
81             0.081000       2              80              
82             0.082000       2              81              
83             0.083000       2              82              
84             0.084000       2              83              
85             0.085000       2              84              
86             0.086000       2              85              
87             0.087000       2              86              
88             0.088000       2              87              
89             0.089000       2              88              
90             0.090000       2              89              
91             0.091000       2              90              
92             0.092000       2              91              
93             0.093000       2              92              
94             0.094000       2              93              
95             0.095000       2              94              
96             0.096000       2              95              
97             0.097000       2              96              
98             0.098000       2              97              
99             0.099000       2              98              
100            0.100000       2              99              
101            0.101000       2              100             
102            0.102000       2              101             
103            0.103000       2              102             
104            0.104000       2              103             
105            0.105000       2              104             
106            0.106000       2              105             
107            0.107000       2              106             
108            0.108000       2              107             
109            0.109000       2              108             
110            0.110000       2              109             

Cumulative set for (1, 10): 11

DPF  Scoping: 
  with TimeFreq_steps location and 1 entity

Traceback (most recent call last):
  File "D:\ANSYSDev\Sandbox\pydpf-core\Issues\Issue544\issue544.py", line 19, in <module>
    output = op.outputs.fields_container()[0].data
  File "d:\ansysdev\sandbox\pydpf-core\ansys\dpf\core\outputs.py", line 57, in __call__
    return self.get_data()
  File "d:\ansysdev\sandbox\pydpf-core\ansys\dpf\core\outputs.py", line 54, in get_data
    return self._operator.get_output(self._pin, type_output)
  File "d:\ansysdev\sandbox\pydpf-core\ansys\dpf\core\dpf_operator.py", line 375, in get_output
    parameters = {type_tuple[2]: type_tuple[1](self, pin)}
  File "D:\ANSYSDev\Sandbox\pydpf-core\venv\lib\site-packages\ansys\dpf\gate\generated\operator_capi.py", line 368, in operator_getoutput_fields_container
    raise errors.DPFServerException(sError.value)
ansys.dpf.gate.errors.DPFServerException: U:28<-step of id 11 doesn't exist
PProfizi commented 2 years ago

@germa89 further modifying my previous code, I can obtain the right result by asking for: set_ = (1, 0) So:

PProfizi commented 2 years ago

Hi @germa89. So, following a discussion with Ramdane, it appears that the only thing that is guaranteed bijective between DPF and MAPDL is the Load Step ID. The substep ID or cumulative ID in MAPDL is not guaranteed when running in parallel. Thus DPF generates its own substep ID, starting from 1, for each Load Step. Following this, the "cumulative index" is the zero-based position in the data of the (loadstep+substep) combination, yet what is printed by DPF is a "cumulative ID" starting with one, which is thus equivalent to the MAPDL "set".

Clearly there is a lot going on and this required clarification/fixes.

germa89 commented 2 years ago

Indeed a lot of going on... clearly this is challenging.

Thank you very much for your help @PProfizi