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