Source code for pyleecan.Classes.SlotCirc

# -*- coding: utf-8 -*-
# File generated according to Generator/ClassesRef/Slot/SlotCirc.csv
# WARNING! All changes made in this file will be lost!
"""Method code available at https://github.com/Eomys/pyleecan/tree/master/pyleecan/Methods/Slot/SlotCirc
"""

from os import linesep
from sys import getsizeof
from logging import getLogger
from ._check import check_var, raise_
from ..Functions.get_logger import get_logger
from ..Functions.save import save
from ..Functions.load import load_init_dict
from ..Functions.Load.import_class import import_class
from copy import deepcopy
from .Slot import Slot

# Import all class method
# Try/catch to remove unnecessary dependencies in unused method
try:
    from ..Methods.Slot.SlotCirc._comp_line_dict import _comp_line_dict
except ImportError as error:
    _comp_line_dict = error

try:
    from ..Methods.Slot.SlotCirc._comp_point_coordinate import _comp_point_coordinate
except ImportError as error:
    _comp_point_coordinate = error

try:
    from ..Methods.Slot.SlotCirc._comp_R0 import _comp_R0
except ImportError as error:
    _comp_R0 = error

try:
    from ..Methods.Slot.SlotCirc.build_geometry import build_geometry
except ImportError as error:
    build_geometry = error

try:
    from ..Methods.Slot.SlotCirc.check import check
except ImportError as error:
    check = error

try:
    from ..Methods.Slot.SlotCirc.comp_angle_opening import comp_angle_opening
except ImportError as error:
    comp_angle_opening = error

try:
    from ..Methods.Slot.SlotCirc.comp_height import comp_height
except ImportError as error:
    comp_height = error

try:
    from ..Methods.Slot.SlotCirc.comp_height_active import comp_height_active
except ImportError as error:
    comp_height_active = error

try:
    from ..Methods.Slot.SlotCirc.comp_surface import comp_surface
except ImportError as error:
    comp_surface = error

try:
    from ..Methods.Slot.SlotCirc.comp_surface_active import comp_surface_active
except ImportError as error:
    comp_surface_active = error

try:
    from ..Methods.Slot.SlotCirc.comp_surface_opening import comp_surface_opening
except ImportError as error:
    comp_surface_opening = error

try:
    from ..Methods.Slot.SlotCirc.get_surface_active import get_surface_active
except ImportError as error:
    get_surface_active = error

try:
    from ..Methods.Slot.SlotCirc.get_surface_opening import get_surface_opening
except ImportError as error:
    get_surface_opening = error

try:
    from ..Methods.Slot.SlotCirc.plot_schematics import plot_schematics
except ImportError as error:
    plot_schematics = error

try:
    from ..Methods.Slot.SlotCirc.convert_to_H0_bore import convert_to_H0_bore
except ImportError as error:
    convert_to_H0_bore = error


from numpy import isnan
from ._check import InitUnKnowClassError


