/*
 * This code is generated by BioUML FrameWork 
 * for BIOMD0000000108.xml diagram  at 2008.03.20 15:08:44
 */
import biouml.plugins.simulation.ae.NewtonSolver;
import biouml.plugins.simulation.java.JavaBaseModel;
import ru.biosoft.math.MathRoutines;

public class BIOMD0000000108 extends JavaBaseModel
{

/*
 * Write rules to calculate equation parameters
 */
    private void __internalVarInitFunc_0(double time, double[] x)
    {
        HO2star = x[0]/100;
        Cu_I_ZnSOD = _compartment_0000001_species_0000016_ - x[1];
    }


/*
 * Write rules to calculate equation parameters excluding internal variables.
 */
    public void __internalRateVarInitFunc_0(double time, double[] x)
    {
        rate_fast = k10*HO2star*compartment_0000001;
        rate_reaction_0 = compartment_0000001*k2*x[0]*x[1];
        rate_reaction_0000001 = compartment_0000001*k1;
        rate_reaction_1 = compartment_0000001*k3*x[0]*Cu_I_ZnSOD;
        rate_reaction_10 = compartment_0000001*k13a*Cu_I_ZnSOD;
        rate_reaction_11 = compartment_0000001*k13b*x[1];
        rate_reaction_12 = compartment_0000001*k17*x[6];
        rate_reaction_13 = compartment_0000001*k18*x[3];
        rate_reaction_14 = compartment_0000001*k19*Math.pow(x[3], 2.0);
        rate_reaction_2 = compartment_0000001*k4*x[0]*x[3];
        rate_reaction_3 = compartment_0000001*k5*x[0]*x[2];
        rate_reaction_4 = compartment_0000001*k6*x[2]*x[1];
        rate_reaction_5 = compartment_0000001*k7*x[2]*_compartment_0000001_species_0000017_;
        rate_reaction_6 = compartment_0000001*k9*x[4];
        rate_reaction_7 = compartment_0000001*k10*HO2star;
        rate_reaction_8 = compartment_0000001*k11*x[4];
        rate_reaction_9 = compartment_0000001*k12*x[5];
    }

    public void Init()
    {
        initialValues = getInitialValues();
/*
 * Initialize variables
 */
        _compartment_0000001_species_0000016_ = 1.0E-5; // initial value of $"compartment_0000001.species_0000016"
        _compartment_0000001_species_0000017_ = 1.0E-5; // initial value of $"compartment_0000001.species_0000017"
        compartment_0000001 = 1.0; // initial value of $compartment_0000001
        k1 = 6.6E-7; // initial value of k1
        k10 = 1000.0; // initial value of k10
        k11 = 2.5E8; // initial value of k11
        k12 = 0.38; // initial value of k12
        k13a = 0.0087; // initial value of k13a
        k13b = 0.0087; // initial value of k13b
        k17 = 30000.0; // initial value of k17
        k18 = 7.0; // initial value of k18
        k19 = 88000.0; // initial value of k19
        k2 = 1.6E9; // initial value of k2
        k3 = 1.6E9; // initial value of k3
        k4 = 100000.0; // initial value of k4
        k5 = 20000.0; // initial value of k5
        k6 = 1.0; // initial value of k6
        k7 = 3.4E7; // initial value of k7
        k9 = 1000000.0; // initial value of k9
    }

    /*
     * Model variables initial values
     */
    protected double _compartment_0000001_species_0000016_;
    protected double _compartment_0000001_species_0000017_;
    protected double rate_fast;
    protected double rate_reaction_0;
    protected double rate_reaction_0000001;
    protected double rate_reaction_1;
    protected double rate_reaction_10;
    protected double rate_reaction_11;
    protected double rate_reaction_12;
    protected double rate_reaction_13;
    protected double rate_reaction_14;
    protected double rate_reaction_2;
    protected double rate_reaction_3;
    protected double rate_reaction_4;
    protected double rate_reaction_5;
    protected double rate_reaction_6;
    protected double rate_reaction_7;
    protected double rate_reaction_8;
    protected double rate_reaction_9;
    protected double compartment_0000001;
    protected double Cu_I_ZnSOD;
    protected double HO2star;
    protected double k1;
    protected double k10;
    protected double k11;
    protected double k12;
    protected double k13a;
    protected double k13b;
    protected double k17;
    protected double k18;
    protected double k19;
    protected double k2;
    protected double k3;
    protected double k4;
    protected double k5;
    protected double k6;
    protected double k7;
    protected double k9;

    public double[] extendResult(double time,double [] x)
    {
        this.time = time;

        __internalVarInitFunc_0(time, x);

        double[] y = new double[9];
        y[0] = x[0];
        y[1] = x[1];
        y[2] = x[2];
        y[3] = x[3];
        y[4] = x[4];
        y[5] = x[5];
        y[6] = x[6];
        y[7] = Cu_I_ZnSOD;
        y[8] = HO2star;
        return y;
    }
    public double[] getInitialValues()
    {
        double [] x = new double[7];
        this.time = 0.0;
        x[0] = 0.0; // - $"compartment_0000001.species_0000001"
        x[1] = 5.0E-6; // - $"compartment_0000001.species_0000002"
        x[2] = 0.0; // - $"compartment_0000001.species_0000006"
        x[3] = 0.0; // - $"compartment_0000001.species_0000007"
        x[4] = 0.0; // - $"compartment_0000001.species_0000008"
        x[5] = 0.0; // - $"compartment_0000001.species_0000009"
        x[6] = 0.0; // - $"compartment_0000001.species_0000011"

        __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 'BIOMD0000000108.xml' model
         */
    public void __internalDyDt_0(double time, double [] x, double[] result)
    {
        result[0] = -rate_fast+rate_reaction_0000001-rate_reaction_0-rate_reaction_1-rate_reaction_2-rate_reaction_3;
        result[1] = -rate_reaction_0+rate_reaction_10-rate_reaction_11+rate_reaction_1;
        result[2] = +rate_reaction_1-rate_reaction_3-rate_reaction_4-rate_reaction_5+rate_reaction_7;
        result[3] = +rate_reaction_12-rate_reaction_13-rate_reaction_14*2-rate_reaction_2;
        result[4] = +rate_reaction_3*2+rate_reaction_4*2-rate_reaction_6-rate_reaction_8;
        result[5] = +rate_reaction_13+rate_reaction_2-rate_reaction_9;
        result[6] = -rate_reaction_12+rate_reaction_13+rate_reaction_7+rate_reaction_8;
    }
    protected double [] calculateResult(double time, double[] x)
    {
        double[] result = new double[7];
        __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 ...