Skip to content

Commit 21821ef

Browse files
Merge pull request #715 from dogukanteber/clean-up
Simplify `ParentLayer.cpp` and `SnowLayer.cpp` We noticed some repetition in function used for calculating heat capacity and thermal conductivity in `ParentLayer.cpp` and `SnowLayer.cpp` which was unclear at initial inspection. We realized this is due to the way these functions are called indiscriminately of layer type (soil, snow, rock/parent) within `TemperatureUpdator.cpp` and any changes to this structure would require serious refactoring of the code. As this approach does not require significantly more computation, we have left this as it is, and instead cleaned up some of the code and added comments to make this clearer to future users. result.pdf showed no change between current version of master as expected.
2 parents 7a57846 + c103890 commit 21821ef

File tree

2 files changed

+23
-33
lines changed

2 files changed

+23
-33
lines changed

src/ParentLayer.cpp

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,32 +27,35 @@ void ParentLayer::updateProperty() {
2727
vhcsolid = 2700000;
2828
};
2929

30-
// get frozen layer specific heat capcity
30+
// Note: Though the following functions return the same value,
31+
// they require different names to work inside TemperatureUpdator.cpp
32+
// where these will be called by name and not by layer type.
33+
// Hence they must match with the functions used in Layer.cpp
34+
// and SoilLayer.cpp.
35+
36+
// get frozen layer volumetric heat capacity
3137
double ParentLayer::getFrzVolHeatCapa() {
32-
double vhc = vhcsolid ;
33-
return vhc;
38+
return vhcsolid;
3439
};
3540

41+
// get unfrozen layer volumetric heat capacity
3642
double ParentLayer::getUnfVolHeatCapa() {
37-
double vhc= vhcsolid ;
38-
return vhc;
43+
return vhcsolid;
3944
};
4045

46+
// get mixed (partially frozen) layer volumetric heat capacity
4147
double ParentLayer::getMixVolHeatCapa() {
42-
double vhc= vhcsolid ;
43-
return vhc;
48+
return vhcsolid;
4449
};
4550

4651
// get frozen layer thermal conductivity
4752
double ParentLayer::getFrzThermCond() {
48-
double tc=tcsolid;
49-
return tc;
53+
return tcsolid;
5054
};
5155

5256
// get unfrozen layer thermal conductivity
5357
double ParentLayer::getUnfThermCond() {
54-
double tc=tcsolid;
55-
return tc;
58+
return tcsolid;
5659
};
5760

5861
// get albedo of visible radiation

src/SnowLayer.cpp

Lines changed: 9 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -102,34 +102,21 @@ double SnowLayer::getThermCond() {
102102
return tc;
103103
}
104104

105-
// FIX THIS: THESE 3 functions see to be identical???
105+
// Note: Though the following functions return the same value,
106+
// they require different names to work inside TemperatureUpdator.cpp
107+
// where these will be called by name and not by layer type.
108+
// Hence they must match with the functions used in Layer.cpp
109+
// and SoilLayer.cpp.
110+
106111
double SnowLayer::getFrzVolHeatCapa() {
107-
if (dz != 0) {
108-
// FIX THIS: divide by zero error when there is no thickness!
109-
double vhc = SHCICE * ice/dz;
110-
return vhc;
111-
} else {
112-
return 0;
113-
}
112+
return (dz != 0) ? (SHCICE * ice/dz) : 0;
114113
};
115114

116115
double SnowLayer::getUnfVolHeatCapa() {
117-
if (dz != 0) {
118-
// FIX THIS: divide by zero error when there is no thickness!
119-
double vhc = SHCICE * ice/dz;
120-
return vhc;
121-
} else {
122-
return 0;
123-
}
116+
return (dz != 0) ? (SHCICE * ice/dz) : 0;
124117
};
125118

126119
double SnowLayer::getMixVolHeatCapa() {
127-
if (dz != 0) {
128-
// FIX THIS: divide by zero error when there is no thickness!
129-
double vhc = SHCICE * ice/dz;
130-
return vhc;
131-
} else {
132-
return 0;
133-
}
120+
return (dz != 0) ? (SHCICE * ice/dz) : 0;
134121
};
135122

0 commit comments

Comments
 (0)