src/OFLCalcs.cpp
dvariable OFL_Calculator::calcFofl(dvariable Bmsy, dvariable Fmsy, dvar3_array& n_msz, ostream& cout){
    if (debug) {
        cout<<"starting double OFL_Calculator::calcFofl(Bmsy, Fmsy,n_msz)"<<endl;
        cout<<"Bmsy = "<<Bmsy<<"; Fmsy = "<<Fmsy<<endl;
        cout<<"n_msz = "<<endl;wts::print(n_msz,cout,1); cout<<endl;        
    }
    RETURN_ARRAYS_INCREMENT();
    
    PopProjector* pPrjM = pTCM->pEC->pPP;
    
    //start with guess for Fofl based on currMMB
    dvariable currMMB = pPrjM->projectMatureBiomassAtMating(Fmsy,n_msz,cout);
    if (debug) cout<<"init currMMB = "<<currMMB<<"; B/Bmsy = "<<currMMB/Bmsy<<endl;
    dvariable Fofl = calcHCR(currMMB,Bmsy,Fmsy,cout);
    if (debug) cout<<"init Fofl = "<<Fofl<<endl;
    //now iterate until Fofl yields currMMB
    dvariable Foflp = 0.0;
    int i = 1;
    while (i++ < maxIts){
        if (debug&&(i==maxIts)) cout<<"HCR iteration for Fofl = "<<i<<endl;
        //calculate currMMB based on Fofl
        currMMB = pPrjM->projectMatureBiomassAtMating(Fofl,n_msz,cout);
        if (debug) cout<<"--updated prjMMB = "<<currMMB<<"; B/Bmsy = "<<currMMB/Bmsy<<endl;
        //update Fofl based on currMMB
        Foflp = Fofl;
        Fofl  = calcHCR(currMMB,Bmsy,Fmsy,cout);
        if (debug) cout<<"--updated Fofl = "<<Fofl<<"; delF = "<<Fofl - Foflp<<endl;
    }
    double criF = 0.001;
    if (sfabs(value(Fofl - Foflp))>criF){
        cout<<endl<<"-------ERROR!!-------"<<endl;
        cout<<"Convergence in calcFofl failed: |delF| = "<<sfabs(value(Fofl - Foflp))<<" > "<<criF<<endl;
        cout<<"-------ERROR!!-------"<<endl<<endl;
    }
    prjMMB = currMMB;
    if (debug) {
        cout<<"Fofl   = "<<Fofl<<endl;
        cout<<"prjMMB = "<<prjMMB<<endl;
        cout<<"finished double OFL_Calculator::calcFofl(Bmsy, Fmsy,n_msz)"<<endl;
    }
    RETURN_ARRAYS_DECREMENT();
    return Fofl;
}
/**
 * Calculate Fofl using the Harvest Control Rule (HCR), based on Bmsy,
 * Fmsy, and the initial (July 1) male abundance n_msz. This is an 
 * iterative process because Fofl is given by the HCR based on the
 * projected MMB, which itself depends on what the target fishery capture
 * rate (F) was.
 * 
 * Also calculates prjMMB;
 * 
 * @param Bmsy - equilibrium MMB when population fished at Fmsy
 * @param Fmsy - directed fishery capture rate yielding MSY
 * @param n_msz - initial (July 1) male abundance
 * @param cout - output stream for debug info
 * 
 * @return Fofl
 */
Calculate Fofl using the Harvest Control Rule (HCR), based on Bmsy,
Fmsy, and the initial (July 1) male abundance n_msz. This is an
iterative process because Fofl is given by the HCR based on the
projected MMB, which itself depends on what the target fishery capture
rate (F) was.

Also calculates prjMMB.

@param Bmsy - equilibrium MMB when population fished at Fmsy
@param Fmsy - directed fishery capture rate yielding MSY
@param n_msz - initial (July 1) male abundance
@param cout - output stream for debug info

