# Inference using two nonlinear models measuring only temperature

import numpy
import scipy.stats
import openloop.params as params
import src.Results as Results
import src.RBPF as RBPF
import src.SPF as SPF
import matplotlib.pyplot as plt

tend = 300
params = params.Params(tend)
# srand(8745)

init_state = numpy.array([0.55, 450])

A = numpy.array([[0.99, 0.01], [0.01, 0.99]])


def fun1(x, u, w):
    return params.cstr_model.run_reactor(x, u, params.h) + w


def fun2(x, u, w):
    return params.cstr_model_broken.run_reactor(x, u, params.h) + w


def gs(x):
    return params.C2 @ x

# Qualitative Analysis of the CSTR
# Nominal and bifurcation analysis

import matplotlib as mpl
import matplotlib.pyplot as plt
import numpy
import scipy.optimize
import openloop.params as parameters

tend = 150
params = parameters.Params(tend)
N = 100
Ts = numpy.linspace(200, 600, N)  # temperature range
qrs1 = numpy.zeros(N)  # heat removals
qrs2 = numpy.zeros(N)  # heat removals
qrs3 = numpy.zeros(N)  # heat removals
qgs1 = numpy.zeros(N)  # heat generations

for k in range(N):
    qrs1[k] = params.cstr_model.qr(Ts[k], -906.)
    qrs2[k] = params.cstr_model.qr(Ts[k], 0.0)
    qrs3[k] = params.cstr_model.qr(Ts[k], 1145.0)
    qgs1[k] = params.cstr_model.qg(Ts[k])

mpl.rc("font", family="serif", serif="Computer Modern", size=12)
mpl.rc("text", usetex=True)

plt.figure(1)
q1, = plt.plot(Ts, qrs1, "b", linewidth=1)
q2, = plt.plot(Ts, qrs2, "g", linewidth=1)
q3, = plt.plot(Ts, qrs3, "r", linewidth=1)