/*
 * This code is generated by BioUML FrameWork 
 * for BIOMD0000000125.xml diagram  at 2008.03.20 15:09:02
 */
import biouml.plugins.simulation.ae.NewtonSolver;
import biouml.plugins.simulation.java.JavaBaseModel;
import ru.biosoft.math.MathRoutines;

public class BIOMD0000000125 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_reaction_0000001 = compartment_0000001*a1*compartment_0000001_x0;
        rate_reaction_0000002 = compartment_0000001*b1*compartment_0000001_y0;
        rate_reaction_0000003 = compartment_0000001*x[0]*a2;
        rate_reaction_0000004 = compartment_0000001*x[0]*b2;
        rate_reaction_0000005 = compartment_0000001*d1*x[0];
        rate_reaction_0000006 = compartment_0000001*d2x*x[1];
        rate_reaction_0000007 = compartment_0000001*d2y*x[2];
    }

    public void Init()
    {
        initialValues = getInitialValues();
/*
 * Initialize variables
 */
        compartment_0000001 = 1.0; // initial value of $compartment_0000001
        compartment_0000001_x0 = 1.0; // initial value of $compartment_0000001.x0
        a1 = 2.0; // initial value of a1
        a2 = 2.0; // initial value of a2
        b1 = 1.0; // initial value of b1
        b2 = 1.0; // initial value of b2
        d1 = 1.0; // initial value of d1
        d2x = 1.0; // initial value of d2x
        d2y = 1.0; // initial value of d2y
    }

    /*
     * 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 rate_reaction_0000006;
    protected double rate_reaction_0000007;
    protected double compartment_0000001;
    protected double compartment_0000001_x0;
    protected double compartment_0000001_y0;
    protected double a1;
    protected double a2;
    protected double b1;
    protected double b2;
    protected double d1;
    protected double d2x;
    protected double d2y;
    protected double time;

    public double[] extendResult(double time,double [] x)
    {
        this.time = time;


        double[] y = new double[4];
        y[0] = compartment_0000001_x0;
        y[1] = x[0];
        y[2] = x[1];
        y[3] = x[2];
        return y;
    }
    public double[] getInitialValues()
    {
        double [] x = new double[3];
        this.time = 0.0;
        x[0] = 0.0; // - $compartment_0000001.x1
        x[1] = 0.0; // - $compartment_0000001.x2
        x[2] = 0.0; // - $compartment_0000001.y2

        __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 'BIOMD0000000125.xml' model
         */
    public void __internalDyDt_0(double time, double [] x, double[] result)
    {
        result[0] = +rate_reaction_0000001+rate_reaction_0000002-rate_reaction_0000005;
        result[1] = +rate_reaction_0000003-rate_reaction_0000006;
        result[2] = +rate_reaction_0000004-rate_reaction_0000007;
    }
    protected double [] calculateResult(double time, double[] x)
    {
        double[] result = new double[3];
        __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 );
    }

    public double[] checkEvent(double time, double[] x)
    {
        this.time = time;

        __internalRateVarInitFunc_0(time, x);

        double [] flags = new double[1];
        flags[0] = (time > 1) ? +1 : -1; //event_0000001
        return flags;
    }

    public void processEvent(int __internalVar12060041425150, double time, double[] x)
    {
        this.time = time;
        if ( __internalVar12060041425150 == 0) //event_0000001
        {
            compartment_0000001_x0 = 0;
        }
    }

} // class ...