# -*- coding: utf-8 -*-
# File generated according to Generator/ClassesRef/Slot/VentilationPolar.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/VentilationPolar
"""
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 .Hole import Hole
# Import all class method
# Try/catch to remove unnecessary dependencies in unused method
try:
from ..Methods.Slot.VentilationPolar.build_geometry import build_geometry
except ImportError as error:
build_geometry = error
try:
from ..Methods.Slot.VentilationPolar.check import check
except ImportError as error:
check = error
try:
from ..Methods.Slot.VentilationPolar.comp_radius import comp_radius
except ImportError as error:
comp_radius = error
try:
from ..Methods.Slot.VentilationPolar.comp_surface import comp_surface
except ImportError as error:
comp_surface = error
try:
from ..Methods.Slot.VentilationPolar.get_center import get_center
except ImportError as error:
get_center = error
try:
from ..Methods.Slot.VentilationPolar._comp_point_coordinate import (
_comp_point_coordinate,
)
except ImportError as error:
_comp_point_coordinate = error
try:
from ..Methods.Slot.VentilationPolar.plot_schematics import plot_schematics
except ImportError as error:
plot_schematics = error
from numpy import isnan
from ._check import InitUnKnowClassError
[docs]class VentilationPolar(Hole):
"""Polar axial ventilation duct"""
VERSION = 1
# Check ImportError to remove unnecessary dependencies in unused method
# cf Methods.Slot.VentilationPolar.build_geometry
if isinstance(build_geometry, ImportError):
build_geometry = property(
fget=lambda x: raise_(
ImportError(
"Can't use VentilationPolar method build_geometry: "
+ str(build_geometry)
)
)
)
else:
build_geometry = build_geometry
# cf Methods.Slot.VentilationPolar.check
if isinstance(check, ImportError):
check = property(
fget=lambda x: raise_(
ImportError("Can't use VentilationPolar method check: " + str(check))
)
)
else:
check = check
# cf Methods.Slot.VentilationPolar.comp_radius
if isinstance(comp_radius, ImportError):
comp_radius = property(
fget=lambda x: raise_(
ImportError(
"Can't use VentilationPolar method comp_radius: " + str(comp_radius)
)
)
)
else:
comp_radius = comp_radius
# cf Methods.Slot.VentilationPolar.comp_surface
if isinstance(comp_surface, ImportError):
comp_surface = property(
fget=lambda x: raise_(
ImportError(
"Can't use VentilationPolar method comp_surface: "
+ str(comp_surface)
)
)
)
else:
comp_surface = comp_surface
# cf Methods.Slot.VentilationPolar.get_center
if isinstance(get_center, ImportError):
get_center = property(
fget=lambda x: raise_(
ImportError(
"Can't use VentilationPolar method get_center: " + str(get_center)
)
)
)
else:
get_center = get_center
# cf Methods.Slot.VentilationPolar._comp_point_coordinate
if isinstance(_comp_point_coordinate, ImportError):
_comp_point_coordinate = property(
fget=lambda x: raise_(
ImportError(
"Can't use VentilationPolar method _comp_point_coordinate: "
+ str(_comp_point_coordinate)
)
)
)
else:
_comp_point_coordinate = _comp_point_coordinate
# cf Methods.Slot.VentilationPolar.plot_schematics
if isinstance(plot_schematics, ImportError):
plot_schematics = property(
fget=lambda x: raise_(
ImportError(
"Can't use VentilationPolar method plot_schematics: "
+ str(plot_schematics)
)
)
)
else:
plot_schematics = plot_schematics
# 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,
D0=1,
H0=1,
W1=1,
Zh=36,
mat_void=-1,
magnetization_dict_offset=None,
Alpha0=0,
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 "D0" in list(init_dict.keys()):
D0 = init_dict["D0"]
if "H0" in list(init_dict.keys()):
H0 = init_dict["H0"]
if "W1" in list(init_dict.keys()):
W1 = init_dict["W1"]
if "Zh" in list(init_dict.keys()):
Zh = init_dict["Zh"]
if "mat_void" in list(init_dict.keys()):
mat_void = init_dict["mat_void"]
if "magnetization_dict_offset" in list(init_dict.keys()):
magnetization_dict_offset = init_dict["magnetization_dict_offset"]
if "Alpha0" in list(init_dict.keys()):
Alpha0 = init_dict["Alpha0"]
# Set the properties (value check and convertion are done in setter)
self.D0 = D0
self.H0 = H0
self.W1 = W1
# Call Hole init
super(VentilationPolar, self).__init__(
Zh=Zh,
mat_void=mat_void,
magnetization_dict_offset=magnetization_dict_offset,
Alpha0=Alpha0,
)
# The class is frozen (in Hole init), for now it's impossible to
# add new properties
def __str__(self):
"""Convert this object in a readeable string (for print)"""
VentilationPolar_str = ""
# Get the properties inherited from Hole
VentilationPolar_str += super(VentilationPolar, self).__str__()
VentilationPolar_str += "D0 = " + str(self.D0) + linesep
VentilationPolar_str += "H0 = " + str(self.H0) + linesep
VentilationPolar_str += "W1 = " + str(self.W1) + linesep
return VentilationPolar_str
def __eq__(self, other):
"""Compare two objects (skip parent)"""
if type(other) != type(self):
return False
# Check the properties inherited from Hole
if not super(VentilationPolar, self).__eq__(other):
return False
if other.D0 != self.D0:
return False
if other.H0 != self.H0:
return False
if other.W1 != self.W1:
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 Hole
diff_list.extend(
super(VentilationPolar, self).compare(
other, name=name, ignore_list=ignore_list, is_add_value=is_add_value
)
)
if (
other._D0 is not None
and self._D0 is not None
and isnan(other._D0)
and isnan(self._D0)
):
pass
elif other._D0 != self._D0:
if is_add_value:
val_str = " (self=" + str(self._D0) + ", other=" + str(other._D0) + ")"
diff_list.append(name + ".D0" + val_str)
else:
diff_list.append(name + ".D0")
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._W1 is not None
and self._W1 is not None
and isnan(other._W1)
and isnan(self._W1)
):
pass
elif other._W1 != self._W1:
if is_add_value:
val_str = " (self=" + str(self._W1) + ", other=" + str(other._W1) + ")"
diff_list.append(name + ".W1" + val_str)
else:
diff_list.append(name + ".W1")
# 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 Hole
S += super(VentilationPolar, self).__sizeof__()
S += getsizeof(self.D0)
S += getsizeof(self.H0)
S += getsizeof(self.W1)
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 Hole
VentilationPolar_dict = super(VentilationPolar, self).as_dict(
type_handle_ndarray=type_handle_ndarray,
keep_function=keep_function,
**kwargs
)
VentilationPolar_dict["D0"] = self.D0
VentilationPolar_dict["H0"] = self.H0
VentilationPolar_dict["W1"] = self.W1
# The class name is added to the dict for deserialisation purpose
# Overwrite the mother class name
VentilationPolar_dict["__class__"] = "VentilationPolar"
return VentilationPolar_dict
[docs] def copy(self):
"""Creates a deepcopy of the object"""
# Handle deepcopy of all the properties
D0_val = self.D0
H0_val = self.H0
W1_val = self.W1
Zh_val = self.Zh
if self.mat_void is None:
mat_void_val = None
else:
mat_void_val = self.mat_void.copy()
if self.magnetization_dict_offset is None:
magnetization_dict_offset_val = None
else:
magnetization_dict_offset_val = self.magnetization_dict_offset.copy()
Alpha0_val = self.Alpha0
# Creates new object of the same type with the copied properties
obj_copy = type(self)(
D0=D0_val,
H0=H0_val,
W1=W1_val,
Zh=Zh_val,
mat_void=mat_void_val,
magnetization_dict_offset=magnetization_dict_offset_val,
Alpha0=Alpha0_val,
)
return obj_copy
def _set_None(self):
"""Set all the properties to None (except pyleecan object)"""
self.D0 = None
self.H0 = None
self.W1 = None
# Set to None the properties inherited from Hole
super(VentilationPolar, self)._set_None()
def _get_D0(self):
"""getter of D0"""
return self._D0
def _set_D0(self, value):
"""setter of D0"""
check_var("D0", value, "float", Vmin=0)
self._D0 = value
D0 = property(
fget=_get_D0,
fset=_set_D0,
doc=u"""Height of the hole
: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"""Radius of the bottom of Hole
:Type: float
:min: 0
""",
)
def _get_W1(self):
"""getter of W1"""
return self._W1
def _set_W1(self, value):
"""setter of W1"""
check_var("W1", value, "float", Vmin=0, Vmax=6.29)
self._W1 = value
W1 = property(
fget=_get_W1,
fset=_set_W1,
doc=u"""Hole angular width
:Type: float
:min: 0
:max: 6.29
""",
)