/*
 * This code is generated by BioUML FrameWork 
 * for BIOMD0000000115.xml diagram  at 2008.03.20 15:08:52
 */
import biouml.plugins.simulation.ae.NewtonSolver;
import biouml.plugins.simulation.java.JavaBaseModel;
import ru.biosoft.math.MathRoutines;

public class BIOMD0000000115 extends JavaBaseModel
{

/*
 * Write rules to calculate equation parameters
 */
    private void __internalVarInitFunc_0(double time, double[] x)
    {
        fy = Math.pow(x[0], n)/(Math.pow(a, n) + Math.pow(x[0], n));
    }


/*
 * Write rules to calculate equation parameters excluding internal variables.
 */
    public void __internalRateVarInitFunc_0(double time, double[] x)
    {
        rate_reaction_0000001 = gamma*Cytosol;
        rate_reaction_0000002 = Cytosol*k*(x[1] - x[0]);
        rate_reaction_0000003 = k1*x[0]*ER;
        rate_reaction_0000004 = alpha*fy*(x[1] - x[0])*Cytosol;
        rate_reaction_0000005 = beta*x[0]*Extracellular;
    }

    public void Init()
    {
        initialValues = getInitialValues();
/*
 * Initialize variables
 */
        Cytosol = 1.0; // initial value of $Cytosol
        ER = 1.0; // initial value of $ER
        Extracellular = 1.0; // initial value of $Extracellular
        a = 1.4; // initial value of a
        alpha = 10.0; // initial value of alpha
        beta = 1.0; // initial value of beta
        gamma = 1.0; // initial value of gamma
        k = 0.01; // initial value of k
        k1 = 2.0; // initial value of k1
        n = 4.0; // initial value of n
    }

    /*
     * Model variables initial values
     */
    protected double rate_reaction_0000001;
    protected double rate_reaction_0000002;
    protected double rate_reaction_0000003;
    protected double rate_reaction_0000004;
    protected double rate_reaction_0000005;
    protected double Cytosol;
    protected double ER;
    protected double Extracellular;
    protected double a;
    protected double alpha;
    protected double beta;
    protected double fy;
    protected double gamma;
    protected double k;
    protected double k1;
    protected double n;

    public double[] extendResult(double time,double [] x)
    {
        this.time = time;

        __internalVarInitFunc_0(time, x);

        double[] y = new double[3];
        y[0] = x[0];
        y[1] = x[1];
        y[2] = fy;
        return y;
    }
    public double[] getInitialValues()
    {
        double [] x = new double[2];
        this.time = 0.0;
        x[0] = 1.0; // - $"Cytosol.y"
        x[1] = 1.0; // - $"ER.x"

        __internalVarInitFunc_0(time, x);
        __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)
    {

        __internalVarInitFunc_0(time, x);
        __internalRateVarInitFunc_0(time, x);

    }

        /*
         * calculate dy/dt for 'BIOMD0000000115.xml' model
         */
    public void __internalDyDt_0(double time, double [] x, double[] result)
    {
        result[0] = +rate_reaction_0000001+rate_reaction_0000002-rate_reaction_0000003+rate_reaction_0000004-rate_reaction_0000005;
        result[1] = -rate_reaction_0000002+rate_reaction_0000003-rate_reaction_0000004;
    }
    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 ...