forked from perabrahamsen/daisy-model
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ABAprod_soil.C
153 lines (131 loc) · 4.14 KB
/
ABAprod_soil.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
// ABAprod_soil.C -- ABA production based on soil location.
//
// Copyright 2007 Per Abrahamsen and KVL.
//
// This file is part of Daisy.
//
// Daisy is free software; you can redistribute it and/or modify
// it under the terms of the GNU Lesser Public License as published by
// the Free Software Foundation; either version 2.1 of the License, or
// (at your option) any later version.5
//
// Daisy is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser Public License for more details.
//
// You should have received a copy of the GNU Lesser Public License
// along with Daisy; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#define BUILD_DLL
#include "ABAprod.h"
#include "number.h"
#include "scope_exchange.h"
#include "geometry.h"
#include "soil_water.h"
#include "assertion.h"
#include "librarian.h"
#include "frame.h"
#include "block_model.h"
#include "treelog.h"
struct ABAProdSoil : public ABAProd
{
// Units.
static const symbol h_name;
static const symbol L_name;
static const symbol S_name;
static const symbol ABA_unit;
// Parameters.
mutable ScopeExchange scope;
const std::unique_ptr<Number> expr;
// Solve.
void production (const Geometry&, const SoilWater&,
const std::vector<double>& S /* [cm^3/cm^3/h] */,
const std::vector<double>& L /* [cm/cm^3] */,
std::vector<double>& ABA /* [g/cm^3/h] */,
Treelog&) const;
void output (Log&) const
{ }
// Create and Destroy.
void initialize (Treelog&);
bool check (Treelog&) const;
ABAProdSoil (const BlockModel& al);
~ABAProdSoil ();
};
const symbol
ABAProdSoil::h_name ("h");
const symbol
ABAProdSoil::L_name ("L");
const symbol
ABAProdSoil::S_name ("S");
const symbol
ABAProdSoil::ABA_unit ("g/cm^3/h");
void
ABAProdSoil::production (const Geometry& geo, const SoilWater& soil_water,
const std::vector<double>& S /* [cm^3/cm^3/h] */,
const std::vector<double>& L /* [cm/cm^3] */,
std::vector<double>& ABA /* [g/cm^3/h] */,
Treelog& msg) const
{
// Check input.
const size_t cell_size = geo.cell_size ();
daisy_assert (ABA.size () == cell_size);
daisy_assert (L.size () == cell_size);
daisy_assert (S.size () == cell_size);
// For all cells.
for (size_t c = 0; c < cell_size; c++)
{
// Set up values in scope.
scope.set (h_name, soil_water.h (c));
scope.set (L_name, L[c]);
scope.set (S_name, S[c]);
// Find expr value.
double value = 0.0;
if (!expr->tick_value (units, value, ABA_unit, scope, msg))
msg.error ("No ABA production value found");
// Find ABA uptake.
ABA[c] = value; // [g/cm^3 S/h]
}
}
void
ABAProdSoil::initialize (Treelog& msg)
{ expr->initialize (units, scope, msg); }
bool
ABAProdSoil::check (Treelog& msg) const
{
bool ok = true;
if (!expr->check_dim (units, scope, ABA_unit, msg))
ok = false;
return ok;
}
ABAProdSoil::ABAProdSoil (const BlockModel& al)
: ABAProd (al),
scope (__FUNCTION__),
expr (Librarian::build_item<Number> (al, "expr"))
{
scope.add_item (new ExchangeNumber (h_name, "cm", "Soil water pressure."));
scope.add_item (new ExchangeNumber (L_name, "cm/cm^3", "Root density."));
scope.add_item (new ExchangeNumber (S_name, "cm^3/cm^3/h", "Water uptake."));
scope.done ();
}
ABAProdSoil::~ABAProdSoil ()
{ }
static struct ABAProdSoilSyntax : public DeclareModel
{
Model* make (const BlockModel& al) const
{ return new ABAProdSoil (al); }
ABAProdSoilSyntax ()
: DeclareModel (ABAProd::component, "soil", "\
ABA production based on soil location.")
{ }
void load_frame (Frame& frame) const
{
frame.declare_object ("expr", Number::component,
Attribute::Const, Attribute::Singleton, "\
Expression to evaluate to ABA uptake [g/cm^3/h].\n\
The symbol 'h' will be bound to the water pressure [cm].\n\
The symbol 'L' will be bound to the root density [cm/cm^3].\n\
The symbol 'S' will be bound to the water uptake [cm^3/cm^3/h].");
}
} ABAProdSoil_syntax;
// ABAprod_soil.C ends here