Skip to content

Commit

Permalink
Implement HarmonicMechanicalSimulation results (#293)
Browse files Browse the repository at this point in the history
* Add HarmonicMechanicalSimulation

* Add amplitude step to _get_result generated workflow

* Add amplitude test

* Only use "from ansys.dpf import post" and use post.locations instead of core.locations

* Update _get_result with latest changes in Static, Transient and Modal

* Add user-friendly and autocomplete friendly inits for simulation types.

* Add node_ids argument to non-located result APIs for Static

* Add node_ids argument to non-located result APIs for Transient

* Add node_ids argument to non-located result APIs for Modal

* Fix type hinting for MechanicalSimulation._build_selection

* Fix load_simulation with new Simulation init

* Raise an error if node_ids is given while location is not nodal

* Remove first set as default (copied from modal)

* Add a default sweeping_phase operator at 0°

* Fix docstring in transient_mechanical_simulation.py

* Add result APIs to harmonic_mechanical_simulation.py (without sweeping_pahse and amplitude)

* Add tests to harmonic_mechanical_simulation.py

* Fix modal_mechanical_simulation.py tests

* Fix _get_result docstring

* Add coverage for elastic_strain_eqv_von_mises methods

* Fix TestModalMechanicalSimulation.test_elastic_strain_eqv_von_mises_nodal and _elemental

* Remove TestHarmonicMechanicalSimulation.test_velocity and test_acceleration for now due to GitHub CI.

* Test with the latest released ansys-dpf-core and not its current master.

* Change references to locations in docstrings to only mention locations.X

* Improve load_steps argument docstring.
  • Loading branch information
PProfizi committed Mar 8, 2023
1 parent fba87bf commit 3d040f9
Show file tree
Hide file tree
Showing 11 changed files with 4,571 additions and 665 deletions.
4 changes: 2 additions & 2 deletions examples/00-Overview/02-get_data_from_static_simulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
###############################################################################
# Imports and loading simulation
# ------------------------------
import ansys.dpf.post as dpf
from ansys.dpf import post
from ansys.dpf.post import examples

simulation = dpf.load_simulation(examples.static_rst)
simulation = post.load_simulation(examples.static_rst)
print(simulation)

###############################################################################
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ maintainers = [
{name = "PyAnsys developers", email = "[email protected]"},
]
dependencies = [
"ansys.dpf.core @ git+https://[email protected]/pyansys/pydpf-core.git",
"ansys.dpf.core",
"scooby",
]
classifiers = [
Expand Down
2 changes: 1 addition & 1 deletion src/ansys/dpf/post/common.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""Module containing the common tools for a better usage of the DPF-Post module."""

from ansys.dpf.post.harmonic_mechanical_simulation import HarmonicMechanicalSimulation
from ansys.dpf.post.modal_mechanical_simulation import ModalMechanicalSimulation
from ansys.dpf.post.simulation import HarmonicMechanicalSimulation
from ansys.dpf.post.static_mechanical_simulation import StaticMechanicalSimulation
from ansys.dpf.post.transient_mechanical_simulation import TransientMechanicalSimulation

Expand Down
2,724 changes: 2,724 additions & 0 deletions src/ansys/dpf/post/harmonic_mechanical_simulation.py

Large diffs are not rendered by default.

349 changes: 217 additions & 132 deletions src/ansys/dpf/post/modal_mechanical_simulation.py

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/ansys/dpf/post/post_utility.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ def load_simulation(
if simulation_type in [
getattr(AvailableSimulationTypes, x) for x in vars(AvailableSimulationTypes)
]:
return simulation_type_str_to_class[simulation_type](data_sources, _model)
return simulation_type_str_to_class[simulation_type](data_sources)
else:
raise ValueError(
f"Simulation type '{simulation_type}' is not a recognized simulation type."
Expand Down
33 changes: 17 additions & 16 deletions src/ansys/dpf/post/simulation.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
"""Module containing the ``Simulation`` class."""
from abc import ABC
from enum import Enum
from os import PathLike
import re
from typing import List, Tuple, Union

import ansys.dpf.core as dpf
from ansys.dpf.core import DataSources, Model
from ansys.dpf.core.plotter import DpfPlotter
import numpy as np

from ansys.dpf import core
from ansys.dpf.post import locations
from ansys.dpf.post.mesh import Mesh
from ansys.dpf.post.selection import Selection

Expand Down Expand Up @@ -374,9 +376,9 @@ def _build_components_from_principal(self, base_name, components):
def _build_result_operator(
self,
name: str,
location: Union[core.locations, str],
location: Union[locations, str],
force_elemental_nodal: bool,
) -> core.Operator:
) -> dpf.Operator:
op = self._model.operator(name=name)
op.connect(7, self.mesh._meshed_region)
if force_elemental_nodal:
Expand All @@ -392,9 +394,11 @@ class MechanicalSimulation(Simulation, ABC):
This class provides common methods and properties for all mechanical type simulations.
"""

def __init__(self, data_sources: core.DataSources, model: core.Model):
def __init__(self, result_file: PathLike):
"""Instantiate a mechanical type simulation."""
super().__init__(data_sources, model)
model = dpf.Model(result_file)
data_sources = model.metadata.data_sources
super().__init__(data_sources=data_sources, model=model)

def _build_selection(
self,
Expand All @@ -408,7 +412,7 @@ def _build_selection(
named_selections: Union[List[str], str, None] = None,
element_ids: Union[List[int], None] = None,
node_ids: Union[List[int], None] = None,
location: core.locations = core.locations.nodal,
location: Union[locations, str] = locations.nodal,
) -> Selection:
tot = (
(node_ids is not None)
Expand All @@ -429,16 +433,21 @@ def _build_selection(
if named_selections:
selection.select_named_selection(named_selection=named_selections)
elif element_ids:
if location == core.locations.nodal:
if location == locations.nodal:
selection.select_nodes_of_elements(elements=element_ids, mesh=self.mesh)
else:
selection.select_elements(elements=element_ids)
elif node_ids:
if location != locations.nodal:
raise ValueError(
"Argument 'node_ids' can only be used if 'location' "
"is equal to 'post.locations.nodal'."
)
selection.select_nodes(nodes=node_ids)
# Create the TimeFreqSelection
if all_sets:
selection.time_freq_selection.select_with_scoping(
core.time_freq_scoping_factory.scoping_on_all_time_freqs(self._model)
dpf.time_freq_scoping_factory.scoping_on_all_time_freqs(self._model)
)
elif set_ids is not None:
if isinstance(set_ids, int):
Expand Down Expand Up @@ -513,11 +522,3 @@ def _build_selection(
time_freq_sets=[self.time_freq_support.n_sets]
)
return selection


class HarmonicMechanicalSimulation(MechanicalSimulation):
"""Provides methods for mechanical harmonic simulations."""

def _build_time_freq_scoping(self) -> core.time_freq_scoping_factory.Scoping:
"""Generate a time_freq_scoping from input arguments."""
pass
Loading

0 comments on commit 3d040f9

Please sign in to comment.