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

Various improvements to streamline example code #350

Merged
merged 40 commits into from
Jan 31, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
4aeb607
Initial prototypes for workflow and examples
janvonrickenbach Jan 19, 2024
8bcfa09
Move to_pvista function to individual data points
janvonrickenbach Jan 22, 2024
80ff74d
Cleanup example
janvonrickenbach Jan 23, 2024
b81ed76
Fix component names in mesh data
janvonrickenbach Jan 23, 2024
40f5444
Initial prototypes for workflow and examples
janvonrickenbach Jan 23, 2024
d88d2f4
Document upload and download
janvonrickenbach Jan 23, 2024
2152ab7
Remove unneeded readme parts
janvonrickenbach Jan 23, 2024
f3faadd
Initial prototypes for workflow and examples
janvonrickenbach Jan 24, 2024
7702f4f
Improve plotting API
janvonrickenbach Jan 24, 2024
7e2c94a
Move temp directory logic from ACP Client to ACP workflow
janvonrickenbach Jan 24, 2024
d6c4204
Merge with main
janvonrickenbach Jan 25, 2024
5f7f062
Add type hints for plot data objects
janvonrickenbach Jan 25, 2024
d2e6ef8
Get example files from example-data repo
janvonrickenbach Jan 25, 2024
8ce6887
Fix download location of example
janvonrickenbach Jan 25, 2024
3f3c5e6
Fix package structure and add documentation
janvonrickenbach Jan 25, 2024
bc7f779
Delay import of ansys-dpf-composites
janvonrickenbach Jan 25, 2024
db17cab
Finish tree printer
janvonrickenbach Jan 26, 2024
b11678e
Add tests for workflow
janvonrickenbach Jan 26, 2024
fe570fb
Merge branch 'main' into feat/cleanup_for_release
janvonrickenbach Jan 26, 2024
35d4295
Add type checks for plots
janvonrickenbach Jan 26, 2024
153de9c
Return labels the same way as other data.
janvonrickenbach Jan 26, 2024
2b2e8cc
Convert unit systems.
janvonrickenbach Jan 29, 2024
8d12d56
Delay imports from dpf core
janvonrickenbach Jan 29, 2024
92128de
Remove obsolete local example
janvonrickenbach Jan 29, 2024
ec44b32
Remove obsolete local example
janvonrickenbach Jan 29, 2024
cb2c796
Remove obsolete local example
janvonrickenbach Jan 29, 2024
116231c
Fix docstring
janvonrickenbach Jan 30, 2024
2e23309
Avoid modifications of input files and fix doc
janvonrickenbach Jan 30, 2024
a4c3acd
Remove obsolete input file
janvonrickenbach Jan 30, 2024
d5d6b47
Implement PR comments
janvonrickenbach Jan 31, 2024
581386a
Improve tree printer
janvonrickenbach Jan 31, 2024
73d57f9
Update src/ansys/acp/core/_workflow.py
janvonrickenbach Jan 31, 2024
f448438
Update src/ansys/acp/core/_workflow.py
janvonrickenbach Jan 31, 2024
ddc2f37
Update src/ansys/acp/core/_workflow.py
janvonrickenbach Jan 31, 2024
4e912b9
Fix renames
janvonrickenbach Jan 31, 2024
fb0dba0
Better import error for optional dependencies
janvonrickenbach Jan 31, 2024
22c0bc4
Fix renames
janvonrickenbach Jan 31, 2024
423b387
Fix examples title
janvonrickenbach Jan 31, 2024
560a9c3
Remove note on docker containers from example readme
janvonrickenbach Jan 31, 2024
af1b49c
Close open dpf streams by setting composite model to None
janvonrickenbach Jan 31, 2024
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
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ On Windows:

The generated HTML files can be viewed with the browser of your choice.

Alternatively you can build the documentation by starting an mapdl and pydpf-composites docker
Alternatively you can build the documentation by starting a mapdl and pydpf-composites docker
janvonrickenbach marked this conversation as resolved.
Show resolved Hide resolved
container. First ensure that you have accepted the DPF Preview License Agreement by setting the
ANSYS_DPF_ACCEPT_LA environment variable to Y
(see `DPF Preview License Agreement <https://dpf.docs.pyansys.com/version/stable/user_guide/getting_started_with_dpf_server.html#dpf-preview-license-agreement>`_
Expand Down
2 changes: 2 additions & 0 deletions doc/source/api/workflow.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ Workflow
ACPWorkflow
get_composite_post_processing_files
get_model_tree
janvonrickenbach marked this conversation as resolved.
Show resolved Hide resolved
get_dpf_unit_system
print_model



11 changes: 4 additions & 7 deletions examples/001_basic_flat_plate.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
ACPWorkflow,
Client,
get_composite_post_processing_files,
get_dpf_unit_system,
launch_acp,
print_model,
)
Expand Down Expand Up @@ -57,7 +58,7 @@

# %%
# Define the input file and instantiate an ACPWorkflow
# The ACPWorkflow class provides convenience methods which simplifies the file handling.
# The ACPWorkflow class provides convenience methods which simplify the file handling.
# It automatically creates a model based on the input file.

