-
Notifications
You must be signed in to change notification settings - Fork 23
/
MassBalance.c
executable file
·158 lines (133 loc) · 6.37 KB
/
MassBalance.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
/*
* SUMMARY: MassBalance.c - calculate basin-wide mass balance
* USAGE: Part of DHSVM
*
* AUTHOR: Mark Wigmosta
* ORG: Battelle - Pacific Northwest National Laboratory
* E-MAIL: ms_wigmosta@pnl.gov
* ORIG-DATE: Oct-96
* DESCRIPTION: Calculate water and sediment mass balance errors
*
* DESCRIP-END.
* FUNCTIONS: MassBalance()
* COMMENTS:
* Modification made on 2012/12/31
* $Id: MassBalance.c, v 4.0 Ning Exp $
*/
#include <stdio.h>
#include <stdlib.h>
#include "settings.h"
#include "data.h"
#include "DHSVMerror.h"
#include "functions.h"
#include "constants.h"
#include "Calendar.h"
/*****************************************************************************
Aggregate()
Calculate the average values for the different fluxes and state variables
over the basin. Only the runoff and some of the sediment variables (as
noted) are calculated as a totals (i.e. runoff is total volume) instead
of an average. In the current implementation the local radiation
elements are not stored for the entire area. Therefore these components
are aggregated in AggregateRadiation() inside MassEnergyBalance().
The aggregated values are set to zero in the function RestAggregate,
which is executed at the beginning of each time step.
*****************************************************************************/
void MassBalance(DATE *Current, FILES *Out, FILES *SedOut, AGGREGATED *Total,
WATERBALANCE *Mass, OPTIONSTRUCT * Options)
{
float NewWaterStorage; /* water storage at the end of the time step */
float Output; /* total water flux leaving the basin; */
float Input;
float MassError; /* mass balance error m */
float MWMMassError; /* mass wasting mass balance error m3 */
float SedInput, SedOutput, SedMassError; /* sediment mass balance variables
for channel network */
NewWaterStorage = Total->Soil.IExcess + Total->Road.IExcess +
Total->CanopyWater + Total->SoilWater +
Total->Snow.Swq + Total->Soil.SatFlow + Total->Soil.DetentionStorage;
Output = Total->ChannelInt + Total->RoadInt + Total->Evap.ETot;
Input = Total->Precip.Precip + Total->Snow.VaporMassFlux +
Total->Snow.CanopyVaporMassFlux + Total->CulvertReturnFlow;
MassError = (NewWaterStorage - Mass->OldWaterStorage) + Output -
Total->Precip.Precip - Total->Snow.VaporMassFlux -
Total->Snow.CanopyVaporMassFlux - Total->CulvertReturnFlow;
/* update */
Mass->OldWaterStorage = NewWaterStorage;
Mass->CumPrecipIn += Total->Precip.Precip;
Mass->CumIExcess += Total->Soil.IExcess;
Mass->CumChannelInt += Total->ChannelInt;
Mass->CumRoadInt += Total->RoadInt;
Mass->CumET += Total->Evap.ETot;
Mass->CumSnowVaporFlux += Total->Snow.VaporMassFlux +
Total->Snow.CanopyVaporMassFlux;
Mass->CumCulvertReturnFlow += Total->CulvertReturnFlow;
Mass->CumCulvertToChannel += Total->CulvertToChannel;
Mass->CumRunoffToChannel += Total->RunoffToChannel;
PrintDate(Current, Out->FilePtr);
fprintf(Out->FilePtr, " %7.4f %7.4f %6.3f %8.4f %.2e \
%.2e %5.2f %5.2f %7.4f %7.4f %7.4f %6.3f %.2e %5.2f %.2e %7.3f \n",
Total->Soil.IExcess, Total->CanopyWater, Total->SoilWater,
Total->Snow.Swq, Total->Soil.SatFlow,
Total->ChannelInt, Total->RoadInt, Total->CulvertReturnFlow, Total->Evap.ETot,
Total->Precip.Precip, Total->Snow.VaporMassFlux,
Total->Snow.CanopyVaporMassFlux, Mass->OldWaterStorage, Total->CulvertToChannel,
Total->RunoffToChannel, MassError);
if(Options->Sediment){
/* Calculate sediment mass errors */
MWMMassError = Total->Fine.MassWasting -Total->Fine.SedimentToChannel -
Total->Fine.MassDeposition ;
SedInput = Total->DebrisInflow +
(Total->SedimentOverlandInflow - Total->CulvertSedToChannel) +
Total->SedimentOverroadInflow ;
SedOutput = Total->SedimentOutflow -
(Total->CulvertSedToChannel + Total->CulvertReturnSedFlow);
SedMassError = (Total->ChannelSedimentStorage +
Total->ChannelSuspendedSediment -
Mass->LastChannelSedimentStorage) +
SedOutput - SedInput;
/* update */
/* Mass Wasting - tota,l m3 */
Mass->CumMassWasting += Total->Fine.MassWasting;
Mass->CumSedimentToChannel += Total->Fine.SedimentToChannel;
Mass->CumMassDeposition += Total->Fine.MassDeposition;
/* Surface Erosion - ave, mm */
Mass->CumSedimentErosion += Total->Sediment.Erosion;
/* Road Erosion - ave, m */
Mass->CumRoadErosion += Total->Road.Erosion;
Mass->CumRoadSedHill += Total->Sediment.RoadSed;
/* Channel Erosion - total, kg */
Mass->CumDebrisInflow += Total->DebrisInflow;
Mass->CumSedOverlandInflow += Total->SedimentOverlandInflow;
Mass->CumSedOverroadInflow += Total->SedimentOverroadInflow;
Mass->CumCulvertSedToChannel += Total->CulvertSedToChannel;
Mass->CumCulvertReturnSedFlow += Total->CulvertReturnSedFlow;
Mass->CumSedimentOutflow += Total->SedimentOutflow;
Mass->LastChannelSedimentStorage = Total->ChannelSedimentStorage +
Total->ChannelSuspendedSediment;
PrintDate(Current, SedOut->FilePtr);
fprintf(SedOut->FilePtr, " %g %g %g %g %g %g %g %g %g %g %g %g %g %g %g \n",
Total->Fine.MassWasting, Total->Fine.SedimentToChannel,
Total->Fine.MassDeposition, MWMMassError, Total->Sediment.Erosion,
Total->Road.Erosion,Total->Sediment.RoadSed,
Total->DebrisInflow, Total->SedimentOverlandInflow,
Total->SedimentOverroadInflow, Total->SedimentOutflow,
Total->CulvertReturnSedFlow, Total->CulvertSedToChannel,
Mass->LastChannelSedimentStorage, SedMassError);
}
}
/* 1. Total mass wasted (m3) */
/* 2. Total mass wasted delivered to channel (m3) */
/* 3. Total mass deposition (m3) */
/* 4. Total mass wasting mass error (m3) */
/* 5. Ave hillslope erosion (mm) */
/* 6. Ave road erosion (m) */
/* 7. Ave road erosion delivered to hillslope (m)*/
/* 8. Total debris inflow (kg) */
/* 9. Total overland inflow (kg) */
/* 10. Total overroad inflow (kg) */
/* 11. Total sediment outflow (kg) */
/* 12. Total culvert return sediment flow (kg) */
/* 13. Total culvert sediment to channel (kg) */
/* 14. Total amount of sediment stored in channels (kg) */
/* 15. Total channel erosion mass balance error for the current time step (kg) */