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