Skip to content

Commit

Permalink
Jvonrick/more doc improvements (#113)
Browse files Browse the repository at this point in the history
* More doc improvements

* Rename criteria to criterion

* Fix sampling point test
  • Loading branch information
janvonrickenbach authored Jan 24, 2023
1 parent c5facfe commit ccbff5b
Show file tree
Hide file tree
Showing 13 changed files with 73 additions and 50 deletions.
3 changes: 3 additions & 0 deletions doc/source/api/composite_model.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,16 @@ Composite Model
CompositeScope
ContinuousFiberCompositesFiles
FailureMeasure
FailureResult
MaterialOperators
ResultDefinition
SamplingPoint
LayupProperty
FailureOutput
SamplingPointFigure
Sym3x3TensorComponent
LayerProperty




11 changes: 5 additions & 6 deletions doc/source/intro.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,20 @@ Since the module is not yet public, please install from github:
pip install git+https://github.com/pyansys/pydpf-composites.git
Whenever you call the function connect_to_or_start_server you have to pass the location of the 231 installer
Whenever you call the function connect_to_or_start_server you have to pass the location of the 23.1 installer
with the ansys_path argument:

.. code::
connect_to_or_start_server(ansys_path=os.environ["AWP_ROOT231"])
Otherwise, the dpf server will be started with the latest installer it finds, which probably is 232.
Otherwise, the dpf server will be started with the latest installer it finds, which probably is 23.2.


Installation
^^^^^^^^^^^^

ansys-dpf-composites supports Ansys version 23.1 and later. Make sure you have licensed copy of Ansys installed.
ansys-dpf-composites supports Ansys version 2023 R1 and later. Make sure you have licensed copy of Ansys installed.
Install the ansys-dpf-composites module from pip:

.. code::
Expand Down Expand Up @@ -97,11 +97,10 @@ detailed output for a sampling point.
# Show sampling point for element with id/label 1
element_id = 1
sampling_point = composite_model.get_sampling_point(
combined_criteria=combined_failure_criterion, element_id=element_id
combined_criterion=combined_failure_criterion, element_id=element_id
)
fig, axes = sampling_point.get_result_plots()
fig.show()
sampling_point.get_result_plots()
.. image:: _static/boat_irf.png
Expand Down
6 changes: 3 additions & 3 deletions examples/1_failure_operator_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,15 @@
# %%
# Failure evaluation for the entire model
output_all_elements = composite_model.evaluate_failure_criteria(
combined_criteria=combined_fc,
combined_criterion=combined_fc,
)
irf_field = output_all_elements.get_field({"failure_label": FailureOutput.failure_value})
irf_field.plot()

# %%
# Scope failure evaluation to a certain element scope
output_two_elements = composite_model.evaluate_failure_criteria(
combined_criteria=combined_fc,
combined_criterion=combined_fc,
composite_scope=CompositeScope(elements=[1, 3]),
)
irf_field = output_two_elements.get_field({"failure_label": FailureOutput.failure_value})
Expand All @@ -80,7 +80,7 @@
# %%
# Scope by plies
output_woven_plies = composite_model.evaluate_failure_criteria(
combined_criteria=combined_fc,
combined_criterion=combined_fc,
composite_scope=CompositeScope(plies=["P1L1__ud_patch ns1"]),
)
irf_field = output_woven_plies.get_field({"failure_label": FailureOutput.failure_value})
Expand Down
16 changes: 8 additions & 8 deletions examples/2_sampling_point_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,25 +58,25 @@

# %%
# Create a sampling point
sampling_point = composite_model.get_sampling_point(combined_criteria=combined_fc, element_id=3)
sampling_point = composite_model.get_sampling_point(combined_criterion=combined_fc, element_id=3)

# %%
# Plot Results
# """"""""""""
#
# Use pre-configured plots. See also :class:`~ansys.dpf.composites.SamplingPoint.get_result_plots`.
fig, axes = sampling_point.get_result_plots(
sampling_point_plot = sampling_point.get_result_plots(
strain_components=[], # do not plot strains
core_scale_factor=0.1,
spots=[Spot.bottom, Spot.top],
show_failure_modes=True,
)
fig.set_figheight(8)
fig.set_figwidth(12)
sampling_point_plot.figure.set_figheight(8)
sampling_point_plot.figure.set_figwidth(12)

# %%
# Plot polar properties
fig, polar_plot = sampling_point.get_polar_plot(["E1", "G12"])
sampling_point_plot = sampling_point.get_polar_plot(["E1", "G12"])

# %%
# Custom plots:
Expand Down Expand Up @@ -131,11 +131,11 @@
#
# The element id of the sampling point can be easily changed.
sampling_point.element_id = 4
fig, axes = sampling_point.get_result_plots(
sampling_point_plot = sampling_point.get_result_plots(
strain_components=[], # do not plot strains
core_scale_factor=0.1,
spots=[Spot.bottom, Spot.top],
show_failure_modes=True,
)
fig.set_figheight(8)
fig.set_figwidth(12)
sampling_point_plot.figure.set_figheight(8)
sampling_point_plot.figure.set_figwidth(12)
2 changes: 1 addition & 1 deletion examples/8_assembly_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
# %%
# Plot the max IRF per element
#
output_all_elements = composite_model.evaluate_failure_criteria(combined_criteria=combined_fc)
output_all_elements = composite_model.evaluate_failure_criteria(combined_criterion=combined_fc)
irf_field = output_all_elements.get_field({"failure_label": FailureOutput.failure_value})
irf_field.plot()

Expand Down
4 changes: 3 additions & 1 deletion src/ansys/dpf/composites/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
)
from .material_setup import MaterialOperators
from .result_definition import ResultDefinition
from .sampling_point import SamplingPoint
from .sampling_point import FailureResult, SamplingPoint, SamplingPointFigure
from .select_indices import (
get_selected_indices,
get_selected_indices_by_analysis_ply,
Expand Down Expand Up @@ -79,4 +79,6 @@
"FailureOutput",
"Sym3x3TensorComponent",
"LayerProperty",
"FailureResult",
"SamplingPointFigure",
]
12 changes: 6 additions & 6 deletions src/ansys/dpf/composites/composite_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ def get_layup_operator(self, composite_definition_label: Optional[str] = None) -

def evaluate_failure_criteria(
self,
combined_criteria: CombinedFailureCriterion,
combined_criterion: CombinedFailureCriterion,
composite_scope: Optional[CompositeScope] = None,
measure: FailureMeasure = FailureMeasure.inverse_reserve_factor,
write_data_for_full_element_scope: bool = True,
Expand All @@ -189,7 +189,7 @@ def evaluate_failure_criteria(
Parameters
----------
combined_criteria:
combined_criterion:
Combined failure criterion to evaluate
composite_scope:
Composite scope on which the failure criteria are evaluated. If
Expand Down Expand Up @@ -239,7 +239,7 @@ def evaluate_failure_criteria(
name="combined failure criteria",
rst_file=self._composite_files.rst,
material_file=self._composite_files.engineering_data,
combined_failure_criterion=combined_criteria,
combined_failure_criterion=combined_criterion,
composite_scopes=scopes,
time=time_in,
measure=measure.value,
Expand All @@ -255,7 +255,7 @@ def evaluate_failure_criteria(

def get_sampling_point(
self,
combined_criteria: CombinedFailureCriterion,
combined_criterion: CombinedFailureCriterion,
element_id: int,
time: Optional[float] = None,
composite_definition_label: Optional[str] = None,
Expand All @@ -264,7 +264,7 @@ def get_sampling_point(
Parameters
----------
combined_criteria:
combined_criterion:
Combined failure criterion to evaluate
element_id:
Element Id/Label of the sampling point
Expand Down Expand Up @@ -304,7 +304,7 @@ def get_sampling_point(
name="combined failure criteria",
rst_file=self._composite_files.rst,
material_file=self._composite_files.engineering_data,
combined_failure_criterion=combined_criteria,
combined_failure_criterion=combined_criterion,
time=time_in,
composite_scopes=[scope],
)
Expand Down
17 changes: 10 additions & 7 deletions src/ansys/dpf/composites/connect_to_or_start_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import os
from typing import Any, Callable, Dict, Optional, Union

import ansys.dpf.core as dpf
from ansys.dpf.core import connect_to_server, server, start_local_server

from ansys.dpf.composites.load_plugin import load_composites_plugin

Expand All @@ -25,7 +25,7 @@ def _try_until_timeout(fun: Callable[[], Any], error_message: str, timeout: int
raise TimeoutError(f"Timeout is reached: {error_message}")


def _wait_until_server_is_up(server: dpf.server) -> Any:
def _wait_until_server_is_up(server: server) -> Any:
# Small hack to check if the server is up
# The dpf server should check this in connect_to_server but that's currently not the case
# https://github.com/pyansys/pydpf-core/issues/414
Expand All @@ -35,21 +35,24 @@ def _wait_until_server_is_up(server: dpf.server) -> Any:

def connect_to_or_start_server(
port: Optional[int] = None, ip: Optional[str] = None, ansys_path: Optional[str] = None
) -> dpf.server:
) -> Any:
r"""Connect to or start a dpf server with the composites plugin loaded.
Note: If port or ip are set, this function will try to
connect to a server and the ansys_path is ignored.
I no arguments are passed a local server from the latest available installer
If no arguments are passed a local server from the latest available installer
is started.
Parameters
----------
port:
ip:
ansys_path:
Ansys root path, for example C:\Program Files\ANSYS Inc\v231.
Ansys root path, for example C:\\Program Files\\ANSYS Inc\\v231.
Ignored if either port or ip are set.
Returns
-------
dpf server
"""
port_in_env = os.environ.get("PYDPF_COMPOSITES_DOCKER_CONTAINER_PORT")
if port_in_env is not None:
Expand All @@ -62,9 +65,9 @@ def connect_to_or_start_server(
connect_kwargs["ip"] = ip

if len(list(connect_kwargs.keys())) > 0:
server = dpf.server.connect_to_server(**connect_kwargs)
server = connect_to_server(**connect_kwargs)
else:
server = dpf.server.start_local_server(ansys_path=ansys_path)
server = start_local_server(ansys_path=ansys_path)

server.check_version(
"5.0",
Expand Down
4 changes: 2 additions & 2 deletions src/ansys/dpf/composites/failure_criteria/puck.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,10 @@ def _get_wf_pd(self) -> float:
def _set_wf_pd(self, value: float) -> None:
self._wf_pd = value

def _get_cfps(self) -> float:
def _get_cfps(self) -> bool:
return self._cfps

def _set_cfps(self, value: float) -> None:
def _set_cfps(self, value: bool) -> None:
self._cfps = value

def _get_s(self) -> float:
Expand Down
28 changes: 22 additions & 6 deletions src/ansys/dpf/composites/sampling_point.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"""Wrapper for the Sampling Point Operator."""

from collections import namedtuple
import dataclasses
import hashlib
import json
from typing import Any, Collection, Dict, List, Sequence, Union, cast
Expand All @@ -17,8 +16,23 @@
from .load_plugin import load_composites_plugin
from .result_definition import ResultDefinition

SamplingPointFigure = namedtuple("SamplingPointFigure", ("figure", "axes"))
FailureResult = namedtuple("FailureResult", "mode irf rf mos")

@dataclasses.dataclass(frozen=True)
class SamplingPointFigure:
"""Sampling Point Figure and Axes."""

figure: Any
axes: Any


@dataclasses.dataclass(frozen=True)
class FailureResult:
"""Components of a failure result."""

mode: str
irf: float
rf: float
mos: float


def _check_result_definition_has_single_scope(result_definition: ResultDefinition) -> None:
Expand Down Expand Up @@ -474,7 +488,9 @@ def get_ply_wise_critical_failures(self) -> List[FailureResult]:

return result

def get_polar_plot(self, components: Sequence[str] = ("E1", "E2", "G12")) -> Any:
def get_polar_plot(
self, components: Sequence[str] = ("E1", "E2", "G12")
) -> SamplingPointFigure:
"""Create a standard polar plot to visualize the polar properties of the laminate.
Parameters
Expand Down Expand Up @@ -599,7 +615,7 @@ def get_result_plots(
create_laminate_plot: bool = True,
core_scale_factor: float = 1.0,
spots: Collection[Spot] = (Spot.bottom, Spot.middle, Spot.top),
) -> Any:
) -> SamplingPointFigure:
"""Generate a figure with a grid of axes (plot) for each selected result entity.
Parameters
Expand Down
10 changes: 5 additions & 5 deletions tests/composite_model_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def test_basic_functionality_of_composite_model(dpf_server):
)

failure_output = composite_model.evaluate_failure_criteria(
combined_criteria=combined_failure_criterion,
combined_criterion=combined_failure_criterion,
composite_scope=CompositeScope(),
)
irf_field = failure_output.get_field({"failure_label": FailureOutput.failure_value})
Expand Down Expand Up @@ -133,7 +133,7 @@ def test_basic_functionality_of_composite_model(dpf_server):
assert composite_model.get_mesh() is not None
assert composite_model.data_sources is not None
sampling_point = composite_model.get_sampling_point(
combined_criteria=combined_failure_criterion, element_id=1
combined_criterion=combined_failure_criterion, element_id=1
)

assert [ply["id"] for ply in sampling_point.analysis_plies] == analysis_ply_ids
Expand Down Expand Up @@ -164,7 +164,7 @@ def test_assembly_model(dpf_server):
)

failure_output = composite_model.evaluate_failure_criteria(
combined_criteria=combined_failure_criterion,
combined_criterion=combined_failure_criterion,
composite_scope=CompositeScope(),
)
timer.add("After get failure output")
Expand Down Expand Up @@ -259,7 +259,7 @@ def test_assembly_model(dpf_server):
assert composite_model.get_mesh(solid_label) is not None
assert composite_model.data_sources is not None
sampling_point = composite_model.get_sampling_point(
combined_criteria=combined_failure_criterion,
combined_criterion=combined_failure_criterion,
element_id=shell_element_id,
composite_definition_label=shell_label,
)
Expand Down Expand Up @@ -305,7 +305,7 @@ def test_failure_measures(dpf_server):

for v in FailureMeasure:
failure_output = composite_model.evaluate_failure_criteria(
combined_criteria=combined_failure_criterion,
combined_criterion=combined_failure_criterion,
composite_scope=CompositeScope(),
measure=v,
)
Expand Down
6 changes: 3 additions & 3 deletions tests/getting_started_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,13 @@ def test_getting_started(dpf_server: dpf.server):

irf_field = failure_result.get_field({"failure_label": FailureOutput.failure_value})
# Commented because it blocks execution. Uncomment this
# line when you copy this code the the getting started example
# line when you copy this code the getting started example
# irf_field.plot()

# Show sampling point for element with id/label 1
element_id = 1
sampling_point = composite_model.get_sampling_point(
combined_criteria=combined_failure_criterion, element_id=element_id
combined_criterion=combined_failure_criterion, element_id=element_id
)

fig, axes = sampling_point.get_result_plots()
sampling_point.get_result_plots()
Loading

0 comments on commit ccbff5b

Please sign in to comment.