Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PETSc interface fails with Lagrange-Legendre collocation #1343

Open
dallan-keylogic opened this issue Feb 19, 2024 · 0 comments
Open

PETSc interface fails with Lagrange-Legendre collocation #1343

dallan-keylogic opened this issue Feb 19, 2024 · 0 comments
Assignees
Labels
bug Something isn't working core Issues dealing with core modeling components PETSc Priority:Low Low Priority Issue or PR

Comments

@dallan-keylogic
Copy link
Contributor

dallan-keylogic commented Feb 19, 2024

Presently, the PETSc interface throws an error when one attempts to integrate a DAE discretized with Lagrange-Legendre discretization:

    import pyomo.environ as pyo
    import pyomo.dae as pyodae
    from idaes.core.solvers import petsc

    m = pyo.ConcreteModel()

    m.time = pyodae.ContinuousSet(initialize=(0.0, 1.0, 2.0))
    m.x = pyo.Var(m.time)
    m.u = pyo.Var(m.time)
    m.dxdt = pyodae.DerivativeVar(m.x, wrt=m.time)

    def diff_eq_rule(m, t):
        return m.dxdt[t] == m.x[t] ** 2 - m.u[t]

    m.diff_eq = pyo.Constraint(m.time, rule=diff_eq_rule)

    discretizer = pyo.TransformationFactory("dae.collocation")
    discretizer.apply_to(m, nfe=2, scheme="LAGRANGE-LEGENDRE")

    m.u.fix(1.0)
    m.x[0].fix(0.0)

    res = petsc.petsc_dae_by_time_element(
        m,
        time=m.time,
        between=[0.0, 2.0],
        ts_options={
            "--ts_type": "beuler",
            "--ts_dt": 3e-2,
        },
        skip_initial=True,  # With u and x fixed, no variables to solve for at t0
        calculate_derivatives=True,
    )

produces a log with a degrees-of-freedom error:

2024-02-19 14:06:27 [INFO] idaes.solve.petsc-dae: Called fg_read, err: 0 (0 is good)
2024-02-19 14:06:27 [INFO] idaes.solve.petsc-dae: ---------------------------------------------------
2024-02-19 14:06:27 [INFO] idaes.solve.petsc-dae: DAE: 1
2024-02-19 14:06:27 [INFO] idaes.solve.petsc-dae: Reading nl file: C:\Users\dallan\AppData\Local\Temp\tmpwptc4we3.pyomo.nl
2024-02-19 14:06:27 [INFO] idaes.solve.petsc-dae: Number of constraints: 2
2024-02-19 14:06:27 [INFO] idaes.solve.petsc-dae: Number of nonlinear constraints: 1
2024-02-19 14:06:27 [INFO] idaes.solve.petsc-dae: Number of linear constraints: 1
2024-02-19 14:06:27 [INFO] idaes.solve.petsc-dae: Number of inequalities: 0
2024-02-19 14:06:27 [INFO] idaes.solve.petsc-dae: Number of variables: 6
2024-02-19 14:06:27 [INFO] idaes.solve.petsc-dae: Number of integers: 0
2024-02-19 14:06:27 [INFO] idaes.solve.petsc-dae: Number of binary: 0
2024-02-19 14:06:27 [INFO] idaes.solve.petsc-dae: Number of objectives: 0 (Ignoring)
2024-02-19 14:06:27 [INFO] idaes.solve.petsc-dae: Number of non-zeros in Jacobian: 7
2024-02-19 14:06:27 [INFO] idaes.solve.petsc-dae: Explicit time variable: 0
2024-02-19 14:06:27 [INFO] idaes.solve.petsc-dae: Number of derivatives: 1
2024-02-19 14:06:27 [INFO] idaes.solve.petsc-dae: Number of differential vars: 1
2024-02-19 14:06:27 [INFO] idaes.solve.petsc-dae: Number of algebraic vars: 4
2024-02-19 14:06:27 [INFO] idaes.solve.petsc-dae: Number of state vars: 5
2024-02-19 14:06:27 [INFO] idaes.solve.petsc-dae: Number of degrees of freedom: 3
2024-02-19 14:06:27 [INFO] idaes.solve.petsc-dae: ---------------------------------------------------
2024-02-19 14:06:27 [INFO] idaes.solve.petsc-dae: ERROR: Degrees of freedom not equal to 0

I suspect the code @eslickj wrote to collect differential equations and discretization equations is failing because this discretization method has continuity equations in addition to normal discretization equations. How exactly we want to handle this case is up for discussion.

@dallan-keylogic dallan-keylogic added bug Something isn't working Priority:Low Low Priority Issue or PR core Issues dealing with core modeling components PETSc labels Feb 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working core Issues dealing with core modeling components PETSc Priority:Low Low Priority Issue or PR
Projects
None yet
Development

No branches or pull requests

1 participant