@return Fofl
Calculate Fofl using the Harvest Control Rule ( HCR ) based on Bmsy Fmsy and the initial ( July 1 ) male abundance n_msz . This is an iterative process because Fofl is given by the HCR based on the projected MMB which itself depends on what the target fishery capture rate ( F ) was . Also calculates prjMMB . @param Bmsy - equilibrium MMB when population fished at Fmsy @param Fmsy - directed fishery capture rate yielding MSY @param n_msz - initial ( July 1 ) male abundance @param cout - output stream for debug info @return Fofl
dvariable OFL_Calculator::calcFofl(dvariable Bmsy, dvariable Fmsy, dvar3_array& n_msz, ostream& cout){
    if (debug) {
        cout<<"starting double OFL_Calculator::calcFofl(Bmsy, Fmsy,n_msz)"<<endl;
        cout<<"Bmsy = "<<Bmsy<<"; Fmsy = "<<Fmsy<<endl;
        cout<<"n_msz = "<<endl;wts::print(n_msz,cout,1); cout<<endl;        
    }
    RETURN_ARRAYS_INCREMENT();
    PopProjector* pPrjM = pTCM->pEC->pPP;
    dvariable currMMB = pPrjM->projectMatureBiomassAtMating(Fmsy,n_msz,cout);
    if (debug) cout<<"init currMMB = "<<currMMB<<"; B/Bmsy = "<<currMMB/Bmsy<<endl;
    dvariable Fofl = calcHCR(currMMB,Bmsy,Fmsy,cout);
    if (debug) cout<<"init Fofl = "<<Fofl<<endl;
    dvariable Foflp = 0.0;
    int i = 1;
    while (i++ < maxIts){
        if (debug&&(i==maxIts)) cout<<"HCR iteration for Fofl = "<<i<<endl;
        currMMB = pPrjM->projectMatureBiomassAtMating(Fofl,n_msz,cout);
        if (debug) cout<<"--updated prjMMB = "<<currMMB<<"; B/Bmsy = "<<currMMB/Bmsy<<endl;
        Foflp = Fofl;
        Fofl  = calcHCR(currMMB,Bmsy,Fmsy,cout);
        if (debug) cout<<"--updated Fofl = "<<Fofl<<"; delF = "<<Fofl - Foflp<<endl;
    }
    double criF = 0.001;
    if (sfabs(value(Fofl - Foflp))>criF){
        cout<<endl<<"-------ERROR!!-------"<<endl;
        cout<<"Convergence in calcFofl failed: |delF| = "<<sfabs(value(Fofl - Foflp))<<" > "<<criF<<endl;
        cout<<"-------ERROR!!-------"<<endl<<endl;
    }
    prjMMB = currMMB;
    if (debug) {
        cout<<"Fofl   = "<<Fofl<<endl;
        cout<<"prjMMB = "<<prjMMB<<endl;
        cout<<"finished double OFL_Calculator::calcFofl(Bmsy, Fmsy,n_msz)"<<endl;
    }
    RETURN_ARRAYS_DECREMENT();
    return Fofl;
}
dvariable OFL_Calculator :: calcFofl ( dvariable Bmsy , dvariable Fmsy , dvar3_array & n_msz , ostream & cout ) { if ( debug ) { cout << " " << endl ; cout << " " << Bmsy << " " << Fmsy << endl ; cout << " " << endl ; wts :: print ( n_msz , cout , 1 ) ; cout << endl ; } RETURN_ARRAYS_INCREMENT ( ) ; PopProjector * pPrjM = pTCM -> pEC -> pPP ; dvariable currMMB = pPrjM -> projectMatureBiomassAtMating ( Fmsy , n_msz , cout ) ; if ( debug ) cout << " " << currMMB << " " << currMMB / Bmsy << endl ; dvariable Fofl = calcHCR ( currMMB , Bmsy , Fmsy , cout ) ; if ( debug ) cout << " " << Fofl << endl ; dvariable Foflp = 0.0 ; int i = 1 ; while ( i ++ < maxIts ) { if ( debug && ( i == maxIts ) ) cout << " " << i << endl ; currMMB = pPrjM -> projectMatureBiomassAtMating ( Fofl , n_msz , cout ) ; if ( debug ) cout << " " << currMMB << " " << currMMB / Bmsy << endl ; Foflp = Fofl ; Fofl = calcHCR ( currMMB , Bmsy , Fmsy , cout ) ; if ( debug ) cout << " " << Fofl << " " << Fofl - Foflp << endl ; } double criF = 0.001 ; if ( sfabs ( value ( Fofl - Foflp ) ) > criF ) { cout << endl << " " << endl ; cout << " " << sfabs ( value ( Fofl - Foflp ) ) << " " << criF << endl ; cout << " " << endl << endl ; } prjMMB = currMMB ; if ( debug ) { cout << " " << Fofl << endl ; cout << " " << prjMMB << endl ; cout << " " << endl ; } RETURN_ARRAYS_DECREMENT ( ) ; return Fofl ; }
Calculate Fofl using the Harvest Control Rule (HCR), based on Bmsy,
 Fmsy, and the initial (July 1) male abundance n_msz.
Calculate Fofl using the Harvest Control Rule ( HCR ) based on Bmsy Fmsy and the initial ( July 1 ) male abundance n_msz .
//start with guess for Fofl based on currMMB //now iterate until Fofl yields currMMB //calculate currMMB based on Fofl //update Fofl based on currMMB