/*
 * This code is generated by BioUML FrameWork 
 * for BIOMD0000000114.xml diagram  at 2008.03.20 15:08:51
 */
import biouml.plugins.simulation.ae.NewtonSolver;
import biouml.plugins.simulation.java.JavaBaseModel;
import ru.biosoft.math.MathRoutines;

public class BIOMD0000000114 extends JavaBaseModel
{

/*
 * Write rules to calculate equation parameters
 */
    private void __internalVarInitFunc_0(double time, double[] x)
    {
        fy = Math.pow(x[1], n)/(Math.pow(a, n) + Math.pow(x[1], n));
    }


/*
 * Write rules to calculate equation parameters excluding internal variables.
 */
    public void __internalRateVarInitFunc_0(double time, double[] x)
    {
        rate_reaction_0000001 = gamma*cytoplasm;
        rate_reaction_0000002 = k*x[0]*cytoplasm - k1*x[1]*ER;
        rate_reaction_0000003 = beta*x[1]*extracellular;
        rate_reaction_0000004 = alpha*fy*x[0]*cytoplasm;
    }

    public void Init()
    {
        initialValues = getInitialValues();
/*
 * Initialize variables
 */
        ER = 1.0; // initial value of $ER
        cytoplasm = 1.0; // initial value of $cytoplasm
        extracellular = 1.0; // initial value of $extracellular
        a = 3.0; // initial value of a
        alpha = 5.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 ER;
    protected double cytoplasm;
    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; // - $"ER.x"
        x[1] = 1.0; // - $"cytoplasm.y"

        __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 'BIOMD0000000114.xml' model
         */
    public void __internalDyDt_0(double time, double [] x, double[] result)
    {
        result[0] = -rate_reaction_0000002-rate_reaction_0000004;
        result[1] = +rate_reaction_0000001+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 ...