Esempio n. 1
0
//This is the function that gets called to evaluate each parameter set
void calc_hymod(double* parameters)
{
    // assign parameter values for this run
    // Rate constants Ks and Kq should be specified in units of time-1, 0 < Ks < Kq < 1
    hymod.parameters.Ks    = parameters[0];
    hymod.parameters.Kq    = parameters[1];
    hymod.parameters.DDF   = parameters[2];
    hymod.parameters.Tb    = parameters[3];
    hymod.parameters.Tth   = parameters[4];
    hymod.parameters.alpha = parameters[5];
    hymod.parameters.B     = parameters[6];
    hymod.parameters.Huz   = parameters[7];
    hymod.parameters.Cpar = hymod.parameters.Huz / (1.0 + hymod.parameters.B); // max capacity of soil moisture tank

    // Reinitialize everything to zero
    zero_states_and_fluxes(nDays);

    //Run Model for Simulation Period
    int dataDay;
    for (int modelDay = 0; modelDay < nDays; modelDay++)
    {
        //Since used as an index, we need to convert to zero indexing
        dataDay = startingIndex + modelDay;

        // Run snow model to find effective precip for this timestep
        hymod.fluxes.effPrecip[modelDay] = snowDD(modelDay, dataDay);

        // Run Pdm soil moisture accounting including evapotranspiration
        PDM_soil_moisture(modelDay, dataDay);

        // Run Nash Cascade routing of quickflow component
        double new_quickflow = hymod.parameters.alpha * hymod.fluxes.OV[modelDay];
        hymod.fluxes.Qq[modelDay] = Nash(hymod.parameters.Kq, hymod.parameters.Nq, new_quickflow, hymod.states.Xq[modelDay]);

        // Run Nash Cascade routing of slowflow component
        double new_slowflow = (1.0-hymod.parameters.alpha) * hymod.fluxes.OV[modelDay];
        hymod.fluxes.Qs[modelDay] = Nash(hymod.parameters.Ks, 1, new_slowflow, &hymod.states.Xs[modelDay]);

        // Set the intial states of the next time step to those of the current time step
        if (modelDay < nDays-1)
        {
            hymod.states.XHuz[modelDay+1] = hymod.states.XHuz[modelDay];
            hymod.states.Xs[modelDay+1]   = hymod.states.Xs[modelDay];
            hymod.states.snow_store[modelDay+1] = hymod.states.snow_store[modelDay];

            for(int m = 0; m < hymod.parameters.Nq; m++)
                hymod.states.Xq[modelDay+1][m] = hymod.states.Xq[modelDay][m];
        }

        hymod.fluxes.Q[modelDay] = hymod.fluxes.Qq[modelDay] + hymod.fluxes.Qs[modelDay];
    }

    return;
}
Esempio n. 2
0
void LinearFit()
{
    int r, c, g, n, m, z ;
    unsigned int size, rank ;
    double *U, *V, sum ;

    /*
     *  allocate storage for A
     *
     */

    NP = PointCount ;

    if( NP < GSIZE )
        size = NP * GSIZE + NP * NP ;
    else
        size = NP * GSIZE + GSIZE * GSIZE ;

    if( Asize < size )
    {
        Asize = size + 32 * GSIZE ;		/* extra room */
        A  = (double *) realloc( A, Asize * sizeof(double) ) ;
    }

    /*
     *  put the data into A and take the SVD
     *
     */

    r = c = 0 ;
    for( P = PointZero ; P ; P = P->next )
    {
        LinearVector( P, G ) ;
        if( NP < GSIZE )
        {
            for( r = 0 ; r < GSIZE ; r++ )
                A[ r * NP + c ] = G[r] ;
            c++ ;
        }
        else
        {
            for( c = 0 ; c < GSIZE ; c++ )
                A[ r * GSIZE + c ] = G[c] ;
            r++ ;
        }
    }

    if( NP < GSIZE )
        rank = Nash( A, Z, (int) GSIZE, (int) NP ) ;
    else
        rank = Nash( A, Z, (int) NP, (int) GSIZE ) ;

    if( rank < GSIZE )
        LinearCondition = (int) rank - (int) GSIZE ;
    else if( rank )
        LinearCondition = log( Z[0] / Z[rank - 1] ) ;
    else
        LinearCondition = 0.0 ;

    U = &( A[0] ) ;
    V = &( A[ GSIZE * NP ] ) ;
}