Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Average per body #690

Merged
merged 81 commits into from
Oct 16, 2024
Merged

Average per body #690

merged 81 commits into from
Oct 16, 2024

Conversation

janvonrickenbach
Copy link
Contributor

@janvonrickenbach janvonrickenbach commented Sep 3, 2024

Adds an averaging_config to the _get_results and _get_results_workflow functions of

  • static_mechanical_simulation
  • transient_mechanical_simulation
  • modal_mechanical_simulation
  • harmonic_mechanical_simulation

By default the averaging happens across bodies, which is the current behavior. If average_per_body is activated, the results are averaged per body and the resulting Dataframe/FieldsContainer contains separate fields for each body (with the a tuple of the selected properties with which a body is identified). The properties by which bodies are identified are configurable. The tests use the properties "mat", "apdl_element_type", "elshape" and "apdl_real_id". The flag is currently not exposed for the results functions (stress, stress_nodal etc). The mesh support of the fields is always the full mesh.

@janvonrickenbach janvonrickenbach changed the title Jvonrick/average per body impl Average per body Oct 8, 2024
@@ -254,6 +254,7 @@ def _get_result_workflow(

_connect_initial_results_inputs(
initial_result_workflow=initial_result_workflow,
split_by_body_workflow=None,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not supported for fluid simulations

):
res = _result_properties[base_name] if base_name in _result_properties else None
native_location = res["location"] if res is not None else None

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to force elemental nodal if average_across_bodies is False

names_field.get_entity_data_by_id(value)[0] + f" ({value})"
for value in values
]
if label == "mat":
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure this is the right way to do this. Using the code currently in the else block was not working for the "mat" label.

Copy link
Contributor

@PProfizi PProfizi Oct 14, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@janvonrickenbach here the logic is to expose names whenever available instead of IDs. I think this is going to need a rework.
I do not think we have access to material names, so what you did is ok for me.
I think in your case the prrevious code was supposed to end-up in the except.

@@ -66,14 +68,9 @@ def _get_result_workflow(
mesh=self.mesh._meshed_region,
location=location,
force_elemental_nodal=result_workflows.force_elemental_nodal,
averaging_config=averaging_config,
)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not needed anymore, the mesh is already available on the simulation object.



default_per_body_averaging_config = AveragingConfig(
body_defining_properties=[
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to prevent string duplications, could you please use ansys.dpf.core.common.elemental_properties?

"apdl_element_type",
"elshape",
"apdl_real_id",
],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By default do we split over all combinations of these properties?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This configuration is currently only used in the tests. We are still evaluating what are the best properties to split so we get the bodies the user expects. Once we have consolidated that a bit more we can define a default.

selection_wf.connect(_WfNames.initial_mesh, mesh)

if averaging_config.average_per_body:
_enrich_mesh_with_property_fields(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought that the Operator splitting the mesh with a scoping had an option for that?

Copy link
Contributor Author

@janvonrickenbach janvonrickenbach Oct 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see anything related in the docs: https://dpf.docs.pyansys.com/version/stable/operator_reference_load.html split on property type Note: We split the scoping, not the mesh.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't use "meshes::by_scopings" ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No its scoping::by_property. We split the scoping and average the results separately. But all the results have still the original mesh as a support.

default_per_body_averaging_config = AveragingConfig(
body_defining_properties=[
elemental_properties.material,
"mapdl_element_type_id",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@janvonrickenbach is this one specific to your use-case or is it the same as apdl_element_type?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As discussed: moved this default config which is not very generic to the tests

average_per_body: bool = False


default_per_body_averaging_config = AveragingConfig(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@janvonrickenbach the default averaging config is then dedicated to MAPDL results. Should this be dependent on the type of analysis?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As discussed: moved this default config which is not very generic to the tests

@janvonrickenbach janvonrickenbach merged commit 523c102 into master Oct 16, 2024
29 checks passed
@janvonrickenbach janvonrickenbach deleted the jvonrick/average_per_body_impl branch October 16, 2024 13:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants