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

Implement HarmonicMechanicalSimulation results #293

Merged
merged 25 commits into from
Feb 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
b378737
Add HarmonicMechanicalSimulation
PProfizi Feb 20, 2023
e6e16b6
Add amplitude step to _get_result generated workflow
PProfizi Feb 20, 2023
77d4cd3
Add amplitude test
PProfizi Feb 20, 2023
8cdd9fe
Only use "from ansys.dpf import post" and use post.locations instead …
PProfizi Feb 24, 2023
4398d3a
Update _get_result with latest changes in Static, Transient and Modal
PProfizi Feb 24, 2023
63d949f
Add user-friendly and autocomplete friendly inits for simulation types.
PProfizi Feb 24, 2023
996c32b
Add node_ids argument to non-located result APIs for Static
PProfizi Feb 24, 2023
247f4f3
Add node_ids argument to non-located result APIs for Transient
PProfizi Feb 24, 2023
579a3cc
Add node_ids argument to non-located result APIs for Modal
PProfizi Feb 24, 2023
19901a9
Fix type hinting for MechanicalSimulation._build_selection
PProfizi Feb 24, 2023
a8d93aa
Fix load_simulation with new Simulation init
PProfizi Feb 24, 2023
d4be04f
Raise an error if node_ids is given while location is not nodal
PProfizi Feb 24, 2023
f27fa96
Remove first set as default (copied from modal)
PProfizi Feb 27, 2023
aef0226
Add a default sweeping_phase operator at 0°
PProfizi Feb 27, 2023
584fdfb
Fix docstring in transient_mechanical_simulation.py
PProfizi Feb 27, 2023
9deb268
Add result APIs to harmonic_mechanical_simulation.py (without sweepin…
PProfizi Feb 27, 2023
4683107
Add tests to harmonic_mechanical_simulation.py
PProfizi Feb 27, 2023
ca4f286
Fix modal_mechanical_simulation.py tests
PProfizi Feb 27, 2023
508ef00
Fix _get_result docstring
PProfizi Feb 27, 2023
99e74a6
Add coverage for elastic_strain_eqv_von_mises methods
PProfizi Feb 27, 2023
29d2f96
Fix TestModalMechanicalSimulation.test_elastic_strain_eqv_von_mises_n…
PProfizi Feb 27, 2023
4b6ea3a
Remove TestHarmonicMechanicalSimulation.test_velocity and test_accele…
PProfizi Feb 27, 2023
59a19b5
Test with the latest released ansys-dpf-core and not its current master.
PProfizi Feb 27, 2023
0527d2d
Change references to locations in docstrings to only mention locations.X
PProfizi Feb 27, 2023
fb46213
Improve load_steps argument docstring.
PProfizi Feb 27, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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