[docs]class SlotCirc(Slot): """Circular slot (for notches)""" VERSION = 1 IS_SYMMETRICAL = 1 # Check ImportError to remove unnecessary dependencies in unused method # cf Methods.Slot.SlotCirc._comp_line_dict if isinstance(_comp_line_dict, ImportError): _comp_line_dict = property( fget=lambda x: raise_( ImportError( "Can't use SlotCirc method _comp_line_dict: " + str(_comp_line_dict) ) ) ) else: _comp_line_dict = _comp_line_dict # cf Methods.Slot.SlotCirc._comp_point_coordinate if isinstance(_comp_point_coordinate, ImportError): _comp_point_coordinate = property( fget=lambda x: raise_( ImportError( "Can't use SlotCirc method _comp_point_coordinate: " + str(_comp_point_coordinate) ) ) ) else: _comp_point_coordinate = _comp_point_coordinate # cf Methods.Slot.SlotCirc._comp_R0 if isinstance(_comp_R0, ImportError): _comp_R0 = property( fget=lambda x: raise_( ImportError("Can't use SlotCirc method _comp_R0: " + str(_comp_R0)) ) ) else: _comp_R0 = _comp_R0 # cf Methods.Slot.SlotCirc.build_geometry if isinstance(build_geometry, ImportError): build_geometry = property( fget=lambda x: raise_( ImportError( "Can't use SlotCirc method build_geometry: " + str(build_geometry) ) ) ) else: build_geometry = build_geometry # cf Methods.Slot.SlotCirc.check if isinstance(check, ImportError): check = property( fget=lambda x: raise_( ImportError("Can't use SlotCirc method check: " + str(check)) ) ) else: check = check # cf Methods.Slot.SlotCirc.comp_angle_opening if isinstance(comp_angle_opening, ImportError): comp_angle_opening = property( fget=lambda x: raise_( ImportError( "Can't use SlotCirc method comp_angle_opening: " + str(comp_angle_opening) ) ) ) else: comp_angle_opening = comp_angle_opening # cf Methods.Slot.SlotCirc.comp_height if isinstance(comp_height, ImportError): comp_height = property( fget=lambda x: raise_( ImportError( "Can't use SlotCirc method comp_height: " + str(comp_height) ) ) ) else: comp_height = comp_height # cf Methods.Slot.SlotCirc.comp_height_active if isinstance(comp_height_active, ImportError): comp_height_active = property( fget=lambda x: raise_( ImportError( "Can't use SlotCirc method comp_height_active: " + str(comp_height_active) ) ) ) else: comp_height_active = comp_height_active # cf Methods.Slot.SlotCirc.comp_surface if isinstance(comp_surface, ImportError): comp_surface = property( fget=lambda x: raise_( ImportError( "Can't use SlotCirc method comp_surface: " + str(comp_surface) ) ) ) else: comp_surface = comp_surface # cf Methods.Slot.SlotCirc.comp_surface_active if isinstance(comp_surface_active, ImportError): comp_surface_active = property( fget=lambda x: raise_( ImportError( "Can't use SlotCirc method comp_surface_active: " + str(comp_surface_active) ) ) ) else: comp_surface_active = comp_surface_active # cf Methods.Slot.SlotCirc.comp_surface_opening if isinstance(comp_surface_opening, ImportError): comp_surface_opening = property( fget=lambda x: raise_( ImportError( "Can't use SlotCirc method comp_surface_opening: " + str(comp_surface_opening) ) ) ) else: comp_surface_opening = comp_surface_opening # cf Methods.Slot.SlotCirc.get_surface_active if isinstance(get_surface_active, ImportError): get_surface_active = property( fget=lambda x: raise_( ImportError( "Can't use SlotCirc method get_surface_active: " + str(get_surface_active) ) ) ) else: get_surface_active = get_surface_active # cf Methods.Slot.SlotCirc.get_surface_opening if isinstance(get_surface_opening, ImportError): get_surface_opening = property( fget=lambda x: raise_( ImportError( "Can't use SlotCirc method get_surface_opening: " + str(get_surface_opening) ) ) ) else: get_surface_opening = get_surface_opening # cf Methods.Slot.SlotCirc.plot_schematics if isinstance(plot_schematics, ImportError): plot_schematics = property( fget=lambda x: raise_( ImportError( "Can't use SlotCirc method plot_schematics: " + str(plot_schematics) ) ) ) else: plot_schematics = plot_schematics # cf Methods.Slot.SlotCirc.convert_to_H0_bore if isinstance(convert_to_H0_bore, ImportError): convert_to_H0_bore = property( fget=lambda x: raise_( ImportError( "Can't use SlotCirc method convert_to_H0_bore: " + str(convert_to_H0_bore) ) ) ) else: convert_to_H0_bore = convert_to_H0_bore # generic save method is available in all object save = save # get_logger method is available in all object get_logger = get_logger def __init__( self, W0=0.01, H0=0.03, is_H0_bore=True, Zs=36, wedge_mat=None, is_bore=True, init_dict=None, init_str=None, ): """Constructor of the class. Can be use in three ways : - __init__ (arg1 = 1, arg3 = 5) every parameters have name and default values for pyleecan type, -1 will call the default constructor - __init__ (init_dict = d) d must be a dictionary with property names as keys - __init__ (init_str = s) s must be a string s is the file path to load ndarray or list can be given for Vector and Matrix object or dict can be given for pyleecan Object""" if init_str is not None: # Load from a file init_dict = load_init_dict(init_str)[1] if init_dict is not None: # Initialisation by dict assert type(init_dict) is dict # Overwrite default value with init_dict content if "W0" in list(init_dict.keys()): W0 = init_dict["W0"] if "H0" in list(init_dict.keys()): H0 = init_dict["H0"] if "is_H0_bore" in list(init_dict.keys()): is_H0_bore = init_dict["is_H0_bore"] if "Zs" in list(init_dict.keys()): Zs = init_dict["Zs"] if "wedge_mat" in list(init_dict.keys()): wedge_mat = init_dict["wedge_mat"] if "is_bore" in list(init_dict.keys()): is_bore = init_dict["is_bore"] # Set the properties (value check and convertion are done in setter) self.W0 = W0 self.H0 = H0 self.is_H0_bore = is_H0_bore # Call Slot init super(SlotCirc, self).__init__(Zs=Zs, wedge_mat=wedge_mat, is_bore=is_bore) # The class is frozen (in Slot init), for now it's impossible to # add new properties def __str__(self): """Convert this object in a readeable string (for print)""" SlotCirc_str = "" # Get the properties inherited from Slot SlotCirc_str += super(SlotCirc, self).__str__() SlotCirc_str += "W0 = " + str(self.W0) + linesep SlotCirc_str += "H0 = " + str(self.H0) + linesep SlotCirc_str += "is_H0_bore = " + str(self.is_H0_bore) + linesep return SlotCirc_str def __eq__(self, other): """Compare two objects (skip parent)""" if type(other) != type(self): return False # Check the properties inherited from Slot if not super(SlotCirc, self).__eq__(other): return False if other.W0 != self.W0: return False if other.H0 != self.H0: return False if other.is_H0_bore != self.is_H0_bore: return False return True
[docs] def compare(self, other, name="self", ignore_list=None, is_add_value=False): """Compare two objects and return list of differences""" if ignore_list is None: ignore_list = list() if type(other) != type(self): return ["type(" + name + ")"] diff_list = list() # Check the properties inherited from Slot diff_list.extend( super(SlotCirc, self).compare( other, name=name, ignore_list=ignore_list, is_add_value=is_add_value ) ) if ( other._W0 is not None and self._W0 is not None and isnan(other._W0) and isnan(self._W0) ): pass elif other._W0 != self._W0: if is_add_value: val_str = " (self=" + str(self._W0) + ", other=" + str(other._W0) + ")" diff_list.append(name + ".W0" + val_str) else: diff_list.append(name + ".W0") if ( other._H0 is not None and self._H0 is not None and isnan(other._H0) and isnan(self._H0) ): pass elif other._H0 != self._H0: if is_add_value: val_str = " (self=" + str(self._H0) + ", other=" + str(other._H0) + ")" diff_list.append(name + ".H0" + val_str) else: diff_list.append(name + ".H0") if other._is_H0_bore != self._is_H0_bore: if is_add_value: val_str = ( " (self=" + str(self._is_H0_bore) + ", other=" + str(other._is_H0_bore) + ")" ) diff_list.append(name + ".is_H0_bore" + val_str) else: diff_list.append(name + ".is_H0_bore") # Filter ignore differences diff_list = list(filter(lambda x: x not in ignore_list, diff_list)) return diff_list
def __sizeof__(self): """Return the size in memory of the object (including all subobject)""" S = 0 # Full size of the object # Get size of the properties inherited from Slot S += super(SlotCirc, self).__sizeof__() S += getsizeof(self.W0) S += getsizeof(self.H0) S += getsizeof(self.is_H0_bore) return S
[docs] def as_dict(self, type_handle_ndarray=0, keep_function=False, **kwargs): """ Convert this object in a json serializable dict (can be use in __init__). type_handle_ndarray: int How to handle ndarray (0: tolist, 1: copy, 2: nothing) keep_function : bool True to keep the function object, else return str Optional keyword input parameter is for internal use only and may prevent json serializability. """ # Get the properties inherited from Slot SlotCirc_dict = super(SlotCirc, self).as_dict( type_handle_ndarray=type_handle_ndarray, keep_function=keep_function, **kwargs ) SlotCirc_dict["W0"] = self.W0 SlotCirc_dict["H0"] = self.H0 SlotCirc_dict["is_H0_bore"] = self.is_H0_bore # The class name is added to the dict for deserialisation purpose # Overwrite the mother class name SlotCirc_dict["__class__"] = "SlotCirc" return SlotCirc_dict
[docs] def copy(self): """Creates a deepcopy of the object""" # Handle deepcopy of all the properties W0_val = self.W0 H0_val = self.H0 is_H0_bore_val = self.is_H0_bore Zs_val = self.Zs if self.wedge_mat is None: wedge_mat_val = None else: wedge_mat_val = self.wedge_mat.copy() is_bore_val = self.is_bore # Creates new object of the same type with the copied properties obj_copy = type(self)( W0=W0_val, H0=H0_val, is_H0_bore=is_H0_bore_val, Zs=Zs_val, wedge_mat=wedge_mat_val, is_bore=is_bore_val, ) return obj_copy
def _set_None(self): """Set all the properties to None (except pyleecan object)""" self.W0 = None self.H0 = None self.is_H0_bore = None # Set to None the properties inherited from Slot super(SlotCirc, self)._set_None() def _get_W0(self): """getter of W0""" return self._W0 def _set_W0(self, value): """setter of W0""" check_var("W0", value, "float", Vmin=0) self._W0 = value W0 = property( fget=_get_W0, fset=_set_W0, doc=u"""Slot isthmus width. :Type: float :min: 0 """, ) def _get_H0(self): """getter of H0""" return self._H0 def _set_H0(self, value): """setter of H0""" check_var("H0", value, "float", Vmin=0) self._H0 = value H0 = property( fget=_get_H0, fset=_set_H0, doc=u"""Slot height :Type: float :min: 0 """, ) def _get_is_H0_bore(self): """getter of is_H0_bore""" return self._is_H0_bore def _set_is_H0_bore(self, value): """setter of is_H0_bore""" check_var("is_H0_bore", value, "bool") self._is_H0_bore = value is_H0_bore = property( fget=_get_is_H0_bore, fset=_set_is_H0_bore, doc=u"""True to define H0 from top of arc to bore radius, False top arc to middle of W0 segment :Type: bool """, )