From 9fe03173fbe74447532e4be727a783cf375d093d Mon Sep 17 00:00:00 2001 From: Ruizhi Yu Date: Thu, 9 Jan 2025 14:27:41 +0800 Subject: [PATCH] feat: make add model element elegantly --- Solverz/model/basic.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/Solverz/model/basic.py b/Solverz/model/basic.py index eaffb0e..fa4bc07 100644 --- a/Solverz/model/basic.py +++ b/Solverz/model/basic.py @@ -92,3 +92,13 @@ def create_instance(self): warnings.warn(f'Equation size {eqs.eqn_size} and variable size {eqs.vsize} not equal!') return eqs, y0 + + def add(self, m): + if isinstance(m, Model): + self.__dict__.update(m.__dict__) + elif isinstance(m, (Var, ParamBase, Eqn, Ode)): + self.__dict__[m.name] = m + elif isinstance(m, dict): + self.__dict__.update(m) + else: + raise ValueError(f"Unknown element type {type(m)}")