Alpine3D

Alpine3D Svn Source Tree

Root/trunk/alpine3d/snowdrift/checksum.cc

1/***********************************************************************************/
2/* Copyright 2009-2015 WSL Institute for Snow and Avalanche Research SLF-DAVOS */
3/***********************************************************************************/
4/* This file is part of Alpine3D.
5 Alpine3D is free software: you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
9
10 Alpine3D is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public License
16 along with Alpine3D. If not, see <http://www.gnu.org/licenses/>.
17*/
18#include <alpine3d/snowdrift/checksum.h>
19
20using namespace mio;
21using namespace std;
22
23double checksum(const CDoubleArray &x)
24{
25double t=0;
26size_t n=x.getNx();
27for (size_t i=0;i<n;i++) {
28t+=x[i];
29}
30return t;
31}
32
33double checksum(const CDoubleArray &x, int start, int step)
34{
35double t=0;
36size_t n=x.getNx();
37if (step<=0) {
38step=1;
39}
40for (size_t i=static_cast<size_t>(start);i<n;i+=static_cast<size_t>(step)) {
41t+=x[i];
42}
43return t;
44}
45
46double checksum(const CElementArray &x)
47{
48double t=0;
49size_t n, tmp;
50x.size(n, tmp);
51for (size_t i=0;i<n;i++) {
52for (size_t j=0;j<8;j++) {
53t+=x(i,j);
54}
55}
56return t;
57}
58
59double checksum(const mio::Array2D<double> &x)
60{
61size_t nx, ny;
62x.size(nx,ny);
63double t=0;
64for (size_t i=0;i<nx;i++) {
65for (size_t j=0;j<ny;j++) {
66t+=x(i,j);
67}
68}
69
70return t;
71}
72
73double checksum_rows(const mio::Array2D<double> &x, const size_t& from, size_t to)
74{
75size_t nx, ny;
76x.size(nx,ny);
77double t=0;
78
79if (to>=nx) {
80to=nx-1;
81}
82
83for (size_t i=from;i<=to;i++) {
84for (size_t j=0;j<ny;j++) {
85t+=x(i,j);
86}
87}
88
89return t;
90}
91
92double checksum_cols(const mio::Array2D<double> &x, const size_t& from, size_t to)
93{
94size_t nx, ny;
95x.size(nx,ny);
96double t=0;
97
98if (to>=ny) {
99to=ny-1;
100}
101
102for (size_t i=0;i<nx;i++) {
103for (size_t j=from;j<=to;j++) {
104t+=x(i,j);
105}
106}
107return t;
108}
109
110double checksum_c(const Grid3DObject &grid)
111{
112 const double t = grid.grid3D.getMean()*static_cast<double>(grid.grid3D.getCount());
113 return t;
114
115}
116
117double checksum(const mio::Array1D<SnowStation>&x)
118{
119const size_t n = x.getNx();
120double t1=0;
121bool first=true;
122
123for (size_t ii=0; ii<n; ii++)
124{
125double t=0;
126t+=x[ii].Albedo+x[ii].SoilAlb+x[ii].BareSoil_z0+static_cast<double>(x[ii].SoilNode)+x[ii].cH+x[ii].mH+x[ii].Ground;
127t+=x[ii].hn+x[ii].rho_hn+x[ii].windward+static_cast<double>(x[ii].ErosionLevel);
128t+=x[ii].S_class1+x[ii].S_class2+x[ii].S_d+x[ii].z_S_d+x[ii].S_s+x[ii].z_S_s+
129x[ii].S_n+x[ii].z_S_n+x[ii].S_4+x[ii].z_S_4+x[ii].S_5+x[ii].z_S_5+static_cast<double>(x[ii].getNumberOfNodes());
130
131t+=checksum(x[ii].Ndata, x[ii].getNumberOfNodes());
132t+=checksum(x[ii].Edata, x[ii].getNumberOfElements());
133if (x[ii].Kt!=NULL) {
134t+=0.1;
135}
136
137t+=checksum(x[ii].Cdata);
138
139if (t>1.0E20 && first) {
140first=false;
141cerr << "STATION VALUE TO BIG AT INDEX #" << ii << "\n";
142}
143
144t1+=t;
145}
146return t1;
147
148}
149
150double checksum(const std::vector<NodeData>& x, const size_t n)
151{
152double t=0;
153for (size_t i=0;i<n;i++) {
154t+=x[i].z+x[i].u+x[i].f+x[i].udot+x[i].T+x[i].S_n+x[i].S_s+x[i].hoar;
155}
156return t;
157
158}
159
160double checksum(const std::vector<ElementData>& x, const size_t n)
161{
162double t=0;
163for (size_t i=0; i<n; i++) {
164t+=x[i].depositionDate.getJulian()+x[i].L0+x[i].L+x[i].Te+x[i].gradT+x[i].Rho+x[i].M;
165for (int j=0;j<N_COMPONENTS;j++) {
166t+=x[i].theta[j];
167for (unsigned int k=0;k<SnowStation::number_of_solutes;k++) {
168t += (x[i]).conc(j,k);
169}
170}
171for (int j=0;j<N_SN_FIELDS;j++) {
172if (x[i].k[j] < Constants::big) {
173t+=x[i].k[j]+x[i].c[j]+x[i].soil[j];
174}
175}
176
177t+=x[i].sw_abs+x[i].rg+x[i].dd+x[i].sp+x[i].rb+x[i].N3+static_cast<double>(x[i].mk+x[i].type);
178
179t+=x[i].dEps+x[i].Eps+x[i].Eps_e+x[i].Eps_v+x[i].Eps_Dot+x[i].Eps_vDot+x[i].S+x[i].C+ x[i].S_dr+x[i].hard;
180}
181return t;
182}
183
184double checksum(const CanopyData &x)
185{
186const size_t n = sizeof(CanopyData)/sizeof(double);
187double *xp=(double *)(&x);
188double t=0;
189for (size_t i=0;i<n;i++, xp++) {
190t+=*xp;
191}
192return t;
193}
194

Archive Download this file

Revision: HEAD