Skip to content

Commit

Permalink
doc: modified more files
Browse files Browse the repository at this point in the history
  • Loading branch information
moe-ad committed Dec 24, 2024
1 parent da69029 commit 6a6f2a9
Show file tree
Hide file tree
Showing 7 changed files with 129 additions and 81 deletions.
51 changes: 37 additions & 14 deletions src/ansys/dpf/core/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
# SOFTWARE.

"""
Common
Common.
.. autoclass:: locations
:members:
Expand Down Expand Up @@ -82,13 +82,7 @@ def __missing__(self, key):


class types(Enum):
"""
The ``'types'`` enum contains the available types passed through operators
and workflows to DPF.
"""
"""The ``'types'`` enum contains the available types passed through operators and workflows to DPF."""

# Types from grpc proto, do not modify
string = 0
Expand Down Expand Up @@ -126,6 +120,13 @@ class types(Enum):


def types_enum_to_types():
"""Return a mapping of enums and corresponding python or dpf types.
Returns
-------
dict
Mapping of enum to the corresponding type.
"""
from ansys.dpf.core import (
cyclic_support,
data_sources,
Expand Down Expand Up @@ -185,6 +186,7 @@ def types_enum_to_types():

class natures(Enum):
"""The ``'natures'`` enum contains the dimensionality types.
It can be used to create a field of a given dimensionality.
"""

Expand All @@ -195,7 +197,9 @@ class natures(Enum):


class shell_layers(Enum):
"""The ``'shell_layers'`` enum contains the available order of
"""Contains data identifying shell layers.
The ``'shell_layers'`` enum contains the available order of
shell layers (or lack of shell layers) that defines how the
field's data is ordered.
"""
Expand Down Expand Up @@ -303,6 +307,8 @@ class DefinitionLabels:


class TqdmProgressBar(ProgressBarBase):
"""Custom progress bar implementation based on tqdm."""

def __init__(self, text, unit, tot_size=None):
import tqdm

Expand All @@ -322,13 +328,21 @@ def __init__(self, text, unit, tot_size=None):
)

def update(self, current_value):
"""Modify how the current value of the progress bar is updated."""
if self.tot_size is None:
self.bar.total = current_value * 2
self.bar.update(current_value - self.current)
self.current = current_value

@staticmethod
def progress_available():
"""Check if the tdqm module exists.
Returns
-------
bool
True if module exists, else False.
"""
return module_exists("tqdm")


Expand All @@ -345,10 +359,10 @@ def _common_percentage_progress_bar(text):


class SubClassSmartDict(dict):
"""Return the superclass name for a key if not found initially."""

def __getitem__(self, item):
"""If found returns the item of key == ìtem`, else returns item with key matching `issubclass(item,
key)`.
"""
"""If found returns the item of key == ìtem`, else returns item with key matching `issubclass(item, key)`."""
if item in self:
return super().__getitem__(item)
else:
Expand All @@ -362,6 +376,13 @@ def __getitem__(self, item):


def type_to_internal_object_keyword():
"""Return dpf types mapped to internal object keywords.
Returns
-------
SubClassSmartDict
Custom dictionary that returns superclass name for a key if not found initially.
"""
global _type_to_internal_object_keyword
if _type_to_internal_object_keyword is None:
from ansys.dpf.core import (
Expand Down Expand Up @@ -418,6 +439,7 @@ def type_to_internal_object_keyword():


def type_to_special_dpf_constructors():
"""Return dpf type mapped to special dpf constructors."""
global _type_to_special_dpf_constructors
if _type_to_special_dpf_constructors is None:
from ansys.dpf.gate.dpf_vector import DPFVectorInt
Expand All @@ -436,7 +458,7 @@ def type_to_special_dpf_constructors():

def derived_class_name_to_type() -> Dict[str, type]:
"""
Returns a mapping of derived class names to their corresponding Python classes.
Return a mapping of derived class names to their corresponding Python classes.
Returns
-------
Expand All @@ -454,7 +476,7 @@ def derived_class_name_to_type() -> Dict[str, type]:

def record_derived_class(class_name: str, py_class: type, overwrite: bool = False):
"""
Records a new derived class in the mapping of class names to their corresponding Python classes.
Record a new derived class in the mapping of class names to their corresponding Python classes.
This function updates the global dictionary that maps derived class names (str) to their corresponding
Python class objects (type). If the provided class name already exists in the dictionary, it will either
Expand All @@ -477,6 +499,7 @@ def record_derived_class(class_name: str, py_class: type, overwrite: bool = Fals


def create_dpf_instance(type, internal_obj, server):
"""Create a server instance of a given type."""
spe_constructors = type_to_special_dpf_constructors()
if type in spe_constructors:
return spe_constructors[type](internal_obj, server)
Expand Down
23 changes: 14 additions & 9 deletions src/ansys/dpf/core/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,7 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

"""
Operator Configuration
"""
"""Operator Configuration."""

import functools
import warnings
Expand Down Expand Up @@ -222,6 +219,18 @@ def config_option_value(self, config_name):
raise KeyError(f"{config_name} option doesn't exist.")

def __try_get_option__(self, config_name):
"""Return option associated with a given config name.
Parameters
----------
config_name : _type_
Name of the configuration.
Returns
-------
ConfigSpecification
Available configuration options supported by the Operator
"""
if self._config_help:
if config_name in self._config_help:
return self._config_help[config_name]
Expand Down Expand Up @@ -265,11 +274,6 @@ def config_option_accepted_types(self, config_name):
def config_option_default_value(self, config_name):
"""Retrieve the default value for a configuration option.
Parameters
----------
config_name : str
Name of the configuration option.
Returns
-------
str
Expand Down Expand Up @@ -307,6 +311,7 @@ def __str__(self):
return _description(self._internal_obj, self._server)

def __del__(self):
"""Delete this instance of config."""
try:
self._deleter_func[0](self._deleter_func[1](self))
except:
Expand Down
Loading

0 comments on commit 6a6f2a9

Please sign in to comment.