Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Class Members | File Members

CropSoil.h

Go to the documentation of this file.
00001 //------------------------------------------------------------------------------
00002 //
00003 //  Thomas Berger (main author), Pepijn Schreinemachers, and Thorsten Arnold
00004 //
00005 //
00006 //  Hohenheim University (490d)
00007 //  Professorship for Land Use Economics in the Tropics and Subtropics
00008 //
00009 //  May not be distributed without permission by main author
00010 //
00011 //  File:       CropSoil.h (formerly soils.h)
00012 //
00013 //  Contents:   Implemenation of the soil nutrient model TSPC
00014 //
00015 //
00016 //
00017 //------------------------------------------------------------------------------
00018 
00019 #ifndef _CropSoil_h
00020 #define _CropSoil_h
00021 
00022 
00023 #include "BasicData.h"
00024 
00025 //general parameters
00026 typedef struct
00027 {  double dc;
00028    double bd;
00029    double rf;
00030    double ef;
00031    double so;
00032 }  gnrlP;
00033 
00034 //mineral fertilizer parameters
00035 typedef struct
00036 {  double mf_n;
00037    double mf_p;
00038    double mf_k;
00039    double ph_f;
00040    double li_f;
00041 }  mferP;
00042 
00043 
00044 //organic fertilizer parameters
00045 typedef struct
00046 {  double of_n;
00047    double of_p;
00048    double of_k;
00049    double of_c;
00050 }  oferP;
00051 
00052 
00053 //crop yield parameters
00054 typedef struct
00055 {  double yp;
00056    double m1;
00057    double m2;
00058    double n1;
00059    double n2;
00060    double p1;
00061    double p2;
00062    double k1;
00063    double k2;
00064    double c1;
00065    double c2;
00066    double c3;
00067    double a1;
00068    double a2;
00069    double fg;
00070    double fs;
00071 }  yildF;
00072 
00073 //crop physical parameters
00074 typedef struct
00075 {  double s1;
00076    double h1;
00077    double gn;
00078    double gp;
00079    double gk;
00080    double sn;
00081    double sp;
00082    double sk;
00083    double sc;
00084    double me;
00085 }  cropP;
00086 
00087 //crop erosion parameters
00088 typedef struct
00089 {  double e1;
00090    double e2;
00091 }  erosP;
00092 
00093 //-----------------------------------------------------------------------------
00094 
00095 //data structures for cropping activities
00096 typedef struct
00097 {  double yld;    //grain yield
00098    double ysm;    //stover energy yield
00099 }  caYld;
00100 
00101 
00102 class inCrA
00103 {  //auxiliary class, everthing public
00104    public:
00105 
00106    //input data per cropping activity
00107    int      crpID;  //crop ID
00108    double   inLab;  //labor input
00109    double*  inFer;  //input of mineral fertilizers
00110 
00111    inCrA(int numF);
00112    virtual ~inCrA();
00113 };
00114 
00115 //-----------------------------------------------------------------------------
00116 
00117 //auxiliary class soil conditions (held by grid object "flaeche9")
00118 class soilC
00119 {  public:
00120 
00121    double N;
00122    double P;
00123    double K;
00124    double A;
00125    double C;
00126    double sl;
00127    double se;
00128 
00129    virtual ~soilC()
00130    {
00131    }
00132 
00133 };
00134 
00135 //soil process variables (held by parcel object "parzelle")
00136 class sProc
00137 {  //auxiliary class, everthing public
00138    public:
00139 
00140    double SON1;
00141    double RTN1;
00142    double PCO1;
00143    double CER1;
00144    double KIC1;
00145    double NER1;
00146    double RTS1;
00147    double KGC1;
00148    double YST1;
00149    double SOC1;
00150    double APH1;
00151 
00152    double* FER1;
00153 
00154    sProc(int numF)
00155    {  if((FER1 = new double[numF]) == NULL)
00156       { printf("Error: Not enough memory for 'sProc'\n");
00157         exitfun();
00158       }
00159    }
00160 
00161    virtual ~sProc()
00162    {  delete [] FER1;
00163    }
00164 };
00165 
00166 //land use history of plot (held by parcel object "parzelle")
00167 typedef struct
00168 {  double STN1;
00169    double STN2;
00170    double STN3;
00171    double RES1;
00172    double RES2;
00173    double RES3;
00174    double MAN1;
00175    double MAN2;
00176    double MAN3;
00177 }  lUseH;
00178 
00179 
00180 //crop mix per NRU (held by parcel object "parzelle")
00181 //IMPORTANT: all values in crop mix are per ha values
00182 class crpMixNRU
00183 {  //auxiliary class, everthing public
00184    public:
00185 
00186    //data per cropping activity
00187    int nCr;    //number of cropping activities
00188    int*    crA;//cropping activity ID
00189    int*    cID;//crop IDs
00190    int*    cLP;//LP columns
00191    int*    yLP;//yield price column in LP
00192    double* aHa;//hectar of cropping activities per plot
00193    double* LAB;//labor input per ha
00194    double* YLD;//grain yield per ha
00195    double* YSM;//stover energy yield per ha
00196    double** FER;//mineral fertilizers applied per ha
00197 
00198    //average data of nutrient response unit
00199    int nru;              //ID of NRU
00200    int soilID;  //soil type ID of NRU
00201    double tSize;//size of NRU in ha
00202    double tStvL;//expected stover demand of livestock from NRU in MJ
00203    double avgSl;//average slope length in NRU
00204    double avgSe;//average slope erodibility in NRU
00205 
00206    double STN;  //average N in stover per ha
00207    double RES;  //average percentage of stover left on plot
00208    double MAN;  //average manure left on plot per ha
00209 
00210    sProc* soilP;//soil process variables of previous year
00211    lUseH landU;//land use history
00212 
00213 
00214    crpMixNRU(int n, int numF)
00215    {  nCr = n;
00216 
00217                 if((crA = new    int[nCr]) == NULL)
00218                 {       printf( "Error: Not enough memory for 'crpMix'\n");
00219                         exitfun();
00220                 }
00221 
00222                 if((cID = new    int[nCr]) == NULL)
00223                 {       printf( "Error: Not enough memory for 'crpMix'\n");
00224                         exitfun();
00225                 }
00226 
00227                 if((cLP = new    int[nCr]) == NULL)
00228                 {       printf( "Error: Not enough memory for 'crpMix'\n");
00229                         exitfun();
00230                 }
00231 
00232                 if((yLP = new    int[nCr]) == NULL)
00233                 {       printf( "Error: Not enough memory for 'crpMix'\n");
00234                         exitfun();
00235                 }
00236 
00237                 if((aHa = new double[nCr]) == NULL)
00238                 {       printf( "Error: Not enough memory for 'crpMix'\n");
00239                         exitfun();
00240                 }
00241 
00242                 if((LAB = new double[nCr]) == NULL)
00243                 {       printf( "Error: Not enough memory for 'crpMix'\n");
00244                         exitfun();
00245                 }
00246 
00247                 if((YLD = new double[nCr]) == NULL)
00248                 {       printf( "Error: Not enough memory for 'crpMix'\n");
00249                         exitfun();
00250                 }
00251 
00252                 if((YSM = new double[nCr]) == NULL)
00253                 {       printf( "Error: Not enough memory for 'crpMix'\n");
00254                         exitfun();
00255                 }
00256 
00257                 if((FER = new double*[nCr]) == NULL)
00258                 {       printf( "Error: Not enough memory for 'crpMix'\n");
00259                         exitfun();
00260                 }
00261 
00262       for (int i = 0; i < nCr; i++)
00263       {  if((FER[i] = new double[numF]) == NULL)
00264          {      printf( "Error: Not enough memory for 'crpMix'\n");
00265                 exitfun();
00266          }
00267       }
00268    }
00269 
00270    virtual ~crpMixNRU()
00271    {  delete [] crA;
00272       delete [] cID;
00273       delete [] cLP;
00274       delete [] yLP;
00275       delete [] aHa;
00276       delete [] LAB;
00277       delete [] YLD;
00278       delete [] YSM;
00279 
00280       for (int i = 0; i < nCr; i++)
00281       {  delete [] FER[i];
00282       }
00283       delete [] FER;
00284    }
00285 };
00286 
00287 //-----------------------------------------------------------------------------
00288 
00289 class CropSoil
00290 {  protected:
00291         FILE* datStrm;
00292    int numTypes;//soil types (from basic data)
00293 
00294    int numCrops;//number of crops in TSPC model
00295    int numCropA;//number of cropping activities per NRU
00296    int numNRUnt;//number of nutrient response units
00297    int numMiFer;//number mineral fertilizers
00298    int numOrFer;//number organic fertilizers
00299    int numSeasn;//number of cropping seasons per year
00300 
00301    gnrlP* gnrlPars; //general parameters of soil types
00302    mferP* mferPars; //pointer to mineral fertilizer parameters
00303    oferP* oferPars; //pointer to organic fertilizer parameters
00304    yildF* yldFuncs; //pointer to crop yield function parameters
00305    cropP* cropPars; //pointer to crop physical parameters
00306    erosP* erosPars; //pointer to crop erosion parameters
00307 
00308    sProc** initPro;  //initial values soil processes per soil type
00309    lUseH* initLuh;  //initial values land use history per soil type
00310 
00311    caYld** yldExp;  //start values for yield expectations
00312    inCrA*** craInp;  //inputs to cropping activities
00313 
00314         public:
00315         CropSoil(void)
00316         {  numTypes = -1;
00317 
00318       numCrops = -1;
00319       numCropA = -1;
00320       numNRUnt = -1;
00321       numMiFer = -1;
00322       numOrFer = -1;
00323       numSeasn = -1;
00324 
00325       gnrlPars = NULL;
00326       mferPars = NULL;
00327       oferPars = NULL;
00328       yldFuncs = NULL;
00329       cropPars = NULL;
00330       erosPars = NULL;
00331 
00332            initPro = NULL;
00333 
00334       yldExp  = NULL;
00335       craInp  = NULL;
00336    }
00337 
00338    virtual ~CropSoil()
00339         {       deallocateMem();
00340         }
00341 
00342    virtual void readInputFromFile(char*);
00343    virtual void writeInputIntoFile(char*);
00344 
00345    virtual int getNumCrops();//number of crops in TSPC model
00346    virtual int getNumCropA();//number of cropping activities per NRU
00347    virtual int getNumNRUnt();//number of nutrient response units
00348    virtual int getNumMiFer();//number mineral fertilizers
00349    virtual int getNumOrFer();//number organic fertilizers
00350    virtual int getNumSeasn();//number of cropping seasons per year
00351 
00352    virtual gnrlP& getGnrlPars(int typ);
00353    virtual double getLimeInFert(int fer);
00354    virtual sProc* getInitSoilPr(int typ);
00355    virtual lUseH& getInitLdUseH(int typ);
00356    virtual caYld  getInitYldExp(int act, int typ);
00357    virtual int getCrpID(int cra, int typ);
00358    virtual double getInLab(int cra, int typ);
00359    virtual double getInFer(int cra, int typ, int fer);
00360         virtual int getZeroLabAct(int typ);//neu 2004 returns activity ID of fallow
00361 
00362    virtual void makeYldOfCropMix(int aID, int sID, int kID, int fID,
00363                                                                 crpMixNRU*& cmNRU, sProc*& sPrNRU, soilC*& sConNRU);
00364    virtual void writeRowInfoStrm(int aID, int sID, int kID, int fID, int nru,
00365                                                                 int cID, int typ, int crA);
00366    virtual void writeEquatInStrm(double rslt);
00367    virtual void writeNewLineStrm();
00368 
00369         virtual void printToScreen(void);
00370         virtual void deallocateMem(void);
00371 };
00372 
00373 
00374 
00375 #endif

Generated on Thu Aug 28 12:38:44 2008 for MPMAS by  doxygen 1.3.9.1