DPF: scoping on named selection operator doesn't work

dafedin
dafedin Member Posts: 21
10 Comments First Anniversary Name Dropper
**

Hello all,

When I was trying to use dpf.operators.scoping.on_named_selection() in my script in Mechanical, I encountered a problem while trying to access the named selection’s data. I have two named selections in my model:

1.    ns_tree (created in model tree using Mechanical interface);

2.    ns_apdl (created via APDL -script).

The both are present in solver components names and node id is accessible via APDL -script as well. Then, I try to get node Id via DPF-script:

import mech_dpf

import Ans.DataProcessing as dpf

import os

mech_dpf.setExtAPI(ExtAPI)

analyses = ExtAPI.DataModel.AnalysisList

analysis = analyses[0]

analysis_dir_path = analysis.WorkingDir

path = os.path.join(analysis_dir_path, 'file.rst')

dataSources = mech_dpf.GetDataSources()


op = dpf.operators.scoping.on_named_selection()

op.inputs.requested_location.Connect('Nodal')

op.inputs.named_selection_name.Connect('NS_TREE')

op.inputs.data_sources.Connect(dataSources)

my_mesh_scoping = op.outputs.mesh_scoping.GetData()

print(my_mesh_scoping)

The DPF-script works fine only for named selection, created via Mechanical interface, but not for named selection, created via APDL. In the case of named selection, created via APDL, I get the following error message:

scoping_provider_by_ns:0<-error: GetScoping -Failed to read the named selection or the named selection is empty-:line 22

Hence, for DPF, the named selection, created via APDL, is empty or not accessible! Is it a known issue? Is there a workaround?

Best Answer

  • dafedin
    dafedin Member Posts: 21
    10 Comments First Anniversary Name Dropper
    **
    Answer ✓

    Hello all,

    The solution has been found! Now it is clear, that in the code proposed earlier named selection's location is unknown. The following code gets the entity data regardless of the type of named selection:

    import mech_dpf

    import Ans.DataProcessing as dpf

    import os


    mech_dpf.setExtAPI(ExtAPI)

    analyses = ExtAPI.DataModel.AnalysisList

    analysis = analyses[0]

    analysis_dir_path = analysis.WorkingDir

    path = os.path.join(analysis_dir_path, 'file.rst')

    model = dpf.Model(path)

    nsName_nodal = model.AvailableNamedSelections[1]

    scoping = dpf.MeshScopingFactory.NamedSelectionScoping(nsName_nodal, model)

    scoping.Location = 'Nodal'

    dataSources = mech_dpf.GetDataSources(0)

    stress_X = dpf.operators.result.stress_X()

    stress_X.inputs.data_sources.Connect(dataSources)

    stress_X.inputs.mesh_scoping.Connect(scoping)

    my_sx = stress_X.outputs.fields_container.GetData()

    sx = my_sx[0].Data

    print(sx)[0]

    I hope this insight is helpful to the community.

    Thanks for all and regards

Answers

  • Rajesh Meena
    Rajesh Meena Moderator, Employee Posts: 85
    Second Anniversary 10 Comments 5 Answers Solution Developer Community of Practice Member
    ✭✭✭✭

    @dafedin I could not reproduce this.


    Make sure you see the components in solution worksheet and make sure you use component name with all CAPITAL letters when trying to get scoping for it.


    Feel free to share your project if you are unable to get around it.

  • dafedin
    dafedin Member Posts: 21
    10 Comments First Anniversary Name Dropper
    **

    Hi @Rajesh Kumar Meena,

    Of course, I am sure that both components are present in the Solution Worksheet and are not empty.

    The ns_tree is readable by DPF but ns_apdl is not!

    I've attached the demo project archive (2022R2, extension changed from .wbpz to .rar) to show You the case.

    Regards.