workflow = ACPWorkflow(
Expand Down Expand Up @@ -96,9 +97,6 @@
eSxz=strain_limit,
)

# Deletes the StructuralSteel Todo should we remove it from the input cdb
# model.materials["1"]

ud_material = model.create_material(
name="UD",
ply_type=PlyType.REGULAR,
Expand Down Expand Up @@ -133,7 +131,7 @@


# %%
# Create various plies a different angles and add them to a modeling group
# Create various plies with different angles and add them to a modeling group
modeling_group = model.create_modeling_group(name="modeling_group")
angles = [0, 45, -45, 45, -45, 0]
for idx, angle in enumerate(angles):
Expand Down Expand Up @@ -200,7 +198,6 @@
from ansys.dpf.composites.constants import FailureOutput
from ansys.dpf.composites.failure_criteria import CombinedFailureCriterion, MaxStrainCriterion
from ansys.dpf.composites.server_helpers import connect_to_or_start_server
from ansys.dpf.core.unit_system import unit_systems

# %%
# Connect to the server. The ``connect_to_or_start_server`` function
Expand All @@ -220,7 +217,7 @@
# Create the CompositeModel and configure its input
composite_model = CompositeModel(
get_composite_post_processing_files(workflow, rst_file_local_path),
default_unit_system=unit_systems.solver_nmm,
default_unit_system=get_dpf_unit_system(model.unit_system),
server=dpf_server,
)

Expand Down
3 changes: 2 additions & 1 deletion src/ansys/acp/core/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
VirtualGeometry,
)
from ._utils.example_helpers import ExampleKeys, get_example_file
from ._workflow import ACPWorkflow, get_composite_post_processing_files
from ._workflow import ACPWorkflow, get_composite_post_processing_files, get_dpf_unit_system

__version__ = importlib.metadata.version(__name__.replace(".", "-"))

Expand Down Expand Up @@ -103,4 +103,5 @@
"print_model",
"ScalarData",
"VectorData",
"get_dpf_unit_system",
]
2 changes: 1 addition & 1 deletion src/ansys/acp/core/_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def download_file(self, remote_filename: _PATH, local_path: _PATH) -> None:
Download a file from the server.

If the server is remote, download the file to the local path.
If the server is local do nothing.
If the server is local, do nothing.

Parameters
----------
Expand Down
1 change: 1 addition & 0 deletions src/ansys/acp/core/_tree_objects/_mesh_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,7 @@ def get_pyvista_glyphs(


def _check_field_type(klass: Any, field_name: str, actual_field_type: str) -> None:
"""Checks that the type declared in the dataclass (klass) matches the actual type."""
declared_field_types: typing.Sequence[str] = cast(
typing.Sequence[str],
[field.type for field in dataclasses.fields(klass) if field.name == field_name],
Expand Down
2 changes: 1 addition & 1 deletion src/ansys/acp/core/_utils/example_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class ExampleKeys(Enum):


def get_example_file(example_key: ExampleKeys, working_directory: pathlib.Path) -> pathlib.Path:
"""Download an example file from the example-data repo to the working directory.
"""Downloads an example file from the example-data repo to the working directory.

Parameters
----------
Expand Down
36 changes: 35 additions & 1 deletion src/ansys/acp/core/_workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@
import tempfile
from typing import Any, Callable, Optional, Protocol

from ansys.dpf.core import UnitSystem, unit_systems

from . import UnitSystemType
from ._client import Client
from ._tree_objects import Model
from ._typing_helper import PATH

__all__ = ["ACPWorkflow", "get_composite_post_processing_files"]
__all__ = ["ACPWorkflow", "get_composite_post_processing_files", "get_dpf_unit_system"]


class _LocalWorkingDir:
Expand Down Expand Up @@ -210,3 +213,34 @@ def get_composite_post_processing_files(
engineering_data=acp_workflow.get_local_materials_file(),
)
return composite_files


def get_dpf_unit_system(unit_system: UnitSystemType) -> UnitSystem:
"""Converts pyACP unit system to DPF unit system.

Parameters
----------
unit_system
The pyACP unit system.
"""
unit_systems_map = {
UnitSystemType.UNDEFINED: unit_systems.undefined,
# looks like the only difference from MKS to SI is
# that temperature is defined as Kelvin in SI and °C in MKS.
# We should still force the user to use MKS in this case.
UnitSystemType.SI: None,
UnitSystemType.MKS: unit_systems.solver_mks,
UnitSystemType.uMKS: unit_systems.solver_umks,
UnitSystemType.CGS: unit_systems.solver_cgs,
# MPA is equivalent to nmm
UnitSystemType.MPA: unit_systems.solver_nmm,
UnitSystemType.BFT: unit_systems.solver_bft,
UnitSystemType.BIN: unit_systems.solver_bin,
}

if unit_systems_map[unit_system] is None:
raise ValueError(f"Unit system {unit_system} not supported. Use MKS instead of SI.")
if unit_system not in unit_systems_map:
raise ValueError(f"Unit system {unit_system} not supported.")

return unit_systems_map[unit_system]
Loading