/*
 * This code is generated by BioUML FrameWork 
 * for BIOMD0000000055.xml diagram  at 2008.03.20 15:04:40
 */
import biouml.plugins.simulation.ae.NewtonSolver;
import biouml.plugins.simulation.java.JavaBaseModel;
import ru.biosoft.math.MathRoutines;

public class BIOMD0000000055 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_four12 = compartment*(m2*x[0]/(k2 + x[0]));
        rate_four15 = compartment*((1.0 - LD(time, dayLength))*m5 + m6)*(x[4]/(k5 + x[4]));
        rate_four18 = compartment*(m10*x[7]/(k8 + x[7]));
        rate_four21 = compartment*(m13*x[10]/(k11 + x[10]));
        rate_one11 = compartment*LD(time, dayLength)*q1*x[3];
        rate_one12 = compartment*p1*x[1];
        rate_one13 = compartment*r1*x[0];
        rate_one14 = compartment*(n2*Math.pow(x[12], b)/(Math.pow(g2, b) + Math.pow(x[12], b)))*(Math.pow(g3, c)/(Math.pow(g3, c) + Math.pow(x[2], c)));
        rate_one15 = compartment*p2*x[5];
        rate_one16 = compartment*r3*x[4];
        rate_one17 = compartment*(n3*Math.pow(x[6], d)/(Math.pow(g4, d) + Math.pow(x[6], d)));
        rate_one18 = compartment*p3*x[8];
        rate_one19 = compartment*r5*x[7];
        rate_one20 = compartment*(LD(time, dayLength)*q2*x[3] + (LD(time, dayLength)*n4 + n5)*Math.pow(g5, e)/(Math.pow(g5, e) + Math.pow(x[6], e)))*(Math.pow(g6, f)/(Math.pow(g6, f) + Math.pow(x[2], f)));
        rate_one21 = compartment*p4*x[11];
        rate_one22 = compartment*r7*x[10];
        rate_one23 = compartment*(1.0 - LD(time, dayLength))*p5;
        rate_three11 = compartment*(m1*x[1]/(k1 + x[1]));
        rate_three12 = compartment*r2*x[2];
        rate_three13 = compartment*(m3*x[2]/(k3 + x[2]));
        rate_three15 = compartment*r4*x[6];
        rate_three16 = compartment*((1.0 - LD(time, dayLength))*m7 + m8)*(x[6]/(k6 + x[6]));
        rate_three18 = compartment*r6*x[9];
        rate_three19 = compartment*(m11*x[9]/(k9 + x[9]));
        rate_three21 = compartment*r8*x[12];
        rate_three22 = compartment*(m14*x[12]/(k12 + x[12]));
        rate_three23 = compartment*q3*LD(time, dayLength)*x[3];
        rate_two11 = compartment*(n1*Math.pow(x[9], a)/(Math.pow(g1, a) + Math.pow(x[9], a)));
        rate_two14 = compartment*(m4*x[5]/(k4 + x[5]));
        rate_two17 = compartment*(m9*x[8]/(k7 + x[8]));
        rate_two20 = compartment*(m12*x[11]/(k10 + x[11]));
        rate_two23 = compartment*(m15*x[3]/(k13 + x[3]));
    }

    public void Init()
    {
        initialValues = getInitialValues();
/*
 * Initialize variables
 */
        compartment = 1.0; // initial value of $compartment
        a = 3.3064; // initial value of a
        b = 1.0258; // initial value of b
        c = 1.0258; // initial value of c
        d = 1.4422; // initial value of d
        dayLength = 12.0; // initial value of dayLength
        e = 3.6064; // initial value of e
        f = 1.0237; // initial value of f
        g1 = 0.876738488; // initial value of g1
        g2 = 0.036805783; // initial value of g2
        g3 = 0.26593318; // initial value of g3
        g4 = 0.538811228; // initial value of g4
        g5 = 1.17803247; // initial value of g5
        g6 = 0.064455137; // initial value of g6
        k1 = 1.817; // initial value of k1
        k10 = 1.7303; // initial value of k10
        k11 = 1.8258; // initial value of k11
        k12 = 1.8066; // initial value of k12
        k13 = 1.2; // initial value of k13
        k2 = 1.5644; // initial value of k2
        k3 = 1.2765; // initial value of k3
        k4 = 2.5734; // initial value of k4
        k5 = 2.7454; // initial value of k5
        k6 = 0.4033; // initial value of k6
        k7 = 6.5585; // initial value of k7
        k8 = 0.6632; // initial value of k8
        k9 = 17.1111; // initial value of k9
        m1 = 1.5283; // initial value of m1
        m10 = 0.2179; // initial value of m10
        m11 = 3.3442; // initial value of m11
        m12 = 4.297; // initial value of m12
        m13 = 0.1347; // initial value of m13
        m14 = 0.6114; // initial value of m14
        m15 = 1.2; // initial value of m15
        m2 = 20.44; // initial value of m2
        m3 = 3.6888; // initial value of m3
        m4 = 3.8231; // initial value of m4
        m5 = 0.0013; // initial value of m5
        m6 = 3.1741; // initial value of m6
        m7 = 0.0492; // initial value of m7
        m8 = 4.0424; // initial value of m8
        m9 = 10.1132; // initial value of m9
        n1 = 5.1694; // initial value of n1
        n2 = 3.0087; // initial value of n2
        n3 = 0.2431; // initial value of n3
        n4 = 0.0857; // initial value of n4
        n5 = 0.1649; // initial value of n5
        p1 = 0.8295; // initial value of p1
        p2 = 4.324; // initial value of p2
        p3 = 2.147; // initial value of p3
        p4 = 0.2485; // initial value of p4
        p5 = 0.5; // initial value of p5
        q1 = 2.4514; // initial value of q1
        q2 = 2.40178; // initial value of q2
        q3 = 1.0; // initial value of q3
        r1 = 16.8363; // initial value of r1
        r2 = 0.1687; // initial value of r2
        r3 = 0.3166; // initial value of r3
        r4 = 2.1509; // initial value of r4
        r5 = 1.0352; // initial value of r5
        r6 = 3.3017; // initial value of r6
        r7 = 2.2123; // initial value of r7
        r8 = 0.2002; // initial value of r8
    }

    /*
     * Model variables initial values
     */
    protected double rate_four12;
    protected double rate_four15;
    protected double rate_four18;
    protected double rate_four21;
    protected double rate_one11;
    protected double rate_one12;
    protected double rate_one13;
    protected double rate_one14;
    protected double rate_one15;
    protected double rate_one16;
    protected double rate_one17;
    protected double rate_one18;
    protected double rate_one19;
    protected double rate_one20;
    protected double rate_one21;
    protected double rate_one22;
    protected double rate_one23;
    protected double rate_three11;
    protected double rate_three12;
    protected double rate_three13;
    protected double rate_three15;
    protected double rate_three16;
    protected double rate_three18;
    protected double rate_three19;
    protected double rate_three21;
    protected double rate_three22;
    protected double rate_three23;
    protected double rate_two11;
    protected double rate_two14;
    protected double rate_two17;
    protected double rate_two20;
    protected double rate_two23;
    protected double compartment;
    protected double a;
    protected double b;
    protected double c;
    protected double d;
    protected double dayLength;
    protected double e;
    protected double f;
    protected double g1;
    protected double g2;
    protected double g3;
    protected double g4;
    protected double g5;
    protected double g6;
    protected double k1;
    protected double k10;
    protected double k11;
    protected double k12;
    protected double k13;
    protected double k2;
    protected double k3;
    protected double k4;
    protected double k5;
    protected double k6;
    protected double k7;
    protected double k8;
    protected double k9;
    protected double m1;
    protected double m10;
    protected double m11;
    protected double m12;
    protected double m13;
    protected double m14;
    protected double m15;
    protected double m2;
    protected double m3;
    protected double m4;
    protected double m5;
    protected double m6;
    protected double m7;
    protected double m8;
    protected double m9;
    protected double n1;
    protected double n2;
    protected double n3;
    protected double n4;
    protected double n5;
    protected double p1;
    protected double p2;
    protected double p3;
    protected double p4;
    protected double p5;
    protected double q1;
    protected double q2;
    protected double q3;
    protected double r1;
    protected double r2;
    protected double r3;
    protected double r4;
    protected double r5;
    protected double r6;
    protected double r7;
    protected double r8;
    protected double time;

    public double[] extendResult(double time,double [] x)
    {
        this.time = time;


        double[] y = new double[13];
        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] = x[7];
        y[8] = x[8];
        y[9] = x[9];
        y[10] = x[10];
        y[11] = x[11];
        y[12] = x[12];
        return y;
    }
    public double[] getInitialValues()
    {
        double [] x = new double[13];
        this.time = 0.0;
        x[0] = 0.015; // - $"compartment.cLc"
        x[1] = 0.539; // - $"compartment.cLm"
        x[2] = 0.0855; // - $"compartment.cLn"
        x[3] = 0.835; // - $"compartment.cPn"
        x[4] = 8.7; // - $"compartment.cTc"
        x[5] = 0.456; // - $"compartment.cTm"
        x[6] = 0.4; // - $"compartment.cTn"
        x[7] = 1.34; // - $"compartment.cXc"
        x[8] = 0.08; // - $"compartment.cXm"
        x[9] = 0.4; // - $"compartment.cXn"
        x[10] = 0.0040; // - $"compartment.cYc"
        x[11] = 0.037; // - $"compartment.cYm"
        x[12] = 0.013; // - $"compartment.cYn"

        __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 'BIOMD0000000055.xml' model
         */
    public void __internalDyDt_0(double time, double [] x, double[] result)
    {
        result[0] = -rate_four12+rate_one12-rate_one13+rate_three12;
        result[1] = +rate_one11-rate_three11+rate_two11;
        result[2] = +rate_one13-rate_three12-rate_three13;
        result[3] = +rate_one23-rate_three23-rate_two23;
        result[4] = -rate_four15+rate_one15-rate_one16+rate_three15;
        result[5] = +rate_one14-rate_two14;
        result[6] = +rate_one16-rate_three15-rate_three16;
        result[7] = -rate_four18+rate_one18-rate_one19+rate_three18;
        result[8] = +rate_one17-rate_two17;
        result[9] = +rate_one19-rate_three18-rate_three19;
        result[10] = -rate_four21+rate_one21-rate_one22+rate_three21;
        result[11] = +rate_one20-rate_two20;
        result[12] = +rate_one22-rate_three21-rate_three22;
    }
    protected double [] calculateResult(double time, double[] x)
    {
        double[] result = new double[13];
        __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 );
    }

    protected double LD(double tod, double length)
    {
         return Math.ceil(Math.sin(3.141592653589793*tod/length + 0.0010)/2);
    }
} // class ...