Skip to content

Commit

Permalink
feat: make add model element elegantly
Browse files Browse the repository at this point in the history
  • Loading branch information
rzyu45 committed Jan 9, 2025
1 parent 29d928e commit 9fe0317
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions Solverz/model/basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)}")

0 comments on commit 9fe0317

Please sign in to comment.