github.com/archlabjp/eeslism-go@v0.0.0-20231109122333-4bb7bfcdf292/eeslism/blsnbklib.go (about) 1 //This file is part of EESLISM. 2 // 3 //Foobar is free software : you can redistribute itand /or modify 4 //it under the terms of the GNU General Public License as published by 5 //the Free Software Foundation, either version 3 of the License, or 6 //(at your option) any later version. 7 // 8 //Foobar is distributed in the hope that it will be useful, 9 //but WITHOUT ANY WARRANTY; without even the implied warranty of 10 //MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the 11 //GNU General Public License for more details. 12 // 13 //You should have received a copy of the GNU General Public License 14 //along with Foobar.If not, see < https://www.gnu.org/licenses/>. 15 16 /* snbklib.c */ 17 18 package eeslism 19 20 import ( 21 "fmt" 22 "math" 23 ) 24 25 // 入力: 26 // 27 // 出力: 28 // 日よけの影面積率 Fsdw [-] 29 func FNFsdw(Ksdw, Ksi int, Xazm, Xprf, D, Wr, Hr, Wi1, Hi1, Wi2, Hi2 float64) float64 { 30 31 if DEBUG { 32 fmt.Printf("----- FNFsdw Ksdw=%d Ksi=%d Xazm=%f Xprf=%f D=%f Wr=%f Hr=%f Wi1=%f Hi1=%f Wi2=%f Hi2=%f\n", 33 Ksdw, Ksi, Xazm, Xprf, D, Wr, Hr, Wi1, Hi1, Wi2, Hi2) 34 } 35 36 if Ksdw == 0 { 37 return 0.0 38 } 39 40 Da := D * Xazm 41 Dp := D * Xprf 42 if Ksdw == 2 || Ksdw == 6 { 43 Da = math.Abs(Da) 44 } 45 if Ksdw == 4 || Ksdw == 8 { 46 Da = -Da 47 } 48 49 Asdw := 0.0 50 switch Ksdw { 51 case 1: 52 Asdw = FNAsdw1(Da, Dp, Wr, Hr, Wi1, Hi1, Wi2) 53 case 2, 3, 4: 54 Asdw = FNAsdw1(Dp, Da, Hr, Wr, Hi1, Wi1, Hi2) 55 case 5: 56 Asdw = FNAsdw2(Dp, Hr, Wr, Hi1) 57 case 6, 7, 8: 58 Asdw = FNAsdw2(Da, Wr, Hr, Wi1) 59 case 9: 60 Asdw = FNAsdw3(Da, Dp, Wr, Hr, Wi1, Hi1, Wi2, Hi2) 61 } 62 63 Fsdw := Asdw / (Wr * Hr) 64 65 if Ksi == 1 { 66 Fsdw = 1.0 - Fsdw 67 } 68 69 return Fsdw 70 } 71 72 /* ----------------------------------------------------- */ 73 74 func FNAsdw1(Da, Dp, Wr, Hr, Wi1, Hi, Wi2 float64) float64 { 75 if Dp <= 0.0 { 76 return 0.0 77 } 78 79 Wi := Wi1 80 if Da < 0.0 { 81 Wi = Wi2 82 } 83 84 Daa := math.Abs(Da) 85 86 Dha := Wi*Dp/math.Max(Wi, Daa) - Hi 87 Dha = math.Min(math.Max(0.0, Dha), Hr) 88 89 Dhb := (Wi+Wr)*Dp/math.Max(Wi+Wr, Daa) - Hi 90 Dhb = math.Min(math.Max(0.0, Dhb), Hr) 91 92 var Dwa float64 93 if Hi >= Dp { 94 Dwa = 0.0 95 } else { 96 Dwa = (Wi + Wr) - Hi*Daa/Dp 97 Dwa = math.Min(math.Max(0.0, Dwa), Wr) 98 } 99 100 Dwb := (Wi + Wr) - (Hi+Hr)*Daa/math.Max(Hi+Hr, Dp) 101 Dwb = math.Min(math.Max(0.0, Dwb), Wr) 102 103 Asdw := Dwa*Dha + 0.5*(Dwa+Dwb)*(Dhb-Dha) 104 105 return Asdw 106 } 107 108 /* ----------------------------------------------------- */ 109 110 func FNAsdw2(Dp, Hr, Wr, Hi float64) float64 { 111 if Dp <= 0.0 { 112 return 0.0 113 } 114 115 Dh := math.Min(math.Max(0.0, Dp-Hi), Hr) 116 Asdw := Wr * Dh 117 return Asdw 118 } 119 120 /* ----------------------------------------------------- */ 121 122 func FNAsdw3(Da, Dp, Wr, Hr, Wi1, Hi1, Wi2, Hi2 float64) float64 { 123 Dw1 := math.Min(math.Max(0.0, Da-Wi1), Wr) 124 Dw2 := math.Min(math.Max(0.0, -Da-Wi2), Wr) 125 Dh1 := math.Min(math.Max(0.0, Dp-Hi1), Hr) 126 Dh2 := math.Min(math.Max(0.0, -Dp-Hi2), Hr) 127 Asdw := Wr*(Dh1+Dh2) + (Dw1+Dw2)*(Hr-Dh1-Dh2) 128 129 return Asdw 130 }