ansys / pydpf-core

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

erp_accumulate_results operator not working #1285

Open pmaroneh opened 1 year ago

pmaroneh commented 1 year ago

Before submitting the issue

Description of the bug

All input pins of erp_accumulate_results operator have been defined, but I get an error message saying that some input parameters are missing or badly defined.

image

This has been reported here: https://discuss.ansys.com/discussion/comment/3118#Comment_3118

Steps To Reproduce

Execute following code:

import ansys.dpf.core as dpf
import numpy as np

path = r"C:\Data\file.rst"

model = dpf.Model(path)

tfreq = model.metadata.time_freq_support.time_frequencies
freqVal = np.array(tfreq.data)

opNamedSel = dpf.operators.scoping.on_named_selection()
opNamedSel.inputs.named_selection_name.connect("LARGE")
opNamedSel.inputs.requested_location.connect("Nodal")
opNamedSel.inputs.data_sources.connect(model)
NSmeshscope = opNamedSel.outputs.mesh_scoping()

fullMesh = model.metadata.meshed_region
op = dpf.operators.mesh.skin() # operator instantiation
op.inputs.mesh.connect(fullMesh)
op.inputs.mesh_scoping.connect(NSmeshscope)# optional
skinMesh = op.outputs.mesh()

op = dpf.operators.result.displacement() # operator instantiation
op.inputs.time_scoping.connect(tfreq)# optional
op.inputs.data_sources.connect(model)
op.inputs.mesh.connect(skinMesh)# optional
disp_fc = op.outputs.fields_container()

erp_field = dpf.operators.result.erp_accumulate_results() # operator instantiation
erp_field.inputs.fields_container.connect(disp_fc)
erp_field.inputs.mesh.connect(skinMesh)
erp_field.inputs.time_scoping.connect(int(1))
erp_field.inputs.mass_density.connect(float(1.293))
erp_field.inputs.speed_of_sound.connect(float(346.0))
erp_field.inputs.erp_type.connect(int(0))
erp_field.inputs.boolean.connect(False)
erp_field.inputs.factor.connect(float(1E-12))
my_field = erp_field.outputs.field()

Which Operating System causes the issue?

Windows

Which DPF/Ansys version are you using?

Ansys 2023 R1

Which Python version causes the issue?

3.10

Installed packages

ansys-dpf-core 0.10.0
asttokens 2.4.1
cachetools 5.3.2
certifi 2023.11.17 charset-normalizer 3.3.2
colorama 0.4.6
comm 0.2.0
debugpy 1.8.0
decorator 5.1.1
exceptiongroup 1.2.0
executing 2.0.1
google-api-core 2.14.0
google-api-python-client 2.108.0 google-auth 2.23.4 google-auth-httplib2 0.1.1 googleapis-common-protos 1.61.0 grpcio 1.59.3 httplib2 0.22.0 idna 3.4 importlib-metadata 6.8.0 ipykernel 6.26.0 ipython 8.17.2 jedi 0.19.1 jupyter_client 8.6.0 jupyter_core 5.5.0 matplotlib-inline 0.1.6 nest-asyncio 1.5.8 numpy 1.26.2 packaging 23.2 parso 0.8.3 pip 23.3.1 platformdirs 4.0.0 prompt-toolkit 3.0.41 protobuf 4.25.1 psutil 5.9.6 pure-eval 0.2.2 pyasn1 0.5.1 pyasn1-modules 0.3.0 Pygments 2.17.1 pyparsing 3.1.1 python-dateutil 2.8.2 pywin32 306 pyzmq 25.1.1 requests 2.31.0 rsa 4.9 setuptools 65.5.0 six 1.16.0 stack-data 0.6.3 tornado 6.3.3 tqdm 4.66.1 traitlets 5.13.0 uritemplate 4.1.1 urllib3 2.1.0 wcwidth 0.2.11 zipp 3.17.0

PProfizi commented 10 months ago

Hi @pmaroneh, Just started looking at the issue, and it seems this exact error can only appear if:

Would it be possible to check for all of these criteria? It is most likely that disp_fc does not have the complex label. You can check that by printing the available labels of the FieldsContainer like so:

print(disp_fc.labels)

PS: I will ask for the operator's documentation and specification to be updated as it seems most pins are optional but not marked as such, and some pin descriptions are not clear enough.

KristianKvistIbsen commented 10 months ago

Hi PProfizi - Thanks for the help!

If I extract the displacement field from a damped Harmonic solution, the displacements should be complex (right?) Can i manually assign the "complex" label, and simply set complex part to zero in cases where displacements are purely real-valued?

PProfizi commented 10 months ago

Hi @KristianKvistIbsen,

To make sure the displacements are complex, you can use the following command to list the labels associated to the FieldsContainer:

print(disp_fc.labels)

It seems right now we do not have an operator to add a null imaginary part to all fields in a FieldsContainer, yet here is how you can do it:

from ansys.dpf import core as dpf

#############
# Construct a mock FieldsContainer with only real fields labelled in time
field_real = dpf.field_from_array([1., 2., 3.])
fc_real = dpf.fields_container_factory.over_time_freq_fields_container(
    fields=[field_real],
)
print(fc_real)
############# 

# Copy the real FieldsContainer, multiply it by zero
fc_imaginary = (fc_real.deep_copy() * 0.).eval()
# then manually add the "complex" label to each FieldsContainer
fc_real.add_label(label="complex", default_value=0)
print(fc_real)
fc_imaginary.add_label(label="complex", default_value=1)
print(fc_imaginary)
# and merge the two
fc_complex = dpf.operators.utility.merge_fields_containers(
    fields_containers1=fc_real, fields_containers2=fc_imaginary
).eval()
print(fc_complex)
KristianKvistIbsen commented 10 months ago

Thanks again! - I will run a test to see if i can get some results from the erp_accumulate_results() operator. I will return with an update.

UPDATE:

I have re-run the code originally posted by @pmaroneh, still resulting in the error: DPFServerException: erp_accumulate_results:31<-ERP input parameters are missing or badly defined. Printing labels resulted in:

print(disp_fc.labels)
['complex', 'time']