diff --git a/src/Model/BoundaryCondition/BoundaryCondition.py b/src/Model/BoundaryCondition/BoundaryCondition.py index 806bceeb178af775761cda7ec7edeb0513daae1a..17b7336ffbe086b0d7c030b95078d197856e95ab 100644 --- a/src/Model/BoundaryCondition/BoundaryCondition.py +++ b/src/Model/BoundaryCondition/BoundaryCondition.py @@ -9,7 +9,9 @@ class BoundaryCondition(object): self._name = name self._type = "" self._node = None - self._data = None + self._data = [] + self.header = [] + self.types = [int, float] @property def name(self): @@ -34,5 +36,64 @@ class BoundaryCondition(object): def has_node(self): return self._node is not None + @property + def header(self): + return self._header.copy() + + @property + def data(self): + return self._data.copy() + def is_define(self): return self._data is not None + + def add(self, index:int): + value = (self.default_0, self_default_1) + self._data.insert(index, value) + + def insert(self, index:int, value): + self._data.insert(index, value) + + def delete(self, indexes): + self._data = list( + map( + lambda e: e[1], + filter( + lambda e: e[0] not in indexes, + enumerate(self.data) + ) + ) + ) + + def sort(self, _reverse): + self._data.sort(reverse=_reverse) + + def _set_i_c_v(self, index, column, value): + v = list(self._data[index]) + v[column] = self.types[column](value) + self._data[index] = tuple(v) + + def set_i_0(self, index:int, value): + self._set_i_c_v(index, 0, value): + + def set_i_1(self, index:int, value): + self._set_i_c_v(index, 1, value): + + def convert(self, cls): + new = cls(name = self.name) + for i, _ in self.data: + new.add(i) + + for i in [0,1]: + for j in [0,1]: + if self.header[i] == new.header[j]: + for ind, v in self.data: + new._set_i_c_v(ind, j, v[i]) + + return new + + def _default_0(self): + return self.types[0](0) + + def _default_1(self): + return self.types[1](0.0) diff --git a/src/Model/BoundaryCondition/Types.py b/src/Model/BoundaryCondition/Types.py new file mode 100644 index 0000000000000000000000000000000000000000..78df831eeec4772e146a706e4d002c7e575ecf3b --- /dev/null +++ b/src/Model/BoundaryCondition/Types.py @@ -0,0 +1,44 @@ +# -*- coding: utf-8 -*- + +from Model.Except import NotImplementedMethodeError + +from Model.BoundaryCondition.BoundaryCondition import BoundaryCondition + +BC_types = [ + "PC", + "TZ", + "TD", + "ZD" +] + +class PonctualContribution(BoundaryCondition): + def __init__(self, name:str = ""): + super(PonctualContribution, self).__init__(name=name) + + self._type = "PC" + self._header = ["time", "debit"] + +class TimeOverZ(BoundaryCondition): + def __init__(self, name:str = ""): + super(PonctualContribution, self).__init__(name=name) + + self._type = "TZ" + self._header = ["time", "z"] + +class TimeOverDebit(BoundaryCondition): + def __init__(self, name:str = ""): + super(PonctualContribution, self).__init__(name=name) + + self._type = "TD" + self._header = ["time", "debit"] + +class ZOverDebit(BoundaryCondition): + def __init__(self, name:str = ""): + super(PonctualContribution, self).__init__(name=name) + + self._type = "ZD" + self._header = ["z", "debit"] + self._types = [float, float] + + def _default_0(self): + return 0.0