...
777{
779 {
780 KLOGERROR( "[BUG] ", "root_system is NULL when not expected \"",_vt->name(),"\"!");
781 return LDNDC_ERR_RUNTIME_ERROR;
782 }
783
784 bool const mulching = _attributes.get( "/mulching", false);
785
786 double const export_root = _attributes.get( "/fraction-export-rootwood", 0.0);
787 double const rootlitter_c( (1.0 - export_root) * _vt->mFrt * cbm::CCDM);
788 double const rootlitter_n( (1.0 - export_root) * _vt->n_frt());
789 double const root_c_export( export_root * _vt->mFrt * cbm::CCDM);
790 double const root_n_export( export_root * _vt->mFrt * _vt->ncFrt);
791
792 double const straw_c( (_vt->mFol + _vt->dw_dfol + _vt->dw_lst+ _vt->dw_dst) * cbm::CCDM);
793 double const straw_n( _vt->n_fol() + _vt->n_dfol + _vt->n_lst + _vt->n_dst);
794
795 double const fru_c( _vt->mBud * cbm::CCDM);
796 double const fru_n( _vt->n_bud());
797
798 double fru_c_export( 0.0);
799 double fru_n_export( 0.0);
800
801 double straw_c_export( 0.0);
802 double straw_n_export( 0.0);
803
804 double mulching_c( 0.0);
805 double mulching_n( 0.0);
806
807 double stubble_c( 0.0);
808 double stubble_n( 0.0);
809
810 double gdd_sum( _vt->growing_degree_days );
811 double dvs_flush( _vt->dvsFlush );
812
813 double const height( _attributes.get( "/height", invalid_flt));
814 double remains_relative( _attributes.get( "/remains_relative", invalid_flt));
815 double remains_absolute( _attributes.get( "/remains_absolute", invalid_flt));
816 if( cbm::is_valid( remains_absolute))
817 {
818 remains_absolute *= cbm::HA_IN_M2;
819 }
820
821 if ( !cbm::flt_greater_equal_zero( remains_relative)
822 && !cbm::flt_greater_equal_zero( remains_absolute)
823 && !cbm::flt_greater_equal_zero( height))
824 {
825 if ( _vt->is_covercrop)
826 {
827 remains_relative = 1.0;
828 }
829 else
830 {
831 KLOGWARN( "harvest event attribute \"remains_relative\" and \"remains_absolute\" and \"height\" not set;",
832 " \"remains_relative\" set to zero and used [species=", _vt->name(),"]");
833 }
834 }
835 else if ( (cbm::flt_greater_equal_zero( remains_relative) ||
836 cbm::flt_greater_equal_zero( remains_absolute))
837 && cbm::flt_greater_equal_zero( height))
838 {
839 KLOGWARN( "harvest event attribute \"remains_(relative/absolute)\" and \"height\" both set;"
840 " attribute \"remains_relative\" used [species=", _vt->name(),"]");
841 }
842
843 if ( cbm::flt_greater_equal_zero( remains_relative))
844 {
845
846 }
847 else if ( cbm::flt_greater_equal_zero( remains_absolute))
848 {
849 remains_relative = cbm::bound( 0.0,
850 remains_absolute / (_vt->mFol + _vt->dw_dfol + _vt->dw_lst+ _vt->dw_dst),
851 1.0);
852 }
853 else if ( cbm::flt_equal_zero( height))
854 {
855 remains_relative = 0.0;
856 }
857 else if ( cbm::flt_greater_zero( height))
858 {
859 double h_cum( 0.0);
860 double remains_relative_fol = 0.0;
861 for ( int fl = 0; fl < m_setup->canopylayers(); ++fl)
862 {
863 remains_relative_fol += _vt->fFol_fl[fl];
864 h_cum += ph_.h_fl[fl];
865 if ( cbm::flt_greater_equal( h_cum, height))
866 {
867 break;
868 }
869 }
870
871 h_cum = 0.0;
872 double remains_relative_lst = 0.0;
873 double remains_relative_lst_total = 0.0;
874 for ( int fl = 0; fl < m_setup->canopylayers(); ++fl)
875 {
876
877 remains_relative_lst_total += pow( cbm::bound_min( 0.0, _vt->height_max - h_cum), 0.3);
878 if ( cbm::flt_less_equal( h_cum, height))
879 {
880 remains_relative_lst += pow( cbm::bound_min( 0.0, _vt->height_max - h_cum), 0.3);
881 }
882 h_cum += ph_.h_fl[fl];
883 }
884 remains_relative_lst /= remains_relative_lst_total;
885
886 remains_relative = (remains_relative_fol * (_vt->mFol + _vt->dw_dfol) +
887 remains_relative_lst * (_vt->dw_lst+ _vt->dw_dst)) /
888 (_vt->mFol + _vt->dw_dfol + _vt->dw_lst+ _vt->dw_dst);
889 }
890 else
891 {
892 KLOGERROR( "[BUG] ", "harvest event attribute \"remains_relative\" and \"height\" are invalid [species=", _vt->name(),"]");
893 return LDNDC_ERR_FAIL;
894 }
895
896 stubble_c += remains_relative * straw_c;
897 stubble_n += remains_relative * straw_n;
898 if ( mulching)
899 {
900 mulching_c += (1.0-remains_relative) * straw_c;
901 mulching_n += (1.0-remains_relative) * straw_n;
902 }
903 else
904 {
905 straw_c_export += (1.0-remains_relative) * straw_c;
906 straw_n_export += (1.0-remains_relative) * straw_n;
907 }
908
909 if ( _vt->is_covercrop)
910 {
911 stubble_c += remains_relative * fru_c;
912 stubble_n += remains_relative * fru_n;
913 if ( mulching)
914 {
915 mulching_c += (1.0-remains_relative) * fru_c;
916 mulching_n += (1.0-remains_relative) * fru_n;
917 }
918 else
919 {
920 stubble_c += (1.0-remains_relative) * fru_c;
921 stubble_n += (1.0-remains_relative) * fru_n;
922 }
923 }
924 else
925 {
926 fru_c_export = fru_c;
927 fru_n_export = fru_n;
928 }
929
930
931 c_total_exported += straw_c_export + fru_c_export;
932 c_fruit_exported += fru_c_export;
933 n_total_exported += straw_n_export + fru_n_export;
934 n_fruit_exported += fru_n_export;
935
936 ph_.accumulated_c_export_harvest += straw_c_export + fru_c_export + root_c_export;
937 ph_.accumulated_n_export_harvest += straw_n_export + fru_n_export + root_n_export;
938
939 ph_.accumulated_c_fru_export_harvest += fru_c_export;
940 ph_.accumulated_n_fru_export_harvest += fru_n_export;
941
942
943 sc_.c_stubble_lit3 += stubble_c * (*_vt)->LIGNIN();
944 sc_.c_stubble_lit2 += stubble_c * (*_vt)->CELLULOSE();
945 sc_.c_stubble_lit1 += stubble_c * (1.0 - (*_vt)->LIGNIN() - (*_vt)->CELLULOSE());
946 sc_.accumulated_c_litter_stubble += stubble_c;
947
948 sc_.n_stubble_lit3 += stubble_n * (*_vt)->LIGNIN();
949 sc_.n_stubble_lit2 += stubble_n * (*_vt)->CELLULOSE();
950 sc_.n_stubble_lit1 += stubble_n * (1.0 - (*_vt)->LIGNIN() - (*_vt)->CELLULOSE());
951 sc_.accumulated_n_litter_stubble += stubble_n;
952
953
954 sc_.c_raw_lit_1_above += mulching_c * (1.0 - (*_vt)->CELLULOSE() - (*_vt)->LIGNIN());
955 sc_.c_raw_lit_2_above += mulching_c * (*_vt)->CELLULOSE();
956 sc_.c_raw_lit_3_above += mulching_c * (*_vt)->LIGNIN();
957 sc_.accumulated_c_litter_above += mulching_c;
958
959 sc_.n_raw_lit_1_above += mulching_n * (1.0 - (*_vt)->CELLULOSE() - (*_vt)->LIGNIN());
960 sc_.n_raw_lit_2_above += mulching_n * (*_vt)->CELLULOSE();
961 sc_.n_raw_lit_3_above += mulching_n * (*_vt)->LIGNIN();
962 sc_.accumulated_n_litter_above += mulching_n;
963
964
965 for ( size_t sl = 0; sl < sl_.soil_layer_cnt(); ++sl)
966 {
967 double const dw_rootlitter( rootlitter_c / cbm::CCDM * _vt->fFrt_sl[sl]);
968 double const n_rootlitter( dw_rootlitter * _vt->ncFrt);
969
970 sc_.c_raw_lit_1_sl[sl] += dw_rootlitter * (1.0 - (*_vt)->CELLULOSE() - (*_vt)->LIGNIN()) * cbm::CCDM;
971 sc_.c_raw_lit_2_sl[sl] += dw_rootlitter * (*_vt)->CELLULOSE() * cbm::CCDM;
972 sc_.c_raw_lit_3_sl[sl] += dw_rootlitter * (*_vt)->LIGNIN() * cbm::CCDM;
973 sc_.accumulated_c_litter_below_sl[sl] += dw_rootlitter * cbm::CCDM;
974
975 sc_.n_raw_lit_1_sl[sl] += n_rootlitter * (1.0 - (*_vt)->CELLULOSE() - (*_vt)->LIGNIN());
976 sc_.n_raw_lit_2_sl[sl] += n_rootlitter * (*_vt)->CELLULOSE();
977 sc_.n_raw_lit_3_sl[sl] += n_rootlitter * (*_vt)->LIGNIN();
978 sc_.accumulated_n_litter_below_sl[sl] += n_rootlitter;
979 }
980
981 cbm::state_scratch_t * mcom = io_kcomm->get_scratch();
982 std::string mcom_key;
983
984 char const * species_name = _attributes.get( "/name", "?");
985
986 cbm::state_scratch_t::make_item_key( &mcom_key, "harvest:%s:daysOnField", species_name);
987 mcom->set( mcom_key.c_str(), (double)((lclock()->seconds() - seconds_crop_planting[_vt->slot]) / cbm::SEC_IN_DAY));
988
989 cbm::state_scratch_t::make_item_key( &mcom_key, "harvest:%s:gddsum", species_name);
990 mcom->set( mcom_key.c_str(), gdd_sum);
991
992 cbm::state_scratch_t::make_item_key( &mcom_key, "harvest:%s:dvsflush", species_name);
993 mcom->set( mcom_key.c_str(), dvs_flush);
994
995 cbm::state_scratch_t::make_item_key( &mcom_key, "harvest:%s:c_fru", species_name);
996 mcom->set( mcom_key.c_str(), fru_c);
997
998 cbm::state_scratch_t::make_item_key( &mcom_key, "harvest:%s:c_fru_export", species_name);
999 mcom->set( mcom_key.c_str(), fru_c_export);
1000
1001 cbm::state_scratch_t::make_item_key( &mcom_key, "harvest:%s:n_fru", species_name);
1002 mcom->set( mcom_key.c_str(), fru_n);
1003
1004 cbm::state_scratch_t::make_item_key( &mcom_key, "harvest:%s:n_fru_export", species_name);
1005 mcom->set( mcom_key.c_str(), fru_n_export);
1006
1007 cbm::state_scratch_t::make_item_key( &mcom_key, "harvest:%s:c_straw", species_name);
1008 mcom->set( mcom_key.c_str(), straw_c);
1009
1010 cbm::state_scratch_t::make_item_key( &mcom_key, "harvest:%s:c_straw_export", species_name);
1011 mcom->set( mcom_key.c_str(), straw_c_export);
1012
1013 cbm::state_scratch_t::make_item_key( &mcom_key, "harvest:%s:n_straw", species_name);
1014 mcom->set( mcom_key.c_str(), straw_n);
1015
1016 cbm::state_scratch_t::make_item_key( &mcom_key, "harvest:%s:n_straw_export", species_name);
1017 mcom->set( mcom_key.c_str(), straw_n_export);
1018
1019 cbm::state_scratch_t::make_item_key( &mcom_key, "harvest:%s:c_stubble", species_name);
1020 mcom->set( mcom_key.c_str(), stubble_c);
1021
1022 cbm::state_scratch_t::make_item_key( &mcom_key, "harvest:%s:n_stubble", species_name);
1023 mcom->set( mcom_key.c_str(), stubble_n);
1024
1025 cbm::state_scratch_t::make_item_key( &mcom_key, "harvest:%s:c_frt", species_name);
1026 mcom->set( mcom_key.c_str(), rootlitter_c);
1027
1028 cbm::state_scratch_t::make_item_key( &mcom_key, "harvest:%s:n_frt", species_name);
1029 mcom->set( mcom_key.c_str(), rootlitter_n);
1030
1031 for ( size_t sl = 0; sl < sl_.soil_layer_cnt(); ++sl)
1032 {
1033 _vt->fFrt_sl[sl] = 0.0;
1034 }
1035
1037 _vt->rooting_depth = 0.0;
1038
1039 days_after_emergence[_vt->slot] = -1;
1040
1041 dw_retranslocation_stem[_vt->slot] = 0.0;
1042 dw_retranslocation_foliage[_vt->slot] = 0.0;
1043
1044 dw_fol_old[_vt->slot] = 0.0;
1045 lai_dynamic[_vt->slot] = 0.0;
1046
1047 _vt->mFol = 0.0;
1048 _vt->dw_dfol = 0.0;
1049 _vt->ncFol = 0.0;
1050 _vt->n_dfol = 0.0;
1051
1052 _vt->dw_lst = 0.0;
1053 _vt->n_lst = 0.0;
1054
1055 _vt->dw_dst = 0.0;
1056 _vt->n_dst = 0.0;
1057
1058 _vt->mBud = 0.0;
1059 _vt->mBudStart = 0.0;
1060 _vt->ncBud = 0.0;
1061
1062 _vt->mFrt = 0.0;
1063 _vt->ncFrt = 0.0;
1064
1065 _vt->dEmerg = -1;
1066 _vt->growing_degree_days = 0.0;
1067 _vt->dvsMort = 0.0;
1068 _vt->dvsFlush = 0.0;
1069 _vt->dvsFlushOld = 0.0;
1070
1071 n_plant[_vt->slot] = 0.0;
1072 _vt->a_fix_n = 0.0;
1073
1074 _vt->height_max = 0.0;
1075 _vt->height_at_canopy_start = 0.0;
1076
1077 _vt->f_area = 0.0;
1078 for ( int fl = 0; fl < m_setup->canopylayers(); ++fl)
1079 {
1080 _vt->fFol_fl[fl] = 0.0;
1081 _vt->lai_fl[fl] = 0.0;
1082 }
1083
1084 _vt->f_fac = 0.0;
1086 _vt->chill_factor = 1.0;
1087
1088 yearly_cuts[_vt->slot] = 0;
1089
1094
1095 m_fruit_maximum[_vt->slot] = -1.0;
1096 spikelets_sterility[_vt->slot] = 0.0;
1097 hypoxia[_vt->slot] = 0.0;
1098
1101
1102 return LDNDC_ERR_OK;
1103}
lvector_t< double > allocation_factor_stems
Allocation factor of daily assimilated carbon to stem growth [-].
Definition plamox.h:271
lvector_t< double > allocation_factor_fruit
Allocation factor of daily assimilated carbon to fruit growth [-].
Definition plamox.h:277
lvector_t< double > allocation_factor_roots
Allocation factor of daily assimilated carbon to root growth [-].
Definition plamox.h:283
lvector_t< double > allocation_factor_leafs
Allocation factor of daily assimilated carbon to leaf growth [-].
Definition plamox.h:265
lvector_t< unsigned int > root_q_vt_
Largest soil layer index where roots exist [-].
Definition plamox.h:327
lvector_t< double > chill_units
Accumulated chilling units for vernalization;.
Definition plamox.h:303