From 81b8fd67a68b911c993b1ad7a09bd6bb21b591e4 Mon Sep 17 00:00:00 2001 From: Pierre-Antoine Rouby <pierre-antoine.rouby@inrae.fr> Date: Fri, 28 Apr 2023 14:40:04 +0200 Subject: [PATCH] BC: Add some implementation of model BC. --- .../BoundaryCondition/BoundaryCondition.py | 63 ++++++++++++++++++- src/Model/BoundaryCondition/Types.py | 44 +++++++++++++ 2 files changed, 106 insertions(+), 1 deletion(-) create mode 100644 src/Model/BoundaryCondition/Types.py diff --git a/src/Model/BoundaryCondition/BoundaryCondition.py b/src/Model/BoundaryCondition/BoundaryCondition.py index 806bceeb..17b7336f 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 00000000..78df831e --- /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 -- GitLab