/*
 * This code is generated by BioUML FrameWork 
 * for BIOMD0000000036.xml diagram  at 2008.03.20 15:04:15
 */
import biouml.plugins.simulation.ae.NewtonSolver;
import biouml.plugins.simulation.java.JavaBaseModel;
import ru.biosoft.math.MathRoutines;

public class BIOMD0000000036 extends JavaBaseModel
{

/*
 * Write rules to calculate equation parameters
 */


/*
 * Write rules to calculate equation parameters excluding internal variables.
 */
    public void __internalRateVarInitFunc_0(double time, double[] x)
    {
        rate_DBT = CYTOPLASM*((DBT_k1*x[1]*(2.0/(1.0 + Math.pow((1.0 + 8.0*DBT_Keq*x[1]), 0.5))) + DBT_k2*x[1])/(DBT_J + x[1]));
        rate_ProteinD = ProteinD_D*x[1]*CYTOPLASM;
        rate_TC = CYTOPLASM*(TC_Vm/(1.0 + Math.pow((x[1]*(1.0 - 2.0/(1.0 + Math.pow((1.0 + 8.0*TC_Keq*x[1]), 0.5)))/(2.0*TC_Pcrit)), 2.0)));
        rate_TL = TL_V*x[0]*CYTOPLASM;
        rate_mRNAD = mRNAD_D*x[0]*CYTOPLASM;
    }

    public void Init()
    {
        initialValues = getInitialValues();
/*
 * Initialize variables
 */
        CYTOPLASM = 1.0; // initial value of $CYTOPLASM
        DBT_J = 0.05; // initial value of DBT_J
        DBT_Keq = 200.0; // initial value of DBT_Keq
        DBT_k1 = 10.0; // initial value of DBT_k1
        DBT_k2 = 0.03; // initial value of DBT_k2
        ProteinD_D = 0.1; // initial value of ProteinD_D
        TC_Keq = 200.0; // initial value of TC_Keq
        TC_Pcrit = 0.1; // initial value of TC_Pcrit
        TC_Vm = 1.0; // initial value of TC_Vm
        TL_V = 0.5; // initial value of TL_V
        mRNAD_D = 0.1; // initial value of mRNAD_D
    }

    /*
     * Model variables initial values
     */
    protected double _default_EmptySet_;
    protected double rate_DBT;
    protected double rate_ProteinD;
    protected double rate_TC;
    protected double rate_TL;
    protected double rate_mRNAD;
    protected double CYTOPLASM;
    protected double DBT_J;
    protected double DBT_Keq;
    protected double DBT_k1;
    protected double DBT_k2;
    protected double ProteinD_D;
    protected double TC_Keq;
    protected double TC_Pcrit;
    protected double TC_Vm;
    protected double TL_V;
    protected double mRNAD_D;

    public double[] extendResult(double time,double [] x)
    {
        this.time = time;


        double[] y = new double[2];
        y[0] = x[0];
        y[1] = x[1];
        return y;
    }
    public double[] getInitialValues()
    {
        double [] x = new double[2];
        this.time = 0.0;
        x[0] = 1.0; // - $"CYTOPLASM.M"
        x[1] = 1.0; // - $"CYTOPLASM.P"

        __internalRateVarInitFunc_0(time, x);

        return x;
    }

/*
 * code for algebraic rules calculations
 */

/*
 * end of code for algebraic rules calculations
 */

    protected void calculateRates(double time, double[] x)
    {

        __internalRateVarInitFunc_0(time, x);

    }

        /*
         * calculate dy/dt for 'BIOMD0000000036.xml' model
         */
    public void __internalDyDt_0(double time, double [] x, double[] result)
    {
        result[0] = +rate_TC-rate_mRNAD;
        result[1] = -rate_DBT-rate_ProteinD+rate_TL;
    }
    protected double [] calculateResult(double time, double[] x)
    {
        double[] result = new double[2];
        __internalDyDt_0(time, x, result);
        return result;
    }
    public double[] dy_dt(double time, double[] x)
    {
        this.time = time;
        calculateRates( time,x );

        return calculateResult( time,x );
    }

} // class ...