Skip to content

Commit

Permalink
refactor: remove stale modelling component
Browse files Browse the repository at this point in the history
  • Loading branch information
rzyu45 committed Dec 13, 2024
1 parent a169489 commit b6dc841
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 25 deletions.
3 changes: 1 addition & 2 deletions Solverz/__init__.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
from Solverz.equation.eqn import Eqn, Ode
from Solverz.equation.equations import AE, FDAE, DAE
from Solverz.equation.param import Param, IdxParam, TimeSeriesParam
from Solverz.sym_algebra.symbols import idx, Para, iVar, iAliasVar
from Solverz.sym_algebra.functions import (Sign, Abs, transpose, exp, Diag, Mat_Mul, sin, cos, Min, AntiWindUp,
Saturation, heaviside, ln, MulVarFunc, UniVarFunc)
from Solverz.variable.variables import Vars, TimeVars, as_Vars
from Solverz.variable.variables import Vars, TimeVars
from Solverz.solvers import *
from Solverz.code_printer import made_numerical, module_printer
from Solverz.utilities.io import save, load, save_result
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@
import numpy as np
from sympy import symbols, pycode, Integer

from Solverz import as_Vars, Eqn, Ode, AE, sin, made_numerical, Model, Var, Param, TimeSeriesParam, AliasVar, Abs, exp, \
from Solverz import Eqn, Ode, AE, sin, made_numerical, Model, Var, Param, TimeSeriesParam, AliasVar, Abs, exp, \
cos
from Solverz.code_printer.make_module import module_printer
from Solverz.code_printer.python.inline.inline_printer import print_J_block
from Solverz.code_printer.python.utilities import _print_var_parser
from Solverz.sym_algebra.symbols import idx, iVar, Para
from Solverz.variable.variables import as_Vars

expected_dependency = r"""import os
current_module_dir = os.path.dirname(os.path.abspath(__file__))
Expand Down
5 changes: 3 additions & 2 deletions Solverz/equation/test/test_DAE.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from sympy import Integer
from Solverz import Ode, iVar, DAE, as_Vars, made_numerical

from Solverz import Ode, DAE, made_numerical
from Solverz.sym_algebra.symbols import iVar
from Solverz.variable.variables import as_Vars

def test_zero_index():
# to test if index zero, being the sympy.Integer.instance, raises error when creating the singular mass mat
Expand Down
19 changes: 11 additions & 8 deletions tests/test_0.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
from Solverz import Eqn, AE, nr_method, as_Vars, iVar, made_numerical, Opt
from Solverz import Eqn, AE, nr_method, Model, Var, made_numerical, Opt

x = iVar(name='x', value=2)
m = Model()

e = Eqn(name='e', eqn=x ** 2 - 1)
f = AE(name='F',
eqn=e)
y = as_Vars(x)
nf = made_numerical(f, y)
sol = nr_method(nf, y, Opt(ite_tol=1e-8))
m.x = Var(name='x', value=2)

m.e = Eqn(name='e', eqn=m.x ** 2 - 1)
m.F = AE(name='F', eqn=m.e)

g, y0 = m.create_instance()

nae = made_numerical(g, y0)
sol = nr_method(nae, y0, Opt(ite_tol=1e-8))


def test_nr_method():
Expand Down
25 changes: 13 additions & 12 deletions tests/test_dae.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
import pandas as pd
import numpy as np

from Solverz import Eqn, Ode, DAE, iVar, as_Vars, Rodas, implicit_trapezoid, Opt, made_numerical
from Solverz import Eqn, Ode, DAE, Rodas, implicit_trapezoid, Opt, made_numerical, Model, Var

x = iVar('x', 1)
y = iVar('y', 1)
m = Model()

f = Ode(name='f', f=-x ** 3 + 0.5 * y ** 2, diff_var=x)
g = Eqn(name='g', eqn=x ** 2 + y ** 2 - 2)
dae = DAE([f, g])
m.x = Var('x', 1)
m.y = Var('y', 1)

z = as_Vars([x, y])
ndae = made_numerical(dae, z)
m.f = Ode(name='f', f=-m.x ** 3 + 0.5 * m.y ** 2, diff_var=m.x)
m.g = Eqn(name='g', eqn=m.x ** 2 + m.y ** 2 - 2)
dae, y0 = m.create_instance()

ndae = made_numerical(dae, y0)

df = pd.read_excel('tests/dae_test.xlsx',
sheet_name=None,
Expand All @@ -20,18 +21,18 @@

sol_rodas = Rodas(ndae,
[0, 20],
z,
y0,
opt=Opt(hinit=0.1))

sol_rodas_dense = Rodas(ndae,
np.linspace(0, 20, 201),
z,
y0,
Opt(hinit=0.1))
sol_trape = implicit_trapezoid(ndae, [0, 20], z, Opt(step_size=0.1))
sol_trape = implicit_trapezoid(ndae, [0, 20], y0, Opt(step_size=0.1))

sol_bench = Rodas(ndae,
np.linspace(0, 20, 201),
z,
y0,
Opt(rtol=1e-6,
atol=1e-8))

Expand Down

0 comments on commit b6dc841

Please sign in to comment.